@swapkit/helpers 1.0.0-rc.10 → 1.0.0-rc.100
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/dist/index.js +2452 -0
- package/dist/index.js.map +30 -0
- package/package.json +24 -37
- package/src/helpers/__tests__/asset.test.ts +149 -105
- package/src/helpers/__tests__/memo.test.ts +52 -40
- package/src/helpers/__tests__/others.test.ts +42 -37
- package/src/helpers/__tests__/validators.test.ts +24 -0
- package/src/helpers/asset.ts +130 -94
- package/src/helpers/derivationPath.ts +53 -0
- package/src/helpers/liquidity.ts +50 -43
- package/src/helpers/memo.ts +31 -28
- package/src/helpers/others.ts +30 -13
- package/src/helpers/validators.ts +15 -6
- package/src/helpers/web3wallets.ts +177 -0
- package/src/index.ts +14 -9
- package/src/modules/__tests__/assetValue.test.ts +414 -117
- package/src/modules/__tests__/bigIntArithmetics.test.ts +30 -0
- package/src/modules/__tests__/swapKitNumber.test.ts +306 -183
- package/src/modules/assetValue.ts +218 -152
- package/src/modules/bigIntArithmetics.ts +214 -165
- package/src/modules/requestClient.ts +39 -0
- package/src/modules/swapKitError.ts +33 -5
- package/src/modules/swapKitNumber.ts +8 -1
- package/src/types/abis/erc20.ts +99 -0
- package/src/types/abis/mayaEvmVaults.ts +331 -0
- package/src/types/abis/tcEthVault.ts +496 -0
- package/src/types/chains.ts +220 -0
- package/src/types/commonTypes.ts +119 -0
- package/src/types/derivationPath.ts +56 -0
- package/src/types/errors/apiV1.ts +0 -0
- package/src/types/index.ts +10 -0
- package/src/types/network.ts +43 -0
- package/src/types/sdk.ts +44 -0
- package/src/types/tokens.ts +30 -0
- package/src/types/wallet.ts +47 -0
- package/LICENSE +0 -201
- package/dist/index.cjs +0 -1
- package/dist/index.d.ts +0 -355
- package/dist/index.es.js +0 -1064
- package/src/helpers/request.ts +0 -16
|
@@ -1,157 +1,201 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import { BaseDecimal, Chain } from "@swapkit/helpers";
|
|
3
3
|
|
|
4
|
-
import { getAssetType, getDecimal } from
|
|
4
|
+
import { assetFromString, getAssetType, getDecimal } from "../asset.ts";
|
|
5
5
|
|
|
6
6
|
const tickerMap: Record<string, string> = {
|
|
7
|
-
[Chain.THORChain]:
|
|
8
|
-
[Chain.Cosmos]:
|
|
9
|
-
[Chain.BinanceSmartChain]:
|
|
7
|
+
[Chain.THORChain]: "RUNE",
|
|
8
|
+
[Chain.Cosmos]: "ATOM",
|
|
9
|
+
[Chain.BinanceSmartChain]: "BNB",
|
|
10
10
|
};
|
|
11
11
|
|
|
12
|
-
describe(
|
|
13
|
-
describe(
|
|
14
|
-
|
|
15
|
-
const result = getAssetType({ chain: Chain.Bitcoin, symbol:
|
|
16
|
-
expect(result).toBe(
|
|
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(
|
|
21
|
-
describe(
|
|
22
|
-
Object.values(Chain)
|
|
23
|
-
|
|
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(
|
|
27
|
+
expect(result).toBe("Native");
|
|
28
28
|
});
|
|
29
|
-
}
|
|
29
|
+
}
|
|
30
30
|
});
|
|
31
31
|
|
|
32
|
-
describe(
|
|
33
|
-
|
|
34
|
-
const result = getAssetType({ chain: Chain.Cosmos, symbol:
|
|
35
|
-
expect(result).toBe(
|
|
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(
|
|
40
|
-
|
|
41
|
-
const result = getAssetType({ chain: Chain.Binance, symbol:
|
|
42
|
-
expect(result).toBe(
|
|
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(
|
|
47
|
-
|
|
48
|
-
const result = getAssetType({ chain: Chain.BinanceSmartChain, symbol:
|
|
49
|
-
expect(result).toBe(
|
|
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(
|
|
54
|
-
|
|
55
|
-
const result = getAssetType({ chain: Chain.Ethereum, symbol:
|
|
56
|
-
expect(result).toBe(
|
|
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(
|
|
61
|
-
|
|
62
|
-
const result = getAssetType({ chain: Chain.Avalanche, symbol:
|
|
63
|
-
expect(result).toBe(
|
|
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(
|
|
69
|
+
describe("getDecimal", () => {
|
|
70
70
|
/**
|
|
71
71
|
* Test out native
|
|
72
72
|
*/
|
|
73
|
-
Object.values(Chain)
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
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(
|
|
80
|
+
`returns proper decimal for native ${chain} asset`,
|
|
81
|
+
async () => {
|
|
78
82
|
const decimal = await getDecimal({ chain, symbol: chain });
|
|
79
83
|
expect(decimal).toBe(BaseDecimal[chain]);
|
|
80
|
-
}
|
|
81
|
-
|
|
84
|
+
},
|
|
85
|
+
{ retry: 3 },
|
|
86
|
+
);
|
|
82
87
|
});
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
describe("ETH", () => {
|
|
91
|
+
test(
|
|
92
|
+
"returns proper decimal for eth and it's assets",
|
|
93
|
+
async () => {
|
|
94
|
+
const ethDecimal = await getDecimal({ chain: Chain.Ethereum, symbol: "ETH" });
|
|
95
|
+
expect(ethDecimal).toBe(BaseDecimal.ETH);
|
|
96
|
+
await Bun.sleep(500);
|
|
97
|
+
|
|
98
|
+
const usdcDecimal = await getDecimal({
|
|
99
|
+
chain: Chain.Ethereum,
|
|
100
|
+
symbol: "USDC-0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
|
|
101
|
+
});
|
|
102
|
+
expect(usdcDecimal).toBe(6);
|
|
103
|
+
await Bun.sleep(500);
|
|
83
104
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
105
|
+
const wbtcDecimal = await getDecimal({
|
|
106
|
+
chain: Chain.Ethereum,
|
|
107
|
+
symbol: "WBTC-0x2260fac5e5542a773aa44fbcfedf7c193bc2c599",
|
|
108
|
+
});
|
|
109
|
+
expect(wbtcDecimal).toBe(8);
|
|
110
|
+
await Bun.sleep(500);
|
|
88
111
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
112
|
+
const kindDecimal = await getDecimal({
|
|
113
|
+
chain: Chain.Ethereum,
|
|
114
|
+
symbol: "KIND-0x4618519de4c304f3444ffa7f812dddc2971cc688",
|
|
115
|
+
});
|
|
116
|
+
expect(kindDecimal).toBe(8);
|
|
117
|
+
await Bun.sleep(500);
|
|
94
118
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
119
|
+
const shitcoinDecimal = await getDecimal({
|
|
120
|
+
chain: Chain.Ethereum,
|
|
121
|
+
symbol: "HOMI-0xCa208BfD69ae6D2667f1FCbE681BAe12767c0078",
|
|
122
|
+
});
|
|
123
|
+
expect(shitcoinDecimal).toBe(0);
|
|
124
|
+
await Bun.sleep(500);
|
|
125
|
+
},
|
|
126
|
+
{ retry: 3 },
|
|
127
|
+
);
|
|
128
|
+
});
|
|
100
129
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
130
|
+
describe("AVAX", () => {
|
|
131
|
+
test(
|
|
132
|
+
"returns proper decimal for avax and it's assets",
|
|
133
|
+
async () => {
|
|
134
|
+
const avaxDecimal = await getDecimal({ chain: Chain.Avalanche, symbol: "AVAX" });
|
|
135
|
+
expect(avaxDecimal).toBe(BaseDecimal.AVAX);
|
|
106
136
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
137
|
+
const wbtceDecimal = await getDecimal({
|
|
138
|
+
chain: Chain.Avalanche,
|
|
139
|
+
symbol: "WBTC.e-0x50b7545627a5162f82a992c33b87adc75187b218",
|
|
140
|
+
});
|
|
141
|
+
expect(wbtceDecimal).toBe(8);
|
|
142
|
+
await Bun.sleep(500);
|
|
112
143
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
});
|
|
144
|
+
const btcbDecimal = await getDecimal({
|
|
145
|
+
chain: Chain.Avalanche,
|
|
146
|
+
symbol: "BTC.b-0x152b9d0FdC40C096757F570A51E494bd4b943E50",
|
|
147
|
+
});
|
|
148
|
+
expect(btcbDecimal).toBe(8);
|
|
149
|
+
await Bun.sleep(500);
|
|
120
150
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
151
|
+
const timeDecimal = await getDecimal({
|
|
152
|
+
chain: Chain.Avalanche,
|
|
153
|
+
symbol: "TIME-0xb54f16fB19478766A268F172C9480f8da1a7c9C3",
|
|
154
|
+
});
|
|
155
|
+
expect(timeDecimal).toBe(9);
|
|
156
|
+
await Bun.sleep(500);
|
|
125
157
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
158
|
+
const usdtDecimal = await getDecimal({
|
|
159
|
+
chain: Chain.Avalanche,
|
|
160
|
+
symbol: "USDT-0x9702230A8Ea53601f5cD2dc00fDBc13d4dF4A8c7",
|
|
161
|
+
});
|
|
162
|
+
expect(usdtDecimal).toBe(6);
|
|
163
|
+
await Bun.sleep(500);
|
|
131
164
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
165
|
+
const usdcDecimal = await getDecimal({
|
|
166
|
+
chain: Chain.Avalanche,
|
|
167
|
+
symbol: "USDC-0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E",
|
|
168
|
+
});
|
|
169
|
+
expect(usdcDecimal).toBe(6);
|
|
170
|
+
await Bun.sleep(500);
|
|
171
|
+
},
|
|
172
|
+
{ retry: 3 },
|
|
173
|
+
);
|
|
174
|
+
});
|
|
175
|
+
});
|
|
137
176
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
expect(timeDecimal).toBe(9);
|
|
177
|
+
describe("assetFromString", () => {
|
|
178
|
+
test("should return the correct object", () => {
|
|
179
|
+
const assetString = "THOR.RUNE";
|
|
180
|
+
const result = assetFromString(assetString);
|
|
143
181
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
182
|
+
expect(result).toEqual({
|
|
183
|
+
chain: Chain.THORChain,
|
|
184
|
+
symbol: "RUNE",
|
|
185
|
+
ticker: "RUNE",
|
|
186
|
+
synth: false,
|
|
187
|
+
});
|
|
188
|
+
});
|
|
149
189
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
190
|
+
test("should return the correct object for multiple dashes", () => {
|
|
191
|
+
const assetString = "ETH.PENDLE-LPT-0x1234";
|
|
192
|
+
const result = assetFromString(assetString);
|
|
193
|
+
|
|
194
|
+
expect(result).toEqual({
|
|
195
|
+
chain: Chain.Ethereum,
|
|
196
|
+
symbol: "PENDLE-LPT-0x1234",
|
|
197
|
+
ticker: "PENDLE-LPT",
|
|
198
|
+
synth: false,
|
|
155
199
|
});
|
|
156
200
|
});
|
|
157
201
|
});
|
|
@@ -1,79 +1,91 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import { Chain, MemoType } from "@swapkit/helpers";
|
|
3
3
|
|
|
4
|
-
import { getMemoFor } from
|
|
4
|
+
import { getMemoFor } from "../memo.ts";
|
|
5
5
|
|
|
6
|
-
describe(
|
|
7
|
-
describe(
|
|
8
|
-
[
|
|
9
|
-
[MemoType.LEAVE,
|
|
10
|
-
[MemoType.BOND,
|
|
11
|
-
]
|
|
12
|
-
|
|
13
|
-
|
|
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(
|
|
20
|
-
|
|
21
|
-
const result = getMemoFor(MemoType.UNBOND, { address:
|
|
22
|
-
expect(result).toBe(
|
|
21
|
+
describe("for Unbond and Thorname/Mayaname 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");
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
test("returns correct memo for Thorname Register", () => {
|
|
28
|
+
const result = getMemoFor(MemoType.THORNAME_REGISTER, {
|
|
29
|
+
name: "thorname",
|
|
30
|
+
chain: "BNB",
|
|
31
|
+
address: "0xABC123",
|
|
32
|
+
owner: "0xDEF456",
|
|
33
|
+
});
|
|
34
|
+
expect(result).toBe("~:thorname:BNB:0xABC123:0xDEF456");
|
|
23
35
|
});
|
|
24
36
|
|
|
25
|
-
|
|
37
|
+
test("returns correct memo for Mayaname Register", () => {
|
|
26
38
|
const result = getMemoFor(MemoType.THORNAME_REGISTER, {
|
|
27
|
-
name:
|
|
28
|
-
chain:
|
|
29
|
-
address:
|
|
30
|
-
owner:
|
|
39
|
+
name: "mayaname",
|
|
40
|
+
chain: "BNB",
|
|
41
|
+
address: "0xABC123",
|
|
42
|
+
owner: "0xDEF456",
|
|
31
43
|
});
|
|
32
|
-
expect(result).toBe(
|
|
44
|
+
expect(result).toBe("~:mayaname:BNB:0xABC123:0xDEF456");
|
|
33
45
|
});
|
|
34
46
|
});
|
|
35
47
|
|
|
36
|
-
describe(
|
|
37
|
-
|
|
48
|
+
describe("for Deposit", () => {
|
|
49
|
+
test("returns correct memo for Deposit (single side)", () => {
|
|
38
50
|
const result = getMemoFor(MemoType.DEPOSIT, {
|
|
39
51
|
chain: Chain.Ethereum,
|
|
40
|
-
symbol:
|
|
52
|
+
symbol: "ETH",
|
|
41
53
|
singleSide: true,
|
|
42
54
|
});
|
|
43
|
-
expect(result).toBe(
|
|
55
|
+
expect(result).toBe("+:ETH/ETH");
|
|
44
56
|
});
|
|
45
57
|
|
|
46
|
-
|
|
58
|
+
test("returns correct memo for Deposit (dual side)", () => {
|
|
47
59
|
const result = getMemoFor(MemoType.DEPOSIT, {
|
|
48
60
|
chain: Chain.Avalanche,
|
|
49
|
-
symbol:
|
|
50
|
-
address:
|
|
61
|
+
symbol: "AVAX",
|
|
62
|
+
address: "0xABC123",
|
|
51
63
|
});
|
|
52
|
-
expect(result).toBe(
|
|
64
|
+
expect(result).toBe("+:AVAX.AVAX:0xABC123");
|
|
53
65
|
});
|
|
54
66
|
});
|
|
55
67
|
|
|
56
|
-
describe(
|
|
57
|
-
|
|
68
|
+
describe("for Withdraw", () => {
|
|
69
|
+
test("returns correct memo for Withdraw (single side)", () => {
|
|
58
70
|
const result = getMemoFor(MemoType.WITHDRAW, {
|
|
59
71
|
chain: Chain.Bitcoin,
|
|
60
|
-
ticker:
|
|
61
|
-
symbol:
|
|
72
|
+
ticker: "BTC",
|
|
73
|
+
symbol: "BTC",
|
|
62
74
|
basisPoints: 10000,
|
|
63
75
|
singleSide: true,
|
|
64
76
|
});
|
|
65
|
-
expect(result).toBe(
|
|
77
|
+
expect(result).toBe("-:BTC/BTC:10000");
|
|
66
78
|
});
|
|
67
79
|
|
|
68
|
-
|
|
80
|
+
test("returns correct memo for Withdraw (dual side)", () => {
|
|
69
81
|
const result = getMemoFor(MemoType.WITHDRAW, {
|
|
70
82
|
chain: Chain.Ethereum,
|
|
71
|
-
ticker:
|
|
72
|
-
symbol:
|
|
83
|
+
ticker: "ETH",
|
|
84
|
+
symbol: "ETH",
|
|
73
85
|
basisPoints: 100,
|
|
74
|
-
targetAssetString:
|
|
86
|
+
targetAssetString: "ETH.ETH",
|
|
75
87
|
});
|
|
76
|
-
expect(result).toBe(
|
|
88
|
+
expect(result).toBe("-:ETH.ETH:100:ETH.ETH");
|
|
77
89
|
});
|
|
78
90
|
});
|
|
79
91
|
});
|
|
@@ -1,59 +1,64 @@
|
|
|
1
|
-
import { describe, expect,
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import { Chain, type DerivationPathArray } from "@swapkit/helpers";
|
|
2
3
|
|
|
3
|
-
import {
|
|
4
|
+
import { findAssetBy } from "../asset.ts";
|
|
5
|
+
import { derivationPathToString, getTHORNameCost } from "../others.ts";
|
|
4
6
|
|
|
5
|
-
describe(
|
|
6
|
-
|
|
7
|
-
const path = [1, 2, 3, 4, 5];
|
|
8
|
-
|
|
9
|
-
expect(result).toEqual("1'/2'/3'/4/5");
|
|
7
|
+
describe("derivationPathToString", () => {
|
|
8
|
+
test("should return the correct string for a full path", () => {
|
|
9
|
+
const path = [1, 2, 3, 4, 5] as DerivationPathArray;
|
|
10
|
+
expect(derivationPathToString(path)).toEqual("m/1'/2'/3'/4/5");
|
|
10
11
|
});
|
|
11
12
|
|
|
12
|
-
|
|
13
|
-
const path = [1, 2, 3, 4];
|
|
14
|
-
|
|
15
|
-
expect(result).toEqual("1'/2'/3'/4");
|
|
13
|
+
test("should return the correct string for a short path", () => {
|
|
14
|
+
const path = [1, 2, 3, 4] as DerivationPathArray;
|
|
15
|
+
expect(derivationPathToString(path)).toEqual("m/1'/2'/3'/4");
|
|
16
16
|
});
|
|
17
17
|
});
|
|
18
18
|
|
|
19
|
-
describe(
|
|
20
|
-
describe(
|
|
21
|
-
[
|
|
19
|
+
describe("getTHORNameCost", () => {
|
|
20
|
+
describe("for correct values", () => {
|
|
21
|
+
const costCases = [
|
|
22
22
|
[1, 11],
|
|
23
23
|
[2, 12],
|
|
24
24
|
[3, 13],
|
|
25
25
|
[10, 20],
|
|
26
|
-
]
|
|
27
|
-
|
|
26
|
+
];
|
|
27
|
+
|
|
28
|
+
for (const [years = 0, expected = 10] of costCases) {
|
|
29
|
+
test(`returns correct ${expected} cost for ${years} years`, () => {
|
|
28
30
|
const result = getTHORNameCost(years);
|
|
29
31
|
expect(result).toBe(expected);
|
|
30
32
|
});
|
|
31
|
-
}
|
|
33
|
+
}
|
|
32
34
|
});
|
|
33
35
|
|
|
34
|
-
|
|
35
|
-
expect(() => getTHORNameCost(-1)).
|
|
36
|
+
test("throws an error for negative years", () => {
|
|
37
|
+
expect(() => getTHORNameCost(-1)).toThrow("Invalid number of year");
|
|
36
38
|
});
|
|
37
39
|
});
|
|
38
40
|
|
|
39
|
-
describe(
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
41
|
+
describe("getAssetBy", () => {
|
|
42
|
+
test("find asset by identifier", async () => {
|
|
43
|
+
const assetByIdentifier = await findAssetBy({ identifier: "ETH.ETH" });
|
|
44
|
+
expect(assetByIdentifier).toBe("ETH.ETH");
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
test("find asset by chain and contract", async () => {
|
|
48
|
+
const assetByChainAndContract = await findAssetBy({
|
|
49
|
+
chain: Chain.Ethereum,
|
|
50
|
+
contract: "0XA0B86991C6218B36C1D19D4A2E9EB0CE3606EB48",
|
|
51
|
+
});
|
|
52
|
+
expect(assetByChainAndContract).toBe("ETH.USDC-0XA0B86991C6218B36C1D19D4A2E9EB0CE3606EB48");
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
test("return undefined if asset can't be found", async () => {
|
|
56
|
+
const assetByIdentifier = await findAssetBy({ identifier: "ARB.NOTEXISTINGTOKEN" });
|
|
57
|
+
const assetByChainAndContract = await findAssetBy({
|
|
58
|
+
chain: Chain.Ethereum,
|
|
59
|
+
contract: "NOTFOUND",
|
|
57
60
|
});
|
|
61
|
+
expect(assetByIdentifier).toBeUndefined();
|
|
62
|
+
expect(assetByChainAndContract).toBeUndefined();
|
|
58
63
|
});
|
|
59
64
|
});
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import { validateTNS } from "../validators";
|
|
3
|
+
|
|
4
|
+
describe("validateTNS", () => {
|
|
5
|
+
const casesWithExpectation: [string, boolean][] = [
|
|
6
|
+
["validname", true],
|
|
7
|
+
["valid-name", true],
|
|
8
|
+
["valid_name", true],
|
|
9
|
+
["valid+name", true],
|
|
10
|
+
["name_with_numbers123", true],
|
|
11
|
+
["UPPER_CASE", true],
|
|
12
|
+
["toolongname123456789012345678901", false],
|
|
13
|
+
["invalid@name", false],
|
|
14
|
+
["invalid!name", false],
|
|
15
|
+
["invalid#name", false],
|
|
16
|
+
];
|
|
17
|
+
|
|
18
|
+
for (const [name, expected] of casesWithExpectation) {
|
|
19
|
+
test(`returns ${expected} for THORName "${name}"`, () => {
|
|
20
|
+
const result = validateTNS(name);
|
|
21
|
+
expect(result).toBe(expected);
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
});
|