From d80fbfd24a87906f19b37b8bd6896005b657b65c Mon Sep 17 00:00:00 2001 From: solanoe Date: Fri, 18 Oct 2024 15:27:06 -0300 Subject: [PATCH] solana upgrade token router script --- .../scripts/solana/upgrade-token-router.ts | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 deployment/scripts/solana/upgrade-token-router.ts diff --git a/deployment/scripts/solana/upgrade-token-router.ts b/deployment/scripts/solana/upgrade-token-router.ts new file mode 100644 index 00000000..769d7608 --- /dev/null +++ b/deployment/scripts/solana/upgrade-token-router.ts @@ -0,0 +1,45 @@ +import { Connection, PublicKey } from "@solana/web3.js"; +import "dotenv/config"; +import { + UpgradeManagerProgram, + ProgramId as UpgradeManagerProgramId, +} from "@wormhole-foundation/example-liquidity-layer-solana/upgradeManager"; + +import { + solana, + getContractAddress, + getEnv, +} from "../../helpers"; + +solana.runOnSolana("upgrade-token-router", async (chain, signer, log) => { + const connection = new Connection(chain.rpc, solana.connectionCommitmentLevel); + const upgradeManagerProgramId = getContractAddress( + "UpgradeManager", + chain.chainId, + ) as UpgradeManagerProgramId; + const a = new PublicKey(await signer.getAddress()); + + const upgradeManager = new UpgradeManagerProgram(connection, upgradeManagerProgramId); + + const buffer = new PublicKey(getEnv("TOKEN_ROUTER_UPGRADE_BUFFER_ACCOUNT")); + + await checkBufferExists(buffer, connection); + + const upgradeIx = await upgradeManager.executeTokenRouterUpgradeIx({ + owner: new PublicKey((await signer.getAddress()).toString()), + tokenRouterBuffer: buffer, + }); + + const txId = await solana.ledgerSignAndSend(connection, [upgradeIx], []); + log(`Succesfully upgraded on tx -> ${txId}`); +}); + +async function checkBufferExists(buffer: PublicKey, connection: Connection) { + const accInfo = await connection.getAccountInfo(buffer, { + dataSlice: { offset: 0, length: 8 }, + }); + + if (accInfo === null) { + throw new Error(`Buffer at ${buffer.toString()} not found`); + } +}