diff --git a/precompile/binaries/stdlib/vip_reward.mv b/precompile/binaries/stdlib/vip_reward.mv index 38927080..5e90a4d0 100644 Binary files a/precompile/binaries/stdlib/vip_reward.mv and b/precompile/binaries/stdlib/vip_reward.mv differ diff --git a/precompile/binaries/stdlib/vip_zapping.mv b/precompile/binaries/stdlib/vip_zapping.mv index c19ffa6f..159a37e2 100644 Binary files a/precompile/binaries/stdlib/vip_zapping.mv and b/precompile/binaries/stdlib/vip_zapping.mv differ diff --git a/precompile/modules/initia_stdlib/sources/vip/reward.move b/precompile/modules/initia_stdlib/sources/vip/reward.move index fb450b4b..8f5e1c7a 100644 --- a/precompile/modules/initia_stdlib/sources/vip/reward.move +++ b/precompile/modules/initia_stdlib/sources/vip/reward.move @@ -6,6 +6,7 @@ module initia_std::vip_reward { use std::vector; use std::option; use std::event; + use std::block; use initia_std::object::{Self, Object, ExtendRef}; use initia_std::fungible_asset::{Self, Metadata, FungibleAsset, FungibleStore}; @@ -46,6 +47,7 @@ module initia_std::vip_reward { const EZAPPING_STAKELISTED_NOT_ENOUGH: u64 = 23; const EALREADY_REGISTERED: u64 = 24; const EBRIDGE_NOT_FOUND: u64 = 25; + const EVESTING_IN_PROGRESS: u64 = 26; // // Constants @@ -55,46 +57,51 @@ module initia_std::vip_reward { const PROOF_LENGTH: u64 = 32; const REWARD_SYMBOL: vector = b"uinit"; const DEFAULT_PROPORTION_RATIO: vector = b"0.5"; - const DEFAULT_VESTING_PERIOD: u64 = 52; // stage + const DEFAULT_VESTING_PERIOD: u64 = 52; // 52 times const DEFAULT_MINIMUM_TVL: u64 = 0; const DEFAULT_MAXIMUM_TVL: u64 = 100_000_000_000_000_000; - const DEFAULT_VIP_WEIGHT: u64 = 1; const DEFAULT_VIP_START_STAGE: u64 = 1; struct ModuleStore has key { // global stage stage: u64, + // governance-defined vesting period in stage unit + // the number of times vesting is divided + vesting_period: u64, // agent for VIP reward and snapshot taker agent: address, // governance-defined proportion to decrease overhead of keeping the L2 INIT balance. - // A user only need to keep the `vesting.l2_score * proportion` amount of INIT token + // a user only need to keep the `vesting.l2_score * proportion` amount of INIT token // to vest whole vesting rewards. proportion: Decimal256, - // governance-defined vesting period in stage unit. - vesting_period: u64, // TVL cap of L2 INIT token to receive the reward. maximum_tvl: u64, // minimum TVL of L2 INIT token to receive the reward. minimum_tvl: u64, - // total reward amount for each stage - total_stage_reward: table::Table /* stage */, u64 /* total reward amount */>, + stage_history: table::Table /* stage */, StageHistory>, // a set of bridge info bridges: table::Table /* bridge id */, Bridge>, } struct RewardStore has key { - /// Reward object's ExtendRef + // reward object's ExtendRef extend_ref: ExtendRef, - /// The total reward coins + // the total reward coins reward: Object, - /// The stage data for each stage. - /// key: stage (use `table_key::encode_u64` for iterating) - stage_data: table::Table, StageData>, - /// Total reward for the stage. - stage_reward: table::Table, u64>, + // the stage data for each stage. + stage_data: table::Table /* stage */, StageData>, + // total reward for the stage. + stage_reward: table::Table /* stage */, u64>, + } + + struct StageHistory has store { + // total reward amount funded + total_reward: u64, + vesting_period: u64, + release_time: u64, } - struct Bridge has store { + struct Bridge has store, drop { bridge_addr: address, reward_addr: address, operator_addr: address, @@ -102,35 +109,31 @@ module initia_std::vip_reward { } struct StageData has store { - /// Merkle root of L2 INIT token score. + // merkle root of L2 INIT token score. merkle_root: vector, - /// Sum of total L2 scores. + // sum of total L2 scores. total_l2_score: u64, } - /// User vesting store contains the claimed stages - /// and the vesting rewards. struct VestingStore has key { - /// key: stage claimed_stages: table::Table, - /// key: start_stage (use `table_key::encode_u64` for iterating) - vestings: table::Table, VestingScore>, - vestings_finalized: table::Table, VestingScore>, + vestings: table::Table /* vesting start stage */, VestingScore>, + vestings_finalized: table::Table /* vesting start stage */, VestingScore>, } struct VestingScore has copy, drop, store { - /// initial vesting reward amount. + // initial vesting reward amount. initial_reward: u64, - /// remaining vesting reward amount. + // remaining vesting reward amount. remaining_reward: u64, - /// The initial score of the L2 contract that were present - /// to receive the reward. + // the initial score of the L2 contract that were present + // to receive the reward. l2_score: u64, - /// start stage + // start stage start_stage: u64, - /// end stage (start_stage + vesting_period) + // end stage (start_stage + vesting_period) end_stage: u64, - /// minimum score to receive the reward. + // minimum score to receive the reward. minimum_score: u64, } @@ -152,32 +155,57 @@ module initia_std::vip_reward { maximum_tvl: u64, } + struct StageHistoryResponse has drop { + total_reward: u64, + vesting_period: u64, + release_time: u64, + } + struct BridgeResponse has drop { bridge_addr: address, reward_addr: address, operator_addr: address, vip_weight: u64, } + + struct VestingResponse has drop { + length: u64, + vestings: vector, + } + + struct Vesting has drop { + start_stage: u64, + end_stage: u64, + remaining_reward: u64, + initial_reward: u64 + } + + struct VestingChange has drop, store { + vesting_start_stage: u64, + initial_reward: u64, + remaining_reward: u64, + } + // // Events // #[event] - /// Event emitted when a user claimed the rewards. + // Event emitted when a user claimed the rewards. struct ClaimEvent has drop, store { account: address, operator: address, bridge_id: u64, - /// Claimed stage. + // claimed stage. stage: u64, - /// Newly distributed vesting reward amount. + // newly distributed vesting reward amount. vesting_reward_amount: u64, - /// Quantity claimed vesting reward that was previously distributed. + // accumulated claimed vesting reward that was previously distributed. vested_reward_amount: u64, - // reward coin metadata - metadata: Object, - /// l2 score + // l2 score l2_score: u64, + // vesting changes + vesting_changes: vector, } #[event] @@ -198,9 +226,9 @@ module initia_std::vip_reward { vesting_period: DEFAULT_VESTING_PERIOD, proportion: decimal256::from_string(&string::utf8(DEFAULT_PROPORTION_RATIO)), agent: signer::address_of(chain), - total_stage_reward: table::new, u64>(), maximum_tvl: DEFAULT_MAXIMUM_TVL, minimum_tvl: DEFAULT_MINIMUM_TVL, + stage_history: table::new, StageHistory>(), bridges: table::new, Bridge>(), }); } @@ -266,10 +294,10 @@ module initia_std::vip_reward { vesting_addr } - /// Compare bytes and return a following result number: - /// 0: equal - /// 1: v1 is greator than v2 - /// 2: v1 is less than v2 + // Compare bytes and return a following result number: + // 0: equal + // 1: v1 is greator than v2 + // 2: v1 is less than v2 fun bytes_cmp(v1: &vector, v2: &vector): u8 { assert!(vector::length(v1) == PROOF_LENGTH, error::invalid_argument(EINVALID_PROOF_LENGTH)); assert!(vector::length(v2) == PROOF_LENGTH, error::invalid_argument(EINVALID_PROOF_LENGTH)); @@ -342,12 +370,12 @@ module initia_std::vip_reward { assert!(merkle_root == root_hash, error::invalid_argument(EINVALID_MERKLE_PROOFS)); } - /// check signer is chain + // check signer is chain fun check_chain_permission(chain: &signer) { assert!(signer::address_of(chain) == @initia_std, error::permission_denied(EUNAUTHORIZED)); } - /// check signer is chain + // check signer is chain fun check_agent_permission(agent: &signer) acquires ModuleStore { let module_store = borrow_global(@initia_std); assert!(signer::address_of(agent) == module_store.agent, error::permission_denied(EUNAUTHORIZED)); @@ -395,6 +423,7 @@ module initia_std::vip_reward { l2_score: u64, vestings: &mut table::Table, VestingScore>, vestings_finalized: &mut table::Table, VestingScore>, + vesting_changes: &mut vector, ) : u64 { let vested_reward = 0u64; let iter = table::iter_mut(vestings, option::none(), option::none(), 1); @@ -421,11 +450,16 @@ module initia_std::vip_reward { // // vest_ratio = max_ratio * score_ratio // vest_amount = value.initial_reward * vest_ratio - let vest_amount = calculate_vest(value, l2_score); vested_reward = vested_reward + vest_amount; value.remaining_reward = value.remaining_reward - vest_amount; + + vector::push_back(vesting_changes, VestingChange { + vesting_start_stage: value.start_stage, + initial_reward: value.initial_reward, + remaining_reward: value.remaining_reward, + }); }; vested_reward } @@ -451,6 +485,11 @@ module initia_std::vip_reward { let module_store = borrow_global(@initia_std); // assert claimable conditions + let (_, block_time) = block::get_block_info(); + let vesting_history = table::borrow(&module_store.stage_history, table_key::encode_u64(stage)); + + assert!(block_time >= vesting_history.release_time , error::unavailable(EVESTING_IN_PROGRESS)); + assert!(!table::contains(&vesting_store.claimed_stages, stage), error::invalid_argument(ESTAGE_ALREADY_CLAIMED)); assert!(table::contains(&reward_store.stage_data, table_key::encode_u64(stage)), error::not_found(ESTAGE_DATA_NOT_FOUND)); @@ -472,11 +511,13 @@ module initia_std::vip_reward { // Vest previous vesting rewards. let reward_signer = &object::generate_signer_for_extending(&reward_store.extend_ref); + let vesting_changes = vector::empty(); let amount = vest_reward( stage, l2_score, &mut vesting_store.vestings, &mut vesting_store.vestings_finalized, + &mut vesting_changes, ); let vested_reward = fungible_asset::withdraw(reward_signer, reward_store.reward, amount); @@ -487,13 +528,14 @@ module initia_std::vip_reward { let remaining_reward_ratio = decimal256::sub(&decimal256::one(),&operator_store.commission_rate); let vesting_reward_amount = decimal256::mul_u64(&remaining_reward_ratio, reward_amount); + let stage_history = table::borrow(&module_store.stage_history, table_key::encode_u64(stage)); table::add(&mut vesting_store.vestings, table_key::encode_u64(stage), VestingScore { initial_reward: vesting_reward_amount, remaining_reward: vesting_reward_amount, l2_score, start_stage: stage, - end_stage: stage + module_store.vesting_period, + end_stage: stage + stage_history.vesting_period, minimum_score: decimal256::mul_u64(&module_store.proportion, l2_score), }); @@ -506,8 +548,8 @@ module initia_std::vip_reward { stage, vesting_reward_amount, vested_reward_amount: fungible_asset::amount(&vested_reward), - metadata: reward_metadata(), - l2_score + l2_score, + vesting_changes, } ); @@ -554,45 +596,59 @@ module initia_std::vip_reward { // Entry Functions // - /// Permissioned entry function for vesting snapshot operator. public entry fun register( chain: &signer, operator: address, bridge_id: u64, bridge_address: address, + vip_weight: u64, ) acquires ModuleStore { check_chain_permission(chain); let module_store = borrow_global_mut(signer::address_of(chain)); assert!(!table::contains(&module_store.bridges, table_key::encode_u64(bridge_id)), error::already_exists(EALREADY_REGISTERED)); - let constructor_ref = object::create_named_object(chain, generate_reward_seed(operator, bridge_id), false); - let extend_ref = object::generate_extend_ref(&constructor_ref); - let object = object::generate_signer(&constructor_ref); - let object_addr = object::address_from_constructor_ref(&constructor_ref); - let transfer_ref = object::generate_transfer_ref(&constructor_ref); - object::disable_ungated_transfer(&transfer_ref); + let object_addr = object::create_object_address(signer::address_of(chain), generate_reward_seed(operator, bridge_id)); + + if (!exists(object_addr)){ + let constructor_ref = object::create_named_object(chain, generate_reward_seed(operator, bridge_id), false); + let extend_ref = object::generate_extend_ref(&constructor_ref); + let object = object::generate_signer(&constructor_ref); + let transfer_ref = object::generate_transfer_ref(&constructor_ref); + object::disable_ungated_transfer(&transfer_ref); + + let reward_store = primary_fungible_store::ensure_primary_store_exists(object_addr, reward_metadata()); + + move_to( + &object, RewardStore { + extend_ref, + reward: reward_store, + stage_data: table::new, StageData>(), + stage_reward: table::new, u64>(), + } + ); + }; // add bridge info table::add(&mut module_store.bridges, table_key::encode_u64(bridge_id), Bridge { bridge_addr: bridge_address, reward_addr: object_addr, operator_addr: operator, - vip_weight: DEFAULT_VIP_WEIGHT, + vip_weight, }); + } - assert!(!exists(object_addr), error::already_exists(EREWARD_STORE_ALREADY_EXISTS)); - let reward_store = primary_fungible_store::ensure_primary_store_exists(object_addr, reward_metadata()); + public entry fun deregister( + chain: &signer, + bridge_id: u64, + ) acquires ModuleStore { + check_chain_permission(chain); + let module_store = borrow_global_mut(signer::address_of(chain)); + assert!(table::contains(&module_store.bridges, table_key::encode_u64(bridge_id)), error::not_found(EBRIDGE_NOT_FOUND)); - move_to( - &object, RewardStore { - extend_ref, - reward: reward_store, - stage_data: table::new, StageData>(), - stage_reward: table::new, u64>(), - } - ); + table::remove(&mut module_store.bridges, table_key::encode_u64(bridge_id)); } + public entry fun update_agent( old_agent: &signer, new_agent: address, @@ -619,17 +675,26 @@ module initia_std::vip_reward { } } - /// Permissionless interface to fund reward reserve. + // Permissionless interface to fund reward reserve. public entry fun fund_reward_script( agent: &signer, amount: u64, stage: u64, + release_time: u64, ) acquires ModuleStore, RewardStore { let shares = vector::empty(); let total_share = calculate_total_share(&mut shares); assert!(total_share > 0, error::invalid_state(EINVALID_TOTAL_SHARE)); - fund_reward(agent, total_share, &mut shares, reward_metadata(), amount, stage); + fund_reward( + agent, + total_share, + &mut shares, + reward_metadata(), + amount, + stage, + release_time, + ); } fun fund_reward( @@ -639,10 +704,11 @@ module initia_std::vip_reward { metadata: Object, amount: u64, stage: u64, + release_time: u64, ) acquires RewardStore, ModuleStore { let module_store = borrow_global_mut(@initia_std); assert!(signer::address_of(agent) == module_store.agent, error::permission_denied(EUNAUTHORIZED)); - assert!(!table::contains(&mut module_store.total_stage_reward, table_key::encode_u64(stage)), error::already_exists(EALREADY_FUNDED)); + assert!(!table::contains(&mut module_store.stage_history, table_key::encode_u64(stage)), error::already_exists(EALREADY_FUNDED)); assert!(stage == module_store.stage, error::invalid_argument(EINVALID_FUND_STAGE)); assert!(primary_fungible_store::balance(signer::address_of(agent), metadata) >= amount, error::invalid_argument(EREWARD_NOT_ENOUGH)); @@ -679,7 +745,11 @@ module initia_std::vip_reward { primary_fungible_store::deposit(signer::address_of(agent), total_reward); module_store.stage = stage + 1; - table::add(&mut module_store.total_stage_reward, table_key::encode_u64(stage), amount) + table::add(&mut module_store.stage_history, table_key::encode_u64(stage), StageHistory { + total_reward: amount, + vesting_period: module_store.vesting_period, + release_time + }) } fun calculate_total_share( @@ -710,7 +780,7 @@ module initia_std::vip_reward { (total_share) } - /// Permissioned entry function for vesting snapshot operator. + // Permissioned entry function for vesting snapshot operator. public entry fun set_merkle_root ( agent: &signer, operator: address, @@ -746,7 +816,7 @@ module initia_std::vip_reward { }); } - /// Claim user rewards and unlock vesting rewards. + // Claim user rewards and unlock vesting rewards. public entry fun claim_reward_script ( account: &signer, operator: address, @@ -788,7 +858,7 @@ module initia_std::vip_reward { ) acquires ModuleStore { check_chain_permission(chain); let module_store = borrow_global_mut(signer::address_of(chain)); - assert!(vesting_period > 0,error::invalid_argument(EINVALID_VEST_PERIOD)); + assert!(vesting_period > 0, error::invalid_argument(EINVALID_VEST_PERIOD)); module_store.vesting_period = vesting_period; } @@ -855,6 +925,18 @@ module initia_std::vip_reward { // // View Functions // + + #[view] + public fun get_stage_history_info(stage: u64): StageHistoryResponse acquires ModuleStore { + let module_store = borrow_global(@initia_std); + let vesting_history = table::borrow(&module_store.stage_history, table_key::encode_u64(stage)); + + StageHistoryResponse { + total_reward: vesting_history.total_reward, + vesting_period: vesting_history.vesting_period, + release_time: vesting_history.release_time, + } + } #[view] public fun get_bridge_info(bridge_id: u64): BridgeResponse acquires ModuleStore { @@ -878,18 +960,7 @@ module initia_std::vip_reward { } #[view] - public fun get_reward_reserve(bridge_id: u64): u64 acquires RewardStore, ModuleStore { - let bridge_info = get_bridge_info(bridge_id); - - let reward_addr = create_reward_address(bridge_info.operator_addr, bridge_id); - assert!(exists(reward_addr), error::not_found(EVESTING_STORE_NOT_FOUND)); - let reward_store = borrow_global(reward_addr); - - fungible_asset::balance(reward_store.reward) - } - - #[view] - public fun get_vesting_at_stage(account_addr: address, bridge_id: u64, stage: u64): VestingScore acquires VestingStore { + public fun get_vesting(account_addr: address, bridge_id: u64, stage: u64): VestingScore acquires VestingStore { let vesting_addr = create_vesting_address(account_addr, bridge_id); assert!(exists(vesting_addr), error::not_found(EVESTING_STORE_NOT_FOUND)); let vesting_store = borrow_global_mut(vesting_addr); @@ -901,7 +972,7 @@ module initia_std::vip_reward { } #[view] - public fun get_vesting_finalized_at_stage(account_addr: address, bridge_id: u64, stage: u64): VestingScore acquires VestingStore { + public fun get_vesting_finalized(account_addr: address, bridge_id: u64, stage: u64): VestingScore acquires VestingStore { let vesting_addr = create_vesting_address(account_addr, bridge_id); assert!(exists(vesting_addr), error::not_found(EVESTING_STORE_NOT_FOUND)); let vesting_store = borrow_global_mut(vesting_addr); @@ -912,6 +983,64 @@ module initia_std::vip_reward { *vesting_finalized } + #[view] + public fun get_vestings(account_addr: address, bridge_id: u64) : VestingResponse acquires VestingStore { + let vesting_addr = create_vesting_address(account_addr, bridge_id); + assert!(exists(vesting_addr), error::not_found(EVESTING_STORE_NOT_FOUND)); + let vesting_store = borrow_global_mut(vesting_addr); + + let vestings = vector::empty(); + let iter = table::iter(&mut vesting_store.vestings, option::none(), option::none(), 1); + loop { + if (!table::prepare, VestingScore>(&mut iter)) { + break + }; + + let (_, value) = table::next, VestingScore>(&mut iter); + + vector::push_back(&mut vestings, Vesting { + start_stage: value.start_stage, + end_stage: value.end_stage, + remaining_reward: value.remaining_reward, + initial_reward: value.initial_reward, + }); + }; + + VestingResponse { + length: vector::length(&vestings), + vestings + } + } + + #[view] + public fun get_vestings_finalized(account_addr: address, bridge_id: u64) : VestingResponse acquires VestingStore { + let vesting_addr = create_vesting_address(account_addr, bridge_id); + assert!(exists(vesting_addr), error::not_found(EVESTING_STORE_NOT_FOUND)); + let vesting_store = borrow_global_mut(vesting_addr); + + let vestings = vector::empty(); + let iter = table::iter(&mut vesting_store.vestings_finalized, option::none(), option::none(), 1); + loop { + if (!table::prepare, VestingScore>(&mut iter)) { + break + }; + + let (_, value) = table::next, VestingScore>(&mut iter); + + vector::push_back(&mut vestings, Vesting { + start_stage: value.start_stage, + end_stage: value.end_stage, + remaining_reward: value.remaining_reward, + initial_reward: value.initial_reward, + }); + }; + + VestingResponse { + length: vector::length(&vestings), + vestings + } + } + #[view] public fun get_last_claimed_stage(account_addr: address, bridge_id: u64): u64 acquires VestingStore { let vesting_addr = create_vesting_address(account_addr, bridge_id); @@ -968,24 +1097,6 @@ module initia_std::vip_reward { } } - #[view] - public fun get_stage(): u64 acquires ModuleStore { - let module_response = get_module_store(); - module_response.stage - } - - #[view] - public fun get_proportion(): Decimal256 acquires ModuleStore { - let module_response = get_module_store(); - module_response.proportion - } - - #[view] - public fun get_vesting_period(): u64 acquires ModuleStore { - let module_response = get_module_store(); - module_response.vesting_period - } - #[view] public fun get_minimum_score(account_addr: address, bridge_id: u64, stage: u64): u64 acquires VestingStore { let vesting_store = borrow_global_mut(get_vesting_address(account_addr, bridge_id)); @@ -1032,13 +1143,10 @@ module initia_std::vip_reward { // // Test Functions // - + #[test_only] use initia_std::coin::{BurnCapability, FreezeCapability, MintCapability}; - #[test_only] - use std::block; - #[test_only] use initia_std::dex; @@ -1053,7 +1161,10 @@ module initia_std::vip_reward { burn_cap: BurnCapability, freeze_cap: FreezeCapability, mint_cap: MintCapability, - } + } + + #[test_only] + const DEFAULT_VIP_WEIGHT_FOR_TEST: u64 = 1; #[test_only] public fun init_module_for_test(chain: &signer){ @@ -1099,6 +1210,7 @@ module initia_std::vip_reward { signer::address_of(operator), bridge_id, bridge_address, + DEFAULT_VIP_WEIGHT_FOR_TEST, ); update_operator_commission_rate( @@ -1118,7 +1230,7 @@ module initia_std::vip_reward { mint_amount: u64, commission_rate: Decimal256, proportion: Decimal256, - ): (u64) acquires OperatorStore, ModuleStore { + ): u64 acquires OperatorStore, ModuleStore { primary_fungible_store::init_module_for_test(chain); init_module_for_test(chain); let (burn_cap, freeze_cap, mint_cap, _) = test_initialize_coin(chain, string::utf8(b"uinit")); @@ -1144,7 +1256,7 @@ module initia_std::vip_reward { mint_cap, }); - (bridge_id) + bridge_id } #[test_only] @@ -1153,13 +1265,14 @@ module initia_std::vip_reward { operator: address, bridge_id: u64, reward_amount: u64, + release_time: u64, ): vector> acquires RewardStore, OperatorStore, ModuleStore { - fund_reward_script(agent, reward_amount, 1); - fund_reward_script(agent, reward_amount, 2); - fund_reward_script(agent, reward_amount, 3); - fund_reward_script(agent, reward_amount, 4); - fund_reward_script(agent, reward_amount, 5); - fund_reward_script(agent, reward_amount, 6); + fund_reward_script(agent, reward_amount, 1, release_time); + fund_reward_script(agent, reward_amount, 2, release_time); + fund_reward_script(agent, reward_amount, 3, release_time); + fund_reward_script(agent, reward_amount, 4, release_time); + fund_reward_script(agent, reward_amount, 5, release_time); + fund_reward_script(agent, reward_amount, 6, release_time); set_merkle_root(agent, operator, bridge_id, 1, x"c2c9964717d099fa39ebfde03685dd0b050be59fce12231da9eae065fc8dfb93", 800_000); set_merkle_root(agent, operator, bridge_id, 2, x"c2c9964717d099fa39ebfde03685dd0b050be59fce12231da9eae065fc8dfb93", 800_000); @@ -1181,19 +1294,20 @@ module initia_std::vip_reward { operator: address, bridge_id: u64, reward_amount: u64, + release_time: u64, ): vector> acquires RewardStore, OperatorStore, ModuleStore { - fund_reward_script(agent, reward_amount, 1); - fund_reward_script(agent, reward_amount, 2); + fund_reward_script(agent, reward_amount, 1, release_time); + fund_reward_script(agent, reward_amount, 2, release_time); set_merkle_root(agent, operator, bridge_id, 1, x"c40a82c8bd1653b6f4da68b0d0f137efd2d04d65af60007e6a623eb203dc44a3", 1_000); set_merkle_root(agent, operator, bridge_id, 2, x"c40a82c8bd1653b6f4da68b0d0f137efd2d04d65af60007e6a623eb203dc44a3", 1_000); - fund_reward_script(agent, reward_amount, 3); - fund_reward_script(agent, reward_amount, 4); + fund_reward_script(agent, reward_amount, 3, release_time); + fund_reward_script(agent, reward_amount, 4, release_time); set_merkle_root(agent, operator, bridge_id, 3, x"932a2280f1a1afdd9cc9a4ed047b0b8019ba542440264a826b38bc883c951a45", 500); set_merkle_root(agent, operator, bridge_id, 4, x"932a2280f1a1afdd9cc9a4ed047b0b8019ba542440264a826b38bc883c951a45", 500); - fund_reward_script(agent, reward_amount, 5); - fund_reward_script(agent, reward_amount, 6); + fund_reward_script(agent, reward_amount, 5, release_time); + fund_reward_script(agent, reward_amount, 6, release_time); set_merkle_root(agent, operator, bridge_id, 5, x"a123e381099b7b8a60b0019e739797eabf6ce8bfcc831e52475a96c0ca499e9f", 100); set_merkle_root(agent, operator, bridge_id, 6, x"a123e381099b7b8a60b0019e739797eabf6ce8bfcc831e52475a96c0ca499e9f", 100); @@ -1265,6 +1379,7 @@ module initia_std::vip_reward { signer::address_of(operator), 1, @0x90, + DEFAULT_VIP_WEIGHT_FOR_TEST, ); // initialize vip_reward @@ -1273,6 +1388,7 @@ module initia_std::vip_reward { signer::address_of(operator), 1, @0x90, + DEFAULT_VIP_WEIGHT_FOR_TEST, ); } @@ -1294,10 +1410,11 @@ module initia_std::vip_reward { signer::address_of(operator), 1, @0x90, + DEFAULT_VIP_WEIGHT_FOR_TEST ); let bridge_info = get_bridge_info(1); - assert!(bridge_info.vip_weight == DEFAULT_VIP_WEIGHT, 1); + assert!(bridge_info.vip_weight == DEFAULT_VIP_WEIGHT_FOR_TEST, 1); update_vip_weight( chain, @@ -1312,7 +1429,7 @@ module initia_std::vip_reward { #[test(chain=@0x1, operator=@0x56ccf33c45b99546cd1da172cf6849395bbf8573, bridge=@0x99, receiver=@0x19c9b6007d21a996737ea527f46b160b0a057c37)] fun test_update_proportion(chain: &signer, operator: &signer, bridge: &signer, receiver: &signer) acquires RewardStore, VestingStore, OperatorStore, ModuleStore { let operator_addr = signer::address_of(operator); - let (bridge_id) = test_setup( + let bridge_id = test_setup( chain, operator, 1, @@ -1320,10 +1437,10 @@ module initia_std::vip_reward { 1_000_000_000_000, decimal256::from_string(&string::utf8(b"0")), decimal256::from_string(&string::utf8(b"0.1")) - ); + ); let reward_per_stage = 1_000_000; - let score_merkle_proofs = test_setup_merkle_scene1(chain, operator_addr, bridge_id, reward_per_stage); + let score_merkle_proofs = test_setup_merkle_scene1(chain, operator_addr, bridge_id, reward_per_stage, 0); claim_reward_script(receiver, operator_addr, bridge_id, 1, score_merkle_proofs, 800_000); claim_reward_script(receiver, operator_addr, bridge_id, 2, score_merkle_proofs, 800_000); @@ -1343,7 +1460,7 @@ module initia_std::vip_reward { #[test(chain=@0x1, operator=@0x56ccf33c45b99546cd1da172cf6849395bbf8573, bridge=@0x99, receiver=@0x19c9b6007d21a996737ea527f46b160b0a057c37)] fun test_get_last_claimed_stages(chain: &signer, operator: &signer, bridge: &signer, receiver: &signer) acquires RewardStore, VestingStore, OperatorStore, ModuleStore { let operator_addr = signer::address_of(operator); - let (bridge_id) = test_setup( + let bridge_id = test_setup( chain, operator, 1, @@ -1353,7 +1470,7 @@ module initia_std::vip_reward { decimal256::from_string(&string::utf8(b"1")) ); - let score_merkle_proofs = test_setup_merkle_scene1(chain, operator_addr, bridge_id, 1_000_000); + let score_merkle_proofs = test_setup_merkle_scene1(chain, operator_addr, bridge_id, 1_000_000, 0); claim_reward_script(receiver, operator_addr, bridge_id, 1, score_merkle_proofs, 800_000); assert!(get_last_claimed_stage(signer::address_of(receiver), bridge_id) == 1, 2); @@ -1371,7 +1488,7 @@ module initia_std::vip_reward { #[test(chain=@0x1, operator=@0x56ccf33c45b99546cd1da172cf6849395bbf8573, bridge=@0x99, receiver=@0x19c9b6007d21a996737ea527f46b160b0a057c37)] fun test_update_vesting_period(chain: &signer, operator: &signer, bridge: &signer, receiver: &signer) acquires RewardStore, VestingStore, OperatorStore, ModuleStore { let operator_addr = signer::address_of(operator); - let (bridge_id) = test_setup( + let bridge_id = test_setup( chain, operator, 1, @@ -1384,7 +1501,7 @@ module initia_std::vip_reward { let reward_per_stage = 1_000_000; let vesting_period = 10; update_vesting_period(chain, vesting_period); - let score_merkle_proofs = test_setup_merkle_scene1(chain, operator_addr, bridge_id, reward_per_stage); + let score_merkle_proofs = test_setup_merkle_scene1(chain, operator_addr, bridge_id, reward_per_stage, 0); claim_reward_script(receiver, operator_addr, bridge_id, 1, score_merkle_proofs, 800_000); claim_reward_script(receiver, operator_addr, bridge_id, 2, score_merkle_proofs, 800_000); @@ -1392,18 +1509,19 @@ module initia_std::vip_reward { claim_reward_script(receiver, operator_addr, bridge_id, 4, score_merkle_proofs, 400_000); claim_reward_script(receiver, operator_addr, bridge_id, 5, score_merkle_proofs, 800_000); + assert!(get_stage_history_info(1).vesting_period == vesting_period, 1); assert!(coin::balance(signer::address_of(receiver), reward_metadata()) == ( reward_per_stage/vesting_period + reward_per_stage/(vesting_period*2) + reward_per_stage/(vesting_period*2) + reward_per_stage/vesting_period // stage 1 + reward_per_stage/(vesting_period*2) + reward_per_stage/(vesting_period*2) + reward_per_stage/vesting_period // stage 2 + reward_per_stage/vesting_period + reward_per_stage/vesting_period // stage 3 + reward_per_stage/vesting_period // stage 4 - ), 6); + ), 2); } #[test(chain=@0x1, operator=@0x56ccf33c45b99546cd1da172cf6849395bbf8573, bridge=@0x99, receiver=@0x19c9b6007d21a996737ea527f46b160b0a057c37)] fun test_finalized_vesting(chain: &signer, operator: &signer, bridge: &signer, receiver: &signer) acquires RewardStore, VestingStore, OperatorStore, ModuleStore { let operator_addr = signer::address_of(operator); - let (bridge_id) = test_setup( + let bridge_id = test_setup( chain, operator, 1, @@ -1416,27 +1534,30 @@ module initia_std::vip_reward { let reward_per_stage = 1_000_000; let vesting_period = 2; update_vesting_period(chain, vesting_period); - let score_merkle_proofs = test_setup_merkle_scene1(chain, operator_addr, bridge_id, reward_per_stage); + let score_merkle_proofs = test_setup_merkle_scene1(chain, operator_addr, bridge_id, reward_per_stage, 0); claim_reward_script(receiver, operator_addr, bridge_id, 1, score_merkle_proofs, 800_000); // vesting 1 created claim_reward_script(receiver, operator_addr, bridge_id, 2, score_merkle_proofs, 800_000); // vesting 2 created - get_vesting_at_stage(signer::address_of(receiver), bridge_id, 1); - get_vesting_at_stage(signer::address_of(receiver), bridge_id, 2); + get_vesting(signer::address_of(receiver), bridge_id, 1); + get_vesting(signer::address_of(receiver), bridge_id, 2); claim_reward_script(receiver, operator_addr, bridge_id, 3, score_merkle_proofs, 400_000); claim_reward_script(receiver, operator_addr, bridge_id, 4, score_merkle_proofs, 400_000); // vesting 1 finalized claim_reward_script(receiver, operator_addr, bridge_id, 5, score_merkle_proofs, 800_000); // vesting 2 finalized - get_vesting_finalized_at_stage(signer::address_of(receiver), bridge_id, 1); - get_vesting_finalized_at_stage(signer::address_of(receiver), bridge_id, 2); + get_vesting_finalized(signer::address_of(receiver), bridge_id, 1); + get_vesting_finalized(signer::address_of(receiver), bridge_id, 2); + + assert!(get_vestings(signer::address_of(receiver), bridge_id).length == 3, 1); + assert!(get_vestings_finalized(signer::address_of(receiver), bridge_id).length == 2, 2); } #[test(chain=@0x1, operator=@0x56ccf33c45b99546cd1da172cf6849395bbf8573, bridge=@0x99, receiver=@0x19c9b6007d21a996737ea527f46b160b0a057c37)] fun test_update_minimum_tvl(chain: &signer, operator: &signer, bridge: &signer, receiver: &signer) acquires ModuleStore, VestingStore, OperatorStore, RewardStore { let operator_addr = signer::address_of(operator); - let (bridge_id) = test_setup( + let bridge_id = test_setup( chain, operator, 1, @@ -1446,7 +1567,7 @@ module initia_std::vip_reward { decimal256::from_string(&string::utf8(b"1")) ); - let score_merkle_proofs = test_setup_merkle_scene1(chain, operator_addr, bridge_id, 1_000_000); + let score_merkle_proofs = test_setup_merkle_scene1(chain, operator_addr, bridge_id, 1_000_000, 0); update_minimum_tvl(chain, 1_000); claim_reward_script(receiver, operator_addr, bridge_id, 1, score_merkle_proofs, 800_000); @@ -1459,7 +1580,7 @@ module initia_std::vip_reward { fun test_claim_already_claimed(chain: &signer, operator: &signer, bridge: &signer, receiver: &signer) acquires RewardStore, VestingStore, OperatorStore, ModuleStore { let operator_addr = signer::address_of(operator); - let (bridge_id) = test_setup( + let bridge_id = test_setup( chain, operator, 1, @@ -1469,7 +1590,7 @@ module initia_std::vip_reward { decimal256::from_string(&string::utf8(b"1")) ); - let score_merkle_proofs = test_setup_merkle_scene1(chain, operator_addr, bridge_id, 1_000_000); + let score_merkle_proofs = test_setup_merkle_scene1(chain, operator_addr, bridge_id, 1_000_000, 0); claim_reward_script(receiver, operator_addr, bridge_id, 1, score_merkle_proofs, 800_000); claim_reward_script(receiver, operator_addr, bridge_id, 1, score_merkle_proofs, 800_000); @@ -1479,7 +1600,7 @@ module initia_std::vip_reward { fun test_shrink_reward(chain: &signer, operator: &signer, bridge: &signer, receiver: &signer) acquires RewardStore, VestingStore, OperatorStore, ModuleStore { let operator_addr = signer::address_of(operator); - let (bridge_id) = test_setup( + let bridge_id = test_setup( chain, operator, 1, @@ -1493,7 +1614,7 @@ module initia_std::vip_reward { let reward_per_stage = 1_000_000; update_vesting_period(chain, vesting_period); - let score_merkle_proofs = test_setup_merkle_scene2(chain, operator_addr, bridge_id, reward_per_stage); + let score_merkle_proofs = test_setup_merkle_scene2(chain, operator_addr, bridge_id, reward_per_stage, 0); claim_reward_script(receiver, operator_addr, bridge_id, 1, score_merkle_proofs, 1_000); claim_reward_script(receiver, operator_addr, bridge_id, 2, score_merkle_proofs, 1_000); @@ -1501,7 +1622,8 @@ module initia_std::vip_reward { claim_reward_script(receiver, operator_addr, bridge_id, 4, score_merkle_proofs, 500); claim_reward_script(receiver, operator_addr, bridge_id, 5, score_merkle_proofs, 100); claim_reward_script(receiver, operator_addr, bridge_id, 6, score_merkle_proofs, 100); - let vesting = get_vesting_at_stage(signer::address_of(receiver), bridge_id, 1); + + let vesting = get_vesting(signer::address_of(receiver), bridge_id, 1); let reward_by_stage_1 = vesting.initial_reward - vesting.remaining_reward; let max_reward_per_claim = reward_per_stage / vesting_period; @@ -1516,7 +1638,7 @@ module initia_std::vip_reward { fun test_claim_jump_stage(chain: &signer, operator: &signer, bridge: &signer, receiver: &signer) acquires RewardStore, VestingStore, OperatorStore, ModuleStore { let operator_addr = signer::address_of(operator); - let (bridge_id) = test_setup( + let bridge_id = test_setup( chain, operator, 1, @@ -1528,7 +1650,7 @@ module initia_std::vip_reward { let reward_per_stage = 1_000_000; let vesting_period = DEFAULT_VESTING_PERIOD; - let score_merkle_proofs = test_setup_merkle_scene1(chain, operator_addr, bridge_id, reward_per_stage); + let score_merkle_proofs = test_setup_merkle_scene1(chain, operator_addr, bridge_id, reward_per_stage, 0); claim_reward_script(receiver, operator_addr, bridge_id, 1, score_merkle_proofs, 800_000); claim_reward_script(receiver, operator_addr, bridge_id, 3, score_merkle_proofs, 400_000); @@ -1556,6 +1678,7 @@ module initia_std::vip_reward { signer::address_of(operator), 1, @0x90, + DEFAULT_VIP_WEIGHT_FOR_TEST, ); register( @@ -1563,6 +1686,7 @@ module initia_std::vip_reward { signer::address_of(operator), 2, @0x91, + DEFAULT_VIP_WEIGHT_FOR_TEST, ); register( @@ -1570,6 +1694,7 @@ module initia_std::vip_reward { signer::address_of(operator), 3, @0x92, + DEFAULT_VIP_WEIGHT_FOR_TEST, ); update_operator_commission_rate( @@ -1578,11 +1703,7 @@ module initia_std::vip_reward { ); let total_reward_amount = 100_000_000; - fund_reward_script( - chain, - total_reward_amount, - 1 - ); + fund_reward_script(chain, total_reward_amount, 1, 0); let reward_addr = create_reward_address(signer::address_of(operator), 1); let reward_store = borrow_global(reward_addr); @@ -1595,12 +1716,75 @@ module initia_std::vip_reward { assert!(fungible_asset::balance(reward_store.reward) == total_reward_amount/4, 3); } + #[test(chain=@0x1, agent=@0x2, operator=@0x56ccf33c45b99546cd1da172cf6849395bbf8573, bridge=@0x99, receiver=@0x19c9b6007d21a996737ea527f46b160b0a057c37)] + fun test_deregistered_bridge(chain: &signer, agent:&signer, operator: &signer, receiver: &signer, bridge: &signer) + acquires RewardStore, VestingStore, OperatorStore, ModuleStore, TestCapability { + let operator_addr = signer::address_of(operator); + let bridge_id = test_setup( + chain, + operator, + 1, + signer::address_of(bridge), + 1_000_000_000_000, + decimal256::from_string(&string::utf8(b"0")), + decimal256::from_string(&string::utf8(b"0.5")) + ); + + let cap = borrow_global(signer::address_of(chain)); + let bridge_id2 = 2; + + test_register_bridge( + chain, + operator, + bridge_id2, + @0x1000, + 10000000000000000, + decimal256::from_string(&string::utf8(b"0")), + &cap.mint_cap + ); + + let reward_per_stage = 1_000_000_000; + let score_merkle_proofs: vector> = vector::empty>(); + vector::push_back(&mut score_merkle_proofs, x"b59284dd26bfe937d585d797edaf117bce6981a38fffa321b4f324f21932a010"); + vector::push_back(&mut score_merkle_proofs, x"437b58ec38d14fca98d5dc411b2d59cb03915ccce0718f94a94952846613f3f2"); + + update_agent(chain, signer::address_of(agent)); + primary_fungible_store::transfer(chain, reward_metadata(), signer::address_of(agent), 1_000_000_000_000); + + fund_reward_script(agent, reward_per_stage, 1, 0); + fund_reward_script(agent, reward_per_stage/2, 2, 0); + + deregister(chain, bridge_id); + + fund_reward_script(agent, reward_per_stage, 3, 0); + fund_reward_script(agent, reward_per_stage, 4, 0); + + register( + chain, + operator_addr, + bridge_id, + signer::address_of(bridge), + DEFAULT_VIP_WEIGHT_FOR_TEST, + ); + + fund_reward_script(agent, reward_per_stage, 5, 0); + + set_merkle_root(agent, operator_addr, bridge_id, 1, x"c2c9964717d099fa39ebfde03685dd0b050be59fce12231da9eae065fc8dfb93", 8_000_000); + set_merkle_root(agent, operator_addr, bridge_id, 2, x"c2c9964717d099fa39ebfde03685dd0b050be59fce12231da9eae065fc8dfb93", 8_000_000); + set_merkle_root(agent, operator_addr, bridge_id, 5, x"c2c9964717d099fa39ebfde03685dd0b050be59fce12231da9eae065fc8dfb93", 8_000_000); + + claim_reward_script(receiver, operator_addr, bridge_id, 1, score_merkle_proofs, 800_000); + claim_reward_script(receiver, operator_addr, bridge_id, 2, score_merkle_proofs, 800_000); + claim_reward_script(receiver, operator_addr, bridge_id, 5, score_merkle_proofs, 800_000); + } + + #[test(chain=@0x1, operator=@0x56ccf33c45b99546cd1da172cf6849395bbf8573, bridge=@0x99, receiver=@0x19c9b6007d21a996737ea527f46b160b0a057c37)] fun test_e2e_scene1(chain: &signer, operator: &signer, receiver: &signer, bridge: &signer) acquires RewardStore, VestingStore, OperatorStore, ModuleStore { let operator_addr = signer::address_of(operator); let vesting_period = DEFAULT_VESTING_PERIOD; - let (bridge_id) = test_setup( + let bridge_id = test_setup( chain, operator, 1, @@ -1611,11 +1795,11 @@ module initia_std::vip_reward { ); let reward_per_stage = 1_000_000_000; - let score_merkle_proofs = test_setup_merkle_scene1(chain, operator_addr, bridge_id, reward_per_stage); + let score_merkle_proofs = test_setup_merkle_scene1(chain, operator_addr, bridge_id, reward_per_stage, 0); claim_reward_script(receiver, operator_addr, bridge_id, 1, score_merkle_proofs, 800_000); assert!(coin::balance(signer::address_of(receiver), reward_metadata()) == 0, 1); - assert!(get_vesting_at_stage(signer::address_of(receiver), bridge_id, 1).initial_reward == reward_per_stage, 2); + assert!(get_vesting(signer::address_of(receiver), bridge_id, 1).initial_reward == reward_per_stage, 2); claim_reward_script(receiver, operator_addr, bridge_id, 2, score_merkle_proofs, 800_000); assert!(coin::balance(signer::address_of(receiver), reward_metadata()) == (reward_per_stage/vesting_period), 3); @@ -1646,7 +1830,7 @@ module initia_std::vip_reward { let bridge_info = get_bridge_info(bridge_id); assert!(bridge_info.reward_addr == reward_address && bridge_info.operator_addr == operator_addr - && bridge_info.vip_weight == DEFAULT_VIP_WEIGHT + && bridge_info.vip_weight == DEFAULT_VIP_WEIGHT_FOR_TEST && bridge_info.bridge_addr == signer::address_of(bridge), 7); assert!(get_stage_reward(1, 1) == reward_per_stage, 8); assert!(get_stage_reward(1, 100) == 0, 9); @@ -1657,7 +1841,7 @@ module initia_std::vip_reward { fun test_e2e_scene2(chain: &signer, agent:&signer, operator: &signer, receiver: &signer, bridge: &signer) acquires RewardStore, VestingStore, OperatorStore, ModuleStore { let operator_addr = signer::address_of(operator); let vesting_period = DEFAULT_VESTING_PERIOD; - let (bridge_id) = test_setup( + let bridge_id = test_setup( chain, operator, 1, @@ -1676,11 +1860,11 @@ module initia_std::vip_reward { update_agent(chain, signer::address_of(agent)); primary_fungible_store::transfer(chain, reward_metadata(), signer::address_of(agent), 1_000_000_000_000); - fund_reward_script(agent, reward_per_stage, 1); - fund_reward_script(agent, reward_per_stage/2, 2); - fund_reward_script(agent, reward_per_stage, 3); - fund_reward_script(agent, reward_per_stage, 4); - fund_reward_script(agent, reward_per_stage, 5); + fund_reward_script(agent, reward_per_stage, 1, 0); + fund_reward_script(agent, reward_per_stage/2, 2, 0); + fund_reward_script(agent, reward_per_stage, 3, 0); + fund_reward_script(agent, reward_per_stage, 4, 0); + fund_reward_script(agent, reward_per_stage, 5, 0); set_merkle_root(agent, operator_addr, bridge_id, 1, x"c2c9964717d099fa39ebfde03685dd0b050be59fce12231da9eae065fc8dfb93", 8_000_000); set_merkle_root(agent, operator_addr, bridge_id, 2, x"c2c9964717d099fa39ebfde03685dd0b050be59fce12231da9eae065fc8dfb93", 8_000_000); set_merkle_root(agent, operator_addr, bridge_id, 3, x"b949f287db8f4c1489df57c66034eac6948a35cfc52fdfb7638e7f6313dc15e6", 4_000_000); @@ -1689,7 +1873,7 @@ module initia_std::vip_reward { claim_reward_script(receiver, operator_addr, bridge_id, 1, score_merkle_proofs, 800_000); assert!(get_locked_reward(signer::address_of(receiver), bridge_id, 1) == reward_per_stage/portion, 1); - assert!(get_vesting_at_stage(signer::address_of(receiver), bridge_id, 1).initial_reward == reward_per_stage/portion, 2); + assert!(get_vesting(signer::address_of(receiver), bridge_id, 1).initial_reward == reward_per_stage/portion, 2); claim_reward_script(receiver, operator_addr, bridge_id, 2, score_merkle_proofs, 800_000); assert!(get_unlocked_reward(signer::address_of(receiver), bridge_id, 2, 800_000) == (reward_per_stage/vesting_period)/portion, 3); @@ -1720,7 +1904,7 @@ module initia_std::vip_reward { fun test_get_next_stage(chain: &signer, operator: &signer, operator2: &signer) acquires RewardStore, OperatorStore, ModuleStore, TestCapability { let operator_addr = signer::address_of(operator); - let (bridge_id) = test_setup( + let bridge_id = test_setup( chain, operator, 1, @@ -1729,23 +1913,24 @@ module initia_std::vip_reward { decimal256::from_string(&string::utf8(b"0")), decimal256::from_string(&string::utf8(b"1")) ); - + let release_time = 0; assert!(get_module_store().stage == 1, 1); assert!(get_next_stage(bridge_id) == 1, 2); // increase stage - fund_reward_script(chain, 100_000_000, 1); + fund_reward_script(chain, 100_000_000, 1, release_time); set_merkle_root(chain, operator_addr, bridge_id, 1, x"8888888888888888888888888888888888888888888888888888888888888888", 0); assert!(get_next_stage(bridge_id) == 2, 2); assert!(get_module_store().stage == 2, 3); // increase stage - fund_reward_script(chain, 100_000_000, 2); + fund_reward_script(chain, 100_000_000, 2, release_time); set_merkle_root(chain, operator_addr, bridge_id, 2, x"8888888888888888888888888888888888888888888888888888888888888888", 0); let cap = borrow_global(signer::address_of(chain)); let operator_addr2 = signer::address_of(operator2); let bridge_id2 = 2; + // new bridge registered test_register_bridge( chain, @@ -1759,7 +1944,7 @@ module initia_std::vip_reward { assert!(get_next_stage(bridge_id2) == 3, 4); // increase stage - fund_reward_script(chain, 100_000_000, 3); + fund_reward_script(chain, 100_000_000, 3, release_time); set_merkle_root(chain, operator_addr, bridge_id, 3, x"8888888888888888888888888888888888888888888888888888888888888888", 0); set_merkle_root(chain, operator_addr2, bridge_id2, 3, x"8888888888888888888888888888888888888888888888888888888888888888", 0); assert!(get_next_stage(bridge_id) == 4, 5); @@ -1793,6 +1978,7 @@ module initia_std::vip_reward { signer::address_of(operator), bridge_id, bridge_address, + DEFAULT_VIP_WEIGHT_FOR_TEST ); let (_burn_cap, _freeze_cap, mint_cap, stakelisted_metadata) = test_initialize_coin(chain,string::utf8(b"USDC")); @@ -1841,7 +2027,7 @@ module initia_std::vip_reward { decimal256::from_string(&string::utf8(b"0")), ); - let score_merkle_proofs = test_setup_merkle_scene1(chain, operator_addr, bridge_id, 1_000_000); + let score_merkle_proofs = test_setup_merkle_scene1(chain, operator_addr, bridge_id, 1_000_000, 0); claim_reward_script(receiver, operator_addr, bridge_id, 1, score_merkle_proofs, 800_000); let stage = 1; @@ -1898,7 +2084,7 @@ module initia_std::vip_reward { vector::push_back(&mut score_merkle_proofs, x"437b58ec38d14fca98d5dc411b2d59cb03915ccce0718f94a94952846613f3f2"); while (idx <= vesting_period ) { - fund_reward_script(chain, reward_per_stage, idx); + fund_reward_script(chain, reward_per_stage, idx, 0); set_merkle_root(chain, operator_addr, bridge_id, idx, x"c2c9964717d099fa39ebfde03685dd0b050be59fce12231da9eae065fc8dfb93", 800_000); claim_reward_script(receiver, operator_addr, bridge_id, idx, score_merkle_proofs, 800_000); diff --git a/precompile/modules/initia_stdlib/sources/vip/zapping.move b/precompile/modules/initia_stdlib/sources/vip/zapping.move index 65e375ee..742061c3 100644 --- a/precompile/modules/initia_stdlib/sources/vip/zapping.move +++ b/precompile/modules/initia_stdlib/sources/vip/zapping.move @@ -32,7 +32,7 @@ module initia_std::vip_zapping { // Constants // const ZAPPING_PREFIX: u8 = 0xf5; - const DEFAULT_LOCK_PERIOD: u64 = 60 * 60 * 24 * 7 * 52; // 52 weeks + const DEFAULT_LOCK_PERIOD: u64 = 60 * 60 * 24 * 7 * 26; // 26 weeks struct ModuleStore has key { extend_ref: ExtendRef,