From a5eecc31bd9048b966dc51d73ab1c2cd58c1a174 Mon Sep 17 00:00:00 2001 From: Gianfranco Tasteri Date: Mon, 25 Sep 2023 13:30:57 -0300 Subject: [PATCH 1/4] added mint and burn chain extension functions --- runtime/src/lib.rs | 62 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 61 insertions(+), 1 deletion(-) diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 5341323..5da2539 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 + 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 + 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 => { From 02daf0f3e1a316c8688abcbae7cb947eec9c1176 Mon Sep 17 00:00:00 2001 From: gianfra-t <96739519+gianfra-t@users.noreply.github.com> Date: Wed, 4 Oct 2023 15:34:57 -0300 Subject: [PATCH 2/4] Update runtime/src/lib.rs comments Co-authored-by: Marcel Ebert --- runtime/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 5da2539..369ae4d 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -1064,7 +1064,7 @@ where amount, )?; }, - //mint + // mint(currency, recipient, amount) 1107 => { let ext = env.ext(); let caller = ext.caller().clone(); From 4275a1968ea7a52922bfaab60d8bdf6742e55eb1 Mon Sep 17 00:00:00 2001 From: gianfra-t <96739519+gianfra-t@users.noreply.github.com> Date: Wed, 4 Oct 2023 15:35:27 -0300 Subject: [PATCH 3/4] comments for input types on chain extensions comments for input types Co-authored-by: Marcel Ebert --- runtime/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 369ae4d..26ef664 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -1093,7 +1093,7 @@ where orml_currencies::Pallet::::deposit(currency_id, &recipient, amount)?; }, - //burn + // burn(currency, from, amount) 1108 => { let ext = env.ext(); let caller = ext.caller().clone(); From 490bfd041888d273a633adf4095e6f7c52bdb5e4 Mon Sep 17 00:00:00 2001 From: Gianfranco Tasteri Date: Wed, 4 Oct 2023 16:59:35 -0300 Subject: [PATCH 4/4] added allowed currencies xcm 1,2,3 by default to avoid setting manually in tests --- node/src/chain_spec.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) 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), + ], }, } }