Skip to content

Commit d80fbfd

Browse files
solana upgrade token router script
1 parent 6d7c26c commit d80fbfd

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { Connection, PublicKey } from "@solana/web3.js";
2+
import "dotenv/config";
3+
import {
4+
UpgradeManagerProgram,
5+
ProgramId as UpgradeManagerProgramId,
6+
} from "@wormhole-foundation/example-liquidity-layer-solana/upgradeManager";
7+
8+
import {
9+
solana,
10+
getContractAddress,
11+
getEnv,
12+
} from "../../helpers";
13+
14+
solana.runOnSolana("upgrade-token-router", async (chain, signer, log) => {
15+
const connection = new Connection(chain.rpc, solana.connectionCommitmentLevel);
16+
const upgradeManagerProgramId = getContractAddress(
17+
"UpgradeManager",
18+
chain.chainId,
19+
) as UpgradeManagerProgramId;
20+
const a = new PublicKey(await signer.getAddress());
21+
22+
const upgradeManager = new UpgradeManagerProgram(connection, upgradeManagerProgramId);
23+
24+
const buffer = new PublicKey(getEnv("TOKEN_ROUTER_UPGRADE_BUFFER_ACCOUNT"));
25+
26+
await checkBufferExists(buffer, connection);
27+
28+
const upgradeIx = await upgradeManager.executeTokenRouterUpgradeIx({
29+
owner: new PublicKey((await signer.getAddress()).toString()),
30+
tokenRouterBuffer: buffer,
31+
});
32+
33+
const txId = await solana.ledgerSignAndSend(connection, [upgradeIx], []);
34+
log(`Succesfully upgraded on tx -> ${txId}`);
35+
});
36+
37+
async function checkBufferExists(buffer: PublicKey, connection: Connection) {
38+
const accInfo = await connection.getAccountInfo(buffer, {
39+
dataSlice: { offset: 0, length: 8 },
40+
});
41+
42+
if (accInfo === null) {
43+
throw new Error(`Buffer at ${buffer.toString()} not found`);
44+
}
45+
}

0 commit comments

Comments
 (0)