@curvefi/llamalend-api 1.1.10 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/docs/MIGRATION.md +325 -0
- package/docs/SUPPORT_LLv2.md +409 -0
- package/lib/constants/abis/OneWayLendingFactoryV2ABI.json +543 -0
- package/lib/constants/aliases.d.ts +0 -11
- package/lib/constants/aliases.js +1 -86
- package/lib/constants/coins.d.ts +0 -11
- package/lib/constants/coins.js +0 -14
- package/lib/constants/utils.d.ts +2 -0
- package/lib/constants/utils.js +2 -0
- package/lib/index.d.ts +10 -4
- package/lib/interfaces.d.ts +3 -2
- package/lib/lendMarkets/LendMarketTemplate.d.ts +13 -502
- package/lib/lendMarkets/LendMarketTemplate.js +237 -2860
- package/lib/lendMarkets/fetch/fetchFactoryData.d.ts +13 -0
- package/lib/lendMarkets/fetch/fetchFactoryData.js +101 -0
- package/lib/lendMarkets/fetch/fetchLendMarkets.d.ts +3 -0
- package/lib/lendMarkets/fetch/fetchLendMarkets.js +94 -0
- package/lib/lendMarkets/interfaces/common/amm.d.ts +10 -0
- package/lib/lendMarkets/interfaces/common/amm.js +1 -0
- package/lib/lendMarkets/interfaces/common/index.d.ts +5 -0
- package/lib/lendMarkets/interfaces/common/index.js +5 -0
- package/lib/lendMarkets/interfaces/common/prices.d.ts +13 -0
- package/lib/lendMarkets/interfaces/common/prices.js +1 -0
- package/lib/lendMarkets/interfaces/common/userPosition.d.ts +39 -0
- package/lib/lendMarkets/interfaces/common/userPosition.js +1 -0
- package/lib/lendMarkets/interfaces/common/vault.d.ts +55 -0
- package/lib/lendMarkets/interfaces/common/vault.js +1 -0
- package/lib/lendMarkets/interfaces/common/wallet.d.ts +8 -0
- package/lib/lendMarkets/interfaces/common/wallet.js +1 -0
- package/lib/lendMarkets/interfaces/v1/index.d.ts +4 -0
- package/lib/lendMarkets/interfaces/v1/index.js +4 -0
- package/lib/lendMarkets/interfaces/v1/leverageV1.d.ts +90 -0
- package/lib/lendMarkets/interfaces/v1/leverageV1.js +1 -0
- package/lib/lendMarkets/interfaces/v1/loanV1.d.ts +73 -0
- package/lib/lendMarkets/interfaces/v1/loanV1.js +1 -0
- package/lib/lendMarkets/interfaces/v1/statsV1.d.ts +49 -0
- package/lib/lendMarkets/interfaces/v1/statsV1.js +1 -0
- package/lib/lendMarkets/interfaces/v2/index.d.ts +3 -0
- package/lib/lendMarkets/interfaces/v2/index.js +3 -0
- package/lib/lendMarkets/interfaces/v2/leverageV2.d.ts +90 -0
- package/lib/lendMarkets/interfaces/v2/leverageV2.js +1 -0
- package/lib/lendMarkets/interfaces/v2/loanV2.d.ts +73 -0
- package/lib/lendMarkets/interfaces/v2/loanV2.js +1 -0
- package/lib/lendMarkets/interfaces/v2/statsV2.d.ts +49 -0
- package/lib/lendMarkets/interfaces/v2/statsV2.js +1 -0
- package/lib/lendMarkets/lendMarketConstructor.js +1 -1
- package/lib/lendMarkets/modules/common/amm.d.ts +19 -0
- package/lib/lendMarkets/modules/common/amm.js +137 -0
- package/lib/lendMarkets/modules/common/index.d.ts +9 -0
- package/lib/lendMarkets/modules/common/index.js +9 -0
- package/lib/lendMarkets/modules/common/leverageZapV1Base.d.ts +118 -0
- package/lib/lendMarkets/modules/common/leverageZapV1Base.js +770 -0
- package/lib/lendMarkets/modules/{leverageZapV2.d.ts → common/leverageZapV2Base.d.ts} +10 -5
- package/lib/lendMarkets/modules/{leverageZapV2.js → common/leverageZapV2Base.js} +36 -32
- package/lib/lendMarkets/modules/common/loanBase.d.ts +115 -0
- package/lib/lendMarkets/modules/common/loanBase.js +793 -0
- package/lib/lendMarkets/modules/common/prices.d.ts +19 -0
- package/lib/lendMarkets/modules/common/prices.js +104 -0
- package/lib/lendMarkets/modules/common/statsBase.d.ts +69 -0
- package/lib/lendMarkets/modules/common/statsBase.js +291 -0
- package/lib/lendMarkets/modules/common/userPosition.d.ts +46 -0
- package/lib/lendMarkets/modules/common/userPosition.js +223 -0
- package/lib/lendMarkets/modules/common/vault.d.ts +69 -0
- package/lib/lendMarkets/modules/common/vault.js +535 -0
- package/lib/lendMarkets/modules/common/wallet.d.ts +13 -0
- package/lib/lendMarkets/modules/common/wallet.js +28 -0
- package/lib/lendMarkets/modules/index.d.ts +1 -1
- package/lib/lendMarkets/modules/index.js +1 -1
- package/lib/lendMarkets/modules/v1/index.d.ts +4 -0
- package/lib/lendMarkets/modules/v1/index.js +4 -0
- package/lib/lendMarkets/modules/v1/leverageV1ZapV1.d.ts +3 -0
- package/lib/lendMarkets/modules/v1/leverageV1ZapV1.js +3 -0
- package/lib/lendMarkets/modules/v1/leverageV1ZapV2.d.ts +3 -0
- package/lib/lendMarkets/modules/v1/leverageV1ZapV2.js +3 -0
- package/lib/lendMarkets/modules/v1/loanV1.d.ts +4 -0
- package/lib/lendMarkets/modules/v1/loanV1.js +3 -0
- package/lib/lendMarkets/modules/v1/statsV1.d.ts +3 -0
- package/lib/lendMarkets/modules/v1/statsV1.js +3 -0
- package/lib/lendMarkets/modules/v2/index.d.ts +4 -0
- package/lib/lendMarkets/modules/v2/index.js +4 -0
- package/lib/lendMarkets/modules/v2/leverageV2ZapV1.d.ts +3 -0
- package/lib/lendMarkets/modules/v2/leverageV2ZapV1.js +3 -0
- package/lib/lendMarkets/modules/v2/leverageV2ZapV2.d.ts +3 -0
- package/lib/lendMarkets/modules/v2/leverageV2ZapV2.js +3 -0
- package/lib/lendMarkets/modules/v2/loanV2.d.ts +4 -0
- package/lib/lendMarkets/modules/v2/loanV2.js +3 -0
- package/lib/lendMarkets/modules/v2/statsV2.d.ts +3 -0
- package/lib/lendMarkets/modules/v2/statsV2.js +3 -0
- package/lib/llamalend.d.ts +6 -6
- package/lib/llamalend.js +46 -210
- package/lib/utils.js +2 -33
- package/package.json +1 -1
- package/src/constants/abis/OneWayLendingFactoryV2ABI.json +543 -0
- package/src/constants/aliases.ts +1 -97
- package/src/constants/coins.ts +0 -25
- package/src/constants/utils.ts +4 -0
- package/src/interfaces.ts +3 -2
- package/src/lendMarkets/LendMarketTemplate.ts +318 -3222
- package/src/lendMarkets/fetch/fetchFactoryData.ts +113 -0
- package/src/lendMarkets/fetch/fetchLendMarkets.ts +108 -0
- package/src/lendMarkets/interfaces/common/amm.ts +11 -0
- package/src/lendMarkets/interfaces/common/index.ts +5 -0
- package/src/lendMarkets/interfaces/common/prices.ts +13 -0
- package/src/lendMarkets/interfaces/common/userPosition.ts +24 -0
- package/src/lendMarkets/interfaces/common/vault.ts +48 -0
- package/src/lendMarkets/interfaces/common/wallet.ts +3 -0
- package/src/lendMarkets/interfaces/v1/index.ts +4 -0
- package/src/lendMarkets/interfaces/v1/leverageV1.ts +84 -0
- package/src/lendMarkets/interfaces/v1/loanV1.ts +77 -0
- package/src/lendMarkets/interfaces/v1/statsV1.ts +21 -0
- package/src/lendMarkets/interfaces/v2/index.ts +3 -0
- package/src/lendMarkets/interfaces/v2/leverageV2.ts +84 -0
- package/src/lendMarkets/interfaces/v2/loanV2.ts +77 -0
- package/src/lendMarkets/interfaces/v2/statsV2.ts +21 -0
- package/src/lendMarkets/lendMarketConstructor.ts +1 -1
- package/src/lendMarkets/modules/common/amm.ts +132 -0
- package/src/lendMarkets/modules/common/index.ts +9 -0
- package/src/lendMarkets/modules/common/leverageZapV1Base.ts +912 -0
- package/src/lendMarkets/modules/{leverageZapV2.ts → common/leverageZapV2Base.ts} +41 -37
- package/src/lendMarkets/modules/common/loanBase.ts +773 -0
- package/src/lendMarkets/modules/common/prices.ts +111 -0
- package/src/lendMarkets/modules/common/statsBase.ts +313 -0
- package/src/lendMarkets/modules/common/userPosition.ts +243 -0
- package/src/lendMarkets/modules/common/vault.ts +551 -0
- package/src/lendMarkets/modules/common/wallet.ts +29 -0
- package/src/lendMarkets/modules/index.ts +1 -1
- package/src/lendMarkets/modules/v1/index.ts +4 -0
- package/src/lendMarkets/modules/v1/leverageV1ZapV1.ts +3 -0
- package/src/lendMarkets/modules/v1/leverageV1ZapV2.ts +3 -0
- package/src/lendMarkets/modules/v1/loanV1.ts +4 -0
- package/src/lendMarkets/modules/v1/statsV1.ts +3 -0
- package/src/lendMarkets/modules/v2/index.ts +4 -0
- package/src/lendMarkets/modules/v2/leverageV2ZapV1.ts +3 -0
- package/src/lendMarkets/modules/v2/leverageV2ZapV2.ts +3 -0
- package/src/lendMarkets/modules/v2/loanV2.ts +4 -0
- package/src/lendMarkets/modules/v2/statsV2.ts +3 -0
- package/src/llamalend.ts +47 -244
- package/src/utils.ts +2 -35
package/src/llamalend.ts
CHANGED
|
@@ -9,18 +9,13 @@ import {
|
|
|
9
9
|
ICurveContract,
|
|
10
10
|
IOneWayMarket,
|
|
11
11
|
ICoin,
|
|
12
|
-
|
|
12
|
+
|
|
13
13
|
} from "./interfaces.js";
|
|
14
14
|
// OneWayMarket ABIs
|
|
15
15
|
import OneWayLendingFactoryABI from "./constants/abis/OneWayLendingFactoryABI.json" with {type: 'json'};
|
|
16
|
+
import OneWayLendingFactoryV2ABI from "./constants/abis/OneWayLendingFactoryV2ABI.json" with {type: 'json'};
|
|
16
17
|
import ERC20ABI from './constants/abis/ERC20.json' with {type: 'json'};
|
|
17
18
|
import ERC4626ABI from './constants/abis/ERC4626.json' with {type: 'json'};
|
|
18
|
-
import LlammaABI from './constants/abis/Llamma.json' with {type: 'json'};
|
|
19
|
-
import ControllerABI from './constants/abis/Controller.json' with {type: 'json'};
|
|
20
|
-
import MonetaryPolicyABI from './constants/abis/MonetaryPolicy.json' with {type: 'json'};
|
|
21
|
-
import VaultABI from './constants/abis/Vault.json' with {type: 'json'};
|
|
22
|
-
import GaugeABI from './constants/abis/GaugeV5.json' with {type: 'json'};
|
|
23
|
-
import SidechainGaugeABI from './constants/abis/SidechainGauge.json' with {type: 'json'};
|
|
24
19
|
import GaugeControllerABI from './constants/abis/GaugeController.json' with {type: 'json'};
|
|
25
20
|
import GaugeFactoryMainnetABI from './constants/abis/GaugeFactoryMainnet.json' with {type: 'json'};
|
|
26
21
|
import GaugeFactorySidechainABI from './constants/abis/GaugeFactorySidechain.json' with {type: 'json'};
|
|
@@ -42,36 +37,14 @@ import DeleverageZapABI from "./constants/abis/crvUSD/DeleverageZap.json" with {
|
|
|
42
37
|
import {
|
|
43
38
|
ALIASES_ETHEREUM,
|
|
44
39
|
ALIASES_OPTIMISM,
|
|
45
|
-
ALIASES_POLYGON,
|
|
46
|
-
ALIASES_FANTOM,
|
|
47
|
-
ALIASES_AVALANCHE,
|
|
48
40
|
ALIASES_ARBITRUM,
|
|
49
|
-
ALIASES_XDAI,
|
|
50
|
-
ALIASES_MOONBEAM,
|
|
51
|
-
ALIASES_AURORA,
|
|
52
|
-
ALIASES_KAVA,
|
|
53
|
-
ALIASES_CELO,
|
|
54
|
-
ALIASES_ZKSYNC,
|
|
55
|
-
ALIASES_BASE,
|
|
56
|
-
ALIASES_BSC,
|
|
57
41
|
ALIASES_FRAXTAL,
|
|
58
42
|
ALIASES_SONIC,
|
|
59
43
|
} from "./constants/aliases.js";
|
|
60
44
|
import {
|
|
61
45
|
COINS_ETHEREUM,
|
|
62
46
|
COINS_OPTIMISM,
|
|
63
|
-
COINS_POLYGON,
|
|
64
|
-
COINS_FANTOM,
|
|
65
|
-
COINS_AVALANCHE,
|
|
66
47
|
COINS_ARBITRUM,
|
|
67
|
-
COINS_XDAI,
|
|
68
|
-
COINS_MOONBEAM,
|
|
69
|
-
COINS_AURORA,
|
|
70
|
-
COINS_KAVA,
|
|
71
|
-
COINS_CELO,
|
|
72
|
-
COINS_ZKSYNC,
|
|
73
|
-
COINS_BASE,
|
|
74
|
-
COINS_BSC,
|
|
75
48
|
COINS_FRAXTAL,
|
|
76
49
|
COINS_SONIC,
|
|
77
50
|
} from "./constants/coins.js";
|
|
@@ -83,6 +56,7 @@ import {_getMarketsData, _getHiddenPools} from "./external-api.js";
|
|
|
83
56
|
import {extractDecimals} from "./constants/utils.js";
|
|
84
57
|
import {MintMarketTemplate} from "./mintMarkets";
|
|
85
58
|
import {LendMarketTemplate} from "./lendMarkets";
|
|
59
|
+
import {fetchOneWayMarketsByBlockchain, fetchOneWayMarketsByAPI} from "./lendMarkets/fetch/fetchLendMarkets.js";
|
|
86
60
|
|
|
87
61
|
export const NETWORK_CONSTANTS: { [index: number]: any } = {
|
|
88
62
|
1: {
|
|
@@ -96,77 +70,22 @@ export const NETWORK_CONSTANTS: { [index: number]: any } = {
|
|
|
96
70
|
ALIASES: ALIASES_OPTIMISM,
|
|
97
71
|
COINS: COINS_OPTIMISM,
|
|
98
72
|
},
|
|
99
|
-
56: {
|
|
100
|
-
NAME: 'bsc',
|
|
101
|
-
ALIASES: ALIASES_BSC,
|
|
102
|
-
COINS: COINS_BSC,
|
|
103
|
-
},
|
|
104
|
-
100: {
|
|
105
|
-
NAME: 'xdai',
|
|
106
|
-
ALIASES: ALIASES_XDAI,
|
|
107
|
-
COINS: COINS_XDAI,
|
|
108
|
-
},
|
|
109
|
-
137: {
|
|
110
|
-
NAME: 'polygon',
|
|
111
|
-
ALIASES: ALIASES_POLYGON,
|
|
112
|
-
COINS: COINS_POLYGON,
|
|
113
|
-
},
|
|
114
73
|
146: {
|
|
115
74
|
NAME: 'sonic',
|
|
116
75
|
ALIASES: ALIASES_SONIC,
|
|
117
76
|
COINS: COINS_SONIC,
|
|
118
77
|
},
|
|
119
|
-
250: {
|
|
120
|
-
NAME: 'fantom',
|
|
121
|
-
ALIASES: ALIASES_FANTOM,
|
|
122
|
-
COINS: COINS_FANTOM,
|
|
123
|
-
},
|
|
124
78
|
252: {
|
|
125
79
|
NAME: 'fraxtal',
|
|
126
80
|
ALIASES: ALIASES_FRAXTAL,
|
|
127
81
|
COINS: COINS_FRAXTAL,
|
|
128
82
|
},
|
|
129
|
-
324: {
|
|
130
|
-
NAME: 'zksync',
|
|
131
|
-
ALIASES: ALIASES_ZKSYNC,
|
|
132
|
-
COINS: COINS_ZKSYNC,
|
|
133
|
-
},
|
|
134
|
-
1284: {
|
|
135
|
-
NAME: 'moonbeam',
|
|
136
|
-
ALIASES: ALIASES_MOONBEAM,
|
|
137
|
-
COINS: COINS_MOONBEAM,
|
|
138
|
-
},
|
|
139
|
-
2222: {
|
|
140
|
-
NAME: 'kava',
|
|
141
|
-
ALIASES: ALIASES_KAVA,
|
|
142
|
-
COINS: COINS_KAVA,
|
|
143
|
-
},
|
|
144
|
-
8453: {
|
|
145
|
-
NAME: 'base',
|
|
146
|
-
ALIASES: ALIASES_BASE,
|
|
147
|
-
COINS: COINS_BASE,
|
|
148
|
-
},
|
|
149
83
|
42161: {
|
|
150
84
|
NAME: 'arbitrum',
|
|
151
85
|
ALIASES: ALIASES_ARBITRUM,
|
|
152
86
|
COINS: COINS_ARBITRUM,
|
|
153
87
|
EXCLUDED_PROTOCOLS_1INCH: "",
|
|
154
88
|
},
|
|
155
|
-
42220: {
|
|
156
|
-
NAME: 'celo',
|
|
157
|
-
ALIASES: ALIASES_CELO,
|
|
158
|
-
COINS: COINS_CELO,
|
|
159
|
-
},
|
|
160
|
-
43114: {
|
|
161
|
-
NAME: 'avalanche',
|
|
162
|
-
ALIASES: ALIASES_AVALANCHE,
|
|
163
|
-
COINS: COINS_AVALANCHE,
|
|
164
|
-
},
|
|
165
|
-
1313161554: {
|
|
166
|
-
NAME: 'aurora',
|
|
167
|
-
ALIASES: ALIASES_AURORA,
|
|
168
|
-
COINS: COINS_AURORA,
|
|
169
|
-
},
|
|
170
89
|
}
|
|
171
90
|
|
|
172
91
|
|
|
@@ -187,6 +106,7 @@ class Llamalend implements ILlamalend {
|
|
|
187
106
|
L1WeightedGasPrice?: number;
|
|
188
107
|
constants: {
|
|
189
108
|
ONE_WAY_MARKETS: IDict<IOneWayMarket>,
|
|
109
|
+
ONE_WAY_MARKETS_V2: IDict<IOneWayMarket>,
|
|
190
110
|
DECIMALS: IDict<number>;
|
|
191
111
|
NETWORK_NAME: INetworkName;
|
|
192
112
|
ALIASES: Record<string, string>;
|
|
@@ -215,6 +135,7 @@ class Llamalend implements ILlamalend {
|
|
|
215
135
|
this.options = {};
|
|
216
136
|
this.constants = {
|
|
217
137
|
ONE_WAY_MARKETS: {},
|
|
138
|
+
ONE_WAY_MARKETS_V2: {},
|
|
218
139
|
LLAMMAS: {},
|
|
219
140
|
COINS: {},
|
|
220
141
|
DECIMALS: {},
|
|
@@ -250,6 +171,7 @@ class Llamalend implements ILlamalend {
|
|
|
250
171
|
this.options = {};
|
|
251
172
|
this.constants = {
|
|
252
173
|
ONE_WAY_MARKETS: {},
|
|
174
|
+
ONE_WAY_MARKETS_V2: {},
|
|
253
175
|
LLAMMAS: {...LLAMMAS},
|
|
254
176
|
COINS: {},
|
|
255
177
|
DECIMALS: {},
|
|
@@ -346,6 +268,9 @@ class Llamalend implements ILlamalend {
|
|
|
346
268
|
|
|
347
269
|
// oneWayMarkets contracts
|
|
348
270
|
this.setContract(this.constants.ALIASES['one_way_factory'], OneWayLendingFactoryABI);
|
|
271
|
+
if(this.constants.ALIASES['one_way_factory_v2'] && this.constants.ALIASES['one_way_factory_v2'] !== this.constants.ZERO_ADDRESS) {
|
|
272
|
+
this.setContract(this.constants.ALIASES['one_way_factory_v2'], OneWayLendingFactoryV2ABI);
|
|
273
|
+
}
|
|
349
274
|
this.setContract(this.constants.ALIASES['gauge_controller'], GaugeControllerABI);
|
|
350
275
|
this.setContract(this.constants.ALIASES['leverage_zap'], LeverageZapABI);
|
|
351
276
|
this.setContract(this.constants.ALIASES['leverage_zap_v2'], LeverageZapABI);
|
|
@@ -541,53 +466,20 @@ class Llamalend implements ILlamalend {
|
|
|
541
466
|
return Object.fromEntries(Object.entries(markets).filter(([id]) => !hiddenMarkets.includes(id))) as IDict<IOneWayMarket>;
|
|
542
467
|
}
|
|
543
468
|
|
|
544
|
-
getLendMarketList = () => Object.keys(this.constants.ONE_WAY_MARKETS);
|
|
469
|
+
getLendMarketList = () => Object.keys({...this.constants.ONE_WAY_MARKETS, ...this.constants.ONE_WAY_MARKETS_V2});
|
|
545
470
|
|
|
546
471
|
getMintMarketList = () => Object.keys(this.constants.LLAMMAS);
|
|
547
472
|
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
calls.push(createCall(factory,item, [i]))
|
|
558
|
-
})
|
|
473
|
+
fetchLendMarkets = async ({ useApi = true, version = 'v1' }: { useApi?: boolean, version?: 'v1' | 'v2' } = {}) => {
|
|
474
|
+
if(version === 'v2' && useApi) {
|
|
475
|
+
throw new Error('API fetch is not supported for v2 markets yet. Please use fetchMarkets({ useApi: false, version: "v2" }) to fetch from blockchain.');
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
if(useApi) {
|
|
479
|
+
await fetchOneWayMarketsByAPI(this, version)
|
|
480
|
+
} else {
|
|
481
|
+
await fetchOneWayMarketsByBlockchain(this, version)
|
|
559
482
|
}
|
|
560
|
-
const res = (await this.multicallProvider.all(calls) as string[]).map((addr) => addr.toLowerCase());
|
|
561
|
-
|
|
562
|
-
return handleMultiCallResponse(callsMap, res)
|
|
563
|
-
}
|
|
564
|
-
|
|
565
|
-
getFactoryMarketDataByAPI = async () => {
|
|
566
|
-
const apiData = (await _getMarketsData(this.constants.NETWORK_NAME)).lendingVaultData;
|
|
567
|
-
|
|
568
|
-
const result: Record<string, string[]> = {
|
|
569
|
-
names: [],
|
|
570
|
-
amms: [],
|
|
571
|
-
controllers: [],
|
|
572
|
-
borrowed_tokens: [],
|
|
573
|
-
collateral_tokens: [],
|
|
574
|
-
monetary_policies: [],
|
|
575
|
-
vaults: [],
|
|
576
|
-
gauges: [],
|
|
577
|
-
};
|
|
578
|
-
|
|
579
|
-
apiData.forEach((market: IMarketDataAPI) => {
|
|
580
|
-
result.names.push(market.name);
|
|
581
|
-
result.amms.push(market.ammAddress.toLowerCase());
|
|
582
|
-
result.controllers.push(market.controllerAddress.toLowerCase());
|
|
583
|
-
result.borrowed_tokens.push(market.assets.borrowed.address.toLowerCase());
|
|
584
|
-
result.collateral_tokens.push(market.assets.collateral.address.toLowerCase());
|
|
585
|
-
result.monetary_policies.push(market.monetaryPolicyAddress.toLowerCase());
|
|
586
|
-
result.vaults.push(market.address.toLowerCase());
|
|
587
|
-
result.gauges.push(market.gaugeAddress?.toLowerCase() || this.constants.ZERO_ADDRESS);
|
|
588
|
-
});
|
|
589
|
-
|
|
590
|
-
return result;
|
|
591
483
|
}
|
|
592
484
|
|
|
593
485
|
getCoins = async (collateral_tokens: string[], borrowed_tokens: string[], useApi = false): Promise<IDict<ICoin>> => {
|
|
@@ -648,142 +540,53 @@ class Llamalend implements ILlamalend {
|
|
|
648
540
|
}
|
|
649
541
|
|
|
650
542
|
|
|
651
|
-
fetchStats = async (amms: string[], controllers: string[], vaults: string[], borrowed_tokens: string[], collateral_tokens: string[]) => {
|
|
543
|
+
fetchStats = async (amms: string[], controllers: string[], vaults: string[], borrowed_tokens: string[], collateral_tokens: string[], version: 'v1' | 'v2' = 'v1') => {
|
|
652
544
|
cacheStats.clear();
|
|
653
545
|
|
|
654
546
|
const marketCount = controllers.length;
|
|
547
|
+
console.log(controllers.length)
|
|
655
548
|
|
|
656
549
|
const calls: Call[] = [];
|
|
657
550
|
|
|
658
551
|
for (let i = 0; i < marketCount; i++) {
|
|
659
552
|
calls.push(createCall(this.contracts[controllers[i]], 'total_debt', []));
|
|
660
|
-
calls.push(createCall(this.contracts[vaults[i]], 'totalAssets', [
|
|
553
|
+
calls.push(createCall(this.contracts[vaults[i]], 'totalAssets', []));
|
|
661
554
|
calls.push(createCall(this.contracts[borrowed_tokens[i]], 'balanceOf', [controllers[i]]));
|
|
662
555
|
calls.push(createCall(this.contracts[amms[i]], 'rate', []));
|
|
663
556
|
calls.push(createCall(this.contracts[borrowed_tokens[i]], 'balanceOf', [amms[i]]));
|
|
664
|
-
|
|
665
|
-
|
|
557
|
+
|
|
558
|
+
if (version === 'v1') {
|
|
559
|
+
calls.push(createCall(this.contracts[amms[i]], 'admin_fees_x', []));
|
|
560
|
+
calls.push(createCall(this.contracts[amms[i]], 'admin_fees_y', []));
|
|
561
|
+
}
|
|
562
|
+
|
|
666
563
|
calls.push(createCall(this.contracts[collateral_tokens[i]], 'balanceOf', [amms[i]]));
|
|
667
564
|
}
|
|
668
565
|
|
|
669
566
|
const res = await this.multicallProvider.all(calls);
|
|
670
567
|
|
|
671
568
|
for (let i = 0; i < marketCount; i++) {
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
}
|
|
691
|
-
|
|
692
|
-
_fetchOneWayMarketsByBlockchain = async () => {
|
|
693
|
-
const {names, amms, controllers, borrowed_tokens, collateral_tokens, monetary_policies, vaults, gauges} = await this.getFactoryMarketData()
|
|
694
|
-
const COIN_DATA = await this.getCoins(collateral_tokens, borrowed_tokens);
|
|
695
|
-
for (const c in COIN_DATA) {
|
|
696
|
-
this.constants.DECIMALS[c] = COIN_DATA[c].decimals;
|
|
697
|
-
}
|
|
698
|
-
|
|
699
|
-
amms.forEach((amm: string, index: number) => {
|
|
700
|
-
this.setContract(amm, LlammaABI);
|
|
701
|
-
this.setContract(controllers[index], ControllerABI);
|
|
702
|
-
this.setContract(monetary_policies[index], MonetaryPolicyABI);
|
|
703
|
-
this.setContract(vaults[index], VaultABI);
|
|
704
|
-
this.setContract(gauges[index], this.chainId === 1 ? GaugeABI : SidechainGaugeABI);
|
|
705
|
-
COIN_DATA[vaults[index]] = {
|
|
706
|
-
address: vaults[index],
|
|
707
|
-
decimals: 18,
|
|
708
|
-
name: "Curve Vault for " + COIN_DATA[borrowed_tokens[index]].name,
|
|
709
|
-
symbol: "cv" + COIN_DATA[borrowed_tokens[index]].symbol,
|
|
710
|
-
};
|
|
711
|
-
COIN_DATA[gauges[index]] = {
|
|
712
|
-
address: gauges[index],
|
|
713
|
-
decimals: 18,
|
|
714
|
-
name: "curve.finance " + COIN_DATA[borrowed_tokens[index]].name + " Gauge Deposit",
|
|
715
|
-
symbol: "cv" + COIN_DATA[borrowed_tokens[index]].symbol + "-gauge",
|
|
716
|
-
};
|
|
717
|
-
this.constants.DECIMALS[vaults[index]] = 18;
|
|
718
|
-
this.constants.DECIMALS[gauges[index]] = 18;
|
|
719
|
-
this.constants.ONE_WAY_MARKETS[`one-way-market-${index}`] = {
|
|
720
|
-
name: names[index],
|
|
721
|
-
addresses: {
|
|
722
|
-
amm: amms[index],
|
|
723
|
-
controller: controllers[index],
|
|
724
|
-
borrowed_token: borrowed_tokens[index],
|
|
725
|
-
collateral_token: collateral_tokens[index],
|
|
726
|
-
monetary_policy: monetary_policies[index],
|
|
727
|
-
vault: vaults[index],
|
|
728
|
-
gauge: gauges[index],
|
|
729
|
-
},
|
|
730
|
-
borrowed_token: COIN_DATA[borrowed_tokens[index]],
|
|
731
|
-
collateral_token: COIN_DATA[collateral_tokens[index]],
|
|
569
|
+
if (version === 'v1') {
|
|
570
|
+
cacheStats.set(cacheKey(controllers[i], 'total_debt'), res[(i * 8) + 0]);
|
|
571
|
+
cacheStats.set(cacheKey(vaults[i], 'totalAssets', controllers[i]), res[(i * 8) + 1]);
|
|
572
|
+
cacheStats.set(cacheKey(borrowed_tokens[i], 'balanceOf', controllers[i]), res[(i * 8) + 2]);
|
|
573
|
+
cacheStats.set(cacheKey(amms[i], 'rate'), res[(i * 8) + 3]);
|
|
574
|
+
cacheStats.set(cacheKey(borrowed_tokens[i], 'balanceOf', amms[i]), res[(i * 8) + 4]);
|
|
575
|
+
cacheStats.set(cacheKey(amms[i], 'admin_fees_x'), res[(i * 8) + 5]);
|
|
576
|
+
cacheStats.set(cacheKey(amms[i], 'admin_fees_y'), res[(i * 8) + 6]);
|
|
577
|
+
cacheStats.set(cacheKey(collateral_tokens[i], 'balanceOf', amms[i]), res[(i * 8) + 7]);
|
|
578
|
+
} else {
|
|
579
|
+
cacheStats.set(cacheKey(controllers[i], 'total_debt'), res[(i * 6) + 0]);
|
|
580
|
+
cacheStats.set(cacheKey(vaults[i], 'totalAssets', controllers[i]), res[(i * 6) + 1]);
|
|
581
|
+
cacheStats.set(cacheKey(borrowed_tokens[i], 'balanceOf', controllers[i]), res[(i * 6) + 2]);
|
|
582
|
+
cacheStats.set(cacheKey(amms[i], 'rate'), res[(i * 6) + 3]);
|
|
583
|
+
cacheStats.set(cacheKey(borrowed_tokens[i], 'balanceOf', amms[i]), res[(i * 6) + 4]);
|
|
584
|
+
cacheStats.set(cacheKey(amms[i], 'admin_fees_x'), BigInt(0)); // Always 0 for v2
|
|
585
|
+
cacheStats.set(cacheKey(amms[i], 'admin_fees_y'), BigInt(0)); // Always 0 for v2
|
|
586
|
+
cacheStats.set(cacheKey(collateral_tokens[i], 'balanceOf', amms[i]), res[(i * 6) + 5]);
|
|
732
587
|
}
|
|
733
|
-
})
|
|
734
|
-
|
|
735
|
-
this.constants.ONE_WAY_MARKETS = await this._filterHiddenMarkets(this.constants.ONE_WAY_MARKETS);
|
|
736
|
-
|
|
737
|
-
await this.fetchStats(amms, controllers, vaults, borrowed_tokens, collateral_tokens);
|
|
738
|
-
}
|
|
739
|
-
|
|
740
|
-
_fetchOneWayMarketsByAPI = async () => {
|
|
741
|
-
const {names, amms, controllers, borrowed_tokens, collateral_tokens, monetary_policies, vaults, gauges} = await this.getFactoryMarketDataByAPI()
|
|
742
|
-
const COIN_DATA = await this.getCoins(collateral_tokens, borrowed_tokens, true);
|
|
743
|
-
for (const c in COIN_DATA) {
|
|
744
|
-
this.constants.DECIMALS[c] = COIN_DATA[c].decimals;
|
|
745
588
|
}
|
|
746
|
-
|
|
747
|
-
amms.forEach((amm: string, index: number) => {
|
|
748
|
-
this.setContract(amms[index], LlammaABI);
|
|
749
|
-
this.setContract(controllers[index], ControllerABI);
|
|
750
|
-
this.setContract(monetary_policies[index], MonetaryPolicyABI);
|
|
751
|
-
this.setContract(vaults[index], VaultABI);
|
|
752
|
-
if(gauges[index]){
|
|
753
|
-
this.setContract(gauges[index], this.chainId === 1 ? GaugeABI : SidechainGaugeABI);
|
|
754
|
-
}
|
|
755
|
-
COIN_DATA[vaults[index]] = {
|
|
756
|
-
address: vaults[index],
|
|
757
|
-
decimals: 18,
|
|
758
|
-
name: "Curve Vault for " + COIN_DATA[borrowed_tokens[index]].name,
|
|
759
|
-
symbol: "cv" + COIN_DATA[borrowed_tokens[index]].symbol,
|
|
760
|
-
};
|
|
761
|
-
COIN_DATA[gauges[index]] = {
|
|
762
|
-
address: gauges[index],
|
|
763
|
-
decimals: 18,
|
|
764
|
-
name: "curve.finance " + COIN_DATA[borrowed_tokens[index]].name + " Gauge Deposit",
|
|
765
|
-
symbol: "cv" + COIN_DATA[borrowed_tokens[index]].symbol + "-gauge",
|
|
766
|
-
};
|
|
767
|
-
this.constants.DECIMALS[vaults[index]] = 18;
|
|
768
|
-
this.constants.DECIMALS[gauges[index]] = 18;
|
|
769
|
-
this.constants.ONE_WAY_MARKETS[`one-way-market-${index}`] = {
|
|
770
|
-
name: names[index],
|
|
771
|
-
addresses: {
|
|
772
|
-
amm: amms[index],
|
|
773
|
-
controller: controllers[index],
|
|
774
|
-
borrowed_token: borrowed_tokens[index],
|
|
775
|
-
collateral_token: collateral_tokens[index],
|
|
776
|
-
monetary_policy: monetary_policies[index],
|
|
777
|
-
vault: vaults[index],
|
|
778
|
-
gauge: gauges[index],
|
|
779
|
-
},
|
|
780
|
-
borrowed_token: COIN_DATA[borrowed_tokens[index]],
|
|
781
|
-
collateral_token: COIN_DATA[collateral_tokens[index]],
|
|
782
|
-
}
|
|
783
|
-
})
|
|
784
|
-
|
|
785
|
-
this.constants.ONE_WAY_MARKETS = await this._filterHiddenMarkets(this.constants.ONE_WAY_MARKETS);
|
|
786
|
-
}
|
|
589
|
+
};
|
|
787
590
|
|
|
788
591
|
formatUnits(value: BigNumberish, unit?: string | Numeric): string {
|
|
789
592
|
return ethers.formatUnits(value, unit);
|
package/src/utils.ts
CHANGED
|
@@ -19,7 +19,6 @@ export const createCall = (contract: ICurveContract, name: string, params: any[]
|
|
|
19
19
|
const func = _abi.find((f: JsonFragment) => f.name === _name)
|
|
20
20
|
const inputs = func?.inputs || [];
|
|
21
21
|
const outputs = func?.outputs || [];
|
|
22
|
-
|
|
23
22
|
return {
|
|
24
23
|
contract: {
|
|
25
24
|
address: contract.address,
|
|
@@ -289,48 +288,22 @@ export const _getUsdRate = async function (this: Llamalend, assetId: string): Pr
|
|
|
289
288
|
const pricesFromApi = await _getUsdPricesFromApi(this.constants.NETWORK_NAME);
|
|
290
289
|
if (assetId.toLowerCase() in pricesFromApi) return pricesFromApi[assetId.toLowerCase()];
|
|
291
290
|
|
|
292
|
-
if (assetId === 'USD' || (
|
|
291
|
+
if (assetId === 'USD' || (assetId.toLowerCase() === this.constants.COINS.am3crv.toLowerCase())) return 1
|
|
293
292
|
|
|
294
|
-
|
|
293
|
+
const chainName = {
|
|
295
294
|
1: 'ethereum',
|
|
296
295
|
10: 'optimistic-ethereum',
|
|
297
|
-
56: "binance-smart-chain",
|
|
298
|
-
100: 'xdai',
|
|
299
|
-
137: 'polygon-pos',
|
|
300
296
|
146: 'sonic',
|
|
301
|
-
196: 'x-layer',
|
|
302
|
-
250: 'fantom',
|
|
303
297
|
252: 'fraxtal',
|
|
304
|
-
324: 'zksync',
|
|
305
|
-
1284: 'moonbeam',
|
|
306
|
-
2222: 'kava',
|
|
307
|
-
5000: 'mantle',
|
|
308
|
-
8453: 'base',
|
|
309
|
-
42220: 'celo',
|
|
310
|
-
43114: 'avalanche',
|
|
311
298
|
42161: 'arbitrum-one',
|
|
312
|
-
1313161554: 'aurora',
|
|
313
299
|
}[this.chainId];
|
|
314
300
|
|
|
315
301
|
const nativeTokenName = {
|
|
316
302
|
1: 'ethereum',
|
|
317
303
|
10: 'ethereum',
|
|
318
|
-
56: 'binancecoin',
|
|
319
|
-
100: 'xdai',
|
|
320
|
-
137: 'matic-network',
|
|
321
304
|
146: 'sonic-3',
|
|
322
|
-
196: 'okb',
|
|
323
|
-
250: 'fantom',
|
|
324
305
|
252: 'frax-ether',
|
|
325
|
-
324: 'ethereum',
|
|
326
|
-
1284: 'moonbeam',
|
|
327
|
-
2222: 'kava',
|
|
328
|
-
5000: 'mantle',
|
|
329
|
-
8453: 'ethereum',
|
|
330
|
-
42220: 'celo',
|
|
331
|
-
43114: 'avalanche-2',
|
|
332
306
|
42161: 'ethereum',
|
|
333
|
-
1313161554: 'ethereum',
|
|
334
307
|
}[this.chainId] as string;
|
|
335
308
|
|
|
336
309
|
if (chainName === undefined) {
|
|
@@ -346,12 +319,6 @@ export const _getUsdRate = async function (this: Llamalend, assetId: string): Pr
|
|
|
346
319
|
}[assetId.toUpperCase()] || assetId
|
|
347
320
|
assetId = isEth(assetId) ? nativeTokenName : assetId.toLowerCase();
|
|
348
321
|
|
|
349
|
-
// No EURT on Coingecko Polygon
|
|
350
|
-
if (this.chainId === 137 && assetId.toLowerCase() === this.constants.COINS.eurt) {
|
|
351
|
-
chainName = 'ethereum';
|
|
352
|
-
assetId = '0xC581b735A1688071A1746c968e0798D642EDE491'.toLowerCase(); // EURT Ethereum
|
|
353
|
-
}
|
|
354
|
-
|
|
355
322
|
// CRV
|
|
356
323
|
if (assetId.toLowerCase() === this.constants.ALIASES.crv) {
|
|
357
324
|
assetId = 'curve-dao-token';
|