Cant get update fee

Network: Monad Testnet
Timestamp: yesterday and today
Steps to reproduce:

  • Get price feed id (mine is BTC/USD)
  • Call the Hermes API to retrieve binary data
  • Pass the binary data to getUpdateFee
  • Error: invalid arrayify value (argument=“value”, value=
    Additional notes:
    I am trying to create a prediction game on monad testnet that utilizes Pyth price feeds with Pyth Pull Oracle, Hermes API and Gelato Web3 Automated functions. The flow goes like this:
    we have a round. there is a 20 second threshold where the users could bet if the price is going to go up or down. then, after 20 seconds, the round locks. we then get the updated data from hermes API, push it to the pull oracle via Gelato operator, compare the new price against the players’ bets and reward whoever won.
    right now stuck at getting the fees

Can you please share how you are calling getUpdateFee. Also share the complete error logs.

For your reference Price Feeds | Pyth Network API Reference , you can test it here.

hi, sorry for the delayed answer. i already found the issue, it was a mismatch in the types inside the contract. now i dont get any errors, but i still get 0 updates on price feed retrieval inside of the contract.

here is the function i have trouble with:

    function executeRound(bytes calldata pythUpdateData) external payable onlyOperator whenNotPaused {
        require(genesisStarted, "Genesis not started");

        uint256 currentRoundEpoch = currentEpoch;
        Round storage round = rounds[currentRoundEpoch];

        require(block.timestamp >= round.lockTimestamp, "Too early to lock");
        require(!round.settled, "Round already settled");
        bytes[] memory updateData = new bytes[](1);
        updateData[0] = pythUpdateData;

        uint256 fee = pyth.getUpdateFee(updateData);
        pyth.updatePriceFeeds{value: fee}(updateData);

        PythStructs.Price memory price = pyth.getPrice(priceId);

        round.lockPrice = price.price;
        round.lockTimestamp = block.timestamp;

        emit RoundLocked(currentRoundEpoch, round.lockPrice, block.timestamp);

        if (currentRoundEpoch > 1) {
            _settleRound(currentRoundEpoch - 1, price.price);
        }

        currentEpoch = currentRoundEpoch + 1;
        _startRound(currentEpoch);

        if (msg.value > fee) {
            (bool success, ) = msg.sender.call{value: msg.value - fee}("");
            require(success, "Refund failed");
        }
    }

it passes the calldata properly and the function runs all the way. however, whenever we retrieve prices via the contract, they are always 0. i tried reading the IPyth contract on Monad Testnet via javascript/ethers, and all the data was in place. However, whenever pyth.getPrice is being called via contract it returns 0. or i am not handling it properly. the address, abi and interface is the same in both cases.

I see few lines of code are redundant. You don’t have to create a new bytes array named updateData.
Refer https://docs.pyth.network/price-feeds/use-real-time-data/evm#write-contract-code, change the data type of the input parameter to bytes[] calldata and use it directly.

Also getPrice has been deprecated, please use function getPriceNoOlderThan

May be create a simple version of the function and see if it works.

i tried using bytes calldata in my previous contract, and it did not work for some reason. at least now it recognizes the calldata, so i’ll keep it like this because it does not revert. i also tried getPriceNoOlderThan(priceId, 20) right after the price update call, but i still get 0.

and both of getPrice and getPriceNoOlderThan work properly called via js ethers script from the contract operator account. and they do have the values i need

That seems weird. Can you share which version of @pythnetwork/pyth-sdk-solidity are you using in your solidity smart contract.

There is additional logic involved other than getting pyth price feed.
To isolate the issue, can you try creating a simple version of function. Something similar to this pyth-pricefeed-demo/src/PriceFeed.sol at main · nidhi-singh02/pyth-pricefeed-demo · GitHub. Refer the README.md file for the instructions.

Run it for your case as in Monad testnet and your asset pair and let me know the outcome please.

1 Like

sure. using version 4.2.0 of pyth-sdk. will try to separate the update logic like in your example

update: i was finally able to update prices with actual data on my contract. your function separation helped most likely. i also rewrote quite a bit of code as well. but consider it solved

2 Likes