@curvefi/llamalend-api 2.0.22 → 2.0.23
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/lib/external-api.d.ts +12 -1
- package/lib/external-api.js +12 -7
- package/lib/index.d.ts +6 -2
- package/lib/index.js +1 -2
- package/lib/lendMarkets/fetch/fetchLendMarkets.js +0 -13
- package/lib/llamalend.d.ts +8 -4
- package/lib/llamalend.js +101 -177
- package/lib/mintMarkets/fetch/fetchMintMarkets.d.ts +3 -0
- package/lib/mintMarkets/fetch/fetchMintMarkets.js +135 -0
- package/package.json +1 -1
- package/src/external-api.ts +28 -12
- package/src/index.ts +1 -3
- package/src/lendMarkets/fetch/fetchLendMarkets.ts +0 -14
- package/src/llamalend.ts +124 -199
- package/src/mintMarkets/fetch/fetchMintMarkets.ts +146 -0
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import type { Llamalend } from "../../llamalend.js";
|
|
2
|
+
import { _getCrvUsdMarketsData } from "../../external-api.js";
|
|
3
|
+
import ERC20ABI from '../../constants/abis/ERC20.json' with {type: 'json'};
|
|
4
|
+
import llammaABI from "../../constants/abis/crvUSD/llamma.json" with {type: 'json'};
|
|
5
|
+
import controllerABI from "../../constants/abis/crvUSD/controller.json" with {type: 'json'};
|
|
6
|
+
import controllerV2ABI from "../../constants/abis/crvUSD/controller_v2.json";
|
|
7
|
+
import FactoryABI from "../../constants/abis/crvUSD/Factory.json" with {type: 'json'};
|
|
8
|
+
import MonetaryPolicy2ABI from "../../constants/abis/crvUSD/MonetaryPolicy2.json" with {type: 'json'};
|
|
9
|
+
|
|
10
|
+
export const fetchMintMarketsByAPI = async (llamalend: Llamalend): Promise<void> => {
|
|
11
|
+
if (llamalend.chainId !== 1) return;
|
|
12
|
+
|
|
13
|
+
const data = await _getCrvUsdMarketsData();
|
|
14
|
+
|
|
15
|
+
const existingControllers = new Set(
|
|
16
|
+
Object.values(llamalend.constants.LLAMMAS).map((l) => l.controller_address)
|
|
17
|
+
);
|
|
18
|
+
const newMarkets = data.filter((m) => !existingControllers.has(m.address.toLowerCase()));
|
|
19
|
+
|
|
20
|
+
if (newMarkets.length === 0) return;
|
|
21
|
+
|
|
22
|
+
const N1 = Object.keys(llamalend.constants.LLAMMAS).length;
|
|
23
|
+
const controllers = newMarkets.map((m) => m.address.toLowerCase());
|
|
24
|
+
const amms = newMarkets.map((m) => m.llamma.toLowerCase());
|
|
25
|
+
const collaterals = newMarkets.map((m) => m.collateral_token.address.toLowerCase());
|
|
26
|
+
|
|
27
|
+
for (const collateral of collaterals) llamalend.setContract(collateral, ERC20ABI);
|
|
28
|
+
for (const amm of amms) llamalend.setContract(amm, llammaABI);
|
|
29
|
+
for (const controller of controllers) llamalend.setContract(controller, controllerABI);
|
|
30
|
+
|
|
31
|
+
for (let i = 0; i < newMarkets.length; i++) {
|
|
32
|
+
const market = newMarkets[i];
|
|
33
|
+
const collateral_address = collaterals[i];
|
|
34
|
+
const is_eth = collateral_address === llamalend.constants.WETH;
|
|
35
|
+
const collateral_symbol = market.collateral_token.symbol;
|
|
36
|
+
const monetary_policy_address = market.monetary_policy_address.toLowerCase();
|
|
37
|
+
|
|
38
|
+
llamalend.setContract(monetary_policy_address, MonetaryPolicy2ABI);
|
|
39
|
+
|
|
40
|
+
const _llammaId = is_eth ? "eth" : collateral_symbol.toLowerCase();
|
|
41
|
+
let llammaId = _llammaId;
|
|
42
|
+
let j = 2;
|
|
43
|
+
while (llammaId in llamalend.constants.LLAMMAS) llammaId = _llammaId + j++;
|
|
44
|
+
|
|
45
|
+
llamalend.constants.LLAMMAS[llammaId] = {
|
|
46
|
+
amm_address: amms[i],
|
|
47
|
+
controller_address: controllers[i],
|
|
48
|
+
monetary_policy_address,
|
|
49
|
+
collateral_address: is_eth ? "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee" : collateral_address,
|
|
50
|
+
leverage_zap: llamalend.constants.ALIASES.leverage_zap,
|
|
51
|
+
deleverage_zap: "0x0000000000000000000000000000000000000000",
|
|
52
|
+
collateral_symbol: is_eth ? "ETH" : collateral_symbol,
|
|
53
|
+
collateral_decimals: market.collateral_token.decimals,
|
|
54
|
+
min_bands: 4,
|
|
55
|
+
max_bands: 50,
|
|
56
|
+
default_bands: 10,
|
|
57
|
+
A: market.amm_a,
|
|
58
|
+
monetary_policy_abi: MonetaryPolicy2ABI,
|
|
59
|
+
is_deleverage_supported: true,
|
|
60
|
+
index: N1 + i,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
export const fetchMintMarketsByBlockchain = async (llamalend: Llamalend): Promise<void> => {
|
|
66
|
+
if (llamalend.chainId !== 1) return;
|
|
67
|
+
|
|
68
|
+
llamalend.setContract(llamalend.constants.FACTORY, FactoryABI);
|
|
69
|
+
const factoryContract = llamalend.contracts[llamalend.constants.FACTORY].contract;
|
|
70
|
+
const factoryMulticallContract = llamalend.contracts[llamalend.constants.FACTORY].multicallContract;
|
|
71
|
+
|
|
72
|
+
const N1 = Object.keys(llamalend.constants.LLAMMAS).length;
|
|
73
|
+
const N2 = await factoryContract.n_collaterals(llamalend.constantOptions);
|
|
74
|
+
let calls = [];
|
|
75
|
+
for (let i = N1; i < N2; i++) {
|
|
76
|
+
calls.push(
|
|
77
|
+
factoryMulticallContract.collaterals(i),
|
|
78
|
+
factoryMulticallContract.amms(i),
|
|
79
|
+
factoryMulticallContract.controllers(i)
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
const res: string[] = (await llamalend.multicallProvider.all(calls) as string[]).map((c) => c.toLowerCase());
|
|
83
|
+
const collaterals = res.filter((a, i) => i % 3 == 0) as string[];
|
|
84
|
+
const amms = res.filter((a, i) => i % 3 == 1) as string[];
|
|
85
|
+
const controllers = res.filter((a, i) => i % 3 == 2) as string[];
|
|
86
|
+
|
|
87
|
+
if (collaterals.length === 0) return;
|
|
88
|
+
|
|
89
|
+
for (const collateral of collaterals) llamalend.setContract(collateral, ERC20ABI);
|
|
90
|
+
|
|
91
|
+
calls = [];
|
|
92
|
+
for (const collateral of collaterals) {
|
|
93
|
+
calls.push(
|
|
94
|
+
llamalend.contracts[collateral].multicallContract.symbol(),
|
|
95
|
+
llamalend.contracts[collateral].multicallContract.decimals()
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
const collateralData = (await llamalend.multicallProvider.all(calls)).map((x) => {
|
|
99
|
+
if (typeof x === "string") return x.toLowerCase();
|
|
100
|
+
return x;
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
calls = [];
|
|
104
|
+
for (const amm of amms) {
|
|
105
|
+
llamalend.setContract(amm, llammaABI);
|
|
106
|
+
calls.push(llamalend.contracts[amm].multicallContract.A());
|
|
107
|
+
}
|
|
108
|
+
const AParams = (await llamalend.multicallProvider.all(calls)).map((x) => Number(x));
|
|
109
|
+
|
|
110
|
+
for (let i = 0; i < collaterals.length; i++) {
|
|
111
|
+
const is_eth = collaterals[i] === llamalend.constants.WETH;
|
|
112
|
+
const [collateral_symbol, collateral_decimals] = collateralData.splice(0, 2) as [string, number];
|
|
113
|
+
|
|
114
|
+
if (i >= collaterals.length - 3) {
|
|
115
|
+
llamalend.setContract(controllers[i], controllerV2ABI);
|
|
116
|
+
} else {
|
|
117
|
+
llamalend.setContract(controllers[i], controllerABI);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
const monetary_policy_address = (await llamalend.contracts[controllers[i]].contract.monetary_policy(llamalend.constantOptions)).toLowerCase();
|
|
121
|
+
llamalend.setContract(monetary_policy_address, MonetaryPolicy2ABI);
|
|
122
|
+
|
|
123
|
+
const _llammaId: string = is_eth ? "eth" : collateral_symbol.toLowerCase();
|
|
124
|
+
let llammaId = _llammaId;
|
|
125
|
+
let j = 2;
|
|
126
|
+
while (llammaId in llamalend.constants.LLAMMAS) llammaId = _llammaId + j++;
|
|
127
|
+
|
|
128
|
+
llamalend.constants.LLAMMAS[llammaId] = {
|
|
129
|
+
amm_address: amms[i],
|
|
130
|
+
controller_address: controllers[i],
|
|
131
|
+
monetary_policy_address,
|
|
132
|
+
collateral_address: is_eth ? "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee" : collaterals[i],
|
|
133
|
+
leverage_zap: llamalend.constants.ALIASES.leverage_zap,
|
|
134
|
+
deleverage_zap: "0x0000000000000000000000000000000000000000",
|
|
135
|
+
collateral_symbol: is_eth ? "ETH" : collateral_symbol,
|
|
136
|
+
collateral_decimals,
|
|
137
|
+
min_bands: 4,
|
|
138
|
+
max_bands: 50,
|
|
139
|
+
default_bands: 10,
|
|
140
|
+
A: AParams[i],
|
|
141
|
+
monetary_policy_abi: MonetaryPolicy2ABI,
|
|
142
|
+
is_deleverage_supported: true,
|
|
143
|
+
index: N1 + i,
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
};
|