Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/generated/PythWords.pointers.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pragma solidity ^0.8.25;
// file needs the contract to exist so that it can be compiled.

/// @dev Hash of the known bytecode.
bytes32 constant BYTECODE_HASH = bytes32(0x5d94c45d9a500c4e7faac0ed6cce231d1c5fd68d3a4a2783213dc5ae00c8fe97);
bytes32 constant BYTECODE_HASH = bytes32(0x722de02276682e53411ffcc00f434daadbc3540bc68d3c26d5582e9b7a4874fb);

/// @dev The hash of the meta that describes the contract.
bytes32 constant DESCRIBED_BY_META_HASH = bytes32(0xe7bb5842b2cf1d25681a9885109fbf8943495bcebb9ec049bc3790e5db57fa80);
Expand Down
32 changes: 32 additions & 0 deletions src/lib/pyth/LibPyth.sol
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,30 @@ library LibPyth {
// slither-disable-next-line too-many-digits
uint256 constant PRICE_FEED_SYMBOL_INTORASTRING_EQUITY_US_ARKK_USD =
uint256(0x924571756974792e55532e41524b4b2f55534400000000000000000000000000);
/// CEG/USD
bytes32 constant PRICE_FEED_ID_EQUITY_US_CEG_USD =
0xa541bc5c4b69961442e45e9198c7cce151ff9c2a1003f620c6d4a9785c77a4d9;
// slither-disable-next-line too-many-digits
uint256 constant PRICE_FEED_SYMBOL_INTORASTRING_EQUITY_US_CEG_USD =
uint256(0x914571756974792e55532e4345472f5553440000000000000000000000000000);
/// TSM/USD
bytes32 constant PRICE_FEED_ID_EQUITY_US_TSM_USD =
0xe722560a66e4ab00522ef20a38fa2ba5d1b41f1c5404723ed895d202a7af7cc4;
// slither-disable-next-line too-many-digits
uint256 constant PRICE_FEED_SYMBOL_INTORASTRING_EQUITY_US_TSM_USD =
uint256(0x914571756974792e55532e54534d2f5553440000000000000000000000000000);
/// TSM/USD.PRE
bytes32 constant PRICE_FEED_ID_EQUITY_US_TSM_USD_PRE =
0x6ad383437975189ea6ff0efad3de790d34ff36091a5a24c965e5f047a5de45de;
// slither-disable-next-line too-many-digits
uint256 constant PRICE_FEED_SYMBOL_INTORASTRING_EQUITY_US_TSM_USD_PRE =
uint256(0x954571756974792e55532e54534d2f5553442e50524500000000000000000000);
/// TSM/USD.POST
bytes32 constant PRICE_FEED_ID_EQUITY_US_TSM_USD_POST =
0x763b87165de66edfce13a7c98c13eb781a44b01ff474b61a6155833b12a65ec3;
// slither-disable-next-line too-many-digits
uint256 constant PRICE_FEED_SYMBOL_INTORASTRING_EQUITY_US_TSM_USD_POST =
uint256(0x964571756974792e55532e54534d2f5553442e504f5354000000000000000000);

/// TODO replace with O(1) lookup table.
function getPriceFeedContract(uint256 chainId) internal pure returns (IPyth) {
Expand Down Expand Up @@ -422,6 +446,14 @@ library LibPyth {
return PRICE_FEED_ID_EQUITY_US_VWO_USD;
} else if (feedSymbol == PRICE_FEED_SYMBOL_INTORASTRING_EQUITY_US_ARKK_USD) {
return PRICE_FEED_ID_EQUITY_US_ARKK_USD;
} else if (feedSymbol == PRICE_FEED_SYMBOL_INTORASTRING_EQUITY_US_CEG_USD) {
return PRICE_FEED_ID_EQUITY_US_CEG_USD;
} else if (feedSymbol == PRICE_FEED_SYMBOL_INTORASTRING_EQUITY_US_TSM_USD) {
return PRICE_FEED_ID_EQUITY_US_TSM_USD;
} else if (feedSymbol == PRICE_FEED_SYMBOL_INTORASTRING_EQUITY_US_TSM_USD_PRE) {
return PRICE_FEED_ID_EQUITY_US_TSM_USD_PRE;
} else if (feedSymbol == PRICE_FEED_SYMBOL_INTORASTRING_EQUITY_US_TSM_USD_POST) {
return PRICE_FEED_ID_EQUITY_US_TSM_USD_POST;
} else {
revert UnsupportedFeedSymbol();
}
Expand Down
2 changes: 2 additions & 0 deletions test/lib/LibFork.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ uint256 constant FORK_BLOCK_BASE_SGOV = 44912388;
uint256 constant FORK_BLOCK_BASE_QQQM = 45610515;
uint256 constant FORK_BLOCK_BASE_VWO = 45610515;
uint256 constant FORK_BLOCK_BASE_ARKK = 45610515;
uint256 constant FORK_BLOCK_BASE_CEG = 46192140;
uint256 constant FORK_BLOCK_BASE_TSM = 46192140;
16 changes: 16 additions & 0 deletions test/src/lib/pyth/LibPyth.constants.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -217,5 +217,21 @@ contract LibPythConstantsTest is Test {
LibPyth.PRICE_FEED_SYMBOL_INTORASTRING_EQUITY_US_ARKK_USD,
IntOrAString.unwrap(LibIntOrAString.fromString2("Equity.US.ARKK/USD"))
);
assertEq(
LibPyth.PRICE_FEED_SYMBOL_INTORASTRING_EQUITY_US_CEG_USD,
IntOrAString.unwrap(LibIntOrAString.fromString2("Equity.US.CEG/USD"))
);
assertEq(
LibPyth.PRICE_FEED_SYMBOL_INTORASTRING_EQUITY_US_TSM_USD,
IntOrAString.unwrap(LibIntOrAString.fromString2("Equity.US.TSM/USD"))
);
assertEq(
LibPyth.PRICE_FEED_SYMBOL_INTORASTRING_EQUITY_US_TSM_USD_PRE,
IntOrAString.unwrap(LibIntOrAString.fromString2("Equity.US.TSM/USD.PRE"))
);
assertEq(
LibPyth.PRICE_FEED_SYMBOL_INTORASTRING_EQUITY_US_TSM_USD_POST,
IntOrAString.unwrap(LibIntOrAString.fromString2("Equity.US.TSM/USD.POST"))
);
}
}
22 changes: 22 additions & 0 deletions test/src/lib/pyth/LibPyth.getPriceFeedId.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,22 @@ contract LibPythGetPriceFeedIdTest is Test {
LibPyth.PRICE_FEED_ID_EQUITY_US_ARKK_USD,
LibPyth.getPriceFeedId(LibIntOrAString.fromString2("Equity.US.ARKK/USD"))
);
assertEq(
LibPyth.PRICE_FEED_ID_EQUITY_US_CEG_USD,
LibPyth.getPriceFeedId(LibIntOrAString.fromString2("Equity.US.CEG/USD"))
);
assertEq(
LibPyth.PRICE_FEED_ID_EQUITY_US_TSM_USD,
LibPyth.getPriceFeedId(LibIntOrAString.fromString2("Equity.US.TSM/USD"))
);
assertEq(
LibPyth.PRICE_FEED_ID_EQUITY_US_TSM_USD_PRE,
LibPyth.getPriceFeedId(LibIntOrAString.fromString2("Equity.US.TSM/USD.PRE"))
);
assertEq(
LibPyth.PRICE_FEED_ID_EQUITY_US_TSM_USD_POST,
LibPyth.getPriceFeedId(LibIntOrAString.fromString2("Equity.US.TSM/USD.POST"))
);
}

function testPriceFeedIdUnknownMappings(IntOrAString symbol) external {
Expand Down Expand Up @@ -272,6 +288,12 @@ contract LibPythGetPriceFeedIdTest is Test {
&& IntOrAString.unwrap(symbol) != IntOrAString.unwrap(LibIntOrAString.fromString2("Equity.US.QQQM/USD"))
&& IntOrAString.unwrap(symbol) != IntOrAString.unwrap(LibIntOrAString.fromString2("Equity.US.VWO/USD"))
&& IntOrAString.unwrap(symbol) != IntOrAString.unwrap(LibIntOrAString.fromString2("Equity.US.ARKK/USD"))
&& IntOrAString.unwrap(symbol) != IntOrAString.unwrap(LibIntOrAString.fromString2("Equity.US.CEG/USD"))
&& IntOrAString.unwrap(symbol) != IntOrAString.unwrap(LibIntOrAString.fromString2("Equity.US.TSM/USD"))
&& IntOrAString.unwrap(symbol)
!= IntOrAString.unwrap(LibIntOrAString.fromString2("Equity.US.TSM/USD.PRE"))
&& IntOrAString.unwrap(symbol)
!= IntOrAString.unwrap(LibIntOrAString.fromString2("Equity.US.TSM/USD.POST"))
);
vm.expectRevert(UnsupportedFeedSymbol.selector);
this.getPriceFeedIdExternal(symbol);
Expand Down
36 changes: 35 additions & 1 deletion test/src/lib/pyth/LibPyth.getPriceNoOlderThan.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ import {
FORK_BLOCK_BASE_SGOV,
FORK_BLOCK_BASE_QQQM,
FORK_BLOCK_BASE_VWO,
FORK_BLOCK_BASE_ARKK
FORK_BLOCK_BASE_ARKK,
FORK_BLOCK_BASE_CEG,
FORK_BLOCK_BASE_TSM
} from "test/lib/LibFork.sol";
import {IntOrAString, LibIntOrAString} from "rain.intorastring/lib/LibIntOrAString.sol";
import {Float, LibDecimalFloat} from "rain.math.float/lib/LibDecimalFloat.sol";
Expand Down Expand Up @@ -437,4 +439,36 @@ contract LibPythGetPriceNoOlderThanTest is Test {
LibDecimalFloat.packLossless(0.04361e5, -5)
);
}

function testPriceNoOlderThanBaseCeg() external {
vm.createSelectFork(FORK_RPC_URL_BASE, FORK_BLOCK_BASE_CEG);
checkPriceNoOlderThan(
LibIntOrAString.fromString2("Equity.US.CEG/USD"),
LibDecimalFloat.packLossless(24 hours, 0),
LibDecimalFloat.packLossless(262.064e5, -5),
LibDecimalFloat.packLossless(0.4233e5, -5)
);
}

function testPriceNoOlderThanBaseTsm() external {
vm.createSelectFork(FORK_RPC_URL_BASE, FORK_BLOCK_BASE_TSM);
checkPriceNoOlderThan(
LibIntOrAString.fromString2("Equity.US.TSM/USD"),
LibDecimalFloat.packLossless(24 hours, 0),
LibDecimalFloat.packLossless(396.08005e5, -5),
LibDecimalFloat.packLossless(0.23804e5, -5)
);
checkPriceNoOlderThan(
LibIntOrAString.fromString2("Equity.US.TSM/USD.PRE"),
LibDecimalFloat.packLossless(36 hours, 0),
LibDecimalFloat.packLossless(409.37e5, -5),
LibDecimalFloat.packLossless(2.37e5, -5)
);
checkPriceNoOlderThan(
LibIntOrAString.fromString2("Equity.US.TSM/USD.POST"),
LibDecimalFloat.packLossless(24 hours, 0),
LibDecimalFloat.packLossless(396.45964e5, -5),
LibDecimalFloat.packLossless(0.45688e5, -5)
);
}
}
Loading