@pioneer-platform/helpers 0.0.0 → 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 (48) 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 +22 -35
  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/LICENSE +0 -21
  41. package/src/__tests__/asset.test.ts +0 -33
  42. package/src/__tests__/derivationPath.test.ts +0 -16
  43. package/src/amount.ts +0 -29
  44. package/src/asset.ts +0 -13
  45. package/src/derivationPath.ts +0 -5
  46. package/src/exceptions/index.ts +0 -1
  47. package/src/fees.ts +0 -13
  48. package/src/request.ts +0 -34
@@ -0,0 +1,74 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ var __importDefault = (this && this.__importDefault) || function (mod) {
39
+ return (mod && mod.__esModule) ? mod : { "default": mod };
40
+ };
41
+ Object.defineProperty(exports, "__esModule", { value: true });
42
+ exports.RequestClient = void 0;
43
+ var ky_1 = __importDefault(require("ky"));
44
+ var headers = typeof window !== 'undefined'
45
+ ? {}
46
+ : {
47
+ Referrer: 'https://sk.thorswap.net',
48
+ Referer: 'https://sk.thorswap.net',
49
+ };
50
+ // Define default options for the new ky instance
51
+ var defaultOptions = {
52
+ headers: headers,
53
+ timeout: 30000, // Example: 10000 milliseconds = 10 seconds
54
+ retry: {
55
+ limit: 2, // Maximum number of retry attempts
56
+ methods: ['get', 'post', 'put', 'patch', 'head', 'delete'], // HTTP methods to retry
57
+ statusCodes: [408, 500, 502, 503, 504], // HTTP status codes to retry
58
+ },
59
+ };
60
+ // Create a new ky instance with the default options
61
+ var kyInstance = ky_1.default.create(defaultOptions);
62
+ exports.RequestClient = {
63
+ get: function (url, options) { return __awaiter(void 0, void 0, void 0, function () {
64
+ return __generator(this, function (_a) {
65
+ return [2 /*return*/, kyInstance.get(url, options).json()];
66
+ });
67
+ }); },
68
+ post: function (url, options) { return __awaiter(void 0, void 0, void 0, function () {
69
+ return __generator(this, function (_a) {
70
+ return [2 /*return*/, kyInstance.post(url, options).json()];
71
+ });
72
+ }); },
73
+ // Implement other methods (put, delete, patch, head) as needed
74
+ };
@@ -0,0 +1 @@
1
+ export declare const validateIdentifier: (identifier?: string) => boolean;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.validateIdentifier = void 0;
4
+ var types_1 = require("@coinmasters/types");
5
+ var supportedChains = Object.values(types_1.Chain);
6
+ var validateIdentifier = function (identifier) {
7
+ if (identifier === void 0) { identifier = ''; }
8
+ var uppercasedIdentifier = identifier.toUpperCase();
9
+ var chain = uppercasedIdentifier.split('.')[0];
10
+ if (supportedChains.includes(chain))
11
+ return true;
12
+ var synthChain = uppercasedIdentifier.split('/')[0];
13
+ if (supportedChains.includes(synthChain))
14
+ return true;
15
+ throw new Error("Invalid identifier: ".concat(identifier, ". Expected format: <Chain>.<Ticker> or <Chain>.<Ticker>-<ContractAddress>"));
16
+ };
17
+ exports.validateIdentifier = validateIdentifier;
package/lib/index.d.ts ADDED
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Helpers
3
+ */
4
+ export * from './helpers/asset';
5
+ export * from './helpers/liquidity';
6
+ export * from './helpers/memo';
7
+ export * from './helpers/others';
8
+ export * from './helpers/request';
9
+ /**
10
+ * Modules
11
+ */
12
+ export * from './modules/assetValue';
13
+ export * from './modules/bigIntArithmetics';
14
+ export * from './modules/swapKitError';
15
+ export * from './modules/swapKitNumber';
package/lib/index.js ADDED
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ /**
18
+ * Helpers
19
+ */
20
+ __exportStar(require("./helpers/asset"), exports);
21
+ __exportStar(require("./helpers/liquidity"), exports);
22
+ __exportStar(require("./helpers/memo"), exports);
23
+ __exportStar(require("./helpers/others"), exports);
24
+ __exportStar(require("./helpers/request"), exports);
25
+ /**
26
+ * Modules
27
+ */
28
+ __exportStar(require("./modules/assetValue"), exports);
29
+ __exportStar(require("./modules/bigIntArithmetics"), exports);
30
+ __exportStar(require("./modules/swapKitError"), exports);
31
+ __exportStar(require("./modules/swapKitNumber"), exports);
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,399 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ var types_1 = require("@coinmasters/types");
40
+ var vitest_1 = require("vitest");
41
+ var assetValue_ts_1 = require("../assetValue.ts");
42
+ (0, vitest_1.describe)('AssetValue', function () {
43
+ (0, vitest_1.describe)('assetValue', function () {
44
+ (0, vitest_1.test)('returns asset ticker with value', function () {
45
+ var fakeAvaxUSDCAsset = new assetValue_ts_1.AssetValue({
46
+ decimal: 6,
47
+ value: 1234567890,
48
+ chain: types_1.Chain.Avalanche,
49
+ symbol: 'USDC-0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e',
50
+ });
51
+ (0, vitest_1.expect)(fakeAvaxUSDCAsset.toString(true)).toBe('USDC');
52
+ (0, vitest_1.expect)(fakeAvaxUSDCAsset.toString()).toBe('AVAX.USDC-0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e');
53
+ var thor = assetValue_ts_1.AssetValue.fromChainOrSignature('ETH.THOR');
54
+ (0, vitest_1.expect)(thor.toString(true)).toBe('THOR');
55
+ var ethSynth = new assetValue_ts_1.AssetValue({
56
+ chain: types_1.Chain.THORChain,
57
+ symbol: 'ETH/ETH',
58
+ decimal: 8,
59
+ value: 1234567890,
60
+ });
61
+ (0, vitest_1.expect)(ethSynth.toString()).toBe('THOR.ETH/ETH');
62
+ (0, vitest_1.expect)(ethSynth.toString(true)).toBe('ETH/ETH');
63
+ (0, vitest_1.expect)(ethSynth.mul(21.37).getValue('string')).toBe('26382715809.3');
64
+ var ethThorSynth = new assetValue_ts_1.AssetValue({
65
+ chain: types_1.Chain.THORChain,
66
+ symbol: 'ETH/THOR-0xa5f2211b9b8170f694421f2046281775e8468044',
67
+ decimal: 8,
68
+ value: 1234567890,
69
+ });
70
+ (0, vitest_1.expect)(ethThorSynth.toString()).toBe('THOR.ETH/THOR-0xa5f2211b9b8170f694421f2046281775e8468044');
71
+ (0, vitest_1.expect)(ethThorSynth.toString(true)).toBe('ETH/THOR-0xa5f2211b9b8170f694421f2046281775e8468044');
72
+ var atomDerived = new assetValue_ts_1.AssetValue({
73
+ identifier: 'THOR.ATOM',
74
+ decimal: 6,
75
+ value: 123456789,
76
+ });
77
+ (0, vitest_1.expect)(atomDerived.toString(true)).toBe('ATOM');
78
+ (0, vitest_1.expect)(atomDerived.toString()).toBe('THOR.ATOM');
79
+ });
80
+ });
81
+ (0, vitest_1.describe)('toUrl', function () {
82
+ (0, vitest_1.test)('returns asset compliance with url', function () {
83
+ var fakeAvaxUSDCAsset = new assetValue_ts_1.AssetValue({
84
+ decimal: 6,
85
+ value: 1234567890,
86
+ chain: types_1.Chain.Avalanche,
87
+ symbol: 'USDC-0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e',
88
+ });
89
+ (0, vitest_1.expect)(fakeAvaxUSDCAsset.toUrl()).toBe('AVAX.USDC-0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e');
90
+ var thor = assetValue_ts_1.AssetValue.fromChainOrSignature('ETH.THOR');
91
+ (0, vitest_1.expect)(thor.toUrl()).toBe('ETH.THOR-0xa5f2211b9b8170f694421f2046281775e8468044');
92
+ var ethSynth = new assetValue_ts_1.AssetValue({
93
+ chain: types_1.Chain.THORChain,
94
+ symbol: 'ETH/ETH',
95
+ decimal: 8,
96
+ value: 1234567890,
97
+ });
98
+ (0, vitest_1.expect)(ethSynth.toUrl()).toBe('THOR.ETH.ETH');
99
+ var ethThorSynth = new assetValue_ts_1.AssetValue({
100
+ chain: types_1.Chain.THORChain,
101
+ symbol: 'ETH/THOR-0xa5f2211b9b8170f694421f2046281775e8468044',
102
+ decimal: 8,
103
+ value: 1234567890,
104
+ });
105
+ (0, vitest_1.expect)(ethThorSynth.toUrl()).toBe('THOR.ETH.THOR-0xa5f2211b9b8170f694421f2046281775e8468044');
106
+ });
107
+ });
108
+ (0, vitest_1.describe)('eq', function () {
109
+ (0, vitest_1.test)('checks if assets are same chain and symbol', function () {
110
+ var firstThor = assetValue_ts_1.AssetValue.fromChainOrSignature('ETH.THOR');
111
+ var secondThor = assetValue_ts_1.AssetValue.fromChainOrSignature('ETH.THOR');
112
+ var vThor = assetValue_ts_1.AssetValue.fromChainOrSignature('ETH.vTHOR');
113
+ var firstUsdc = new assetValue_ts_1.AssetValue({
114
+ chain: types_1.Chain.Avalanche,
115
+ symbol: 'USDC-0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e',
116
+ decimal: 6,
117
+ value: 1234567890,
118
+ });
119
+ var secondUsdc = new assetValue_ts_1.AssetValue({
120
+ chain: types_1.Chain.Avalanche,
121
+ symbol: 'USDC-0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e',
122
+ decimal: 6,
123
+ value: 1234,
124
+ });
125
+ (0, vitest_1.expect)(firstThor.eq(firstThor)).toBe(true);
126
+ (0, vitest_1.expect)(firstThor.eq(secondThor)).toBe(true);
127
+ (0, vitest_1.expect)(firstThor.eq(vThor)).toBe(false);
128
+ (0, vitest_1.expect)(firstThor.eq(firstUsdc)).toBe(false);
129
+ (0, vitest_1.expect)(firstThor.eq(secondUsdc)).toBe(false);
130
+ (0, vitest_1.expect)(firstUsdc.eq(firstThor)).toBe(false);
131
+ (0, vitest_1.expect)(firstUsdc.eq(secondThor)).toBe(false);
132
+ (0, vitest_1.expect)(firstUsdc.eq(vThor)).toBe(false);
133
+ (0, vitest_1.expect)(firstUsdc.eq(firstUsdc)).toBe(true);
134
+ (0, vitest_1.expect)(firstUsdc.eq(secondUsdc)).toBe(true);
135
+ });
136
+ });
137
+ (0, vitest_1.describe)('from bigint', function () {
138
+ (0, vitest_1.test)('returns asset value with correct decimal', function () { return __awaiter(void 0, void 0, void 0, function () {
139
+ var avaxUSDCAsset;
140
+ return __generator(this, function (_a) {
141
+ switch (_a.label) {
142
+ case 0: return [4 /*yield*/, assetValue_ts_1.AssetValue.fromIdentifier("".concat(types_1.Chain.Avalanche, ".USDC-0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e"), 1234567800n)];
143
+ case 1:
144
+ avaxUSDCAsset = _a.sent();
145
+ (0, vitest_1.expect)(avaxUSDCAsset.getValue('string')).toBe('1234.5678');
146
+ return [2 /*return*/];
147
+ }
148
+ });
149
+ }); });
150
+ });
151
+ (0, vitest_1.describe)('toString', function () {
152
+ (0, vitest_1.test)('returns asset value string/identifier', function () { return __awaiter(void 0, void 0, void 0, function () {
153
+ var avaxUSDCAsset, thor, ethSynth;
154
+ return __generator(this, function (_a) {
155
+ switch (_a.label) {
156
+ case 0:
157
+ avaxUSDCAsset = new assetValue_ts_1.AssetValue({
158
+ decimal: 6,
159
+ value: 1234567890,
160
+ chain: types_1.Chain.Avalanche,
161
+ symbol: 'USDC-0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e',
162
+ });
163
+ (0, vitest_1.expect)(avaxUSDCAsset.toString()).toBe('AVAX.USDC-0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e');
164
+ thor = assetValue_ts_1.AssetValue.fromChainOrSignature('ETH.THOR');
165
+ (0, vitest_1.expect)(thor.toString()).toBe('ETH.THOR-0xa5f2211b9b8170f694421f2046281775e8468044');
166
+ return [4 /*yield*/, assetValue_ts_1.AssetValue.fromIdentifier('ETH/ETH')];
167
+ case 1:
168
+ ethSynth = _a.sent();
169
+ (0, vitest_1.expect)(ethSynth.toString()).toBe('THOR.ETH/ETH');
170
+ return [2 /*return*/];
171
+ }
172
+ });
173
+ }); });
174
+ });
175
+ (0, vitest_1.describe)('fromIdentifier', function () {
176
+ (0, vitest_1.test)('creates AssetValue from string', function () { return __awaiter(void 0, void 0, void 0, function () {
177
+ var avaxUSDCAsset;
178
+ return __generator(this, function (_a) {
179
+ switch (_a.label) {
180
+ case 0: return [4 /*yield*/, assetValue_ts_1.AssetValue.fromIdentifier('AVAX.USDC-0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e')];
181
+ case 1:
182
+ avaxUSDCAsset = _a.sent();
183
+ (0, vitest_1.expect)(avaxUSDCAsset).toEqual(vitest_1.expect.objectContaining({
184
+ address: '0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e',
185
+ chain: types_1.Chain.Avalanche,
186
+ decimal: 6,
187
+ isGasAsset: false,
188
+ isSynthetic: false,
189
+ symbol: 'USDC-0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e',
190
+ ticker: 'USDC',
191
+ }));
192
+ return [2 /*return*/];
193
+ }
194
+ });
195
+ }); });
196
+ });
197
+ (0, vitest_1.describe)('fromString', function () {
198
+ (0, vitest_1.test)('creates AssetValue from string', function () {
199
+ (0, vitest_1.test)('creates AssetValue from string', function () { return __awaiter(void 0, void 0, void 0, function () {
200
+ var fakeAvaxAssetString, fakeAvaxAsset;
201
+ return __generator(this, function (_a) {
202
+ switch (_a.label) {
203
+ case 0:
204
+ fakeAvaxAssetString = 'AVAX.ASDF-1234';
205
+ return [4 /*yield*/, assetValue_ts_1.AssetValue.fromString(fakeAvaxAssetString)];
206
+ case 1:
207
+ fakeAvaxAsset = _a.sent();
208
+ (0, vitest_1.expect)(fakeAvaxAsset).toEqual(vitest_1.expect.objectContaining({
209
+ address: '1234',
210
+ chain: types_1.Chain.Avalanche,
211
+ decimal: 10,
212
+ isGasAsset: false,
213
+ isSynthetic: false,
214
+ symbol: 'ASDF-1234',
215
+ ticker: 'ASDF',
216
+ }));
217
+ return [2 /*return*/];
218
+ }
219
+ });
220
+ }); });
221
+ });
222
+ });
223
+ (0, vitest_1.describe)('fromIdentifierSync', function () {
224
+ (0, vitest_1.test)('(same as fromIdentifier) - creates AssetValue from string via `@coinmasters/tokens` lists', function () { return __awaiter(void 0, void 0, void 0, function () {
225
+ var thor;
226
+ return __generator(this, function (_a) {
227
+ switch (_a.label) {
228
+ case 0: return [4 /*yield*/, assetValue_ts_1.AssetValue.loadStaticAssets()];
229
+ case 1:
230
+ _a.sent();
231
+ thor = assetValue_ts_1.AssetValue.fromIdentifierSync('ARB.USDT-0XFD086BC7CD5C481DCC9C85EBE478A1C0B69FCBB9');
232
+ (0, vitest_1.expect)(thor).toBeDefined();
233
+ (0, vitest_1.expect)(thor).toEqual(vitest_1.expect.objectContaining({
234
+ address: '0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb9',
235
+ chain: types_1.Chain.Arbitrum,
236
+ decimal: 6,
237
+ isGasAsset: false,
238
+ isSynthetic: false,
239
+ symbol: 'USDT-0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb9',
240
+ ticker: 'USDT',
241
+ }));
242
+ return [2 /*return*/];
243
+ }
244
+ });
245
+ }); });
246
+ });
247
+ (0, vitest_1.describe)('fromStringSync', function () {
248
+ (0, vitest_1.test)('creates AssetValue from string via `@coinmasters/tokens` lists', function () { return __awaiter(void 0, void 0, void 0, function () {
249
+ var thor;
250
+ return __generator(this, function (_a) {
251
+ switch (_a.label) {
252
+ case 0: return [4 /*yield*/, assetValue_ts_1.AssetValue.loadStaticAssets()];
253
+ case 1:
254
+ _a.sent();
255
+ thor = assetValue_ts_1.AssetValue.fromStringSync('ETH.THOR-0xa5f2211b9b8170f694421f2046281775e8468044');
256
+ (0, vitest_1.expect)(thor).toBeDefined();
257
+ (0, vitest_1.expect)(thor).toEqual(vitest_1.expect.objectContaining({
258
+ address: '0xa5f2211b9b8170f694421f2046281775e8468044',
259
+ chain: types_1.Chain.Ethereum,
260
+ decimal: 18,
261
+ isGasAsset: false,
262
+ isSynthetic: false,
263
+ symbol: 'THOR-0xa5f2211b9b8170f694421f2046281775e8468044',
264
+ ticker: 'THOR',
265
+ }));
266
+ return [2 /*return*/];
267
+ }
268
+ });
269
+ }); });
270
+ (0, vitest_1.test)('returns undefined if string is not in `@coinmasters/tokens` lists', function () { return __awaiter(void 0, void 0, void 0, function () {
271
+ var fakeAvaxUSDCAssetString, fakeAvaxUSDCAsset;
272
+ return __generator(this, function (_a) {
273
+ switch (_a.label) {
274
+ case 0: return [4 /*yield*/, assetValue_ts_1.AssetValue.loadStaticAssets()];
275
+ case 1:
276
+ _a.sent();
277
+ fakeAvaxUSDCAssetString = 'AVAX.USDC-1234';
278
+ fakeAvaxUSDCAsset = assetValue_ts_1.AssetValue.fromStringSync(fakeAvaxUSDCAssetString);
279
+ (0, vitest_1.expect)(fakeAvaxUSDCAsset).toBeUndefined();
280
+ return [2 /*return*/];
281
+ }
282
+ });
283
+ }); });
284
+ });
285
+ (0, vitest_1.describe)('fromChainOrSignature', function () {
286
+ (0, vitest_1.test)('creates AssetValue from common asset string or chain', function () {
287
+ var customBaseAsset = [types_1.Chain.Cosmos, types_1.Chain.BinanceSmartChain, types_1.Chain.THORChain, types_1.Chain.Maya];
288
+ Object.values(types_1.Chain)
289
+ .filter(function (c) { return !customBaseAsset.includes(c); })
290
+ .forEach(function (chain) {
291
+ var asset = assetValue_ts_1.AssetValue.fromChainOrSignature(chain);
292
+ (0, vitest_1.expect)(asset).toEqual(vitest_1.expect.objectContaining({
293
+ address: undefined,
294
+ chain: chain,
295
+ decimal: types_1.BaseDecimal[chain],
296
+ isGasAsset: ![types_1.Chain.Arbitrum, types_1.Chain.Optimism].includes(chain),
297
+ isSynthetic: false,
298
+ symbol: chain,
299
+ ticker: chain,
300
+ type: 'Native',
301
+ }));
302
+ });
303
+ var cosmosAsset = assetValue_ts_1.AssetValue.fromChainOrSignature(types_1.Chain.Cosmos);
304
+ (0, vitest_1.expect)(cosmosAsset).toEqual(vitest_1.expect.objectContaining({
305
+ address: undefined,
306
+ chain: types_1.Chain.Cosmos,
307
+ decimal: types_1.BaseDecimal.GAIA,
308
+ isGasAsset: true,
309
+ isSynthetic: false,
310
+ symbol: 'ATOM',
311
+ ticker: 'ATOM',
312
+ type: 'Native',
313
+ }));
314
+ var bscAsset = assetValue_ts_1.AssetValue.fromChainOrSignature(types_1.Chain.BinanceSmartChain);
315
+ (0, vitest_1.expect)(bscAsset).toEqual(vitest_1.expect.objectContaining({
316
+ address: undefined,
317
+ chain: types_1.Chain.BinanceSmartChain,
318
+ decimal: types_1.BaseDecimal.BSC,
319
+ isGasAsset: true,
320
+ isSynthetic: false,
321
+ symbol: 'BNB',
322
+ ticker: 'BNB',
323
+ type: 'Native',
324
+ }));
325
+ var thorAsset = assetValue_ts_1.AssetValue.fromChainOrSignature(types_1.Chain.THORChain);
326
+ (0, vitest_1.expect)(thorAsset).toEqual(vitest_1.expect.objectContaining({
327
+ address: undefined,
328
+ chain: types_1.Chain.THORChain,
329
+ decimal: types_1.BaseDecimal.THOR,
330
+ isGasAsset: true,
331
+ isSynthetic: false,
332
+ symbol: 'RUNE',
333
+ ticker: 'RUNE',
334
+ type: 'Native',
335
+ }));
336
+ var cacaoAsset = assetValue_ts_1.AssetValue.fromChainOrSignature(types_1.Chain.Maya);
337
+ (0, vitest_1.expect)(cacaoAsset).toEqual(vitest_1.expect.objectContaining({
338
+ address: undefined,
339
+ chain: types_1.Chain.Maya,
340
+ decimal: types_1.BaseDecimal.MAYA,
341
+ isGasAsset: true,
342
+ isSynthetic: false,
343
+ symbol: 'CACAO',
344
+ ticker: 'CACAO',
345
+ type: 'Native',
346
+ }));
347
+ var thor = assetValue_ts_1.AssetValue.fromChainOrSignature('ETH.THOR');
348
+ (0, vitest_1.expect)(thor).toEqual(vitest_1.expect.objectContaining({
349
+ address: '0xa5f2211b9b8170f694421f2046281775e8468044',
350
+ chain: types_1.Chain.Ethereum,
351
+ decimal: 18,
352
+ isGasAsset: false,
353
+ isSynthetic: false,
354
+ symbol: 'THOR-0xa5f2211b9b8170f694421f2046281775e8468044',
355
+ ticker: 'THOR',
356
+ }));
357
+ var vthor = assetValue_ts_1.AssetValue.fromChainOrSignature('ETH.vTHOR');
358
+ (0, vitest_1.expect)(vthor).toEqual(vitest_1.expect.objectContaining({
359
+ address: '0x815c23eca83261b6ec689b60cc4a58b54bc24d8d',
360
+ chain: types_1.Chain.Ethereum,
361
+ decimal: 18,
362
+ isGasAsset: false,
363
+ isSynthetic: false,
364
+ symbol: 'vTHOR-0x815c23eca83261b6ec689b60cc4a58b54bc24d8d',
365
+ ticker: 'vTHOR',
366
+ }));
367
+ });
368
+ });
369
+ (0, vitest_1.describe)('loadStaticAssets', function () {
370
+ (0, vitest_1.test)('loads static assets from `@coinmasters/tokens` lists', function () { return __awaiter(void 0, void 0, void 0, function () {
371
+ var ok;
372
+ return __generator(this, function (_a) {
373
+ switch (_a.label) {
374
+ case 0: return [4 /*yield*/, assetValue_ts_1.AssetValue.loadStaticAssets()];
375
+ case 1:
376
+ ok = (_a.sent()).ok;
377
+ (0, vitest_1.expect)(ok).toBe(true);
378
+ return [2 /*return*/];
379
+ }
380
+ });
381
+ }); });
382
+ });
383
+ });
384
+ (0, vitest_1.describe)('getMinAmountByChain', function () {
385
+ (0, vitest_1.test)('returns min amount for chain', function () {
386
+ (0, vitest_1.expect)((0, assetValue_ts_1.getMinAmountByChain)(types_1.Chain.THORChain).getValue('string')).toBe('0');
387
+ (0, vitest_1.expect)((0, assetValue_ts_1.getMinAmountByChain)(types_1.Chain.Maya).getValue('string')).toBe('0');
388
+ (0, vitest_1.expect)((0, assetValue_ts_1.getMinAmountByChain)(types_1.Chain.Cosmos).getValue('string')).toBe('0');
389
+ (0, vitest_1.expect)((0, assetValue_ts_1.getMinAmountByChain)(types_1.Chain.Bitcoin).getValue('string')).toBe('0.00010001');
390
+ (0, vitest_1.expect)((0, assetValue_ts_1.getMinAmountByChain)(types_1.Chain.Litecoin).getValue('string')).toBe('0.00010001');
391
+ (0, vitest_1.expect)((0, assetValue_ts_1.getMinAmountByChain)(types_1.Chain.BitcoinCash).getValue('string')).toBe('0.00010001');
392
+ (0, vitest_1.expect)((0, assetValue_ts_1.getMinAmountByChain)(types_1.Chain.Dogecoin).getValue('string')).toBe('1.00000001');
393
+ (0, vitest_1.expect)((0, assetValue_ts_1.getMinAmountByChain)(types_1.Chain.BinanceSmartChain).getValue('string')).toBe('0.00000001');
394
+ (0, vitest_1.expect)((0, assetValue_ts_1.getMinAmountByChain)(types_1.Chain.Ethereum).getValue('string')).toBe('0.00000001');
395
+ (0, vitest_1.expect)((0, assetValue_ts_1.getMinAmountByChain)(types_1.Chain.Avalanche).getValue('string')).toBe('0.00000001');
396
+ (0, vitest_1.expect)((0, assetValue_ts_1.getMinAmountByChain)(types_1.Chain.Arbitrum).getValue('string')).toBe('0.00000001');
397
+ (0, vitest_1.expect)((0, assetValue_ts_1.getMinAmountByChain)(types_1.Chain.Optimism).getValue('string')).toBe('0.00000001');
398
+ });
399
+ });
@@ -0,0 +1 @@
1
+ export {};