Skip to content

Commit

Permalink
deposit and call wip
Browse files Browse the repository at this point in the history
  • Loading branch information
fadeev committed Dec 10, 2024
1 parent 2f593a5 commit 0cf8745
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 23 deletions.
2 changes: 2 additions & 0 deletions packages/client/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
getZRC20GasToken,
sendZeta,
solanaDeposit,
solanaDepositAndCall,
trackCCTX,
zetachainCall,
zetachainWithdraw,
Expand Down Expand Up @@ -176,6 +177,7 @@ export class ZetaChainClient {
getZRC20FromERC20 = getZRC20FromERC20;
getZRC20GasToken = getZRC20GasToken;
solanaDeposit = solanaDeposit;
solanaDepositAndCall = solanaDepositAndCall;
zetachainWithdrawAndCall = zetachainWithdrawAndCall;
zetachainWithdraw = zetachainWithdraw;
zetachainCall = zetachainCall;
Expand Down
1 change: 1 addition & 0 deletions packages/client/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export * from "./getSupportedChains";
export * from "./prepareData";
export * from "./sendZeta";
export * from "./solanaDeposit";
export * from "./solanaDepositAndCall";
export * from "./trackCCTX";
export * from "./zetachainCall";
export * from "./zetachainWithdraw";
Expand Down
12 changes: 6 additions & 6 deletions packages/client/src/solanaDepositAndCall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,16 @@ export const solanaDepositAndCall = async function (

try {
const tx = new anchor.web3.Transaction();
const m = Buffer.from(
const recipient = Buffer.from(ethers.utils.arrayify(args.recipient));

const message = Buffer.from(
ethers.utils.arrayify(
args.recipient +
ethers.utils.defaultAbiCoder
.encode(args.params[0], args.params[1])
.slice(2)
ethers.utils.defaultAbiCoder.encode(args.params[0], args.params[1])
)
);

const depositInstruction = await gatewayProgram.methods
.deposit(depositAmount, m)
.depositAndCall(depositAmount, recipient, message)
.accounts({
pda: pdaAccount,
signer: this.solanaAdapter
Expand Down
1 change: 1 addition & 0 deletions packages/tasks/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export { poolsTask } from "./pools";
export { sendBTCTask } from "./sendBTC";
export { sendZETATask } from "./sendZETA";
export { solanaDeposit } from "./solanaDeposit";
export { solanaDepositAndCall } from "./solanaDepositAndCall";
export { tokensTask } from "./tokens";
export { zetachainCall } from "./zetachainCall";
export { zetachainWithdraw } from "./zetachainWithdraw";
Expand Down
17 changes: 10 additions & 7 deletions packages/tasks/src/solanaDeposit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ import type { HardhatRuntimeEnvironment } from "hardhat/types";

import { ZetaChainClient } from "../../client/src";

export const main = async (args: any, hre: HardhatRuntimeEnvironment) => {
export const solanaDeposit = async (
args: any,
hre: HardhatRuntimeEnvironment
) => {
const keypair = await getKeypairFromFile(args.idPath);
const wallet = new Wallet(keypair);

Expand All @@ -30,12 +33,6 @@ export const main = async (args: any, hre: HardhatRuntimeEnvironment) => {
await client.solanaDeposit({ amount, recipient });
};

task("solana-deposit", "Solana deposit", main)
.addParam("amount", "Amount of SOL to deposit")
.addParam("recipient", "Universal contract address")
.addOptionalParam("solanaNetwork", "Solana Network", "devnet")
.addOptionalParam("idPath", "Path to id.json", "~/.config/solana/id.json");

export const getKeypairFromFile = async (filepath: string) => {
const path = await import("path");
if (filepath[0] === "~") {
Expand Down Expand Up @@ -66,3 +63,9 @@ export const getKeypairFromFile = async (filepath: string) => {
}
return Keypair.fromSecretKey(parsedFileContents);
};

task("solana-deposit", "Solana deposit", solanaDeposit)
.addParam("amount", "Amount of SOL to deposit")
.addParam("recipient", "Universal contract address")
.addOptionalParam("solanaNetwork", "Solana Network", "devnet")
.addOptionalParam("idPath", "Path to id.json", "~/.config/solana/id.json");
23 changes: 13 additions & 10 deletions packages/tasks/src/solanaDepositAndCall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ import type { HardhatRuntimeEnvironment } from "hardhat/types";

import { ZetaChainClient } from "../../client/src";

export const main = async (args: any, hre: HardhatRuntimeEnvironment) => {
export const solanaDepositAndCall = async (
args: any,
hre: HardhatRuntimeEnvironment
) => {
const keypair = await getKeypairFromFile(args.idPath);
const wallet = new Wallet(keypair);

Expand All @@ -28,17 +31,9 @@ export const main = async (args: any, hre: HardhatRuntimeEnvironment) => {
}
const { amount, idPath } = args;
const params = [JSON.parse(args.types), args.values];
await client.solanaDeposit({ amount, recipient });
await client.solanaDepositAndCall({ amount, params, recipient });
};

task("solana-deposit-and-call", "Solana deposit and call", main)
.addParam("amount", "Amount of SOL to deposit")
.addParam("recipient", "Universal contract address")
.addOptionalParam("solanaNetwork", "Solana Network", "devnet")
.addOptionalParam("idPath", "Path to id.json", "~/.config/solana/id.json")
.addParam("types", "The types of the parameters (example: ['string'])")
.addVariadicPositionalParam("values", "The values of the parameters");

export const getKeypairFromFile = async (filepath: string) => {
const path = await import("path");
if (filepath[0] === "~") {
Expand Down Expand Up @@ -69,3 +64,11 @@ export const getKeypairFromFile = async (filepath: string) => {
}
return Keypair.fromSecretKey(parsedFileContents);
};

task("solana-deposit-and-call", "Solana deposit and call", solanaDepositAndCall)
.addParam("amount", "Amount of SOL to deposit")
.addParam("recipient", "Universal contract address")
.addOptionalParam("solanaNetwork", "Solana Network", "devnet")
.addOptionalParam("idPath", "Path to id.json", "~/.config/solana/id.json")
.addParam("types", "The types of the parameters (example: ['string'])")
.addVariadicPositionalParam("values", "The values of the parameters");

0 comments on commit 0cf8745

Please sign in to comment.