@pioneer-platform/helpers 0.0.0-development.114 → 0.0.1

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.
Files changed (47) hide show
  1. package/lib/helpers/asset.d.ts +36 -0
  2. package/lib/helpers/asset.js +270 -0
  3. package/lib/helpers/liquidity.d.ts +58 -0
  4. package/lib/helpers/liquidity.js +112 -0
  5. package/lib/helpers/memo.d.ts +46 -0
  6. package/lib/helpers/memo.js +46 -0
  7. package/lib/helpers/others.d.ts +3 -0
  8. package/lib/helpers/others.js +24 -0
  9. package/lib/helpers/request.d.ts +5 -0
  10. package/lib/helpers/request.js +74 -0
  11. package/lib/helpers/validators.d.ts +1 -0
  12. package/lib/helpers/validators.js +17 -0
  13. package/lib/index.d.ts +15 -0
  14. package/lib/index.js +31 -0
  15. package/lib/modules/__tests__/assetValue.test.d.ts +1 -0
  16. package/lib/modules/__tests__/assetValue.test.js +399 -0
  17. package/lib/modules/__tests__/swapKitNumber.test.d.ts +1 -0
  18. package/lib/modules/__tests__/swapKitNumber.test.js +425 -0
  19. package/lib/modules/assetValue.d.ts +55 -0
  20. package/lib/modules/assetValue.js +389 -0
  21. package/lib/modules/bigIntArithmetics.d.ts +58 -0
  22. package/lib/modules/bigIntArithmetics.js +344 -0
  23. package/lib/modules/swapKitError.d.ts +64 -0
  24. package/lib/modules/swapKitError.js +90 -0
  25. package/lib/modules/swapKitNumber.d.ts +6 -0
  26. package/lib/modules/swapKitNumber.js +36 -0
  27. package/package.json +20 -33
  28. package/src/helpers/asset.ts +232 -0
  29. package/src/helpers/liquidity.ts +174 -0
  30. package/src/helpers/memo.ts +90 -0
  31. package/src/helpers/others.ts +20 -0
  32. package/src/helpers/request.ts +33 -0
  33. package/src/helpers/validators.ts +17 -0
  34. package/src/index.ts +16 -6
  35. package/src/modules/assetValue.ts +358 -0
  36. package/src/modules/bigIntArithmetics.ts +416 -0
  37. package/src/{exceptions/SwapKitError.ts → modules/swapKitError.ts} +15 -4
  38. package/src/modules/swapKitNumber.ts +16 -0
  39. package/tsconfig.json +13 -0
  40. package/src/__tests__/asset.test.ts +0 -33
  41. package/src/__tests__/derivationPath.test.ts +0 -16
  42. package/src/amount.ts +0 -29
  43. package/src/asset.ts +0 -13
  44. package/src/derivationPath.ts +0 -5
  45. package/src/exceptions/index.ts +0 -1
  46. package/src/fees.ts +0 -13
  47. package/src/request.ts +0 -34
@@ -0,0 +1,344 @@
1
+ "use strict";
2
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
3
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
4
+ if (ar || !(i in from)) {
5
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
6
+ ar[i] = from[i];
7
+ }
8
+ }
9
+ return to.concat(ar || Array.prototype.slice.call(from));
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.BigIntArithmetics = exports.formatBigIntToSafeValue = void 0;
13
+ var types_1 = require("@coinmasters/types");
14
+ var DEFAULT_DECIMAL = 8;
15
+ var bigintPow = function (base, exponent) {
16
+ var result = BigInt(1);
17
+ while (exponent > 0) {
18
+ if (exponent % 2 === 1) {
19
+ result *= base;
20
+ }
21
+ base *= base;
22
+ exponent = Math.floor(exponent / 2);
23
+ }
24
+ return result;
25
+ };
26
+ var toMultiplier = function (decimal) {
27
+ console.log('toMultiplier input decimal:', decimal);
28
+ try {
29
+ var result = bigintPow(BigInt(10), decimal);
30
+ console.log('toMultiplier result:', result);
31
+ return result;
32
+ }
33
+ catch (error) {
34
+ console.error('Error in toMultiplier:', error);
35
+ return BigInt(10);
36
+ }
37
+ };
38
+ var decimalFromMultiplier = function (multiplier) { return Math.log10(Number(multiplier)); };
39
+ function formatBigIntToSafeValue(_a) {
40
+ var value = _a.value, _b = _a.bigIntDecimal, bigIntDecimal = _b === void 0 ? DEFAULT_DECIMAL : _b, _c = _a.decimal, decimal = _c === void 0 ? DEFAULT_DECIMAL : _c;
41
+ var isNegative = value < BigInt(0);
42
+ var valueString = value.toString().substring(isNegative ? 1 : 0);
43
+ var padLength = decimal - (valueString.length - 1);
44
+ if (padLength > 0) {
45
+ valueString = '0'.repeat(padLength) + valueString;
46
+ }
47
+ var decimalIndex = valueString.length - decimal;
48
+ var decimalString = valueString.slice(-decimal);
49
+ if (parseInt(decimalString[bigIntDecimal]) >= 5) {
50
+ decimalString = "".concat(decimalString.substring(0, bigIntDecimal - 1)).concat((parseInt(decimalString[bigIntDecimal - 1]) + 1).toString());
51
+ }
52
+ else {
53
+ decimalString = decimalString.substring(0, bigIntDecimal);
54
+ }
55
+ return "".concat(isNegative ? '-' : '').concat(valueString.slice(0, decimalIndex), ".").concat(decimalString).replace(/\.?0*$/, '');
56
+ }
57
+ exports.formatBigIntToSafeValue = formatBigIntToSafeValue;
58
+ var BigIntArithmetics = /** @class */ (function () {
59
+ function BigIntArithmetics(params) {
60
+ this.decimalMultiplier = bigintPow(BigInt(10), 8);
61
+ this.bigIntValue = BigInt(0);
62
+ console.log('Constructor Params:', params);
63
+ var value = getStringValue(params);
64
+ console.log('String Value:', value);
65
+ var isComplex = typeof params === 'object' && params !== null;
66
+ this.decimal = isComplex ? params.decimal : undefined;
67
+ console.log('Decimal:', this.decimal);
68
+ if (isComplex && 'decimalMultiplier' in params) {
69
+ this.decimalMultiplier = params.decimalMultiplier;
70
+ }
71
+ else {
72
+ var maxDecimals = Math.max(getFloatDecimals(toSafeValue(value)), this.decimal || 0);
73
+ this.decimalMultiplier = toMultiplier(maxDecimals);
74
+ }
75
+ console.log('Decimal Multiplier:', this.decimalMultiplier);
76
+ this.setValue(value);
77
+ console.log('BigInt Value:', this.bigIntValue);
78
+ }
79
+ BigIntArithmetics.fromBigInt = function (value, decimal) {
80
+ return new BigIntArithmetics({
81
+ decimal: decimal,
82
+ value: formatBigIntToSafeValue({ value: value, bigIntDecimal: decimal, decimal: decimal }),
83
+ });
84
+ };
85
+ BigIntArithmetics.shiftDecimals = function (_a) {
86
+ var value = _a.value, from = _a.from, to = _a.to;
87
+ return this.fromBigInt((value.getBaseValue('bigint') * toMultiplier(to)) / toMultiplier(from), to);
88
+ };
89
+ BigIntArithmetics.prototype.set = function (value) {
90
+ // @ts-ignore
91
+ return new BigIntArithmetics({ decimal: this.decimal, value: value });
92
+ };
93
+ BigIntArithmetics.prototype.add = function () {
94
+ var args = [];
95
+ for (var _i = 0; _i < arguments.length; _i++) {
96
+ args[_i] = arguments[_i];
97
+ }
98
+ return this.arithmetics.apply(this, __spreadArray(['add'], args, false));
99
+ };
100
+ BigIntArithmetics.prototype.sub = function () {
101
+ var args = [];
102
+ for (var _i = 0; _i < arguments.length; _i++) {
103
+ args[_i] = arguments[_i];
104
+ }
105
+ return this.arithmetics.apply(this, __spreadArray(['sub'], args, false));
106
+ };
107
+ BigIntArithmetics.prototype.mul = function () {
108
+ var args = [];
109
+ for (var _i = 0; _i < arguments.length; _i++) {
110
+ args[_i] = arguments[_i];
111
+ }
112
+ return this.arithmetics.apply(this, __spreadArray(['mul'], args, false));
113
+ };
114
+ BigIntArithmetics.prototype.div = function () {
115
+ var args = [];
116
+ for (var _i = 0; _i < arguments.length; _i++) {
117
+ args[_i] = arguments[_i];
118
+ }
119
+ return this.arithmetics.apply(this, __spreadArray(['div'], args, false));
120
+ };
121
+ BigIntArithmetics.prototype.gt = function (value) {
122
+ return this.comparison('gt', value);
123
+ };
124
+ BigIntArithmetics.prototype.gte = function (value) {
125
+ return this.comparison('gte', value);
126
+ };
127
+ BigIntArithmetics.prototype.lt = function (value) {
128
+ return this.comparison('lt', value);
129
+ };
130
+ BigIntArithmetics.prototype.lte = function (value) {
131
+ return this.comparison('lte', value);
132
+ };
133
+ BigIntArithmetics.prototype.eqValue = function (value) {
134
+ return this.comparison('eqValue', value);
135
+ };
136
+ // @ts-ignore
137
+ BigIntArithmetics.prototype.getValue = function (type) {
138
+ var value = formatBigIntToSafeValue({
139
+ value: this.bigIntValue,
140
+ bigIntDecimal: this.decimal || decimalFromMultiplier(this.decimalMultiplier),
141
+ });
142
+ switch (type) {
143
+ case 'number':
144
+ return Number(value);
145
+ case 'string':
146
+ return value;
147
+ case 'bigint':
148
+ return ((this.bigIntValue * bigintPow(BigInt(10), this.decimal || 8)) /
149
+ this.decimalMultiplier);
150
+ }
151
+ };
152
+ // @ts-ignore
153
+ BigIntArithmetics.prototype.getBaseValue = function (type) {
154
+ var divisor = this.decimalMultiplier / toMultiplier(this.decimal || types_1.BaseDecimal.THOR);
155
+ var baseValue = this.bigIntValue / divisor;
156
+ switch (type) {
157
+ case 'number':
158
+ return Number(baseValue);
159
+ case 'string':
160
+ return baseValue.toString();
161
+ case 'bigint':
162
+ return baseValue;
163
+ }
164
+ };
165
+ BigIntArithmetics.prototype.getBigIntValue = function (value, decimal) {
166
+ if (!decimal && typeof value === 'object' && value !== null) {
167
+ return value.bigIntValue;
168
+ }
169
+ var stringValue = getStringValue(value);
170
+ var safeValue = toSafeValue(stringValue);
171
+ if (safeValue === '0' || safeValue === 'undefined')
172
+ return BigInt(0);
173
+ return this.toBigInt(safeValue, decimal);
174
+ };
175
+ BigIntArithmetics.prototype.toSignificant = function (significantDigits) {
176
+ if (significantDigits === void 0) { significantDigits = 6; }
177
+ var _a = this.getValue('string').split('.'), int = _a[0], dec = _a[1];
178
+ var integer = int || '';
179
+ var decimal = dec || '';
180
+ var valueLength = parseInt(integer) ? integer.length + decimal.length : decimal.length;
181
+ if (valueLength <= significantDigits) {
182
+ return this.getValue('string');
183
+ }
184
+ if (integer.length >= significantDigits) {
185
+ return integer.slice(0, significantDigits).padEnd(integer.length, '0');
186
+ }
187
+ if (parseInt(integer)) {
188
+ return "".concat(integer, ".").concat(decimal.slice(0, significantDigits - integer.length)).padEnd(significantDigits - integer.length, '0');
189
+ }
190
+ var trimmedDecimal = parseInt(decimal);
191
+ var slicedDecimal = "".concat(trimmedDecimal).slice(0, significantDigits);
192
+ return "0.".concat(slicedDecimal.padStart(decimal.length - "".concat(trimmedDecimal).length + slicedDecimal.length, '0'));
193
+ };
194
+ BigIntArithmetics.prototype.toFixed = function (fixedDigits) {
195
+ if (fixedDigits === void 0) { fixedDigits = 6; }
196
+ var _a = this.getValue('string').split('.'), int = _a[0], dec = _a[1];
197
+ var integer = int || '';
198
+ var decimal = dec || '';
199
+ if (parseInt(integer)) {
200
+ return "".concat(integer, ".").concat(decimal.slice(0, fixedDigits)).padEnd(fixedDigits, '0');
201
+ }
202
+ var trimmedDecimal = parseInt(decimal);
203
+ var slicedDecimal = "".concat(trimmedDecimal).slice(0, fixedDigits);
204
+ return "0.".concat(slicedDecimal.padStart(decimal.length - "".concat(trimmedDecimal).length + slicedDecimal.length, '0'));
205
+ };
206
+ BigIntArithmetics.prototype.toAbbreviation = function (digits) {
207
+ if (digits === void 0) { digits = 2; }
208
+ var value = this.getValue('number');
209
+ var abbreviations = ['', 'K', 'M', 'B', 'T', 'Q', 'Qi', 'S'];
210
+ var tier = Math.floor(Math.log10(Math.abs(value)) / 3);
211
+ var suffix = abbreviations[tier];
212
+ if (!suffix)
213
+ return this.getValue('string');
214
+ var scale = Math.pow(10, (tier * 3));
215
+ var scaled = value / scale;
216
+ return "".concat(scaled.toFixed(digits)).concat(suffix);
217
+ };
218
+ BigIntArithmetics.prototype.toCurrency = function (currency, _a) {
219
+ if (currency === void 0) { currency = '$'; }
220
+ var _b = _a === void 0 ? {} : _a, _c = _b.currencyPosition, currencyPosition = _c === void 0 ? 'start' : _c, _d = _b.decimal, decimal = _d === void 0 ? 2 : _d, _e = _b.decimalSeparator, decimalSeparator = _e === void 0 ? '.' : _e, _f = _b.thousandSeparator, thousandSeparator = _f === void 0 ? ',' : _f;
221
+ var value = this.getValue('number');
222
+ var _g = value.toFixed(6).split('.'), int = _g[0], _h = _g[1], dec = _h === void 0 ? '' : _h;
223
+ var integer = int.replace(/\B(?=(\d{3})+(?!\d))/g, thousandSeparator);
224
+ var parsedValue = !int && !dec
225
+ ? '0.00'
226
+ : int === '0'
227
+ ? "".concat(parseFloat("0.".concat(dec))).replace('.', decimalSeparator)
228
+ : "".concat(integer).concat(parseInt(dec) ? "".concat(decimalSeparator).concat(dec.slice(0, decimal)) : '');
229
+ return "".concat(currencyPosition === 'start' ? currency : '').concat(parsedValue).concat(currencyPosition === 'end' ? currency : '');
230
+ };
231
+ BigIntArithmetics.prototype.arithmetics = function (method) {
232
+ var _this = this;
233
+ var args = [];
234
+ for (var _i = 1; _i < arguments.length; _i++) {
235
+ args[_i - 1] = arguments[_i];
236
+ }
237
+ var precisionDecimal = this.retrievePrecisionDecimal.apply(this, __spreadArray([this], args, false));
238
+ var decimal = Math.max(precisionDecimal, decimalFromMultiplier(this.decimalMultiplier));
239
+ var precisionDecimalMultiplier = toMultiplier(decimal);
240
+ var result = args.reduce(function (acc, arg) {
241
+ var value = _this.getBigIntValue(arg, decimal);
242
+ switch (method) {
243
+ case 'add':
244
+ return acc + value;
245
+ case 'sub':
246
+ return acc - value;
247
+ case 'mul':
248
+ return (acc * value) / precisionDecimalMultiplier;
249
+ case 'div': {
250
+ if (value === BigInt(0))
251
+ throw new RangeError('Division by zero');
252
+ return (acc * precisionDecimalMultiplier) / value;
253
+ }
254
+ default:
255
+ return acc;
256
+ }
257
+ }, (this.bigIntValue * precisionDecimalMultiplier) / this.decimalMultiplier);
258
+ var formattedValue = formatBigIntToSafeValue({
259
+ bigIntDecimal: decimal,
260
+ decimal: decimal,
261
+ value: result,
262
+ });
263
+ return new BigIntArithmetics({
264
+ decimalMultiplier: toMultiplier(decimal),
265
+ decimal: this.decimal,
266
+ value: formattedValue,
267
+ });
268
+ };
269
+ BigIntArithmetics.prototype.comparison = function (method) {
270
+ var args = [];
271
+ for (var _i = 1; _i < arguments.length; _i++) {
272
+ args[_i - 1] = arguments[_i];
273
+ }
274
+ var decimal = this.retrievePrecisionDecimal.apply(this, __spreadArray([this], args, false));
275
+ var value = this.getBigIntValue(args[0], decimal);
276
+ var compareToValue = this.getBigIntValue(this, decimal);
277
+ switch (method) {
278
+ case 'gt':
279
+ return compareToValue > value;
280
+ case 'gte':
281
+ return compareToValue >= value;
282
+ case 'lt':
283
+ return compareToValue < value;
284
+ case 'lte':
285
+ return compareToValue <= value;
286
+ case 'eqValue':
287
+ return compareToValue === value;
288
+ }
289
+ };
290
+ BigIntArithmetics.prototype.setValue = function (value) {
291
+ var safeValue = toSafeValue(value) || '0';
292
+ this.bigIntValue = this.toBigInt(safeValue);
293
+ };
294
+ BigIntArithmetics.prototype.retrievePrecisionDecimal = function () {
295
+ var args = [];
296
+ for (var _i = 0; _i < arguments.length; _i++) {
297
+ args[_i] = arguments[_i];
298
+ }
299
+ var decimals = args
300
+ .map(function (arg) {
301
+ var isObject = typeof arg === 'object' && arg !== null;
302
+ var value = isObject
303
+ ? arg.decimal || decimalFromMultiplier(arg.decimalMultiplier)
304
+ : getFloatDecimals(toSafeValue(arg));
305
+ return value;
306
+ })
307
+ .filter(Boolean);
308
+ return Math.max.apply(Math, __spreadArray(__spreadArray([], decimals, false), [DEFAULT_DECIMAL], false));
309
+ };
310
+ BigIntArithmetics.prototype.toBigInt = function (value, decimal) {
311
+ var multiplier = decimal ? toMultiplier(decimal) : this.decimalMultiplier;
312
+ var padDecimal = decimalFromMultiplier(multiplier);
313
+ var _a = value.split('.'), _b = _a[0], integerPart = _b === void 0 ? '' : _b, _c = _a[1], decimalPart = _c === void 0 ? '' : _c;
314
+ return BigInt("".concat(integerPart).concat(decimalPart.padEnd(padDecimal, '0')));
315
+ };
316
+ return BigIntArithmetics;
317
+ }());
318
+ exports.BigIntArithmetics = BigIntArithmetics;
319
+ var numberFormatter = Intl.NumberFormat('fullwide', {
320
+ useGrouping: false,
321
+ maximumFractionDigits: 20,
322
+ });
323
+ function toSafeValue(value) {
324
+ var parsedValue = typeof value === 'number' ? numberFormatter.format(value) : getStringValue(value);
325
+ var splitValue = "".concat(parsedValue).replace(/,/g, '.').split('.');
326
+ return splitValue.length > 1
327
+ ? "".concat(splitValue.slice(0, -1).join(''), ".").concat(splitValue.at(-1))
328
+ : splitValue[0];
329
+ }
330
+ function getFloatDecimals(value) {
331
+ var decimals = 0;
332
+ var parts = value.split('.');
333
+ if (parts.length > 1 && parts[1].length > 0) {
334
+ decimals = parts[1].length;
335
+ }
336
+ return Math.max(decimals, DEFAULT_DECIMAL);
337
+ }
338
+ function getStringValue(param) {
339
+ return typeof param === 'object' && param !== null
340
+ ? 'getValue' in param
341
+ ? param.getValue('string')
342
+ : param.value
343
+ : param;
344
+ }
@@ -0,0 +1,64 @@
1
+ declare const errorMessages: {
2
+ /**
3
+ * Core
4
+ */
5
+ readonly core_wallet_connection_not_found: 10001;
6
+ readonly core_estimated_max_spendable_chain_not_supported: 10002;
7
+ readonly core_extend_error: 10003;
8
+ readonly core_inbound_data_not_found: 10004;
9
+ readonly core_approve_asset_address_or_from_not_found: 10005;
10
+ readonly core_chain_halted: 10099;
11
+ /**
12
+ * Core - Wallet Connection
13
+ */
14
+ readonly core_wallet_xdefi_not_installed: 10101;
15
+ readonly core_wallet_evmwallet_not_installed: 10102;
16
+ readonly core_wallet_walletconnect_not_installed: 10103;
17
+ readonly core_wallet_keystore_not_installed: 10104;
18
+ readonly core_wallet_ledger_not_installed: 10105;
19
+ readonly core_wallet_trezor_not_installed: 10106;
20
+ readonly core_wallet_keplr_not_installed: 10107;
21
+ readonly core_wallet_okx_not_installed: 10108;
22
+ readonly core_wallet_keepkey_not_installed: 10109;
23
+ /**
24
+ * Core - Swap
25
+ */
26
+ readonly core_swap_invalid_params: 10200;
27
+ readonly core_swap_route_not_complete: 10201;
28
+ readonly core_swap_asset_not_recognized: 10202;
29
+ readonly core_swap_contract_not_found: 10203;
30
+ readonly core_swap_route_transaction_not_found: 10204;
31
+ readonly core_swap_contract_not_supported: 10205;
32
+ readonly core_swap_quote_mode_not_supported: 10207;
33
+ /**
34
+ * Core - Transaction
35
+ */
36
+ readonly core_transaction_deposit_error: 10301;
37
+ readonly core_transaction_create_liquidity_rune_error: 10302;
38
+ readonly core_transaction_create_liquidity_asset_error: 10303;
39
+ readonly core_transaction_create_liquidity_invalid_params: 10304;
40
+ readonly core_transaction_add_liquidity_invalid_params: 10305;
41
+ readonly core_transaction_add_liquidity_no_rune_address: 10306;
42
+ readonly core_transaction_add_liquidity_rune_error: 10307;
43
+ readonly core_transaction_add_liquidity_asset_error: 10308;
44
+ readonly core_transaction_withdraw_error: 10309;
45
+ readonly core_transaction_deposit_to_pool_error: 10310;
46
+ readonly core_transaction_deposit_insufficient_funds_error: 10311;
47
+ readonly core_transaction_deposit_gas_error: 10312;
48
+ readonly core_transaction_invalid_sender_address: 10313;
49
+ readonly core_transaction_deposit_server_error: 10314;
50
+ readonly core_swap_transaction_error: 10400;
51
+ /**
52
+ * Wallets
53
+ */
54
+ readonly wallet_ledger_connection_error: 20001;
55
+ /**
56
+ * Helpers
57
+ */
58
+ readonly helpers_number_different_decimals: 99101;
59
+ };
60
+ export type Keys = keyof typeof errorMessages;
61
+ export declare class SwapKitError extends Error {
62
+ constructor(errorKey: Keys, sourceError?: any);
63
+ }
64
+ export {};
@@ -0,0 +1,90 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.SwapKitError = void 0;
19
+ var errorMessages = {
20
+ /**
21
+ * Core
22
+ */
23
+ core_wallet_connection_not_found: 10001,
24
+ core_estimated_max_spendable_chain_not_supported: 10002,
25
+ core_extend_error: 10003,
26
+ core_inbound_data_not_found: 10004,
27
+ core_approve_asset_address_or_from_not_found: 10005,
28
+ core_chain_halted: 10099,
29
+ /**
30
+ * Core - Wallet Connection
31
+ */
32
+ core_wallet_xdefi_not_installed: 10101,
33
+ core_wallet_evmwallet_not_installed: 10102,
34
+ core_wallet_walletconnect_not_installed: 10103,
35
+ core_wallet_keystore_not_installed: 10104,
36
+ core_wallet_ledger_not_installed: 10105,
37
+ core_wallet_trezor_not_installed: 10106,
38
+ core_wallet_keplr_not_installed: 10107,
39
+ core_wallet_okx_not_installed: 10108,
40
+ core_wallet_keepkey_not_installed: 10109,
41
+ /**
42
+ * Core - Swap
43
+ */
44
+ core_swap_invalid_params: 10200,
45
+ core_swap_route_not_complete: 10201,
46
+ core_swap_asset_not_recognized: 10202,
47
+ core_swap_contract_not_found: 10203,
48
+ core_swap_route_transaction_not_found: 10204,
49
+ core_swap_contract_not_supported: 10205,
50
+ core_swap_quote_mode_not_supported: 10207,
51
+ /**
52
+ * Core - Transaction
53
+ */
54
+ core_transaction_deposit_error: 10301,
55
+ core_transaction_create_liquidity_rune_error: 10302,
56
+ core_transaction_create_liquidity_asset_error: 10303,
57
+ core_transaction_create_liquidity_invalid_params: 10304,
58
+ core_transaction_add_liquidity_invalid_params: 10305,
59
+ core_transaction_add_liquidity_no_rune_address: 10306,
60
+ core_transaction_add_liquidity_rune_error: 10307,
61
+ core_transaction_add_liquidity_asset_error: 10308,
62
+ core_transaction_withdraw_error: 10309,
63
+ core_transaction_deposit_to_pool_error: 10310,
64
+ core_transaction_deposit_insufficient_funds_error: 10311,
65
+ core_transaction_deposit_gas_error: 10312,
66
+ core_transaction_invalid_sender_address: 10313,
67
+ core_transaction_deposit_server_error: 10314,
68
+ core_swap_transaction_error: 10400,
69
+ /**
70
+ * Wallets
71
+ */
72
+ wallet_ledger_connection_error: 20001,
73
+ /**
74
+ * Helpers
75
+ */
76
+ helpers_number_different_decimals: 99101,
77
+ };
78
+ var SwapKitError = /** @class */ (function (_super) {
79
+ __extends(SwapKitError, _super);
80
+ function SwapKitError(errorKey, sourceError) {
81
+ var _this = this;
82
+ console.error(sourceError, { stack: sourceError === null || sourceError === void 0 ? void 0 : sourceError.stack, message: sourceError === null || sourceError === void 0 ? void 0 : sourceError.message });
83
+ // @ts-ignore
84
+ _this = _super.call(this, errorKey, { cause: { code: errorMessages[errorKey], message: errorKey } }) || this;
85
+ Object.setPrototypeOf(_this, SwapKitError.prototype);
86
+ return _this;
87
+ }
88
+ return SwapKitError;
89
+ }(Error));
90
+ exports.SwapKitError = SwapKitError;
@@ -0,0 +1,6 @@
1
+ import { BigIntArithmetics } from './bigIntArithmetics';
2
+ export type SwapKitValueType = BigIntArithmetics | string | number;
3
+ export declare class SwapKitNumber extends BigIntArithmetics {
4
+ eq(value: SwapKitValueType): boolean;
5
+ static fromBigInt(value: bigint, decimal?: number): SwapKitNumber;
6
+ }
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.SwapKitNumber = void 0;
19
+ var bigIntArithmetics_1 = require("./bigIntArithmetics");
20
+ var SwapKitNumber = /** @class */ (function (_super) {
21
+ __extends(SwapKitNumber, _super);
22
+ function SwapKitNumber() {
23
+ return _super !== null && _super.apply(this, arguments) || this;
24
+ }
25
+ SwapKitNumber.prototype.eq = function (value) {
26
+ return this.eqValue(value);
27
+ };
28
+ SwapKitNumber.fromBigInt = function (value, decimal) {
29
+ return new SwapKitNumber({
30
+ decimal: decimal,
31
+ value: (0, bigIntArithmetics_1.formatBigIntToSafeValue)({ value: value, bigIntDecimal: decimal, decimal: decimal }),
32
+ });
33
+ };
34
+ return SwapKitNumber;
35
+ }(bigIntArithmetics_1.BigIntArithmetics));
36
+ exports.SwapKitNumber = SwapKitNumber;
package/package.json CHANGED
@@ -1,38 +1,25 @@
1
1
  {
2
- "dependencies": {
3
- "@pioneer-platform/swapkit-entities": "workspace:*",
4
- "@pioneer-platform/types": "workspace:*"
5
- },
6
- "description": "THORSwap Lib - Helper library for THORSwap",
7
- "devDependencies": {
8
- "@ethersproject/bignumber": "5.7.0",
9
- "@internal/config": "workspace:*",
10
- "@vitest/coverage-istanbul": "0.34.3",
11
- "bignumber.js": "9.1.2",
12
- "vite": "4.4.9",
13
- "vitest": "0.34.3"
14
- },
15
- "eslintConfig": {
16
- "extends": "../eslint-config-thorswap"
17
- },
18
- "files": [
19
- "src/"
20
- ],
21
- "homepage": "https://github.com/thorswap/SwapKit",
22
- "license": "MIT",
23
- "main": "./src/index.ts",
24
2
  "name": "@pioneer-platform/helpers",
25
- "peerDependencies": {
26
- "@ethersproject/bignumber": "^5.7.0",
27
- "bignumber.js": "^9.1.2"
28
- },
3
+ "version": "0.0.1",
4
+ "main": "./lib/index.js",
5
+ "types": "./lib/main.d.ts",
29
6
  "scripts": {
30
- "build": "vite build",
31
- "clean": "rm -rf dist .turbo node_modules",
32
- "lint": "eslint --ext .ts,.tsx --fix; tsc --noEmit",
33
- "test": "vitest --run",
34
- "test:coverage": "vitest run --coverage"
7
+ "npm": "npm i",
8
+ "test": "npm run build && node __tests__/test-module.js",
9
+ "lint": "prettier --write '**/**/*.ts'",
10
+ "start": "nodemon --watch 'src/**/*.ts' --exec ts-node __tests__node",
11
+ "build": "tsc -p .",
12
+ "prepublish": "npm run build",
13
+ "refresh": "rm -rf ./node_modules ./package-lock.json && npm install"
14
+ },
15
+ "dependencies": {
16
+ "@coinmasters/tokens": "^3.7.28",
17
+ "@coinmasters/types": "^4.7.28",
18
+ "@noble/hashes": "^1.4.0",
19
+ "@pioneer-platform/loggerdog": "^8.3.1",
20
+ "@types/node": "^18.15.11",
21
+ "ts-node": "^8.10.2",
22
+ "typescript": "^5.0.2"
35
23
  },
36
- "type": "module",
37
- "version": "0.0.0-development.114"
24
+ "gitHead": "aeae28273014ab69b42f22abec159c6693a56c40"
38
25
  }