From b3d935351e99f2ec3aff4a1cbfd197b273075b62 Mon Sep 17 00:00:00 2001 From: Roy Yang Date: Fri, 17 Jan 2025 03:27:48 +1300 Subject: [PATCH 1/4] chore: add versioning to Solana's ccm additional data (#5558) * WIP Added a V0 wrapper for Solana's CCM additional data. * Updated bouncer definition to add the V0 wrapper * chore: small renaming * chore: nit --------- Co-authored-by: albert --- bouncer/shared/swapping.ts | 11 +++- bouncer/shared/utils.ts | 13 ++-- .../cf-integration-tests/src/solana.rs | 10 +-- state-chain/chains/src/ccm_checker.rs | 65 ++++++++++++------- state-chain/chains/src/sol/api.rs | 11 ++-- .../chains/src/sol/instruction_builder.rs | 4 +- state-chain/chains/src/sol/sol_tx_core.rs | 9 ++- state-chain/runtime/src/lib.rs | 4 +- 8 files changed, 78 insertions(+), 49 deletions(-) diff --git a/bouncer/shared/swapping.ts b/bouncer/shared/swapping.ts index e6de975832..f024eff2fc 100644 --- a/bouncer/shared/swapping.ts +++ b/bouncer/shared/swapping.ts @@ -8,7 +8,7 @@ import { chainFromAsset, getContractAddress, ccmSupportedChains, - solCcmAdditionalDataCodec, + solVersionedCcmAdditionalDataCodec, } from '../shared/utils'; import { BtcAddressType } from '../shared/new_btc_address'; import { CcmDepositMetadata } from '../shared/new_swap'; @@ -32,7 +32,7 @@ export function newSolanaCcmAdditionalData(maxAccounts: number) { }); } - const cfParameters = { + const ccmAccounts = { cf_receiver: { pubkey: new PublicKey(cfReceiverAddress).toBytes(), is_writable: false, @@ -41,7 +41,12 @@ export function newSolanaCcmAdditionalData(maxAccounts: number) { fallback_address: fallbackAddress, }; - return u8aToHex(solCcmAdditionalDataCodec.enc(cfParameters)); + return u8aToHex( + solVersionedCcmAdditionalDataCodec.enc({ + tag: 'V0', + value: ccmAccounts, + }), + ); } // Generate random bytes. Setting a minimum length of 10 because very short messages can end up diff --git a/bouncer/shared/utils.ts b/bouncer/shared/utils.ts index c72e180003..4c2ab871f8 100644 --- a/bouncer/shared/utils.ts +++ b/bouncer/shared/utils.ts @@ -17,7 +17,7 @@ import { import Web3 from 'web3'; import { Connection, Keypair, PublicKey } from '@solana/web3.js'; import { hexToU8a, u8aToHex, BN } from '@polkadot/util'; -import { Vector, bool, Struct, Bytes as TsBytes } from 'scale-ts'; +import { Vector, bool, Struct, Enum, Bytes as TsBytes } from 'scale-ts'; import BigNumber from 'bignumber.js'; import { EventParser, BorshCoder } from '@coral-xyz/anchor'; import { ISubmittableResult } from '@polkadot/types/types'; @@ -63,7 +63,7 @@ const isSDKChain = (chain: Chain): chain is SDKChain => chain in chainConstants; export const solanaNumberOfNonces = 10; -export const solCcmAdditionalDataCodec = Struct({ +const solCcmAccountsCodec = Struct({ cf_receiver: Struct({ pubkey: TsBytes(32), is_writable: bool, @@ -77,6 +77,10 @@ export const solCcmAdditionalDataCodec = Struct({ fallback_address: TsBytes(32), }); +export const solVersionedCcmAdditionalDataCodec = Enum({ + V0: solCcmAccountsCodec, +}); + export function getContractAddress(chain: Chain, contract: string): string { switch (chain) { case 'Ethereum': @@ -807,9 +811,8 @@ export async function observeSolanaCcmEvent( // The message is being used as the main discriminator if (matchEventName && matchSourceChain && matchMessage) { - const { remaining_accounts: expectedRemainingAccounts } = solCcmAdditionalDataCodec.dec( - messageMetadata.ccmAdditionalData!, - ); + const { remaining_accounts: expectedRemainingAccounts } = + solVersionedCcmAdditionalDataCodec.dec(messageMetadata.ccmAdditionalData!).value; if ( expectedRemainingAccounts.length !== event.data.remaining_is_writable.length || diff --git a/state-chain/cf-integration-tests/src/solana.rs b/state-chain/cf-integration-tests/src/solana.rs index d1369b6574..e15828821b 100644 --- a/state-chain/cf-integration-tests/src/solana.rs +++ b/state-chain/cf-integration-tests/src/solana.rs @@ -6,7 +6,7 @@ use super::*; use cf_chains::{ address::{AddressConverter, AddressDerivationApi, EncodedAddress}, assets::{any::Asset, sol::Asset as SolAsset}, - ccm_checker::CcmValidityError, + ccm_checker::{CcmValidityError, VersionedSolanaCcmAdditionalData}, sol::{ api::{SolanaApi, SolanaEnvironment, SolanaTransactionBuildingError}, sol_tx_core::sol_test_values, @@ -490,14 +490,14 @@ fn solana_ccm_fails_with_invalid_input() { channel_metadata: CcmChannelMetadata { message: vec![0u8, 1u8, 2u8, 3u8].try_into().unwrap(), gas_budget: 0u128, - ccm_additional_data: SolCcmAccounts { + ccm_additional_data: VersionedSolanaCcmAdditionalData::V0(SolCcmAccounts { cf_receiver: SolCcmAddress { pubkey: receiver.into(), is_writable: true }, remaining_accounts: vec![ SolCcmAddress { pubkey: SolPubkey([0x01; 32]), is_writable: false }, SolCcmAddress { pubkey: SolPubkey([0x02; 32]), is_writable: false }, ], fallback_address: FALLBACK_ADDRESS.into(), - } + }) .encode() .try_into() .unwrap(), @@ -706,14 +706,14 @@ fn solana_ccm_execution_error_can_trigger_fallback() { channel_metadata: CcmChannelMetadata { message: vec![0u8, 1u8, 2u8, 3u8].try_into().unwrap(), gas_budget: 1_000_000_000u128, - ccm_additional_data: SolCcmAccounts { + ccm_additional_data: VersionedSolanaCcmAdditionalData::V0(SolCcmAccounts { cf_receiver: SolCcmAddress { pubkey: SolPubkey([0x10; 32]), is_writable: true }, remaining_accounts: vec![ SolCcmAddress { pubkey: SolPubkey([0x01; 32]), is_writable: false }, SolCcmAddress { pubkey: SolPubkey([0x02; 32]), is_writable: false }, ], fallback_address: FALLBACK_ADDRESS.into(), - } + }) .encode() .try_into() .unwrap(), diff --git a/state-chain/chains/src/ccm_checker.rs b/state-chain/chains/src/ccm_checker.rs index d4d403bc4f..fdcb9e4e6b 100644 --- a/state-chain/chains/src/ccm_checker.rs +++ b/state-chain/chains/src/ccm_checker.rs @@ -41,10 +41,15 @@ pub trait CcmValidityCheck { } } -#[derive(Clone, Debug, PartialEq, Eq)] +#[derive(Clone, Debug, Decode, PartialEq, Eq)] pub enum DecodedCcmAdditionalData { - Solana(SolCcmAccounts), NotRequired, + Solana(VersionedSolanaCcmAdditionalData), +} + +#[derive(Clone, Debug, Encode, Decode, PartialEq, Eq)] +pub enum VersionedSolanaCcmAdditionalData { + V0(SolCcmAccounts), } pub struct CcmValidityChecker; @@ -58,25 +63,33 @@ impl CcmValidityCheck for CcmValidityChecker { egress_asset: Asset, ) -> Result { if ForeignChain::from(egress_asset) == ForeignChain::Solana { - // Check if the cf_parameter can be decoded - let ccm_accounts = SolCcmAccounts::decode(&mut &ccm.ccm_additional_data.clone()[..]) - .map_err(|_| CcmValidityError::CannotDecodeCcmAdditionalData)?; let asset: SolAsset = egress_asset .try_into() .expect("Only Solana chain's asset will be checked. This conversion must succeed."); - // Length of CCM = length of message + total no. remaining_accounts * constant; - let ccm_length = - ccm.message.len() + ccm_accounts.remaining_accounts.len() * CCM_BYTES_PER_ACCOUNT; - if ccm_length > - match asset { - SolAsset::Sol => MAX_CCM_BYTES_SOL, - SolAsset::SolUsdc => MAX_CCM_BYTES_USDC, - } { - return Err(CcmValidityError::CcmIsTooLong) - } + // Check if the cf_parameter can be decoded + match VersionedSolanaCcmAdditionalData::decode( + &mut &ccm.ccm_additional_data.clone()[..], + ) + .map_err(|_| CcmValidityError::CannotDecodeCcmAdditionalData)? + { + VersionedSolanaCcmAdditionalData::V0(ccm_accounts) => { + // Length of CCM = length of message + total no. remaining_accounts * constant; + let ccm_length = ccm.message.len() + + ccm_accounts.remaining_accounts.len() * CCM_BYTES_PER_ACCOUNT; + if ccm_length > + match asset { + SolAsset::Sol => MAX_CCM_BYTES_SOL, + SolAsset::SolUsdc => MAX_CCM_BYTES_USDC, + } { + return Err(CcmValidityError::CcmIsTooLong) + } - Ok(DecodedCcmAdditionalData::Solana(ccm_accounts)) + Ok(DecodedCcmAdditionalData::Solana(VersionedSolanaCcmAdditionalData::V0( + ccm_accounts, + ))) + }, + } } else if !ccm.ccm_additional_data.is_empty() { Err(CcmValidityError::RedundantDataSupplied) } else { @@ -115,7 +128,9 @@ mod test { let ccm = sol_test_values::ccm_parameter().channel_metadata; assert_eq!( CcmValidityChecker::check_and_decode(&ccm, Asset::Sol), - Ok(DecodedCcmAdditionalData::Solana(sol_test_values::ccm_accounts())) + Ok(DecodedCcmAdditionalData::Solana(VersionedSolanaCcmAdditionalData::V0( + sol_test_values::ccm_accounts() + ))) ); } @@ -138,11 +153,11 @@ mod test { let ccm = || CcmChannelMetadata { message: vec![0x01; MAX_CCM_BYTES_SOL].try_into().unwrap(), gas_budget: 0, - ccm_additional_data: SolCcmAccounts { + ccm_additional_data: VersionedSolanaCcmAdditionalData::V0(SolCcmAccounts { cf_receiver: SolCcmAddress { pubkey: SolPubkey([0x01; 32]), is_writable: true }, remaining_accounts: vec![], fallback_address: SolPubkey([0xf0; 32]), - } + }) .encode() .try_into() .unwrap(), @@ -158,14 +173,14 @@ mod test { ); let mut invalid_ccm = ccm(); - invalid_ccm.ccm_additional_data = SolCcmAccounts { + invalid_ccm.ccm_additional_data = VersionedSolanaCcmAdditionalData::V0(SolCcmAccounts { cf_receiver: SolCcmAddress { pubkey: SolPubkey([0x01; 32]), is_writable: true }, remaining_accounts: vec![SolCcmAddress { pubkey: SolPubkey([0x01; 32]), is_writable: true, }], fallback_address: SolPubkey([0xf0; 32]), - } + }) .encode() .try_into() .unwrap(); @@ -180,11 +195,11 @@ mod test { let ccm = || CcmChannelMetadata { message: vec![0x01; MAX_CCM_BYTES_USDC].try_into().unwrap(), gas_budget: 0, - ccm_additional_data: SolCcmAccounts { + ccm_additional_data: VersionedSolanaCcmAdditionalData::V0(SolCcmAccounts { cf_receiver: SolCcmAddress { pubkey: SolPubkey([0x01; 32]), is_writable: true }, fallback_address: SolPubkey([0xf0; 32]), remaining_accounts: vec![], - } + }) .encode() .try_into() .unwrap(), @@ -200,14 +215,14 @@ mod test { ); let mut invalid_ccm = ccm(); - invalid_ccm.ccm_additional_data = SolCcmAccounts { + invalid_ccm.ccm_additional_data = VersionedSolanaCcmAdditionalData::V0(SolCcmAccounts { cf_receiver: SolCcmAddress { pubkey: SolPubkey([0x01; 32]), is_writable: true }, remaining_accounts: vec![SolCcmAddress { pubkey: SolPubkey([0x01; 32]), is_writable: true, }], fallback_address: SolPubkey([0xf0; 32]), - } + }) .encode() .try_into() .unwrap(); diff --git a/state-chain/chains/src/sol/api.rs b/state-chain/chains/src/sol/api.rs index 9c1ee73942..7119039133 100644 --- a/state-chain/chains/src/sol/api.rs +++ b/state-chain/chains/src/sol/api.rs @@ -12,7 +12,7 @@ use sp_std::{vec, vec::Vec}; use crate::{ ccm_checker::{ check_ccm_for_blacklisted_accounts, CcmValidityCheck, CcmValidityChecker, CcmValidityError, - DecodedCcmAdditionalData, + DecodedCcmAdditionalData, VersionedSolanaCcmAdditionalData, }, sol::{ transaction_builder::SolanaTransactionBuilder, SolAddress, SolAmount, SolApiEnvironment, @@ -350,7 +350,7 @@ impl SolanaApi { ) -> Result { // For extra safety, re-verify the validity of the CCM message here // and extract the decoded `ccm_accounts` from `ccm_additional_data`. - let decoded_cf_params = CcmValidityChecker::check_and_decode( + let decoded_ccm_additional_data = CcmValidityChecker::check_and_decode( &CcmChannelMetadata { message: message .clone() @@ -368,9 +368,12 @@ impl SolanaApi { // Always expects the `DecodedCcmAdditionalData::Solana(..)` variant of the decoded cf // params. - let ccm_accounts = if let DecodedCcmAdditionalData::Solana(ccm_accounts) = decoded_cf_params + let ccm_accounts = if let DecodedCcmAdditionalData::Solana(versioned_sol_data) = + decoded_ccm_additional_data { - Ok(ccm_accounts) + match versioned_sol_data { + VersionedSolanaCcmAdditionalData::V0(ccm_accounts) => Ok(ccm_accounts), + } } else { Err(SolanaTransactionBuildingError::InvalidCcm( CcmValidityError::CannotDecodeCcmAdditionalData, diff --git a/state-chain/chains/src/sol/instruction_builder.rs b/state-chain/chains/src/sol/instruction_builder.rs index 4b71501922..edf8473ac6 100644 --- a/state-chain/chains/src/sol/instruction_builder.rs +++ b/state-chain/chains/src/sol/instruction_builder.rs @@ -261,7 +261,7 @@ mod test { FROM.into(), ); - let expected_serialized_tx = hex_literal::hex!("02bbf3ca52ee11d2e8fa7bdec12f1099dc6ebd68b33ec490e6805d2f37396fe22b7e04ce39f58f2ac276a8ca53c261a86d9f0b0f6d15bd0c2a71c529fbc04d8c04ad36b9b7e45512eb9de33761013387dc3ce8115713d4086fed0e6b1752c5102da951f5b1f2e31c4185c865c948c27ac312019af07cce26ae598c1678110e1f0702000307cf2a079e1506b29d02c8feac98d589a9059a740891dcd3dab6c64b3160bc28317f799121d6c125f312c5f423a51959ce1d41df06af977e9a17f48b2c82ecf89f1c1f0efc91eeb48bb80c90cf97775cd5d843a96f16500266cee2c20d053152d2f79d5e026f12edc6443a534b2cdd5072233989b415d7596573e743f3e5b386fb00000000000000000000000000000000000000000000000000000000000000001ef91c791d2aa8492c90f12540abd10056ce5dd8d9ab08461476c1dcc1622938a1e031c8bc9bec3b610cf7b36eb3bf3aa40237c9e5be2c7893878578439eb00b0000000000000000000000000000000000000000000000000000000000000000010506060300010204ad02a3265ce2f3698dc4d20296490000000005000000200000009e0d6a70e12d54edf90971cc977fa26a1d3bb4b0b26e72470171c36b0006b01f0a00000001040000007c1d0f070000000000000000dc000000008d017417da8b99d7748127a76b03d61fee69c80dfef73ad2d5503737beedc5a9ed480104a73bdf31e341218a693b8772c43ecfcecd4cf35fada09a87ea0f860d028168e50090e0b0f5b60147b325842c1fc68f6c90fe26419ea7c4afeb982f71f1f54b5b440a000000049e0d6a70e12d54edf90971cc977fa26a1d3bb4b0b26e72470171c36b0006b01f0000000000000000000000000000000000000000000000000000000000000000010a0000001400000002a0edda1a4beee4fe2df32c0802aa6759da49ae6165fcdb5c40d7f4cd5a30db0e010008010a0214").to_vec(); + let expected_serialized_tx = hex_literal::hex!("02b0f0eb7b671ca7af132904f3f349accba018d93f90c2e73a8ea566e88a9bb3590a72ee8ccdbc8e308807e8487839a7a89e1920c4f15f1941ef760a3e07596b029a3fc1c1ad1d27a5fc227808bfcfbb447294aa7b5dbf156aeb2092a5745f0c7e4d8580a8757be3223dfbdbdd0cc60937418b597d229774b6ec6622a9adee0a0e02000307cf2a079e1506b29d02c8feac98d589a9059a740891dcd3dab6c64b3160bc28317f799121d6c125f312c5f423a51959ce1d41df06af977e9a17f48b2c82ecf89f1c1f0efc91eeb48bb80c90cf97775cd5d843a96f16500266cee2c20d053152d2f79d5e026f12edc6443a534b2cdd5072233989b415d7596573e743f3e5b386fb00000000000000000000000000000000000000000000000000000000000000001ef91c791d2aa8492c90f12540abd10056ce5dd8d9ab08461476c1dcc1622938a1e031c8bc9bec3b610cf7b36eb3bf3aa40237c9e5be2c7893878578439eb00b0000000000000000000000000000000000000000000000000000000000000000010506060300010204ae02a3265ce2f3698dc4d20296490000000005000000200000009e0d6a70e12d54edf90971cc977fa26a1d3bb4b0b26e72470171c36b0006b01f0a00000001040000007c1d0f070000000000000000dd000000009101007417da8b99d7748127a76b03d61fee69c80dfef73ad2d5503737beedc5a9ed480104a73bdf31e341218a693b8772c43ecfcecd4cf35fada09a87ea0f860d028168e50090e0b0f5b60147b325842c1fc68f6c90fe26419ea7c4afeb982f71f1f54b5b440a000000049e0d6a70e12d54edf90971cc977fa26a1d3bb4b0b26e72470171c36b0006b01f0000000000000000000000000000000000000000000000000000000000000000010a0000001400000002a0edda1a4beee4fe2df32c0802aa6759da49ae6165fcdb5c40d7f4cd5a30db0e010008010a0214").to_vec(); let from_signing_key = SolSigningKey::from_bytes(&FROM_KEY_BYTES).unwrap(); let event_data_account_signing_key = @@ -343,7 +343,7 @@ mod test { FROM.into(), ); - let expected_serialized_tx = hex_literal::hex!("023e5b1a678b28f8b654115fd642b2cc79787987801e1b1dc1a0ef70a0152d9031bee0790147cca8ecaadd97a8e59b4526782f0f37ec399e5247bd5cd5f6838b07509dedd300d554befdee2208f5b634b1c34200aecaf632a072e3afe36a9afd75f0dc66b0cc5a8a89c0cc40ab81762d959f473c16fb7afad098e6a6b7429219000200060bcf2a079e1506b29d02c8feac98d589a9059a740891dcd3dab6c64b3160bc28317f799121d6c125f312c5f423a51959ce1d41df06af977e9a17f48b2c82ecf89f1c1f0efc91eeb48bb80c90cf97775cd5d843a96f16500266cee2c20d053152d227fefc7ec198ef3eacb0f17871e1fad81f07a40cd55f4f364c3915877d89bd8ae91372b3d301c202a633da0a92365a736e462131aecfad1fac47322cf8863ada000000000000000000000000000000000000000000000000000000000000000006ddf6e1d765a193d9cbe146ceeb79ac1cb485ed5f5b37913a8cf5857eff00a90fb9ba52b1f09445f1e3a7508d59f0797923acf744fbe2da303fb06da859ee871ef91c791d2aa8492c90f12540abd10056ce5dd8d9ab08461476c1dcc16229382e9acf1ff8568fbe655e616a167591aeedc250afbc88d759ec959b1982e8769ca1e031c8bc9bec3b610cf7b36eb3bf3aa40237c9e5be2c7893878578439eb00b000000000000000000000000000000000000000000000000000000000000000001080a0a040003010209060705ae024532fc63e55377ebd20296490000000005000000200000009e0d6a70e12d54edf90971cc977fa26a1d3bb4b0b26e72470171c36b0006b01f0900000001040000007c1d0f070000000000000000dc000000008d017417da8b99d7748127a76b03d61fee69c80dfef73ad2d5503737beedc5a9ed480104a73bdf31e341218a693b8772c43ecfcecd4cf35fada09a87ea0f860d028168e50090e0b0f5b60147b325842c1fc68f6c90fe26419ea7c4afeb982f71f1f54b5b440a000000049e0d6a70e12d54edf90971cc977fa26a1d3bb4b0b26e72470171c36b0006b01f0000000000000000000000000000000000000000000000000000000000000000010a0000001400000002a0edda1a4beee4fe2df32c0802aa6759da49ae6165fcdb5c40d7f4cd5a30db0e010008010a021406").to_vec(); + let expected_serialized_tx = hex_literal::hex!("02f67f0e322569f5497d6703f08d43ddaa84b617589d4dffb1825f50bd7ba23835ac6b00074a49f2c9324ea4652a8e335394cc290d472bc52e61671c6851109605d89e6841c5499e0f30744855f8f516fd3794a4a5c2f34c4fbbfc02505b3c1a8af193e4e66218d59795d9038816fc95d35ba960f2ba13bd65e8e77a745a74540c0200060bcf2a079e1506b29d02c8feac98d589a9059a740891dcd3dab6c64b3160bc28317f799121d6c125f312c5f423a51959ce1d41df06af977e9a17f48b2c82ecf89f1c1f0efc91eeb48bb80c90cf97775cd5d843a96f16500266cee2c20d053152d227fefc7ec198ef3eacb0f17871e1fad81f07a40cd55f4f364c3915877d89bd8ae91372b3d301c202a633da0a92365a736e462131aecfad1fac47322cf8863ada000000000000000000000000000000000000000000000000000000000000000006ddf6e1d765a193d9cbe146ceeb79ac1cb485ed5f5b37913a8cf5857eff00a90fb9ba52b1f09445f1e3a7508d59f0797923acf744fbe2da303fb06da859ee871ef91c791d2aa8492c90f12540abd10056ce5dd8d9ab08461476c1dcc16229382e9acf1ff8568fbe655e616a167591aeedc250afbc88d759ec959b1982e8769ca1e031c8bc9bec3b610cf7b36eb3bf3aa40237c9e5be2c7893878578439eb00b000000000000000000000000000000000000000000000000000000000000000001080a0a040003010209060705af024532fc63e55377ebd20296490000000005000000200000009e0d6a70e12d54edf90971cc977fa26a1d3bb4b0b26e72470171c36b0006b01f0900000001040000007c1d0f070000000000000000dd000000009101007417da8b99d7748127a76b03d61fee69c80dfef73ad2d5503737beedc5a9ed480104a73bdf31e341218a693b8772c43ecfcecd4cf35fada09a87ea0f860d028168e50090e0b0f5b60147b325842c1fc68f6c90fe26419ea7c4afeb982f71f1f54b5b440a000000049e0d6a70e12d54edf90971cc977fa26a1d3bb4b0b26e72470171c36b0006b01f0000000000000000000000000000000000000000000000000000000000000000010a0000001400000002a0edda1a4beee4fe2df32c0802aa6759da49ae6165fcdb5c40d7f4cd5a30db0e010008010a021406").to_vec(); let from_signing_key = SolSigningKey::from_bytes(&FROM_KEY_BYTES).unwrap(); let event_data_account_signing_key = diff --git a/state-chain/chains/src/sol/sol_tx_core.rs b/state-chain/chains/src/sol/sol_tx_core.rs index 21f6d6796d..8c26846e1e 100644 --- a/state-chain/chains/src/sol/sol_tx_core.rs +++ b/state-chain/chains/src/sol/sol_tx_core.rs @@ -967,6 +967,7 @@ impl FromStr for Hash { #[cfg(any(test, feature = "runtime-integration-tests"))] pub mod sol_test_values { use crate::{ + ccm_checker::VersionedSolanaCcmAdditionalData, sol::{ api::{DurableNonceAndAccount, VaultSwapAccountAndSender}, signing_key::SolSigningKey, @@ -1126,9 +1127,11 @@ pub mod sol_test_values { channel_metadata: CcmChannelMetadata { message: vec![124u8, 29u8, 15u8, 7u8].try_into().unwrap(), // CCM message gas_budget: 0u128, // unused - ccm_additional_data: codec::Encode::encode(&ccm_accounts()) - .try_into() - .expect("Test data cannot be too long"), // Extra addresses + ccm_additional_data: codec::Encode::encode(&VersionedSolanaCcmAdditionalData::V0( + ccm_accounts(), + )) + .try_into() + .expect("Test data cannot be too long"), // Extra addresses }, } } diff --git a/state-chain/runtime/src/lib.rs b/state-chain/runtime/src/lib.rs index c97c3475f4..430a615936 100644 --- a/state-chain/runtime/src/lib.rs +++ b/state-chain/runtime/src/lib.rs @@ -49,7 +49,7 @@ use cf_chains::{ btc::{api::BitcoinApi, BitcoinCrypto, BitcoinRetryPolicy, ScriptPubkey}, ccm_checker::{ check_ccm_for_blacklisted_accounts, CcmValidityCheck, CcmValidityChecker, - DecodedCcmAdditionalData, + DecodedCcmAdditionalData, VersionedSolanaCcmAdditionalData, }, dot::{self, PolkadotAccountId, PolkadotCrypto}, eth::{self, api::EthereumApi, Address as EthereumAddress, Ethereum}, @@ -2269,7 +2269,7 @@ impl_runtime_apis! { // Ensure CCM message is valid match CcmValidityChecker::check_and_decode(ccm, destination_asset) { - Ok(DecodedCcmAdditionalData::Solana(ccm_accounts)) => { + Ok(DecodedCcmAdditionalData::Solana(VersionedSolanaCcmAdditionalData::V0(ccm_accounts))) => { // Ensure the CCM parameters do not contain blacklisted accounts. // Load up environment variables. let api_environment = From 740de73390daac147c4f1ab16759134c0af838e3 Mon Sep 17 00:00:00 2001 From: Jamie Ford Date: Fri, 17 Jan 2025 19:25:08 +1100 Subject: [PATCH 2/4] chore: added broker_id to swap origin (#5557) * chore: added broker_id to swap origin * chore: make broker id explicitly optional for vault swaps (#5559) fix: make broker id explicitly optional for vault swaps --------- Co-authored-by: dandanlen <3168260+dandanlen@users.noreply.github.com> --- .../src/witnessing/state_chain.rs | 20 ++-- engine/src/witness/btc/vault_swaps.rs | 8 +- engine/src/witness/evm/vault.rs | 6 +- .../cf-integration-tests/src/solana.rs | 5 +- .../cf-integration-tests/src/swapping.rs | 5 +- state-chain/chains/src/lib.rs | 14 ++- .../cf-ingress-egress/src/benchmarking.rs | 2 +- .../pallets/cf-ingress-egress/src/lib.rs | 99 ++++++++++++------- .../pallets/cf-ingress-egress/src/tests.rs | 18 ++-- .../cf-ingress-egress/src/tests/boost.rs | 7 +- state-chain/pallets/cf-swapping/src/lib.rs | 4 +- state-chain/pallets/cf-swapping/src/tests.rs | 26 ++++- .../pallets/cf-swapping/src/tests/ccm.rs | 10 +- .../pallets/cf-swapping/src/tests/config.rs | 10 +- .../pallets/cf-swapping/src/tests/dca.rs | 5 +- .../pallets/cf-swapping/src/tests/fees.rs | 20 +++- .../runtime/src/chainflip/solana_elections.rs | 2 +- .../traits/src/mocks/swap_request_api.rs | 4 +- state-chain/traits/src/swapping.rs | 2 +- 19 files changed, 174 insertions(+), 93 deletions(-) diff --git a/api/bin/chainflip-ingress-egress-tracker/src/witnessing/state_chain.rs b/api/bin/chainflip-ingress-egress-tracker/src/witnessing/state_chain.rs index d23efe3842..21799406e0 100644 --- a/api/bin/chainflip-ingress-egress-tracker/src/witnessing/state_chain.rs +++ b/api/bin/chainflip-ingress-egress-tracker/src/witnessing/state_chain.rs @@ -130,7 +130,7 @@ enum WitnessInformation { destination_address: TrackerAddress, ccm_deposit_metadata: Option, deposit_details: Option, - broker_fee: Beneficiary, + broker_fee: Option>, affiliate_fees: Affiliates, refund_params: Option>, dca_params: Option, @@ -278,9 +278,9 @@ where Beneficiary { account: affiliate_mapping.get(&affiliate.account).cloned() .unwrap_or_else(|| { log::warn!( - "Affiliate not found for short id {} on broker `{}`", + "Affiliate not found for short id {} on broker `{:?}`", affiliate.account, - self.broker_fee.account, + self.broker_fee.as_ref().map(|Beneficiary { account, .. }| account), ); AccountId32::from([0; 32]) }), bps: affiliate.bps } @@ -400,9 +400,15 @@ where ::DepositDetails: IntoDepositDetailsAnyChain, StateChainClient: CfGetAffiliates + 'static + Send + Sync, { - let affiliate_mapping = state_chain_client - .cf_get_affiliates(&deposit_witness.broker_fee.account) - .await?; + let affiliate_mapping = if let Some(broker_id) = deposit_witness + .broker_fee + .as_ref() + .map(|Beneficiary { account, .. }| account.clone()) + { + state_chain_client.cf_get_affiliates(&broker_id).await? + } else { + Default::default() + }; let _ = deposit_witness .into_witness_information(block_height, &affiliate_mapping, network) @@ -919,7 +925,7 @@ mod tests { )), }), deposit_details: Default::default(), - broker_fee: Beneficiary { account: AccountId32::new([0; 32]), bps: 10 }, + broker_fee: Some(Beneficiary { account: AccountId32::new([0; 32]), bps: 10 }), affiliate_fees: frame_support::BoundedVec::try_from(vec![Beneficiary { account: affiliate_short_id, bps: 10 diff --git a/engine/src/witness/btc/vault_swaps.rs b/engine/src/witness/btc/vault_swaps.rs index d8f1a1c2d0..bc29976714 100644 --- a/engine/src/witness/btc/vault_swaps.rs +++ b/engine/src/witness/btc/vault_swaps.rs @@ -147,10 +147,10 @@ pub fn try_extract_vault_swap_witness( deposit_address: vault_address.clone(), }, deposit_metadata: None, // No ccm for BTC (yet?) - broker_fee: Beneficiary { + broker_fee: Some(Beneficiary { account: broker_id.clone(), bps: data.parameters.broker_fee.into(), - }, + }), affiliate_fees: data .parameters .affiliates @@ -320,10 +320,10 @@ mod tests { amount: DEPOSIT_AMOUNT, deposit_address: vault_deposit_address.clone(), }, - broker_fee: Beneficiary { + broker_fee: Some(Beneficiary { account: BROKER, bps: MOCK_SWAP_PARAMS.parameters.broker_fee.into() - }, + }), affiliate_fees: bounded_vec![MOCK_SWAP_PARAMS.parameters.affiliates[0].into()], deposit_metadata: None, refund_params: Some(ChannelRefundParametersDecoded { diff --git a/engine/src/witness/evm/vault.rs b/engine/src/witness/evm/vault.rs index 9136ab2e96..639105caa0 100644 --- a/engine/src/witness/evm/vault.rs +++ b/engine/src/witness/evm/vault.rs @@ -254,7 +254,6 @@ macro_rules! vault_deposit_witness { deposit_address: None, } } else { - use cf_primitives::Beneficiary; VaultDepositWitness { input_asset: $source_asset.try_into().expect("invalid asset for chain"), output_asset: $dest_asset, @@ -263,10 +262,7 @@ macro_rules! vault_deposit_witness { deposit_metadata: $metadata, tx_id: $tx_id, deposit_details: DepositDetails { tx_hashes: Some(vec![$tx_id]) }, - broker_fee: Beneficiary { - account: sp_runtime::AccountId32::new([0; 32]), - bps: 0, - }, + broker_fee: None, affiliate_fees: Default::default(), boost_fee: 0, dca_params: None, diff --git a/state-chain/cf-integration-tests/src/solana.rs b/state-chain/cf-integration-tests/src/solana.rs index e15828821b..ced4af1b8e 100644 --- a/state-chain/cf-integration-tests/src/solana.rs +++ b/state-chain/cf-integration-tests/src/solana.rs @@ -378,10 +378,7 @@ fn vault_swap_deposit_witness( deposit_metadata, tx_id: Default::default(), deposit_details: (), - broker_fee: cf_primitives::Beneficiary { - account: sp_runtime::AccountId32::new([0; 32]), - bps: 0, - }, + broker_fee: None, affiliate_fees: Default::default(), refund_params: Some(REFUND_PARAMS), dca_params: None, diff --git a/state-chain/cf-integration-tests/src/swapping.rs b/state-chain/cf-integration-tests/src/swapping.rs index 14f02ff554..a9e43fa124 100644 --- a/state-chain/cf-integration-tests/src/swapping.rs +++ b/state-chain/cf-integration-tests/src/swapping.rs @@ -530,10 +530,7 @@ fn vault_swap_deposit_witness( deposit_metadata: Some(ccm_deposit_metadata_mock()), tx_id: Default::default(), deposit_details: DepositDetails { tx_hashes: None }, - broker_fee: cf_primitives::Beneficiary { - account: sp_runtime::AccountId32::new([0; 32]), - bps: 0, - }, + broker_fee: None, affiliate_fees: Default::default(), refund_params: Some(ETH_REFUND_PARAMS), dca_params: None, diff --git a/state-chain/chains/src/lib.rs b/state-chain/chains/src/lib.rs index 94e977b567..7a82e4fe76 100644 --- a/state-chain/chains/src/lib.rs +++ b/state-chain/chains/src/lib.rs @@ -670,18 +670,30 @@ impl IntoTransactionInIdForAnyChain for () { } #[derive(Clone, Debug, PartialEq, Eq, Encode, Decode, TypeInfo)] -pub enum SwapOrigin { +pub enum SwapOrigin { DepositChannel { deposit_address: address::EncodedAddress, channel_id: ChannelId, deposit_block_height: u64, + broker_id: AccountId, }, Vault { tx_id: TransactionInIdForAnyChain, + broker_id: Option, }, Internal, } +impl SwapOrigin { + pub fn broker_id(&self) -> Option<&AccountId> { + match self { + Self::DepositChannel { ref broker_id, .. } => Some(broker_id), + Self::Vault { ref broker_id, .. } => broker_id.as_ref(), + Self::Internal => None, + } + } +} + #[derive(Clone, Debug, PartialEq, Eq, Encode, Decode, TypeInfo)] pub enum DepositOriginType { DepositChannel, diff --git a/state-chain/pallets/cf-ingress-egress/src/benchmarking.rs b/state-chain/pallets/cf-ingress-egress/src/benchmarking.rs index 55b3f82711..d75054cd07 100644 --- a/state-chain/pallets/cf-ingress-egress/src/benchmarking.rs +++ b/state-chain/pallets/cf-ingress-egress/src/benchmarking.rs @@ -314,7 +314,7 @@ mod benchmarks { deposit_metadata: Some(deposit_metadata), tx_id: TransactionInIdFor::::benchmark_value(), deposit_details: BenchmarkValue::benchmark_value(), - broker_fee: cf_primitives::Beneficiary { account: account("broker", 0, 0), bps: 0 }, + broker_fee: None, affiliate_fees: Default::default(), refund_params: Some(ChannelRefundParametersDecoded { retry_duration: Default::default(), diff --git a/state-chain/pallets/cf-ingress-egress/src/lib.rs b/state-chain/pallets/cf-ingress-egress/src/lib.rs index f29b0198b9..f693e27558 100644 --- a/state-chain/pallets/cf-ingress-egress/src/lib.rs +++ b/state-chain/pallets/cf-ingress-egress/src/lib.rs @@ -160,27 +160,38 @@ mod deposit_origin { deposit_address: ::ChainAccount, channel_id: ChannelId, deposit_block_height: u64, + broker_id: T::AccountId, }, Vault { tx_id: TransactionInIdFor, + broker_id: Option, }, } impl, I: 'static> DepositOrigin { - pub(super) fn deposit_channel( + pub fn deposit_channel( deposit_address: ::ChainAccount, channel_id: ChannelId, deposit_block_height: ::ChainBlockNumber, + broker_id: T::AccountId, ) -> Self { DepositOrigin::DepositChannel { deposit_address, channel_id, deposit_block_height: deposit_block_height.into(), + broker_id, } } - pub(super) fn vault(tx_id: TransactionInIdFor) -> Self { - DepositOrigin::Vault { tx_id } + pub fn vault(tx_id: TransactionInIdFor, broker_id: Option) -> Self { + DepositOrigin::Vault { tx_id, broker_id } + } + + pub fn broker_id(&self) -> Option<&T::AccountId> { + match self { + Self::DepositChannel { ref broker_id, .. } => Some(broker_id), + Self::Vault { ref broker_id, .. } => broker_id.as_ref(), + } } } @@ -193,15 +204,18 @@ mod deposit_origin { } } - impl, I: 'static> From> for SwapOrigin { - fn from(origin: DepositOrigin) -> SwapOrigin { + impl, I: 'static> From> for SwapOrigin { + fn from(origin: DepositOrigin) -> SwapOrigin { match origin { - DepositOrigin::Vault { tx_id } => - SwapOrigin::Vault { tx_id: tx_id.into_transaction_in_id_for_any_chain() }, + DepositOrigin::Vault { tx_id, broker_id } => SwapOrigin::Vault { + tx_id: tx_id.into_transaction_in_id_for_any_chain(), + broker_id, + }, DepositOrigin::DepositChannel { deposit_address, channel_id, deposit_block_height, + broker_id, } => SwapOrigin::DepositChannel { deposit_address: T::AddressConverter::to_encoded_address( ::ChainAccount::into_foreign_chain_address( @@ -210,6 +224,7 @@ mod deposit_origin { ), channel_id, deposit_block_height, + broker_id, }, } } @@ -383,7 +398,7 @@ pub mod pallet { pub destination_address: EncodedAddress, pub deposit_metadata: Option, pub tx_id: TransactionInIdFor, - pub broker_fee: Beneficiary, + pub broker_fee: Option>, pub affiliate_fees: Affiliates, pub refund_params: Option, pub dca_params: Option, @@ -1832,7 +1847,6 @@ impl, I: 'static> Pallet { Some(deposit_address.clone()), None, // source address is unknown action, - &owner, boost_fee, boost_status, Some(deposit_channel.channel_id), @@ -1841,6 +1855,7 @@ impl, I: 'static> Pallet { deposit_address.clone(), deposit_channel.channel_id, block_height, + owner.clone(), ), ) { // Update boost status @@ -1940,8 +1955,12 @@ impl, I: 'static> Pallet { return Err(Error::::InvalidDepositAddress.into()) } - let deposit_origin = - DepositOrigin::deposit_channel(deposit_address.clone(), channel_id, block_height); + let deposit_origin = DepositOrigin::deposit_channel( + deposit_address.clone(), + channel_id, + block_height, + deposit_channel_details.owner.clone(), + ); match Self::process_full_witness_deposit_inner( Some(deposit_address.clone()), @@ -1949,7 +1968,6 @@ impl, I: 'static> Pallet { *amount, deposit_details.clone(), None, // source address is unknown - &deposit_channel_details.owner, deposit_channel_details.boost_status, deposit_channel_details.boost_fee, Some(channel_id), @@ -1986,14 +2004,24 @@ impl, I: 'static> Pallet { } fn assemble_broker_fees( - broker_fee: Beneficiary, + broker_fee: Option>, affiliate_fees: Affiliates, ) -> Beneficiaries { - let primary_broker = broker_fee.account.clone(); - - if T::AccountRoleRegistry::has_account_role(&primary_broker, AccountRole::Broker) { - [broker_fee] - .into_iter() + broker_fee + .as_ref() + .filter(|Beneficiary { account, .. }| { + if T::AccountRoleRegistry::has_account_role(account, AccountRole::Broker) { + true + } else { + Self::deposit_event(Event::::UnknownBroker { + broker_id: account.clone(), + }); + false + } + }) + .map(|primary_broker_fee| { + let primary_broker = primary_broker_fee.account.clone(); + core::iter::once(primary_broker_fee.clone()) .chain(affiliate_fees.into_iter().filter_map( |Beneficiary { account: short_affiliate_id, bps }| { if let Some(affiliate_id) = T::AffiliateRegistry::get_account_id( @@ -2018,10 +2046,8 @@ impl, I: 'static> Pallet { .expect( "must fit since affiliates are limited to 1 fewer element than beneficiaries", ) - } else { - Self::deposit_event(Event::::UnknownBroker { broker_id: primary_broker }); - Default::default() - } + }) + .unwrap_or_default() } fn process_prewitness_deposit_inner( @@ -2031,7 +2057,6 @@ impl, I: 'static> Pallet { deposit_address: Option>, source_address: Option, action: ChannelAction, - broker: &T::AccountId, boost_fee: u16, boost_status: BoostStatus>, channel_id: Option, @@ -2044,8 +2069,8 @@ impl, I: 'static> Pallet { return None; } - if let Some(tx_id) = deposit_details.deposit_id() { - if TransactionsMarkedForRejection::::mutate(broker, &tx_id, |opt| { + if let (Some(tx_id), Some(broker_id)) = (deposit_details.deposit_id(), origin.broker_id()) { + if TransactionsMarkedForRejection::::mutate(broker_id, &tx_id, |opt| { match opt.as_mut() { // Transaction has been reported, mark it as pre-witnessed. Some(status @ TransactionPrewitnessedStatus::Unseen) => { @@ -2181,8 +2206,10 @@ impl, I: 'static> Pallet { } } - let broker = broker_fee.account.clone(); - + let origin = DepositOrigin::vault( + tx_id.clone(), + broker_fee.as_ref().map(|Beneficiary { account, .. }| account.clone()), + ); let broker_fees = Self::assemble_broker_fees(broker_fee, affiliate_fees); let (channel_metadata, source_address) = match deposit_metadata { @@ -2202,8 +2229,6 @@ impl, I: 'static> Pallet { let boost_status = BoostedVaultTransactions::::get(&tx_id).unwrap_or(BoostStatus::NotBoosted); - let origin = DepositOrigin::vault(tx_id.clone()); - if let Some(new_boost_status) = Self::process_prewitness_deposit_inner( amount, asset, @@ -2211,7 +2236,6 @@ impl, I: 'static> Pallet { deposit_address, source_address, action, - &broker, boost_fee, boost_status, channel_id, @@ -2228,7 +2252,6 @@ impl, I: 'static> Pallet { deposit_amount: TargetChainAmount, deposit_details: ::DepositDetails, source_address: Option, - broker: &T::AccountId, boost_status: BoostStatus>, max_boost_fee_bps: BasisPoints, channel_id: Option, @@ -2242,10 +2265,12 @@ impl, I: 'static> Pallet { // TODO: track these funds somewhere, for example add them to the withheld fees. return Err(DepositFailedReason::BelowMinimumDeposit); } - if let Some(tx_id) = deposit_details.deposit_id() { + if let (Some(tx_id), Some(broker_id)) = + (deposit_details.deposit_id(), origin.broker_id()) + { // Only consider rejecting a transaction if we haven't already boosted it, // since by boosting the protocol is committing to accept the deposit. - if TransactionsMarkedForRejection::::take(broker, &tx_id).is_some() { + if TransactionsMarkedForRejection::::take(broker_id, &tx_id).is_some() { let refund_address = match &action { ChannelAction::Swap { refund_params, .. } => refund_params .as_ref() @@ -2449,9 +2474,10 @@ impl, I: 'static> Pallet { }, }; - let deposit_origin = DepositOrigin::vault(tx_id.clone()); - - let broker = broker_fee.account.clone(); + let deposit_origin = DepositOrigin::vault( + tx_id.clone(), + broker_fee.as_ref().map(|Beneficiary { account, .. }| account.clone()), + ); let broker_fees = Self::assemble_broker_fees(broker_fee.clone(), affiliate_fees.clone()); if T::SwapLimitsProvider::validate_broker_fees(&broker_fees).is_err() { @@ -2514,7 +2540,6 @@ impl, I: 'static> Pallet { deposit_amount, deposit_details.clone(), source_address, - &broker, boost_status, boost_fee, channel_id, diff --git a/state-chain/pallets/cf-ingress-egress/src/tests.rs b/state-chain/pallets/cf-ingress-egress/src/tests.rs index c4bc6dbd20..c7da4b9bf4 100644 --- a/state-chain/pallets/cf-ingress-egress/src/tests.rs +++ b/state-chain/pallets/cf-ingress-egress/src/tests.rs @@ -1825,7 +1825,7 @@ fn submit_vault_swap_request( destination_address, deposit_metadata, tx_id, - broker_fee, + broker_fee: Some(broker_fee), affiliate_fees, refund_params: Some(refund_params), dca_params, @@ -1869,6 +1869,7 @@ fn can_request_swap_via_extrinsic() { broker_fees: bounded_vec![Beneficiary { account: BROKER, bps: 0 }], origin: SwapOrigin::Vault { tx_id: TransactionInIdForAnyChain::Evm(H256::default()), + broker_id: Some(BROKER), }, },] ); @@ -1932,7 +1933,8 @@ fn vault_swaps_support_affiliate_fees() { Beneficiary { account: AFFILIATE_1, bps: AFFILIATE_FEE } ], origin: SwapOrigin::Vault { - tx_id: cf_chains::TransactionInIdForAnyChain::Evm(H256::default()) + tx_id: cf_chains::TransactionInIdForAnyChain::Evm(H256::default()), + broker_id: Some(BROKER), }, },] ); @@ -1983,7 +1985,8 @@ fn charge_no_broker_fees_on_unknown_primary_broker() { swap_type: SwapRequestType::Regular { output_address, ccm_deposit_metadata: None }, broker_fees: Default::default(), origin: SwapOrigin::Vault { - tx_id: cf_chains::TransactionInIdForAnyChain::Evm(H256::default()) + tx_id: cf_chains::TransactionInIdForAnyChain::Evm(H256::default()), + broker_id: Some(NOT_A_BROKER), }, },] ); @@ -2043,6 +2046,7 @@ fn can_request_ccm_swap_via_extrinsic() { broker_fees: bounded_vec![Beneficiary { account: BROKER, bps: 0 }], origin: SwapOrigin::Vault { tx_id: TransactionInIdForAnyChain::Evm(H256::default()), + broker_id: Some(BROKER), }, },] ); @@ -2227,7 +2231,7 @@ fn assembling_broker_fees() { Beneficiary { account: 50, bps: 5 }, ]; - assert_eq!(IngressEgress::assemble_broker_fees(broker_fee, affiliate_fees), expected); + assert_eq!(IngressEgress::assemble_broker_fees(Some(broker_fee), affiliate_fees), expected); }); } @@ -2246,13 +2250,12 @@ fn ignore_change_of_minimum_deposit_if_deposit_is_not_boosted() { DEPOSIT_AMOUNT, Default::default(), None, - &BROKER, BoostStatus::NotBoosted, 0, None, ChannelAction::LiquidityProvision { lp_account: 0, refund_address: None }, 0, - DepositOrigin::Vault { tx_id: H256::default() }, + DepositOrigin::Vault { tx_id: H256::default(), broker_id: Some(BROKER) }, ) .err(), Some(DepositFailedReason::BelowMinimumDeposit) @@ -2264,7 +2267,6 @@ fn ignore_change_of_minimum_deposit_if_deposit_is_not_boosted() { DEPOSIT_AMOUNT, Default::default(), None, - &BROKER, BoostStatus::Boosted { prewitnessed_deposit_id: 0, pools: vec![], @@ -2274,7 +2276,7 @@ fn ignore_change_of_minimum_deposit_if_deposit_is_not_boosted() { None, ChannelAction::LiquidityProvision { lp_account: 0, refund_address: None }, 0, - DepositOrigin::Vault { tx_id: H256::default() }, + DepositOrigin::Vault { tx_id: H256::default(), broker_id: Some(BROKER) }, ) .is_ok()); }); diff --git a/state-chain/pallets/cf-ingress-egress/src/tests/boost.rs b/state-chain/pallets/cf-ingress-egress/src/tests/boost.rs index 571fe07bc7..fd285c0963 100644 --- a/state-chain/pallets/cf-ingress-egress/src/tests/boost.rs +++ b/state-chain/pallets/cf-ingress-egress/src/tests/boost.rs @@ -1197,7 +1197,7 @@ mod vault_swaps { ), deposit_metadata: None, tx_id, - broker_fee: Beneficiary { account: BROKER, bps: 5 }, + broker_fee: Some(Beneficiary { account: BROKER, bps: 5 }), affiliate_fees: Default::default(), refund_params: Some(ChannelRefundParametersDecoded { retry_duration: 2, @@ -1233,7 +1233,10 @@ mod vault_swaps { ccm_deposit_metadata: None }, broker_fees: bounded_vec![Beneficiary { account: BROKER, bps: 5 }], - origin: SwapOrigin::Vault { tx_id: TransactionInIdForAnyChain::Evm(tx_id) }, + origin: SwapOrigin::Vault { + tx_id: TransactionInIdForAnyChain::Evm(tx_id), + broker_id: Some(BROKER) + }, },] ); diff --git a/state-chain/pallets/cf-swapping/src/lib.rs b/state-chain/pallets/cf-swapping/src/lib.rs index d0025123b2..cb5b6b1cdd 100644 --- a/state-chain/pallets/cf-swapping/src/lib.rs +++ b/state-chain/pallets/cf-swapping/src/lib.rs @@ -556,7 +556,7 @@ pub mod pallet { input_asset: Asset, input_amount: AssetAmount, // includes broker fee output_asset: Asset, - origin: SwapOrigin, + origin: SwapOrigin, request_type: SwapRequestTypeEncoded, broker_fees: Beneficiaries, refund_parameters: Option, @@ -1908,7 +1908,7 @@ pub mod pallet { broker_fees: Beneficiaries, refund_params: Option, dca_params: Option, - origin: SwapOrigin, + origin: SwapOrigin, ) -> SwapRequestId { let request_id = SwapRequestIdCounter::::mutate(|id| { id.saturating_accrue(1); diff --git a/state-chain/pallets/cf-swapping/src/tests.rs b/state-chain/pallets/cf-swapping/src/tests.rs index 8c90b7eaac..7bd8b0b29b 100644 --- a/state-chain/pallets/cf-swapping/src/tests.rs +++ b/state-chain/pallets/cf-swapping/src/tests.rs @@ -211,7 +211,10 @@ fn insert_swaps(swaps: &[TestSwapParams]) { bounded_vec![Beneficiary { account: broker_id as u64, bps: BROKER_FEE_BPS }], swap.refund_params.clone(), swap.dca_params.clone(), - SwapOrigin::Vault { tx_id: TransactionInIdForAnyChain::Evm(H256::default()) }, + SwapOrigin::Vault { + tx_id: TransactionInIdForAnyChain::Evm(H256::default()), + broker_id: Some(BROKER), + }, ); } } @@ -264,6 +267,7 @@ fn swap_with_custom_broker_fee( )), channel_id: 1, deposit_block_height: 0, + broker_id: BROKER, }, ); } @@ -342,7 +346,10 @@ fn cannot_swap_with_incorrect_destination_address_type() { Default::default(), None, None, - SwapOrigin::Vault { tx_id: TransactionInIdForAnyChain::Evm(H256::default()) }, + SwapOrigin::Vault { + tx_id: TransactionInIdForAnyChain::Evm(H256::default()), + broker_id: Some(BROKER), + }, ); assert_swaps_queue_is_empty(); @@ -516,7 +523,10 @@ fn process_all_into_stable_swaps_first() { Default::default(), None, None, - SwapOrigin::Vault { tx_id: TransactionInIdForAnyChain::Evm(H256::default()) }, + SwapOrigin::Vault { + tx_id: TransactionInIdForAnyChain::Evm(H256::default()), + broker_id: Some(BROKER), + }, ); }); @@ -651,7 +661,10 @@ fn can_handle_ccm_with_zero_swap_outputs() { Default::default(), None, None, - SwapOrigin::Vault { tx_id: TransactionInIdForAnyChain::Evm(H256::default()) }, + SwapOrigin::Vault { + tx_id: TransactionInIdForAnyChain::Evm(H256::default()), + broker_id: Some(BROKER), + }, ); // Change the swap rate so swap output will be 0 @@ -1307,7 +1320,10 @@ fn swap_output_amounts_correctly_account_for_fees() { Default::default(), None, None, - SwapOrigin::Vault { tx_id: TransactionInIdForAnyChain::Evm(H256::default()) }, + SwapOrigin::Vault { + tx_id: TransactionInIdForAnyChain::Evm(H256::default()), + broker_id: Some(BROKER), + }, ); Swapping::on_finalize(System::block_number() + SWAP_DELAY_BLOCKS as u64); diff --git a/state-chain/pallets/cf-swapping/src/tests/ccm.rs b/state-chain/pallets/cf-swapping/src/tests/ccm.rs index f8b447ad83..5ca5147698 100644 --- a/state-chain/pallets/cf-swapping/src/tests/ccm.rs +++ b/state-chain/pallets/cf-swapping/src/tests/ccm.rs @@ -7,7 +7,10 @@ fn init_ccm_swap_request(input_asset: Asset, output_asset: Asset, input_amount: let ccm_deposit_metadata = generate_ccm_deposit(); let output_address = (*EVM_OUTPUT_ADDRESS).clone(); let encoded_output_address = MockAddressConverter::to_encoded_address(output_address.clone()); - let origin = SwapOrigin::Vault { tx_id: TransactionInIdForAnyChain::Evm(H256::default()) }; + let origin = SwapOrigin::Vault { + tx_id: TransactionInIdForAnyChain::Evm(H256::default()), + broker_id: Some(BROKER), + }; Swapping::init_swap_request( input_asset, @@ -106,7 +109,10 @@ fn can_process_ccms_via_swap_deposit_address() { Default::default(), None, None, - SwapOrigin::Vault { tx_id: TransactionInIdForAnyChain::Evm(H256::default()) }, + SwapOrigin::Vault { + tx_id: TransactionInIdForAnyChain::Evm(H256::default()), + broker_id: Some(BROKER), + }, ); // Principal swap is scheduled first diff --git a/state-chain/pallets/cf-swapping/src/tests/config.rs b/state-chain/pallets/cf-swapping/src/tests/config.rs index 4baae085d0..fb3f71f787 100644 --- a/state-chain/pallets/cf-swapping/src/tests/config.rs +++ b/state-chain/pallets/cf-swapping/src/tests/config.rs @@ -123,7 +123,10 @@ fn max_swap_amount_can_be_removed() { Default::default(), None, None, - SwapOrigin::Vault { tx_id: TransactionInIdForAnyChain::Evm(H256::default()) }, + SwapOrigin::Vault { + tx_id: TransactionInIdForAnyChain::Evm(H256::default()), + broker_id: Some(BROKER), + }, ); }; @@ -221,7 +224,10 @@ fn can_swap_below_max_amount() { Default::default(), None, None, - SwapOrigin::Vault { tx_id: TransactionInIdForAnyChain::Evm(H256::default()) }, + SwapOrigin::Vault { + tx_id: TransactionInIdForAnyChain::Evm(H256::default()), + broker_id: Some(BROKER), + }, ); assert_eq!(CollectedRejectedFunds::::get(from), 0u128); diff --git a/state-chain/pallets/cf-swapping/src/tests/dca.rs b/state-chain/pallets/cf-swapping/src/tests/dca.rs index edd14e31ed..2e00755f26 100644 --- a/state-chain/pallets/cf-swapping/src/tests/dca.rs +++ b/state-chain/pallets/cf-swapping/src/tests/dca.rs @@ -685,7 +685,10 @@ fn test_minimum_chunk_size() { vec![].try_into().unwrap(), None, Some(dca_params), - SwapOrigin::Vault { tx_id: TransactionInIdForAnyChain::Evm(H256::default()) }, + SwapOrigin::Vault { + tx_id: TransactionInIdForAnyChain::Evm(H256::default()), + broker_id: Some(BROKER), + }, ); // Check that the swap was initiated with the updated number of chunks diff --git a/state-chain/pallets/cf-swapping/src/tests/fees.rs b/state-chain/pallets/cf-swapping/src/tests/fees.rs index 76b38d315f..790c078aac 100644 --- a/state-chain/pallets/cf-swapping/src/tests/fees.rs +++ b/state-chain/pallets/cf-swapping/src/tests/fees.rs @@ -40,7 +40,10 @@ fn swap_output_amounts_correctly_account_for_fees() { Default::default(), None, None, - SwapOrigin::Vault { tx_id: TransactionInIdForAnyChain::Evm(H256::default()) }, + SwapOrigin::Vault { + tx_id: TransactionInIdForAnyChain::Evm(H256::default()), + broker_id: Some(BROKER), + }, ); Swapping::on_finalize(System::block_number() + SWAP_DELAY_BLOCKS as u64); @@ -368,7 +371,10 @@ fn input_amount_excludes_network_fee() { bounded_vec![], None, None, - SwapOrigin::Vault { tx_id: TransactionInIdForAnyChain::Evm(H256::default()) }, + SwapOrigin::Vault { + tx_id: TransactionInIdForAnyChain::Evm(H256::default()), + broker_id: Some(BROKER), + }, ); }) .then_process_blocks_until(|_| System::block_number() == 3) @@ -571,7 +577,10 @@ fn min_network_fee_is_enforced_in_regular_swaps() { Default::default(), None, None, - SwapOrigin::Vault { tx_id: TransactionInIdForAnyChain::Evm(H256::default()) }, + SwapOrigin::Vault { + tx_id: TransactionInIdForAnyChain::Evm(H256::default()), + broker_id: Some(BROKER), + }, ); assert_eq!(CollectedNetworkFee::::get(), 0); @@ -589,7 +598,10 @@ fn min_network_fee_is_enforced_in_regular_swaps() { Default::default(), None, None, - SwapOrigin::Vault { tx_id: TransactionInIdForAnyChain::Evm(H256::default()) }, + SwapOrigin::Vault { + tx_id: TransactionInIdForAnyChain::Evm(H256::default()), + broker_id: Some(BROKER), + }, ); }) .then_process_blocks_until_block(FEE_SWAP_BLOCK) diff --git a/state-chain/runtime/src/chainflip/solana_elections.rs b/state-chain/runtime/src/chainflip/solana_elections.rs index 2b33171745..74b02eb4f4 100644 --- a/state-chain/runtime/src/chainflip/solana_elections.rs +++ b/state-chain/runtime/src/chainflip/solana_elections.rs @@ -590,7 +590,7 @@ impl destination_address: swap_details.destination_address, deposit_metadata: swap_details.deposit_metadata, tx_id: (swap_details.swap_account, swap_details.creation_slot), - broker_fee: swap_details.broker_fee, + broker_fee: Some(swap_details.broker_fee), affiliate_fees: swap_details.affiliate_fees, dca_params: swap_details.dca_params, refund_params: Some(swap_details.refund_params), diff --git a/state-chain/traits/src/mocks/swap_request_api.rs b/state-chain/traits/src/mocks/swap_request_api.rs index b18e5f1bc0..65437f241d 100644 --- a/state-chain/traits/src/mocks/swap_request_api.rs +++ b/state-chain/traits/src/mocks/swap_request_api.rs @@ -18,7 +18,7 @@ pub struct MockSwapRequest { pub input_amount: AssetAmount, pub swap_type: SwapRequestType, pub broker_fees: Beneficiaries, - pub origin: SwapOrigin, + pub origin: SwapOrigin, } impl MockPallet for MockSwapRequestHandler { @@ -47,7 +47,7 @@ where broker_fees: Beneficiaries, _refund_params: Option, _dca_params: Option, - origin: SwapOrigin, + origin: SwapOrigin, ) -> SwapRequestId { let id = Self::mutate_value(SWAP_REQUESTS, |swaps: &mut Option>| { let swaps = swaps.get_or_insert(vec![]); diff --git a/state-chain/traits/src/swapping.rs b/state-chain/traits/src/swapping.rs index d2d4317d59..a72e2e0eba 100644 --- a/state-chain/traits/src/swapping.rs +++ b/state-chain/traits/src/swapping.rs @@ -36,6 +36,6 @@ pub trait SwapRequestHandler { broker_fees: Beneficiaries, refund_params: Option, dca_params: Option, - origin: SwapOrigin, + origin: SwapOrigin, ) -> SwapRequestId; } From bbad75bcce809626090d4233f86e5bea705d67ab Mon Sep 17 00:00:00 2001 From: Albert Llimos <53186777+albert-llimos@users.noreply.github.com> Date: Fri, 17 Jan 2025 11:24:21 +0100 Subject: [PATCH 3/4] chore: rename Solana CCM remaining accounts (#5562) * chore: rename to additional * chore: fix event names --- bouncer/shared/swapping.ts | 10 ++++----- bouncer/shared/utils.ts | 22 +++++++++---------- .../cf-integration-tests/src/solana.rs | 4 ++-- state-chain/chains/src/ccm_checker.rs | 22 +++++++++---------- state-chain/chains/src/sol/sol_tx_core.rs | 16 +++++++------- .../sol/sol_tx_core/program_instructions.rs | 4 ++-- .../chains/src/sol/transaction_builder.rs | 6 ++--- 7 files changed, 42 insertions(+), 42 deletions(-) diff --git a/bouncer/shared/swapping.ts b/bouncer/shared/swapping.ts index f024eff2fc..a20469dedc 100644 --- a/bouncer/shared/swapping.ts +++ b/bouncer/shared/swapping.ts @@ -22,11 +22,11 @@ export function newSolanaCcmAdditionalData(maxAccounts: number) { const fallbackAddress = Keypair.generate().publicKey.toBytes(); - const remainingAccounts = []; - const numRemainingAccounts = Math.floor(Math.random() * maxAccounts); + const additionalAccounts = []; + const numAdditionalAccounts = Math.floor(Math.random() * maxAccounts); - for (let i = 0; i < numRemainingAccounts; i++) { - remainingAccounts.push({ + for (let i = 0; i < numAdditionalAccounts; i++) { + additionalAccounts.push({ pubkey: Keypair.generate().publicKey.toBytes(), is_writable: Math.random() < 0.5, }); @@ -37,7 +37,7 @@ export function newSolanaCcmAdditionalData(maxAccounts: number) { pubkey: new PublicKey(cfReceiverAddress).toBytes(), is_writable: false, }, - remaining_accounts: remainingAccounts, + additional_accounts: additionalAccounts, fallback_address: fallbackAddress, }; diff --git a/bouncer/shared/utils.ts b/bouncer/shared/utils.ts index 4c2ab871f8..7fafa7b254 100644 --- a/bouncer/shared/utils.ts +++ b/bouncer/shared/utils.ts @@ -68,7 +68,7 @@ const solCcmAccountsCodec = Struct({ pubkey: TsBytes(32), is_writable: bool, }), - remaining_accounts: Vector( + additional_accounts: Vector( Struct({ pubkey: TsBytes(32), is_writable: bool, @@ -811,39 +811,39 @@ export async function observeSolanaCcmEvent( // The message is being used as the main discriminator if (matchEventName && matchSourceChain && matchMessage) { - const { remaining_accounts: expectedRemainingAccounts } = + const { additional_accounts: expectedAdditionalAccounts } = solVersionedCcmAdditionalDataCodec.dec(messageMetadata.ccmAdditionalData!).value; if ( - expectedRemainingAccounts.length !== event.data.remaining_is_writable.length || - expectedRemainingAccounts.length !== event.data.remaining_pubkeys.length + expectedAdditionalAccounts.length !== event.data.remaining_is_writable.length || + expectedAdditionalAccounts.length !== event.data.remaining_pubkeys.length ) { throw new Error( - `Unexpected remaining accounts length: ${expectedRemainingAccounts.length}, expecting ${event.data.remaining_is_writable.length}, ${event.data.remaining_pubkeys.length}`, + `Unexpected additional accounts length: ${expectedAdditionalAccounts.length}, expecting ${event.data.remaining_is_writable.length}, ${event.data.remaining_pubkeys.length}`, ); } - for (let index = 0; index < expectedRemainingAccounts.length; index++) { + for (let index = 0; index < expectedAdditionalAccounts.length; index++) { if ( - expectedRemainingAccounts[index].is_writable.toString() !== + expectedAdditionalAccounts[index].is_writable.toString() !== event.data.remaining_is_writable[index].toString() ) { throw new Error( - `Unexpected remaining account is_writable: ${event.data.remaining_is_writable[index]}, expecting ${expectedRemainingAccounts[index].is_writable}`, + `Unexpected additional account is_writable: ${event.data.remaining_is_writable[index]}, expecting ${expectedAdditionalAccounts[index].is_writable}`, ); } const expectedPubkey = new PublicKey( - expectedRemainingAccounts[index].pubkey, + expectedAdditionalAccounts[index].pubkey, ).toString(); if (expectedPubkey !== event.data.remaining_pubkeys[index].toString()) { throw new Error( - `Unexpected remaining account pubkey: ${event.data.remaining_pubkeys[index].toString()}, expecting ${expectedPubkey}`, + `Unexpected additional account pubkey: ${event.data.remaining_pubkeys[index].toString()}, expecting ${expectedPubkey}`, ); } } if (event.data.remaining_is_signer.some((value: boolean) => value === true)) { - throw new Error(`Expected all remaining accounts to be read-only`); + throw new Error(`Expected all additional accounts to be read-only`); } if (sourceAddress !== null) { diff --git a/state-chain/cf-integration-tests/src/solana.rs b/state-chain/cf-integration-tests/src/solana.rs index ced4af1b8e..afa70f54ac 100644 --- a/state-chain/cf-integration-tests/src/solana.rs +++ b/state-chain/cf-integration-tests/src/solana.rs @@ -489,7 +489,7 @@ fn solana_ccm_fails_with_invalid_input() { gas_budget: 0u128, ccm_additional_data: VersionedSolanaCcmAdditionalData::V0(SolCcmAccounts { cf_receiver: SolCcmAddress { pubkey: receiver.into(), is_writable: true }, - remaining_accounts: vec![ + additional_accounts: vec![ SolCcmAddress { pubkey: SolPubkey([0x01; 32]), is_writable: false }, SolCcmAddress { pubkey: SolPubkey([0x02; 32]), is_writable: false }, ], @@ -705,7 +705,7 @@ fn solana_ccm_execution_error_can_trigger_fallback() { gas_budget: 1_000_000_000u128, ccm_additional_data: VersionedSolanaCcmAdditionalData::V0(SolCcmAccounts { cf_receiver: SolCcmAddress { pubkey: SolPubkey([0x10; 32]), is_writable: true }, - remaining_accounts: vec![ + additional_accounts: vec![ SolCcmAddress { pubkey: SolPubkey([0x01; 32]), is_writable: false }, SolCcmAddress { pubkey: SolPubkey([0x02; 32]), is_writable: false }, ], diff --git a/state-chain/chains/src/ccm_checker.rs b/state-chain/chains/src/ccm_checker.rs index fdcb9e4e6b..53c8ed5950 100644 --- a/state-chain/chains/src/ccm_checker.rs +++ b/state-chain/chains/src/ccm_checker.rs @@ -74,9 +74,9 @@ impl CcmValidityCheck for CcmValidityChecker { .map_err(|_| CcmValidityError::CannotDecodeCcmAdditionalData)? { VersionedSolanaCcmAdditionalData::V0(ccm_accounts) => { - // Length of CCM = length of message + total no. remaining_accounts * constant; + // Length of CCM = length of message + total no. additional_accounts * constant; let ccm_length = ccm.message.len() + - ccm_accounts.remaining_accounts.len() * CCM_BYTES_PER_ACCOUNT; + ccm_accounts.additional_accounts.len() * CCM_BYTES_PER_ACCOUNT; if ccm_length > match asset { SolAsset::Sol => MAX_CCM_BYTES_SOL, @@ -106,7 +106,7 @@ pub fn check_ccm_for_blacklisted_accounts( blacklisted_accounts.into_iter().try_for_each(|blacklisted_account| { (ccm_accounts.cf_receiver.pubkey != blacklisted_account && !ccm_accounts - .remaining_accounts + .additional_accounts .iter() .any(|acc| acc.pubkey == blacklisted_account)) .then_some(()) @@ -155,7 +155,7 @@ mod test { gas_budget: 0, ccm_additional_data: VersionedSolanaCcmAdditionalData::V0(SolCcmAccounts { cf_receiver: SolCcmAddress { pubkey: SolPubkey([0x01; 32]), is_writable: true }, - remaining_accounts: vec![], + additional_accounts: vec![], fallback_address: SolPubkey([0xf0; 32]), }) .encode() @@ -175,7 +175,7 @@ mod test { let mut invalid_ccm = ccm(); invalid_ccm.ccm_additional_data = VersionedSolanaCcmAdditionalData::V0(SolCcmAccounts { cf_receiver: SolCcmAddress { pubkey: SolPubkey([0x01; 32]), is_writable: true }, - remaining_accounts: vec![SolCcmAddress { + additional_accounts: vec![SolCcmAddress { pubkey: SolPubkey([0x01; 32]), is_writable: true, }], @@ -198,7 +198,7 @@ mod test { ccm_additional_data: VersionedSolanaCcmAdditionalData::V0(SolCcmAccounts { cf_receiver: SolCcmAddress { pubkey: SolPubkey([0x01; 32]), is_writable: true }, fallback_address: SolPubkey([0xf0; 32]), - remaining_accounts: vec![], + additional_accounts: vec![], }) .encode() .try_into() @@ -217,7 +217,7 @@ mod test { let mut invalid_ccm = ccm(); invalid_ccm.ccm_additional_data = VersionedSolanaCcmAdditionalData::V0(SolCcmAccounts { cf_receiver: SolCcmAddress { pubkey: SolPubkey([0x01; 32]), is_writable: true }, - remaining_accounts: vec![SolCcmAddress { + additional_accounts: vec![SolCcmAddress { pubkey: SolPubkey([0x01; 32]), is_writable: true, }], @@ -318,7 +318,7 @@ mod test { pubkey: sol_test_values::TOKEN_VAULT_PDA_ACCOUNT.into(), is_writable: true, }, - remaining_accounts: vec![ + additional_accounts: vec![ SolCcmAddress { pubkey: crate::sol::SolPubkey([0x01; 32]), is_writable: false }, SolCcmAddress { pubkey: crate::sol::SolPubkey([0x02; 32]), is_writable: false }, ], @@ -334,7 +334,7 @@ mod test { pubkey: crate::sol::SolPubkey([0x01; 32]), is_writable: true, }, - remaining_accounts: vec![ + additional_accounts: vec![ SolCcmAddress { pubkey: sol_test_values::TOKEN_VAULT_PDA_ACCOUNT.into(), is_writable: false, @@ -354,7 +354,7 @@ mod test { pubkey: sol_test_values::agg_key().into(), is_writable: true, }, - remaining_accounts: vec![ + additional_accounts: vec![ SolCcmAddress { pubkey: crate::sol::SolPubkey([0x01; 32]), is_writable: false }, SolCcmAddress { pubkey: crate::sol::SolPubkey([0x02; 32]), is_writable: false }, ], @@ -370,7 +370,7 @@ mod test { pubkey: crate::sol::SolPubkey([0x01; 32]), is_writable: true, }, - remaining_accounts: vec![ + additional_accounts: vec![ SolCcmAddress { pubkey: sol_test_values::agg_key().into(), is_writable: false }, SolCcmAddress { pubkey: crate::sol::SolPubkey([0x02; 32]), is_writable: false }, ], diff --git a/state-chain/chains/src/sol/sol_tx_core.rs b/state-chain/chains/src/sol/sol_tx_core.rs index 8c26846e1e..8a1a7ce3f0 100644 --- a/state-chain/chains/src/sol/sol_tx_core.rs +++ b/state-chain/chains/src/sol/sol_tx_core.rs @@ -848,13 +848,13 @@ impl From for AccountMeta { #[derive(Encode, Decode, TypeInfo, Serialize, Deserialize, Debug, Clone, PartialEq, Eq)] pub struct CcmAccounts { pub cf_receiver: CcmAddress, - pub remaining_accounts: Vec, + pub additional_accounts: Vec, pub fallback_address: Pubkey, } impl CcmAccounts { - pub fn remaining_account_metas(self) -> Vec { - self.remaining_accounts.into_iter().map(|acc| acc.into()).collect::>() + pub fn additional_account_metas(self) -> Vec { + self.additional_accounts.into_iter().map(|acc| acc.into()).collect::>() } } @@ -912,7 +912,7 @@ pub mod rpc_types { fn ccm_extra_accounts_encoding() { let extra_accounts = CcmAccounts { cf_receiver: CcmAddress { pubkey: Pubkey([0x11; 32]), is_writable: false }, - remaining_accounts: vec![ + additional_accounts: vec![ CcmAddress { pubkey: Pubkey([0x22; 32]), is_writable: true }, CcmAddress { pubkey: Pubkey([0x33; 32]), is_writable: true }, ], @@ -923,7 +923,7 @@ fn ccm_extra_accounts_encoding() { // Scale encoding format: // cf_receiver(32 bytes, bool), - // size_of_vec(compact encoding), remaining_accounts_0(32 bytes, bool), remaining_accounts_1, + // size_of_vec(compact encoding), additional_accounts_0(32 bytes, bool), additional_accounts_1, // etc.. assert_eq!( encoded, @@ -1112,7 +1112,7 @@ pub mod sol_test_values { pubkey: const_address("8pBPaVfTAcjLeNfC187Fkvi9b1XEFhRNJ95BQXXVksmH").into(), is_writable: true, }, - remaining_accounts: vec![SolCcmAddress { + additional_accounts: vec![SolCcmAddress { pubkey: const_address("CFp37nEY6E9byYHiuxQZg6vMCnzwNrgiF9nFGT6Zwcnx").into(), is_writable: false, }], @@ -1669,7 +1669,7 @@ mod tests { SYSTEM_PROGRAM_ID, SYS_VAR_INSTRUCTIONS, ) - .with_remaining_accounts(extra_accounts.remaining_account_metas()), + .with_additional_accounts(extra_accounts.additional_account_metas()), ]; let message = Message::new_with_blockhash(&instructions, Some(&agg_key_pubkey), &durable_nonce); @@ -1732,7 +1732,7 @@ mod tests { TOKEN_PROGRAM_ID, USDC_TOKEN_MINT_PUB_KEY, SYS_VAR_INSTRUCTIONS, - ).with_remaining_accounts(extra_accounts.remaining_account_metas()), + ).with_additional_accounts(extra_accounts.additional_account_metas()), ]; let message = Message::new_with_blockhash(&instructions, Some(&agg_key_pubkey), &durable_nonce); diff --git a/state-chain/chains/src/sol/sol_tx_core/program_instructions.rs b/state-chain/chains/src/sol/sol_tx_core/program_instructions.rs index a4182aeb3f..c7a30beaaa 100644 --- a/state-chain/chains/src/sol/sol_tx_core/program_instructions.rs +++ b/state-chain/chains/src/sol/sol_tx_core/program_instructions.rs @@ -251,11 +251,11 @@ pub trait ProgramInstruction: BorshSerialize { } pub trait InstructionExt { - fn with_remaining_accounts(self, accounts: Vec) -> Self; + fn with_additional_accounts(self, accounts: Vec) -> Self; } impl InstructionExt for Instruction { - fn with_remaining_accounts(mut self, accounts: Vec) -> Self { + fn with_additional_accounts(mut self, accounts: Vec) -> Self { self.accounts.extend(accounts); self } diff --git a/state-chain/chains/src/sol/transaction_builder.rs b/state-chain/chains/src/sol/transaction_builder.rs index 78a2dd0ce1..fbc2a3d50b 100644 --- a/state-chain/chains/src/sol/transaction_builder.rs +++ b/state-chain/chains/src/sol/transaction_builder.rs @@ -321,7 +321,7 @@ impl SolanaTransactionBuilder { system_program_id(), sys_var_instructions(), ) - .with_remaining_accounts(ccm_accounts.remaining_account_metas()), + .with_additional_accounts(ccm_accounts.additional_account_metas()), ]; Self::build(instructions, durable_nonce, agg_key.into(), compute_price, compute_limit) @@ -376,7 +376,7 @@ impl SolanaTransactionBuilder { token_program_id(), token_mint_pubkey, sys_var_instructions(), - ).with_remaining_accounts(ccm_accounts.remaining_account_metas())]; + ).with_additional_accounts(ccm_accounts.additional_account_metas())]; Self::build(instructions, durable_nonce, agg_key.into(), compute_price, compute_limit) } @@ -430,7 +430,7 @@ impl SolanaTransactionBuilder { let instructions = vec![SwapEndpointProgram::with_id(swap_endpoint_program) .close_event_accounts(vault_program_data_account, agg_key, swap_endpoint_data_account) - .with_remaining_accounts(swap_and_sender_vec)]; + .with_additional_accounts(swap_and_sender_vec)]; Self::build( instructions, From 13433b5ca89941336fdc5d6da1bcc6ea6bfc0194 Mon Sep 17 00:00:00 2001 From: kylezs Date: Fri, 17 Jan 2025 13:34:55 +0100 Subject: [PATCH 4/4] chore: remove non-breaking changes section from PR template (#5563) --- .github/pull_request_template.md | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index 4ce69dfa32..860fdb6373 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -14,7 +14,3 @@ Please conduct a thorough self-review before opening the PR. ## Summary *Please include a succinct description of the purpose and content of the PR. What problem does it solve, and how? Link issues, discussions, other PRs, and anything else that will help the reviewer.* - -#### Non-Breaking changes - -If this PR includes non-breaking changes, select the `non-breaking` label. On merge, CI will automatically cherry-pick the commit to a PR against the release branch.