Skip to content

Commit 719798e

Browse files
committed
Migrate chain funcs to solana web3
1 parent 724c667 commit 719798e

File tree

9 files changed

+905
-136
lines changed

9 files changed

+905
-136
lines changed

packages/commands/src/solana/call.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,22 @@ import { z } from "zod";
33
import { solanaCall } from "../../../../src/chains/solana/call";
44
import { handleError, validateAndParseSchema } from "../../../../utils";
55
import { parseAbiValues } from "../../../../utils/parseAbiValues";
6+
import {
7+
getAPIbyChainId,
8+
getBrowserSafeKeypair,
9+
} from "../../../../utils/solana.browser.helpers";
610
import {
711
confirmSolanaTx,
8-
createRevertOptions,
12+
createRevertOptions as createCliRevertOptions,
913
createSolanaCommandWithCommonOptions,
10-
getAPIbyChainId,
11-
getKeypair,
1214
prepareRevertOptions,
1315
solanaCallOptionsSchema,
1416
} from "../../../../utils/solana.commands.helpers";
1517

1618
type CallOptions = z.infer<typeof solanaCallOptionsSchema>;
1719

1820
const main = async (options: CallOptions) => {
19-
const keypair = await getKeypair({
21+
const keypair = await getBrowserSafeKeypair({
2022
mnemonic: options.mnemonic,
2123
name: options.name,
2224
privateKey: options.privateKey,
@@ -29,11 +31,16 @@ const main = async (options: CallOptions) => {
2931

3032
const revertOptions = prepareRevertOptions(options);
3133

34+
// Create an Anchor PublicKey for CLI confirmation (which expects Anchor types)
35+
const anchorPublicKey = new (
36+
await import("@coral-xyz/anchor")
37+
).web3.PublicKey(keypair.publicKey.toBase58());
38+
3239
await confirmSolanaTx({
3340
api: API,
3441
message: values.join(", "),
3542
receiver: options.receiver,
36-
revertOptions: createRevertOptions(revertOptions, keypair.publicKey),
43+
revertOptions: createCliRevertOptions(revertOptions, anchorPublicKey),
3744
sender: keypair.publicKey.toBase58(),
3845
});
3946

packages/commands/src/solana/deposit.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,22 @@ import { z } from "zod";
33
import { solanaDeposit } from "../../../../src/chains/solana/deposit";
44
import { SOLANA_TOKEN_PROGRAM } from "../../../../types/shared.constants";
55
import { handleError, validateAndParseSchema } from "../../../../utils";
6+
import {
7+
getAPIbyChainId,
8+
getBrowserSafeKeypair,
9+
} from "../../../../utils/solana.browser.helpers";
610
import {
711
confirmSolanaTx,
812
createRevertOptions,
913
createSolanaCommandWithCommonOptions,
10-
getAPIbyChainId,
11-
getKeypair,
1214
prepareRevertOptions,
1315
solanaDepositOptionsSchema,
1416
} from "../../../../utils/solana.commands.helpers";
1517

1618
type DepositOptions = z.infer<typeof solanaDepositOptionsSchema>;
1719

1820
const main = async (options: DepositOptions) => {
19-
const keypair = await getKeypair({
21+
const keypair = await getBrowserSafeKeypair({
2022
mnemonic: options.mnemonic,
2123
name: options.name,
2224
privateKey: options.privateKey,
@@ -26,12 +28,17 @@ const main = async (options: DepositOptions) => {
2628

2729
const revertOptions = prepareRevertOptions(options);
2830

31+
// Create an Anchor PublicKey for CLI confirmation (which expects Anchor types)
32+
const anchorPublicKey = new (
33+
await import("@coral-xyz/anchor")
34+
).web3.PublicKey(keypair.publicKey.toBase58());
35+
2936
await confirmSolanaTx({
3037
amount: options.amount,
3138
api: API,
3239
mint: options.mint,
3340
receiver: options.receiver,
34-
revertOptions: createRevertOptions(revertOptions, keypair.publicKey),
41+
revertOptions: createRevertOptions(revertOptions, anchorPublicKey),
3542
sender: keypair.publicKey.toBase58(),
3643
});
3744

packages/commands/src/solana/depositAndCall.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,22 @@ import { solanaDepositAndCall } from "../../../../src/chains/solana/depositAndCa
44
import { SOLANA_TOKEN_PROGRAM } from "../../../../types/shared.constants";
55
import { handleError, validateAndParseSchema } from "../../../../utils";
66
import { parseAbiValues } from "../../../../utils/parseAbiValues";
7+
import {
8+
getAPIbyChainId,
9+
getBrowserSafeKeypair,
10+
} from "../../../../utils/solana.browser.helpers";
711
import {
812
confirmSolanaTx,
913
createRevertOptions,
1014
createSolanaCommandWithCommonOptions,
11-
getAPIbyChainId,
12-
getKeypair,
1315
prepareRevertOptions,
1416
solanaDepositAndCallOptionsSchema,
1517
} from "../../../../utils/solana.commands.helpers";
1618

1719
type DepositAndCallOptions = z.infer<typeof solanaDepositAndCallOptionsSchema>;
1820

1921
const main = async (options: DepositAndCallOptions) => {
20-
const keypair = await getKeypair({
22+
const keypair = await getBrowserSafeKeypair({
2123
mnemonic: options.mnemonic,
2224
name: options.name,
2325
privateKey: options.privateKey,
@@ -30,13 +32,18 @@ const main = async (options: DepositAndCallOptions) => {
3032

3133
const revertOptions = prepareRevertOptions(options);
3234

35+
// Create an Anchor PublicKey for CLI confirmation (which expects Anchor types)
36+
const anchorPublicKey = new (
37+
await import("@coral-xyz/anchor")
38+
).web3.PublicKey(keypair.publicKey.toBase58());
39+
3340
await confirmSolanaTx({
3441
amount: options.amount,
3542
api: API,
3643
message: values.join(", "),
3744
mint: options.mint,
3845
receiver: options.receiver,
39-
revertOptions: createRevertOptions(revertOptions, keypair.publicKey),
46+
revertOptions: createRevertOptions(revertOptions, anchorPublicKey),
4047
sender: keypair.publicKey.toBase58(),
4148
});
4249

src/chains/solana/call.ts

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import { z } from "zod";
33

44
import {
55
createRevertOptions,
6-
createSolanaGatewayProgram,
7-
} from "../../../utils/solana.commands.helpers";
6+
executeBrowserSolanaCall,
7+
} from "../../../utils/solana.browser.helpers";
88
import { validateAndParseSchema } from "../../../utils/validateAndParseSchema";
99
import {
1010
solanaCallParamsSchema,
@@ -35,11 +35,6 @@ export const solanaCall = async (
3535
);
3636
const validatedOptions = validateAndParseSchema(options, solanaOptionsSchema);
3737

38-
const { gatewayProgram } = createSolanaGatewayProgram(
39-
validatedOptions.chainId,
40-
validatedOptions.signer
41-
);
42-
4338
const receiverBytes = ethers.getBytes(validatedParams.receiver);
4439
const abiCoder = ethers.AbiCoder.defaultAbiCoder();
4540
const encodedParameters = abiCoder.encode(
@@ -53,9 +48,13 @@ export const solanaCall = async (
5348
validatedOptions.signer.publicKey
5449
);
5550

56-
const tx = await gatewayProgram.methods
57-
.call(receiverBytes, message, revertOptions)
58-
.accounts({})
59-
.rpc();
51+
const tx = await executeBrowserSolanaCall(
52+
validatedOptions.chainId,
53+
validatedOptions.signer,
54+
receiverBytes,
55+
message,
56+
revertOptions
57+
);
58+
6059
return tx;
6160
};

0 commit comments

Comments
 (0)