@ocap/util 1.27.16 → 1.28.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/esm/bn.d.ts +8 -6
- package/esm/bn.js +11 -7
- package/esm/constant.d.ts +4 -1
- package/esm/constant.js +5 -1
- package/esm/create-sorted-list.d.ts +4 -1
- package/esm/create-sorted-list.js +8 -3
- package/esm/curve.d.ts +85 -55
- package/esm/curve.js +132 -127
- package/esm/error.d.ts +12 -9
- package/esm/error.js +24 -17
- package/esm/get-list-field.d.ts +4 -1
- package/esm/get-list-field.js +7 -2
- package/esm/get-related-addr.d.ts +4 -1
- package/esm/get-related-addr.js +5 -1
- package/esm/index.d.ts +47 -44
- package/esm/index.js +364 -469
- package/esm/lodash.d.ts +12 -0
- package/esm/md5.d.ts +4 -1
- package/esm/md5.js +7 -3
- package/esm/ready.d.ts +13 -9
- package/esm/ready.js +33 -36
- package/esm/retry.d.ts +16 -9
- package/esm/retry.js +26 -27
- package/esm/tsfixme.d.ts +3 -0
- package/esm/url.d.ts +16 -12
- package/esm/url.js +67 -92
- package/lib/_virtual/rolldown_runtime.js +29 -0
- package/lib/bn.d.ts +8 -6
- package/lib/bn.js +12 -12
- package/lib/constant.d.ts +4 -1
- package/lib/constant.js +6 -4
- package/lib/create-sorted-list.d.ts +4 -1
- package/lib/create-sorted-list.js +11 -10
- package/lib/curve.d.ts +84 -55
- package/lib/curve.js +139 -137
- package/lib/error.d.ts +12 -9
- package/lib/error.js +25 -21
- package/lib/get-list-field.d.ts +4 -1
- package/lib/get-list-field.js +9 -9
- package/lib/get-related-addr.d.ts +4 -1
- package/lib/get-related-addr.js +5 -4
- package/lib/index.d.ts +47 -44
- package/lib/index.js +386 -506
- package/lib/lodash.d.ts +12 -0
- package/lib/md5.d.ts +4 -1
- package/lib/md5.js +9 -10
- package/lib/ready.d.ts +13 -9
- package/lib/ready.js +34 -42
- package/lib/retry.d.ts +16 -9
- package/lib/retry.js +27 -30
- package/lib/tsfixme.d.ts +3 -0
- package/lib/url.d.ts +16 -12
- package/lib/url.js +69 -118
- package/package.json +23 -9
package/esm/bn.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import BaseBN from
|
|
2
|
-
|
|
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
|
-
|
|
5
|
-
|
|
6
|
-
}
|
|
7
|
-
export { BaseBN };
|
|
8
|
+
//#endregion
|
|
9
|
+
export { BN, BaseBN };
|
package/esm/bn.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
|
-
import BaseBN from
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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
package/esm/constant.js
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
-
import uniq from
|
|
2
|
-
import flatten from
|
|
3
|
-
|
|
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
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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
|
-
|
|
11
|
-
|
|
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
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}
|
|
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
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
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
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}):
|
|
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
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}):
|
|
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
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
}):
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
}):
|
|
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
|
|
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
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
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
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
* Constant Curve
|
|
15
|
+
* Price = fixedPrice
|
|
16
|
+
*/
|
|
17
|
+
function calcConstantPrice({ fixedPrice }) {
|
|
18
|
+
return new BN(fixedPrice);
|
|
17
19
|
}
|
|
18
20
|
/**
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
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
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
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
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
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
|
-
|
|
123
|
-
|
|
100
|
+
function calcFee({ reserveAmount, feeRate }) {
|
|
101
|
+
return new BN(reserveAmount).mul(new BN(feeRate)).div(new BN(1e4));
|
|
124
102
|
}
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
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
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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
|
-
|
|
10
|
-
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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 };
|
package/esm/get-list-field.d.ts
CHANGED
package/esm/get-list-field.js
CHANGED
|
@@ -1,2 +1,7 @@
|
|
|
1
|
-
import get from
|
|
2
|
-
|
|
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 };
|
package/esm/get-related-addr.js
CHANGED
|
@@ -1 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
//#region src/get-related-addr.ts
|
|
2
|
+
const getRelatedAddresses = (state) => [state.address].concat(state.migratedFrom || []).filter(Boolean);
|
|
3
|
+
|
|
4
|
+
//#endregion
|
|
5
|
+
export { getRelatedAddresses };
|