@swapkit/helpers 1.0.0-rc.65 → 1.0.0-rc.67

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/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "author": "swapkit-oss-team",
3
3
  "description": "SwapKit Lib swapkit-helpers",
4
4
  "dependencies": {
5
- "@swapkit/api": "1.0.0-rc.35"
5
+ "@swapkit/api": "1.0.0-rc.36"
6
6
  },
7
7
  "devDependencies": {
8
8
  "@vitest/coverage-istanbul": "1.2.1",
@@ -10,14 +10,14 @@
10
10
  "vitest": "1.2.1",
11
11
  "@internal/config": "0.0.2-rc.0",
12
12
  "@swapkit/tokens": "1.0.0-rc.33",
13
- "@swapkit/types": "1.0.0-rc.34"
13
+ "@swapkit/types": "1.0.0-rc.35"
14
14
  },
15
15
  "eslintConfig": {
16
16
  "extends": "../../../internal/eslint-config"
17
17
  },
18
18
  "peerDependencies": {
19
19
  "@swapkit/tokens": "1.0.0-rc.33",
20
- "@swapkit/types": "1.0.0-rc.34"
20
+ "@swapkit/types": "1.0.0-rc.35"
21
21
  },
22
22
  "exports": {
23
23
  ".": {
@@ -42,7 +42,7 @@
42
42
  },
43
43
  "type": "module",
44
44
  "types": "./dist/index.d.ts",
45
- "version": "1.0.0-rc.65",
45
+ "version": "1.0.0-rc.67",
46
46
  "scripts": {
47
47
  "build": "vite build",
48
48
  "clean": "rm -rf dist vite.config.ts.* .turbo node_modules",
@@ -254,6 +254,25 @@ describe('AssetValue', () => {
254
254
  }),
255
255
  );
256
256
  });
257
+
258
+ test('returns proper avax string with address from `@swapkit/tokens` lists', async () => {
259
+ await AssetValue.loadStaticAssets();
260
+ const avaxBTCb = 'AVAX.BTC.b-0x152b9d0fdc40c096757f570a51e494bd4b943e50';
261
+ const AvaxBTCb = AssetValue.fromStringSync(avaxBTCb);
262
+
263
+ expect(AvaxBTCb).toBeDefined();
264
+ expect(AvaxBTCb).toEqual(
265
+ expect.objectContaining({
266
+ address: '0x152b9d0fdc40c096757f570a51e494bd4b943e50',
267
+ chain: Chain.Avalanche,
268
+ decimal: 8,
269
+ isGasAsset: false,
270
+ isSynthetic: false,
271
+ symbol: 'BTC.b-0x152b9d0fdc40c096757f570a51e494bd4b943e50',
272
+ ticker: 'BTC.b',
273
+ }),
274
+ );
275
+ });
257
276
  });
258
277
 
259
278
  describe('fromChainOrSignature', () => {
@@ -108,6 +108,7 @@ export class AssetValue extends BigIntArithmetics {
108
108
  decimal: BaseDecimal[chain],
109
109
  identifier: assetString,
110
110
  };
111
+
111
112
  return new AssetValue({
112
113
  tax,
113
114
  value: safeValue(value, decimal),
@@ -231,8 +232,10 @@ function safeValue(value: NumberPrimitives, decimal: number) {
231
232
  : value;
232
233
  }
233
234
 
235
+ // TODO refactor & split into smaller functions
234
236
  function getAssetInfo(identifier: string) {
235
237
  const isSynthetic = identifier.slice(0, 14).includes('/');
238
+
236
239
  const [synthChain, synthSymbol] =
237
240
  identifier.split('.')[0].toUpperCase() === Chain.THORChain
238
241
  ? identifier.split('.').slice(1)!.join().split('/')
@@ -243,8 +246,12 @@ function getAssetInfo(identifier: string) {
243
246
  const adjustedIdentifier =
244
247
  identifier.includes('.') && !isSynthetic ? identifier : `${Chain.THORChain}.${synthSymbol}`;
245
248
 
246
- const [chain, symbol] = adjustedIdentifier.split('.') as [Chain, string];
247
- const [ticker, address] = (isSynthetic ? synthSymbol : symbol).split('-') as [string, string?];
249
+ const [chain, ...rest] = adjustedIdentifier.split('.') as [Chain, string];
250
+ const [ticker, address] = (isSynthetic ? synthSymbol : rest.join('.')).split('-') as [
251
+ string,
252
+ string?,
253
+ ];
254
+ const symbol = isSynthetic ? synthSymbol : rest.join('.');
248
255
 
249
256
  return {
250
257
  address: address?.toLowerCase(),