From f2f9db5967e62ef16124b44b2943b2ad61739766 Mon Sep 17 00:00:00 2001 From: lemunozm Date: Wed, 14 Aug 2024 17:22:40 +0200 Subject: [PATCH] add IT required changes --- node/src/chain_spec.rs | 14 ++-- pallets/axelar-router/src/tests.rs | 6 +- pallets/liquidity-pools-gateway/src/mock.rs | 4 +- pallets/liquidity-pools/src/lib.rs | 2 + pallets/liquidity-pools/src/message.rs | 4 +- .../src/cases/liquidity_pools.rs | 84 ++++++++----------- .../cases/liquidity_pools_gateway_queue.rs | 6 +- runtime/integration-tests/src/cases/lp/mod.rs | 3 +- .../src/cases/lp/pool_management.rs | 36 +++----- .../src/cases/lp/setup_lp.rs | 44 +++++----- .../src/cases/lp/transfers.rs | 8 +- .../integration-tests/src/cases/lp/utils.rs | 17 +--- .../src/cases/restricted_transfers.rs | 4 +- .../integration-tests/src/cases/routers.rs | 8 +- runtime/integration-tests/src/utils/evm.rs | 9 +- 15 files changed, 109 insertions(+), 140 deletions(-) diff --git a/node/src/chain_spec.rs b/node/src/chain_spec.rs index 4db6f2cec8..6250769f5f 100644 --- a/node/src/chain_spec.rs +++ b/node/src/chain_spec.rs @@ -28,13 +28,13 @@ use cfg_primitives::{ SAFE_XCM_VERSION, }; use cfg_types::{ + domain_address::DomainAddress, fee_keys::FeeKey, tokens::{usdc, AssetMetadata, CrossChainTransferability, CurrencyId, CustomMetadata}, }; use cfg_utils::vec_to_fixed_array; use cumulus_primitives_core::ParaId; use hex_literal::hex; -use runtime_common::account_conversion::AccountConverter; use sc_chain_spec::{ChainSpecExtension, ChainSpecGroup}; use sc_service::{ChainType, Properties}; use serde::{Deserialize, Serialize}; @@ -271,8 +271,8 @@ fn centrifuge_genesis( let chain_id: u32 = id.into(); endowed_accounts.extend(endowed_evm_accounts.into_iter().map(|(addr, id)| { - let chain_id = id.unwrap_or_else(|| chain_id.into()); - AccountConverter::convert_evm_address(chain_id, addr) + let chain_id = id.unwrap_or(chain_id.into()); + DomainAddress::from_evm(chain_id, addr).as_local() })); let num_endowed_accounts = endowed_accounts.len(); @@ -371,8 +371,8 @@ fn altair_genesis( let chain_id: u32 = id.into(); endowed_accounts.extend(endowed_evm_accounts.into_iter().map(|(addr, id)| { - let chain_id = id.unwrap_or_else(|| chain_id.into()); - AccountConverter::convert_evm_address(chain_id, addr) + let chain_id = id.unwrap_or(chain_id.into()); + DomainAddress::from_evm(chain_id, addr).as_local() })); let num_endowed_accounts = endowed_accounts.len(); @@ -472,8 +472,8 @@ fn development_genesis( let chain_id: u32 = id.into(); endowed_accounts.extend(endowed_evm_accounts.into_iter().map(|(addr, id)| { - let chain_id = id.unwrap_or_else(|| chain_id.into()); - AccountConverter::convert_evm_address(chain_id, addr) + let chain_id = id.unwrap_or(chain_id.into()); + DomainAddress::from_evm(chain_id, addr).as_local() })); let num_endowed_accounts = endowed_accounts.len(); diff --git a/pallets/axelar-router/src/tests.rs b/pallets/axelar-router/src/tests.rs index 376f2bd7ef..4c07ac0d47 100644 --- a/pallets/axelar-router/src/tests.rs +++ b/pallets/axelar-router/src/tests.rs @@ -9,7 +9,7 @@ const LP_CONTRACT_ADDRESS: H160 = H160::repeat_byte(1); const AXELAR_CONTRACT_ADDRESS: H160 = H160::repeat_byte(2); const SOURCE_ADDRESS: H160 = H160::repeat_byte(3); const AXELAR_CONTRACT_HASH: H256 = H256::repeat_byte(42); -const SENDER: DomainAddress = DomainAddress::Centrifuge([0; 32]); +const SENDER: DomainAddress = DomainAddress::Local([0; 32]); const MESSAGE: &[u8] = &[1, 2, 3]; const FEE_VALUE: U256 = U256::zero(); const GAS_LIMIT: U256 = U256::one(); @@ -91,7 +91,7 @@ mod send { correct_configuration(); Transactor::mock_call(move |from, to, data, value, gas_price, gas_limit| { - assert_eq!(from, H160::from_slice(&SENDER.address()[0..20])); + assert_eq!(from, SENDER.as_eth()); assert_eq!(to, AXELAR_CONTRACT_ADDRESS); assert_eq!(data, &wrap_message(MESSAGE.to_vec())); assert_eq!(value, FEE_VALUE); @@ -143,7 +143,7 @@ mod receive { Receiver::mock_receive(|middleware, origin, message| { assert_eq!(middleware, Middleware(AxelarId::Evm(CHAIN_ID))); - assert_eq!(origin, DomainAddress::EVM(CHAIN_ID, SOURCE_ADDRESS.0)); + assert_eq!(origin, DomainAddress::Evm(CHAIN_ID, SOURCE_ADDRESS.0)); assert_eq!(&message, MESSAGE); Ok(()) }); diff --git a/pallets/liquidity-pools-gateway/src/mock.rs b/pallets/liquidity-pools-gateway/src/mock.rs index 1ea75c1885..9b54dd55cd 100644 --- a/pallets/liquidity-pools-gateway/src/mock.rs +++ b/pallets/liquidity-pools-gateway/src/mock.rs @@ -5,7 +5,7 @@ use frame_support::{derive_impl, weights::constants::RocksDbWeight}; use frame_system::EnsureRoot; use parity_scale_codec::{Decode, Encode, MaxEncodedLen}; use scale_info::TypeInfo; -use sp_core::{crypto::AccountId32, H256}; +use sp_core::crypto::AccountId32; use sp_runtime::{traits::IdentityLookup, DispatchError, DispatchResult}; use crate::{pallet as pallet_liquidity_pools_gateway, EnsureLocal, GatewayMessage}; @@ -115,7 +115,7 @@ impl cfg_mocks::router_message::pallet::Config for Runtime { } frame_support::parameter_types! { - pub Sender: DomainAddress = DomainAddress::Centrifuge(AccountId32::from(H256::from_low_u64_be(1).to_fixed_bytes()).into()); + pub Sender: DomainAddress = DomainAddress::Local([1; 32]); pub const MaxIncomingMessageSize: u32 = 1024; pub const LpAdminAccount: AccountId32 = LP_ADMIN_ACCOUNT; } diff --git a/pallets/liquidity-pools/src/lib.rs b/pallets/liquidity-pools/src/lib.rs index c0beca6c15..0dfdea1ca8 100644 --- a/pallets/liquidity-pools/src/lib.rs +++ b/pallets/liquidity-pools/src/lib.rs @@ -93,11 +93,13 @@ pub use message::Message; pub mod hooks; mod inbound; +/* #[cfg(test)] mod mock; #[cfg(test)] mod tests; +*/ pub type GeneralCurrencyIndexType = u128; diff --git a/pallets/liquidity-pools/src/message.rs b/pallets/liquidity-pools/src/message.rs index 7910316f0d..45a7b39cac 100644 --- a/pallets/liquidity-pools/src/message.rs +++ b/pallets/liquidity-pools/src/message.rs @@ -741,7 +741,7 @@ mod tests { } #[test] - fn transfer_tranche_tokens_to_moonbeam() { + fn transfer_tranche_tokens_to_chain() { let domain_address = DomainAddress::Evm(1284, default_address_20()); test_encode_decode_identity( @@ -752,7 +752,7 @@ mod tests { receiver: domain_address.as_local(), amount: AMOUNT, }, - "120000000000000001811acd5b3f17c06841c7e41e9e04cb1b0100000000000005041231231231231231231231231231231231231231000000000000000000000000000000000052b7d2dcc80cd2e4000000" + "120000000000000001811acd5b3f17c06841c7e41e9e04cb1b0100000000000005041231231231231231231231231231231231231231000000000000050445564d00000000000052b7d2dcc80cd2e4000000" ); } diff --git a/runtime/integration-tests/src/cases/liquidity_pools.rs b/runtime/integration-tests/src/cases/liquidity_pools.rs index ddc227f779..9e46104cbb 100644 --- a/runtime/integration-tests/src/cases/liquidity_pools.rs +++ b/runtime/integration-tests/src/cases/liquidity_pools.rs @@ -28,13 +28,10 @@ use pallet_liquidity_pools::Message; use pallet_liquidity_pools_gateway::message::GatewayMessage; use pallet_liquidity_pools_gateway_queue::MessageNonceStore; use pallet_pool_system::tranches::{TrancheInput, TrancheLoc, TrancheType}; -use runtime_common::{ - account_conversion::AccountConverter, foreign_investments::IdentityPoolCurrencyConverter, - xcm::general_key, -}; +use runtime_common::{foreign_investments::IdentityPoolCurrencyConverter, xcm::general_key}; use sp_core::Get; use sp_runtime::{ - traits::{AccountIdConversion, Convert, EnsureAdd, One, Zero}, + traits::{AccountIdConversion, EnsureAdd, One, Zero}, BoundedVec, DispatchError, FixedPointNumber, Perquintill, SaturatedConversion, }; use staging_xcm::{ @@ -72,11 +69,11 @@ pub const POOL_ID: PoolId = 42; pub const MOONBEAM_EVM_CHAIN_ID: u64 = 1284; pub const DEFAULT_EVM_ADDRESS_MOONBEAM: [u8; 20] = [99; 20]; pub const DEFAULT_VALIDITY: Seconds = 2555583502; -pub const DOMAIN_MOONBEAM: Domain = Domain::EVM(MOONBEAM_EVM_CHAIN_ID); +pub const DOMAIN_MOONBEAM: Domain = Domain::Evm(MOONBEAM_EVM_CHAIN_ID); pub const DEFAULT_DOMAIN_ADDRESS_MOONBEAM: DomainAddress = - DomainAddress::EVM(MOONBEAM_EVM_CHAIN_ID, DEFAULT_EVM_ADDRESS_MOONBEAM); + DomainAddress::Evm(MOONBEAM_EVM_CHAIN_ID, DEFAULT_EVM_ADDRESS_MOONBEAM); pub const DEFAULT_OTHER_DOMAIN_ADDRESS: DomainAddress = - DomainAddress::EVM(MOONBEAM_EVM_CHAIN_ID, [0; 20]); + DomainAddress::Evm(MOONBEAM_EVM_CHAIN_ID, [0; 20]); pub type LiquidityPoolMessage = Message; @@ -280,10 +277,7 @@ pub mod utils { assert_ok!(orml_tokens::Pallet::::set_balance( ::RuntimeOrigin::root(), - AccountId::from( - ::Sender::get().address() - ) - .into(), + T::Sender::get().as_local::().into(), GLMR_CURRENCY_ID, DEFAULT_BALANCE_GLMR, 0, @@ -509,7 +503,7 @@ pub mod utils { assert_eq!( orml_tokens::Pallet::::balance( default_investment_id::().into(), - &AccountConverter::convert(DEFAULT_OTHER_DOMAIN_ADDRESS) + &DEFAULT_OTHER_DOMAIN_ADDRESS.as_local(), ), 0 ); @@ -683,8 +677,8 @@ mod foreign_investments { env.parachain_state_mut(|| { let pool_id = POOL_ID; let amount = 10 * decimals(12); - let investor = - AccountConverter::domain_account_to_account(DOMAIN_MOONBEAM, Keyring::Bob.id()); + let investor: AccountId = + DomainAddress::new(DOMAIN_MOONBEAM, Keyring::Bob.into()).as_local(); let currency_id = AUSD_CURRENCY_ID; let currency_decimals = currency_decimals::AUSD; @@ -731,8 +725,8 @@ mod foreign_investments { env.parachain_state_mut(|| { let pool_id = POOL_ID; let invest_amount: u128 = 10 * decimals(12); - let investor = - AccountConverter::domain_account_to_account(DOMAIN_MOONBEAM, Keyring::Bob.id()); + let investor: AccountId = + DomainAddress::new(DOMAIN_MOONBEAM, Keyring::Bob.into()).as_local(); let currency_id: CurrencyId = AUSD_CURRENCY_ID; let currency_decimals = currency_decimals::AUSD; @@ -821,8 +815,8 @@ mod foreign_investments { env.parachain_state_mut(|| { let pool_id = POOL_ID; let invest_amount = 10 * decimals(12); - let investor = - AccountConverter::domain_account_to_account(DOMAIN_MOONBEAM, Keyring::Bob.id()); + let investor: AccountId = + DomainAddress::new(DOMAIN_MOONBEAM, Keyring::Bob.into()).as_local(); let currency_id = AUSD_CURRENCY_ID; let currency_decimals = currency_decimals::AUSD; @@ -921,8 +915,8 @@ mod foreign_investments { env.parachain_state_mut(|| { let pool_id = POOL_ID; let amount = 10 * decimals(12); - let investor = - AccountConverter::domain_account_to_account(DOMAIN_MOONBEAM, Keyring::Bob.id()); + let investor: AccountId = + DomainAddress::new(DOMAIN_MOONBEAM, Keyring::Bob.into()).as_local(); let currency_id = AUSD_CURRENCY_ID; let currency_decimals = currency_decimals::AUSD; let sending_domain_locator = @@ -1029,7 +1023,7 @@ mod foreign_investments { let nonce = MessageNonceStore::::get(); - let sender = ::Sender::get(); + let sender = T::Sender::get(); // Clearing of foreign InvestState should be dispatched assert!(frame_system::Pallet::::events().iter().any(|e| { @@ -1067,8 +1061,8 @@ mod foreign_investments { env.parachain_state_mut(|| { let pool_id = POOL_ID; let invest_amount = 10 * decimals(12); - let investor = - AccountConverter::domain_account_to_account(DOMAIN_MOONBEAM, Keyring::Bob.id()); + let investor: AccountId = + DomainAddress::new(DOMAIN_MOONBEAM, Keyring::Bob.into()).as_local(); let currency_id = AUSD_CURRENCY_ID; let currency_decimals = currency_decimals::AUSD; let sending_domain_locator = @@ -1304,8 +1298,8 @@ mod foreign_investments { env.parachain_state_mut(|| { let pool_id = POOL_ID; let amount = 10 * decimals(12); - let investor = - AccountConverter::domain_account_to_account(DOMAIN_MOONBEAM, Keyring::Bob.id()); + let investor: AccountId = + DomainAddress::new(DOMAIN_MOONBEAM, Keyring::Bob.into()).as_local(); let currency_id = AUSD_CURRENCY_ID; let currency_decimals = currency_decimals::AUSD; @@ -1357,8 +1351,8 @@ mod foreign_investments { env.parachain_state_mut(|| { let pool_id = POOL_ID; let redeem_amount = 10 * decimals(12); - let investor = - AccountConverter::domain_account_to_account(DOMAIN_MOONBEAM, Keyring::Bob.id()); + let investor: AccountId = + DomainAddress::new(DOMAIN_MOONBEAM, Keyring::Bob.into()).as_local(); let currency_id = AUSD_CURRENCY_ID; let currency_decimals = currency_decimals::AUSD; let sending_domain_locator = @@ -1452,8 +1446,8 @@ mod foreign_investments { env.parachain_state_mut(|| { let pool_id = POOL_ID; let redeem_amount = 10 * decimals(12); - let investor = - AccountConverter::domain_account_to_account(DOMAIN_MOONBEAM, Keyring::Bob.id()); + let investor: AccountId = + DomainAddress::new(DOMAIN_MOONBEAM, Keyring::Bob.into()).as_local(); let currency_id = AUSD_CURRENCY_ID; let currency_decimals = currency_decimals::AUSD; let pool_account = pallet_pool_system::pool_types::PoolLocator { pool_id } @@ -1645,10 +1639,8 @@ mod foreign_investments { env.parachain_state_mut(|| { let pool_id = POOL_ID; let amount: u128 = 10 * decimals(12); - let investor = AccountConverter::domain_account_to_account( - DOMAIN_MOONBEAM, - Keyring::Bob.id(), - ); + let investor: AccountId = + DomainAddress::new(DOMAIN_MOONBEAM, Keyring::Bob.into()).as_local(); let currency_id: CurrencyId = AUSD_CURRENCY_ID; let currency_decimals = currency_decimals::AUSD; create_currency_pool::(pool_id, currency_id, currency_decimals.into()); @@ -1725,10 +1717,8 @@ mod foreign_investments { env.parachain_state_mut(|| { let pool_id = POOL_ID; let amount: u128 = 10 * decimals(12); - let investor = AccountConverter::domain_account_to_account( - DOMAIN_MOONBEAM, - Keyring::Bob.id(), - ); + let investor: AccountId = + DomainAddress::new(DOMAIN_MOONBEAM, Keyring::Bob.into()).as_local(); let currency_id: CurrencyId = AUSD_CURRENCY_ID; let currency_decimals = currency_decimals::AUSD; create_currency_pool::(pool_id, currency_id, currency_decimals.into()); @@ -1815,10 +1805,8 @@ mod foreign_investments { env.parachain_state_mut(|| { let pool_id = POOL_ID; - let investor = AccountConverter::domain_account_to_account( - DOMAIN_MOONBEAM, - Keyring::Bob.id(), - ); + let investor: AccountId = + DomainAddress::new(DOMAIN_MOONBEAM, Keyring::Bob.into()).as_local(); let pool_currency = AUSD_CURRENCY_ID; let currency_decimals = currency_decimals::AUSD; let foreign_currency: CurrencyId = USDT_CURRENCY_ID; @@ -1877,8 +1865,8 @@ mod foreign_investments { env.parachain_state_mut(|| { let pool_id = POOL_ID; - let investor = - AccountConverter::domain_account_to_account(DOMAIN_MOONBEAM, Keyring::Bob.id()); + let investor: AccountId = + DomainAddress::new(DOMAIN_MOONBEAM, Keyring::Bob.into()).as_local(); let pool_currency: CurrencyId = AUSD_CURRENCY_ID; let foreign_currency: CurrencyId = USDT_CURRENCY_ID; let pool_currency_decimals = currency_decimals::AUSD; @@ -1999,8 +1987,8 @@ mod foreign_investments { env.parachain_state_mut(|| { let pool_id = POOL_ID; - let investor = - AccountConverter::domain_account_to_account(DOMAIN_MOONBEAM, Keyring::Bob.id()); + let investor: AccountId = + DomainAddress::new(DOMAIN_MOONBEAM, Keyring::Bob.into()).as_local(); let trader: AccountId = Keyring::Alice.into(); let pool_currency: CurrencyId = AUSD_CURRENCY_ID; let foreign_currency: CurrencyId = USDT_CURRENCY_ID; @@ -2147,8 +2135,8 @@ mod foreign_investments { env.parachain_state_mut(|| { let pool_id = POOL_ID; - let investor = - AccountConverter::domain_account_to_account(DOMAIN_MOONBEAM, Keyring::Bob.id()); + let investor: AccountId = + DomainAddress::new(DOMAIN_MOONBEAM, Keyring::Bob.into()).as_local(); let pool_currency: CurrencyId = AUSD_CURRENCY_ID; let foreign_currency: CurrencyId = USDT_CURRENCY_ID; let pool_currency_decimals = currency_decimals::AUSD; diff --git a/runtime/integration-tests/src/cases/liquidity_pools_gateway_queue.rs b/runtime/integration-tests/src/cases/liquidity_pools_gateway_queue.rs index 7034f18ecb..876401c176 100644 --- a/runtime/integration-tests/src/cases/liquidity_pools_gateway_queue.rs +++ b/runtime/integration-tests/src/cases/liquidity_pools_gateway_queue.rs @@ -25,7 +25,7 @@ fn inbound() { let expected_event = env.parachain_state_mut(|| { let nonce = ::MessageNonce::one(); let message = GatewayMessage::Inbound { - domain_address: DomainAddress::EVM(1, [2; 20]), + domain_address: DomainAddress::Evm(1, [2; 20]), message: Message::Invalid, }; @@ -55,8 +55,8 @@ fn outbound() { let expected_event = env.parachain_state_mut(|| { let nonce = ::MessageNonce::one(); let message = GatewayMessage::Outbound { - sender: DomainAddress::Centrifuge([1; 32]), - destination: Domain::EVM(1), + sender: DomainAddress::Local([1; 32]), + destination: Domain::Evm(1), message: Message::Invalid, }; diff --git a/runtime/integration-tests/src/cases/lp/mod.rs b/runtime/integration-tests/src/cases/lp/mod.rs index 1c6896a9bf..9e215fb7de 100644 --- a/runtime/integration-tests/src/cases/lp/mod.rs +++ b/runtime/integration-tests/src/cases/lp/mod.rs @@ -26,7 +26,6 @@ use frame_system::pallet_prelude::OriginFor; use hex_literal::hex; use pallet_axelar_router::{AxelarConfig, DomainConfig, EvmConfig, FeeValues}; use pallet_evm::FeeCalculator; -use runtime_common::account_conversion::AccountConverter; pub use setup_lp::*; use sp_core::Get; use sp_runtime::traits::{BlakeTwo256, Hash}; @@ -86,7 +85,7 @@ pub const EVM_DOMAIN_STR: &str = "TestDomain"; /// The test domain ChainId for the tests. pub const EVM_DOMAIN_CHAIN_ID: u64 = 1; -pub const EVM_DOMAIN: Domain = Domain::EVM(EVM_DOMAIN_CHAIN_ID); +pub const EVM_DOMAIN: Domain = Domain::Evm(EVM_DOMAIN_CHAIN_ID); /// Represents Solidity enum Domain.Centrifuge pub const DOMAIN_CENTRIFUGE: u8 = 0; diff --git a/runtime/integration-tests/src/cases/lp/pool_management.rs b/runtime/integration-tests/src/cases/lp/pool_management.rs index 48ada53f6f..05dfa88f33 100644 --- a/runtime/integration-tests/src/cases/lp/pool_management.rs +++ b/runtime/integration-tests/src/cases/lp/pool_management.rs @@ -21,7 +21,6 @@ use ethabi::{ethereum_types::H160, Token, Uint}; use frame_support::{assert_ok, traits::OriginTrait}; use frame_system::pallet_prelude::OriginFor; use pallet_liquidity_pools::GeneralCurrencyIndexOf; -use runtime_common::account_conversion::AccountConverter; use sp_runtime::FixedPointNumber; use crate::{ @@ -142,7 +141,7 @@ fn add_pool() { assert_ok!(pallet_liquidity_pools::Pallet::::add_pool( OriginFor::::signed(Keyring::Admin.into()), POOL, - Domain::EVM(EVM_DOMAIN_CHAIN_ID) + Domain::Evm(EVM_DOMAIN_CHAIN_ID) )); utils::process_gateway_message::(utils::verify_gateway_message_success::); @@ -163,7 +162,7 @@ fn add_pool() { assert_ok!(pallet_liquidity_pools::Pallet::::add_pool( T::RuntimeOriginExt::signed(Keyring::Admin.into()), POOL, - Domain::EVM(EVM_DOMAIN_CHAIN_ID) + Domain::Evm(EVM_DOMAIN_CHAIN_ID) )); utils::process_gateway_message::(|_| { @@ -213,7 +212,7 @@ fn add_tranche() { OriginFor::::signed(Keyring::Admin.into()), POOL_A, pool_a_tranche_1_id::(), - Domain::EVM(EVM_DOMAIN_CHAIN_ID) + Domain::Evm(EVM_DOMAIN_CHAIN_ID) )); utils::process_gateway_message::(utils::verify_gateway_message_success::); @@ -403,7 +402,7 @@ fn update_member() { env.state_mut(|_| { crate::utils::pool::give_role::( - AccountConverter::convert_evm_address(EVM_DOMAIN_CHAIN_ID, Keyring::Bob.into()), + DomainAddress::Evm(EVM_DOMAIN_CHAIN_ID, Keyring::TrancheInvestor(2).into()).as_local(), POOL_A, PoolRole::TrancheInvestor(pool_a_tranche_1_id::(), SECONDS_PER_YEAR), ); @@ -412,7 +411,7 @@ fn update_member() { Keyring::Bob.as_origin(), POOL_A, pool_a_tranche_1_id::(), - DomainAddress::evm(EVM_DOMAIN_CHAIN_ID, Keyring::Bob.into()), + DomainAddress::Evm(EVM_DOMAIN_CHAIN_ID, Keyring::Bob.into()), SECONDS_PER_YEAR, )); @@ -517,7 +516,7 @@ fn update_tranche_token_metadata() { OriginFor::::signed(Keyring::Alice.into()), POOL_A, pool_a_tranche_1_id::(), - Domain::EVM(EVM_DOMAIN_CHAIN_ID) + Domain::Evm(EVM_DOMAIN_CHAIN_ID) ) ); utils::process_gateway_message::(utils::verify_gateway_message_success::); @@ -573,7 +572,7 @@ fn update_tranche_token_price() { POOL_A, pool_a_tranche_1_id::(), USDC.id(), - Domain::EVM(EVM_DOMAIN_CHAIN_ID) + Domain::Evm(EVM_DOMAIN_CHAIN_ID) )); utils::process_gateway_message::(utils::verify_gateway_message_success::); @@ -630,10 +629,7 @@ fn freeze_member() { env.state_mut(|_| { give_role::( - AccountConverter::convert_evm_address( - EVM_DOMAIN_CHAIN_ID, - Keyring::TrancheInvestor(2).into(), - ), + DomainAddress::Evm(EVM_DOMAIN_CHAIN_ID, Keyring::TrancheInvestor(2).into()).as_local(), POOL_A, PoolRole::FrozenTrancheInvestor(pool_a_tranche_1_id::()), ); @@ -641,7 +637,7 @@ fn freeze_member() { Keyring::Admin.as_origin(), POOL_A, pool_a_tranche_1_id::(), - DomainAddress::evm(EVM_DOMAIN_CHAIN_ID, Keyring::TrancheInvestor(2).into()), + DomainAddress::Evm(EVM_DOMAIN_CHAIN_ID, Keyring::TrancheInvestor(2).into()), )); utils::process_gateway_message::(utils::verify_gateway_message_success::); @@ -677,10 +673,7 @@ fn unfreeze_member() { env.state_mut(|_| { give_role::( - AccountConverter::convert_evm_address( - EVM_DOMAIN_CHAIN_ID, - Keyring::TrancheInvestor(2).into(), - ), + DomainAddress::Evm(EVM_DOMAIN_CHAIN_ID, Keyring::TrancheInvestor(2).into()).as_local(), POOL_A, PoolRole::FrozenTrancheInvestor(pool_a_tranche_1_id::()), ); @@ -688,7 +681,7 @@ fn unfreeze_member() { Keyring::Admin.as_origin(), POOL_A, pool_a_tranche_1_id::(), - DomainAddress::evm(EVM_DOMAIN_CHAIN_ID, Keyring::TrancheInvestor(2).into()), + DomainAddress::Evm(EVM_DOMAIN_CHAIN_ID, Keyring::TrancheInvestor(2).into()), )); utils::process_gateway_message::(utils::verify_gateway_message_success::); @@ -711,10 +704,7 @@ fn unfreeze_member() { env.state_mut(|_| { remove_role::( - AccountConverter::convert_evm_address( - EVM_DOMAIN_CHAIN_ID, - Keyring::TrancheInvestor(2).into(), - ), + DomainAddress::Evm(EVM_DOMAIN_CHAIN_ID, Keyring::TrancheInvestor(2).into()).as_local(), POOL_A, PoolRole::FrozenTrancheInvestor(pool_a_tranche_1_id::()), ); @@ -722,7 +712,7 @@ fn unfreeze_member() { Keyring::Admin.as_origin(), POOL_A, pool_a_tranche_1_id::(), - DomainAddress::evm(EVM_DOMAIN_CHAIN_ID, Keyring::TrancheInvestor(2).into()), + DomainAddress::Evm(EVM_DOMAIN_CHAIN_ID, Keyring::TrancheInvestor(2).into()), )); utils::process_gateway_message::(utils::verify_gateway_message_success::); diff --git a/runtime/integration-tests/src/cases/lp/setup_lp.rs b/runtime/integration-tests/src/cases/lp/setup_lp.rs index efc3ad0299..cf0812532f 100644 --- a/runtime/integration-tests/src/cases/lp/setup_lp.rs +++ b/runtime/integration-tests/src/cases/lp/setup_lp.rs @@ -41,7 +41,7 @@ pub fn setup as EnvEvmExtension>::E evm.load_contracts(); // Fund gateway sender - give_balance::(T::Sender::get().address().into(), DEFAULT_BALANCE * CFG); + give_balance::(T::Sender::get().as_local(), DEFAULT_BALANCE * CFG); // Register general local pool-currency register_currency::(LocalUSDC, |_| {}); @@ -88,13 +88,13 @@ pub fn setup as EnvEvmExtension>::E assert_ok!(pallet_liquidity_pools_gateway::Pallet::::add_instance( RawOrigin::Root.into(), - DomainAddress::evm(EVM_DOMAIN_CHAIN_ID, EVM_LP_INSTANCE) + DomainAddress::Evm(EVM_DOMAIN_CHAIN_ID, EVM_LP_INSTANCE) )); assert_ok!( pallet_liquidity_pools_gateway::Pallet::::set_domain_hook_address( RawOrigin::Root.into(), - Domain::EVM(EVM_DOMAIN_CHAIN_ID), + Domain::Evm(EVM_DOMAIN_CHAIN_ID), LOCAL_RESTRICTION_MANAGER_ADDRESS.into(), ) ); @@ -228,7 +228,7 @@ pub fn setup_tranches(evm: &mut impl EvmEnv) { OriginFor::::signed(Keyring::Admin.into()), POOL_A, tranche_id, - Domain::EVM(EVM_DOMAIN_CHAIN_ID) + Domain::Evm(EVM_DOMAIN_CHAIN_ID) )); utils::process_gateway_message::(utils::verify_gateway_message_success::); @@ -271,7 +271,7 @@ pub fn setup_tranches(evm: &mut impl EvmEnv) { OriginFor::::signed(Keyring::Admin.into()), POOL_B, tranche_id, - Domain::EVM(EVM_DOMAIN_CHAIN_ID) + Domain::Evm(EVM_DOMAIN_CHAIN_ID) )); utils::process_gateway_message::(utils::verify_gateway_message_success::); @@ -314,7 +314,7 @@ pub fn setup_tranches(evm: &mut impl EvmEnv) { OriginFor::::signed(Keyring::Admin.into()), POOL_B, utils::pool_b_tranche_2_id::(), - Domain::EVM(EVM_DOMAIN_CHAIN_ID) + Domain::Evm(EVM_DOMAIN_CHAIN_ID) )); utils::process_gateway_message::(utils::verify_gateway_message_success::); @@ -357,7 +357,7 @@ pub fn setup_tranches(evm: &mut impl EvmEnv) { OriginFor::::signed(Keyring::Admin.into()), POOL_C, tranche_id, - Domain::EVM(EVM_DOMAIN_CHAIN_ID) + Domain::Evm(EVM_DOMAIN_CHAIN_ID) )); utils::process_gateway_message::(utils::verify_gateway_message_success::); @@ -403,7 +403,7 @@ pub fn setup_pools(_evm: &mut impl EvmEnv) { assert_ok!(pallet_liquidity_pools::Pallet::::add_pool( OriginFor::::signed(Keyring::Admin.into()), POOL_A, - Domain::EVM(EVM_DOMAIN_CHAIN_ID) + Domain::Evm(EVM_DOMAIN_CHAIN_ID) )); utils::process_gateway_message::(utils::verify_gateway_message_success::); @@ -413,7 +413,7 @@ pub fn setup_pools(_evm: &mut impl EvmEnv) { assert_ok!(pallet_liquidity_pools::Pallet::::add_pool( OriginFor::::signed(Keyring::Admin.into()), POOL_B, - Domain::EVM(EVM_DOMAIN_CHAIN_ID) + Domain::Evm(EVM_DOMAIN_CHAIN_ID) )); crate::utils::pool::create_one_tranched::(Keyring::Admin.into(), POOL_C, USDC.id()); @@ -421,7 +421,7 @@ pub fn setup_pools(_evm: &mut impl EvmEnv) { assert_ok!(pallet_liquidity_pools::Pallet::::add_pool( OriginFor::::signed(Keyring::Admin.into()), POOL_C, - Domain::EVM(EVM_DOMAIN_CHAIN_ID) + Domain::Evm(EVM_DOMAIN_CHAIN_ID) )); utils::process_gateway_message::(utils::verify_gateway_message_success::); @@ -667,7 +667,7 @@ pub fn setup_investors(evm: &mut impl EvmEnv) { ); // Centrifuge Chain setup: Add permissions and dispatch LP message crate::utils::pool::give_role::( - AccountConverter::convert_evm_address(EVM_DOMAIN_CHAIN_ID, investor.into()), + DomainAddress::Evm(EVM_DOMAIN_CHAIN_ID, investor.into()).as_local(), POOL_A, PoolRole::TrancheInvestor(pool_a_tranche_1_id::(), SECONDS_PER_YEAR), ); @@ -675,7 +675,7 @@ pub fn setup_investors(evm: &mut impl EvmEnv) { investor.as_origin(), POOL_A, pool_a_tranche_1_id::(), - DomainAddress::evm(EVM_DOMAIN_CHAIN_ID, investor.into()), + DomainAddress::Evm(EVM_DOMAIN_CHAIN_ID, investor.into()), SECONDS_PER_YEAR, )); @@ -687,7 +687,7 @@ pub fn setup_investors(evm: &mut impl EvmEnv) { PoolRole::TrancheInvestor(pool_b_tranche_1_id::(), SECONDS_PER_YEAR), ); crate::utils::pool::give_role::( - AccountConverter::convert_evm_address(EVM_DOMAIN_CHAIN_ID, investor.into()), + DomainAddress::Evm(EVM_DOMAIN_CHAIN_ID, investor.into()).as_local(), POOL_B, PoolRole::TrancheInvestor(pool_b_tranche_1_id::(), SECONDS_PER_YEAR), ); @@ -695,7 +695,7 @@ pub fn setup_investors(evm: &mut impl EvmEnv) { investor.as_origin(), POOL_B, pool_b_tranche_1_id::(), - DomainAddress::evm(EVM_DOMAIN_CHAIN_ID, investor.into()), + DomainAddress::Evm(EVM_DOMAIN_CHAIN_ID, investor.into()), SECONDS_PER_YEAR, )); @@ -707,7 +707,7 @@ pub fn setup_investors(evm: &mut impl EvmEnv) { PoolRole::TrancheInvestor(pool_b_tranche_2_id::(), SECONDS_PER_YEAR), ); crate::utils::pool::give_role::( - AccountConverter::convert_evm_address(EVM_DOMAIN_CHAIN_ID, investor.into()), + DomainAddress::Evm(EVM_DOMAIN_CHAIN_ID, investor.into()).as_local(), POOL_B, PoolRole::TrancheInvestor(pool_b_tranche_2_id::(), SECONDS_PER_YEAR), ); @@ -715,7 +715,7 @@ pub fn setup_investors(evm: &mut impl EvmEnv) { investor.as_origin(), POOL_B, pool_b_tranche_2_id::(), - DomainAddress::evm(EVM_DOMAIN_CHAIN_ID, investor.into()), + DomainAddress::Evm(EVM_DOMAIN_CHAIN_ID, investor.into()), SECONDS_PER_YEAR, )); @@ -727,7 +727,7 @@ pub fn setup_investors(evm: &mut impl EvmEnv) { PoolRole::TrancheInvestor(utils::pool_c_tranche_1_id::(), SECONDS_PER_YEAR), ); crate::utils::pool::give_role::( - AccountConverter::convert_evm_address(EVM_DOMAIN_CHAIN_ID, investor.into()), + DomainAddress::Evm(EVM_DOMAIN_CHAIN_ID, investor.into()).as_local(), POOL_C, PoolRole::TrancheInvestor(utils::pool_c_tranche_1_id::(), SECONDS_PER_YEAR), ); @@ -735,7 +735,7 @@ pub fn setup_investors(evm: &mut impl EvmEnv) { investor.as_origin(), POOL_C, utils::pool_c_tranche_1_id::(), - DomainAddress::evm(EVM_DOMAIN_CHAIN_ID, investor.into()), + DomainAddress::Evm(EVM_DOMAIN_CHAIN_ID, investor.into()), SECONDS_PER_YEAR, )); @@ -930,7 +930,7 @@ pub fn setup_market_ratios() { POOL_A, pool_a_tranche_1_id::(), currency_id, - Domain::EVM(EVM_DOMAIN_CHAIN_ID) + Domain::Evm(EVM_DOMAIN_CHAIN_ID) )); crate::cases::liquidity_pools::utils::enable_symmetric_trading_pair::( @@ -945,7 +945,7 @@ pub fn setup_market_ratios() { POOL_B, pool_b_tranche_1_id::(), currency_id, - Domain::EVM(EVM_DOMAIN_CHAIN_ID) + Domain::Evm(EVM_DOMAIN_CHAIN_ID) )); crate::cases::liquidity_pools::utils::enable_symmetric_trading_pair::( pallet_foreign_investments::pool_currency_of::((POOL_B, pool_b_tranche_2_id::())) @@ -959,7 +959,7 @@ pub fn setup_market_ratios() { POOL_B, pool_b_tranche_2_id::(), currency_id, - Domain::EVM(EVM_DOMAIN_CHAIN_ID) + Domain::Evm(EVM_DOMAIN_CHAIN_ID) )); crate::cases::liquidity_pools::utils::enable_symmetric_trading_pair::( @@ -974,7 +974,7 @@ pub fn setup_market_ratios() { POOL_C, pool_c_tranche_1_id::(), currency_id, - Domain::EVM(EVM_DOMAIN_CHAIN_ID) + Domain::Evm(EVM_DOMAIN_CHAIN_ID) )); } } diff --git a/runtime/integration-tests/src/cases/lp/transfers.rs b/runtime/integration-tests/src/cases/lp/transfers.rs index e81fe2f3de..281121badb 100644 --- a/runtime/integration-tests/src/cases/lp/transfers.rs +++ b/runtime/integration-tests/src/cases/lp/transfers.rs @@ -78,7 +78,7 @@ mod utils { OriginFor::::signed(Keyring::TrancheInvestor(1).into()), POOL_A, pool_a_tranche_1_id::(), - DomainAddress::evm(EVM_DOMAIN_CHAIN_ID, Keyring::TrancheInvestor(1).into()), + DomainAddress::Evm(EVM_DOMAIN_CHAIN_ID, Keyring::TrancheInvestor(1).into()), AMOUNT, ) .unwrap(); @@ -157,7 +157,7 @@ fn transfer_tokens_from_local() { pallet_liquidity_pools::Pallet::::transfer( OriginFor::::signed(Keyring::Ferdie.into()), USDC.id(), - DomainAddress::evm(EVM_DOMAIN_CHAIN_ID, Keyring::Ferdie.into()), + DomainAddress::Evm(EVM_DOMAIN_CHAIN_ID, Keyring::Ferdie.into()), AMOUNT, ) .unwrap(); @@ -215,7 +215,7 @@ fn transfer_tranche_tokens_from_local() { OriginFor::::signed(Keyring::TrancheInvestor(1).into()), POOL_A, pool_a_tranche_1_id::(), - DomainAddress::evm(EVM_DOMAIN_CHAIN_ID, Keyring::TrancheInvestor(1).into()), + DomainAddress::Evm(EVM_DOMAIN_CHAIN_ID, Keyring::TrancheInvestor(1).into()), AMOUNT, ) .unwrap(); @@ -292,7 +292,7 @@ fn transfer_tranche_tokens_domain_to_local_to_domain() { Message::TransferTrancheTokens { pool_id: POOL_A, tranche_id: pool_a_tranche_1_id::(), - domain: Domain::EVM(EVM_DOMAIN_CHAIN_ID).into(), + domain: Domain::Evm(EVM_DOMAIN_CHAIN_ID).into(), receiver: as_h160_32bytes(Keyring::TrancheInvestor(2)), amount: AMOUNT, }, diff --git a/runtime/integration-tests/src/cases/lp/utils.rs b/runtime/integration-tests/src/cases/lp/utils.rs index e8229d5c17..e6eb5e6b71 100644 --- a/runtime/integration-tests/src/cases/lp/utils.rs +++ b/runtime/integration-tests/src/cases/lp/utils.rs @@ -21,10 +21,7 @@ use frame_system::pallet_prelude::OriginFor; use pallet_evm::ExecutionInfo; use pallet_liquidity_pools_gateway::message::GatewayMessage; use sp_core::Get; -use sp_runtime::{ - traits::{Convert, EnsureAdd}, - DispatchError, -}; +use sp_runtime::{traits::EnsureAdd, DispatchError}; use staging_xcm::{ v4::{ Junction::{AccountKey20, GlobalConsensus, PalletInstance}, @@ -40,10 +37,7 @@ use crate::{ }; pub fn remote_account_of(keyring: Keyring) -> ::AccountId { - ::DomainAddressToAccountId::convert(DomainAddress::evm( - EVM_DOMAIN_CHAIN_ID, - keyring.into(), - )) + DomainAddress::Evm(EVM_DOMAIN_CHAIN_ID, keyring.into()).as_local() } pub const REVERT_ERR: Result = @@ -97,10 +91,7 @@ pub fn verify_outbound_failure_on_lp(to: H160) { .clone(); // The sender is the sender account on the gateway - assert_eq!( - status.from.0, - ::Sender::get().address()[0..20] - ); + assert_eq!(T::Sender::get().as_eth::<[u8; 20]>(), status.from.0); assert_eq!(status.to.unwrap().0, to.0); assert!(!receipt_ok(receipt)); assert!(matches!( @@ -156,7 +147,7 @@ pub fn process_gateway_message( sender, ::Sender::get() ); - assert_eq!(destination, Domain::EVM(EVM_DOMAIN_CHAIN_ID)); + assert_eq!(destination, Domain::Evm(EVM_DOMAIN_CHAIN_ID)); verifier(message) } } diff --git a/runtime/integration-tests/src/cases/restricted_transfers.rs b/runtime/integration-tests/src/cases/restricted_transfers.rs index bb1cfe7466..ed20d487f9 100644 --- a/runtime/integration-tests/src/cases/restricted_transfers.rs +++ b/runtime/integration-tests/src/cases/restricted_transfers.rs @@ -397,7 +397,7 @@ mod eth_address { ); env.parachain_state_mut(|| { - let curr_contract = DomainAddress::EVM(CHAIN_ID, CONTRACT_ACCOUNT); + let curr_contract = DomainAddress::Evm(CHAIN_ID, CONTRACT_ACCOUNT); assert_ok!( pallet_transfer_allowlist::Pallet::::add_transfer_allowance( @@ -411,7 +411,7 @@ mod eth_address { pallet_liquidity_pools::Pallet::::transfer( RawOrigin::Signed(Keyring::Alice.into()).into(), curr.id(), - DomainAddress::EVM(CHAIN_ID, [2; 20]), // Not the allowed contract account + DomainAddress::Evm(CHAIN_ID, [2; 20]), // Not the allowed contract account curr.val(TRANSFER), ), pallet_transfer_allowlist::Error::::NoAllowanceForDestination diff --git a/runtime/integration-tests/src/cases/routers.rs b/runtime/integration-tests/src/cases/routers.rs index e4c13f0d55..d857103365 100644 --- a/runtime/integration-tests/src/cases/routers.rs +++ b/runtime/integration-tests/src/cases/routers.rs @@ -12,7 +12,7 @@ use pallet_liquidity_pools::Message; use pallet_liquidity_pools_gateway::message::GatewayMessage; use runtime_common::{ account_conversion::AccountConverter, evm::precompile::LP_AXELAR_GATEWAY, - gateway::get_gateway_h160_account, + gateway::get_gateway_domain_address, }; use sp_core::{Get, H160, H256, U256}; use sp_runtime::traits::{BlakeTwo256, Hash}; @@ -35,7 +35,7 @@ mod axelar_evm { const CHAIN_NAME: &str = "Ethereum"; const INITIAL: Balance = 100; const CHAIN_ID: EVMChainId = 1; - const TEST_DOMAIN: Domain = Domain::EVM(CHAIN_ID); + const TEST_DOMAIN: Domain = Domain::Evm(CHAIN_ID); const AXELAR_CONTRACT_CODE: &[u8] = &[0, 0, 0]; const AXELAR_CONTRACT_ADDRESS: H160 = H160::repeat_byte(1); const LP_CONTRACT_ADDRESS: H160 = H160::repeat_byte(2); @@ -120,7 +120,7 @@ mod axelar_evm { utils::evm::mint_balance_into_derived_account::(AXELAR_CONTRACT_ADDRESS, cfg(1)); utils::evm::mint_balance_into_derived_account::( - get_gateway_h160_account::(), + get_gateway_domain_address::().as_eth::(), cfg(1), ); @@ -171,7 +171,7 @@ mod axelar_evm { pallet_liquidity_pools_gateway::Pallet::::add_instance( RawOrigin::Root.into(), - DomainAddress::EVM(CHAIN_ID, SOURCE_ADDRESS.0), + DomainAddress::Evm(CHAIN_ID, SOURCE_ADDRESS.0), ) .unwrap(); diff --git a/runtime/integration-tests/src/utils/evm.rs b/runtime/integration-tests/src/utils/evm.rs index 4c91a4aef9..53949fecd4 100644 --- a/runtime/integration-tests/src/utils/evm.rs +++ b/runtime/integration-tests/src/utils/evm.rs @@ -4,12 +4,12 @@ use std::{ path::{Path, PathBuf}, }; +use cfg_types::domain_address::DomainAddress; use cfg_utils::vec_to_fixed_array; use ethabi::{ethereum_types::H160, Contract}; use ethereum::ReceiptV3; use frame_support::traits::{fungible::Mutate, OriginTrait}; use pallet_evm::FeeCalculator; -use runtime_common::account_conversion::AccountConverter; use sp_runtime::traits::Get; use crate::{config::Runtime, utils::ESSENTIAL}; @@ -184,11 +184,10 @@ pub fn receipt_ok(receipt: ReceiptV3) -> bool { inner.status_code == 1 } -pub fn mint_balance_into_derived_account(address: impl AsRef<[u8]>, balance: u128) { +pub fn mint_balance_into_derived_account(address: impl Into<[u8; 20]>, balance: u128) { let chain_id = pallet_evm_chain_id::Pallet::::get(); - let derived_account = - AccountConverter::convert_evm_address(chain_id, vec_to_fixed_array(address)); - pallet_balances::Pallet::::mint_into(&derived_account.into(), balance) + let derived_account = DomainAddress::from_evm(chain_id, address).as_local(); + pallet_balances::Pallet::::mint_into(&derived_account, balance) .expect("Minting into derived EVM accounf failed."); }