@@ -16,6 +16,7 @@ import {
16
16
getOrDeployWormholeContract ,
17
17
BaseDeployConfig ,
18
18
} from "./common" ;
19
+ import { HermesClient } from "@pythnetwork/hermes-client" ;
19
20
20
21
interface DeploymentConfig extends BaseDeployConfig {
21
22
type : DeploymentType ;
@@ -45,6 +46,21 @@ const parser = yargs(hideBin(process.argv))
45
46
default : 1 ,
46
47
desc : "Single update fee in wei for the price feed" ,
47
48
} ,
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
+ } ,
48
64
} ) ;
49
65
50
66
async function deployPriceFeedContracts (
@@ -92,11 +108,46 @@ async function deployPriceFeedContracts(
92
108
93
109
async function main ( ) {
94
110
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
+ }
95
146
96
147
const deploymentConfig : DeploymentConfig = {
97
148
type : toDeploymentType ( argv . deploymentType ) ,
98
149
validTimePeriodSeconds : argv . validTimePeriodSeconds ,
99
- singleUpdateFeeInWei : argv . singleUpdateFeeInWei ,
150
+ singleUpdateFeeInWei : singleUpdateFeeInWei ,
100
151
gasMultiplier : argv . gasMultiplier ,
101
152
gasPriceMultiplier : argv . gasPriceMultiplier ,
102
153
privateKey : toPrivateKey ( argv . privateKey ) ,
0 commit comments