@proton/wrap-constants 0.2.185 → 0.2.187
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/dist/index.d.ts +5 -5
- package/dist/index.js +34 -15
- package/dist/index.mjs +34 -15
- package/package.json +8 -8
- package/src/coins.ts +1 -1
- package/src/math.ts +95 -60
- package/src/parsers/auth.ts +32 -18
- package/src/parsers/pool.ts +34 -33
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Asset, ExtendedAsset as ExtendedAsset$1 } from '@bloks/numbers';
|
|
2
2
|
import * as z from 'zod';
|
|
3
|
-
import
|
|
3
|
+
import BN from 'bignumber.js';
|
|
4
4
|
|
|
5
5
|
declare enum Chains {
|
|
6
6
|
BitcoinMainnet = "Bitcoin",
|
|
@@ -4958,7 +4958,7 @@ interface RawPool {
|
|
|
4958
4958
|
active: boolean;
|
|
4959
4959
|
amplifier: number;
|
|
4960
4960
|
}
|
|
4961
|
-
interface Pool extends Omit<RawPool,
|
|
4961
|
+
interface Pool extends Omit<RawPool, "pool1" | "pool2"> {
|
|
4962
4962
|
lt_symbol: string;
|
|
4963
4963
|
creator: string;
|
|
4964
4964
|
memo: string;
|
|
@@ -13260,9 +13260,9 @@ declare const median: (numbers: number[]) => number;
|
|
|
13260
13260
|
*
|
|
13261
13261
|
* result = term - (term * fee)
|
|
13262
13262
|
*/
|
|
13263
|
-
declare const compute_transfer: (pool1:
|
|
13264
|
-
declare const compute_transfer_curve: (reserve_in: number, reserve_out: number, amount_in: number, exchange_fee: number, precision: number, amplifier: number) =>
|
|
13265
|
-
declare const compute_liquidity: (amount_lt:
|
|
13263
|
+
declare const compute_transfer: (pool1: BN.Instance, pool2: BN.Instance, swap: BN.Instance, exchange_fee: number, precision: number) => BN;
|
|
13264
|
+
declare const compute_transfer_curve: (reserve_in: number, reserve_out: number, amount_in: number, exchange_fee: number, precision: number, amplifier: number) => BN;
|
|
13265
|
+
declare const compute_liquidity: (amount_lt: BN.Instance, pool: BN.Instance, lt_supply: BN.Instance, precision: number) => number;
|
|
13266
13266
|
declare const isInputInvalid: (data: string, value: string | number, pool: {
|
|
13267
13267
|
xtokenPrecision: number;
|
|
13268
13268
|
}) => boolean;
|
package/dist/index.js
CHANGED
|
@@ -444,7 +444,7 @@ var initializeCoins = (protonChain) => {
|
|
|
444
444
|
hasWithdrawMemo: false
|
|
445
445
|
},
|
|
446
446
|
{
|
|
447
|
-
wallet: "METAL",
|
|
447
|
+
wallet: "METAL-ERC20",
|
|
448
448
|
symbol: "METAL",
|
|
449
449
|
chain: "Ethereum" /* EthereumMainnet */,
|
|
450
450
|
network: "erc20" /* ERC20 */,
|
|
@@ -1773,8 +1773,16 @@ var generateAuthData = {
|
|
|
1773
1773
|
time: z3.string(),
|
|
1774
1774
|
protonAccount: z3.string()
|
|
1775
1775
|
};
|
|
1776
|
-
var generateAuthActionsBaseParser = baseActionParser(
|
|
1777
|
-
|
|
1776
|
+
var generateAuthActionsBaseParser = baseActionParser(
|
|
1777
|
+
WRAP_CONTRACT,
|
|
1778
|
+
WRAP_AUTH_ACTION,
|
|
1779
|
+
generateAuthData
|
|
1780
|
+
);
|
|
1781
|
+
var generateAuthParser = createAbstractAuthParser(
|
|
1782
|
+
WRAP_CONTRACT,
|
|
1783
|
+
WRAP_AUTH_ACTION,
|
|
1784
|
+
generateAuthData
|
|
1785
|
+
);
|
|
1778
1786
|
|
|
1779
1787
|
// src/parsers/address.ts
|
|
1780
1788
|
var addressParser = z4.object({
|
|
@@ -4126,21 +4134,28 @@ function toFixedPoint(str, e, z13) {
|
|
|
4126
4134
|
return str;
|
|
4127
4135
|
}
|
|
4128
4136
|
var BigNumber = clone();
|
|
4137
|
+
var bignumber_default = BigNumber;
|
|
4129
4138
|
|
|
4130
4139
|
// src/math.ts
|
|
4131
4140
|
var compute_transfer = (pool1, pool2, swap, exchange_fee, precision) => {
|
|
4132
4141
|
const term1 = pool2;
|
|
4133
4142
|
const term2over = pool1.times(pool2);
|
|
4134
4143
|
const term2under = pool1.plus(swap);
|
|
4135
|
-
const term2 = term2over.div(term2under).integerValue(
|
|
4144
|
+
const term2 = term2over.div(term2under).integerValue(bignumber_default.ROUND_DOWN);
|
|
4136
4145
|
const term = term1.minus(term2);
|
|
4137
|
-
const fee = new
|
|
4146
|
+
const fee = new bignumber_default(exchange_fee).div(FEE_FACTOR);
|
|
4138
4147
|
const result = term.minus(term.times(fee));
|
|
4139
|
-
return result.integerValue(
|
|
4148
|
+
return result.integerValue(bignumber_default.ROUND_DOWN).shiftedBy(-precision);
|
|
4140
4149
|
};
|
|
4141
4150
|
var compute_transfer_curve = (reserve_in, reserve_out, amount_in, exchange_fee, precision, amplifier) => {
|
|
4142
4151
|
if (amplifier === 0) {
|
|
4143
|
-
return compute_transfer(
|
|
4152
|
+
return compute_transfer(
|
|
4153
|
+
new bignumber_default(reserve_in),
|
|
4154
|
+
new bignumber_default(reserve_out),
|
|
4155
|
+
new bignumber_default(amount_in),
|
|
4156
|
+
exchange_fee,
|
|
4157
|
+
precision
|
|
4158
|
+
);
|
|
4144
4159
|
}
|
|
4145
4160
|
const MAX_ITERATIONS = 10;
|
|
4146
4161
|
const sum = reserve_in + reserve_out;
|
|
@@ -4153,29 +4168,33 @@ var compute_transfer_curve = (reserve_in, reserve_out, amount_in, exchange_fee,
|
|
|
4153
4168
|
while (D != D_prev && i--) {
|
|
4154
4169
|
const prod1 = F(F(D * D / (reserve_in * 2)) * D / (reserve_out * 2));
|
|
4155
4170
|
D_prev = D;
|
|
4156
|
-
D = F(
|
|
4171
|
+
D = F(
|
|
4172
|
+
2 * D * (amplifier * sum + prod1) / ((2 * amplifier - 1) * D + 3 * prod1)
|
|
4173
|
+
);
|
|
4157
4174
|
}
|
|
4158
4175
|
const b = reserve_in + amount_in + F(D / (amplifier * 2)) - D;
|
|
4159
|
-
const c = F(
|
|
4176
|
+
const c = F(
|
|
4177
|
+
F(D * D / ((reserve_in + amount_in) * 2)) * D / (amplifier * 4)
|
|
4178
|
+
);
|
|
4160
4179
|
let x = D, x_prev = 0;
|
|
4161
4180
|
i = MAX_ITERATIONS;
|
|
4162
4181
|
while (x != x_prev && i--) {
|
|
4163
4182
|
x_prev = F(x);
|
|
4164
|
-
x = +new
|
|
4183
|
+
x = +new bignumber_default(x * x + c).div(2 * x + b).toFixed(0, bignumber_default.ROUND_DOWN);
|
|
4165
4184
|
}
|
|
4166
4185
|
if (reserve_out <= x) {
|
|
4167
4186
|
throw new Error("curve: insufficient reserve out");
|
|
4168
4187
|
}
|
|
4169
|
-
const amount_out_with_fee = new
|
|
4170
|
-
const fee = amount_out_with_fee.times(exchange_fee).div(FEE_FACTOR).plus(1).toFixed(0,
|
|
4188
|
+
const amount_out_with_fee = new bignumber_default(reserve_out - x);
|
|
4189
|
+
const fee = amount_out_with_fee.times(exchange_fee).div(FEE_FACTOR).plus(1).toFixed(0, bignumber_default.ROUND_DOWN);
|
|
4171
4190
|
const amount_out = amount_out_with_fee.minus(fee);
|
|
4172
|
-
return amount_out.integerValue(
|
|
4191
|
+
return amount_out.integerValue(bignumber_default.ROUND_DOWN).shiftedBy(-precision);
|
|
4173
4192
|
};
|
|
4174
4193
|
var compute_liquidity = (amount_lt, pool, lt_supply, precision) => {
|
|
4175
4194
|
const over = amount_lt.times(pool);
|
|
4176
4195
|
const under = lt_supply;
|
|
4177
|
-
const result = over.div(under).integerValue(
|
|
4178
|
-
return +result.shiftedBy(-precision).toFixed(precision,
|
|
4196
|
+
const result = over.div(under).integerValue(bignumber_default.ROUND_DOWN);
|
|
4197
|
+
return +result.shiftedBy(-precision).toFixed(precision, bignumber_default.ROUND_DOWN);
|
|
4179
4198
|
};
|
|
4180
4199
|
var isInputInvalid = (data, value, pool) => {
|
|
4181
4200
|
value = String(value);
|
package/dist/index.mjs
CHANGED
|
@@ -289,7 +289,7 @@ var initializeCoins = (protonChain) => {
|
|
|
289
289
|
hasWithdrawMemo: false
|
|
290
290
|
},
|
|
291
291
|
{
|
|
292
|
-
wallet: "METAL",
|
|
292
|
+
wallet: "METAL-ERC20",
|
|
293
293
|
symbol: "METAL",
|
|
294
294
|
chain: "Ethereum" /* EthereumMainnet */,
|
|
295
295
|
network: "erc20" /* ERC20 */,
|
|
@@ -1618,8 +1618,16 @@ var generateAuthData = {
|
|
|
1618
1618
|
time: z3.string(),
|
|
1619
1619
|
protonAccount: z3.string()
|
|
1620
1620
|
};
|
|
1621
|
-
var generateAuthActionsBaseParser = baseActionParser(
|
|
1622
|
-
|
|
1621
|
+
var generateAuthActionsBaseParser = baseActionParser(
|
|
1622
|
+
WRAP_CONTRACT,
|
|
1623
|
+
WRAP_AUTH_ACTION,
|
|
1624
|
+
generateAuthData
|
|
1625
|
+
);
|
|
1626
|
+
var generateAuthParser = createAbstractAuthParser(
|
|
1627
|
+
WRAP_CONTRACT,
|
|
1628
|
+
WRAP_AUTH_ACTION,
|
|
1629
|
+
generateAuthData
|
|
1630
|
+
);
|
|
1623
1631
|
|
|
1624
1632
|
// src/parsers/address.ts
|
|
1625
1633
|
var addressParser = z4.object({
|
|
@@ -3971,21 +3979,28 @@ function toFixedPoint(str, e, z13) {
|
|
|
3971
3979
|
return str;
|
|
3972
3980
|
}
|
|
3973
3981
|
var BigNumber = clone();
|
|
3982
|
+
var bignumber_default = BigNumber;
|
|
3974
3983
|
|
|
3975
3984
|
// src/math.ts
|
|
3976
3985
|
var compute_transfer = (pool1, pool2, swap, exchange_fee, precision) => {
|
|
3977
3986
|
const term1 = pool2;
|
|
3978
3987
|
const term2over = pool1.times(pool2);
|
|
3979
3988
|
const term2under = pool1.plus(swap);
|
|
3980
|
-
const term2 = term2over.div(term2under).integerValue(
|
|
3989
|
+
const term2 = term2over.div(term2under).integerValue(bignumber_default.ROUND_DOWN);
|
|
3981
3990
|
const term = term1.minus(term2);
|
|
3982
|
-
const fee = new
|
|
3991
|
+
const fee = new bignumber_default(exchange_fee).div(FEE_FACTOR);
|
|
3983
3992
|
const result = term.minus(term.times(fee));
|
|
3984
|
-
return result.integerValue(
|
|
3993
|
+
return result.integerValue(bignumber_default.ROUND_DOWN).shiftedBy(-precision);
|
|
3985
3994
|
};
|
|
3986
3995
|
var compute_transfer_curve = (reserve_in, reserve_out, amount_in, exchange_fee, precision, amplifier) => {
|
|
3987
3996
|
if (amplifier === 0) {
|
|
3988
|
-
return compute_transfer(
|
|
3997
|
+
return compute_transfer(
|
|
3998
|
+
new bignumber_default(reserve_in),
|
|
3999
|
+
new bignumber_default(reserve_out),
|
|
4000
|
+
new bignumber_default(amount_in),
|
|
4001
|
+
exchange_fee,
|
|
4002
|
+
precision
|
|
4003
|
+
);
|
|
3989
4004
|
}
|
|
3990
4005
|
const MAX_ITERATIONS = 10;
|
|
3991
4006
|
const sum = reserve_in + reserve_out;
|
|
@@ -3998,29 +4013,33 @@ var compute_transfer_curve = (reserve_in, reserve_out, amount_in, exchange_fee,
|
|
|
3998
4013
|
while (D != D_prev && i--) {
|
|
3999
4014
|
const prod1 = F(F(D * D / (reserve_in * 2)) * D / (reserve_out * 2));
|
|
4000
4015
|
D_prev = D;
|
|
4001
|
-
D = F(
|
|
4016
|
+
D = F(
|
|
4017
|
+
2 * D * (amplifier * sum + prod1) / ((2 * amplifier - 1) * D + 3 * prod1)
|
|
4018
|
+
);
|
|
4002
4019
|
}
|
|
4003
4020
|
const b = reserve_in + amount_in + F(D / (amplifier * 2)) - D;
|
|
4004
|
-
const c = F(
|
|
4021
|
+
const c = F(
|
|
4022
|
+
F(D * D / ((reserve_in + amount_in) * 2)) * D / (amplifier * 4)
|
|
4023
|
+
);
|
|
4005
4024
|
let x = D, x_prev = 0;
|
|
4006
4025
|
i = MAX_ITERATIONS;
|
|
4007
4026
|
while (x != x_prev && i--) {
|
|
4008
4027
|
x_prev = F(x);
|
|
4009
|
-
x = +new
|
|
4028
|
+
x = +new bignumber_default(x * x + c).div(2 * x + b).toFixed(0, bignumber_default.ROUND_DOWN);
|
|
4010
4029
|
}
|
|
4011
4030
|
if (reserve_out <= x) {
|
|
4012
4031
|
throw new Error("curve: insufficient reserve out");
|
|
4013
4032
|
}
|
|
4014
|
-
const amount_out_with_fee = new
|
|
4015
|
-
const fee = amount_out_with_fee.times(exchange_fee).div(FEE_FACTOR).plus(1).toFixed(0,
|
|
4033
|
+
const amount_out_with_fee = new bignumber_default(reserve_out - x);
|
|
4034
|
+
const fee = amount_out_with_fee.times(exchange_fee).div(FEE_FACTOR).plus(1).toFixed(0, bignumber_default.ROUND_DOWN);
|
|
4016
4035
|
const amount_out = amount_out_with_fee.minus(fee);
|
|
4017
|
-
return amount_out.integerValue(
|
|
4036
|
+
return amount_out.integerValue(bignumber_default.ROUND_DOWN).shiftedBy(-precision);
|
|
4018
4037
|
};
|
|
4019
4038
|
var compute_liquidity = (amount_lt, pool, lt_supply, precision) => {
|
|
4020
4039
|
const over = amount_lt.times(pool);
|
|
4021
4040
|
const under = lt_supply;
|
|
4022
|
-
const result = over.div(under).integerValue(
|
|
4023
|
-
return +result.shiftedBy(-precision).toFixed(precision,
|
|
4041
|
+
const result = over.div(under).integerValue(bignumber_default.ROUND_DOWN);
|
|
4042
|
+
return +result.shiftedBy(-precision).toFixed(precision, bignumber_default.ROUND_DOWN);
|
|
4024
4043
|
};
|
|
4025
4044
|
var isInputInvalid = (data, value, pool) => {
|
|
4026
4045
|
value = String(value);
|
package/package.json
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
8
|
-
"version": "0.2.
|
|
8
|
+
"version": "0.2.187",
|
|
9
9
|
"license": "MIT",
|
|
10
10
|
"main": "dist/index.js",
|
|
11
11
|
"typings": "dist/index.d.ts",
|
|
@@ -25,20 +25,20 @@
|
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"@bloks/numbers": "^27.0.0",
|
|
28
|
-
"@
|
|
29
|
-
"@proton/js": "^26.0.1",
|
|
30
|
-
"@size-limit/preset-small-lib": "^4.9.1",
|
|
28
|
+
"@size-limit/preset-small-lib": "^11.2.0",
|
|
31
29
|
"@types/lodash.clonedeep": "^4.5.6",
|
|
32
|
-
"@typescript-eslint/
|
|
33
|
-
"
|
|
34
|
-
"
|
|
30
|
+
"@typescript-eslint/eslint-plugin": "^8.36.0",
|
|
31
|
+
"@typescript-eslint/parser": "^8.36.0",
|
|
32
|
+
"eslint": "^9.30.1",
|
|
33
|
+
"size-limit": "^11.2.0",
|
|
34
|
+
"tsup": "^8.5.0"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"lodash.clonedeep": "^4.5.0",
|
|
38
38
|
"zod": "^3.19.1"
|
|
39
39
|
},
|
|
40
40
|
"resolutions": {
|
|
41
|
-
"typescript": "4.
|
|
41
|
+
"typescript": "4.8.4"
|
|
42
42
|
},
|
|
43
43
|
"gitHead": "88555c5fb8a463f5e0d8af0e6976025739398ba3"
|
|
44
44
|
}
|
package/src/coins.ts
CHANGED
package/src/math.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { FEE_FACTOR } from
|
|
1
|
+
import BN from "bignumber.js";
|
|
2
|
+
import { FEE_FACTOR } from "./constants";
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* XPR<>XUSDT (XPR -> XUSDT)
|
|
@@ -10,17 +10,23 @@ import { FEE_FACTOR } from './constants'
|
|
|
10
10
|
*
|
|
11
11
|
* result = term - (term * fee)
|
|
12
12
|
*/
|
|
13
|
-
export const compute_transfer = (
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
13
|
+
export const compute_transfer = (
|
|
14
|
+
pool1: BN.Instance,
|
|
15
|
+
pool2: BN.Instance,
|
|
16
|
+
swap: BN.Instance,
|
|
17
|
+
exchange_fee: number,
|
|
18
|
+
precision: number
|
|
19
|
+
): BN => {
|
|
20
|
+
const term1 = pool2;
|
|
21
|
+
const term2over = pool1.times(pool2);
|
|
22
|
+
const term2under = pool1.plus(swap);
|
|
23
|
+
const term2 = term2over.div(term2under).integerValue(BN.ROUND_DOWN);
|
|
24
|
+
const term = term1.minus(term2);
|
|
25
|
+
const fee = new BN(exchange_fee).div(FEE_FACTOR);
|
|
26
|
+
const result = term.minus(term.times(fee));
|
|
27
|
+
|
|
28
|
+
return result.integerValue(BN.ROUND_DOWN).shiftedBy(-precision);
|
|
29
|
+
};
|
|
24
30
|
|
|
25
31
|
export const compute_transfer_curve = (
|
|
26
32
|
reserve_in: number,
|
|
@@ -31,39 +37,51 @@ export const compute_transfer_curve = (
|
|
|
31
37
|
amplifier: number
|
|
32
38
|
): BN => {
|
|
33
39
|
if (amplifier === 0) {
|
|
34
|
-
|
|
40
|
+
return compute_transfer(
|
|
41
|
+
new BN(reserve_in),
|
|
42
|
+
new BN(reserve_out),
|
|
43
|
+
new BN(amount_in),
|
|
44
|
+
exchange_fee,
|
|
45
|
+
precision
|
|
46
|
+
);
|
|
35
47
|
}
|
|
36
48
|
|
|
37
|
-
const MAX_ITERATIONS = 10
|
|
49
|
+
const MAX_ITERATIONS = 10;
|
|
38
50
|
|
|
39
|
-
const sum = reserve_in + reserve_out
|
|
51
|
+
const sum = reserve_in + reserve_out;
|
|
40
52
|
let D = sum;
|
|
41
|
-
let D_prev = 0
|
|
53
|
+
let D_prev = 0;
|
|
42
54
|
|
|
43
55
|
const F = (v: number) => {
|
|
44
|
-
|
|
45
|
-
}
|
|
56
|
+
return (v >= 0 ? 1 : -1) * Math.floor(Math.abs(v));
|
|
57
|
+
};
|
|
46
58
|
|
|
47
|
-
let i = MAX_ITERATIONS
|
|
59
|
+
let i = MAX_ITERATIONS;
|
|
48
60
|
while (D != D_prev && i--) {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
61
|
+
const prod1 = F((F((D * D) / (reserve_in * 2)) * D) / (reserve_out * 2));
|
|
62
|
+
D_prev = D;
|
|
63
|
+
D = F(
|
|
64
|
+
(2 * D * (amplifier * sum + prod1)) /
|
|
65
|
+
((2 * amplifier - 1) * D + 3 * prod1)
|
|
66
|
+
);
|
|
52
67
|
}
|
|
53
68
|
|
|
54
|
-
const b =
|
|
69
|
+
const b = reserve_in + amount_in + F(D / (amplifier * 2)) - D;
|
|
55
70
|
|
|
56
|
-
const c = F(
|
|
71
|
+
const c = F(
|
|
72
|
+
(F((D * D) / ((reserve_in + amount_in) * 2)) * D) / (amplifier * 4)
|
|
73
|
+
);
|
|
57
74
|
|
|
58
|
-
let x = D,
|
|
75
|
+
let x = D,
|
|
76
|
+
x_prev = 0;
|
|
59
77
|
i = MAX_ITERATIONS;
|
|
60
|
-
while (
|
|
78
|
+
while (x != x_prev && i--) {
|
|
61
79
|
x_prev = F(x);
|
|
62
|
-
x = +new BN(x * x + c).div(2 * x + b).toFixed(0, BN.ROUND_DOWN)
|
|
80
|
+
x = +new BN(x * x + c).div(2 * x + b).toFixed(0, BN.ROUND_DOWN);
|
|
63
81
|
}
|
|
64
82
|
|
|
65
83
|
if (reserve_out <= x) {
|
|
66
|
-
|
|
84
|
+
throw new Error("curve: insufficient reserve out");
|
|
67
85
|
}
|
|
68
86
|
|
|
69
87
|
// Amount out + Fee + 1
|
|
@@ -71,42 +89,59 @@ export const compute_transfer_curve = (
|
|
|
71
89
|
|
|
72
90
|
// Fee + 1
|
|
73
91
|
// +1 covers small precision issues
|
|
74
|
-
const fee = amount_out_with_fee
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
92
|
+
const fee = amount_out_with_fee
|
|
93
|
+
.times(exchange_fee)
|
|
94
|
+
.div(FEE_FACTOR)
|
|
95
|
+
.plus(1)
|
|
96
|
+
.toFixed(0, BN.ROUND_DOWN);
|
|
78
97
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
const
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
98
|
+
// Amount out
|
|
99
|
+
const amount_out = amount_out_with_fee.minus(fee);
|
|
100
|
+
|
|
101
|
+
return amount_out.integerValue(BN.ROUND_DOWN).shiftedBy(-precision);
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
export const compute_liquidity = (
|
|
105
|
+
amount_lt: BN.Instance,
|
|
106
|
+
pool: BN.Instance,
|
|
107
|
+
lt_supply: BN.Instance,
|
|
108
|
+
precision: number
|
|
109
|
+
): number => {
|
|
110
|
+
const over = amount_lt.times(pool);
|
|
111
|
+
const under = lt_supply;
|
|
112
|
+
const result = over.div(under).integerValue(BN.ROUND_DOWN);
|
|
113
|
+
|
|
114
|
+
return +result.shiftedBy(-precision).toFixed(precision, BN.ROUND_DOWN);
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
export const isInputInvalid = (
|
|
118
|
+
data: string,
|
|
119
|
+
value: string | number,
|
|
120
|
+
pool: { xtokenPrecision: number }
|
|
121
|
+
): boolean => {
|
|
122
|
+
value = String(value);
|
|
123
|
+
|
|
124
|
+
const isBackspace = data === null;
|
|
125
|
+
const isNumber = !/[0-9]|\./.test(data);
|
|
126
|
+
const isDoubleDot = data === "." && value.indexOf(".") !== value.length - 1;
|
|
127
|
+
const isPrecisionTooHigh =
|
|
128
|
+
value &&
|
|
129
|
+
value.indexOf(".") !== -1 &&
|
|
130
|
+
value.split(".")[1].length > pool.xtokenPrecision;
|
|
131
|
+
const isInvalid =
|
|
132
|
+
!isBackspace && Boolean(isNumber || isDoubleDot || isPrecisionTooHigh);
|
|
133
|
+
|
|
134
|
+
return isInvalid;
|
|
135
|
+
};
|
|
101
136
|
|
|
102
137
|
export const applyDiscountToFee = (fee: number, staked: number): number => {
|
|
103
138
|
if (staked >= 10000000) {
|
|
104
|
-
return fee * 0
|
|
139
|
+
return fee * 0;
|
|
105
140
|
} else if (staked >= 1000000) {
|
|
106
|
-
return fee * 0.33
|
|
141
|
+
return fee * 0.33;
|
|
107
142
|
} else if (staked >= 100000) {
|
|
108
|
-
return fee * 0.66
|
|
143
|
+
return fee * 0.66;
|
|
109
144
|
} else {
|
|
110
|
-
return fee
|
|
145
|
+
return fee;
|
|
111
146
|
}
|
|
112
|
-
}
|
|
147
|
+
};
|
package/src/parsers/auth.ts
CHANGED
|
@@ -1,22 +1,36 @@
|
|
|
1
|
-
import * as z from
|
|
2
|
-
import { baseActionParser, singleActionTransactionParser } from
|
|
3
|
-
import { authorizationParser } from
|
|
4
|
-
import { WRAP_CONTRACT, WRAP_AUTH_ACTION } from
|
|
1
|
+
import * as z from "zod";
|
|
2
|
+
import { baseActionParser, singleActionTransactionParser } from "./actions";
|
|
3
|
+
import { authorizationParser } from "./base";
|
|
4
|
+
import { WRAP_CONTRACT, WRAP_AUTH_ACTION } from "../constants";
|
|
5
5
|
|
|
6
|
-
export const createAbstractAuthParser = (
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
6
|
+
export const createAbstractAuthParser = (
|
|
7
|
+
contract: string,
|
|
8
|
+
action: string,
|
|
9
|
+
data: z.ZodRawShape
|
|
10
|
+
) => {
|
|
11
|
+
return z.object({
|
|
12
|
+
signer: authorizationParser,
|
|
13
|
+
signatures: z.array(z.string()).length(1),
|
|
14
|
+
transaction: singleActionTransactionParser(contract, action, data),
|
|
15
|
+
});
|
|
16
|
+
};
|
|
13
17
|
|
|
14
18
|
const generateAuthData = {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
const generateAuthActionsBaseParser = baseActionParser(
|
|
19
|
-
|
|
19
|
+
time: z.string(),
|
|
20
|
+
protonAccount: z.string(),
|
|
21
|
+
};
|
|
22
|
+
const generateAuthActionsBaseParser = baseActionParser(
|
|
23
|
+
WRAP_CONTRACT,
|
|
24
|
+
WRAP_AUTH_ACTION,
|
|
25
|
+
generateAuthData
|
|
26
|
+
);
|
|
27
|
+
export type GenerateAuthBaseAction = z.infer<
|
|
28
|
+
typeof generateAuthActionsBaseParser
|
|
29
|
+
>;
|
|
20
30
|
|
|
21
|
-
export const generateAuthParser = createAbstractAuthParser(
|
|
22
|
-
|
|
31
|
+
export const generateAuthParser = createAbstractAuthParser(
|
|
32
|
+
WRAP_CONTRACT,
|
|
33
|
+
WRAP_AUTH_ACTION,
|
|
34
|
+
generateAuthData
|
|
35
|
+
);
|
|
36
|
+
export type GenerateAuth = z.infer<typeof generateAuthParser>;
|
package/src/parsers/pool.ts
CHANGED
|
@@ -1,30 +1,29 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { ExtendedAsset } from "@bloks/numbers";
|
|
2
|
+
import { Coin } from "../coins";
|
|
3
3
|
import { INode } from "../graph";
|
|
4
4
|
|
|
5
|
-
|
|
6
5
|
export interface RawPool {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
6
|
+
lt_symbol: string;
|
|
7
|
+
creator: string;
|
|
8
|
+
memo: string;
|
|
9
|
+
pool1: {
|
|
10
|
+
quantity: string;
|
|
11
|
+
contract: string;
|
|
12
|
+
};
|
|
13
|
+
pool2: {
|
|
14
|
+
quantity: string;
|
|
15
|
+
contract: string;
|
|
16
|
+
};
|
|
17
|
+
hash: string;
|
|
18
|
+
fee: {
|
|
19
|
+
exchange_fee: number;
|
|
20
|
+
add_liquidity_fee: number;
|
|
21
|
+
remove_liquidity_fee: number;
|
|
22
|
+
};
|
|
23
|
+
active: boolean;
|
|
24
|
+
amplifier: number;
|
|
26
25
|
}
|
|
27
|
-
export interface Pool extends Omit<RawPool,
|
|
26
|
+
export interface Pool extends Omit<RawPool, "pool1" | "pool2"> {
|
|
28
27
|
lt_symbol: string;
|
|
29
28
|
creator: string;
|
|
30
29
|
memo: string;
|
|
@@ -39,14 +38,16 @@ export interface Pool extends Omit<RawPool, 'pool1'|'pool2'> {
|
|
|
39
38
|
liquidityUsd: number;
|
|
40
39
|
liquidityApr: number;
|
|
41
40
|
}
|
|
42
|
-
|
|
43
|
-
export type ExtendedToken = Coin & ExtendedAsset & { key: string; }
|
|
44
|
-
export type ExtendedTokenWithRate = ExtendedToken & { rate: number; }
|
|
45
41
|
|
|
46
|
-
export type
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
42
|
+
export type ExtendedToken = Coin & ExtendedAsset & { key: string };
|
|
43
|
+
export type ExtendedTokenWithRate = ExtendedToken & { rate: number };
|
|
44
|
+
|
|
45
|
+
export type PoolTable =
|
|
46
|
+
| {
|
|
47
|
+
pool1: ExtendedTokenWithRate;
|
|
48
|
+
pool2: ExtendedTokenWithRate;
|
|
49
|
+
path: INode<Pool>[];
|
|
50
|
+
shortestPath: INode<Pool>[];
|
|
51
|
+
getPathString: () => string;
|
|
52
|
+
}
|
|
53
|
+
| undefined;
|