@curvefi/api 2.37.0 → 2.39.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 +46 -0
- package/lib/boosting.d.ts +10 -1
- package/lib/boosting.js +189 -0
- package/lib/constants/abis/anycall.json +552 -0
- package/lib/constants/abis/factory-tricrypto/factory-tricrypto-pool.json +1502 -0
- package/lib/constants/abis/factory-tricrypto.json +664 -0
- package/lib/constants/abis/voting_escrow_oracle.json +450 -0
- package/lib/constants/abis/voting_escrow_oracle_eth.json +76 -0
- package/lib/constants/aliases.js +11 -0
- package/lib/curve.d.ts +6 -0
- package/lib/curve.js +89 -2
- package/lib/external-api.d.ts +8 -1
- package/lib/external-api.js +16 -0
- package/lib/factory/factory-api.d.ts +1 -1
- package/lib/factory/factory-api.js +22 -37
- package/lib/factory/factory-crypto.js +1 -1
- package/lib/factory/factory-tricrypto.d.ts +2 -0
- package/lib/factory/factory-tricrypto.js +303 -0
- package/lib/index.d.ts +19 -1
- package/lib/index.js +28 -2
- package/lib/interfaces.d.ts +3 -0
- package/lib/pools/PoolTemplate.js +5 -5
- package/lib/router.js +1 -1
- package/lib/utils.js +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -26,6 +26,7 @@ import curve from "@curvefi/api";
|
|
|
26
26
|
await curve.factory.fetchPools();
|
|
27
27
|
await curve.crvUSDFactory.fetchPools();
|
|
28
28
|
await curve.cryptoFactory.fetchPools();
|
|
29
|
+
await curve.tricryptoFactory.fetchPools();
|
|
29
30
|
})()
|
|
30
31
|
```
|
|
31
32
|
**Note 1.** ```chainId``` parameter is optional, but you must specify it in the case you use Metamask on localhost network, because Metamask has that [bug](https://hardhat.org/metamask-issue.html)
|
|
@@ -188,6 +189,7 @@ import curve from "@curvefi/api";
|
|
|
188
189
|
await curve.factory.fetchPools();
|
|
189
190
|
await curve.crvUSDFactory.fetchPools();
|
|
190
191
|
await curve.cryptoFactory.fetchPools();
|
|
192
|
+
await curve.tricryptoFactory.fetchPools();
|
|
191
193
|
|
|
192
194
|
curve.getMainPoolList();
|
|
193
195
|
// [
|
|
@@ -264,6 +266,9 @@ import curve from "@curvefi/api";
|
|
|
264
266
|
// 'factory-crypto-60', 'factory-crypto-61', 'factory-crypto-62'
|
|
265
267
|
// ]
|
|
266
268
|
|
|
269
|
+
curve.tricryptoFactory.getPoolList();
|
|
270
|
+
// ['factory-tricrypto-0', 'factory-tricrypto-1']
|
|
271
|
+
|
|
267
272
|
curve.getPoolList();
|
|
268
273
|
// [
|
|
269
274
|
// 'compound', 'usdt', 'y', 'busd',
|
|
@@ -305,6 +310,7 @@ import curve from "@curvefi/api";
|
|
|
305
310
|
await curve.factory.fetchPools();
|
|
306
311
|
await curve.crvUSDFactory.fetchPools();
|
|
307
312
|
await curve.cryptoFactory.fetchPools();
|
|
313
|
+
await curve.tricryptoFactory.fetchPools();
|
|
308
314
|
|
|
309
315
|
const pool = curve.getPool('factory-v2-11');
|
|
310
316
|
|
|
@@ -1011,6 +1017,7 @@ import curve from "@curvefi/api";
|
|
|
1011
1017
|
await curve.factory.fetchPools();
|
|
1012
1018
|
await curve.crvUSDFactory.fetchPools();
|
|
1013
1019
|
await curve.cryptoFactory.fetchPools();
|
|
1020
|
+
await curve.tricryptoFactory.fetchPools();
|
|
1014
1021
|
|
|
1015
1022
|
await curve.getBalances(['DAI', 'CRV']);
|
|
1016
1023
|
// [ '9900.0', '100049.744832225238317557' ]
|
|
@@ -1144,6 +1151,42 @@ import curve from "@curvefi/api";
|
|
|
1144
1151
|
// 0.0
|
|
1145
1152
|
})()
|
|
1146
1153
|
```
|
|
1154
|
+
### Sidechain
|
|
1155
|
+
```ts
|
|
1156
|
+
import curve from "@curvefi/api";
|
|
1157
|
+
|
|
1158
|
+
(async () => {
|
|
1159
|
+
|
|
1160
|
+
// --- SIDECHAIN ---
|
|
1161
|
+
|
|
1162
|
+
await curve.init('JsonRpc', {}, { gasPrice: 0, maxFeePerGas: 0, maxPriorityFeePerGas: 0 });
|
|
1163
|
+
|
|
1164
|
+
await curve.boosting.sidechain.lastBlockhash();
|
|
1165
|
+
// 16931944
|
|
1166
|
+
await curve.boosting.sidechain.checkBlockhash(17377005);
|
|
1167
|
+
// false
|
|
1168
|
+
|
|
1169
|
+
await curve.boosting.sidechain.getAnycallBalance();
|
|
1170
|
+
// 0.033837278711248954
|
|
1171
|
+
await curve.boosting.sidechain.topUpAnycall(0.1);
|
|
1172
|
+
await curve.boosting.sidechain.getAnycallBalance();
|
|
1173
|
+
// 0.133837278711248954
|
|
1174
|
+
|
|
1175
|
+
|
|
1176
|
+
// --- MAINNET (ETHEREUM) ---
|
|
1177
|
+
|
|
1178
|
+
await curve.init('JsonRpc', {}, { gasPrice: 0, maxFeePerGas: 0, maxPriorityFeePerGas: 0 });
|
|
1179
|
+
await curve.boosting.sidechain.sendBlockhash(17377005, 137); // Polygon
|
|
1180
|
+
|
|
1181
|
+
// --- SIDECHAIN ---
|
|
1182
|
+
|
|
1183
|
+
await curve.init('JsonRpc', {}, { gasPrice: 0, maxFeePerGas: 0, maxPriorityFeePerGas: 0 });
|
|
1184
|
+
await curve.boosting.sidechain.checkBlockhash(17377005);
|
|
1185
|
+
// true
|
|
1186
|
+
await curve.boosting.sidechain.submitProof(17377005, "0x33A4622B82D4c04a53e170c638B944ce27cffce3");
|
|
1187
|
+
})()
|
|
1188
|
+
```
|
|
1189
|
+
|
|
1147
1190
|
|
|
1148
1191
|
## CRV. Profit, claim, boosting
|
|
1149
1192
|
```ts
|
|
@@ -1333,12 +1376,15 @@ import curve from "@curvefi/api";
|
|
|
1333
1376
|
// Fetch pools from api (if false arg is not passed)
|
|
1334
1377
|
await curve.factory.fetchPools();
|
|
1335
1378
|
await curve.cryptoFactory.fetchPools();
|
|
1379
|
+
await curve.tricryptoFactory.fetchPools();
|
|
1336
1380
|
|
|
1337
1381
|
// Fetch very new pools (that haven't been added to api yet) from blockchain
|
|
1338
1382
|
await curve.factory.fetchNewPools();
|
|
1339
1383
|
// [ 'factory-v2-285' ]
|
|
1340
1384
|
await curve.cryptoFactory.fetchNewPools();
|
|
1341
1385
|
// [ 'factory-crypto-232' ]
|
|
1386
|
+
await curve.tricryptoFactory.fetchNewPools();
|
|
1387
|
+
// [ 'factory-tricrypto-2' ]
|
|
1342
1388
|
})()
|
|
1343
1389
|
```
|
|
1344
1390
|
|
package/lib/boosting.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IDict } from "./interfaces";
|
|
1
|
+
import { IDict, IChainId } from "./interfaces";
|
|
2
2
|
export declare const getCrv: (...addresses: string[] | string[][]) => Promise<IDict<string> | string>;
|
|
3
3
|
export declare const getLockedAmountAndUnlockTime: (...addresses: string[] | string[][]) => Promise<IDict<{
|
|
4
4
|
lockedAmount: string;
|
|
@@ -24,3 +24,12 @@ export declare const withdrawLockedCrv: () => Promise<string>;
|
|
|
24
24
|
export declare const claimableFees: (address?: string) => Promise<string>;
|
|
25
25
|
export declare const claimFeesEstimateGas: (address?: string) => Promise<number>;
|
|
26
26
|
export declare const claimFees: (address?: string) => Promise<string>;
|
|
27
|
+
export declare const lastBlockhash: () => Promise<number>;
|
|
28
|
+
export declare const checkBlockhash: (block: number) => Promise<boolean>;
|
|
29
|
+
export declare const getAnycallBalance: () => Promise<string>;
|
|
30
|
+
export declare const topUpAnycallEstimateGas: (amount?: number | string) => Promise<number>;
|
|
31
|
+
export declare const topUpAnycall: (amount?: number | string) => Promise<string>;
|
|
32
|
+
export declare const sendBlockhashEstimateGas: (block: number, chainId: IChainId) => Promise<number>;
|
|
33
|
+
export declare const sendBlockhash: (block: number, chainId: IChainId) => Promise<string>;
|
|
34
|
+
export declare const submitProofEstimateGas: (block: number, address?: string) => Promise<number>;
|
|
35
|
+
export declare const submitProof: (block: number, address?: string) => Promise<string>;
|
package/lib/boosting.js
CHANGED
|
@@ -50,6 +50,7 @@ import { curve } from "./curve.js";
|
|
|
50
50
|
import feeDistributorViewABI from "./constants/abis/fee_distributor_view.json" assert { type: 'json' };
|
|
51
51
|
import { _getBalances, _prepareAddresses, ensureAllowance, ensureAllowanceEstimateGas, hasAllowance, mulBy1_3 } from "./utils.js";
|
|
52
52
|
import { _ensureAllowance, toBN, toStringFromBN, parseUnits } from './utils.js';
|
|
53
|
+
import { _generateBoostingProof } from './external-api.js';
|
|
53
54
|
export var getCrv = function () {
|
|
54
55
|
var addresses = [];
|
|
55
56
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
@@ -400,3 +401,191 @@ export var claimFees = function (address) {
|
|
|
400
401
|
});
|
|
401
402
|
});
|
|
402
403
|
};
|
|
404
|
+
// ------------ SIDECHAIN ------------
|
|
405
|
+
export var lastBlockhash = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
406
|
+
var veOracleContract, _a;
|
|
407
|
+
return __generator(this, function (_b) {
|
|
408
|
+
switch (_b.label) {
|
|
409
|
+
case 0:
|
|
410
|
+
if (curve.chainId === 1)
|
|
411
|
+
throw Error("There is no lastBlock method on ethereum network");
|
|
412
|
+
veOracleContract = curve.contracts[curve.constants.ALIASES.voting_escrow_oracle].contract;
|
|
413
|
+
_a = Number;
|
|
414
|
+
return [4 /*yield*/, veOracleContract.last_eth_block_number(curve.constantOptions)];
|
|
415
|
+
case 1: return [2 /*return*/, _a.apply(void 0, [_b.sent()])];
|
|
416
|
+
}
|
|
417
|
+
});
|
|
418
|
+
}); };
|
|
419
|
+
export var checkBlockhash = function (block) { return __awaiter(void 0, void 0, void 0, function () {
|
|
420
|
+
var veOracleContract, e_1;
|
|
421
|
+
return __generator(this, function (_a) {
|
|
422
|
+
switch (_a.label) {
|
|
423
|
+
case 0:
|
|
424
|
+
if (curve.chainId === 1)
|
|
425
|
+
throw Error("There is no checkBlockhash method on ethereum network");
|
|
426
|
+
veOracleContract = curve.contracts[curve.constants.ALIASES.voting_escrow_oracle].contract;
|
|
427
|
+
_a.label = 1;
|
|
428
|
+
case 1:
|
|
429
|
+
_a.trys.push([1, 3, , 4]);
|
|
430
|
+
return [4 /*yield*/, veOracleContract.get_eth_blockhash(block, curve.constantOptions)];
|
|
431
|
+
case 2:
|
|
432
|
+
_a.sent();
|
|
433
|
+
return [2 /*return*/, true];
|
|
434
|
+
case 3:
|
|
435
|
+
e_1 = _a.sent();
|
|
436
|
+
return [2 /*return*/, false];
|
|
437
|
+
case 4: return [2 /*return*/];
|
|
438
|
+
}
|
|
439
|
+
});
|
|
440
|
+
}); };
|
|
441
|
+
export var getAnycallBalance = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
442
|
+
var anycallContract, _balance;
|
|
443
|
+
return __generator(this, function (_a) {
|
|
444
|
+
switch (_a.label) {
|
|
445
|
+
case 0:
|
|
446
|
+
if (curve.chainId === 1)
|
|
447
|
+
throw Error("There is no getAnycallBalance method on ethereum network");
|
|
448
|
+
anycallContract = curve.contracts[curve.constants.ALIASES.anycall].contract;
|
|
449
|
+
return [4 /*yield*/, anycallContract.executionBudget(curve.constants.ALIASES.voting_escrow_oracle, curve.constantOptions)];
|
|
450
|
+
case 1:
|
|
451
|
+
_balance = _a.sent();
|
|
452
|
+
return [2 /*return*/, curve.formatUnits(_balance)];
|
|
453
|
+
}
|
|
454
|
+
});
|
|
455
|
+
}); };
|
|
456
|
+
var DEFAULT_AMOUNT = (curve.chainId === 42161 || curve.chainId === 10) ? 0.00001 : 0.1;
|
|
457
|
+
var _topUpAnycall = function (amount, estimateGas) { return __awaiter(void 0, void 0, void 0, function () {
|
|
458
|
+
var anycallContract, value, gas, gasLimit;
|
|
459
|
+
return __generator(this, function (_a) {
|
|
460
|
+
switch (_a.label) {
|
|
461
|
+
case 0:
|
|
462
|
+
if (curve.chainId === 1)
|
|
463
|
+
throw Error("There is no topUpAnycall method on ethereum network");
|
|
464
|
+
anycallContract = curve.contracts[curve.constants.ALIASES.anycall].contract;
|
|
465
|
+
value = curve.parseUnits(String(amount));
|
|
466
|
+
return [4 /*yield*/, anycallContract.deposit.estimateGas(curve.constants.ALIASES.voting_escrow_oracle, __assign(__assign({}, curve.constantOptions), { value: value }))];
|
|
467
|
+
case 1:
|
|
468
|
+
gas = _a.sent();
|
|
469
|
+
if (estimateGas)
|
|
470
|
+
return [2 /*return*/, Number(gas)];
|
|
471
|
+
return [4 /*yield*/, curve.updateFeeData()];
|
|
472
|
+
case 2:
|
|
473
|
+
_a.sent();
|
|
474
|
+
gasLimit = mulBy1_3(gas);
|
|
475
|
+
return [4 /*yield*/, anycallContract.deposit(curve.constants.ALIASES.voting_escrow_oracle, __assign(__assign({}, curve.options), { gasLimit: gasLimit, value: value }))];
|
|
476
|
+
case 3: return [2 /*return*/, (_a.sent()).hash];
|
|
477
|
+
}
|
|
478
|
+
});
|
|
479
|
+
}); };
|
|
480
|
+
export var topUpAnycallEstimateGas = function (amount) {
|
|
481
|
+
if (amount === void 0) { amount = DEFAULT_AMOUNT; }
|
|
482
|
+
return __awaiter(void 0, void 0, void 0, function () {
|
|
483
|
+
return __generator(this, function (_a) {
|
|
484
|
+
switch (_a.label) {
|
|
485
|
+
case 0: return [4 /*yield*/, _topUpAnycall(amount, true)];
|
|
486
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
487
|
+
}
|
|
488
|
+
});
|
|
489
|
+
});
|
|
490
|
+
};
|
|
491
|
+
export var topUpAnycall = function (amount) {
|
|
492
|
+
if (amount === void 0) { amount = DEFAULT_AMOUNT; }
|
|
493
|
+
return __awaiter(void 0, void 0, void 0, function () {
|
|
494
|
+
return __generator(this, function (_a) {
|
|
495
|
+
switch (_a.label) {
|
|
496
|
+
case 0: return [4 /*yield*/, _topUpAnycall(amount, false)];
|
|
497
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
498
|
+
}
|
|
499
|
+
});
|
|
500
|
+
});
|
|
501
|
+
};
|
|
502
|
+
var _sendBlockhash = function (block, chainId, estimateGas) { return __awaiter(void 0, void 0, void 0, function () {
|
|
503
|
+
var veOracleContract, gas, gasLimit;
|
|
504
|
+
return __generator(this, function (_a) {
|
|
505
|
+
switch (_a.label) {
|
|
506
|
+
case 0:
|
|
507
|
+
if (curve.chainId !== 1)
|
|
508
|
+
throw Error("sendBlockhash method is on ethereum network only");
|
|
509
|
+
veOracleContract = curve.contracts[curve.constants.ALIASES.voting_escrow_oracle].contract;
|
|
510
|
+
return [4 /*yield*/, veOracleContract.send_blockhash.estimateGas(block, chainId, curve.constantOptions)];
|
|
511
|
+
case 1:
|
|
512
|
+
gas = _a.sent();
|
|
513
|
+
if (estimateGas)
|
|
514
|
+
return [2 /*return*/, Number(gas)];
|
|
515
|
+
return [4 /*yield*/, curve.updateFeeData()];
|
|
516
|
+
case 2:
|
|
517
|
+
_a.sent();
|
|
518
|
+
gasLimit = mulBy1_3(gas);
|
|
519
|
+
return [4 /*yield*/, veOracleContract.deposit(curve.constants.ALIASES.voting_escrow_oracle, __assign(__assign({}, curve.options), { gasLimit: gasLimit }))];
|
|
520
|
+
case 3: return [2 /*return*/, (_a.sent()).hash];
|
|
521
|
+
}
|
|
522
|
+
});
|
|
523
|
+
}); };
|
|
524
|
+
export var sendBlockhashEstimateGas = function (block, chainId) { return __awaiter(void 0, void 0, void 0, function () {
|
|
525
|
+
return __generator(this, function (_a) {
|
|
526
|
+
switch (_a.label) {
|
|
527
|
+
case 0: return [4 /*yield*/, _sendBlockhash(block, chainId, true)];
|
|
528
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
529
|
+
}
|
|
530
|
+
});
|
|
531
|
+
}); };
|
|
532
|
+
export var sendBlockhash = function (block, chainId) { return __awaiter(void 0, void 0, void 0, function () {
|
|
533
|
+
return __generator(this, function (_a) {
|
|
534
|
+
switch (_a.label) {
|
|
535
|
+
case 0: return [4 /*yield*/, _sendBlockhash(block, chainId, false)];
|
|
536
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
537
|
+
}
|
|
538
|
+
});
|
|
539
|
+
}); };
|
|
540
|
+
var _submitProof = function (block, address, estimateGas) {
|
|
541
|
+
if (address === void 0) { address = curve.signerAddress; }
|
|
542
|
+
return __awaiter(void 0, void 0, void 0, function () {
|
|
543
|
+
var proof, veOracleContract, gas, gasLimit;
|
|
544
|
+
return __generator(this, function (_a) {
|
|
545
|
+
switch (_a.label) {
|
|
546
|
+
case 0:
|
|
547
|
+
if (curve.chainId === 1)
|
|
548
|
+
throw Error("submitProof method is on ethereum network only");
|
|
549
|
+
if (address === "")
|
|
550
|
+
throw Error("Pass address you want to submit proof for");
|
|
551
|
+
return [4 /*yield*/, _generateBoostingProof(block, address)];
|
|
552
|
+
case 1:
|
|
553
|
+
proof = _a.sent();
|
|
554
|
+
veOracleContract = curve.contracts[curve.constants.ALIASES.voting_escrow_oracle].contract;
|
|
555
|
+
return [4 /*yield*/, veOracleContract.submit_state.estimateGas(address, "0x" + proof.block_header_rlp, "0x" + proof.proof_rlp, curve.constantOptions)];
|
|
556
|
+
case 2:
|
|
557
|
+
gas = _a.sent();
|
|
558
|
+
if (estimateGas)
|
|
559
|
+
return [2 /*return*/, Number(gas)];
|
|
560
|
+
return [4 /*yield*/, curve.updateFeeData()];
|
|
561
|
+
case 3:
|
|
562
|
+
_a.sent();
|
|
563
|
+
gasLimit = mulBy1_3(gas);
|
|
564
|
+
return [4 /*yield*/, veOracleContract.submit_state(address, "0x" + proof.block_header_rlp, "0x" + proof.proof_rlp, __assign(__assign({}, curve.options), { gasLimit: gasLimit }))];
|
|
565
|
+
case 4: return [2 /*return*/, (_a.sent()).hash];
|
|
566
|
+
}
|
|
567
|
+
});
|
|
568
|
+
});
|
|
569
|
+
};
|
|
570
|
+
export var submitProofEstimateGas = function (block, address) {
|
|
571
|
+
if (address === void 0) { address = curve.signerAddress; }
|
|
572
|
+
return __awaiter(void 0, void 0, void 0, function () {
|
|
573
|
+
return __generator(this, function (_a) {
|
|
574
|
+
switch (_a.label) {
|
|
575
|
+
case 0: return [4 /*yield*/, _submitProof(block, address, true)];
|
|
576
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
577
|
+
}
|
|
578
|
+
});
|
|
579
|
+
});
|
|
580
|
+
};
|
|
581
|
+
export var submitProof = function (block, address) {
|
|
582
|
+
if (address === void 0) { address = curve.signerAddress; }
|
|
583
|
+
return __awaiter(void 0, void 0, void 0, function () {
|
|
584
|
+
return __generator(this, function (_a) {
|
|
585
|
+
switch (_a.label) {
|
|
586
|
+
case 0: return [4 /*yield*/, _submitProof(block, address, false)];
|
|
587
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
588
|
+
}
|
|
589
|
+
});
|
|
590
|
+
});
|
|
591
|
+
};
|