diff --git a/README.md b/README.md index 9f5cf96..4ac150c 100644 --- a/README.md +++ b/README.md @@ -40,10 +40,10 @@ yarn add omni-bridge-sdk The SDK currently provides a split interface for cross-chain transfers: - `omniTransfer`: A unified interface for initiating transfers from any supported chain -- Chain-specific deployers: Required for finalizing transfers on destination chains +- Chain-specific clients: Required for finalizing transfers on destination chains > [!NOTE] -> We're working on unifying this into a single interface that will handle the complete transfer lifecycle. For now, you'll need to use both `omniTransfer` and chain-specific deployers as shown below. +> We're working on unifying this into a single interface that will handle the complete transfer lifecycle. For now, you'll need to use both `omniTransfer` and chain-specific clients as shown below. Here's a complete example: @@ -53,7 +53,7 @@ import { ChainKind, omniAddress, OmniBridgeAPI, - getDeployer, + getClient, } from "omni-bridge-sdk"; import { connect } from "near-api-js"; @@ -97,8 +97,8 @@ do { if (status === "ready_for_finalize") { // 4. Finalize transfer on destination chain - const ethDeployer = getDeployer(ChainKind.Eth, ethWallet); - await ethDeployer.finalizeTransfer(transferMessage, signature); + const ethClient = getClient(ChainKind.Eth, ethWallet); + await ethClient.finalizeTransfer(transferMessage, signature); break; } @@ -131,16 +131,16 @@ const status = await api.getTransferStatus(chain, nonce); ### 3. Transfer Finalization -When status is "ready_for_finalize", use chain-specific deployers to complete the transfer: +When status is "ready_for_finalize", use chain-specific clients to complete the transfer: ```typescript // Finalize on Ethereum/EVM chains -const evmDeployer = getDeployer(ChainKind.Eth, ethWallet); -await evmDeployer.finalizeTransfer(transferMessage, signature); +const evmClient = getClient(ChainKind.Eth, ethWallet); +await evmClient.finalizeTransfer(transferMessage, signature); // Finalize on NEAR -const nearDeployer = getDeployer(ChainKind.Near, nearAccount); -await nearDeployer.finalizeTransfer( +const nearClient = getClient(ChainKind.Near, nearAccount); +await nearClient.finalizeTransfer( token, recipientAccount, storageDeposit, @@ -149,8 +149,8 @@ await nearDeployer.finalizeTransfer( ); // Finalize on Solana -const solDeployer = getDeployer(ChainKind.Sol, provider); -await solDeployer.finalizeTransfer(transferMessage, signature); +const solClient = getClient(ChainKind.Sol, provider); +await solClient.finalizeTransfer(transferMessage, signature); ``` ## Core Concepts @@ -245,20 +245,20 @@ const result = await omniTransfer(provider, transfer); ### Deploying Tokens -Token deployment uses chain-specific deployers through a unified interface: +Token deployment uses chain-specific clients through a unified interface: ```typescript -import { getDeployer } from "omni-bridge-sdk"; +import { getClient } from "omni-bridge-sdk"; -// Initialize deployer for source chain -const deployer = getDeployer(ChainKind.Near, wallet); +// Initialize client for source chain +const client = getClient(ChainKind.Near, wallet); // Example: Deploy NEAR token to Ethereum -const txHash = await deployer.logMetadata("near:token.near"); +const txHash = await client.logMetadata("near:token.near"); console.log(`Metadata logged with tx: ${txHash}`); // Deploy token with signed MPC payload -const result = await deployer.deployToken(signature, { +const result = await client.deployToken(signature, { token: "token.near", name: "Token Name", symbol: "TKN", diff --git a/docs/token-deployment.md b/docs/token-deployment.md index 9a37694..6cdfc1b 100644 --- a/docs/token-deployment.md +++ b/docs/token-deployment.md @@ -17,7 +17,7 @@ Important: To deploy a token on any chain, it must first exist on NEAR. You cann ### NEAR Chain Deployment ```typescript -import { NearDeployer, ChainKind } from "omni-bridge-sdk"; +import { NearBridgeClient, ChainKind } from "omni-bridge-sdk"; import { connect } from "near-api-js"; // Setup NEAR connection @@ -25,22 +25,22 @@ const near = await connect({ networkId: "testnet", nodeUrl: "https://rpc.testnet.near.org", }); -const account = await near.account("deployer.near"); +const account = await near.account("client.near"); -// Initialize deployer -const deployer = new NearDeployer(account); +// Initialize client +const client = new NearBridgeClient(account); // 1. Log metadata for existing NEAR token -const logTxHash = await deployer.logMetadata("near:token.near"); +const logTxHash = await client.logMetadata("near:token.near"); // 2. Deploy to destination chain (e.g., Ethereum) -const deployTxHash = await deployer.deployToken( +const deployTxHash = await client.deployToken( ChainKind.Eth, vaa // Wormhole VAA containing deployment approval ); // 3. For tokens being deployed TO NEAR, bind them after deployment -await deployer.bindToken( +await client.bindToken( ChainKind.Eth, // Source chain vaa, // Optional: Wormhole VAA evmProof // Optional: EVM proof (for EVM chains) @@ -50,21 +50,21 @@ await deployer.bindToken( ### EVM Chain Deployment (Ethereum/Base/Arbitrum) ```typescript -import { EVMDeployer, ChainKind } from "omni-bridge-sdk"; +import { EvmBridgeClient, ChainKind } from "omni-bridge-sdk"; import { ethers } from "ethers"; // Setup EVM wallet const provider = new ethers.providers.Web3Provider(window.ethereum); const wallet = provider.getSigner(); -// Initialize deployer for specific chain -const deployer = new EVMDeployer(wallet, ChainKind.Eth); +// Initialize client for specific chain +const client = new EvmBridgeClient(wallet, ChainKind.Eth); // 1. Log metadata for existing token -const logTxHash = await deployer.logMetadata("eth:0x123..."); +const logTxHash = await client.logMetadata("eth:0x123..."); // 2. Deploy token using MPC signature -const { txHash, tokenAddress } = await deployer.deployToken( +const { txHash, tokenAddress } = await client.deployToken( signature, // MPC signature authorizing deployment { token: "token_id", @@ -78,27 +78,27 @@ const { txHash, tokenAddress } = await deployer.deployToken( ### Solana Deployment ```typescript -import { SolanaDeployer } from "omni-bridge-sdk"; +import { SolanaBridgeClient } from "omni-bridge-sdk"; import { Connection, PublicKey, Keypair } from "@solana/web3.js"; // Setup Solana connection const connection = new Connection("https://api.testnet.solana.com"); const payer = Keypair.generate(); -// Initialize deployer -const deployer = new SolanaDeployer( +// Initialize client +const client = new SolanaBridgeClient( provider, new PublicKey("wormhole_program_id") ); // 1. Log metadata for existing SPL token -const logTxHash = await deployer.logMetadata( +const logTxHash = await client.logMetadata( tokenPubkey, payer // Optional payer for transaction ); // 2. Deploy token using MPC signature -const { txHash, tokenAddress } = await deployer.deployToken( +const { txHash, tokenAddress } = await client.deployToken( signature, { token: "token_id", @@ -116,7 +116,7 @@ Each deployment step can encounter different types of errors that need handling: ```typescript try { - await deployer.logMetadata("near:token.near"); + await client.logMetadata("near:token.near"); } catch (error) { if (error.message.includes("Token metadata not provided")) { // Handle missing metadata @@ -164,12 +164,12 @@ console.log(status); // "pending" | "ready_for_finalize" | "finalized" | "ready_ ```typescript // For EVM chains -const evmDeployer = new EVMDeployer(wallet, ChainKind.Eth); -const nearTokenAddress = await evmDeployer.factory.nearToEthToken("token.near"); +const evmClient = new EvmClient(wallet, ChainKind.Eth); +const nearTokenAddress = await evmClient.factory.nearToEthToken("token.near"); // For Solana -const solDeployer = new SolanaDeployer(provider, wormholeProgramId); -const isBridgedToken = await solDeployer.isBridgedToken(tokenPubkey); +const solClient = new SolanaClient(provider, wormholeProgramId); +const isBridgedToken = await solClient.isBridgedToken(tokenPubkey); ``` ## Security Considerations @@ -193,7 +193,7 @@ const isBridgedToken = await solDeployer.isBridgedToken(tokenPubkey); ```typescript // Check required balances on NEAR -const { regBalance, initBalance, storage } = await deployer.getBalances(); +const { regBalance, initBalance, storage } = await client.getBalances(); const requiredBalance = regBalance + initBalance; ``` @@ -222,7 +222,7 @@ if (!signature.isValidFor(ChainKind.Eth)) { while ((await api.getDeploymentStatus(txHash)).status !== "ready_for_bind") { await new Promise((r) => setTimeout(r, 1000)); } -await deployer.bindToken(sourceChain, vaa); +await client.bindToken(sourceChain, vaa); ``` ## Chain Support Matrix diff --git a/src/client.ts b/src/client.ts index ac6b6e5..263a722 100644 --- a/src/client.ts +++ b/src/client.ts @@ -2,9 +2,9 @@ import { AnchorProvider as SolWallet } from "@coral-xyz/anchor" import { PublicKey } from "@solana/web3.js" import { Wallet as EthWallet } from "ethers" import { Account as NearAccount } from "near-api-js" -import { EVMDeployer } from "./deployer/evm" -import { NearDeployer } from "./deployer/near" -import { SolanaDeployer } from "./deployer/solana" +import { EvmBridgeClient } from "./clients/evm" +import { NearBridgeClient } from "./clients/near" +import { SolanaBridgeClient } from "./clients/solana" import { ChainKind, type OmniTransferMessage, type OmniTransferResult } from "./types" export async function omniTransfer( @@ -12,12 +12,8 @@ export async function omniTransfer( transfer: OmniTransferMessage, ): Promise { if (wallet instanceof NearAccount) { - const deployer = new NearDeployer(wallet, "omni-locker.testnet") // TODO: Get from config - const { nonce, hash } = await deployer.initTransfer( - transfer.tokenAddress, - transfer.recipient, - transfer.amount, - ) + const client = new NearBridgeClient(wallet) + const { nonce, hash } = await client.initTransfer(transfer) return { txId: hash, nonce: BigInt(nonce), @@ -25,12 +21,8 @@ export async function omniTransfer( } if (wallet instanceof EthWallet) { - const deployer = new EVMDeployer(wallet, ChainKind.Eth) - const { hash, nonce } = await deployer.initTransfer( - transfer.tokenAddress, - transfer.recipient, - transfer.amount, - ) + const client = new EvmBridgeClient(wallet, ChainKind.Eth) + const { hash, nonce } = await client.initTransfer(transfer) return { txId: hash, nonce: BigInt(nonce), @@ -38,15 +30,11 @@ export async function omniTransfer( } if (wallet instanceof SolWallet) { - const deployer = new SolanaDeployer( + const client = new SolanaBridgeClient( wallet, new PublicKey("3u8hJUVTA4jH1wYAyUur7FFZVQ8H635K3tSHHF4ssjQ5"), ) // TODO: Get from config - const { nonce, hash } = await deployer.initTransfer( - transfer.tokenAddress, - transfer.recipient, - transfer.amount, - ) + const { nonce, hash } = await client.initTransfer(transfer) return { txId: hash, nonce: BigInt(nonce), diff --git a/src/deployer/evm.ts b/src/clients/evm.ts similarity index 92% rename from src/deployer/evm.ts rename to src/clients/evm.ts index ad7c316..770dfbc 100644 --- a/src/deployer/evm.ts +++ b/src/clients/evm.ts @@ -4,9 +4,9 @@ import type { ChainKind, MPCSignature, OmniAddress, + OmniTransferMessage, TokenMetadata, TransferMessagePayload, - U128, } from "../types" import { getChain } from "../utils" @@ -68,15 +68,15 @@ const FACTORY_ADDRESSES: Record, string | undefined> = { } /** - * EVM blockchain implementation of the token deployer + * EVM blockchain implementation of the bridge client */ -export class EVMDeployer { +export class EvmBridgeClient { private factory: ethers.Contract private chainKind: EVMChainKind private chainTag: ChainTag /** - * Creates a new EVM token deployer instance + * Creates a new EVM bridge client instance * @param wallet - Ethereum signer instance for transaction signing * @param chain - The EVM chain to deploy to (Ethereum, Base, or Arbitrum) * @throws {Error} If factory address is not configured for the chain or if chain is not EVM @@ -109,7 +109,7 @@ export class EVMDeployer { async logMetadata(tokenAddress: OmniAddress): Promise { const sourceChain = getChain(tokenAddress) - // Validate source chain matches the deployer's chain + // Validate source chain matches the client's chain if (!ChainUtils.areEqual(sourceChain, this.chainKind)) { throw new Error(`Token address must be on ${this.chainTag}`) } @@ -168,27 +168,23 @@ export class EVMDeployer { * @throws {Error} If token address is not on the correct EVM chain * @returns Promise resolving to object containing transaction hash and nonce */ - async initTransfer( - token: OmniAddress, - recipient: OmniAddress, - amount: U128, - ): Promise<{ hash: string; nonce: number }> { - const sourceChain = getChain(token) - - // Validate source chain matches the deployer's chain + async initTransfer(transfer: OmniTransferMessage): Promise<{ hash: string; nonce: number }> { + const sourceChain = getChain(transfer.tokenAddress) + + // Validate source chain matches the client's chain if (!ChainUtils.areEqual(sourceChain, this.chainKind)) { throw new Error(`Token address must be on ${this.chainTag}`) } - const [_, tokenAccountId] = token.split(":") + const [_, tokenAccountId] = transfer.tokenAddress.split(":") try { const tx = await this.factory.initTransfer( tokenAccountId, - amount.valueOf(), - 0, - 0, - recipient, + transfer.amount, + transfer.fee, + transfer.nativeFee, + transfer.recipient, "", ) return { diff --git a/src/deployer/near.ts b/src/clients/near.ts similarity index 94% rename from src/deployer/near.ts rename to src/clients/near.ts index f3c0a97..73274bf 100644 --- a/src/deployer/near.ts +++ b/src/clients/near.ts @@ -13,6 +13,7 @@ import { FinTransferArgsSchema, type LogMetadataArgs, type OmniAddress, + type OmniTransferMessage, ProofKind, type U128, type WormholeVerifyProofArgs, @@ -85,22 +86,22 @@ interface BalanceResults { } /** - * NEAR blockchain implementation of the token deployer. + * NEAR blockchain implementation of the bridge client. * Handles token deployment, binding, and transfer operations on the NEAR blockchain. */ -export class NearDeployer { +export class NearBridgeClient { /** - * Creates a new NEAR token deployer instance + * Creates a new NEAR bridge client instance * @param wallet - NEAR account instance for transaction signing * @param lockerAddress - Address of the token locker contract * @throws {Error} If locker address is not configured */ constructor( private wallet: Account, - private lockerAddress: string = process.env.OMNI_LOCKER_NEAR as string, + private lockerAddress: string = process.env.OMNI_BRIDGE_NEAR as string, ) { if (!this.lockerAddress) { - throw new Error("OMNI_LOCKER_NEAR address not configured") + throw new Error("OMNI_BRIDGE_NEAR address not configured") } } @@ -236,15 +237,11 @@ export class NearDeployer { * @returns Promise resolving to object containing transaction hash and nonce */ - async initTransfer( - token: OmniAddress, - recipient: OmniAddress, - amount: U128, - ): Promise<{ hash: string; nonce: number }> { - if (getChain(token) !== ChainKind.Near) { + async initTransfer(transfer: OmniTransferMessage): Promise<{ hash: string; nonce: number }> { + if (getChain(transfer.tokenAddress) !== ChainKind.Near) { throw new Error("Token address must be on NEAR") } - const tokenAddress = token.split(":")[1] + const tokenAddress = transfer.tokenAddress.split(":")[1] const { regBalance, initBalance, storage } = await this.getBalances() const requiredBalance = regBalance + initBalance @@ -262,13 +259,13 @@ export class NearDeployer { } const initTransferMessage: InitTransferMessage = { - recipient: recipient, - fee: "0", - native_token_fee: "0", + recipient: transfer.recipient, + fee: transfer.fee.toString(), + native_token_fee: transfer.nativeFee.toString(), } const args: TransferMessage = { receiver_id: this.lockerAddress, - amount: amount.toString(), + amount: transfer.amount.toString(), memo: null, msg: JSON.stringify(initTransferMessage), } diff --git a/src/deployer/solana.ts b/src/clients/solana.ts similarity index 93% rename from src/deployer/solana.ts rename to src/clients/solana.ts index 47c9c3b..6de88e8 100644 --- a/src/deployer/solana.ts +++ b/src/clients/solana.ts @@ -13,9 +13,9 @@ import { type DepositPayload, type MPCSignature, type OmniAddress, + type OmniTransferMessage, type TokenMetadata, type TransferMessagePayload, - type U128, } from "../types" import type { BridgeTokenFactory } from "../types/solana/bridge_token_factory" import BRIDGE_TOKEN_FACTORY_IDL from "../types/solana/bridge_token_factory.json" @@ -23,7 +23,7 @@ import { getChain } from "../utils" const MPL_PROGRAM_ID = new PublicKey("metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s") -export class SolanaDeployer { +export class SolanaBridgeClient { private readonly wormholeProgramId: PublicKey private readonly program: Program @@ -45,18 +45,24 @@ export class SolanaDeployer { SOL_VAULT: this.getConstant("SOL_VAULT_SEED"), } - constructor(provider: Provider, wormholeProgramId: PublicKey) { + constructor( + provider: Provider, + wormholeProgramId: PublicKey = new PublicKey(process.env.WORMHOLE_SOL as string), + ) { this.wormholeProgramId = wormholeProgramId this.program = new Program(BRIDGE_TOKEN_FACTORY_IDL as BridgeTokenFactory, provider) } private config(): [PublicKey, number] { - return PublicKey.findProgramAddressSync([SolanaDeployer.SEEDS.CONFIG], this.program.programId) + return PublicKey.findProgramAddressSync( + [SolanaBridgeClient.SEEDS.CONFIG], + this.program.programId, + ) } private authority(): [PublicKey, number] { return PublicKey.findProgramAddressSync( - [SolanaDeployer.SEEDS.AUTHORITY], + [SolanaBridgeClient.SEEDS.AUTHORITY], this.program.programId, ) } @@ -84,21 +90,21 @@ export class SolanaDeployer { private wrappedMintId(token: string): [PublicKey, number] { return PublicKey.findProgramAddressSync( - [SolanaDeployer.SEEDS.WRAPPED_MINT, Buffer.from(token, "utf-8")], + [SolanaBridgeClient.SEEDS.WRAPPED_MINT, Buffer.from(token, "utf-8")], this.program.programId, ) } private vaultId(mint: PublicKey): [PublicKey, number] { return PublicKey.findProgramAddressSync( - [SolanaDeployer.SEEDS.VAULT, mint.toBuffer()], + [SolanaBridgeClient.SEEDS.VAULT, mint.toBuffer()], this.program.programId, ) } private solVaultId(): [PublicKey, number] { return PublicKey.findProgramAddressSync( - [SolanaDeployer.SEEDS.SOL_VAULT], + [SolanaBridgeClient.SEEDS.SOL_VAULT], this.program.programId, ) } @@ -219,12 +225,10 @@ export class SolanaDeployer { * @returns Promise resolving to object containing transaction hash and nonce */ async initTransfer( - token: OmniAddress, - recipient: OmniAddress, - amount: U128, + transfer: OmniTransferMessage, payer?: Keypair, ): Promise<{ hash: string; nonce: number }> { - if (getChain(token) !== ChainKind.Sol) { + if (getChain(transfer.tokenAddress) !== ChainKind.Sol) { throw new Error("Token address must be on Solana") } const wormholeMessage = Keypair.generate() @@ -234,7 +238,7 @@ export class SolanaDeployer { throw new Error("Payer is not configured") } - const mint = new PublicKey(token.split(":")[1]) + const mint = new PublicKey(transfer.tokenAddress.split(":")[1]) const [from] = PublicKey.findProgramAddressSync( [payerPubKey.toBuffer(), TOKEN_PROGRAM_ID.toBuffer(), mint.toBuffer()], ASSOCIATED_TOKEN_PROGRAM_ID, @@ -245,10 +249,10 @@ export class SolanaDeployer { try { const tx = await this.program.methods .initTransfer({ - amount: new BN(amount.valueOf()), - recipient, - fee: new BN(0), - nativeFee: new BN(0), + amount: new BN(transfer.amount.valueOf()), + recipient: transfer.recipient, + fee: new BN(transfer.fee.valueOf()), + nativeFee: new BN(transfer.nativeFee.valueOf()), }) .accountsStrict({ authority: this.authority()[0], diff --git a/src/factory.ts b/src/factory.ts index ce02ea4..a218dde 100644 --- a/src/factory.ts +++ b/src/factory.ts @@ -1,32 +1,36 @@ +import type { AnchorProvider } from "@coral-xyz/anchor" import type { ethers } from "ethers" import type { Account } from "near-api-js" -import { EVMDeployer } from "./deployer/evm" -import { NearDeployer } from "./deployer/near" +import { EvmBridgeClient } from "./clients/evm" +import { NearBridgeClient } from "./clients/near" +import { SolanaBridgeClient } from "./clients/solana" import { ChainKind } from "./types" /** - * Creates a chain-specific deployer instance - * @param chain - The blockchain network to create a deployer for + * Creates a chain-specific bridge client instance + * @param chain - The blockchain network to create a client for * @param wallet - Chain-specific wallet instance for signing transactions - * @returns A deployer instance for the specified chain - * @throws {Error} If no deployer implementation exists for the chain + * @returns A client instance for the specified chain + * @throws {Error} If no client implementation exists for the chain * * @example * ```typescript * const nearAccount = await connect(config); - * const deployer = getDeployer(ChainKind.Near, nearAccount); - * const txHash = await deployer.initDeployToken("near:token.near"); + * const client = getClient(ChainKind.Near, nearAccount); + * const txHash = await client.initDeployToken("near:token.near"); * ``` */ -export function getDeployer(chain: ChainKind, wallet: TWallet) { +export function getClient(chain: ChainKind, wallet: TWallet) { switch (chain) { case ChainKind.Near: - return new NearDeployer(wallet as Account) + return new NearBridgeClient(wallet as Account) case ChainKind.Eth: case ChainKind.Base: case ChainKind.Arb: - return new EVMDeployer(wallet as ethers.Signer, chain) + return new EvmBridgeClient(wallet as ethers.Signer, chain) + case ChainKind.Sol: + return new SolanaBridgeClient(wallet as AnchorProvider) default: - throw new Error(`No deployer implementation for chain: ${chain}`) + throw new Error(`No client implementation for chain: ${chain}`) } } diff --git a/tests/chains/near.test.ts b/tests/chains/near.test.ts index 6c00c9b..6fad0cb 100644 --- a/tests/chains/near.test.ts +++ b/tests/chains/near.test.ts @@ -1,6 +1,6 @@ import type { Account } from "near-api-js" import { beforeEach, describe, expect, it, vi } from "vitest" -import { NearDeployer } from "../../src/deployer/near" +import { NearBridgeClient } from "../../src/clients/near" import { ChainKind, ProofKind } from "../../src/types" // Mock the entire borsher module @@ -16,9 +16,9 @@ vi.mock("borsher", () => ({ }, })) -describe("NearDeployer", () => { +describe("NearBridgeClient", () => { let mockWallet: Account - let deployer: NearDeployer + let client: NearBridgeClient const mockLockerAddress = "test.near" const mockTxHash = "mock-tx-hash" @@ -32,33 +32,31 @@ describe("NearDeployer", () => { }), } as unknown as Account - // Create deployer instance - deployer = new NearDeployer(mockWallet, mockLockerAddress) + // Create client instance + client = new NearBridgeClient(mockWallet, mockLockerAddress) }) describe("constructor", () => { it("should throw error if locker address is not provided", () => { - expect(() => new NearDeployer(mockWallet, "")).toThrow( - "OMNI_LOCKER_NEAR address not configured", + expect(() => new NearBridgeClient(mockWallet, "")).toThrow( + "OMNI_BRIDGE_NEAR address not configured", ) }) it("should create instance with provided wallet and locker address", () => { - const deployer = new NearDeployer(mockWallet, mockLockerAddress) - expect(deployer).toBeInstanceOf(NearDeployer) + const client = new NearBridgeClient(mockWallet, mockLockerAddress) + expect(client).toBeInstanceOf(NearBridgeClient) }) }) describe("logMetadata", () => { it("should throw error if token address is not on NEAR", async () => { - await expect(deployer.logMetadata("eth:0x123")).rejects.toThrow( - "Token address must be on NEAR", - ) + await expect(client.logMetadata("eth:0x123")).rejects.toThrow("Token address must be on NEAR") }) it("should call log_metadata with correct arguments", async () => { const tokenAddress = "near:test-token.near" - const txHash = await deployer.logMetadata(tokenAddress) + const txHash = await client.logMetadata(tokenAddress) expect(mockWallet.functionCall).toHaveBeenCalledWith({ contractId: mockLockerAddress, @@ -78,7 +76,7 @@ describe("NearDeployer", () => { const destinationChain = ChainKind.Eth const mockVaa = "mock-vaa" - const txHash = await deployer.deployToken(destinationChain, mockVaa) + const txHash = await client.deployToken(destinationChain, mockVaa) expect(mockWallet.functionCall).toHaveBeenCalledWith({ contractId: mockLockerAddress, @@ -96,7 +94,7 @@ describe("NearDeployer", () => { const destinationChain = ChainKind.Eth const mockVaa = "mock-vaa" - const txHash = await deployer.bindToken(destinationChain, mockVaa) + const txHash = await client.bindToken(destinationChain, mockVaa) expect(mockWallet.functionCall).toHaveBeenCalledWith({ contractId: mockLockerAddress, @@ -127,13 +125,13 @@ describe("NearDeployer", () => { it("should throw error if neither VAA nor EVM proof is provided", async () => { await expect( - deployer.finalizeTransfer(mockToken, mockAccount, mockStorageDeposit, ChainKind.Near), + client.finalizeTransfer(mockToken, mockAccount, mockStorageDeposit, ChainKind.Near), ).rejects.toThrow("Must provide either VAA or EVM proof") }) it("should throw error if EVM proof is provided for non-EVM chain", async () => { await expect( - deployer.finalizeTransfer( + client.finalizeTransfer( mockToken, mockAccount, mockStorageDeposit, @@ -145,7 +143,7 @@ describe("NearDeployer", () => { }) it("should call finalize_transfer with VAA correctly", async () => { - const txHash = await deployer.finalizeTransfer( + const txHash = await client.finalizeTransfer( mockToken, mockAccount, mockStorageDeposit, @@ -164,7 +162,7 @@ describe("NearDeployer", () => { }) it("should call finalize_transfer with EVM proof correctly", async () => { - const txHash = await deployer.finalizeTransfer( + const txHash = await client.finalizeTransfer( mockToken, mockAccount, mockStorageDeposit, @@ -188,13 +186,7 @@ describe("NearDeployer", () => { mockWallet.functionCall = vi.fn().mockRejectedValue(error) await expect( - deployer.finalizeTransfer( - mockToken, - mockAccount, - mockStorageDeposit, - ChainKind.Sol, - mockVaa, - ), + client.finalizeTransfer(mockToken, mockAccount, mockStorageDeposit, ChainKind.Sol, mockVaa), ).rejects.toThrow("NEAR finalize transfer error") }) }) @@ -204,7 +196,7 @@ describe("NearDeployer", () => { const error = new Error("NEAR error") mockWallet.functionCall = vi.fn().mockRejectedValue(error) - await expect(deployer.logMetadata("near:test-token.near")).rejects.toThrow("NEAR error") + await expect(client.logMetadata("near:test-token.near")).rejects.toThrow("NEAR error") }) }) })