From 47d6fce0a54fa3228af2a8e9e58c5dfda276cbf1 Mon Sep 17 00:00:00 2001 From: Carl Wiles <131632522+CarlWiles@users.noreply.github.com> Date: Tue, 15 Oct 2024 20:27:03 +0800 Subject: [PATCH] Fix/rho markets (#21) * fix: Resolve the exchange rate discrepancy between blocks 9664314 and 9671174 * fix: exchange rate adjust * fix: rho markets exchange rate --------- Co-authored-by: Carl Co-authored-by: 0xroll <96259407+0xroll@users.noreply.github.com> --- adapters/rhomarkets/src/sdk/config.ts | 6 ++++ adapters/rhomarkets/src/sdk/marketDetails.ts | 30 ++++++++++++++------ 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/adapters/rhomarkets/src/sdk/config.ts b/adapters/rhomarkets/src/sdk/config.ts index 05bf245..e4e70c5 100644 --- a/adapters/rhomarkets/src/sdk/config.ts +++ b/adapters/rhomarkets/src/sdk/config.ts @@ -22,3 +22,9 @@ export const RPC_URLS = { export const WETH_ADDRESS = { [CHAINS.SCROLL]: "0x5300000000000000000000000000000000000004", }; + +export const rUSDC_ADDRESS = "0xAE1846110F72f2DaaBC75B7cEEe96558289EDfc5"; + +export const FIXED_BLOCK_NUMS = [9664314n, 10135815n]; + +export const FIXED_EXCHANGE_RATE = 1020933877280826510n; diff --git a/adapters/rhomarkets/src/sdk/marketDetails.ts b/adapters/rhomarkets/src/sdk/marketDetails.ts index 856bb4e..c90a234 100644 --- a/adapters/rhomarkets/src/sdk/marketDetails.ts +++ b/adapters/rhomarkets/src/sdk/marketDetails.ts @@ -1,5 +1,11 @@ import { createPublicClient, extractChain, http, getContract } from "viem"; -import { CHAINS, RPC_URLS } from "./config"; +import { + CHAINS, + FIXED_BLOCK_NUMS, + FIXED_EXCHANGE_RATE, + RPC_URLS, + rUSDC_ADDRESS, +} from "./config"; import { scroll } from "viem/chains"; import coreAbi from "./abi/core.abi"; import ltokenAbi from "./abi/ltoken.abi"; @@ -75,9 +81,8 @@ export const getMarketInfos = async ( functionName: "symbol", })) as any, }); - - const exchangeRateResults = await publicClient.multicall({ + let exchangeRateResults = await publicClient.multicall({ contracts: markets.map((m) => ({ address: m.address, abi: m.abi, @@ -92,16 +97,25 @@ export const getMarketInfos = async ( const marketAddress = markets[i].address.toLowerCase(); const underlyingAddress = underlyingAddresses[i]; + // Fix rUSDC exchange rate issue that occurred between blocks 9664314 and 9671174 + const fixedUSDCBlockData = + marketAddress.toLowerCase() === rUSDC_ADDRESS.toLowerCase() && + blockNumber && + blockNumber > FIXED_BLOCK_NUMS[0] && + blockNumber < FIXED_BLOCK_NUMS[1]; + marketInfos.push({ address: marketAddress, underlyingAddress, decimals: (decimalResults[i].result as number) || 0, underlyingSymbol: (underlyingSymbolResults[i].result as any) || "ETH", - exchangeRateStored: BigInt( - exchangeRateResults[i].status === "success" - ? (exchangeRateResults[i].result as any) - : 0 - ), + exchangeRateStored: fixedUSDCBlockData + ? FIXED_EXCHANGE_RATE + : BigInt( + exchangeRateResults[i].status === "success" + ? (exchangeRateResults[i].result as any) + : 0 + ), }); }