@curvefi/api 2.70.2 → 2.70.4

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.
@@ -1760,13 +1760,13 @@ export class PoolTemplate extends CorePool {
1760
1760
  const contractAddress = this.isCrypto && this.isMeta ? this.zap : this.address;
1761
1761
  const contract = this.curve.contracts[contractAddress].contract;
1762
1762
  if ('get_dy_underlying' in contract) {
1763
- return yield contract.get_dy_underlying(i, j, _amount, this.curve.constantOptions);
1763
+ return yield contract.get_dy_underlying(i, j, _amount);
1764
1764
  }
1765
1765
  else {
1766
1766
  if ('get_dy(address,uint256,uint256,uint256)' in contract) { // atricrypto3 based metapools
1767
- return yield contract.get_dy(this.address, i, j, _amount, this.curve.constantOptions);
1767
+ return yield contract.get_dy(this.address, i, j, _amount);
1768
1768
  }
1769
- return yield contract.get_dy(i, j, _amount, this.curve.constantOptions);
1769
+ return yield contract.get_dy(i, j, _amount);
1770
1770
  }
1771
1771
  });
1772
1772
  }
@@ -1793,21 +1793,21 @@ export class PoolTemplate extends CorePool {
1793
1793
  return __awaiter(this, void 0, void 0, function* () {
1794
1794
  if (this.isCrypto) {
1795
1795
  if (this.isNg)
1796
- return yield this.curve.contracts[this.address].contract.get_dx(i, j, _amount, this.curve.constantOptions);
1796
+ return yield this.curve.contracts[this.address].contract.get_dx(i, j, _amount);
1797
1797
  const contract = this.curve.contracts[this.curve.constants.ALIASES.crypto_calc].contract;
1798
1798
  if (this.isMeta && isUnderlying) {
1799
1799
  const basePool = new PoolTemplate(this.basePool, this.curve);
1800
1800
  if (this.wrappedCoins.length === 3) {
1801
- return yield contract.get_dx_tricrypto_meta_underlying(this.address, i, j, _amount, this.wrappedCoins.length, basePool.address, basePool.lpToken, this.curve.constantOptions);
1801
+ return yield contract.get_dx_tricrypto_meta_underlying(this.address, i, j, _amount, this.wrappedCoins.length, basePool.address, basePool.lpToken);
1802
1802
  }
1803
1803
  if (basePool.isFake) {
1804
1804
  const secondPool = new PoolTemplate(basePool.basePool, this.curve);
1805
- return yield contract.get_dx_double_meta_underlying(this.address, i, j, _amount, basePool.address, basePool.zap, secondPool.address, secondPool.lpToken, this.curve.constantOptions);
1805
+ return yield contract.get_dx_double_meta_underlying(this.address, i, j, _amount, basePool.address, basePool.zap, secondPool.address, secondPool.lpToken);
1806
1806
  }
1807
- return yield contract.get_dx_meta_underlying(this.address, i, j, _amount, this.underlyingCoins.length, basePool.address, basePool.lpToken, this.curve.constantOptions);
1807
+ return yield contract.get_dx_meta_underlying(this.address, i, j, _amount, this.underlyingCoins.length, basePool.address, basePool.lpToken);
1808
1808
  }
1809
1809
  else {
1810
- return yield contract.get_dx(this.address, i, j, _amount, this.wrappedCoins.length, this.curve.constantOptions);
1810
+ return yield contract.get_dx(this.address, i, j, _amount, this.wrappedCoins.length);
1811
1811
  }
1812
1812
  }
1813
1813
  else {
@@ -1815,32 +1815,32 @@ export class PoolTemplate extends CorePool {
1815
1815
  const contract = this.curve.contracts[this.address].contract;
1816
1816
  if (this.isMeta) {
1817
1817
  if (isUnderlying) {
1818
- return yield contract.get_dx_underlying(i, j, _amount, this.curve.constantOptions);
1818
+ return yield contract.get_dx_underlying(i, j, _amount);
1819
1819
  }
1820
1820
  else {
1821
- return yield contract.get_dx(i, j, _amount, this.curve.constantOptions);
1821
+ return yield contract.get_dx(i, j, _amount);
1822
1822
  }
1823
1823
  }
1824
1824
  else {
1825
- return yield contract.get_dx(i, j, _amount, this.curve.constantOptions);
1825
+ return yield contract.get_dx(i, j, _amount);
1826
1826
  }
1827
1827
  }
1828
1828
  const contract = this.curve.contracts[this.curve.constants.ALIASES.stable_calc].contract;
1829
1829
  if (this.isMeta) {
1830
1830
  const basePool = new PoolTemplate(this.basePool, this.curve);
1831
1831
  if (isUnderlying) {
1832
- return yield contract.get_dx_meta_underlying(this.address, i, j, _amount, this.underlyingCoins.length, basePool.address, basePool.lpToken, this.curve.constantOptions);
1832
+ return yield contract.get_dx_meta_underlying(this.address, i, j, _amount, this.underlyingCoins.length, basePool.address, basePool.lpToken);
1833
1833
  }
1834
1834
  else {
1835
- return yield contract.get_dx_meta(this.address, i, j, _amount, this.wrappedCoins.length, basePool.address, this.curve.constantOptions);
1835
+ return yield contract.get_dx_meta(this.address, i, j, _amount, this.wrappedCoins.length, basePool.address);
1836
1836
  }
1837
1837
  }
1838
1838
  else {
1839
1839
  if (isUnderlying && this.isLending) {
1840
- return yield contract.get_dx_underlying(this.address, i, j, _amount, this.underlyingCoins.length, this.curve.constantOptions);
1840
+ return yield contract.get_dx_underlying(this.address, i, j, _amount, this.underlyingCoins.length);
1841
1841
  }
1842
1842
  else {
1843
- return yield contract.get_dx(this.address, i, j, _amount, this.wrappedCoins.length, this.curve.constantOptions);
1843
+ return yield contract.get_dx(this.address, i, j, _amount, this.wrappedCoins.length);
1844
1844
  }
1845
1845
  }
1846
1846
  }
package/lib/utils.d.ts CHANGED
@@ -6,14 +6,14 @@ import { Curve } from "./curve.js";
6
6
  export declare const ETH_ADDRESS = "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee";
7
7
  export declare const MAX_ALLOWANCE: bigint;
8
8
  export declare const abiInfoBuild: (address: string, method: string, abi: any) => IMethodInfo;
9
- export declare const _cutZeros: (strn: string) => string;
10
9
  export declare const checkNumber: (n: number | string) => number | string;
11
- export declare const formatNumber: (n: number | string, decimals?: number) => string;
12
- export declare function parseUnits(n: number | string, decimals?: number): bigint;
13
10
  export declare const BN: (val: number | string) => BigNumber;
14
11
  export declare const toBN: (n: bigint, decimals?: number) => BigNumber;
15
12
  export declare const toStringFromBN: (bn: BigNumber, decimals?: number) => string;
16
13
  export declare const fromBN: (bn: BigNumber, decimals?: number) => bigint;
14
+ export declare const _cutZeros: (strn: string) => string;
15
+ export declare const formatNumber: (n: number | string, decimals?: number) => string;
16
+ export declare function parseUnits(n: number | string, decimals?: number): bigint;
17
17
  export declare const mulBy1_3: (n: bigint) => bigint;
18
18
  export declare const smartNumber: (abstractNumber: bigint | bigint[]) => number | number[];
19
19
  export declare const DIGas: (gas: bigint | Array<bigint>) => bigint;
package/lib/utils.js CHANGED
@@ -28,25 +28,12 @@ export const abiInfoBuild = (address, method, abi) => ({
28
28
  method,
29
29
  abi,
30
30
  });
31
- // Formatting numbers
32
- export const _cutZeros = (strn) => {
33
- return strn.replace(/(\.\d*[1-9])0+$/gi, '$1').replace(/\.0+$/gi, '');
34
- };
31
+ // bignumber.js
35
32
  export const checkNumber = (n) => {
36
33
  if (Number(n) !== Number(n))
37
34
  throw Error(`${n} is not a number`); // NaN
38
35
  return n;
39
36
  };
40
- export const formatNumber = (n, decimals = 18) => {
41
- if (Number(n) !== Number(n))
42
- throw Error(`${n} is not a number`); // NaN
43
- const [integer, fractional] = String(n).split(".");
44
- return !fractional ? integer : integer + "." + fractional.slice(0, decimals);
45
- };
46
- export function parseUnits(n, decimals = 18) {
47
- return ethers.parseUnits(formatNumber(n, decimals), decimals);
48
- }
49
- // bignumber.js
50
37
  export const BN = (val) => new BigNumber(checkNumber(val));
51
38
  export const toBN = (n, decimals = 18) => {
52
39
  return BN(formatUnits(n, decimals));
@@ -57,6 +44,14 @@ export const toStringFromBN = (bn, decimals = 18) => {
57
44
  export const fromBN = (bn, decimals = 18) => {
58
45
  return parseUnits(toStringFromBN(bn, decimals), decimals);
59
46
  };
47
+ // Formatting numbers
48
+ export const _cutZeros = (strn) => {
49
+ return strn.replace(/(\.\d*[1-9])0+$/gi, '$1').replace(/\.0+$/gi, '');
50
+ };
51
+ export const formatNumber = (n, decimals = 18) => BN(n).toFixed(decimals, BigNumber.ROUND_DOWN);
52
+ export function parseUnits(n, decimals = 18) {
53
+ return ethers.parseUnits(formatNumber(n, decimals), decimals);
54
+ }
60
55
  // -------------------
61
56
  export const mulBy1_3 = (n) => n * parseUnits("130", 0) / parseUnits("100", 0);
62
57
  export const smartNumber = (abstractNumber) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@curvefi/api",
3
- "version": "2.70.2",
3
+ "version": "2.70.4",
4
4
  "description": "JavaScript library for curve.finance",
5
5
  "main": "lib/index.js",
6
6
  "author": "Macket",