@curvefi/llamalend-api 1.0.4 → 1.0.7
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/.github/workflows/lint.yml +2 -2
- package/.github/workflows/publish.yml +11 -7
- package/eslint.config.mjs +87 -0
- package/lib/cache/index.js +18 -19
- package/lib/constants/L2Networks.js +1 -1
- package/lib/constants/aliases.js +28 -28
- package/lib/constants/coins.js +16 -16
- package/lib/constants/llammas.js +1 -1
- package/lib/constants/utils.js +8 -10
- package/lib/external-api.d.ts +8 -6
- package/lib/external-api.js +136 -397
- package/lib/index.d.ts +12 -11
- package/lib/index.js +49 -82
- package/lib/interfaces.d.ts +3 -18
- package/lib/lendMarkets/LendMarketTemplate.js +2438 -4440
- package/lib/lendMarkets/lendMarketConstructor.js +2 -2
- package/lib/llamalend.js +510 -722
- package/lib/mintMarkets/MintMarketTemplate.js +1469 -2799
- package/lib/mintMarkets/mintMarketConstructor.js +1 -1
- package/lib/st-crvUSD.js +172 -488
- package/lib/utils.d.ts +2 -2
- package/lib/utils.js +318 -548
- package/package.json +21 -16
- package/src/cache/index.ts +1 -0
- package/src/external-api.ts +27 -148
- package/src/index.ts +3 -1
- package/src/interfaces.ts +4 -19
- package/src/lendMarkets/LendMarketTemplate.ts +5 -5
- package/src/llamalend.ts +2 -2
- package/src/mintMarkets/MintMarketTemplate.ts +7 -7
- package/src/utils.ts +6 -6
- package/tsconfig.json +1 -1
- package/.eslintrc.json +0 -40
package/lib/external-api.js
CHANGED
|
@@ -1,14 +1,3 @@
|
|
|
1
|
-
var __assign = (this && this.__assign) || function () {
|
|
2
|
-
__assign = Object.assign || function(t) {
|
|
3
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
-
s = arguments[i];
|
|
5
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
-
t[p] = s[p];
|
|
7
|
-
}
|
|
8
|
-
return t;
|
|
9
|
-
};
|
|
10
|
-
return __assign.apply(this, arguments);
|
|
11
|
-
};
|
|
12
1
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
13
2
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
14
3
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -18,419 +7,169 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
18
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
19
8
|
});
|
|
20
9
|
};
|
|
21
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
22
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
23
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
24
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
25
|
-
function step(op) {
|
|
26
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
27
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
28
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
29
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
30
|
-
switch (op[0]) {
|
|
31
|
-
case 0: case 1: t = op; break;
|
|
32
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
33
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
34
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
35
|
-
default:
|
|
36
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
37
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
38
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
39
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
40
|
-
if (t[2]) _.ops.pop();
|
|
41
|
-
_.trys.pop(); continue;
|
|
42
|
-
}
|
|
43
|
-
op = body.call(thisArg, _);
|
|
44
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
45
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
import axios from "axios";
|
|
49
10
|
import { ethers } from "ethers";
|
|
50
11
|
import memoize from "memoizee";
|
|
51
|
-
import BigNumber from 'bignumber.js';
|
|
52
12
|
import { llamalend } from "./llamalend.js";
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
return
|
|
57
|
-
|
|
58
|
-
case 0:
|
|
59
|
-
url = "https://api.curve.fi/api/getPools/".concat(network, "/").concat(poolFactory);
|
|
60
|
-
return [4 /*yield*/, axios.get(url, { validateStatus: function () { return true; } })];
|
|
61
|
-
case 1:
|
|
62
|
-
response = _b.sent();
|
|
63
|
-
return [2 /*return*/, (_a = response.data.data) !== null && _a !== void 0 ? _a : { poolData: [], tvl: 0, tvlAll: 0 }];
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
}); }, {
|
|
13
|
+
const _getPoolsFromApi = memoize((network, poolFactory) => __awaiter(void 0, void 0, void 0, function* () {
|
|
14
|
+
const response = yield fetch(`https://api.curve.fi/api/getPools/${network}/${poolFactory}`);
|
|
15
|
+
const { data } = yield response.json();
|
|
16
|
+
return data !== null && data !== void 0 ? data : { poolData: [], tvl: 0, tvlAll: 0 };
|
|
17
|
+
}), {
|
|
67
18
|
promise: true,
|
|
68
19
|
maxAge: 5 * 60 * 1000, // 5m
|
|
69
20
|
});
|
|
70
|
-
|
|
71
|
-
return
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
coin = _d[_c];
|
|
120
|
-
if (typeof coin.usdPrice === "number") {
|
|
121
|
-
if (coin.address.toLowerCase() in priceDict) {
|
|
122
|
-
priceDict[coin.address.toLowerCase()].push({
|
|
123
|
-
price: coin.usdPrice,
|
|
124
|
-
tvl: pool.usdTotal,
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
else {
|
|
128
|
-
priceDict[coin.address.toLowerCase()] = [];
|
|
129
|
-
priceDict[coin.address.toLowerCase()].push({
|
|
130
|
-
price: coin.usdPrice,
|
|
131
|
-
tvl: pool.usdTotal,
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
for (_e = 0, _f = (_h = pool.gaugeRewards) !== null && _h !== void 0 ? _h : []; _e < _f.length; _e++) {
|
|
137
|
-
coin = _f[_e];
|
|
138
|
-
if (typeof coin.tokenPrice === "number") {
|
|
139
|
-
if (coin.tokenAddress.toLowerCase() in priceDict) {
|
|
140
|
-
priceDict[coin.tokenAddress.toLowerCase()].push({
|
|
141
|
-
price: coin.tokenPrice,
|
|
142
|
-
tvl: pool.usdTotal,
|
|
143
|
-
});
|
|
144
|
-
}
|
|
145
|
-
else {
|
|
146
|
-
priceDict[coin.tokenAddress.toLowerCase()] = [];
|
|
147
|
-
priceDict[coin.tokenAddress.toLowerCase()].push({
|
|
148
|
-
price: coin.tokenPrice,
|
|
149
|
-
tvl: pool.usdTotal,
|
|
150
|
-
});
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
}
|
|
21
|
+
const _getAllPoolsFromApi = (network) => __awaiter(void 0, void 0, void 0, function* () {
|
|
22
|
+
return yield Promise.all([
|
|
23
|
+
_getPoolsFromApi(network, "main"),
|
|
24
|
+
_getPoolsFromApi(network, "crypto"),
|
|
25
|
+
_getPoolsFromApi(network, "factory"),
|
|
26
|
+
_getPoolsFromApi(network, "factory-crvusd"),
|
|
27
|
+
_getPoolsFromApi(network, "factory-crypto"),
|
|
28
|
+
_getPoolsFromApi(network, "factory-twocrypto"),
|
|
29
|
+
_getPoolsFromApi(network, "factory-tricrypto"),
|
|
30
|
+
_getPoolsFromApi(network, "factory-stable-ng"),
|
|
31
|
+
]);
|
|
32
|
+
});
|
|
33
|
+
export const _getUsdPricesFromApi = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
34
|
+
var _a, _b;
|
|
35
|
+
const network = llamalend.constants.NETWORK_NAME;
|
|
36
|
+
const allTypesExtendedPoolData = yield _getAllPoolsFromApi(network);
|
|
37
|
+
const priceDict = {};
|
|
38
|
+
const priceDictByMaxTvl = {};
|
|
39
|
+
for (const extendedPoolData of allTypesExtendedPoolData) {
|
|
40
|
+
for (const pool of extendedPoolData.poolData) {
|
|
41
|
+
const lpTokenAddress = (_a = pool.lpTokenAddress) !== null && _a !== void 0 ? _a : pool.address;
|
|
42
|
+
const totalSupply = pool.totalSupply / (Math.pow(10, 18));
|
|
43
|
+
if (lpTokenAddress.toLowerCase() in priceDict) {
|
|
44
|
+
priceDict[lpTokenAddress.toLowerCase()].push({
|
|
45
|
+
price: pool.usdTotal && totalSupply ? pool.usdTotal / totalSupply : 0,
|
|
46
|
+
tvl: pool.usdTotal,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
priceDict[lpTokenAddress.toLowerCase()] = [];
|
|
51
|
+
priceDict[lpTokenAddress.toLowerCase()].push({
|
|
52
|
+
price: pool.usdTotal && totalSupply ? pool.usdTotal / totalSupply : 0,
|
|
53
|
+
tvl: pool.usdTotal,
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
for (const coin of pool.coins) {
|
|
57
|
+
if (typeof coin.usdPrice === "number") {
|
|
58
|
+
if (coin.address.toLowerCase() in priceDict) {
|
|
59
|
+
priceDict[coin.address.toLowerCase()].push({
|
|
60
|
+
price: coin.usdPrice,
|
|
61
|
+
tvl: pool.usdTotal,
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
priceDict[coin.address.toLowerCase()] = [];
|
|
66
|
+
priceDict[coin.address.toLowerCase()].push({
|
|
67
|
+
price: coin.usdPrice,
|
|
68
|
+
tvl: pool.usdTotal,
|
|
69
|
+
});
|
|
154
70
|
}
|
|
155
71
|
}
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
return prev;
|
|
164
|
-
}
|
|
72
|
+
}
|
|
73
|
+
for (const coin of (_b = pool.gaugeRewards) !== null && _b !== void 0 ? _b : []) {
|
|
74
|
+
if (typeof coin.tokenPrice === "number") {
|
|
75
|
+
if (coin.tokenAddress.toLowerCase() in priceDict) {
|
|
76
|
+
priceDict[coin.tokenAddress.toLowerCase()].push({
|
|
77
|
+
price: coin.tokenPrice,
|
|
78
|
+
tvl: pool.usdTotal,
|
|
165
79
|
});
|
|
166
|
-
priceDictByMaxTvl[address] = maxTvlItem.price;
|
|
167
80
|
}
|
|
168
81
|
else {
|
|
169
|
-
|
|
82
|
+
priceDict[coin.tokenAddress.toLowerCase()] = [];
|
|
83
|
+
priceDict[coin.tokenAddress.toLowerCase()].push({
|
|
84
|
+
price: coin.tokenPrice,
|
|
85
|
+
tvl: pool.usdTotal,
|
|
86
|
+
});
|
|
170
87
|
}
|
|
171
88
|
}
|
|
172
|
-
|
|
89
|
+
}
|
|
173
90
|
}
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
total_deposit_precise: response.data.total_deposit_precise,
|
|
187
|
-
total_deposit_from_user: response.data.total_deposit_from_user,
|
|
188
|
-
total_deposit_usd_value: response.data.total_deposit_usd_value,
|
|
189
|
-
}];
|
|
91
|
+
}
|
|
92
|
+
for (const address in priceDict) {
|
|
93
|
+
if (priceDict[address].length > 0) {
|
|
94
|
+
const maxTvlItem = priceDict[address].reduce((prev, current) => {
|
|
95
|
+
if (+current.tvl > +prev.tvl) {
|
|
96
|
+
return current;
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
return prev;
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
priceDictByMaxTvl[address] = maxTvlItem.price;
|
|
190
103
|
}
|
|
191
|
-
|
|
192
|
-
|
|
104
|
+
else {
|
|
105
|
+
priceDictByMaxTvl[address] = 0;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return priceDictByMaxTvl;
|
|
109
|
+
});
|
|
110
|
+
export const _getUserCollateral = memoize((network, controller, user) => __awaiter(void 0, void 0, void 0, function* () {
|
|
111
|
+
const url = `https://prices.curve.fi/v1/lending/collateral_events/${network}/${controller}/${user}`;
|
|
112
|
+
const response = yield fetch(url);
|
|
113
|
+
const data = yield response.json();
|
|
114
|
+
return {
|
|
115
|
+
total_deposit_precise: data.total_deposit_precise,
|
|
116
|
+
total_deposit_from_user: data.total_deposit_from_user,
|
|
117
|
+
total_deposit_usd_value: data.total_deposit_usd_value,
|
|
118
|
+
};
|
|
119
|
+
}), {
|
|
193
120
|
promise: true,
|
|
194
121
|
maxAge: 60 * 1000, // 1m
|
|
195
122
|
});
|
|
196
|
-
export
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
return [4 /*yield*/, axios.get(url, { validateStatus: function () { return true; } })];
|
|
203
|
-
case 1:
|
|
204
|
-
response = _a.sent();
|
|
205
|
-
return [2 /*return*/, response.data.total_deposit];
|
|
206
|
-
}
|
|
207
|
-
});
|
|
208
|
-
}); }, {
|
|
123
|
+
export const _getUserCollateralCrvUsd = memoize((network, controller, user) => __awaiter(void 0, void 0, void 0, function* () {
|
|
124
|
+
const url = `https://prices.curve.fi/v1/crvusd/collateral_events/${network}/${controller}/${user}`;
|
|
125
|
+
const response = yield fetch(url);
|
|
126
|
+
const { total_deposit } = yield response.json();
|
|
127
|
+
return total_deposit;
|
|
128
|
+
}), {
|
|
209
129
|
promise: true,
|
|
210
130
|
maxAge: 60 * 1000, // 1m
|
|
211
131
|
});
|
|
212
|
-
export
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
validateStatus: function () { return true; },
|
|
221
|
-
})];
|
|
222
|
-
case 1:
|
|
223
|
-
response = _a.sent();
|
|
224
|
-
if (response.status !== 200) {
|
|
225
|
-
throw Error("Fetch error: ".concat(response.status, " ").concat(response.statusText));
|
|
226
|
-
}
|
|
227
|
-
return [2 /*return*/, response.data.data];
|
|
228
|
-
}
|
|
229
|
-
});
|
|
230
|
-
}); }, {
|
|
132
|
+
export const _getMarketsData = memoize((network) => __awaiter(void 0, void 0, void 0, function* () {
|
|
133
|
+
const url = `https://api.curve.fi/api/getLendingVaults/${network}/oneway`;
|
|
134
|
+
const response = yield fetch(url, { headers: { "accept": "application/json" } });
|
|
135
|
+
if (response.status !== 200) {
|
|
136
|
+
throw Error(`Fetch error: ${response.status} ${response.statusText}`);
|
|
137
|
+
}
|
|
138
|
+
return (yield response.json()).data;
|
|
139
|
+
}), {
|
|
231
140
|
promise: true,
|
|
232
141
|
maxAge: 10 * 1000, // 10s
|
|
233
142
|
});
|
|
234
143
|
// --- ODOS ---
|
|
235
|
-
export
|
|
236
|
-
if (
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
return [4 /*yield*/, axios.get(url, {
|
|
252
|
-
headers: { "accept": "application/json" },
|
|
253
|
-
validateStatus: function () { return true; },
|
|
254
|
-
})];
|
|
255
|
-
case 1:
|
|
256
|
-
response = _a.sent();
|
|
257
|
-
if (response.status !== 200) {
|
|
258
|
-
throw Error("Odos quote error - ".concat(response.status, " ").concat(response.statusText));
|
|
259
|
-
}
|
|
260
|
-
return [2 /*return*/, __assign(__assign({}, response.data), { slippage: slippage })];
|
|
261
|
-
}
|
|
262
|
-
});
|
|
263
|
-
});
|
|
264
|
-
};
|
|
265
|
-
export var _getExpectedOdos = function (fromToken, toToken, _amount, blacklist) { return __awaiter(void 0, void 0, void 0, function () {
|
|
266
|
-
return __generator(this, function (_a) {
|
|
267
|
-
switch (_a.label) {
|
|
268
|
-
case 0: return [4 /*yield*/, _getQuoteOdos(fromToken, toToken, _amount, blacklist, false)];
|
|
269
|
-
case 1: return [2 /*return*/, (_a.sent()).outAmounts[0]];
|
|
270
|
-
}
|
|
271
|
-
});
|
|
272
|
-
}); };
|
|
273
|
-
export var _assembleTxOdos = memoize(function (pathId) { return __awaiter(void 0, void 0, void 0, function () {
|
|
274
|
-
var url, response;
|
|
275
|
-
return __generator(this, function (_a) {
|
|
276
|
-
switch (_a.label) {
|
|
277
|
-
case 0:
|
|
278
|
-
url = "https://prices.curve.fi/odos/assemble?user=".concat(ethers.getAddress(llamalend.constants.ALIASES.leverage_zap), "&path_id=").concat(pathId);
|
|
279
|
-
return [4 /*yield*/, axios.get(url, {
|
|
280
|
-
headers: { 'Content-Type': 'application/json' },
|
|
281
|
-
validateStatus: function () { return true; },
|
|
282
|
-
})];
|
|
283
|
-
case 1:
|
|
284
|
-
response = _a.sent();
|
|
285
|
-
if (response.status !== 200) {
|
|
286
|
-
throw Error("Odos assemble error - ".concat(response.status, " ").concat(response.statusText));
|
|
287
|
-
}
|
|
288
|
-
return [2 /*return*/, response.data['transaction']['data']];
|
|
289
|
-
}
|
|
290
|
-
});
|
|
291
|
-
}); }, {
|
|
292
|
-
promise: true,
|
|
293
|
-
maxAge: 10 * 1000, // 10s
|
|
294
|
-
});
|
|
295
|
-
export var _getSpotPriceOdos = memoize(function (fromToken, toToken) { return __awaiter(void 0, void 0, void 0, function () {
|
|
296
|
-
var url, response, pricesFromOdos, pricesFromApi, _i, _a, coin, _pricesFromApi, prices;
|
|
297
|
-
return __generator(this, function (_b) {
|
|
298
|
-
switch (_b.label) {
|
|
299
|
-
case 0:
|
|
300
|
-
fromToken = ethers.getAddress(fromToken);
|
|
301
|
-
toToken = ethers.getAddress(toToken);
|
|
302
|
-
url = "https://prices.curve.fi/odos/prices?chain_id=".concat(llamalend.chainId, "&tokens=").concat(fromToken, ",").concat(toToken);
|
|
303
|
-
return [4 /*yield*/, axios.get(url, {
|
|
304
|
-
headers: { "accept": "application/json" },
|
|
305
|
-
validateStatus: function () { return true; },
|
|
306
|
-
})];
|
|
307
|
-
case 1:
|
|
308
|
-
response = _b.sent();
|
|
309
|
-
if (response.status !== 200) {
|
|
310
|
-
throw Error("Odos spot prices error - ".concat(response.status, " ").concat(response.statusText));
|
|
311
|
-
}
|
|
312
|
-
pricesFromOdos = response.data.tokenPrices;
|
|
313
|
-
pricesFromApi = {};
|
|
314
|
-
_i = 0, _a = [fromToken, toToken];
|
|
315
|
-
_b.label = 2;
|
|
316
|
-
case 2:
|
|
317
|
-
if (!(_i < _a.length)) return [3 /*break*/, 5];
|
|
318
|
-
coin = _a[_i];
|
|
319
|
-
if (pricesFromOdos[coin] !== 0)
|
|
320
|
-
return [3 /*break*/, 4];
|
|
321
|
-
return [4 /*yield*/, _getUsdPricesFromApi()];
|
|
322
|
-
case 3:
|
|
323
|
-
_pricesFromApi = _b.sent();
|
|
324
|
-
pricesFromApi[coin] = String(_pricesFromApi[coin] || 0);
|
|
325
|
-
_b.label = 4;
|
|
326
|
-
case 4:
|
|
327
|
-
_i++;
|
|
328
|
-
return [3 /*break*/, 2];
|
|
329
|
-
case 5:
|
|
330
|
-
prices = __assign(__assign({}, pricesFromOdos), pricesFromApi);
|
|
331
|
-
if (BigNumber(prices[fromToken]).eq(0) || BigNumber(prices[toToken]).eq(0))
|
|
332
|
-
return [2 /*return*/, undefined];
|
|
333
|
-
return [2 /*return*/, (new BigNumber(prices[toToken])).div(prices[fromToken]).toString()];
|
|
334
|
-
}
|
|
335
|
-
});
|
|
336
|
-
}); }, {
|
|
337
|
-
promise: true,
|
|
338
|
-
maxAge: 10 * 1000, // 10s
|
|
144
|
+
export const _getQuoteOdos = (fromToken_1, toToken_1, _amount_1, blacklist_1, pathVizImage_1, ...args_1) => __awaiter(void 0, [fromToken_1, toToken_1, _amount_1, blacklist_1, pathVizImage_1, ...args_1], void 0, function* (fromToken, toToken, _amount, blacklist, pathVizImage, slippage = 0.5) {
|
|
145
|
+
if (_amount === BigInt(0))
|
|
146
|
+
return { outAmounts: ["0.0"], pathId: '', pathVizImage: '', priceImpact: 0, slippage };
|
|
147
|
+
if (ethers.getAddress(fromToken) == "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE")
|
|
148
|
+
fromToken = "0x0000000000000000000000000000000000000000";
|
|
149
|
+
if (ethers.getAddress(toToken) == "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE")
|
|
150
|
+
toToken = "0x0000000000000000000000000000000000000000";
|
|
151
|
+
const url = `https://prices.curve.fi/odos/quote?chain_id=${llamalend.chainId}&from_address=${ethers.getAddress(fromToken)}` +
|
|
152
|
+
`&to_address=${ethers.getAddress(toToken)}&amount=${_amount.toString()}&slippage=${slippage}&pathVizImage=${pathVizImage}` +
|
|
153
|
+
`&caller_address=${ethers.getAddress(llamalend.constants.ALIASES.leverage_zap)}&blacklist=${ethers.getAddress(blacklist)}`;
|
|
154
|
+
const response = yield fetch(url, { headers: { "accept": "application/json" } });
|
|
155
|
+
if (response.status !== 200) {
|
|
156
|
+
throw Error(`Odos quote error - ${response.status} ${response.statusText}`);
|
|
157
|
+
}
|
|
158
|
+
const data = yield response.json();
|
|
159
|
+
return Object.assign(Object.assign({}, data), { slippage });
|
|
339
160
|
});
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
var url, response;
|
|
343
|
-
return __generator(this, function (_a) {
|
|
344
|
-
switch (_a.label) {
|
|
345
|
-
case 0:
|
|
346
|
-
if (_amount === BigInt(0))
|
|
347
|
-
return [2 /*return*/, "0.0"];
|
|
348
|
-
url = "https://prices.curve.fi/1inch/swap/v6.0/".concat(llamalend.chainId, "/quote?src=").concat(fromToken, "&dst=").concat(toToken, "&amount=").concat(_amount, "&excludedProtocols=").concat(llamalend.constants.EXCLUDED_PROTOCOLS_1INCH, "&includeTokensInfo=true&includeProtocols=true");
|
|
349
|
-
return [4 /*yield*/, axios.get(url, {
|
|
350
|
-
headers: { "accept": "application/json" },
|
|
351
|
-
validateStatus: function () { return true; },
|
|
352
|
-
})];
|
|
353
|
-
case 1:
|
|
354
|
-
response = _a.sent();
|
|
355
|
-
if (response.status !== 200) {
|
|
356
|
-
throw Error("1inch error: ".concat(response.status, " ").concat(response.statusText));
|
|
357
|
-
}
|
|
358
|
-
return [2 /*return*/, response.data.dstAmount];
|
|
359
|
-
}
|
|
360
|
-
});
|
|
361
|
-
}); }, {
|
|
362
|
-
promise: true,
|
|
363
|
-
maxAge: 10 * 1000, // 10s
|
|
161
|
+
export const _getExpectedOdos = (fromToken, toToken, _amount, blacklist) => __awaiter(void 0, void 0, void 0, function* () {
|
|
162
|
+
return (yield _getQuoteOdos(fromToken, toToken, _amount, blacklist, false)).outAmounts[0];
|
|
364
163
|
});
|
|
365
|
-
export
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
headers: { "accept": "application/json" },
|
|
375
|
-
validateStatus: function () { return true; },
|
|
376
|
-
})];
|
|
377
|
-
case 1:
|
|
378
|
-
response = _a.sent();
|
|
379
|
-
if (response.status !== 200) {
|
|
380
|
-
throw Error("1inch error: ".concat(response.status, " ").concat(response.statusText));
|
|
381
|
-
}
|
|
382
|
-
return [2 /*return*/, response.data];
|
|
383
|
-
}
|
|
384
|
-
});
|
|
385
|
-
}); }, {
|
|
386
|
-
promise: true,
|
|
387
|
-
maxAge: 10 * 1000, // 10s
|
|
388
|
-
});
|
|
389
|
-
export var _getSpotPrice1inch = memoize(function (fromToken, toToken) { return __awaiter(void 0, void 0, void 0, function () {
|
|
390
|
-
var url, response, pricesFromApi, _a, _b, _c, _i, coin, _pricesFromApi, prices;
|
|
391
|
-
return __generator(this, function (_d) {
|
|
392
|
-
switch (_d.label) {
|
|
393
|
-
case 0:
|
|
394
|
-
url = "https://prices.curve.fi/1inch/price/v1.1/".concat(llamalend.chainId, "?tokens=").concat(fromToken, ",").concat(toToken, "¤cy=USD");
|
|
395
|
-
return [4 /*yield*/, axios.get(url, {
|
|
396
|
-
headers: { "accept": "application/json" },
|
|
397
|
-
validateStatus: function () { return true; },
|
|
398
|
-
})];
|
|
399
|
-
case 1:
|
|
400
|
-
response = _d.sent();
|
|
401
|
-
if (response.status !== 200) {
|
|
402
|
-
throw Error("1inch error: ".concat(response.status, " ").concat(response.statusText));
|
|
403
|
-
}
|
|
404
|
-
pricesFromApi = {};
|
|
405
|
-
_a = response.data;
|
|
406
|
-
_b = [];
|
|
407
|
-
for (_c in _a)
|
|
408
|
-
_b.push(_c);
|
|
409
|
-
_i = 0;
|
|
410
|
-
_d.label = 2;
|
|
411
|
-
case 2:
|
|
412
|
-
if (!(_i < _b.length)) return [3 /*break*/, 5];
|
|
413
|
-
_c = _b[_i];
|
|
414
|
-
if (!(_c in _a)) return [3 /*break*/, 4];
|
|
415
|
-
coin = _c;
|
|
416
|
-
if (response.data[coin] !== "0")
|
|
417
|
-
return [3 /*break*/, 4];
|
|
418
|
-
return [4 /*yield*/, _getUsdPricesFromApi()];
|
|
419
|
-
case 3:
|
|
420
|
-
_pricesFromApi = _d.sent();
|
|
421
|
-
pricesFromApi[coin] = String(_pricesFromApi[coin] || 0);
|
|
422
|
-
_d.label = 4;
|
|
423
|
-
case 4:
|
|
424
|
-
_i++;
|
|
425
|
-
return [3 /*break*/, 2];
|
|
426
|
-
case 5:
|
|
427
|
-
prices = __assign(__assign({}, response.data), pricesFromApi);
|
|
428
|
-
if (prices[fromToken] === '0' || prices[toToken] === '0')
|
|
429
|
-
return [2 /*return*/, undefined];
|
|
430
|
-
return [2 /*return*/, (new BigNumber(prices[toToken])).div(prices[fromToken]).toString()];
|
|
431
|
-
}
|
|
432
|
-
});
|
|
433
|
-
}); }, {
|
|
164
|
+
export const _assembleTxOdos = memoize((pathId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
165
|
+
const url = `https://prices.curve.fi/odos/assemble?user=${ethers.getAddress(llamalend.constants.ALIASES.leverage_zap)}&path_id=${pathId}`;
|
|
166
|
+
const response = yield fetch(url, { headers: { 'Content-Type': 'application/json' } });
|
|
167
|
+
if (response.status !== 200) {
|
|
168
|
+
throw Error(`Odos assemble error - ${response.status} ${response.statusText}`);
|
|
169
|
+
}
|
|
170
|
+
const { transaction } = yield response.json();
|
|
171
|
+
return transaction.data;
|
|
172
|
+
}), {
|
|
434
173
|
promise: true,
|
|
435
174
|
maxAge: 10 * 1000, // 10s
|
|
436
175
|
});
|
package/lib/index.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="memoizee" />
|
|
2
1
|
import { ethers, Networkish } from "ethers";
|
|
3
2
|
import { LendMarketTemplate } from "./lendMarkets/index.js";
|
|
4
3
|
import { MintMarketTemplate } from "./mintMarkets/index.js";
|
|
@@ -35,11 +34,11 @@ declare const llamalend: {
|
|
|
35
34
|
minted: string;
|
|
36
35
|
pegKeepersDebt: string;
|
|
37
36
|
}>;
|
|
38
|
-
getLsdApy: ((name: "
|
|
37
|
+
getLsdApy: ((name: "wstETH" | "sfrxETH") => Promise<{
|
|
39
38
|
apy: number;
|
|
40
39
|
baseApy: number;
|
|
41
40
|
apyMean30d: number;
|
|
42
|
-
}>) & import("memoizee").Memoized<(name: "
|
|
41
|
+
}>) & import("memoizee").Memoized<(name: "wstETH" | "sfrxETH") => Promise<{
|
|
43
42
|
apy: number;
|
|
44
43
|
baseApy: number;
|
|
45
44
|
apyMean30d: number;
|
|
@@ -47,31 +46,33 @@ declare const llamalend: {
|
|
|
47
46
|
setCustomFeeData: typeof setCustomFeeData;
|
|
48
47
|
getBalances: (coins: string[], address?: string) => Promise<string[]>;
|
|
49
48
|
getAllowance: (coins: string[], address: string, spender: string) => Promise<string[]>;
|
|
50
|
-
hasAllowance: (coins: string[], amounts: (
|
|
51
|
-
ensureAllowance: (coins: string[], amounts: (
|
|
49
|
+
hasAllowance: (coins: string[], amounts: (number | string)[], address: string, spender: string) => Promise<boolean>;
|
|
50
|
+
ensureAllowance: (coins: string[], amounts: (number | string)[], spender: string, isMax?: boolean) => Promise<string[]>;
|
|
52
51
|
getUsdRate: (coin: string) => Promise<number>;
|
|
53
52
|
getGasPriceFromL1: () => Promise<number>;
|
|
54
53
|
getGasPriceFromL2: () => Promise<number>;
|
|
55
54
|
getGasInfoForL2: () => Promise<Record<string, number>>;
|
|
56
55
|
fetchStats: (amms: string[], controllers: string[], vaults: string[], borrowed_tokens: string[], collateral_tokens: string[]) => Promise<void>;
|
|
57
|
-
|
|
56
|
+
mintMarkets: {
|
|
57
|
+
getMarketList: () => string[];
|
|
58
|
+
};
|
|
58
59
|
lendMarkets: {
|
|
59
60
|
fetchMarkets: (useAPI?: boolean) => Promise<void>;
|
|
60
61
|
getMarketList: () => string[];
|
|
61
62
|
};
|
|
62
63
|
estimateGas: {
|
|
63
|
-
ensureAllowance: (coins: string[], amounts: (
|
|
64
|
+
ensureAllowance: (coins: string[], amounts: (number | string)[], spender: string, isMax?: boolean) => Promise<import("./interfaces.js").TGas>;
|
|
64
65
|
};
|
|
65
66
|
st_crvUSD: {
|
|
66
67
|
convertToAssets: (shares: import("./interfaces.js").TAmount) => Promise<string>;
|
|
67
68
|
convertToShares: (assets: import("./interfaces.js").TAmount) => Promise<string>;
|
|
68
69
|
userBalances: (address?: string) => Promise<{
|
|
69
|
-
crvUSD: string;
|
|
70
|
-
st_crvUSD: string;
|
|
70
|
+
"crvUSD": string;
|
|
71
|
+
"st_crvUSD": string;
|
|
71
72
|
}>;
|
|
72
73
|
totalSupplyAndCrvUSDLocked: () => Promise<{
|
|
73
|
-
crvUSD: string;
|
|
74
|
-
st_crvUSD: string;
|
|
74
|
+
"crvUSD": string;
|
|
75
|
+
"st_crvUSD": string;
|
|
75
76
|
}>;
|
|
76
77
|
maxDeposit: (address?: string) => Promise<string>;
|
|
77
78
|
previewDeposit: (assets: import("./interfaces.js").TAmount) => Promise<string>;
|