@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 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 { BigNumber } from 'bignumber.js';
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, 'pool1' | 'pool2'> {
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: BigNumber.Instance, pool2: BigNumber.Instance, swap: BigNumber.Instance, exchange_fee: number, precision: number) => BigNumber;
13264
- declare const compute_transfer_curve: (reserve_in: number, reserve_out: number, amount_in: number, exchange_fee: number, precision: number, amplifier: number) => BigNumber;
13265
- declare const compute_liquidity: (amount_lt: BigNumber.Instance, pool: BigNumber.Instance, lt_supply: BigNumber.Instance, precision: number) => number;
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(WRAP_CONTRACT, WRAP_AUTH_ACTION, generateAuthData);
1777
- var generateAuthParser = createAbstractAuthParser(WRAP_CONTRACT, WRAP_AUTH_ACTION, generateAuthData);
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(BigNumber.ROUND_DOWN);
4144
+ const term2 = term2over.div(term2under).integerValue(bignumber_default.ROUND_DOWN);
4136
4145
  const term = term1.minus(term2);
4137
- const fee = new BigNumber(exchange_fee).div(FEE_FACTOR);
4146
+ const fee = new bignumber_default(exchange_fee).div(FEE_FACTOR);
4138
4147
  const result = term.minus(term.times(fee));
4139
- return result.integerValue(BigNumber.ROUND_DOWN).shiftedBy(-precision);
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(new BigNumber(reserve_in), new BigNumber(reserve_out), new BigNumber(amount_in), exchange_fee, precision);
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(2 * D * (amplifier * sum + prod1) / ((2 * amplifier - 1) * D + 3 * prod1));
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(F(D * D / ((reserve_in + amount_in) * 2)) * D / (amplifier * 4));
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 BigNumber(x * x + c).div(2 * x + b).toFixed(0, BigNumber.ROUND_DOWN);
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 BigNumber(reserve_out - x);
4170
- const fee = amount_out_with_fee.times(exchange_fee).div(FEE_FACTOR).plus(1).toFixed(0, BigNumber.ROUND_DOWN);
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(BigNumber.ROUND_DOWN).shiftedBy(-precision);
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(BigNumber.ROUND_DOWN);
4178
- return +result.shiftedBy(-precision).toFixed(precision, BigNumber.ROUND_DOWN);
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(WRAP_CONTRACT, WRAP_AUTH_ACTION, generateAuthData);
1622
- var generateAuthParser = createAbstractAuthParser(WRAP_CONTRACT, WRAP_AUTH_ACTION, generateAuthData);
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(BigNumber.ROUND_DOWN);
3989
+ const term2 = term2over.div(term2under).integerValue(bignumber_default.ROUND_DOWN);
3981
3990
  const term = term1.minus(term2);
3982
- const fee = new BigNumber(exchange_fee).div(FEE_FACTOR);
3991
+ const fee = new bignumber_default(exchange_fee).div(FEE_FACTOR);
3983
3992
  const result = term.minus(term.times(fee));
3984
- return result.integerValue(BigNumber.ROUND_DOWN).shiftedBy(-precision);
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(new BigNumber(reserve_in), new BigNumber(reserve_out), new BigNumber(amount_in), exchange_fee, precision);
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(2 * D * (amplifier * sum + prod1) / ((2 * amplifier - 1) * D + 3 * prod1));
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(F(D * D / ((reserve_in + amount_in) * 2)) * D / (amplifier * 4));
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 BigNumber(x * x + c).div(2 * x + b).toFixed(0, BigNumber.ROUND_DOWN);
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 BigNumber(reserve_out - x);
4015
- const fee = amount_out_with_fee.times(exchange_fee).div(FEE_FACTOR).plus(1).toFixed(0, BigNumber.ROUND_DOWN);
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(BigNumber.ROUND_DOWN).shiftedBy(-precision);
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(BigNumber.ROUND_DOWN);
4023
- return +result.shiftedBy(-precision).toFixed(precision, BigNumber.ROUND_DOWN);
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.185",
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
- "@bloks/utils": "^25.0.0",
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/parser": "^4.28.2",
33
- "size-limit": "^4.9.1",
34
- "tsup": "^6.7.0"
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.5"
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,
package/src/math.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { BigNumber as BN } from 'bignumber.js'
2
- import { FEE_FACTOR } from './constants'
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 = (pool1: BN.Instance, pool2: BN.Instance, swap: BN.Instance, exchange_fee: number, precision: number): BN => {
14
- const term1 = pool2
15
- const term2over = pool1.times(pool2)
16
- const term2under = pool1.plus(swap)
17
- const term2 = term2over.div(term2under).integerValue(BN.ROUND_DOWN)
18
- const term = term1.minus(term2)
19
- const fee = new BN(exchange_fee).div(FEE_FACTOR)
20
- const result = term.minus(term.times(fee))
21
-
22
- return result.integerValue(BN.ROUND_DOWN).shiftedBy(-precision)
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
- return compute_transfer(new BN(reserve_in), new BN(reserve_out), new BN(amount_in), exchange_fee, precision)
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
- return (v >= 0 ? 1 : -1) * Math.floor(Math.abs(v));
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
- const prod1 = F((F((D * D) / (reserve_in * 2)) * D) / (reserve_out * 2));
50
- D_prev = D
51
- D = F((2 * D * ((amplifier * sum) + prod1)) / ((2 * amplifier - 1) * D + 3 * prod1));
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 = ((reserve_in + amount_in) + F(D / (amplifier * 2))) - D;
69
+ const b = reserve_in + amount_in + F(D / (amplifier * 2)) - D;
55
70
 
56
- const c = F(F((D * D) / ((reserve_in + amount_in) * 2)) * D / (amplifier * 4));
71
+ const c = F(
72
+ (F((D * D) / ((reserve_in + amount_in) * 2)) * D) / (amplifier * 4)
73
+ );
57
74
 
58
- let x = D, x_prev = 0;
75
+ let x = D,
76
+ x_prev = 0;
59
77
  i = MAX_ITERATIONS;
60
- while ( x != x_prev && i--) {
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
- throw new Error("curve: insufficient reserve out")
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.times(exchange_fee).div(FEE_FACTOR).plus(1).toFixed(0, BN.ROUND_DOWN);
75
-
76
- // Amount out
77
- const amount_out = amount_out_with_fee.minus(fee)
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
- return amount_out.integerValue(BN.ROUND_DOWN).shiftedBy(-precision)
80
- }
81
-
82
- export const compute_liquidity = (amount_lt: BN.Instance, pool: BN.Instance, lt_supply: BN.Instance, precision: number): number => {
83
- const over = amount_lt.times(pool)
84
- const under = lt_supply
85
- const result = over.div(under).integerValue(BN.ROUND_DOWN)
86
-
87
- return +(result.shiftedBy(-precision).toFixed(precision, BN.ROUND_DOWN))
88
- }
89
-
90
- export const isInputInvalid = (data: string, value: string | number, pool: { xtokenPrecision: number }): boolean => {
91
- value = String(value)
92
-
93
- const isBackspace = data === null
94
- const isNumber = !/[0-9]|\./.test(data)
95
- const isDoubleDot = data === '.' && value.indexOf('.') !== value.length - 1
96
- const isPrecisionTooHigh = value && value.indexOf('.') !== -1 && value.split('.')[1].length > pool.xtokenPrecision
97
- const isInvalid = !isBackspace && Boolean(isNumber || isDoubleDot || isPrecisionTooHigh)
98
-
99
- return isInvalid
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
+ };
@@ -1,22 +1,36 @@
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'
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 = (contract: string, action: string, data: z.ZodRawShape) => {
7
- return z.object({
8
- signer : authorizationParser,
9
- signatures : z.array(z.string()).length(1),
10
- transaction: singleActionTransactionParser(contract, action, data)
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
- time: z.string(),
16
- protonAccount: z.string()
17
- }
18
- const generateAuthActionsBaseParser = baseActionParser(WRAP_CONTRACT, WRAP_AUTH_ACTION, generateAuthData)
19
- export type GenerateAuthBaseAction = z.infer<typeof generateAuthActionsBaseParser>
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(WRAP_CONTRACT, WRAP_AUTH_ACTION, generateAuthData)
22
- export type GenerateAuth = z.infer<typeof generateAuthParser>
31
+ export const generateAuthParser = createAbstractAuthParser(
32
+ WRAP_CONTRACT,
33
+ WRAP_AUTH_ACTION,
34
+ generateAuthData
35
+ );
36
+ export type GenerateAuth = z.infer<typeof generateAuthParser>;
@@ -1,30 +1,29 @@
1
- import { Coin } from "../coins"
2
- import { ExtendedAsset } from '@bloks/numbers'
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
- lt_symbol: string;
8
- creator: string;
9
- memo: string;
10
- pool1: {
11
- quantity: string;
12
- contract: string;
13
- };
14
- pool2: {
15
- quantity: string;
16
- contract: string;
17
- };
18
- hash: string;
19
- fee: {
20
- exchange_fee: number;
21
- add_liquidity_fee: number;
22
- remove_liquidity_fee: number;
23
- };
24
- active: boolean;
25
- amplifier: number;
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, 'pool1'|'pool2'> {
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 PoolTable = {
47
- pool1: ExtendedTokenWithRate;
48
- pool2: ExtendedTokenWithRate;
49
- path: INode<Pool>[];
50
- shortestPath: INode<Pool>[];
51
- getPathString: () => string;
52
- } | undefined
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;