@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/utils.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,110 +7,68 @@ 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
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
49
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
50
|
-
if (ar || !(i in from)) {
|
|
51
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
52
|
-
ar[i] = from[i];
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
56
|
-
};
|
|
57
|
-
import axios from "axios";
|
|
58
10
|
import { ethers } from "ethers";
|
|
59
11
|
import BigNumber from 'bignumber.js';
|
|
60
12
|
import { _getUsdPricesFromApi } from "./external-api.js";
|
|
61
13
|
import { llamalend } from "./llamalend.js";
|
|
62
14
|
import { L2Networks } from "./constants/L2Networks.js";
|
|
63
15
|
import memoize from "memoizee";
|
|
64
|
-
export
|
|
65
|
-
export
|
|
16
|
+
export const MAX_ALLOWANCE = BigInt("115792089237316195423570985008687907853269984665640564039457584007913129639935"); // 2**256 - 1
|
|
17
|
+
export const MAX_ACTIVE_BAND = BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819967"); // 2**255 - 1
|
|
66
18
|
// Common
|
|
67
|
-
export
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
19
|
+
export const createCall = (contract, name, params) => {
|
|
20
|
+
const _abi = contract.abi;
|
|
21
|
+
const _name = name.split('-')[0];
|
|
22
|
+
const func = _abi.find((f) => f.name === _name);
|
|
23
|
+
const inputs = (func === null || func === void 0 ? void 0 : func.inputs) || [];
|
|
24
|
+
const outputs = (func === null || func === void 0 ? void 0 : func.outputs) || [];
|
|
73
25
|
return {
|
|
74
26
|
contract: {
|
|
75
27
|
address: contract.address,
|
|
76
28
|
},
|
|
77
29
|
name: _name,
|
|
78
|
-
inputs
|
|
79
|
-
outputs
|
|
80
|
-
params
|
|
30
|
+
inputs,
|
|
31
|
+
outputs,
|
|
32
|
+
params,
|
|
81
33
|
};
|
|
82
34
|
};
|
|
83
35
|
// Formatting numbers
|
|
84
|
-
export
|
|
36
|
+
export const _cutZeros = (strn) => {
|
|
85
37
|
return strn.replace(/0+$/gi, '').replace(/\.$/gi, '');
|
|
86
38
|
};
|
|
87
|
-
export
|
|
39
|
+
export const checkNumber = (n) => {
|
|
88
40
|
if (Number(n) !== Number(n))
|
|
89
|
-
throw Error(
|
|
41
|
+
throw Error(`${n} is not a number`); // NaN
|
|
90
42
|
return n;
|
|
91
43
|
};
|
|
92
|
-
export
|
|
93
|
-
if (decimals === void 0) { decimals = 18; }
|
|
44
|
+
export const formatNumber = (n, decimals = 18) => {
|
|
94
45
|
n = checkNumber(n);
|
|
95
|
-
|
|
46
|
+
const [integer, fractional] = String(n).split(".");
|
|
96
47
|
return !fractional ? integer : integer + "." + fractional.slice(0, decimals);
|
|
97
48
|
};
|
|
98
|
-
export
|
|
49
|
+
export const formatUnits = (value, unit) => {
|
|
99
50
|
return ethers.formatUnits(value, unit);
|
|
100
51
|
};
|
|
101
|
-
export
|
|
102
|
-
if (decimals === void 0) { decimals = 18; }
|
|
52
|
+
export const parseUnits = (n, decimals = 18) => {
|
|
103
53
|
return ethers.parseUnits(formatNumber(n, decimals), decimals);
|
|
104
54
|
};
|
|
105
55
|
// bignumber.js
|
|
106
|
-
export
|
|
107
|
-
export
|
|
108
|
-
if (decimals === void 0) { decimals = 18; }
|
|
56
|
+
export const BN = (val) => new BigNumber(checkNumber(val));
|
|
57
|
+
export const toBN = (n, decimals = 18) => {
|
|
109
58
|
return BN(formatUnits(n, decimals));
|
|
110
59
|
};
|
|
111
|
-
export
|
|
112
|
-
if (decimals === void 0) { decimals = 18; }
|
|
60
|
+
export const toStringFromBN = (bn, decimals = 18) => {
|
|
113
61
|
return bn.toFixed(decimals);
|
|
114
62
|
};
|
|
115
|
-
export
|
|
116
|
-
if (decimals === void 0) { decimals = 18; }
|
|
63
|
+
export const fromBN = (bn, decimals = 18) => {
|
|
117
64
|
return parseUnits(toStringFromBN(bn, decimals), decimals);
|
|
118
65
|
};
|
|
119
66
|
// -----------------------------------------------------------------------------------------------
|
|
120
|
-
export
|
|
121
|
-
export
|
|
122
|
-
export
|
|
123
|
-
export
|
|
124
|
-
export
|
|
67
|
+
export const ETH_ADDRESS = "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee";
|
|
68
|
+
export const isEth = (address) => address.toLowerCase() === ETH_ADDRESS.toLowerCase();
|
|
69
|
+
export const getEthIndex = (addresses) => addresses.map((address) => address.toLowerCase()).indexOf(ETH_ADDRESS.toLowerCase());
|
|
70
|
+
export const _mulBy1_3 = (n) => n * parseUnits("130", 0) / parseUnits("100", 0);
|
|
71
|
+
export const smartNumber = (abstractNumber) => {
|
|
125
72
|
if (Array.isArray(abstractNumber)) {
|
|
126
73
|
return [Number(abstractNumber[0]), Number(abstractNumber[1])];
|
|
127
74
|
}
|
|
@@ -129,7 +76,7 @@ export var smartNumber = function (abstractNumber) {
|
|
|
129
76
|
return Number(abstractNumber);
|
|
130
77
|
}
|
|
131
78
|
};
|
|
132
|
-
export
|
|
79
|
+
export const DIGas = (gas) => {
|
|
133
80
|
if (Array.isArray(gas)) {
|
|
134
81
|
return gas[0];
|
|
135
82
|
}
|
|
@@ -137,7 +84,7 @@ export var DIGas = function (gas) {
|
|
|
137
84
|
return gas;
|
|
138
85
|
}
|
|
139
86
|
};
|
|
140
|
-
export
|
|
87
|
+
export const getGasFromArray = (gas) => {
|
|
141
88
|
if (gas[1] === 0) {
|
|
142
89
|
return gas[0];
|
|
143
90
|
}
|
|
@@ -145,7 +92,7 @@ export var getGasFromArray = function (gas) {
|
|
|
145
92
|
return gas;
|
|
146
93
|
}
|
|
147
94
|
};
|
|
148
|
-
export
|
|
95
|
+
export const gasSum = (gas, currentGas) => {
|
|
149
96
|
if (Array.isArray(currentGas)) {
|
|
150
97
|
gas[0] = gas[0] + currentGas[0];
|
|
151
98
|
gas[1] = gas[1] + currentGas[1];
|
|
@@ -155,507 +102,330 @@ export var gasSum = function (gas, currentGas) {
|
|
|
155
102
|
}
|
|
156
103
|
return gas;
|
|
157
104
|
};
|
|
158
|
-
export
|
|
105
|
+
export const _getAddress = (address) => {
|
|
159
106
|
address = address || llamalend.signerAddress;
|
|
160
107
|
if (!address)
|
|
161
108
|
throw Error("Need to connect wallet or pass address into args");
|
|
162
109
|
return address;
|
|
163
110
|
};
|
|
164
|
-
export
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
result[callsMap[i]] = response.filter(
|
|
169
|
-
};
|
|
170
|
-
for (var i = 0; i < responseLength; i++) {
|
|
171
|
-
_loop_1(i);
|
|
111
|
+
export const handleMultiCallResponse = (callsMap, response) => {
|
|
112
|
+
const result = {};
|
|
113
|
+
const responseLength = callsMap.length;
|
|
114
|
+
for (let i = 0; i < responseLength; i++) {
|
|
115
|
+
result[callsMap[i]] = response.filter((a, j) => j % responseLength === i);
|
|
172
116
|
}
|
|
173
117
|
return result;
|
|
174
118
|
};
|
|
175
119
|
// coins can be either addresses or symbols
|
|
176
|
-
export
|
|
177
|
-
var coins = [];
|
|
178
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
179
|
-
coins[_i] = arguments[_i];
|
|
180
|
-
}
|
|
120
|
+
export const _getCoinAddressesNoCheck = (...coins) => {
|
|
181
121
|
if (coins.length == 1 && Array.isArray(coins[0]))
|
|
182
122
|
coins = coins[0];
|
|
183
123
|
coins = coins;
|
|
184
|
-
return coins.map(
|
|
124
|
+
return coins.map((c) => c.toLowerCase()).map((c) => llamalend.constants.COINS[c] || c);
|
|
185
125
|
};
|
|
186
|
-
export
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
for (
|
|
190
|
-
var coinAddr = coinAddresses_1[_i];
|
|
126
|
+
export const _getCoinAddresses = (coins) => {
|
|
127
|
+
const coinAddresses = _getCoinAddressesNoCheck(coins);
|
|
128
|
+
const availableAddresses = Object.keys(llamalend.constants.DECIMALS);
|
|
129
|
+
for (const coinAddr of coinAddresses) {
|
|
191
130
|
if (!availableAddresses.includes(coinAddr))
|
|
192
|
-
throw Error(
|
|
131
|
+
throw Error(`Coin with address '${coinAddr}' is not available`);
|
|
193
132
|
}
|
|
194
133
|
return coinAddresses;
|
|
195
134
|
};
|
|
196
|
-
export
|
|
197
|
-
return coinAddresses.map(
|
|
135
|
+
export const _getCoinDecimals = (coinAddresses) => {
|
|
136
|
+
return coinAddresses.map((coinAddr) => { var _a; return (_a = llamalend.constants.DECIMALS[coinAddr.toLowerCase()]) !== null && _a !== void 0 ? _a : 18; });
|
|
198
137
|
};
|
|
199
138
|
// --- BALANCES ---
|
|
200
|
-
export
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
_balances = _a.sent();
|
|
244
|
-
return [2 /*return*/, _balances.map(function (_b, i) { return formatUnits(_b, decimals[i]); })];
|
|
245
|
-
}
|
|
246
|
-
});
|
|
247
|
-
});
|
|
248
|
-
};
|
|
249
|
-
export var _getAllowance = memoize(function (coins, address, spender) { return __awaiter(void 0, void 0, void 0, function () {
|
|
250
|
-
var _coins, ethIndex, allowance, contractCalls;
|
|
251
|
-
return __generator(this, function (_a) {
|
|
252
|
-
switch (_a.label) {
|
|
253
|
-
case 0:
|
|
254
|
-
_coins = __spreadArray([], coins, true);
|
|
255
|
-
ethIndex = getEthIndex(_coins);
|
|
256
|
-
if (ethIndex !== -1) {
|
|
257
|
-
_coins.splice(ethIndex, 1);
|
|
258
|
-
}
|
|
259
|
-
if (!(_coins.length === 1)) return [3 /*break*/, 2];
|
|
260
|
-
return [4 /*yield*/, llamalend.contracts[_coins[0]].contract.allowance(address, spender, llamalend.constantOptions)];
|
|
261
|
-
case 1:
|
|
262
|
-
allowance = [_a.sent()];
|
|
263
|
-
return [3 /*break*/, 4];
|
|
264
|
-
case 2:
|
|
265
|
-
contractCalls = _coins.map(function (coinAddr) { return llamalend.contracts[coinAddr].multicallContract.allowance(address, spender); });
|
|
266
|
-
return [4 /*yield*/, llamalend.multicallProvider.all(contractCalls)];
|
|
267
|
-
case 3:
|
|
268
|
-
allowance = _a.sent();
|
|
269
|
-
_a.label = 4;
|
|
270
|
-
case 4:
|
|
271
|
-
if (ethIndex !== -1) {
|
|
272
|
-
allowance.splice(ethIndex, 0, MAX_ALLOWANCE);
|
|
273
|
-
}
|
|
274
|
-
return [2 /*return*/, allowance];
|
|
275
|
-
}
|
|
276
|
-
});
|
|
277
|
-
}); }, {
|
|
139
|
+
export const _getBalances = (coinAddresses_1, ...args_1) => __awaiter(void 0, [coinAddresses_1, ...args_1], void 0, function* (coinAddresses, address = "") {
|
|
140
|
+
address = _getAddress(address);
|
|
141
|
+
const _coinAddresses = [...coinAddresses];
|
|
142
|
+
const ethIndex = getEthIndex(_coinAddresses);
|
|
143
|
+
if (ethIndex !== -1) {
|
|
144
|
+
_coinAddresses.splice(ethIndex, 1);
|
|
145
|
+
}
|
|
146
|
+
const contractCalls = [];
|
|
147
|
+
for (const coinAddr of _coinAddresses) {
|
|
148
|
+
contractCalls.push(llamalend.contracts[coinAddr].multicallContract.balanceOf(address));
|
|
149
|
+
}
|
|
150
|
+
const _balances = yield llamalend.multicallProvider.all(contractCalls);
|
|
151
|
+
if (ethIndex !== -1) {
|
|
152
|
+
const ethBalance = yield llamalend.provider.getBalance(address);
|
|
153
|
+
_balances.splice(ethIndex, 0, ethBalance);
|
|
154
|
+
}
|
|
155
|
+
return _balances;
|
|
156
|
+
});
|
|
157
|
+
export const getBalances = (coins_1, ...args_1) => __awaiter(void 0, [coins_1, ...args_1], void 0, function* (coins, address = "") {
|
|
158
|
+
const coinAddresses = _getCoinAddresses(coins);
|
|
159
|
+
const decimals = _getCoinDecimals(coinAddresses);
|
|
160
|
+
const _balances = yield _getBalances(coinAddresses, address);
|
|
161
|
+
return _balances.map((_b, i) => formatUnits(_b, decimals[i]));
|
|
162
|
+
});
|
|
163
|
+
export const _getAllowance = memoize((coins, address, spender) => __awaiter(void 0, void 0, void 0, function* () {
|
|
164
|
+
const _coins = [...coins];
|
|
165
|
+
const ethIndex = getEthIndex(_coins);
|
|
166
|
+
if (ethIndex !== -1) {
|
|
167
|
+
_coins.splice(ethIndex, 1);
|
|
168
|
+
}
|
|
169
|
+
let allowance;
|
|
170
|
+
if (_coins.length === 1) {
|
|
171
|
+
allowance = [yield llamalend.contracts[_coins[0]].contract.allowance(address, spender, llamalend.constantOptions)];
|
|
172
|
+
}
|
|
173
|
+
else {
|
|
174
|
+
const contractCalls = _coins.map((coinAddr) => llamalend.contracts[coinAddr].multicallContract.allowance(address, spender));
|
|
175
|
+
allowance = yield llamalend.multicallProvider.all(contractCalls);
|
|
176
|
+
}
|
|
177
|
+
if (ethIndex !== -1) {
|
|
178
|
+
allowance.splice(ethIndex, 0, MAX_ALLOWANCE);
|
|
179
|
+
}
|
|
180
|
+
return allowance;
|
|
181
|
+
}), {
|
|
278
182
|
promise: true,
|
|
279
|
-
maxAge: 5 * 1000,
|
|
183
|
+
maxAge: 5 * 1000, // 5s
|
|
280
184
|
primitive: true,
|
|
281
185
|
length: 3,
|
|
282
186
|
});
|
|
283
187
|
// coins can be either addresses or symbols
|
|
284
|
-
export
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
decimals = _getCoinDecimals(coinAddresses);
|
|
291
|
-
return [4 /*yield*/, _getAllowance(coinAddresses, address, spender)];
|
|
292
|
-
case 1:
|
|
293
|
-
_allowance = _a.sent();
|
|
294
|
-
return [2 /*return*/, _allowance.map(function (a, i) { return llamalend.formatUnits(a, decimals[i]); })];
|
|
295
|
-
}
|
|
296
|
-
});
|
|
297
|
-
}); };
|
|
188
|
+
export const getAllowance = (coins, address, spender) => __awaiter(void 0, void 0, void 0, function* () {
|
|
189
|
+
const coinAddresses = _getCoinAddresses(coins);
|
|
190
|
+
const decimals = _getCoinDecimals(coinAddresses);
|
|
191
|
+
const _allowance = yield _getAllowance(coinAddresses, address, spender);
|
|
192
|
+
return _allowance.map((a, i) => llamalend.formatUnits(a, decimals[i]));
|
|
193
|
+
});
|
|
298
194
|
// coins can be either addresses or symbols
|
|
299
|
-
export
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
195
|
+
export const hasAllowance = (coins, amounts, address, spender) => __awaiter(void 0, void 0, void 0, function* () {
|
|
196
|
+
const coinAddresses = _getCoinAddresses(coins);
|
|
197
|
+
const decimals = _getCoinDecimals(coinAddresses);
|
|
198
|
+
const _allowance = yield _getAllowance(coinAddresses, address, spender);
|
|
199
|
+
const _amounts = amounts.map((a, i) => parseUnits(a, decimals[i]));
|
|
200
|
+
return _allowance.map((a, i) => a >= _amounts[i]).reduce((a, b) => a && b);
|
|
201
|
+
});
|
|
202
|
+
export const _ensureAllowance = (coins_1, _amounts_1, spender_1, ...args_1) => __awaiter(void 0, [coins_1, _amounts_1, spender_1, ...args_1], void 0, function* (coins, _amounts, spender, isMax = true) {
|
|
203
|
+
const address = llamalend.signerAddress;
|
|
204
|
+
const _allowance = yield _getAllowance(coins, address, spender);
|
|
205
|
+
const txHashes = [];
|
|
206
|
+
for (let i = 0; i < _allowance.length; i++) {
|
|
207
|
+
if (_allowance[i] < _amounts[i]) {
|
|
208
|
+
const contract = llamalend.contracts[coins[i]].contract;
|
|
209
|
+
const _approveAmount = isMax ? MAX_ALLOWANCE : _amounts[i];
|
|
210
|
+
yield llamalend.updateFeeData();
|
|
211
|
+
const gasLimit = _mulBy1_3(DIGas(yield contract.approve.estimateGas(spender, _approveAmount, llamalend.constantOptions)));
|
|
212
|
+
txHashes.push((yield contract.approve(spender, _approveAmount, Object.assign(Object.assign({}, llamalend.options), { gasLimit }))).hash);
|
|
311
213
|
}
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
if (isMax === void 0) { isMax = true; }
|
|
316
|
-
return __awaiter(void 0, void 0, void 0, function () {
|
|
317
|
-
var address, _allowance, txHashes, i, contract, _approveAmount, gasLimit, _a, _c, _d, _e;
|
|
318
|
-
return __generator(this, function (_f) {
|
|
319
|
-
switch (_f.label) {
|
|
320
|
-
case 0:
|
|
321
|
-
address = llamalend.signerAddress;
|
|
322
|
-
return [4 /*yield*/, _getAllowance(coins, address, spender)];
|
|
323
|
-
case 1:
|
|
324
|
-
_allowance = _f.sent();
|
|
325
|
-
txHashes = [];
|
|
326
|
-
i = 0;
|
|
327
|
-
_f.label = 2;
|
|
328
|
-
case 2:
|
|
329
|
-
if (!(i < _allowance.length)) return [3 /*break*/, 7];
|
|
330
|
-
if (!(_allowance[i] < _amounts[i])) return [3 /*break*/, 6];
|
|
331
|
-
contract = llamalend.contracts[coins[i]].contract;
|
|
332
|
-
_approveAmount = isMax ? MAX_ALLOWANCE : _amounts[i];
|
|
333
|
-
return [4 /*yield*/, llamalend.updateFeeData()];
|
|
334
|
-
case 3:
|
|
335
|
-
_f.sent();
|
|
336
|
-
_a = _mulBy1_3;
|
|
337
|
-
_c = DIGas;
|
|
338
|
-
return [4 /*yield*/, contract.approve.estimateGas(spender, _approveAmount, llamalend.constantOptions)];
|
|
339
|
-
case 4:
|
|
340
|
-
gasLimit = _a.apply(void 0, [_c.apply(void 0, [_f.sent()])]);
|
|
341
|
-
_e = (_d = txHashes).push;
|
|
342
|
-
return [4 /*yield*/, contract.approve(spender, _approveAmount, __assign(__assign({}, llamalend.options), { gasLimit: gasLimit }))];
|
|
343
|
-
case 5:
|
|
344
|
-
_e.apply(_d, [(_f.sent()).hash]);
|
|
345
|
-
_f.label = 6;
|
|
346
|
-
case 6:
|
|
347
|
-
i++;
|
|
348
|
-
return [3 /*break*/, 2];
|
|
349
|
-
case 7: return [2 /*return*/, txHashes];
|
|
350
|
-
}
|
|
351
|
-
});
|
|
352
|
-
});
|
|
353
|
-
};
|
|
214
|
+
}
|
|
215
|
+
return txHashes;
|
|
216
|
+
});
|
|
354
217
|
// coins can be either addresses or symbols
|
|
355
|
-
export
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
case 2:
|
|
372
|
-
if (!(i < _allowance.length)) return [3 /*break*/, 5];
|
|
373
|
-
if (!(_allowance[i] < _amounts[i])) return [3 /*break*/, 4];
|
|
374
|
-
contract = llamalend.contracts[coinAddresses[i]].contract;
|
|
375
|
-
_approveAmount = isMax ? MAX_ALLOWANCE : _amounts[i];
|
|
376
|
-
_a = smartNumber;
|
|
377
|
-
return [4 /*yield*/, contract.approve.estimateGas(spender, _approveAmount, llamalend.constantOptions)];
|
|
378
|
-
case 3:
|
|
379
|
-
currentGas = _a.apply(void 0, [_c.sent()]);
|
|
380
|
-
gas = gasSum(gas, currentGas);
|
|
381
|
-
_c.label = 4;
|
|
382
|
-
case 4:
|
|
383
|
-
i++;
|
|
384
|
-
return [3 /*break*/, 2];
|
|
385
|
-
case 5: return [2 /*return*/, getGasFromArray(gas)];
|
|
386
|
-
}
|
|
387
|
-
});
|
|
388
|
-
});
|
|
389
|
-
};
|
|
218
|
+
export const ensureAllowanceEstimateGas = (coins_1, amounts_1, spender_1, ...args_1) => __awaiter(void 0, [coins_1, amounts_1, spender_1, ...args_1], void 0, function* (coins, amounts, spender, isMax = true) {
|
|
219
|
+
const coinAddresses = _getCoinAddresses(coins);
|
|
220
|
+
const decimals = _getCoinDecimals(coinAddresses);
|
|
221
|
+
const _amounts = amounts.map((a, i) => parseUnits(a, decimals[i]));
|
|
222
|
+
const _allowance = yield _getAllowance(coinAddresses, llamalend.signerAddress, spender);
|
|
223
|
+
let gas = [0, 0];
|
|
224
|
+
for (let i = 0; i < _allowance.length; i++) {
|
|
225
|
+
if (_allowance[i] < _amounts[i]) {
|
|
226
|
+
const contract = llamalend.contracts[coinAddresses[i]].contract;
|
|
227
|
+
const _approveAmount = isMax ? MAX_ALLOWANCE : _amounts[i];
|
|
228
|
+
const currentGas = smartNumber(yield contract.approve.estimateGas(spender, _approveAmount, llamalend.constantOptions));
|
|
229
|
+
gas = gasSum(gas, currentGas);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
return getGasFromArray(gas);
|
|
233
|
+
});
|
|
390
234
|
// coins can be either addresses or symbols
|
|
391
|
-
export
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
decimals = _getCoinDecimals(coinAddresses);
|
|
400
|
-
_amounts = amounts.map(function (a, i) { return parseUnits(a, decimals[i]); });
|
|
401
|
-
return [4 /*yield*/, _ensureAllowance(coinAddresses, _amounts, spender, isMax)];
|
|
402
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
403
|
-
}
|
|
404
|
-
});
|
|
405
|
-
});
|
|
406
|
-
};
|
|
407
|
-
var _usdRatesCache = {};
|
|
408
|
-
export var _getUsdRate = function (assetId) { return __awaiter(void 0, void 0, void 0, function () {
|
|
409
|
-
var pricesFromApi, chainName, nativeTokenName, url, response;
|
|
235
|
+
export const ensureAllowance = (coins_1, amounts_1, spender_1, ...args_1) => __awaiter(void 0, [coins_1, amounts_1, spender_1, ...args_1], void 0, function* (coins, amounts, spender, isMax = true) {
|
|
236
|
+
const coinAddresses = _getCoinAddresses(coins);
|
|
237
|
+
const decimals = _getCoinDecimals(coinAddresses);
|
|
238
|
+
const _amounts = amounts.map((a, i) => parseUnits(a, decimals[i]));
|
|
239
|
+
return yield _ensureAllowance(coinAddresses, _amounts, spender, isMax);
|
|
240
|
+
});
|
|
241
|
+
const _usdRatesCache = {};
|
|
242
|
+
export const _getUsdRate = (assetId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
410
243
|
var _a, _c;
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
"https://api.coingecko.com/api/v3/simple/token_price/".concat(chainName, "?contract_addresses=").concat(assetId, "&vs_currencies=usd");
|
|
487
|
-
return [4 /*yield*/, axios.get(url)];
|
|
488
|
-
case 2:
|
|
489
|
-
response = _d.sent();
|
|
490
|
-
try {
|
|
491
|
-
_usdRatesCache[assetId] = { 'rate': (_c = response.data[assetId]['usd']) !== null && _c !== void 0 ? _c : 0, 'time': Date.now() };
|
|
492
|
-
}
|
|
493
|
-
catch (err) { // TODO pay attention!
|
|
494
|
-
_usdRatesCache[assetId] = { 'rate': 0, 'time': Date.now() };
|
|
495
|
-
}
|
|
496
|
-
_d.label = 3;
|
|
497
|
-
case 3: return [2 /*return*/, _usdRatesCache[assetId]['rate']];
|
|
498
|
-
}
|
|
499
|
-
});
|
|
500
|
-
}); };
|
|
501
|
-
export var getUsdRate = function (coin) { return __awaiter(void 0, void 0, void 0, function () {
|
|
502
|
-
var coinAddress;
|
|
503
|
-
return __generator(this, function (_a) {
|
|
504
|
-
switch (_a.label) {
|
|
505
|
-
case 0:
|
|
506
|
-
coinAddress = _getCoinAddressesNoCheck(coin)[0];
|
|
507
|
-
return [4 /*yield*/, _getUsdRate(coinAddress)];
|
|
508
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
509
|
-
}
|
|
510
|
-
});
|
|
511
|
-
}); };
|
|
512
|
-
export var getBaseFeeByLastBlock = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
513
|
-
var provider, block, error_1;
|
|
514
|
-
return __generator(this, function (_a) {
|
|
515
|
-
switch (_a.label) {
|
|
516
|
-
case 0:
|
|
517
|
-
provider = llamalend.provider;
|
|
518
|
-
_a.label = 1;
|
|
519
|
-
case 1:
|
|
520
|
-
_a.trys.push([1, 3, , 4]);
|
|
521
|
-
return [4 /*yield*/, provider.getBlock('latest')];
|
|
522
|
-
case 2:
|
|
523
|
-
block = _a.sent();
|
|
524
|
-
if (!block) {
|
|
525
|
-
return [2 /*return*/, 0.01];
|
|
526
|
-
}
|
|
527
|
-
return [2 /*return*/, Number(block.baseFeePerGas) / (Math.pow(10, 9))];
|
|
528
|
-
case 3:
|
|
529
|
-
error_1 = _a.sent();
|
|
530
|
-
throw new Error(error_1);
|
|
531
|
-
case 4: return [2 /*return*/];
|
|
244
|
+
if (llamalend.chainId === 1 && assetId.toLowerCase() === '0x8762db106b2c2a0bccb3a80d1ed41273552616e8')
|
|
245
|
+
return 0; // RSR
|
|
246
|
+
const pricesFromApi = yield _getUsdPricesFromApi();
|
|
247
|
+
if (assetId.toLowerCase() in pricesFromApi)
|
|
248
|
+
return pricesFromApi[assetId.toLowerCase()];
|
|
249
|
+
if (assetId === 'USD' || (llamalend.chainId === 137 && (assetId.toLowerCase() === llamalend.constants.COINS.am3crv.toLowerCase())))
|
|
250
|
+
return 1;
|
|
251
|
+
let chainName = {
|
|
252
|
+
1: 'ethereum',
|
|
253
|
+
10: 'optimistic-ethereum',
|
|
254
|
+
56: "binance-smart-chain",
|
|
255
|
+
100: 'xdai',
|
|
256
|
+
137: 'polygon-pos',
|
|
257
|
+
146: 'sonic',
|
|
258
|
+
196: 'x-layer',
|
|
259
|
+
250: 'fantom',
|
|
260
|
+
252: 'fraxtal',
|
|
261
|
+
324: 'zksync',
|
|
262
|
+
1284: 'moonbeam',
|
|
263
|
+
2222: 'kava',
|
|
264
|
+
5000: 'mantle',
|
|
265
|
+
8453: 'base',
|
|
266
|
+
42220: 'celo',
|
|
267
|
+
43114: 'avalanche',
|
|
268
|
+
42161: 'arbitrum-one',
|
|
269
|
+
1313161554: 'aurora',
|
|
270
|
+
}[llamalend.chainId];
|
|
271
|
+
const nativeTokenName = {
|
|
272
|
+
1: 'ethereum',
|
|
273
|
+
10: 'ethereum',
|
|
274
|
+
56: 'binancecoin',
|
|
275
|
+
100: 'xdai',
|
|
276
|
+
137: 'matic-network',
|
|
277
|
+
146: 'sonic-3',
|
|
278
|
+
196: 'okb',
|
|
279
|
+
250: 'fantom',
|
|
280
|
+
252: 'frax-ether',
|
|
281
|
+
324: 'ethereum',
|
|
282
|
+
1284: 'moonbeam',
|
|
283
|
+
2222: 'kava',
|
|
284
|
+
5000: 'mantle',
|
|
285
|
+
8453: 'ethereum',
|
|
286
|
+
42220: 'celo',
|
|
287
|
+
43114: 'avalanche-2',
|
|
288
|
+
42161: 'ethereum',
|
|
289
|
+
1313161554: 'ethereum',
|
|
290
|
+
}[llamalend.chainId];
|
|
291
|
+
if (chainName === undefined) {
|
|
292
|
+
throw Error('curve object is not initialized');
|
|
293
|
+
}
|
|
294
|
+
assetId = {
|
|
295
|
+
'CRV': 'curve-dao-token',
|
|
296
|
+
'EUR': 'stasis-eurs',
|
|
297
|
+
'BTC': 'bitcoin',
|
|
298
|
+
'ETH': 'ethereum',
|
|
299
|
+
'LINK': 'link',
|
|
300
|
+
}[assetId.toUpperCase()] || assetId;
|
|
301
|
+
assetId = isEth(assetId) ? nativeTokenName : assetId.toLowerCase();
|
|
302
|
+
// No EURT on Coingecko Polygon
|
|
303
|
+
if (llamalend.chainId === 137 && assetId.toLowerCase() === llamalend.constants.COINS.eurt) {
|
|
304
|
+
chainName = 'ethereum';
|
|
305
|
+
assetId = '0xC581b735A1688071A1746c968e0798D642EDE491'.toLowerCase(); // EURT Ethereum
|
|
306
|
+
}
|
|
307
|
+
// CRV
|
|
308
|
+
if (assetId.toLowerCase() === llamalend.constants.ALIASES.crv) {
|
|
309
|
+
assetId = 'curve-dao-token';
|
|
310
|
+
}
|
|
311
|
+
if ((((_a = _usdRatesCache[assetId]) === null || _a === void 0 ? void 0 : _a.time) || 0) + 600000 < Date.now()) {
|
|
312
|
+
const url = [nativeTokenName, 'ethereum', 'bitcoin', 'link', 'curve-dao-token', 'stasis-eurs'].includes(assetId.toLowerCase()) ?
|
|
313
|
+
`https://api.coingecko.com/api/v3/simple/price?ids=${assetId}&vs_currencies=usd` :
|
|
314
|
+
`https://api.coingecko.com/api/v3/simple/token_price/${chainName}?contract_addresses=${assetId}&vs_currencies=usd`;
|
|
315
|
+
const response = yield fetch(url);
|
|
316
|
+
const data = yield response.json();
|
|
317
|
+
try {
|
|
318
|
+
_usdRatesCache[assetId] = { 'rate': (_c = data[assetId]['usd']) !== null && _c !== void 0 ? _c : 0, 'time': Date.now() };
|
|
532
319
|
}
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
return __generator(this, function (_a) {
|
|
537
|
-
if (L2Networks.includes(llamalend.chainId) && llamalend.L1WeightedGasPrice) {
|
|
538
|
-
return [2 /*return*/, llamalend.L1WeightedGasPrice + 1e9]; // + 1 gwei
|
|
320
|
+
catch ( // TODO pay attention!
|
|
321
|
+
_d) { // TODO pay attention!
|
|
322
|
+
_usdRatesCache[assetId] = { 'rate': 0, 'time': Date.now() };
|
|
539
323
|
}
|
|
540
|
-
|
|
541
|
-
|
|
324
|
+
}
|
|
325
|
+
return _usdRatesCache[assetId]['rate'];
|
|
326
|
+
});
|
|
327
|
+
export const getUsdRate = (coin) => __awaiter(void 0, void 0, void 0, function* () {
|
|
328
|
+
const [coinAddress] = _getCoinAddressesNoCheck(coin);
|
|
329
|
+
return yield _getUsdRate(coinAddress);
|
|
330
|
+
});
|
|
331
|
+
export const getBaseFeeByLastBlock = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
332
|
+
const provider = llamalend.provider;
|
|
333
|
+
try {
|
|
334
|
+
const block = yield provider.getBlock('latest');
|
|
335
|
+
if (!block) {
|
|
336
|
+
return 0.01;
|
|
542
337
|
}
|
|
543
|
-
return
|
|
544
|
-
}
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
case 5: throw Error("This method exists only for ARBITRUM network");
|
|
562
|
-
case 6: return [2 /*return*/];
|
|
338
|
+
return Number(block.baseFeePerGas) / (Math.pow(10, 9));
|
|
339
|
+
}
|
|
340
|
+
catch (error) {
|
|
341
|
+
throw new Error(error);
|
|
342
|
+
}
|
|
343
|
+
});
|
|
344
|
+
export const getGasPriceFromL1 = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
345
|
+
if (L2Networks.includes(llamalend.chainId) && llamalend.L1WeightedGasPrice) {
|
|
346
|
+
return llamalend.L1WeightedGasPrice + 1e9; // + 1 gwei
|
|
347
|
+
}
|
|
348
|
+
else {
|
|
349
|
+
throw Error("This method exists only for L2 networks");
|
|
350
|
+
}
|
|
351
|
+
});
|
|
352
|
+
export const getGasPriceFromL2 = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
353
|
+
if (llamalend.chainId === 42161) {
|
|
354
|
+
try {
|
|
355
|
+
return yield getBaseFeeByLastBlock();
|
|
563
356
|
}
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
export var getGasInfoForL2 = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
567
|
-
var baseFee, e_2;
|
|
568
|
-
return __generator(this, function (_a) {
|
|
569
|
-
switch (_a.label) {
|
|
570
|
-
case 0:
|
|
571
|
-
if (!(llamalend.chainId === 42161)) return [3 /*break*/, 5];
|
|
572
|
-
_a.label = 1;
|
|
573
|
-
case 1:
|
|
574
|
-
_a.trys.push([1, 3, , 4]);
|
|
575
|
-
return [4 /*yield*/, getBaseFeeByLastBlock()];
|
|
576
|
-
case 2:
|
|
577
|
-
baseFee = _a.sent();
|
|
578
|
-
return [2 /*return*/, {
|
|
579
|
-
maxFeePerGas: Number(((baseFee * 1.1) + 0.01).toFixed(2)),
|
|
580
|
-
maxPriorityFeePerGas: 0.01,
|
|
581
|
-
}];
|
|
582
|
-
case 3:
|
|
583
|
-
e_2 = _a.sent();
|
|
584
|
-
throw Error(e_2);
|
|
585
|
-
case 4: return [3 /*break*/, 6];
|
|
586
|
-
case 5: throw Error("This method exists only for ARBITRUM network");
|
|
587
|
-
case 6: return [2 /*return*/];
|
|
357
|
+
catch (e) {
|
|
358
|
+
throw Error(e);
|
|
588
359
|
}
|
|
589
|
-
}
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
}
|
|
603
|
-
for (_c = 0, _d = llamalend.constants.PEG_KEEPERS; _c < _d.length; _c++) {
|
|
604
|
-
pegKeeper = _d[_c];
|
|
605
|
-
calls.push(llamalend.contracts[pegKeeper].multicallContract.debt());
|
|
606
|
-
}
|
|
607
|
-
return [4 /*yield*/, llamalend.multicallProvider.all(calls)];
|
|
608
|
-
case 1:
|
|
609
|
-
res = _g.sent();
|
|
610
|
-
mintedBN = BN(0);
|
|
611
|
-
for (i = 0; i < llamalend.getMintMarketList().length; i++) {
|
|
612
|
-
_e = res.splice(0, 2), _minted = _e[0], _redeemed = _e[1];
|
|
613
|
-
mintedBN = toBN(_minted).minus(toBN(_redeemed)).plus(mintedBN);
|
|
614
|
-
}
|
|
615
|
-
pegKeepersBN = BN(0);
|
|
616
|
-
for (_f = 0, res_1 = res; _f < res_1.length; _f++) {
|
|
617
|
-
_pegKeeperDebt = res_1[_f];
|
|
618
|
-
pegKeepersBN = pegKeepersBN.plus(toBN(_pegKeeperDebt));
|
|
619
|
-
}
|
|
620
|
-
return [2 /*return*/, { total: mintedBN.plus(pegKeepersBN).toString(), minted: mintedBN.toString(), pegKeepersDebt: pegKeepersBN.toString() }];
|
|
360
|
+
}
|
|
361
|
+
else {
|
|
362
|
+
throw Error("This method exists only for ARBITRUM network");
|
|
363
|
+
}
|
|
364
|
+
});
|
|
365
|
+
export const getGasInfoForL2 = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
366
|
+
if (llamalend.chainId === 42161) {
|
|
367
|
+
try {
|
|
368
|
+
const baseFee = yield getBaseFeeByLastBlock();
|
|
369
|
+
return {
|
|
370
|
+
maxFeePerGas: Number(((baseFee * 1.1) + 0.01).toFixed(2)),
|
|
371
|
+
maxPriorityFeePerGas: 0.01,
|
|
372
|
+
};
|
|
621
373
|
}
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
export var getLsdApy = memoize(function (name) { return __awaiter(void 0, void 0, void 0, function () {
|
|
625
|
-
var response, data, params, result;
|
|
626
|
-
return __generator(this, function (_a) {
|
|
627
|
-
switch (_a.label) {
|
|
628
|
-
case 0: return [4 /*yield*/, axios.get('https://yields.llama.fi/pools')];
|
|
629
|
-
case 1:
|
|
630
|
-
response = _a.sent();
|
|
631
|
-
data = response.data;
|
|
632
|
-
params = {
|
|
633
|
-
'wstETH': {
|
|
634
|
-
project: 'lido',
|
|
635
|
-
symbol: 'STETH',
|
|
636
|
-
},
|
|
637
|
-
'sfrxETH': {
|
|
638
|
-
project: 'frax-ether',
|
|
639
|
-
symbol: 'SFRXETH',
|
|
640
|
-
},
|
|
641
|
-
};
|
|
642
|
-
result = data.find(function (_a) {
|
|
643
|
-
var chain = _a.chain, project = _a.project, symbol = _a.symbol;
|
|
644
|
-
return (chain === 'Ethereum' &&
|
|
645
|
-
project === params[name].project &&
|
|
646
|
-
symbol === params[name].symbol);
|
|
647
|
-
});
|
|
648
|
-
if (result) {
|
|
649
|
-
return [2 /*return*/, {
|
|
650
|
-
apy: result.apy,
|
|
651
|
-
baseApy: result.apyBase,
|
|
652
|
-
apyMean30d: result.apyMean30d,
|
|
653
|
-
}];
|
|
654
|
-
}
|
|
655
|
-
throw new Error('Pool not found');
|
|
374
|
+
catch (e) {
|
|
375
|
+
throw Error(e);
|
|
656
376
|
}
|
|
657
|
-
}
|
|
658
|
-
|
|
377
|
+
}
|
|
378
|
+
else {
|
|
379
|
+
throw Error("This method exists only for ARBITRUM network");
|
|
380
|
+
}
|
|
381
|
+
});
|
|
382
|
+
export const totalSupply = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
383
|
+
const calls = [];
|
|
384
|
+
for (const llammaId of llamalend.getMintMarketList()) {
|
|
385
|
+
const controllerAddress = llamalend.constants.LLAMMAS[llammaId].controller_address;
|
|
386
|
+
const controllerContract = llamalend.contracts[controllerAddress].multicallContract;
|
|
387
|
+
calls.push(controllerContract.minted(), controllerContract.redeemed());
|
|
388
|
+
}
|
|
389
|
+
for (const pegKeeper of llamalend.constants.PEG_KEEPERS) {
|
|
390
|
+
calls.push(llamalend.contracts[pegKeeper].multicallContract.debt());
|
|
391
|
+
}
|
|
392
|
+
const res = yield llamalend.multicallProvider.all(calls);
|
|
393
|
+
let mintedBN = BN(0);
|
|
394
|
+
for (let i = 0; i < llamalend.getMintMarketList().length; i++) {
|
|
395
|
+
const [_minted, _redeemed] = res.splice(0, 2);
|
|
396
|
+
mintedBN = toBN(_minted).minus(toBN(_redeemed)).plus(mintedBN);
|
|
397
|
+
}
|
|
398
|
+
let pegKeepersBN = BN(0);
|
|
399
|
+
for (const _pegKeeperDebt of res) {
|
|
400
|
+
pegKeepersBN = pegKeepersBN.plus(toBN(_pegKeeperDebt));
|
|
401
|
+
}
|
|
402
|
+
return { total: mintedBN.plus(pegKeepersBN).toString(), minted: mintedBN.toString(), pegKeepersDebt: pegKeepersBN.toString() };
|
|
403
|
+
});
|
|
404
|
+
export const getLsdApy = memoize((name) => __awaiter(void 0, void 0, void 0, function* () {
|
|
405
|
+
const response = yield fetch('https://yields.llama.fi/pools');
|
|
406
|
+
const { data } = yield response.json();
|
|
407
|
+
const params = {
|
|
408
|
+
'wstETH': {
|
|
409
|
+
project: 'lido',
|
|
410
|
+
symbol: 'STETH',
|
|
411
|
+
},
|
|
412
|
+
'sfrxETH': {
|
|
413
|
+
project: 'frax-ether',
|
|
414
|
+
symbol: 'SFRXETH',
|
|
415
|
+
},
|
|
416
|
+
};
|
|
417
|
+
const result = data.find(({ chain, project, symbol, }) => (chain === 'Ethereum' &&
|
|
418
|
+
project === params[name].project &&
|
|
419
|
+
symbol === params[name].symbol));
|
|
420
|
+
if (result) {
|
|
421
|
+
return {
|
|
422
|
+
apy: result.apy,
|
|
423
|
+
baseApy: result.apyBase,
|
|
424
|
+
apyMean30d: result.apyMean30d,
|
|
425
|
+
};
|
|
426
|
+
}
|
|
427
|
+
throw new Error('Pool not found');
|
|
428
|
+
}), {
|
|
659
429
|
promise: true,
|
|
660
430
|
maxAge: 60 * 1000, // 1m
|
|
661
431
|
});
|