Skip to content

Commit

Permalink
feat: add script to get price feed details
Browse files Browse the repository at this point in the history
Add get_pricefeed_details.ts script that:
- Takes chain_name as argument
- Returns pythImplAddr and pythInitData
- Uses wormholeAddr from store
- Uses validTimePeriodSeconds = 60
- Uses singleUpdateFeeInWei = 1

Co-Authored-By: Jayant Krishnamurthy <[email protected]>
  • Loading branch information
devin-ai-integration[bot] and Jayant Krishnamurthy committed Jan 16, 2025
1 parent 2fe9fb8 commit eef23fd
Showing 1 changed file with 127 additions and 0 deletions.
127 changes: 127 additions & 0 deletions contract_manager/scripts/get_pricefeed_details.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
import yargs from "yargs";
import { hideBin } from "yargs/helpers";
import { EvmChain } from "../src/chains";
import { DefaultStore } from "../src/store";
import {
DeploymentType,
getDefaultDeploymentConfig,
toDeploymentType,
toPrivateKey,
} from "../src";
import {
COMMON_DEPLOY_OPTIONS,
deployIfNotCached,
getWeb3Contract,
getOrDeployWormholeContract,
BaseDeployConfig,
} from "./common";

interface DeploymentConfig extends BaseDeployConfig {
type: DeploymentType;
validTimePeriodSeconds: number;
singleUpdateFeeInWei: number;
saveContract: boolean;
}

const CACHE_FILE = ".cache-get-pricefeed";

const parser = yargs(hideBin(process.argv))
.scriptName("get_pricefeed_details.ts")
.usage(
"Usage: $0 --std-output-dir <path/to/std-output-dir/> --private-key <private-key> --chain <chain-name>"
)
.options({
...COMMON_DEPLOY_OPTIONS,
chain: {
type: "string",
demandOption: true,
desc: "Chain name to get price feed details for",
},
});

async function getPriceFeedDetails(
chain: EvmChain,
config: DeploymentConfig,
wormholeAddr: string
): Promise<{ pythImplAddr: string; pythInitData: string }> {
const pythImplAddr = await deployIfNotCached(
CACHE_FILE,
chain,
config,
"PythUpgradable",
[]
);

// Get the init data for the proxy contract
const { dataSources, governanceDataSource } = getDefaultDeploymentConfig(
config.type
);

const pythImplContract = getWeb3Contract(
config.jsonOutputDir,
"PythUpgradable",
pythImplAddr
);

const pythInitData = pythImplContract.methods
.initialize(
wormholeAddr,
dataSources.map((ds) => ds.emitterChain),
dataSources.map((ds) => "0x" + ds.emitterAddress),
governanceDataSource.emitterChain,
"0x" + governanceDataSource.emitterAddress,
0, // governanceInitialSequence
config.validTimePeriodSeconds,
config.singleUpdateFeeInWei
)
.encodeABI();

return { pythImplAddr, pythInitData };
}

async function main() {
const argv = await parser.argv;

const deploymentConfig: DeploymentConfig = {
type: toDeploymentType(argv.deploymentType),
validTimePeriodSeconds: 60, // As specified
singleUpdateFeeInWei: 1, // As specified
gasMultiplier: argv.gasMultiplier,
gasPriceMultiplier: argv.gasPriceMultiplier,
privateKey: toPrivateKey(argv.privateKey),
jsonOutputDir: argv.stdOutputDir,
saveContract: argv.saveContract,
};

console.log(
`Deployment config: ${JSON.stringify(deploymentConfig, null, 2)}\n`
);

const chainName = argv.chain as string;
const chain = DefaultStore.chains[chainName];
if (!chain) {
throw new Error(`Chain ${chainName} not found`);
} else if (!(chain instanceof EvmChain)) {
throw new Error(`Chain ${chainName} is not an EVM chain`);
}

console.log(`Getting price feed details for ${chain.getId()}...`);

const wormholeContract = await getOrDeployWormholeContract(
chain,
deploymentConfig,
CACHE_FILE
);

const { pythImplAddr, pythInitData } = await getPriceFeedDetails(
chain,
deploymentConfig,
wormholeContract.address
);

console.log(`\nPrice Feed Details for ${chain.getId()}:`);
console.log(`Pyth Implementation Address: ${pythImplAddr}`);
console.log(`Pyth Init Data: ${pythInitData}\n`);
}

main();

0 comments on commit eef23fd

Please sign in to comment.