-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6d7c26c
commit d80fbfd
Showing
1 changed file
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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`); | ||
} | ||
} |