@storknetwork/stork_pyth_adapter
v1.0.1
Published
EVM Solidity contracts to adapt Stork price feeds to Pyth's IPyth interface
Readme
Stork Pyth Adapter
This is the Stork Pyth Adapter for EVM-compatible chains. This package is maintained by Stork Labs.
It is available on npm.
This package can be used as an SDK to build contracts that interact with Stork price feeds using Pyth's familiar IPyth interface, or deployed as a standalone contract.
Pyth Compatibility
The adapter implements Pyth's IPyth interface, allowing existing Pyth-integrated applications to seamlessly integrate with Stork price feeds with minimal code changes. Price precision (exponent) is dynamically reduced from Stork's int192 values to fit within the less precise int64 used in the IPyth interface.
Note that all timestamps are returned in seconds (converted from Stork's nanosecond precision) and confidence intervals are not supported in this adapter.
Usage as SDK
Install the package in your Solidity project:
npm install @storknetwork/stork_pyth_adapterImport and use in your contract:
// SPDX-License-Identifier: Apache-2.0
pragma solidity >=0.8.24 <0.9.0;
import "@storknetwork/stork_pyth_adapter/contracts/StorkPythAdapter.sol";
contract YourContract {
StorkPythAdapter public priceAdapter;
constructor(address storkContract) {
priceAdapter = new StorkPythAdapter(storkContract);
}
function getLatestPrice(bytes32 priceId) external view returns (int64) {
PythStructs.Price memory price = priceAdapter.getPrice(priceId);
return price.price;
}
}Supported Features
This adapter supports the following IPyth interface methods:
getValidTimePeriod()- Returns the validity period for price feedsgetPrice(bytes32 id)- Returns the latest price for a given asset IDgetPriceUnsafe(bytes32 id)- Returns price without validation checksgetPriceNoOlderThan(bytes32 id, uint age)- Returns price with age validation
Unsupported Features
The following IPyth methods are not supported and will revert:
- EMA price methods (
getEmaPrice,getEmaPriceUnsafe,getEmaPriceNoOlderThan) - Update methods (
updatePriceFeeds,updatePriceFeedsIfNecessary,parsePriceFeedUpdates, etc.) - Fee calculation methods (
getUpdateFee,getTwapUpdateFee) A complete working example can be found in the stork-external repository.
Deploying
To deploy the contract, clone down the repo and run the following commands from this contract's directory:
npm installnpx hardhat compile- Set the
storkContractin theignition/parameters.jsonfile. Stork contract addresses can be found in the Stork Documentation. npx hardhat ignition deploy ignition/modules/StorkPythAdapter.ts --network <network>
