Skip to content

Commit 525a983

Browse files
evgenikokcsongor
andauthored
cli: add payer to the push solana (#486)
* add payer to the ntt push command * testing adjustments * Update cli/src/index.ts * add payer path to pushDeployment method --------- Co-authored-by: Csongor Kiss <cs@wormholelabs.xyz>
1 parent befcdd1 commit 525a983

File tree

3 files changed

+35
-13
lines changed

3 files changed

+35
-13
lines changed

cli/src/getSigner.ts

+20-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import solana from "@wormhole-foundation/sdk/platforms/solana";
22
import * as myEvmSigner from "./evmsigner.js";
33
import { ChainContext, Wormhole, chainToPlatform, type Chain, type ChainAddress, type Network, type Signer } from "@wormhole-foundation/sdk";
4+
import { Keypair } from "@solana/web3.js";
5+
import fs from "fs";
6+
import { encoding } from '@wormhole-foundation/sdk-connect';
47

58
export type SignerType = "privateKey" | "ledger";
69

@@ -38,23 +41,34 @@ export function forgeSignerArgs(
3841
export async function getSigner<N extends Network, C extends Chain>(
3942
chain: ChainContext<N, C>,
4043
type: SignerType,
41-
source?: string
44+
source?: string,
45+
filePath?: string
4246
): Promise<SignerStuff<N, C>> {
4347
let signer: Signer;
4448
const platform = chainToPlatform(chain.chain);
4549
switch (platform) {
4650
case "Solana":
4751
switch (type) {
4852
case "privateKey":
49-
source = source ?? process.env.SOLANA_PRIVATE_KEY;
50-
if (source === undefined) {
51-
throw new Error("SOLANA_PRIVATE_KEY env var not set");
52-
}
53+
let privateKey: string;
54+
if (filePath) {
55+
// Read the private key from the file if filePath is provided
56+
const keyPair = Keypair.fromSecretKey(new Uint8Array(JSON.parse(fs.readFileSync(filePath, 'utf8'))));
57+
privateKey = encoding.b58.encode(keyPair.secretKey);
58+
} else {
59+
const privateKeySource = source ?? process.env.SOLANA_PRIVATE_KEY;
60+
if (privateKeySource === undefined) {
61+
throw new Error("Private key not provided and SOLANA_PRIVATE_KEY env var not set");
62+
}
63+
privateKey = privateKeySource;
64+
}
65+
console.log(privateKey);
5366
signer = await solana.getSigner(
5467
await chain.getRpc(),
55-
source,
68+
privateKey,
5669
{ debug: false }
5770
);
71+
console.log(signer);
5872
break;
5973
case "ledger":
6074
throw new Error("Ledger not yet supported on Solana");

cli/src/index.ts

+14-6
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,11 @@ const options = {
158158
describe: "Skip contract verification",
159159
type: "boolean",
160160
default: false,
161-
}
161+
},
162+
payer: {
163+
describe: "Path to the payer json file (Solana)",
164+
type: "string",
165+
},
162166
} as const;
163167

164168

@@ -573,23 +577,26 @@ yargs(hideBin(process.argv))
573577
.option("signer-type", options.signerType)
574578
.option("verbose", options.verbose)
575579
.option("skip-verify", options.skipVerify)
580+
.option("payer", options.payer)
576581
.example("$0 push", "Push local configuration changes to the blockchain")
577582
.example("$0 push --signer-type ledger", "Push changes using a Ledger hardware wallet for signing")
578-
.example("$0 push --skip-verify", "Push changes without verifying contracts on EVM chains"),
583+
.example("$0 push --skip-verify", "Push changes without verifying contracts on EVM chains")
584+
.example("$0 push --payer <SOLANA_KEYPAIR_PATH>", "Path to the payer json file (Solana), instead of setting SOLANA_PRIVATE_KEY env variable"),
579585
async (argv) => {
580586
const deployments: Config = loadConfig(argv["path"]);
581587
const verbose = argv["verbose"];
582588
const network = deployments.network as Network;
583589
const deps: Partial<{ [C in Chain]: Deployment<Chain> }> = await pullDeployments(deployments, network, verbose);
584590
const signerType = argv["signer-type"] as SignerType;
591+
const payerPath = argv["payer"];
585592

586593
const missing = await missingConfigs(deps, verbose);
587594

588595
for (const [chain, missingConfig] of Object.entries(missing)) {
589596
assertChain(chain);
590597
const ntt = deps[chain]!.ntt;
591598
const ctx = deps[chain]!.ctx;
592-
const signer = await getSigner(ctx, signerType)
599+
const signer = await getSigner(ctx, signerType, undefined, payerPath);
593600
for (const manager of missingConfig.managerPeers) {
594601
const tx = ntt.setPeer(manager.address, manager.tokenDecimals, manager.inboundLimit, signer.address.address)
595602
await signSendWait(ctx, tx, signer.signer)
@@ -613,7 +620,7 @@ yargs(hideBin(process.argv))
613620

614621
for (const [chain, deployment] of Object.entries(depsAfterRegistrations)) {
615622
assertChain(chain);
616-
await pushDeployment(deployment as any, signerType, !argv["skip-verify"], argv["yes"]);
623+
await pushDeployment(deployment as any, signerType, !argv["skip-verify"], argv["yes"], payerPath);
617624
}
618625
})
619626
.command("status",
@@ -1129,6 +1136,7 @@ async function deploySolana<N extends Network, C extends SolanaChains>(
11291136
binary = `${pwd}/solana/target/deploy/example_native_token_transfers.so`;
11301137
}
11311138

1139+
11321140
await checkSolanaBinary(binary, wormhole, providedProgramId)
11331141

11341142
// do the actual deployment
@@ -1254,7 +1262,7 @@ async function missingConfigs(
12541262
return missingConfigs;
12551263
}
12561264

1257-
async function pushDeployment<C extends Chain>(deployment: Deployment<C>, signerType: SignerType, evmVerify: boolean, yes: boolean): Promise<void> {
1265+
async function pushDeployment<C extends Chain>(deployment: Deployment<C>, signerType: SignerType, evmVerify: boolean, yes: boolean, filePath?: string): Promise<void> {
12581266
const diff = diffObjects(deployment.config.local!, deployment.config.remote!);
12591267
if (Object.keys(diff).length === 0) {
12601268
return;
@@ -1270,7 +1278,7 @@ async function pushDeployment<C extends Chain>(deployment: Deployment<C>, signer
12701278

12711279
const ctx = deployment.ctx;
12721280

1273-
const signer = await getSigner(ctx, signerType);
1281+
const signer = await getSigner(ctx, signerType, undefined, filePath);
12741282

12751283
let txs = [];
12761284
// we perform this last to make sure we don't accidentally lock ourselves out

package-lock.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)