This repository has been archived by the owner on Jan 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 382
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(rari-fuse): Optimize balances to use Comptroller to pre-emptively…
… determine participated markets (#550)
- Loading branch information
1 parent
1cd1cb0
commit 46d8593
Showing
5 changed files
with
91 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
src/apps/rari-fuse/ethereum/rari-fuse.supply.token-balance-fetcher.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { Inject } from '@nestjs/common'; | ||
|
||
import { APP_TOOLKIT, IAppToolkit } from '~app-toolkit/app-toolkit.interface'; | ||
import { Register } from '~app-toolkit/decorators'; | ||
import { CompoundSupplyTokenDataProps } from '~apps/compound/helper/compound.supply.token-helper'; | ||
import { PositionBalanceFetcher } from '~position/position-balance-fetcher.interface'; | ||
import { AppTokenPositionBalance } from '~position/position-balance.interface'; | ||
import { Network } from '~types/network.interface'; | ||
|
||
import { RariFuseContractFactory } from '../contracts'; | ||
import { RARI_FUSE_DEFINITION } from '../rari-fuse.definition'; | ||
|
||
@Register.TokenPositionBalanceFetcher({ | ||
appId: RARI_FUSE_DEFINITION.id, | ||
groupId: RARI_FUSE_DEFINITION.groups.supply.id, | ||
network: Network.ETHEREUM_MAINNET, | ||
}) | ||
export class EthereumRariFuseSupplyTokenBalanceFetcher implements PositionBalanceFetcher<AppTokenPositionBalance> { | ||
constructor( | ||
@Inject(APP_TOOLKIT) | ||
private readonly appToolkit: IAppToolkit, | ||
@Inject(RariFuseContractFactory) | ||
private readonly rariFuseContractFactory: RariFuseContractFactory, | ||
) {} | ||
|
||
async getBalances(address: string) { | ||
const network = Network.ETHEREUM_MAINNET; | ||
const fuseLensAddress = '0x8da38681826f4abbe089643d2b3fe4c6e4730493'; | ||
const fuseLens = this.rariFuseContractFactory.rariFusePoolLens({ address: fuseLensAddress, network }); | ||
const poolsBySupplier = await fuseLens.getPoolsBySupplierWithData(address); | ||
const participatedComptrollers = poolsBySupplier[1].map(p => p.comptroller.toLowerCase()); | ||
|
||
return this.appToolkit.helpers.tokenBalanceHelper.getTokenBalances<CompoundSupplyTokenDataProps>({ | ||
address, | ||
appId: RARI_FUSE_DEFINITION.id, | ||
groupId: RARI_FUSE_DEFINITION.groups.supply.id, | ||
network: Network.ETHEREUM_MAINNET, | ||
filter: v => participatedComptrollers.includes(v.dataProps.comptrollerAddress), | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters