@curvefi/api 2.46.7 → 2.47.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
@@ -71,14 +71,13 @@ import anycallABI from './constants/abis/anycall.json' assert { type: 'json' };
71
71
  import votingEscrowOracleABI from './constants/abis/voting_escrow_oracle.json' assert { type: 'json' };
72
72
  import votingEscrowOracleEthABI from './constants/abis/voting_escrow_oracle_eth.json' assert { type: 'json' };
73
73
  import feeDistributorABI from './constants/abis/fee_distributor.json' assert { type: 'json' };
74
- import addressProviderABI from './constants/abis/address_provider.json' assert { type: 'json' };
75
74
  import gaugeControllerABI from './constants/abis/gaugecontroller.json' assert { type: 'json' };
76
- import routerABI from './constants/abis/router.json' assert { type: 'json' };
77
75
  import depositAndStakeABI from './constants/abis/deposit_and_stake.json' assert { type: 'json' };
78
76
  import cryptoCalcZapABI from './constants/abis/crypto_calc.json' assert { type: 'json' };
79
77
  import depositAndStake6CoinsABI from './constants/abis/deposit_and_stake_6coins.json' assert { type: 'json' };
80
78
  import StableCalcZapABI from './constants/abis/stable_calc.json' assert { type: 'json' };
81
- import registryExchangeABI from './constants/abis/registry_exchange.json' assert { type: 'json' };
79
+ import routerABI from './constants/abis/router.json' assert { type: 'json' };
80
+ import routerPolygonABI from './constants/abis/routerPolygon.json' assert { type: 'json' };
82
81
  import streamerABI from './constants/abis/streamer.json' assert { type: 'json' };
83
82
  import factoryABI from './constants/abis/factory.json' assert { type: 'json' };
84
83
  import factoryEywaABI from './constants/abis/factory-eywa.json' assert { type: 'json' };
@@ -702,9 +701,9 @@ var Curve = /** @class */ (function () {
702
701
  var _a;
703
702
  if (options === void 0) { options = {}; }
704
703
  return __awaiter(this, void 0, void 0, function () {
705
- var jsonRpcApiProviderOptions, _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, _gaugeFactoryABI, addressProviderContract, _o, factoryContract, _p;
706
- return __generator(this, function (_q) {
707
- switch (_q.label) {
704
+ var jsonRpcApiProviderOptions, _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, _gaugeFactoryABI, factoryContract, _o;
705
+ return __generator(this, function (_p) {
706
+ switch (_p.label) {
708
707
  case 0:
709
708
  // @ts-ignore
710
709
  this.provider = null;
@@ -754,16 +753,16 @@ var Curve = /** @class */ (function () {
754
753
  return [3 /*break*/, 5];
755
754
  case 1:
756
755
  if (!!((_a = providerSettings.url) === null || _a === void 0 ? void 0 : _a.startsWith("https://rpc.gnosischain.com"))) return [3 /*break*/, 5];
757
- _q.label = 2;
756
+ _p.label = 2;
758
757
  case 2:
759
- _q.trys.push([2, 4, , 5]);
758
+ _p.trys.push([2, 4, , 5]);
760
759
  _b = this;
761
760
  return [4 /*yield*/, this.provider.getSigner()];
762
761
  case 3:
763
- _b.signer = _q.sent();
762
+ _b.signer = _p.sent();
764
763
  return [3 /*break*/, 5];
765
764
  case 4:
766
- e_1 = _q.sent();
765
+ e_1 = _p.sent();
767
766
  this.signer = null;
768
767
  return [3 /*break*/, 5];
769
768
  case 5: return [3 /*break*/, 9];
@@ -774,7 +773,7 @@ var Curve = /** @class */ (function () {
774
773
  _c = this;
775
774
  return [4 /*yield*/, this.provider.getSigner()];
776
775
  case 7:
777
- _c.signer = _q.sent();
776
+ _c.signer = _p.sent();
778
777
  return [3 /*break*/, 9];
779
778
  case 8:
780
779
  if (providerType.toLowerCase() === 'Infura'.toLowerCase()) {
@@ -791,10 +790,10 @@ var Curve = /** @class */ (function () {
791
790
  else {
792
791
  throw Error('Wrong providerType');
793
792
  }
794
- _q.label = 9;
793
+ _p.label = 9;
795
794
  case 9: return [4 /*yield*/, this.provider.getNetwork()];
796
795
  case 10:
797
- network = _q.sent();
796
+ network = _p.sent();
798
797
  console.log("CURVE-JS IS CONNECTED TO NETWORK:", { name: network.name.toUpperCase(), chainId: Number(network.chainId) });
799
798
  this.chainId = Number(network.chainId) === 133 || Number(network.chainId) === 31337 ? 1 : Number(network.chainId);
800
799
  this.constants.NATIVE_TOKEN = NATIVE_TOKENS[this.chainId];
@@ -821,30 +820,30 @@ var Curve = /** @class */ (function () {
821
820
  customAbiTokens = __spreadArray(__spreadArray(__spreadArray(__spreadArray([], cTokens, true), yTokens, true), ycTokens, true), aTokens, true);
822
821
  return [4 /*yield*/, _killGauges(this.constants.POOLS_DATA)];
823
822
  case 11:
824
- _q.sent();
823
+ _p.sent();
825
824
  this.multicallProvider = new MulticallProvider(this.chainId, this.provider);
826
825
  if (!this.signer) return [3 /*break*/, 16];
827
- _q.label = 12;
826
+ _p.label = 12;
828
827
  case 12:
829
- _q.trys.push([12, 14, , 15]);
828
+ _p.trys.push([12, 14, , 15]);
830
829
  _e = this;
831
830
  return [4 /*yield*/, this.signer.getAddress()];
832
831
  case 13:
833
- _e.signerAddress = _q.sent();
832
+ _e.signerAddress = _p.sent();
834
833
  return [3 /*break*/, 15];
835
834
  case 14:
836
- err_1 = _q.sent();
835
+ err_1 = _p.sent();
837
836
  this.signer = null;
838
837
  return [3 /*break*/, 15];
839
838
  case 15: return [3 /*break*/, 17];
840
839
  case 16:
841
840
  this.signerAddress = '';
842
- _q.label = 17;
841
+ _p.label = 17;
843
842
  case 17:
844
843
  this.feeData = { gasPrice: options.gasPrice, maxFeePerGas: options.maxFeePerGas, maxPriorityFeePerGas: options.maxPriorityFeePerGas };
845
844
  return [4 /*yield*/, this.updateFeeData()];
846
845
  case 18:
847
- _q.sent();
846
+ _p.sent();
848
847
  for (_i = 0, _f = Object.values(__assign(__assign({}, this.constants.POOLS_DATA), this.constants.LLAMMAS_DATA)); _i < _f.length; _i++) {
849
848
  pool = _f[_i];
850
849
  this.setContract(pool.swap_address, pool.swap_abi);
@@ -899,18 +898,13 @@ var Curve = /** @class */ (function () {
899
898
  }
900
899
  this.setContract(this.constants.ALIASES.voting_escrow, votingEscrowABI);
901
900
  this.setContract(this.constants.ALIASES.fee_distributor, feeDistributorABI);
902
- this.setContract(this.constants.ALIASES.address_provider, addressProviderABI);
903
- if (!(this.chainId !== 324 && this.chainId !== 8453)) return [3 /*break*/, 20];
904
- addressProviderContract = this.contracts[this.constants.ALIASES.address_provider].contract;
905
- _o = this.constants.ALIASES;
906
- return [4 /*yield*/, addressProviderContract.get_address(2, this.constantOptions)];
907
- case 19:
908
- _o.registry_exchange = (_q.sent()).toLowerCase();
909
- this.setContract(this.constants.ALIASES.registry_exchange, registryExchangeABI);
910
- _q.label = 20;
911
- case 20:
912
901
  this.setContract(this.constants.ALIASES.gauge_controller, gaugeControllerABI);
913
- this.setContract(this.constants.ALIASES.router, routerABI);
902
+ if (this.chainId == 137) {
903
+ this.setContract(this.constants.ALIASES.router, routerPolygonABI);
904
+ }
905
+ else {
906
+ this.setContract(this.constants.ALIASES.router, routerABI);
907
+ }
914
908
  if (this.chainId === 137) {
915
909
  this.setContract(this.constants.ALIASES.deposit_and_stake, depositAndStake6CoinsABI);
916
910
  }
@@ -920,15 +914,15 @@ var Curve = /** @class */ (function () {
920
914
  this.setContract(this.constants.ALIASES.crypto_calc, cryptoCalcZapABI);
921
915
  this.setContract(this.constants.ALIASES.stable_calc, StableCalcZapABI);
922
916
  this.setContract(this.constants.ALIASES.factory, factoryABI);
923
- if (!(this.chainId !== 1313161554)) return [3 /*break*/, 22];
917
+ if (!(this.chainId !== 1313161554)) return [3 /*break*/, 20];
924
918
  factoryContract = this.contracts[this.constants.ALIASES.factory].contract;
925
- _p = this.constants.ALIASES;
919
+ _o = this.constants.ALIASES;
926
920
  return [4 /*yield*/, factoryContract.admin(this.constantOptions)];
927
- case 21:
928
- _p.factory_admin = (_q.sent()).toLowerCase();
921
+ case 19:
922
+ _o.factory_admin = (_p.sent()).toLowerCase();
929
923
  this.setContract(this.constants.ALIASES.factory_admin, factoryAdminABI);
930
- _q.label = 22;
931
- case 22:
924
+ _p.label = 20;
925
+ case 20:
932
926
  this.setContract(this.constants.ALIASES.crvusd_factory, factoryABI);
933
927
  this.setContract(this.constants.ALIASES.eywa_factory, factoryEywaABI);
934
928
  this.setContract(this.constants.ALIASES.crypto_factory, cryptoFactoryABI);
package/lib/index.d.ts CHANGED
@@ -55,6 +55,8 @@ declare const curve: {
55
55
  cryptoVolume: number;
56
56
  cryptoShare: number;
57
57
  }>;
58
+ hasDepositAndStake: () => boolean;
59
+ hasRouter: () => boolean;
58
60
  factory: {
59
61
  fetchPools: (useApi?: boolean) => Promise<void>;
60
62
  fetchNewPools: () => Promise<string[]>;
@@ -176,7 +178,17 @@ declare const curve: {
176
178
  route: import("./interfaces.js").IRoute;
177
179
  output: string;
178
180
  }>;
181
+ getArgs: (route: import("./interfaces.js").IRoute) => {
182
+ _route: string[];
183
+ _swapParams: number[][];
184
+ _pools: string[];
185
+ _basePools: string[];
186
+ _baseTokens: string[];
187
+ _secondBasePools: string[];
188
+ _secondBaseTokens: string[];
189
+ };
179
190
  expected: (inputCoin: string, outputCoin: string, amount: string | number) => Promise<string>;
191
+ required: (route: import("./interfaces.js").IRoute, outAmount: string | number) => Promise<string>;
180
192
  priceImpact: (inputCoin: string, outputCoin: string, amount: string | number) => Promise<number>;
181
193
  isApproved: (inputCoin: string, amount: string | number) => Promise<boolean>;
182
194
  approve: (inputCoin: string, amount: string | number) => Promise<string[]>;
package/lib/index.js CHANGED
@@ -36,10 +36,10 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
36
36
  };
37
37
  import { PoolTemplate, getPool } from "./pools/index.js";
38
38
  import { getUserPoolListByLiquidity, getUserPoolListByClaimable, getUserPoolList, getUserLiquidityUSD, getUserClaimable, } from "./pools/utils.js";
39
- import { getBestRouteAndOutput, swapExpected, swapPriceImpact, swapIsApproved, swapApproveEstimateGas, swapApprove, swapEstimateGas, swap, getSwappedAmount, } from "./router.js";
39
+ import { getBestRouteAndOutput, getArgs, swapExpected, swapRequired, swapPriceImpact, swapIsApproved, swapApproveEstimateGas, swapApprove, swapEstimateGas, swap, getSwappedAmount, } from "./router.js";
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, lastEthBlock, getAnycallBalance, topUpAnycall, topUpAnycallEstimateGas, lastBlockSent, blockToSend, sendBlockhash, sendBlockhashEstimateGas, submitProof, submitProofEstimateGas, } from "./boosting.js";
42
- import { getBalances, getAllowance, hasAllowance, ensureAllowanceEstimateGas, ensureAllowance, getUsdRate, getTVL, getCoinsData, getVolume, } from "./utils.js";
42
+ import { getBalances, getAllowance, hasAllowance, ensureAllowanceEstimateGas, ensureAllowance, getUsdRate, getTVL, getCoinsData, getVolume, hasDepositAndStake, hasRouter, } from "./utils.js";
43
43
  import { deployStablePlainPool, deployStablePlainPoolEstimateGas, getDeployedStablePlainPoolAddress, setOracle, setOracleEstimateGas, deployStableMetaPool, deployStableMetaPoolEstimateGas, getDeployedStableMetaPoolAddress, deployCryptoPool, deployCryptoPoolEstimateGas, getDeployedCryptoPoolAddress, deployTricryptoPool, deployTricryptoPoolEstimateGas, getDeployedTricryptoPoolAddress, deployGauge, deployGaugeEstimateGas, getDeployedGaugeAddress, deployGaugeSidechain, deployGaugeSidechainEstimateGas, deployGaugeMirror, deployGaugeMirrorEstimateGas, } from './factory/deploy.js';
44
44
  function init(providerType, providerSettings, options) {
45
45
  if (options === void 0) { options = {}; }
@@ -83,6 +83,8 @@ var curve = {
83
83
  ensureAllowance: ensureAllowance,
84
84
  getCoinsData: getCoinsData,
85
85
  getVolume: getVolume,
86
+ hasDepositAndStake: hasDepositAndStake,
87
+ hasRouter: hasRouter,
86
88
  factory: {
87
89
  fetchPools: _curve.fetchFactoryPools,
88
90
  fetchNewPools: _curve.fetchNewFactoryPools,
@@ -231,7 +233,9 @@ var curve = {
231
233
  },
232
234
  router: {
233
235
  getBestRouteAndOutput: getBestRouteAndOutput,
236
+ getArgs: getArgs,
234
237
  expected: swapExpected,
238
+ required: swapRequired,
235
239
  priceImpact: swapPriceImpact,
236
240
  isApproved: swapIsApproved,
237
241
  approve: swapApprove,
@@ -7,6 +7,7 @@ export type INetworkName = "ethereum" | "optimism" | "xdai" | "polygon" | "fanto
7
7
  export type IChainId = 1 | 10 | 100 | 137 | 250 | 324 | 1284 | 2222 | 8453 | 42161 | 42220 | 43114 | 1313161554;
8
8
  export type IFactoryPoolType = "factory" | "factory-crvusd" | "factory-eywa" | "factory-crypto" | "factory-tricrypto";
9
9
  export type IPoolType = "main" | "crypto" | IFactoryPoolType;
10
+ export type ISwapType = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9;
10
11
  export type REFERENCE_ASSET = 'USD' | 'EUR' | 'BTC' | 'ETH' | 'LINK' | 'CRYPTO' | 'OTHER';
11
12
  export interface IPoolData {
12
13
  name: string;
@@ -140,13 +141,15 @@ export interface IExtendedPoolDataFromApi {
140
141
  }
141
142
  export interface IRouteStep {
142
143
  poolId: string;
143
- poolAddress: string;
144
+ swapAddress: string;
144
145
  inputCoinAddress: string;
145
146
  outputCoinAddress: string;
146
- i: number;
147
- j: number;
148
- swapType: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15;
149
- swapAddress: string;
147
+ swapParams: [number, number, ISwapType, number, number];
148
+ poolAddress: string;
149
+ basePool: string;
150
+ baseToken: string;
151
+ secondBasePool: string;
152
+ secondBaseToken: string;
150
153
  }
151
154
  export type IRoute = IRouteStep[];
152
155
  export interface IRouteTvl {
package/lib/router.d.ts CHANGED
@@ -4,7 +4,17 @@ export declare const getBestRouteAndOutput: (inputCoin: string, outputCoin: stri
4
4
  route: IRoute;
5
5
  output: string;
6
6
  }>;
7
+ export declare const getArgs: (route: IRoute) => {
8
+ _route: string[];
9
+ _swapParams: number[][];
10
+ _pools: string[];
11
+ _basePools: string[];
12
+ _baseTokens: string[];
13
+ _secondBasePools: string[];
14
+ _secondBaseTokens: string[];
15
+ };
7
16
  export declare const swapExpected: (inputCoin: string, outputCoin: string, amount: number | string) => Promise<string>;
17
+ export declare const swapRequired: (route: IRoute, outAmount: number | string) => Promise<string>;
8
18
  export declare const swapPriceImpact: (inputCoin: string, outputCoin: string, amount: number | string) => Promise<number>;
9
19
  export declare const swapIsApproved: (inputCoin: string, amount: number | string) => Promise<boolean>;
10
20
  export declare const swapApproveEstimateGas: (inputCoin: string, amount: number | string) => Promise<number>;