-
Notifications
You must be signed in to change notification settings - Fork 308
feat(contract_manager): add upgrade script to contract_manager #2147
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
88 changes: 88 additions & 0 deletions
88
contract_manager/scripts/generate_upgrade_ton_contract_proposal.ts
This file contains hidden or 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,88 @@ | ||
| import yargs from "yargs"; | ||
| import { hideBin } from "yargs/helpers"; | ||
| import { DefaultStore, loadHotWallet } from "../src"; | ||
| import { TonChain } from "../src/chains"; | ||
| import { CHAINS, toChainName } from "@pythnetwork/xc-admin-common"; | ||
| import fs from "fs"; | ||
| import path from "path"; | ||
|
|
||
| const parser = yargs(hideBin(process.argv)) | ||
| .usage( | ||
| "Upgrades the Pyth contract on TON and creates a governance proposal for it.\n" + | ||
| "Usage: $0 --network <mainnet|testnet> --contract-address <address> --ops-key-path <ops_key_path>" | ||
| ) | ||
| .options({ | ||
| network: { | ||
| type: "string", | ||
| choices: ["mainnet", "testnet"], | ||
| description: "Network to deploy to", | ||
| demandOption: true, | ||
| }, | ||
| "contract-address": { | ||
| type: "string", | ||
| description: "Address of the contract to upgrade", | ||
| demandOption: true, | ||
| }, | ||
| "ops-key-path": { | ||
| type: "string", | ||
| description: "Path to operations key file", | ||
| demandOption: true, | ||
| }, | ||
| }); | ||
|
|
||
| async function main() { | ||
| const argv = await parser.argv; | ||
| const isMainnet = argv.network === "mainnet"; | ||
|
|
||
| // Get chain ID and name from CHAINS mapping | ||
| const chainId = isMainnet ? CHAINS.ton_mainnet : CHAINS.ton_testnet; | ||
| const wormholeChainName = toChainName(chainId); | ||
|
|
||
| // Get the TON chain instance with appropriate RPC URL based on network | ||
| const chain = new TonChain( | ||
| chainId.toString(), | ||
| isMainnet, | ||
| wormholeChainName, | ||
| undefined, | ||
| isMainnet | ||
| ? "https://toncenter.com/api/v2/jsonRPC" | ||
| : "https://testnet.toncenter.com/api/v2/jsonRPC" | ||
| ); | ||
|
|
||
| const vault = | ||
| DefaultStore.vaults[ | ||
| "mainnet-beta_FVQyHcooAtThJ83XFrNnv74BcinbRH3bRmfFamAHBfuj" | ||
| ]; | ||
|
|
||
| console.log( | ||
| `Upgrading contract on TON ${argv.network} (Chain ID: ${chainId}, Wormhole Chain Name: ${wormholeChainName})` | ||
| ); | ||
|
|
||
| // Read the compiled contract from the build directory | ||
| // NOTE: Remember to rebuild contract_manager before running this script because it will also build the ton contract | ||
| const compiledPath = path.resolve( | ||
| __dirname, | ||
| "../../target_chains/ton/contracts/build/Main.compiled.json" | ||
| ); | ||
| const compiled = JSON.parse(fs.readFileSync(compiledPath, "utf8")); | ||
| const newCodeHash = compiled.hash; | ||
| console.log("New code hash:", newCodeHash); | ||
|
|
||
| // Generate governance payload for the upgrade | ||
| const payload = chain.generateGovernanceUpgradePayload(newCodeHash); | ||
| console.log("Generated governance payload"); | ||
| console.log("Payload:", payload); | ||
|
|
||
| // Create and submit governance proposal | ||
| console.log("Using vault for proposal:", vault.getId()); | ||
| const keypair = await loadHotWallet(argv["ops-key-path"] as string); | ||
| console.log("Using wallet:", keypair.publicKey.toBase58()); | ||
| vault.connect(keypair); | ||
| const proposal = await vault.proposeWormholeMessage([payload]); | ||
| console.log("Proposal address:", proposal.address.toBase58()); | ||
| } | ||
|
|
||
| main().catch((error) => { | ||
| console.error("Error during upgrade:", error); | ||
| process.exit(1); | ||
| }); |
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
renamed from
upgrade_ton_contract.tsto better reflect the script's purpose