From 73f937631955fd011ea7d647b2fabe44f1e85527 Mon Sep 17 00:00:00 2001 From: Roy Yang Date: Sat, 9 Sep 2023 02:13:27 +1200 Subject: [PATCH] chore: Rename EmergencyWithdrawalAddress: LiquidityRefundAddress (#3970) Co-authored-by: Daniel Co-authored-by: dandanlen <3168260+dandanlen@users.noreply.github.com> --- api/bin/chainflip-cli/src/main.rs | 11 ++--- api/bin/chainflip-cli/src/settings.rs | 4 +- api/bin/chainflip-lp-api/README.md | 4 +- api/bin/chainflip-lp-api/src/main.rs | 8 ++-- api/lib/src/lp.rs | 6 +-- bouncer/shared/provide_liquidity.ts | 13 +++--- bouncer/tests/double_deposit.ts | 4 +- state-chain/pallets/cf-lp/src/benchmarking.rs | 8 ++-- state-chain/pallets/cf-lp/src/lib.rs | 29 ++++++------- state-chain/pallets/cf-lp/src/tests.rs | 42 ++++++++----------- state-chain/pallets/cf-lp/src/weights.rs | 6 +-- 11 files changed, 61 insertions(+), 74 deletions(-) diff --git a/api/bin/chainflip-cli/src/main.rs b/api/bin/chainflip-cli/src/main.rs index fed905dc5fc..2b81f92ed7a 100644 --- a/api/bin/chainflip-cli/src/main.rs +++ b/api/bin/chainflip-cli/src/main.rs @@ -80,15 +80,12 @@ async fn run_cli() -> Result<()> { println!("Deposit Address: {address}"); }, LiquidityProvider( - LiquidityProviderSubcommands::RegisterEmergencyWithdrawalAddress { - chain, - address, - }, + LiquidityProviderSubcommands::RegisterLiquidityRefundAddress { chain, address }, ) => { - let ewa_address = chainflip_api::clean_foreign_chain_address(chain, &address)?; + let lra_address = chainflip_api::clean_foreign_chain_address(chain, &address)?; let tx_hash = - api.lp_api().register_emergency_withdrawal_address(ewa_address).await?; - println!("Emergency Withdrawal Address registered. Tx hash: {tx_hash}"); + api.lp_api().register_liquidity_refund_address(lra_address).await?; + println!("Liquidity Refund address registered. Tx hash: {tx_hash}"); }, Redeem { amount, eth_address, executor } => { request_redemption(api, amount, eth_address, executor).await?; diff --git a/api/bin/chainflip-cli/src/settings.rs b/api/bin/chainflip-cli/src/settings.rs index 0e6cecf0fb4..5279e1fa0f6 100644 --- a/api/bin/chainflip-cli/src/settings.rs +++ b/api/bin/chainflip-cli/src/settings.rs @@ -82,9 +82,9 @@ pub enum LiquidityProviderSubcommands { /// Asset to deposit. asset: Asset, }, - /// Register an Emergency Withdrawal Address for the given chain. An address must be + /// Register an Liquidity Refund Address for the given chain. An address must be /// registered to request a deposit address for the given chain. - RegisterEmergencyWithdrawalAddress { chain: ForeignChain, address: String }, + RegisterLiquidityRefundAddress { chain: ForeignChain, address: String }, } #[derive(Parser, Clone, Debug)] diff --git a/api/bin/chainflip-lp-api/README.md b/api/bin/chainflip-lp-api/README.md index 70e4d0e690e..49af3b37ec4 100644 --- a/api/bin/chainflip-lp-api/README.md +++ b/api/bin/chainflip-lp-api/README.md @@ -87,11 +87,11 @@ Return: - Hex encoded deposit address. -### `lp_registerEmergencyWithdrawalAddress` +### `lp_registerLiquidityRefundAddress` Parameters: - Chain: the forein chain where the address belongs to -- Address: Address to be used as Emergency Withdrawal Address. +- Address: Address refunded liquidity will be send to. e.g. ["Ethereum", "1594300cbd587694AffD70c933B9eE9155B186d9"] diff --git a/api/bin/chainflip-lp-api/src/main.rs b/api/bin/chainflip-lp-api/src/main.rs index f7a98c265fe..fa1b6475a07 100644 --- a/api/bin/chainflip-lp-api/src/main.rs +++ b/api/bin/chainflip-lp-api/src/main.rs @@ -75,8 +75,8 @@ pub trait Rpc { asset: Asset, ) -> Result; - #[method(name = "registerEmergencyWithdrawalAddress")] - async fn register_emergency_withdrawal_address( + #[method(name = "registerLiquidityRefundAddress")] + async fn register_liquidity_refund_address( &self, chain: ForeignChain, address: &str, @@ -170,13 +170,13 @@ impl RpcServer for RpcServerImpl { .map(|address| address.to_string())?) } - async fn register_emergency_withdrawal_address( + async fn register_liquidity_refund_address( &self, chain: ForeignChain, address: &str, ) -> Result { let ewa_address = chainflip_api::clean_foreign_chain_address(chain, address)?; - Ok(self.api.lp_api().register_emergency_withdrawal_address(ewa_address).await?) + Ok(self.api.lp_api().register_liquidity_refund_address(ewa_address).await?) } /// Returns an egress id diff --git a/api/lib/src/lp.rs b/api/lib/src/lp.rs index e9041fa5b70..a2116f5cd0c 100644 --- a/api/lib/src/lp.rs +++ b/api/lib/src/lp.rs @@ -99,15 +99,15 @@ impl LpApi for StateChainClient {} #[async_trait] pub trait LpApi: SignedExtrinsicApi { - async fn register_emergency_withdrawal_address(&self, address: EncodedAddress) -> Result { + async fn register_liquidity_refund_address(&self, address: EncodedAddress) -> Result { let (tx_hash, ..) = self .submit_signed_extrinsic(RuntimeCall::from( - pallet_cf_lp::Call::register_emergency_withdrawal_address { address }, + pallet_cf_lp::Call::register_liquidity_refund_address { address }, )) .await .until_finalized() .await - .context("Registration for Emergency Withdrawal address failed.")?; + .context("Registration for Liquidity Refund Address failed.")?; Ok(tx_hash) } diff --git a/bouncer/shared/provide_liquidity.ts b/bouncer/shared/provide_liquidity.ts index de338aa49f4..a91d052868e 100644 --- a/bouncer/shared/provide_liquidity.ts +++ b/bouncer/shared/provide_liquidity.ts @@ -20,23 +20,22 @@ export async function provideLiquidity(ccy: Asset, amount: number) { const lpUri = process.env.LP_URI || '//LP_1'; const lp = keyring.createFromUri(lpUri); - // If no emergency withdrawal address is registered, then do that now + // If no liquidity refund address is registered, then do that now if ( ( - await chainflip.query.liquidityProvider.emergencyWithdrawalAddress( + await chainflip.query.liquidityProvider.liquidityRefundAddress( lp.address, chainContractIds[assetChains[ccy]], ) ).toJSON() === null ) { - let emergencyAddress = await newAddress(assetToChain(ccy).toUpperCase() as Asset, 'LP_1'); - emergencyAddress = - ccy === 'DOT' ? decodeDotAddressForContract(emergencyAddress) : emergencyAddress; + let refundAddress = await newAddress(assetToChain(ccy).toUpperCase() as Asset, 'LP_1'); + refundAddress = ccy === 'DOT' ? decodeDotAddressForContract(refundAddress) : refundAddress; - console.log('Registering Emergency Withdrawal Address for ' + ccy + ': ' + emergencyAddress); + console.log('Registering Liquidity Refund Address for ' + ccy + ': ' + refundAddress); await lpMutex.runExclusive(async () => { await chainflip.tx.liquidityProvider - .registerEmergencyWithdrawalAddress({ [assetToChain(ccy)]: emergencyAddress }) + .registerLiquidityRefundAddress({ [assetToChain(ccy)]: refundAddress }) .signAndSend(lp, { nonce: -1 }, handleSubstrateError(chainflip)); }); } diff --git a/bouncer/tests/double_deposit.ts b/bouncer/tests/double_deposit.ts index 6abf36021f4..8f2cac7e6ea 100755 --- a/bouncer/tests/double_deposit.ts +++ b/bouncer/tests/double_deposit.ts @@ -33,12 +33,12 @@ async function main(): Promise { }, }); - // Register Emergency Withdrawal Address before requesting reposit address. + // Register Liquidity Refund Address before requesting reposit address. const encodedEthAddr = chainflip.createType('EncodedAddress', { Eth: hexStringToBytesArray(await newAddress('ETH', 'LP_1')), }); await chainflip.tx.liquidityProvider - .registerEmergencyWithdrawalAddress(encodedEthAddr) + .registerLiquidityRefundAddress(encodedEthAddr) .signAndSend(lp); await chainflip.tx.liquidityProvider.requestLiquidityDepositAddress('Eth').signAndSend(lp); diff --git a/state-chain/pallets/cf-lp/src/benchmarking.rs b/state-chain/pallets/cf-lp/src/benchmarking.rs index 3315462ecf5..a341899a2c4 100644 --- a/state-chain/pallets/cf-lp/src/benchmarking.rs +++ b/state-chain/pallets/cf-lp/src/benchmarking.rs @@ -13,7 +13,7 @@ benchmarks! { let caller: T::AccountId = whitelisted_caller(); ::OnNewAccount::on_new_account(&caller); ::AccountRoleRegistry::register_as_liquidity_provider(&caller).unwrap(); - let _ = Pallet::::register_emergency_withdrawal_address( + let _ = Pallet::::register_liquidity_refund_address( RawOrigin::Signed(caller.clone()).into(), EncodedAddress::Eth(Default::default()), ); @@ -46,7 +46,7 @@ benchmarks! { let caller: T::AccountId = whitelisted_caller(); ::OnNewAccount::on_new_account(&caller); let _ = Pallet::::register_lp_account(RawOrigin::Signed(caller.clone()).into()); - let _ = Pallet::::register_emergency_withdrawal_address( + let _ = Pallet::::register_liquidity_refund_address( RawOrigin::Signed(caller.clone()).into(), EncodedAddress::Eth(Default::default()), ); @@ -72,13 +72,13 @@ benchmarks! { assert_eq!(crate::LpTTL::::get(), ttl); } - register_emergency_withdrawal_address { + register_liquidity_refund_address { let caller: T::AccountId = whitelisted_caller(); ::OnNewAccount::on_new_account(&caller); ::AccountRoleRegistry::register_as_liquidity_provider(&caller).unwrap(); }: _(RawOrigin::Signed(caller.clone()), EncodedAddress::Eth([0x01; 20])) verify { - assert_eq!(EmergencyWithdrawalAddress::::get(caller, ForeignChain::Ethereum), Some(ForeignChainAddress::Eth([0x01; 20].into()))); + assert_eq!(LiquidityRefundAddress::::get(caller, ForeignChain::Ethereum), Some(ForeignChainAddress::Eth([0x01; 20].into()))); } impl_benchmark_test_suite!( diff --git a/state-chain/pallets/cf-lp/src/lib.rs b/state-chain/pallets/cf-lp/src/lib.rs index d1c36ac34d7..be0391a7be1 100644 --- a/state-chain/pallets/cf-lp/src/lib.rs +++ b/state-chain/pallets/cf-lp/src/lib.rs @@ -74,9 +74,9 @@ pub mod pallet { InvalidEgressAddress, // Then given encoded address cannot be decoded into a valid ForeignChainAddress. InvalidEncodedAddress, - // An emergency withdrawal address must be set by the user for the chain before + // An liquidity refund address must be set by the user for the chain before // deposit address can be requested. - NoEmergencyWithdrawalAddressRegistered, + NoLiquidityRefundAddressRegistered, // Liquidity deposit is disabled due to Safe Mode. LiquidityDepositDisabled, // Withdrawals are disabled due to Safe Mode. @@ -128,7 +128,7 @@ pub mod pallet { LpTtlSet { ttl: BlockNumberFor, }, - EmergencyWithdrawalAddressRegistered { + LiquidityRefundAddressRegistered { account_id: T::AccountId, chain: ForeignChain, address: ForeignChainAddress, @@ -175,7 +175,7 @@ pub mod pallet { /// Stores the registered energency withdrawal address for an Account #[pallet::storage] - pub type EmergencyWithdrawalAddress = StorageDoubleMap< + pub type LiquidityRefundAddress = StorageDoubleMap< _, Identity, T::AccountId, @@ -203,11 +203,8 @@ pub mod pallet { let account_id = T::AccountRoleRegistry::ensure_liquidity_provider(origin)?; ensure!( - EmergencyWithdrawalAddress::::contains_key( - &account_id, - ForeignChain::from(asset) - ), - Error::::NoEmergencyWithdrawalAddressRegistered + LiquidityRefundAddress::::contains_key(&account_id, ForeignChain::from(asset)), + Error::::NoLiquidityRefundAddressRegistered ); let expiry_block = @@ -311,15 +308,15 @@ pub mod pallet { Ok(()) } - /// Registers an Emergency Withdrawal Address (EWA) for an account. - /// To request deposit address for a chain, an EWA must be registered for that chain. + /// Registers an Liquidity Refund Address(LRA) for an account. + /// To request deposit address for a chain, an LRA must be registered for that chain. /// /// ## Events /// - /// - [On Success](Event::EmergencyWithdrawalAddressRegistered) + /// - [On Success](Event::LiquidityRefundAddressRegistered) #[pallet::call_index(4)] - #[pallet::weight(T::WeightInfo::register_emergency_withdrawal_address())] - pub fn register_emergency_withdrawal_address( + #[pallet::weight(T::WeightInfo::register_liquidity_refund_address())] + pub fn register_liquidity_refund_address( origin: OriginFor, address: EncodedAddress, ) -> DispatchResult { @@ -328,13 +325,13 @@ pub mod pallet { let decoded_address = T::AddressConverter::try_from_encoded_address(address) .map_err(|()| Error::::InvalidEncodedAddress)?; - EmergencyWithdrawalAddress::::insert( + LiquidityRefundAddress::::insert( &account_id, decoded_address.chain(), decoded_address.clone(), ); - Self::deposit_event(Event::::EmergencyWithdrawalAddressRegistered { + Self::deposit_event(Event::::LiquidityRefundAddressRegistered { account_id, chain: decoded_address.chain(), address: decoded_address, diff --git a/state-chain/pallets/cf-lp/src/tests.rs b/state-chain/pallets/cf-lp/src/tests.rs index 822570b09cc..f9c7f2c7a09 100644 --- a/state-chain/pallets/cf-lp/src/tests.rs +++ b/state-chain/pallets/cf-lp/src/tests.rs @@ -1,4 +1,4 @@ -use crate::{mock::*, EmergencyWithdrawalAddress, FreeBalances, LiquidityChannelExpiries, LpTTL}; +use crate::{mock::*, FreeBalances, LiquidityChannelExpiries, LiquidityRefundAddress, LpTTL}; use cf_chains::{ address::{AddressConverter, EncodedAddress}, @@ -72,7 +72,7 @@ fn liquidity_providers_can_withdraw_asset() { fn cannot_deposit_and_withdrawal_during_safe_mode() { new_test_ext().execute_with(|| { FreeBalances::::insert(AccountId::from(LP_ACCOUNT), Asset::Eth, 1_000); - assert_ok!(LiquidityProvider::register_emergency_withdrawal_address( + assert_ok!(LiquidityProvider::register_liquidity_refund_address( RuntimeOrigin::signed(LP_ACCOUNT.into()), EncodedAddress::Eth(Default::default()), )); @@ -121,7 +121,7 @@ fn cannot_deposit_and_withdrawal_during_safe_mode() { #[test] fn deposit_channel_expires() { new_test_ext().execute_with(|| { - assert_ok!(LiquidityProvider::register_emergency_withdrawal_address( + assert_ok!(LiquidityProvider::register_liquidity_refund_address( RuntimeOrigin::signed(LP_ACCOUNT.into()), EncodedAddress::Eth(Default::default()), )); @@ -186,34 +186,28 @@ fn can_set_lp_ttl() { } #[test] -fn can_register_and_deregister_emergency_withdrawal_address() { +fn can_register_and_deregister_liquidity_refund_address() { new_test_ext().execute_with(|| { let account_id = AccountId::from(LP_ACCOUNT); let encoded_address = EncodedAddress::Eth([0x01; 20]); let decoded_address = ForeignChainAddress::Eth([0x01; 20].into()); - assert!( - EmergencyWithdrawalAddress::::get(&account_id, ForeignChain::Ethereum).is_none() - ); + assert!(LiquidityRefundAddress::::get(&account_id, ForeignChain::Ethereum).is_none()); // Can register EWA - assert_ok!(LiquidityProvider::register_emergency_withdrawal_address( + assert_ok!(LiquidityProvider::register_liquidity_refund_address( RuntimeOrigin::signed(account_id.clone()), encoded_address )); assert_eq!( - EmergencyWithdrawalAddress::::get(&account_id, ForeignChain::Ethereum), + LiquidityRefundAddress::::get(&account_id, ForeignChain::Ethereum), Some(decoded_address.clone()) ); // Other chain should be unaffected. - assert!( - EmergencyWithdrawalAddress::::get(&account_id, ForeignChain::Polkadot).is_none() - ); - assert!( - EmergencyWithdrawalAddress::::get(&account_id, ForeignChain::Bitcoin).is_none() - ); + assert!(LiquidityRefundAddress::::get(&account_id, ForeignChain::Polkadot).is_none()); + assert!(LiquidityRefundAddress::::get(&account_id, ForeignChain::Bitcoin).is_none()); System::assert_last_event(RuntimeEvent::LiquidityProvider( - crate::Event::::EmergencyWithdrawalAddressRegistered { + crate::Event::::LiquidityRefundAddressRegistered { account_id: account_id.clone(), chain: ForeignChain::Ethereum, address: decoded_address, @@ -224,16 +218,16 @@ fn can_register_and_deregister_emergency_withdrawal_address() { let encoded_address = EncodedAddress::Eth([0x05; 20]); let decoded_address = ForeignChainAddress::Eth([0x05; 20].into()); - assert_ok!(LiquidityProvider::register_emergency_withdrawal_address( + assert_ok!(LiquidityProvider::register_liquidity_refund_address( RuntimeOrigin::signed(account_id.clone()), encoded_address, )); assert_eq!( - EmergencyWithdrawalAddress::::get(&account_id, ForeignChain::Ethereum), + LiquidityRefundAddress::::get(&account_id, ForeignChain::Ethereum), Some(decoded_address.clone()), ); System::assert_last_event(RuntimeEvent::LiquidityProvider( - crate::Event::::EmergencyWithdrawalAddressRegistered { + crate::Event::::LiquidityRefundAddressRegistered { account_id, chain: ForeignChain::Ethereum, address: decoded_address, @@ -243,15 +237,15 @@ fn can_register_and_deregister_emergency_withdrawal_address() { } #[test] -fn cannot_request_deposit_address_without_registering_emergency_withdrawal_address() { +fn cannot_request_deposit_address_without_registering_liquidity_refund_address() { new_test_ext().execute_with(|| { assert_noop!(LiquidityProvider::request_liquidity_deposit_address( RuntimeOrigin::signed(LP_ACCOUNT.into()), Asset::Eth, - ), crate::Error::::NoEmergencyWithdrawalAddressRegistered); + ), crate::Error::::NoLiquidityRefundAddressRegistered); // Register EWA - assert_ok!(LiquidityProvider::register_emergency_withdrawal_address( + assert_ok!(LiquidityProvider::register_liquidity_refund_address( RuntimeOrigin::signed(LP_ACCOUNT.into()), EncodedAddress::Eth([0x01; 20]) )); @@ -282,10 +276,10 @@ fn cannot_request_deposit_address_without_registering_emergency_withdrawal_addre assert_noop!(LiquidityProvider::request_liquidity_deposit_address( RuntimeOrigin::signed(LP_ACCOUNT.into()), Asset::Btc, - ), crate::Error::::NoEmergencyWithdrawalAddressRegistered); + ), crate::Error::::NoLiquidityRefundAddressRegistered); assert_noop!(LiquidityProvider::request_liquidity_deposit_address( RuntimeOrigin::signed(LP_ACCOUNT.into()), Asset::Dot, - ), crate::Error::::NoEmergencyWithdrawalAddressRegistered); + ), crate::Error::::NoLiquidityRefundAddressRegistered); }); } diff --git a/state-chain/pallets/cf-lp/src/weights.rs b/state-chain/pallets/cf-lp/src/weights.rs index fa980179901..f56ba0d79f3 100644 --- a/state-chain/pallets/cf-lp/src/weights.rs +++ b/state-chain/pallets/cf-lp/src/weights.rs @@ -35,7 +35,7 @@ pub trait WeightInfo { fn register_lp_account() -> Weight; fn on_initialize(a: u32, ) -> Weight; fn set_lp_ttl() -> Weight; - fn register_emergency_withdrawal_address() -> Weight; + fn register_liquidity_refund_address() -> Weight; } /// Weights for pallet_cf_lp using the Substrate node and recommended hardware. @@ -98,7 +98,7 @@ impl WeightInfo for PalletWeight { Weight::from_parts(14_000_000, 0) .saturating_add(T::DbWeight::get().writes(1)) } - fn register_emergency_withdrawal_address() -> Weight { + fn register_liquidity_refund_address() -> Weight { Weight::from_parts(1_000_000, 0) } } @@ -162,7 +162,7 @@ impl WeightInfo for () { Weight::from_parts(14_000_000, 0) .saturating_add(RocksDbWeight::get().writes(1)) } - fn register_emergency_withdrawal_address() -> Weight { + fn register_liquidity_refund_address() -> Weight { Weight::from_parts(1_000_000, 0) } }