Skip to content
Merged
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;

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

/// @dev The hash of the meta that describes the contract.
bytes32 constant DESCRIBED_BY_META_HASH = bytes32(0xe7bb5842b2cf1d25681a9885109fbf8943495bcebb9ec049bc3790e5db57fa80);
Expand Down
39 changes: 39 additions & 0 deletions src/lib/pyth/LibPyth.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,38 +24,69 @@ library LibPyth {
/// Google.
bytes32 constant PRICE_FEED_ID_EQUITY_US_GOOG_USD =
0xe65ff435be42630439c96396653a342829e877e2aafaeaf1a10d0ee5fd2cf3f2;
// slither-disable-next-line too-many-digits
uint256 constant PRICE_FEED_SYMBOL_INTORASTRING_EQUITY_US_GOOG_USD =
0x924571756974792e55532e474f4f472f55534400000000000000000000000000;
/// Amazon.
bytes32 constant PRICE_FEED_ID_EQUITY_US_AMZN_USD =
0xb5d0e0fa58a1f8b81498ae670ce93c872d14434b72c364885d4fa1b257cbb07a;
// slither-disable-next-line too-many-digits
uint256 constant PRICE_FEED_SYMBOL_INTORASTRING_EQUITY_US_AMZN_USD =
0x924571756974792e55532e414d5a4e2f55534400000000000000000000000000;
/// Apple.
bytes32 constant PRICE_FEED_ID_EQUITY_US_AAPL_USD =
0x49f6b65cb1de6b10eaf75e7c03ca029c306d0357e91b5311b175084a5ad55688;
// slither-disable-next-line too-many-digits
uint256 constant PRICE_FEED_SYMBOL_INTORASTRING_EQUITY_US_AAPL_USD =
0x924571756974792e55532e4141504c2f55534400000000000000000000000000;
/// Microsoft.
bytes32 constant PRICE_FEED_ID_EQUITY_US_MSFT_USD =
0xd0ca23c1cc005e004ccf1db5bf76aeb6a49218f43dac3d4b275e92de12ded4d1;
// slither-disable-next-line too-many-digits
uint256 constant PRICE_FEED_SYMBOL_INTORASTRING_EQUITY_US_MSFT_USD =
0x924571756974792e55532e4d5346542f55534400000000000000000000000000;
/// Tesla.
bytes32 constant PRICE_FEED_ID_EQUITY_US_TSLA_USD =
0x16dad506d7db8da01c87581c87ca897a012a153557d4d578c3b9c9e1bc0632f1;
// slither-disable-next-line too-many-digits
uint256 constant PRICE_FEED_SYMBOL_INTORASTRING_EQUITY_US_TSLA_USD =
0x924571756974792e55532e54534c412f55534400000000000000000000000000;
/// Nvidia.
bytes32 constant PRICE_FEED_ID_EQUITY_US_NVDA_USD =
0xb1073854ed24cbc755dc527418f52b7d271f6cc967bbf8d8129112b18860a593;
// slither-disable-next-line too-many-digits
uint256 constant PRICE_FEED_SYMBOL_INTORASTRING_EQUITY_US_NVDA_USD =
0x924571756974792e55532e4e5644412f55534400000000000000000000000000;
/// Meta Platforms (Facebook).
bytes32 constant PRICE_FEED_ID_EQUITY_US_META_USD =
0x78a3e3b8e676a8f73c439f5d749737034b139bbbe899ba5775216fba596607fe;
// slither-disable-next-line too-many-digits
uint256 constant PRICE_FEED_SYMBOL_INTORASTRING_EQUITY_US_META_USD =
0x924571756974792e55532e4d4554412f55534400000000000000000000000000;
/// Gamestop
bytes32 constant PRICE_FEED_ID_EQUITY_US_GME_USD =
0x6f9cd89ef1b7fd39f667101a91ad578b6c6ace4579d5f7f285a4b06aa4504be6;
// slither-disable-next-line too-many-digits
uint256 constant PRICE_FEED_SYMBOL_INTORASTRING_EQUITY_US_GME_USD =
0x914571756974792e55532e474d452f5553440000000000000000000000000000;
/// MicroStrategy (MSTR)
bytes32 constant PRICE_FEED_ID_EQUITY_US_MSTR_USD =
0xe1e80251e5f5184f2195008382538e847fafc36f751896889dd3d1b1f6111f09;
// slither-disable-next-line too-many-digits
uint256 constant PRICE_FEED_SYMBOL_INTORASTRING_EQUITY_US_MSTR_USD =
0x924571756974792e55532e4d5354522f55534400000000000000000000000000;
/// Berkshire Hathaway Class B (BRK-B)
bytes32 constant PRICE_FEED_ID_EQUITY_US_BRK_B_USD =
0xe21c688b7fc65b4606a50f3635f466f6986db129bf16979875d160f9c508e8c7;
// slither-disable-next-line too-many-digits
uint256 constant PRICE_FEED_SYMBOL_INTORASTRING_EQUITY_US_BRK_B_USD =
0x934571756974792e55532e42524b2d422f555344000000000000000000000000;
/// SPDR Portfolio S&P 500 ETF (SPLG)
bytes32 constant PRICE_FEED_ID_EQUITY_US_SPLG_USD =
0x4dfbf28d72ab41a878afcd4c6d5e9593dca7cf65a0da739cbad9b7414004f82d;
// slither-disable-next-line too-many-digits
uint256 constant PRICE_FEED_SYMBOL_INTORASTRING_EQUITY_US_SPLG_USD =
0x924571756974792e55532e53504c472f55534400000000000000000000000000;

/// TODO replace with O(1) lookup table.
function getPriceFeedContract(uint256 chainId) internal pure returns (IPyth) {
Expand Down Expand Up @@ -85,6 +116,14 @@ library LibPyth {
return PRICE_FEED_ID_EQUITY_US_NVDA_USD;
} else if (feedSymbol == PRICE_FEED_SYMBOL_INTORASTRING_EQUITY_US_META_USD) {
return PRICE_FEED_ID_EQUITY_US_META_USD;
} else if (feedSymbol == PRICE_FEED_SYMBOL_INTORASTRING_EQUITY_US_GME_USD) {
return PRICE_FEED_ID_EQUITY_US_GME_USD;
} else if (feedSymbol == PRICE_FEED_SYMBOL_INTORASTRING_EQUITY_US_MSTR_USD) {
return PRICE_FEED_ID_EQUITY_US_MSTR_USD;
} else if (feedSymbol == PRICE_FEED_SYMBOL_INTORASTRING_EQUITY_US_BRK_B_USD) {
return PRICE_FEED_ID_EQUITY_US_BRK_B_USD;
} else if (feedSymbol == PRICE_FEED_SYMBOL_INTORASTRING_EQUITY_US_SPLG_USD) {
return PRICE_FEED_ID_EQUITY_US_SPLG_USD;
} else {
revert UnsupportedFeedSymbol();
}
Expand Down
2 changes: 1 addition & 1 deletion test/lib/LibFork.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ string constant FORK_RPC_URL_ARBITRUM = "https://arbitrum.gateway.tenderly.co";
string constant FORK_RPC_URL_BASE = "https://base.gateway.tenderly.co";

uint256 constant FORK_BLOCK_ARBITRUM = 345270769;
uint256 constant FORK_BLOCK_BASE = 31309429;
uint256 constant FORK_BLOCK_BASE = 36353737;
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 @@ -41,5 +41,21 @@ contract LibPythConstantsTest is Test {
LibPyth.PRICE_FEED_SYMBOL_INTORASTRING_EQUITY_US_META_USD,
IntOrAString.unwrap(LibIntOrAString.fromString2("Equity.US.META/USD"))
);
assertEq(
LibPyth.PRICE_FEED_SYMBOL_INTORASTRING_EQUITY_US_GME_USD,
IntOrAString.unwrap(LibIntOrAString.fromString2("Equity.US.GME/USD"))
);
assertEq(
LibPyth.PRICE_FEED_SYMBOL_INTORASTRING_EQUITY_US_MSTR_USD,
IntOrAString.unwrap(LibIntOrAString.fromString2("Equity.US.MSTR/USD"))
);
assertEq(
LibPyth.PRICE_FEED_SYMBOL_INTORASTRING_EQUITY_US_BRK_B_USD,
IntOrAString.unwrap(LibIntOrAString.fromString2("Equity.US.BRK-B/USD"))
);
assertEq(
LibPyth.PRICE_FEED_SYMBOL_INTORASTRING_EQUITY_US_SPLG_USD,
IntOrAString.unwrap(LibIntOrAString.fromString2("Equity.US.SPLG/USD"))
);
}
}
20 changes: 20 additions & 0 deletions test/src/lib/pyth/LibPyth.getPriceFeedId.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,22 @@ contract LibPythGetPriceFeedIdTest is Test {
LibPyth.PRICE_FEED_ID_EQUITY_US_META_USD,
LibPyth.getPriceFeedId(LibIntOrAString.fromString2("Equity.US.META/USD"))
);
assertEq(
LibPyth.PRICE_FEED_ID_EQUITY_US_GME_USD,
LibPyth.getPriceFeedId(LibIntOrAString.fromString2("Equity.US.GME/USD"))
);
assertEq(
LibPyth.PRICE_FEED_ID_EQUITY_US_MSTR_USD,
LibPyth.getPriceFeedId(LibIntOrAString.fromString2("Equity.US.MSTR/USD"))
);
assertEq(
LibPyth.PRICE_FEED_ID_EQUITY_US_BRK_B_USD,
LibPyth.getPriceFeedId(LibIntOrAString.fromString2("Equity.US.BRK-B/USD"))
);
assertEq(
LibPyth.PRICE_FEED_ID_EQUITY_US_SPLG_USD,
LibPyth.getPriceFeedId(LibIntOrAString.fromString2("Equity.US.SPLG/USD"))
);
}

function testPriceFeedIdUnknownMappings(IntOrAString symbol) external {
Expand All @@ -52,6 +68,10 @@ contract LibPythGetPriceFeedIdTest is Test {
&& IntOrAString.unwrap(symbol) != IntOrAString.unwrap(LibIntOrAString.fromString2("Equity.US.TSLA/USD"))
&& IntOrAString.unwrap(symbol) != IntOrAString.unwrap(LibIntOrAString.fromString2("Equity.US.NVDA/USD"))
&& IntOrAString.unwrap(symbol) != IntOrAString.unwrap(LibIntOrAString.fromString2("Equity.US.META/USD"))
&& IntOrAString.unwrap(symbol) != IntOrAString.unwrap(LibIntOrAString.fromString2("Equity.US.GME/USD"))
&& IntOrAString.unwrap(symbol) != IntOrAString.unwrap(LibIntOrAString.fromString2("Equity.US.MSTR/USD"))
&& IntOrAString.unwrap(symbol) != IntOrAString.unwrap(LibIntOrAString.fromString2("Equity.US.BRK-B/USD"))
&& IntOrAString.unwrap(symbol) != IntOrAString.unwrap(LibIntOrAString.fromString2("Equity.US.SPLG/USD"))
);
vm.expectRevert(UnsupportedFeedSymbol.selector);
this.getPriceFeedIdExternal(symbol);
Expand Down
22 changes: 15 additions & 7 deletions test/src/lib/pyth/LibPyth.getPriceNoOlderThan.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,21 @@ contract LibPythGetPriceNoOlderThanTest is Test {
checkPriceNoOlderThan(LibIntOrAString.fromString2("Equity.US.TSLA/USD"), 300 hours, 360.02978e18);
checkPriceNoOlderThan(LibIntOrAString.fromString2("Equity.US.NVDA/USD"), 1000 hours, 104.5623e18);
checkPriceNoOlderThan(LibIntOrAString.fromString2("Equity.US.META/USD"), 8000 hours, 448.73e18);
checkPriceNoOlderThan(LibIntOrAString.fromString2("Equity.US.GME/USD"), 8000 hours, 29.3177e18);
}

function testPriceNoOlderThanBase() external {
vm.createSelectFork(FORK_RPC_URL_BASE, FORK_BLOCK_BASE);
checkPriceNoOlderThan(LibIntOrAString.fromString2("Equity.US.GOOG/USD"), 72 hours, 174.93179e18);
checkPriceNoOlderThan(LibIntOrAString.fromString2("Equity.US.AMZN/USD"), 500 hours, 207.372e18);
checkPriceNoOlderThan(LibIntOrAString.fromString2("Equity.US.AAPL/USD"), 72 hours, 205.12e18);
checkPriceNoOlderThan(LibIntOrAString.fromString2("Equity.US.MSFT/USD"), 300 hours, 458.35309e18);
checkPriceNoOlderThan(LibIntOrAString.fromString2("Equity.US.TSLA/USD"), 72 hours, 301.47341e18);
checkPriceNoOlderThan(LibIntOrAString.fromString2("Equity.US.NVDA/USD"), 72 hours, 141.66994e18);
checkPriceNoOlderThan(LibIntOrAString.fromString2("Equity.US.META/USD"), 72 hours, 693.349e18);
checkPriceNoOlderThan(LibIntOrAString.fromString2("Equity.US.GOOG/USD"), 24 hours, 246.29352e18);
checkPriceNoOlderThan(LibIntOrAString.fromString2("Equity.US.AMZN/USD"), 24 hours, 222.43512e18);
checkPriceNoOlderThan(LibIntOrAString.fromString2("Equity.US.AAPL/USD"), 24 hours, 257.33026e18);
checkPriceNoOlderThan(LibIntOrAString.fromString2("Equity.US.MSFT/USD"), 24 hours, 515.64431e18);
checkPriceNoOlderThan(LibIntOrAString.fromString2("Equity.US.TSLA/USD"), 24 hours, 436.03414e18);
checkPriceNoOlderThan(LibIntOrAString.fromString2("Equity.US.NVDA/USD"), 24 hours, 188.92e18);
checkPriceNoOlderThan(LibIntOrAString.fromString2("Equity.US.META/USD"), 24 hours, 727.0145e18);
checkPriceNoOlderThan(LibIntOrAString.fromString2("Equity.US.GME/USD"), 24 hours, 27.24202e18);
checkPriceNoOlderThan(LibIntOrAString.fromString2("Equity.US.MSTR/USD"), 24 hours, 352.34642e18);
checkPriceNoOlderThan(LibIntOrAString.fromString2("Equity.US.BRK-B/USD"), 24 hours, 496.12003e18);
checkPriceNoOlderThan(LibIntOrAString.fromString2("Equity.US.SPLG/USD"), 24 hours, 78.71367e18);
}
}