From 1f40e36226a85e089761fafc2e48a7f746a0804e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Noah=20Bayindirli=20=F0=9F=A5=82?= Date: Fri, 10 May 2024 17:11:31 -0400 Subject: [PATCH] add ICA innerCall batching based on network --- .../transformer/TxTransformerTypes.ts | 11 ---- .../EV5InterchainAccountTxTransformer.ts | 55 ++++++++++--------- 2 files changed, 28 insertions(+), 38 deletions(-) diff --git a/typescript/sdk/src/providers/transactions/transformer/TxTransformerTypes.ts b/typescript/sdk/src/providers/transactions/transformer/TxTransformerTypes.ts index 2e064fb65d..b8e029b2c1 100644 --- a/typescript/sdk/src/providers/transactions/transformer/TxTransformerTypes.ts +++ b/typescript/sdk/src/providers/transactions/transformer/TxTransformerTypes.ts @@ -1,14 +1,3 @@ -import { InterchainAccount } from '../../../middleware/account/InterchainAccount.js'; -import { AccountConfig } from '../../../middleware/account/types.js'; -import { ChainName } from '../../../types.js'; - export enum TxTransformerType { ICA = 'Interchain Account', } - -export interface EV5InterchainAccountTxTransformerProps { - chain: ChainName; - interchainAccount: InterchainAccount; - accountConfig: AccountConfig; - hookMetadata?: string; -} diff --git a/typescript/sdk/src/providers/transactions/transformer/ethersV5/EV5InterchainAccountTxTransformer.ts b/typescript/sdk/src/providers/transactions/transformer/ethersV5/EV5InterchainAccountTxTransformer.ts index e89fb72137..25ae331e76 100644 --- a/typescript/sdk/src/providers/transactions/transformer/ethersV5/EV5InterchainAccountTxTransformer.ts +++ b/typescript/sdk/src/providers/transactions/transformer/ethersV5/EV5InterchainAccountTxTransformer.ts @@ -3,13 +3,12 @@ import { Logger } from 'pino'; import { CallData, assert, rootLogger } from '@hyperlane-xyz/utils'; +import { ChainName } from '../../../../types.js'; import { MultiProvider } from '../../../MultiProvider.js'; -import { - EV5InterchainAccountTxTransformerProps, - TxTransformerType, -} from '../TxTransformerTypes.js'; +import { TxTransformerType } from '../TxTransformerTypes.js'; import { EV5TxTransformerInterface } from './EV5TxTransformerInterface.js'; +import { EV5InterchainAccountTxTransformerProps } from './EV5TxTransformerTypes.js'; export class EV5InterchainAccountTxTransformer implements EV5TxTransformerInterface @@ -27,28 +26,30 @@ export class EV5InterchainAccountTxTransformer public async transform( ...txs: PopulatedTransaction[] ): Promise { - const innerCalls: CallData[] = txs.map( - ({ to, data, value, chainId }: PopulatedTransaction) => { - assert(to, 'Invalid PopulatedTransaction: Missing to field'); - assert(data, 'Invalid PopulatedTransaction: Missing data field'); - assert(chainId, 'Invalid PopulatedTransaction: Missing chainId field'); - const txChain = this.multiProvider.getChainName(chainId); - assert( - txChain === this.props.chain, - `Invalid PopulatedTransaction: Cannot submit ${txChain} tx to ${this.props.chain} submitter.`, - ); - return { to, data, value }; - }, - ); - - return [ - await this.props.interchainAccount.getCallRemote( - this.props.chain, - this.multiProvider.getChainName(txs[0].chainId!), - innerCalls, - this.props.accountConfig, - this.props.hookMetadata, - ), - ]; + const txChainsToInnerCalls: Record = {}; + + txs.map(({ to, data, value, chainId }: PopulatedTransaction) => { + assert(to, 'Invalid PopulatedTransaction: Missing to field'); + assert(data, 'Invalid PopulatedTransaction: Missing data field'); + assert(chainId, 'Invalid PopulatedTransaction: Missing chainId field'); + const txChain = this.multiProvider.getChainName(chainId); + if (!txChainsToInnerCalls[txChain]) txChainsToInnerCalls[txChain] = []; + txChainsToInnerCalls[txChain].push({ to, data, value }); + }); + + const transformedTxs: Promise[] = []; + Object.keys(txChainsToInnerCalls).map((txChain: ChainName) => { + transformedTxs.push( + this.props.interchainAccount.getCallRemote( + this.props.chain, + txChain, + txChainsToInnerCalls[txChain], + this.props.accountConfig, + this.props.hookMetadata, + ), + ); + }); + + return Promise.all(transformedTxs); } }