@@ -20,6 +20,17 @@ const parser = yargs(hideBin(process.argv))
2020 type : "string" ,
2121 desc : "Hermes endpoint to use, defaults to https://hermes.pyth.network" ,
2222 } ,
23+ encoding : {
24+ type : "string" ,
25+ desc : "Encoding to use for the price feeds (hex or base64), defaults to hex" ,
26+ choices : [ "hex" , "base64" ] ,
27+ default : "hex" ,
28+ } ,
29+ "chunk-size" : {
30+ type : "number" ,
31+ desc : "Chunk size to use for the price feeds, defaults to 150" ,
32+ default : 150 ,
33+ } ,
2334 } ) ;
2435
2536// This script is intended to update all pricefeeds after we deploy pyth pricefeeds contract.
@@ -32,6 +43,7 @@ async function main() {
3243 ) ;
3344 const contract = DefaultStore . contracts [ argv . contract ] ;
3445 const privateKey = toPrivateKey ( argv [ "private-key" ] ) ;
46+ const encoding = argv . encoding || "hex" ;
3547
3648 priceFeedsMetadata = await client . getPriceFeeds ( ) ;
3749
@@ -40,8 +52,13 @@ async function main() {
4052
4153 // We can adjust the chunk size based on the chain. Don't exceed 150 for now.
4254 // TODO: Add a check for the chain's block gas limit and adjust the chunk size accordingly.
43- const chunkSize = 150 ;
55+ const chunkSize = argv . chunkSize ;
4456 for ( let i = 0 ; i < priceFeedIds . length ; i += chunkSize ) {
57+ console . log (
58+ `Processing chunk ${ i / chunkSize + 1 } of ${ Math . ceil (
59+ priceFeedIds . length / chunkSize
60+ ) } `
61+ ) ;
4562 const chunk = priceFeedIds . slice ( i , i + chunkSize ) ;
4663 console . log ( `length: ${ chunk . length } ` ) ;
4764 const updates = await client . getLatestPriceUpdates ( chunk , {
@@ -50,7 +67,11 @@ async function main() {
5067 console . log (
5168 await contract . executeUpdatePriceFeed (
5269 privateKey ,
53- updates . binary . data . map ( ( update ) => Buffer . from ( update , "hex" ) )
70+ updates . binary . data . map ( ( update ) =>
71+ encoding === "hex"
72+ ? Buffer . from ( update , "hex" )
73+ : Buffer . from ( update , "base64" )
74+ )
5475 )
5576 ) ;
5677 }
0 commit comments