|
1 | | -import type { Address, Instruction } from '@solana/kit'; |
| 1 | +import type { |
| 2 | + AltVM, |
| 3 | + ChainMetadataForAltVM, |
| 4 | + ITransactionSubmitter, |
| 5 | + MinimumRequiredGasByAction, |
| 6 | + ProtocolProvider, |
| 7 | + SignerConfig, |
| 8 | + TransactionSubmitterConfig, |
| 9 | +} from '@hyperlane-xyz/provider-sdk'; |
| 10 | +import type { IProvider } from '@hyperlane-xyz/provider-sdk/altvm'; |
| 11 | +import type { IRawHookArtifactManager } from '@hyperlane-xyz/provider-sdk/hook'; |
| 12 | +import type { IRawIsmArtifactManager } from '@hyperlane-xyz/provider-sdk/ism'; |
| 13 | +import type { |
| 14 | + AnnotatedTx, |
| 15 | + TxReceipt, |
| 16 | +} from '@hyperlane-xyz/provider-sdk/module'; |
| 17 | +import type { IRawWarpArtifactManager } from '@hyperlane-xyz/provider-sdk/warp'; |
| 18 | +import { address as parseAddress } from '@solana/kit'; |
| 19 | +import { assert } from '@hyperlane-xyz/utils'; |
2 | 20 |
|
3 | | -export interface SvmInstructionEnvelope { |
4 | | - programAddress: Address; |
5 | | - instruction: Instruction; |
6 | | - label?: string; |
| 21 | +import { SvmHookArtifactManager } from '../hook/hook-artifact-manager.js'; |
| 22 | +import { SvmIsmArtifactManager } from '../ism/ism-artifact-manager.js'; |
| 23 | +import { createRpc } from '../rpc.js'; |
| 24 | + |
| 25 | +import { SvmProvider } from './provider.js'; |
| 26 | +import { SvmSigner } from './signer.js'; |
| 27 | + |
| 28 | +export class SvmProtocolProvider implements ProtocolProvider { |
| 29 | + createProvider(chainMetadata: ChainMetadataForAltVM): Promise<IProvider> { |
| 30 | + const rpcUrls = this.getRpcUrls(chainMetadata); |
| 31 | + return SvmProvider.connect(rpcUrls, chainMetadata.chainId); |
| 32 | + } |
| 33 | + |
| 34 | + async createSigner( |
| 35 | + chainMetadata: ChainMetadataForAltVM, |
| 36 | + config: SignerConfig, |
| 37 | + ): Promise<AltVM.ISigner<AnnotatedTx, TxReceipt>> { |
| 38 | + const rpcUrls = this.getRpcUrls(chainMetadata); |
| 39 | + return SvmSigner.connectWithSigner(rpcUrls, config.privateKey); |
| 40 | + } |
| 41 | + |
| 42 | + createSubmitter<TConfig extends TransactionSubmitterConfig>( |
| 43 | + _chainMetadata: ChainMetadataForAltVM, |
| 44 | + _config: TConfig, |
| 45 | + ): Promise<ITransactionSubmitter> { |
| 46 | + throw new Error('Transaction submitter not yet implemented for Sealevel'); |
| 47 | + } |
| 48 | + |
| 49 | + createIsmArtifactManager( |
| 50 | + chainMetadata: ChainMetadataForAltVM, |
| 51 | + ): IRawIsmArtifactManager { |
| 52 | + const rpc = createRpc(this.getRpcUrls(chainMetadata)[0]); |
| 53 | + return new SvmIsmArtifactManager(rpc); |
| 54 | + } |
| 55 | + |
| 56 | + createHookArtifactManager( |
| 57 | + chainMetadata: ChainMetadataForAltVM, |
| 58 | + context?: { mailbox?: string }, |
| 59 | + ): IRawHookArtifactManager { |
| 60 | + assert( |
| 61 | + context?.mailbox, |
| 62 | + 'Mailbox address is required for SVM hook artifact manager', |
| 63 | + ); |
| 64 | + const rpc = createRpc(this.getRpcUrls(chainMetadata)[0]); |
| 65 | + return new SvmHookArtifactManager(rpc, parseAddress(context.mailbox)); |
| 66 | + } |
| 67 | + |
| 68 | + createWarpArtifactManager( |
| 69 | + _chainMetadata: ChainMetadataForAltVM, |
| 70 | + _context?: { mailbox?: string }, |
| 71 | + ): IRawWarpArtifactManager { |
| 72 | + throw new Error('Warp artifact manager not yet implemented for Sealevel'); |
| 73 | + } |
| 74 | + |
| 75 | + getMinGas(): MinimumRequiredGasByAction { |
| 76 | + return { |
| 77 | + CORE_DEPLOY_GAS: 0n, |
| 78 | + // ~2.6 SOL covers program account rent + token PDA rent + ATA payer funding |
| 79 | + WARP_DEPLOY_GAS: 2_600_000_000n, |
| 80 | + TEST_SEND_GAS: 0n, |
| 81 | + AVS_GAS: 0n, |
| 82 | + ISM_DEPLOY_GAS: 0n, |
| 83 | + }; |
| 84 | + } |
| 85 | + |
| 86 | + private getRpcUrls(chainMetadata: ChainMetadataForAltVM): string[] { |
| 87 | + assert( |
| 88 | + chainMetadata.rpcUrls && chainMetadata.rpcUrls.length > 0, |
| 89 | + 'At least one RPC URL is required', |
| 90 | + ); |
| 91 | + return chainMetadata.rpcUrls.map((r) => r.http); |
| 92 | + } |
7 | 93 | } |
0 commit comments