pyth-crosschain/target_chains/sui/scripts/wormhole/init.ts

121 lines
3.7 KiB
TypeScript
Raw Normal View History

[sui 9/x] - hot potato fix for price updates (#805) * state getters and setters, change Move.toml dependency to sui/integration_v2 * finish state.move * add new line to pyth * use deployer cap pattern for state module * sui pyth * update price feeds, dynamic object fields, Sui object PriceInfoObject * register price info object with pyth state after creation * sui governance * some newlines * error codes * update and comment * unit tests for pyth.move, add UpgradeCap to Pyth State (will be used for contract upgrades) * updates * test_get_update_fee test passes * fix test_get_update_fee and test_update_price_feeds_corrupt_vaa * test_update_price_feeds_invalid_data_source * test_create_and_update_price_feeds * test_create_and_update_price_feeds_success and test_create_and_update_price_feeds_price_info_object_not_found_failure * test_update_cache * update * test_update_cache_old_update * update_price_feeds_if_fresh * comment * contract upgrades start * contract upgradeability * update clock stuff * edits * use clone of sui/integration_v2 for stability * make contract_upgrade::execute a public(friend) fun, remove clock arg * E_INCORRECT_IDENTIFIER_LENGTH * comment and edit * add a single comment * upgradeability fixes, other fixes * update, migrate, state, pyth, setup, version_control * upgradeability, governance, LatestOnly * - state init_version, init_package_info - governance and contract ugpradeability stuff * make several functions public(friend), and friend the right modules in data_source.move * add comment * fix bug in from_u8, so that value <= TRANSFER_FEE * rename error message to E_MUST_USE_CONTRACT_UPGRADE_MODULE_TO_DO_UPGRADES * set_last_executed_governance_sequence * set pyth governance_module to 0000000000000000000000000000000000000000000000000000000000000001 * update README * Update README.md * Update README.md * delete comments * Update README.md * Update README.md * change Wormhole dependency to branch sui/mainnet, which has the latest update that includes VAA sequence number in DecreeReceipt do proper checking of sequence number when executing governance instructions, allow set_governance_data_source to update the sequence number to some initial_sequence. * state::set_last_executed_governance_sequence * rename error * add newline to setup.move * delete space * Update README.md * mark test module as well as some imports #[test_only] so sui move build works * scripts for Pyth contract testing and deployment remove required_version.move, as it is no longer being used for access control make init_and_share_state a public(friend) function * add build to Makefile * init pyth ts script * sui deploy and testing scripts * contract fixes, set_fee_recipient governance action, emit price update event only if fresh price update * init_pyth.ts, registry.ts, create_price_feed.ts * create price feeds * deploy script and Move.toml * some contract updates to compile with WH branch sui/mainnet deployment script updates * update README * update readme * rename TS scripts, edit readme * add rev for wormhole dependency, edit README * edit create_price_feed script * - add price_info::get function for getting PriceInfoObject ID from PriceIdentifier - add test for price_info::get * contract updates * script edits * contract upgrade in version_control.move and fix pyth_create_price_feed.ts * add get_price_info_object_id function to pyth::state * tests and build pass * update scripts * Pyth mainnet deploy, create all price feeds script * clean up script imports * add mainnet addresses to readme * correct Pyth Mainnet addresses * create price feeds on mainnet * use git dependency in Move.toml * edits * delete required contracts * get price info object ids * get price info object IDs * add json file containing price feed id to price info object id * comment * clean up scripts folder and imports * more script clean up (comments) * script updates * hot potato stuff * create_price_infos_hot_potato and update_single_price_feed * don't create hot potato in batch price attestation * latest only checks in Pyth.move * delete tab * edit * run pre-commit hooks * update price feeds script * update_single_price_feed_logic, give hot potato contents type T copy and drop ability * delete custom price attestation test * get update multiple price feeds POC to work * formatting via pre-commit * update Move.toml so can run "sui move test", delete some error codes that were unused * update update_price_feeds demo to auto-retrieve price info object ids * update readme * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * don't print map, get prices after update * script comments * Update update_price_feeds.ts * Update update_price_feeds.ts * Update README.md * script for token transfers * testnet "mainnet simulation" deployment (with 19 mainnet guardians), and testnet deployment (with single testnet guardian) * mainnet deploy * update Move.toml * Update README.md * Update README.md * edit readme * Update README.md * Update README.md * Update README.md * add PRICE_INFO_OBJECT map ID to README * common questions * edit comment * update readme * fix link * add comments for update_single_price_feed * edits * Update README.md * Update README.md * Update README.md * pre-commit run --all-files
2023-06-19 21:04:01 -07:00
/// Initialize Wormhole on Sui testnet
import {
fromB64,
getPublishedObjectChanges,
normalizeSuiObjectId,
RawSigner,
TransactionBlock,
SUI_CLOCK_OBJECT_ID,
JsonRpcProvider,
Ed25519Keypair,
testnetConnection,
Connection,
} from "@mysten/sui.js";
import { execSync } from "child_process";
import fs from "fs";
import { resolve } from "path";
import dotenv from "dotenv";
import { REGISTRY, NETWORK } from "../registry";
dotenv.config({ path: "~/.env" });
// Network dependent settings
let network = NETWORK.TESTNET; // <= NOTE: Update this when changing network
const walletPrivateKey = process.env.SUI_TESTNET; // <= NOTE: Update this when changing network
// Load registry and provider.
const registry = REGISTRY[network];
const provider = new JsonRpcProvider(
new Connection({ fullnode: registry["RPC_URL"] })
);
async function main() {
if (walletPrivateKey === undefined) {
throw new Error("SUI_TESTNET unset in environment");
}
const wallet = new RawSigner(
Ed25519Keypair.fromSecretKey(Buffer.from(walletPrivateKey, "hex")),
provider
);
await init_wormhole(wallet, registry["WORMHOLE_PACKAGE_ID"]);
}
main();
async function init_wormhole(signer: RawSigner, WORMHOLE_PACKAGE_ID: string) {
try {
const tx = new TransactionBlock();
tx.setGasBudget(2500000000);
let DEPLOYER_CAP =
"0x922ff3519eb0e71afaa7c6a7a8a1d074a2269d8ace73e8147bee286dd2d122a1";
let UPGRADE_CAP =
"0x21a346dae01e5f57829f8a2a0bf744b6be4e6d1131faf218b82f0f96708be99f";
let GOVERNANCE_CHAIN = 1;
let GOVERNANCE_CONTRACT = "04";
let GUARDIAN_SET_INDEX = 0; // this should be 3 or higher for mainnet (can check by parsing VAA)
let INITIAL_GUARDIANS = ["13947bd48b18e53fdaeee77f3473391ac727c638"]; // testnet guardian
// Ordered mainnet guardians
// let INITIAL_MAINNET_GUARDIANS =
// [
// "58CC3AE5C097b213cE3c81979e1B9f9570746AA5",
// "fF6CB952589BDE862c25Ef4392132fb9D4A42157",
// "114De8460193bdf3A2fCf81f86a09765F4762fD1",
// "107A0086b32d7A0977926A205131d8731D39cbEB",
// "8C82B2fd82FaeD2711d59AF0F2499D16e726f6b2",
// "11b39756c042441be6d8650b69b54ebe715e2343",
// "54Ce5B4D348fb74B958e8966e2ec3dBd4958a7cd",
// "15e7cAF07C4e3DC8e7C469f92C8Cd88FB8005a20",
// "74a3bf913953D695260D88BC1aA25A4eeE363ef0",
// "000aC0076727b35FBea2dAc28fEE5cCB0fEA768e",
// "AF45Ced136b9D9e24903464AE889F5C8a723FC14",
// "f93124b7c738843CBB89E864c862c38cddCccF95",
// "D2CC37A4dc036a8D232b48f62cDD4731412f4890",
// "DA798F6896A3331F64b48c12D1D57Fd9cbe70811",
// "71AA1BE1D36CaFE3867910F99C09e347899C19C3",
// "8192b6E7387CCd768277c17DAb1b7a5027c0b3Cf",
// "178e21ad2E77AE06711549CFBB1f9c7a9d8096e8",
// "5E1487F35515d02A92753504a8D75471b9f49EdB",
// "6FbEBc898F403E4773E95feB15E80C9A99c8348d"
// ]
let GUARDIAN_SECONDS_TO_LIVE = "1000000000";
let MESSAGE_FEE = 0;
tx.moveCall({
target: `${WORMHOLE_PACKAGE_ID}::setup::complete`,
arguments: [
tx.object(DEPLOYER_CAP),
tx.object(UPGRADE_CAP),
tx.pure(GOVERNANCE_CHAIN),
tx.pure(GOVERNANCE_CONTRACT),
tx.pure(GUARDIAN_SET_INDEX),
tx.pure(INITIAL_GUARDIANS.map((x) => [...Buffer.from(x, "hex")])),
tx.pure(GUARDIAN_SECONDS_TO_LIVE),
tx.pure(MESSAGE_FEE),
],
});
let res = await signer.signAndExecuteTransactionBlock({
transactionBlock: tx,
options: {
showInput: true,
showEffects: true,
showEvents: true,
showObjectChanges: true,
showBalanceChanges: true,
},
});
console.log(res);
// Return publish transaction info
return res;
} catch (e) {
throw e;
} finally {
}
}