Skip to content
This repository has been archived by the owner on Jan 24, 2024. It is now read-only.

Commit

Permalink
feat(studio): Fix Midas revert error (#3063)
Browse files Browse the repository at this point in the history
  • Loading branch information
immasandwich authored Nov 16, 2023
1 parent 393b984 commit f58621b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export class BinanceSmartChainMidasMarketTokenFetcher extends MidasMarketTokenFe
groupLabel = 'Lending';

poolDirectoryAddress = '0x295d7347606f4bd810c8296bb8d75d657001fcf7';
poolLensAddress = '0x6f4e0b5405f3751f7327cf8095004c34fc307f55';
poolLensAddress = '0x2d3c31e38d3ad71571b1406639003a6648481628';

constructor(
@Inject(APP_TOOLKIT) protected readonly appToolkit: IAppToolkit,
Expand Down Expand Up @@ -59,7 +59,6 @@ export class BinanceSmartChainMidasMarketTokenFetcher extends MidasMarketTokenFe

async getMarketTokenAddresses(contract: MidasPoolLensContract, poolAddress: string): Promise<string[]> {
const assets = await contract.simulate.getPoolAssetsWithData([poolAddress]).then(v => v.result);

return assets.map(asset => asset.cToken);
}

Expand Down
15 changes: 13 additions & 2 deletions src/apps/midas/common/midas.market.token-fetcher.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Inject } from '@nestjs/common';
import { BigNumberish } from 'ethers';
import { Abi, GetContractReturnType, PublicClient } from 'viem';
import { Abi, BaseError, ContractFunctionRevertedError, GetContractReturnType, PublicClient } from 'viem';

import { APP_TOOLKIT, IAppToolkit } from '~app-toolkit/app-toolkit.interface';
import { BLOCKS_PER_DAY } from '~app-toolkit/constants/blocks';
Expand Down Expand Up @@ -79,7 +79,18 @@ export abstract class MidasMarketTokenFetcher<
const definitions = await Promise.all(
poolIndexes.map(async poolId => {
const { comptroller, name } = await this.getPool(poolDirectory, poolId);
const marketAddresses = await this.getMarketTokenAddresses(poolLens, comptroller);
const marketAddresses = await this.getMarketTokenAddresses(poolLens, comptroller).catch(e => {
if (e instanceof BaseError) {
const err = e.walk((e: Error) => e instanceof ContractFunctionRevertedError);

if (err) {
const reason = (err as ContractFunctionRevertedError).reason;
if (reason === 'Not implemented') return [];
}
}

throw e;
});

return marketAddresses.map(marketAddress => ({
address: marketAddress.toLowerCase(),
Expand Down
3 changes: 1 addition & 2 deletions src/apps/midas/polygon/midas.market.token-fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export class PolygonMidasMarketTokenFetcher extends MidasMarketTokenFetcher<
groupLabel = 'Lending';

poolDirectoryAddress = '0x9a161e68ec0d5364f4d09a6080920daff6fff250';
poolLensAddress = '0xd94ca960132557385e9ad993c69cc22a3344c2e7';
poolLensAddress = '0x16d8c0ee982d5219285b1042d3675a6d9e247f9d';

constructor(
@Inject(APP_TOOLKIT) protected readonly appToolkit: IAppToolkit,
Expand Down Expand Up @@ -59,7 +59,6 @@ export class PolygonMidasMarketTokenFetcher extends MidasMarketTokenFetcher<

async getMarketTokenAddresses(contract: MidasPoolLensContract, poolAddress: string): Promise<string[]> {
const assets = await contract.simulate.getPoolAssetsWithData([poolAddress]).then(v => v.result);

return assets.map(asset => asset.cToken);
}

Expand Down

0 comments on commit f58621b

Please sign in to comment.