@swapkit/helpers 4.0.0-beta.32 → 4.0.0-beta.34

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 (251) hide show
  1. package/dist/api/index.js +2 -2
  2. package/dist/api/index.js.map +1 -1
  3. package/dist/{chunk-ganzk321.js → chunk-hm14bfyg.js} +3 -3
  4. package/dist/{chunk-fazw0jvt.js.map → chunk-hm14bfyg.js.map} +1 -1
  5. package/dist/chunk-vb4wtm2w.js +4 -0
  6. package/dist/{chunk-ganzk321.js.map → chunk-vb4wtm2w.js.map} +1 -1
  7. package/dist/contracts.cjs +4 -0
  8. package/dist/contracts.cjs.map +10 -0
  9. package/dist/contracts.js +4 -0
  10. package/dist/contracts.js.map +10 -0
  11. package/dist/index.cjs +3 -3
  12. package/dist/index.cjs.map +11 -11
  13. package/dist/index.js +3 -3
  14. package/dist/index.js.map +11 -11
  15. package/dist/tokens.cjs +4 -0
  16. package/dist/tokens.cjs.map +10 -0
  17. package/dist/tokens.js +4 -0
  18. package/dist/tokens.js.map +10 -0
  19. package/dist/types/api/index.d.ts +238 -0
  20. package/dist/types/api/index.d.ts.map +1 -0
  21. package/dist/types/api/microgard/endpoints.d.ts +25 -0
  22. package/dist/types/api/microgard/endpoints.d.ts.map +1 -0
  23. package/dist/types/api/microgard/types.d.ts +56 -0
  24. package/dist/types/api/microgard/types.d.ts.map +1 -0
  25. package/dist/types/api/midgard/endpoints.d.ts +35 -0
  26. package/dist/types/api/midgard/endpoints.d.ts.map +1 -0
  27. package/dist/types/api/midgard/types.d.ts +102 -0
  28. package/dist/types/api/midgard/types.d.ts.map +1 -0
  29. package/dist/types/api/swapkitApi/endpoints.d.ts +194 -0
  30. package/dist/types/api/swapkitApi/endpoints.d.ts.map +1 -0
  31. package/dist/types/api/swapkitApi/types.d.ts +7238 -0
  32. package/dist/types/api/swapkitApi/types.d.ts.map +1 -0
  33. package/dist/types/api/thornode/endpoints.d.ts +31 -0
  34. package/dist/types/api/thornode/endpoints.d.ts.map +1 -0
  35. package/dist/types/api/thornode/types.d.ts +264 -0
  36. package/dist/types/api/thornode/types.d.ts.map +1 -0
  37. package/dist/types/api/thorswapStatic/endpoints.d.ts +7 -0
  38. package/dist/types/api/thorswapStatic/endpoints.d.ts.map +1 -0
  39. package/dist/types/api/thorswapStatic/types.d.ts +22 -0
  40. package/dist/types/api/thorswapStatic/types.d.ts.map +1 -0
  41. package/dist/types/contracts.d.ts +2 -0
  42. package/dist/types/contracts.d.ts.map +1 -0
  43. package/{src/index.ts → dist/types/index.d.ts} +3 -4
  44. package/dist/types/index.d.ts.map +1 -0
  45. package/dist/types/modules/assetValue.d.ts +71 -0
  46. package/dist/types/modules/assetValue.d.ts.map +1 -0
  47. package/dist/types/modules/bigIntArithmetics.d.ts +56 -0
  48. package/dist/types/modules/bigIntArithmetics.d.ts.map +1 -0
  49. package/dist/types/modules/feeMultiplier.d.ts +45 -0
  50. package/dist/types/modules/feeMultiplier.d.ts.map +1 -0
  51. package/dist/types/modules/requestClient.d.ts +22 -0
  52. package/dist/types/modules/requestClient.d.ts.map +1 -0
  53. package/dist/types/modules/swapKitConfig.d.ts +98 -0
  54. package/dist/types/modules/swapKitConfig.d.ts.map +1 -0
  55. package/dist/types/modules/swapKitError.d.ts +829 -0
  56. package/dist/types/modules/swapKitError.d.ts.map +1 -0
  57. package/dist/types/modules/swapKitNumber.d.ts +7 -0
  58. package/dist/types/modules/swapKitNumber.d.ts.map +1 -0
  59. package/dist/types/tokens.d.ts +2 -0
  60. package/dist/types/tokens.d.ts.map +1 -0
  61. package/dist/types/types/chains.d.ts +187 -0
  62. package/dist/types/types/chains.d.ts.map +1 -0
  63. package/dist/types/types/commonTypes.d.ts +37 -0
  64. package/dist/types/types/commonTypes.d.ts.map +1 -0
  65. package/dist/types/types/derivationPath.d.ts +17 -0
  66. package/dist/types/types/derivationPath.d.ts.map +1 -0
  67. package/dist/types/types/errors/apiV1.d.ts +2 -0
  68. package/dist/types/types/errors/apiV1.d.ts.map +1 -0
  69. package/{src/types/index.ts → dist/types/types/index.d.ts} +1 -1
  70. package/dist/types/types/index.d.ts.map +1 -0
  71. package/dist/types/types/quotes.d.ts +170 -0
  72. package/dist/types/types/quotes.d.ts.map +1 -0
  73. package/dist/types/types/radix.d.ts +15 -0
  74. package/dist/types/types/radix.d.ts.map +1 -0
  75. package/dist/types/types/sdk.d.ts +35 -0
  76. package/dist/types/types/sdk.d.ts.map +1 -0
  77. package/dist/types/types/wallet.d.ts +121 -0
  78. package/dist/types/types/wallet.d.ts.map +1 -0
  79. package/dist/types/utils/asset.d.ts +40 -0
  80. package/dist/types/utils/asset.d.ts.map +1 -0
  81. package/dist/types/utils/derivationPath.d.ts +19 -0
  82. package/dist/types/utils/derivationPath.d.ts.map +1 -0
  83. package/dist/types/utils/explorerUrls.d.ts +10 -0
  84. package/dist/types/utils/explorerUrls.d.ts.map +1 -0
  85. package/dist/types/utils/liquidity.d.ts +59 -0
  86. package/dist/types/utils/liquidity.d.ts.map +1 -0
  87. package/dist/types/utils/memo.d.ts +65 -0
  88. package/dist/types/utils/memo.d.ts.map +1 -0
  89. package/dist/types/utils/others.d.ts +9 -0
  90. package/dist/types/utils/others.d.ts.map +1 -0
  91. package/dist/types/utils/validators.d.ts +3 -0
  92. package/dist/types/utils/validators.d.ts.map +1 -0
  93. package/dist/types/utils/wallets.d.ts +32 -0
  94. package/dist/types/utils/wallets.d.ts.map +1 -0
  95. package/package.json +14 -15
  96. package/dist/chunk-06q78xy3.js +0 -4
  97. package/dist/chunk-06q78xy3.js.map +0 -10
  98. package/dist/chunk-0q5vvg5c.js +0 -5
  99. package/dist/chunk-0q5vvg5c.js.map +0 -10
  100. package/dist/chunk-18bxh1n7.js +0 -5
  101. package/dist/chunk-18bxh1n7.js.map +0 -10
  102. package/dist/chunk-3qya5ng9.js +0 -4
  103. package/dist/chunk-3qya5ng9.js.map +0 -10
  104. package/dist/chunk-4yqymkbp.js +0 -5
  105. package/dist/chunk-4yqymkbp.js.map +0 -10
  106. package/dist/chunk-50gpwcq9.js +0 -4
  107. package/dist/chunk-50gpwcq9.js.map +0 -10
  108. package/dist/chunk-6atq9cs7.js +0 -4
  109. package/dist/chunk-6atq9cs7.js.map +0 -10
  110. package/dist/chunk-6m0d5pv4.js +0 -5
  111. package/dist/chunk-6m0d5pv4.js.map +0 -10
  112. package/dist/chunk-8x46g3wq.js +0 -5
  113. package/dist/chunk-8x46g3wq.js.map +0 -10
  114. package/dist/chunk-92sk0g47.js +0 -5
  115. package/dist/chunk-92sk0g47.js.map +0 -10
  116. package/dist/chunk-9f2b3enk.js +0 -5
  117. package/dist/chunk-9f2b3enk.js.map +0 -10
  118. package/dist/chunk-adrafsdk.js +0 -5
  119. package/dist/chunk-adrafsdk.js.map +0 -10
  120. package/dist/chunk-b1hang9z.js +0 -5
  121. package/dist/chunk-b1hang9z.js.map +0 -10
  122. package/dist/chunk-becdmywt.js +0 -4
  123. package/dist/chunk-becdmywt.js.map +0 -10
  124. package/dist/chunk-ehz0t9d1.js +0 -4
  125. package/dist/chunk-ehz0t9d1.js.map +0 -10
  126. package/dist/chunk-fazw0jvt.js +0 -4
  127. package/dist/chunk-fm9ycn0h.js +0 -5
  128. package/dist/chunk-fm9ycn0h.js.map +0 -10
  129. package/dist/chunk-g67e2r57.js +0 -4
  130. package/dist/chunk-g67e2r57.js.map +0 -10
  131. package/dist/chunk-he3vy8gt.js +0 -4
  132. package/dist/chunk-he3vy8gt.js.map +0 -10
  133. package/dist/chunk-jjayk2y5.js +0 -4
  134. package/dist/chunk-jjayk2y5.js.map +0 -10
  135. package/dist/chunk-mmyv2vsv.js +0 -5
  136. package/dist/chunk-mmyv2vsv.js.map +0 -10
  137. package/dist/chunk-phev7aw7.js +0 -4
  138. package/dist/chunk-phev7aw7.js.map +0 -10
  139. package/dist/chunk-rhqk87p2.js +0 -5
  140. package/dist/chunk-rhqk87p2.js.map +0 -10
  141. package/dist/chunk-rnv7fdjk.js +0 -4
  142. package/dist/chunk-rnv7fdjk.js.map +0 -10
  143. package/dist/chunk-rwh98p1c.js +0 -4
  144. package/dist/chunk-rwh98p1c.js.map +0 -10
  145. package/dist/chunk-v9zj2gsj.js +0 -5
  146. package/dist/chunk-v9zj2gsj.js.map +0 -10
  147. package/dist/chunk-vv5bgsn8.js +0 -4
  148. package/dist/chunk-vv5bgsn8.js.map +0 -10
  149. package/dist/chunk-vwh9jfxn.js +0 -5
  150. package/dist/chunk-vwh9jfxn.js.map +0 -10
  151. package/dist/chunk-x0rqy75t.js +0 -4
  152. package/dist/chunk-x0rqy75t.js.map +0 -10
  153. package/dist/contracts/index.cjs +0 -4
  154. package/dist/contracts/index.cjs.map +0 -38
  155. package/dist/contracts/index.js +0 -4
  156. package/dist/contracts/index.js.map +0 -38
  157. package/dist/tokens/index.cjs +0 -4
  158. package/dist/tokens/index.cjs.map +0 -10
  159. package/dist/tokens/index.js +0 -4
  160. package/dist/tokens/index.js.map +0 -10
  161. package/src/api/index.ts +0 -19
  162. package/src/api/microgard/endpoints.ts +0 -83
  163. package/src/api/microgard/types.ts +0 -57
  164. package/src/api/midgard/endpoints.ts +0 -90
  165. package/src/api/midgard/types.ts +0 -106
  166. package/src/api/swapkitApi/endpoints.ts +0 -193
  167. package/src/api/swapkitApi/types.ts +0 -635
  168. package/src/api/thornode/endpoints.ts +0 -116
  169. package/src/api/thornode/types.ts +0 -276
  170. package/src/api/thorswapStatic/endpoints.ts +0 -46
  171. package/src/api/thorswapStatic/types.ts +0 -18
  172. package/src/contracts/abis/avaxGeneric.ts +0 -92
  173. package/src/contracts/abis/avaxWoofi.ts +0 -145
  174. package/src/contracts/abis/bscGeneric.ts +0 -106
  175. package/src/contracts/abis/chainflipGateway.ts +0 -330
  176. package/src/contracts/abis/erc20.ts +0 -99
  177. package/src/contracts/abis/ethGeneric.ts +0 -92
  178. package/src/contracts/abis/mayaEvmVaults.ts +0 -331
  179. package/src/contracts/abis/pancakeV2.ts +0 -145
  180. package/src/contracts/abis/pangolin.ts +0 -120
  181. package/src/contracts/abis/sushiswap.ts +0 -120
  182. package/src/contracts/abis/tcEthVault.ts +0 -650
  183. package/src/contracts/abis/traderJoe.ts +0 -120
  184. package/src/contracts/abis/uniswapV2.ts +0 -120
  185. package/src/contracts/abis/uniswapV2Leg.ts +0 -128
  186. package/src/contracts/abis/uniswapV3_100.ts +0 -128
  187. package/src/contracts/abis/uniswapV3_10000.ts +0 -128
  188. package/src/contracts/abis/uniswapV3_3000.ts +0 -128
  189. package/src/contracts/abis/uniswapV3_500.ts +0 -128
  190. package/src/contracts/index.ts +0 -95
  191. package/src/contracts/routers/index.ts +0 -58
  192. package/src/contracts/routers/kyber.ts +0 -402
  193. package/src/contracts/routers/oneinch.ts +0 -2188
  194. package/src/contracts/routers/pancakeswap.ts +0 -340
  195. package/src/contracts/routers/pangolin.ts +0 -340
  196. package/src/contracts/routers/sushiswap.ts +0 -340
  197. package/src/contracts/routers/traderJoe.ts +0 -340
  198. package/src/contracts/routers/uniswapv2.ts +0 -340
  199. package/src/contracts/routers/uniswapv3.ts +0 -254
  200. package/src/contracts/routers/woofi.ts +0 -171
  201. package/src/modules/__tests__/assetValue.test.ts +0 -877
  202. package/src/modules/__tests__/bigIntArithmetics.test.ts +0 -30
  203. package/src/modules/__tests__/swapKitConfig.test.ts +0 -37
  204. package/src/modules/__tests__/swapKitNumber.test.ts +0 -560
  205. package/src/modules/assetValue.ts +0 -387
  206. package/src/modules/bigIntArithmetics.ts +0 -436
  207. package/src/modules/feeMultiplier.ts +0 -87
  208. package/src/modules/requestClient.ts +0 -83
  209. package/src/modules/swapKitConfig.ts +0 -143
  210. package/src/modules/swapKitError.ts +0 -442
  211. package/src/modules/swapKitNumber.ts +0 -16
  212. package/src/tokens/index.ts +0 -15
  213. package/src/tokens/lists/camelot_v3.ts +0 -16060
  214. package/src/tokens/lists/caviar_v1.ts +0 -1704
  215. package/src/tokens/lists/chainflip.ts +0 -104
  216. package/src/tokens/lists/index.ts +0 -14
  217. package/src/tokens/lists/jupiter.ts +0 -33563
  218. package/src/tokens/lists/mayachain.ts +0 -509
  219. package/src/tokens/lists/near.ts +0 -458
  220. package/src/tokens/lists/oneinch.ts +0 -15006
  221. package/src/tokens/lists/openocean_v2.ts +0 -12434
  222. package/src/tokens/lists/pancakeswap.ts +0 -6136
  223. package/src/tokens/lists/pangolin_v1.ts +0 -75
  224. package/src/tokens/lists/sushiswap_v2.ts +0 -595
  225. package/src/tokens/lists/thorchain.ts +0 -748
  226. package/src/tokens/lists/traderjoe_v2.ts +0 -594
  227. package/src/tokens/lists/uniswap_v2.ts +0 -11484
  228. package/src/tokens/lists/uniswap_v3.ts +0 -19424
  229. package/src/types/chains.ts +0 -555
  230. package/src/types/commonTypes.ts +0 -58
  231. package/src/types/derivationPath.ts +0 -58
  232. package/src/types/errors/apiV1.ts +0 -0
  233. package/src/types/quotes.ts +0 -172
  234. package/src/types/radix.ts +0 -14
  235. package/src/types/sdk.ts +0 -42
  236. package/src/types/tokens.ts +0 -17
  237. package/src/types/wallet.ts +0 -166
  238. package/src/utils/__tests__/asset.test.ts +0 -193
  239. package/src/utils/__tests__/derivationPath.test.ts +0 -16
  240. package/src/utils/__tests__/memo.test.ts +0 -103
  241. package/src/utils/__tests__/others.test.ts +0 -88
  242. package/src/utils/__tests__/validators.test.ts +0 -24
  243. package/src/utils/asset.ts +0 -231
  244. package/src/utils/derivationPath.ts +0 -98
  245. package/src/utils/liquidity.ts +0 -179
  246. package/src/utils/memo.ts +0 -143
  247. package/src/utils/others.ts +0 -86
  248. package/src/utils/plugin.ts +0 -13
  249. package/src/utils/tokens.ts +0 -73
  250. package/src/utils/validators.ts +0 -32
  251. package/src/utils/wallets.ts +0 -276
@@ -1,103 +0,0 @@
1
- import { describe, expect, test } from "bun:test";
2
- import { Chain, MemoType } from "../../types";
3
-
4
- import {
5
- getMemoForDeposit,
6
- getMemoForLeaveAndBond,
7
- getMemoForNamePreferredAssetRegister,
8
- getMemoForNameRegister,
9
- getMemoForRunePoolDeposit,
10
- getMemoForRunePoolWithdraw,
11
- getMemoForWithdraw,
12
- } from "../memo";
13
-
14
- describe("getMemoForLeaveAndBond", () => {
15
- test("returns correct memo for Leave", () => {
16
- const result = getMemoForLeaveAndBond({ address: "ABC123", type: MemoType.LEAVE });
17
- expect(result).toBe("LEAVE:ABC123");
18
- });
19
-
20
- test("returns correct memo for Bond", () => {
21
- const result = getMemoForLeaveAndBond({ address: "ABC123", type: MemoType.BOND });
22
- expect(result).toBe("BOND:ABC123");
23
- });
24
- });
25
-
26
- describe("getMemoForNameRegister", () => {
27
- test("returns correct memo for single side", () => {
28
- const result = getMemoForNameRegister({
29
- name: "asdfg",
30
- chain: Chain.Ethereum,
31
- owner: "thor1234",
32
- address: "0xaasd123",
33
- });
34
- expect(result).toBe("~:asdfg:ETH:0xaasd123:thor1234");
35
- });
36
- });
37
-
38
- describe("getMemoForNamePreferredAssetRegister", () => {
39
- test("returns correct memo for single side", () => {
40
- const result = getMemoForNamePreferredAssetRegister({
41
- name: "asdfg",
42
- chain: Chain.Ethereum,
43
- owner: "thor1234",
44
- asset: "ETH.USDC-0XA0B86991C6218B36C1D19D4A2E9EB0CE3606EB48",
45
- payout: "0x6621d872f17109d6601c49edba526ebcfd332d5d",
46
- });
47
- expect(result).toBe(
48
- "~:asdfg:ETH:0x6621d872f17109d6601c49edba526ebcfd332d5d:thor1234:ETH.USDC-0XA0B86991C6218B36C1D19D4A2E9EB0CE3606EB48",
49
- );
50
- });
51
- });
52
-
53
- describe("getMemoForDeposit", () => {
54
- test("returns correct memo for single side", () => {
55
- const result = getMemoForDeposit({ chain: Chain.Ethereum, symbol: "ETH" });
56
- expect(result).toBe("+:ETH.ETH");
57
- });
58
-
59
- test("returns correct memo when paired address is not available but affiliate info is present", () => {
60
- const result = getMemoForDeposit({
61
- chain: Chain.Ethereum,
62
- symbol: "ETH",
63
- affiliateAddress: "thor1abc123",
64
- affiliateBasisPoints: 500,
65
- });
66
- expect(result).toBe("+:ETH.ETH::thor1abc123:500");
67
- });
68
- });
69
-
70
- describe("getMemoForWithdraw", () => {
71
- test("returns correct memo for single side", () => {
72
- const result = getMemoForWithdraw({
73
- chain: Chain.Ethereum,
74
- symbol: "ETH",
75
- ticker: "ETH",
76
- basisPoints: 100,
77
- });
78
- expect(result).toBe("-:ETH.ETH:100");
79
- });
80
- });
81
-
82
- describe("getMemoForRunePoolDeposit", () => {
83
- test("returns correct memo for single side", () => {
84
- const result = getMemoForRunePoolDeposit();
85
- expect(result).toBe("POOL+");
86
- });
87
- });
88
-
89
- describe("getMemoForRunePoolWithdraw", () => {
90
- test("returns correct memo for single side", () => {
91
- const result = getMemoForRunePoolWithdraw({ basisPoints: 500 });
92
- expect(result).toBe("POOL-:500");
93
- });
94
-
95
- test("returns correct memo when affiliate info is present", () => {
96
- const result = getMemoForRunePoolWithdraw({
97
- basisPoints: 500,
98
- affiliateAddress: "thor1abc123",
99
- affiliateBasisPoints: 500,
100
- });
101
- expect(result).toBe("POOL-:500:thor1abc123:500");
102
- });
103
- });
@@ -1,88 +0,0 @@
1
- import { describe, expect, test } from "bun:test";
2
- import { Chain } from "../../types";
3
-
4
- import { findAssetBy } from "../asset";
5
- import { getTHORNameCost } from "../others";
6
-
7
- describe("getTHORNameCost", () => {
8
- describe("for correct values", () => {
9
- const costCases = [
10
- [1, 11],
11
- [2, 12],
12
- [3, 13],
13
- [10, 20],
14
- ];
15
-
16
- for (const [years = 0, expected = 10] of costCases) {
17
- test(`returns correct ${expected} cost for ${years} years`, () => {
18
- const result = getTHORNameCost(years);
19
- expect(result).toBe(expected);
20
- });
21
- }
22
- });
23
-
24
- test("throws an error for negative years", () => {
25
- expect(() => getTHORNameCost(-1)).toThrow("helpers_invalid_number_of_years");
26
- });
27
- });
28
-
29
- describe("getAssetBy", () => {
30
- test("find asset by identifier", async () => {
31
- const assetByIdentifier = await findAssetBy({ identifier: "ETH.ETH" });
32
- expect(assetByIdentifier).toBe("ETH.ETH");
33
- });
34
-
35
- test("find asset by chain and contract", async () => {
36
- const assetByChainAndContract = await findAssetBy({
37
- chain: Chain.Ethereum,
38
- contract: "0XA0B86991C6218B36C1D19D4A2E9EB0CE3606EB48",
39
- });
40
- expect(assetByChainAndContract?.toUpperCase()).toBe(
41
- "ETH.USDC-0XA0B86991C6218B36C1D19D4A2E9EB0CE3606EB48",
42
- );
43
- });
44
-
45
- test("return undefined if asset can't be found", async () => {
46
- const assetByIdentifier = await findAssetBy({ identifier: "ARB.NOTEXISTINGTOKEN" });
47
- const assetByChainAndContract = await findAssetBy({
48
- chain: Chain.Ethereum,
49
- contract: "NOTFOUND",
50
- });
51
- expect(assetByIdentifier).toBeUndefined();
52
- expect(assetByChainAndContract).toBeUndefined();
53
- });
54
-
55
- test("find asset by chain and radix resource", async () => {
56
- const assetByChainAndContract = await findAssetBy({
57
- chain: Chain.Radix,
58
- contract: "resource_rdx1t580qxc7upat7lww4l2c4jckacafjeudxj5wpjrrct0p3e82sq4y75",
59
- });
60
- expect(assetByChainAndContract?.toUpperCase()).toBe(
61
- "XRD.XWBTC-resource_rdx1t580qxc7upat7lww4l2c4jckacafjeudxj5wpjrrct0p3e82sq4y75".toUpperCase(),
62
- );
63
- });
64
-
65
- test("find asset by radix identifier", async () => {
66
- const assetByChainAndContract = await findAssetBy({
67
- identifier: "XRD.XRD",
68
- });
69
- expect(assetByChainAndContract?.toUpperCase()).toBe("XRD.XRD".toUpperCase());
70
- });
71
-
72
- test("find asset by chain and Solana resource", async () => {
73
- const assetByChainAndContract = await findAssetBy({
74
- chain: Chain.Solana,
75
- contract: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
76
- });
77
- expect(assetByChainAndContract?.toUpperCase()).toBe(
78
- "SOL.USDC-EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v".toUpperCase(),
79
- );
80
- });
81
-
82
- test("find asset by Solana identifier", async () => {
83
- const assetByChainAndContract = await findAssetBy({
84
- identifier: "SOL.SOL",
85
- });
86
- expect(assetByChainAndContract?.toUpperCase()).toBe("SOL.SOL".toUpperCase());
87
- });
88
- });
@@ -1,24 +0,0 @@
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
- });
@@ -1,231 +0,0 @@
1
- import { match } from "ts-pattern";
2
- import { AssetValue } from "../modules/assetValue";
3
- import { RequestClient } from "../modules/requestClient";
4
- import { SKConfig } from "../modules/swapKitConfig";
5
- import { BaseDecimal, Chain, type EVMChain, EVMChains, UTXOChains } from "../types/chains";
6
- import type { RadixCoreStateResourceDTO } from "../types/radix";
7
- import type { TokenNames } from "../types/tokens";
8
-
9
- export type CommonAssetString = (typeof CommonAssetStrings)[number] | Chain;
10
-
11
- export type ConditionalAssetValueReturn<T extends boolean> = T extends true
12
- ? Promise<AssetValue[]>
13
- : AssetValue[];
14
-
15
- export const CommonAssetStrings = [
16
- `${Chain.Maya}.MAYA`,
17
- `${Chain.Maya}.CACAO`,
18
- `${Chain.Ethereum}.THOR`,
19
- `${Chain.Ethereum}.vTHOR`,
20
- `${Chain.Kujira}.USK`,
21
- `${Chain.Ethereum}.FLIP`,
22
- `${Chain.Radix}.XRD`,
23
- ] as const;
24
-
25
- const ethGasChains = [
26
- Chain.Arbitrum,
27
- Chain.Aurora,
28
- Chain.Base,
29
- Chain.Ethereum,
30
- Chain.Optimism,
31
- Chain.Polygon,
32
- ] as const;
33
-
34
- async function getContractDecimals({ chain, to }: { chain: EVMChain; to: string }) {
35
- const getDecimalMethodHex = "0x313ce567";
36
-
37
- try {
38
- const { result } = await RequestClient.post<{ result: string }>(
39
- SKConfig.get("rpcUrls")[chain],
40
- {
41
- headers: {
42
- accept: "*/*",
43
- "content-type": "application/json",
44
- "cache-control": "no-cache",
45
- },
46
- body: JSON.stringify({
47
- id: 44,
48
- jsonrpc: "2.0",
49
- method: "eth_call",
50
- params: [{ to: to.toLowerCase(), data: getDecimalMethodHex }, "latest"],
51
- }),
52
- },
53
- );
54
-
55
- return Number.parseInt(BigInt(result || BaseDecimal[chain]).toString());
56
- } catch (error) {
57
- console.error(`Failed to fetch contract decimals for ${to} on ${chain}:`, error);
58
- return BaseDecimal[chain];
59
- }
60
- }
61
-
62
- async function getRadixAssetDecimal(symbol: string) {
63
- if (symbol === Chain.Radix) return BaseDecimal.XRD;
64
-
65
- try {
66
- const resourceAddress = symbol.split("-")[1]?.toLowerCase();
67
-
68
- const { manager } = await RequestClient.post<RadixCoreStateResourceDTO>(
69
- `${SKConfig.get("rpcUrls").XRD}/state/resource`,
70
- {
71
- headers: { Accept: "*/*", "Content-Type": "application/json" },
72
- body: JSON.stringify({
73
- network: "mainnet",
74
- resource_address: resourceAddress,
75
- }),
76
- },
77
- );
78
-
79
- return manager.divisibility.value.divisibility;
80
- } catch (error) {
81
- console.error(`Failed to fetch Radix asset decimal for ${symbol}:`, error);
82
- return BaseDecimal[Chain.Radix];
83
- }
84
- }
85
-
86
- async function getEVMAssetDecimal({ chain, symbol }: { chain: EVMChain; symbol: string }) {
87
- if (EVMChains.includes(symbol as EVMChain)) return BaseDecimal[symbol as EVMChain];
88
-
89
- const splitSymbol = symbol.split("-");
90
- const address =
91
- splitSymbol.length === 1 ? undefined : splitSymbol[splitSymbol.length - 1]?.toLowerCase();
92
-
93
- const decimal = await (address?.startsWith("0x")
94
- ? getContractDecimals({ chain, to: address })
95
- : BaseDecimal[chain as EVMChain]);
96
-
97
- return decimal;
98
- }
99
-
100
- export function getDecimal({ chain, symbol }: { chain: Chain; symbol: string }) {
101
- return match(chain)
102
- .with(...EVMChains, (chain) => getEVMAssetDecimal({ chain, symbol }))
103
- .with(Chain.Radix, () => getRadixAssetDecimal(symbol))
104
- .otherwise(() => BaseDecimal[chain]);
105
- }
106
-
107
- /**
108
- * @deprecated Use AssetValue.from({ chain }) instead
109
- */
110
- export function getGasAsset({ chain }: { chain: Chain }) {
111
- return AssetValue.from({ chain });
112
- }
113
-
114
- export function isGasAsset({ chain, symbol }: { chain: Chain; symbol: string }) {
115
- return match(chain)
116
- .with(...ethGasChains, () => symbol === "ETH")
117
- .with(Chain.Avalanche, () => symbol === "AVAX")
118
- .with(Chain.Berachain, () => symbol === "BERA")
119
- .with(Chain.BinanceSmartChain, () => symbol === "BNB")
120
- .with(Chain.Gnosis, () => symbol === "XDAU")
121
- .with(Chain.Maya, () => symbol === "CACAO")
122
- .with(Chain.Cosmos, () => symbol === "ATOM")
123
- .with(Chain.THORChain, () => symbol === "RUNE")
124
- .with(Chain.Radix, () => `${chain}.${symbol}` === getCommonAssetInfo(chain).identifier)
125
- .otherwise(() => symbol === chain);
126
- }
127
-
128
- export const getCommonAssetInfo = (assetString: CommonAssetString) => {
129
- const decimal = BaseDecimal[assetString as Chain];
130
-
131
- const commonAssetInfo = match(assetString.toUpperCase())
132
- .with(...ethGasChains, (asset) => ({ identifier: `${asset}.ETH`, decimal }))
133
- .with(Chain.THORChain, (asset) => ({ identifier: `${asset}.RUNE`, decimal }))
134
- .with(Chain.Cosmos, (asset) => ({ identifier: `${asset}.ATOM`, decimal }))
135
- .with(Chain.Maya, (asset) => ({ identifier: `${asset}.CACAO`, decimal: 10 }))
136
- .with(Chain.BinanceSmartChain, (asset) => ({ identifier: `${asset}.BNB`, decimal }))
137
- .with(Chain.Avalanche, (asset) => ({ identifier: `${asset}.AVAX`, decimal }))
138
- .with(Chain.Gnosis, (asset) => ({ identifier: `${asset}.XDAI`, decimal }))
139
- .with(Chain.Berachain, (asset) => ({ identifier: `${asset}.BERA`, decimal }))
140
- .with(
141
- ...UTXOChains,
142
- Chain.Solana,
143
- Chain.Chainflip,
144
- Chain.Kujira,
145
- Chain.Ripple,
146
- Chain.Polkadot,
147
- Chain.Tron,
148
- Chain.Near,
149
- (asset) => ({ identifier: `${asset}.${asset}`, decimal }),
150
- )
151
- .with(Chain.Radix, "XRD.XRD", () => ({ identifier: "XRD.XRD", decimal }))
152
-
153
- .with("KUJI.USK", (asset) => ({ identifier: asset, decimal: 6 }))
154
- .with("ETH.FLIP", () => ({
155
- identifier: "ETH.FLIP-0x826180541412D574cf1336d22c0C0a287822678A",
156
- decimal: BaseDecimal.ETH,
157
- }))
158
- .with("ETH.THOR", () => ({
159
- identifier: "ETH.THOR-0xa5f2211b9b8170f694421f2046281775e8468044",
160
- decimal: BaseDecimal.ETH,
161
- }))
162
- .with("ETH.vTHOR", () => ({
163
- identifier: "ETH.vTHOR-0x815c23eca83261b6ec689b60cc4a58b54bc24d8d",
164
- decimal: BaseDecimal.ETH,
165
- }))
166
- .with("MAYA.CACAO", (identifier) => ({ identifier, decimal: 10 }))
167
- .with("MAYA.MAYA", (identifier) => ({ identifier, decimal: 4 }))
168
- // Just to be sure that we are not missing any chain
169
- .otherwise(() => ({ identifier: assetString, decimal }));
170
-
171
- return commonAssetInfo;
172
- };
173
-
174
- export function getAssetType({ chain, symbol }: { chain: Chain; symbol: string }) {
175
- if (symbol.includes("/")) return "Synth";
176
- if (symbol.includes("~")) return "Trade";
177
-
178
- const isNative = match(chain)
179
- .with(
180
- Chain.Radix,
181
- () => symbol === Chain.Radix || `${chain}.${symbol}` === getCommonAssetInfo(chain).identifier,
182
- )
183
- .with(Chain.Arbitrum, Chain.Optimism, Chain.Base, () => symbol === Chain.Ethereum)
184
- .with(Chain.Cosmos, () => symbol === "ATOM")
185
- .with(Chain.BinanceSmartChain, () => symbol === "BNB")
186
- .with(Chain.Maya, () => symbol === "CACAO")
187
- .with(Chain.THORChain, () => symbol === "RUNE")
188
- .otherwise(() => symbol === chain);
189
-
190
- return isNative ? "Native" : chain;
191
- }
192
-
193
- export const assetFromString = (assetString: string) => {
194
- const [chain, ...symbolArray] = assetString.split(".") as [Chain, ...(string | undefined)[]];
195
- const synth = assetString.includes("/");
196
- const symbol = symbolArray.join(".");
197
- const splitSymbol = symbol?.split("-");
198
- const ticker = splitSymbol?.length
199
- ? splitSymbol.length === 1
200
- ? splitSymbol[0]
201
- : splitSymbol.slice(0, -1).join("-")
202
- : undefined;
203
-
204
- return { chain, symbol, ticker, synth };
205
- };
206
-
207
- export async function findAssetBy(
208
- params:
209
- | { chain: EVMChain | Chain.Radix | Chain.Solana; contract: string }
210
- | { identifier: `${Chain}.${string}` },
211
- ) {
212
- const { tokenLists } = await import("@swapkit/helpers/tokens");
213
-
214
- for (const tokenList of Object.values(tokenLists)) {
215
- for (const { identifier, chain: tokenChain, ...rest } of tokenList.tokens) {
216
- if ("identifier" in params && identifier === params.identifier) {
217
- return identifier as TokenNames;
218
- }
219
-
220
- if (
221
- "address" in rest &&
222
- "chain" in params &&
223
- tokenChain === params.chain &&
224
- rest.address.toLowerCase() === params.contract.toLowerCase()
225
- )
226
- return identifier as TokenNames;
227
- }
228
- }
229
-
230
- return;
231
- }
@@ -1,98 +0,0 @@
1
- import {
2
- Chain,
3
- type DerivationPathArray,
4
- type EVMChain,
5
- EVMChains,
6
- NetworkDerivationPath,
7
- } from "../types";
8
-
9
- type Params = {
10
- chain: Chain;
11
- index: number;
12
- addressIndex?: number;
13
- type?: "legacy" | "ledgerLive" | "nativeSegwitMiddleAccount" | "segwit" | "account";
14
- };
15
-
16
- export function updateDerivationPath(
17
- path: DerivationPathArray,
18
- params: { index: number } | { account: number } | { change: number },
19
- ) {
20
- if ("index" in params) {
21
- const newPath = [...path.slice(0, path.length - 1), params.index];
22
- return newPath as DerivationPathArray;
23
- }
24
-
25
- if ("change" in params) {
26
- const [network, chainId, account, , index] = path;
27
- return [network, chainId, account, params.change, index] as DerivationPathArray;
28
- }
29
-
30
- if ("account" in params) {
31
- const [network, chainId, , change, index] = path;
32
- return [network, chainId, params.account, change, index] as DerivationPathArray;
33
- }
34
-
35
- return path;
36
- }
37
-
38
- export function derivationPathToString([network, chainId, account, change, index]:
39
- | [number, number, number, number?, number?]
40
- | [number, number, number, number, number?]
41
- | DerivationPathArray) {
42
- const shortPath = typeof index !== "number";
43
- const accountPath = typeof change !== "number";
44
-
45
- if (accountPath) {
46
- return `m/${network}'/${chainId}'/${account}'`;
47
- }
48
-
49
- return `m/${network}'/${chainId}'/${account}'/${change}${shortPath ? "" : `/${index}`}`;
50
- }
51
-
52
- // TODO @towan - sort this out and make it more readable
53
- export function getDerivationPathFor({ chain, index, addressIndex = 0, type }: Params) {
54
- if (EVMChains.includes(chain as EVMChain)) {
55
- if (type && ["legacy", "account"].includes(type)) {
56
- return [44, 60, 0, index] as DerivationPathArray;
57
- }
58
-
59
- if (type === "ledgerLive") {
60
- return [44, 60, index, 0, addressIndex] as DerivationPathArray;
61
- }
62
-
63
- return updateDerivationPath(NetworkDerivationPath[chain], { index });
64
- }
65
-
66
- if (chain === Chain.Solana) {
67
- if (type === "account") return [44, 501, 0, index] as DerivationPathArray;
68
- return updateDerivationPath(NetworkDerivationPath[chain], { index });
69
- }
70
-
71
- const chainId = chain === Chain.Litecoin ? 2 : 0;
72
-
73
- switch (type) {
74
- case "nativeSegwitMiddleAccount":
75
- return [84, chainId, index, 0, addressIndex] as DerivationPathArray;
76
- case "segwit":
77
- return [49, chainId, 0, 0, index] as DerivationPathArray;
78
- case "legacy":
79
- return [44, chainId, 0, 0, index] as DerivationPathArray;
80
- default:
81
- return updateDerivationPath(NetworkDerivationPath[chain], { index });
82
- }
83
- }
84
-
85
- export function getWalletFormatFor(path: string) {
86
- const [_, purpose, chainId] = path.split("/").map((p) => Number.parseInt(p, 10));
87
-
88
- if (chainId === 145) "cashaddr";
89
-
90
- switch (purpose) {
91
- case 44:
92
- return "legacy";
93
- case 49:
94
- return "p2sh";
95
- default:
96
- return "bech32";
97
- }
98
- }