@curvefi/api 2.39.0 → 2.40.1

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
@@ -1573,4 +1573,69 @@ import curve from "@curvefi/api";
1573
1573
  const underlyingBalances = await pool.stats.underlyingBalances();
1574
1574
  // [ '30.0', '0.02' ]
1575
1575
  })()
1576
+ ```
1577
+
1578
+ ### Deploy tricrypto pool
1579
+
1580
+ ```ts
1581
+ import curve from "@curvefi/api";
1582
+
1583
+ (async () => {
1584
+ await curve.init('JsonRpc', {}, { gasPrice: 0 });
1585
+
1586
+ const coins = [
1587
+ "0xC581b735A1688071A1746c968e0798D642EDE491", // EURT
1588
+ "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2", // WETH
1589
+ "0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599", // WBTC
1590
+ ];
1591
+
1592
+ // Deploy pool
1593
+
1594
+ const deployPoolTx = await curve.tricryptoFactory.deployPool(
1595
+ "Test tricrypto pool",
1596
+ "TTP",
1597
+ coins,
1598
+ 400000,
1599
+ 0.0000725,
1600
+ 0.25,
1601
+ 0.45,
1602
+ 0.000002,
1603
+ 0.00023,
1604
+ 0.000146,
1605
+ 600,
1606
+ [1700, 27000]
1607
+ );
1608
+ // ContractTransactionResponse {
1609
+ // provider: JsonRpcProvider {},
1610
+ // blockNumber: 17393463,
1611
+ // blockHash: '0x7f393493d7eb30b39aeef3118b51925426946eb83b72b18946f0da8c7bec40a0',
1612
+ // ...
1613
+ // }
1614
+ const poolAddress = await curve.tricryptoFactory.getDeployedPoolAddress(deployPoolTx);
1615
+ // 0x2889302a794dA87fBF1D6Db415C1492194663D13
1616
+
1617
+ // Deploy gauge
1618
+
1619
+ const deployGaugeTx = await curve.tricryptoFactory.deployGauge(poolAddress);
1620
+ // ContractTransactionResponse {
1621
+ // provider: JsonRpcProvider {},
1622
+ // blockNumber: 17393463,
1623
+ // blockHash: '0x7f393493d7eb30b39aeef3118b51925426946eb83b72b18946f0da8c7bec40a0',
1624
+ // ...
1625
+ // }
1626
+ const gaugeAddress = await curve.factory.getDeployedGaugeAddress(deployGaugeTx);
1627
+ // 0x60d3d7ebbc44dc810a743703184f062d00e6db7e
1628
+
1629
+ // Deposit & Stake
1630
+
1631
+ const poolId = await curve.tricryptoFactory.fetchRecentlyDeployedPool(poolAddress);
1632
+ // factory-tricrypto-2
1633
+ const pool = curve.getPool(poolId);
1634
+
1635
+ const amounts = await pool.cryptoSeedAmounts(30); // Initial amounts for crypto pools must have the ratio corresponding to initialPrice
1636
+ // [ '30', '0.017647058823529412', '0.00111111' ]
1637
+ await pool.depositAndStake(amounts);
1638
+ const underlyingBalances = await pool.stats.underlyingBalances();
1639
+ // [ '30', '0.017647058823529412', '0.00111111' ]
1640
+ })()
1576
1641
  ```
@@ -1,6 +1,6 @@
1
1
  import memoize from "memoizee";
2
- import { IExtendedPoolDataFromApi, ISubgraphPoolData, IDict, INetworkName } from "./interfaces";
3
- export declare const _getPoolsFromApi: ((network: INetworkName, poolType: "main" | "crypto" | "factory" | "factory-crvusd" | "factory-crypto" | "factory-tricrypto") => Promise<IExtendedPoolDataFromApi>) & memoize.Memoized<(network: INetworkName, poolType: "main" | "crypto" | "factory" | "factory-crvusd" | "factory-crypto" | "factory-tricrypto") => Promise<IExtendedPoolDataFromApi>>;
2
+ import { IExtendedPoolDataFromApi, ISubgraphPoolData, IDict, INetworkName, IPoolType } from "./interfaces";
3
+ export declare const _getPoolsFromApi: ((network: INetworkName, poolType: IPoolType) => Promise<IExtendedPoolDataFromApi>) & memoize.Memoized<(network: INetworkName, poolType: IPoolType) => Promise<IExtendedPoolDataFromApi>>;
4
4
  export declare const _getAllPoolsFromApi: (network: INetworkName) => Promise<IExtendedPoolDataFromApi[]>;
5
5
  export declare const _getSubgraphData: ((network: INetworkName) => Promise<{
6
6
  poolsData: ISubgraphPoolData[];
@@ -62,6 +62,7 @@ export var _getAllPoolsFromApi = function (network) { return __awaiter(void 0, v
62
62
  _getPoolsFromApi(network, "factory"),
63
63
  _getPoolsFromApi(network, "factory-crvusd"),
64
64
  _getPoolsFromApi(network, "factory-crypto"),
65
+ _getPoolsFromApi(network, "factory-tricrypto"),
65
66
  ])];
66
67
  case 1: return [2 /*return*/, _a.sent()];
67
68
  }
@@ -8,9 +8,12 @@ export declare const setOracle: (poolAddress: string, oracleAddress?: string, me
8
8
  export declare const deployStableMetaPoolEstimateGas: (basePool: string, name: string, symbol: string, coin: string, A: number | string, fee: number | string, implementationIdx: 0 | 1) => Promise<number>;
9
9
  export declare const deployStableMetaPool: (basePool: string, name: string, symbol: string, coin: string, A: number | string, fee: number | string, implementationIdx: 0 | 1) => Promise<ethers.ContractTransactionResponse>;
10
10
  export declare const getDeployedStableMetaPoolAddress: (tx: ethers.ContractTransactionResponse) => Promise<string>;
11
- export declare const deployCryptoPoolEstimateGas: (name: string, symbol: string, coins: string[], A: number | string, gamma: number | string, midFee: number | string, outFee: number | string, allowedExtraProfit: number | string, feeGamma: number | string, adjustmentStep: number | string, maHalfTime: number | string, initialPrice: number | string) => Promise<number>;
12
- export declare const deployCryptoPool: (name: string, symbol: string, coins: string[], A: number | string, gamma: number | string, midFee: number | string, outFee: number | string, allowedExtraProfit: number | string, feeGamma: number | string, adjustmentStep: number | string, maHalfTime: number | string, initialPrice: number | string) => Promise<ethers.ContractTransactionResponse>;
11
+ export declare const deployCryptoPoolEstimateGas: (name: string, symbol: string, coins: string[], A: number | string, gamma: number | string, midFee: number | string, outFee: number | string, allowedExtraProfit: number | string, feeGamma: number | string, adjustmentStep: number | string, maHalfTime: number, initialPrice: number | string) => Promise<number>;
12
+ export declare const deployCryptoPool: (name: string, symbol: string, coins: string[], A: number | string, gamma: number | string, midFee: number | string, outFee: number | string, allowedExtraProfit: number | string, feeGamma: number | string, adjustmentStep: number | string, maHalfTime: number, initialPrice: number | string) => Promise<ethers.ContractTransactionResponse>;
13
13
  export declare const getDeployedCryptoPoolAddress: (tx: ethers.ContractTransactionResponse) => Promise<string>;
14
- export declare const deployGaugeEstimateGas: (pool: string, isCrypto: boolean) => Promise<number>;
15
- export declare const deployGauge: (pool: string, isCrypto: boolean) => Promise<ethers.ContractTransactionResponse>;
14
+ export declare const deployTricryptoPoolEstimateGas: (name: string, symbol: string, coins: string[], A: number | string, gamma: number | string, midFee: number | string, outFee: number | string, allowedExtraProfit: number | string, feeGamma: number | string, adjustmentStep: number | string, emaTime: number, initialPrices: (number | string)[]) => Promise<number>;
15
+ export declare const deployTricryptoPool: (name: string, symbol: string, coins: string[], A: number | string, gamma: number | string, midFee: number | string, outFee: number | string, allowedExtraProfit: number | string, feeGamma: number | string, adjustmentStep: number | string, emaTime: number, initialPrices: (number | string)[]) => Promise<ethers.ContractTransactionResponse>;
16
+ export declare const getDeployedTricryptoPoolAddress: (tx: ethers.ContractTransactionResponse) => Promise<string>;
17
+ export declare const deployGaugeEstimateGas: (pool: string, factory: string) => Promise<number>;
18
+ export declare const deployGauge: (pool: string, factory: string) => Promise<ethers.ContractTransactionResponse>;
16
19
  export declare const getDeployedGaugeAddress: (tx: ethers.ContractTransactionResponse) => Promise<string>;
@@ -103,7 +103,7 @@ oracleAddress, methodName, estimateGas) { return __awaiter(void 0, void 0, void
103
103
  contract = curve.contracts[contractAddress].contract;
104
104
  args = [name, symbol, _coins, _A, _fee, assetType, implementationIdx];
105
105
  if (useProxy || setOracle)
106
- args.push(curve.parseUnits((emaTime / Math.log(2)).toFixed(0), 0));
106
+ args.push(parseUnits(Math.floor(emaTime / Math.log(2)), 0));
107
107
  if (setOracle) {
108
108
  methodId = methodName === "0x00000000" ? "0x00000000" : ethers.id(methodName).substring(0, 10);
109
109
  args.push(methodId, oracleAddress);
@@ -301,7 +301,7 @@ initialPrice, estimateGas) { return __awaiter(void 0, void 0, void 0, function (
301
301
  throw Error("Max symbol length = 10");
302
302
  if (coins.length !== 2)
303
303
  throw Error("Invalid number of coins. Must be 2");
304
- if (coins[1] === coins[2])
304
+ if (coins[0] === coins[1])
305
305
  throw Error("Coins must be different");
306
306
  if (BN(A).lt(4000))
307
307
  throw Error("A must be >= 4000. Passed A = ".concat(A));
@@ -402,14 +402,137 @@ export var getDeployedCryptoPoolAddress = function (tx) { return __awaiter(void
402
402
  }
403
403
  });
404
404
  }); };
405
+ // ------- TRICRYPTO POOLS -------
406
+ var _deployTricryptoPool = function (name, symbol, coins, A, gamma, midFee, // %
407
+ outFee, // %
408
+ allowedExtraProfit, feeGamma, adjustmentStep, emaTime, // Seconds
409
+ initialPrices, estimateGas) { return __awaiter(void 0, void 0, void 0, function () {
410
+ var _A, _gamma, _midFee, _outFee, _allowedExtraProfit, _feeGamma, _adjustmentStep, _emaTime, _initialPrices, contract, gas, gasLimit;
411
+ return __generator(this, function (_a) {
412
+ switch (_a.label) {
413
+ case 0:
414
+ if (name.length > 64)
415
+ throw Error("Max name length = 64");
416
+ if (symbol.length > 32)
417
+ throw Error("Max symbol length = 32");
418
+ if (coins.length !== 3)
419
+ throw Error("Invalid number of coins. Must be 3");
420
+ if (coins[0] === coins[1] || coins[1] === coins[2] || coins[0] === coins[2])
421
+ throw Error("Coins must be different");
422
+ if (BN(A).lt(2700))
423
+ throw Error("A must be >= 2700. Passed A = ".concat(A));
424
+ if (BN(A).gt(27 * (Math.pow(10, 7))))
425
+ throw Error("A must be <= 27 * 10 ** 7. Passed A = ".concat(A));
426
+ if (BN(gamma).lt(1e-8))
427
+ throw Error("gamma must be >= 1e-8. Passed gamma = ".concat(gamma));
428
+ if (BN(gamma).gt(0.05))
429
+ throw Error("gamma must be <= 0.05. Passed gamma = ".concat(gamma));
430
+ if (BN(midFee).lt(0))
431
+ throw Error("midFee must be >= 0. Passed midFee = ".concat(midFee));
432
+ if (BN(midFee).gt(100))
433
+ throw Error("midFee must be <= 100. Passed midFee = ".concat(midFee));
434
+ if (BN(outFee).lt(BN(midFee)))
435
+ throw Error("outFee must be >= midFee. Passed outFee = ".concat(outFee, " < midFee = ").concat(midFee));
436
+ if (BN(outFee).gt(100))
437
+ throw Error("outFee must be <= 100. Passed outFee = ".concat(outFee));
438
+ if (BN(allowedExtraProfit).lt(0))
439
+ throw Error("allowedExtraProfit must be >= 0. Passed allowedExtraProfit = ".concat(allowedExtraProfit));
440
+ if (BN(allowedExtraProfit).gt(1))
441
+ throw Error("allowedExtraProfit must be <= 1. Passed allowedExtraProfit = ".concat(allowedExtraProfit));
442
+ if (BN(feeGamma).lt(0))
443
+ throw Error("feeGamma must be >= 0. Passed feeGamma = ".concat(feeGamma));
444
+ if (BN(feeGamma).gt(1))
445
+ throw Error("feeGamma must be <= 1. Passed feeGamma = ".concat(feeGamma));
446
+ if (BN(adjustmentStep).lt(0))
447
+ throw Error("adjustmentStep must be >= 0. Passed adjustmentStep=".concat(adjustmentStep));
448
+ if (BN(adjustmentStep).gt(1))
449
+ throw Error("adjustmentStep must be <= 1. Passed adjustmentStep=".concat(adjustmentStep));
450
+ if (BN(emaTime).lt(60))
451
+ throw Error("maHalfTime must be >= 60. Passed maHalfTime=".concat(emaTime));
452
+ if (BN(emaTime).gt(604800))
453
+ throw Error("maHalfTime must be <= 604800. Passed maHalfTime=".concat(emaTime));
454
+ if (initialPrices.length !== 2)
455
+ throw Error("Invalid number of initial prices. Must be 2");
456
+ if (BN(initialPrices[0]).lt(1e-12))
457
+ throw Error("initialPrices[0] must be >= 1e-12. Passed initialPrices[0]=".concat(initialPrices[0]));
458
+ if (BN(initialPrices[0]).gt(1e12))
459
+ throw Error("initialPrices[0] must be <= 1e12. Passed initialPrices[0]=".concat(initialPrices[0]));
460
+ if (BN(initialPrices[1]).lt(1e-12))
461
+ throw Error("initialPrices[1] must be >= 1e-12. Passed initialPrices[1]=".concat(initialPrices[1]));
462
+ if (BN(initialPrices[1]).gt(1e12))
463
+ throw Error("initialPrices[1] must be <= 1e12. Passed initialPrices[1]=".concat(initialPrices[1]));
464
+ _A = parseUnits(A, 0);
465
+ _gamma = parseUnits(gamma);
466
+ _midFee = parseUnits(midFee, 8);
467
+ _outFee = parseUnits(outFee, 8);
468
+ _allowedExtraProfit = parseUnits(allowedExtraProfit);
469
+ _feeGamma = parseUnits(feeGamma);
470
+ _adjustmentStep = parseUnits(adjustmentStep);
471
+ _emaTime = parseUnits(Math.floor(emaTime / Math.log(2)), 0);
472
+ _initialPrices = [parseUnits(initialPrices[0]), parseUnits(initialPrices[1])];
473
+ contract = curve.contracts[curve.constants.ALIASES.tricrypto_factory].contract;
474
+ return [4 /*yield*/, contract.deploy_pool.estimateGas(name, symbol, coins, curve.constants.NATIVE_TOKEN.wrappedAddress, 0, _A, _gamma, _midFee, _outFee, _feeGamma, _allowedExtraProfit, _adjustmentStep, _emaTime, _initialPrices, curve.constantOptions)];
475
+ case 1:
476
+ gas = _a.sent();
477
+ if (estimateGas)
478
+ return [2 /*return*/, Number(gas)];
479
+ gasLimit = mulBy1_3(gas);
480
+ return [4 /*yield*/, curve.updateFeeData()];
481
+ case 2:
482
+ _a.sent();
483
+ return [4 /*yield*/, contract.deploy_pool(name, symbol, coins, curve.constants.NATIVE_TOKEN.wrappedAddress, 0, _A, _gamma, _midFee, _outFee, _feeGamma, _allowedExtraProfit, _adjustmentStep, _emaTime, _initialPrices, __assign(__assign({}, curve.options), { gasLimit: gasLimit }))];
484
+ case 3: return [2 /*return*/, _a.sent()];
485
+ }
486
+ });
487
+ }); };
488
+ export var deployTricryptoPoolEstimateGas = function (name, symbol, coins, A, gamma, midFee, // %
489
+ outFee, // %
490
+ allowedExtraProfit, feeGamma, adjustmentStep, emaTime, // Seconds
491
+ initialPrices) { return __awaiter(void 0, void 0, void 0, function () {
492
+ return __generator(this, function (_a) {
493
+ switch (_a.label) {
494
+ case 0: return [4 /*yield*/, _deployTricryptoPool(name, symbol, coins, A, gamma, midFee, outFee, allowedExtraProfit, feeGamma, adjustmentStep, emaTime, initialPrices, true)];
495
+ case 1: return [2 /*return*/, _a.sent()];
496
+ }
497
+ });
498
+ }); };
499
+ export var deployTricryptoPool = function (name, symbol, coins, A, gamma, midFee, // %
500
+ outFee, // %
501
+ allowedExtraProfit, feeGamma, adjustmentStep, emaTime, // Seconds
502
+ initialPrices) { return __awaiter(void 0, void 0, void 0, function () {
503
+ return __generator(this, function (_a) {
504
+ switch (_a.label) {
505
+ case 0: return [4 /*yield*/, _deployTricryptoPool(name, symbol, coins, A, gamma, midFee, outFee, allowedExtraProfit, feeGamma, adjustmentStep, emaTime, initialPrices, false)];
506
+ case 1: return [2 /*return*/, _a.sent()];
507
+ }
508
+ });
509
+ }); };
510
+ export var getDeployedTricryptoPoolAddress = function (tx) { return __awaiter(void 0, void 0, void 0, function () {
511
+ var txInfo, i;
512
+ return __generator(this, function (_a) {
513
+ switch (_a.label) {
514
+ case 0: return [4 /*yield*/, tx.wait()];
515
+ case 1:
516
+ txInfo = _a.sent();
517
+ if (!txInfo)
518
+ throw Error("Can't get tx info");
519
+ for (i = txInfo.logs.length - 1; i > -1; i--) {
520
+ if ("args" in txInfo.logs[i]) {
521
+ // @ts-ignore
522
+ return [2 /*return*/, txInfo.logs[i].args[0]];
523
+ }
524
+ }
525
+ throw Error("Can't get deployed tricrypto pool address");
526
+ }
527
+ });
528
+ }); };
405
529
  // ------- GAUGE -------
406
- var _deployGauge = function (pool, isCrypto, estimateGas) { return __awaiter(void 0, void 0, void 0, function () {
407
- var contractAddress, contract, gas, gasLimit;
530
+ var _deployGauge = function (pool, factory, estimateGas) { return __awaiter(void 0, void 0, void 0, function () {
531
+ var contract, gas, gasLimit;
408
532
  return __generator(this, function (_a) {
409
533
  switch (_a.label) {
410
534
  case 0:
411
- contractAddress = isCrypto ? curve.constants.ALIASES.crypto_factory : curve.constants.ALIASES.factory;
412
- contract = curve.contracts[contractAddress].contract;
535
+ contract = curve.contracts[factory].contract;
413
536
  return [4 /*yield*/, contract.deploy_gauge.estimateGas(pool, curve.constantOptions)];
414
537
  case 1:
415
538
  gas = _a.sent();
@@ -424,15 +547,15 @@ var _deployGauge = function (pool, isCrypto, estimateGas) { return __awaiter(voi
424
547
  }
425
548
  });
426
549
  }); };
427
- export var deployGaugeEstimateGas = function (pool, isCrypto) { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
550
+ export var deployGaugeEstimateGas = function (pool, factory) { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
428
551
  switch (_a.label) {
429
- case 0: return [4 /*yield*/, _deployGauge(pool, isCrypto, true)];
552
+ case 0: return [4 /*yield*/, _deployGauge(pool, factory, true)];
430
553
  case 1: return [2 /*return*/, _a.sent()];
431
554
  }
432
555
  }); }); };
433
- export var deployGauge = function (pool, isCrypto) { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
556
+ export var deployGauge = function (pool, factory) { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
434
557
  switch (_a.label) {
435
- case 0: return [4 /*yield*/, _deployGauge(pool, isCrypto, false)];
558
+ case 0: return [4 /*yield*/, _deployGauge(pool, factory, false)];
436
559
  case 1: return [2 /*return*/, _a.sent()];
437
560
  }
438
561
  }); }); };
package/lib/index.d.ts CHANGED
@@ -81,13 +81,13 @@ declare const curve: {
81
81
  fetchPools: (useApi?: boolean) => Promise<void>;
82
82
  fetchNewPools: () => Promise<string[]>;
83
83
  getPoolList: () => string[];
84
- deployPool: (name: string, symbol: string, coins: string[], A: string | number, gamma: string | number, midFee: string | number, outFee: string | number, allowedExtraProfit: string | number, feeGamma: string | number, adjustmentStep: string | number, maHalfTime: string | number, initialPrice: string | number) => Promise<ethers.ContractTransactionResponse>;
84
+ deployPool: (name: string, symbol: string, coins: string[], A: string | number, gamma: string | number, midFee: string | number, outFee: string | number, allowedExtraProfit: string | number, feeGamma: string | number, adjustmentStep: string | number, maHalfTime: number, initialPrice: string | number) => Promise<ethers.ContractTransactionResponse>;
85
85
  deployGauge: (poolAddress: string) => Promise<ethers.ContractTransactionResponse>;
86
86
  getDeployedPoolAddress: (tx: ethers.ContractTransactionResponse) => Promise<string>;
87
87
  getDeployedGaugeAddress: (tx: ethers.ContractTransactionResponse) => Promise<string>;
88
88
  fetchRecentlyDeployedPool: (poolAddress: string) => Promise<string>;
89
89
  estimateGas: {
90
- deployPool: (name: string, symbol: string, coins: string[], A: string | number, gamma: string | number, midFee: string | number, outFee: string | number, allowedExtraProfit: string | number, feeGamma: string | number, adjustmentStep: string | number, maHalfTime: string | number, initialPrice: string | number) => Promise<number>;
90
+ deployPool: (name: string, symbol: string, coins: string[], A: string | number, gamma: string | number, midFee: string | number, outFee: string | number, allowedExtraProfit: string | number, feeGamma: string | number, adjustmentStep: string | number, maHalfTime: number, initialPrice: string | number) => Promise<number>;
91
91
  deployGauge: (poolAddress: string) => Promise<number>;
92
92
  };
93
93
  };
@@ -95,7 +95,15 @@ declare const curve: {
95
95
  fetchPools: (useApi?: boolean) => Promise<void>;
96
96
  fetchNewPools: () => Promise<string[]>;
97
97
  getPoolList: () => string[];
98
+ deployPool: (name: string, symbol: string, coins: string[], A: string | number, gamma: string | number, midFee: string | number, outFee: string | number, allowedExtraProfit: string | number, feeGamma: string | number, adjustmentStep: string | number, emaTime: number, initialPrices: (string | number)[]) => Promise<ethers.ContractTransactionResponse>;
99
+ deployGauge: (poolAddress: string) => Promise<ethers.ContractTransactionResponse>;
100
+ getDeployedPoolAddress: (tx: ethers.ContractTransactionResponse) => Promise<string>;
101
+ getDeployedGaugeAddress: (tx: ethers.ContractTransactionResponse) => Promise<string>;
98
102
  fetchRecentlyDeployedPool: (poolAddress: string) => Promise<string>;
103
+ estimateGas: {
104
+ deployPool: (name: string, symbol: string, coins: string[], A: string | number, gamma: string | number, midFee: string | number, outFee: string | number, allowedExtraProfit: string | number, feeGamma: string | number, adjustmentStep: string | number, emaTime: number, initialPrices: (string | number)[]) => Promise<number>;
105
+ deployGauge: (poolAddress: string) => Promise<number>;
106
+ };
99
107
  };
100
108
  estimateGas: {
101
109
  ensureAllowance: (coins: string[], amounts: (string | number)[], spender: string, isMax?: boolean) => Promise<number>;
package/lib/index.js CHANGED
@@ -40,7 +40,7 @@ import { getBestRouteAndOutput, swapExpected, swapPriceImpact, swapIsApproved, s
40
40
  import { curve as _curve } from "./curve.js";
41
41
  import { getCrv, getLockedAmountAndUnlockTime, getVeCrv, getVeCrvPct, calcUnlockTime, createLockEstimateGas, createLock, isApproved, approveEstimateGas, approve, increaseAmountEstimateGas, increaseAmount, increaseUnlockTimeEstimateGas, increaseUnlockTime, withdrawLockedCrvEstimateGas, withdrawLockedCrv, claimableFees, claimFeesEstimateGas, claimFees, lastBlockhash, checkBlockhash, getAnycallBalance, topUpAnycall, topUpAnycallEstimateGas, sendBlockhash, sendBlockhashEstimateGas, submitProof, submitProofEstimateGas, } from "./boosting.js";
42
42
  import { getBalances, getAllowance, hasAllowance, ensureAllowanceEstimateGas, ensureAllowance, getUsdRate, getTVL, getCoinsData, getVolume, } from "./utils.js";
43
- import { deployStablePlainPool, deployStablePlainPoolEstimateGas, setOracle, setOracleEstimateGas, deployStableMetaPool, deployStableMetaPoolEstimateGas, deployCryptoPool, deployCryptoPoolEstimateGas, deployGauge, deployGaugeEstimateGas, getDeployedStablePlainPoolAddress, getDeployedStableMetaPoolAddress, getDeployedCryptoPoolAddress, getDeployedGaugeAddress, } from './factory/deploy.js';
43
+ import { deployStablePlainPool, deployStablePlainPoolEstimateGas, getDeployedStablePlainPoolAddress, setOracle, setOracleEstimateGas, deployStableMetaPool, deployStableMetaPoolEstimateGas, getDeployedStableMetaPoolAddress, deployCryptoPool, deployCryptoPoolEstimateGas, getDeployedCryptoPoolAddress, deployTricryptoPool, deployTricryptoPoolEstimateGas, getDeployedTricryptoPoolAddress, deployGauge, deployGaugeEstimateGas, getDeployedGaugeAddress, } from './factory/deploy.js';
44
44
  function init(providerType, providerSettings, options) {
45
45
  if (options === void 0) { options = {}; }
46
46
  return __awaiter(this, void 0, void 0, function () {
@@ -91,7 +91,7 @@ var curve = {
91
91
  setOracle: setOracle,
92
92
  deployMetaPool: deployStableMetaPool,
93
93
  deployGauge: function (poolAddress) { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
94
- return [2 /*return*/, deployGauge(poolAddress, false)];
94
+ return [2 /*return*/, deployGauge(poolAddress, _curve.constants.ALIASES.factory)];
95
95
  }); }); },
96
96
  getDeployedPlainPoolAddress: getDeployedStablePlainPoolAddress,
97
97
  getDeployedMetaPoolAddress: getDeployedStableMetaPoolAddress,
@@ -102,7 +102,7 @@ var curve = {
102
102
  setOracle: setOracleEstimateGas,
103
103
  deployMetaPool: deployStableMetaPoolEstimateGas,
104
104
  deployGauge: function (poolAddress) { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
105
- return [2 /*return*/, deployGaugeEstimateGas(poolAddress, false)];
105
+ return [2 /*return*/, deployGaugeEstimateGas(poolAddress, _curve.constants.ALIASES.factory)];
106
106
  }); }); },
107
107
  },
108
108
  },
@@ -116,7 +116,7 @@ var curve = {
116
116
  getPoolList: _curve.getCryptoFactoryPoolList,
117
117
  deployPool: deployCryptoPool,
118
118
  deployGauge: function (poolAddress) { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
119
- return [2 /*return*/, deployGauge(poolAddress, true)];
119
+ return [2 /*return*/, deployGauge(poolAddress, _curve.constants.ALIASES.crypto_factory)];
120
120
  }); }); },
121
121
  getDeployedPoolAddress: getDeployedCryptoPoolAddress,
122
122
  getDeployedGaugeAddress: getDeployedGaugeAddress,
@@ -124,7 +124,7 @@ var curve = {
124
124
  estimateGas: {
125
125
  deployPool: deployCryptoPoolEstimateGas,
126
126
  deployGauge: function (poolAddress) { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
127
- return [2 /*return*/, deployGaugeEstimateGas(poolAddress, true)];
127
+ return [2 /*return*/, deployGaugeEstimateGas(poolAddress, _curve.constants.ALIASES.crypto_factory)];
128
128
  }); }); },
129
129
  },
130
130
  },
@@ -132,15 +132,19 @@ var curve = {
132
132
  fetchPools: _curve.fetchTricryptoFactoryPools,
133
133
  fetchNewPools: _curve.fetchNewTricryptoFactoryPools,
134
134
  getPoolList: _curve.getTricryptoFactoryPoolList,
135
- // deployPool: deployCryptoPool,
136
- // deployGauge: async (poolAddress: string): Promise<ethers.ContractTransactionResponse> => deployGauge(poolAddress, true),
137
- // getDeployedPoolAddress: getDeployedCryptoPoolAddress,
138
- // getDeployedGaugeAddress: getDeployedGaugeAddress,
135
+ deployPool: deployTricryptoPool,
136
+ deployGauge: function (poolAddress) { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
137
+ return [2 /*return*/, deployGauge(poolAddress, _curve.constants.ALIASES.tricrypto_factory)];
138
+ }); }); },
139
+ getDeployedPoolAddress: getDeployedTricryptoPoolAddress,
140
+ getDeployedGaugeAddress: getDeployedGaugeAddress,
139
141
  fetchRecentlyDeployedPool: _curve.fetchRecentlyDeployedTricryptoFactoryPool,
140
- // estimateGas: {
141
- // deployPool: deployCryptoPoolEstimateGas,
142
- // deployGauge: async (poolAddress: string): Promise<number> => deployGaugeEstimateGas(poolAddress, true),
143
- // },
142
+ estimateGas: {
143
+ deployPool: deployTricryptoPoolEstimateGas,
144
+ deployGauge: function (poolAddress) { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
145
+ return [2 /*return*/, deployGaugeEstimateGas(poolAddress, _curve.constants.ALIASES.tricrypto_factory)];
146
+ }); }); },
147
+ },
144
148
  },
145
149
  estimateGas: {
146
150
  ensureAllowance: ensureAllowanceEstimateGas,
@@ -5,6 +5,7 @@ export interface IDict<T> {
5
5
  }
6
6
  export type INetworkName = "ethereum" | "optimism" | "xdai" | "polygon" | "fantom" | "moonbeam" | "kava" | "arbitrum" | "celo" | "avalanche" | "aurora";
7
7
  export type IChainId = 1 | 10 | 100 | 137 | 250 | 1284 | 2222 | 42161 | 42220 | 43114 | 1313161554;
8
+ export type IPoolType = "main" | "crypto" | "factory" | "factory-crvusd" | "factory-crypto" | "factory-tricrypto";
8
9
  export type REFERENCE_ASSET = 'USD' | 'EUR' | 'BTC' | 'ETH' | 'LINK' | 'CRYPTO' | 'OTHER';
9
10
  export interface IPoolData {
10
11
  name: string;
@@ -78,7 +78,7 @@ var PoolTemplate = /** @class */ (function () {
78
78
  calls = [
79
79
  multicallContract.get_virtual_price(),
80
80
  multicallContract.fee(),
81
- multicallContract.admin_fee(),
81
+ "admin_fee" in multicallContract ? multicallContract.admin_fee() : multicallContract.ADMIN_FEE(),
82
82
  multicallContract.A(),
83
83
  lpMulticallContract.totalSupply(),
84
84
  ];
@@ -157,7 +157,7 @@ var PoolTemplate = /** @class */ (function () {
157
157
  this.statsTotalLiquidity = function (useApi) {
158
158
  if (useApi === void 0) { useApi = true; }
159
159
  return __awaiter(_this, void 0, void 0, function () {
160
- var stablecoinContract, collateralContract, ammContract, _c, _balance_x, _fee_x, _balance_y, _fee_y, collateralRate, stablecoinTvlBN, collateralTvlBN, network, poolType, poolsData, totalLiquidity_1, balances, promises, _i, _d, addr, prices, totalLiquidity;
160
+ var stablecoinContract, collateralContract, ammContract, _c, _balance_x, _fee_x, _balance_y, _fee_y, collateralRate, stablecoinTvlBN, collateralTvlBN, network, poolType, factoryType, poolsData, totalLiquidity_1, balances, promises, _i, _d, addr, prices, totalLiquidity;
161
161
  var _this = this;
162
162
  return __generator(this, function (_e) {
163
163
  switch (_e.label) {
@@ -184,12 +184,12 @@ var PoolTemplate = /** @class */ (function () {
184
184
  if (!useApi) return [3 /*break*/, 5];
185
185
  network = curve.constants.NETWORK_NAME;
186
186
  poolType = this.isCrypto ? "crypto" : "main";
187
- if (this.id.startsWith("factory-v2-"))
187
+ if (this.id.startsWith("factory")) {
188
188
  poolType = "factory";
189
- if (this.id.startsWith("factory-crvusd-"))
190
- poolType = "factory-crvusd";
191
- if (this.id.startsWith("factory-crypto-"))
192
- poolType = "factory-crypto";
189
+ factoryType = this.id.split("-")[1];
190
+ if (factoryType)
191
+ poolType += "-" + factoryType;
192
+ }
193
193
  return [4 /*yield*/, _getPoolsFromApi(network, poolType)];
194
194
  case 4:
195
195
  poolsData = (_e.sent()).poolData;
@@ -376,7 +376,7 @@ var PoolTemplate = /** @class */ (function () {
376
376
  if (this.gauge === curve.constants.ZERO_ADDRESS)
377
377
  return [2 /*return*/, []];
378
378
  isDisabledChain = [1313161554].includes(curve.chainId);
379
- if (!(curve.chainId === 1 || (useApi && !isDisabledChain))) return [3 /*break*/, 2];
379
+ if (!(useApi && !isDisabledChain)) return [3 /*break*/, 2];
380
380
  return [4 /*yield*/, _getRewardsFromApi()];
381
381
  case 1:
382
382
  rewards = _d.sent();
@@ -464,7 +464,7 @@ var PoolTemplate = /** @class */ (function () {
464
464
  if (!BN(a).eq(BN(seedAmounts_1[i])))
465
465
  throw Error("Amounts must be = ".concat(seedAmounts_1));
466
466
  });
467
- return [2 /*return*/, parseUnits(Math.sqrt(Number(amounts[0]) * Number(amounts[1])))];
467
+ return [2 /*return*/, parseUnits(Math.sqrt(amounts.map(Number).reduce(function (a, b) { return a * b; })))];
468
468
  case 6:
469
469
  _c.trys.push([6, 11, , 13]);
470
470
  contract = curve.contracts[curve.constants.ALIASES.stable_calc].contract;
@@ -1283,23 +1283,36 @@ var PoolTemplate = /** @class */ (function () {
1283
1283
  };
1284
1284
  PoolTemplate.prototype.cryptoSeedAmounts = function (amount1) {
1285
1285
  return __awaiter(this, void 0, void 0, function () {
1286
- var decimals, amount1BN, priceScaleBN, _c;
1286
+ var decimals, amount1BN, priceScaleBN, _c, priceScaleBN;
1287
1287
  return __generator(this, function (_d) {
1288
1288
  switch (_d.label) {
1289
1289
  case 0:
1290
1290
  if (!this.isCrypto)
1291
1291
  throw Error("cryptoSeedAmounts method doesn't exist for stable pools");
1292
1292
  decimals = this.isMeta ? this.wrappedDecimals : this.underlyingDecimals;
1293
- if (decimals.length > 2)
1294
- throw Error("cryptoSeedAmounts method doesn't exist for pools with N coins > 2");
1295
1293
  amount1BN = BN(amount1);
1296
1294
  if (amount1BN.lte(0))
1297
1295
  throw Error("Initial deposit amounts must be > 0");
1296
+ if (!(decimals.length === 2)) return [3 /*break*/, 2];
1298
1297
  _c = toBN;
1299
1298
  return [4 /*yield*/, curve.contracts[this.address].contract.price_scale(curve.constantOptions)];
1300
1299
  case 1:
1301
1300
  priceScaleBN = _c.apply(void 0, [_d.sent()]);
1302
1301
  return [2 /*return*/, [_cutZeros(amount1BN.toFixed(decimals[0])), _cutZeros(amount1BN.div(priceScaleBN).toFixed(decimals[1]))]];
1302
+ case 2:
1303
+ if (!(decimals.length === 3)) return [3 /*break*/, 4];
1304
+ return [4 /*yield*/, curve.multicallProvider.all([
1305
+ curve.contracts[this.address].multicallContract.price_scale(0),
1306
+ curve.contracts[this.address].multicallContract.price_scale(1),
1307
+ ])];
1308
+ case 3:
1309
+ priceScaleBN = (_d.sent()).map(function (_p) { return toBN(_p); });
1310
+ return [2 /*return*/, [
1311
+ _cutZeros(amount1BN.toFixed(decimals[0])),
1312
+ _cutZeros(amount1BN.div(priceScaleBN[0]).toFixed(decimals[1])),
1313
+ _cutZeros(amount1BN.div(priceScaleBN[1]).toFixed(decimals[2])),
1314
+ ]];
1315
+ case 4: throw Error("cryptoSeedAmounts method doesn't exist for pools with N coins > 3");
1303
1316
  }
1304
1317
  });
1305
1318
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@curvefi/api",
3
- "version": "2.39.0",
3
+ "version": "2.40.1",
4
4
  "description": "JavaScript library for curve.fi",
5
5
  "main": "lib/index.js",
6
6
  "author": "Macket",