From 91f1ec8ecc6895ae7441276dc5a505e6311d2393 Mon Sep 17 00:00:00 2001 From: kaleb <62237347+kaleb-keny@users.noreply.github.com> Date: Sat, 26 Oct 2024 01:30:24 +0200 Subject: [PATCH] Fix tbtc / btc price feed (#513) * temporary-fix this is a temporary fix, until a long term fix where real is swapped to just btc and the spot things are tbtc * version bump * Use pythFeeds.json instead of extras * Rename settings to pyth_feed_id_btc and pyth_feed_id_tbtc * Fix Use pythFeeds.json instead of extras * fix Perps_Trading.e2e.js * fix Spot_Market_BTC.e2e.js * Add tBTC collateral price before liquidating position (as both eth and tbtc were deposited as collaterals) --------- Co-authored-by: Noisekit --- e2e/tasks/doAllPriceUpdates.js | 11 +---- .../Perps_Trading.e2e.js | 4 +- .../Spot_Market_BTC.e2e.js | 2 +- omnibus-arbitrum-mainnet.toml | 6 ++- .../oracles/pyth-btc.toml | 22 +++++----- .../oracles/pyth-tbtc.toml | 40 +++++++++++++++++++ .../perps/markets/btc.toml | 2 +- tomls/omnibus-arbitrum-mainnet/spot/tbtc.toml | 2 +- 8 files changed, 62 insertions(+), 27 deletions(-) create mode 100644 tomls/omnibus-arbitrum-mainnet/oracles/pyth-tbtc.toml diff --git a/e2e/tasks/doAllPriceUpdates.js b/e2e/tasks/doAllPriceUpdates.js index 1e9766c31..de511cab3 100755 --- a/e2e/tasks/doAllPriceUpdates.js +++ b/e2e/tasks/doAllPriceUpdates.js @@ -19,16 +19,9 @@ async function doAllPriceUpdates({ wallet }) { const priceVerificationContract = extras.pyth_price_verification_address || extras.pythPriceVerificationAddress; - const possiblyDuplicateFeedIds = Object.entries(extras) - .filter( - ([key]) => - key.startsWith('pyth_feed_id_') || (key.startsWith('pyth') && key.endsWith('FeedId')) - ) - .map(([_key, value]) => value); - const feedIds = Array.from(new Set(possiblyDuplicateFeedIds)); - + const feedIds = require('../deployments/pythFeeds.json'); log({ feeds: feedIds.length, feedIds }); - const batches = splitIntoChunks(feedIds, 50); + const batches = splitIntoChunks(feedIds, 200); for (const batch of batches) { await doPriceUpdateForPyth({ wallet, feedId: batch, priceVerificationContract }); diff --git a/e2e/tests/omnibus-arbitrum-mainnet.toml/Perps_Trading.e2e.js b/e2e/tests/omnibus-arbitrum-mainnet.toml/Perps_Trading.e2e.js index 6414ed2a9..af6a9ed97 100644 --- a/e2e/tests/omnibus-arbitrum-mainnet.toml/Perps_Trading.e2e.js +++ b/e2e/tests/omnibus-arbitrum-mainnet.toml/Perps_Trading.e2e.js @@ -227,7 +227,7 @@ describe(require('path').basename(__filename, '.e2e.js'), function () { it('should wrap 5 tBTC', async () => { await doPriceUpdateForPyth({ wallet, - feedId: extras.pyth_feed_id_btc, + feedId: extras.pyth_feed_id_tbtc, priceVerificationContract: extras.pyth_price_verification_address, }); const balance = await wrapCollateral({ @@ -400,7 +400,7 @@ describe(require('path').basename(__filename, '.e2e.js'), function () { await doPriceUpdateForPyth({ wallet, - feedId: extras.pyth_feed_id_eth, + feedId: [extras.pyth_feed_id_eth, extras.pyth_feed_id_tbtc], priceVerificationContract: extras.pyth_price_verification_address, }); diff --git a/e2e/tests/omnibus-arbitrum-mainnet.toml/Spot_Market_BTC.e2e.js b/e2e/tests/omnibus-arbitrum-mainnet.toml/Spot_Market_BTC.e2e.js index e0a9c75f9..b0c106c2b 100644 --- a/e2e/tests/omnibus-arbitrum-mainnet.toml/Spot_Market_BTC.e2e.js +++ b/e2e/tests/omnibus-arbitrum-mainnet.toml/Spot_Market_BTC.e2e.js @@ -102,7 +102,7 @@ describe(require('path').basename(__filename, '.e2e.js'), function () { it(`should do strict price update`, async () => { await doPriceUpdateForPyth({ wallet, - feedId: require('../../deployments/extras.json').pyth_feed_id_btc, + feedId: require('../../deployments/extras.json').pyth_feed_id_tbtc, priceVerificationContract: require('../../deployments/extras.json') .pyth_price_verification_address, }); diff --git a/omnibus-arbitrum-mainnet.toml b/omnibus-arbitrum-mainnet.toml index 14c783b6e..39915cebf 100644 --- a/omnibus-arbitrum-mainnet.toml +++ b/omnibus-arbitrum-mainnet.toml @@ -1,5 +1,5 @@ name = "synthetix-omnibus" -version = "35" +version = "36" description = "Includes the full synthetix system with configurations applied" preset = "main" include = [ @@ -111,6 +111,7 @@ include = [ "tomls/omnibus-arbitrum-mainnet/oracles/pyth-susde.toml", "tomls/omnibus-arbitrum-mainnet/oracles/pyth-sushi.toml", "tomls/omnibus-arbitrum-mainnet/oracles/pyth-tao.toml", + "tomls/omnibus-arbitrum-mainnet/oracles/pyth-tbtc.toml", "tomls/omnibus-arbitrum-mainnet/oracles/pyth-tia.toml", "tomls/omnibus-arbitrum-mainnet/oracles/pyth-ton.toml", "tomls/omnibus-arbitrum-mainnet/oracles/pyth-trx.toml", @@ -369,7 +370,7 @@ pyth_feed_id_blur = "0x856aac602516addee497edf6f50d39e8c95ae5fb0da1ed434a8c2ab9c pyth_feed_id_bnb = "0x2f95862b045670cd22bee3114c39763a4a08beeb663b145d283c31d7d1101c4f" pyth_feed_id_bome = "0x30e4780570973e438fdb3f1b7ad22618b2fc7333b65c7853a7ca144c39052f7a" pyth_feed_id_bonk = "0x72b021217ca3fe68922a19aaf990109cb9d84e9ad004b4d2025ad6f529314419" -pyth_feed_id_btc = "0x56a3121958b01f99fdc4e1fd01e81050602c7ace3a571918bb55c6a96657cca9" +pyth_feed_id_btc = "0xe62df6c8b4a85fe1a67db44dc12de5db330f7ac66b72dc658afedf0f4a415b43" pyth_feed_id_comp = "0x4a8e42861cabc5ecb50996f92e7cfa2bce3fd0a2423b0c44c9b423fb2bd25478" pyth_feed_id_crv = "0xa19d04ac696c7a6616d291c7e5d1377cc8be437c327b75adb5dc1bad745fcae8" pyth_feed_id_doge = "0xdcef50dd0a4cd2dcc17e45df1676dcb336a11a61c69df7a0299b0150c672d25c" @@ -424,6 +425,7 @@ pyth_feed_id_sui = "0x23d7315113f5b1d3ba7a83604c44b94d79f4fd69af77f804fc7f920a6d pyth_feed_id_susde = "0xca3ba9a619a4b3755c10ac7d5e760275aa95e9823d38a84fedd416856cdba37c" pyth_feed_id_sushi = "0x26e4f737fde0263a9eea10ae63ac36dcedab2aaf629261a994e1eeb6ee0afe53" pyth_feed_id_tao = "0x410f41de235f2db824e562ea7ab2d3d3d4ff048316c61d629c0b93f58584e1af" +pyth_feed_id_tbtc = "0x56a3121958b01f99fdc4e1fd01e81050602c7ace3a571918bb55c6a96657cca9" pyth_feed_id_tia = "0x09f7c1d7dfbb7df2b8fe3d3d87ee94a2259d212da4f30c1f0540d066dfa44723" pyth_feed_id_ton = "0x8963217838ab4cf5cadc172203c1f0b763fbaa45f346d8ee50ba994bbcac3026" pyth_feed_id_trx = "0x67aed5a24fdad045475e7195c98a98aea119c763f272d4523f5bac93a4f33c2b" diff --git a/tomls/omnibus-arbitrum-mainnet/oracles/pyth-btc.toml b/tomls/omnibus-arbitrum-mainnet/oracles/pyth-btc.toml index ef8bc3a10..d0afd73a4 100644 --- a/tomls/omnibus-arbitrum-mainnet/oracles/pyth-btc.toml +++ b/tomls/omnibus-arbitrum-mainnet/oracles/pyth-btc.toml @@ -1,4 +1,4 @@ -[invoke.OracleManagerProxy_registerNode_pyth_BTC] +[invoke.OracleManagerProxy_registerNode_pyth_real_BTC] description = "Latest Pyth Price. This registers a staleness node that looks to Pyth for a fresh enough price, or otherwise reverts with an ERC-7412 compatible error" target = ["system.oracle_manager.Proxy"] func = "registerNode" @@ -8,10 +8,10 @@ args = [ [ ], ] -extra.btc_pyth_oracle_id.event = "NodeRegistered" -extra.btc_pyth_oracle_id.arg = 0 +extra.real_btc_pyth_oracle_id.event = "NodeRegistered" +extra.real_btc_pyth_oracle_id.arg = 0 -[invoke.OracleManagerProxy_registerNode_pyth_offchain_lookup_BTC] +[invoke.OracleManagerProxy_registerNode_pyth_offchain_lookup_real_BTC] description = "Pyth Off-chain Lookup" target = ["system.oracle_manager.Proxy"] func = "registerNode" @@ -21,20 +21,20 @@ args = [ [ ], ] -extra.btc_lookup_oracle_id.event = "NodeRegistered" -extra.btc_lookup_oracle_id.arg = 0 +extra.real_btc_lookup_oracle_id.event = "NodeRegistered" +extra.real_btc_lookup_oracle_id.arg = 0 # Staleness Node -[invoke.OracleManagerProxy_registerNode_staleness_BTC] +[invoke.OracleManagerProxy_registerNode_staleness_real_BTC] target = ["system.oracle_manager.Proxy"] func = "registerNode" args = [ 7, # 7 = staleness circuit breaker "<%= defaultAbiCoder.encode(['uint256'], [settings.default_staleness_tolerance]) %>", [ - "<%= extras.btc_pyth_oracle_id %>", - "<%= extras.btc_lookup_oracle_id %>", + "<%= extras.real_btc_pyth_oracle_id %>", + "<%= extras.real_btc_lookup_oracle_id %>", ], ] -extra.btc_oracle_id.event = "NodeRegistered" -extra.btc_oracle_id.arg = 0 +extra.real_btc_oracle_id.event = "NodeRegistered" +extra.real_btc_oracle_id.arg = 0 diff --git a/tomls/omnibus-arbitrum-mainnet/oracles/pyth-tbtc.toml b/tomls/omnibus-arbitrum-mainnet/oracles/pyth-tbtc.toml new file mode 100644 index 000000000..5937b876d --- /dev/null +++ b/tomls/omnibus-arbitrum-mainnet/oracles/pyth-tbtc.toml @@ -0,0 +1,40 @@ +[invoke.OracleManagerProxy_registerNode_pyth_BTC] +description = "Latest Pyth Price. This registers a staleness node that looks to Pyth for a fresh enough price, or otherwise reverts with an ERC-7412 compatible error" +target = ["system.oracle_manager.Proxy"] +func = "registerNode" +args = [ + 5, # 5 = pyth aggregator type + "<%= defaultAbiCoder.encode(['address', 'bytes32', 'bool'], [settings.pyth_price_verification_address, settings.pyth_feed_id_tbtc, false]) %>", + [ + ], +] +extra.btc_pyth_oracle_id.event = "NodeRegistered" +extra.btc_pyth_oracle_id.arg = 0 + +[invoke.OracleManagerProxy_registerNode_pyth_offchain_lookup_BTC] +description = "Pyth Off-chain Lookup" +target = ["system.oracle_manager.Proxy"] +func = "registerNode" +args = [ + 9, # 9 = PythOffchainLookupNode + "<%= defaultAbiCoder.encode(['address', 'bytes32', 'uint256'], [imports.pyth_erc7412_wrapper.contracts.PythERC7412Wrapper.address, settings.pyth_feed_id_tbtc, settings.default_staleness_tolerance]) %>", + [ + ], +] +extra.btc_lookup_oracle_id.event = "NodeRegistered" +extra.btc_lookup_oracle_id.arg = 0 + +# Staleness Node +[invoke.OracleManagerProxy_registerNode_staleness_BTC] +target = ["system.oracle_manager.Proxy"] +func = "registerNode" +args = [ + 7, # 7 = staleness circuit breaker + "<%= defaultAbiCoder.encode(['uint256'], [settings.default_staleness_tolerance]) %>", + [ + "<%= extras.btc_pyth_oracle_id %>", + "<%= extras.btc_lookup_oracle_id %>", + ], +] +extra.btc_oracle_id.event = "NodeRegistered" +extra.btc_oracle_id.arg = 0 diff --git a/tomls/omnibus-arbitrum-mainnet/perps/markets/btc.toml b/tomls/omnibus-arbitrum-mainnet/perps/markets/btc.toml index 08e7e6ecd..f9059d42f 100644 --- a/tomls/omnibus-arbitrum-mainnet/perps/markets/btc.toml +++ b/tomls/omnibus-arbitrum-mainnet/perps/markets/btc.toml @@ -30,7 +30,7 @@ fromCall.func = "owner" func = "updatePriceData" args = [ "<%= settings.btc_perps_market_id %>", - "<%= extras.btc_oracle_id %>", + "<%= extras.real_btc_oracle_id %>", "<%= settings.strict_staleness_tolerance %>", ] diff --git a/tomls/omnibus-arbitrum-mainnet/spot/tbtc.toml b/tomls/omnibus-arbitrum-mainnet/spot/tbtc.toml index e1c8c7d56..7b387aea1 100644 --- a/tomls/omnibus-arbitrum-mainnet/spot/tbtc.toml +++ b/tomls/omnibus-arbitrum-mainnet/spot/tbtc.toml @@ -74,7 +74,7 @@ func = "setSettlementStrategy" args = [ "<%= extras.synth_btc_market_id %>", "<%= extras.synth_btc_settlement_strategy_id %>", - { strategyType = "1", settlementDelay = "<%= settings.settlement_delay %>", settlementWindowDuration = "<%= settings.settlement_window_duration %>", priceVerificationContract = "<%= imports.pyth_erc7412_wrapper.contracts.PythERC7412Wrapper.address %>", feedId = "<%= settings.pyth_feed_id_btc %>", url = "<%= settings.pyth_feed_url %>", settlementReward = "<%= settings.settlement_reward %>", minimumUsdExchangeAmount = "<%= settings.settlement_minimum_usd_exchange_amount %>", maxRoundingLoss = "<%= settings.settlement_max_rounding_loss %>", priceDeviationTolerance = "<%= settings.price_deviation_tolerance %>", disabled = true }, + { strategyType = "1", settlementDelay = "<%= settings.settlement_delay %>", settlementWindowDuration = "<%= settings.settlement_window_duration %>", priceVerificationContract = "<%= imports.pyth_erc7412_wrapper.contracts.PythERC7412Wrapper.address %>", feedId = "<%= settings.pyth_feed_id_tbtc %>", url = "<%= settings.pyth_feed_url %>", settlementReward = "<%= settings.settlement_reward %>", minimumUsdExchangeAmount = "<%= settings.settlement_minimum_usd_exchange_amount %>", maxRoundingLoss = "<%= settings.settlement_max_rounding_loss %>", priceDeviationTolerance = "<%= settings.price_deviation_tolerance %>", disabled = true }, ] # note that the actual btc price feed is used due to lack of liquidity of tbtc spot token, until a better redemption price is available [invoke.CoreProxy_configureCollateral_tBTC]