OlympusDAO / terra-gOHM-staking

Apache License 2.0
0 stars 6 forks source link

staking contract : migration has a problem #1

Open omni7642 opened 2 years ago

omni7642 commented 2 years ago

below migration function issue The migrate function transfers the reward tokens to the new staking contract. But it doesn't transfer the staked tokens to the new contract. I think it's the problem. After migration, new staking contract can't unbond the staked tokens back to the users. The users still have to unbond from the old contract. So migration can't reach its purpose. I think, in migration there should be another transfer of staked tokens. I hope to know that I was wrong. So please let me know if I misunderstood. `

    if sender_addr_raw != config.governance {
        return Err(StdError::generic_err("unauthorized"));
    }

    let mut state: State = read_state(deps.storage)?;

    // compute global reward, sets last_distributed_seconds to env.block.time.seconds
    compute_reward(&config, &mut state, env.block.time.seconds());

    let total_distribution_amount: Uint128 =
        config.distribution_schedule.iter().map(|item| item.2).sum();

    let block_time = env.block.time.seconds();
    // eliminate distribution slots that have not started
    config
        .distribution_schedule
        .retain(|slot| slot.0 < block_time);

    let mut distributed_amount = Uint128::zero();
    for s in config.distribution_schedule.iter_mut() {
        if s.1 < block_time {
            // all distributed
            distributed_amount += s.2;
        } else {
            // partially distributed slot
            let whole_time = s.1 - s.0;
            let distribution_amount_per_second: Decimal = Decimal::from_ratio(s.2, whole_time);

            let passed_time = block_time - s.0;
            let distributed_amount_on_slot =
                distribution_amount_per_second * Uint128::from(passed_time as u128);
            distributed_amount += distributed_amount_on_slot;

            // modify distribution slot
            s.1 = block_time;
            s.2 = distributed_amount_on_slot;
        }
    }

    // update config
    store_config(deps.storage, &config)?;
    // update state
    store_state(deps.storage, &state)?;

    let remaining_anc = total_distribution_amount.checked_sub(distributed_amount)?;

    let reward_token: Addr = deps.api.addr_humanize(&config.reward_token)?;

    Ok(Response::new()
        .add_messages(vec![CosmosMsg::Wasm(WasmMsg::Execute {
            contract_addr: reward_token.to_string(),
            msg: to_binary(&Cw20ExecuteMsg::Transfer {
                recipient: new_staking_contract,
                amount: remaining_anc,
            })?,
            funds: vec![],
        })])
        .add_attributes(vec![
            ("action", "migrate_staking"),
            ("distributed_amount", &distributed_amount.to_string()),
            ("remaining_amount", &remaining_anc.to_string()),
        ]))
}

`

tj327 commented 2 years ago

I don't think this is an issue. We cannot update user's bond amount, so it's good to keep staked tokens in old staking contract. This will allow users to unbond their staked tokens and bond to new staking tokens to get reward.