upgrade_ton_contract.ts 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import yargs from "yargs";
  2. import { hideBin } from "yargs/helpers";
  3. import { DefaultStore, TonPriceFeedContract, toPrivateKey } from "../src";
  4. import fs from "fs";
  5. import path from "path";
  6. import { Cell } from "@ton/ton";
  7. const parser = yargs(hideBin(process.argv))
  8. .usage(
  9. "Upgrades the Pyth contract on TON and creates a governance proposal for it.\n" +
  10. "Usage: $0 --network <mainnet|testnet> --contract <contract_name> --private-key <private_key>"
  11. )
  12. .options({
  13. network: {
  14. type: "string",
  15. choices: ["mainnet", "testnet"],
  16. description: "Network to deploy to",
  17. demandOption: true,
  18. },
  19. contract: {
  20. type: "string",
  21. description: "Contract name",
  22. demandOption: true,
  23. },
  24. "private-key": {
  25. type: "string",
  26. description: "Private key of the sender",
  27. demandOption: true,
  28. },
  29. });
  30. async function main() {
  31. const argv = await parser.argv;
  32. const contract = DefaultStore.contracts[
  33. argv.contract
  34. ] as TonPriceFeedContract;
  35. // Read the compiled contract from the build directory
  36. // NOTE: Remember to rebuild contract_manager before running this script because it will also build the ton contract
  37. const compiledPath = path.resolve(
  38. __dirname,
  39. "../../target_chains/ton/contracts/build/Main.compiled.json"
  40. );
  41. const compiled = JSON.parse(fs.readFileSync(compiledPath, "utf8"));
  42. const newCode = Cell.fromHex(compiled.hex);
  43. console.log(newCode);
  44. const tx = await contract.upgradeContract(
  45. toPrivateKey(argv["private-key"]),
  46. newCode
  47. );
  48. console.log("Upgrade transaction:", tx);
  49. }
  50. main().catch((error) => {
  51. console.error("Error during upgrade:", error);
  52. process.exit(1);
  53. });