Skip to content

Commit eef23fd

Browse files
devin-ai-integration[bot]Jayant Krishnamurthy
andcommitted
feat: add script to get price feed details
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]>
1 parent 2fe9fb8 commit eef23fd

File tree

1 file changed

+127
-0
lines changed

1 file changed

+127
-0
lines changed
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
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+
getDefaultDeploymentConfig,
8+
toDeploymentType,
9+
toPrivateKey,
10+
} from "../src";
11+
import {
12+
COMMON_DEPLOY_OPTIONS,
13+
deployIfNotCached,
14+
getWeb3Contract,
15+
getOrDeployWormholeContract,
16+
BaseDeployConfig,
17+
} from "./common";
18+
19+
interface DeploymentConfig extends BaseDeployConfig {
20+
type: DeploymentType;
21+
validTimePeriodSeconds: number;
22+
singleUpdateFeeInWei: number;
23+
saveContract: boolean;
24+
}
25+
26+
const CACHE_FILE = ".cache-get-pricefeed";
27+
28+
const parser = yargs(hideBin(process.argv))
29+
.scriptName("get_pricefeed_details.ts")
30+
.usage(
31+
"Usage: $0 --std-output-dir <path/to/std-output-dir/> --private-key <private-key> --chain <chain-name>"
32+
)
33+
.options({
34+
...COMMON_DEPLOY_OPTIONS,
35+
chain: {
36+
type: "string",
37+
demandOption: true,
38+
desc: "Chain name to get price feed details for",
39+
},
40+
});
41+
42+
async function getPriceFeedDetails(
43+
chain: EvmChain,
44+
config: DeploymentConfig,
45+
wormholeAddr: string
46+
): Promise<{ pythImplAddr: string; pythInitData: string }> {
47+
const pythImplAddr = await deployIfNotCached(
48+
CACHE_FILE,
49+
chain,
50+
config,
51+
"PythUpgradable",
52+
[]
53+
);
54+
55+
// Get the init data for the proxy contract
56+
const { dataSources, governanceDataSource } = getDefaultDeploymentConfig(
57+
config.type
58+
);
59+
60+
const pythImplContract = getWeb3Contract(
61+
config.jsonOutputDir,
62+
"PythUpgradable",
63+
pythImplAddr
64+
);
65+
66+
const pythInitData = pythImplContract.methods
67+
.initialize(
68+
wormholeAddr,
69+
dataSources.map((ds) => ds.emitterChain),
70+
dataSources.map((ds) => "0x" + ds.emitterAddress),
71+
governanceDataSource.emitterChain,
72+
"0x" + governanceDataSource.emitterAddress,
73+
0, // governanceInitialSequence
74+
config.validTimePeriodSeconds,
75+
config.singleUpdateFeeInWei
76+
)
77+
.encodeABI();
78+
79+
return { pythImplAddr, pythInitData };
80+
}
81+
82+
async function main() {
83+
const argv = await parser.argv;
84+
85+
const deploymentConfig: DeploymentConfig = {
86+
type: toDeploymentType(argv.deploymentType),
87+
validTimePeriodSeconds: 60, // As specified
88+
singleUpdateFeeInWei: 1, // As specified
89+
gasMultiplier: argv.gasMultiplier,
90+
gasPriceMultiplier: argv.gasPriceMultiplier,
91+
privateKey: toPrivateKey(argv.privateKey),
92+
jsonOutputDir: argv.stdOutputDir,
93+
saveContract: argv.saveContract,
94+
};
95+
96+
console.log(
97+
`Deployment config: ${JSON.stringify(deploymentConfig, null, 2)}\n`
98+
);
99+
100+
const chainName = argv.chain as string;
101+
const chain = DefaultStore.chains[chainName];
102+
if (!chain) {
103+
throw new Error(`Chain ${chainName} not found`);
104+
} else if (!(chain instanceof EvmChain)) {
105+
throw new Error(`Chain ${chainName} is not an EVM chain`);
106+
}
107+
108+
console.log(`Getting price feed details for ${chain.getId()}...`);
109+
110+
const wormholeContract = await getOrDeployWormholeContract(
111+
chain,
112+
deploymentConfig,
113+
CACHE_FILE
114+
);
115+
116+
const { pythImplAddr, pythInitData } = await getPriceFeedDetails(
117+
chain,
118+
deploymentConfig,
119+
wormholeContract.address
120+
);
121+
122+
console.log(`\nPrice Feed Details for ${chain.getId()}:`);
123+
console.log(`Pyth Implementation Address: ${pythImplAddr}`);
124+
console.log(`Pyth Init Data: ${pythInitData}\n`);
125+
}
126+
127+
main();

0 commit comments

Comments
 (0)