Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"@openzeppelin/contracts-upgradeable": "4.9.6",
"@scroll-tech/contracts": "^0.1.0",
"@solana-developers/helpers": "^2.4.0",
"@solana-program/token": "^0.5.1",
"@solana/kit": "^2.1.0",
"@solana/spl-token": "^0.4.6",
"@solana/web3.js": "^1.31.0",
Expand Down
112 changes: 102 additions & 10 deletions test/svm/SvmSpoke.Deposit.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,38 @@
import * as anchor from "@coral-xyz/anchor";
import { BN } from "@coral-xyz/anchor";
import { BigNumber, ethers } from "ethers";
import { getApproveCheckedInstruction } from "@solana-program/token";
import {
address,
airdropFactory,
appendTransactionMessageInstruction,
createKeyPairFromBytes,
createSignerFromKeyPair,
getProgramDerivedAddress,
lamports,
pipe,
} from "@solana/kit";
import {
ASSOCIATED_TOKEN_PROGRAM_ID,
TOKEN_PROGRAM_ID,
ExtensionType,
TOKEN_2022_PROGRAM_ID,
createMint,
getOrCreateAssociatedTokenAccount,
mintTo,
getAccount,
TOKEN_PROGRAM_ID,
createApproveCheckedInstruction,
createEnableCpiGuardInstruction,
createMint,
createReallocateInstruction,
ExtensionType,
getAccount,
getOrCreateAssociatedTokenAccount,
mintTo,
} from "@solana/spl-token";
import { PublicKey, Keypair, Transaction, sendAndConfirmTransaction } from "@solana/web3.js";
import { common } from "./SvmSpoke.common";
import { Keypair, PublicKey, Transaction, sendAndConfirmTransaction } from "@solana/web3.js";
import { BigNumber, ethers } from "ethers";
import { SvmSpokeClient } from "../../src/svm";
import { DepositInput } from "../../src/svm/clients/SvmSpoke";
import { intToU8Array32, readEventsUntilFound, u8Array32ToBigNumber, u8Array32ToInt } from "../../src/svm/web3-v1";
import { DepositDataValues } from "../../src/types/svm";
import { intToU8Array32, readEventsUntilFound, u8Array32ToInt, u8Array32ToBigNumber } from "../../src/svm/web3-v1";
import { MAX_EXCLUSIVITY_OFFSET_SECONDS } from "../../test-utils";
import { common } from "./SvmSpoke.common";
import { createDefaultSolanaClient, createDefaultTransaction, signAndSendTransaction } from "./utils";
const { provider, connection, program, owner, seedBalance, initializeState, depositData } = common;
const { createRoutePda, getVaultAta, assertSE, assert, getCurrentTime, depositQuoteTimeBuffer, fillDeadlineBuffer } =
common;
Expand Down Expand Up @@ -698,4 +712,82 @@ describe("svm_spoke.deposit", () => {
assert.include(err.toString(), "owner does not match");
}
});

describe("codama client and solana kit", () => {
it("Deposit with with solana kit and codama client", async () => {
// typescript is not happy with the depositData object
if (!depositData.inputToken || !depositData.depositor) {
throw new Error("Input token or depositor is null");
}

const rpcClient = createDefaultSolanaClient();
const signer = await createSignerFromKeyPair(await createKeyPairFromBytes(depositor.secretKey));

await airdropFactory(rpcClient)({
recipientAddress: signer.address,
lamports: lamports(100000000000000n),
commitment: "confirmed",
});

const [eventAuthority] = await getProgramDerivedAddress({
programAddress: address(program.programId.toString()),
seeds: ["__event_authority"],
});

// note that we are using getApproveCheckedInstruction from @solana-program/token
const approveIx = getApproveCheckedInstruction({
source: address(depositAccounts.depositorTokenAccount.toString()),
mint: address(depositAccounts.mint.toString()),
delegate: address(depositAccounts.state.toString()),
owner: address(depositor.publicKey.toString()),
amount: BigInt(depositData.inputAmount.toString()),
decimals: tokenDecimals,
});

const formattedDepositData = {
depositor: address(depositData.depositor.toString()),
recipient: address(depositData.recipient.toString()),
inputToken: address(depositData.inputToken.toString()),
outputToken: address(depositData.outputToken.toString()),
inputAmount: BigInt(depositData.inputAmount.toString()),
outputAmount: BigInt(depositData.outputAmount.toString()),
destinationChainId: depositData.destinationChainId.toNumber(),
exclusiveRelayer: address(depositData.exclusiveRelayer.toString()),
quoteTimestamp: depositData.quoteTimestamp.toNumber(),
fillDeadline: depositData.fillDeadline.toNumber(),
exclusivityParameter: depositData.exclusivityParameter.toNumber(),
message: depositData.message,
};

const formattedAccounts = {
state: address(depositAccounts.state.toString()),
route: address(depositAccounts.route.toString()),
depositorTokenAccount: address(depositAccounts.depositorTokenAccount.toString()),
mint: address(depositAccounts.mint.toString()),
tokenProgram: address(tokenProgram.toString()),
program: address(program.programId.toString()),
vault: address(vault.toString()),
};

const depositInput: DepositInput = {
...formattedDepositData,
...formattedAccounts,
eventAuthority,
signer,
};

const depositIx = await SvmSpokeClient.getDepositInstructionAsync(depositInput);

const tx = await pipe(
await createDefaultTransaction(rpcClient, signer),
(tx) => appendTransactionMessageInstruction(approveIx, tx),
(tx) => appendTransactionMessageInstruction(depositIx, tx),
(tx) => signAndSendTransaction(rpcClient, tx)
);

const events = await readEventsUntilFound(connection, tx, [program]);
const event = events[0].data; // 0th event is the latest event;
assertSE(event.depositId, intToU8Array32(1), "Deposit ID should match the expected hash");
});
});
});
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2507,6 +2507,11 @@
bs58 "^6.0.0"
dotenv "^16.4.5"

"@solana-program/token@^0.5.1":
version "0.5.1"
resolved "https://registry.npmjs.org/@solana-program/token/-/token-0.5.1.tgz#10e327df23f05a7f892fd33a9b6418f17dd62296"
integrity sha512-bJvynW5q9SFuVOZ5vqGVkmaPGA0MCC+m9jgJj1nk5m20I389/ms69ASnhWGoOPNcie7S9OwBX0gTj2fiyWpfag==

"@solana/accounts@2.1.0":
version "2.1.0"
resolved "https://registry.npmjs.org/@solana/accounts/-/accounts-2.1.0.tgz#23fa5ba20dd7af9bfb84abc638096378b62c7276"
Expand Down
Loading