Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pyth solana stub #1754

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from
Prev Previous commit
Next Next commit
Implemented test contract to test library functions in Remix IDE
  • Loading branch information
lopeselio committed Jun 25, 2024
commit 4ccc1dd5b9188afd6a8aa6e906a2860dfe3a7326
34 changes: 34 additions & 0 deletions target_chains/ethereum/sdk/solidity/PriceCombineTest.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// SPDX-License-Identifier: Apache 2
pragma solidity ^0.8.0;

import "./PythStructs.sol";
import "./PriceCombine.sol";

// This contract is used to test the library functions and tested in Remix IDE. All ABIs are present in the /abis folder
contract PriceCombineTest {
using PriceCombine for PythStructs.Price;

/**
* @notice Test the getPriceInQuote function
* @param basePrice The price of the base currency (example: SOL/USD) 13913000000 (represents the current SOL/USD $139.13 with 8 decimal places)
* @param baseConf The confidence interval of the base currency
* @param baseExpo The exponent of the base currency (here: -8 -> 8 decimal units) indicates price is scaled by 10^-8
* @param basePublishTime The publish time of the base currency (UNIX timestamp)
* @param quotePrice The price of the quote currency (example: ETH/USD) 341853000000 (represents the current ETH/USD $3418.53 with 8 decimal places)
* @param quoteConf The confidence interval of the quote currency
* @param quoteExpo The exponent of the quote currency (here: -8 -> 8 decimal units) indicates price is scaled by 10^-8
* @param quotePublishTime The publish time of the quote currency (UNIX timestamp)
* @param resultExpo The desired exponent for the result (here: -8)
* @return The price, confidence interval, exponent, and publish time of the resulting price
*/
function testGetPriceInQuote(int64 basePrice, uint64 baseConf, int32 baseExpo, uint basePublishTime,
int64 quotePrice, uint64 quoteConf, int32 quoteExpo, uint quotePublishTime,
int32 resultExpo) public pure returns (int64, uint64, int32, uint) {
PythStructs.Price memory base = PythStructs.Price(basePrice, baseConf, baseExpo, basePublishTime);
PythStructs.Price memory quote = PythStructs.Price(quotePrice, quoteConf, quoteExpo, quotePublishTime);
PythStructs.Price memory result = base.getPriceInQuote(quote, resultExpo);
return (result.price, result.conf, result.expo, result.publishTime);
}

// Add more test functions as needed
}