I'm currently facing an issue related to the Pyth (pyth: 0x80004)

I’m using the following script to submit a transaction that updates the funding rate via the Pyth price feed on Aptos Testnet. However, when the script starts, I often receive the following error on the first attempt:

Move abort in 0x7e783b349d3e89cf5931af376ebeadbfab855b3fa239b7ada8f5a92fbea6b387::pyth: 0x80004

Here is the full code:

import { Account, Aptos, AptosConfig, Ed25519PrivateKey, InputEntryFunctionData, Network, PrivateKey, PrivateKeyVariants } from "@aptos-labs/ts-sdk";
import dotenv from "dotenv";
import { MARKET_PRICE_FEEDS } from "../src/perpetuals/constant";
import { AptosPriceServiceConnection } from "@pythnetwork/pyth-aptos-js";
dotenv.config();

const config = new AptosConfig({ network: Network.TESTNET, fullnode: process.env.NODEREAL_TESTNET_URL });
const aptos = new Aptos(config);

const rawPrivateKey = process.env.APTOS_PRIVATEKEY_2 || '';
const prefixedPrivateKey = `ed25519-priv-${rawPrivateKey}`;

const formattedPrivateKey = PrivateKey.formatPrivateKey(
    prefixedPrivateKey,
    'ed25519' as PrivateKeyVariants
);

const account = Account.fromPrivateKey({
    privateKey: new Ed25519PrivateKey(formattedPrivateKey),
});

let lastUpdateHex = "";

async function main(): Promise<void> {
    const priceFeedId = MARKET_PRICE_FEEDS[1338];
    const TESTNET_HERMES_ENDPOINT = "https://hermes-beta.pyth.network";
    const testnetConnection = new AptosPriceServiceConnection(TESTNET_HERMES_ENDPOINT);
    const priceFeedUpdateData = await testnetConnection.getPriceFeedsUpdateData([priceFeedId]);

    const newUpdateHex = Buffer.from(priceFeedUpdateData[0]).toString("hex");
    console.log("newUpdateHex: ", newUpdateHex);
    console.log("lastUpdateHex: ", lastUpdateHex);
    if (newUpdateHex === lastUpdateHex) {
        console.log("No new price update. Skipping transaction.");
        return;
    }
    lastUpdateHex = newUpdateHex;

    const payloadResponse = {
        function: "0x732f891290449af5e9369866537a51a8e7dc566791aec61a468223ed840b1eb4::perpetual_core::update_funding_rate_external",
        functionArguments: [1338, priceFeedUpdateData],
        typeArguments: [],
    } as InputEntryFunctionData;

    const transactionPayload = await aptos.transaction.build.simple({
        sender: account.accountAddress,
        data: payloadResponse
    });
    const committedTxn = await aptos.transaction.signAndSubmitTransaction({
        transaction: transactionPayload,
        signer: account,
    });
    console.log(`Submitted transaction: ${committedTxn.hash}`);
    const response = await aptos.waitForTransaction({
        transactionHash: committedTxn.hash,
    });
    console.log("response", response.success);
}

setInterval(() => {
    main().catch(error => {
        console.error('An error occurred:', error);
    });
}, 2000); // 10000 ms = 10 seconds

When the script starts, I receive the following error:

Move abort in 0x7e783b349d3e89cf5931af376ebeadbfab855b3fa239b7ada8f5a92fbea6b387::pyth: 0x80004

Here’s the full transaction response

transaction: {
    version: '6695136723',
    hash: '0x968e4fcf2913a2e592019302905c7c17c72db2115402861524534de760f88098',
    state_change_hash: '0xd4d0ec0de026b29b0f336dfa4c879f55d1d124223be91a4dfd27c99fef514294',
    event_root_hash: '0x9a6b71794212218afcbeb820e6a2c1b6e19f2416f24733291db777f547158444',
    state_checkpoint_hash: null,
    gas_used: '97',
    success: false,
    vm_status: 'Move abort in 0x7e783b349d3e89cf5931af376ebeadbfab855b3fa239b7ada8f5a92fbea6b387::pyth: 0x80004',
    accumulator_root_hash: '0x7ef6b1e51c6b6156529c6b5871f0ee12c6337b3ae1b521489e4eefdd4c8a32a6',
    changes: [ [Object], [Object], [Object] ],
    sender: '0x37d5a65c13e855b49f3b8657589ee2de09d9948a5daedf1ca739fb8a6d50558',
    sequence_number: '223',
    max_gas_amount: '200000',
    gas_unit_price: '100',
    expiration_timestamp_secs: '1745315165',
    payload: {
      function: '0x732f891290449af5e9369866537a51a8e7dc566791aec61a468223ed840b1eb4::perpetual_core::update_funding_rate_external',
      type_arguments: [],
      arguments: [Array],
      type: 'entry_function_payload'
    },
    signature: {
      public_key: '0x333d6ec6ff12f79184b83825e25bf547c53f2af5bc441cdbede8f256cfaf1694',
      signature: '0x3258f0ab8016e041ff501f0d0b4087c557217572783ef6dfe77138f97f918156480d0511a1aebe7c8b830292fe93bb9318e1a4d7ee1f6de8fde917f69f103c0f',
      type: 'ed25519_signature'
    },
    events: [ [Object] ],
    timestamp: '1745315146193550',
    type: 'user_transaction'
  }

Oddly, the next attempt always succeeds without any issues.

To avoid sending redundant transactions, I added a condition to compare the newly fetched price update data with the last one:

const TESTNET_HERMES_ENDPOINT = "https://hermes-beta.pyth.network";
    const testnetConnection = new AptosPriceServiceConnection(TESTNET_HERMES_ENDPOINT);
    const priceFeedUpdateData = await testnetConnection.getPriceFeedsUpdateData([priceFeedId]);

I added a condition to check whether the previous and current data are the same data:

if (newUpdateHex === lastUpdateHex)

However, the condition is not being triggered, so it fetches new data every time.

Most of the time, when the script starts, it returns an error on the first attempt, but the subsequent requests succeed. After some time, though, the error occurs again.

This is how we use it and this is where the error occurs:

let coins = coin::withdraw(user, pyth_oracle::get_update_fee(&pyth_update_data));
pyth_oracle::update_price_feeds(pyth_update_data, coins);
let price_id = price_identifier::from_byte_vec(price_data.pyth_price_id);
let price = pyth_oracle::get_price_no_older_than(price_id, PYTH_STALE_PRICE_THRESHOLD);

Could someone please help me identify and resolve this issue?

@Ajay that error means that the price is stale (see here) but it is very strange that you are getting it like this. What is the value of PYTH_STALE_PRICE_THRESHOLD?

Would you be able to switch to Hermes client? With the new API that this client has you get the update data with the parsed data and we can see whether the price you are fetching is stale or not.

Hi @ali ,

The value of PYTH_STALE_PRICE_THRESHOLD is set to 60 seconds.

I also switched to the Hermes client. Below is my code:

const priceIds = [MARKET_PRICE_FEEDS[marketId]];
const connection = new HermesClient("https://hermes-beta.pyth.network", {});
const priceFeedUpdateData = await connection.getLatestPriceUpdates(priceIds, {
    encoding: "base64",
});
const binaryDataAsNumbers: number[][] = priceFeedUpdateData.binary.data.map((base64String: string) =>
    Array.from(Buffer.from(base64String, "base64"))
);
const payloadResponse = {
    function: FUNCTION_ADDRESS_PARAMS.testnet.update_funding_rate_external_function,
    functionArguments: [marketId, binaryDataAsNumbers],
    typeArguments: [],
} as InputEntryFunctionData;
return payloadResponse;

Using this payload, I tried to submit the transaction, but I am still encountering the same issue.

:cross_mark: Update Funding Rates Transaction Execution Failed:
Error: Transaction 0x8dc30c4d60d44137b973f9b2154b3dff6b0d47467925e35a9881ec0fa5e1e1f8 failed with the following error:
Move abort in 0x7e783b349d3e89cf5931af376ebeadbfab855b3fa239b7ada8f5a92fbea6b387::pyth: 0x80004

Transaction details:

{
    "version": "6696111624",
    "hash": "0x8dc30c4d60d44137b973f9b2154b3dff6b0d47467925e35a9881ec0fa5e1e1f8",
    "state_change_hash": "0x5f496b0abe397e38ea37c5d3109ff793a526c8d244178f5c754d474cff4c4007",
    "event_root_hash": "0x9a6b71794212218afcbeb820e6a2c1b6e19f2416f24733291db777f547158444",
    "state_checkpoint_hash": null,
    "gas_used": "97",
    "success": false,
    "vm_status": "Move abort in 0x7e783b349d3e89cf5931af376ebeadbfab855b3fa239b7ada8f5a92fbea6b387::pyth: 0x80004",
    "accumulator_root_hash": "0x69c0124203daa82d1d3d4479f073de5151f6caf5e3e3d704b49a17ba7dce61a2",
    "changes": [ ... ],
    "sender": "0x6070678dc39334e9f3463e7f18d2b604a5448529664b41138cc4d0c2e17ce73b",
    "sequence_number": "134922",
    "max_gas_amount": "200000",
    "gas_unit_price": "100",
    "expiration_timestamp_secs": "1745402894",
    "payload": {
        "function": "0x732f891290449af5e9369866537a51a8e7dc566791aec61a468223ed840b1eb4::perpetual_core::update_funding_rate_external",
        "type_arguments": [],
        "arguments": [ ... ],
        "type": "entry_function_payload"
    },
    "signature": {
        "public_key": "0x00cb8c7304836e45442e8e84ec05ba69b77a613e4113cdc25af77c396cb1c085",
        "signature": "0xeef5d8f88e516313e742361fc17031bc5a26ee1174a15107f945bb25b2630aaae68fd810bd81fc535b8abe0e4357aae7254818f443502062a2a6f225b7aa5606",
        "type": "ed25519_signature"
    },
    "events": [ ... ],
    "timestamp": "1745402875884318",
    "type": "user_transaction"
}

Could you please take a look at this and help us resolve the issue? @ali

@Ajay When you fetch the update data from Hermes. can you print it (price, and publish time) along with the current utc timestamp? I also like to know the ids of the feeds you are trying to work with.

Hi @ali

Let me share some more details regarding this.

Here is the priceFeedUpdateData:

priceFeedUpdateData {
  binary: {
    data: [
      'UE5BVQEAAAAAoAEAAAAAAQA3GcJAkKshiDbSMYgOjbUX3vipf75s8sbZj5AroUluWDq7CoWUPMJSQb4nzoSgut/GVwF36sgbAECUW3LGNNwzAWgJBuQAAAAAABrhAfrtrFhR4yubI7X5QRqMK6xKrj7U3XuBHdGnLqSqcQAAAAAIFlKDAUFVV1YAAAAAAAyrmlMAACcQtrnrHsaWGrmJS0ukD9jeEawhrhEBAFUARKk93djv+lTqUQdsToUbbLv9k46C65AZfeOP6Idrtm4AAAAAHyeDPgAAAAAABFI+////+AAAAABoCQbkAAAAAGgJBuMAAAAAH53u1gAAAAAABHmuDL5J+qSLgGrCs6lhM6uQUIQQ2UssrP+xBRYb39mJWYCn9wPa9n4YX8sYjw9kV9or0V7mdSP4hjunHyc2OJn6uyL3zdAYjALFvTs1hlAnnyyTP5o/pYGe7nxoWmmF31SQCQvGsEVwVZEaa7jGnhD7heQxqRt6mvTHER+lkIsef0na2OM4btzL5QZAJLnwtzLTh0diOlI4mUokjpGOp1AWwksUfcnkUJz8B+7GTwO/X7MNkIjqhh5ACyZ1ww7iCE9BlTr9897wyedXPOwGZi80hQkd1o+yFCN7zvKMOT2TSrdx+675+lwQDnUj1Mv+oOfZqQ=='
    ],
    encoding: 'base64'
  },
  parsed: [
    {
      ema_price: [Object],
      id: '44a93dddd8effa54ea51076c4e851b6cbbfd938e82eb90197de38fe8876bb66e',
      metadata: [Object],
      price: [Object]
    }
  ]
}
ema_price: {
  conf: '293294',
  expo: -8,
  price: '530443990',
  publish_time: 1745422052
}
metadata: {
  prev_publish_time: 1745422051,
  proof_available_time: 1745422053,
  slot: 212572755
}
price: {
  conf: '283198',
  expo: -8,
  price: '522683198',
  publish_time: 1745422052
}

Here are the price feed IDs I’m currently using on the beta Aptos testnet:

  • APT_PRICE_FEED_ID: 0x44a93dddd8effa54ea51076c4e851b6cbbfd938e82eb90197de38fe8876bb66e
  • BTC_PRICE_FEED_ID: 0xf9c0172ba10dfa4d19088d94f5bf61d3b54d5bd7483a322a982e1373ee8ea31b
  • ETH_PRICE_FEED_ID: 0xca80ba6dc32e08d06f1aa886011eed1d77c77be9eb761cc10d72b7d0a2fd57a6

If you need any additional information, please let me know.

Thanks!

Just to close this issue, the problem was that the PYTH_STALE_PRICE_THRESHOLD was set to 3 seconds (and not 60 as previously mentioned). Changing it to 10 solved the problem.

1 Like