diff --git a/node/src/chain_spec.rs b/node/src/chain_spec.rs index 92c4a41..b088e01 100644 --- a/node/src/chain_spec.rs +++ b/node/src/chain_spec.rs @@ -403,7 +403,13 @@ fn testnet_genesis( coin_infos_map: vec![], }, token_allowance: foucoco_standalone_runtime::TokenAllowanceConfig { - allowed_currencies: vec![CurrencyId::Native, CurrencyId::XCM(0), CurrencyId::XCM(1)], + allowed_currencies: vec![ + CurrencyId::Native, + CurrencyId::XCM(0), + CurrencyId::XCM(1), + CurrencyId::XCM(2), + CurrencyId::XCM(3), + ], }, } } diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 5341323..26ef664 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -51,6 +51,7 @@ use frame_support::{ PalletId, }; + pub use frame_system::Call as SystemCall; pub use pallet_balances::Call as BalancesCall; pub use pallet_timestamp::Call as TimestampCall; @@ -836,7 +837,8 @@ where + pallet_contracts::Config + orml_currencies::Config + orml_currencies_allowance_extension::Config - + dia_oracle::Config, + + dia_oracle::Config + + pallet_balances::Config, ::AccountId: UncheckedFrom<::Hash> + AsRef<[u8]>, { fn call(&mut self, mut env: Environment) -> Result @@ -1062,6 +1064,64 @@ where amount, )?; }, + // mint(currency, recipient, amount) + 1107 => { + let ext = env.ext(); + let caller = ext.caller().clone(); + + let mut env = env.buf_in_buf_out(); + let base_weight = + ::WeightInfo::transfer_non_native_currency(); + env.charge_weight(base_weight.saturating_add(overhead_weight))?; + + let input = env.read(256)?; + let (currency_id, recipient, amount): ( + CurrencyId, + T::AccountId, + BalanceOfForChainExt, + ) = chain_ext::decode(input) + .map_err(|_| DispatchError::Other("ChainExtension failed to decode input"))?; + + warn!("Minting token: {:?} to {:?} amount {:?}. Caller: {:?}", currency_id, recipient, amount, caller); + + ensure!( + orml_currencies_allowance_extension::Pallet::::is_allowed_currency( + currency_id, + ), + DispatchError::Other("CurrencyId is not allowed for chain extension",) + ); + + orml_currencies::Pallet::::deposit(currency_id, &recipient, amount)?; + }, + // burn(currency, from, amount) + 1108 => { + let ext = env.ext(); + let caller = ext.caller().clone(); + + let mut env = env.buf_in_buf_out(); + let base_weight = + ::WeightInfo::transfer_non_native_currency(); + env.charge_weight(base_weight.saturating_add(overhead_weight))?; + + let input = env.read(256)?; + let (currency_id, from, amount): ( + CurrencyId, + T::AccountId, + BalanceOfForChainExt, + ) = chain_ext::decode(input) + .map_err(|_| DispatchError::Other("ChainExtension failed to decode input"))?; + + warn!("Burning token: {:?} from {:?} amount {:?}. Caller: {:?}", currency_id, from, amount, caller); + + ensure!( + orml_currencies_allowance_extension::Pallet::::is_allowed_currency( + currency_id, + ), + DispatchError::Other("CurrencyId is not allowed for chain extension",) + ); + + orml_currencies::Pallet::::withdraw(currency_id, &from, amount)?; + }, // get_coin_info(blockchain, symbol) 1200 => {