This repository has been archived by the owner on Jan 24, 2024. It is now read-only.
/
compound.claimable.contract-position-fetcher.ts
83 lines (72 loc) · 2.72 KB
/
compound.claimable.contract-position-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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import { BigNumberish } from 'ethers';
import { Abi, GetContractReturnType, PublicClient } from 'viem';
import { getLabelFromToken } from '~app-toolkit/helpers/presentation/image.present';
import { ContractPosition, MetaType } from '~position/position.interface';
import { ContractPositionTemplatePositionFetcher } from '~position/template/contract-position.template.position-fetcher';
import {
DefaultContractPositionDefinition,
GetDataPropsParams,
GetDisplayPropsParams,
GetTokenBalancesParams,
GetTokenDefinitionsParams,
UnderlyingTokenDefinition,
} from '~position/template/contract-position.template.types';
export type CompoundClaimablePositionDataProps = {
lensAddress: string;
};
export abstract class CompoundClaimableContractPositionFetcher<
R extends Abi,
S extends Abi,
> extends ContractPositionTemplatePositionFetcher<R> {
abstract lensAddress: string;
abstract rewardTokenAddress: string;
abstract comptrollerAddress: string;
abstract getCompoundComptrollerContract(address: string): GetContractReturnType<R, PublicClient>;
abstract getCompoundLensContract(address: string): GetContractReturnType<S, PublicClient>;
abstract getClaimableBalance(
address: string,
opts: {
contract: GetContractReturnType<S, PublicClient>;
contractPosition: ContractPosition<CompoundClaimablePositionDataProps>;
},
): Promise<BigNumberish>;
getContract(address: string) {
return this.getCompoundComptrollerContract(address);
}
async getDefinitions(): Promise<DefaultContractPositionDefinition[]> {
return [{ address: this.comptrollerAddress }];
}
async getTokenDefinitions(
_opts: GetTokenDefinitionsParams<R, DefaultContractPositionDefinition>,
): Promise<UnderlyingTokenDefinition[] | null> {
return [
{
metaType: MetaType.CLAIMABLE,
address: this.rewardTokenAddress,
network: this.network,
},
];
}
async getLabel({ contractPosition }: GetDisplayPropsParams<R>) {
const rewardToken = contractPosition.tokens[0];
return `Claimable ${getLabelFromToken(rewardToken)}`;
}
async getDataProps(
_params: GetDataPropsParams<R, CompoundClaimablePositionDataProps>,
): Promise<CompoundClaimablePositionDataProps> {
return {
lensAddress: this.lensAddress,
};
}
async getTokenBalancesPerPosition({
address,
contractPosition,
}: GetTokenBalancesParams<R, CompoundClaimablePositionDataProps>): Promise<BigNumberish[]> {
const {
dataProps: { lensAddress },
} = contractPosition;
const lensContract = this.getCompoundLensContract(lensAddress);
const claimableBalance = await this.getClaimableBalance(address, { contract: lensContract, contractPosition });
return [claimableBalance];
}
}