@curvefi/api 2.68.25 → 2.68.27

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.d.ts CHANGED
@@ -36,6 +36,7 @@ export declare class Curve implements ICurve {
36
36
  L1WeightedGasPrice?: number;
37
37
  constants: INetworkConstants;
38
38
  nativeTokenAddress: string;
39
+ poolAddressMapCache: IDict<string> | null;
39
40
  constructor();
40
41
  init(providerType: 'JsonRpc' | 'Web3' | 'Infura' | 'Alchemy' | 'NoRPC', providerSettings: {
41
42
  url?: string;
package/lib/curve.js CHANGED
@@ -341,6 +341,7 @@ export class Curve {
341
341
  this.constantOptions = { gasLimit: 12000000 };
342
342
  this.options = {};
343
343
  this.nativeTokenAddress = NETWORK_CONSTANTS[1].NATIVE_COIN.address;
344
+ this.poolAddressMapCache = null;
344
345
  this.constants = {
345
346
  NATIVE_TOKEN: NETWORK_CONSTANTS[1].NATIVE_COIN,
346
347
  NETWORK_NAME: 'ethereum',
package/lib/index.d.ts CHANGED
@@ -40,7 +40,7 @@ export declare const createCurve: () => {
40
40
  }[][]>;
41
41
  PoolTemplate: typeof PoolTemplate;
42
42
  getBasePools: () => Promise<import("./interfaces.js").IBasePoolShortItem[]>;
43
- getPool: (poolId: string) => PoolTemplate;
43
+ getPool: (poolIdOrAddress: string) => PoolTemplate;
44
44
  getUsdRate: (coin: string) => Promise<number>;
45
45
  getGasPriceFromL1: () => Promise<number>;
46
46
  getGasPriceFromL2: () => Promise<number>;
@@ -353,7 +353,7 @@ declare const _default: {
353
353
  }[][]>;
354
354
  PoolTemplate: typeof PoolTemplate;
355
355
  getBasePools: () => Promise<import("./interfaces.js").IBasePoolShortItem[]>;
356
- getPool: (poolId: string) => PoolTemplate;
356
+ getPool: (poolIdOrAddress: string) => PoolTemplate;
357
357
  getUsdRate: (coin: string) => Promise<number>;
358
358
  getGasPriceFromL1: () => Promise<number>;
359
359
  getGasPriceFromL2: () => Promise<number>;
@@ -1,3 +1,3 @@
1
1
  import { type Curve } from "../curve.js";
2
2
  import { PoolTemplate } from "./PoolTemplate.js";
3
- export declare function getPool(this: Curve, poolId: string): PoolTemplate;
3
+ export declare function getPool(this: Curve, poolIdOrAddress: string): PoolTemplate;
@@ -14,9 +14,24 @@ import { withdrawOneCoinWrappedExpected2argsMixin, withdrawOneCoinWrappedExpecte
14
14
  import { withdrawOneCoinWrappedLendingOrCryptoMixin, withdrawOneCoinWrappedMixin, } from "./mixins/withdrawOneCoinWrappedMixins.js";
15
15
  import { swapCryptoMetaFactoryMixin, swapMetaFactoryMixin, swapMixin, swapTricrypto2Mixin } from "./mixins/swapMixins.js";
16
16
  import { swapWrappedExpectedAndApproveMixin, swapWrappedMixin, swapWrappedRequiredMixin, swapWrappedTricrypto2Mixin, } from "./mixins/swapWrappedMixins.js";
17
- import { findAbiSignature, getCountArgsOfMethodByAbi } from "../utils.js";
17
+ import { findAbiSignature, getCountArgsOfMethodByAbi, getPoolIdBySwapAddress } from "../utils.js";
18
18
  import { StatsPool } from "./subClasses/statsPool.js";
19
- export function getPool(poolId) {
19
+ export function getPool(poolIdOrAddress) {
20
+ let poolId;
21
+ const _poolIdOrAddress = poolIdOrAddress.toLowerCase();
22
+ if (_poolIdOrAddress.startsWith('0x')) {
23
+ poolId = getPoolIdBySwapAddress.call(this, _poolIdOrAddress);
24
+ if (!poolId || !this.getPoolsData()[poolId]) {
25
+ throw new Error(`Pool with address ${_poolIdOrAddress} not found`);
26
+ }
27
+ }
28
+ else {
29
+ poolId = _poolIdOrAddress;
30
+ const poolsData = this.getPoolsData();
31
+ if (!poolsData[poolId]) {
32
+ throw new Error(`Pool with id ${_poolIdOrAddress} not found`);
33
+ }
34
+ }
20
35
  const poolDummy = new PoolTemplate(poolId, this);
21
36
  class Pool extends PoolTemplate {
22
37
  constructor(poolId, curve) {
@@ -1,5 +1,9 @@
1
1
  export function routeGraphWorker() {
2
2
  const GRAPH_MAX_EDGES = 3;
3
+ // Pools excluded from router
4
+ const EXCLUDED_POOLS_FROM_ROUTER = {
5
+ 1: ['usdt'], // Ethereum mainnet
6
+ };
3
7
  const SNX = {
4
8
  10: {
5
9
  swap: "0x8700dAec35aF8Ff88c16BdF0418774CB3D7599B4".toLowerCase(),
@@ -12,7 +16,7 @@ export function routeGraphWorker() {
12
16
  },
13
17
  };
14
18
  const createRouteGraph = ({ constants, chainId, isLiteChain, allPools, amplificationCoefficientDict, poolTvlDict }) => {
15
- var _a, _b, _c;
19
+ var _a, _b, _c, _d;
16
20
  const routerGraph = {};
17
21
  // ETH <-> WETH (exclude Celo)
18
22
  if (chainId !== 42220) {
@@ -292,6 +296,9 @@ export function routeGraphWorker() {
292
296
  continue;
293
297
  if (chainId !== 1 && !isLiteChain && tvl < 100)
294
298
  continue;
299
+ // Skip excluded pools from router
300
+ if ((_d = EXCLUDED_POOLS_FROM_ROUTER[chainId]) === null || _d === void 0 ? void 0 : _d.includes(poolId))
301
+ continue;
295
302
  const excludedUnderlyingSwaps = (poolId === 'ib' && chainId === 1) ||
296
303
  (poolId === 'geist' && chainId === 250) ||
297
304
  (poolId === 'saave' && chainId === 1);
package/lib/utils.js CHANGED
@@ -291,11 +291,24 @@ export function populateApprove(coins_1, amounts_1, spender_1) {
291
291
  });
292
292
  }
293
293
  export function getPoolIdBySwapAddress(swapAddress) {
294
- const poolsData = this.getPoolsData();
295
- const poolIds = Object.entries(poolsData).filter(([, poolData]) => poolData.swap_address.toLowerCase() === swapAddress.toLowerCase());
296
- if (poolIds.length === 0)
297
- return "";
298
- return poolIds[0][0];
294
+ var _a;
295
+ const _swapAddress = swapAddress.toLowerCase();
296
+ const buildCache = () => {
297
+ const poolsData = this.getPoolsData();
298
+ this.poolAddressMapCache = Object.entries(poolsData).reduce((acc, [poolId, poolData]) => {
299
+ acc[poolData.swap_address.toLowerCase()] = poolId;
300
+ return acc;
301
+ }, {});
302
+ };
303
+ if (this.poolAddressMapCache === null) {
304
+ buildCache();
305
+ }
306
+ if (this.poolAddressMapCache[_swapAddress]) {
307
+ return this.poolAddressMapCache[_swapAddress];
308
+ }
309
+ // Retry - cache update (if new pools were added through fetchFactoryPools and etc.)
310
+ buildCache();
311
+ return (_a = this.poolAddressMapCache[_swapAddress]) !== null && _a !== void 0 ? _a : "";
299
312
  }
300
313
  export function _getRewardsFromApi() {
301
314
  return __awaiter(this, void 0, void 0, function* () {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@curvefi/api",
3
- "version": "2.68.25",
3
+ "version": "2.68.27",
4
4
  "description": "JavaScript library for curve.finance",
5
5
  "main": "lib/index.js",
6
6
  "author": "Macket",