@curvefi/api 1.21.0 → 1.24.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/README.md +68 -2
- package/lib/constants/abis/json/registry_exchange.json +30 -0
- package/lib/curve.js +128 -109
- package/lib/external-api.d.ts +3 -0
- package/lib/external-api.js +67 -0
- package/lib/index.d.ts +11 -0
- package/lib/index.js +8 -0
- package/lib/interfaces.d.ts +23 -1
- package/lib/pools.d.ts +13 -2
- package/lib/pools.js +603 -22
- package/lib/utils.d.ts +2 -0
- package/lib/utils.js +67 -7
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -241,6 +241,9 @@ import curve from "@curvefi/api";
|
|
|
241
241
|
|
|
242
242
|
(async () => {
|
|
243
243
|
await curve.init('JsonRpc', {}, {gasPrice: 0, maxFeePerGas: 0, maxPriorityFeePerGas: 0});
|
|
244
|
+
|
|
245
|
+
console.log(await curve.getTVL());
|
|
246
|
+
// 19281307454.671753
|
|
244
247
|
|
|
245
248
|
const aave = new curve.Pool('aave');
|
|
246
249
|
|
|
@@ -491,7 +494,66 @@ import curve from "@curvefi/api";
|
|
|
491
494
|
})()
|
|
492
495
|
```
|
|
493
496
|
|
|
494
|
-
## Exchange
|
|
497
|
+
## Exchange
|
|
498
|
+
|
|
499
|
+
### Router exchange
|
|
500
|
+
|
|
501
|
+
```ts
|
|
502
|
+
import curve from "@curvefi/api";
|
|
503
|
+
|
|
504
|
+
(async () => {
|
|
505
|
+
await curve.init('JsonRpc', {}, { gasPrice: 0, chainId: 1 });
|
|
506
|
+
|
|
507
|
+
console.log(await curve.getBalances(['DAI', 'CRV']));
|
|
508
|
+
// [ '9900.0', '100049.744832225238317557' ]
|
|
509
|
+
|
|
510
|
+
const { route, output } = await curve.getBestRouteAndOutput('DAI', 'CRV', '1000');
|
|
511
|
+
// OR await curve.getBestPoolAndOutput('0x6B175474E89094C44Da98b954EedeAC495271d0F', '0xD533a949740bb3306d119CC777fa900bA034cd52', '10000');
|
|
512
|
+
const expected = await curve.routerExchangeExpected('DAI', 'CRV', '1000');
|
|
513
|
+
// OR await curve.exchangeExpected('0x6B175474E89094C44Da98b954EedeAC495271d0F', '0xD533a949740bb3306d119CC777fa900bA034cd52', '10000');
|
|
514
|
+
|
|
515
|
+
console.log(route, output, expected);
|
|
516
|
+
// route = [
|
|
517
|
+
// {
|
|
518
|
+
// poolId: '3pool',
|
|
519
|
+
// poolAddress: '0xbEbc44782C7dB0a1A60Cb6fe97d0b483032FF1C7',
|
|
520
|
+
// outputCoinAddress: '0xdac17f958d2ee523a2206206994597c13d831ec7',
|
|
521
|
+
// i: 0,
|
|
522
|
+
// j: 2,
|
|
523
|
+
// swapType: 1,
|
|
524
|
+
// swapAddress: '0x0000000000000000000000000000000000000000'
|
|
525
|
+
// },
|
|
526
|
+
// {
|
|
527
|
+
// poolId: 'tricrypto2',
|
|
528
|
+
// poolAddress: '0xD51a44d3FaE010294C616388b506AcdA1bfAAE46',
|
|
529
|
+
// outputCoinAddress: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
530
|
+
// i: 0,
|
|
531
|
+
// j: 2,
|
|
532
|
+
// swapType: 3,
|
|
533
|
+
// swapAddress: '0x0000000000000000000000000000000000000000'
|
|
534
|
+
// },
|
|
535
|
+
// {
|
|
536
|
+
// poolId: 'crveth',
|
|
537
|
+
// poolAddress: '0x8301AE4fc9c624d1D396cbDAa1ed877821D7C511',
|
|
538
|
+
// outputCoinAddress: '0xd533a949740bb3306d119cc777fa900ba034cd52',
|
|
539
|
+
// i: 0,
|
|
540
|
+
// j: 1,
|
|
541
|
+
// swapType: 3,
|
|
542
|
+
// swapAddress: '0x0000000000000000000000000000000000000000'
|
|
543
|
+
// }
|
|
544
|
+
// ]
|
|
545
|
+
//
|
|
546
|
+
// output = expected = 378.881631202862354937
|
|
547
|
+
|
|
548
|
+
await curve.routerExchange('DAI', 'CRV', '1000')
|
|
549
|
+
// OR await curve.exchange('0x6B175474E89094C44Da98b954EedeAC495271d0F', '0xD533a949740bb3306d119CC777fa900bA034cd52', '10000');
|
|
550
|
+
|
|
551
|
+
console.log(await curve.getBalances(['DAI', 'CRV']));
|
|
552
|
+
// [ '8900.0', '100428.626463428100672494' ]
|
|
553
|
+
})()
|
|
554
|
+
```
|
|
555
|
+
|
|
556
|
+
### Single-pool exchange
|
|
495
557
|
|
|
496
558
|
```ts
|
|
497
559
|
import curve from "@curvefi/api";
|
|
@@ -518,7 +580,7 @@ import curve from "@curvefi/api";
|
|
|
518
580
|
})()
|
|
519
581
|
```
|
|
520
582
|
|
|
521
|
-
|
|
583
|
+
### Cross-Asset Exchange
|
|
522
584
|
|
|
523
585
|
```ts
|
|
524
586
|
import curve from "@curvefi/api";
|
|
@@ -665,6 +727,10 @@ await pool.exchangeWrappedApprove("0x6c3F90f043a72FA612cbac8115EE7e52BDe6E490",
|
|
|
665
727
|
|
|
666
728
|
### Exchange
|
|
667
729
|
```ts
|
|
730
|
+
// Router
|
|
731
|
+
await curve.routerExchangeisApproved("DAI", "0x99d8a9c45b2eca8864373a26d1459e3dff1e17f3", "1000"); // DAI -> MIM
|
|
732
|
+
await curve.routerExchangeApprove("DAI", "0x99d8a9c45b2eca8864373a26d1459e3dff1e17f3", "1000"); // DAI -> MIM
|
|
733
|
+
|
|
668
734
|
// Straight
|
|
669
735
|
await curve.exchangeisApproved("DAI", "0x99d8a9c45b2eca8864373a26d1459e3dff1e17f3", "1000"); // DAI -> MIM
|
|
670
736
|
await curve.exchangeApprove("DAI", "0x99d8a9c45b2eca8864373a26d1459e3dff1e17f3", "1000"); // DAI -> MIM
|
|
@@ -385,6 +385,36 @@
|
|
|
385
385
|
"stateMutability": "view",
|
|
386
386
|
"type": "function"
|
|
387
387
|
},
|
|
388
|
+
{
|
|
389
|
+
"gas": "278915",
|
|
390
|
+
"inputs": [
|
|
391
|
+
{
|
|
392
|
+
"name": "_route",
|
|
393
|
+
"type": "address[9]"
|
|
394
|
+
},
|
|
395
|
+
{
|
|
396
|
+
"name": "_swap_params",
|
|
397
|
+
"type": "uint256[3][4]"
|
|
398
|
+
},
|
|
399
|
+
{
|
|
400
|
+
"name": "_amount",
|
|
401
|
+
"type": "uint256"
|
|
402
|
+
},
|
|
403
|
+
{
|
|
404
|
+
"name": "_pools",
|
|
405
|
+
"type": "address[4]"
|
|
406
|
+
}
|
|
407
|
+
],
|
|
408
|
+
"name": "get_exchange_multiple_amount",
|
|
409
|
+
"outputs": [
|
|
410
|
+
{
|
|
411
|
+
"name": "",
|
|
412
|
+
"type": "uint256"
|
|
413
|
+
}
|
|
414
|
+
],
|
|
415
|
+
"stateMutability": "view",
|
|
416
|
+
"type": "function"
|
|
417
|
+
},
|
|
388
418
|
{
|
|
389
419
|
"gas": "2654",
|
|
390
420
|
"inputs": [
|
package/lib/curve.js
CHANGED
|
@@ -115,9 +115,9 @@ var Curve = /** @class */ (function () {
|
|
|
115
115
|
) {
|
|
116
116
|
if (options === void 0) { options = {}; }
|
|
117
117
|
return __awaiter(this, void 0, void 0, function () {
|
|
118
|
-
var cTokens, yTokens, ycTokens, aTokens, network, _a, customAbiTokens, _b, _i, _c, pool, _d, _e, coinAddr, _f, _g, coinAddr, _h, _j, coinAddr, _k, _l, rewardTokenAddr, addressProviderContract,
|
|
119
|
-
return __generator(this, function (
|
|
120
|
-
switch (
|
|
118
|
+
var cTokens, yTokens, ycTokens, aTokens, network, _a, customAbiTokens, _b, _i, _c, pool, _d, _e, coinAddr, _f, _g, coinAddr, _h, _j, coinAddr, _k, _l, rewardTokenAddr, _m, _o, _p, _q, _r, addressProviderContract, _s;
|
|
119
|
+
return __generator(this, function (_t) {
|
|
120
|
+
switch (_t.label) {
|
|
121
121
|
case 0:
|
|
122
122
|
// JsonRpc provider
|
|
123
123
|
if (providerType.toLowerCase() === 'JsonRpc'.toLowerCase()) {
|
|
@@ -160,8 +160,8 @@ var Curve = /** @class */ (function () {
|
|
|
160
160
|
if (_a) return [3 /*break*/, 2];
|
|
161
161
|
return [4 /*yield*/, this.provider._networkPromise];
|
|
162
162
|
case 1:
|
|
163
|
-
_a = (
|
|
164
|
-
|
|
163
|
+
_a = (_t.sent());
|
|
164
|
+
_t.label = 2;
|
|
165
165
|
case 2:
|
|
166
166
|
network = _a;
|
|
167
167
|
console.log("CURVE-JS IS CONNECTED TO NETWORK:", network);
|
|
@@ -217,75 +217,100 @@ var Curve = /** @class */ (function () {
|
|
|
217
217
|
this.multicallProvider = new ethcall_1.Provider();
|
|
218
218
|
return [4 /*yield*/, this.multicallProvider.init(this.provider)];
|
|
219
219
|
case 3:
|
|
220
|
-
|
|
220
|
+
_t.sent();
|
|
221
221
|
if (!this.signer) return [3 /*break*/, 5];
|
|
222
222
|
_b = this;
|
|
223
223
|
return [4 /*yield*/, this.signer.getAddress()];
|
|
224
224
|
case 4:
|
|
225
|
-
_b.signerAddress =
|
|
225
|
+
_b.signerAddress = _t.sent();
|
|
226
226
|
return [3 /*break*/, 6];
|
|
227
227
|
case 5:
|
|
228
228
|
this.signerAddress = '';
|
|
229
|
-
|
|
229
|
+
_t.label = 6;
|
|
230
230
|
case 6:
|
|
231
231
|
this.feeData = { gasPrice: options.gasPrice, maxFeePerGas: options.maxFeePerGas, maxPriorityFeePerGas: options.maxPriorityFeePerGas };
|
|
232
232
|
return [4 /*yield*/, this.updateFeeData()];
|
|
233
233
|
case 7:
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
234
|
+
_t.sent();
|
|
235
|
+
_i = 0, _c = Object.values(exports.POOLS_DATA);
|
|
236
|
+
_t.label = 8;
|
|
237
|
+
case 8:
|
|
238
|
+
if (!(_i < _c.length)) return [3 /*break*/, 13];
|
|
239
|
+
pool = _c[_i];
|
|
240
|
+
this.contracts[pool.swap_address] = {
|
|
241
|
+
contract: new ethers_1.Contract(pool.swap_address, pool.swap_abi, this.signer || this.provider),
|
|
242
|
+
multicallContract: new ethcall_1.Contract(pool.swap_address, pool.swap_abi),
|
|
243
|
+
};
|
|
244
|
+
this.contracts[pool.swap_address.toLowerCase()] = {
|
|
245
|
+
contract: new ethers_1.Contract(pool.swap_address, pool.swap_abi, this.signer || this.provider),
|
|
246
|
+
multicallContract: new ethcall_1.Contract(pool.swap_address, pool.swap_abi),
|
|
247
|
+
};
|
|
248
|
+
if (pool.token_address !== pool.swap_address) {
|
|
249
|
+
this.contracts[pool.token_address] = {
|
|
250
|
+
contract: new ethers_1.Contract(pool.token_address, ERC20_json_1.default, this.signer || this.provider),
|
|
251
|
+
multicallContract: new ethcall_1.Contract(pool.token_address, ERC20_json_1.default),
|
|
241
252
|
};
|
|
242
|
-
this.contracts[pool.
|
|
243
|
-
contract: new ethers_1.Contract(pool.
|
|
244
|
-
multicallContract: new ethcall_1.Contract(pool.
|
|
253
|
+
this.contracts[pool.token_address.toLowerCase()] = {
|
|
254
|
+
contract: new ethers_1.Contract(pool.token_address, ERC20_json_1.default, this.signer || this.provider),
|
|
255
|
+
multicallContract: new ethcall_1.Contract(pool.token_address, ERC20_json_1.default),
|
|
245
256
|
};
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
this.contracts[pool.
|
|
257
|
-
contract: new ethers_1.Contract(pool.
|
|
258
|
-
multicallContract: new ethcall_1.Contract(pool.
|
|
257
|
+
}
|
|
258
|
+
this.contracts[pool.gauge_address] = {
|
|
259
|
+
contract: new ethers_1.Contract(pool.gauge_address, pool.gauge_abi, this.signer || this.provider),
|
|
260
|
+
multicallContract: new ethcall_1.Contract(pool.gauge_address, pool.gauge_abi),
|
|
261
|
+
};
|
|
262
|
+
this.contracts[pool.gauge_address.toLowerCase()] = {
|
|
263
|
+
contract: new ethers_1.Contract(pool.gauge_address, pool.gauge_abi, this.signer || this.provider),
|
|
264
|
+
multicallContract: new ethcall_1.Contract(pool.gauge_address, pool.gauge_abi),
|
|
265
|
+
};
|
|
266
|
+
if (pool.deposit_address && this.contracts[pool.deposit_address] === undefined) {
|
|
267
|
+
this.contracts[pool.deposit_address] = {
|
|
268
|
+
contract: new ethers_1.Contract(pool.deposit_address, pool.deposit_abi, this.signer || this.provider),
|
|
269
|
+
multicallContract: new ethcall_1.Contract(pool.deposit_address, pool.deposit_abi),
|
|
259
270
|
};
|
|
260
|
-
this.contracts[pool.
|
|
261
|
-
contract: new ethers_1.Contract(pool.
|
|
262
|
-
multicallContract: new ethcall_1.Contract(pool.
|
|
271
|
+
this.contracts[pool.deposit_address.toLowerCase()] = {
|
|
272
|
+
contract: new ethers_1.Contract(pool.deposit_address, pool.deposit_abi, this.signer || this.provider),
|
|
273
|
+
multicallContract: new ethcall_1.Contract(pool.deposit_address, pool.deposit_abi),
|
|
263
274
|
};
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
275
|
+
}
|
|
276
|
+
for (_d = 0, _e = pool.underlying_coin_addresses; _d < _e.length; _d++) {
|
|
277
|
+
coinAddr = _e[_d];
|
|
278
|
+
this.contracts[coinAddr] = {
|
|
279
|
+
contract: new ethers_1.Contract(coinAddr, ERC20_json_1.default, this.signer || this.provider),
|
|
280
|
+
multicallContract: new ethcall_1.Contract(coinAddr, ERC20_json_1.default),
|
|
281
|
+
};
|
|
282
|
+
this.contracts[coinAddr.toLowerCase()] = {
|
|
283
|
+
contract: new ethers_1.Contract(coinAddr, ERC20_json_1.default, this.signer || this.provider),
|
|
284
|
+
multicallContract: new ethcall_1.Contract(coinAddr, ERC20_json_1.default),
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
for (_f = 0, _g = pool.coin_addresses; _f < _g.length; _f++) {
|
|
288
|
+
coinAddr = _g[_f];
|
|
289
|
+
if (customAbiTokens.includes(coinAddr))
|
|
290
|
+
continue;
|
|
291
|
+
this.contracts[coinAddr] = {
|
|
292
|
+
contract: new ethers_1.Contract(coinAddr, ERC20_json_1.default, this.signer || this.provider),
|
|
293
|
+
multicallContract: new ethcall_1.Contract(coinAddr, ERC20_json_1.default),
|
|
294
|
+
};
|
|
295
|
+
this.contracts[coinAddr.toLowerCase()] = {
|
|
296
|
+
contract: new ethers_1.Contract(coinAddr, ERC20_json_1.default, this.signer || this.provider),
|
|
297
|
+
multicallContract: new ethcall_1.Contract(coinAddr, ERC20_json_1.default),
|
|
298
|
+
};
|
|
299
|
+
}
|
|
300
|
+
// TODO add all coins
|
|
301
|
+
for (_h = 0, _j = pool.coin_addresses; _h < _j.length; _h++) {
|
|
302
|
+
coinAddr = _j[_h];
|
|
303
|
+
if (cTokens.includes(coinAddr)) {
|
|
276
304
|
this.contracts[coinAddr] = {
|
|
277
|
-
contract: new ethers_1.Contract(coinAddr,
|
|
278
|
-
multicallContract: new ethcall_1.Contract(coinAddr,
|
|
305
|
+
contract: new ethers_1.Contract(coinAddr, cERC20_json_1.default, this.signer || this.provider),
|
|
306
|
+
multicallContract: new ethcall_1.Contract(coinAddr, cERC20_json_1.default),
|
|
279
307
|
};
|
|
280
308
|
this.contracts[coinAddr.toLowerCase()] = {
|
|
281
|
-
contract: new ethers_1.Contract(coinAddr,
|
|
282
|
-
multicallContract: new ethcall_1.Contract(coinAddr,
|
|
309
|
+
contract: new ethers_1.Contract(coinAddr, cERC20_json_1.default, this.signer || this.provider),
|
|
310
|
+
multicallContract: new ethcall_1.Contract(coinAddr, cERC20_json_1.default),
|
|
283
311
|
};
|
|
284
312
|
}
|
|
285
|
-
|
|
286
|
-
coinAddr = _g[_f];
|
|
287
|
-
if (customAbiTokens.includes(coinAddr))
|
|
288
|
-
continue;
|
|
313
|
+
if (aTokens.includes(coinAddr)) {
|
|
289
314
|
this.contracts[coinAddr] = {
|
|
290
315
|
contract: new ethers_1.Contract(coinAddr, ERC20_json_1.default, this.signer || this.provider),
|
|
291
316
|
multicallContract: new ethcall_1.Contract(coinAddr, ERC20_json_1.default),
|
|
@@ -295,62 +320,56 @@ var Curve = /** @class */ (function () {
|
|
|
295
320
|
multicallContract: new ethcall_1.Contract(coinAddr, ERC20_json_1.default),
|
|
296
321
|
};
|
|
297
322
|
}
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
this.contracts[coinAddr] = {
|
|
303
|
-
contract: new ethers_1.Contract(coinAddr, cERC20_json_1.default, this.signer || this.provider),
|
|
304
|
-
multicallContract: new ethcall_1.Contract(coinAddr, cERC20_json_1.default),
|
|
305
|
-
};
|
|
306
|
-
this.contracts[coinAddr.toLowerCase()] = {
|
|
307
|
-
contract: new ethers_1.Contract(coinAddr, cERC20_json_1.default, this.signer || this.provider),
|
|
308
|
-
multicallContract: new ethcall_1.Contract(coinAddr, cERC20_json_1.default),
|
|
309
|
-
};
|
|
310
|
-
}
|
|
311
|
-
if (aTokens.includes(coinAddr)) {
|
|
312
|
-
this.contracts[coinAddr] = {
|
|
313
|
-
contract: new ethers_1.Contract(coinAddr, ERC20_json_1.default, this.signer || this.provider),
|
|
314
|
-
multicallContract: new ethcall_1.Contract(coinAddr, ERC20_json_1.default),
|
|
315
|
-
};
|
|
316
|
-
this.contracts[coinAddr.toLowerCase()] = {
|
|
317
|
-
contract: new ethers_1.Contract(coinAddr, ERC20_json_1.default, this.signer || this.provider),
|
|
318
|
-
multicallContract: new ethcall_1.Contract(coinAddr, ERC20_json_1.default),
|
|
319
|
-
};
|
|
320
|
-
}
|
|
321
|
-
if (yTokens.includes(coinAddr) || ycTokens.includes(coinAddr)) {
|
|
322
|
-
this.contracts[coinAddr] = {
|
|
323
|
-
contract: new ethers_1.Contract(coinAddr, yERC20_json_1.default, this.signer || this.provider),
|
|
324
|
-
multicallContract: new ethcall_1.Contract(coinAddr, yERC20_json_1.default),
|
|
325
|
-
};
|
|
326
|
-
this.contracts[coinAddr.toLowerCase()] = {
|
|
327
|
-
contract: new ethers_1.Contract(coinAddr, yERC20_json_1.default, this.signer || this.provider),
|
|
328
|
-
multicallContract: new ethcall_1.Contract(coinAddr, yERC20_json_1.default),
|
|
329
|
-
};
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
|
-
if (pool.reward_contract) {
|
|
333
|
-
this.contracts[pool.reward_contract] = {
|
|
334
|
-
contract: new ethers_1.Contract(pool.reward_contract, streamer_json_1.default, this.signer || this.provider),
|
|
335
|
-
multicallContract: new ethcall_1.Contract(pool.reward_contract, streamer_json_1.default),
|
|
336
|
-
};
|
|
337
|
-
this.contracts[pool.reward_contract.toLowerCase()] = {
|
|
338
|
-
contract: new ethers_1.Contract(pool.reward_contract, streamer_json_1.default, this.signer || this.provider),
|
|
339
|
-
multicallContract: new ethcall_1.Contract(pool.reward_contract, streamer_json_1.default),
|
|
340
|
-
};
|
|
341
|
-
}
|
|
342
|
-
for (_k = 0, _l = pool.reward_tokens || []; _k < _l.length; _k++) {
|
|
343
|
-
rewardTokenAddr = _l[_k];
|
|
344
|
-
this.contracts[rewardTokenAddr] = {
|
|
345
|
-
contract: new ethers_1.Contract(rewardTokenAddr, ERC20_json_1.default, this.signer || this.provider),
|
|
346
|
-
multicallContract: new ethcall_1.Contract(rewardTokenAddr, ERC20_json_1.default),
|
|
323
|
+
if (yTokens.includes(coinAddr) || ycTokens.includes(coinAddr)) {
|
|
324
|
+
this.contracts[coinAddr] = {
|
|
325
|
+
contract: new ethers_1.Contract(coinAddr, yERC20_json_1.default, this.signer || this.provider),
|
|
326
|
+
multicallContract: new ethcall_1.Contract(coinAddr, yERC20_json_1.default),
|
|
347
327
|
};
|
|
348
|
-
this.contracts[
|
|
349
|
-
contract: new ethers_1.Contract(
|
|
350
|
-
multicallContract: new ethcall_1.Contract(
|
|
328
|
+
this.contracts[coinAddr.toLowerCase()] = {
|
|
329
|
+
contract: new ethers_1.Contract(coinAddr, yERC20_json_1.default, this.signer || this.provider),
|
|
330
|
+
multicallContract: new ethcall_1.Contract(coinAddr, yERC20_json_1.default),
|
|
351
331
|
};
|
|
352
332
|
}
|
|
353
333
|
}
|
|
334
|
+
if (pool.reward_contract) {
|
|
335
|
+
this.contracts[pool.reward_contract] = {
|
|
336
|
+
contract: new ethers_1.Contract(pool.reward_contract, streamer_json_1.default, this.signer || this.provider),
|
|
337
|
+
multicallContract: new ethcall_1.Contract(pool.reward_contract, streamer_json_1.default),
|
|
338
|
+
};
|
|
339
|
+
this.contracts[pool.reward_contract.toLowerCase()] = {
|
|
340
|
+
contract: new ethers_1.Contract(pool.reward_contract, streamer_json_1.default, this.signer || this.provider),
|
|
341
|
+
multicallContract: new ethcall_1.Contract(pool.reward_contract, streamer_json_1.default),
|
|
342
|
+
};
|
|
343
|
+
}
|
|
344
|
+
_k = 0, _l = pool.reward_tokens || [];
|
|
345
|
+
_t.label = 9;
|
|
346
|
+
case 9:
|
|
347
|
+
if (!(_k < _l.length)) return [3 /*break*/, 12];
|
|
348
|
+
rewardTokenAddr = _l[_k];
|
|
349
|
+
this.contracts[rewardTokenAddr] = {
|
|
350
|
+
contract: new ethers_1.Contract(rewardTokenAddr, ERC20_json_1.default, this.signer || this.provider),
|
|
351
|
+
multicallContract: new ethcall_1.Contract(rewardTokenAddr, ERC20_json_1.default),
|
|
352
|
+
};
|
|
353
|
+
this.contracts[rewardTokenAddr.toLowerCase()] = {
|
|
354
|
+
contract: new ethers_1.Contract(rewardTokenAddr, ERC20_json_1.default, this.signer || this.provider),
|
|
355
|
+
multicallContract: new ethcall_1.Contract(rewardTokenAddr, ERC20_json_1.default),
|
|
356
|
+
};
|
|
357
|
+
_m = exports.DECIMALS_LOWER_CASE;
|
|
358
|
+
_o = rewardTokenAddr.toLowerCase();
|
|
359
|
+
_p = Number;
|
|
360
|
+
_r = (_q = ethers_1.ethers.utils).formatUnits;
|
|
361
|
+
return [4 /*yield*/, this.contracts[rewardTokenAddr].contract.decimals()];
|
|
362
|
+
case 10:
|
|
363
|
+
_m[_o] =
|
|
364
|
+
_p.apply(void 0, [_r.apply(_q, [_t.sent(), 0])]);
|
|
365
|
+
_t.label = 11;
|
|
366
|
+
case 11:
|
|
367
|
+
_k++;
|
|
368
|
+
return [3 /*break*/, 9];
|
|
369
|
+
case 12:
|
|
370
|
+
_i++;
|
|
371
|
+
return [3 /*break*/, 8];
|
|
372
|
+
case 13:
|
|
354
373
|
this.contracts[exports.ALIASES.crv] = {
|
|
355
374
|
contract: new ethers_1.Contract(exports.ALIASES.crv, ERC20_json_1.default, this.signer || this.provider),
|
|
356
375
|
multicallContract: new ethcall_1.Contract(exports.ALIASES.crv, ERC20_json_1.default),
|
|
@@ -384,10 +403,10 @@ var Curve = /** @class */ (function () {
|
|
|
384
403
|
multicallContract: new ethcall_1.Contract(exports.ALIASES.address_provider, address_provider_json_1.default),
|
|
385
404
|
};
|
|
386
405
|
addressProviderContract = this.contracts[exports.ALIASES.address_provider].contract;
|
|
387
|
-
|
|
406
|
+
_s = exports.ALIASES;
|
|
388
407
|
return [4 /*yield*/, addressProviderContract.get_address(2, this.constantOptions)];
|
|
389
|
-
case
|
|
390
|
-
|
|
408
|
+
case 14:
|
|
409
|
+
_s.registry_exchange = _t.sent();
|
|
391
410
|
this.contracts[exports.ALIASES.registry_exchange] = {
|
|
392
411
|
contract: new ethers_1.Contract(exports.ALIASES.registry_exchange, registry_exchange_json_1.default, this.signer || this.provider),
|
|
393
412
|
multicallContract: new ethcall_1.Contract(exports.ALIASES.registry_exchange, registry_exchange_json_1.default),
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { IExtendedPoolDataFromApi } from "./interfaces";
|
|
2
|
+
import memoize from "memoizee";
|
|
3
|
+
export declare const _getPoolsFromApi: ((network: "ethereum" | "polygon", poolType: "main" | "crypto" | "factory" | "factory-crypto") => Promise<IExtendedPoolDataFromApi>) & memoize.Memoized<(network: "ethereum" | "polygon", poolType: "main" | "crypto" | "factory" | "factory-crypto") => Promise<IExtendedPoolDataFromApi>>;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (_) try {
|
|
18
|
+
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;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
|
+
};
|
|
41
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
+
exports._getPoolsFromApi = void 0;
|
|
43
|
+
var axios_1 = __importDefault(require("axios"));
|
|
44
|
+
var memoizee_1 = __importDefault(require("memoizee"));
|
|
45
|
+
exports._getPoolsFromApi = (0, memoizee_1.default)(function (network, poolType) { return __awaiter(void 0, void 0, void 0, function () {
|
|
46
|
+
var url, response, err_1;
|
|
47
|
+
return __generator(this, function (_a) {
|
|
48
|
+
switch (_a.label) {
|
|
49
|
+
case 0:
|
|
50
|
+
url = "https://api.curve.fi/api/getPools/".concat(network, "/").concat(poolType);
|
|
51
|
+
_a.label = 1;
|
|
52
|
+
case 1:
|
|
53
|
+
_a.trys.push([1, 3, , 4]);
|
|
54
|
+
return [4 /*yield*/, axios_1.default.get(url)];
|
|
55
|
+
case 2:
|
|
56
|
+
response = _a.sent();
|
|
57
|
+
return [2 /*return*/, response.data.data];
|
|
58
|
+
case 3:
|
|
59
|
+
err_1 = _a.sent();
|
|
60
|
+
return [2 /*return*/, { poolData: [], tvl: 0, tvlAll: 0 }];
|
|
61
|
+
case 4: return [2 /*return*/];
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
}); }, {
|
|
65
|
+
promise: true,
|
|
66
|
+
maxAge: 5 * 60 * 1000, // 5m
|
|
67
|
+
});
|
package/lib/index.d.ts
CHANGED
|
@@ -30,6 +30,7 @@ declare const curve: {
|
|
|
30
30
|
getFactoryPoolList: () => string[];
|
|
31
31
|
getCryptoFactoryPoolList: () => string[];
|
|
32
32
|
getUsdRate: (coin: string) => Promise<number>;
|
|
33
|
+
getTVL: (chainId?: number) => Promise<number>;
|
|
33
34
|
setCustomFeeData: typeof setCustomFeeData;
|
|
34
35
|
signerAddress: string;
|
|
35
36
|
chainId: number;
|
|
@@ -57,12 +58,22 @@ declare const curve: {
|
|
|
57
58
|
crossAssetExchangeApprove: (inputCoin: string, amount: string) => Promise<string[]>;
|
|
58
59
|
crossAssetExchange: (inputCoin: string, outputCoin: string, amount: string, maxSlippage?: number) => Promise<string>;
|
|
59
60
|
getUserPoolList: (address?: string | undefined) => Promise<string[]>;
|
|
61
|
+
getBestRouteAndOutput: (inputCoin: string, outputCoin: string, amount: string) => Promise<{
|
|
62
|
+
route: import("./interfaces").IRouteStep[];
|
|
63
|
+
output: string;
|
|
64
|
+
}>;
|
|
65
|
+
routerExchangeExpected: (inputCoin: string, outputCoin: string, amount: string) => Promise<string>;
|
|
66
|
+
routerExchangeIsApproved: (inputCoin: string, amount: string) => Promise<boolean>;
|
|
67
|
+
routerExchangeApprove: (inputCoin: string, amount: string) => Promise<string[]>;
|
|
68
|
+
routerExchange: (inputCoin: string, outputCoin: string, amount: string, maxSlippage?: number) => Promise<string>;
|
|
60
69
|
estimateGas: {
|
|
61
70
|
ensureAllowance: (coins: string[], amounts: string[], spender: string) => Promise<number>;
|
|
62
71
|
exchangeApprove: (inputCoin: string, outputCoin: string, amount: string) => Promise<number>;
|
|
63
72
|
exchange: (inputCoin: string, outputCoin: string, amount: string, maxSlippage?: number) => Promise<number>;
|
|
64
73
|
crossAssetExchangeApprove: (inputCoin: string, amount: string) => Promise<number>;
|
|
65
74
|
crossAssetExchange: (inputCoin: string, outputCoin: string, amount: string, maxSlippage?: number) => Promise<number>;
|
|
75
|
+
routerExchangeApprove: (inputCoin: string, amount: string) => Promise<number>;
|
|
76
|
+
routerExchange: (inputCoin: string, outputCoin: string, amount: string) => Promise<number>;
|
|
66
77
|
};
|
|
67
78
|
boosting: {
|
|
68
79
|
getCrv: (...addresses: string[] | string[][]) => Promise<string | import("./interfaces").DictInterface<string>>;
|
package/lib/index.js
CHANGED
|
@@ -94,6 +94,7 @@ var curve = {
|
|
|
94
94
|
getFactoryPoolList: utils_1.getFactoryPoolList,
|
|
95
95
|
getCryptoFactoryPoolList: utils_1.getCryptoFactoryPoolList,
|
|
96
96
|
getUsdRate: utils_1.getUsdRate,
|
|
97
|
+
getTVL: utils_1.getTVL,
|
|
97
98
|
setCustomFeeData: setCustomFeeData,
|
|
98
99
|
signerAddress: '',
|
|
99
100
|
chainId: 0,
|
|
@@ -114,12 +115,19 @@ var curve = {
|
|
|
114
115
|
crossAssetExchangeApprove: pools_1.crossAssetExchangeApprove,
|
|
115
116
|
crossAssetExchange: pools_1.crossAssetExchange,
|
|
116
117
|
getUserPoolList: pools_1.getUserPoolList,
|
|
118
|
+
getBestRouteAndOutput: pools_1.getBestRouteAndOutput,
|
|
119
|
+
routerExchangeExpected: pools_1.routerExchangeExpected,
|
|
120
|
+
routerExchangeIsApproved: pools_1.routerExchangeIsApproved,
|
|
121
|
+
routerExchangeApprove: pools_1.routerExchangeApprove,
|
|
122
|
+
routerExchange: pools_1.routerExchange,
|
|
117
123
|
estimateGas: {
|
|
118
124
|
ensureAllowance: utils_1.ensureAllowanceEstimateGas,
|
|
119
125
|
exchangeApprove: pools_1.exchangeApproveEstimateGas,
|
|
120
126
|
exchange: pools_1.exchangeEstimateGas,
|
|
121
127
|
crossAssetExchangeApprove: pools_1.crossAssetExchangeApproveEstimateGas,
|
|
122
128
|
crossAssetExchange: pools_1.crossAssetExchangeEstimateGas,
|
|
129
|
+
routerExchangeApprove: pools_1.routerExchangeApproveEstimateGas,
|
|
130
|
+
routerExchange: pools_1.routerExchangeEstimateGas,
|
|
123
131
|
},
|
|
124
132
|
boosting: {
|
|
125
133
|
getCrv: boosting_1.getCrv,
|
package/lib/interfaces.d.ts
CHANGED
|
@@ -92,6 +92,7 @@ export interface ICoinFromPoolDataApi {
|
|
|
92
92
|
address: string;
|
|
93
93
|
symbol: string;
|
|
94
94
|
decimals: string;
|
|
95
|
+
usdPrice: number | string;
|
|
95
96
|
}
|
|
96
97
|
export interface IPoolDataFromApi {
|
|
97
98
|
id: string;
|
|
@@ -104,6 +105,12 @@ export interface IPoolDataFromApi {
|
|
|
104
105
|
implementation: string;
|
|
105
106
|
implementationAddress: string;
|
|
106
107
|
coins: ICoinFromPoolDataApi[];
|
|
108
|
+
usdTotal: number;
|
|
109
|
+
}
|
|
110
|
+
export interface IExtendedPoolDataFromApi {
|
|
111
|
+
poolData: IPoolDataFromApi[];
|
|
112
|
+
tvl?: number;
|
|
113
|
+
tvlAll: number;
|
|
107
114
|
}
|
|
108
115
|
export interface RewardsApyInterface {
|
|
109
116
|
token: string;
|
|
@@ -127,9 +134,24 @@ export interface ISinglePoolSwapData {
|
|
|
127
134
|
poolAddress: string;
|
|
128
135
|
i: number;
|
|
129
136
|
j: number;
|
|
130
|
-
swapType: 1 | 2 | 3 | 4;
|
|
137
|
+
swapType: 1 | 2 | 3 | 4 | 5;
|
|
131
138
|
swapAddress: string;
|
|
132
139
|
}
|
|
133
140
|
export interface ISinglePoolSwapDataAndOutput extends ISinglePoolSwapData {
|
|
134
141
|
_output: ethers.BigNumber;
|
|
135
142
|
}
|
|
143
|
+
export interface IRouteStep {
|
|
144
|
+
poolId: string;
|
|
145
|
+
poolAddress: string;
|
|
146
|
+
outputCoinAddress: string;
|
|
147
|
+
i: number;
|
|
148
|
+
j: number;
|
|
149
|
+
swapType: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10;
|
|
150
|
+
swapAddress: string;
|
|
151
|
+
}
|
|
152
|
+
export interface IRoute {
|
|
153
|
+
steps: IRouteStep[];
|
|
154
|
+
_output: ethers.BigNumber;
|
|
155
|
+
outputUsd: number;
|
|
156
|
+
txCostUsd: number;
|
|
157
|
+
}
|