@curvefi/api 2.36.1 → 2.38.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 CHANGED
@@ -1144,6 +1144,42 @@ import curve from "@curvefi/api";
1144
1144
  // 0.0
1145
1145
  })()
1146
1146
  ```
1147
+ ### Sidechain
1148
+ ```ts
1149
+ import curve from "@curvefi/api";
1150
+
1151
+ (async () => {
1152
+
1153
+ // --- SIDECHAIN ---
1154
+
1155
+ await curve.init('JsonRpc', {}, { gasPrice: 0, maxFeePerGas: 0, maxPriorityFeePerGas: 0 });
1156
+
1157
+ await curve.boosting.sidechain.lastBlockhash();
1158
+ // 16931944
1159
+ await curve.boosting.sidechain.checkBlockhash(17377005);
1160
+ // false
1161
+
1162
+ await curve.boosting.sidechain.getAnycallBalance();
1163
+ // 0.033837278711248954
1164
+ await curve.boosting.sidechain.topUpAnycall(0.1);
1165
+ await curve.boosting.sidechain.getAnycallBalance();
1166
+ // 0.133837278711248954
1167
+
1168
+
1169
+ // --- MAINNET (ETHEREUM) ---
1170
+
1171
+ await curve.init('JsonRpc', {}, { gasPrice: 0, maxFeePerGas: 0, maxPriorityFeePerGas: 0 });
1172
+ await curve.boosting.sidechain.sendBlockhash(17377005, 137); // Polygon
1173
+
1174
+ // --- SIDECHAIN ---
1175
+
1176
+ await curve.init('JsonRpc', {}, { gasPrice: 0, maxFeePerGas: 0, maxPriorityFeePerGas: 0 });
1177
+ await curve.boosting.sidechain.checkBlockhash(17377005);
1178
+ // true
1179
+ await curve.boosting.sidechain.submitProof(17377005, "0x33A4622B82D4c04a53e170c638B944ce27cffce3");
1180
+ })()
1181
+ ```
1182
+
1147
1183
 
1148
1184
  ## CRV. Profit, claim, boosting
1149
1185
  ```ts
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
+ };