Skip to content

Commit

Permalink
add ICA innerCall batching based on network
Browse files Browse the repository at this point in the history
  • Loading branch information
nbayindirli committed May 10, 2024
1 parent 5aee461 commit 1f40e36
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 38 deletions.
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -27,28 +26,30 @@ export class EV5InterchainAccountTxTransformer
public async transform(
...txs: PopulatedTransaction[]
): Promise<PopulatedTransaction[]> {
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<ChainName, 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);
if (!txChainsToInnerCalls[txChain]) txChainsToInnerCalls[txChain] = [];
txChainsToInnerCalls[txChain].push({ to, data, value });
});

const transformedTxs: Promise<PopulatedTransaction>[] = [];
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);
}
}

0 comments on commit 1f40e36

Please sign in to comment.