Skip to content

Commit

Permalink
Currency tidying (#1135)
Browse files Browse the repository at this point in the history
* fix: 🐛 currency tidying up

* refactor: 💡 mv LDOT

* fix: 🐛 rm definition of VSBOND_KSM_2102_19_26 in mock

* fix: 🐛 use VSBOND_BNC_2001_0_8
  • Loading branch information
yooml authored Jan 9, 2024
1 parent 99891e9 commit e1f6ea0
Show file tree
Hide file tree
Showing 17 changed files with 102 additions and 117 deletions.
16 changes: 4 additions & 12 deletions pallets/farming/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#![cfg(test)]
#![allow(non_upper_case_globals)]

use bifrost_primitives::{CurrencyId, TokenSymbol};
pub use bifrost_primitives::{currency::*, CurrencyId, TokenSymbol};
use frame_support::{ord_parameter_types, parameter_types, traits::Nothing, PalletId};
use frame_system::EnsureSignedBy;
use sp_core::{ConstU32, H256};
Expand All @@ -37,16 +37,9 @@ pub type Amount = i128;
pub type Balance = u128;

pub type AccountId = AccountId32;
pub const BNC: CurrencyId = CurrencyId::Native(TokenSymbol::ASG);
pub const vBNC: CurrencyId = CurrencyId::VToken(TokenSymbol::BNC);
pub const DOT: CurrencyId = CurrencyId::Token(TokenSymbol::DOT);
pub const vDOT: CurrencyId = CurrencyId::VToken(TokenSymbol::DOT);
pub const KSM: CurrencyId = CurrencyId::Token(TokenSymbol::KSM);
pub const vsKSM: CurrencyId = CurrencyId::VSToken(TokenSymbol::KSM);
pub const ALICE: AccountId = AccountId32::new([0u8; 32]);
pub const BOB: AccountId = AccountId32::new([1u8; 32]);
pub const CHARLIE: AccountId = AccountId32::new([3u8; 32]);
pub const vsBond: CurrencyId = CurrencyId::VSBond(TokenSymbol::BNC, 2001, 0, 8);
pub const TREASURY_ACCOUNT: AccountId = AccountId32::new([9u8; 32]);

frame_support::construct_runtime!(
Expand Down Expand Up @@ -228,14 +221,13 @@ impl ExtBuilder {
(ALICE, BNC, 100),
(BOB, BNC, 100),
(CHARLIE, BNC, 1_000_000_000_000),
(CHARLIE, vBNC, 1_000_000_000_000_000),
(CHARLIE, VBNC, 1_000_000_000_000_000),
(CHARLIE, KSM, 1_000_000_000_000),
(ALICE, DOT, 100),
(ALICE, vDOT, 100),
(ALICE, VDOT, 100),
(ALICE, KSM, 3000),
(BOB, vsKSM, 100),
(BOB, VSKSM, 100),
(BOB, KSM, 10000000),
(BOB, vsBond, 100),
])
}

Expand Down
1 change: 1 addition & 0 deletions pallets/fee-share/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ std = [
"frame-system/std",
"frame-benchmarking/std",
"bifrost-primitives/std",
"orml-xtokens/std",
"orml-traits/std",
"bifrost-vtoken-minting/std",
"zenlink-protocol/std",
Expand Down
15 changes: 3 additions & 12 deletions pallets/fee-share/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#![allow(non_upper_case_globals)]

use bifrost_asset_registry::AssetIdMaps;
use bifrost_primitives::{CurrencyId, SlpxOperator, TokenSymbol};
pub use bifrost_primitives::{currency::*, CurrencyId, SlpxOperator, TokenSymbol};
use bifrost_slp::{QueryId, QueryResponseManager};
pub use cumulus_primitives_core::ParaId;
use frame_support::{
Expand Down Expand Up @@ -60,16 +60,9 @@ pub type Amount = i128;
pub type Balance = u64;

pub type AccountId = AccountId32;
pub const BNC: CurrencyId = CurrencyId::Native(TokenSymbol::ASG);
// pub const DOT: CurrencyId = CurrencyId::Token(TokenSymbol::DOT);
// pub const vDOT: CurrencyId = CurrencyId::VToken(TokenSymbol::DOT);
pub const KSM: CurrencyId = CurrencyId::Token(TokenSymbol::KSM);
pub const vKSM: CurrencyId = CurrencyId::VToken(TokenSymbol::KSM);
pub const vsKSM: CurrencyId = CurrencyId::VSToken(TokenSymbol::KSM);
pub const ALICE: AccountId = AccountId32::new([0u8; 32]);
pub const BOB: AccountId = AccountId32::new([1u8; 32]);
pub const CHARLIE: AccountId = AccountId32::new([3u8; 32]);
pub const vsBond: CurrencyId = CurrencyId::VSBond(TokenSymbol::BNC, 2001, 0, 8);
pub const TREASURY_ACCOUNT: AccountId = AccountId32::new([9u8; 32]);

frame_support::construct_runtime!(
Expand Down Expand Up @@ -538,11 +531,9 @@ impl ExtBuilder {
(BOB, BNC, 100),
(CHARLIE, BNC, 100),
(ALICE, RelayCurrencyId::get(), 10000),
(ALICE, vKSM, 10000),
(BOB, vsKSM, 100),
(ALICE, VKSM, 10000),
(BOB, KSM, 100),
(BOB, vsBond, 100),
(FeeSharePalletId::get().into_account_truncating(), vKSM, 10000),
(FeeSharePalletId::get().into_account_truncating(), VKSM, 10000),
(FeeSharePalletId::get().into_account_truncating(), KSM, 10000),
])
}
Expand Down
10 changes: 1 addition & 9 deletions pallets/lend-market/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub use super::*;
use sp_runtime::BuildStorage;

use bifrost_asset_registry::AssetIdMaps;
pub use bifrost_primitives::*;
pub use bifrost_primitives::{currency::*, *};
use frame_support::{
construct_runtime, parameter_types,
traits::{AsEnsureOriginWithArg, Everything, Nothing, SortedMembers},
Expand All @@ -33,16 +33,8 @@ use std::{
hash::{Hash, Hasher},
};

pub use bifrost_primitives::{Price, BNC, DOT, DOT_U, KSM, VBNC, VDOT, VKSM, VSKSM};

type Block = frame_system::mocking::MockBlock<Test>;

pub const LDOT: CurrencyId = CurrencyId::Token2(10);
pub const LKSM: CurrencyId = CurrencyId::Token2(11);
pub const LUSDT: CurrencyId = CurrencyId::Token2(12);
pub const PHA: CurrencyId = CurrencyId::Token2(5);
pub const VPHA: CurrencyId = CurrencyId::VToken2(5);

construct_runtime!(
pub enum Test {
System: frame_system,
Expand Down
7 changes: 2 additions & 5 deletions pallets/leverage-staking/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ pub use super::*;
use crate as leverage_staking;
use bifrost_asset_registry::AssetIdMaps;
pub use bifrost_primitives::{
AccountId, Balance, CurrencyId, CurrencyIdMapping, SlpOperator, SlpxOperator, TokenSymbol,
ASTR, BNC, DOT, DOT_TOKEN_ID, GLMR, VBNC, VDOT, *,
currency::*, AccountId, Balance, CurrencyId, CurrencyIdMapping, SlpOperator, SlpxOperator,
TokenSymbol, *,
};
use bifrost_runtime_common::milli;
use frame_support::{
Expand Down Expand Up @@ -54,9 +54,6 @@ use xcm_executor::XcmExecutor;

type Block = frame_system::mocking::MockBlock<Test>;

pub const LDOT: CurrencyId = CurrencyId::Lend(0);
pub const LVDOT: CurrencyId = CurrencyId::Lend(1);

// Configure a mock runtime to test the pallet.
frame_support::construct_runtime!(
pub enum Test{
Expand Down
1 change: 1 addition & 0 deletions pallets/leverage-staking/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#![cfg(test)]

use crate::mock::*;
use frame_support::{assert_noop, assert_ok, traits::fungibles::Inspect, BoundedVec};
Expand Down
3 changes: 0 additions & 3 deletions pallets/slp/src/primitives/phala_primitives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,10 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.

use crate::{MultiLocation, TimeUnit};
use bifrost_primitives::{CurrencyId, TokenSymbol};
use parity_scale_codec::{Decode, Encode};
use scale_info::TypeInfo;
use sp_runtime::RuntimeDebug;

pub const PHA: CurrencyId = CurrencyId::Token(TokenSymbol::PHA);

#[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug, TypeInfo)]
pub struct PhalaLedger<Balance> {
/// The delegator multilocation
Expand Down
2 changes: 1 addition & 1 deletion pallets/slp/src/tests/phala_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use crate::{
Junctions::X2,
*,
};
use bifrost_primitives::currency::VPHA;
use bifrost_primitives::currency::{PHA, VPHA};
use frame_support::{assert_noop, assert_ok, PalletId};
use polkadot_parachain_primitives::primitives::Sibling;
use sp_runtime::traits::AccountIdConversion;
Expand Down
9 changes: 4 additions & 5 deletions pallets/slpx/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@

use crate as slpx;
use bifrost_asset_registry::AssetIdMaps;
use bifrost_primitives::{
CurrencyId, CurrencyIdMapping, DoNothingExecuteXcm, SlpxOperator, TokenSymbol,
pub use bifrost_primitives::{
CurrencyId, CurrencyIdMapping, DoNothingExecuteXcm, SlpxOperator, TokenSymbol, BNC, KSM,
};
use bifrost_slp::{QueryId, QueryResponseManager};
use cumulus_primitives_core::ParaId;
Expand Down Expand Up @@ -68,7 +68,6 @@ pub type Amount = i128;
pub type BlockNumber = u64;
pub type AccountId = AccountId32;

pub const KSM: CurrencyId = CurrencyId::Token(TokenSymbol::KSM);
pub const ALICE: AccountId = AccountId32::new([1u8; 32]);
pub const BOB: AccountId = AccountId32::new([2u8; 32]);

Expand Down Expand Up @@ -163,8 +162,8 @@ impl bifrost_currencies::Config for Test {
parameter_type_with_key! {
pub ExistentialDeposits: |currency_id: CurrencyId| -> u128 {
match currency_id {
&CurrencyId::Native(TokenSymbol::BNC) => 10 * 1_000_000_000,
&CurrencyId::Token(TokenSymbol::KSM) => 10 * 1_000_000_000,
&BNC => 10 * 1_000_000_000,
&KSM => 10 * 1_000_000_000,
_=> 10 * 1_000_000_000
}
};
Expand Down
15 changes: 3 additions & 12 deletions pallets/system-maker/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#![allow(non_upper_case_globals)]

use bifrost_asset_registry::AssetIdMaps;
use bifrost_primitives::{CurrencyId, SlpxOperator, TokenSymbol};
pub use bifrost_primitives::{currency::*, CurrencyId, SlpxOperator, TokenSymbol};
use bifrost_slp::{QueryId, QueryResponseManager};
pub use cumulus_primitives_core::ParaId;
use frame_support::{
Expand Down Expand Up @@ -60,16 +60,9 @@ pub type Amount = i128;
pub type Balance = u64;

pub type AccountId = AccountId32;
pub const BNC: CurrencyId = CurrencyId::Native(TokenSymbol::ASG);
// pub const DOT: CurrencyId = CurrencyId::Token(TokenSymbol::DOT);
// pub const vDOT: CurrencyId = CurrencyId::VToken(TokenSymbol::DOT);
pub const KSM: CurrencyId = CurrencyId::Token(TokenSymbol::KSM);
pub const vKSM: CurrencyId = CurrencyId::VToken(TokenSymbol::KSM);
pub const vsKSM: CurrencyId = CurrencyId::VSToken(TokenSymbol::KSM);
pub const ALICE: AccountId = AccountId32::new([0u8; 32]);
pub const BOB: AccountId = AccountId32::new([1u8; 32]);
pub const CHARLIE: AccountId = AccountId32::new([3u8; 32]);
pub const vsBond: CurrencyId = CurrencyId::VSBond(TokenSymbol::BNC, 2001, 0, 8);
pub const TREASURY_ACCOUNT: AccountId = AccountId32::new([9u8; 32]);

frame_support::construct_runtime!(
Expand Down Expand Up @@ -545,11 +538,9 @@ impl ExtBuilder {
(BOB, BNC, 100),
(CHARLIE, BNC, 100),
(ALICE, RelayCurrencyId::get(), 10000),
(ALICE, vKSM, 10000),
(BOB, vsKSM, 100),
(ALICE, VKSM, 10000),
(BOB, KSM, 100),
(BOB, vsBond, 100),
(SystemMakerPalletId::get().into_account_truncating(), vKSM, 10000),
(SystemMakerPalletId::get().into_account_truncating(), VKSM, 10000),
(SystemMakerPalletId::get().into_account_truncating(), KSM, 10000),
])
}
Expand Down
16 changes: 8 additions & 8 deletions pallets/system-maker/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ fn on_idle() {
RuntimeOrigin::signed(ALICE),
RelayCurrencyId::get(),
Info {
vcurrency_id: vKSM,
vcurrency_id: VKSM,
annualization: 600_000u32,
granularity: 1000,
minimum_redeem: 20000
Expand All @@ -49,31 +49,31 @@ fn on_idle() {
Weight::from_parts(100000000, 0),
);
System::set_block_number(System::block_number() + 1);
assert_eq!(Tokens::free_balance(vKSM, &system_maker), 10731);
assert_eq!(Tokens::free_balance(VKSM, &system_maker), 10731);
assert_eq!(Tokens::free_balance(KSM, &zenlink_pair_account_id), 3000);
assert_eq!(Tokens::free_balance(vKSM, &zenlink_pair_account_id), 1469);
assert_eq!(Tokens::free_balance(VKSM, &zenlink_pair_account_id), 1469);
init_vtoken_minting();
SystemMaker::on_idle(<frame_system::Pallet<Runtime>>::block_number(), Weight::zero());
assert_eq!(Tokens::free_balance(vKSM, &system_maker), 10731);
assert_eq!(Tokens::free_balance(VKSM, &system_maker), 10731);
assert_ok!(SystemMaker::set_config(
RuntimeOrigin::signed(ALICE),
RelayCurrencyId::get(),
Info {
vcurrency_id: vKSM,
vcurrency_id: VKSM,
annualization: 600_000u32,
granularity: 1000,
minimum_redeem: 2000
},
));
SystemMaker::on_idle(<frame_system::Pallet<Runtime>>::block_number(), Weight::zero());
assert_eq!(Tokens::free_balance(vKSM, &system_maker), 0);
assert_eq!(Tokens::free_balance(VKSM, &system_maker), 0);
});
}

fn init_zenlink(para_id: u32) -> AccountIdOf<Runtime> {
let asset_0_currency_id: AssetId =
AssetId::try_convert_from(RelayCurrencyId::get(), para_id).unwrap();
let asset_1_currency_id: AssetId = AssetId::try_convert_from(vKSM, para_id).unwrap();
let asset_1_currency_id: AssetId = AssetId::try_convert_from(VKSM, para_id).unwrap();
// let path = vec![asset_0_currency_id, asset_1_currency_id];
assert_ok!(ZenlinkProtocol::create_pair(
RuntimeOrigin::root(),
Expand Down Expand Up @@ -105,5 +105,5 @@ fn init_vtoken_minting() {
));
assert_ok!(VtokenMinting::increase_token_pool(KSM, 1000));
assert_ok!(VtokenMinting::update_ongoing_time_unit(KSM, TimeUnit::Era(1)));
assert_ok!(VtokenMinting::set_minimum_redeem(RuntimeOrigin::signed(ALICE), vKSM, 90));
assert_ok!(VtokenMinting::set_minimum_redeem(RuntimeOrigin::signed(ALICE), VKSM, 90));
}
12 changes: 3 additions & 9 deletions pallets/system-staking/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#![allow(non_upper_case_globals)]

use bifrost_asset_registry::AssetIdMaps;
use bifrost_primitives::{CurrencyId, SlpxOperator, TokenSymbol};
pub use bifrost_primitives::{currency::*, CurrencyId, SlpxOperator, TokenSymbol};
use bifrost_slp::{QueryId, QueryResponseManager};
pub use cumulus_primitives_core::ParaId;
use cumulus_primitives_core::*;
Expand Down Expand Up @@ -53,12 +53,6 @@ pub type Amount = i128;
pub type Balance = u128;

pub type AccountId = AccountId32;
pub const BNC: CurrencyId = CurrencyId::Native(TokenSymbol::ASG);
pub const DOT: CurrencyId = CurrencyId::Token(TokenSymbol::DOT);
pub const vDOT: CurrencyId = CurrencyId::VToken(TokenSymbol::DOT);
pub const KSM: CurrencyId = CurrencyId::Token(TokenSymbol::KSM);
pub const vKSM: CurrencyId = CurrencyId::VToken(TokenSymbol::KSM);
pub const MOVR: CurrencyId = CurrencyId::Token(TokenSymbol::MOVR);
pub const ALICE: AccountId = AccountId32::new([0u8; 32]);
pub const BOB: AccountId = AccountId32::new([1u8; 32]);
pub const CHARLIE: AccountId = AccountId32::new([3u8; 32]);
Expand Down Expand Up @@ -475,9 +469,9 @@ impl ExtBuilder {
(BOB, BNC, 100),
(CHARLIE, BNC, 100),
(ALICE, DOT, 100),
(ALICE, vDOT, 400),
(ALICE, VDOT, 400),
(ALICE, KSM, 3000),
(BOB, vKSM, 1000),
(BOB, VKSM, 1000),
(BOB, KSM, 10000000000),
(BOB, MOVR, 1000000000000000000000),
])
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 @@ -132,7 +132,7 @@ fn refresh_token_info_should_work() {
));
assert_ok!(VtokenMinting::increase_token_pool(KSM, 1000));
assert_ok!(VtokenMinting::update_ongoing_time_unit(KSM, TimeUnit::Era(1)));
assert_ok!(VtokenMinting::set_minimum_redeem(RuntimeOrigin::signed(ALICE), vKSM, 10));
assert_ok!(VtokenMinting::set_minimum_redeem(RuntimeOrigin::signed(ALICE), VKSM, 10));

assert_ok!(SystemStaking::token_config(
RuntimeOrigin::root(),
Expand Down Expand Up @@ -166,7 +166,7 @@ fn round_process_token() {
));
assert_ok!(VtokenMinting::increase_token_pool(KSM, 1000));
assert_ok!(VtokenMinting::update_ongoing_time_unit(KSM, TimeUnit::Era(1)));
assert_ok!(VtokenMinting::set_minimum_redeem(RuntimeOrigin::signed(ALICE), vKSM, 10));
assert_ok!(VtokenMinting::set_minimum_redeem(RuntimeOrigin::signed(ALICE), VKSM, 10));

assert_ok!(SystemStaking::token_config(
RuntimeOrigin::root(),
Expand Down Expand Up @@ -202,7 +202,7 @@ fn round_process_token_rollback() {
));
assert_ok!(VtokenMinting::increase_token_pool(KSM, 1000));
assert_ok!(VtokenMinting::update_ongoing_time_unit(KSM, TimeUnit::Era(1)));
assert_ok!(VtokenMinting::set_minimum_redeem(RuntimeOrigin::signed(ALICE), vKSM, 10000));
assert_ok!(VtokenMinting::set_minimum_redeem(RuntimeOrigin::signed(ALICE), VKSM, 10000));

assert_ok!(SystemStaking::token_config(
RuntimeOrigin::root(),
Expand Down
18 changes: 7 additions & 11 deletions pallets/ve-minting/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@

use crate as bifrost_ve_minting;
use bifrost_asset_registry::AssetIdMaps;
use bifrost_primitives::{CurrencyId, CurrencyIdMapping, SlpxOperator, TokenSymbol};
pub use bifrost_primitives::{
currency::*, CurrencyId, CurrencyIdMapping, SlpxOperator, TokenSymbol,
};
use bifrost_runtime_common::{micro, milli};
use bifrost_slp::{QueryId, QueryResponseManager};
pub use cumulus_primitives_core::ParaId;
Expand Down Expand Up @@ -54,12 +56,6 @@ pub type Amount = i128;
pub type Balance = u128;

pub type AccountId = AccountId32;
pub const BNC: CurrencyId = CurrencyId::Native(TokenSymbol::BNC);
pub const vBNC: CurrencyId = CurrencyId::VToken(TokenSymbol::BNC);
pub const KSM: CurrencyId = CurrencyId::Token(TokenSymbol::KSM);
pub const vKSM: CurrencyId = CurrencyId::VToken(TokenSymbol::KSM);
pub const MOVR: CurrencyId = CurrencyId::Token(TokenSymbol::MOVR);
// pub const vMOVR: CurrencyId = CurrencyId::VToken(TokenSymbol::MOVR);
pub const ALICE: AccountId = AccountId32::new([0u8; 32]);
pub const BOB: AccountId = AccountId32::new([1u8; 32]);
pub const CHARLIE: AccountId = AccountId32::new([3u8; 32]);
Expand Down Expand Up @@ -470,14 +466,14 @@ impl ExtBuilder {
pub fn one_hundred_for_alice_n_bob(self) -> Self {
self.balances(vec![
(ALICE, BNC, 1_000_000_000_000),
(ALICE, vBNC, 1_000_000_000_000_000),
(ALICE, VBNC, 1_000_000_000_000_000),
(ALICE, KSM, 1_000_000_000_000),
(BOB, BNC, 1_000_000_000_000),
(BOB, vBNC, 1_000_000_000_000_000),
(BOB, vKSM, 1_000_000_000_000),
(BOB, VBNC, 1_000_000_000_000_000),
(BOB, VKSM, 1_000_000_000_000),
(BOB, MOVR, 1_000_000_000_000),
(CHARLIE, BNC, 1_000_000_000_000),
(CHARLIE, vBNC, 1_000_000_000_000_000),
(CHARLIE, VBNC, 1_000_000_000_000_000),
])
}

Expand Down
Loading

0 comments on commit e1f6ea0

Please sign in to comment.