Skip to content

Commit

Permalink
fix: Resolve the exchange rate discrepancy between blocks 9664314 and…
Browse files Browse the repository at this point in the history
… 9671174
  • Loading branch information
Carl committed Oct 7, 2024
1 parent 88a1ea5 commit 450dabb
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
6 changes: 6 additions & 0 deletions adapters/rhomarkets/src/sdk/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, 9671174n];

export const FIXED_EXCHANGE_RATE = 1020933877280826510n;
30 changes: 22 additions & 8 deletions adapters/rhomarkets/src/sdk/marketDetails.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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,
Expand All @@ -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
),
});
}

Expand Down

0 comments on commit 450dabb

Please sign in to comment.