@@ -16,6 +16,7 @@ import {
1616 getOrDeployWormholeContract ,
1717 BaseDeployConfig ,
1818} from "./common" ;
19+ import { HermesClient } from "@pythnetwork/hermes-client" ;
1920
2021interface DeploymentConfig extends BaseDeployConfig {
2122 type : DeploymentType ;
@@ -45,6 +46,21 @@ const parser = yargs(hideBin(process.argv))
4546 default : 1 ,
4647 desc : "Single update fee in wei for the price feed" ,
4748 } ,
49+ "single-update-fee-in-usd" : {
50+ type : "number" ,
51+ demandOption : false ,
52+ desc : "Single update fee in USD for the price feed. (This overrides the single-update-fee-in-wei option) " ,
53+ } ,
54+ "native-token-price-feed-id" : {
55+ type : "string" ,
56+ demandOption : false ,
57+ desc : "Pyth Price Feed ID to fetch the current price of the native token (This will be used to calculate the single-update-fee-in-usd)" ,
58+ } ,
59+ "native-token-decimals" : {
60+ type : "number" ,
61+ demandOption : false ,
62+ desc : "Number of decimals of the native token" ,
63+ } ,
4864 } ) ;
4965
5066async function deployPriceFeedContracts (
@@ -92,11 +108,46 @@ async function deployPriceFeedContracts(
92108
93109async function main ( ) {
94110 const argv = await parser . argv ;
111+ let singleUpdateFeeInWei = argv . singleUpdateFeeInWei ;
112+
113+ const singleUpdateFeeInUsd = argv [ "single-update-fee-in-usd" ] ;
114+ const nativeTokenPriceFeedId = argv [ "native-token-price-feed-id" ] ;
115+ const nativeTokenDecimals = argv [ "native-token-decimals" ] ;
116+ if (
117+ singleUpdateFeeInUsd &&
118+ ( nativeTokenPriceFeedId == null || nativeTokenDecimals == null )
119+ ) {
120+ throw new Error (
121+ "native-token-price-feed-id and native-token-decimals are required when single-update-fee-in-usd is provided" ,
122+ ) ;
123+ }
124+
125+ if ( nativeTokenPriceFeedId && singleUpdateFeeInUsd && nativeTokenDecimals ) {
126+ const hermesClient = new HermesClient ( "https://hermes.pyth.network" ) ;
127+ const priceObject = await hermesClient . getLatestPriceUpdates (
128+ [ nativeTokenPriceFeedId ] ,
129+ {
130+ parsed : true ,
131+ } ,
132+ ) ;
133+
134+ const price = priceObject . parsed ?. [ 0 ] . price ;
135+ if ( price == null ) {
136+ throw new Error ( "Failed to get price of the native token" ) ;
137+ }
138+ const priceInUsd = Number ( price . price ) ;
139+ const exponent = price . expo ;
140+ singleUpdateFeeInWei = Math . round (
141+ Math . pow ( 10 , nativeTokenDecimals ) *
142+ ( singleUpdateFeeInUsd / ( priceInUsd * Math . pow ( 10 , exponent ) ) ) ,
143+ ) ;
144+ console . log ( `Single update fee in wei: ${ singleUpdateFeeInWei } ` ) ;
145+ }
95146
96147 const deploymentConfig : DeploymentConfig = {
97148 type : toDeploymentType ( argv . deploymentType ) ,
98149 validTimePeriodSeconds : argv . validTimePeriodSeconds ,
99- singleUpdateFeeInWei : argv . singleUpdateFeeInWei ,
150+ singleUpdateFeeInWei : singleUpdateFeeInWei ,
100151 gasMultiplier : argv . gasMultiplier ,
101152 gasPriceMultiplier : argv . gasPriceMultiplier ,
102153 privateKey : toPrivateKey ( argv . privateKey ) ,
0 commit comments