@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/lib/curve.d.ts
CHANGED
|
@@ -1,84 +1,113 @@
|
|
|
1
|
-
import { BN } from
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { BN } from "./bn.js";
|
|
2
|
+
import * as bn_js0 from "bn.js";
|
|
3
|
+
|
|
4
|
+
//#region src/curve.d.ts
|
|
5
|
+
declare enum Direction {
|
|
6
|
+
Mint = "mint",
|
|
7
|
+
Burn = "burn",
|
|
5
8
|
}
|
|
6
9
|
/**
|
|
7
10
|
* Constant Curve
|
|
8
11
|
* Price = fixedPrice
|
|
9
12
|
*/
|
|
10
|
-
|
|
11
|
-
|
|
13
|
+
declare function calcConstantPrice({
|
|
14
|
+
fixedPrice
|
|
15
|
+
}: {
|
|
16
|
+
fixedPrice: string;
|
|
12
17
|
}): BN;
|
|
13
18
|
/**
|
|
14
19
|
* Constant Curve
|
|
15
20
|
* Cost = amount * fixedPrice
|
|
16
21
|
*/
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}
|
|
22
|
+
declare function calcConstantCost({
|
|
23
|
+
amount,
|
|
24
|
+
fixedPrice,
|
|
25
|
+
decimal
|
|
26
|
+
}: {
|
|
27
|
+
amount: string;
|
|
28
|
+
fixedPrice: string;
|
|
29
|
+
decimal: number;
|
|
30
|
+
}): bn_js0;
|
|
22
31
|
/**
|
|
23
32
|
* linear Curve
|
|
24
33
|
* Price = basePrice + slope * currentSupply
|
|
25
34
|
*/
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
35
|
+
declare function calcLinearPrice({
|
|
36
|
+
basePrice,
|
|
37
|
+
slope,
|
|
38
|
+
currentSupply,
|
|
39
|
+
decimal
|
|
40
|
+
}: {
|
|
41
|
+
basePrice: string;
|
|
42
|
+
slope: string;
|
|
43
|
+
currentSupply: string;
|
|
44
|
+
decimal: number;
|
|
45
|
+
}): bn_js0;
|
|
32
46
|
/**
|
|
33
47
|
* Linear Curve
|
|
34
48
|
* mint Cost = (slope / 2) * ( (currentSupply + amount) ** 2 - currentSupply ** 2 ) + basePrice * amount;
|
|
35
49
|
* burn Cost = (slope / 2) * ( currentSupply ** 2 - (currentSupply - amount) ** 2 ) + basePrice * amount;
|
|
36
50
|
*/
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}):
|
|
51
|
+
declare function calcLinearCost(params: {
|
|
52
|
+
amount: string;
|
|
53
|
+
currentSupply: string;
|
|
54
|
+
basePrice: string;
|
|
55
|
+
slope: string;
|
|
56
|
+
decimal: number;
|
|
57
|
+
direction: Direction;
|
|
58
|
+
}): bn_js0;
|
|
45
59
|
/**
|
|
46
60
|
* Quadratic Curve
|
|
47
61
|
* Price = basePrice + currentSupply ** 2 / constant
|
|
48
62
|
*/
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}):
|
|
63
|
+
declare function calcQuadraticPrice(params: {
|
|
64
|
+
basePrice: string;
|
|
65
|
+
currentSupply: string;
|
|
66
|
+
constant: string;
|
|
67
|
+
decimal: number;
|
|
68
|
+
}): bn_js0;
|
|
55
69
|
/**
|
|
56
70
|
* Quadratic Curve
|
|
57
71
|
* Price = basePrice + currentSupply ** 2 / constant
|
|
58
72
|
* mint Cost = ( (currentSupply + amount)^3 / 3 - currentSupply^3 / 3 ) / constant + basePrice * amount;
|
|
59
73
|
* burn Cost = ( currentSupply^3 / 3 - (currentSupply - amount)^3 / 3 ) / constant + basePrice * amount;
|
|
60
74
|
*/
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
}):
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
}):
|
|
75
|
+
declare function calcQuadraticCost(params: {
|
|
76
|
+
amount: string;
|
|
77
|
+
currentSupply: string;
|
|
78
|
+
basePrice: string;
|
|
79
|
+
constant: string;
|
|
80
|
+
decimal: number;
|
|
81
|
+
direction: Direction;
|
|
82
|
+
}): bn_js0;
|
|
83
|
+
declare function calcFee({
|
|
84
|
+
reserveAmount,
|
|
85
|
+
feeRate
|
|
86
|
+
}: {
|
|
87
|
+
reserveAmount: string;
|
|
88
|
+
feeRate: string;
|
|
89
|
+
}): bn_js0;
|
|
90
|
+
declare function calcPrice({
|
|
91
|
+
currentSupply,
|
|
92
|
+
decimal,
|
|
93
|
+
curve
|
|
94
|
+
}: {
|
|
95
|
+
currentSupply: string;
|
|
96
|
+
decimal: number;
|
|
97
|
+
curve: any;
|
|
98
|
+
}): bn_js0;
|
|
99
|
+
declare function calcCost({
|
|
100
|
+
amount,
|
|
101
|
+
decimal,
|
|
102
|
+
currentSupply,
|
|
103
|
+
direction,
|
|
104
|
+
curve
|
|
105
|
+
}: {
|
|
106
|
+
amount: string;
|
|
107
|
+
decimal: number;
|
|
108
|
+
currentSupply: string;
|
|
109
|
+
curve: any;
|
|
110
|
+
direction: Direction;
|
|
111
|
+
}): bn_js0;
|
|
112
|
+
//#endregion
|
|
113
|
+
export { Direction, calcConstantCost, calcConstantPrice, calcCost, calcFee, calcLinearCost, calcLinearPrice, calcPrice, calcQuadraticCost, calcQuadraticPrice };
|
package/lib/curve.js
CHANGED
|
@@ -1,158 +1,160 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const index_1 = require("./index");
|
|
14
|
-
const ZERO = new index_1.BN(0);
|
|
15
|
-
const TWO = new index_1.BN(2);
|
|
16
|
-
const THREE = new index_1.BN(3);
|
|
17
|
-
const TEN = new index_1.BN(10);
|
|
18
|
-
var Direction;
|
|
19
|
-
(function (Direction) {
|
|
20
|
-
Direction["Mint"] = "mint";
|
|
21
|
-
Direction["Burn"] = "burn";
|
|
22
|
-
})(Direction || (exports.Direction = Direction = {}));
|
|
1
|
+
const require_bn = require('./bn.js');
|
|
2
|
+
|
|
3
|
+
//#region src/curve.ts
|
|
4
|
+
const ZERO = new require_bn.BN(0);
|
|
5
|
+
const TWO = new require_bn.BN(2);
|
|
6
|
+
const THREE = new require_bn.BN(3);
|
|
7
|
+
const TEN = new require_bn.BN(10);
|
|
8
|
+
let Direction = /* @__PURE__ */ function(Direction$1) {
|
|
9
|
+
Direction$1["Mint"] = "mint";
|
|
10
|
+
Direction$1["Burn"] = "burn";
|
|
11
|
+
return Direction$1;
|
|
12
|
+
}({});
|
|
23
13
|
/**
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
14
|
+
* Constant Curve
|
|
15
|
+
* Price = fixedPrice
|
|
16
|
+
*/
|
|
27
17
|
function calcConstantPrice({ fixedPrice }) {
|
|
28
|
-
|
|
18
|
+
return new require_bn.BN(fixedPrice);
|
|
29
19
|
}
|
|
30
20
|
/**
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
function calcConstantCost({ amount, fixedPrice, decimal
|
|
35
|
-
|
|
36
|
-
|
|
21
|
+
* Constant Curve
|
|
22
|
+
* Cost = amount * fixedPrice
|
|
23
|
+
*/
|
|
24
|
+
function calcConstantCost({ amount, fixedPrice, decimal }) {
|
|
25
|
+
const decimalFactor = TEN.pow(new require_bn.BN(decimal));
|
|
26
|
+
return new require_bn.BN(amount).mul(new require_bn.BN(fixedPrice)).div(decimalFactor);
|
|
37
27
|
}
|
|
38
28
|
/**
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
function calcLinearPrice({ basePrice, slope, currentSupply, decimal
|
|
43
|
-
|
|
44
|
-
|
|
29
|
+
* linear Curve
|
|
30
|
+
* Price = basePrice + slope * currentSupply
|
|
31
|
+
*/
|
|
32
|
+
function calcLinearPrice({ basePrice, slope, currentSupply, decimal }) {
|
|
33
|
+
const decimalFactor = TEN.pow(new require_bn.BN(decimal));
|
|
34
|
+
return new require_bn.BN(basePrice).add(new require_bn.BN(slope).mul(new require_bn.BN(currentSupply)).div(decimalFactor));
|
|
45
35
|
}
|
|
46
36
|
/**
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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
|
+
*/
|
|
51
41
|
function calcLinearCost(params) {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
if (params.direction === Direction.Burn && amount.gt(currentSupply)) {
|
|
68
|
-
throw new Error('SUPPLY_INSUFFICIENT');
|
|
69
|
-
}
|
|
70
|
-
const integralDelta = params.direction === Direction.Mint
|
|
71
|
-
? amount.mul(currentSupply.mul(TWO).add(amount)) // (currentSupply + amount) ** 2 - currentSupply ** 2 = amount * (2 * currentSupply + amount)
|
|
72
|
-
: amount.mul(currentSupply.mul(TWO).sub(amount)); // currentSupply ** 2 - (currentSupply - amount) ** 2 = amount * (2 * currentSupply - amount)
|
|
73
|
-
const linearTerm = basePrice.mul(amount).div(decimalFactor);
|
|
74
|
-
const integralTerm = slope.mul(integralDelta).div(TWO.mul(decimalFactor.sqr()));
|
|
75
|
-
return linearTerm.add(integralTerm);
|
|
42
|
+
const amount = new require_bn.BN(params.amount);
|
|
43
|
+
const currentSupply = new require_bn.BN(params.currentSupply);
|
|
44
|
+
const basePrice = new require_bn.BN(params.basePrice);
|
|
45
|
+
const slope = new require_bn.BN(params.slope);
|
|
46
|
+
const decimalFactor = TEN.pow(new require_bn.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);
|
|
76
57
|
}
|
|
77
58
|
/**
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
59
|
+
* Quadratic Curve
|
|
60
|
+
* Price = basePrice + currentSupply ** 2 / constant
|
|
61
|
+
*/
|
|
81
62
|
function calcQuadraticPrice(params) {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
throw new Error('INVALID_DECIMAL_FACTOR');
|
|
94
|
-
// Single division to reduce double-flooring error
|
|
95
|
-
const denom = constant.mul(decimalFactor);
|
|
96
|
-
const a = currentSupply.sqr().div(denom);
|
|
97
|
-
return basePrice.add(a);
|
|
63
|
+
const basePrice = new require_bn.BN(params.basePrice);
|
|
64
|
+
const currentSupply = new require_bn.BN(params.currentSupply);
|
|
65
|
+
const constant = new require_bn.BN(params.constant);
|
|
66
|
+
const decimalFactor = TEN.pow(new require_bn.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);
|
|
98
74
|
}
|
|
99
75
|
/**
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
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
|
+
*/
|
|
105
81
|
function calcQuadraticCost(params) {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
// cubicDelta = |S1^3 - S0^3| = (S1 - S0) * (S1^2 + S1 * S0 + S0^2)
|
|
124
|
-
const diff = params.direction === Direction.Mint ? newSupply.sub(currentSupply) : currentSupply.sub(newSupply);
|
|
125
|
-
const sumSquaresAndProduct = newSupply.sqr().add(newSupply.mul(currentSupply)).add(currentSupply.sqr());
|
|
126
|
-
const cubicDelta = diff.mul(sumSquaresAndProduct);
|
|
127
|
-
// integral term: (S1^3 - S0^3) / (3 * constant * M^2)
|
|
128
|
-
const denom = THREE.mul(constant).mul(decimalFactor.sqr());
|
|
129
|
-
const cubicCost = cubicDelta.div(denom);
|
|
130
|
-
// linear term: basePrice * amount / M
|
|
131
|
-
const linearCost = basePrice.mul(amount).div(decimalFactor);
|
|
132
|
-
return cubicCost.add(linearCost);
|
|
82
|
+
const amount = new require_bn.BN(params.amount);
|
|
83
|
+
const currentSupply = new require_bn.BN(params.currentSupply);
|
|
84
|
+
const basePrice = new require_bn.BN(params.basePrice);
|
|
85
|
+
const constant = new require_bn.BN(params.constant);
|
|
86
|
+
const decimalFactor = TEN.pow(new require_bn.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);
|
|
133
99
|
}
|
|
134
100
|
function calcFee({ reserveAmount, feeRate }) {
|
|
135
|
-
|
|
101
|
+
return new require_bn.BN(reserveAmount).mul(new require_bn.BN(feeRate)).div(new require_bn.BN(1e4));
|
|
136
102
|
}
|
|
137
103
|
function calcPrice({ currentSupply, decimal, curve }) {
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
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();
|
|
147
123
|
}
|
|
148
|
-
function calcCost({ amount, decimal, currentSupply, direction, curve
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
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();
|
|
158
148
|
}
|
|
149
|
+
|
|
150
|
+
//#endregion
|
|
151
|
+
exports.Direction = Direction;
|
|
152
|
+
exports.calcConstantCost = calcConstantCost;
|
|
153
|
+
exports.calcConstantPrice = calcConstantPrice;
|
|
154
|
+
exports.calcCost = calcCost;
|
|
155
|
+
exports.calcFee = calcFee;
|
|
156
|
+
exports.calcLinearCost = calcLinearCost;
|
|
157
|
+
exports.calcLinearPrice = calcLinearPrice;
|
|
158
|
+
exports.calcPrice = calcPrice;
|
|
159
|
+
exports.calcQuadraticCost = calcQuadraticCost;
|
|
160
|
+
exports.calcQuadraticPrice = calcQuadraticPrice;
|
package/lib/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/lib/error.js
CHANGED
|
@@ -1,22 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
1
|
+
|
|
2
|
+
//#region src/error.ts
|
|
3
|
+
var CustomError = class CustomError extends Error {
|
|
4
|
+
constructor(code, message, props = {}) {
|
|
5
|
+
super(message);
|
|
6
|
+
if (Error.captureStackTrace) Error.captureStackTrace(this, CustomError);
|
|
7
|
+
this.code = code;
|
|
8
|
+
this.props = {
|
|
9
|
+
persist: false,
|
|
10
|
+
...props
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
var PersistError = class extends CustomError {
|
|
15
|
+
constructor(code, message, props = {}) {
|
|
16
|
+
super(code, message);
|
|
17
|
+
this.props = {
|
|
18
|
+
persist: true,
|
|
19
|
+
...props
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
//#endregion
|
|
15
25
|
exports.CustomError = CustomError;
|
|
16
|
-
|
|
17
|
-
constructor(code, message, props = {}) {
|
|
18
|
-
super(code, message);
|
|
19
|
-
this.props = { persist: true, ...props };
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
exports.PersistError = PersistError;
|
|
26
|
+
exports.PersistError = PersistError;
|
package/lib/get-list-field.d.ts
CHANGED
package/lib/get-list-field.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
exports.getListField = getListField;
|
|
1
|
+
const require_rolldown_runtime = require('./_virtual/rolldown_runtime.js');
|
|
2
|
+
let lodash_get = require("lodash/get");
|
|
3
|
+
lodash_get = require_rolldown_runtime.__toESM(lodash_get);
|
|
4
|
+
|
|
5
|
+
//#region src/get-list-field.ts
|
|
6
|
+
const getListField = (obj, key) => (0, lodash_get.default)(obj, `${key}List`) || (0, lodash_get.default)(obj, key) || [];
|
|
7
|
+
|
|
8
|
+
//#endregion
|
|
9
|
+
exports.getListField = getListField;
|
package/lib/get-related-addr.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.getRelatedAddresses = void 0;
|
|
1
|
+
|
|
2
|
+
//#region src/get-related-addr.ts
|
|
4
3
|
const getRelatedAddresses = (state) => [state.address].concat(state.migratedFrom || []).filter(Boolean);
|
|
5
|
-
|
|
4
|
+
|
|
5
|
+
//#endregion
|
|
6
|
+
exports.getRelatedAddresses = getRelatedAddresses;
|