Skip to content

Commit

Permalink
deposit works
Browse files Browse the repository at this point in the history
  • Loading branch information
fadeev committed Dec 10, 2024
1 parent f900f8a commit 2f593a5
Showing 1 changed file with 32 additions and 39 deletions.
71 changes: 32 additions & 39 deletions packages/client/src/solanaDeposit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
}
Expand Down

0 comments on commit 2f593a5

Please sign in to comment.