From caca2da9e228fa53bf1d8e4dc5f0e99f395ceb97 Mon Sep 17 00:00:00 2001 From: Mohammad Amin Khashkhashi Moghaddam Date: Wed, 9 Aug 2023 14:43:06 +0200 Subject: [PATCH] [price-pusher] Fix fee calculation on injective price pusher (#1007) * Fix fee calculation on injective price pusher We used an optimization to calculate the update fee based on the number of VAAs. This used to be true before the accumulator messages but now since both formats can be used, it is not obvious what the final fee would be. We can again try to optimize this code and reduce rpc calls by replicating the fee calculation logic from the smart contract, but for now we have rolled back to the unoptimized version. --- package-lock.json | 2 +- price_pusher/README.md | 5 +++-- price_pusher/package.json | 2 +- price_pusher/src/injective/injective.ts | 27 +++++++++++++++++++------ 4 files changed, 26 insertions(+), 10 deletions(-) diff --git a/package-lock.json b/package-lock.json index a0dba16f..42396596 100644 --- a/package-lock.json +++ b/package-lock.json @@ -55997,7 +55997,7 @@ }, "price_pusher": { "name": "@pythnetwork/price-pusher", - "version": "5.4.6", + "version": "5.4.7", "license": "Apache-2.0", "dependencies": { "@injectivelabs/sdk-ts": "1.10.72", diff --git a/price_pusher/README.md b/price_pusher/README.md index 92a9f50b..b19c1532 100644 --- a/price_pusher/README.md +++ b/price_pusher/README.md @@ -79,8 +79,9 @@ npm run start -- injective --grpc-endpoint https://grpc-endpoint.com \ --pyth-contract-address inj1z60tg0... --price-service-endpoint "https://example-pyth-price.com" \ --price-config-file "path/to/price-config.testnet.sample.yaml" \ --mnemonic-file "path/to/mnemonic.txt" \ + --network testnet \ [--pushing-frequency 10] \ - [--polling-frequency 5] \ + [--polling-frequency 5] # For Aptos npm run start -- aptos --endpoint https://fullnode.testnet.aptoslabs.com/v1 \ @@ -88,7 +89,7 @@ npm run start -- aptos --endpoint https://fullnode.testnet.aptoslabs.com/v1 \ --price-config-file "./price-config.testnet.sample.yaml" \ --mnemonic-file "path/to/mnemonic.txt" \ [--pushing-frequency 10] \ - [--polling-frequency 5] \ + [--polling-frequency 5] # For Sui npm run start -- sui \ diff --git a/price_pusher/package.json b/price_pusher/package.json index dc786e7a..73d1bb20 100644 --- a/price_pusher/package.json +++ b/price_pusher/package.json @@ -1,6 +1,6 @@ { "name": "@pythnetwork/price-pusher", - "version": "5.4.6", + "version": "5.4.7", "description": "Pyth Price Pusher", "homepage": "https://pyth.network", "main": "lib/index.js", diff --git a/price_pusher/src/injective/injective.ts b/price_pusher/src/injective/injective.ts index fb847205..7c7c649d 100644 --- a/price_pusher/src/injective/injective.ts +++ b/price_pusher/src/injective/injective.ts @@ -213,12 +213,27 @@ export class InjectivePricePusher implements IPricePusher { return; } - // In order to reduce the number of API calls - // We are calculating the fee using the same logic as in contract. - const updateFeeQueryResponse: UpdateFeeResponse = { - denom: "inj", - amount: priceFeedUpdateObject.update_price_feeds.data.length.toFixed(), - }; + let updateFeeQueryResponse: UpdateFeeResponse; + try { + const api = new ChainGrpcWasmApi(this.grpcEndpoint); + const { data } = await api.fetchSmartContractState( + this.pythContractAddress, + Buffer.from( + JSON.stringify({ + get_update_fee: { + vaas: priceFeedUpdateObject.update_price_feeds.data, + }, + }) + ).toString("base64") + ); + + const json = Buffer.from(data).toString(); + updateFeeQueryResponse = JSON.parse(json); + } catch (e) { + console.error("Error fetching update fee"); + console.error(e); + return; + } try { const executeMsg = MsgExecuteContract.fromJSON({