forked from Zapper-fi/studio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index-coop.index.token-fetcher.ts
67 lines (56 loc) · 2.57 KB
/
index-coop.index.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
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
import { Inject } from '@nestjs/common';
import { APP_TOOLKIT, IAppToolkit } from '~app-toolkit/app-toolkit.interface';
import { PositionTemplate } from '~app-toolkit/decorators/position-template.decorator';
import { AppTokenTemplatePositionFetcher } from '~position/template/app-token.template.position-fetcher';
import {
GetDataPropsParams,
GetDisplayPropsParams,
GetUnderlyingTokensParams,
} from '~position/template/app-token.template.types';
import { IndexCoopContractFactory, IndexCoopToken } from '../contracts';
@PositionTemplate()
export class EthereumIndexCoopIndexTokenFetcher extends AppTokenTemplatePositionFetcher<IndexCoopToken> {
groupLabel = 'Index';
deprecatedProducts = [
'0x33d63ba1e57e54779f7ddaeaa7109349344cf5f1', // DATA
'0x47110d43175f7f2c2425e7d15792acc5817eb44f', // GMI
];
constructor(
@Inject(APP_TOOLKIT) protected readonly appToolkit: IAppToolkit,
@Inject(IndexCoopContractFactory) protected readonly contractFactory: IndexCoopContractFactory,
) {
super(appToolkit);
}
getContract(address: string): IndexCoopToken {
return this.contractFactory.indexCoopToken({ address, network: this.network });
}
async getAddresses(): Promise<string[]> {
return [
'0x1494ca1f11d487c2bbe4543e90080aeba4ba3c2b', // DPI
'0x72e364f2abdc788b7e918bc238b21f109cd634d7', // MVI
'0x2af1df3ab0ab157e1e2ad8f88a7d04fbea0c7dc6', // BED
'0x7c07f7abe10ce8e33dc6c5ad68fe033085256a84', // icETH
'0xaa6e8127831c9de45ae56bb1b0d4d4da6e5665bd', // ETH x2 Flex Leverage
'0x0b498ff89709d3838a063f1dfa463091f9801c2b', // BTC x2 Flex Leverage
'0x341c05c0e9b33c0e38d64de76516b2ce970bb3be', // DSETH
'0xc30fba978743a43e736fc32fbeed364b8a2039cd', // Money Market Index
...this.deprecatedProducts,
];
}
async getUnderlyingTokenDefinitions({ contract }: GetUnderlyingTokensParams<IndexCoopToken>) {
return (await contract.getComponents()).map(address => ({ address, network: this.network }));
}
async getPricePerShare({ appToken, contract }: GetDataPropsParams<IndexCoopToken>) {
const pricePerShare = await Promise.all(
appToken.tokens.map(async underlyingToken => {
const ratio = await contract.getTotalComponentRealUnits(underlyingToken.address);
return Number(ratio) / 10 ** underlyingToken.decimals;
}),
);
return pricePerShare;
}
async getLabel({ appToken }: GetDisplayPropsParams<IndexCoopToken>) {
const deprecated = this.deprecatedProducts.includes(appToken.address);
return `${appToken.symbol}${deprecated === true ? ' (deprecated)' : ''}`;
}
}