Skip to content

Commit 6818964

Browse files
committed
Add scripts for initialize staking program in mainnet
1 parent 1cd1da1 commit 6818964

9 files changed

+327
-17
lines changed

solana/app/deploy/devnet/constants.ts

+8-6
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ import { contracts } from "@wormhole-foundation/sdk-base";
55

66
export const RPC_NODE = "https://api.devnet.solana.com";
77

8+
/// Wormhole Token (W) (devnet solana address)
9+
export const WORMHOLE_TOKEN = new PublicKey(
10+
"Exne2kdeGToBnC2WVSdt1gLy6fjnNftbPtsCPx8AuL7V",
11+
);
12+
813
export const STAKING_ADDRESS = new PublicKey(
914
"AFuHPdrQGsW8rNQ4oEFF35sm5fg36gwrxyqjkjKvi6ap",
1015
);
@@ -24,11 +29,13 @@ export const hubProposalMetadataUint8Array = new Uint8Array(
2429
);
2530

2631
/// Wormhole Hub Chain ID
32+
// https://wormhole.com/docs/build/reference/chain-ids/#__tabbed_1_2
2733
export const HUB_CHAIN_ID = 10002; // SEPOLIA
2834

2935
export const CHECKPOINTS_ACCOUNT_LIMIT = 654998;
3036
export const TEST_CHECKPOINTS_ACCOUNT_LIMIT = 15;
3137

38+
/// Wormhole hubSolanaMessageDispatcher Contract (sepolia ethereum address)
3239
export const HUB_SOLANA_MESSAGE_DISPATCHER_ADDRESS =
3340
"0xaeb78fb7ddedbbcab908e91e94f1fb04a23fbce5";
3441
const hubSolanaMessageDispatcherHex20 =
@@ -80,16 +87,11 @@ export const USER_AUTHORITY_KEYPAIR = loadKeypair(
8087
homedir() + USER_AUTHORITY_PATH,
8188
);
8289

83-
export const USER2_AUTHORITY_PATH =
84-
"/.config/solana/secretKey_617X3kwJzjfAbr6zHMa4rzbjaHQN8mzST8VAb8oE8xo8.json";
90+
export const USER2_AUTHORITY_PATH = "/.config/solana/user2.json";
8591
export const USER2_AUTHORITY_KEYPAIR = loadKeypair(
8692
homedir() + USER2_AUTHORITY_PATH,
8793
);
8894

89-
export const WORMHOLE_TOKEN = new PublicKey(
90-
"Exne2kdeGToBnC2WVSdt1gLy6fjnNftbPtsCPx8AuL7V",
91-
);
92-
9395
export const AIRLOCK_PDA_ADDRESS = new PublicKey(
9496
"2ejzW2eFPedskg1KcrjcFs9g1JorRVcMes1TBPpGbhdy",
9597
);
+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import { PublicKey } from "@solana/web3.js";
2+
import { homedir } from "os";
3+
import { loadKeypair } from "../../../tests/utils/keys";
4+
import { contracts } from "@wormhole-foundation/sdk-base";
5+
6+
export const RPC_NODE = "https://api.mainnet-beta.solana.com";
7+
8+
/// Wormhole Token (W) (mainnet solana address)
9+
export const WORMHOLE_TOKEN = new PublicKey(
10+
"85VBFQZC9TZkfaptBWjvUw7YbZjy52A6mjtPGjstQAmQ",
11+
);
12+
13+
export const STAKING_ADDRESS = new PublicKey(
14+
"AFuHPdrQGsW8rNQ4oEFF35sm5fg36gwrxyqjkjKvi6ap",
15+
);
16+
17+
export const CORE_BRIDGE_PID = new PublicKey(
18+
contracts.coreBridge.get("Mainnet", "Solana")!, // worm2ZoG2kUd4vFXhvjh93UUH596ayRfgQ2MgjNMTth
19+
);
20+
console.log(CORE_BRIDGE_PID);
21+
22+
/// Wormhole Hub Proposal Metadata Contract (mainnet ethereum address)
23+
export const HUB_PROPOSAL_METADATA_ADDRESS =
24+
"0x1a3e5624769c3dc9106347a239523e4a08d85c38"; // TODO: needs to be updated after a deployment to ethereum mainnet
25+
export const hubProposalMetadataUint8Array = new Uint8Array(
26+
HUB_PROPOSAL_METADATA_ADDRESS.slice(2)
27+
.toLowerCase()
28+
.match(/.{1,2}/g)
29+
?.map((byte) => parseInt(byte, 16)),
30+
);
31+
32+
/// Wormhole Hub Chain ID
33+
// https://wormhole.com/docs/build/reference/chain-ids/#__tabbed_1_1
34+
export const HUB_CHAIN_ID = 2; // Mainnet
35+
36+
export const CHECKPOINTS_ACCOUNT_LIMIT = 654998;
37+
38+
/// Wormhole hubSolanaMessageDispatcher Contract (mainnet ethereum address)
39+
export const HUB_SOLANA_MESSAGE_DISPATCHER_ADDRESS =
40+
"0xaeb78fb7ddedbbcab908e91e94f1fb04a23fbce5"; // TODO: needs to be updated after a deployment to ethereum mainnet
41+
const hubSolanaMessageDispatcherHex20 =
42+
HUB_SOLANA_MESSAGE_DISPATCHER_ADDRESS.slice(2);
43+
const hubSolanaMessageDispatcherHex32 =
44+
"000000000000000000000000" + hubSolanaMessageDispatcherHex20.toLowerCase();
45+
const hubSolanaMessageDispatcherUint8Array32 = new Uint8Array(
46+
hubSolanaMessageDispatcherHex32
47+
.match(/.{1,2}/g)
48+
?.map((byte) => parseInt(byte, 16)),
49+
);
50+
export const hubSolanaMessageDispatcherUint8Array20 =
51+
hubSolanaMessageDispatcherUint8Array32.slice(-20);
52+
export const hubSolanaMessageDispatcherPublicKey = new PublicKey(
53+
hubSolanaMessageDispatcherUint8Array32,
54+
);
55+
// console.log("hubSolanaMessageDispatcherPublicKey:", hubSolanaMessageDispatcherPublicKey);
56+
57+
export const DEPLOYER_AUTHORITY_PATH = "/.config/solana/deployer.json";
58+
export const DEPLOYER_AUTHORITY_KEYPAIR = loadKeypair(
59+
homedir() + DEPLOYER_AUTHORITY_PATH,
60+
);
61+
62+
export const GOVERNANCE_AUTHORITY_PATH =
63+
"/.config/solana/governanceAuthority.json";
64+
export const GOVERNANCE_AUTHORITY_KEYPAIR = loadKeypair(
65+
homedir() + GOVERNANCE_AUTHORITY_PATH,
66+
);
67+
68+
export const VESTING_ADMIN_PATH = "/.config/solana/vestingAdmin.json";
69+
export const VESTING_ADMIN_KEYPAIR = loadKeypair(
70+
homedir() + VESTING_ADMIN_PATH,
71+
);
72+
73+
export const VOTE_WEIGHT_WINDOW_LENGTHS = 10 * 60; // 10 minutes
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Usage: npx ts-node app/deploy/mainnet/initialize/initAddressLookupTable.ts
2+
3+
import { Wallet, AnchorProvider } from "@coral-xyz/anchor";
4+
import { Connection } from "@solana/web3.js";
5+
import {
6+
DEPLOYER_AUTHORITY_KEYPAIR,
7+
RPC_NODE,
8+
STAKING_ADDRESS,
9+
WORMHOLE_TOKEN,
10+
} from "../constants";
11+
import { initAddressLookupTable } from "../../../helpers/utils/lookup_table";
12+
13+
async function main() {
14+
try {
15+
const connection = new Connection(RPC_NODE);
16+
const provider = new AnchorProvider(
17+
connection,
18+
new Wallet(DEPLOYER_AUTHORITY_KEYPAIR),
19+
{},
20+
);
21+
22+
const lookupTableAddress = await initAddressLookupTable(
23+
provider,
24+
WORMHOLE_TOKEN,
25+
STAKING_ADDRESS,
26+
);
27+
28+
console.log("Lookup table address: ", lookupTableAddress.toBase58());
29+
} catch (err) {
30+
console.error("Error:", err);
31+
}
32+
}
33+
34+
main();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Usage: npx ts-node app/deploy/mainnet/initialize/initConfig.ts
2+
3+
import { Wallet, AnchorProvider, Program } from "@coral-xyz/anchor";
4+
import { Connection } from "@solana/web3.js";
5+
import {
6+
CHECKPOINTS_ACCOUNT_LIMIT,
7+
STAKING_ADDRESS,
8+
DEPLOYER_AUTHORITY_KEYPAIR,
9+
GOVERNANCE_AUTHORITY_KEYPAIR,
10+
VESTING_ADMIN_KEYPAIR,
11+
WORMHOLE_TOKEN,
12+
RPC_NODE,
13+
} from "../constants";
14+
15+
async function main() {
16+
const connection = new Connection(RPC_NODE);
17+
const provider = new AnchorProvider(
18+
connection,
19+
new Wallet(DEPLOYER_AUTHORITY_KEYPAIR),
20+
{},
21+
);
22+
23+
const idl = (await Program.fetchIdl(STAKING_ADDRESS, provider))!;
24+
const program = new Program(idl, provider);
25+
26+
const globalConfig = {
27+
bump: 255,
28+
governanceAuthority: GOVERNANCE_AUTHORITY_KEYPAIR.publicKey,
29+
votingTokenMint: WORMHOLE_TOKEN,
30+
vestingAdmin: VESTING_ADMIN_KEYPAIR.publicKey,
31+
maxCheckpointsAccountLimit: CHECKPOINTS_ACCOUNT_LIMIT,
32+
};
33+
await program.methods.initConfig(globalConfig).rpc();
34+
}
35+
36+
main();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Usage: npx ts-node app/deploy/mainnet/initialize/initializeSpokeAirlock.ts
2+
3+
import { AnchorProvider, Program, Wallet } from "@coral-xyz/anchor";
4+
import { Connection, PublicKey, SystemProgram } from "@solana/web3.js";
5+
import { DEPLOYER_AUTHORITY_KEYPAIR, RPC_NODE } from "../constants";
6+
import { Staking } from "../../../../target/types/staking";
7+
import fs from "fs";
8+
9+
async function main() {
10+
try {
11+
const DEBUG = true;
12+
const connection = new Connection(RPC_NODE);
13+
const provider = new AnchorProvider(
14+
connection,
15+
new Wallet(DEPLOYER_AUTHORITY_KEYPAIR),
16+
{},
17+
);
18+
19+
let program: Program<Staking>;
20+
program = new Program(
21+
JSON.parse(fs.readFileSync("./target/idl/staking.json").toString()),
22+
provider,
23+
);
24+
25+
const airlockPDA: PublicKey = PublicKey.findProgramAddressSync(
26+
[Buffer.from("airlock")],
27+
program.programId,
28+
)[0];
29+
30+
await program.methods
31+
.initializeSpokeAirlock()
32+
.accounts({
33+
payer: DEPLOYER_AUTHORITY_KEYPAIR.publicKey,
34+
// @ts-ignore
35+
airlock: airlockPDA,
36+
systemProgram: SystemProgram.programId,
37+
})
38+
.rpc({ skipPreflight: DEBUG });
39+
} catch (err) {
40+
console.error("Error:", err);
41+
}
42+
}
43+
44+
main();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// Usage: npx ts-node app/deploy/mainnet/initialize/initializeSpokeMessageExecutor.ts
2+
3+
import { AnchorProvider, Program, Wallet } from "@coral-xyz/anchor";
4+
import { Connection, PublicKey, SystemProgram } from "@solana/web3.js";
5+
import {
6+
DEPLOYER_AUTHORITY_KEYPAIR,
7+
hubSolanaMessageDispatcherPublicKey,
8+
HUB_CHAIN_ID,
9+
RPC_NODE,
10+
} from "../constants";
11+
import { Staking } from "../../../../target/types/staking";
12+
import fs from "fs";
13+
import { wasm } from "../../../StakeConnection";
14+
15+
async function main() {
16+
try {
17+
const connection = new Connection(RPC_NODE);
18+
const provider = new AnchorProvider(
19+
connection,
20+
new Wallet(DEPLOYER_AUTHORITY_KEYPAIR),
21+
{},
22+
);
23+
24+
let program: Program<Staking>;
25+
program = new Program(
26+
JSON.parse(fs.readFileSync("./target/idl/staking.json").toString()),
27+
provider,
28+
);
29+
30+
const messageExecutorPDA: PublicKey = PublicKey.findProgramAddressSync(
31+
[Buffer.from("spoke_message_executor")],
32+
program.programId,
33+
)[0];
34+
const config: PublicKey = PublicKey.findProgramAddressSync(
35+
[Buffer.from(wasm.Constants.CONFIG_SEED())],
36+
program.programId,
37+
)[0];
38+
39+
await program.methods
40+
.initializeSpokeMessageExecutor(HUB_CHAIN_ID)
41+
.accounts({
42+
governanceAuthority: DEPLOYER_AUTHORITY_KEYPAIR.publicKey,
43+
// @ts-ignore
44+
executor: messageExecutorPDA,
45+
config: config,
46+
hubDispatcher: hubSolanaMessageDispatcherPublicKey,
47+
systemProgram: SystemProgram.programId,
48+
})
49+
.rpc();
50+
} catch (err) {
51+
console.error("Error:", err);
52+
}
53+
}
54+
55+
main();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Usage: npx ts-node app/deploy/mainnet/initialize/initializeSpokeMetadataCollector.ts
2+
3+
import { AnchorProvider, Program, Wallet } from "@coral-xyz/anchor";
4+
import { Connection } from "@solana/web3.js";
5+
import {
6+
DEPLOYER_AUTHORITY_KEYPAIR,
7+
HUB_CHAIN_ID,
8+
hubProposalMetadataUint8Array,
9+
RPC_NODE,
10+
} from "../constants";
11+
import { Staking } from "../../../../target/types/staking";
12+
import fs from "fs";
13+
14+
async function main() {
15+
try {
16+
const connection = new Connection(RPC_NODE);
17+
const provider = new AnchorProvider(
18+
connection,
19+
new Wallet(DEPLOYER_AUTHORITY_KEYPAIR),
20+
{},
21+
);
22+
23+
let program: Program<Staking>;
24+
program = new Program(
25+
JSON.parse(fs.readFileSync("./target/idl/staking.json").toString()),
26+
provider,
27+
);
28+
29+
await program.methods
30+
.initializeSpokeMetadataCollector(
31+
HUB_CHAIN_ID,
32+
Array.from(hubProposalMetadataUint8Array),
33+
)
34+
.rpc();
35+
} catch (err) {
36+
console.error("Error:", err);
37+
}
38+
}
39+
40+
main();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Usage: npx ts-node app/deploy/mainnet/initialize/initializeVoteWeightWindowLengths.ts
2+
3+
import { AnchorProvider, Program, Wallet } from "@coral-xyz/anchor";
4+
import { Connection } from "@solana/web3.js";
5+
import {
6+
DEPLOYER_AUTHORITY_KEYPAIR,
7+
RPC_NODE,
8+
VOTE_WEIGHT_WINDOW_LENGTHS,
9+
} from "../constants";
10+
import { Staking } from "../../../../target/types/staking";
11+
import fs from "fs";
12+
import BN from "bn.js";
13+
14+
async function main() {
15+
try {
16+
const connection = new Connection(RPC_NODE);
17+
const provider = new AnchorProvider(
18+
connection,
19+
new Wallet(DEPLOYER_AUTHORITY_KEYPAIR),
20+
{},
21+
);
22+
23+
let program: Program<Staking>;
24+
program = new Program(
25+
JSON.parse(fs.readFileSync("./target/idl/staking.json").toString()),
26+
provider,
27+
);
28+
29+
await program.methods
30+
.initializeVoteWeightWindowLengths(new BN(VOTE_WEIGHT_WINDOW_LENGTHS))
31+
.rpc();
32+
} catch (err) {
33+
console.error("Error:", err);
34+
}
35+
}
36+
37+
main();

solana/app/deploy/mainnet/mainnet_beta.ts

-11
This file was deleted.

0 commit comments

Comments
 (0)