@pioneer-platform/helpers 4.0.12 → 4.1.0

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.
@@ -1,22 +1,7 @@
1
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
2
  Object.defineProperty(exports, "__esModule", { value: true });
18
3
  exports.SwapKitError = void 0;
19
- var errorMessages = {
4
+ const errorMessages = {
20
5
  /**
21
6
  * Core
22
7
  */
@@ -75,16 +60,12 @@ var errorMessages = {
75
60
  */
76
61
  helpers_number_different_decimals: 99101,
77
62
  };
78
- var SwapKitError = /** @class */ (function (_super) {
79
- __extends(SwapKitError, _super);
80
- function SwapKitError(errorKey, sourceError) {
81
- var _this = this;
63
+ class SwapKitError extends Error {
64
+ constructor(errorKey, sourceError) {
82
65
  console.error(sourceError, { stack: sourceError === null || sourceError === void 0 ? void 0 : sourceError.stack, message: sourceError === null || sourceError === void 0 ? void 0 : sourceError.message });
83
66
  // @ts-ignore
84
- _this = _super.call(this, errorKey, { cause: { code: errorMessages[errorKey], message: errorKey } }) || this;
85
- Object.setPrototypeOf(_this, SwapKitError.prototype);
86
- return _this;
67
+ super(errorKey, { cause: { code: errorMessages[errorKey], message: errorKey } });
68
+ Object.setPrototypeOf(this, SwapKitError.prototype);
87
69
  }
88
- return SwapKitError;
89
- }(Error));
70
+ }
90
71
  exports.SwapKitError = SwapKitError;
@@ -1,37 +1,17 @@
1
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
2
  Object.defineProperty(exports, "__esModule", { value: true });
18
3
  exports.SwapKitNumber = void 0;
19
- var bigIntArithmetics_1 = require("./bigIntArithmetics");
20
- var DEFAULT_DECIMAL = 8;
21
- var SwapKitNumber = /** @class */ (function (_super) {
22
- __extends(SwapKitNumber, _super);
23
- function SwapKitNumber() {
24
- return _super !== null && _super.apply(this, arguments) || this;
25
- }
26
- SwapKitNumber.prototype.eq = function (value) {
4
+ const bigIntArithmetics_1 = require("./bigIntArithmetics");
5
+ const DEFAULT_DECIMAL = 8;
6
+ class SwapKitNumber extends bigIntArithmetics_1.BigIntArithmetics {
7
+ eq(value) {
27
8
  return this.eqValue(value);
28
- };
29
- SwapKitNumber.fromBigInt = function (value, decimal) {
9
+ }
10
+ static fromBigInt(value, decimal) {
30
11
  return new SwapKitNumber({
31
- decimal: decimal,
32
- value: (0, bigIntArithmetics_1.formatBigIntToSafeValue)({ value: value, bigIntDecimal: (0, bigIntArithmetics_1.toMultiplier)(decimal || DEFAULT_DECIMAL), decimal: decimal }),
12
+ decimal,
13
+ value: (0, bigIntArithmetics_1.formatBigIntToSafeValue)({ value, bigIntDecimal: (0, bigIntArithmetics_1.toMultiplier)(decimal || DEFAULT_DECIMAL), decimal }),
33
14
  });
34
- };
35
- return SwapKitNumber;
36
- }(bigIntArithmetics_1.BigIntArithmetics));
15
+ }
16
+ }
37
17
  exports.SwapKitNumber = SwapKitNumber;
package/package.json CHANGED
@@ -1,25 +1,28 @@
1
1
  {
2
2
  "name": "@pioneer-platform/helpers",
3
- "version": "4.0.12",
3
+ "version": "4.1.0",
4
4
  "main": "./lib/index.js",
5
5
  "types": "./lib/index.d.ts",
6
- "scripts": {
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
6
  "dependencies": {
7
+ "@coinmasters/core": "^12.0.8",
16
8
  "@coinmasters/tokens": "^3.7.28",
17
- "@coinmasters/types": "latest",
9
+ "@coinmasters/types": "^4.10.1",
18
10
  "@noble/hashes": "^1.4.0",
19
- "@pioneer-platform/loggerdog": "^8.3.1",
11
+ "@pioneer-platform/loggerdog": "^8.4.0",
20
12
  "@types/node": "^18.15.11",
13
+ "ethers": "5.7.2",
14
+ "ky": "^1.8.0",
21
15
  "ts-node": "^8.10.2",
22
- "typescript": "^5.0.2"
16
+ "typescript": "^5.0.4"
23
17
  },
24
- "gitHead": "aeae28273014ab69b42f22abec159c6693a56c40"
25
- }
18
+ "gitHead": "aeae28273014ab69b42f22abec159c6693a56c40",
19
+ "scripts": {
20
+ "npm": "pnpm i",
21
+ "test": "pnpm run build && node __tests__/test-module.js",
22
+ "lint": "prettier --write '**/**/*.ts'",
23
+ "start": "nodemon --watch 'src/**/*.ts' --exec ts-node __tests__node",
24
+ "build": "tsc -p .",
25
+ "prepublish": "pnpm run build",
26
+ "refresh": "rm -rf ./node_modules ./package-lock.json && pnpm install"
27
+ }
28
+ }
@@ -85,7 +85,6 @@ export const isGasAsset = ({ chain, symbol }: { chain: Chain; symbol: string })
85
85
  case Chain.Ripple:
86
86
  case Chain.Litecoin:
87
87
  case Chain.Dogecoin:
88
- case Chain.Binance:
89
88
  case Chain.Ethereum:
90
89
  case Chain.Avalanche:
91
90
  return symbol === chain;
@@ -144,7 +143,6 @@ export const getCommonAssetInfo = (
144
143
  case Chain.Dash:
145
144
  case Chain.Litecoin:
146
145
  case Chain.Dogecoin:
147
- case Chain.Binance:
148
146
  case Chain.Polygon:
149
147
  case Chain.Bitcoin:
150
148
  case Chain.Ethereum:
@@ -172,10 +170,7 @@ export const getAssetType = ({ chain, symbol }: { chain: Chain; symbol: string }
172
170
  return symbol === 'ATOM' ? 'Native' : Chain.Cosmos;
173
171
  case Chain.Kujira:
174
172
  return symbol === Chain.Kujira ? 'Native' : Chain.Kujira;
175
- case Chain.Binance:
176
- return symbol === Chain.Binance ? 'Native' : 'BEP2';
177
173
  case Chain.BinanceSmartChain:
178
- return symbol === Chain.Binance ? 'Native' : 'BEP20';
179
174
  case Chain.Ethereum:
180
175
  return symbol === Chain.Ethereum ? 'Native' : 'ERC20';
181
176
  case Chain.Avalanche:
package/tsconfig.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "compilerOptions": {
3
- "target": "es5",
3
+ "target": "es2015",
4
4
  "module": "commonjs",
5
5
  "lib": ["es6", "es2015", "dom"],
6
6
  "declaration": true,
@@ -1 +0,0 @@
1
- export {};
@@ -1,399 +0,0 @@
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
- });
@@ -1 +0,0 @@
1
- export {};