├── .github └── workflows │ ├── abi-check.yml │ ├── build.yml │ ├── check-formatting.yml │ └── publish.yml ├── .gitignore ├── .pre-commit-config.yaml ├── AbstractPyth.sol ├── IPyth.sol ├── IPythEvents.sol ├── MockPyth.sol ├── PythErrors.sol ├── PythStructs.sol ├── README.md ├── abis ├── AbstractPyth.json ├── IPyth.json ├── IPythEvents.json └── MockPyth.json ├── package-lock.json ├── package.json └── scripts └── generateAbi.js /.github/workflows/abi-check.yml: -------------------------------------------------------------------------------- 1 | name: ABI Check 2 | on: 3 | push: 4 | branches: [main] 5 | pull_request: 6 | branches: [main] 7 | jobs: 8 | abi-check: 9 | name: Check ABI files are up to date 10 | runs-on: ubuntu-latest 11 | steps: 12 | - name: Checkout sources 13 | uses: actions/checkout@v3 14 | - uses: actions/setup-node@v3 15 | with: 16 | node-version: 14 17 | - run: npm ci 18 | - name: Generate ABI 19 | run: npm run generate-abi 20 | - name: Check ABI changes 21 | # Fails if the ABI files are not up to date. Please use npm run generate-abi to regenerate the ABI files for 22 | # the current version of the contracts. 23 | run: git diff --exit-code abis/* 24 | -------------------------------------------------------------------------------- /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | name: Build 2 | on: 3 | push: 4 | branches: [main] 5 | pull_request: 6 | branches: [main] 7 | jobs: 8 | abi-check: 9 | name: Check contracts can be built 10 | runs-on: ubuntu-latest 11 | steps: 12 | - name: Checkout sources 13 | uses: actions/checkout@v3 14 | - uses: actions/setup-node@v3 15 | with: 16 | node-version: 14 17 | - run: npm ci 18 | - name: Build 19 | run: npm run build-mock 20 | -------------------------------------------------------------------------------- /.github/workflows/check-formatting.yml: -------------------------------------------------------------------------------- 1 | name: Check formatting 2 | 3 | on: 4 | pull_request: 5 | push: 6 | branches: [main] 7 | 8 | jobs: 9 | pre-commit: 10 | runs-on: ubuntu-latest 11 | steps: 12 | - uses: actions/checkout@v2 13 | - uses: actions/setup-python@v2 14 | - uses: pre-commit/action@v2.0.3 15 | -------------------------------------------------------------------------------- /.github/workflows/publish.yml: -------------------------------------------------------------------------------- 1 | name: Node.js Package Publish 2 | on: 3 | release: 4 | types: [created] 5 | jobs: 6 | build: 7 | runs-on: ubuntu-latest 8 | steps: 9 | - uses: actions/checkout@v2 10 | - uses: actions/setup-node@v2 11 | with: 12 | node-version: "12.x" 13 | registry-url: "https://registry.npmjs.org" 14 | - run: npm ci 15 | - run: npm publish --access public 16 | env: 17 | NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | lerna-debug.log* 8 | .pnpm-debug.log* 9 | 10 | # Diagnostic reports (https://nodejs.org/api/report.html) 11 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json 12 | 13 | # Runtime data 14 | pids 15 | *.pid 16 | *.seed 17 | *.pid.lock 18 | 19 | # Directory for instrumented libs generated by jscoverage/JSCover 20 | lib-cov 21 | 22 | # Coverage directory used by tools like istanbul 23 | coverage 24 | *.lcov 25 | 26 | # nyc test coverage 27 | .nyc_output 28 | 29 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) 30 | .grunt 31 | 32 | # Bower dependency directory (https://bower.io/) 33 | bower_components 34 | 35 | # node-waf configuration 36 | .lock-wscript 37 | 38 | # Compiled binary addons (https://nodejs.org/api/addons.html) 39 | build/Release 40 | 41 | # Dependency directories 42 | node_modules/ 43 | jspm_packages/ 44 | 45 | # Snowpack dependency directory (https://snowpack.dev/) 46 | web_modules/ 47 | 48 | # TypeScript cache 49 | *.tsbuildinfo 50 | 51 | # Optional npm cache directory 52 | .npm 53 | 54 | # Optional eslint cache 55 | .eslintcache 56 | 57 | # Optional stylelint cache 58 | .stylelintcache 59 | 60 | # Microbundle cache 61 | .rpt2_cache/ 62 | .rts2_cache_cjs/ 63 | .rts2_cache_es/ 64 | .rts2_cache_umd/ 65 | 66 | # Optional REPL history 67 | .node_repl_history 68 | 69 | # Output of 'npm pack' 70 | *.tgz 71 | 72 | # Yarn Integrity file 73 | .yarn-integrity 74 | 75 | # dotenv environment variable files 76 | .env 77 | .env.development.local 78 | .env.test.local 79 | .env.production.local 80 | .env.local 81 | 82 | # parcel-bundler cache (https://parceljs.org/) 83 | .cache 84 | .parcel-cache 85 | 86 | # Next.js build output 87 | .next 88 | out 89 | 90 | # Nuxt.js build / generate output 91 | .nuxt 92 | dist 93 | 94 | # Gatsby files 95 | .cache/ 96 | # Comment in the public line in if your project uses Gatsby and not Next.js 97 | # https://nextjs.org/blog/next-9-1#public-directory-support 98 | # public 99 | 100 | # vuepress build output 101 | .vuepress/dist 102 | 103 | # vuepress v2.x temp and cache directory 104 | .temp 105 | .cache 106 | 107 | # Docusaurus cache and generated files 108 | .docusaurus 109 | 110 | # Serverless directories 111 | .serverless/ 112 | 113 | # FuseBox cache 114 | .fusebox/ 115 | 116 | # DynamoDB Local files 117 | .dynamodb/ 118 | 119 | # TernJS port file 120 | .tern-port 121 | 122 | # Stores VSCode versions used for testing VSCode extensions 123 | .vscode-test 124 | 125 | # yarn v2 126 | .yarn/cache 127 | .yarn/unplugged 128 | .yarn/build-state.yml 129 | .yarn/install-state.gz 130 | .pnp.* 131 | 132 | build/ 133 | -------------------------------------------------------------------------------- /.pre-commit-config.yaml: -------------------------------------------------------------------------------- 1 | repos: 2 | - repo: https://github.com/pre-commit/pre-commit-hooks 3 | rev: v3.2.0 4 | hooks: 5 | - id: trailing-whitespace 6 | - id: end-of-file-fixer 7 | - id: check-added-large-files 8 | args: ["--maxkb=1024"] 9 | - repo: https://github.com/pre-commit/mirrors-prettier 10 | rev: "v2.7.1" 11 | hooks: 12 | - id: prettier 13 | additional_dependencies: 14 | - "prettier@2.7.1" 15 | - "prettier-plugin-solidity@1.0.0-rc.1" 16 | -------------------------------------------------------------------------------- /AbstractPyth.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | pragma solidity ^0.8.0; 3 | 4 | import "./PythStructs.sol"; 5 | import "./IPyth.sol"; 6 | import "./PythErrors.sol"; 7 | 8 | /** 9 | * @notice **Deprecated** – this codebase will be removed on **1 August 2025**. 10 | * 11 | * @dev Switch to the maintained package: 12 | * `npm install @pythnetwork/pyth-sdk-solidity` 13 | * 14 | * Migration guide: 15 | * https://docs.pyth.network/price-feeds/use-real-time-data/evm 16 | * 17 | * @custom:deprecated Repository scheduled for deletion on 1 August 2025. 18 | * Use `@pythnetwork/pyth-sdk-solidity` instead. 19 | */ 20 | abstract contract AbstractPyth is IPyth { 21 | /// @notice Returns the price feed with given id. 22 | /// @dev Reverts if the price does not exist. 23 | /// @param id The Pyth Price Feed ID of which to fetch the PriceFeed. 24 | function queryPriceFeed( 25 | bytes32 id 26 | ) public view virtual returns (PythStructs.PriceFeed memory priceFeed); 27 | 28 | /// @notice Returns true if a price feed with the given id exists. 29 | /// @param id The Pyth Price Feed ID of which to check its existence. 30 | function priceFeedExists( 31 | bytes32 id 32 | ) public view virtual returns (bool exists); 33 | 34 | function getValidTimePeriod() 35 | public 36 | view 37 | virtual 38 | override 39 | returns (uint validTimePeriod); 40 | 41 | function getPrice( 42 | bytes32 id 43 | ) external view virtual override returns (PythStructs.Price memory price) { 44 | return getPriceNoOlderThan(id, getValidTimePeriod()); 45 | } 46 | 47 | function getEmaPrice( 48 | bytes32 id 49 | ) external view virtual override returns (PythStructs.Price memory price) { 50 | return getEmaPriceNoOlderThan(id, getValidTimePeriod()); 51 | } 52 | 53 | function getPriceUnsafe( 54 | bytes32 id 55 | ) public view virtual override returns (PythStructs.Price memory price) { 56 | PythStructs.PriceFeed memory priceFeed = queryPriceFeed(id); 57 | return priceFeed.price; 58 | } 59 | 60 | function getPriceNoOlderThan( 61 | bytes32 id, 62 | uint age 63 | ) public view virtual override returns (PythStructs.Price memory price) { 64 | price = getPriceUnsafe(id); 65 | 66 | if (diff(block.timestamp, price.publishTime) > age) 67 | revert PythErrors.StalePrice(); 68 | 69 | return price; 70 | } 71 | 72 | function getEmaPriceUnsafe( 73 | bytes32 id 74 | ) public view virtual override returns (PythStructs.Price memory price) { 75 | PythStructs.PriceFeed memory priceFeed = queryPriceFeed(id); 76 | return priceFeed.emaPrice; 77 | } 78 | 79 | function getEmaPriceNoOlderThan( 80 | bytes32 id, 81 | uint age 82 | ) public view virtual override returns (PythStructs.Price memory price) { 83 | price = getEmaPriceUnsafe(id); 84 | 85 | if (diff(block.timestamp, price.publishTime) > age) 86 | revert PythErrors.StalePrice(); 87 | 88 | return price; 89 | } 90 | 91 | function diff(uint x, uint y) internal pure returns (uint) { 92 | if (x > y) { 93 | return x - y; 94 | } else { 95 | return y - x; 96 | } 97 | } 98 | 99 | // Access modifier is overridden to public to be able to call it locally. 100 | function updatePriceFeeds( 101 | bytes[] calldata updateData 102 | ) public payable virtual override; 103 | 104 | function updatePriceFeedsIfNecessary( 105 | bytes[] calldata updateData, 106 | bytes32[] calldata priceIds, 107 | uint64[] calldata publishTimes 108 | ) external payable virtual override { 109 | if (priceIds.length != publishTimes.length) 110 | revert PythErrors.InvalidArgument(); 111 | 112 | for (uint i = 0; i < priceIds.length; i++) { 113 | if ( 114 | !priceFeedExists(priceIds[i]) || 115 | queryPriceFeed(priceIds[i]).price.publishTime < publishTimes[i] 116 | ) { 117 | updatePriceFeeds(updateData); 118 | return; 119 | } 120 | } 121 | 122 | revert PythErrors.NoFreshUpdate(); 123 | } 124 | 125 | function parsePriceFeedUpdates( 126 | bytes[] calldata updateData, 127 | bytes32[] calldata priceIds, 128 | uint64 minPublishTime, 129 | uint64 maxPublishTime 130 | ) 131 | external 132 | payable 133 | virtual 134 | override 135 | returns (PythStructs.PriceFeed[] memory priceFeeds); 136 | } 137 | -------------------------------------------------------------------------------- /IPyth.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | pragma solidity ^0.8.0; 3 | 4 | import "./PythStructs.sol"; 5 | import "./IPythEvents.sol"; 6 | 7 | /** 8 | * @title Consume prices from the Pyth Network (https://pyth.network/). 9 | * @author Pyth Data Association 10 | * @notice **Deprecated** – this codebase will be removed on **1 August 2025**. 11 | * 12 | * @dev Switch to the maintained package: 13 | * `npm install @pythnetwork/pyth-sdk-solidity` 14 | * 15 | * Migration guide: 16 | * https://docs.pyth.network/price-feeds/use-real-time-data/evm 17 | * 18 | * @custom:deprecated Repository scheduled for deletion on 1 August 2025. 19 | * Use `@pythnetwork/pyth-sdk-solidity` instead. 20 | */ 21 | interface IPyth is IPythEvents { 22 | /// @notice Returns the period (in seconds) that a price feed is considered valid since its publish time 23 | function getValidTimePeriod() external view returns (uint validTimePeriod); 24 | 25 | /// @notice Returns the price and confidence interval. 26 | /// @dev Reverts if the price has not been updated within the last `getValidTimePeriod()` seconds. 27 | /// @param id The Pyth Price Feed ID of which to fetch the price and confidence interval. 28 | /// @return price - please read the documentation of PythStructs.Price to understand how to use this safely. 29 | function getPrice( 30 | bytes32 id 31 | ) external view returns (PythStructs.Price memory price); 32 | 33 | /// @notice Returns the exponentially-weighted moving average price and confidence interval. 34 | /// @dev Reverts if the EMA price is not available. 35 | /// @param id The Pyth Price Feed ID of which to fetch the EMA price and confidence interval. 36 | /// @return price - please read the documentation of PythStructs.Price to understand how to use this safely. 37 | function getEmaPrice( 38 | bytes32 id 39 | ) external view returns (PythStructs.Price memory price); 40 | 41 | /// @notice Returns the price of a price feed without any sanity checks. 42 | /// @dev This function returns the most recent price update in this contract without any recency checks. 43 | /// This function is unsafe as the returned price update may be arbitrarily far in the past. 44 | /// 45 | /// Users of this function should check the `publishTime` in the price to ensure that the returned price is 46 | /// sufficiently recent for their application. If you are considering using this function, it may be 47 | /// safer / easier to use either `getPrice` or `getPriceNoOlderThan`. 48 | /// @return price - please read the documentation of PythStructs.Price to understand how to use this safely. 49 | function getPriceUnsafe( 50 | bytes32 id 51 | ) external view returns (PythStructs.Price memory price); 52 | 53 | /// @notice Returns the price that is no older than `age` seconds of the current time. 54 | /// @dev This function is a sanity-checked version of `getPriceUnsafe` which is useful in 55 | /// applications that require a sufficiently-recent price. Reverts if the price wasn't updated sufficiently 56 | /// recently. 57 | /// @return price - please read the documentation of PythStructs.Price to understand how to use this safely. 58 | function getPriceNoOlderThan( 59 | bytes32 id, 60 | uint age 61 | ) external view returns (PythStructs.Price memory price); 62 | 63 | /// @notice Returns the exponentially-weighted moving average price of a price feed without any sanity checks. 64 | /// @dev This function returns the same price as `getEmaPrice` in the case where the price is available. 65 | /// However, if the price is not recent this function returns the latest available price. 66 | /// 67 | /// The returned price can be from arbitrarily far in the past; this function makes no guarantees that 68 | /// the returned price is recent or useful for any particular application. 69 | /// 70 | /// Users of this function should check the `publishTime` in the price to ensure that the returned price is 71 | /// sufficiently recent for their application. If you are considering using this function, it may be 72 | /// safer / easier to use either `getEmaPrice` or `getEmaPriceNoOlderThan`. 73 | /// @return price - please read the documentation of PythStructs.Price to understand how to use this safely. 74 | function getEmaPriceUnsafe( 75 | bytes32 id 76 | ) external view returns (PythStructs.Price memory price); 77 | 78 | /// @notice Returns the exponentially-weighted moving average price that is no older than `age` seconds 79 | /// of the current time. 80 | /// @dev This function is a sanity-checked version of `getEmaPriceUnsafe` which is useful in 81 | /// applications that require a sufficiently-recent price. Reverts if the price wasn't updated sufficiently 82 | /// recently. 83 | /// @return price - please read the documentation of PythStructs.Price to understand how to use this safely. 84 | function getEmaPriceNoOlderThan( 85 | bytes32 id, 86 | uint age 87 | ) external view returns (PythStructs.Price memory price); 88 | 89 | /// @notice Update price feeds with given update messages. 90 | /// This method requires the caller to pay a fee in wei; the required fee can be computed by calling 91 | /// `getUpdateFee` with the length of the `updateData` array. 92 | /// Prices will be updated if they are more recent than the current stored prices. 93 | /// The call will succeed even if the update is not the most recent. 94 | /// @dev Reverts if the transferred fee is not sufficient or the updateData is invalid. 95 | /// @param updateData Array of price update data. 96 | function updatePriceFeeds(bytes[] calldata updateData) external payable; 97 | 98 | /// @notice Wrapper around updatePriceFeeds that rejects fast if a price update is not necessary. A price update is 99 | /// necessary if the current on-chain publishTime is older than the given publishTime. It relies solely on the 100 | /// given `publishTimes` for the price feeds and does not read the actual price update publish time within `updateData`. 101 | /// 102 | /// This method requires the caller to pay a fee in wei; the required fee can be computed by calling 103 | /// `getUpdateFee` with the length of the `updateData` array. 104 | /// 105 | /// `priceIds` and `publishTimes` are two arrays with the same size that correspond to senders known publishTime 106 | /// of each priceId when calling this method. If all of price feeds within `priceIds` have updated and have 107 | /// a newer or equal publish time than the given publish time, it will reject the transaction to save gas. 108 | /// Otherwise, it calls updatePriceFeeds method to update the prices. 109 | /// 110 | /// @dev Reverts if update is not needed or the transferred fee is not sufficient or the updateData is invalid. 111 | /// @param updateData Array of price update data. 112 | /// @param priceIds Array of price ids. 113 | /// @param publishTimes Array of publishTimes. `publishTimes[i]` corresponds to known `publishTime` of `priceIds[i]` 114 | function updatePriceFeedsIfNecessary( 115 | bytes[] calldata updateData, 116 | bytes32[] calldata priceIds, 117 | uint64[] calldata publishTimes 118 | ) external payable; 119 | 120 | /// @notice Returns the required fee to update an array of price updates. 121 | /// @param updateData Array of price update data. 122 | /// @return feeAmount The required fee in Wei. 123 | function getUpdateFee( 124 | bytes[] calldata updateData 125 | ) external view returns (uint feeAmount); 126 | 127 | /// @notice Parse `updateData` and return price feeds of the given `priceIds` if they are all published 128 | /// within `minPublishTime` and `maxPublishTime`. 129 | /// 130 | /// You can use this method if you want to use a Pyth price at a fixed time and not the most recent price; 131 | /// otherwise, please consider using `updatePriceFeeds`. This method does not store the price updates on-chain. 132 | /// 133 | /// This method requires the caller to pay a fee in wei; the required fee can be computed by calling 134 | /// `getUpdateFee` with the length of the `updateData` array. 135 | /// 136 | /// 137 | /// @dev Reverts if the transferred fee is not sufficient or the updateData is invalid or there is 138 | /// no update for any of the given `priceIds` within the given time range. 139 | /// @param updateData Array of price update data. 140 | /// @param priceIds Array of price ids. 141 | /// @param minPublishTime minimum acceptable publishTime for the given `priceIds`. 142 | /// @param maxPublishTime maximum acceptable publishTime for the given `priceIds`. 143 | /// @return priceFeeds Array of the price feeds corresponding to the given `priceIds` (with the same order). 144 | function parsePriceFeedUpdates( 145 | bytes[] calldata updateData, 146 | bytes32[] calldata priceIds, 147 | uint64 minPublishTime, 148 | uint64 maxPublishTime 149 | ) external payable returns (PythStructs.PriceFeed[] memory priceFeeds); 150 | } 151 | -------------------------------------------------------------------------------- /IPythEvents.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | pragma solidity ^0.8.0; 3 | 4 | /** 5 | * @title IPythEvents contains the events that Pyth contract emits. 6 | * @notice **Deprecated** – this codebase will be removed on **1 August 2025**. 7 | * 8 | * @dev Switch to the maintained package: 9 | * `npm install @pythnetwork/pyth-sdk-solidity` 10 | * 11 | * Migration guide: 12 | * https://docs.pyth.network/price-feeds/use-real-time-data/evm 13 | * 14 | * @custom:deprecated Repository scheduled for deletion on 1 August 2025. 15 | * Use `@pythnetwork/pyth-sdk-solidity` instead. 16 | */ 17 | interface IPythEvents { 18 | /// @dev Emitted when the price feed with `id` has received a fresh update. 19 | /// @param id The Pyth Price Feed ID. 20 | /// @param publishTime Publish time of the given price update. 21 | /// @param price Price of the given price update. 22 | /// @param conf Confidence interval of the given price update. 23 | event PriceFeedUpdate( 24 | bytes32 indexed id, 25 | uint64 publishTime, 26 | int64 price, 27 | uint64 conf 28 | ); 29 | 30 | /// @dev Emitted when a batch price update is processed successfully. 31 | /// @param chainId ID of the source chain that the batch price update comes from. 32 | /// @param sequenceNumber Sequence number of the batch price update. 33 | event BatchPriceFeedUpdate(uint16 chainId, uint64 sequenceNumber); 34 | } 35 | -------------------------------------------------------------------------------- /MockPyth.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | pragma solidity ^0.8.0; 3 | 4 | import "./AbstractPyth.sol"; 5 | import "./PythStructs.sol"; 6 | import "./PythErrors.sol"; 7 | 8 | /** 9 | * @notice **Deprecated** – this codebase will be removed on **1 August 2025**. 10 | * 11 | * @dev Switch to the maintained package: 12 | * `npm install @pythnetwork/pyth-sdk-solidity` 13 | * 14 | * Migration guide: 15 | * https://docs.pyth.network/price-feeds/use-real-time-data/evm 16 | * 17 | * @custom:deprecated Repository scheduled for deletion on 1 August 2025. 18 | * Use `@pythnetwork/pyth-sdk-solidity` instead. 19 | */ 20 | contract MockPyth is AbstractPyth { 21 | mapping(bytes32 => PythStructs.PriceFeed) priceFeeds; 22 | uint64 sequenceNumber; 23 | 24 | uint singleUpdateFeeInWei; 25 | uint validTimePeriod; 26 | 27 | constructor(uint _validTimePeriod, uint _singleUpdateFeeInWei) { 28 | singleUpdateFeeInWei = _singleUpdateFeeInWei; 29 | validTimePeriod = _validTimePeriod; 30 | } 31 | 32 | function queryPriceFeed( 33 | bytes32 id 34 | ) public view override returns (PythStructs.PriceFeed memory priceFeed) { 35 | if (priceFeeds[id].id == 0) revert PythErrors.PriceFeedNotFound(); 36 | return priceFeeds[id]; 37 | } 38 | 39 | function priceFeedExists(bytes32 id) public view override returns (bool) { 40 | return (priceFeeds[id].id != 0); 41 | } 42 | 43 | function getValidTimePeriod() public view override returns (uint) { 44 | return validTimePeriod; 45 | } 46 | 47 | // Takes an array of encoded price feeds and stores them. 48 | // You can create this data either by calling createPriceFeedData or 49 | // by using web3.js or ethers abi utilities. 50 | function updatePriceFeeds( 51 | bytes[] calldata updateData 52 | ) public payable override { 53 | uint requiredFee = getUpdateFee(updateData); 54 | if (msg.value < requiredFee) revert PythErrors.InsufficientFee(); 55 | 56 | // Chain ID is id of the source chain that the price update comes from. Since it is just a mock contract 57 | // We set it to 1. 58 | uint16 chainId = 1; 59 | 60 | for (uint i = 0; i < updateData.length; i++) { 61 | PythStructs.PriceFeed memory priceFeed = abi.decode( 62 | updateData[i], 63 | (PythStructs.PriceFeed) 64 | ); 65 | 66 | uint lastPublishTime = priceFeeds[priceFeed.id].price.publishTime; 67 | 68 | if (lastPublishTime < priceFeed.price.publishTime) { 69 | // Price information is more recent than the existing price information. 70 | priceFeeds[priceFeed.id] = priceFeed; 71 | emit PriceFeedUpdate( 72 | priceFeed.id, 73 | uint64(lastPublishTime), 74 | priceFeed.price.price, 75 | priceFeed.price.conf 76 | ); 77 | } 78 | } 79 | 80 | // In the real contract, the input of this function contains multiple batches that each contain multiple prices. 81 | // This event is emitted when a batch is processed. In this mock contract we consider there is only one batch of prices. 82 | // Each batch has (chainId, sequenceNumber) as it's unique identifier. Here chainId is set to 1 and an increasing sequence number is used. 83 | emit BatchPriceFeedUpdate(chainId, sequenceNumber); 84 | sequenceNumber += 1; 85 | } 86 | 87 | function getUpdateFee( 88 | bytes[] calldata updateData 89 | ) public view override returns (uint feeAmount) { 90 | return singleUpdateFeeInWei * updateData.length; 91 | } 92 | 93 | function parsePriceFeedUpdates( 94 | bytes[] calldata updateData, 95 | bytes32[] calldata priceIds, 96 | uint64 minPublishTime, 97 | uint64 maxPublishTime 98 | ) external payable override returns (PythStructs.PriceFeed[] memory feeds) { 99 | uint requiredFee = getUpdateFee(updateData); 100 | if (msg.value < requiredFee) revert PythErrors.InsufficientFee(); 101 | 102 | feeds = new PythStructs.PriceFeed[](priceIds.length); 103 | 104 | for (uint i = 0; i < priceIds.length; i++) { 105 | for (uint j = 0; j < updateData.length; j++) { 106 | feeds[i] = abi.decode(updateData[j], (PythStructs.PriceFeed)); 107 | 108 | if (feeds[i].id == priceIds[i]) { 109 | uint publishTime = feeds[i].price.publishTime; 110 | if ( 111 | minPublishTime <= publishTime && 112 | publishTime <= maxPublishTime 113 | ) { 114 | break; 115 | } else { 116 | feeds[i].id = 0; 117 | } 118 | } 119 | } 120 | 121 | if (feeds[i].id != priceIds[i]) 122 | revert PythErrors.PriceFeedNotFoundWithinRange(); 123 | } 124 | } 125 | 126 | function createPriceFeedUpdateData( 127 | bytes32 id, 128 | int64 price, 129 | uint64 conf, 130 | int32 expo, 131 | int64 emaPrice, 132 | uint64 emaConf, 133 | uint64 publishTime 134 | ) public pure returns (bytes memory priceFeedData) { 135 | PythStructs.PriceFeed memory priceFeed; 136 | 137 | priceFeed.id = id; 138 | 139 | priceFeed.price.price = price; 140 | priceFeed.price.conf = conf; 141 | priceFeed.price.expo = expo; 142 | priceFeed.price.publishTime = publishTime; 143 | 144 | priceFeed.emaPrice.price = emaPrice; 145 | priceFeed.emaPrice.conf = emaConf; 146 | priceFeed.emaPrice.expo = expo; 147 | priceFeed.emaPrice.publishTime = publishTime; 148 | 149 | priceFeedData = abi.encode(priceFeed); 150 | } 151 | } 152 | -------------------------------------------------------------------------------- /PythErrors.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache 2 2 | 3 | pragma solidity ^0.8.0; 4 | 5 | /** 6 | * @notice **Deprecated** – this codebase will be removed on **1 August 2025**. 7 | * 8 | * @dev Switch to the maintained package: 9 | * `npm install @pythnetwork/pyth-sdk-solidity` 10 | * 11 | * Migration guide: 12 | * https://docs.pyth.network/price-feeds/use-real-time-data/evm 13 | * 14 | * @custom:deprecated Repository scheduled for deletion on 1 August 2025. 15 | * Use `@pythnetwork/pyth-sdk-solidity` instead. 16 | */ 17 | library PythErrors { 18 | // Function arguments are invalid (e.g., the arguments lengths mismatch) 19 | error InvalidArgument(); 20 | // Update data is coming from an invalid data source. 21 | error InvalidUpdateDataSource(); 22 | // Update data is invalid (e.g., deserialization error) 23 | error InvalidUpdateData(); 24 | // Insufficient fee is paid to the method. 25 | error InsufficientFee(); 26 | // There is no fresh update, whereas expected fresh updates. 27 | error NoFreshUpdate(); 28 | // There is no price feed found within the given range or it does not exists. 29 | error PriceFeedNotFoundWithinRange(); 30 | // Price feed not found or it is not pushed on-chain yet. 31 | error PriceFeedNotFound(); 32 | // Requested price is stale. 33 | error StalePrice(); 34 | // Given message is not a valid Wormhole VAA. 35 | error InvalidWormholeVaa(); 36 | // Governance message is invalid (e.g., deserialization error). 37 | error InvalidGovernanceMessage(); 38 | // Governance message is not for this contract. 39 | error InvalidGovernanceTarget(); 40 | // Governance message is coming from an invalid data source. 41 | error InvalidGovernanceDataSource(); 42 | // Governance message is old. 43 | error OldGovernanceMessage(); 44 | } 45 | -------------------------------------------------------------------------------- /PythStructs.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | pragma solidity ^0.8.0; 3 | 4 | /** 5 | * @notice **Deprecated** – this codebase will be removed on **1 August 2025**. 6 | * 7 | * @dev Switch to the maintained package: 8 | * `npm install @pythnetwork/pyth-sdk-solidity` 9 | * 10 | * Migration guide: 11 | * https://docs.pyth.network/price-feeds/use-real-time-data/evm 12 | * 13 | * @custom:deprecated Repository scheduled for deletion on 1 August 2025. 14 | * Use `@pythnetwork/pyth-sdk-solidity` instead. 15 | */ 16 | contract PythStructs { 17 | // A price with a degree of uncertainty, represented as a price +- a confidence interval. 18 | // 19 | // The confidence interval roughly corresponds to the standard error of a normal distribution. 20 | // Both the price and confidence are stored in a fixed-point numeric representation, 21 | // `x * (10^expo)`, where `expo` is the exponent. 22 | // 23 | // Please refer to the documentation at https://docs.pyth.network/consumers/best-practices for how 24 | // to how this price safely. 25 | struct Price { 26 | // Price 27 | int64 price; 28 | // Confidence interval around the price 29 | uint64 conf; 30 | // Price exponent 31 | int32 expo; 32 | // Unix timestamp describing when the price was published 33 | uint publishTime; 34 | } 35 | 36 | // PriceFeed represents a current aggregate price from pyth publisher feeds. 37 | struct PriceFeed { 38 | // The price ID. 39 | bytes32 id; 40 | // Latest available price 41 | Price price; 42 | // Latest available exponentially-weighted moving average price 43 | Price emaPrice; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | > [!CAUTION] 2 | > **This is an outdated and unsupported version of the SDK** 3 | > This GitHub repository will be removed on August 1st, 2025. To continue using the Pyth Solidity SDK, you must migrate to the [@pythnetwork/pyth-sdk-solidity package on NPM](https://www.npmjs.com/package/@pythnetwork/pyth-sdk-solidity). 4 | > For more information, see [How to Use Real-Time Data in EVM Contracts](https://docs.pyth.network/price-feeds/use-real-time-data/evm). The SDK source has moved to the [Crosschain Pyth programs and utilities repository](https://github.com/pyth-network/pyth-crosschain). 5 | 6 | --- 7 | 8 | # Pyth Solidity SDK 9 | 10 | This package provides utilities for consuming prices from the [Pyth Network](https://pyth.network/) Oracle using Solidity. Also, it contains [the Pyth Interface ABI](./abis/IPyth.json) that you can use in your libraries 11 | to communicate with the Pyth contract. 12 | 13 | It is **strongly recommended** to follow the [consumer best practices](https://docs.pyth.network/consumers/best-practices) when consuming Pyth data. 14 | 15 | ## Installation 16 | 17 | ```bash 18 | npm install @pythnetwork/pyth-sdk-solidity 19 | ``` 20 | 21 | ## Example Usage 22 | 23 | To consume prices you should use the [`IPyth`](IPyth.sol) interface. Please make sure to read the documentation of this interface in order to use the prices safely. 24 | 25 | For example, to read the latest price, call [`getPrice`](IPyth.sol) with the Price ID of the price feed you're interested in. The price feeds available on each chain are listed [below](#target-chains). 26 | 27 | ```solidity 28 | // SPDX-License-Identifier: MIT 29 | pragma solidity ^0.8.0; 30 | 31 | import "@pythnetwork/pyth-sdk-solidity/IPyth.sol"; 32 | import "@pythnetwork/pyth-sdk-solidity/PythStructs.sol"; 33 | 34 | contract ExampleContract { 35 | IPyth pyth; 36 | 37 | constructor(address pythContract) { 38 | pyth = IPyth(pythContract); 39 | } 40 | 41 | function getBtcUsdPrice( 42 | bytes[] calldata priceUpdateData 43 | ) public payable returns (PythStructs.Price memory) { 44 | // Update the prices to the latest available values and pay the required fee for it. The `priceUpdateData` data 45 | // should be retrieved from our off-chain Price Service API using the `pyth-evm-js` package. 46 | // See section "How Pyth Works on EVM Chains" below for more information. 47 | uint fee = pyth.getUpdateFee(priceUpdateData); 48 | pyth.updatePriceFeeds{ value: fee }(priceUpdateData); 49 | 50 | bytes32 priceID = 0xf9c0172ba10dfa4d19088d94f5bf61d3b54d5bd7483a322a982e1373ee8ea31b; 51 | // Read the current value of priceID, aborting the transaction if the price has not been updated recently. 52 | // Every chain has a default recency threshold which can be retrieved by calling the getValidTimePeriod() function on the contract. 53 | // Please see IPyth.sol for variants of this function that support configurable recency thresholds and other useful features. 54 | return pyth.getPrice(priceID); 55 | } 56 | } 57 | 58 | ``` 59 | 60 | ## How Pyth Works on EVM Chains 61 | 62 | Pyth prices are published on Pythnet, and relayed to EVM chains using the [Wormhole Network](https://wormholenetwork.com/) as a cross-chain message passing bridge. The Wormhole Network observes when Pyth prices on Pythnet have changed and publishes an off-chain signed message attesting to this fact. This is explained in more detail [here](https://docs.wormholenetwork.com/wormhole/). 63 | 64 | This signed message can then be submitted to the Pyth contract on the EVM networks along the required update fee for it, which will verify the Wormhole message and update the Pyth contract with the new price. 65 | 66 | Please refer to [Pyth On-Demand Updates page](https://docs.pyth.network/consume-data/on-demand) for more information. 67 | 68 | ## Solidity Target Chains 69 | 70 | [This](https://docs.pyth.network/consume-data/evm#networks) document contains list of the EVM networks that Pyth is available on. 71 | 72 | You can find a list of available price feeds [here](https://pyth.network/developers/price-feed-ids/). 73 | 74 | ## Mocking Pyth 75 | 76 | [MockPyth](./MockPyth.sol) is a mock contract that you can use and deploy locally to mock Pyth contract behaviour. To set and update price feeds you should call `updatePriceFeeds` and provide an array of encoded price feeds (the struct defined in [PythStructs](./PythStructs.sol)) as its argument. You can create encoded price feeds either by using web3.js or ethers ABI utilities or calling `createPriceFeedUpdateData` function in the mock contract. 77 | 78 | ## Development 79 | 80 | ### ABIs 81 | 82 | When making changes to a contract interface, please make sure to update the ABI files too. You can update it using `npm run generate-abi` and it will update the ABI files in [abis](./abis) directory. If you create a new contract, you also need to add the contract name in [the ABI generation script](./scripts/generateAbi.js#L5) so the script can create the ABI file for the new contract as well. 83 | 84 | ### Releases 85 | 86 | We use [Semantic Versioning](https://semver.org/) for our releases. In order to release a new version of this package and publish it to npm, follow these steps: 87 | 88 | 1. Run `npm version --no-git-tag-version`. This command will update the version of the package. Then push your changes to github. 89 | 2. Once your change is merged into `main`, create a release with tag `v` like `v1.5.2`, and a github action will automatically publish the new version of this package to npm. 90 | 91 | ### pre-commit hooks 92 | 93 | pre-commit is a tool that checks and fixes simple issues (formatting, ...) before each commit. You can install it by following [their website](https://pre-commit.com/). In order to enable checks for this repo run `pre-commit install` from command-line in the root of this repo. 94 | 95 | The checks are also performed in the CI to ensure the code follows consistent formatting. 96 | -------------------------------------------------------------------------------- /abis/AbstractPyth.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "inputs": [], 4 | "name": "InvalidArgument", 5 | "type": "error" 6 | }, 7 | { 8 | "inputs": [], 9 | "name": "NoFreshUpdate", 10 | "type": "error" 11 | }, 12 | { 13 | "inputs": [], 14 | "name": "StalePrice", 15 | "type": "error" 16 | }, 17 | { 18 | "anonymous": false, 19 | "inputs": [ 20 | { 21 | "indexed": false, 22 | "internalType": "uint16", 23 | "name": "chainId", 24 | "type": "uint16" 25 | }, 26 | { 27 | "indexed": false, 28 | "internalType": "uint64", 29 | "name": "sequenceNumber", 30 | "type": "uint64" 31 | } 32 | ], 33 | "name": "BatchPriceFeedUpdate", 34 | "type": "event" 35 | }, 36 | { 37 | "anonymous": false, 38 | "inputs": [ 39 | { 40 | "indexed": true, 41 | "internalType": "bytes32", 42 | "name": "id", 43 | "type": "bytes32" 44 | }, 45 | { 46 | "indexed": false, 47 | "internalType": "uint64", 48 | "name": "publishTime", 49 | "type": "uint64" 50 | }, 51 | { 52 | "indexed": false, 53 | "internalType": "int64", 54 | "name": "price", 55 | "type": "int64" 56 | }, 57 | { 58 | "indexed": false, 59 | "internalType": "uint64", 60 | "name": "conf", 61 | "type": "uint64" 62 | } 63 | ], 64 | "name": "PriceFeedUpdate", 65 | "type": "event" 66 | }, 67 | { 68 | "inputs": [ 69 | { 70 | "internalType": "bytes32", 71 | "name": "id", 72 | "type": "bytes32" 73 | } 74 | ], 75 | "name": "getEmaPrice", 76 | "outputs": [ 77 | { 78 | "components": [ 79 | { 80 | "internalType": "int64", 81 | "name": "price", 82 | "type": "int64" 83 | }, 84 | { 85 | "internalType": "uint64", 86 | "name": "conf", 87 | "type": "uint64" 88 | }, 89 | { 90 | "internalType": "int32", 91 | "name": "expo", 92 | "type": "int32" 93 | }, 94 | { 95 | "internalType": "uint256", 96 | "name": "publishTime", 97 | "type": "uint256" 98 | } 99 | ], 100 | "internalType": "struct PythStructs.Price", 101 | "name": "price", 102 | "type": "tuple" 103 | } 104 | ], 105 | "stateMutability": "view", 106 | "type": "function" 107 | }, 108 | { 109 | "inputs": [ 110 | { 111 | "internalType": "bytes32", 112 | "name": "id", 113 | "type": "bytes32" 114 | }, 115 | { 116 | "internalType": "uint256", 117 | "name": "age", 118 | "type": "uint256" 119 | } 120 | ], 121 | "name": "getEmaPriceNoOlderThan", 122 | "outputs": [ 123 | { 124 | "components": [ 125 | { 126 | "internalType": "int64", 127 | "name": "price", 128 | "type": "int64" 129 | }, 130 | { 131 | "internalType": "uint64", 132 | "name": "conf", 133 | "type": "uint64" 134 | }, 135 | { 136 | "internalType": "int32", 137 | "name": "expo", 138 | "type": "int32" 139 | }, 140 | { 141 | "internalType": "uint256", 142 | "name": "publishTime", 143 | "type": "uint256" 144 | } 145 | ], 146 | "internalType": "struct PythStructs.Price", 147 | "name": "price", 148 | "type": "tuple" 149 | } 150 | ], 151 | "stateMutability": "view", 152 | "type": "function" 153 | }, 154 | { 155 | "inputs": [ 156 | { 157 | "internalType": "bytes32", 158 | "name": "id", 159 | "type": "bytes32" 160 | } 161 | ], 162 | "name": "getEmaPriceUnsafe", 163 | "outputs": [ 164 | { 165 | "components": [ 166 | { 167 | "internalType": "int64", 168 | "name": "price", 169 | "type": "int64" 170 | }, 171 | { 172 | "internalType": "uint64", 173 | "name": "conf", 174 | "type": "uint64" 175 | }, 176 | { 177 | "internalType": "int32", 178 | "name": "expo", 179 | "type": "int32" 180 | }, 181 | { 182 | "internalType": "uint256", 183 | "name": "publishTime", 184 | "type": "uint256" 185 | } 186 | ], 187 | "internalType": "struct PythStructs.Price", 188 | "name": "price", 189 | "type": "tuple" 190 | } 191 | ], 192 | "stateMutability": "view", 193 | "type": "function" 194 | }, 195 | { 196 | "inputs": [ 197 | { 198 | "internalType": "bytes32", 199 | "name": "id", 200 | "type": "bytes32" 201 | } 202 | ], 203 | "name": "getPrice", 204 | "outputs": [ 205 | { 206 | "components": [ 207 | { 208 | "internalType": "int64", 209 | "name": "price", 210 | "type": "int64" 211 | }, 212 | { 213 | "internalType": "uint64", 214 | "name": "conf", 215 | "type": "uint64" 216 | }, 217 | { 218 | "internalType": "int32", 219 | "name": "expo", 220 | "type": "int32" 221 | }, 222 | { 223 | "internalType": "uint256", 224 | "name": "publishTime", 225 | "type": "uint256" 226 | } 227 | ], 228 | "internalType": "struct PythStructs.Price", 229 | "name": "price", 230 | "type": "tuple" 231 | } 232 | ], 233 | "stateMutability": "view", 234 | "type": "function" 235 | }, 236 | { 237 | "inputs": [ 238 | { 239 | "internalType": "bytes32", 240 | "name": "id", 241 | "type": "bytes32" 242 | }, 243 | { 244 | "internalType": "uint256", 245 | "name": "age", 246 | "type": "uint256" 247 | } 248 | ], 249 | "name": "getPriceNoOlderThan", 250 | "outputs": [ 251 | { 252 | "components": [ 253 | { 254 | "internalType": "int64", 255 | "name": "price", 256 | "type": "int64" 257 | }, 258 | { 259 | "internalType": "uint64", 260 | "name": "conf", 261 | "type": "uint64" 262 | }, 263 | { 264 | "internalType": "int32", 265 | "name": "expo", 266 | "type": "int32" 267 | }, 268 | { 269 | "internalType": "uint256", 270 | "name": "publishTime", 271 | "type": "uint256" 272 | } 273 | ], 274 | "internalType": "struct PythStructs.Price", 275 | "name": "price", 276 | "type": "tuple" 277 | } 278 | ], 279 | "stateMutability": "view", 280 | "type": "function" 281 | }, 282 | { 283 | "inputs": [ 284 | { 285 | "internalType": "bytes32", 286 | "name": "id", 287 | "type": "bytes32" 288 | } 289 | ], 290 | "name": "getPriceUnsafe", 291 | "outputs": [ 292 | { 293 | "components": [ 294 | { 295 | "internalType": "int64", 296 | "name": "price", 297 | "type": "int64" 298 | }, 299 | { 300 | "internalType": "uint64", 301 | "name": "conf", 302 | "type": "uint64" 303 | }, 304 | { 305 | "internalType": "int32", 306 | "name": "expo", 307 | "type": "int32" 308 | }, 309 | { 310 | "internalType": "uint256", 311 | "name": "publishTime", 312 | "type": "uint256" 313 | } 314 | ], 315 | "internalType": "struct PythStructs.Price", 316 | "name": "price", 317 | "type": "tuple" 318 | } 319 | ], 320 | "stateMutability": "view", 321 | "type": "function" 322 | }, 323 | { 324 | "inputs": [ 325 | { 326 | "internalType": "bytes[]", 327 | "name": "updateData", 328 | "type": "bytes[]" 329 | } 330 | ], 331 | "name": "getUpdateFee", 332 | "outputs": [ 333 | { 334 | "internalType": "uint256", 335 | "name": "feeAmount", 336 | "type": "uint256" 337 | } 338 | ], 339 | "stateMutability": "view", 340 | "type": "function" 341 | }, 342 | { 343 | "inputs": [], 344 | "name": "getValidTimePeriod", 345 | "outputs": [ 346 | { 347 | "internalType": "uint256", 348 | "name": "validTimePeriod", 349 | "type": "uint256" 350 | } 351 | ], 352 | "stateMutability": "view", 353 | "type": "function" 354 | }, 355 | { 356 | "inputs": [ 357 | { 358 | "internalType": "bytes[]", 359 | "name": "updateData", 360 | "type": "bytes[]" 361 | }, 362 | { 363 | "internalType": "bytes32[]", 364 | "name": "priceIds", 365 | "type": "bytes32[]" 366 | }, 367 | { 368 | "internalType": "uint64", 369 | "name": "minPublishTime", 370 | "type": "uint64" 371 | }, 372 | { 373 | "internalType": "uint64", 374 | "name": "maxPublishTime", 375 | "type": "uint64" 376 | } 377 | ], 378 | "name": "parsePriceFeedUpdates", 379 | "outputs": [ 380 | { 381 | "components": [ 382 | { 383 | "internalType": "bytes32", 384 | "name": "id", 385 | "type": "bytes32" 386 | }, 387 | { 388 | "components": [ 389 | { 390 | "internalType": "int64", 391 | "name": "price", 392 | "type": "int64" 393 | }, 394 | { 395 | "internalType": "uint64", 396 | "name": "conf", 397 | "type": "uint64" 398 | }, 399 | { 400 | "internalType": "int32", 401 | "name": "expo", 402 | "type": "int32" 403 | }, 404 | { 405 | "internalType": "uint256", 406 | "name": "publishTime", 407 | "type": "uint256" 408 | } 409 | ], 410 | "internalType": "struct PythStructs.Price", 411 | "name": "price", 412 | "type": "tuple" 413 | }, 414 | { 415 | "components": [ 416 | { 417 | "internalType": "int64", 418 | "name": "price", 419 | "type": "int64" 420 | }, 421 | { 422 | "internalType": "uint64", 423 | "name": "conf", 424 | "type": "uint64" 425 | }, 426 | { 427 | "internalType": "int32", 428 | "name": "expo", 429 | "type": "int32" 430 | }, 431 | { 432 | "internalType": "uint256", 433 | "name": "publishTime", 434 | "type": "uint256" 435 | } 436 | ], 437 | "internalType": "struct PythStructs.Price", 438 | "name": "emaPrice", 439 | "type": "tuple" 440 | } 441 | ], 442 | "internalType": "struct PythStructs.PriceFeed[]", 443 | "name": "priceFeeds", 444 | "type": "tuple[]" 445 | } 446 | ], 447 | "stateMutability": "payable", 448 | "type": "function" 449 | }, 450 | { 451 | "inputs": [ 452 | { 453 | "internalType": "bytes32", 454 | "name": "id", 455 | "type": "bytes32" 456 | } 457 | ], 458 | "name": "priceFeedExists", 459 | "outputs": [ 460 | { 461 | "internalType": "bool", 462 | "name": "exists", 463 | "type": "bool" 464 | } 465 | ], 466 | "stateMutability": "view", 467 | "type": "function" 468 | }, 469 | { 470 | "inputs": [ 471 | { 472 | "internalType": "bytes32", 473 | "name": "id", 474 | "type": "bytes32" 475 | } 476 | ], 477 | "name": "queryPriceFeed", 478 | "outputs": [ 479 | { 480 | "components": [ 481 | { 482 | "internalType": "bytes32", 483 | "name": "id", 484 | "type": "bytes32" 485 | }, 486 | { 487 | "components": [ 488 | { 489 | "internalType": "int64", 490 | "name": "price", 491 | "type": "int64" 492 | }, 493 | { 494 | "internalType": "uint64", 495 | "name": "conf", 496 | "type": "uint64" 497 | }, 498 | { 499 | "internalType": "int32", 500 | "name": "expo", 501 | "type": "int32" 502 | }, 503 | { 504 | "internalType": "uint256", 505 | "name": "publishTime", 506 | "type": "uint256" 507 | } 508 | ], 509 | "internalType": "struct PythStructs.Price", 510 | "name": "price", 511 | "type": "tuple" 512 | }, 513 | { 514 | "components": [ 515 | { 516 | "internalType": "int64", 517 | "name": "price", 518 | "type": "int64" 519 | }, 520 | { 521 | "internalType": "uint64", 522 | "name": "conf", 523 | "type": "uint64" 524 | }, 525 | { 526 | "internalType": "int32", 527 | "name": "expo", 528 | "type": "int32" 529 | }, 530 | { 531 | "internalType": "uint256", 532 | "name": "publishTime", 533 | "type": "uint256" 534 | } 535 | ], 536 | "internalType": "struct PythStructs.Price", 537 | "name": "emaPrice", 538 | "type": "tuple" 539 | } 540 | ], 541 | "internalType": "struct PythStructs.PriceFeed", 542 | "name": "priceFeed", 543 | "type": "tuple" 544 | } 545 | ], 546 | "stateMutability": "view", 547 | "type": "function" 548 | }, 549 | { 550 | "inputs": [ 551 | { 552 | "internalType": "bytes[]", 553 | "name": "updateData", 554 | "type": "bytes[]" 555 | } 556 | ], 557 | "name": "updatePriceFeeds", 558 | "outputs": [], 559 | "stateMutability": "payable", 560 | "type": "function" 561 | }, 562 | { 563 | "inputs": [ 564 | { 565 | "internalType": "bytes[]", 566 | "name": "updateData", 567 | "type": "bytes[]" 568 | }, 569 | { 570 | "internalType": "bytes32[]", 571 | "name": "priceIds", 572 | "type": "bytes32[]" 573 | }, 574 | { 575 | "internalType": "uint64[]", 576 | "name": "publishTimes", 577 | "type": "uint64[]" 578 | } 579 | ], 580 | "name": "updatePriceFeedsIfNecessary", 581 | "outputs": [], 582 | "stateMutability": "payable", 583 | "type": "function" 584 | } 585 | ] 586 | -------------------------------------------------------------------------------- /abis/IPyth.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "anonymous": false, 4 | "inputs": [ 5 | { 6 | "indexed": false, 7 | "internalType": "uint16", 8 | "name": "chainId", 9 | "type": "uint16" 10 | }, 11 | { 12 | "indexed": false, 13 | "internalType": "uint64", 14 | "name": "sequenceNumber", 15 | "type": "uint64" 16 | } 17 | ], 18 | "name": "BatchPriceFeedUpdate", 19 | "type": "event" 20 | }, 21 | { 22 | "anonymous": false, 23 | "inputs": [ 24 | { 25 | "indexed": true, 26 | "internalType": "bytes32", 27 | "name": "id", 28 | "type": "bytes32" 29 | }, 30 | { 31 | "indexed": false, 32 | "internalType": "uint64", 33 | "name": "publishTime", 34 | "type": "uint64" 35 | }, 36 | { 37 | "indexed": false, 38 | "internalType": "int64", 39 | "name": "price", 40 | "type": "int64" 41 | }, 42 | { 43 | "indexed": false, 44 | "internalType": "uint64", 45 | "name": "conf", 46 | "type": "uint64" 47 | } 48 | ], 49 | "name": "PriceFeedUpdate", 50 | "type": "event" 51 | }, 52 | { 53 | "inputs": [ 54 | { 55 | "internalType": "bytes32", 56 | "name": "id", 57 | "type": "bytes32" 58 | } 59 | ], 60 | "name": "getEmaPrice", 61 | "outputs": [ 62 | { 63 | "components": [ 64 | { 65 | "internalType": "int64", 66 | "name": "price", 67 | "type": "int64" 68 | }, 69 | { 70 | "internalType": "uint64", 71 | "name": "conf", 72 | "type": "uint64" 73 | }, 74 | { 75 | "internalType": "int32", 76 | "name": "expo", 77 | "type": "int32" 78 | }, 79 | { 80 | "internalType": "uint256", 81 | "name": "publishTime", 82 | "type": "uint256" 83 | } 84 | ], 85 | "internalType": "struct PythStructs.Price", 86 | "name": "price", 87 | "type": "tuple" 88 | } 89 | ], 90 | "stateMutability": "view", 91 | "type": "function" 92 | }, 93 | { 94 | "inputs": [ 95 | { 96 | "internalType": "bytes32", 97 | "name": "id", 98 | "type": "bytes32" 99 | }, 100 | { 101 | "internalType": "uint256", 102 | "name": "age", 103 | "type": "uint256" 104 | } 105 | ], 106 | "name": "getEmaPriceNoOlderThan", 107 | "outputs": [ 108 | { 109 | "components": [ 110 | { 111 | "internalType": "int64", 112 | "name": "price", 113 | "type": "int64" 114 | }, 115 | { 116 | "internalType": "uint64", 117 | "name": "conf", 118 | "type": "uint64" 119 | }, 120 | { 121 | "internalType": "int32", 122 | "name": "expo", 123 | "type": "int32" 124 | }, 125 | { 126 | "internalType": "uint256", 127 | "name": "publishTime", 128 | "type": "uint256" 129 | } 130 | ], 131 | "internalType": "struct PythStructs.Price", 132 | "name": "price", 133 | "type": "tuple" 134 | } 135 | ], 136 | "stateMutability": "view", 137 | "type": "function" 138 | }, 139 | { 140 | "inputs": [ 141 | { 142 | "internalType": "bytes32", 143 | "name": "id", 144 | "type": "bytes32" 145 | } 146 | ], 147 | "name": "getEmaPriceUnsafe", 148 | "outputs": [ 149 | { 150 | "components": [ 151 | { 152 | "internalType": "int64", 153 | "name": "price", 154 | "type": "int64" 155 | }, 156 | { 157 | "internalType": "uint64", 158 | "name": "conf", 159 | "type": "uint64" 160 | }, 161 | { 162 | "internalType": "int32", 163 | "name": "expo", 164 | "type": "int32" 165 | }, 166 | { 167 | "internalType": "uint256", 168 | "name": "publishTime", 169 | "type": "uint256" 170 | } 171 | ], 172 | "internalType": "struct PythStructs.Price", 173 | "name": "price", 174 | "type": "tuple" 175 | } 176 | ], 177 | "stateMutability": "view", 178 | "type": "function" 179 | }, 180 | { 181 | "inputs": [ 182 | { 183 | "internalType": "bytes32", 184 | "name": "id", 185 | "type": "bytes32" 186 | } 187 | ], 188 | "name": "getPrice", 189 | "outputs": [ 190 | { 191 | "components": [ 192 | { 193 | "internalType": "int64", 194 | "name": "price", 195 | "type": "int64" 196 | }, 197 | { 198 | "internalType": "uint64", 199 | "name": "conf", 200 | "type": "uint64" 201 | }, 202 | { 203 | "internalType": "int32", 204 | "name": "expo", 205 | "type": "int32" 206 | }, 207 | { 208 | "internalType": "uint256", 209 | "name": "publishTime", 210 | "type": "uint256" 211 | } 212 | ], 213 | "internalType": "struct PythStructs.Price", 214 | "name": "price", 215 | "type": "tuple" 216 | } 217 | ], 218 | "stateMutability": "view", 219 | "type": "function" 220 | }, 221 | { 222 | "inputs": [ 223 | { 224 | "internalType": "bytes32", 225 | "name": "id", 226 | "type": "bytes32" 227 | }, 228 | { 229 | "internalType": "uint256", 230 | "name": "age", 231 | "type": "uint256" 232 | } 233 | ], 234 | "name": "getPriceNoOlderThan", 235 | "outputs": [ 236 | { 237 | "components": [ 238 | { 239 | "internalType": "int64", 240 | "name": "price", 241 | "type": "int64" 242 | }, 243 | { 244 | "internalType": "uint64", 245 | "name": "conf", 246 | "type": "uint64" 247 | }, 248 | { 249 | "internalType": "int32", 250 | "name": "expo", 251 | "type": "int32" 252 | }, 253 | { 254 | "internalType": "uint256", 255 | "name": "publishTime", 256 | "type": "uint256" 257 | } 258 | ], 259 | "internalType": "struct PythStructs.Price", 260 | "name": "price", 261 | "type": "tuple" 262 | } 263 | ], 264 | "stateMutability": "view", 265 | "type": "function" 266 | }, 267 | { 268 | "inputs": [ 269 | { 270 | "internalType": "bytes32", 271 | "name": "id", 272 | "type": "bytes32" 273 | } 274 | ], 275 | "name": "getPriceUnsafe", 276 | "outputs": [ 277 | { 278 | "components": [ 279 | { 280 | "internalType": "int64", 281 | "name": "price", 282 | "type": "int64" 283 | }, 284 | { 285 | "internalType": "uint64", 286 | "name": "conf", 287 | "type": "uint64" 288 | }, 289 | { 290 | "internalType": "int32", 291 | "name": "expo", 292 | "type": "int32" 293 | }, 294 | { 295 | "internalType": "uint256", 296 | "name": "publishTime", 297 | "type": "uint256" 298 | } 299 | ], 300 | "internalType": "struct PythStructs.Price", 301 | "name": "price", 302 | "type": "tuple" 303 | } 304 | ], 305 | "stateMutability": "view", 306 | "type": "function" 307 | }, 308 | { 309 | "inputs": [ 310 | { 311 | "internalType": "bytes[]", 312 | "name": "updateData", 313 | "type": "bytes[]" 314 | } 315 | ], 316 | "name": "getUpdateFee", 317 | "outputs": [ 318 | { 319 | "internalType": "uint256", 320 | "name": "feeAmount", 321 | "type": "uint256" 322 | } 323 | ], 324 | "stateMutability": "view", 325 | "type": "function" 326 | }, 327 | { 328 | "inputs": [], 329 | "name": "getValidTimePeriod", 330 | "outputs": [ 331 | { 332 | "internalType": "uint256", 333 | "name": "validTimePeriod", 334 | "type": "uint256" 335 | } 336 | ], 337 | "stateMutability": "view", 338 | "type": "function" 339 | }, 340 | { 341 | "inputs": [ 342 | { 343 | "internalType": "bytes[]", 344 | "name": "updateData", 345 | "type": "bytes[]" 346 | }, 347 | { 348 | "internalType": "bytes32[]", 349 | "name": "priceIds", 350 | "type": "bytes32[]" 351 | }, 352 | { 353 | "internalType": "uint64", 354 | "name": "minPublishTime", 355 | "type": "uint64" 356 | }, 357 | { 358 | "internalType": "uint64", 359 | "name": "maxPublishTime", 360 | "type": "uint64" 361 | } 362 | ], 363 | "name": "parsePriceFeedUpdates", 364 | "outputs": [ 365 | { 366 | "components": [ 367 | { 368 | "internalType": "bytes32", 369 | "name": "id", 370 | "type": "bytes32" 371 | }, 372 | { 373 | "components": [ 374 | { 375 | "internalType": "int64", 376 | "name": "price", 377 | "type": "int64" 378 | }, 379 | { 380 | "internalType": "uint64", 381 | "name": "conf", 382 | "type": "uint64" 383 | }, 384 | { 385 | "internalType": "int32", 386 | "name": "expo", 387 | "type": "int32" 388 | }, 389 | { 390 | "internalType": "uint256", 391 | "name": "publishTime", 392 | "type": "uint256" 393 | } 394 | ], 395 | "internalType": "struct PythStructs.Price", 396 | "name": "price", 397 | "type": "tuple" 398 | }, 399 | { 400 | "components": [ 401 | { 402 | "internalType": "int64", 403 | "name": "price", 404 | "type": "int64" 405 | }, 406 | { 407 | "internalType": "uint64", 408 | "name": "conf", 409 | "type": "uint64" 410 | }, 411 | { 412 | "internalType": "int32", 413 | "name": "expo", 414 | "type": "int32" 415 | }, 416 | { 417 | "internalType": "uint256", 418 | "name": "publishTime", 419 | "type": "uint256" 420 | } 421 | ], 422 | "internalType": "struct PythStructs.Price", 423 | "name": "emaPrice", 424 | "type": "tuple" 425 | } 426 | ], 427 | "internalType": "struct PythStructs.PriceFeed[]", 428 | "name": "priceFeeds", 429 | "type": "tuple[]" 430 | } 431 | ], 432 | "stateMutability": "payable", 433 | "type": "function" 434 | }, 435 | { 436 | "inputs": [ 437 | { 438 | "internalType": "bytes[]", 439 | "name": "updateData", 440 | "type": "bytes[]" 441 | } 442 | ], 443 | "name": "updatePriceFeeds", 444 | "outputs": [], 445 | "stateMutability": "payable", 446 | "type": "function" 447 | }, 448 | { 449 | "inputs": [ 450 | { 451 | "internalType": "bytes[]", 452 | "name": "updateData", 453 | "type": "bytes[]" 454 | }, 455 | { 456 | "internalType": "bytes32[]", 457 | "name": "priceIds", 458 | "type": "bytes32[]" 459 | }, 460 | { 461 | "internalType": "uint64[]", 462 | "name": "publishTimes", 463 | "type": "uint64[]" 464 | } 465 | ], 466 | "name": "updatePriceFeedsIfNecessary", 467 | "outputs": [], 468 | "stateMutability": "payable", 469 | "type": "function" 470 | } 471 | ] 472 | -------------------------------------------------------------------------------- /abis/IPythEvents.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "anonymous": false, 4 | "inputs": [ 5 | { 6 | "indexed": false, 7 | "internalType": "uint16", 8 | "name": "chainId", 9 | "type": "uint16" 10 | }, 11 | { 12 | "indexed": false, 13 | "internalType": "uint64", 14 | "name": "sequenceNumber", 15 | "type": "uint64" 16 | } 17 | ], 18 | "name": "BatchPriceFeedUpdate", 19 | "type": "event" 20 | }, 21 | { 22 | "anonymous": false, 23 | "inputs": [ 24 | { 25 | "indexed": true, 26 | "internalType": "bytes32", 27 | "name": "id", 28 | "type": "bytes32" 29 | }, 30 | { 31 | "indexed": false, 32 | "internalType": "uint64", 33 | "name": "publishTime", 34 | "type": "uint64" 35 | }, 36 | { 37 | "indexed": false, 38 | "internalType": "int64", 39 | "name": "price", 40 | "type": "int64" 41 | }, 42 | { 43 | "indexed": false, 44 | "internalType": "uint64", 45 | "name": "conf", 46 | "type": "uint64" 47 | } 48 | ], 49 | "name": "PriceFeedUpdate", 50 | "type": "event" 51 | } 52 | ] 53 | -------------------------------------------------------------------------------- /abis/MockPyth.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "inputs": [ 4 | { 5 | "internalType": "uint256", 6 | "name": "_validTimePeriod", 7 | "type": "uint256" 8 | }, 9 | { 10 | "internalType": "uint256", 11 | "name": "_singleUpdateFeeInWei", 12 | "type": "uint256" 13 | } 14 | ], 15 | "stateMutability": "nonpayable", 16 | "type": "constructor" 17 | }, 18 | { 19 | "inputs": [], 20 | "name": "InsufficientFee", 21 | "type": "error" 22 | }, 23 | { 24 | "inputs": [], 25 | "name": "InvalidArgument", 26 | "type": "error" 27 | }, 28 | { 29 | "inputs": [], 30 | "name": "NoFreshUpdate", 31 | "type": "error" 32 | }, 33 | { 34 | "inputs": [], 35 | "name": "PriceFeedNotFound", 36 | "type": "error" 37 | }, 38 | { 39 | "inputs": [], 40 | "name": "PriceFeedNotFoundWithinRange", 41 | "type": "error" 42 | }, 43 | { 44 | "inputs": [], 45 | "name": "StalePrice", 46 | "type": "error" 47 | }, 48 | { 49 | "anonymous": false, 50 | "inputs": [ 51 | { 52 | "indexed": false, 53 | "internalType": "uint16", 54 | "name": "chainId", 55 | "type": "uint16" 56 | }, 57 | { 58 | "indexed": false, 59 | "internalType": "uint64", 60 | "name": "sequenceNumber", 61 | "type": "uint64" 62 | } 63 | ], 64 | "name": "BatchPriceFeedUpdate", 65 | "type": "event" 66 | }, 67 | { 68 | "anonymous": false, 69 | "inputs": [ 70 | { 71 | "indexed": true, 72 | "internalType": "bytes32", 73 | "name": "id", 74 | "type": "bytes32" 75 | }, 76 | { 77 | "indexed": false, 78 | "internalType": "uint64", 79 | "name": "publishTime", 80 | "type": "uint64" 81 | }, 82 | { 83 | "indexed": false, 84 | "internalType": "int64", 85 | "name": "price", 86 | "type": "int64" 87 | }, 88 | { 89 | "indexed": false, 90 | "internalType": "uint64", 91 | "name": "conf", 92 | "type": "uint64" 93 | } 94 | ], 95 | "name": "PriceFeedUpdate", 96 | "type": "event" 97 | }, 98 | { 99 | "inputs": [ 100 | { 101 | "internalType": "bytes32", 102 | "name": "id", 103 | "type": "bytes32" 104 | }, 105 | { 106 | "internalType": "int64", 107 | "name": "price", 108 | "type": "int64" 109 | }, 110 | { 111 | "internalType": "uint64", 112 | "name": "conf", 113 | "type": "uint64" 114 | }, 115 | { 116 | "internalType": "int32", 117 | "name": "expo", 118 | "type": "int32" 119 | }, 120 | { 121 | "internalType": "int64", 122 | "name": "emaPrice", 123 | "type": "int64" 124 | }, 125 | { 126 | "internalType": "uint64", 127 | "name": "emaConf", 128 | "type": "uint64" 129 | }, 130 | { 131 | "internalType": "uint64", 132 | "name": "publishTime", 133 | "type": "uint64" 134 | } 135 | ], 136 | "name": "createPriceFeedUpdateData", 137 | "outputs": [ 138 | { 139 | "internalType": "bytes", 140 | "name": "priceFeedData", 141 | "type": "bytes" 142 | } 143 | ], 144 | "stateMutability": "pure", 145 | "type": "function" 146 | }, 147 | { 148 | "inputs": [ 149 | { 150 | "internalType": "bytes32", 151 | "name": "id", 152 | "type": "bytes32" 153 | } 154 | ], 155 | "name": "getEmaPrice", 156 | "outputs": [ 157 | { 158 | "components": [ 159 | { 160 | "internalType": "int64", 161 | "name": "price", 162 | "type": "int64" 163 | }, 164 | { 165 | "internalType": "uint64", 166 | "name": "conf", 167 | "type": "uint64" 168 | }, 169 | { 170 | "internalType": "int32", 171 | "name": "expo", 172 | "type": "int32" 173 | }, 174 | { 175 | "internalType": "uint256", 176 | "name": "publishTime", 177 | "type": "uint256" 178 | } 179 | ], 180 | "internalType": "struct PythStructs.Price", 181 | "name": "price", 182 | "type": "tuple" 183 | } 184 | ], 185 | "stateMutability": "view", 186 | "type": "function" 187 | }, 188 | { 189 | "inputs": [ 190 | { 191 | "internalType": "bytes32", 192 | "name": "id", 193 | "type": "bytes32" 194 | }, 195 | { 196 | "internalType": "uint256", 197 | "name": "age", 198 | "type": "uint256" 199 | } 200 | ], 201 | "name": "getEmaPriceNoOlderThan", 202 | "outputs": [ 203 | { 204 | "components": [ 205 | { 206 | "internalType": "int64", 207 | "name": "price", 208 | "type": "int64" 209 | }, 210 | { 211 | "internalType": "uint64", 212 | "name": "conf", 213 | "type": "uint64" 214 | }, 215 | { 216 | "internalType": "int32", 217 | "name": "expo", 218 | "type": "int32" 219 | }, 220 | { 221 | "internalType": "uint256", 222 | "name": "publishTime", 223 | "type": "uint256" 224 | } 225 | ], 226 | "internalType": "struct PythStructs.Price", 227 | "name": "price", 228 | "type": "tuple" 229 | } 230 | ], 231 | "stateMutability": "view", 232 | "type": "function" 233 | }, 234 | { 235 | "inputs": [ 236 | { 237 | "internalType": "bytes32", 238 | "name": "id", 239 | "type": "bytes32" 240 | } 241 | ], 242 | "name": "getEmaPriceUnsafe", 243 | "outputs": [ 244 | { 245 | "components": [ 246 | { 247 | "internalType": "int64", 248 | "name": "price", 249 | "type": "int64" 250 | }, 251 | { 252 | "internalType": "uint64", 253 | "name": "conf", 254 | "type": "uint64" 255 | }, 256 | { 257 | "internalType": "int32", 258 | "name": "expo", 259 | "type": "int32" 260 | }, 261 | { 262 | "internalType": "uint256", 263 | "name": "publishTime", 264 | "type": "uint256" 265 | } 266 | ], 267 | "internalType": "struct PythStructs.Price", 268 | "name": "price", 269 | "type": "tuple" 270 | } 271 | ], 272 | "stateMutability": "view", 273 | "type": "function" 274 | }, 275 | { 276 | "inputs": [ 277 | { 278 | "internalType": "bytes32", 279 | "name": "id", 280 | "type": "bytes32" 281 | } 282 | ], 283 | "name": "getPrice", 284 | "outputs": [ 285 | { 286 | "components": [ 287 | { 288 | "internalType": "int64", 289 | "name": "price", 290 | "type": "int64" 291 | }, 292 | { 293 | "internalType": "uint64", 294 | "name": "conf", 295 | "type": "uint64" 296 | }, 297 | { 298 | "internalType": "int32", 299 | "name": "expo", 300 | "type": "int32" 301 | }, 302 | { 303 | "internalType": "uint256", 304 | "name": "publishTime", 305 | "type": "uint256" 306 | } 307 | ], 308 | "internalType": "struct PythStructs.Price", 309 | "name": "price", 310 | "type": "tuple" 311 | } 312 | ], 313 | "stateMutability": "view", 314 | "type": "function" 315 | }, 316 | { 317 | "inputs": [ 318 | { 319 | "internalType": "bytes32", 320 | "name": "id", 321 | "type": "bytes32" 322 | }, 323 | { 324 | "internalType": "uint256", 325 | "name": "age", 326 | "type": "uint256" 327 | } 328 | ], 329 | "name": "getPriceNoOlderThan", 330 | "outputs": [ 331 | { 332 | "components": [ 333 | { 334 | "internalType": "int64", 335 | "name": "price", 336 | "type": "int64" 337 | }, 338 | { 339 | "internalType": "uint64", 340 | "name": "conf", 341 | "type": "uint64" 342 | }, 343 | { 344 | "internalType": "int32", 345 | "name": "expo", 346 | "type": "int32" 347 | }, 348 | { 349 | "internalType": "uint256", 350 | "name": "publishTime", 351 | "type": "uint256" 352 | } 353 | ], 354 | "internalType": "struct PythStructs.Price", 355 | "name": "price", 356 | "type": "tuple" 357 | } 358 | ], 359 | "stateMutability": "view", 360 | "type": "function" 361 | }, 362 | { 363 | "inputs": [ 364 | { 365 | "internalType": "bytes32", 366 | "name": "id", 367 | "type": "bytes32" 368 | } 369 | ], 370 | "name": "getPriceUnsafe", 371 | "outputs": [ 372 | { 373 | "components": [ 374 | { 375 | "internalType": "int64", 376 | "name": "price", 377 | "type": "int64" 378 | }, 379 | { 380 | "internalType": "uint64", 381 | "name": "conf", 382 | "type": "uint64" 383 | }, 384 | { 385 | "internalType": "int32", 386 | "name": "expo", 387 | "type": "int32" 388 | }, 389 | { 390 | "internalType": "uint256", 391 | "name": "publishTime", 392 | "type": "uint256" 393 | } 394 | ], 395 | "internalType": "struct PythStructs.Price", 396 | "name": "price", 397 | "type": "tuple" 398 | } 399 | ], 400 | "stateMutability": "view", 401 | "type": "function" 402 | }, 403 | { 404 | "inputs": [ 405 | { 406 | "internalType": "bytes[]", 407 | "name": "updateData", 408 | "type": "bytes[]" 409 | } 410 | ], 411 | "name": "getUpdateFee", 412 | "outputs": [ 413 | { 414 | "internalType": "uint256", 415 | "name": "feeAmount", 416 | "type": "uint256" 417 | } 418 | ], 419 | "stateMutability": "view", 420 | "type": "function" 421 | }, 422 | { 423 | "inputs": [], 424 | "name": "getValidTimePeriod", 425 | "outputs": [ 426 | { 427 | "internalType": "uint256", 428 | "name": "", 429 | "type": "uint256" 430 | } 431 | ], 432 | "stateMutability": "view", 433 | "type": "function" 434 | }, 435 | { 436 | "inputs": [ 437 | { 438 | "internalType": "bytes[]", 439 | "name": "updateData", 440 | "type": "bytes[]" 441 | }, 442 | { 443 | "internalType": "bytes32[]", 444 | "name": "priceIds", 445 | "type": "bytes32[]" 446 | }, 447 | { 448 | "internalType": "uint64", 449 | "name": "minPublishTime", 450 | "type": "uint64" 451 | }, 452 | { 453 | "internalType": "uint64", 454 | "name": "maxPublishTime", 455 | "type": "uint64" 456 | } 457 | ], 458 | "name": "parsePriceFeedUpdates", 459 | "outputs": [ 460 | { 461 | "components": [ 462 | { 463 | "internalType": "bytes32", 464 | "name": "id", 465 | "type": "bytes32" 466 | }, 467 | { 468 | "components": [ 469 | { 470 | "internalType": "int64", 471 | "name": "price", 472 | "type": "int64" 473 | }, 474 | { 475 | "internalType": "uint64", 476 | "name": "conf", 477 | "type": "uint64" 478 | }, 479 | { 480 | "internalType": "int32", 481 | "name": "expo", 482 | "type": "int32" 483 | }, 484 | { 485 | "internalType": "uint256", 486 | "name": "publishTime", 487 | "type": "uint256" 488 | } 489 | ], 490 | "internalType": "struct PythStructs.Price", 491 | "name": "price", 492 | "type": "tuple" 493 | }, 494 | { 495 | "components": [ 496 | { 497 | "internalType": "int64", 498 | "name": "price", 499 | "type": "int64" 500 | }, 501 | { 502 | "internalType": "uint64", 503 | "name": "conf", 504 | "type": "uint64" 505 | }, 506 | { 507 | "internalType": "int32", 508 | "name": "expo", 509 | "type": "int32" 510 | }, 511 | { 512 | "internalType": "uint256", 513 | "name": "publishTime", 514 | "type": "uint256" 515 | } 516 | ], 517 | "internalType": "struct PythStructs.Price", 518 | "name": "emaPrice", 519 | "type": "tuple" 520 | } 521 | ], 522 | "internalType": "struct PythStructs.PriceFeed[]", 523 | "name": "feeds", 524 | "type": "tuple[]" 525 | } 526 | ], 527 | "stateMutability": "payable", 528 | "type": "function" 529 | }, 530 | { 531 | "inputs": [ 532 | { 533 | "internalType": "bytes32", 534 | "name": "id", 535 | "type": "bytes32" 536 | } 537 | ], 538 | "name": "priceFeedExists", 539 | "outputs": [ 540 | { 541 | "internalType": "bool", 542 | "name": "", 543 | "type": "bool" 544 | } 545 | ], 546 | "stateMutability": "view", 547 | "type": "function" 548 | }, 549 | { 550 | "inputs": [ 551 | { 552 | "internalType": "bytes32", 553 | "name": "id", 554 | "type": "bytes32" 555 | } 556 | ], 557 | "name": "queryPriceFeed", 558 | "outputs": [ 559 | { 560 | "components": [ 561 | { 562 | "internalType": "bytes32", 563 | "name": "id", 564 | "type": "bytes32" 565 | }, 566 | { 567 | "components": [ 568 | { 569 | "internalType": "int64", 570 | "name": "price", 571 | "type": "int64" 572 | }, 573 | { 574 | "internalType": "uint64", 575 | "name": "conf", 576 | "type": "uint64" 577 | }, 578 | { 579 | "internalType": "int32", 580 | "name": "expo", 581 | "type": "int32" 582 | }, 583 | { 584 | "internalType": "uint256", 585 | "name": "publishTime", 586 | "type": "uint256" 587 | } 588 | ], 589 | "internalType": "struct PythStructs.Price", 590 | "name": "price", 591 | "type": "tuple" 592 | }, 593 | { 594 | "components": [ 595 | { 596 | "internalType": "int64", 597 | "name": "price", 598 | "type": "int64" 599 | }, 600 | { 601 | "internalType": "uint64", 602 | "name": "conf", 603 | "type": "uint64" 604 | }, 605 | { 606 | "internalType": "int32", 607 | "name": "expo", 608 | "type": "int32" 609 | }, 610 | { 611 | "internalType": "uint256", 612 | "name": "publishTime", 613 | "type": "uint256" 614 | } 615 | ], 616 | "internalType": "struct PythStructs.Price", 617 | "name": "emaPrice", 618 | "type": "tuple" 619 | } 620 | ], 621 | "internalType": "struct PythStructs.PriceFeed", 622 | "name": "priceFeed", 623 | "type": "tuple" 624 | } 625 | ], 626 | "stateMutability": "view", 627 | "type": "function" 628 | }, 629 | { 630 | "inputs": [ 631 | { 632 | "internalType": "bytes[]", 633 | "name": "updateData", 634 | "type": "bytes[]" 635 | } 636 | ], 637 | "name": "updatePriceFeeds", 638 | "outputs": [], 639 | "stateMutability": "payable", 640 | "type": "function" 641 | }, 642 | { 643 | "inputs": [ 644 | { 645 | "internalType": "bytes[]", 646 | "name": "updateData", 647 | "type": "bytes[]" 648 | }, 649 | { 650 | "internalType": "bytes32[]", 651 | "name": "priceIds", 652 | "type": "bytes32[]" 653 | }, 654 | { 655 | "internalType": "uint64[]", 656 | "name": "publishTimes", 657 | "type": "uint64[]" 658 | } 659 | ], 660 | "name": "updatePriceFeedsIfNecessary", 661 | "outputs": [], 662 | "stateMutability": "payable", 663 | "type": "function" 664 | } 665 | ] 666 | -------------------------------------------------------------------------------- /package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@pythnetwork/pyth-sdk-solidity", 3 | "version": "2.2.0", 4 | "lockfileVersion": 2, 5 | "requires": true, 6 | "packages": { 7 | "": { 8 | "name": "@pythnetwork/pyth-sdk-solidity", 9 | "version": "2.2.0", 10 | "license": "Apache-2.0", 11 | "devDependencies": { 12 | "prettier": "^2.7.1", 13 | "prettier-plugin-solidity": "^1.0.0-rc.1", 14 | "solc": "^0.8.15" 15 | } 16 | }, 17 | "node_modules/@solidity-parser/parser": { 18 | "version": "0.14.5", 19 | "resolved": "https://registry.npmjs.org/@solidity-parser/parser/-/parser-0.14.5.tgz", 20 | "integrity": "sha512-6dKnHZn7fg/iQATVEzqyUOyEidbn05q7YA2mQ9hC0MMXhhV3/JrsxmFSYZAcr7j1yUP700LLhTruvJ3MiQmjJg==", 21 | "dev": true, 22 | "dependencies": { 23 | "antlr4ts": "^0.5.0-alpha.4" 24 | } 25 | }, 26 | "node_modules/ansi-regex": { 27 | "version": "5.0.1", 28 | "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", 29 | "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==", 30 | "dev": true, 31 | "engines": { 32 | "node": ">=8" 33 | } 34 | }, 35 | "node_modules/antlr4ts": { 36 | "version": "0.5.0-alpha.4", 37 | "resolved": "https://registry.npmjs.org/antlr4ts/-/antlr4ts-0.5.0-alpha.4.tgz", 38 | "integrity": "sha512-WPQDt1B74OfPv/IMS2ekXAKkTZIHl88uMetg6q3OTqgFxZ/dxDXI0EWLyZid/1Pe6hTftyg5N7gel5wNAGxXyQ==", 39 | "dev": true 40 | }, 41 | "node_modules/command-exists": { 42 | "version": "1.2.9", 43 | "resolved": "https://registry.npmjs.org/command-exists/-/command-exists-1.2.9.tgz", 44 | "integrity": "sha512-LTQ/SGc+s0Xc0Fu5WaKnR0YiygZkm9eKFvyS+fRsU7/ZWFF8ykFM6Pc9aCVf1+xasOOZpO3BAVgVrKvsqKHV7w==", 45 | "dev": true 46 | }, 47 | "node_modules/commander": { 48 | "version": "8.3.0", 49 | "resolved": "https://registry.npmjs.org/commander/-/commander-8.3.0.tgz", 50 | "integrity": "sha512-OkTL9umf+He2DZkUq8f8J9of7yL6RJKI24dVITBmNfZBmri9zYZQrKkuXiKhyfPSu8tUhnVBB1iKXevvnlR4Ww==", 51 | "dev": true, 52 | "engines": { 53 | "node": ">= 12" 54 | } 55 | }, 56 | "node_modules/emoji-regex": { 57 | "version": "10.2.1", 58 | "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-10.2.1.tgz", 59 | "integrity": "sha512-97g6QgOk8zlDRdgq1WxwgTMgEWGVAQvB5Fdpgc1MkNy56la5SKP9GsMXKDOdqwn90/41a8yPwIGk1Y6WVbeMQA==", 60 | "dev": true 61 | }, 62 | "node_modules/escape-string-regexp": { 63 | "version": "4.0.0", 64 | "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-4.0.0.tgz", 65 | "integrity": "sha512-TtpcNJ3XAzx3Gq8sWRzJaVajRs0uVxA2YAkdb1jm2YkPz4G6egUFAyA3n5vtEIZefPk5Wa4UXbKuS5fKkJWdgA==", 66 | "dev": true, 67 | "engines": { 68 | "node": ">=10" 69 | }, 70 | "funding": { 71 | "url": "https://github.com/sponsors/sindresorhus" 72 | } 73 | }, 74 | "node_modules/follow-redirects": { 75 | "version": "1.15.1", 76 | "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.1.tgz", 77 | "integrity": "sha512-yLAMQs+k0b2m7cVxpS1VKJVvoz7SS9Td1zss3XRwXj+ZDH00RJgnuLx7E44wx02kQLrdM3aOOy+FpzS7+8OizA==", 78 | "dev": true, 79 | "funding": [ 80 | { 81 | "type": "individual", 82 | "url": "https://github.com/sponsors/RubenVerborgh" 83 | } 84 | ], 85 | "engines": { 86 | "node": ">=4.0" 87 | }, 88 | "peerDependenciesMeta": { 89 | "debug": { 90 | "optional": true 91 | } 92 | } 93 | }, 94 | "node_modules/is-fullwidth-code-point": { 95 | "version": "3.0.0", 96 | "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz", 97 | "integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==", 98 | "dev": true, 99 | "engines": { 100 | "node": ">=8" 101 | } 102 | }, 103 | "node_modules/js-sha3": { 104 | "version": "0.8.0", 105 | "resolved": "https://registry.npmjs.org/js-sha3/-/js-sha3-0.8.0.tgz", 106 | "integrity": "sha512-gF1cRrHhIzNfToc802P800N8PpXS+evLLXfsVpowqmAFR9uwbi89WvXg2QspOmXL8QL86J4T1EpFu+yUkwJY3Q==", 107 | "dev": true 108 | }, 109 | "node_modules/lru-cache": { 110 | "version": "6.0.0", 111 | "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", 112 | "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==", 113 | "dev": true, 114 | "dependencies": { 115 | "yallist": "^4.0.0" 116 | }, 117 | "engines": { 118 | "node": ">=10" 119 | } 120 | }, 121 | "node_modules/memorystream": { 122 | "version": "0.3.1", 123 | "resolved": "https://registry.npmjs.org/memorystream/-/memorystream-0.3.1.tgz", 124 | "integrity": "sha512-S3UwM3yj5mtUSEfP41UZmt/0SCoVYUcU1rkXv+BQ5Ig8ndL4sPoJNBUJERafdPb5jjHJGuMgytgKvKIf58XNBw==", 125 | "dev": true, 126 | "engines": { 127 | "node": ">= 0.10.0" 128 | } 129 | }, 130 | "node_modules/os-tmpdir": { 131 | "version": "1.0.2", 132 | "resolved": "https://registry.npmjs.org/os-tmpdir/-/os-tmpdir-1.0.2.tgz", 133 | "integrity": "sha512-D2FR03Vir7FIu45XBY20mTb+/ZSWB00sjU9jdQXt83gDrI4Ztz5Fs7/yy74g2N5SVQY4xY1qDr4rNddwYRVX0g==", 134 | "dev": true, 135 | "engines": { 136 | "node": ">=0.10.0" 137 | } 138 | }, 139 | "node_modules/prettier": { 140 | "version": "2.7.1", 141 | "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.7.1.tgz", 142 | "integrity": "sha512-ujppO+MkdPqoVINuDFDRLClm7D78qbDt0/NR+wp5FqEZOoTNAjPHWj17QRhu7geIHJfcNhRk1XVQmF8Bp3ye+g==", 143 | "dev": true, 144 | "bin": { 145 | "prettier": "bin-prettier.js" 146 | }, 147 | "engines": { 148 | "node": ">=10.13.0" 149 | }, 150 | "funding": { 151 | "url": "https://github.com/prettier/prettier?sponsor=1" 152 | } 153 | }, 154 | "node_modules/prettier-plugin-solidity": { 155 | "version": "1.0.0-rc.1", 156 | "resolved": "https://registry.npmjs.org/prettier-plugin-solidity/-/prettier-plugin-solidity-1.0.0-rc.1.tgz", 157 | "integrity": "sha512-horUGyCBbfNHWvJ44UVEcsfVySEoG2gxGs7TcBfTZWNvD4VU6rjzwAkrUtKV6VvRZWn9dh01XZ2UhhB3eVnMXQ==", 158 | "dev": true, 159 | "dependencies": { 160 | "@solidity-parser/parser": "^0.14.5", 161 | "emoji-regex": "^10.1.0", 162 | "escape-string-regexp": "^4.0.0", 163 | "semver": "^7.3.7", 164 | "solidity-comments-extractor": "^0.0.7", 165 | "string-width": "^4.2.3" 166 | }, 167 | "engines": { 168 | "node": ">=12" 169 | }, 170 | "peerDependencies": { 171 | "prettier": "^2.3.0" 172 | } 173 | }, 174 | "node_modules/prettier-plugin-solidity/node_modules/semver": { 175 | "version": "7.3.8", 176 | "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.8.tgz", 177 | "integrity": "sha512-NB1ctGL5rlHrPJtFDVIVzTyQylMLu9N9VICA6HSFJo8MCGVTMW6gfpicwKmmK/dAjTOrqu5l63JJOpDSrAis3A==", 178 | "dev": true, 179 | "dependencies": { 180 | "lru-cache": "^6.0.0" 181 | }, 182 | "bin": { 183 | "semver": "bin/semver.js" 184 | }, 185 | "engines": { 186 | "node": ">=10" 187 | } 188 | }, 189 | "node_modules/semver": { 190 | "version": "5.7.1", 191 | "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.1.tgz", 192 | "integrity": "sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==", 193 | "dev": true, 194 | "bin": { 195 | "semver": "bin/semver" 196 | } 197 | }, 198 | "node_modules/solc": { 199 | "version": "0.8.15", 200 | "resolved": "https://registry.npmjs.org/solc/-/solc-0.8.15.tgz", 201 | "integrity": "sha512-Riv0GNHNk/SddN/JyEuFKwbcWcEeho15iyupTSHw5Np6WuXA5D8kEHbyzDHi6sqmvLzu2l+8b1YmL8Ytple+8w==", 202 | "dev": true, 203 | "dependencies": { 204 | "command-exists": "^1.2.8", 205 | "commander": "^8.1.0", 206 | "follow-redirects": "^1.12.1", 207 | "js-sha3": "0.8.0", 208 | "memorystream": "^0.3.1", 209 | "semver": "^5.5.0", 210 | "tmp": "0.0.33" 211 | }, 212 | "bin": { 213 | "solcjs": "solc.js" 214 | }, 215 | "engines": { 216 | "node": ">=10.0.0" 217 | } 218 | }, 219 | "node_modules/solidity-comments-extractor": { 220 | "version": "0.0.7", 221 | "resolved": "https://registry.npmjs.org/solidity-comments-extractor/-/solidity-comments-extractor-0.0.7.tgz", 222 | "integrity": "sha512-wciNMLg/Irp8OKGrh3S2tfvZiZ0NEyILfcRCXCD4mp7SgK/i9gzLfhY2hY7VMCQJ3kH9UB9BzNdibIVMchzyYw==", 223 | "dev": true 224 | }, 225 | "node_modules/string-width": { 226 | "version": "4.2.3", 227 | "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz", 228 | "integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==", 229 | "dev": true, 230 | "dependencies": { 231 | "emoji-regex": "^8.0.0", 232 | "is-fullwidth-code-point": "^3.0.0", 233 | "strip-ansi": "^6.0.1" 234 | }, 235 | "engines": { 236 | "node": ">=8" 237 | } 238 | }, 239 | "node_modules/string-width/node_modules/emoji-regex": { 240 | "version": "8.0.0", 241 | "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz", 242 | "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==", 243 | "dev": true 244 | }, 245 | "node_modules/strip-ansi": { 246 | "version": "6.0.1", 247 | "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz", 248 | "integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==", 249 | "dev": true, 250 | "dependencies": { 251 | "ansi-regex": "^5.0.1" 252 | }, 253 | "engines": { 254 | "node": ">=8" 255 | } 256 | }, 257 | "node_modules/tmp": { 258 | "version": "0.0.33", 259 | "resolved": "https://registry.npmjs.org/tmp/-/tmp-0.0.33.tgz", 260 | "integrity": "sha512-jRCJlojKnZ3addtTOjdIqoRuPEKBvNXcGYqzO6zWZX8KfKEpnGY5jfggJQ3EjKuu8D4bJRr0y+cYJFmYbImXGw==", 261 | "dev": true, 262 | "dependencies": { 263 | "os-tmpdir": "~1.0.2" 264 | }, 265 | "engines": { 266 | "node": ">=0.6.0" 267 | } 268 | }, 269 | "node_modules/yallist": { 270 | "version": "4.0.0", 271 | "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", 272 | "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==", 273 | "dev": true 274 | } 275 | }, 276 | "dependencies": { 277 | "@solidity-parser/parser": { 278 | "version": "0.14.5", 279 | "resolved": "https://registry.npmjs.org/@solidity-parser/parser/-/parser-0.14.5.tgz", 280 | "integrity": "sha512-6dKnHZn7fg/iQATVEzqyUOyEidbn05q7YA2mQ9hC0MMXhhV3/JrsxmFSYZAcr7j1yUP700LLhTruvJ3MiQmjJg==", 281 | "dev": true, 282 | "requires": { 283 | "antlr4ts": "^0.5.0-alpha.4" 284 | } 285 | }, 286 | "ansi-regex": { 287 | "version": "5.0.1", 288 | "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", 289 | "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==", 290 | "dev": true 291 | }, 292 | "antlr4ts": { 293 | "version": "0.5.0-alpha.4", 294 | "resolved": "https://registry.npmjs.org/antlr4ts/-/antlr4ts-0.5.0-alpha.4.tgz", 295 | "integrity": "sha512-WPQDt1B74OfPv/IMS2ekXAKkTZIHl88uMetg6q3OTqgFxZ/dxDXI0EWLyZid/1Pe6hTftyg5N7gel5wNAGxXyQ==", 296 | "dev": true 297 | }, 298 | "command-exists": { 299 | "version": "1.2.9", 300 | "resolved": "https://registry.npmjs.org/command-exists/-/command-exists-1.2.9.tgz", 301 | "integrity": "sha512-LTQ/SGc+s0Xc0Fu5WaKnR0YiygZkm9eKFvyS+fRsU7/ZWFF8ykFM6Pc9aCVf1+xasOOZpO3BAVgVrKvsqKHV7w==", 302 | "dev": true 303 | }, 304 | "commander": { 305 | "version": "8.3.0", 306 | "resolved": "https://registry.npmjs.org/commander/-/commander-8.3.0.tgz", 307 | "integrity": "sha512-OkTL9umf+He2DZkUq8f8J9of7yL6RJKI24dVITBmNfZBmri9zYZQrKkuXiKhyfPSu8tUhnVBB1iKXevvnlR4Ww==", 308 | "dev": true 309 | }, 310 | "emoji-regex": { 311 | "version": "10.2.1", 312 | "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-10.2.1.tgz", 313 | "integrity": "sha512-97g6QgOk8zlDRdgq1WxwgTMgEWGVAQvB5Fdpgc1MkNy56la5SKP9GsMXKDOdqwn90/41a8yPwIGk1Y6WVbeMQA==", 314 | "dev": true 315 | }, 316 | "escape-string-regexp": { 317 | "version": "4.0.0", 318 | "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-4.0.0.tgz", 319 | "integrity": "sha512-TtpcNJ3XAzx3Gq8sWRzJaVajRs0uVxA2YAkdb1jm2YkPz4G6egUFAyA3n5vtEIZefPk5Wa4UXbKuS5fKkJWdgA==", 320 | "dev": true 321 | }, 322 | "follow-redirects": { 323 | "version": "1.15.1", 324 | "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.1.tgz", 325 | "integrity": "sha512-yLAMQs+k0b2m7cVxpS1VKJVvoz7SS9Td1zss3XRwXj+ZDH00RJgnuLx7E44wx02kQLrdM3aOOy+FpzS7+8OizA==", 326 | "dev": true 327 | }, 328 | "is-fullwidth-code-point": { 329 | "version": "3.0.0", 330 | "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz", 331 | "integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==", 332 | "dev": true 333 | }, 334 | "js-sha3": { 335 | "version": "0.8.0", 336 | "resolved": "https://registry.npmjs.org/js-sha3/-/js-sha3-0.8.0.tgz", 337 | "integrity": "sha512-gF1cRrHhIzNfToc802P800N8PpXS+evLLXfsVpowqmAFR9uwbi89WvXg2QspOmXL8QL86J4T1EpFu+yUkwJY3Q==", 338 | "dev": true 339 | }, 340 | "lru-cache": { 341 | "version": "6.0.0", 342 | "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", 343 | "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==", 344 | "dev": true, 345 | "requires": { 346 | "yallist": "^4.0.0" 347 | } 348 | }, 349 | "memorystream": { 350 | "version": "0.3.1", 351 | "resolved": "https://registry.npmjs.org/memorystream/-/memorystream-0.3.1.tgz", 352 | "integrity": "sha512-S3UwM3yj5mtUSEfP41UZmt/0SCoVYUcU1rkXv+BQ5Ig8ndL4sPoJNBUJERafdPb5jjHJGuMgytgKvKIf58XNBw==", 353 | "dev": true 354 | }, 355 | "os-tmpdir": { 356 | "version": "1.0.2", 357 | "resolved": "https://registry.npmjs.org/os-tmpdir/-/os-tmpdir-1.0.2.tgz", 358 | "integrity": "sha512-D2FR03Vir7FIu45XBY20mTb+/ZSWB00sjU9jdQXt83gDrI4Ztz5Fs7/yy74g2N5SVQY4xY1qDr4rNddwYRVX0g==", 359 | "dev": true 360 | }, 361 | "prettier": { 362 | "version": "2.7.1", 363 | "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.7.1.tgz", 364 | "integrity": "sha512-ujppO+MkdPqoVINuDFDRLClm7D78qbDt0/NR+wp5FqEZOoTNAjPHWj17QRhu7geIHJfcNhRk1XVQmF8Bp3ye+g==", 365 | "dev": true 366 | }, 367 | "prettier-plugin-solidity": { 368 | "version": "1.0.0-rc.1", 369 | "resolved": "https://registry.npmjs.org/prettier-plugin-solidity/-/prettier-plugin-solidity-1.0.0-rc.1.tgz", 370 | "integrity": "sha512-horUGyCBbfNHWvJ44UVEcsfVySEoG2gxGs7TcBfTZWNvD4VU6rjzwAkrUtKV6VvRZWn9dh01XZ2UhhB3eVnMXQ==", 371 | "dev": true, 372 | "requires": { 373 | "@solidity-parser/parser": "^0.14.5", 374 | "emoji-regex": "^10.1.0", 375 | "escape-string-regexp": "^4.0.0", 376 | "semver": "^7.3.7", 377 | "solidity-comments-extractor": "^0.0.7", 378 | "string-width": "^4.2.3" 379 | }, 380 | "dependencies": { 381 | "semver": { 382 | "version": "7.3.8", 383 | "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.8.tgz", 384 | "integrity": "sha512-NB1ctGL5rlHrPJtFDVIVzTyQylMLu9N9VICA6HSFJo8MCGVTMW6gfpicwKmmK/dAjTOrqu5l63JJOpDSrAis3A==", 385 | "dev": true, 386 | "requires": { 387 | "lru-cache": "^6.0.0" 388 | } 389 | } 390 | } 391 | }, 392 | "semver": { 393 | "version": "5.7.1", 394 | "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.1.tgz", 395 | "integrity": "sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==", 396 | "dev": true 397 | }, 398 | "solc": { 399 | "version": "0.8.15", 400 | "resolved": "https://registry.npmjs.org/solc/-/solc-0.8.15.tgz", 401 | "integrity": "sha512-Riv0GNHNk/SddN/JyEuFKwbcWcEeho15iyupTSHw5Np6WuXA5D8kEHbyzDHi6sqmvLzu2l+8b1YmL8Ytple+8w==", 402 | "dev": true, 403 | "requires": { 404 | "command-exists": "^1.2.8", 405 | "commander": "^8.1.0", 406 | "follow-redirects": "^1.12.1", 407 | "js-sha3": "0.8.0", 408 | "memorystream": "^0.3.1", 409 | "semver": "^5.5.0", 410 | "tmp": "0.0.33" 411 | } 412 | }, 413 | "solidity-comments-extractor": { 414 | "version": "0.0.7", 415 | "resolved": "https://registry.npmjs.org/solidity-comments-extractor/-/solidity-comments-extractor-0.0.7.tgz", 416 | "integrity": "sha512-wciNMLg/Irp8OKGrh3S2tfvZiZ0NEyILfcRCXCD4mp7SgK/i9gzLfhY2hY7VMCQJ3kH9UB9BzNdibIVMchzyYw==", 417 | "dev": true 418 | }, 419 | "string-width": { 420 | "version": "4.2.3", 421 | "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz", 422 | "integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==", 423 | "dev": true, 424 | "requires": { 425 | "emoji-regex": "^8.0.0", 426 | "is-fullwidth-code-point": "^3.0.0", 427 | "strip-ansi": "^6.0.1" 428 | }, 429 | "dependencies": { 430 | "emoji-regex": { 431 | "version": "8.0.0", 432 | "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz", 433 | "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==", 434 | "dev": true 435 | } 436 | } 437 | }, 438 | "strip-ansi": { 439 | "version": "6.0.1", 440 | "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz", 441 | "integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==", 442 | "dev": true, 443 | "requires": { 444 | "ansi-regex": "^5.0.1" 445 | } 446 | }, 447 | "tmp": { 448 | "version": "0.0.33", 449 | "resolved": "https://registry.npmjs.org/tmp/-/tmp-0.0.33.tgz", 450 | "integrity": "sha512-jRCJlojKnZ3addtTOjdIqoRuPEKBvNXcGYqzO6zWZX8KfKEpnGY5jfggJQ3EjKuu8D4bJRr0y+cYJFmYbImXGw==", 451 | "dev": true, 452 | "requires": { 453 | "os-tmpdir": "~1.0.2" 454 | } 455 | }, 456 | "yallist": { 457 | "version": "4.0.0", 458 | "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", 459 | "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==", 460 | "dev": true 461 | } 462 | } 463 | } 464 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@pythnetwork/pyth-sdk-solidity", 3 | "version": "2.2.0", 4 | "description": "Read prices from the Pyth oracle", 5 | "repository": { 6 | "type": "git", 7 | "url": "git+https://github.com/pyth-network/pyth-sdk-solidity.git" 8 | }, 9 | "scripts": { 10 | "format": "npx prettier --write .", 11 | "generate-abi": "node scripts/generateAbi.js", 12 | "build-mock": "solcjs --bin MockPyth.sol -o build/" 13 | }, 14 | "keywords": [ 15 | "pyth", 16 | "solidity", 17 | "oracle" 18 | ], 19 | "author": "Pyth Data Foundation", 20 | "license": "Apache-2.0", 21 | "bugs": { 22 | "url": "https://github.com/pyth-network/pyth-sdk-solidity/issues" 23 | }, 24 | "homepage": "https://github.com/pyth-network/pyth-sdk-solidity#readme", 25 | "devDependencies": { 26 | "prettier": "^2.7.1", 27 | "prettier-plugin-solidity": "^1.0.0-rc.1", 28 | "solc": "^0.8.15" 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /scripts/generateAbi.js: -------------------------------------------------------------------------------- 1 | const fs = require("fs"); 2 | const solc = require("solc"); 3 | 4 | // Assuming each contract is in the file with the same name. 5 | var contracts = ["IPyth", "IPythEvents", "AbstractPyth", "MockPyth"]; 6 | 7 | var sources = {}; 8 | var outputSelection = {}; 9 | 10 | for (let contract of contracts) { 11 | const contractFile = `${contract}.sol`; 12 | sources[contractFile] = { 13 | content: fs.readFileSync(contractFile).toString(), 14 | }; 15 | outputSelection[contractFile] = {}; 16 | outputSelection[contractFile][contract] = ["abi"]; 17 | } 18 | 19 | var input = { 20 | language: "Solidity", 21 | sources, 22 | settings: { 23 | outputSelection, 24 | }, 25 | }; 26 | 27 | function findImports(path) { 28 | return { 29 | contents: fs.readFileSync(path).toString(), 30 | }; 31 | } 32 | 33 | const output = JSON.parse( 34 | solc.compile(JSON.stringify(input), { import: findImports }) 35 | ); 36 | 37 | if (!fs.existsSync("abis")) { 38 | fs.mkdirSync("abis"); 39 | } 40 | 41 | for (let contract of contracts) { 42 | const contractFile = `${contract}.sol`; 43 | 44 | const abi = output.contracts[contractFile][contract].abi; 45 | fs.writeFileSync( 46 | `abis/${contract}.json`, 47 | JSON.stringify(abi, null, 2) + "\n" 48 | ); 49 | } 50 | --------------------------------------------------------------------------------