Skip to content

Commit 3e3333f

Browse files
committed
Fix failing test in Uniswap V3 handler
1 parent e973889 commit 3e3333f

File tree

3 files changed

+21
-14
lines changed

3 files changed

+21
-14
lines changed

subgraphs/ethereum/src/liquidity/LiquidityUniswapV3.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ export function getUniswapV3PairTotalValue(pairAddress: string, excludeOhmValue:
278278

279279
// If the token is OHM, add the balance to the OHM balance
280280
if (currentToken.toLowerCase() == ERC20_OHM_V2.toLowerCase()) {
281+
log.debug("getUniswapV3PairTotalValue: Adding OHM balance for pair {}: {}", [getContractName(pairAddress), ohmBalance.toString()])
281282
ohmBalance = ohmBalance.plus(currentBalance);
282283
}
283284

subgraphs/ethereum/src/utils/ContractHelper.ts

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -344,11 +344,13 @@ export function getERC20DecimalBalance(tokenAddress: string, walletAddress: stri
344344
const tokenSnapshot = getOrCreateERC20TokenSnapshot(tokenAddress, blockNumber);
345345
const tokenContract = getERC20(tokenAddress, blockNumber);
346346
if (tokenContract === null || tokenSnapshot.totalSupply === null) {
347+
log.info("getERC20DecimalBalance: totalSupply is zero. Token: {}", [getContractName(tokenAddress)]);
347348
return BigDecimal.zero();
348349
}
349350

350351
const balanceResult = tokenContract.try_balanceOf(Address.fromString(walletAddress));
351352
if (balanceResult.reverted) {
353+
log.info("getERC20DecimalBalance: balanceOf() reverted. Token: {}, wallet: {}, block: {}", [getContractName(tokenAddress), getContractName(walletAddress), blockNumber.toString()]);
352354
return BigDecimal.zero();
353355
}
354356

@@ -529,12 +531,12 @@ export function getERC20TokenRecordFromWallet(
529531
/**
530532
* Generates TokenRecord objects for the given ERC20 token, representing deposits into a
531533
* Vendor Finance market.
532-
*
533-
* @param timestamp
534-
* @param contractAddress
535-
* @param rate
536-
* @param blockNumber
537-
* @returns
534+
*
535+
* @param timestamp
536+
* @param contractAddress
537+
* @param rate
538+
* @param blockNumber
539+
* @returns
538540
*/
539541
export function getVendorFinanceRecords(
540542
timestamp: BigInt,
@@ -584,12 +586,12 @@ export function getVendorFinanceRecords(
584586
/**
585587
* Generates TokenRecord objects for the given ERC20 token, representing deposits into a
586588
* Myso Finance market.
587-
*
588-
* @param timestamp
589-
* @param contractAddress
590-
* @param rate
591-
* @param blockNumber
592-
* @returns
589+
*
590+
* @param timestamp
591+
* @param contractAddress
592+
* @param rate
593+
* @param blockNumber
594+
* @returns
593595
*/
594596
export function getMysoFinanceRecords(
595597
timestamp: BigInt,

subgraphs/ethereum/tests/price.test.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import {
2929
ERC20_FXS,
3030
ERC20_OHM_V1,
3131
ERC20_OHM_V2,
32+
ERC20_OHM_V2_BLOCK,
3233
ERC20_SYN,
3334
ERC20_TRIBE,
3435
ERC20_USDC,
@@ -54,7 +55,7 @@ import { getUSDRate, getUSDRateBalancer } from "../src/utils/Price";
5455
import { getWalletAddressesForContract } from "../src/utils/ProtocolAddresses";
5556
import { mockClearinghouseRegistryAddressNull, mockTreasuryAddressNull } from "./bophadesHelper";
5657
import { mockStablecoinsPriceFeeds } from "./chainlink";
57-
import { ERC20_STANDARD_DECIMALS, mockERC20Balance } from "./erc20Helper";
58+
import { ERC20_STANDARD_DECIMALS, mockERC20Balance, mockERC20TotalSupply } from "./erc20Helper";
5859
import {
5960
getERC20UsdRate,
6061
getEthUsdRate,
@@ -215,13 +216,16 @@ describe("OHM-USD rate", () => {
215216
mockERC20Balance(ERC20_OHM_V2, PAIR_UNISWAP_V3_WETH_OHM, toBigInt(ohmBalance, OHM_V2_DECIMALS));
216217
mockERC20Balance(ERC20_WETH, PAIR_UNISWAP_V3_WETH_OHM, toBigInt(ethBalance, ERC20_STANDARD_DECIMALS));
217218

219+
// Mock total supply (required by Uniswap V3 handler)
220+
mockERC20TotalSupply(ERC20_OHM_V2, OHM_V2_DECIMALS, toBigInt(ohmBalance, OHM_V2_DECIMALS));
221+
218222
// 919.574080927401380445 * 1898.01397374 / 130454.081369749 = 13.3791479512
219223
// TODO figure out why this is not being returned
220224
const calculatedRate = BigDecimal.fromString("13.3835");
221225

222226
assert.stringEquals(
223227
calculatedRate.truncate(4).toString(),
224-
getUSDRate(ERC20_OHM_V2, BigInt.zero()).truncate(4).toString(),
228+
getUSDRate(ERC20_OHM_V2, BigInt.fromString(ERC20_OHM_V2_BLOCK)).truncate(4).toString(),
225229
);
226230
});
227231

0 commit comments

Comments
 (0)