@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/lib/curve.js CHANGED
@@ -65,6 +65,9 @@ import yERC20Abi from './constants/abis/yERC20.json' assert { type: 'json' };
65
65
  import minterABI from './constants/abis/minter.json' assert { type: 'json' };
66
66
  import minterChildABI from './constants/abis/minter_child.json' assert { type: 'json' };
67
67
  import votingEscrowABI from './constants/abis/votingescrow.json' assert { type: 'json' };
68
+ import anycallABI from './constants/abis/anycall.json' assert { type: 'json' };
69
+ import votingEscrowOracleABI from './constants/abis/voting_escrow_oracle.json' assert { type: 'json' };
70
+ import votingEscrowOracleEthABI from './constants/abis/voting_escrow_oracle_eth.json' assert { type: 'json' };
68
71
  import feeDistributorABI from './constants/abis/fee_distributor.json' assert { type: 'json' };
69
72
  import addressProviderABI from './constants/abis/address_provider.json' assert { type: 'json' };
70
73
  import gaugeControllerABI from './constants/abis/gaugecontroller.json' assert { type: 'json' };
@@ -75,6 +78,7 @@ import StableCalcZapABI from './constants/abis/stable_calc.json' assert { type:
75
78
  import registryExchangeABI from './constants/abis/registry_exchange.json' assert { type: 'json' };
76
79
  import streamerABI from './constants/abis/streamer.json' assert { type: 'json' };
77
80
  import factoryABI from './constants/abis/factory.json' assert { type: 'json' };
81
+ import factoryAdminABI from './constants/abis/factory-admin.json' assert { type: 'json' };
78
82
  import cryptoFactoryABI from './constants/abis/factory-crypto.json' assert { type: 'json' };
79
83
  import { POOLS_DATA_ETHEREUM, LLAMMAS_DATA_ETHEREUM, POOLS_DATA_POLYGON, POOLS_DATA_FANTOM, POOLS_DATA_AVALANCHE, POOLS_DATA_ARBITRUM, POOLS_DATA_OPTIMISM, POOLS_DATA_XDAI, POOLS_DATA_MOONBEAM, POOLS_DATA_AURORA, POOLS_DATA_KAVA, POOLS_DATA_CELO, } from './constants/pools/index.js';
80
84
  import { ALIASES_ETHEREUM, ALIASES_OPTIMISM, ALIASES_POLYGON, ALIASES_FANTOM, ALIASES_AVALANCHE, ALIASES_ARBITRUM, ALIASES_XDAI, ALIASES_MOONBEAM, ALIASES_AURORA, ALIASES_KAVA, ALIASES_CELO, } from "./constants/aliases.js";
@@ -516,9 +520,9 @@ var Curve = /** @class */ (function () {
516
520
  var _a;
517
521
  if (options === void 0) { options = {}; }
518
522
  return __awaiter(this, void 0, void 0, function () {
519
- var _b, e_1, _c, network, poolId, _d, cTokens, yTokens, ycTokens, aTokens, customAbiTokens, _e, err_1, _i, _f, pool, _g, _h, coinAddr, _j, _k, coinAddr, _l, _m, coinAddr, _minterABI, addressProviderContract, _o;
520
- return __generator(this, function (_p) {
521
- switch (_p.label) {
523
+ var _b, e_1, _c, network, poolId, _d, cTokens, yTokens, ycTokens, aTokens, customAbiTokens, _e, err_1, _i, _f, pool, _g, _h, coinAddr, _j, _k, coinAddr, _l, _m, coinAddr, _minterABI, addressProviderContract, _o, factoryContract, _p;
524
+ return __generator(this, function (_q) {
525
+ switch (_q.label) {
522
526
  case 0:
523
527
  // @ts-ignore
524
528
  this.provider = null;
@@ -559,16 +563,16 @@ var Curve = /** @class */ (function () {
559
563
  return [3 /*break*/, 5];
560
564
  case 1:
561
565
  if (!!((_a = providerSettings.url) === null || _a === void 0 ? void 0 : _a.startsWith("https://rpc.gnosischain.com"))) return [3 /*break*/, 5];
562
- _p.label = 2;
566
+ _q.label = 2;
563
567
  case 2:
564
- _p.trys.push([2, 4, , 5]);
568
+ _q.trys.push([2, 4, , 5]);
565
569
  _b = this;
566
570
  return [4 /*yield*/, this.provider.getSigner()];
567
571
  case 3:
568
- _b.signer = _p.sent();
572
+ _b.signer = _q.sent();
569
573
  return [3 /*break*/, 5];
570
574
  case 4:
571
- e_1 = _p.sent();
575
+ e_1 = _q.sent();
572
576
  this.signer = null;
573
577
  return [3 /*break*/, 5];
574
578
  case 5: return [3 /*break*/, 9];
@@ -579,7 +583,7 @@ var Curve = /** @class */ (function () {
579
583
  _c = this;
580
584
  return [4 /*yield*/, this.provider.getSigner()];
581
585
  case 7:
582
- _c.signer = _p.sent();
586
+ _c.signer = _q.sent();
583
587
  return [3 /*break*/, 9];
584
588
  case 8:
585
589
  if (providerType.toLowerCase() === 'Infura'.toLowerCase()) {
@@ -596,15 +600,17 @@ var Curve = /** @class */ (function () {
596
600
  else {
597
601
  throw Error('Wrong providerType');
598
602
  }
599
- _p.label = 9;
603
+ _q.label = 9;
600
604
  case 9: return [4 /*yield*/, this.provider.getNetwork()];
601
605
  case 10:
602
- network = _p.sent();
606
+ network = _q.sent();
603
607
  console.log("CURVE-JS IS CONNECTED TO NETWORK:", { name: network.name.toUpperCase(), chainId: Number(network.chainId) });
604
608
  this.chainId = Number(network.chainId) === 1337 ? 1 : Number(network.chainId);
605
609
  this.constants.NATIVE_TOKEN = NATIVE_TOKENS[this.chainId];
606
610
  this.constants.NETWORK_NAME = NETWORK_CONSTANTS[this.chainId].NAME;
607
611
  this.constants.ALIASES = NETWORK_CONSTANTS[this.chainId].ALIASES;
612
+ this.constants.ALIASES.anycall = "0x37414a8662bc1d25be3ee51fb27c2686e2490a89";
613
+ this.constants.ALIASES.voting_escrow_oracle = "0x12F407340697Ae0b177546E535b91A5be021fBF9";
608
614
  this.constants.POOLS_DATA = NETWORK_CONSTANTS[this.chainId].POOLS_DATA;
609
615
  if (this.chainId === 1)
610
616
  this.constants.LLAMMAS_DATA = NETWORK_CONSTANTS[this.chainId].LLAMMAS_DATA;
@@ -624,30 +630,30 @@ var Curve = /** @class */ (function () {
624
630
  customAbiTokens = __spreadArray(__spreadArray(__spreadArray(__spreadArray([], cTokens, true), yTokens, true), ycTokens, true), aTokens, true);
625
631
  return [4 /*yield*/, _killGauges(this.constants.POOLS_DATA)];
626
632
  case 11:
627
- _p.sent();
633
+ _q.sent();
628
634
  this.multicallProvider = new MulticallProvider(this.chainId, this.provider);
629
635
  if (!this.signer) return [3 /*break*/, 16];
630
- _p.label = 12;
636
+ _q.label = 12;
631
637
  case 12:
632
- _p.trys.push([12, 14, , 15]);
638
+ _q.trys.push([12, 14, , 15]);
633
639
  _e = this;
634
640
  return [4 /*yield*/, this.signer.getAddress()];
635
641
  case 13:
636
- _e.signerAddress = _p.sent();
642
+ _e.signerAddress = _q.sent();
637
643
  return [3 /*break*/, 15];
638
644
  case 14:
639
- err_1 = _p.sent();
645
+ err_1 = _q.sent();
640
646
  this.signer = null;
641
647
  return [3 /*break*/, 15];
642
648
  case 15: return [3 /*break*/, 17];
643
649
  case 16:
644
650
  this.signerAddress = '';
645
- _p.label = 17;
651
+ _q.label = 17;
646
652
  case 17:
647
653
  this.feeData = { gasPrice: options.gasPrice, maxFeePerGas: options.maxFeePerGas, maxPriorityFeePerGas: options.maxPriorityFeePerGas };
648
654
  return [4 /*yield*/, this.updateFeeData()];
649
655
  case 18:
650
- _p.sent();
656
+ _q.sent();
651
657
  for (_i = 0, _f = Object.values(__assign(__assign({}, this.constants.POOLS_DATA), this.constants.LLAMMAS_DATA)); _i < _f.length; _i++) {
652
658
  pool = _f[_i];
653
659
  this.setContract(pool.swap_address, pool.swap_abi);
@@ -704,7 +710,7 @@ var Curve = /** @class */ (function () {
704
710
  _o = this.constants.ALIASES;
705
711
  return [4 /*yield*/, addressProviderContract.get_address(2, this.constantOptions)];
706
712
  case 19:
707
- _o.registry_exchange = (_p.sent()).toLowerCase();
713
+ _o.registry_exchange = (_q.sent()).toLowerCase();
708
714
  this.setContract(this.constants.ALIASES.registry_exchange, registryExchangeABI);
709
715
  this.setContract(this.constants.ALIASES.gauge_controller, gaugeControllerABI);
710
716
  this.setContract(this.constants.ALIASES.router, routerABI);
@@ -716,8 +722,19 @@ var Curve = /** @class */ (function () {
716
722
  }
717
723
  this.setContract(this.constants.ALIASES.stable_calc, StableCalcZapABI);
718
724
  this.setContract(this.constants.ALIASES.factory, factoryABI);
725
+ if (!(this.chainId !== 1313161554)) return [3 /*break*/, 21];
726
+ factoryContract = this.contracts[this.constants.ALIASES.factory].contract;
727
+ _p = this.constants.ALIASES;
728
+ return [4 /*yield*/, factoryContract.admin(this.constantOptions)];
729
+ case 20:
730
+ _p.factory_admin = (_q.sent()).toLowerCase();
731
+ this.setContract(this.constants.ALIASES.factory_admin, factoryAdminABI);
732
+ _q.label = 21;
733
+ case 21:
719
734
  this.setContract(this.constants.ALIASES.crvusd_factory, factoryABI);
720
735
  this.setContract(this.constants.ALIASES.crypto_factory, cryptoFactoryABI);
736
+ this.setContract(this.constants.ALIASES.anycall, anycallABI);
737
+ this.setContract(this.constants.ALIASES.voting_escrow_oracle, this.chainId === 1 ? votingEscrowOracleEthABI : votingEscrowOracleABI);
721
738
  return [2 /*return*/];
722
739
  }
723
740
  });
@@ -43,3 +43,10 @@ export declare const _getAllGauges: (() => Promise<IDict<{
43
43
  is_killed?: boolean;
44
44
  }>>>;
45
45
  export declare const _getHiddenPools: (() => Promise<IDict<string[]>>) & memoize.Memoized<() => Promise<IDict<string[]>>>;
46
+ export declare const _generateBoostingProof: ((block: number, address: string) => Promise<{
47
+ block_header_rlp: string;
48
+ proof_rlp: string;
49
+ }>) & memoize.Memoized<(block: number, address: string) => Promise<{
50
+ block_header_rlp: string;
51
+ proof_rlp: string;
52
+ }>>;
@@ -167,3 +167,19 @@ export var _getHiddenPools = memoize(function () { return __awaiter(void 0, void
167
167
  promise: true,
168
168
  maxAge: 5 * 60 * 1000, // 5m
169
169
  });
170
+ export var _generateBoostingProof = memoize(function (block, address) { return __awaiter(void 0, void 0, void 0, function () {
171
+ var url, response;
172
+ return __generator(this, function (_a) {
173
+ switch (_a.label) {
174
+ case 0:
175
+ url = "https://prices.curve.fi/v1/general/get_merkle_proof?block=".concat(block, "&account_address=").concat(address);
176
+ return [4 /*yield*/, axios.get(url, { validateStatus: function () { return true; } })];
177
+ case 1:
178
+ response = _a.sent();
179
+ return [2 /*return*/, { block_header_rlp: response.data.block_header_rlp, proof_rlp: response.data.proof_rlp }];
180
+ }
181
+ });
182
+ }); }, {
183
+ promise: true,
184
+ maxAge: 5 * 60 * 1000, // 5m
185
+ });
@@ -13,6 +13,7 @@ import MetaUSDGeistABI from "../constants/abis/factory-v2/MetaUSDGeist.json" ass
13
13
  import Plain2BasicABI from "../constants/abis/factory-v2/Plain2Basic.json" assert { type: 'json' };
14
14
  import Plain2BalancesABI from "../constants/abis/factory-v2/Plain2Balances.json" assert { type: 'json' };
15
15
  import Plain2ETHABI from "../constants/abis/factory-v2/Plain2ETH.json" assert { type: 'json' };
16
+ import Plain2ETHOracleABI from "../constants/abis/factory-v2/Plain2ETHOracle.json" assert { type: 'json' };
16
17
  import Plain2OptimizedABI from "../constants/abis/factory-v2/Plain2Optimized.json" assert { type: 'json' };
17
18
  import Plain3BasicABI from "../constants/abis/factory-v2/Plain3Basic.json" assert { type: 'json' };
18
19
  import Plain3BalancesABI from "../constants/abis/factory-v2/Plain3Balances.json" assert { type: 'json' };
@@ -51,8 +52,8 @@ export var implementationABIDictEthereum = lowerCaseKeys({
51
52
  "0x6326DEbBAa15bCFE603d831e7D75f4fc10d9B43E": Plain2ETHABI,
52
53
  "0x4A4d7868390EF5CaC51cDA262888f34bD3025C3F": Plain2OptimizedABI,
53
54
  "0xc629a01eC23AB04E1050500A3717A2a5c0701497": Plain2BasicABI,
55
+ "0x847ee1227A9900B73aEeb3a47fAc92c52FD54ed9": Plain2ETHOracleABI,
54
56
  "0x94b4DFd9Ba5865Cc931195c99A2db42F3fc5d45B": Plain2ETHABI,
55
- "0x847ee1227A9900B73aEeb3a47fAc92c52FD54ed9": Plain2ETHABI,
56
57
  "0x67fe41A94e779CcFa22cff02cc2957DC9C0e4286": Plain2BasicABI,
57
58
  "0x9B52F13DF69D79Ec5aAB6D1aCe3157d29B409cC3": Plain3BasicABI,
58
59
  "0x50b085f2e5958C4A87baf93A8AB79F6bec068494": Plain3BalancesABI,
@@ -127,8 +128,10 @@ export var implementationABIDictArbitrum = lowerCaseKeys({
127
128
  "0x8DEb66a4A40E370355bEe35f12E55Fe9c755d686": MetaFraxUSDABI,
128
129
  "0x3edE9b145F82e9e46C03f8A8F67B77aEE847b632": MetaFraxUSDBalancesABI,
129
130
  "0x54e8A25d0Ac0E4945b697C80b8372445FEA17A62": Plain2BasicABI,
131
+ "0x73Ec37618683C274D0bBf5f5726aA856B2BDAB81": Plain2BasicABI,
130
132
  "0xD68970e266cE1A015953897C7055a5E0bC657Af8": Plain2BalancesABI,
131
133
  "0x7DA64233Fefb352f8F501B357c018158ED8aA455": Plain2ETHABI,
134
+ "0x6F9fb833501f46CBE6f6A4b6Cf32C834E5A5e8C5": Plain2ETHOracleABI,
132
135
  "0x0100fBf414071977B19fC38e6fc7c32FE444F5C9": Plain2OptimizedABI,
133
136
  "0xe381C25de995d62b453aF8B931aAc84fcCaa7A62": Plain3BasicABI,
134
137
  "0xc379bA7b8e1c6C48D64e1cf9dD602C97c9fD0F40": Plain3BalancesABI,
@@ -145,8 +148,10 @@ export var implementationABIDictOptimism = lowerCaseKeys({
145
148
  "0xe8269B33E47761f552E1a3070119560d5fa8bBD6": MetaFraxUSDABI,
146
149
  "0x114C4042B11a2b16F58Fe1BFe847589a122F678a": MetaFraxUSDBalancesABI,
147
150
  "0xC2b1DF84112619D190193E48148000e3990Bf627": Plain2BasicABI,
151
+ "0x73Ec37618683C274D0bBf5f5726aA856B2BDAB81": Plain2BasicABI,
148
152
  "0x16a7DA911A4DD1d83F3fF066fE28F3C792C50d90": Plain2BalancesABI,
149
153
  "0x4f3E8F405CF5aFC05D68142F3783bDfE13811522": Plain2ETHABI,
154
+ "0x6F9fb833501f46CBE6f6A4b6Cf32C834E5A5e8C5": Plain2ETHOracleABI,
150
155
  "0x0f9cb53Ebe405d49A0bbdBD291A65Ff571bC83e1": Plain2OptimizedABI,
151
156
  "0x78D0fC2B9D5AE65512DB242e424a9c683F18c243": Plain3BasicABI,
152
157
  "0x35796DAc54f144DFBAD1441Ec7C32313A7c29F39": Plain3BalancesABI,
@@ -1,7 +1,10 @@
1
1
  import { ethers } from "ethers";
2
- export declare const deployStablePlainPoolEstimateGas: (name: string, symbol: string, coins: string[], A: number | string, fee: number | string, assetType: 0 | 1 | 2 | 3, implementationIdx: 0 | 1 | 2 | 3 | 4 | 5) => Promise<number>;
3
- export declare const deployStablePlainPool: (name: string, symbol: string, coins: string[], A: number | string, fee: number | string, assetType: 0 | 1 | 2 | 3, implementationIdx: 0 | 1 | 2 | 3 | 4 | 5) => Promise<ethers.ContractTransactionResponse>;
2
+ export declare const deployStablePlainPoolEstimateGas: (name: string, symbol: string, coins: string[], A: number | string, fee: number | string, assetType: 0 | 1 | 2 | 3, implementationIdx: 0 | 1 | 2 | 3 | 4 | 5, emaTime?: number, oracleAddress?: string, methodName?: string) => Promise<number>;
3
+ export declare const deployStablePlainPool: (name: string, symbol: string, coins: string[], A: number | string, fee: number | string, assetType: 0 | 1 | 2 | 3, implementationIdx: 0 | 1 | 2 | 3 | 4 | 5, emaTime?: number, oracleAddress?: string, methodName?: string) => Promise<ethers.ContractTransactionResponse>;
4
4
  export declare const getDeployedStablePlainPoolAddress: (tx: ethers.ContractTransactionResponse) => Promise<string>;
5
+ export declare const _setOracle: (poolAddress: string, oracleAddress: string, methodName: string, estimateGas: boolean) => Promise<ethers.ContractTransactionResponse | number>;
6
+ export declare const setOracleEstimateGas: (poolAddress: string, oracleAddress?: string, methodName?: string) => Promise<number>;
7
+ export declare const setOracle: (poolAddress: string, oracleAddress?: string, methodName?: string) => Promise<ethers.ContractTransactionResponse>;
5
8
  export declare const deployStableMetaPoolEstimateGas: (basePool: string, name: string, symbol: string, coin: string, A: number | string, fee: number | string, implementationIdx: 0 | 1) => Promise<number>;
6
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>;
7
10
  export declare const getDeployedStableMetaPoolAddress: (tx: ethers.ContractTransactionResponse) => Promise<string>;
@@ -45,16 +45,30 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
45
45
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
46
46
  }
47
47
  };
48
- import { Contract } from "ethers";
48
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
49
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
50
+ if (ar || !(i in from)) {
51
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
52
+ ar[i] = from[i];
53
+ }
54
+ }
55
+ return to.concat(ar || Array.prototype.slice.call(from));
56
+ };
57
+ import { ethers, Contract } from "ethers";
49
58
  import { curve } from "../curve.js";
50
- import { parseUnits, BN, mulBy1_3 } from "../utils.js";
59
+ import { getPool } from "../pools/index.js";
60
+ import { parseUnits, BN, mulBy1_3, getPoolIdBySwapAddress } from "../utils.js";
51
61
  import CurveLpTokenV5ABI from "../constants/abis/curve_lp_token_v5.json" assert { type: 'json' };
62
+ import Plain2ETHOracleABIABI from "../constants/abis/factory-v2/Plain2ETHOracle.json" assert { type: 'json' };
52
63
  // ------- STABLE PLAIN POOLS -------
53
64
  var _deployStablePlainPool = function (name, symbol, coins, A, fee, // %
54
- assetType, implementationIdx, estimateGas) { return __awaiter(void 0, void 0, void 0, function () {
55
- var _A, _fee, _coins, contract, gas, gasLimit;
56
- return __generator(this, function (_a) {
57
- switch (_a.label) {
65
+ assetType, // 0 = USD, 1 = ETH, 2 = BTC, 3 = Other
66
+ implementationIdx, emaTime, // seconds
67
+ oracleAddress, methodName, estimateGas) { return __awaiter(void 0, void 0, void 0, function () {
68
+ var _A, _fee, _coins, useProxy, setOracle, contractAddress, contract, args, methodId, methodToCall, gas, gasLimit;
69
+ var _a;
70
+ return __generator(this, function (_b) {
71
+ switch (_b.label) {
58
72
  case 0:
59
73
  if (name.length > 32)
60
74
  throw Error("Max name length = 32");
@@ -76,42 +90,71 @@ assetType, implementationIdx, estimateGas) { return __awaiter(void 0, void 0, vo
76
90
  if (![0, 1, 2, 3, 4, 5].includes(implementationIdx))
77
91
  throw Error("Invalid implementationIdx. Must be one 0, 1, 2, 3, 4 or 5");
78
92
  }
93
+ if (emaTime <= 0)
94
+ throw Error("emaTime must be > 0. Passed emaTime = ".concat(emaTime));
79
95
  _A = parseUnits(A, 0);
80
96
  _fee = parseUnits(fee, 8);
81
97
  _coins = coins.concat(Array(4 - coins.length).fill(curve.constants.ZERO_ADDRESS));
82
- contract = curve.contracts[curve.constants.ALIASES.factory].contract;
83
- return [4 /*yield*/, contract.deploy_plain_pool.estimateGas(name, symbol, _coins, _A, _fee, assetType, implementationIdx, curve.constantOptions)];
98
+ useProxy = (curve.chainId === 1 && coins.length === 2 && implementationIdx === 4 && emaTime !== 600) ||
99
+ (curve.chainId === 1 && coins.length === 2 && implementationIdx === 5 && emaTime !== 600) ||
100
+ ((curve.chainId === 42161 || curve.chainId == 10) && coins.length === 2 && implementationIdx === 0 && emaTime !== 600);
101
+ setOracle = ((curve.chainId === 42161 || curve.chainId == 10) && coins.length === 2 && implementationIdx === 2);
102
+ contractAddress = (useProxy || setOracle) ? curve.constants.ALIASES.factory_admin : curve.constants.ALIASES.factory;
103
+ contract = curve.contracts[contractAddress].contract;
104
+ args = [name, symbol, _coins, _A, _fee, assetType, implementationIdx];
105
+ if (useProxy || setOracle)
106
+ args.push(curve.parseUnits((emaTime / Math.log(2)).toFixed(0), 0));
107
+ if (setOracle) {
108
+ methodId = methodName === "0x00000000" ? "0x00000000" : ethers.id(methodName).substring(0, 10);
109
+ args.push(methodId, oracleAddress);
110
+ }
111
+ methodToCall = setOracle ? "deploy_plain_pool_and_set_oracle" : "deploy_plain_pool";
112
+ return [4 /*yield*/, (_a = contract[methodToCall]).estimateGas.apply(_a, __spreadArray(__spreadArray([], args, false), [curve.constantOptions], false))];
84
113
  case 1:
85
- gas = _a.sent();
114
+ gas = _b.sent();
86
115
  if (estimateGas)
87
116
  return [2 /*return*/, Number(gas)];
88
117
  gasLimit = mulBy1_3(gas);
89
118
  return [4 /*yield*/, curve.updateFeeData()];
90
119
  case 2:
91
- _a.sent();
92
- return [4 /*yield*/, contract.deploy_plain_pool(name, symbol, _coins, _A, _fee, assetType, implementationIdx, __assign(__assign({}, curve.options), { gasLimit: gasLimit }))];
93
- case 3: return [2 /*return*/, _a.sent()];
120
+ _b.sent();
121
+ return [4 /*yield*/, contract[methodToCall].apply(contract, __spreadArray(__spreadArray([], args, false), [__assign(__assign({}, curve.options), { gasLimit: gasLimit })], false))];
122
+ case 3: return [2 /*return*/, _b.sent()];
94
123
  }
95
124
  });
96
125
  }); };
97
126
  export var deployStablePlainPoolEstimateGas = function (name, symbol, coins, A, fee, // %
98
- assetType, implementationIdx) { return __awaiter(void 0, void 0, void 0, function () {
99
- return __generator(this, function (_a) {
100
- switch (_a.label) {
101
- case 0: return [4 /*yield*/, _deployStablePlainPool(name, symbol, coins, A, fee, assetType, implementationIdx, true)];
102
- case 1: return [2 /*return*/, _a.sent()];
103
- }
127
+ assetType, // 0 = USD, 1 = ETH, 2 = BTC, 3 = Other
128
+ implementationIdx, emaTime, // seconds
129
+ oracleAddress, methodName) {
130
+ if (emaTime === void 0) { emaTime = 600; }
131
+ if (oracleAddress === void 0) { oracleAddress = curve.constants.ZERO_ADDRESS; }
132
+ if (methodName === void 0) { methodName = "0x00000000"; }
133
+ return __awaiter(void 0, void 0, void 0, function () {
134
+ return __generator(this, function (_a) {
135
+ switch (_a.label) {
136
+ case 0: return [4 /*yield*/, _deployStablePlainPool(name, symbol, coins, A, fee, assetType, implementationIdx, emaTime, oracleAddress, methodName, true)];
137
+ case 1: return [2 /*return*/, _a.sent()];
138
+ }
139
+ });
104
140
  });
105
- }); };
141
+ };
106
142
  export var deployStablePlainPool = function (name, symbol, coins, A, fee, // %
107
- assetType, implementationIdx) { return __awaiter(void 0, void 0, void 0, function () {
108
- return __generator(this, function (_a) {
109
- switch (_a.label) {
110
- case 0: return [4 /*yield*/, _deployStablePlainPool(name, symbol, coins, A, fee, assetType, implementationIdx, false)];
111
- case 1: return [2 /*return*/, _a.sent()];
112
- }
143
+ assetType, // 0 = USD, 1 = ETH, 2 = BTC, 3 = Other
144
+ implementationIdx, emaTime, // seconds
145
+ oracleAddress, methodName) {
146
+ if (emaTime === void 0) { emaTime = 600; }
147
+ if (oracleAddress === void 0) { oracleAddress = curve.constants.ZERO_ADDRESS; }
148
+ if (methodName === void 0) { methodName = "0x00000000"; }
149
+ return __awaiter(void 0, void 0, void 0, function () {
150
+ return __generator(this, function (_a) {
151
+ switch (_a.label) {
152
+ case 0: return [4 /*yield*/, _deployStablePlainPool(name, symbol, coins, A, fee, assetType, implementationIdx, emaTime, oracleAddress, methodName, false)];
153
+ case 1: return [2 /*return*/, _a.sent()];
154
+ }
155
+ });
113
156
  });
114
- }); };
157
+ };
115
158
  export var getDeployedStablePlainPoolAddress = function (tx) { return __awaiter(void 0, void 0, void 0, function () {
116
159
  var txInfo;
117
160
  return __generator(this, function (_a) {
@@ -125,6 +168,52 @@ export var getDeployedStablePlainPoolAddress = function (tx) { return __awaiter(
125
168
  }
126
169
  });
127
170
  }); };
171
+ export var _setOracle = function (poolAddress, oracleAddress, methodName, estimateGas) { return __awaiter(void 0, void 0, void 0, function () {
172
+ var poolContract, methodId, _gas, gasLimit;
173
+ return __generator(this, function (_a) {
174
+ switch (_a.label) {
175
+ case 0:
176
+ curve.setContract(poolAddress, Plain2ETHOracleABIABI);
177
+ poolContract = curve.contracts[poolAddress].contract;
178
+ methodId = methodName === "0x00000000" ? "0x00000000" : ethers.id(methodName).substring(0, 10);
179
+ return [4 /*yield*/, poolContract.set_oracle.estimateGas(methodId, oracleAddress, curve.constantOptions)];
180
+ case 1:
181
+ _gas = _a.sent();
182
+ if (estimateGas)
183
+ return [2 /*return*/, Number(_gas)];
184
+ gasLimit = mulBy1_3(_gas);
185
+ return [4 /*yield*/, curve.updateFeeData()];
186
+ case 2:
187
+ _a.sent();
188
+ return [4 /*yield*/, poolContract.set_oracle(methodId, oracleAddress, __assign(__assign({}, curve.options), { gasLimit: gasLimit }))];
189
+ case 3: return [2 /*return*/, _a.sent()];
190
+ }
191
+ });
192
+ }); };
193
+ export var setOracleEstimateGas = function (poolAddress, oracleAddress, methodName) {
194
+ if (oracleAddress === void 0) { oracleAddress = curve.constants.ZERO_ADDRESS; }
195
+ if (methodName === void 0) { methodName = "0x00000000"; }
196
+ return __awaiter(void 0, void 0, void 0, function () {
197
+ return __generator(this, function (_a) {
198
+ switch (_a.label) {
199
+ case 0: return [4 /*yield*/, _setOracle(poolAddress, oracleAddress, methodName, true)];
200
+ case 1: return [2 /*return*/, _a.sent()];
201
+ }
202
+ });
203
+ });
204
+ };
205
+ export var setOracle = function (poolAddress, oracleAddress, methodName) {
206
+ if (oracleAddress === void 0) { oracleAddress = curve.constants.ZERO_ADDRESS; }
207
+ if (methodName === void 0) { methodName = "0x00000000"; }
208
+ return __awaiter(void 0, void 0, void 0, function () {
209
+ return __generator(this, function (_a) {
210
+ switch (_a.label) {
211
+ case 0: return [4 /*yield*/, _setOracle(poolAddress, oracleAddress, methodName, false)];
212
+ case 1: return [2 /*return*/, _a.sent()];
213
+ }
214
+ });
215
+ });
216
+ };
128
217
  // ------- STABLE META POOLS -------
129
218
  var _deployStableMetaPool = function (basePool, name, symbol, coin, A, fee, // %
130
219
  implementationIdx, estimateGas) { return __awaiter(void 0, void 0, void 0, function () {
@@ -178,7 +267,7 @@ implementationIdx) { return __awaiter(void 0, void 0, void 0, function () {
178
267
  });
179
268
  }); };
180
269
  export var getDeployedStableMetaPoolAddress = function (tx) { return __awaiter(void 0, void 0, void 0, function () {
181
- var txInfo;
270
+ var txInfo, i, basePoolId, basePool;
182
271
  return __generator(this, function (_a) {
183
272
  switch (_a.label) {
184
273
  case 0: return [4 /*yield*/, tx.wait()];
@@ -186,7 +275,14 @@ export var getDeployedStableMetaPoolAddress = function (tx) { return __awaiter(v
186
275
  txInfo = _a.sent();
187
276
  if (!txInfo)
188
277
  throw Error("Can't get tx info");
189
- return [2 /*return*/, txInfo.logs[3].address.toLowerCase()];
278
+ for (i = txInfo.logs.length - 1; i > -1; i--) {
279
+ if ("args" in txInfo.logs[i]) {
280
+ basePoolId = getPoolIdBySwapAddress(txInfo.logs[i].args[1]);
281
+ basePool = getPool(basePoolId);
282
+ return [2 /*return*/, txInfo.logs[basePool.underlyingCoins.length].address.toLowerCase()];
283
+ }
284
+ }
285
+ throw Error("Can't get deployed metapool address");
190
286
  }
191
287
  });
192
288
  }); };
@@ -350,7 +446,7 @@ export var getDeployedGaugeAddress = function (tx) { return __awaiter(void 0, vo
350
446
  if (!txInfo)
351
447
  throw Error("Can't get tx info");
352
448
  // @ts-ignore
353
- return [2 /*return*/, txInfo.events[0].args[txInfo.events[0].args.length - 1].toLowerCase()];
449
+ return [2 /*return*/, txInfo.logs[0].args[txInfo.logs[0].args.length - 1].toLowerCase()];
354
450
  }
355
451
  });
356
452
  }); };
package/lib/index.d.ts CHANGED
@@ -58,7 +58,8 @@ declare const curve: {
58
58
  fetchPools: (useApi?: boolean) => Promise<void>;
59
59
  fetchNewPools: () => Promise<string[]>;
60
60
  getPoolList: () => string[];
61
- deployPlainPool: (name: string, symbol: string, coins: string[], A: string | number, fee: string | number, assetType: 0 | 1 | 2 | 3, implementationIdx: 0 | 1 | 2 | 3 | 4 | 5) => Promise<ethers.ContractTransactionResponse>;
61
+ deployPlainPool: (name: string, symbol: string, coins: string[], A: string | number, fee: string | number, assetType: 0 | 1 | 2 | 3, implementationIdx: 0 | 1 | 2 | 3 | 4 | 5, emaTime?: number, oracleAddress?: string, methodName?: string) => Promise<ethers.ContractTransactionResponse>;
62
+ setOracle: (poolAddress: string, oracleAddress?: string, methodName?: string) => Promise<ethers.ContractTransactionResponse>;
62
63
  deployMetaPool: (basePool: string, name: string, symbol: string, coin: string, A: string | number, fee: string | number, implementationIdx: 0 | 1) => Promise<ethers.ContractTransactionResponse>;
63
64
  deployGauge: (poolAddress: string) => Promise<ethers.ContractTransactionResponse>;
64
65
  getDeployedPlainPoolAddress: (tx: ethers.ContractTransactionResponse) => Promise<string>;
@@ -66,7 +67,8 @@ declare const curve: {
66
67
  getDeployedGaugeAddress: (tx: ethers.ContractTransactionResponse) => Promise<string>;
67
68
  fetchRecentlyDeployedPool: (poolAddress: string) => Promise<string>;
68
69
  estimateGas: {
69
- deployPlainPool: (name: string, symbol: string, coins: string[], A: string | number, fee: string | number, assetType: 0 | 1 | 2 | 3, implementationIdx: 0 | 1 | 2 | 3 | 4 | 5) => Promise<number>;
70
+ deployPlainPool: (name: string, symbol: string, coins: string[], A: string | number, fee: string | number, assetType: 0 | 1 | 2 | 3, implementationIdx: 0 | 1 | 2 | 3 | 4 | 5, emaTime?: number, oracleAddress?: string, methodName?: string) => Promise<number>;
71
+ setOracle: (poolAddress: string, oracleAddress?: string, methodName?: string) => Promise<number>;
70
72
  deployMetaPool: (basePool: string, name: string, symbol: string, coin: string, A: string | number, fee: string | number, implementationIdx: 0 | 1) => Promise<number>;
71
73
  deployGauge: (poolAddress: string) => Promise<number>;
72
74
  };
@@ -121,6 +123,19 @@ declare const curve: {
121
123
  withdrawLockedCrv: () => Promise<number>;
122
124
  claimFees: (address?: string) => Promise<number>;
123
125
  };
126
+ sidechain: {
127
+ lastBlockhash: () => Promise<number>;
128
+ checkBlockhash: (block: number) => Promise<boolean>;
129
+ getAnycallBalance: () => Promise<string>;
130
+ topUpAnycall: (amount?: string | number) => Promise<string>;
131
+ sendBlockhash: (block: number, chainId: import("./interfaces.js").IChainId) => Promise<string>;
132
+ submitProof: (block: number, address?: string) => Promise<string>;
133
+ estimateGas: {
134
+ topUpAnycall: (amount?: string | number) => Promise<number>;
135
+ sendBlockhash: (block: number, chainId: import("./interfaces.js").IChainId) => Promise<number>;
136
+ submitProof: (block: number, address?: string) => Promise<number>;
137
+ };
138
+ };
124
139
  };
125
140
  router: {
126
141
  getBestRouteAndOutput: (inputCoin: string, outputCoin: string, amount: string | number) => Promise<{
package/lib/index.js CHANGED
@@ -38,9 +38,9 @@ import { PoolTemplate, getPool } from "./pools/index.js";
38
38
  import { getUserPoolListByLiquidity, getUserPoolListByClaimable, getUserPoolList, getUserLiquidityUSD, getUserClaimable, } from "./pools/utils.js";
39
39
  import { getBestRouteAndOutput, swapExpected, swapPriceImpact, swapIsApproved, swapApproveEstimateGas, swapApprove, swapEstimateGas, swap, getSwappedAmount, } from "./router.js";
40
40
  import { curve as _curve } from "./curve.js";
41
- import { getCrv, getLockedAmountAndUnlockTime, getVeCrv, getVeCrvPct, calcUnlockTime, createLockEstimateGas, createLock, isApproved, approveEstimateGas, approve, increaseAmountEstimateGas, increaseAmount, increaseUnlockTimeEstimateGas, increaseUnlockTime, withdrawLockedCrvEstimateGas, withdrawLockedCrv, claimableFees, claimFeesEstimateGas, claimFees, } from "./boosting.js";
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, deployStableMetaPool, deployStableMetaPoolEstimateGas, deployCryptoPool, deployCryptoPoolEstimateGas, deployGauge, deployGaugeEstimateGas, getDeployedStablePlainPoolAddress, getDeployedStableMetaPoolAddress, getDeployedCryptoPoolAddress, getDeployedGaugeAddress, } from './factory/deploy.js';
43
+ import { deployStablePlainPool, deployStablePlainPoolEstimateGas, setOracle, setOracleEstimateGas, deployStableMetaPool, deployStableMetaPoolEstimateGas, deployCryptoPool, deployCryptoPoolEstimateGas, deployGauge, deployGaugeEstimateGas, getDeployedStablePlainPoolAddress, getDeployedStableMetaPoolAddress, getDeployedCryptoPoolAddress, 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 () {
@@ -88,6 +88,7 @@ var curve = {
88
88
  fetchNewPools: _curve.fetchNewFactoryPools,
89
89
  getPoolList: _curve.getFactoryPoolList,
90
90
  deployPlainPool: deployStablePlainPool,
91
+ setOracle: setOracle,
91
92
  deployMetaPool: deployStableMetaPool,
92
93
  deployGauge: function (poolAddress) { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
93
94
  return [2 /*return*/, deployGauge(poolAddress, false)];
@@ -98,6 +99,7 @@ var curve = {
98
99
  fetchRecentlyDeployedPool: _curve.fetchRecentlyDeployedFactoryPool,
99
100
  estimateGas: {
100
101
  deployPlainPool: deployStablePlainPoolEstimateGas,
102
+ setOracle: setOracleEstimateGas,
101
103
  deployMetaPool: deployStableMetaPoolEstimateGas,
102
104
  deployGauge: function (poolAddress) { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
103
105
  return [2 /*return*/, deployGaugeEstimateGas(poolAddress, false)];
@@ -152,6 +154,19 @@ var curve = {
152
154
  withdrawLockedCrv: withdrawLockedCrvEstimateGas,
153
155
  claimFees: claimFeesEstimateGas,
154
156
  },
157
+ sidechain: {
158
+ lastBlockhash: lastBlockhash,
159
+ checkBlockhash: checkBlockhash,
160
+ getAnycallBalance: getAnycallBalance,
161
+ topUpAnycall: topUpAnycall,
162
+ sendBlockhash: sendBlockhash,
163
+ submitProof: submitProof,
164
+ estimateGas: {
165
+ topUpAnycall: topUpAnycallEstimateGas,
166
+ sendBlockhash: sendBlockhashEstimateGas,
167
+ submitProof: submitProofEstimateGas,
168
+ },
169
+ },
155
170
  },
156
171
  router: {
157
172
  getBestRouteAndOutput: getBestRouteAndOutput,
@@ -597,8 +597,6 @@ var PoolTemplate = /** @class */ (function () {
597
597
  return __generator(this, function (_d) {
598
598
  switch (_d.label) {
599
599
  case 0:
600
- if (curve.chainId !== 1)
601
- throw Error("Boosting is available only on Ethereum network");
602
600
  if (this.gauge === curve.constants.ZERO_ADDRESS)
603
601
  throw Error("".concat(this.name, " doesn't have gauge"));
604
602
  address = address || curve.signerAddress;
@@ -612,6 +610,10 @@ var PoolTemplate = /** @class */ (function () {
612
610
  case 1:
613
611
  _c = (_d.sent()).map(function (value) { return toBN(value); }), workingBalanceBN = _c[0], balanceBN = _c[1];
614
612
  boostBN = workingBalanceBN.div(0.4).div(balanceBN);
613
+ if (boostBN.lt(1))
614
+ return [2 /*return*/, '1.0'];
615
+ if (boostBN.gt(2.5))
616
+ return [2 /*return*/, '2.5'];
615
617
  return [2 /*return*/, boostBN.toFixed(4).replace(/([0-9])0+$/, '$1')];
616
618
  }
617
619
  });
@@ -654,8 +656,6 @@ var PoolTemplate = /** @class */ (function () {
654
656
  return __generator(this, function (_f) {
655
657
  switch (_f.label) {
656
658
  case 0:
657
- if (curve.chainId !== 1)
658
- throw Error("Boosting is available only on Ethereum network");
659
659
  if (this.gauge === curve.constants.ZERO_ADDRESS)
660
660
  throw Error("".concat(this.name, " doesn't have gauge"));
661
661
  if (addresses.length == 1 && Array.isArray(addresses[0]))
package/lib/utils.d.ts CHANGED
@@ -25,7 +25,7 @@ export declare const hasAllowance: (coins: string[], amounts: (number | string)[
25
25
  export declare const _ensureAllowance: (coins: string[], amounts: bigint[], spender: string, isMax?: boolean) => Promise<string[]>;
26
26
  export declare const ensureAllowanceEstimateGas: (coins: string[], amounts: (number | string)[], spender: string, isMax?: boolean) => Promise<number>;
27
27
  export declare const ensureAllowance: (coins: string[], amounts: (number | string)[], spender: string, isMax?: boolean) => Promise<string[]>;
28
- export declare const getPoolNameBySwapAddress: (swapAddress: string) => string;
28
+ export declare const getPoolIdBySwapAddress: (swapAddress: string) => string;
29
29
  export declare const _getUsdPricesFromApi: () => Promise<IDict<number>>;
30
30
  export declare const _getCrvApyFromApi: () => Promise<IDict<[number, number]>>;
31
31
  export declare const _getRewardsFromApi: () => Promise<IDict<IRewardFromApi[]>>;
package/lib/utils.js CHANGED
@@ -390,7 +390,7 @@ export var ensureAllowance = function (coins, amounts, spender, isMax) {
390
390
  });
391
391
  });
392
392
  };
393
- export var getPoolNameBySwapAddress = function (swapAddress) {
393
+ export var getPoolIdBySwapAddress = function (swapAddress) {
394
394
  var poolsData = __assign(__assign(__assign(__assign({}, curve.constants.POOLS_DATA), curve.constants.FACTORY_POOLS_DATA), curve.constants.CRVUSD_FACTORY_POOLS_DATA), curve.constants.CRYPTO_FACTORY_POOLS_DATA);
395
395
  return Object.entries(poolsData).filter(function (_a) {
396
396
  var _ = _a[0], poolData = _a[1];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@curvefi/api",
3
- "version": "2.36.1",
3
+ "version": "2.38.0",
4
4
  "description": "JavaScript library for curve.fi",
5
5
  "main": "lib/index.js",
6
6
  "author": "Macket",