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 380
/
compound.supply.token-fetcher.ts
41 lines (36 loc) · 2.03 KB
/
compound.supply.token-fetcher.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import { Inject } from '@nestjs/common';
import { Register } from '~app-toolkit/decorators';
import { PositionFetcher } from '~position/position-fetcher.interface';
import { AppTokenPosition } from '~position/position.interface';
import { Network } from '~types/network.interface';
import { COMPOUND_DEFINITION } from '../compound.definition';
import { CompoundContractFactory } from '../contracts';
import { CompoundSupplyTokenHelper } from '../helper/compound.supply.token-helper';
const appId = COMPOUND_DEFINITION.id;
const groupId = COMPOUND_DEFINITION.groups.supply.id;
const network = Network.ETHEREUM_MAINNET;
@Register.TokenPositionFetcher({ appId, groupId, network })
export class EthereumCompoundSupplyTokenFetcher implements PositionFetcher<AppTokenPosition> {
constructor(
@Inject(CompoundContractFactory) private readonly compoundContractFactory: CompoundContractFactory,
@Inject(CompoundSupplyTokenHelper) private readonly compoundSupplyTokenHelper: CompoundSupplyTokenHelper,
) {}
async getPositions() {
return this.compoundSupplyTokenHelper.getTokens({
network,
appId,
groupId,
exchangeable: true,
comptrollerAddress: '0x3d9819210a31b4961b30ef54be2aed79b9c9cd3b',
getComptrollerContract: ({ address, network }) =>
this.compoundContractFactory.compoundComptroller({ address, network }),
getTokenContract: ({ address, network }) => this.compoundContractFactory.compoundCToken({ address, network }),
getAllMarkets: ({ contract, multicall }) => multicall.wrap(contract).getAllMarkets(),
getExchangeRate: ({ contract, multicall }) => multicall.wrap(contract).exchangeRateCurrent(),
getSupplyRate: ({ contract, multicall }) => multicall.wrap(contract).supplyRatePerBlock(),
getBorrowRate: ({ contract, multicall }) => multicall.wrap(contract).borrowRatePerBlock(),
getUnderlyingAddress: ({ contract, multicall }) => multicall.wrap(contract).underlying(),
getExchangeRateMantissa: ({ underlyingTokenDecimals }) => underlyingTokenDecimals + 10,
});
}
}