@swapkit/helpers 1.0.0-rc.70 → 1.0.0-rc.72

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
@@ -1,23 +1,19 @@
1
1
  {
2
- "author": "swapkit-oss-team",
2
+ "author": "swapkit-oss",
3
3
  "description": "SwapKit Lib swapkit-helpers",
4
4
  "dependencies": {
5
- "@swapkit/api": "1.0.0-rc.38"
5
+ "@swapkit/api": "1.0.0-rc.39"
6
6
  },
7
7
  "devDependencies": {
8
- "@vitest/coverage-istanbul": "1.2.1",
9
- "vite": "5.0.12",
10
- "vitest": "1.2.1",
11
- "@internal/config": "0.0.2-rc.0",
12
- "@swapkit/tokens": "1.0.0-rc.34",
13
- "@swapkit/types": "1.0.0-rc.37"
14
- },
15
- "eslintConfig": {
16
- "extends": "../../../internal/eslint-config"
8
+ "@vitest/coverage-istanbul": "1.3.1",
9
+ "vite": "5.1.3",
10
+ "vitest": "1.3.1",
11
+ "@swapkit/tokens": "1.0.0-rc.35",
12
+ "@swapkit/types": "1.0.0-rc.38"
17
13
  },
18
14
  "peerDependencies": {
19
- "@swapkit/tokens": "1.0.0-rc.34",
20
- "@swapkit/types": "1.0.0-rc.37"
15
+ "@swapkit/tokens": "1.0.0-rc.35",
16
+ "@swapkit/types": "1.0.0-rc.38"
21
17
  },
22
18
  "exports": {
23
19
  ".": {
@@ -42,11 +38,11 @@
42
38
  },
43
39
  "type": "module",
44
40
  "types": "./dist/index.d.ts",
45
- "version": "1.0.0-rc.70",
41
+ "version": "1.0.0-rc.72",
46
42
  "scripts": {
47
43
  "build": "vite build",
48
- "clean": "rm -rf dist vite.config.ts.* .turbo node_modules",
49
- "lint": "eslint ./ --ext .ts,.tsx --fix; tsc --noEmit",
44
+ "clean": "rm -rf dist vite.config.ts.* node_modules",
45
+ "lint": "biome check --apply ./src",
50
46
  "test": "vitest --run",
51
47
  "test:coverage": "vitest run --coverage"
52
48
  }
@@ -1,155 +1,157 @@
1
- import { BaseDecimal, Chain } from '@swapkit/types';
2
- import { describe, expect, it } from 'vitest';
1
+ import { BaseDecimal, Chain } from "@swapkit/types";
2
+ import { describe, expect, test } from "vitest";
3
3
 
4
- import { getAssetType, getDecimal } from '../asset.ts';
4
+ import { getAssetType, getDecimal } from "../asset.ts";
5
5
 
6
6
  const tickerMap: Record<string, string> = {
7
- [Chain.THORChain]: 'RUNE',
8
- [Chain.Cosmos]: 'ATOM',
9
- [Chain.BinanceSmartChain]: 'BNB',
7
+ [Chain.THORChain]: "RUNE",
8
+ [Chain.Cosmos]: "ATOM",
9
+ [Chain.BinanceSmartChain]: "BNB",
10
10
  };
11
11
 
12
- describe('getAssetType', () => {
13
- describe('when isSynth is true', () => {
14
- it('should return "Synth"', () => {
15
- const result = getAssetType({ chain: Chain.Bitcoin, symbol: 'BTC/BTC' });
16
- expect(result).toBe('Synth');
12
+ describe("getAssetType", () => {
13
+ describe("when isSynth is true", () => {
14
+ test('should return "Synth"', () => {
15
+ const result = getAssetType({ chain: Chain.Bitcoin, symbol: "BTC/BTC" });
16
+ expect(result).toBe("Synth");
17
17
  });
18
18
  });
19
19
 
20
- describe('when isSynth is false', () => {
21
- describe('for native chains and their assets', () => {
22
- Object.values(Chain).forEach((chain) => {
23
- it(`should return "Native" for chain ${chain} asset`, () => {
20
+ describe("when isSynth is false", () => {
21
+ describe("for native chains and their assets", () => {
22
+ for (const chain of Object.values(Chain)) {
23
+ test(`should return "Native" for chain ${chain} asset`, () => {
24
24
  const ticker = tickerMap[chain] || chain;
25
25
  const result = getAssetType({ chain: chain as Chain, symbol: ticker });
26
26
 
27
- expect(result).toBe('Native');
27
+ expect(result).toBe("Native");
28
28
  });
29
- });
29
+ }
30
30
  });
31
31
 
32
- describe('for Cosmos chain', () => {
33
- it('should return "GAIA" for non-ATOM tickers', () => {
34
- const result = getAssetType({ chain: Chain.Cosmos, symbol: 'NOT_ATOM' });
35
- expect(result).toBe('GAIA');
32
+ describe("for Cosmos chain", () => {
33
+ test('should return "GAIA" for non-ATOM tickers', () => {
34
+ const result = getAssetType({ chain: Chain.Cosmos, symbol: "NOT_ATOM" });
35
+ expect(result).toBe("GAIA");
36
36
  });
37
37
  });
38
38
 
39
- describe('for Binance chain', () => {
40
- it('should return "BEP2" for non-BNB tickers', () => {
41
- const result = getAssetType({ chain: Chain.Binance, symbol: 'NOT_BNB' });
42
- expect(result).toBe('BEP2');
39
+ describe("for Binance chain", () => {
40
+ test('should return "BEP2" for non-BNB tickers', () => {
41
+ const result = getAssetType({ chain: Chain.Binance, symbol: "NOT_BNB" });
42
+ expect(result).toBe("BEP2");
43
43
  });
44
44
  });
45
45
 
46
- describe('for Binance Smart Chain', () => {
47
- it('should return "BEP20" for non-BNB tickers', () => {
48
- const result = getAssetType({ chain: Chain.BinanceSmartChain, symbol: 'NOT_BNB' });
49
- expect(result).toBe('BEP20');
46
+ describe("for Binance Smart Chain", () => {
47
+ test('should return "BEP20" for non-BNB tickers', () => {
48
+ const result = getAssetType({ chain: Chain.BinanceSmartChain, symbol: "NOT_BNB" });
49
+ expect(result).toBe("BEP20");
50
50
  });
51
51
  });
52
52
 
53
- describe('for Ethereum chain', () => {
54
- it('should return "ERC20" for non-ETH tickers', () => {
55
- const result = getAssetType({ chain: Chain.Ethereum, symbol: 'NOT_ETH' });
56
- expect(result).toBe('ERC20');
53
+ describe("for Ethereum chain", () => {
54
+ test('should return "ERC20" for non-ETH tickers', () => {
55
+ const result = getAssetType({ chain: Chain.Ethereum, symbol: "NOT_ETH" });
56
+ expect(result).toBe("ERC20");
57
57
  });
58
58
  });
59
59
 
60
- describe('for Avalanche chain', () => {
61
- it('should return "AVAX" for non-AVAX tickers', () => {
62
- const result = getAssetType({ chain: Chain.Avalanche, symbol: 'NOT_AVAX' });
63
- expect(result).toBe('AVAX');
60
+ describe("for Avalanche chain", () => {
61
+ test('should return "AVAX" for non-AVAX tickers', () => {
62
+ const result = getAssetType({ chain: Chain.Avalanche, symbol: "NOT_AVAX" });
63
+ expect(result).toBe("AVAX");
64
64
  });
65
65
  });
66
66
  });
67
67
  });
68
68
 
69
- describe('getDecimal', () => {
69
+ describe("getDecimal", () => {
70
70
  /**
71
71
  * Test out native
72
72
  */
73
- Object.values(Chain)
74
- .filter((c) => ![Chain.Ethereum, Chain.Avalanche].includes(c))
75
- .forEach((chain) => {
76
- describe(chain, () => {
77
- it(`returns proper decimal for native ${chain} asset`, async () => {
78
- const decimal = await getDecimal({ chain, symbol: chain });
79
- expect(decimal).toBe(BaseDecimal[chain]);
80
- });
73
+ const filteredChains = Object.values(Chain).filter(
74
+ (c) => ![Chain.Ethereum, Chain.Avalanche].includes(c),
75
+ );
76
+
77
+ for (const chain of filteredChains) {
78
+ describe(chain, () => {
79
+ test(`returns proper decimal for native ${chain} asset`, async () => {
80
+ const decimal = await getDecimal({ chain, symbol: chain });
81
+ expect(decimal).toBe(BaseDecimal[chain]);
81
82
  });
82
83
  });
84
+ }
83
85
 
84
- describe('ETH', () => {
85
- it("returns proper decimal for eth and it's assets", async () => {
86
- const ethDecimal = await getDecimal({ chain: Chain.Ethereum, symbol: 'ETH' });
86
+ describe("ETH", () => {
87
+ test("returns proper decimal for eth and it's assets", async () => {
88
+ const ethDecimal = await getDecimal({ chain: Chain.Ethereum, symbol: "ETH" });
87
89
  expect(ethDecimal).toBe(BaseDecimal.ETH);
88
90
 
89
91
  const usdcDecimal = await getDecimal({
90
92
  chain: Chain.Ethereum,
91
- symbol: 'USDC-0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
93
+ symbol: "USDC-0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
92
94
  });
93
95
  expect(usdcDecimal).toBe(6);
94
96
 
95
97
  const wbtcDecimal = await getDecimal({
96
98
  chain: Chain.Ethereum,
97
- symbol: 'WBTC-0x2260fac5e5542a773aa44fbcfedf7c193bc2c599',
99
+ symbol: "WBTC-0x2260fac5e5542a773aa44fbcfedf7c193bc2c599",
98
100
  });
99
101
  expect(wbtcDecimal).toBe(8);
100
102
 
101
103
  const decDecimal = await getDecimal({
102
104
  chain: Chain.Ethereum,
103
- symbol: 'ZIL-0x05f4a42e251f2d52b8ed15e9fedaacfcef1fad27',
105
+ symbol: "ZIL-0x05f4a42e251f2d52b8ed15e9fedaacfcef1fad27",
104
106
  });
105
107
  expect(decDecimal).toBe(12);
106
108
 
107
109
  const kindDecimal = await getDecimal({
108
110
  chain: Chain.Ethereum,
109
- symbol: 'KIND-0x4618519de4c304f3444ffa7f812dddc2971cc688',
111
+ symbol: "KIND-0x4618519de4c304f3444ffa7f812dddc2971cc688",
110
112
  });
111
113
  expect(kindDecimal).toBe(8);
112
114
 
113
115
  const shitcoinDecimal = await getDecimal({
114
116
  chain: Chain.Ethereum,
115
- symbol: 'HOMI-0xCa208BfD69ae6D2667f1FCbE681BAe12767c0078',
117
+ symbol: "HOMI-0xCa208BfD69ae6D2667f1FCbE681BAe12767c0078",
116
118
  });
117
119
  expect(shitcoinDecimal).toBe(0);
118
120
  });
119
121
  });
120
122
 
121
- describe('AVAX', () => {
122
- it("returns proper decimal for avax and it's assets", async () => {
123
- const avaxDecimal = await getDecimal({ chain: Chain.Avalanche, symbol: 'AVAX' });
123
+ describe("AVAX", () => {
124
+ test.skip("returns proper decimal for avax and it's assets", async () => {
125
+ const avaxDecimal = await getDecimal({ chain: Chain.Avalanche, symbol: "AVAX" });
124
126
  expect(avaxDecimal).toBe(BaseDecimal.AVAX);
125
127
 
126
128
  const wbtceDecimal = await getDecimal({
127
129
  chain: Chain.Avalanche,
128
- symbol: 'WBTC.e-0x50b7545627a5162f82a992c33b87adc75187b218',
130
+ symbol: "WBTC.e-0x50b7545627a5162f82a992c33b87adc75187b218",
129
131
  });
130
132
  expect(wbtceDecimal).toBe(8);
131
133
 
132
134
  const btcbDecimal = await getDecimal({
133
135
  chain: Chain.Avalanche,
134
- symbol: 'BTC.b-0x152b9d0FdC40C096757F570A51E494bd4b943E50',
136
+ symbol: "BTC.b-0x152b9d0FdC40C096757F570A51E494bd4b943E50",
135
137
  });
136
138
  expect(btcbDecimal).toBe(8);
137
139
 
138
140
  const timeDecimal = await getDecimal({
139
141
  chain: Chain.Avalanche,
140
- symbol: 'TIME-0xb54f16fB19478766A268F172C9480f8da1a7c9C3',
142
+ symbol: "TIME-0xb54f16fB19478766A268F172C9480f8da1a7c9C3",
141
143
  });
142
144
  expect(timeDecimal).toBe(9);
143
145
 
144
146
  const usdtDecimal = await getDecimal({
145
147
  chain: Chain.Avalanche,
146
- symbol: 'USDT-0x9702230A8Ea53601f5cD2dc00fDBc13d4dF4A8c7',
148
+ symbol: "USDT-0x9702230A8Ea53601f5cD2dc00fDBc13d4dF4A8c7",
147
149
  });
148
150
  expect(usdtDecimal).toBe(6);
149
151
 
150
152
  const usdcDecimal = await getDecimal({
151
153
  chain: Chain.Avalanche,
152
- symbol: 'USDC-0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E',
154
+ symbol: "USDC-0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E",
153
155
  });
154
156
  expect(usdcDecimal).toBe(6);
155
157
  });
@@ -1,79 +1,81 @@
1
- import { Chain, MemoType } from '@swapkit/types';
2
- import { describe, expect, it } from 'vitest';
1
+ import { Chain, MemoType } from "@swapkit/types";
2
+ import { describe, expect, test } from "vitest";
3
3
 
4
- import { getMemoFor } from '../memo.ts';
4
+ import { getMemoFor } from "../memo.ts";
5
5
 
6
- describe('getMemoFor', () => {
7
- describe('for Leave, Upgrade, and Bond', () => {
8
- [
9
- [MemoType.LEAVE, 'LEAVE:ABC123'],
10
- [MemoType.BOND, 'BOND:ABC123'],
11
- ].forEach(([memoType, expected]) => {
12
- it(`returns correct memo for ${memoType}`, () => {
13
- const result = getMemoFor(memoType as MemoType, { address: 'ABC123' });
6
+ describe("getMemoFor", () => {
7
+ describe("for Leave, Upgrade, and Bond", () => {
8
+ const nodeMemos = [
9
+ [MemoType.LEAVE, "LEAVE:ABC123"],
10
+ [MemoType.BOND, "BOND:ABC123"],
11
+ ];
12
+
13
+ for (const [memoType, expected] of nodeMemos) {
14
+ test(`returns correct memo for ${memoType}`, () => {
15
+ const result = getMemoFor(memoType as MemoType, { address: "ABC123" });
14
16
  expect(result).toBe(expected);
15
17
  });
16
- });
18
+ }
17
19
  });
18
20
 
19
- describe('for Unbond and Thorname Register', () => {
20
- it('returns correct memo for Unbond', () => {
21
- const result = getMemoFor(MemoType.UNBOND, { address: 'ABC123', unbondAmount: 1000000000 });
22
- expect(result).toBe('UNBOND:ABC123:1000000000');
21
+ describe("for Unbond and Thorname Register", () => {
22
+ test("returns correct memo for Unbond", () => {
23
+ const result = getMemoFor(MemoType.UNBOND, { address: "ABC123", unbondAmount: 1000000000 });
24
+ expect(result).toBe("UNBOND:ABC123:1000000000");
23
25
  });
24
26
 
25
- it('returns correct memo for Thorname Register', () => {
27
+ test("returns correct memo for Thorname Register", () => {
26
28
  const result = getMemoFor(MemoType.THORNAME_REGISTER, {
27
- name: 'thorname',
28
- chain: 'BNB',
29
- address: '0xABC123',
30
- owner: '0xDEF456',
29
+ name: "thorname",
30
+ chain: "BNB",
31
+ address: "0xABC123",
32
+ owner: "0xDEF456",
31
33
  });
32
- expect(result).toBe('~:thorname:BNB:0xABC123:0xDEF456');
34
+ expect(result).toBe("~:thorname:BNB:0xABC123:0xDEF456");
33
35
  });
34
36
  });
35
37
 
36
- describe('for Deposit', () => {
37
- it('returns correct memo for Deposit (single side)', () => {
38
+ describe("for Deposit", () => {
39
+ test("returns correct memo for Deposit (single side)", () => {
38
40
  const result = getMemoFor(MemoType.DEPOSIT, {
39
41
  chain: Chain.Ethereum,
40
- symbol: 'ETH',
42
+ symbol: "ETH",
41
43
  singleSide: true,
42
44
  });
43
- expect(result).toBe('+:ETH/ETH');
45
+ expect(result).toBe("+:ETH/ETH");
44
46
  });
45
47
 
46
- it('returns correct memo for Deposit (dual side)', () => {
48
+ test("returns correct memo for Deposit (dual side)", () => {
47
49
  const result = getMemoFor(MemoType.DEPOSIT, {
48
50
  chain: Chain.Avalanche,
49
- symbol: 'AVAX',
50
- address: '0xABC123',
51
+ symbol: "AVAX",
52
+ address: "0xABC123",
51
53
  });
52
- expect(result).toBe('+:AVAX.AVAX:0xABC123');
54
+ expect(result).toBe("+:AVAX.AVAX:0xABC123");
53
55
  });
54
56
  });
55
57
 
56
- describe('for Withdraw', () => {
57
- it('returns correct memo for Withdraw (single side)', () => {
58
+ describe("for Withdraw", () => {
59
+ test("returns correct memo for Withdraw (single side)", () => {
58
60
  const result = getMemoFor(MemoType.WITHDRAW, {
59
61
  chain: Chain.Bitcoin,
60
- ticker: 'BTC',
61
- symbol: 'BTC',
62
+ ticker: "BTC",
63
+ symbol: "BTC",
62
64
  basisPoints: 10000,
63
65
  singleSide: true,
64
66
  });
65
- expect(result).toBe('-:BTC/BTC:10000');
67
+ expect(result).toBe("-:BTC/BTC:10000");
66
68
  });
67
69
 
68
- it('returns correct memo for Withdraw (dual side)', () => {
70
+ test("returns correct memo for Withdraw (dual side)", () => {
69
71
  const result = getMemoFor(MemoType.WITHDRAW, {
70
72
  chain: Chain.Ethereum,
71
- ticker: 'ETH',
72
- symbol: 'ETH',
73
+ ticker: "ETH",
74
+ symbol: "ETH",
73
75
  basisPoints: 100,
74
- targetAssetString: 'ETH.ETH',
76
+ targetAssetString: "ETH.ETH",
75
77
  });
76
- expect(result).toBe('-:ETH.ETH:100:ETH.ETH');
78
+ expect(result).toBe("-:ETH.ETH:100:ETH.ETH");
77
79
  });
78
80
  });
79
81
  });
@@ -1,59 +1,59 @@
1
- import { describe, expect, it } from 'vitest';
1
+ import { describe, expect, test } from "vitest";
2
2
 
3
- import { derivationPathToString, getTHORNameCost, validateTHORName } from '../others.ts';
3
+ import { derivationPathToString, getTHORNameCost, validateTHORName } from "../others.ts";
4
4
 
5
- describe('derivationPathToString', () => {
6
- it('should return the correct string for a full path', () => {
5
+ describe("derivationPathToString", () => {
6
+ test("should return the correct string for a full path", () => {
7
7
  const path = [1, 2, 3, 4, 5];
8
- const result = derivationPathToString(path);
9
- expect(result).toEqual("1'/2'/3'/4/5");
8
+ expect(derivationPathToString(path)).toEqual("1'/2'/3'/4/5");
10
9
  });
11
10
 
12
- it('should return the correct string for a short path', () => {
11
+ test("should return the correct string for a short path", () => {
13
12
  const path = [1, 2, 3, 4];
14
- const result = derivationPathToString(path);
15
- expect(result).toEqual("1'/2'/3'/4");
13
+ expect(derivationPathToString(path)).toEqual("1'/2'/3'/4");
16
14
  });
17
15
  });
18
16
 
19
- describe('getTHORNameCost', () => {
20
- describe('for correct values', () => {
21
- [
17
+ describe("getTHORNameCost", () => {
18
+ describe("for correct values", () => {
19
+ const costCases = [
22
20
  [1, 11],
23
21
  [2, 12],
24
22
  [3, 13],
25
23
  [10, 20],
26
- ].forEach(([years, expected]) => {
27
- it(`returns correct ${expected} cost for ${years} years`, () => {
24
+ ];
25
+
26
+ for (const [years, expected] of costCases) {
27
+ test(`returns correct ${expected} cost for ${years} years`, () => {
28
28
  const result = getTHORNameCost(years);
29
29
  expect(result).toBe(expected);
30
30
  });
31
- });
31
+ }
32
32
  });
33
33
 
34
- it('throws an error for negative years', () => {
35
- expect(() => getTHORNameCost(-1)).toThrowError('Invalid number of year');
34
+ test("throws an error for negative years", () => {
35
+ expect(() => getTHORNameCost(-1)).toThrowError("Invalid number of year");
36
36
  });
37
37
  });
38
38
 
39
- describe('validateTHORName', () => {
39
+ describe("validateTHORName", () => {
40
40
  const casesWithExpectation: [string, boolean][] = [
41
- ['validname', true],
42
- ['valid-name', true],
43
- ['valid_name', true],
44
- ['valid+name', true],
45
- ['name_with_numbers123', true],
46
- ['UPPER_CASE', true],
47
- ['toolongname123456789012345678901', false],
48
- ['invalid@name', false],
49
- ['invalid!name', false],
50
- ['invalid#name', false],
41
+ ["validname", true],
42
+ ["valid-name", true],
43
+ ["valid_name", true],
44
+ ["valid+name", true],
45
+ ["name_with_numbers123", true],
46
+ ["UPPER_CASE", true],
47
+ ["toolongname123456789012345678901", false],
48
+ ["invalid@name", false],
49
+ ["invalid!name", false],
50
+ ["invalid#name", false],
51
51
  ];
52
52
 
53
- casesWithExpectation.forEach(([name, expected]) => {
54
- it(`returns ${expected} for THORName "${name}"`, () => {
53
+ for (const [name, expected] of casesWithExpectation) {
54
+ test(`returns ${expected} for THORName "${name}"`, () => {
55
55
  const result = validateTHORName(name);
56
56
  expect(result).toBe(expected);
57
57
  });
58
- });
58
+ }
59
59
  });