diff --git a/Cargo.lock b/Cargo.lock index 5822440cbf..0345843f39 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1217,8 +1217,10 @@ name = "bifrost-vtoken-minting" version = "0.8.0" dependencies = [ "bifrost-asset-registry", + "bifrost-runtime-common", "bifrost-slp", "cumulus-primitives-core", + "env_logger", "frame-benchmarking", "frame-support", "frame-system", diff --git a/pallets/asset-registry/src/lib.rs b/pallets/asset-registry/src/lib.rs index e2c34ae597..ba9cabd999 100644 --- a/pallets/asset-registry/src/lib.rs +++ b/pallets/asset-registry/src/lib.rs @@ -692,6 +692,12 @@ impl CurrencyIdRegister for AssetIdMaps { let vtoken_metadata = Pallet::::convert_to_vtoken_metadata(token_metadata); Pallet::::do_register_metadata(CurrencyId::VToken(token_symbol), &vtoken_metadata)?; return Ok(()); + } else if let Some(token_metadata) = + CurrencyMetadatas::::get(CurrencyId::Native(token_symbol)) + { + let vtoken_metadata = Pallet::::convert_to_vtoken_metadata(token_metadata); + Pallet::::do_register_metadata(CurrencyId::VToken(token_symbol), &vtoken_metadata)?; + return Ok(()); } else { return Err(Error::::CurrencyIdNotExists.into()); } diff --git a/pallets/vtoken-minting/Cargo.toml b/pallets/vtoken-minting/Cargo.toml index 62a1307b9d..a27b05d78b 100644 --- a/pallets/vtoken-minting/Cargo.toml +++ b/pallets/vtoken-minting/Cargo.toml @@ -34,6 +34,8 @@ sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0 sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.28" } bifrost-slp = { path = "../../pallets/slp", default-features = false } bifrost-asset-registry = { path = "../asset-registry", default-features = false } +bifrost-runtime-common = { package = "bifrost-runtime-common", path = "../../runtime/common", default-features = false } +env_logger = "0.9.0" [features] default = ["std"] @@ -47,6 +49,7 @@ std = [ "orml-traits/std", "bifrost-slp/std", "bifrost-asset-registry/std", + "bifrost-runtime-common/std", ] runtime-benchmarks = ["frame-benchmarking/runtime-benchmarks"] diff --git a/pallets/vtoken-minting/src/mock.rs b/pallets/vtoken-minting/src/mock.rs index 485e8158e6..86d2cd5e2f 100644 --- a/pallets/vtoken-minting/src/mock.rs +++ b/pallets/vtoken-minting/src/mock.rs @@ -22,6 +22,7 @@ #![allow(non_upper_case_globals)] use bifrost_asset_registry::AssetIdMaps; +use bifrost_runtime_common::{micro, milli}; use bifrost_slp::{QueryId, QueryResponseManager}; use codec::{Decode, Encode}; pub use cumulus_primitives_core::ParaId; @@ -34,7 +35,7 @@ use frame_support::{ }; use frame_system::EnsureSignedBy; use hex_literal::hex; -use node_primitives::{CurrencyId, TokenSymbol}; +use node_primitives::{CurrencyId, CurrencyIdMapping, TokenSymbol}; use sp_core::{blake2_256, H256}; use sp_runtime::{ testing::Header, @@ -57,9 +58,8 @@ 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 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); @@ -120,14 +120,14 @@ impl frame_system::Config for Runtime { } parameter_types! { - pub const GetNativeCurrencyId: CurrencyId = CurrencyId::Native(TokenSymbol::ASG); + pub const NativeCurrencyId: CurrencyId = CurrencyId::Native(TokenSymbol::BNC); } pub type AdaptedBasicCurrency = orml_currencies::BasicCurrencyAdapter; impl orml_currencies::Config for Runtime { - type GetNativeCurrencyId = GetNativeCurrencyId; + type GetNativeCurrencyId = NativeCurrencyId; type MultiCurrency = Tokens; type NativeCurrency = AdaptedBasicCurrency; type WeightInfo = (); @@ -135,6 +135,11 @@ impl orml_currencies::Config for Runtime { parameter_types! { pub const ExistentialDeposit: Balance = 1; + // pub const NativeCurrencyId: CurrencyId = CurrencyId::Native(TokenSymbol::BNC); + // pub const RelayCurrencyId: CurrencyId = CurrencyId::Token(TokenSymbol::KSM); + pub const StableCurrencyId: CurrencyId = CurrencyId::Stable(TokenSymbol::KUSD); + // pub SelfParaId: u32 = ParachainInfo::parachain_id().into(); + pub const PolkadotCurrencyId: CurrencyId = CurrencyId::Token(TokenSymbol::DOT); } impl pallet_balances::Config for Runtime { @@ -150,8 +155,22 @@ impl pallet_balances::Config for Runtime { } orml_traits::parameter_type_with_key! { - pub ExistentialDeposits: |_currency_id: CurrencyId| -> Balance { - 0 + pub ExistentialDeposits: |currency_id: CurrencyId| -> Balance { + env_logger::try_init().unwrap_or(()); + + log::debug!( + "{:?}",currency_id + ); + match currency_id { + &CurrencyId::Native(TokenSymbol::BNC) => 10 * milli::(NativeCurrencyId::get()), // 0.01 BNC + &CurrencyId::Token(TokenSymbol::KSM) => 0, + &CurrencyId::VToken(TokenSymbol::KSM) => 0, + &CurrencyId::Token(TokenSymbol::MOVR) => 1 * micro::(CurrencyId::Token(TokenSymbol::MOVR)), // MOVR has a decimals of 10e18 + &CurrencyId::VToken(TokenSymbol::MOVR) => 1 * micro::(CurrencyId::Token(TokenSymbol::MOVR)), // MOVR has a decimals of 10e18 + &CurrencyId::VToken(TokenSymbol::BNC) => 10 * milli::(NativeCurrencyId::get()), // 0.01 BNC + _ => AssetIdMaps::::get_currency_metadata(*currency_id) + .map_or(Balance::max_value(), |metatata| metatata.minimal_balance) + } }; } impl orml_tokens::Config for Runtime { @@ -311,13 +330,10 @@ impl ExtBuilder { pub fn one_hundred_for_alice_n_bob(self) -> Self { self.balances(vec![ - (ALICE, BNC, 100), - (BOB, BNC, 100), - (CHARLIE, BNC, 100), - (ALICE, DOT, 100), - (ALICE, vDOT, 400), + (ALICE, BNC, 1000000000000000000000), + (BOB, BNC, 1000000000000), (BOB, vKSM, 1000), - (BOB, KSM, 10000000000), + (BOB, KSM, 1000000000000), (BOB, MOVR, 1000000000000000000000), (CHARLIE, MOVR, 100000000000000000000000), ]) diff --git a/pallets/vtoken-minting/src/tests.rs b/pallets/vtoken-minting/src/tests.rs index 0dfd8156b7..d8cece6121 100644 --- a/pallets/vtoken-minting/src/tests.rs +++ b/pallets/vtoken-minting/src/tests.rs @@ -20,9 +20,32 @@ #![cfg(test)] +use crate::{mock::*, *}; use frame_support::{assert_noop, assert_ok, sp_runtime::Permill, BoundedVec}; -use crate::{mock::*, *}; +#[test] +fn mint_bnc() { + ExtBuilder::default().one_hundred_for_alice_n_bob().build().execute_with(|| { + assert_eq!(Tokens::total_issuance(vBNC), 0); + assert_ok!(VtokenMinting::set_minimum_mint(Origin::signed(ALICE), BNC, 200)); + pub const FEE: Permill = Permill::from_percent(5); + assert_ok!(VtokenMinting::set_fees(Origin::root(), FEE, FEE)); + assert_noop!( + VtokenMinting::mint(Some(BOB).into(), BNC, 100), + Error::::BelowMinimumMint + ); + let (entrance_account, _exit_account) = VtokenMinting::get_entrance_and_exit_accounts(); + assert_eq!(Balances::free_balance(&entrance_account), 0); + assert_ok!(VtokenMinting::mint(Some(BOB).into(), BNC, 100000000000)); + assert_eq!(VtokenMinting::token_pool(BNC), 95000000000); + assert_eq!(VtokenMinting::minimum_mint(BNC), 200); + assert_eq!(Tokens::total_issuance(vBNC), 95000000000); + + assert_eq!(Balances::free_balance(&entrance_account), 95000000000); + let fee_account: AccountId = ::FeeAccount::get(); + assert_eq!(Balances::free_balance(&fee_account), 5000000000); + }); +} #[test] fn mint() { @@ -34,18 +57,18 @@ fn mint() { VtokenMinting::mint(Some(BOB).into(), KSM, 100), Error::::BelowMinimumMint ); - assert_ok!(VtokenMinting::mint(Some(BOB).into(), KSM, 1000)); + assert_ok!(VtokenMinting::mint(Some(BOB).into(), KSM, 100000000000)); assert_ok!(VtokenMinting::mint(Some(BOB).into(), MOVR, 100000000000000000000)); assert_ok!(VtokenMinting::mint(Some(BOB).into(), MOVR, 100000000000000000000)); assert_eq!(VtokenMinting::token_pool(MOVR), 190000000000000000000); - assert_eq!(VtokenMinting::token_pool(KSM), 950); + assert_eq!(VtokenMinting::token_pool(KSM), 95000000000); assert_eq!(VtokenMinting::minimum_mint(KSM), 200); - assert_eq!(Tokens::total_issuance(vKSM), 1950); + assert_eq!(Tokens::total_issuance(vKSM), 95000001000); let (entrance_account, _exit_account) = VtokenMinting::get_entrance_and_exit_accounts(); - assert_eq!(Tokens::free_balance(KSM, &entrance_account), 950); + assert_eq!(Tokens::free_balance(KSM, &entrance_account), 95000000000); let fee_account: AccountId = ::FeeAccount::get(); - assert_eq!(Tokens::free_balance(KSM, &fee_account), 50); + assert_eq!(Tokens::free_balance(KSM, &fee_account), 5000000000); }); } diff --git a/runtime/bifrost-kusama/src/lib.rs b/runtime/bifrost-kusama/src/lib.rs index dc6f24407d..ad402cb024 100644 --- a/runtime/bifrost-kusama/src/lib.rs +++ b/runtime/bifrost-kusama/src/lib.rs @@ -1375,7 +1375,7 @@ parameter_type_with_key! { AssetIdMaps::::get_asset_metadata(AssetIds::ForeignAssetId(*foreign_asset_id)). map_or(Balance::max_value(), |metatata| metatata.minimal_balance) }, - _ => AssetIdMaps::::get_asset_metadata(AssetIds::NativeAssetId(*currency_id)) + _ => AssetIdMaps::::get_currency_metadata(*currency_id) .map_or(Balance::max_value(), |metatata| metatata.minimal_balance) } }; diff --git a/runtime/bifrost-kusama/src/migrations.rs b/runtime/bifrost-kusama/src/migrations.rs index d7cb88308f..9757e873bc 100644 --- a/runtime/bifrost-kusama/src/migrations.rs +++ b/runtime/bifrost-kusama/src/migrations.rs @@ -59,6 +59,7 @@ impl frame_support::traits::OnRuntimeUpgrade for AssetRegistryMigrati len += items.len() as Weight; // vToken + AssetIdMaps::::register_vtoken_metadata(BNC).expect("VToken register"); AssetIdMaps::::register_vtoken_metadata(KSM).expect("VToken register"); AssetIdMaps::::register_vtoken_metadata(MOVR).expect("VToken register"); // vsToken @@ -115,7 +116,7 @@ impl frame_support::traits::OnRuntimeUpgrade for AssetRegistryMigrati fn post_upgrade() -> Result<(), &'static str> { let count = bifrost_asset_registry::CurrencyMetadatas::::iter().count(); log::info!("try-runtime::post_upgrade currency_metadatas count: {:?}", count); - assert_eq!(count, 34); + assert_eq!(count, 35); Ok(()) }