From 1f3450cf2d91332979e777d1ebc01f8296c10c15 Mon Sep 17 00:00:00 2001 From: Daniel Chew Date: Thu, 19 Oct 2023 22:59:13 +0900 Subject: [PATCH] fix getLatestPriceFeed (#86) * fix getLatestPriceFeed * fix parse-price-feed-updates-unique --- pages/aptos/get-update-fee.mdx | 2 +- pages/aptos/update-price-feeds-with-funder.mdx | 2 +- pages/aptos/update-price-feeds.mdx | 5 +++-- pages/evm/get-update-fee.mdx | 2 +- pages/evm/parse-price-feed-updates-unique.mdx | 10 ++++++---- pages/evm/parse-price-feed-updates.mdx | 10 ++++++---- pages/evm/update-price-feeds-if-necessary.mdx | 7 ++++--- 7 files changed, 22 insertions(+), 16 deletions(-) diff --git a/pages/aptos/get-update-fee.mdx b/pages/aptos/get-update-fee.mdx index 2653e5a4..65ede9ed 100644 --- a/pages/aptos/get-update-fee.mdx +++ b/pages/aptos/get-update-fee.mdx @@ -29,7 +29,7 @@ By default, the data is returned as a base64-encoded string that you must deseri JSON.stringify( Array.from( Buffer.from( - (await ctx.getLatestPriceFeed("Crypto.BTC/USD")).vaa, + (await ctx.getLatestPriceFeed("Crypto.BTC/USD", "aptos")).vaa, "base64" ) ) diff --git a/pages/aptos/update-price-feeds-with-funder.mdx b/pages/aptos/update-price-feeds-with-funder.mdx index d42a4b39..ecf27139 100644 --- a/pages/aptos/update-price-feeds-with-funder.mdx +++ b/pages/aptos/update-price-feeds-with-funder.mdx @@ -37,7 +37,7 @@ Reverts if the `account` does not have a sufficient balance or `update_data` is JSON.stringify( Array.from( Buffer.from( - (await ctx.getLatestPriceFeed("Crypto.BTC/USD")).vaa, + (await ctx.getLatestPriceFeed("Crypto.BTC/USD", "aptos")).vaa, "base64" ) ) diff --git a/pages/aptos/update-price-feeds.mdx b/pages/aptos/update-price-feeds.mdx index aab33d73..be53f9c3 100644 --- a/pages/aptos/update-price-feeds.mdx +++ b/pages/aptos/update-price-feeds.mdx @@ -37,7 +37,7 @@ Reverts if the required fee is not paid, or the `update_data` is incorrectly sig JSON.stringify( Array.from( Buffer.from( - (await ctx.getLatestPriceFeed("Crypto.BTC/USD")).vaa, + (await ctx.getLatestPriceFeed("Crypto.BTC/USD", "aptos")).vaa, "base64" ) ) @@ -46,7 +46,8 @@ Reverts if the required fee is not paid, or the `update_data` is incorrectly sig // NOTE: this technically could get the update fee for a different VAA than the one above. // This shouldn't affect the update fee as long as the fee is only dependent on the price feed ids // and not the specific content of the price update. - let vaa = (await ctx.getLatestPriceFeed("Crypto.BTC/USD")).vaa; + // FIXME: this gets the ETH update fee, not the cosmos fee. They're currently the same though. + let vaa = (await ctx.getLatestPriceFeed("Crypto.BTC/USD", "evm")).vaa; return await ctx.getEthUpdateFee([vaa]); }, }} diff --git a/pages/evm/get-update-fee.mdx b/pages/evm/get-update-fee.mdx index b758a719..1083c454 100644 --- a/pages/evm/get-update-fee.mdx +++ b/pages/evm/get-update-fee.mdx @@ -25,7 +25,7 @@ The `updateData` can be retrieved from the [Hermes API](https://hermes.pyth.netw - (await ctx.getLatestPriceFeed("Crypto.BTC/USD")).vaa, + (await ctx.getLatestPriceFeed("Crypto.BTC/USD", "evm")).vaa, }} value="Latest BTC/USD update data" /> diff --git a/pages/evm/parse-price-feed-updates-unique.mdx b/pages/evm/parse-price-feed-updates-unique.mdx index 16bd4bd6..e28ea101 100644 --- a/pages/evm/parse-price-feed-updates-unique.mdx +++ b/pages/evm/parse-price-feed-updates-unique.mdx @@ -38,14 +38,16 @@ contain an update for any of the given `priceIds` within the given time range. - (await ctx.getLatestPriceFeed("Crypto.BTC/USD")).vaa, + (await ctx.getLatestPriceFeed("Crypto.BTC/USD", "evm")).vaa, priceId: (ctx) => ctx.getFeedId0x("Crypto.BTC/USD"), minPublishTime: async (ctx) => - (await ctx.getLatestPriceFeed("Crypto.BTC/USD")).price.publish_time - 5, + (await ctx.getLatestPriceFeed("Crypto.BTC/USD", "evm")).price + .publish_time - 5, maxPublishTime: async (ctx) => - (await ctx.getLatestPriceFeed("Crypto.BTC/USD")).price.publish_time + 5, + (await ctx.getLatestPriceFeed("Crypto.BTC/USD", "evm")).price + .publish_time + 5, fee: async (ctx) => { - let vaa = (await ctx.getLatestPriceFeed("Crypto.BTC/USD")).vaa; + let vaa = (await ctx.getLatestPriceFeed("Crypto.BTC/USD", "evm")).vaa; return await ctx.getEthUpdateFee([vaa]); }, }} diff --git a/pages/evm/parse-price-feed-updates.mdx b/pages/evm/parse-price-feed-updates.mdx index 1ad4a36e..101e717e 100644 --- a/pages/evm/parse-price-feed-updates.mdx +++ b/pages/evm/parse-price-feed-updates.mdx @@ -37,14 +37,16 @@ contain an update for any of the given `priceIds` within the given time range. - (await ctx.getLatestPriceFeed("Crypto.BTC/USD")).vaa, + (await ctx.getLatestPriceFeed("Crypto.BTC/USD", "evm")).vaa, priceId: (ctx) => ctx.getFeedId0x("Crypto.BTC/USD"), minPublishTime: async (ctx) => - (await ctx.getLatestPriceFeed("Crypto.BTC/USD")).price.publish_time - 5, + (await ctx.getLatestPriceFeed("Crypto.BTC/USD", "evm")).price + .publish_time - 5, maxPublishTime: async (ctx) => - (await ctx.getLatestPriceFeed("Crypto.BTC/USD")).price.publish_time + 5, + (await ctx.getLatestPriceFeed("Crypto.BTC/USD", "evm")).price + .publish_time + 5, fee: async (ctx) => { - let vaa = (await ctx.getLatestPriceFeed("Crypto.BTC/USD")).vaa; + let vaa = (await ctx.getLatestPriceFeed("Crypto.BTC/USD", "evm")).vaa; return await ctx.getEthUpdateFee([vaa]); }, }} diff --git a/pages/evm/update-price-feeds-if-necessary.mdx b/pages/evm/update-price-feeds-if-necessary.mdx index 3a3ad0ae..eff99ae5 100644 --- a/pages/evm/update-price-feeds-if-necessary.mdx +++ b/pages/evm/update-price-feeds-if-necessary.mdx @@ -37,12 +37,13 @@ Reverts if the required fee is not paid, or the `updateData` is incorrectly sign - (await ctx.getLatestPriceFeed("Crypto.BTC/USD")).vaa, + (await ctx.getLatestPriceFeed("Crypto.BTC/USD", "evm")).vaa, priceId: (ctx) => ctx.getFeedId0x("Crypto.BTC/USD"), publishTime: async (ctx) => - (await ctx.getLatestPriceFeed("Crypto.BTC/USD")).price.publish_time, + (await ctx.getLatestPriceFeed("Crypto.BTC/USD", "evm")).price + .publish_time, fee: async (ctx) => { - let vaa = (await ctx.getLatestPriceFeed("Crypto.BTC/USD")).vaa; + let vaa = (await ctx.getLatestPriceFeed("Crypto.BTC/USD", "evm")).vaa; return await ctx.getEthUpdateFee([vaa]); }, }}