Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Removed getters in stable-asset and system-staking. #1409

Merged
merged 6 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions pallets/stable-asset/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -401,11 +401,9 @@ pub mod pallet {
pub struct Pallet<T>(_);

#[pallet::storage]
#[pallet::getter(fn pool_count)]
pub type PoolCount<T: Config> = StorageValue<_, StableAssetPoolId, ValueQuery>;

#[pallet::storage]
#[pallet::getter(fn pools)]
pub type Pools<T: Config> = StorageMap<
_,
Blake2_128Concat,
Expand All @@ -420,7 +418,6 @@ pub mod pallet {
>;

#[pallet::storage]
#[pallet::getter(fn token_rate_caches)]
pub type TokenRateCaches<T: Config> = StorageDoubleMap<
_,
Twox64Concat,
Expand All @@ -431,7 +428,6 @@ pub mod pallet {
>;

#[pallet::storage]
#[pallet::getter(fn token_rate_hardcap)]
pub type TokenRateHardcap<T: Config> = StorageMap<_, Twox64Concat, T::AssetId, Permill>;

#[pallet::event]
Expand Down
40 changes: 20 additions & 20 deletions pallets/stable-asset/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.

use crate::{
mock::*, traits::StableAsset as StableAssetInterface, Error, MintResult, RedeemMultiResult,
RedeemProportionResult, RedeemSingleResult, StableAssetPoolInfo, SwapResult,
mock::*, traits::StableAsset as StableAssetInterface, Error, MintResult, PoolCount, Pools,
RedeemMultiResult, RedeemProportionResult, RedeemSingleResult, StableAssetPoolInfo, SwapResult,
};
use frame_support::{assert_noop, assert_ok};
use orml_traits::MultiCurrency;
Expand Down Expand Up @@ -60,7 +60,7 @@ fn create_pool() -> (i64, i64, i64, u64) {
#[test]
fn create_pool_successful() {
new_test_ext().execute_with(|| {
assert_eq!(StableAsset::pool_count(), 0);
assert_eq!(PoolCount::<Test>::get(), 0);
assert_ok!(StableAsset::create_pool(
RuntimeOrigin::signed(1),
1,
Expand All @@ -75,7 +75,7 @@ fn create_pool_successful() {
1000000000000000000u128,
));
assert_eq!(
StableAsset::pools(0),
Pools::<Test>::get(0),
Some(StableAssetPoolInfo {
pool_id: 0,
pool_asset: 1,
Expand Down Expand Up @@ -150,7 +150,7 @@ fn modify_a_successful() {

assert_ok!(StableAsset::modify_a(RuntimeOrigin::signed(1), 0, 100, 100));
assert_eq!(
StableAsset::pools(0),
Pools::<Test>::get(0),
Some(StableAssetPoolInfo {
pool_id: 0,
pool_asset,
Expand Down Expand Up @@ -206,7 +206,7 @@ fn mint_successful_equal_amounts() {
let amounts = vec![10000000u128, 10000000u128];
assert_ok!(StableAsset::mint(RuntimeOrigin::signed(1), 0, amounts, 0));
assert_eq!(
StableAsset::pools(0),
Pools::<Test>::get(0),
Some(StableAssetPoolInfo {
pool_id: 0,
pool_asset,
Expand Down Expand Up @@ -246,7 +246,7 @@ fn mint_successful_different_amounts() {
let amounts = vec![10000000u128, 20000000u128];
assert_ok!(StableAsset::mint(RuntimeOrigin::signed(1), 0, amounts, 0));
assert_eq!(
StableAsset::pools(0),
Pools::<Test>::get(0),
Some(StableAssetPoolInfo {
pool_id: 0,
pool_asset,
Expand Down Expand Up @@ -373,7 +373,7 @@ fn swap_successful() {
assert_ok!(StableAsset::mint(RuntimeOrigin::signed(1), 0, amounts, 0));
assert_ok!(StableAsset::swap(RuntimeOrigin::signed(1), 0, 0, 1, 5000000u128, 0, 2));
assert_eq!(
StableAsset::pools(0),
Pools::<Test>::get(0),
Some(StableAssetPoolInfo {
pool_id: 0,
pool_asset,
Expand Down Expand Up @@ -547,7 +547,7 @@ fn redeem_proportion_successful() {
vec![0u128, 0u128]
));
assert_eq!(
StableAsset::pools(0),
Pools::<Test>::get(0),
Some(StableAssetPoolInfo {
pool_id: 0,
pool_asset,
Expand Down Expand Up @@ -707,7 +707,7 @@ fn redeem_single_successful() {
2,
));
assert_eq!(
StableAsset::pools(0),
Pools::<Test>::get(0),
Some(StableAssetPoolInfo {
pool_id: 0,
pool_asset,
Expand Down Expand Up @@ -874,7 +874,7 @@ fn redeem_multi_successful() {
1100000000000000000u128,
));
assert_eq!(
StableAsset::pools(0),
Pools::<Test>::get(0),
Some(StableAssetPoolInfo {
pool_id: 0,
pool_asset,
Expand Down Expand Up @@ -992,7 +992,7 @@ fn swap_exact_success() {
assert_ok!(StableAsset::mint(RuntimeOrigin::signed(1), 0, amounts, 0));

let amount = 1000345u128;
let pool_info = StableAsset::pools(0).unwrap();
let pool_info = Pools::<Test>::get(0).unwrap();

let result = StableAsset::get_swap_amount_exact(&pool_info, 0, 1, amount).unwrap();
let result_two = StableAsset::get_swap_amount(&pool_info, 0, 1, result.dx).unwrap();
Expand Down Expand Up @@ -1028,7 +1028,7 @@ fn swap_exact_success_different_precision() {
assert_ok!(StableAsset::mint(RuntimeOrigin::signed(1), 0, amounts, 0));

let amount = 1000345u128;
let pool_info = StableAsset::pools(0).unwrap();
let pool_info = Pools::<Test>::get(0).unwrap();

let result = StableAsset::get_swap_amount_exact(&pool_info, 0, 1, amount).unwrap();
let result_two = StableAsset::get_swap_amount(&pool_info, 0, 1, result.dx).unwrap();
Expand All @@ -1049,7 +1049,7 @@ fn modify_fees_successful() {
Some(300)
));
assert_eq!(
StableAsset::pools(0),
Pools::<Test>::get(0),
Some(StableAssetPoolInfo {
pool_id: 0,
pool_asset,
Expand Down Expand Up @@ -1083,7 +1083,7 @@ fn get_mint_amount_same_as_mint() {
assert_ok!(StableAsset::mint(RuntimeOrigin::signed(1), 0, amounts.clone(), 0));
assert_ok!(<Test as crate::Config>::Assets::deposit(coin0, &swap_id, 100_000_000_000));

let pool_info = StableAsset::pools(0).unwrap();
let pool_info = Pools::<Test>::get(0).unwrap();
assert_eq!(pool_info.balances, vec![99999990000000000u128, 199999990000000000u128]);
assert_eq!(
StableAsset::get_balance_update_amount(&pool_info).unwrap().balances,
Expand Down Expand Up @@ -1132,7 +1132,7 @@ fn get_swap_amount_same_as_swap() {
assert_ok!(StableAsset::mint(RuntimeOrigin::signed(1), 0, amounts, 0));
assert_ok!(<Test as crate::Config>::Assets::deposit(coin0, &swap_id, 100_000_000_000));

let pool_info = StableAsset::pools(0).unwrap();
let pool_info = Pools::<Test>::get(0).unwrap();
assert_eq!(pool_info.balances, vec![99999990000000000u128, 199999990000000000u128]);
assert_eq!(
StableAsset::get_balance_update_amount(&pool_info).unwrap().balances,
Expand Down Expand Up @@ -1181,7 +1181,7 @@ fn get_swap_amount_exact_same_as_swap() {
assert_ok!(StableAsset::mint(RuntimeOrigin::signed(1), 0, amounts, 0));
assert_ok!(<Test as crate::Config>::Assets::deposit(coin0, &swap_id, 100_000_000_000));

let pool_info = StableAsset::pools(0).unwrap();
let pool_info = Pools::<Test>::get(0).unwrap();
assert_eq!(pool_info.balances, vec![99999990000000000u128, 199999990000000000u128]);
assert_eq!(
StableAsset::get_balance_update_amount(&pool_info).unwrap().balances,
Expand Down Expand Up @@ -1230,7 +1230,7 @@ fn get_redeem_proportion_amount_same_as_redeem_proportion() {
assert_ok!(StableAsset::mint(RuntimeOrigin::signed(1), 0, amounts, 0));
assert_ok!(<Test as crate::Config>::Assets::deposit(coin0, &swap_id, 100_000_000_000));

let pool_info = StableAsset::pools(0).unwrap();
let pool_info = Pools::<Test>::get(0).unwrap();
assert_eq!(pool_info.balances, vec![99999990000000000u128, 199999990000000000u128]);
assert_eq!(
StableAsset::get_balance_update_amount(&pool_info).unwrap().balances,
Expand Down Expand Up @@ -1285,7 +1285,7 @@ fn get_redeem_single_amount_same_as_redeem_single() {
assert_ok!(StableAsset::mint(RuntimeOrigin::signed(1), 0, amounts, 0));
assert_ok!(<Test as crate::Config>::Assets::deposit(coin0, &swap_id, 100_000_000_000));

let pool_info = StableAsset::pools(0).unwrap();
let pool_info = Pools::<Test>::get(0).unwrap();
assert_eq!(pool_info.balances, vec![99999990000000000u128, 199999990000000000u128]);
assert_eq!(
StableAsset::get_balance_update_amount(&pool_info).unwrap().balances,
Expand Down Expand Up @@ -1342,7 +1342,7 @@ fn get_redeem_multi_amount_same_as_redeem_multi() {
assert_ok!(StableAsset::mint(RuntimeOrigin::signed(1), 0, amounts, 0));
assert_ok!(<Test as crate::Config>::Assets::deposit(coin0, &swap_id, 100_000_000_000));

let pool_info = StableAsset::pools(0).unwrap();
let pool_info = Pools::<Test>::get(0).unwrap();
assert_eq!(pool_info.balances, vec![99999990000000000u128, 199999990000000000u128]);
assert_eq!(
StableAsset::get_balance_update_amount(&pool_info).unwrap().balances,
Expand Down
12 changes: 6 additions & 6 deletions pallets/stable-pool/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.
use crate::{mock::*, AssetIdOf, AtLeast64BitUnsignedOf, Error};
use bifrost_primitives::VtokenMintingOperator;
use bifrost_stable_asset::StableAssetPoolInfo;
use bifrost_stable_asset::{PoolCount, Pools, StableAssetPoolInfo};
use frame_support::{assert_noop, assert_ok, BoundedVec};
use orml_traits::MultiCurrency;
use sp_runtime::{traits::AccountIdConversion, Permill};
Expand Down Expand Up @@ -127,7 +127,7 @@ fn create_pool_successful() {
ExtBuilder::default().new_test_ext().build().execute_with(|| {
let coin0 = DOT;
let coin1 = VDOT;
assert_eq!(StableAsset::pool_count(), 0);
assert_eq!(PoolCount::<Test>::get(), 0);
assert_ok!(StablePool::create_pool(
RuntimeOrigin::root(),
vec![coin0, coin1],
Expand All @@ -141,7 +141,7 @@ fn create_pool_successful() {
1000000000000000000u128,
));
assert_eq!(
StableAsset::pools(0),
Pools::<Test>::get(0),
Some(StableAssetPoolInfo {
pool_id: 0,
pool_asset: CurrencyId::BLP(0),
Expand Down Expand Up @@ -196,7 +196,7 @@ fn mint_successful_equal_amounts() {
assert_ok!(StablePool::mint_inner(&3, 0, amounts, 0));
// assert_ok!(StableAsset::mint(RuntimeOrigin::signed(3), 0, amounts.clone(), 0));
assert_eq!(
StableAsset::pools(0),
Pools::<Test>::get(0),
Some(StableAssetPoolInfo {
pool_id: 0,
pool_asset,
Expand Down Expand Up @@ -246,7 +246,7 @@ fn swap_successful() {
assert_ok!(StableAsset::mint(RuntimeOrigin::signed(3), 0, amounts, 0));
assert_ok!(StableAsset::swap(RuntimeOrigin::signed(3), 0, 0, 1, 5000000u128, 0, 2));
assert_eq!(
StableAsset::pools(0),
Pools::<Test>::get(0),
Some(StableAssetPoolInfo {
pool_id: 0,
pool_asset,
Expand Down Expand Up @@ -339,7 +339,7 @@ fn get_swap_output_amount() {
orml_tokens::Error::<Test>::BalanceTooLow
);
assert_eq!(
StableAsset::pools(0),
Pools::<Test>::get(0),
Some(StableAssetPoolInfo {
pool_id: 0,
pool_asset,
Expand Down
13 changes: 5 additions & 8 deletions pallets/system-staking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,18 +109,15 @@ pub mod pallet {

/// Current Round Information
#[pallet::storage]
#[pallet::getter(fn round)]
pub(crate) type Round<T: Config> = StorageValue<_, RoundInfo<BlockNumberFor<T>>, OptionQuery>;

/// The tokenInfo for each currency
#[pallet::storage]
#[pallet::getter(fn token_status)]
pub(crate) type TokenStatus<T: Config> =
StorageMap<_, Twox64Concat, CurrencyIdOf<T>, TokenInfo<BalanceOf<T>>, OptionQuery>;

/// All token sets
#[pallet::storage]
#[pallet::getter(fn token_list)]
pub(crate) type TokenList<T: Config> =
StorageValue<_, BoundedVec<CurrencyIdOf<T>, T::MaxTokenLen>, ValueQuery>;

Expand Down Expand Up @@ -233,7 +230,7 @@ pub mod pallet {
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
fn on_initialize(n: BlockNumberFor<T>) -> Weight {
// Get token list
let token_list = Self::token_list();
let token_list = TokenList::<T>::get();

//Get round info, if can't find it in the storage, a new one will be created.
let mut round = if let Some(round) = <Round<T>>::get() {
Expand All @@ -255,7 +252,7 @@ pub mod pallet {
// Iterate through the token list
for i in token_list.clone().into_iter() {
// Query the token info for each token in the token list
if let Some(mut token_info) = Self::token_status(i) {
if let Some(mut token_info) = TokenStatus::<T>::get(i) {
// Check token_info.current_config != token_info.new_config
if token_info.check_config_change() {
// Update token_info.current_config , set token_info.current_config =
Expand All @@ -278,7 +275,7 @@ pub mod pallet {
// Iterate through the token list
for i in token_list.into_iter() {
// Query the token info for each token in the token list
if let Some(token_info) = Self::token_status(i) {
if let Some(token_info) = TokenStatus::<T>::get(i) {
// Current blockNumber - BlockNumber of Round Start ==
// token_info.current_config.exec_delay ===> true
if round.check_delay(n, token_info.current_config.exec_delay) {
Expand Down Expand Up @@ -370,7 +367,7 @@ pub mod pallet {

// If it is a new token, add it to the token list
if new_token {
let mut token_list = Self::token_list();
let mut token_list = TokenList::<T>::get();
token_list.try_push(token).map_err(|_| Error::<T>::ExceedMaxTokenLen)?;
<TokenList<T>>::put(token_list);
}
Expand Down Expand Up @@ -401,7 +398,7 @@ pub mod pallet {
<TokenStatus<T>>::remove(&token);

// Remove token from token list
let mut token_list = Self::token_list();
let mut token_list = TokenList::<T>::get();
token_list.retain(|&x| x != token);
<TokenList<T>>::put(token_list);

Expand Down
6 changes: 3 additions & 3 deletions pallets/system-staking/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,9 @@ fn round_info_should_correct() {
None,
));
roll_one_block();
assert_eq!(SystemStaking::round().unwrap().length, 5);
assert_eq!(SystemStaking::round().unwrap().current, 1);
assert_eq!(SystemStaking::round().unwrap().first, 1001);
assert_eq!(Round::<Runtime>::get().unwrap().length, 5);
assert_eq!(Round::<Runtime>::get().unwrap().current, 1);
assert_eq!(Round::<Runtime>::get().unwrap().first, 1001);
});
}

Expand Down