Skip to content

Commit

Permalink
Fix/rho markets (#21)
Browse files Browse the repository at this point in the history
* fix: Resolve the exchange rate discrepancy between blocks 9664314 and 9671174

* fix: exchange rate adjust

* fix: rho markets exchange rate

---------

Co-authored-by: Carl <[email protected]>
Co-authored-by: 0xroll <[email protected]>
  • Loading branch information
3 people authored Oct 15, 2024
1 parent 5735dcb commit 47d6fce
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, 10135815n];

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 47d6fce

Please sign in to comment.