@ocap/util 1.27.16 → 1.28.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.
Files changed (54) hide show
  1. package/esm/bn.d.ts +8 -6
  2. package/esm/bn.js +11 -7
  3. package/esm/constant.d.ts +4 -1
  4. package/esm/constant.js +5 -1
  5. package/esm/create-sorted-list.d.ts +4 -1
  6. package/esm/create-sorted-list.js +8 -3
  7. package/esm/curve.d.ts +85 -55
  8. package/esm/curve.js +132 -127
  9. package/esm/error.d.ts +12 -9
  10. package/esm/error.js +24 -17
  11. package/esm/get-list-field.d.ts +4 -1
  12. package/esm/get-list-field.js +7 -2
  13. package/esm/get-related-addr.d.ts +4 -1
  14. package/esm/get-related-addr.js +5 -1
  15. package/esm/index.d.ts +47 -44
  16. package/esm/index.js +364 -469
  17. package/esm/lodash.d.ts +12 -0
  18. package/esm/md5.d.ts +4 -1
  19. package/esm/md5.js +7 -3
  20. package/esm/ready.d.ts +13 -9
  21. package/esm/ready.js +33 -36
  22. package/esm/retry.d.ts +16 -9
  23. package/esm/retry.js +26 -27
  24. package/esm/tsfixme.d.ts +3 -0
  25. package/esm/url.d.ts +16 -12
  26. package/esm/url.js +67 -92
  27. package/lib/_virtual/rolldown_runtime.js +29 -0
  28. package/lib/bn.d.ts +8 -6
  29. package/lib/bn.js +12 -12
  30. package/lib/constant.d.ts +4 -1
  31. package/lib/constant.js +6 -4
  32. package/lib/create-sorted-list.d.ts +4 -1
  33. package/lib/create-sorted-list.js +11 -10
  34. package/lib/curve.d.ts +84 -55
  35. package/lib/curve.js +139 -137
  36. package/lib/error.d.ts +12 -9
  37. package/lib/error.js +25 -21
  38. package/lib/get-list-field.d.ts +4 -1
  39. package/lib/get-list-field.js +9 -9
  40. package/lib/get-related-addr.d.ts +4 -1
  41. package/lib/get-related-addr.js +5 -4
  42. package/lib/index.d.ts +47 -44
  43. package/lib/index.js +386 -506
  44. package/lib/lodash.d.ts +12 -0
  45. package/lib/md5.d.ts +4 -1
  46. package/lib/md5.js +9 -10
  47. package/lib/ready.d.ts +13 -9
  48. package/lib/ready.js +34 -42
  49. package/lib/retry.d.ts +16 -9
  50. package/lib/retry.js +27 -30
  51. package/lib/tsfixme.d.ts +3 -0
  52. package/lib/url.d.ts +16 -12
  53. package/lib/url.js +69 -118
  54. package/package.json +20 -9
package/esm/bn.d.ts CHANGED
@@ -1,7 +1,9 @@
1
- import BaseBN from 'bn.js';
2
- export interface BN extends BaseBN {
1
+ import BaseBN from "bn.js";
2
+
3
+ //#region src/bn.d.ts
4
+ interface BN extends BaseBN {}
5
+ declare class BN extends BaseBN {
6
+ constructor(value: number | string | number[] | Uint8Array | Buffer | BaseBN | null | undefined, base?: number | 'hex', endian?: BaseBN.Endianness);
3
7
  }
4
- export declare class BN extends BaseBN {
5
- constructor(value: number | string | number[] | Uint8Array | Buffer | BaseBN | null | undefined, base?: number | 'hex', endian?: BaseBN.Endianness);
6
- }
7
- export { BaseBN };
8
+ //#endregion
9
+ export { BN, BaseBN };
package/esm/bn.js CHANGED
@@ -1,7 +1,11 @@
1
- import BaseBN from 'bn.js';
2
- export class BN extends BaseBN {
3
- constructor(value, base, endian) {
4
- super(value === null ? '0' : value, base, endian);
5
- }
6
- }
7
- export { BaseBN };
1
+ import BaseBN from "bn.js";
2
+
3
+ //#region src/bn.ts
4
+ var BN = class extends BaseBN {
5
+ constructor(value, base, endian) {
6
+ super(value === null ? "0" : value, base, endian);
7
+ }
8
+ };
9
+
10
+ //#endregion
11
+ export { BN, BaseBN };
package/esm/constant.d.ts CHANGED
@@ -1 +1,4 @@
1
- export declare const DEFAULT_TOKEN_DECIMAL = 18;
1
+ //#region src/constant.d.ts
2
+ declare const DEFAULT_TOKEN_DECIMAL = 18;
3
+ //#endregion
4
+ export { DEFAULT_TOKEN_DECIMAL };
package/esm/constant.js CHANGED
@@ -1 +1,5 @@
1
- export const DEFAULT_TOKEN_DECIMAL = 18;
1
+ //#region src/constant.ts
2
+ const DEFAULT_TOKEN_DECIMAL = 18;
3
+
4
+ //#endregion
5
+ export { DEFAULT_TOKEN_DECIMAL };
@@ -1 +1,4 @@
1
- export declare const createSortedList: (list: $TSFixMe) => any;
1
+ //#region src/create-sorted-list.d.ts
2
+ declare const createSortedList: (list: $TSFixMe) => unknown[];
3
+ //#endregion
4
+ export { createSortedList };
@@ -1,3 +1,8 @@
1
- import uniq from 'lodash/uniq';
2
- import flatten from 'lodash/flatten';
3
- export const createSortedList = (list) => uniq(flatten(list)).filter(Boolean).sort();
1
+ import uniq from "lodash/uniq.js";
2
+ import flatten from "lodash/flatten.js";
3
+
4
+ //#region src/create-sorted-list.ts
5
+ const createSortedList = (list) => uniq(flatten(list)).filter(Boolean).sort();
6
+
7
+ //#endregion
8
+ export { createSortedList };
package/esm/curve.d.ts CHANGED
@@ -1,84 +1,114 @@
1
- import { BN } from './index';
2
- export declare enum Direction {
3
- Mint = "mint",
4
- Burn = "burn"
1
+ import { BN } from "./bn.js";
2
+ import "./index.js";
3
+ import * as bn_js0 from "bn.js";
4
+
5
+ //#region src/curve.d.ts
6
+ declare enum Direction {
7
+ Mint = "mint",
8
+ Burn = "burn",
5
9
  }
6
10
  /**
7
11
  * Constant Curve
8
12
  * Price = fixedPrice
9
13
  */
10
- export declare function calcConstantPrice({ fixedPrice }: {
11
- fixedPrice: string;
14
+ declare function calcConstantPrice({
15
+ fixedPrice
16
+ }: {
17
+ fixedPrice: string;
12
18
  }): BN;
13
19
  /**
14
20
  * Constant Curve
15
21
  * Cost = amount * fixedPrice
16
22
  */
17
- export declare function calcConstantCost({ amount, fixedPrice, decimal, }: {
18
- amount: string;
19
- fixedPrice: string;
20
- decimal: number;
21
- }): import("bn.js");
23
+ declare function calcConstantCost({
24
+ amount,
25
+ fixedPrice,
26
+ decimal
27
+ }: {
28
+ amount: string;
29
+ fixedPrice: string;
30
+ decimal: number;
31
+ }): bn_js0;
22
32
  /**
23
33
  * linear Curve
24
34
  * Price = basePrice + slope * currentSupply
25
35
  */
26
- export declare function calcLinearPrice({ basePrice, slope, currentSupply, decimal, }: {
27
- basePrice: string;
28
- slope: string;
29
- currentSupply: string;
30
- decimal: number;
31
- }): import("bn.js");
36
+ declare function calcLinearPrice({
37
+ basePrice,
38
+ slope,
39
+ currentSupply,
40
+ decimal
41
+ }: {
42
+ basePrice: string;
43
+ slope: string;
44
+ currentSupply: string;
45
+ decimal: number;
46
+ }): bn_js0;
32
47
  /**
33
48
  * Linear Curve
34
49
  * mint Cost = (slope / 2) * ( (currentSupply + amount) ** 2 - currentSupply ** 2 ) + basePrice * amount;
35
50
  * burn Cost = (slope / 2) * ( currentSupply ** 2 - (currentSupply - amount) ** 2 ) + basePrice * amount;
36
51
  */
37
- export declare function calcLinearCost(params: {
38
- amount: string;
39
- currentSupply: string;
40
- basePrice: string;
41
- slope: string;
42
- decimal: number;
43
- direction: Direction;
44
- }): import("bn.js");
52
+ declare function calcLinearCost(params: {
53
+ amount: string;
54
+ currentSupply: string;
55
+ basePrice: string;
56
+ slope: string;
57
+ decimal: number;
58
+ direction: Direction;
59
+ }): bn_js0;
45
60
  /**
46
61
  * Quadratic Curve
47
62
  * Price = basePrice + currentSupply ** 2 / constant
48
63
  */
49
- export declare function calcQuadraticPrice(params: {
50
- basePrice: string;
51
- currentSupply: string;
52
- constant: string;
53
- decimal: number;
54
- }): import("bn.js");
64
+ declare function calcQuadraticPrice(params: {
65
+ basePrice: string;
66
+ currentSupply: string;
67
+ constant: string;
68
+ decimal: number;
69
+ }): bn_js0;
55
70
  /**
56
71
  * Quadratic Curve
57
72
  * Price = basePrice + currentSupply ** 2 / constant
58
73
  * mint Cost = ( (currentSupply + amount)^3 / 3 - currentSupply^3 / 3 ) / constant + basePrice * amount;
59
74
  * burn Cost = ( currentSupply^3 / 3 - (currentSupply - amount)^3 / 3 ) / constant + basePrice * amount;
60
75
  */
61
- export declare function calcQuadraticCost(params: {
62
- amount: string;
63
- currentSupply: string;
64
- basePrice: string;
65
- constant: string;
66
- decimal: number;
67
- direction: Direction;
68
- }): import("bn.js");
69
- export declare function calcFee({ reserveAmount, feeRate }: {
70
- reserveAmount: string;
71
- feeRate: string;
72
- }): import("bn.js");
73
- export declare function calcPrice({ currentSupply, decimal, curve }: {
74
- currentSupply: string;
75
- decimal: number;
76
- curve: any;
77
- }): import("bn.js");
78
- export declare function calcCost({ amount, decimal, currentSupply, direction, curve, }: {
79
- amount: string;
80
- decimal: number;
81
- currentSupply: string;
82
- curve: any;
83
- direction: Direction;
84
- }): import("bn.js");
76
+ declare function calcQuadraticCost(params: {
77
+ amount: string;
78
+ currentSupply: string;
79
+ basePrice: string;
80
+ constant: string;
81
+ decimal: number;
82
+ direction: Direction;
83
+ }): bn_js0;
84
+ declare function calcFee({
85
+ reserveAmount,
86
+ feeRate
87
+ }: {
88
+ reserveAmount: string;
89
+ feeRate: string;
90
+ }): bn_js0;
91
+ declare function calcPrice({
92
+ currentSupply,
93
+ decimal,
94
+ curve
95
+ }: {
96
+ currentSupply: string;
97
+ decimal: number;
98
+ curve: any;
99
+ }): bn_js0;
100
+ declare function calcCost({
101
+ amount,
102
+ decimal,
103
+ currentSupply,
104
+ direction,
105
+ curve
106
+ }: {
107
+ amount: string;
108
+ decimal: number;
109
+ currentSupply: string;
110
+ curve: any;
111
+ direction: Direction;
112
+ }): bn_js0;
113
+ //#endregion
114
+ export { Direction, calcConstantCost, calcConstantPrice, calcCost, calcFee, calcLinearCost, calcLinearPrice, calcPrice, calcQuadraticCost, calcQuadraticPrice };
package/esm/curve.js CHANGED
@@ -1,146 +1,151 @@
1
- import { BN } from './index';
1
+ import { BN } from "./bn.js";
2
+
3
+ //#region src/curve.ts
2
4
  const ZERO = new BN(0);
3
5
  const TWO = new BN(2);
4
6
  const THREE = new BN(3);
5
7
  const TEN = new BN(10);
6
- export var Direction;
7
- (function (Direction) {
8
- Direction["Mint"] = "mint";
9
- Direction["Burn"] = "burn";
10
- })(Direction || (Direction = {}));
8
+ let Direction = /* @__PURE__ */ function(Direction$1) {
9
+ Direction$1["Mint"] = "mint";
10
+ Direction$1["Burn"] = "burn";
11
+ return Direction$1;
12
+ }({});
11
13
  /**
12
- * Constant Curve
13
- * Price = fixedPrice
14
- */
15
- export function calcConstantPrice({ fixedPrice }) {
16
- return new BN(fixedPrice);
14
+ * Constant Curve
15
+ * Price = fixedPrice
16
+ */
17
+ function calcConstantPrice({ fixedPrice }) {
18
+ return new BN(fixedPrice);
17
19
  }
18
20
  /**
19
- * Constant Curve
20
- * Cost = amount * fixedPrice
21
- */
22
- export function calcConstantCost({ amount, fixedPrice, decimal, }) {
23
- const decimalFactor = TEN.pow(new BN(decimal));
24
- return new BN(amount).mul(new BN(fixedPrice)).div(decimalFactor);
21
+ * Constant Curve
22
+ * Cost = amount * fixedPrice
23
+ */
24
+ function calcConstantCost({ amount, fixedPrice, decimal }) {
25
+ const decimalFactor = TEN.pow(new BN(decimal));
26
+ return new BN(amount).mul(new BN(fixedPrice)).div(decimalFactor);
25
27
  }
26
28
  /**
27
- * linear Curve
28
- * Price = basePrice + slope * currentSupply
29
- */
30
- export function calcLinearPrice({ basePrice, slope, currentSupply, decimal, }) {
31
- const decimalFactor = TEN.pow(new BN(decimal));
32
- return new BN(basePrice).add(new BN(slope).mul(new BN(currentSupply)).div(decimalFactor));
29
+ * linear Curve
30
+ * Price = basePrice + slope * currentSupply
31
+ */
32
+ function calcLinearPrice({ basePrice, slope, currentSupply, decimal }) {
33
+ const decimalFactor = TEN.pow(new BN(decimal));
34
+ return new BN(basePrice).add(new BN(slope).mul(new BN(currentSupply)).div(decimalFactor));
33
35
  }
34
36
  /**
35
- * Linear Curve
36
- * mint Cost = (slope / 2) * ( (currentSupply + amount) ** 2 - currentSupply ** 2 ) + basePrice * amount;
37
- * burn Cost = (slope / 2) * ( currentSupply ** 2 - (currentSupply - amount) ** 2 ) + basePrice * amount;
38
- */
39
- export function calcLinearCost(params) {
40
- const amount = new BN(params.amount);
41
- const currentSupply = new BN(params.currentSupply);
42
- const basePrice = new BN(params.basePrice);
43
- const slope = new BN(params.slope);
44
- const decimalFactor = TEN.pow(new BN(params.decimal));
45
- if (slope.lte(ZERO))
46
- throw new Error('INVALID_SLOPE');
47
- if (amount.lt(ZERO))
48
- throw new Error('INVALID_AMOUNT');
49
- if (currentSupply.lt(ZERO))
50
- throw new Error('INVALID_CURRENT_SUPPLY');
51
- if (basePrice.lt(ZERO))
52
- throw new Error('INVALID_BASE_PRICE');
53
- if (decimalFactor.lte(ZERO))
54
- throw new Error('INVALID_DECIMAL_FACTOR');
55
- if (params.direction === Direction.Burn && amount.gt(currentSupply)) {
56
- throw new Error('SUPPLY_INSUFFICIENT');
57
- }
58
- const integralDelta = params.direction === Direction.Mint
59
- ? amount.mul(currentSupply.mul(TWO).add(amount)) // (currentSupply + amount) ** 2 - currentSupply ** 2 = amount * (2 * currentSupply + amount)
60
- : amount.mul(currentSupply.mul(TWO).sub(amount)); // currentSupply ** 2 - (currentSupply - amount) ** 2 = amount * (2 * currentSupply - amount)
61
- const linearTerm = basePrice.mul(amount).div(decimalFactor);
62
- const integralTerm = slope.mul(integralDelta).div(TWO.mul(decimalFactor.sqr()));
63
- return linearTerm.add(integralTerm);
37
+ * Linear Curve
38
+ * mint Cost = (slope / 2) * ( (currentSupply + amount) ** 2 - currentSupply ** 2 ) + basePrice * amount;
39
+ * burn Cost = (slope / 2) * ( currentSupply ** 2 - (currentSupply - amount) ** 2 ) + basePrice * amount;
40
+ */
41
+ function calcLinearCost(params) {
42
+ const amount = new BN(params.amount);
43
+ const currentSupply = new BN(params.currentSupply);
44
+ const basePrice = new BN(params.basePrice);
45
+ const slope = new BN(params.slope);
46
+ const decimalFactor = TEN.pow(new BN(params.decimal));
47
+ if (slope.lte(ZERO)) throw new Error("INVALID_SLOPE");
48
+ if (amount.lt(ZERO)) throw new Error("INVALID_AMOUNT");
49
+ if (currentSupply.lt(ZERO)) throw new Error("INVALID_CURRENT_SUPPLY");
50
+ if (basePrice.lt(ZERO)) throw new Error("INVALID_BASE_PRICE");
51
+ if (decimalFactor.lte(ZERO)) throw new Error("INVALID_DECIMAL_FACTOR");
52
+ if (params.direction === Direction.Burn && amount.gt(currentSupply)) throw new Error("SUPPLY_INSUFFICIENT");
53
+ const integralDelta = params.direction === Direction.Mint ? amount.mul(currentSupply.mul(TWO).add(amount)) : amount.mul(currentSupply.mul(TWO).sub(amount));
54
+ const linearTerm = basePrice.mul(amount).div(decimalFactor);
55
+ const integralTerm = slope.mul(integralDelta).div(TWO.mul(decimalFactor.sqr()));
56
+ return linearTerm.add(integralTerm);
64
57
  }
65
58
  /**
66
- * Quadratic Curve
67
- * Price = basePrice + currentSupply ** 2 / constant
68
- */
69
- export function calcQuadraticPrice(params) {
70
- const basePrice = new BN(params.basePrice);
71
- const currentSupply = new BN(params.currentSupply);
72
- const constant = new BN(params.constant);
73
- const decimalFactor = TEN.pow(new BN(params.decimal)); // 10^decimal
74
- if (constant.lte(ZERO))
75
- throw new Error('INVALID_CONSTANT');
76
- if (currentSupply.lt(ZERO))
77
- throw new Error('INVALID_CURRENT_SUPPLY');
78
- if (basePrice.lt(ZERO))
79
- throw new Error('INVALID_BASE_PRICE');
80
- if (decimalFactor.lte(ZERO))
81
- throw new Error('INVALID_DECIMAL_FACTOR');
82
- // Single division to reduce double-flooring error
83
- const denom = constant.mul(decimalFactor);
84
- const a = currentSupply.sqr().div(denom);
85
- return basePrice.add(a);
59
+ * Quadratic Curve
60
+ * Price = basePrice + currentSupply ** 2 / constant
61
+ */
62
+ function calcQuadraticPrice(params) {
63
+ const basePrice = new BN(params.basePrice);
64
+ const currentSupply = new BN(params.currentSupply);
65
+ const constant = new BN(params.constant);
66
+ const decimalFactor = TEN.pow(new BN(params.decimal));
67
+ if (constant.lte(ZERO)) throw new Error("INVALID_CONSTANT");
68
+ if (currentSupply.lt(ZERO)) throw new Error("INVALID_CURRENT_SUPPLY");
69
+ if (basePrice.lt(ZERO)) throw new Error("INVALID_BASE_PRICE");
70
+ if (decimalFactor.lte(ZERO)) throw new Error("INVALID_DECIMAL_FACTOR");
71
+ const denom = constant.mul(decimalFactor);
72
+ const a = currentSupply.sqr().div(denom);
73
+ return basePrice.add(a);
86
74
  }
87
75
  /**
88
- * Quadratic Curve
89
- * Price = basePrice + currentSupply ** 2 / constant
90
- * mint Cost = ( (currentSupply + amount)^3 / 3 - currentSupply^3 / 3 ) / constant + basePrice * amount;
91
- * burn Cost = ( currentSupply^3 / 3 - (currentSupply - amount)^3 / 3 ) / constant + basePrice * amount;
92
- */
93
- export function calcQuadraticCost(params) {
94
- const amount = new BN(params.amount);
95
- const currentSupply = new BN(params.currentSupply);
96
- const basePrice = new BN(params.basePrice);
97
- const constant = new BN(params.constant);
98
- const decimalFactor = TEN.pow(new BN(params.decimal)); // M = 10^decimal
99
- // Basic validations
100
- if (constant.lte(ZERO))
101
- throw new Error('INVALID_CONSTANT');
102
- if (amount.lt(ZERO))
103
- throw new Error('INVALID_AMOUNT');
104
- if (amount.isZero())
105
- return ZERO;
106
- // Compute new supply with direction guard
107
- const newSupply = params.direction === Direction.Mint ? currentSupply.add(amount) : currentSupply.sub(amount);
108
- if (params.direction === Direction.Burn && newSupply.lt(ZERO)) {
109
- throw new Error('SUPPLY_INSUFFICIENT');
110
- }
111
- // cubicDelta = |S1^3 - S0^3| = (S1 - S0) * (S1^2 + S1 * S0 + S0^2)
112
- const diff = params.direction === Direction.Mint ? newSupply.sub(currentSupply) : currentSupply.sub(newSupply);
113
- const sumSquaresAndProduct = newSupply.sqr().add(newSupply.mul(currentSupply)).add(currentSupply.sqr());
114
- const cubicDelta = diff.mul(sumSquaresAndProduct);
115
- // integral term: (S1^3 - S0^3) / (3 * constant * M^2)
116
- const denom = THREE.mul(constant).mul(decimalFactor.sqr());
117
- const cubicCost = cubicDelta.div(denom);
118
- // linear term: basePrice * amount / M
119
- const linearCost = basePrice.mul(amount).div(decimalFactor);
120
- return cubicCost.add(linearCost);
76
+ * Quadratic Curve
77
+ * Price = basePrice + currentSupply ** 2 / constant
78
+ * mint Cost = ( (currentSupply + amount)^3 / 3 - currentSupply^3 / 3 ) / constant + basePrice * amount;
79
+ * burn Cost = ( currentSupply^3 / 3 - (currentSupply - amount)^3 / 3 ) / constant + basePrice * amount;
80
+ */
81
+ function calcQuadraticCost(params) {
82
+ const amount = new BN(params.amount);
83
+ const currentSupply = new BN(params.currentSupply);
84
+ const basePrice = new BN(params.basePrice);
85
+ const constant = new BN(params.constant);
86
+ const decimalFactor = TEN.pow(new BN(params.decimal));
87
+ if (constant.lte(ZERO)) throw new Error("INVALID_CONSTANT");
88
+ if (amount.lt(ZERO)) throw new Error("INVALID_AMOUNT");
89
+ if (amount.isZero()) return ZERO;
90
+ const newSupply = params.direction === Direction.Mint ? currentSupply.add(amount) : currentSupply.sub(amount);
91
+ if (params.direction === Direction.Burn && newSupply.lt(ZERO)) throw new Error("SUPPLY_INSUFFICIENT");
92
+ const diff = params.direction === Direction.Mint ? newSupply.sub(currentSupply) : currentSupply.sub(newSupply);
93
+ const sumSquaresAndProduct = newSupply.sqr().add(newSupply.mul(currentSupply)).add(currentSupply.sqr());
94
+ const cubicDelta = diff.mul(sumSquaresAndProduct);
95
+ const denom = THREE.mul(constant).mul(decimalFactor.sqr());
96
+ const cubicCost = cubicDelta.div(denom);
97
+ const linearCost = basePrice.mul(amount).div(decimalFactor);
98
+ return cubicCost.add(linearCost);
121
99
  }
122
- export function calcFee({ reserveAmount, feeRate }) {
123
- return new BN(reserveAmount).mul(new BN(feeRate)).div(new BN(10000));
100
+ function calcFee({ reserveAmount, feeRate }) {
101
+ return new BN(reserveAmount).mul(new BN(feeRate)).div(new BN(1e4));
124
102
  }
125
- export function calcPrice({ currentSupply, decimal, curve }) {
126
- const calculator = {
127
- constant: () => calcConstantPrice({ currentSupply, decimal, ...curve }),
128
- linear: () => calcLinearPrice({ currentSupply, decimal, ...curve }),
129
- quadratic: () => calcQuadraticPrice({ currentSupply, decimal, ...curve }),
130
- }[curve.type];
131
- if (!calculator) {
132
- throw new Error('INVALID_CURVE_TYPE');
133
- }
134
- return calculator();
103
+ function calcPrice({ currentSupply, decimal, curve }) {
104
+ const calculator = {
105
+ constant: () => calcConstantPrice({
106
+ currentSupply,
107
+ decimal,
108
+ ...curve
109
+ }),
110
+ linear: () => calcLinearPrice({
111
+ currentSupply,
112
+ decimal,
113
+ ...curve
114
+ }),
115
+ quadratic: () => calcQuadraticPrice({
116
+ currentSupply,
117
+ decimal,
118
+ ...curve
119
+ })
120
+ }[curve.type];
121
+ if (!calculator) throw new Error("INVALID_CURVE_TYPE");
122
+ return calculator();
135
123
  }
136
- export function calcCost({ amount, decimal, currentSupply, direction, curve, }) {
137
- const calculator = {
138
- constant: () => calcConstantCost({ amount, decimal, ...curve }),
139
- linear: () => calcLinearCost({ amount, decimal, currentSupply, direction, ...curve }),
140
- quadratic: () => calcQuadraticCost({ amount, decimal, currentSupply, direction, ...curve }),
141
- }[curve.type];
142
- if (!calculator) {
143
- throw new Error('INVALID_CURVE_TYPE');
144
- }
145
- return calculator();
124
+ function calcCost({ amount, decimal, currentSupply, direction, curve }) {
125
+ const calculator = {
126
+ constant: () => calcConstantCost({
127
+ amount,
128
+ decimal,
129
+ ...curve
130
+ }),
131
+ linear: () => calcLinearCost({
132
+ amount,
133
+ decimal,
134
+ currentSupply,
135
+ direction,
136
+ ...curve
137
+ }),
138
+ quadratic: () => calcQuadraticCost({
139
+ amount,
140
+ decimal,
141
+ currentSupply,
142
+ direction,
143
+ ...curve
144
+ })
145
+ }[curve.type];
146
+ if (!calculator) throw new Error("INVALID_CURVE_TYPE");
147
+ return calculator();
146
148
  }
149
+
150
+ //#endregion
151
+ export { Direction, calcConstantCost, calcConstantPrice, calcCost, calcFee, calcLinearCost, calcLinearPrice, calcPrice, calcQuadraticCost, calcQuadraticPrice };
package/esm/error.d.ts CHANGED
@@ -1,11 +1,14 @@
1
- export declare class CustomError extends Error {
2
- code: string;
3
- props: {
4
- persist: boolean;
5
- [prop: string]: $TSFixMe;
6
- };
7
- constructor(code: string, message: string, props?: {});
1
+ //#region src/error.d.ts
2
+ declare class CustomError extends Error {
3
+ code: string;
4
+ props: {
5
+ persist: boolean;
6
+ [prop: string]: $TSFixMe;
7
+ };
8
+ constructor(code: string, message: string, props?: {});
8
9
  }
9
- export declare class PersistError extends CustomError {
10
- constructor(code: string, message: string, props?: {});
10
+ declare class PersistError extends CustomError {
11
+ constructor(code: string, message: string, props?: {});
11
12
  }
13
+ //#endregion
14
+ export { CustomError, PersistError };
package/esm/error.js CHANGED
@@ -1,17 +1,24 @@
1
- /* eslint-disable max-classes-per-file */
2
- export class CustomError extends Error {
3
- constructor(code, message, props = {}) {
4
- super(message);
5
- if (Error.captureStackTrace) {
6
- Error.captureStackTrace(this, CustomError);
7
- }
8
- this.code = code;
9
- this.props = { persist: false, ...props };
10
- }
11
- }
12
- export class PersistError extends CustomError {
13
- constructor(code, message, props = {}) {
14
- super(code, message);
15
- this.props = { persist: true, ...props };
16
- }
17
- }
1
+ //#region src/error.ts
2
+ var CustomError = class CustomError extends Error {
3
+ constructor(code, message, props = {}) {
4
+ super(message);
5
+ if (Error.captureStackTrace) Error.captureStackTrace(this, CustomError);
6
+ this.code = code;
7
+ this.props = {
8
+ persist: false,
9
+ ...props
10
+ };
11
+ }
12
+ };
13
+ var PersistError = class extends CustomError {
14
+ constructor(code, message, props = {}) {
15
+ super(code, message);
16
+ this.props = {
17
+ persist: true,
18
+ ...props
19
+ };
20
+ }
21
+ };
22
+
23
+ //#endregion
24
+ export { CustomError, PersistError };
@@ -1 +1,4 @@
1
- export declare const getListField: (obj: $TSFixMe, key: string) => any;
1
+ //#region src/get-list-field.d.ts
2
+ declare const getListField: (obj: $TSFixMe, key: string) => any;
3
+ //#endregion
4
+ export { getListField };
@@ -1,2 +1,7 @@
1
- import get from 'lodash/get';
2
- export const getListField = (obj, key) => get(obj, `${key}List`) || get(obj, key) || [];
1
+ import get from "lodash/get.js";
2
+
3
+ //#region src/get-list-field.ts
4
+ const getListField = (obj, key) => get(obj, `${key}List`) || get(obj, key) || [];
5
+
6
+ //#endregion
7
+ export { getListField };
@@ -1 +1,4 @@
1
- export declare const getRelatedAddresses: (state: $TSFixMe) => any[];
1
+ //#region src/get-related-addr.d.ts
2
+ declare const getRelatedAddresses: (state: $TSFixMe) => any[];
3
+ //#endregion
4
+ export { getRelatedAddresses };
@@ -1 +1,5 @@
1
- export const getRelatedAddresses = (state) => [state.address].concat(state.migratedFrom || []).filter(Boolean);
1
+ //#region src/get-related-addr.ts
2
+ const getRelatedAddresses = (state) => [state.address].concat(state.migratedFrom || []).filter(Boolean);
3
+
4
+ //#endregion
5
+ export { getRelatedAddresses };