diff --git a/Cargo.lock b/Cargo.lock index 514402d5a..9fb36a7bd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -50,7 +50,7 @@ dependencies = [ [[package]] name = "astroport" -version = "3.2.1" +version = "3.2.2" dependencies = [ "astroport-circular-buffer", "cosmwasm-schema", @@ -127,7 +127,7 @@ dependencies = [ [[package]] name = "astroport-generator" -version = "2.3.1" +version = "2.3.2" dependencies = [ "anyhow", "astroport", diff --git a/contracts/pair/tests/integration.rs b/contracts/pair/tests/integration.rs index 762818bc5..61980944d 100644 --- a/contracts/pair/tests/integration.rs +++ b/contracts/pair/tests/integration.rs @@ -1542,12 +1542,9 @@ fn provide_liquidity_with_autostaking_to_generator() { ], ); + assert_eq!(pair.lp_token().balance(&pair.address), Uint128::new(1000)); assert_eq!( - pair.lp_token().balance(pair.address.to_string()), - Uint128::new(1000) - ); - assert_eq!( - generator.query_deposit(&pair.lp_token(), astroport), + generator.query_deposit(&pair.lp_token(), &astroport), Uint128::new(999_999000), ); } diff --git a/contracts/pair_concentrated/tests/pair_concentrated_integration.rs b/contracts/pair_concentrated/tests/pair_concentrated_integration.rs index 959be536d..c05dbb8a8 100644 --- a/contracts/pair_concentrated/tests/pair_concentrated_integration.rs +++ b/contracts/pair_concentrated/tests/pair_concentrated_integration.rs @@ -1423,12 +1423,9 @@ fn provide_liquidity_with_autostaking_to_generator() { ], ); + assert_eq!(pair.lp_token().balance(&pair.address), Uint128::new(1000)); assert_eq!( - pair.lp_token().balance(pair.address.to_string()), - Uint128::new(1000) - ); - assert_eq!( - generator.query_deposit(&pair.lp_token(), astroport), + generator.query_deposit(&pair.lp_token(), &astroport), Uint128::new(999_999000), ); } diff --git a/contracts/pair_concentrated_inj/tests/pair_inj_concentrated_integration.rs b/contracts/pair_concentrated_inj/tests/pair_inj_concentrated_integration.rs index 92f6327c1..740fa9b70 100644 --- a/contracts/pair_concentrated_inj/tests/pair_inj_concentrated_integration.rs +++ b/contracts/pair_concentrated_inj/tests/pair_inj_concentrated_integration.rs @@ -1976,12 +1976,9 @@ fn provide_liquidity_with_autostaking_to_generator() { ], ); + assert_eq!(pair.lp_token().balance(&pair.address), Uint128::new(1000)); assert_eq!( - pair.lp_token().balance(pair.address.to_string()), - Uint128::new(1000) - ); - assert_eq!( - generator.query_deposit(&pair.lp_token(), astroport), + generator.query_deposit(&pair.lp_token(), &astroport), Uint128::new(999_999000), ); } diff --git a/contracts/pair_stable/tests/integration.rs b/contracts/pair_stable/tests/integration.rs index 477e0bb43..6f92086a2 100644 --- a/contracts/pair_stable/tests/integration.rs +++ b/contracts/pair_stable/tests/integration.rs @@ -1393,12 +1393,9 @@ fn provide_liquidity_with_autostaking_to_generator() { ], ); + assert_eq!(pair.lp_token().balance(&pair.address), Uint128::new(1000)); assert_eq!( - pair.lp_token().balance(pair.address.to_string()), - Uint128::new(1000) - ); - assert_eq!( - generator.query_deposit(&pair.lp_token(), astroport), + generator.query_deposit(&pair.lp_token(), &astroport), Uint128::new(1999_999000), ); } diff --git a/contracts/tokenomics/generator/Cargo.toml b/contracts/tokenomics/generator/Cargo.toml index 86bc31411..7c2de8dc4 100644 --- a/contracts/tokenomics/generator/Cargo.toml +++ b/contracts/tokenomics/generator/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "astroport-generator" -version = "2.3.1" +version = "2.3.2" authors = ["Astroport"] edition = "2021" diff --git a/contracts/tokenomics/generator/neutron_bug_fix_log.md b/contracts/tokenomics/generator/neutron_bug_fix_log.md new file mode 100644 index 000000000..cf708d542 --- /dev/null +++ b/contracts/tokenomics/generator/neutron_bug_fix_log.md @@ -0,0 +1,247 @@ +* Given: + + * chain_id: neutron-1 + + * the proposal's id that set up pools: 61 (https://app.astroport.fi/governance/proposal/61) + + * the pools receiving ASTRO and their alloc points: + + neutron1vw93hy8tm3xekpz9286428gesmmc8dqxmw8cujsh3fcu3rt0hvdqvlyrrl, 17739 + neutron1sx99fxy4lqx0nv3ys86tkdrch82qygxyec5c8dxsk9raz4at5zpq48m66c, 38986 + neutron1kmuv6zmpr2nd3fnqefcffgfmhm74c8vhyerklaphrawyp3398gws74huny, 1754 + neutron1jkcf80nd4pfc2krce3xk9m9y994pllq58avx89sfzqlalej4frus27ms3a, 41521 + + * the total alloc point: 100000 + + * the ASTRO amount distributed per block, set by the proposal: 1984587 + + * the satellite address: neutron1ffus553eet978k024lmssw0czsxwr97mggyv85lpcsdkft8v9ufsz3sa07 + + * the generator address: neutron1jz58yjay8uq8zkfw95ngyv3m2wfs2zjef9vdz75d9pa46fdtxc5sxtafny + + * the vesting address: neutron178d2p84ldlzcl53clc25uy6mx3trazxdy08akhjp3qf5chlmccgq6hv2pl + + +* Querying the block height when the proposal was executed: + ``` + neutrond q wasm cs smart neutron1ffus553eet978k024lmssw0czsxwr97mggyv85lpcsdkft8v9ufsz3sa07 '{"proposal_state": {"id": 61}}' -o json | jq '.data' + + 1437191 + ``` + +* Checking the pools that had deposits and their last reward blocks before the proposal's execution: + ``` + neutrond q wasm cs smart neutron1jz58yjay8uq8zkfw95ngyv3m2wfs2zjef9vdz75d9pa46fdtxc5sxtafny '{"pool_info": {"lp_token": "neutron1vw93hy8tm3xekpz9286428gesmmc8dqxmw8cujsh3fcu3rt0hvdqvlyrrl"}}' --height 1437190 -o json | jq + + + pool not found + ``` + + ``` + neutrond q wasm cs smart neutron1jz58yjay8uq8zkfw95ngyv3m2wfs2zjef9vdz75d9pa46fdtxc5sxtafny '{"pool_info": {"lp_token": "neutron1sx99fxy4lqx0nv3ys86tkdrch82qygxyec5c8dxsk9raz4at5zpq48m66c"}}' --height 1437190 -o json | jq '.data.last_reward_block' + + 488583 + ``` + + ``` + neutrond q wasm cs smart neutron1jz58yjay8uq8zkfw95ngyv3m2wfs2zjef9vdz75d9pa46fdtxc5sxtafny '{"pool_info": {"lp_token": "neutron1kmuv6zmpr2nd3fnqefcffgfmhm74c8vhyerklaphrawyp3398gws74huny"}}' --height 1437190 -o json | jq '.data.last_reward_block' + + pool not found + ``` + + ``` + neutrond q wasm cs smart neutron1jz58yjay8uq8zkfw95ngyv3m2wfs2zjef9vdz75d9pa46fdtxc5sxtafny '{"pool_info": {"lp_token": "neutron1jkcf80nd4pfc2krce3xk9m9y994pllq58avx89sfzqlalej4frus27ms3a"}}' --height 1437190 -o json | jq '.data.last_reward_block' + + 488583 + ``` + +* Finding the users who had deposites on the pools before the proposal's execution: + ``` + neutrond q wasm cs smart neutron1jz58yjay8uq8zkfw95ngyv3m2wfs2zjef9vdz75d9pa46fdtxc5sxtafny '{"pool_stakers": {"lp_token": "neutron1sx99fxy4lqx0nv3ys86tkdrch82qygxyec5c8dxsk9raz4at5zpq48m66c"}}' --height 1437190 -o json | jq '.data' + + [ + { + "account": "neutron1ryhxe5fzczelcfmrhmcw9x2jsqy677fw59fsctr09srk24lt93eszwlvyj", + "amount": "936146544918" + } + ] + ``` + + ``` + neutrond q wasm cs smart neutron1jz58yjay8uq8zkfw95ngyv3m2wfs2zjef9vdz75d9pa46fdtxc5sxtafny '{"pool_stakers": {"lp_token": "neutron1jkcf80nd4pfc2krce3xk9m9y994pllq58avx89sfzqlalej4frus27ms3a"}}' --height 1437190 -o json | jq '.data' + [ + { + "account": "neutron1ryhxe5fzczelcfmrhmcw9x2jsqy677fw59fsctr09srk24lt93eszwlvyj", + "amount": "1501110150153" + } + ] + ``` + +* Checking the user's indexes now (block height 1568424 time 2023-07-18T14:59:48 at the moment of writing this): + ``` + key: echo "0009$(ascii_to_hex user_info)0042$(ascii_to_hex neutron1sx99fxy4lqx0nv3ys86tkdrch82qygxyec5c8dxsk9raz4at5zpq48m66c)$(ascii_to_hex neutron1ryhxe5fzczelcfmrhmcw9x2jsqy677fw59fsctr09srk24lt93eszwlvyj)" + + neutrond q wasm cs raw $generator 0009757365725F696E666F00426E657574726F6E3173783939667879346C7178306E763379733836746B647263683832717967787965633563386478736B3972617A346174357A707134386D3636636E657574726F6E31727968786535667A637A656C63666D72686D63773978326A737179363737667735396673637472303973726B32346C74393365737A776C76796A --height 1568424 -o json | jq -r '.data' | base64 --decode | jq -r '.reward_user_index' + + 0 + + key: echo "0009$(ascii_to_hex user_info)0042$(ascii_to_hex neutron1jkcf80nd4pfc2krce3xk9m9y994pllq58avx89sfzqlalej4frus27ms3a)$(ascii_to_hex neutron1ryhxe5fzczelcfmrhmcw9x2jsqy677fw59fsctr09srk24lt93eszwlvyj)" + + neutrond q wasm cs raw $generator 0009757365725F696E666F00426E657574726F6E316A6B636638306E6434706663326B72636533786B396D3979393934706C6C713538617678383973667A716C616C656A346672757332376D7333616E657574726F6E31727968786535667A637A656C63666D72686D63773978326A737179363737667735396673637472303973726B32346C74393365737A776C76796A --height 1568424 -o json | jq -r '.data' | base64 --decode | jq -r '.reward_user_index' + + 0 + ``` + + So, no rewards were withdrawn by the user at the moment + +* Checking whether the user will be able to withdraw rewards before the bug fix: + ``` + neutrond q wasm cs smart neutron1jz58yjay8uq8zkfw95ngyv3m2wfs2zjef9vdz75d9pa46fdtxc5sxtafny '{"pending_token": {"lp_token": "neutron1sx99fxy4lqx0nv3ys86tkdrch82qygxyec5c8dxsk9raz4at5zpq48m66c", "user": "neutron1ryhxe5fzczelcfmrhmcw9x2jsqy677fw59fsctr09srk24lt93eszwlvyj"}}' --height 1568424 + + 835429168530 + ``` + + ``` + neutrond q wasm cs smart neutron1jz58yjay8uq8zkfw95ngyv3m2wfs2zjef9vdz75d9pa46fdtxc5sxtafny '{"pending_token": {"lp_token": "neutron1jkcf80nd4pfc2krce3xk9m9y994pllq58avx89sfzqlalej4frus27ms3a", "user": "neutron1ryhxe5fzczelcfmrhmcw9x2jsqy677fw59fsctr09srk24lt93eszwlvyj"}}' --height 1568424 + + 889723596667 + ``` + + available rewards on the vesting contract for the generator: + ``` + neutrond q wasm cs raw neutron178d2p84ldlzcl53clc25uy6mx3trazxdy08akhjp3qf5chlmccgq6hv2pl 000C76657374696E675F696E666F6E657574726F6E316A7A3538796A6179387571387A6B667739356E677976336D32776673327A6A65663976647A373564397061343666647478633573787461666E79 -o json --height 1568424 | jq -r '.data' | base64 --decode | jq + { + "schedules": [ + { + "start_point": { + "time": 1689217200, + "amount": "0" + }, + "end_point": { + "time": 1704942000, + "amount": "10402412000000" + } + } + ], + "released_amount": "35347828690" + } + + (current_time - start_time) / (end_time - start_time) * end_amount - released_amount + (1689692388 - 1689217200) / (1704942000 - 1689217200) * 10402412000000 - 35347828690 = + + 279002837357 + ``` + + The minimal unlocked amounts that would allow to withdraw rewards are: + ``` + 835429168530 - 279002837357 = 556426331173 + ``` + or + ``` + 889723596667 - 279002837357 = 610720759310 + ``` + + unlocked amount per second by the vesting: + ``` + 10402412000000 / (1704942000 - 1689217200) = 661530 + ``` + + So, roughly calculating, the time that we have to fix the bug is the least of the following: + + ``` + insufficient_ASTRO / (vested amount per second * (total_alloc_point - alloc_point) / total_alloc_point) / minutes / hours / days + + 556426331173 / (661529 * (100000 - 38986) / 100000) / 60 / 60 / 24 = 15 days + + 610720759310 / (661529 * (100000 - 41521) / 100000) / 60 / 60 / 24 = 18 days + ``` + but the more other generator depositors claim their rewards the more time we have. The best case is that no misscomputed reward will be withdrawn until we fix the bug. + +* Querying virtual amounts that the user had on the moment of the proposal execution: + ``` + neutrond q wasm cs smart neutron1jz58yjay8uq8zkfw95ngyv3m2wfs2zjef9vdz75d9pa46fdtxc5sxtafny '{"user_virtual_amount": {"lp_token": "neutron1sx99fxy4lqx0nv3ys86tkdrch82qygxyec5c8dxsk9raz4at5zpq48m66c", "user": "neutron1ryhxe5fzczelcfmrhmcw9x2jsqy677fw59fsctr09srk24lt93eszwlvyj"}}' --height 1437191 + + 374458617967 + + neutrond q wasm cs smart neutron1jz58yjay8uq8zkfw95ngyv3m2wfs2zjef9vdz75d9pa46fdtxc5sxtafny '{"user_virtual_amount": {"lp_token": "neutron1jkcf80nd4pfc2krce3xk9m9y994pllq58avx89sfzqlalej4frus27ms3a", "user": "neutron1ryhxe5fzczelcfmrhmcw9x2jsqy677fw59fsctr09srk24lt93eszwlvyj"}}' --height 1437191 + + 600444060061 + ``` + +* The solution to fix misscomputed rewards is to increase the user reward indexes on contract migration as it follows below: + * query the current user reward indexes for those pools + * increase them by the following calculated indexes: + ``` + (setup_pools_block - the wrong last reward block) * tokens_per_block * alloc_point / total_alloc_point / user's virtual amount + + (1437191 - 488583) * 1984587 * 38986 / 100000 / 374458617967 = 1.96002573416386269210 + + (1437191 - 488583) * 1984587 * 41521 / 100000 / 600444060061 = 1.30182370931349860257 + ``` + +* Checking rewards if the fix would apply now: + * query last reward block and calculate the current pool's global index: + ``` + neutrond q wasm cs smart neutron1jz58yjay8uq8zkfw95ngyv3m2wfs2zjef9vdz75d9pa46fdtxc5sxtafny '{"pool_info": {"lp_token": "neutron1sx99fxy4lqx0nv3ys86tkdrch82qygxyec5c8dxsk9raz4at5zpq48m66c"}}' --height 1568424 -o json | jq -r '.data.global_reward_index, .data.last_reward_block' + + 2.225500979661236903 + + 1565741 + + neutrond q wasm cs smart neutron1jz58yjay8uq8zkfw95ngyv3m2wfs2zjef9vdz75d9pa46fdtxc5sxtafny '{"total_virtual_supply": {"generator": "neutron1sx99fxy4lqx0nv3ys86tkdrch82qygxyec5c8dxsk9raz4at5zpq48m66c"}}' --height 1568424 -o json | jq -r '.data' + + 375311882818 + + last_global_index + (current_block - last_reward_block) * astro_per_block * alloc_point / total_alloc_point / virtual_supply + + 2.225500979661236903 + (1568424 - 1565741) * 1984587 * 38986 / 100000 / 375311882818 = 2.23103202448996594742 + ``` + + ``` + neutrond q wasm cs smart neutron1jz58yjay8uq8zkfw95ngyv3m2wfs2zjef9vdz75d9pa46fdtxc5sxtafny '{"pool_info": {"lp_token": "neutron1jkcf80nd4pfc2krce3xk9m9y994pllq58avx89sfzqlalej4frus27ms3a"}}' --height 1568424 -o json | jq -r '.data.global_reward_index, .data.last_reward_block' + + 1.481537641504742878 + + 1568250 + + neutrond q wasm cs smart neutron1jz58yjay8uq8zkfw95ngyv3m2wfs2zjef9vdz75d9pa46fdtxc5sxtafny '{"total_virtual_supply": {"generator": "neutron1jkcf80nd4pfc2krce3xk9m9y994pllq58avx89sfzqlalej4frus27ms3a"}}' --height 1568424 -o json | jq -r '.data' + + 601532655696 + + last_global_index + (current_block - last_reward_block) * astro_per_block * alloc_point / total_alloc_point / virtual_supply + + 1.481537641504742878 + (1568424 - 1568250) * 1984587 * 41521 / 100000 / 601532655696 = 1.48177599854607936786 + ``` + + * query virtual amounts that the user has now: + ``` + neutrond q wasm cs smart neutron1jz58yjay8uq8zkfw95ngyv3m2wfs2zjef9vdz75d9pa46fdtxc5sxtafny '{"user_virtual_amount": {"lp_token": "neutron1sx99fxy4lqx0nv3ys86tkdrch82qygxyec5c8dxsk9raz4at5zpq48m66c", "user": "neutron1ryhxe5fzczelcfmrhmcw9x2jsqy677fw59fsctr09srk24lt93eszwlvyj"}}' --height 1568424 + + 374458617967 + + neutrond q wasm cs smart neutron1jz58yjay8uq8zkfw95ngyv3m2wfs2zjef9vdz75d9pa46fdtxc5sxtafny '{"user_virtual_amount": {"lp_token": "neutron1jkcf80nd4pfc2krce3xk9m9y994pllq58avx89sfzqlalej4frus27ms3a", "user": "neutron1ryhxe5fzczelcfmrhmcw9x2jsqy677fw59fsctr09srk24lt93eszwlvyj"}}' --height 1568424 + + 600444060061 + ``` + + * calculate reward by indexes: + + (global_reward_index - user_reward_index) * deposit + + ``` + (2.23103202448996594742 - 1.96002573416386269210) * 374458617967 = 101480640935 + + (1.48177599854607936786 - 1.30182370931349860257) * 600444060061 = 108051283164 + ``` + + * calculate reward by blocks: + + (current_block - proposal_block) * astro_per_block * alloc_point / total_alloc_point + + ``` + (1568424 - 1437191) * 1984587 * 38986 / 100000 = 101536427187 + + (1568424 - 1437191) * 1984587 * 41521 / 100000 = 108138664989 + ``` + + * rewards by indexes is a bit less, because of rounding issues that occurs by not using those exact types that used in the contract diff --git a/contracts/tokenomics/generator/src/contract.rs b/contracts/tokenomics/generator/src/contract.rs index 6c8a0515f..f98b90e42 100644 --- a/contracts/tokenomics/generator/src/contract.rs +++ b/contracts/tokenomics/generator/src/contract.rs @@ -611,7 +611,10 @@ pub fn execute_setup_pools( mass_update_pools(deps.branch(), &env, &cfg, &prev_pools)?; for (lp_token, _) in &setup_pools { - if !POOL_INFO.has(deps.storage, lp_token) { + if let Some(mut pool_info) = POOL_INFO.may_load(deps.storage, lp_token)? { + pool_info.last_reward_block = cfg.start_block.max(env.block.height.into()); + POOL_INFO.save(deps.storage, lp_token, &pool_info)?; + } else { create_pool(deps.branch(), &env, lp_token, &cfg)?; } } @@ -2037,7 +2040,12 @@ pub fn migrate(mut deps: DepsMut, env: Env, msg: MigrateMsg) -> Result { migration::migrate_configs_from_v220(&mut deps, &msg)?; } - "2.3.0" => {} + "2.3.0" => { + if env.block.chain_id == "neutron-1" { + migration::fix_neutron_users_reward_indexes(&mut deps)?; + } + } + "2.3.1" => {} _ => return Err(ContractError::MigrationError {}), }, _ => return Err(ContractError::MigrationError {}), diff --git a/contracts/tokenomics/generator/src/migration.rs b/contracts/tokenomics/generator/src/migration.rs index f2a36b7fa..9783e6d26 100644 --- a/contracts/tokenomics/generator/src/migration.rs +++ b/contracts/tokenomics/generator/src/migration.rs @@ -1,9 +1,9 @@ -use crate::state::CONFIG; +use crate::state::{CONFIG, USER_INFO}; use astroport::asset::AssetInfo; use astroport::generator::{Config, MigrateMsg}; use cosmwasm_schema::cw_serde; -use cosmwasm_std::{Addr, DepsMut, StdResult, Uint128, Uint64}; +use cosmwasm_std::{Addr, Decimal, DepsMut, StdError, StdResult, Uint128, Uint64}; use cw_storage_plus::Item; /// This structure stores the core parameters for the Generator contract. @@ -67,3 +67,27 @@ pub fn migrate_configs_from_v220(deps: &mut DepsMut, msg: &MigrateMsg) -> StdRes CONFIG.save(deps.storage, &cfg) } + +pub fn fix_neutron_users_reward_indexes(deps: &mut DepsMut) -> StdResult<()> { + let pool1 = + Addr::unchecked("neutron1sx99fxy4lqx0nv3ys86tkdrch82qygxyec5c8dxsk9raz4at5zpq48m66c"); + let pool2 = + Addr::unchecked("neutron1jkcf80nd4pfc2krce3xk9m9y994pllq58avx89sfzqlalej4frus27ms3a"); + + let depositor = + Addr::unchecked("neutron1ryhxe5fzczelcfmrhmcw9x2jsqy677fw59fsctr09srk24lt93eszwlvyj"); + + // We already know that the new user info structure is used and that the values of that type exist there + USER_INFO.update::<_, StdError>(deps.storage, (&pool1, &depositor), |v| { + let mut r = v.unwrap(); + r.reward_user_index += Decimal::raw(1960025734161847622); + Ok(r) + })?; + USER_INFO.update::<_, StdError>(deps.storage, (&pool2, &depositor), |v| { + let mut r = v.unwrap(); + r.reward_user_index += Decimal::raw(1301823709312052739); + Ok(r) + })?; + + Ok(()) +} diff --git a/contracts/tokenomics/generator/tests/integration.rs b/contracts/tokenomics/generator/tests/integration.rs index 88c97375d..0e4d760e3 100644 --- a/contracts/tokenomics/generator/tests/integration.rs +++ b/contracts/tokenomics/generator/tests/integration.rs @@ -4365,7 +4365,7 @@ fn migrate_proxy() { &lp_token.address, ); - val.mint(vkr_staking.clone(), Uint128::new(110_000_000)); + val.mint(&vkr_staking, Uint128::new(110_000_000)); let proxy_code_id = store_proxy_code(&mut app.borrow_mut()); @@ -4508,3 +4508,41 @@ fn migrate_proxy() { 1 ); } + +#[test] +fn check_that_last_reward_block_is_reset_when_pool_becomes_incentivised() { + let app = Rc::new(RefCell::new(App::default())); + + let astroport = astroport_address(); + + let mut generator = MockGeneratorBuilder::new(&app).instantiate(); + + let factory = generator.factory(); + + let astro = MockToken::try_from((&app, &generator.astro_token_info())).unwrap(); + let tkn1 = MockTokenBuilder::new(&app, "TKN1").instantiate(); + + let pair = factory.instantiate_xyk_pair(&[astro.asset_info(), tkn1.asset_info()]); + + pair.mint_allow_provide_and_stake( + &astroport, + &[ + astro.asset_info().with_balance(Uint128::new(1000_000000)), + tkn1.asset_info().with_balance(Uint128::new(1000_000000)), + ], + ); + + app.borrow_mut().update_block(|b| b.height += 1000); + + let lp_token = pair.lp_token(); + + generator.setup_pools(&[(lp_token.address.to_string(), Uint128::one())]); + + // if last reward block didn't reset, user would get incentives for 1000 blocks + assert_eq!( + generator + .pending_token(&lp_token.address, &astroport) + .pending, + Uint128::zero() + ); +} diff --git a/packages/astroport/Cargo.toml b/packages/astroport/Cargo.toml index 8586ab1a4..02fd28180 100644 --- a/packages/astroport/Cargo.toml +++ b/packages/astroport/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "astroport" -version = "3.2.1" +version = "3.2.2" authors = ["Astroport"] edition = "2021" description = "Common Astroport types, queriers and other utils" diff --git a/packages/astroport_mocks/src/generator.rs b/packages/astroport_mocks/src/generator.rs index 0eaaaeaed..54c6ba7b2 100644 --- a/packages/astroport_mocks/src/generator.rs +++ b/packages/astroport_mocks/src/generator.rs @@ -3,7 +3,7 @@ use std::fmt::Debug; use astroport::{ asset::AssetInfo, factory::ExecuteMsg as FactoryExecuteMsg, - generator::{Config, ExecuteMsg, InstantiateMsg, QueryMsg}, + generator::{Config, ExecuteMsg, InstantiateMsg, PendingTokenResponse, QueryMsg}, token::ExecuteMsg as Cw20ExecuteMsg, vesting::{ Cw20HookMsg as VestingCw20HookMsg, VestingAccount, VestingSchedule, VestingSchedulePoint, @@ -218,7 +218,7 @@ where pub fn query_deposit( &self, lp_token: &MockToken, - user: impl Into, + user: &Addr, ) -> Uint128 { self.app .borrow() @@ -232,4 +232,47 @@ where ) .unwrap() } + + pub fn setup_pools(&mut self, pools: &[(String, Uint128)]) { + self.app + .borrow_mut() + .execute_contract( + astroport_address(), + self.address.clone(), + &ExecuteMsg::SetupPools { + pools: pools.to_vec(), + }, + &[], + ) + .unwrap(); + } + + pub fn set_tokens_per_block(&mut self, amount: Uint128) { + self.app + .borrow_mut() + .execute_contract( + astroport_address(), + self.address.clone(), + &ExecuteMsg::SetTokensPerBlock { amount }, + &[], + ) + .unwrap(); + } + + pub fn pending_token(&self, lp_token: &Addr, user: &Addr) -> PendingTokenResponse { + let res: PendingTokenResponse = self + .app + .borrow() + .wrap() + .query_wasm_smart( + self.address.clone(), + &QueryMsg::PendingToken { + lp_token: lp_token.into(), + user: user.into(), + }, + ) + .unwrap(); + + res + } } diff --git a/packages/astroport_mocks/src/pair.rs b/packages/astroport_mocks/src/pair.rs index 69ea91230..1af4f663c 100644 --- a/packages/astroport_mocks/src/pair.rs +++ b/packages/astroport_mocks/src/pair.rs @@ -162,8 +162,8 @@ where app: self.app.clone(), address: contract_addr.clone(), }; - token.mint(sender.to_string(), asset.amount); - token.allow(sender, self.address.to_string(), asset.amount); + token.mint(sender, asset.amount); + token.allow(sender, &self.address, asset.amount); }; } self.provide(sender, assets, None, true, None) diff --git a/packages/astroport_mocks/src/token.rs b/packages/astroport_mocks/src/token.rs index ef36e64f8..4280eda91 100644 --- a/packages/astroport_mocks/src/token.rs +++ b/packages/astroport_mocks/src/token.rs @@ -52,7 +52,7 @@ where C::ExecT: Clone + Debug + PartialEq + JsonSchema + DeserializeOwned + 'static, C::QueryT: CustomQuery + DeserializeOwned + 'static, { - pub fn new(app: &WKApp, symbol: impl Into) -> Self { + pub fn new(app: &WKApp, symbol: &str) -> Self { Self { app: app.clone(), symbol: symbol.into(), @@ -119,7 +119,7 @@ where } } - pub fn mint(&self, recipient: impl Into, amount: Uint128) { + pub fn mint(&self, recipient: &Addr, amount: Uint128) { let astroport = astroport_address(); self.app .borrow_mut() @@ -135,7 +135,7 @@ where .unwrap(); } - pub fn balance(&self, address: impl Into) -> Uint128 { + pub fn balance(&self, address: &Addr) -> Uint128 { let res: BalanceResponse = self .app .borrow() @@ -163,7 +163,7 @@ where .unwrap(); } - pub fn allow(&self, sender: &Addr, spender: impl Into, amount: Uint128) { + pub fn allow(&self, sender: &Addr, spender: &Addr, amount: Uint128) { self.app .borrow_mut() .execute_contract( diff --git a/packages/astroport_mocks/src/xastro.rs b/packages/astroport_mocks/src/xastro.rs index cd58758c5..f33c761de 100644 --- a/packages/astroport_mocks/src/xastro.rs +++ b/packages/astroport_mocks/src/xastro.rs @@ -52,7 +52,7 @@ where C::ExecT: Clone + Debug + PartialEq + JsonSchema + DeserializeOwned + 'static, C::QueryT: CustomQuery + DeserializeOwned + 'static, { - pub fn new(app: &WKApp, symbol: impl Into) -> Self { + pub fn new(app: &WKApp, symbol: &str) -> Self { Self { app: app.clone(), symbol: symbol.into(),