[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.
This commit is contained in:
Mohammad Amin Khashkhashi Moghaddam 2023-08-09 14:43:06 +02:00 committed by GitHub
parent 1ed8b673f9
commit caca2da9e2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 26 additions and 10 deletions

2
package-lock.json generated
View File

@ -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",

View File

@ -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 \

View File

@ -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",

View File

@ -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({