Skip to content

Commit bfb0834

Browse files
committed
add ton upgrade script
1 parent f68b5d5 commit bfb0834

File tree

5 files changed

+131
-24
lines changed

5 files changed

+131
-24
lines changed

contract_manager/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141
"@pythnetwork/xc-admin-common": "workspace:*",
4242
"@solana/web3.js": "^1.73.0",
4343
"@sqds/mesh": "^1.0.6",
44+
"@ton/blueprint": "^0.22.0",
45+
"@ton/core": "^0.59.0",
4446
"@ton/crypto": "^3.3.0",
4547
"@ton/ton": "^15.1.0",
4648
"@types/yargs": "^17.0.32",
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
import yargs from "yargs";
2+
import { hideBin } from "yargs/helpers";
3+
import { DefaultStore, loadHotWallet } from "../src";
4+
import { TonChain } from "../src/chains";
5+
import { CHAINS, toChainName } from "@pythnetwork/xc-admin-common";
6+
import { compile } from "@ton/blueprint";
7+
8+
const parser = yargs(hideBin(process.argv))
9+
.usage(
10+
"Upgrades the Pyth contract on TON and creates a governance proposal for it.\n" +
11+
"Usage: $0 --network <mainnet|testnet> --contract-address <address> --ops-key-path <ops_key_path>"
12+
)
13+
.options({
14+
network: {
15+
type: "string",
16+
choices: ["mainnet", "testnet"],
17+
description: "Network to deploy to",
18+
demandOption: true,
19+
},
20+
"contract-address": {
21+
type: "string",
22+
description: "Address of the contract to upgrade",
23+
demandOption: true,
24+
},
25+
"ops-key-path": {
26+
type: "string",
27+
description: "Path to operations key file",
28+
demandOption: true,
29+
},
30+
});
31+
32+
async function main() {
33+
const argv = await parser.argv;
34+
const isMainnet = argv.network === "mainnet";
35+
36+
// Get chain ID and name from CHAINS mapping
37+
const chainId = isMainnet ? CHAINS.ton_mainnet : CHAINS.ton_testnet;
38+
const wormholeChainName = toChainName(chainId);
39+
40+
// Get the TON chain instance with appropriate RPC URL based on network
41+
const chain = new TonChain(
42+
chainId.toString(),
43+
isMainnet,
44+
wormholeChainName,
45+
undefined,
46+
isMainnet
47+
? "https://toncenter.com/api/v2/jsonRPC"
48+
: "https://testnet.toncenter.com/api/v2/jsonRPC"
49+
);
50+
51+
let vaultName: string;
52+
if (isMainnet) {
53+
vaultName = "mainnet-beta_FVQyHcooAtThJ83XFrNnv74BcinbRH3bRmfFamAHBfuj";
54+
} else {
55+
vaultName = "devnet_6baWtW1zTUVMSJHJQVxDUXWzqrQeYBr6mu31j3bTKwY3";
56+
}
57+
const vault = DefaultStore.vaults[vaultName];
58+
59+
console.log(
60+
`Upgrading contract on TON ${argv.network} (Chain ID: ${chainId}, Wormhole Chain Name: ${wormholeChainName})`
61+
);
62+
63+
console.log("Compiling new contract code...");
64+
const newCode = await compile("Main");
65+
const newCodeHash = newCode.hash();
66+
console.log("New code hash:", newCodeHash.toString("hex"));
67+
68+
// Generate governance payload for the upgrade
69+
const payload = chain.generateGovernanceUpgradePayload(
70+
newCodeHash.toString("hex")
71+
);
72+
console.log("Generated governance payload");
73+
console.log("Payload:", payload);
74+
75+
// Create and submit governance proposal
76+
console.log("Using vault for proposal:", vault.getId());
77+
const wallet = await loadHotWallet(argv["ops-key-path"] as string);
78+
console.log("Using wallet:", wallet.publicKey.toBase58());
79+
vault.connect(wallet);
80+
const proposal = await vault.proposeWormholeMessage([payload]);
81+
console.log("Proposal address:", proposal.address.toBase58());
82+
}
83+
84+
main().catch((error) => {
85+
console.error("Error during upgrade:", error);
86+
process.exit(1);
87+
});

contract_manager/src/chains.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -807,7 +807,6 @@ export class TonChain extends Chain {
807807
* @param digest hex string of the 32 byte digest for the new package without the 0x prefix
808808
*/
809809
generateGovernanceUpgradePayload(digest: string): Buffer {
810-
// This might throw an error because the Fuel contract doesn't support upgrades yet (blocked on Fuel releasing Upgradeability standard)
811810
return new UpgradeContract256Bit(this.wormholeChainName, digest).encode();
812811
}
813812

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { CompilerConfig } from "@ton/blueprint";
2+
3+
export const compile: CompilerConfig = {
4+
lang: "func",
5+
targets: [
6+
"../target_chains/ton/contracts/contracts/Main.fc",
7+
"../target_chains/ton/contracts/contracts/Pyth.fc",
8+
"../target_chains/ton/contracts/contracts/Wormhole.fc",
9+
],
10+
};

pnpm-lock.yaml

Lines changed: 32 additions & 23 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)