From 2f593a599244960787e78f092a15708e5ce2bddb Mon Sep 17 00:00:00 2001 From: Denis Fadeev Date: Tue, 10 Dec 2024 18:00:56 +0300 Subject: [PATCH] deposit works --- packages/client/src/solanaDeposit.ts | 71 +++++++++++++--------------- 1 file changed, 32 insertions(+), 39 deletions(-) diff --git a/packages/client/src/solanaDeposit.ts b/packages/client/src/solanaDeposit.ts index 722d3c2..290ee0a 100644 --- a/packages/client/src/solanaDeposit.ts +++ b/packages/client/src/solanaDeposit.ts @@ -79,16 +79,9 @@ export const solanaDeposit = async function ( try { const tx = new anchor.web3.Transaction(); - // const m = Buffer.from( - // ethers.utils.arrayify( - // args.recipient + - // ethers.utils.defaultAbiCoder - // .encode(args.params[0], args.params[1]) - // .slice(2) - // ) - // ); + const recipient = Buffer.from(ethers.utils.arrayify(args.recipient)); const depositInstruction = await gatewayProgram.methods - .deposit(depositAmount, args.recipient) + .deposit(depositAmount, recipient) .accounts({ pda: pdaAccount, signer: this.solanaAdapter @@ -98,36 +91,36 @@ export const solanaDeposit = async function ( }) .instruction(); - // tx.add(depositInstruction); - - // // Send the transaction - // let txSignature; - // if (this.solanaAdapter) { - // const { blockhash, lastValidBlockHeight } = - // await connection.getLatestBlockhash(); - // const messageLegacy = new TransactionMessage({ - // instructions: tx.instructions, - // payerKey: this.solanaAdapter.publicKey!, - // recentBlockhash: blockhash, - // }).compileToV0Message(); - - // const versionedTransaction = new VersionedTransaction(messageLegacy); - - // txSignature = await this.solanaAdapter.sendTransaction( - // versionedTransaction, - // connection - // ); - // } else { - // txSignature = await anchor.web3.sendAndConfirmTransaction( - // connection, - // tx, - // [this.solanaWallet!.payer] - // ); - // } - - // console.log("Transaction signature:", txSignature); - - // return txSignature; + tx.add(depositInstruction); + + // Send the transaction + let txSignature; + if (this.solanaAdapter) { + const { blockhash, lastValidBlockHeight } = + await connection.getLatestBlockhash(); + const messageLegacy = new TransactionMessage({ + instructions: tx.instructions, + payerKey: this.solanaAdapter.publicKey!, + recentBlockhash: blockhash, + }).compileToV0Message(); + + const versionedTransaction = new VersionedTransaction(messageLegacy); + + txSignature = await this.solanaAdapter.sendTransaction( + versionedTransaction, + connection + ); + } else { + txSignature = await anchor.web3.sendAndConfirmTransaction( + connection, + tx, + [this.solanaWallet!.payer] + ); + } + + console.log("Transaction signature:", txSignature); + + return txSignature; } catch (error) { console.error("Transaction failed:", error); }