@curvefi/api 2.68.43 → 2.69.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.
@@ -0,0 +1,28 @@
1
+ export declare const GAS_STRATEGIES: {
2
+ readonly economy: {
3
+ readonly percentile: 20;
4
+ readonly baseFeeMulBps: 11000;
5
+ readonly tipMulBps: 9400;
6
+ readonly minTipMainnet: 0;
7
+ readonly legacyGasPriceMulBps: 10000;
8
+ readonly fallbackTipMulBps: 10000;
9
+ };
10
+ readonly standard: {
11
+ readonly percentile: 50;
12
+ readonly baseFeeMulBps: 12500;
13
+ readonly tipMulBps: 10000;
14
+ readonly minTipMainnet: 2000000000;
15
+ readonly legacyGasPriceMulBps: 11000;
16
+ readonly fallbackTipMulBps: 15000;
17
+ };
18
+ readonly aggressive: {
19
+ readonly percentile: 80;
20
+ readonly baseFeeMulBps: 13000;
21
+ readonly tipMulBps: 10200;
22
+ readonly minTipMainnet: 4000000000;
23
+ readonly legacyGasPriceMulBps: 12500;
24
+ readonly fallbackTipMulBps: 20000;
25
+ };
26
+ };
27
+ export declare const FEE_HISTORY_BLOCK_COUNT = 10;
28
+ export declare const MAINNET_CHAIN_ID = 1;
@@ -0,0 +1,28 @@
1
+ export const GAS_STRATEGIES = {
2
+ economy: {
3
+ percentile: 20,
4
+ baseFeeMulBps: 11000, // baseFee × 1.10
5
+ tipMulBps: 9400, // median tip × 0.94
6
+ minTipMainnet: 0, // 0 gwei
7
+ legacyGasPriceMulBps: 10000, // gasPrice × 1.00
8
+ fallbackTipMulBps: 10000, // tip × 1.00
9
+ },
10
+ standard: {
11
+ percentile: 50,
12
+ baseFeeMulBps: 12500, // baseFee × 1.25
13
+ tipMulBps: 10000, // median tip × 1.00
14
+ minTipMainnet: 2000000000, // tip floor = baseFee × 0.05 (mainnet only)
15
+ legacyGasPriceMulBps: 11000, // gasPrice × 1.10
16
+ fallbackTipMulBps: 15000, // tip × 1.50
17
+ },
18
+ aggressive: {
19
+ percentile: 80,
20
+ baseFeeMulBps: 13000, // baseFee × 1.3
21
+ tipMulBps: 10200, // median tip × 1.06
22
+ minTipMainnet: 4000000000, // 4 gwei
23
+ legacyGasPriceMulBps: 12500, // gasPrice × 1.25
24
+ fallbackTipMulBps: 20000, // tip × 2.00
25
+ },
26
+ };
27
+ export const FEE_HISTORY_BLOCK_COUNT = 10;
28
+ export const MAINNET_CHAIN_ID = 1;
package/lib/curve.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { BigNumberish, BrowserProvider, Contract, ethers, JsonRpcProvider, Networkish, Numeric, Signer } from "ethers";
2
2
  import { Contract as MulticallContract, Provider as MulticallProvider } from "@curvefi/ethcall";
3
- import { Abi, IChainId, ICurve, IDict, IExtendedPoolDataFromApi, IFactoryPoolType, INetworkConstants, IPoolData, IPoolType } from "./interfaces";
3
+ import { Abi, IChainId, ICurve, IDict, IExtendedPoolDataFromApi, IFactoryPoolType, IGasStrategy, INetworkConstants, IPoolData, IPoolType } from "./interfaces";
4
4
  export declare const OLD_CHAINS: number[];
5
5
  export declare const memoizedContract: () => (address: string, abi: any, provider: BrowserProvider | JsonRpcProvider | Signer) => Contract;
6
6
  export declare const memoizedMulticallContract: () => (address: string, abi: any) => MulticallContract;
@@ -25,6 +25,7 @@ export declare class Curve implements ICurve {
25
25
  maxFeePerGas?: number;
26
26
  maxPriorityFeePerGas?: number;
27
27
  };
28
+ gasStrategy: IGasStrategy;
28
29
  constantOptions: {
29
30
  gasLimit?: number;
30
31
  };
@@ -51,6 +52,7 @@ export declare class Curve implements ICurve {
51
52
  gasPrice?: number;
52
53
  maxFeePerGas?: number;
53
54
  maxPriorityFeePerGas?: number;
55
+ gasStrategy?: IGasStrategy;
54
56
  chainId?: number;
55
57
  poolsData?: Record<IPoolType, IExtendedPoolDataFromApi>;
56
58
  }): Promise<void>;
@@ -90,6 +92,7 @@ export declare class Curve implements ICurve {
90
92
  maxFeePerGas?: number;
91
93
  maxPriorityFeePerGas?: number;
92
94
  }): void;
95
+ setGasStrategy(strategy: IGasStrategy): void;
93
96
  formatUnits(value: BigNumberish, unit?: string | Numeric): string;
94
97
  parseUnits(value: string, unit?: string | Numeric): bigint;
95
98
  updateFeeData(): Promise<void>;
package/lib/curve.js CHANGED
@@ -52,7 +52,7 @@ import { extractDecimals, extractGauges, formatUnits, lowerCasePoolDataAddresses
52
52
  import { _getHiddenPools } from "./external-api.js";
53
53
  import { L2Networks } from "./constants/L2Networks.js";
54
54
  import { getTwocryptoFactoryPoolData } from "./factory/factory-twocrypto.js";
55
- import { getNetworkConstants } from "./utils.js";
55
+ import { applyFeeDataOverride, computeEip1559Fees, computeLegacyOrFallback, fetchFeeHistory, getNetworkConstants, } from "./utils.js";
56
56
  import { _setPoolsFromApi } from "./cached.js";
57
57
  export const OLD_CHAINS = [1, 10, 56, 100, 137, 250, 1284, 2222, 8453, 42161, 42220, 43114, 1313161554]; // these chains have non-ng pools
58
58
  export const memoizedContract = () => {
@@ -321,6 +321,7 @@ export class Curve {
321
321
  this.multicallProvider = null;
322
322
  this.contracts = {};
323
323
  this.feeData = {};
324
+ this.gasStrategy = 'standard';
324
325
  this.constantOptions = { gasLimit: 12000000 };
325
326
  this.options = {};
326
327
  this.nativeTokenAddress = NETWORK_CONSTANTS[1].NATIVE_COIN.address;
@@ -350,7 +351,7 @@ export class Curve {
350
351
  init(providerType_1, providerSettings_1) {
351
352
  return __awaiter(this, arguments, void 0, function* (providerType, providerSettings, options = {} // gasPrice in Gwei
352
353
  ) {
353
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
354
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
354
355
  this.provider = null;
355
356
  this.signer = null;
356
357
  this.isNoRPC = false;
@@ -359,6 +360,7 @@ export class Curve {
359
360
  this.multicallProvider = null;
360
361
  this.contracts = {};
361
362
  this.feeData = {};
363
+ this.gasStrategy = (_a = options.gasStrategy) !== null && _a !== void 0 ? _a : 'standard';
362
364
  this.constantOptions = { gasLimit: 12000000 };
363
365
  this.options = {};
364
366
  this.nativeTokenAddress = NETWORK_CONSTANTS[1].NATIVE_COIN.address;
@@ -403,11 +405,11 @@ export class Curve {
403
405
  if (providerSettings.privateKey) {
404
406
  this.signer = new ethers.Wallet(providerSettings.privateKey, this.provider);
405
407
  }
406
- else if (!((_a = providerSettings.url) === null || _a === void 0 ? void 0 : _a.startsWith("https://rpc.gnosischain.com"))) {
408
+ else if (!((_b = providerSettings.url) === null || _b === void 0 ? void 0 : _b.startsWith("https://rpc.gnosischain.com"))) {
407
409
  try {
408
410
  this.signer = yield this.provider.getSigner();
409
411
  }
410
- catch (_l) {
412
+ catch (_m) {
411
413
  this.signer = null;
412
414
  }
413
415
  }
@@ -451,11 +453,11 @@ export class Curve {
451
453
  this.constants.ALIASES = network_constants.ALIASES;
452
454
  this.constants.ALIASES.anycall = "0x37414a8662bc1d25be3ee51fb27c2686e2490a89";
453
455
  this.constants.ALIASES.voting_escrow_oracle = "0x12F407340697Ae0b177546E535b91A5be021fBF9";
454
- this.constants.POOLS_DATA = (_b = network_constants.POOLS_DATA) !== null && _b !== void 0 ? _b : {};
455
- this.constants.LLAMMAS_DATA = (_c = network_constants.LLAMMAS_DATA) !== null && _c !== void 0 ? _c : {};
456
+ this.constants.POOLS_DATA = (_c = network_constants.POOLS_DATA) !== null && _c !== void 0 ? _c : {};
457
+ this.constants.LLAMMAS_DATA = (_d = network_constants.LLAMMAS_DATA) !== null && _d !== void 0 ? _d : {};
456
458
  for (const poolId in this.constants.POOLS_DATA)
457
459
  this.constants.POOLS_DATA[poolId].in_api = true;
458
- this.constants.COINS = (_d = network_constants.COINS) !== null && _d !== void 0 ? _d : {};
460
+ this.constants.COINS = (_e = network_constants.COINS) !== null && _e !== void 0 ? _e : {};
459
461
  this.constants.DECIMALS = extractDecimals(Object.assign(Object.assign({}, this.constants.POOLS_DATA), this.constants.LLAMMAS_DATA));
460
462
  this.constants.DECIMALS[this.constants.NATIVE_TOKEN.address] = 18;
461
463
  this.constants.DECIMALS[this.constants.NATIVE_TOKEN.wrappedAddress] = 18;
@@ -464,18 +466,18 @@ export class Curve {
464
466
  this.constants.API_CONSTANTS = network_constants.API_CONSTANTS;
465
467
  }
466
468
  const [cTokens, yTokens, ycTokens, aTokens] = [
467
- (_e = network_constants.cTokens) !== null && _e !== void 0 ? _e : [],
468
- (_f = network_constants.yTokens) !== null && _f !== void 0 ? _f : [],
469
- (_g = network_constants.ycTokens) !== null && _g !== void 0 ? _g : [],
470
- (_h = network_constants.aTokens) !== null && _h !== void 0 ? _h : [],
469
+ (_f = network_constants.cTokens) !== null && _f !== void 0 ? _f : [],
470
+ (_g = network_constants.yTokens) !== null && _g !== void 0 ? _g : [],
471
+ (_h = network_constants.ycTokens) !== null && _h !== void 0 ? _h : [],
472
+ (_j = network_constants.aTokens) !== null && _j !== void 0 ? _j : [],
471
473
  ];
472
474
  const customAbiTokens = [...cTokens, ...yTokens, ...ycTokens, ...aTokens];
473
475
  if (this.isLiteChain) {
474
476
  this.constants.STABLE_FACTORY_CONSTANTS.stableNgBasePoolZap = network_constants.stableNgBasePoolZap;
475
477
  }
476
478
  else {
477
- this.constants.STABLE_FACTORY_CONSTANTS = (_j = STABLE_FACTORY_CONSTANTS[this.chainId]) !== null && _j !== void 0 ? _j : {};
478
- this.constants.CRYPTO_FACTORY_CONSTANTS = (_k = CRYPTO_FACTORY_CONSTANTS[this.chainId]) !== null && _k !== void 0 ? _k : {};
479
+ this.constants.STABLE_FACTORY_CONSTANTS = (_k = STABLE_FACTORY_CONSTANTS[this.chainId]) !== null && _k !== void 0 ? _k : {};
480
+ this.constants.CRYPTO_FACTORY_CONSTANTS = (_l = CRYPTO_FACTORY_CONSTANTS[this.chainId]) !== null && _l !== void 0 ? _l : {};
479
481
  }
480
482
  if (this.chainId === 5000) {
481
483
  this.constantOptions = {};
@@ -485,7 +487,7 @@ export class Curve {
485
487
  try {
486
488
  this.signerAddress = yield this.signer.getAddress();
487
489
  }
488
- catch (_m) {
490
+ catch (_o) {
489
491
  this.signer = null;
490
492
  }
491
493
  }
@@ -673,6 +675,9 @@ export class Curve {
673
675
  setCustomFeeData(customFeeData) {
674
676
  this.feeData = Object.assign(Object.assign({}, this.feeData), customFeeData);
675
677
  }
678
+ setGasStrategy(strategy) {
679
+ this.gasStrategy = strategy;
680
+ }
676
681
  formatUnits(value, unit) {
677
682
  return formatUnits(value, unit);
678
683
  }
@@ -681,26 +686,13 @@ export class Curve {
681
686
  }
682
687
  updateFeeData() {
683
688
  return __awaiter(this, void 0, void 0, function* () {
684
- if (this.isNoRPC) {
689
+ if (this.isNoRPC)
685
690
  return;
686
- }
687
- const feeData = yield this.provider.getFeeData();
688
- if (feeData.maxFeePerGas === null || feeData.maxPriorityFeePerGas === null) {
689
- delete this.options.maxFeePerGas;
690
- delete this.options.maxPriorityFeePerGas;
691
- this.options.gasPrice = this.feeData.gasPrice !== undefined ?
692
- this.parseUnits(this.feeData.gasPrice.toString(), "gwei") :
693
- (feeData.gasPrice || this.parseUnits("20", "gwei"));
694
- }
695
- else {
696
- delete this.options.gasPrice;
697
- this.options.maxFeePerGas = (this.feeData.maxFeePerGas !== undefined && this.feeData.maxFeePerGas !== null) ?
698
- this.parseUnits(this.feeData.maxFeePerGas.toString(), "gwei") :
699
- feeData.maxFeePerGas;
700
- this.options.maxPriorityFeePerGas = (this.feeData.maxPriorityFeePerGas !== undefined && this.feeData.maxPriorityFeePerGas !== null) ?
701
- this.parseUnits(this.feeData.maxPriorityFeePerGas.toString(), "gwei") :
702
- feeData.maxPriorityFeePerGas;
703
- }
691
+ const history = yield fetchFeeHistory(this.provider, this.gasStrategy);
692
+ const computed = history
693
+ ? computeEip1559Fees(history, this.gasStrategy, this.chainId)
694
+ : yield computeLegacyOrFallback(this.provider, this.gasStrategy);
695
+ this.options = applyFeeDataOverride(computed, this.feeData);
704
696
  });
705
697
  }
706
698
  }
package/lib/index.d.ts CHANGED
@@ -17,6 +17,7 @@ export declare const createCurve: () => {
17
17
  gasPrice?: number;
18
18
  maxFeePerGas?: number;
19
19
  maxPriorityFeePerGas?: number;
20
+ gasStrategy?: import("./interfaces.js").IGasStrategy;
20
21
  chainId?: number;
21
22
  poolsData?: Record<import("./interfaces.js").IPoolType, import("./interfaces.js").IExtendedPoolDataFromApi>;
22
23
  } | undefined) => Promise<void>;
@@ -27,6 +28,7 @@ export declare const createCurve: () => {
27
28
  maxFeePerGas?: number;
28
29
  maxPriorityFeePerGas?: number;
29
30
  }) => void;
31
+ setGasStrategy: (strategy: import("./interfaces.js").IGasStrategy) => void;
30
32
  getPoolList: () => string[];
31
33
  getMainPoolList: () => string[];
32
34
  getUserPoolListByLiquidity: (address?: string | undefined) => Promise<string[]>;
@@ -347,6 +349,7 @@ declare const _default: {
347
349
  gasPrice?: number;
348
350
  maxFeePerGas?: number;
349
351
  maxPriorityFeePerGas?: number;
352
+ gasStrategy?: import("./interfaces.js").IGasStrategy;
350
353
  chainId?: number;
351
354
  poolsData?: Record<import("./interfaces.js").IPoolType, import("./interfaces.js").IExtendedPoolDataFromApi>;
352
355
  } | undefined) => Promise<void>;
@@ -357,6 +360,7 @@ declare const _default: {
357
360
  maxFeePerGas?: number;
358
361
  maxPriorityFeePerGas?: number;
359
362
  }) => void;
363
+ setGasStrategy: (strategy: import("./interfaces.js").IGasStrategy) => void;
360
364
  getPoolList: () => string[];
361
365
  getMainPoolList: () => string[];
362
366
  getUserPoolListByLiquidity: (address?: string | undefined) => Promise<string[]>;
@@ -664,3 +668,4 @@ declare const _default: {
664
668
  };
665
669
  };
666
670
  export default _default;
671
+ export type { IGasStrategy } from "./interfaces.js";
package/lib/index.js CHANGED
@@ -32,6 +32,7 @@ export const createCurve = () => {
32
32
  chainId: 0, // until init is called
33
33
  signerAddress: '',
34
34
  setCustomFeeData: _curve.setCustomFeeData.bind(_curve),
35
+ setGasStrategy: _curve.setGasStrategy.bind(_curve),
35
36
  getPoolList: _curve.getPoolList.bind(_curve),
36
37
  getMainPoolList: _curve.getMainPoolList.bind(_curve),
37
38
  getUserPoolListByLiquidity: getUserPoolListByLiquidity.bind(_curve),
@@ -9,6 +9,7 @@ export type IChainId = number;
9
9
  export type IFactoryPoolType = "factory" | "factory-crvusd" | "factory-crypto" | "factory-twocrypto" | "factory-tricrypto" | "factory-stable-ng";
10
10
  export type IPoolType = "main" | "crypto" | IFactoryPoolType;
11
11
  export type ISwapType = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9;
12
+ export type IGasStrategy = 'economy' | 'standard' | 'aggressive';
12
13
  export type REFERENCE_ASSET = 'USD' | 'EUR' | 'BTC' | 'ETH' | 'LINK' | 'CRYPTO' | 'OTHER';
13
14
  export interface IPoolData {
14
15
  name: string;
@@ -110,6 +111,7 @@ export interface ICurve {
110
111
  maxFeePerGas?: number;
111
112
  maxPriorityFeePerGas?: number;
112
113
  };
114
+ gasStrategy: IGasStrategy;
113
115
  constantOptions: {
114
116
  gasLimit?: number;
115
117
  };
@@ -120,6 +122,7 @@ export interface ICurve {
120
122
  };
121
123
  constants: INetworkConstants;
122
124
  setContract: (address: string | undefined, abi: any) => void;
125
+ setGasStrategy(strategy: IGasStrategy): void;
123
126
  formatUnits(value: BigNumberish, unit?: string | Numeric): string;
124
127
  }
125
128
  export interface ICoinFromPoolDataApi {
package/lib/utils.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- import { Contract, TransactionLike } from 'ethers';
1
+ import { Contract, ethers, TransactionLike } from 'ethers';
2
2
  import { Contract as MulticallContract } from "@curvefi/ethcall";
3
3
  import BigNumber from 'bignumber.js';
4
- import { Abi, AbiFunction, IBasePoolShortItem, IChainId, ICurveLiteNetwork, IDict, IMethodInfo, INetworkName, IRewardFromApi, IVolumeAndAPYs, REFERENCE_ASSET } from './interfaces';
4
+ import { Abi, AbiFunction, IBasePoolShortItem, IChainId, ICurveLiteNetwork, IDict, IGasStrategy, IMethodInfo, INetworkName, IRewardFromApi, IVolumeAndAPYs, REFERENCE_ASSET } from './interfaces';
5
5
  import { Curve } from "./curve.js";
6
6
  export declare const ETH_ADDRESS = "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee";
7
7
  export declare const MAX_ALLOWANCE: bigint;
@@ -42,6 +42,36 @@ export declare function getGasPrice(this: Curve): Promise<number>;
42
42
  export declare function getGasPriceFromL1(this: Curve): Promise<number>;
43
43
  export declare function getGasPriceFromL2(this: Curve): Promise<number>;
44
44
  export declare function getGasInfoForL2(this: Curve): Promise<Record<string, number | null>>;
45
+ export declare function medianBigInt(values: bigint[]): bigint;
46
+ export declare function fetchFeeHistory(provider: ethers.JsonRpcProvider | ethers.BrowserProvider, strategy: IGasStrategy): Promise<{
47
+ baseFees: bigint[];
48
+ tips: bigint[];
49
+ } | null>;
50
+ export declare function computeEip1559Fees(history: {
51
+ baseFees: bigint[];
52
+ tips: bigint[];
53
+ }, strategy: IGasStrategy, chainId: number): {
54
+ maxFeePerGas: bigint;
55
+ maxPriorityFeePerGas: bigint;
56
+ };
57
+ export declare function computeLegacyOrFallback(provider: ethers.JsonRpcProvider | ethers.BrowserProvider, strategy: IGasStrategy): Promise<{
58
+ maxFeePerGas?: bigint;
59
+ maxPriorityFeePerGas?: bigint;
60
+ gasPrice?: bigint;
61
+ }>;
62
+ export declare function applyFeeDataOverride(computed: {
63
+ maxFeePerGas?: bigint;
64
+ maxPriorityFeePerGas?: bigint;
65
+ gasPrice?: bigint;
66
+ }, feeData: {
67
+ gasPrice?: number;
68
+ maxFeePerGas?: number;
69
+ maxPriorityFeePerGas?: number;
70
+ }): {
71
+ maxFeePerGas?: bigint;
72
+ maxPriorityFeePerGas?: bigint;
73
+ gasPrice?: bigint;
74
+ };
45
75
  export declare const getTxCostsUsd: (ethUsdRate: number, gasPrice: number, gas: number | number[], gasPriceL1?: number) => number;
46
76
  export declare function getCurveLiteNetworks(this: Curve): Promise<ICurveLiteNetwork[]>;
47
77
  export declare const getNetworkNameByChainId: (chainId: number, networks: ICurveLiteNetwork[]) => string;
package/lib/utils.js CHANGED
@@ -18,6 +18,7 @@ import { volumeNetworks } from "./constants/volumeNetworks.js";
18
18
  import { getPool } from "./pools/index.js";
19
19
  import { NETWORK_CONSTANTS } from "./constants/network_constants.js";
20
20
  import { formatUnits } from "./constants/utils.js";
21
+ import { FEE_HISTORY_BLOCK_COUNT, GAS_STRATEGIES, MAINNET_CHAIN_ID, } from "./constants/gas.js";
21
22
  export const ETH_ADDRESS = "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee";
22
23
  // export const MAX_ALLOWANCE = curve.parseUnits(new BigNumber(2).pow(256).minus(1).toFixed(), 0);
23
24
  export const MAX_ALLOWANCE = BigInt("115792089237316195423570985008687907853269984665640564039457584007913129639935"); // 2**256 - 1
@@ -556,6 +557,84 @@ export function getGasInfoForL2() {
556
557
  }
557
558
  });
558
559
  }
560
+ // ─── Gas strategy helpers ─────────────────────────────────────────────────────
561
+ export function medianBigInt(values) {
562
+ if (values.length === 0)
563
+ return BigInt(0);
564
+ const sorted = [...values].sort((a, b) => (a < b ? -1 : a > b ? 1 : 0));
565
+ const mid = Math.floor(sorted.length / 2);
566
+ return sorted.length % 2 === 0
567
+ ? (sorted[mid - 1] + sorted[mid]) / BigInt(2)
568
+ : sorted[mid];
569
+ }
570
+ export function fetchFeeHistory(provider, strategy) {
571
+ return __awaiter(this, void 0, void 0, function* () {
572
+ const { percentile } = GAS_STRATEGIES[strategy];
573
+ try {
574
+ const raw = yield provider.send('eth_feeHistory', [
575
+ `0x${FEE_HISTORY_BLOCK_COUNT.toString(16)}`,
576
+ 'latest',
577
+ [percentile],
578
+ ]);
579
+ if (!raw || !Array.isArray(raw.baseFeePerGas) || !Array.isArray(raw.reward))
580
+ return null;
581
+ const baseFees = raw.baseFeePerGas.map(BigInt);
582
+ if (baseFees.length === 0 || baseFees[baseFees.length - 1] <= BigInt(0))
583
+ return null;
584
+ const tips = raw.reward.map((row) => {
585
+ var _a;
586
+ try {
587
+ return BigInt((_a = row === null || row === void 0 ? void 0 : row[0]) !== null && _a !== void 0 ? _a : 0);
588
+ }
589
+ catch (_b) {
590
+ return BigInt(0);
591
+ }
592
+ });
593
+ return { baseFees, tips };
594
+ }
595
+ catch (_a) {
596
+ return null;
597
+ }
598
+ });
599
+ }
600
+ export function computeEip1559Fees(history, strategy, chainId) {
601
+ const strategyConfig = GAS_STRATEGIES[strategy];
602
+ const latestBase = history.baseFees[history.baseFees.length - 1];
603
+ const adjustedBase = (latestBase * BigInt(strategyConfig.baseFeeMulBps)) / BigInt(10000);
604
+ const nonZeroTips = history.tips.filter((tip) => tip > BigInt(0));
605
+ const medianTip = medianBigInt(nonZeroTips);
606
+ let tip = (medianTip * BigInt(strategyConfig.tipMulBps)) / BigInt(10000);
607
+ if (chainId === MAINNET_CHAIN_ID) {
608
+ tip = tip > BigInt(strategyConfig.minTipMainnet)
609
+ ? tip
610
+ : BigInt(strategyConfig.minTipMainnet);
611
+ }
612
+ return { maxPriorityFeePerGas: tip, maxFeePerGas: adjustedBase + tip };
613
+ }
614
+ export function computeLegacyOrFallback(provider, strategy) {
615
+ return __awaiter(this, void 0, void 0, function* () {
616
+ var _a;
617
+ const strategyConfig = GAS_STRATEGIES[strategy];
618
+ const networkFeeData = yield provider.getFeeData();
619
+ if (networkFeeData.maxFeePerGas != null && networkFeeData.maxPriorityFeePerGas != null) {
620
+ const tip = (networkFeeData.maxPriorityFeePerGas * BigInt(strategyConfig.fallbackTipMulBps)) / BigInt(10000);
621
+ return { maxFeePerGas: networkFeeData.maxFeePerGas, maxPriorityFeePerGas: tip };
622
+ }
623
+ const gasPrice = (_a = networkFeeData.gasPrice) !== null && _a !== void 0 ? _a : ethers.parseUnits('20', 'gwei');
624
+ return { gasPrice: (gasPrice * BigInt(strategyConfig.legacyGasPriceMulBps)) / BigInt(10000) };
625
+ });
626
+ }
627
+ export function applyFeeDataOverride(computed, feeData) {
628
+ var _a, _b, _c;
629
+ const result = Object.assign({}, computed);
630
+ if (((_a = feeData.gasPrice) !== null && _a !== void 0 ? _a : 0) > 0)
631
+ result.gasPrice = ethers.parseUnits(feeData.gasPrice.toString(), 'gwei');
632
+ if (((_b = feeData.maxFeePerGas) !== null && _b !== void 0 ? _b : 0) > 0)
633
+ result.maxFeePerGas = ethers.parseUnits(feeData.maxFeePerGas.toString(), 'gwei');
634
+ if (((_c = feeData.maxPriorityFeePerGas) !== null && _c !== void 0 ? _c : 0) > 0)
635
+ result.maxPriorityFeePerGas = ethers.parseUnits(feeData.maxPriorityFeePerGas.toString(), 'gwei');
636
+ return result;
637
+ }
559
638
  export const getTxCostsUsd = (ethUsdRate, gasPrice, gas, gasPriceL1 = 0) => {
560
639
  if (Array.isArray(gas)) {
561
640
  return ethUsdRate * ((gas[0] * gasPrice / 1e18) + (gas[1] * gasPriceL1 / 1e18));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@curvefi/api",
3
- "version": "2.68.43",
3
+ "version": "2.69.1",
4
4
  "description": "JavaScript library for curve.finance",
5
5
  "main": "lib/index.js",
6
6
  "author": "Macket",