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(compound): Split compound lending balance helper (#516)
- Loading branch information
1 parent
7dd4568
commit e17f5ec
Showing
9 changed files
with
216 additions
and
135 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
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
53 changes: 53 additions & 0 deletions
53
src/apps/compound/helper/compound.borrow.balance-helper.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,53 @@ | ||
import { Inject, Injectable } from '@nestjs/common'; | ||
import { BigNumberish } from 'ethers'; | ||
|
||
import { drillBalance } from '~app-toolkit'; | ||
import { APP_TOOLKIT, IAppToolkit } from '~app-toolkit/app-toolkit.interface'; | ||
import { EthersMulticall as Multicall } from '~multicall/multicall.ethers'; | ||
import { Network } from '~types/network.interface'; | ||
|
||
import { CompoundCToken } from '../contracts'; | ||
|
||
import { CompoundSupplyTokenDataProps } from './compound.supply.token-helper'; | ||
|
||
type CompoundBorrowBalanceHelperParams<T> = { | ||
address: string; | ||
network: Network; | ||
appId: string; | ||
groupId: string; | ||
getTokenContract: (opts: { address: string; network: Network }) => T; | ||
getBorrowBalanceRaw: (opts: { contract: T; multicall: Multicall; address: string }) => Promise<BigNumberish>; | ||
}; | ||
|
||
@Injectable() | ||
export class CompoundBorrowBalanceHelper { | ||
constructor(@Inject(APP_TOOLKIT) private readonly appToolkit: IAppToolkit) {} | ||
|
||
async getBalances<T = CompoundCToken>({ | ||
address, | ||
network, | ||
appId, | ||
groupId, | ||
getTokenContract, | ||
getBorrowBalanceRaw, | ||
}: CompoundBorrowBalanceHelperParams<T>) { | ||
const multicall = this.appToolkit.getMulticall(network); | ||
|
||
const borrowPositions = await this.appToolkit.getAppContractPositions<CompoundSupplyTokenDataProps>({ | ||
appId, | ||
groupIds: [groupId], | ||
network, | ||
}); | ||
|
||
const borrowPositionBalances = await Promise.all( | ||
borrowPositions.map(async borrowPosition => { | ||
const borrowContract = getTokenContract({ address: borrowPosition.address, network }); | ||
const balanceRaw = await getBorrowBalanceRaw({ contract: borrowContract, multicall, address }); | ||
const tokens = [drillBalance(borrowPosition.tokens[0], balanceRaw.toString(), { isDebt: true })]; | ||
return { ...borrowPosition, tokens, balanceUSD: tokens[0].balanceUSD }; | ||
}), | ||
); | ||
|
||
return borrowPositionBalances; | ||
} | ||
} |
73 changes: 0 additions & 73 deletions
73
src/apps/compound/helper/compound.lending.balance-helper.ts
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.