diff --git a/integration-tests/src/lib.rs b/integration-tests/src/lib.rs index 31e9860b..7f904051 100644 --- a/integration-tests/src/lib.rs +++ b/integration-tests/src/lib.rs @@ -17,8 +17,9 @@ use emulated_integration_tests_common::{ }, }; use frame_support::{ - dispatch::RawOrigin, pallet_prelude::Weight, sp_runtime::traits::Dispatchable, - sp_runtime::DispatchResult, + dispatch::RawOrigin, + pallet_prelude::Weight, + sp_runtime::{traits::Dispatchable, DispatchResult}, }; use polkadot_runtime_parachains::assigner_on_demand; use pop_runtime_common::Balance; @@ -424,7 +425,8 @@ fn reserve_transfer_native_asset_from_system_para_to_para() { fn reserve_transfer_native_asset_from_para_to_system_para() { init_tracing(); - // Setup: reserve transfer from AH to Pop, so that sovereign account accurate for return transfer + // Setup: reserve transfer from AH to Pop, so that sovereign account accurate for return + // transfer let amount_to_send: Balance = ASSET_HUB_ROCOCO_ED * 1000; fund_pop_from_system_para( AssetHubRococoParaSender::get(), @@ -488,7 +490,8 @@ fn place_coretime_spot_order_from_para_to_relay() { let beneficiary: sp_runtime::AccountId32 = [1u8; 32].into(); - // Setup: reserve transfer from relay to Pop, so that sovereign account accurate for return transfer + // Setup: reserve transfer from relay to Pop, so that sovereign account accurate for return + // transfer let amount_to_send: Balance = pop_runtime::UNIT * 1000; fund_pop_from_relay(RococoRelaySender::get(), amount_to_send, beneficiary.clone()); diff --git a/pallets/api/src/fungibles/mod.rs b/pallets/api/src/fungibles/mod.rs index cd34664a..a5f49c94 100644 --- a/pallets/api/src/fungibles/mod.rs +++ b/pallets/api/src/fungibles/mod.rs @@ -91,8 +91,8 @@ pub mod pallet { #[pallet::call] impl Pallet { - /// Transfers `value` amount of tokens from the caller's account to account `to`, with additional - /// `data` in unspecified format. + /// Transfers `value` amount of tokens from the caller's account to account `to`, with + /// additional `data` in unspecified format. /// /// # Parameters /// * `id` - The ID of the asset. @@ -110,6 +110,33 @@ pub mod pallet { AssetsOf::::transfer_keep_alive(origin, id.into(), target, amount) } + /// Transfers `value` amount of tokens from the delegated account approved by the `owner` to + /// account `to`, with additional `data` in unspecified format. + /// + /// # Arguments + /// * `id` - The ID of the asset. + /// * `owner` - The account which previously approved for a transfer of at least `amount` + /// and + /// from which the asset balance will be withdrawn. + /// * `to` - The recipient account. + /// * `value` - The number of tokens to transfer. + /// + /// # Returns + /// Returns `Ok(())` if successful, or an error if the transfer fails. + #[pallet::call_index(1)] + #[pallet::weight(AssetsWeightInfo::::transfer_approved())] + pub fn transfer_from( + origin: OriginFor, + id: AssetIdOf, + owner: AccountIdOf, + target: AccountIdOf, + amount: BalanceOf, + ) -> DispatchResult { + let owner = T::Lookup::unlookup(owner); + let target = T::Lookup::unlookup(target); + Assets::::transfer_approved(origin, id.into(), owner, target, amount) + } + /// Approves an account to spend a specified number of tokens on behalf of the caller. /// /// # Parameters @@ -177,6 +204,34 @@ pub mod pallet { let spender = T::Lookup::unlookup(spender); AssetsOf::::approve_transfer(origin, id.into(), spender, value) } + + /// Decreases the allowance of a spender. + /// + /// # Arguments + /// * `id` - The ID of the asset. + /// * `spender` - The account that is allowed to spend the tokens. + /// * `value` - The number of tokens to decrease the allowance by. + /// + /// # Returns + /// Returns `Ok(())` if successful, or an error if the operation fails. + #[pallet::call_index(4)] + #[pallet::weight(T::DbWeight::get().reads(2) + AssetsWeightInfo::::cancel_approval() + AssetsWeightInfo::::approve_transfer())] + pub fn decrease_allowance( + origin: OriginFor, + id: AssetIdOf, + spender: AccountIdOf, + value: BalanceOf, + ) -> DispatchResultWithPostInfo { + let who = ensure_signed(origin.clone()) + .map_err(|e| e.with_weight(T::DbWeight::get().reads(1)))?; + let mut current_allowance = Assets::::allowance(id.clone(), &who, &spender); + let spender = T::Lookup::unlookup(spender); + let id: AssetIdParameterOf = id.into(); + + current_allowance.saturating_reduce(value); + Self::do_set_allowance(origin, id, spender, current_allowance)?; + Ok(().into()) + } } impl Pallet { @@ -188,8 +243,8 @@ pub mod pallet { AssetsOf::::total_supply(id) } - /// Returns the account balance for the specified `owner` for a given asset ID. Returns `0` if - /// the account is non-existent. + /// Returns the account balance for the specified `owner` for a given asset ID. Returns `0` + /// if the account is non-existent. /// /// # Parameters /// * `id` - The ID of the asset. @@ -236,5 +291,25 @@ pub mod pallet { pub fn token_decimals(id: AssetIdOf) -> u8 { as MetadataInspect>>::decimals(id) } + + /// Set the allowance `value` of the `spender` delegated by `origin` + pub(crate) fn do_set_allowance( + origin: OriginFor, + id: AssetIdParameterOf, + spender: AccountIdLookupOf, + value: BalanceOf, + ) -> DispatchResultWithPostInfo { + Assets::::cancel_approval(origin.clone(), id.clone(), spender.clone()).map_err( + |e| { + e.with_weight( + T::DbWeight::get().reads(2) + AssetsWeightInfo::::cancel_approval(), + ) + }, + )?; + if value > Zero::zero() { + Assets::::approve_transfer(origin, id, spender, value)?; + } + Ok(().into()) + } } } diff --git a/pallets/api/src/fungibles/tests.rs b/pallets/api/src/fungibles/tests.rs index dbfa0b34..16114a9b 100644 --- a/pallets/api/src/fungibles/tests.rs +++ b/pallets/api/src/fungibles/tests.rs @@ -1,11 +1,20 @@ use crate::mock::*; use frame_support::{ - assert_ok, + assert_noop, assert_ok, traits::fungibles::{approvals::Inspect, metadata::Inspect as MetadataInspect}, }; +use sp_runtime::{DispatchError, ModuleError}; const ASSET: u32 = 42; +fn get_dispatch_error(index: u8, error_index: u8, error_message: &'static str) -> DispatchError { + DispatchError::Module(ModuleError { + index, + error: [error_index, 0, 0, 0], + message: Some(error_message), + }) +} + #[test] fn transfer_works() { new_test_ext().execute_with(|| { @@ -18,6 +27,41 @@ fn transfer_works() { }); } +#[test] +fn transfer_from_works() { + new_test_ext().execute_with(|| { + let amount: Balance = 100 * UNIT; + // Approve CHARLIE to transfer up to `amount` to BOB + create_asset_mint_and_approve(ALICE, ASSET, ALICE, amount * 2, CHARLIE, amount / 2); + + let transferred = amount / 2; + + assert_eq!(transferred, Assets::allowance(ASSET, &ALICE, &CHARLIE)); + assert_eq!(0, Assets::allowance(ASSET, &ALICE, &BOB)); + + // Transfer `amount` from an unapproved spender + assert_noop!( + Fungibles::transfer_from(signed(BOB), ASSET, ALICE, BOB, transferred), + get_dispatch_error(1, 10, "Unapproved") + ); + + // Transfer `amount` more than the allowed allowance + assert_noop!( + Fungibles::transfer_from(signed(CHARLIE), ASSET, ALICE, BOB, amount), + get_dispatch_error(1, 10, "Unapproved") + ); + + let alice_balance_before_transfer = Assets::balance(ASSET, &ALICE); + let bob_balance_before_transfer = Assets::balance(ASSET, &BOB); + assert_ok!(Fungibles::transfer_from(signed(CHARLIE), ASSET, ALICE, BOB, transferred)); + let alice_balance_after_transfer = Assets::balance(ASSET, &ALICE); + let bob_balance_after_transfer = Assets::balance(ASSET, &BOB); + // Check that BOB receives the `amount` and ALICE `amount` is spent successfully by CHARLIE + assert_eq!(bob_balance_after_transfer, bob_balance_before_transfer + transferred); + assert_eq!(alice_balance_after_transfer, alice_balance_before_transfer - transferred); + }); +} + // Non-additive, sets new value. #[test] fn approve_works() { @@ -56,6 +100,21 @@ fn increase_allowance_works() { }); } +#[test] +fn decrease_allowance_works() { + new_test_ext().execute_with(|| { + let amount: Balance = 100 * UNIT; + create_asset_mint_and_approve(ALICE, ASSET, ALICE, amount, BOB, amount); + + assert_eq!(Assets::allowance(ASSET, &ALICE, &BOB), amount); + assert_ok!(Fungibles::decrease_allowance(signed(ALICE), ASSET, BOB, amount / 2 - 1 * UNIT)); + assert_eq!(Assets::allowance(ASSET, &ALICE, &BOB), amount / 2 + 1 * UNIT); + // Saturating if the allowance value is already zero. + assert_ok!(Fungibles::decrease_allowance(signed(ALICE), ASSET, BOB, amount)); + assert_eq!(Assets::allowance(ASSET, &ALICE, &BOB), 0); + }); +} + #[test] fn total_supply_works() { new_test_ext().execute_with(|| { diff --git a/pallets/api/src/mock.rs b/pallets/api/src/mock.rs index f5d155ef..71a38e5e 100644 --- a/pallets/api/src/mock.rs +++ b/pallets/api/src/mock.rs @@ -103,6 +103,8 @@ impl crate::fungibles::Config for Test { pub(crate) const ALICE: AccountId = 1; pub(crate) const BOB: AccountId = 2; +pub(crate) const CHARLIE: AccountId = 3; +pub(crate) const DAVE: AccountId = 4; pub(crate) const INIT_AMOUNT: Balance = 100_000_000 * UNIT; pub(crate) const UNIT: Balance = 10_000_000_000; @@ -112,7 +114,12 @@ pub(crate) fn new_test_ext() -> sp_io::TestExternalities { .expect("Frame system builds valid default genesis config"); pallet_balances::GenesisConfig:: { - balances: vec![(ALICE, INIT_AMOUNT), (BOB, INIT_AMOUNT)], + balances: vec![ + (ALICE, INIT_AMOUNT), + (BOB, INIT_AMOUNT), + (CHARLIE, INIT_AMOUNT), + (DAVE, INIT_AMOUNT), + ], } .assimilate_storage(&mut t) .expect("Pallet balances storage can be assimilated"); diff --git a/pop-api/integration-tests/src/lib.rs b/pop-api/integration-tests/src/lib.rs index ea5ccb05..1bdbe835 100644 --- a/pop-api/integration-tests/src/lib.rs +++ b/pop-api/integration-tests/src/lib.rs @@ -23,9 +23,10 @@ type Balance = u128; const ALICE: AccountId32 = AccountId32::new([1_u8; 32]); const BOB: AccountId32 = AccountId32::new([2_u8; 32]); +const CHARLIE: AccountId32 = AccountId32::new([3_u8; 32]); const DEBUG_OUTPUT: pallet_contracts::DebugInfo = pallet_contracts::DebugInfo::UnsafeDebug; // FERDIE has no initial balance. -const FERDIE: AccountId32 = AccountId32::new([3_u8; 32]); +const FERDIE: AccountId32 = AccountId32::new([99_u8; 32]); const GAS_LIMIT: Weight = Weight::from_parts(100_000_000_000, 3 * 1024 * 1024); const INIT_AMOUNT: Balance = 100_000_000 * UNIT; const INIT_VALUE: Balance = 100 * UNIT; @@ -36,7 +37,7 @@ fn new_test_ext() -> sp_io::TestExternalities { .expect("Frame system builds valid default genesis config"); pallet_balances::GenesisConfig:: { - balances: vec![(ALICE, INIT_AMOUNT), (BOB, INIT_AMOUNT)], + balances: vec![(ALICE, INIT_AMOUNT), (BOB, INIT_AMOUNT), (CHARLIE, INIT_AMOUNT)], } .assimilate_storage(&mut t) .expect("Pallet balances storage can be assimilated"); diff --git a/pop-api/integration-tests/src/local_fungibles.rs b/pop-api/integration-tests/src/local_fungibles.rs index c62f0713..a2fa502e 100644 --- a/pop-api/integration-tests/src/local_fungibles.rs +++ b/pop-api/integration-tests/src/local_fungibles.rs @@ -4,6 +4,7 @@ use pop_primitives::error::{ Error::{self, *}, TokenError::*, }; +use std::result::Result; const ASSET_ID: AssetId = 1; const CONTRACT: &str = "contracts/fungibles/target/ink/fungibles.wasm"; @@ -15,6 +16,11 @@ fn decoded(result: ExecReturnValue) -> T { } } +fn checked_decoded(result: ExecReturnValue) -> Result { + ::decode(&mut &result.data[2..]) + .map_err(|_| format!("Test failed by trying to decode `{:?}` into `T`", result).to_string()) +} + // Call total_supply contract message. fn total_supply(addr: AccountId32, asset_id: AssetId) -> Balance { let function = function_selector("total_supply"); @@ -80,6 +86,22 @@ fn transfer( result } +fn transfer_from( + addr: AccountId32, + asset_id: AssetId, + from: AccountId32, + to: AccountId32, + value: Balance, +) -> ExecReturnValue { + let function = function_selector("transfer_from"); + let data: Vec = vec![]; + let params = + [function, asset_id.encode(), from.encode(), to.encode(), value.encode(), data.encode()] + .concat(); + let result = bare_call(addr, params, 0).expect("should work"); + result +} + fn approve( addr: AccountId32, asset_id: AssetId, @@ -104,6 +126,18 @@ fn increase_allowance( result } +fn decrease_allowance( + addr: AccountId32, + asset_id: AssetId, + spender: AccountId32, + value: Balance, +) -> ExecReturnValue { + let function = function_selector("decrease_allowance"); + let params = [function, asset_id.encode(), spender.encode(), value.encode()].concat(); + let result = bare_call(addr, params, 0).expect("should work"); + result +} + // fn asset_exists(addr: AccountId32, asset_id: AssetId) -> bool { // let function = function_selector("asset_exists"); // let params = [function, asset_id.encode()].concat(); @@ -173,7 +207,7 @@ fn create_asset_mint_and_approve( mint: Balance, spender: AccountId32, approve: Balance, -) { +) -> AssetId { create_asset_and_mint_to(owner.clone(), asset_id, to.clone(), mint); assert_ok!(Assets::approve_transfer( RuntimeOrigin::signed(to.into()), @@ -181,6 +215,7 @@ fn create_asset_mint_and_approve( spender.into(), approve, )); + asset_id } // Freeze an asset. @@ -368,6 +403,53 @@ fn transfer_works() { }); } +#[test] +fn transfer_from_works() { + new_test_ext().execute_with(|| { + let _ = env_logger::try_init(); + let addr = instantiate("contracts/fungibles/target/ink/fungibles.wasm", INIT_VALUE, vec![]); + let amount: Balance = 100 * UNIT; + + // Asset does not exist. + assert_eq!( + decoded::(transfer_from(addr.clone(), 1, ALICE, BOB, amount / 2)), + Module { index: 52, error: 3 }, + ); + // Create asset with Alice as owner and mint `amount` to contract address. + let asset = create_asset_and_mint_to(ALICE, 1, ALICE, amount); + // Unapproved transfer + assert_eq!( + decoded::(transfer_from(addr.clone(), asset, ALICE, BOB, amount / 2)), + Module { index: 52, error: 10 } + ); + assert_ok!(Assets::approve_transfer( + RuntimeOrigin::signed(ALICE.into()), + asset.into(), + addr.clone().into(), + amount + 1 * UNIT, + )); + + // Asset is not live, i.e. frozen or being destroyed. + freeze_asset(ALICE, asset); + assert_eq!( + decoded::(transfer_from(addr.clone(), asset, ALICE, BOB, amount)), + Module { index: 52, error: 16 }, + ); + thaw_asset(ALICE, asset); + // Not enough balance. + assert_eq!( + decoded::(transfer_from(addr.clone(), asset, ALICE, BOB, amount + 1 * UNIT,)), + Module { index: 52, error: 0 }, + ); + // Successful transfer. + let bob_balance_before_transfer = Assets::balance(asset, &BOB); + let result = transfer_from(addr.clone(), asset, ALICE, BOB, amount / 2); + assert!(!result.did_revert(), "Contract reverted!"); + let bob_balance_after_transfer = Assets::balance(asset, &BOB); + assert_eq!(bob_balance_after_transfer, bob_balance_before_transfer + amount / 2); + }); +} + #[test] fn approve_works() { new_test_ext().execute_with(|| { @@ -457,6 +539,45 @@ fn increase_allowance_works() { }); } +#[test] +fn decrease_allowance_works() { + new_test_ext().execute_with(|| { + let _ = env_logger::try_init(); + let addr = instantiate("contracts/fungibles/target/ink/fungibles.wasm", INIT_VALUE, vec![]); + let amount: Balance = 100 * UNIT; + // Asset does not exist. + assert_eq!( + checked_decoded::(decrease_allowance(addr.clone(), 0, BOB, amount)), + Ok(Module { index: 52, error: 3 }), + ); + + // Create asset and mint to the address contract, delegate Bob to spend the `amount` + let asset = + create_asset_mint_and_approve(addr.clone(), 0, addr.clone(), amount, BOB, amount); + // Asset is not live, i.e. frozen or being destroyed. + freeze_asset(addr.clone(), asset); + assert_eq!( + decoded::(decrease_allowance(addr.clone(), asset, BOB, amount)), + Module { index: 52, error: 16 }, + ); + thaw_asset(addr.clone(), asset); + + // Successfully decrease allowance + let bob_allowance_before = Assets::allowance(asset, &addr, &BOB); + let result = decrease_allowance(addr.clone(), 0, BOB, amount / 2 - 1 * UNIT); + assert!(!result.did_revert(), "Contract reverted!"); + let bob_allowance_after = Assets::allowance(asset, &addr, &BOB); + assert_eq!(bob_allowance_before - bob_allowance_after, amount / 2 - 1 * UNIT); + + // Asset is not live, i.e. frozen or being destroyed. + start_destroy_asset(addr.clone(), asset); + assert_eq!( + decoded::(decrease_allowance(addr.clone(), asset, BOB, amount)), + Module { index: 52, error: 16 }, + ); + }); +} + /// 2. PSP-22 Metadata Interface: /// - token_name /// - token_symbol diff --git a/primitives/src/lib.rs b/primitives/src/lib.rs index a51661ea..65504a6b 100644 --- a/primitives/src/lib.rs +++ b/primitives/src/lib.rs @@ -20,12 +20,13 @@ pub mod v0 { #[allow(clippy::unnecessary_cast)] pub enum Error { /// An unknown error occurred. This variant captures any unexpected errors that the - /// contract cannot specifically handle. It is useful for cases where there are breaking - /// changes in the runtime or when an error falls outside the predefined categories. The - /// variant includes: + /// contract cannot specifically handle. It is useful for cases where there are + /// breaking changes in the runtime or when an error falls outside the predefined + /// categories. The variant includes: /// /// - `dispatch_error_index`: The index within the `DispatchError`. - /// - `error_index`: The index within the `DispatchError` variant (e.g. a `TokenError`). + /// - `error_index`: The index within the `DispatchError` variant (e.g. a + /// `TokenError`). /// - `error`: The specific error code or sub-index, providing additional context (e.g. /// `error` in `ModuleError`). Other { dispatch_error_index: u8, error_index: u8, error: u8 } = 0, @@ -48,14 +49,16 @@ pub mod v0 { Token(TokenError) = 7, /// An arithmetic error. Arithmetic(ArithmeticError) = 8, - /// The number of transactional layers has been reached, or we are not in a transactional - /// layer. + /// The number of transactional layers has been reached, or we are not in a + /// transactional layer. Transactional(TransactionalError) = 9, - /// Resources exhausted, e.g. attempt to read/write data which is too large to manipulate. + /// Resources exhausted, e.g. attempt to read/write data which is too large to + /// manipulate. Exhausted = 10, /// The state is corrupt; this is generally not going to fix itself. Corruption = 11, - /// Some resource (e.g. a preimage) is unavailable right now. This might fix itself later. + /// Some resource (e.g. a preimage) is unavailable right now. This might fix itself + /// later. Unavailable = 12, /// Root origin is not allowed. RootNotAllowed = 13, @@ -83,8 +86,8 @@ pub mod v0 { pub enum TokenError { /// Funds are unavailable. FundsUnavailable, - /// Some part of the balance gives the only provider reference to the account and thus cannot - /// be (re)moved. + /// Some part of the balance gives the only provider reference to the account and thus + /// cannot be (re)moved. OnlyProvider, /// Account cannot exist with the funds that would be given. BelowMinimum, diff --git a/runtime/devnet/src/extensions/mod.rs b/runtime/devnet/src/extensions/mod.rs index 3aed89df..4b202e3e 100644 --- a/runtime/devnet/src/extensions/mod.rs +++ b/runtime/devnet/src/extensions/mod.rs @@ -70,8 +70,8 @@ where let result = match FuncId::try_from(function_id) { Ok(function_id) => { - // Read encoded parameters from buffer and calculate weight for reading `len` bytes`. - // reference: https://github.com/paritytech/polkadot-sdk/blob/117a9433dac88d5ac00c058c9b39c511d47749d2/substrate/frame/contracts/src/wasm/runtime.rs#L267 + // Read encoded parameters from buffer and calculate weight for reading `len` + // bytes`. reference: https://github.com/paritytech/polkadot-sdk/blob/117a9433dac88d5ac00c058c9b39c511d47749d2/substrate/frame/contracts/src/wasm/runtime.rs#L267 let len = env.in_len(); env.charge_weight(contract_host_weight.return_per_byte.saturating_mul(len.into()))?; let params = env.read(len)?; @@ -205,13 +205,14 @@ enum VersionedDispatch { V0(RuntimeCall), } -// Converts a `DispatchError` to a `u32` status code based on the version of the API the contract uses. -// The contract calling the chain extension can convert the status code to the descriptive `Error`. +// Converts a `DispatchError` to a `u32` status code based on the version of the API the contract +// uses. The contract calling the chain extension can convert the status code to the descriptive +// `Error`. // // For `Error` see `pop_primitives::::error::Error`. // -// The error encoding can vary per version, allowing for flexible and backward-compatible error handling. -// As a result, contracts maintain compatibility across different versions of the runtime. +// The error encoding can vary per version, allowing for flexible and backward-compatible error +// handling. As a result, contracts maintain compatibility across different versions of the runtime. // // # Parameters // @@ -230,10 +231,11 @@ pub(crate) fn convert_to_status_code(error: DispatchError, version: u8) -> u32 { let mut encoded_error = encoded_error.try_into().expect("qed, resized to 4 bytes line above"); match version { // If an unknown variant of the `DispatchError` is detected the error needs to be converted - // into the encoded value of `Error::Other`. This conversion is performed by shifting the bytes one - // position forward (discarding the last byte as it is not used) and setting the first byte to the - // encoded value of `Other` (0u8). This ensures the error is correctly categorized as an `Other` - // variant which provides all the necessary information to debug which error occurred in the runtime. + // into the encoded value of `Error::Other`. This conversion is performed by shifting the + // bytes one position forward (discarding the last byte as it is not used) and setting the + // first byte to the encoded value of `Other` (0u8). This ensures the error is correctly + // categorized as an `Other` variant which provides all the necessary information to debug + // which error occurred in the runtime. // // Byte layout explanation: // - Byte 0: index of the variant within `Error` diff --git a/runtime/testnet/src/extensions.rs b/runtime/testnet/src/extensions.rs index a6e309f9..fc228b03 100644 --- a/runtime/testnet/src/extensions.rs +++ b/runtime/testnet/src/extensions.rs @@ -1,7 +1,7 @@ -use frame_support::traits::{Contains, OriginTrait}; use frame_support::{ dispatch::{GetDispatchInfo, RawOrigin}, pallet_prelude::*, + traits::{Contains, OriginTrait}, }; use pallet_contracts::chain_extension::{ BufInBufOutState, ChainExtension, ChargedAmount, Environment, Ext, InitState, RetVal, diff --git a/scripts/fund-dev-accounts/main.rs b/scripts/fund-dev-accounts/main.rs index 74a82b0f..8a836475 100644 --- a/scripts/fund-dev-accounts/main.rs +++ b/scripts/fund-dev-accounts/main.rs @@ -1,9 +1,8 @@ -/// As Pop Network uses the relay chain token as native, the dev accounts are not funded by default. -/// Therefore, after network launch there needs to be a reserve transfer from the relay chain -/// to the dev accounts. +/// As Pop Network uses the relay chain token as native, the dev accounts are not funded by +/// default. Therefore, after network launch there needs to be a reserve transfer from the +/// relay chain to the dev accounts. /// /// This script performs these reserve transfers to fund the dev accounts from the relay chain. -/// use subxt::{OnlineClient, PolkadotConfig}; use subxt_signer::sr25519::{dev, Keypair}; @@ -27,11 +26,9 @@ mod relay { use runtime::runtime_types::{ staging_xcm::v4::{ - asset::Fungibility::Fungible, - asset::{Asset, AssetId, Assets}, + asset::{Asset, AssetId, Assets, Fungibility::Fungible}, junction::Junction, - junctions::Junctions, - junctions::Junctions::X1, + junctions::{Junctions, Junctions::X1}, location::Location, }, xcm::{v3::WeightLimit, VersionedAssets, VersionedLocation}, @@ -81,8 +78,7 @@ mod relay { xcm::{ v3::{ junction::Junction, - junctions::Junctions, - junctions::Junctions::X1, + junctions::{Junctions, Junctions::X1}, multiasset::{ AssetId::Concrete, Fungibility::Fungible, MultiAsset as Asset, MultiAssets as Assets, diff --git a/scripts/fund-dev-accounts/paseo_interface.rs b/scripts/fund-dev-accounts/paseo_interface.rs index 5f1ff09e..f6d2e101 100644 --- a/scripts/fund-dev-accounts/paseo_interface.rs +++ b/scripts/fund-dev-accounts/paseo_interface.rs @@ -29,8 +29,7 @@ pub mod api { runtime_apis::RuntimeApi } pub mod runtime_apis { - use super::root_mod; - use super::runtime_types; + use super::{root_mod, runtime_types}; use ::subxt::ext::codec::Encode; pub struct RuntimeApi; impl RuntimeApi {} @@ -100,15 +99,13 @@ pub mod api { ] } pub mod system { - use super::root_mod; - use super::runtime_types; + use super::{root_mod, runtime_types}; #[doc = "Error for the System pallet"] pub type Error = runtime_types::frame_system::pallet::Error; #[doc = "Contains a variant per dispatchable extrinsic that this pallet has."] pub type Call = runtime_types::frame_system::pallet::Call; pub mod calls { - use super::root_mod; - use super::runtime_types; + use super::{root_mod, runtime_types}; type DispatchError = runtime_types::sp_runtime::DispatchError; pub mod types { use super::runtime_types; @@ -1210,15 +1207,13 @@ pub mod api { } } pub mod balances { - use super::root_mod; - use super::runtime_types; + use super::{root_mod, runtime_types}; #[doc = "The `Error` enum of this pallet."] pub type Error = runtime_types::pallet_balances::pallet::Error; #[doc = "Contains a variant per dispatchable extrinsic that this pallet has."] pub type Call = runtime_types::pallet_balances::pallet::Call; pub mod calls { - use super::root_mod; - use super::runtime_types; + use super::{root_mod, runtime_types}; type DispatchError = runtime_types::sp_runtime::DispatchError; pub mod types { use super::runtime_types; @@ -2485,15 +2480,13 @@ pub mod api { } } pub mod utility { - use super::root_mod; - use super::runtime_types; + use super::{root_mod, runtime_types}; #[doc = "The `Error` enum of this pallet."] pub type Error = runtime_types::pallet_utility::pallet::Error; #[doc = "Contains a variant per dispatchable extrinsic that this pallet has."] pub type Call = runtime_types::pallet_utility::pallet::Call; pub mod calls { - use super::root_mod; - use super::runtime_types; + use super::{root_mod, runtime_types}; type DispatchError = runtime_types::sp_runtime::DispatchError; pub mod types { use super::runtime_types; @@ -2891,15 +2884,13 @@ pub mod api { } } pub mod xcm_pallet { - use super::root_mod; - use super::runtime_types; + use super::{root_mod, runtime_types}; #[doc = "The `Error` enum of this pallet."] pub type Error = runtime_types::pallet_xcm::pallet::Error; #[doc = "Contains a variant per dispatchable extrinsic that this pallet has."] pub type Call = runtime_types::pallet_xcm::pallet::Call; pub mod calls { - use super::root_mod; - use super::runtime_types; + use super::{root_mod, runtime_types}; type DispatchError = runtime_types::sp_runtime::DispatchError; pub mod types { use super::runtime_types; @@ -4688,15 +4679,13 @@ pub mod api { } } pub mod sudo { - use super::root_mod; - use super::runtime_types; + use super::{root_mod, runtime_types}; #[doc = "Error for the Sudo pallet"] pub type Error = runtime_types::pallet_sudo::pallet::Error; #[doc = "Contains a variant per dispatchable extrinsic that this pallet has."] pub type Call = runtime_types::pallet_sudo::pallet::Call; pub mod calls { - use super::root_mod; - use super::runtime_types; + use super::{root_mod, runtime_types}; type DispatchError = runtime_types::sp_runtime::DispatchError; pub mod types { use super::runtime_types; diff --git a/scripts/fund-dev-accounts/pop_interface.rs b/scripts/fund-dev-accounts/pop_interface.rs index aaa0be92..f6416c2f 100644 --- a/scripts/fund-dev-accounts/pop_interface.rs +++ b/scripts/fund-dev-accounts/pop_interface.rs @@ -29,8 +29,7 @@ pub mod api { runtime_apis::RuntimeApi } pub mod runtime_apis { - use super::root_mod; - use super::runtime_types; + use super::{root_mod, runtime_types}; use ::subxt::ext::codec::Encode; pub struct RuntimeApi; impl RuntimeApi {} @@ -73,15 +72,13 @@ pub mod api { ] } pub mod system { - use super::root_mod; - use super::runtime_types; + use super::{root_mod, runtime_types}; #[doc = "Error for the System pallet"] pub type Error = runtime_types::frame_system::pallet::Error; #[doc = "Contains a variant per dispatchable extrinsic that this pallet has."] pub type Call = runtime_types::frame_system::pallet::Call; pub mod calls { - use super::root_mod; - use super::runtime_types; + use super::{root_mod, runtime_types}; type DispatchError = runtime_types::sp_runtime::DispatchError; pub mod types { use super::runtime_types; diff --git a/scripts/fund-dev-accounts/rococo_interface.rs b/scripts/fund-dev-accounts/rococo_interface.rs index 406dfcd4..54a1ad53 100644 --- a/scripts/fund-dev-accounts/rococo_interface.rs +++ b/scripts/fund-dev-accounts/rococo_interface.rs @@ -29,8 +29,7 @@ pub mod api { runtime_apis::RuntimeApi } pub mod runtime_apis { - use super::root_mod; - use super::runtime_types; + use super::{root_mod, runtime_types}; use ::subxt::ext::codec::Encode; pub struct RuntimeApi; impl RuntimeApi {} @@ -100,15 +99,13 @@ pub mod api { ] } pub mod system { - use super::root_mod; - use super::runtime_types; + use super::{root_mod, runtime_types}; #[doc = "Error for the System pallet"] pub type Error = runtime_types::frame_system::pallet::Error; #[doc = "Contains a variant per dispatchable extrinsic that this pallet has."] pub type Call = runtime_types::frame_system::pallet::Call; pub mod calls { - use super::root_mod; - use super::runtime_types; + use super::{root_mod, runtime_types}; type DispatchError = runtime_types::sp_runtime::DispatchError; pub mod types { use super::runtime_types; @@ -1377,15 +1374,13 @@ pub mod api { } } pub mod balances { - use super::root_mod; - use super::runtime_types; + use super::{root_mod, runtime_types}; #[doc = "The `Error` enum of this pallet."] pub type Error = runtime_types::pallet_balances::pallet::Error; #[doc = "Contains a variant per dispatchable extrinsic that this pallet has."] pub type Call = runtime_types::pallet_balances::pallet::Call; pub mod calls { - use super::root_mod; - use super::runtime_types; + use super::{root_mod, runtime_types}; type DispatchError = runtime_types::sp_runtime::DispatchError; pub mod types { use super::runtime_types; @@ -2706,15 +2701,13 @@ pub mod api { } } pub mod utility { - use super::root_mod; - use super::runtime_types; + use super::{root_mod, runtime_types}; #[doc = "The `Error` enum of this pallet."] pub type Error = runtime_types::pallet_utility::pallet::Error; #[doc = "Contains a variant per dispatchable extrinsic that this pallet has."] pub type Call = runtime_types::pallet_utility::pallet::Call; pub mod calls { - use super::root_mod; - use super::runtime_types; + use super::{root_mod, runtime_types}; type DispatchError = runtime_types::sp_runtime::DispatchError; pub mod types { use super::runtime_types; @@ -3112,15 +3105,13 @@ pub mod api { } } pub mod xcm_pallet { - use super::root_mod; - use super::runtime_types; + use super::{root_mod, runtime_types}; #[doc = "The `Error` enum of this pallet."] pub type Error = runtime_types::pallet_xcm::pallet::Error; #[doc = "Contains a variant per dispatchable extrinsic that this pallet has."] pub type Call = runtime_types::pallet_xcm::pallet::Call; pub mod calls { - use super::root_mod; - use super::runtime_types; + use super::{root_mod, runtime_types}; type DispatchError = runtime_types::sp_runtime::DispatchError; pub mod types { use super::runtime_types; @@ -4990,15 +4981,13 @@ pub mod api { } } pub mod sudo { - use super::root_mod; - use super::runtime_types; + use super::{root_mod, runtime_types}; #[doc = "Error for the Sudo pallet."] pub type Error = runtime_types::pallet_sudo::pallet::Error; #[doc = "Contains a variant per dispatchable extrinsic that this pallet has."] pub type Call = runtime_types::pallet_sudo::pallet::Call; pub mod calls { - use super::root_mod; - use super::runtime_types; + use super::{root_mod, runtime_types}; type DispatchError = runtime_types::sp_runtime::DispatchError; pub mod types { use super::runtime_types;