@proton/wrap-constants 0.2.184 → 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 +112 -112
- package/dist/index.js +49 -15
- package/dist/index.mjs +49 -15
- package/package.json +8 -8
- package/src/coins.ts +16 -1
- package/src/math.ts +95 -60
- package/src/parsers/auth.ts +32 -18
- package/src/parsers/pool.ts +34 -33
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 */,
|
|
@@ -1448,6 +1448,21 @@ var initializeCoins = (protonChain) => {
|
|
|
1448
1448
|
coingeckoId: "",
|
|
1449
1449
|
unifiedCryptoassetId: ""
|
|
1450
1450
|
},
|
|
1451
|
+
{
|
|
1452
|
+
allowSwap: false,
|
|
1453
|
+
allowBridge: false,
|
|
1454
|
+
allowLend: false,
|
|
1455
|
+
allowBorrow: false,
|
|
1456
|
+
name: "Metal Dollar",
|
|
1457
|
+
coin: "MPD",
|
|
1458
|
+
xtokenSymbol: "MPD",
|
|
1459
|
+
xtokenPrecision: 6,
|
|
1460
|
+
xtokenContract: "mpd.token",
|
|
1461
|
+
wallets: [],
|
|
1462
|
+
image: "https://app.metalx.com/img/tokens/mpd.png",
|
|
1463
|
+
coingeckoId: "",
|
|
1464
|
+
unifiedCryptoassetId: ""
|
|
1465
|
+
},
|
|
1451
1466
|
{
|
|
1452
1467
|
allowSwap: false,
|
|
1453
1468
|
allowBridge: true,
|
|
@@ -1758,8 +1773,16 @@ var generateAuthData = {
|
|
|
1758
1773
|
time: z3.string(),
|
|
1759
1774
|
protonAccount: z3.string()
|
|
1760
1775
|
};
|
|
1761
|
-
var generateAuthActionsBaseParser = baseActionParser(
|
|
1762
|
-
|
|
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
|
+
);
|
|
1763
1786
|
|
|
1764
1787
|
// src/parsers/address.ts
|
|
1765
1788
|
var addressParser = z4.object({
|
|
@@ -4111,21 +4134,28 @@ function toFixedPoint(str, e, z13) {
|
|
|
4111
4134
|
return str;
|
|
4112
4135
|
}
|
|
4113
4136
|
var BigNumber = clone();
|
|
4137
|
+
var bignumber_default = BigNumber;
|
|
4114
4138
|
|
|
4115
4139
|
// src/math.ts
|
|
4116
4140
|
var compute_transfer = (pool1, pool2, swap, exchange_fee, precision) => {
|
|
4117
4141
|
const term1 = pool2;
|
|
4118
4142
|
const term2over = pool1.times(pool2);
|
|
4119
4143
|
const term2under = pool1.plus(swap);
|
|
4120
|
-
const term2 = term2over.div(term2under).integerValue(
|
|
4144
|
+
const term2 = term2over.div(term2under).integerValue(bignumber_default.ROUND_DOWN);
|
|
4121
4145
|
const term = term1.minus(term2);
|
|
4122
|
-
const fee = new
|
|
4146
|
+
const fee = new bignumber_default(exchange_fee).div(FEE_FACTOR);
|
|
4123
4147
|
const result = term.minus(term.times(fee));
|
|
4124
|
-
return result.integerValue(
|
|
4148
|
+
return result.integerValue(bignumber_default.ROUND_DOWN).shiftedBy(-precision);
|
|
4125
4149
|
};
|
|
4126
4150
|
var compute_transfer_curve = (reserve_in, reserve_out, amount_in, exchange_fee, precision, amplifier) => {
|
|
4127
4151
|
if (amplifier === 0) {
|
|
4128
|
-
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
|
+
);
|
|
4129
4159
|
}
|
|
4130
4160
|
const MAX_ITERATIONS = 10;
|
|
4131
4161
|
const sum = reserve_in + reserve_out;
|
|
@@ -4138,29 +4168,33 @@ var compute_transfer_curve = (reserve_in, reserve_out, amount_in, exchange_fee,
|
|
|
4138
4168
|
while (D != D_prev && i--) {
|
|
4139
4169
|
const prod1 = F(F(D * D / (reserve_in * 2)) * D / (reserve_out * 2));
|
|
4140
4170
|
D_prev = D;
|
|
4141
|
-
D = F(
|
|
4171
|
+
D = F(
|
|
4172
|
+
2 * D * (amplifier * sum + prod1) / ((2 * amplifier - 1) * D + 3 * prod1)
|
|
4173
|
+
);
|
|
4142
4174
|
}
|
|
4143
4175
|
const b = reserve_in + amount_in + F(D / (amplifier * 2)) - D;
|
|
4144
|
-
const c = F(
|
|
4176
|
+
const c = F(
|
|
4177
|
+
F(D * D / ((reserve_in + amount_in) * 2)) * D / (amplifier * 4)
|
|
4178
|
+
);
|
|
4145
4179
|
let x = D, x_prev = 0;
|
|
4146
4180
|
i = MAX_ITERATIONS;
|
|
4147
4181
|
while (x != x_prev && i--) {
|
|
4148
4182
|
x_prev = F(x);
|
|
4149
|
-
x = +new
|
|
4183
|
+
x = +new bignumber_default(x * x + c).div(2 * x + b).toFixed(0, bignumber_default.ROUND_DOWN);
|
|
4150
4184
|
}
|
|
4151
4185
|
if (reserve_out <= x) {
|
|
4152
4186
|
throw new Error("curve: insufficient reserve out");
|
|
4153
4187
|
}
|
|
4154
|
-
const amount_out_with_fee = new
|
|
4155
|
-
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);
|
|
4156
4190
|
const amount_out = amount_out_with_fee.minus(fee);
|
|
4157
|
-
return amount_out.integerValue(
|
|
4191
|
+
return amount_out.integerValue(bignumber_default.ROUND_DOWN).shiftedBy(-precision);
|
|
4158
4192
|
};
|
|
4159
4193
|
var compute_liquidity = (amount_lt, pool, lt_supply, precision) => {
|
|
4160
4194
|
const over = amount_lt.times(pool);
|
|
4161
4195
|
const under = lt_supply;
|
|
4162
|
-
const result = over.div(under).integerValue(
|
|
4163
|
-
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);
|
|
4164
4198
|
};
|
|
4165
4199
|
var isInputInvalid = (data, value, pool) => {
|
|
4166
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 */,
|
|
@@ -1293,6 +1293,21 @@ var initializeCoins = (protonChain) => {
|
|
|
1293
1293
|
coingeckoId: "",
|
|
1294
1294
|
unifiedCryptoassetId: ""
|
|
1295
1295
|
},
|
|
1296
|
+
{
|
|
1297
|
+
allowSwap: false,
|
|
1298
|
+
allowBridge: false,
|
|
1299
|
+
allowLend: false,
|
|
1300
|
+
allowBorrow: false,
|
|
1301
|
+
name: "Metal Dollar",
|
|
1302
|
+
coin: "MPD",
|
|
1303
|
+
xtokenSymbol: "MPD",
|
|
1304
|
+
xtokenPrecision: 6,
|
|
1305
|
+
xtokenContract: "mpd.token",
|
|
1306
|
+
wallets: [],
|
|
1307
|
+
image: "https://app.metalx.com/img/tokens/mpd.png",
|
|
1308
|
+
coingeckoId: "",
|
|
1309
|
+
unifiedCryptoassetId: ""
|
|
1310
|
+
},
|
|
1296
1311
|
{
|
|
1297
1312
|
allowSwap: false,
|
|
1298
1313
|
allowBridge: true,
|
|
@@ -1603,8 +1618,16 @@ var generateAuthData = {
|
|
|
1603
1618
|
time: z3.string(),
|
|
1604
1619
|
protonAccount: z3.string()
|
|
1605
1620
|
};
|
|
1606
|
-
var generateAuthActionsBaseParser = baseActionParser(
|
|
1607
|
-
|
|
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
|
+
);
|
|
1608
1631
|
|
|
1609
1632
|
// src/parsers/address.ts
|
|
1610
1633
|
var addressParser = z4.object({
|
|
@@ -3956,21 +3979,28 @@ function toFixedPoint(str, e, z13) {
|
|
|
3956
3979
|
return str;
|
|
3957
3980
|
}
|
|
3958
3981
|
var BigNumber = clone();
|
|
3982
|
+
var bignumber_default = BigNumber;
|
|
3959
3983
|
|
|
3960
3984
|
// src/math.ts
|
|
3961
3985
|
var compute_transfer = (pool1, pool2, swap, exchange_fee, precision) => {
|
|
3962
3986
|
const term1 = pool2;
|
|
3963
3987
|
const term2over = pool1.times(pool2);
|
|
3964
3988
|
const term2under = pool1.plus(swap);
|
|
3965
|
-
const term2 = term2over.div(term2under).integerValue(
|
|
3989
|
+
const term2 = term2over.div(term2under).integerValue(bignumber_default.ROUND_DOWN);
|
|
3966
3990
|
const term = term1.minus(term2);
|
|
3967
|
-
const fee = new
|
|
3991
|
+
const fee = new bignumber_default(exchange_fee).div(FEE_FACTOR);
|
|
3968
3992
|
const result = term.minus(term.times(fee));
|
|
3969
|
-
return result.integerValue(
|
|
3993
|
+
return result.integerValue(bignumber_default.ROUND_DOWN).shiftedBy(-precision);
|
|
3970
3994
|
};
|
|
3971
3995
|
var compute_transfer_curve = (reserve_in, reserve_out, amount_in, exchange_fee, precision, amplifier) => {
|
|
3972
3996
|
if (amplifier === 0) {
|
|
3973
|
-
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
|
+
);
|
|
3974
4004
|
}
|
|
3975
4005
|
const MAX_ITERATIONS = 10;
|
|
3976
4006
|
const sum = reserve_in + reserve_out;
|
|
@@ -3983,29 +4013,33 @@ var compute_transfer_curve = (reserve_in, reserve_out, amount_in, exchange_fee,
|
|
|
3983
4013
|
while (D != D_prev && i--) {
|
|
3984
4014
|
const prod1 = F(F(D * D / (reserve_in * 2)) * D / (reserve_out * 2));
|
|
3985
4015
|
D_prev = D;
|
|
3986
|
-
D = F(
|
|
4016
|
+
D = F(
|
|
4017
|
+
2 * D * (amplifier * sum + prod1) / ((2 * amplifier - 1) * D + 3 * prod1)
|
|
4018
|
+
);
|
|
3987
4019
|
}
|
|
3988
4020
|
const b = reserve_in + amount_in + F(D / (amplifier * 2)) - D;
|
|
3989
|
-
const c = F(
|
|
4021
|
+
const c = F(
|
|
4022
|
+
F(D * D / ((reserve_in + amount_in) * 2)) * D / (amplifier * 4)
|
|
4023
|
+
);
|
|
3990
4024
|
let x = D, x_prev = 0;
|
|
3991
4025
|
i = MAX_ITERATIONS;
|
|
3992
4026
|
while (x != x_prev && i--) {
|
|
3993
4027
|
x_prev = F(x);
|
|
3994
|
-
x = +new
|
|
4028
|
+
x = +new bignumber_default(x * x + c).div(2 * x + b).toFixed(0, bignumber_default.ROUND_DOWN);
|
|
3995
4029
|
}
|
|
3996
4030
|
if (reserve_out <= x) {
|
|
3997
4031
|
throw new Error("curve: insufficient reserve out");
|
|
3998
4032
|
}
|
|
3999
|
-
const amount_out_with_fee = new
|
|
4000
|
-
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);
|
|
4001
4035
|
const amount_out = amount_out_with_fee.minus(fee);
|
|
4002
|
-
return amount_out.integerValue(
|
|
4036
|
+
return amount_out.integerValue(bignumber_default.ROUND_DOWN).shiftedBy(-precision);
|
|
4003
4037
|
};
|
|
4004
4038
|
var compute_liquidity = (amount_lt, pool, lt_supply, precision) => {
|
|
4005
4039
|
const over = amount_lt.times(pool);
|
|
4006
4040
|
const under = lt_supply;
|
|
4007
|
-
const result = over.div(under).integerValue(
|
|
4008
|
-
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);
|
|
4009
4043
|
};
|
|
4010
4044
|
var isInputInvalid = (data, value, pool) => {
|
|
4011
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
|
@@ -384,7 +384,7 @@ export const initializeCoins = (
|
|
|
384
384
|
hasWithdrawMemo: false,
|
|
385
385
|
},
|
|
386
386
|
{
|
|
387
|
-
wallet: "METAL",
|
|
387
|
+
wallet: "METAL-ERC20",
|
|
388
388
|
symbol: "METAL",
|
|
389
389
|
chain: Chains.EthereumMainnet,
|
|
390
390
|
network: Networks.ERC20,
|
|
@@ -1460,6 +1460,21 @@ export const initializeCoins = (
|
|
|
1460
1460
|
coingeckoId: "",
|
|
1461
1461
|
unifiedCryptoassetId: "",
|
|
1462
1462
|
},
|
|
1463
|
+
{
|
|
1464
|
+
allowSwap: false,
|
|
1465
|
+
allowBridge: false,
|
|
1466
|
+
allowLend: false,
|
|
1467
|
+
allowBorrow: false,
|
|
1468
|
+
name: "Metal Dollar",
|
|
1469
|
+
coin: "MPD",
|
|
1470
|
+
xtokenSymbol: "MPD",
|
|
1471
|
+
xtokenPrecision: 6,
|
|
1472
|
+
xtokenContract: "mpd.token",
|
|
1473
|
+
wallets: [],
|
|
1474
|
+
image: "https://app.metalx.com/img/tokens/mpd.png",
|
|
1475
|
+
coingeckoId: "",
|
|
1476
|
+
unifiedCryptoassetId: "",
|
|
1477
|
+
},
|
|
1463
1478
|
{
|
|
1464
1479
|
allowSwap: false,
|
|
1465
1480
|
allowBridge: true,
|
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;
|