|
| 1 | +import yargs from "yargs"; |
| 2 | +import { hideBin } from "yargs/helpers"; |
| 3 | +import { EvmChain } from "../src/chains"; |
| 4 | +import { DefaultStore } from "../src/store"; |
| 5 | +import { |
| 6 | + DeploymentType, |
| 7 | + EvmPriceFeedContract, |
| 8 | + getDefaultDeploymentConfig, |
| 9 | + toDeploymentType, |
| 10 | + toPrivateKey, |
| 11 | +} from "../src"; |
| 12 | +import { |
| 13 | + COMMON_DEPLOY_OPTIONS, |
| 14 | + getWeb3Contract, |
| 15 | + getOrDeployWormholeContract, |
| 16 | + BaseDeployConfig, |
| 17 | + findEvmChain, |
| 18 | + deployIfNotCached, |
| 19 | +} from "./common"; |
| 20 | + |
| 21 | +interface Config extends BaseDeployConfig { |
| 22 | + type: DeploymentType; |
| 23 | +} |
| 24 | + |
| 25 | +const parser = yargs(hideBin(process.argv)) |
| 26 | + .scriptName("get_pyth_pricefeed_details.ts") |
| 27 | + .usage("Usage: $0 --chain <chain-name>") |
| 28 | + .options({ |
| 29 | + chain: { |
| 30 | + type: "string", |
| 31 | + demandOption: true, |
| 32 | + desc: "Chain name to get Pyth price feed details for", |
| 33 | + }, |
| 34 | + "deployment-type": { |
| 35 | + type: "string", |
| 36 | + demandOption: false, |
| 37 | + default: "stable", |
| 38 | + desc: "Deployment type to use. Can be 'stable' or 'beta'", |
| 39 | + }, |
| 40 | + }); |
| 41 | + |
| 42 | +async function getPythPriceFeedDetails(chain: EvmChain, config: Config) { |
| 43 | + // Get wormhole contract from store |
| 44 | + const wormholeContract = await getOrDeployWormholeContract(chain, { |
| 45 | + ...config, |
| 46 | + saveContract: true, |
| 47 | + }, ".cache-get-details"); |
| 48 | + |
| 49 | + // Deploy PythUpgradable contract |
| 50 | + const pythImplAddr = await deployIfNotCached( |
| 51 | + ".cache-get-details", |
| 52 | + chain, |
| 53 | + config, |
| 54 | + "PythUpgradable", |
| 55 | + [] |
| 56 | + ); |
| 57 | + |
| 58 | + // Get deployment config |
| 59 | + const { dataSources, governanceDataSource } = getDefaultDeploymentConfig( |
| 60 | + config.type |
| 61 | + ); |
| 62 | + |
| 63 | + // Get contract instance |
| 64 | + const pythImplContract = getWeb3Contract( |
| 65 | + config.jsonOutputDir, |
| 66 | + "PythUpgradable", |
| 67 | + pythImplAddr |
| 68 | + ); |
| 69 | + |
| 70 | + // Create init data |
| 71 | + const pythInitData = pythImplContract.methods |
| 72 | + .initialize( |
| 73 | + wormholeContract.address, |
| 74 | + dataSources.map((ds) => ds.emitterChain), |
| 75 | + dataSources.map((ds) => "0x" + ds.emitterAddress), |
| 76 | + governanceDataSource.emitterChain, |
| 77 | + "0x" + governanceDataSource.emitterAddress, |
| 78 | + 0, // governanceInitialSequence |
| 79 | + 60, // validTimePeriodSeconds |
| 80 | + 1 // singleUpdateFeeInWei |
| 81 | + ) |
| 82 | + .encodeABI(); |
| 83 | + |
| 84 | + return { |
| 85 | + pythImplAddr, |
| 86 | + pythInitData, |
| 87 | + }; |
| 88 | +} |
| 89 | + |
| 90 | +async function main() { |
| 91 | + const argv = await parser.argv; |
| 92 | + const chain = findEvmChain(argv.chain); |
| 93 | + |
| 94 | + const config: Config = { |
| 95 | + type: toDeploymentType(argv.deploymentType), |
| 96 | + privateKey: toPrivateKey(process.env.PRIVATE_KEY!), // Will be needed for deployIfNotCached |
| 97 | + jsonOutputDir: process.env.JSON_OUTPUT_DIR!, // Will be needed for contract artifacts |
| 98 | + gasMultiplier: 2, |
| 99 | + gasPriceMultiplier: 1, |
| 100 | + }; |
| 101 | + |
| 102 | + console.log(`Getting Pyth price feed details for chain ${chain.getId()}...`); |
| 103 | + |
| 104 | + const details = await getPythPriceFeedDetails(chain, config); |
| 105 | + |
| 106 | + console.log(`\nPyth Price Feed Implementation Address: ${details.pythImplAddr}`); |
| 107 | + console.log(`Pyth Init Data: ${details.pythInitData}`); |
| 108 | +} |
| 109 | + |
| 110 | +main().catch((error) => { |
| 111 | + console.error(error); |
| 112 | + process.exit(1); |
| 113 | +}); |
0 commit comments