Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update junoswap migration contracts so users can access unclaimed rewards #1

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions contracts/junoswap-staking/src/contract.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::cmp::min;
#[cfg(not(feature = "library"))]
use cosmwasm_std::entry_point;
use cosmwasm_std::{
Expand All @@ -11,6 +12,7 @@ use wyndex::asset::{Asset, AssetInfo};

use crate::error::ContractError;
use crate::msg::{ExecuteMsg, MigrateMsg, QueryMsg};
use crate::msg::QueryMsg::TotalStakedAtHeight;
use crate::state::{MigrateConfig, MigrateStakersConfig, DESTINATION, MIGRATION};

// this is the contract we are migrating from
Expand All @@ -32,13 +34,26 @@ pub fn instantiate(

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn query(_deps: Deps, _env: Env, msg: QueryMsg) -> Result<Binary, ContractError> {
// Block before the migration was started
let migration_height: u64 = 6634356;
match msg {
QueryMsg::MigrationFinished {} => {
let no_stakers = stake_cw20::state::STAKED_BALANCES
.keys(_deps.storage, None, None, Order::Ascending)
.next()
.is_none();
Ok(to_binary(&no_stakers)?)
},
QueryMsg::TotalStakedAtHeight { height } => {
let new_height = min(migration_height,height.unwrap_or(u64::MAX));
let staked_total = stake_cw20::state::STAKED_TOTAL.may_load_at_height(_deps.storage, new_height)?.unwrap_or_default();
Ok(to_binary(&stake_cw20::msg::TotalStakedAtHeightResponse{ total: staked_total, height: new_height })?)
},
QueryMsg::StakedBalanceAtHeight { address, height } => {
let address = _deps.api.addr_validate(&address)?;
let new_height = min(migration_height,height.unwrap_or(u64::MAX));
let balance = stake_cw20::state::STAKED_BALANCES.may_load_at_height(_deps.storage, &address, new_height)?.unwrap_or_default();
Ok(to_binary(&stake_cw20::msg::StakedBalanceAtHeightResponse{ balance, height: new_height })?)
}
}
}
Expand Down
9 changes: 9 additions & 0 deletions contracts/junoswap-staking/src/msg.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
use cosmwasm_schema::{cw_serde, QueryResponses};
use cosmwasm_std::Uint128;
use stake_cw20::msg::{StakedBalanceAtHeightResponse, TotalStakedAtHeightResponse};

#[cw_serde]
#[derive(QueryResponses)]
pub enum QueryMsg {
/// Checks whether all stakers have been migrated
#[returns(bool)]
MigrationFinished {},
#[returns(StakedBalanceAtHeightResponse)]
StakedBalanceAtHeight {
address: String,
height: Option<u64>,
},
#[returns(TotalStakedAtHeightResponse)]
TotalStakedAtHeight { height: Option<u64> }
}

/// For existing contract, we need to specify which pool it can be withdrawn into
Expand Down
14 changes: 14 additions & 0 deletions contracts/raw-migration/src/contract.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::cmp::min;
#[cfg(not(feature = "library"))]
use cosmwasm_std::entry_point;
use cosmwasm_std::{
Expand Down Expand Up @@ -35,13 +36,26 @@ pub fn instantiate(

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn query(_deps: Deps, _env: Env, msg: QueryMsg) -> Result<Binary, ContractError> {
// Block before the migration was started
let migration_height: u64 = 6634356;
match msg {
QueryMsg::MigrationFinished {} => {
let no_stakers = stake_cw20::state::STAKED_BALANCES
.keys(_deps.storage, None, None, Order::Ascending)
.next()
.is_none();
Ok(to_binary(&no_stakers)?)
},
QueryMsg::TotalStakedAtHeight { height } => {
let new_height = min(migration_height,height.unwrap_or(u64::MAX));
let staked_total = stake_cw20::state::STAKED_TOTAL.may_load_at_height(_deps.storage, new_height)?.unwrap_or_default();
Ok(to_binary(&stake_cw20::msg::TotalStakedAtHeightResponse{ total: staked_total, height: new_height })?)
},
QueryMsg::StakedBalanceAtHeight { address, height } => {
let address = _deps.api.addr_validate(&address)?;
let new_height = min(migration_height,height.unwrap_or(u64::MAX));
let balance = stake_cw20::state::STAKED_BALANCES.may_load_at_height(_deps.storage, &address, new_height)?.unwrap_or_default();
Ok(to_binary(&stake_cw20::msg::StakedBalanceAtHeightResponse{ balance, height: new_height })?)
}
}
}
Expand Down
8 changes: 8 additions & 0 deletions contracts/raw-migration/src/msg.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use cosmwasm_schema::{cw_serde, QueryResponses};
use cosmwasm_std::Decimal;
use stake_cw20::msg::{StakedBalanceAtHeightResponse, TotalStakedAtHeightResponse};

#[cw_serde]
pub struct InstantiateMsg {}
Expand All @@ -10,6 +11,13 @@ pub enum QueryMsg {
/// Checks whether all stakers have been migrated
#[returns(bool)]
MigrationFinished {},
#[returns(StakedBalanceAtHeightResponse)]
StakedBalanceAtHeight {
address: String,
height: Option<u64>,
},
#[returns(TotalStakedAtHeightResponse)]
TotalStakedAtHeight { height: Option<u64> }
}

/// For existing contract, we need to specify which pool it can be withdrawn into
Expand Down