Create CLI Submitter (#3730)
### Description * A CLI-side submitter to interact with the SDK's tx submitter builder ### Drive-by changes * None ### Related issues * Fixes https://github.com/hyperlane-xyz/hyperlane-monorepo/issues/3738 ### Backward compatibility * Yes ### Testing * Nonepull/3752/head
parent
f0df1a4cd1
commit
eba3936803
@ -0,0 +1,5 @@ |
||||
--- |
||||
'@hyperlane-xyz/sdk': patch |
||||
--- |
||||
|
||||
Exports submitter and transformer props types. |
@ -0,0 +1,5 @@ |
||||
--- |
||||
'@hyperlane-xyz/cli': minor |
||||
--- |
||||
|
||||
Add CLI-side submitter to use SDK submitter from CRUD and other command modules. |
@ -0,0 +1,86 @@ |
||||
import { |
||||
EV5GnosisSafeTxSubmitter, |
||||
EV5GnosisSafeTxSubmitterProps, |
||||
EV5ImpersonatedAccountTxSubmitter, |
||||
EV5ImpersonatedAccountTxSubmitterProps, |
||||
EV5InterchainAccountTxTransformer, |
||||
EV5JsonRpcTxSubmitter, |
||||
MultiProvider, |
||||
TxSubmitterBuilder, |
||||
TxSubmitterInterface, |
||||
TxSubmitterType, |
||||
TxTransformerInterface, |
||||
TxTransformerType, |
||||
} from '@hyperlane-xyz/sdk'; |
||||
import { ProtocolType } from '@hyperlane-xyz/utils'; |
||||
|
||||
import { |
||||
SubmitterBuilderSettings, |
||||
SubmitterMetadata, |
||||
TransformerMetadata, |
||||
} from './types.js'; |
||||
|
||||
export async function getSubmitterBuilder<TProtocol extends ProtocolType>({ |
||||
submitterMetadata, |
||||
transformersMetadata, |
||||
multiProvider, |
||||
}: SubmitterBuilderSettings): Promise<TxSubmitterBuilder<TProtocol>> { |
||||
const submitter = await getSubmitter<TProtocol>( |
||||
multiProvider, |
||||
submitterMetadata, |
||||
); |
||||
const transformers = await getTransformers<TProtocol>( |
||||
multiProvider, |
||||
transformersMetadata, |
||||
); |
||||
|
||||
return new TxSubmitterBuilder<TProtocol>(submitter, transformers); |
||||
} |
||||
|
||||
async function getSubmitter<TProtocol extends ProtocolType>( |
||||
multiProvider: MultiProvider, |
||||
submitterMetadata: SubmitterMetadata, |
||||
): Promise<TxSubmitterInterface<TProtocol>> { |
||||
switch (submitterMetadata.type) { |
||||
case TxSubmitterType.JSON_RPC: |
||||
return new EV5JsonRpcTxSubmitter(multiProvider); |
||||
case TxSubmitterType.IMPERSONATED_ACCOUNT: |
||||
return new EV5ImpersonatedAccountTxSubmitter( |
||||
multiProvider, |
||||
submitterMetadata.props as EV5ImpersonatedAccountTxSubmitterProps, |
||||
); |
||||
case TxSubmitterType.GNOSIS_SAFE: |
||||
return new EV5GnosisSafeTxSubmitter( |
||||
multiProvider, |
||||
submitterMetadata.props as EV5GnosisSafeTxSubmitterProps, |
||||
); |
||||
default: |
||||
throw new Error(`Invalid TxSubmitterType: ${submitterMetadata.type}`); |
||||
} |
||||
} |
||||
|
||||
async function getTransformers<TProtocol extends ProtocolType>( |
||||
multiProvider: MultiProvider, |
||||
metadata: TransformerMetadata[], |
||||
): Promise<TxTransformerInterface<TProtocol>[]> { |
||||
return Promise.all( |
||||
metadata.map(({ type, props: settings }) => |
||||
getTransformer<TProtocol>(multiProvider, { type, props: settings }), |
||||
), |
||||
); |
||||
} |
||||
|
||||
async function getTransformer<TProtocol extends ProtocolType>( |
||||
multiProvider: MultiProvider, |
||||
transformerMetadata: TransformerMetadata, |
||||
): Promise<TxTransformerInterface<TProtocol>> { |
||||
switch (transformerMetadata.type) { |
||||
case TxTransformerType.ICA: |
||||
return new EV5InterchainAccountTxTransformer( |
||||
multiProvider, |
||||
transformerMetadata.props, |
||||
); |
||||
default: |
||||
throw new Error(`Invalid TxTransformerType: ${transformerMetadata.type}`); |
||||
} |
||||
} |
@ -0,0 +1,27 @@ |
||||
import type { |
||||
EV5GnosisSafeTxSubmitterProps, |
||||
EV5ImpersonatedAccountTxSubmitterProps, |
||||
EV5InterchainAccountTxTransformerProps, |
||||
MultiProvider, |
||||
TxSubmitterType, |
||||
TxTransformerType, |
||||
} from '@hyperlane-xyz/sdk'; |
||||
|
||||
export interface SubmitterBuilderSettings { |
||||
submitterMetadata: SubmitterMetadata; |
||||
transformersMetadata: TransformerMetadata[]; |
||||
multiProvider: MultiProvider; |
||||
} |
||||
export interface SubmitterMetadata { |
||||
type: TxSubmitterType; |
||||
props: SubmitterProps; |
||||
} |
||||
export interface TransformerMetadata { |
||||
type: TxTransformerType; |
||||
props: TransformerProps; |
||||
} |
||||
|
||||
type SubmitterProps = |
||||
| EV5ImpersonatedAccountTxSubmitterProps |
||||
| EV5GnosisSafeTxSubmitterProps; |
||||
type TransformerProps = EV5InterchainAccountTxTransformerProps; |
@ -0,0 +1,13 @@ |
||||
import { Address } from '@hyperlane-xyz/utils'; |
||||
|
||||
import { ChainName } from '../../../../types.js'; |
||||
|
||||
export interface EV5GnosisSafeTxSubmitterProps { |
||||
chain: ChainName; |
||||
safeAddress: Address; |
||||
} |
||||
|
||||
export interface EV5ImpersonatedAccountTxSubmitterProps { |
||||
chain: ChainName; |
||||
userAddress: Address; |
||||
} |
@ -0,0 +1,10 @@ |
||||
import { InterchainAccount } from '../../../../middleware/account/InterchainAccount.js'; |
||||
import { AccountConfig } from '../../../../middleware/account/types.js'; |
||||
import { ChainName } from '../../../../types.js'; |
||||
|
||||
export interface EV5InterchainAccountTxTransformerProps { |
||||
chain: ChainName; |
||||
interchainAccount: InterchainAccount; |
||||
accountConfig: AccountConfig; |
||||
hookMetadata?: string; |
||||
} |
Loading…
Reference in new issue