0.0.1 • Published 6 months ago
@synthetic-market-programs/pyth-mock-js v0.0.1
Pyth Mock SDK
A mock SDK for Pyth price feeds, designed for testing and development environments on Solana.
Installation
npm install @synthetic-market-programs/pyth-mock-jsUsage
import { PythMock } from "@synthetic-market-programs/pyth-mock-js";
import { PublicKey } from "@solana/web3.js";
// Create a PythMock instance
const pythMock = new PythMock();
// Create a price feed
const priceFeed = await pythMock.createPriceFeed(50); // Initial price is 50
// Get price data
const priceData = await pythMock.getPriceData(priceFeed);
console.log(priceData.price); // 50
// Update price
await pythMock.setPrice(priceFeed, 60);
// Update TWAP
await pythMock.setTwap(priceFeed, 55);
// Get Oracle formatted price data
const oracleData = await pythMock.getOraclePriceData(priceFeed);
console.log(oracleData.price.toString()); // 60000000API Documentation
PythMock
Main class providing all price feed operations.
Methods
createPriceFeed(price: number, exponent?: number, confidence?: number): Promise<PublicKey>- Creates a new price feed
price: Initial priceexponent: Price exponent (default -7)confidence: Confidence value (optional)
setPrice(priceFeed: PublicKey, newPrice: number): Promise<void>- Updates the price feed's price
priceFeed: Price feed's public keynewPrice: New price value
setTwap(priceFeed: PublicKey, newTwap: number): Promise<void>- Updates the price feed's TWAP
priceFeed: Price feed's public keynewTwap: New TWAP value
getPriceData(priceFeed: PublicKey): Promise<PriceData>- Gets detailed price feed data
getOraclePriceData(priceFeed: PublicKey): Promise<OraclePriceData>- Gets Oracle formatted price data
Development
Prerequisites
- Node.js >= 16.0.0
- npm >= 7.0.0
Setup
# Install dependencies
npm install
# Build the project
npm run build
# Run tests
npm test
# Lint the code
npm run lintContributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
MIT
0.0.1
6 months ago