diff --git a/pallets/slp/src/tests/kusama_tests.rs b/pallets/slp/src/tests/kusama_tests.rs index 003a0e1cf..8ca215b76 100644 --- a/pallets/slp/src/tests/kusama_tests.rs +++ b/pallets/slp/src/tests/kusama_tests.rs @@ -20,6 +20,7 @@ use crate::{mocks::mock_kusama::*, *}; use bifrost_primitives::currency::{KSM, VKSM}; +use bifrost_vtoken_minting::{OngoingTimeUnit, TokenPool}; use frame_support::{assert_ok, PalletId}; use orml_traits::MultiCurrency; use sp_runtime::traits::AccountIdConversion; @@ -140,7 +141,7 @@ fn decrease_token_pool_works() { assert_ok!(Slp::decrease_token_pool(RuntimeOrigin::signed(ALICE), KSM, 10)); // Check the value after decreasing - assert_eq!(VtokenMinting::token_pool(KSM), 90); + assert_eq!(TokenPool::::get(KSM), 90); }); } @@ -166,7 +167,7 @@ fn update_ongoing_time_unit_works() { )); // Check the value after updating. - assert_eq!(VtokenMinting::ongoing_time_unit(KSM), Some(TimeUnit::Era(9))); + assert_eq!(OngoingTimeUnit::::get(KSM), Some(TimeUnit::Era(9))); }); } diff --git a/pallets/vtoken-minting/src/lib.rs b/pallets/vtoken-minting/src/lib.rs index 599ea45f5..fe4cb7ac7 100644 --- a/pallets/vtoken-minting/src/lib.rs +++ b/pallets/vtoken-minting/src/lib.rs @@ -310,39 +310,31 @@ pub mod pallet { } #[pallet::storage] - #[pallet::getter(fn fees)] pub type Fees = StorageValue<_, (Permill, Permill), ValueQuery>; #[pallet::storage] - #[pallet::getter(fn token_pool)] pub type TokenPool = StorageMap<_, Twox64Concat, CurrencyIdOf, BalanceOf, ValueQuery>; #[pallet::storage] - #[pallet::getter(fn unlock_duration)] pub type UnlockDuration = StorageMap<_, Twox64Concat, CurrencyIdOf, TimeUnit>; #[pallet::storage] - #[pallet::getter(fn ongoing_time_unit)] pub type OngoingTimeUnit = StorageMap<_, Twox64Concat, CurrencyIdOf, TimeUnit>; #[pallet::storage] - #[pallet::getter(fn minimum_mint)] pub type MinimumMint = StorageMap<_, Twox64Concat, CurrencyIdOf, BalanceOf, ValueQuery>; #[pallet::storage] - #[pallet::getter(fn minimum_redeem)] pub type MinimumRedeem = StorageMap<_, Twox64Concat, CurrencyIdOf, BalanceOf, ValueQuery>; #[pallet::storage] - #[pallet::getter(fn token_unlock_next_id)] pub type TokenUnlockNextId = StorageMap<_, Twox64Concat, CurrencyIdOf, u32, ValueQuery>; #[pallet::storage] - #[pallet::getter(fn token_unlock_ledger)] pub type TokenUnlockLedger = StorageDoubleMap< _, Blake2_128Concat, @@ -354,7 +346,6 @@ pub mod pallet { >; #[pallet::storage] - #[pallet::getter(fn user_unlock_ledger)] pub type UserUnlockLedger = StorageDoubleMap< _, Blake2_128Concat, @@ -366,7 +357,6 @@ pub mod pallet { >; #[pallet::storage] - #[pallet::getter(fn time_unit_unlock_ledger)] pub type TimeUnitUnlockLedger = StorageDoubleMap< _, Blake2_128Concat, @@ -378,39 +368,32 @@ pub mod pallet { >; #[pallet::storage] - #[pallet::getter(fn token_to_rebond)] pub type TokenToRebond = StorageMap<_, Twox64Concat, CurrencyIdOf, BalanceOf>; #[pallet::storage] - #[pallet::getter(fn min_time_unit)] pub type MinTimeUnit = StorageMap<_, Twox64Concat, CurrencyIdOf, TimeUnit, ValueQuery>; #[pallet::storage] - #[pallet::getter(fn unlocking_total)] pub type UnlockingTotal = StorageMap<_, Twox64Concat, CurrencyIdOf, BalanceOf, ValueQuery>; #[pallet::storage] - #[pallet::getter(fn hook_iteration_limit)] pub type HookIterationLimit = StorageValue<_, u32, ValueQuery>; //【vtoken -> Blocks】, the locked blocks for each vtoken when minted in an incentive mode #[pallet::storage] - #[pallet::getter(fn get_mint_with_lock_blocks)] pub type MintWithLockBlocks = StorageMap<_, Blake2_128Concat, CurrencyId, BlockNumberFor>; //【vtoken -> incentive coefficient】,the incentive coefficient for each vtoken when minted in // an incentive mode #[pallet::storage] - #[pallet::getter(fn get_vtoken_incentive_coef)] pub type VtokenIncentiveCoef = StorageMap<_, Blake2_128Concat, CurrencyId, u128>; //【user + vtoken -> (total_locked, vec[(locked_amount, due_block_num)])】, the locked vtoken // records for each user #[pallet::storage] - #[pallet::getter(fn get_vtoken_lock_ledger)] pub type VtokenLockLedger = StorageDoubleMap< _, Blake2_128Concat, @@ -478,9 +461,9 @@ pub mod pallet { let vtoken_id = T::CurrencyIdConversion::convert_to_vtoken(token_id) .map_err(|_| Error::::NotSupportTokenType)?; let _token_amount_to_rebond = - Self::token_to_rebond(token_id).ok_or(Error::::InvalidRebondToken)?; + TokenToRebond::::get(token_id).ok_or(Error::::InvalidRebondToken)?; if let Some((user_unlock_amount, mut ledger_list)) = - Self::user_unlock_ledger(&exchanger, token_id) + UserUnlockLedger::::get(&exchanger, token_id) { ensure!(user_unlock_amount >= token_amount, Error::::NotEnoughBalanceToUnlock); let mut tmp_amount = token_amount; @@ -492,7 +475,7 @@ pub mod pallet { .iter() .map(|&index| -> Result<(UnlockId, bool), Error> { if let Some((_, unlock_amount, time_unit, _)) = - Self::token_unlock_ledger(token_id, index) + TokenUnlockLedger::::get(token_id, index) { if tmp_amount >= unlock_amount { if let Some((_, _, time_unit, _)) = @@ -646,9 +629,9 @@ pub mod pallet { let vtoken_id = T::CurrencyIdConversion::convert_to_vtoken(token_id) .map_err(|_| Error::::NotSupportTokenType)?; let _token_amount_to_rebond = - Self::token_to_rebond(token_id).ok_or(Error::::InvalidRebondToken)?; + TokenToRebond::::get(token_id).ok_or(Error::::InvalidRebondToken)?; - let unlock_amount = match Self::token_unlock_ledger(token_id, unlock_id) { + let unlock_amount = match TokenUnlockLedger::::get(token_id, unlock_id) { Some((who, unlock_amount, time_unit, _)) => { ensure!(who == exchanger, Error::::CanNotRebond); TimeUnitUnlockLedger::::mutate_exists( @@ -825,7 +808,7 @@ pub mod pallet { if TokenToRebond::::contains_key(token_id) { let token_amount_to_rebond = - Self::token_to_rebond(token_id).ok_or(Error::::InvalidRebondToken)?; + TokenToRebond::::get(token_id).ok_or(Error::::InvalidRebondToken)?; ensure!( token_amount_to_rebond == BalanceOf::::zero(), Error::::TokenToRebondNotZero @@ -1164,7 +1147,7 @@ pub mod pallet { token_id: CurrencyId, token_amount: BalanceOf, ) -> Result<(BalanceOf, BalanceOf, BalanceOf), DispatchError> { - let token_pool_amount = Self::token_pool(token_id); + let token_pool_amount = TokenPool::::get(token_id); let vtoken_total_issuance = T::MultiCurrency::total_issuance(vtoken_id); let (mint_rate, _redeem_rate) = Fees::::get(); let mint_fee = mint_rate * token_amount; @@ -1506,9 +1489,9 @@ pub mod pallet { if let Some((_total_locked, ledger_list, token_id)) = TimeUnitUnlockLedger::::get(time_unit.clone(), currency) { - for index in ledger_list.iter().take(Self::hook_iteration_limit() as usize) { + for index in ledger_list.iter().take(HookIterationLimit::::get() as usize) { if let Some((account, unlock_amount, time_unit, redeem_type)) = - Self::token_unlock_ledger(token_id, index) + TokenUnlockLedger::::get(token_id, index) { let entrance_account_balance = T::MultiCurrency::free_balance( token_id, @@ -1634,7 +1617,7 @@ pub mod pallet { redeem_fee, )?; - let token_pool_amount = Self::token_pool(token_id); + let token_pool_amount = TokenPool::::get(token_id); let vtoken_total_issuance = T::MultiCurrency::total_issuance(vtoken_id); let token_amount: BalanceOf = U256::from(vtoken_amount.saturated_into::()) .saturating_mul(token_pool_amount.saturated_into::().into()) @@ -1644,12 +1627,12 @@ pub mod pallet { .map_err(|_| Error::::CalculationOverflow)? .unique_saturated_into(); - let next_id = Self::token_unlock_next_id(token_id); + let next_id = TokenUnlockNextId::::get(token_id); match OngoingTimeUnit::::get(token_id) { Some(time_unit) => { // Calculate the time to be locked let result_time_unit = Self::add_time_unit( - Self::unlock_duration(token_id) + UnlockDuration::::get(token_id) .ok_or(Error::::UnlockDurationNotFound)?, time_unit, )?; @@ -1769,7 +1752,7 @@ pub mod pallet { vtoken_id: CurrencyIdOf, token_amount: BalanceOf, ) -> Result, DispatchError> { - let token_pool_amount = Self::token_pool(token_id); + let token_pool_amount = TokenPool::::get(token_id); let vtoken_total_issuance = T::MultiCurrency::total_issuance(vtoken_id); let value = U256::from(token_amount.saturated_into::()) @@ -1787,7 +1770,7 @@ pub mod pallet { vtoken_id: CurrencyIdOf, vtoken_amount: BalanceOf, ) -> Result, DispatchError> { - let token_pool_amount = Self::token_pool(token_id); + let token_pool_amount = TokenPool::::get(token_id); let vtoken_total_issuance = T::MultiCurrency::total_issuance(vtoken_id); let value = U256::from(vtoken_amount.saturated_into::()) @@ -1835,7 +1818,7 @@ pub mod pallet { &vtoken_id, |value| -> Result<(), Error> { // get the vtoken lock duration from VtokenIncentiveCoef - let lock_duration = Self::get_mint_with_lock_blocks(vtoken_id) + let lock_duration = MintWithLockBlocks::::get(vtoken_id) .ok_or(Error::::IncentiveLockBlocksNotSet)?; let current_block = frame_system::Pallet::::block_number(); let due_block = current_block @@ -1907,7 +1890,7 @@ pub mod pallet { let vtoken_total_issuance = T::MultiCurrency::total_issuance(vtoken_id); // get the incentive coef for the vtoken - let incentive_coef = Self::get_vtoken_incentive_coef(vtoken_id) + let incentive_coef = VtokenIncentiveCoef::::get(vtoken_id) .ok_or(Error::::IncentiveCoefNotFound)?; // calculate the incentive amount, but mind the overflow @@ -1958,7 +1941,7 @@ pub mod pallet { let vtoken_id = T::CurrencyIdConversion::convert_to_vtoken(token) .map_err(|_| Error::::NotSupportTokenType)?; - let token_pool_amount = Self::token_pool(token); + let token_pool_amount = TokenPool::::get(token); let vtoken_total_issuance = T::MultiCurrency::total_issuance(vtoken_id); let mut vtoken_amount = U256::from(amount); @@ -1981,7 +1964,7 @@ impl VtokenMintingOperator, AccountIdOf, for Pallet { fn get_token_pool(currency_id: CurrencyId) -> BalanceOf { - Self::token_pool(currency_id) + TokenPool::::get(currency_id) } fn increase_token_pool(currency_id: CurrencyId, token_amount: BalanceOf) -> DispatchResult { @@ -2013,14 +1996,14 @@ impl VtokenMintingOperator, AccountIdOf, } fn get_ongoing_time_unit(currency_id: CurrencyId) -> Option { - Self::ongoing_time_unit(currency_id) + OngoingTimeUnit::::get(currency_id) } fn get_unlock_records( currency_id: CurrencyId, time_unit: TimeUnit, ) -> Option<(BalanceOf, Vec)> { - if let Some((balance, list, _)) = Self::time_unit_unlock_ledger(&time_unit, currency_id) { + if let Some((balance, list, _)) = TimeUnitUnlockLedger::::get(&time_unit, currency_id) { Some((balance, list.into_inner())) } else { None @@ -2034,7 +2017,7 @@ impl VtokenMintingOperator, AccountIdOf, deduct_amount: BalanceOf, ) -> DispatchResult { if let Some((who, unlock_amount, time_unit, _)) = - Self::token_unlock_ledger(currency_id, index) + TokenUnlockLedger::::get(currency_id, index) { ensure!(unlock_amount >= deduct_amount, Error::::NotEnoughBalanceToUnlock); @@ -2124,7 +2107,7 @@ impl VtokenMintingOperator, AccountIdOf, currency_id: CurrencyId, index: u32, ) -> Option<(AccountIdOf, BalanceOf, TimeUnit, RedeemType>)> { - Self::token_unlock_ledger(currency_id, index) + TokenUnlockLedger::::get(currency_id, index) } fn get_astar_parachain_id() -> u32 { @@ -2203,7 +2186,7 @@ impl VtokenMintingInterface, CurrencyIdOf, BalanceO } fn get_token_pool(currency_id: CurrencyId) -> BalanceOf { - Self::token_pool(currency_id) + TokenPool::::get(currency_id) } fn get_astar_parachain_id() -> u32 { @@ -2234,7 +2217,7 @@ impl VTokenSupplyProvider, BalanceOf> for Pallet) -> Option> { if CurrencyId::is_token(&token) { - Some(Self::token_pool(token)) + Some(TokenPool::::get(token)) } else { None } diff --git a/pallets/vtoken-minting/src/tests.rs b/pallets/vtoken-minting/src/tests.rs index 9f7c4015e..20e47dac7 100644 --- a/pallets/vtoken-minting/src/tests.rs +++ b/pallets/vtoken-minting/src/tests.rs @@ -41,7 +41,7 @@ fn mint_bnc() { TimeUnit::Era(1) )); assert_ok!(VtokenMinting::increase_token_pool(BNC, 70000000000)); - // assert_eq!(VtokenMinting::token_pool(BNC), 70000000000); + // assert_eq!(TokenPool::::get(BNC), 70000000000); assert_ok!(VtokenMinting::update_ongoing_time_unit(BNC, TimeUnit::Era(1))); assert_eq!(Tokens::free_balance(VBNC, &BOB), 95000000000); assert_ok!(VtokenMinting::redeem(Some(BOB).into(), VBNC, 20000000000)); @@ -104,9 +104,9 @@ fn mint() { BoundedVec::default(), None )); - assert_eq!(VtokenMinting::token_pool(MOVR), 190000000000000000000); - assert_eq!(VtokenMinting::token_pool(KSM), 95000000000); - assert_eq!(VtokenMinting::minimum_mint(KSM), 200); + assert_eq!(TokenPool::::get(MOVR), 190000000000000000000); + assert_eq!(TokenPool::::get(KSM), 95000000000); + assert_eq!(MinimumMint::::get(KSM), 200); assert_eq!(Tokens::total_issuance(VKSM), 95000001000); let (entrance_account, _exit_account) = VtokenMinting::get_entrance_and_exit_accounts(); @@ -140,8 +140,8 @@ fn redeem() { ); assert_ok!(VtokenMinting::redeem(Some(BOB).into(), VKSM, 100)); assert_ok!(VtokenMinting::redeem(Some(BOB).into(), VKSM, 200)); - assert_eq!(VtokenMinting::token_pool(KSM), 1686); // 1000 + 980 - 98 - 196 - assert_eq!(VtokenMinting::unlocking_total(KSM), 294); // 98 + 196 + assert_eq!(TokenPool::::get(KSM), 1686); // 1000 + 980 - 98 - 196 + assert_eq!(UnlockingTotal::::get(KSM), 294); // 98 + 196 assert_ok!(VtokenMinting::set_unlock_duration( RuntimeOrigin::signed(ALICE), MOVR, @@ -163,27 +163,27 @@ fn redeem() { MOVR, TimeUnit::Round(1) )); - assert_eq!(VtokenMinting::min_time_unit(MOVR), TimeUnit::Round(1)); + assert_eq!(MinTimeUnit::::get(MOVR), TimeUnit::Round(1)); assert_ok!(VtokenMinting::set_unlocking_total(RuntimeOrigin::signed(ALICE), MOVR, 1000)); - assert_eq!(VtokenMinting::unlocking_total(MOVR), 1000); + assert_eq!(UnlockingTotal::::get(MOVR), 1000); let (entrance_account, _exit_account) = VtokenMinting::get_entrance_and_exit_accounts(); assert_eq!(Tokens::free_balance(KSM, &entrance_account), 980); let mut ledger_list_origin = BoundedVec::default(); assert_ok!(ledger_list_origin.try_push(0)); assert_ok!(ledger_list_origin.try_push(1)); assert_eq!( - VtokenMinting::user_unlock_ledger(BOB, KSM), + UserUnlockLedger::::get(BOB, KSM), Some((294, ledger_list_origin.clone())) ); assert_eq!( - VtokenMinting::token_unlock_ledger(KSM, 0), + TokenUnlockLedger::::get(KSM, 0), Some((BOB, 98, TimeUnit::Era(2), RedeemType::Native)) ); let mut ledger_list_origin2 = BoundedVec::default(); assert_ok!(ledger_list_origin2.try_push(0)); assert_ok!(ledger_list_origin2.try_push(1)); assert_eq!( - VtokenMinting::time_unit_unlock_ledger(TimeUnit::Era(2), KSM), + TimeUnitUnlockLedger::::get(TimeUnit::Era(2), KSM), Some((294, ledger_list_origin2, KSM)) ); }); @@ -210,7 +210,7 @@ fn rebond() { assert_ok!(VtokenMinting::redeem(Some(BOB).into(), VKSM, 200)); assert_ok!(VtokenMinting::redeem(Some(BOB).into(), VKSM, 100)); assert_eq!( - VtokenMinting::token_unlock_ledger(KSM, 1), + TokenUnlockLedger::::get(KSM, 1), Some((BOB, 100, TimeUnit::Era(1), RedeemType::Native)) ); assert_noop!( @@ -220,20 +220,20 @@ fn rebond() { assert_ok!(VtokenMinting::add_support_rebond_token(RuntimeOrigin::signed(ALICE), KSM)); assert_ok!(VtokenMinting::rebond(Some(BOB).into(), KSM, 200)); assert_eq!( - VtokenMinting::time_unit_unlock_ledger(TimeUnit::Era(1), KSM), + TimeUnitUnlockLedger::::get(TimeUnit::Era(1), KSM), Some((100, ledger_list_origin.clone(), KSM)) ); assert_eq!( - VtokenMinting::user_unlock_ledger(BOB, KSM), + UserUnlockLedger::::get(BOB, KSM), Some((100, ledger_list_origin2.clone())) ); assert_eq!( - VtokenMinting::token_unlock_ledger(KSM, 0), + TokenUnlockLedger::::get(KSM, 0), Some((BOB, 100, TimeUnit::Era(1), RedeemType::Native)) ); - assert_eq!(VtokenMinting::token_unlock_ledger(KSM, 1), None); - assert_eq!(VtokenMinting::token_pool(KSM), 1200); - assert_eq!(VtokenMinting::unlocking_total(KSM), 100); // 200 + 100 - 200 + assert_eq!(TokenUnlockLedger::::get(KSM, 1), None); + assert_eq!(TokenPool::::get(KSM), 1200); + assert_eq!(UnlockingTotal::::get(KSM), 100); // 200 + 100 - 200 let (entrance_account, _exit_account) = VtokenMinting::get_entrance_and_exit_accounts(); assert_eq!(Tokens::free_balance(KSM, &entrance_account), 300); }); @@ -273,10 +273,10 @@ fn movr() { VtokenMinting::on_initialize(100); VtokenMinting::on_initialize(100); VtokenMinting::on_initialize(100); - assert_eq!(VtokenMinting::min_time_unit(MOVR), TimeUnit::Round(2)); - assert_eq!(VtokenMinting::ongoing_time_unit(MOVR), Some(TimeUnit::Round(1))); + assert_eq!(MinTimeUnit::::get(MOVR), TimeUnit::Round(2)); + assert_eq!(OngoingTimeUnit::::get(MOVR), Some(TimeUnit::Round(1))); assert_eq!(Tokens::free_balance(MOVR, &BOB), 984200000000000000000); - assert_eq!(VtokenMinting::token_unlock_ledger(MOVR, 0), None); + assert_eq!(TokenUnlockLedger::::get(MOVR, 0), None); assert_ok!(VtokenMinting::mint( Some(CHARLIE).into(), MOVR, @@ -286,41 +286,41 @@ fn movr() { )); assert_ok!(VtokenMinting::redeem(Some(CHARLIE).into(), VMOVR, 20000000000000000000000)); assert_ok!(VtokenMinting::add_support_rebond_token(RuntimeOrigin::signed(ALICE), MOVR)); - assert_eq!(VtokenMinting::token_unlock_ledger(MOVR, 0), None); - assert_eq!(VtokenMinting::token_unlock_ledger(MOVR, 1), None); - assert_eq!(VtokenMinting::token_unlock_ledger(MOVR, 2), None); - assert_eq!(VtokenMinting::token_unlock_next_id(MOVR), 4); + assert_eq!(TokenUnlockLedger::::get(MOVR, 0), None); + assert_eq!(TokenUnlockLedger::::get(MOVR, 1), None); + assert_eq!(TokenUnlockLedger::::get(MOVR, 2), None); + assert_eq!(TokenUnlockNextId::::get(MOVR), 4); assert_ok!(VtokenMinting::rebond(Some(CHARLIE).into(), MOVR, 19000000000000000000000)); assert_ok!(VtokenMinting::rebond_by_unlock_id(Some(CHARLIE).into(), MOVR, 3)); - assert_eq!(VtokenMinting::unlocking_total(MOVR), 0); + assert_eq!(UnlockingTotal::::get(MOVR), 0); }); } #[test] fn hook() { ExtBuilder::default().one_hundred_for_alice_n_bob().build().execute_with(|| { - assert_eq!(VtokenMinting::min_time_unit(KSM), TimeUnit::Era(0)); + assert_eq!(MinTimeUnit::::get(KSM), TimeUnit::Era(0)); assert_ok!(VtokenMinting::update_ongoing_time_unit(KSM, TimeUnit::Era(3))); - assert_eq!(VtokenMinting::ongoing_time_unit(KSM), Some(TimeUnit::Era(3))); + assert_eq!(OngoingTimeUnit::::get(KSM), Some(TimeUnit::Era(3))); assert_ok!(VtokenMinting::set_unlock_duration( RuntimeOrigin::signed(ALICE), KSM, TimeUnit::Era(1) )); assert_ok!(VtokenMinting::set_hook_iteration_limit(RuntimeOrigin::signed(ALICE), 1)); - assert_eq!(VtokenMinting::unlock_duration(KSM), Some(TimeUnit::Era(1))); + assert_eq!(UnlockDuration::::get(KSM), Some(TimeUnit::Era(1))); VtokenMinting::on_initialize(100); VtokenMinting::on_initialize(100); VtokenMinting::on_initialize(100); VtokenMinting::on_initialize(100); VtokenMinting::on_initialize(100); - assert_eq!(VtokenMinting::min_time_unit(KSM), TimeUnit::Era(4)); + assert_eq!(MinTimeUnit::::get(KSM), TimeUnit::Era(4)); assert_ok!(VtokenMinting::increase_token_pool(KSM, 1000)); assert_ok!(VtokenMinting::mint(Some(BOB).into(), KSM, 200, BoundedVec::default(), None)); assert_ok!(VtokenMinting::mint(Some(BOB).into(), KSM, 100, BoundedVec::default(), None)); assert_ok!(VtokenMinting::redeem(Some(BOB).into(), VKSM, 200)); assert_ok!(VtokenMinting::redeem(Some(BOB).into(), VKSM, 100)); - assert_eq!(VtokenMinting::unlocking_total(KSM), 300); // 200 + 100 + assert_eq!(UnlockingTotal::::get(KSM), 300); // 200 + 100 assert_noop!( VtokenMinting::rebond(Some(BOB).into(), KSM, 100), Error::::InvalidRebondToken @@ -329,26 +329,26 @@ fn hook() { let (entrance_account, _exit_account) = VtokenMinting::get_entrance_and_exit_accounts(); assert_eq!(Tokens::free_balance(KSM, &entrance_account), 300); VtokenMinting::on_initialize(100); - assert_eq!(VtokenMinting::min_time_unit(KSM), TimeUnit::Era(4)); + assert_eq!(MinTimeUnit::::get(KSM), TimeUnit::Era(4)); VtokenMinting::on_initialize(100); - assert_eq!(VtokenMinting::token_unlock_ledger(KSM, 0), None); - assert_eq!(VtokenMinting::token_unlock_ledger(KSM, 1), None); - assert_eq!(VtokenMinting::time_unit_unlock_ledger(TimeUnit::Era(4), KSM), None); - assert_eq!(VtokenMinting::time_unit_unlock_ledger(TimeUnit::Era(5), KSM), None); - assert_eq!(VtokenMinting::user_unlock_ledger(BOB, KSM), None); - assert_eq!(VtokenMinting::token_pool(KSM), 1000); + assert_eq!(TokenUnlockLedger::::get(KSM, 0), None); + assert_eq!(TokenUnlockLedger::::get(KSM, 1), None); + assert_eq!(TimeUnitUnlockLedger::::get(TimeUnit::Era(4), KSM), None); + assert_eq!(TimeUnitUnlockLedger::::get(TimeUnit::Era(5), KSM), None); + assert_eq!(UserUnlockLedger::::get(BOB, KSM), None); + assert_eq!(TokenPool::::get(KSM), 1000); assert_eq!(Tokens::free_balance(KSM, &entrance_account), 0); assert_ok!(VtokenMinting::update_ongoing_time_unit(KSM, TimeUnit::Era(5))); VtokenMinting::on_initialize(100); VtokenMinting::on_initialize(0); VtokenMinting::on_initialize(1); - assert_eq!(VtokenMinting::min_time_unit(KSM), TimeUnit::Era(6)); - assert_eq!(VtokenMinting::unlocking_total(KSM), 0); + assert_eq!(MinTimeUnit::::get(KSM), TimeUnit::Era(6)); + assert_eq!(UnlockingTotal::::get(KSM), 0); assert_ok!(VtokenMinting::mint(Some(BOB).into(), KSM, 100, BoundedVec::default(), None)); assert_ok!(VtokenMinting::redeem(Some(BOB).into(), VKSM, 200)); VtokenMinting::on_initialize(0); assert_eq!( - VtokenMinting::token_unlock_ledger(KSM, 2), + TokenUnlockLedger::::get(KSM, 2), Some((BOB, 100, TimeUnit::Era(6), RedeemType::Native)) ); let mut ledger_list_origin = BoundedVec::default(); @@ -356,11 +356,11 @@ fn hook() { let mut ledger_list_origin2 = BoundedVec::default(); assert_ok!(ledger_list_origin2.try_push(2)); assert_eq!( - VtokenMinting::time_unit_unlock_ledger(TimeUnit::Era(6), KSM), + TimeUnitUnlockLedger::::get(TimeUnit::Era(6), KSM), Some((100, ledger_list_origin.clone(), KSM)) ); assert_eq!( - VtokenMinting::user_unlock_ledger(BOB, KSM), + UserUnlockLedger::::get(BOB, KSM), Some((100, ledger_list_origin2.clone())) ); }); @@ -384,7 +384,7 @@ fn rebond_by_unlock_id() { assert_ok!(VtokenMinting::mint(Some(BOB).into(), KSM, 100, BoundedVec::default(), None)); assert_ok!(VtokenMinting::redeem(Some(BOB).into(), VKSM, 200)); assert_ok!(VtokenMinting::redeem(Some(BOB).into(), VKSM, 100)); - assert_eq!(VtokenMinting::token_pool(KSM), 1000); + assert_eq!(TokenPool::::get(KSM), 1000); assert_noop!( VtokenMinting::rebond_by_unlock_id(Some(BOB).into(), KSM, 0), Error::::InvalidRebondToken @@ -396,20 +396,20 @@ fn rebond_by_unlock_id() { ); assert_ok!(VtokenMinting::rebond_by_unlock_id(Some(BOB).into(), KSM, 0)); assert_eq!( - VtokenMinting::time_unit_unlock_ledger(TimeUnit::Era(1), KSM), + TimeUnitUnlockLedger::::get(TimeUnit::Era(1), KSM), Some((100, ledger_list_origin.clone(), KSM)) ); assert_eq!( - VtokenMinting::user_unlock_ledger(BOB, KSM), + UserUnlockLedger::::get(BOB, KSM), Some((100, ledger_list_origin2.clone())) ); - assert_eq!(VtokenMinting::token_unlock_ledger(KSM, 0), None); + assert_eq!(TokenUnlockLedger::::get(KSM, 0), None); assert_eq!( - VtokenMinting::token_unlock_ledger(KSM, 1), + TokenUnlockLedger::::get(KSM, 1), Some((BOB, 100, TimeUnit::Era(1), RedeemType::Native)) ); - assert_eq!(VtokenMinting::token_pool(KSM), 1200); - assert_eq!(VtokenMinting::unlocking_total(KSM), 100); // 200 + 100 - 200 + assert_eq!(TokenPool::::get(KSM), 1200); + assert_eq!(UnlockingTotal::::get(KSM), 100); // 200 + 100 - 200 let (entrance_account, _exit_account) = VtokenMinting::get_entrance_and_exit_accounts(); assert_eq!(Tokens::free_balance(KSM, &entrance_account), 300); }); @@ -424,28 +424,28 @@ fn fast_redeem_for_fil() { FIL, TimeUnit::Kblock(1) )); - assert_eq!(VtokenMinting::min_time_unit(FIL), TimeUnit::Kblock(1)); + assert_eq!(MinTimeUnit::::get(FIL), TimeUnit::Kblock(1)); assert_ok!(VtokenMinting::update_ongoing_time_unit(FIL, TimeUnit::Kblock(3))); - assert_eq!(VtokenMinting::ongoing_time_unit(FIL), Some(TimeUnit::Kblock(3))); + assert_eq!(OngoingTimeUnit::::get(FIL), Some(TimeUnit::Kblock(3))); assert_ok!(VtokenMinting::set_unlock_duration( RuntimeOrigin::signed(ALICE), FIL, TimeUnit::Kblock(1) )); assert_ok!(VtokenMinting::set_hook_iteration_limit(RuntimeOrigin::signed(ALICE), 1)); - assert_eq!(VtokenMinting::unlock_duration(FIL), Some(TimeUnit::Kblock(1))); + assert_eq!(UnlockDuration::::get(FIL), Some(TimeUnit::Kblock(1))); VtokenMinting::on_initialize(100); VtokenMinting::on_initialize(100); VtokenMinting::on_initialize(100); VtokenMinting::on_initialize(100); VtokenMinting::on_initialize(100); - assert_eq!(VtokenMinting::min_time_unit(FIL), TimeUnit::Kblock(4)); + assert_eq!(MinTimeUnit::::get(FIL), TimeUnit::Kblock(4)); assert_ok!(VtokenMinting::increase_token_pool(FIL, 1000)); assert_ok!(VtokenMinting::mint(Some(BOB).into(), FIL, 200, BoundedVec::default(), None)); assert_ok!(VtokenMinting::mint(Some(BOB).into(), FIL, 100, BoundedVec::default(), None)); assert_ok!(VtokenMinting::redeem(Some(BOB).into(), VFIL, 200)); assert_ok!(VtokenMinting::redeem(Some(BOB).into(), VFIL, 100)); - assert_eq!(VtokenMinting::unlocking_total(FIL), 300); // 200 + 100 + assert_eq!(UnlockingTotal::::get(FIL), 300); // 200 + 100 assert_noop!( VtokenMinting::rebond(Some(BOB).into(), FIL, 100), Error::::InvalidRebondToken @@ -454,26 +454,26 @@ fn fast_redeem_for_fil() { let (entrance_account, _exit_account) = VtokenMinting::get_entrance_and_exit_accounts(); assert_eq!(Tokens::free_balance(FIL, &entrance_account), 300); VtokenMinting::on_initialize(100); - assert_eq!(VtokenMinting::min_time_unit(FIL), TimeUnit::Kblock(4)); + assert_eq!(MinTimeUnit::::get(FIL), TimeUnit::Kblock(4)); VtokenMinting::on_initialize(100); - assert_eq!(VtokenMinting::token_unlock_ledger(FIL, 0), None); - assert_eq!(VtokenMinting::token_unlock_ledger(FIL, 1), None); - assert_eq!(VtokenMinting::time_unit_unlock_ledger(TimeUnit::Kblock(4), FIL), None); - assert_eq!(VtokenMinting::time_unit_unlock_ledger(TimeUnit::Kblock(5), FIL), None); - assert_eq!(VtokenMinting::user_unlock_ledger(BOB, FIL), None); - assert_eq!(VtokenMinting::token_pool(FIL), 1000); + assert_eq!(TokenUnlockLedger::::get(FIL, 0), None); + assert_eq!(TokenUnlockLedger::::get(FIL, 1), None); + assert_eq!(TimeUnitUnlockLedger::::get(TimeUnit::Kblock(4), FIL), None); + assert_eq!(TimeUnitUnlockLedger::::get(TimeUnit::Kblock(5), FIL), None); + assert_eq!(UserUnlockLedger::::get(BOB, FIL), None); + assert_eq!(TokenPool::::get(FIL), 1000); assert_eq!(Tokens::free_balance(FIL, &entrance_account), 0); assert_ok!(VtokenMinting::update_ongoing_time_unit(FIL, TimeUnit::Kblock(5))); VtokenMinting::on_initialize(100); VtokenMinting::on_initialize(0); VtokenMinting::on_initialize(1); - assert_eq!(VtokenMinting::min_time_unit(FIL), TimeUnit::Kblock(6)); - assert_eq!(VtokenMinting::unlocking_total(FIL), 0); + assert_eq!(MinTimeUnit::::get(FIL), TimeUnit::Kblock(6)); + assert_eq!(UnlockingTotal::::get(FIL), 0); assert_ok!(VtokenMinting::mint(Some(BOB).into(), FIL, 100, BoundedVec::default(), None)); assert_ok!(VtokenMinting::redeem(Some(BOB).into(), VFIL, 200)); VtokenMinting::on_initialize(0); assert_eq!( - VtokenMinting::token_unlock_ledger(FIL, 2), + TokenUnlockLedger::::get(FIL, 2), Some((BOB, 100, TimeUnit::Kblock(6), RedeemType::Native)) ); let mut ledger_list_origin = BoundedVec::default(); @@ -481,11 +481,11 @@ fn fast_redeem_for_fil() { let mut ledger_list_origin2 = BoundedVec::default(); assert_ok!(ledger_list_origin2.try_push(2)); assert_eq!( - VtokenMinting::time_unit_unlock_ledger(TimeUnit::Kblock(6), FIL), + TimeUnitUnlockLedger::::get(TimeUnit::Kblock(6), FIL), Some((100, ledger_list_origin.clone(), FIL)) ); assert_eq!( - VtokenMinting::user_unlock_ledger(BOB, FIL), + UserUnlockLedger::::get(BOB, FIL), Some((100, ledger_list_origin2.clone())) ); }); @@ -498,7 +498,7 @@ fn recreate_currency_ongoing_time_unit_should_work() { // set KSM ongoing time unit to be Era(1) OngoingTimeUnit::::insert(KSM, TimeUnit::Era(1)); - assert_eq!(VtokenMinting::ongoing_time_unit(KSM), Some(TimeUnit::Era(1))); + assert_eq!(OngoingTimeUnit::::get(KSM), Some(TimeUnit::Era(1))); // recreate_currency_ongoing_time_unit the ongoing time unit of KSM to be Round(2) assert_ok!(VtokenMinting::recreate_currency_ongoing_time_unit( @@ -506,7 +506,7 @@ fn recreate_currency_ongoing_time_unit_should_work() { KSM, TimeUnit::Round(2) )); - assert_eq!(VtokenMinting::ongoing_time_unit(KSM), Some(TimeUnit::Round(2))); + assert_eq!(OngoingTimeUnit::::get(KSM), Some(TimeUnit::Round(2))); }) } @@ -595,7 +595,7 @@ fn mint_with_lock_should_work() { ); // check ledger - let lock_ledger = VtokenMinting::get_vtoken_lock_ledger(BOB, VKSM).unwrap(); + let lock_ledger = VtokenLockLedger::::get(BOB, VKSM).unwrap(); let list = BoundedVec::try_from(vec![(95000000000u128, 100u64)]).unwrap(); let should_be_ledger = (95000000000u128, list); assert_eq!(lock_ledger, should_be_ledger); @@ -637,7 +637,7 @@ fn unlock_incentive_minted_vtoken_should_work() { run_to_block(101); // check ledger - let lock_ledger = VtokenMinting::get_vtoken_lock_ledger(BOB, VKSM).unwrap(); + let lock_ledger = VtokenLockLedger::::get(BOB, VKSM).unwrap(); let list = BoundedVec::try_from(vec![(95000000000u128, 100u64)]).unwrap(); let should_be_ledger = (95000000000u128, list); assert_eq!(lock_ledger, should_be_ledger); @@ -672,7 +672,7 @@ fn unlock_incentive_minted_vtoken_should_work() { assert_eq!(new_bob_vksm_balance, bob_vksm_balance); // check ledger - let lock_ledger = VtokenMinting::get_vtoken_lock_ledger(BOB, VKSM); + let lock_ledger = VtokenLockLedger::::get(BOB, VKSM); assert_eq!(lock_ledger, None); }) } @@ -683,19 +683,19 @@ fn set_incentive_coef_should_work() { env_logger::try_init().unwrap_or(()); // get vksm coefficient should return None - assert_eq!(VtokenMinting::get_vtoken_incentive_coef(VKSM), None); + assert_eq!(VtokenIncentiveCoef::::get(VKSM), None); // set vksm coefficient assert_ok!(VtokenMinting::set_incentive_coef(RuntimeOrigin::signed(ALICE), VKSM, Some(1))); // get vksm coefficient should return Some(1) - assert_eq!(VtokenMinting::get_vtoken_incentive_coef(VKSM), Some(1)); + assert_eq!(VtokenIncentiveCoef::::get(VKSM), Some(1)); // set vksm coefficient to None assert_ok!(VtokenMinting::set_incentive_coef(RuntimeOrigin::signed(ALICE), VKSM, None)); // get vksm coefficient should return None - assert_eq!(VtokenMinting::get_vtoken_incentive_coef(VKSM), None); + assert_eq!(VtokenIncentiveCoef::::get(VKSM), None); }) } @@ -705,7 +705,7 @@ fn set_vtoken_incentive_lock_blocks_should_work() { env_logger::try_init().unwrap_or(()); // get vksm lock blocks should return None - assert_eq!(VtokenMinting::get_mint_with_lock_blocks(VKSM), None); + assert_eq!(MintWithLockBlocks::::get(VKSM), None); // set vksm lock blocks assert_ok!(VtokenMinting::set_vtoken_incentive_lock_blocks( @@ -715,7 +715,7 @@ fn set_vtoken_incentive_lock_blocks_should_work() { )); // get vksm lock blocks should return Some(100) - assert_eq!(VtokenMinting::get_mint_with_lock_blocks(VKSM), Some(100)); + assert_eq!(MintWithLockBlocks::::get(VKSM), Some(100)); // set vksm lock blocks to None assert_ok!(VtokenMinting::set_vtoken_incentive_lock_blocks( @@ -725,6 +725,6 @@ fn set_vtoken_incentive_lock_blocks_should_work() { )); // get vksm lock blocks should return None - assert_eq!(VtokenMinting::get_mint_with_lock_blocks(VKSM), None); + assert_eq!(MintWithLockBlocks::::get(VKSM), None); }) }