@swapkit/toolboxes 1.0.0-beta.9 → 4.0.0-beta.36

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 (132) hide show
  1. package/dist/chunk-4yap1fvd.js +1 -0
  2. package/dist/{chunk-fjfxga2v.js → chunk-5yxc1e69.js} +2 -1
  3. package/dist/{chunk-fjfxga2v.js.map → chunk-5yxc1e69.js.map} +1 -1
  4. package/dist/chunk-6f98phv2.js +5 -0
  5. package/dist/{chunk-0h4xdrwz.js.map → chunk-6f98phv2.js.map} +2 -2
  6. package/dist/{chunk-0f0249b1.js → chunk-9bqegm61.js} +2 -1
  7. package/dist/chunk-fazw0jvt.js +1 -0
  8. package/dist/{chunk-p1kdg37m.js → chunk-s47y8512.js} +3 -2
  9. package/dist/{chunk-p1kdg37m.js.map → chunk-s47y8512.js.map} +1 -1
  10. package/dist/chunk-vtd17cje.js +4 -0
  11. package/dist/chunk-vtd17cje.js.map +10 -0
  12. package/dist/chunk-zcdeg6h9.js +5 -0
  13. package/dist/chunk-zcdeg6h9.js.map +10 -0
  14. package/dist/src/cosmos/index.cjs +4 -0
  15. package/dist/src/cosmos/index.cjs.map +16 -0
  16. package/dist/src/cosmos/index.js +4 -0
  17. package/dist/src/cosmos/index.js.map +16 -0
  18. package/dist/src/evm/index.cjs +4 -0
  19. package/dist/src/evm/index.cjs.map +18 -0
  20. package/dist/src/evm/index.js +4 -0
  21. package/dist/src/evm/index.js.map +18 -0
  22. package/dist/src/index.cjs +4 -0
  23. package/dist/src/index.cjs.map +10 -0
  24. package/dist/src/index.js +4 -0
  25. package/dist/src/index.js.map +10 -0
  26. package/dist/src/near/index.cjs +4 -0
  27. package/dist/src/near/index.cjs.map +13 -0
  28. package/dist/src/near/index.js +4 -0
  29. package/dist/src/near/index.js.map +13 -0
  30. package/dist/{radix → src/radix}/index.cjs +3 -2
  31. package/dist/src/radix/index.cjs.map +10 -0
  32. package/dist/src/radix/index.js +4 -0
  33. package/dist/src/radix/index.js.map +10 -0
  34. package/dist/src/ripple/index.cjs +4 -0
  35. package/dist/src/ripple/index.cjs.map +10 -0
  36. package/dist/src/ripple/index.js +4 -0
  37. package/dist/src/ripple/index.js.map +10 -0
  38. package/dist/src/solana/index.cjs +4 -0
  39. package/dist/src/solana/index.cjs.map +10 -0
  40. package/dist/src/solana/index.js +4 -0
  41. package/dist/src/solana/index.js.map +10 -0
  42. package/dist/src/substrate/index.cjs +4 -0
  43. package/dist/src/substrate/index.cjs.map +12 -0
  44. package/dist/src/substrate/index.js +4 -0
  45. package/dist/src/substrate/index.js.map +12 -0
  46. package/dist/src/tron/index.cjs +4 -0
  47. package/dist/src/tron/index.cjs.map +11 -0
  48. package/dist/src/tron/index.js +4 -0
  49. package/dist/src/tron/index.js.map +11 -0
  50. package/dist/src/utxo/index.cjs +6 -0
  51. package/dist/src/utxo/index.cjs.map +17 -0
  52. package/dist/src/utxo/index.js +6 -0
  53. package/dist/src/utxo/index.js.map +17 -0
  54. package/package.json +92 -43
  55. package/src/cosmos/thorchainUtils/addressFormat.ts +4 -1
  56. package/src/cosmos/thorchainUtils/messages.ts +2 -2
  57. package/src/cosmos/thorchainUtils/registry.ts +3 -3
  58. package/src/cosmos/toolbox/cosmos.ts +35 -16
  59. package/src/cosmos/toolbox/index.ts +2 -2
  60. package/src/cosmos/toolbox/thorchain.ts +11 -9
  61. package/src/cosmos/util.ts +87 -7
  62. package/src/evm/__tests__/address-validation.test.ts +86 -0
  63. package/src/evm/__tests__/ethereum.test.ts +1 -1
  64. package/src/evm/helpers.ts +4 -3
  65. package/src/evm/toolbox/baseEVMToolbox.ts +34 -24
  66. package/src/evm/toolbox/index.ts +2 -2
  67. package/src/evm/toolbox/op.ts +21 -7
  68. package/src/index.ts +118 -100
  69. package/src/near/__tests__/core.test.ts +80 -0
  70. package/src/near/helpers/contractFactory.ts +22 -0
  71. package/src/near/helpers/core.ts +89 -0
  72. package/src/near/helpers/gasEstimation.ts +110 -0
  73. package/src/near/helpers/index.ts +5 -0
  74. package/src/near/helpers/nep141.ts +110 -0
  75. package/src/near/index.ts +24 -0
  76. package/src/near/toolbox.ts +498 -0
  77. package/src/near/types/contract.ts +48 -0
  78. package/src/near/types/nep141.ts +66 -0
  79. package/src/near/types.ts +57 -0
  80. package/src/radix/index.ts +8 -2
  81. package/src/ripple/index.ts +14 -21
  82. package/src/solana/toolbox.ts +73 -2
  83. package/src/substrate/balance.ts +92 -0
  84. package/src/substrate/substrate.ts +7 -5
  85. package/src/tron/__tests__/toolbox.test.ts +147 -0
  86. package/src/tron/helpers/trc20.abi.ts +40 -0
  87. package/src/tron/index.ts +16 -0
  88. package/src/tron/toolbox.ts +336 -0
  89. package/src/tron/types.ts +31 -0
  90. package/src/utxo/__tests__/zcash-integration.test.ts +114 -0
  91. package/src/utxo/helpers/api.ts +66 -16
  92. package/src/utxo/helpers/bchaddrjs.ts +8 -8
  93. package/src/utxo/helpers/coinselect.ts +4 -2
  94. package/src/utxo/helpers/txSize.ts +4 -3
  95. package/src/utxo/index.ts +1 -0
  96. package/src/utxo/toolbox/bitcoinCash.ts +21 -13
  97. package/src/utxo/toolbox/index.ts +16 -4
  98. package/src/utxo/toolbox/utxo.ts +42 -27
  99. package/src/utxo/toolbox/zcash.ts +208 -0
  100. package/dist/chunk-0h4xdrwz.js +0 -4
  101. package/dist/cosmos/index.cjs +0 -3
  102. package/dist/cosmos/index.cjs.map +0 -16
  103. package/dist/cosmos/index.js +0 -3
  104. package/dist/cosmos/index.js.map +0 -16
  105. package/dist/evm/index.cjs +0 -3
  106. package/dist/evm/index.cjs.map +0 -18
  107. package/dist/evm/index.js +0 -3
  108. package/dist/evm/index.js.map +0 -18
  109. package/dist/index.cjs +0 -3
  110. package/dist/index.cjs.map +0 -10
  111. package/dist/index.js +0 -3
  112. package/dist/index.js.map +0 -10
  113. package/dist/radix/index.cjs.map +0 -10
  114. package/dist/radix/index.js +0 -3
  115. package/dist/radix/index.js.map +0 -10
  116. package/dist/ripple/index.cjs +0 -3
  117. package/dist/ripple/index.cjs.map +0 -10
  118. package/dist/ripple/index.js +0 -3
  119. package/dist/ripple/index.js.map +0 -10
  120. package/dist/solana/index.cjs +0 -3
  121. package/dist/solana/index.cjs.map +0 -10
  122. package/dist/solana/index.js +0 -3
  123. package/dist/solana/index.js.map +0 -10
  124. package/dist/substrate/index.cjs +0 -3
  125. package/dist/substrate/index.cjs.map +0 -11
  126. package/dist/substrate/index.js +0 -3
  127. package/dist/substrate/index.js.map +0 -11
  128. package/dist/utxo/index.cjs +0 -3
  129. package/dist/utxo/index.cjs.map +0 -16
  130. package/dist/utxo/index.js +0 -3
  131. package/dist/utxo/index.js.map +0 -16
  132. /package/dist/{chunk-0f0249b1.js.map → chunk-9bqegm61.js.map} +0 -0
package/package.json CHANGED
@@ -1,29 +1,68 @@
1
1
  {
2
- "description": "SwapKit - Toolboxes",
3
- "files": [
4
- "src/",
5
- "dist/"
6
- ],
7
2
  "dependencies": {
3
+ "@bitcoinerlab/secp256k1": "^1.2.0",
4
+ "@cosmjs/amino": "^0.33.0",
5
+ "@cosmjs/crypto": "^0.33.0",
6
+ "@cosmjs/proto-signing": "^0.33.0",
7
+ "@cosmjs/stargate": "^0.33.0",
8
+ "@polkadot/api": "^15.9.0",
9
+ "@polkadot/keyring": "^13.5.0",
10
+ "@polkadot/util": "^13.5.0",
11
+ "@polkadot/util-crypto": "^13.5.0",
12
+ "@psf/bitcoincashjs-lib": "^4.0.3",
13
+ "@radixdlt/babylon-gateway-api-sdk": "^1.10.0",
14
+ "@radixdlt/radix-dapp-toolkit": "^2.2.0",
15
+ "@scure/base": "^1.2.0",
16
+ "@scure/bip32": "^1.7.0",
17
+ "@scure/bip39": "^1.6.0",
18
+ "@solana/spl-memo": "^0.2.5",
19
+ "@solana/spl-token": "^0.4.13",
20
+ "@solana/web3.js": "^1.98.0",
21
+ "@swapkit/helpers": "^4.0.0-beta.24",
22
+ "base64-js": "^1.5.1",
23
+ "bitcoinjs-lib": "^6.1.0",
24
+ "bs58check": "^4.0.0",
25
+ "cashaddrjs": "^0.4.4",
26
+ "coininfo": "^5.2.1",
27
+ "cosmjs-types": "^0.9.0",
28
+ "ecpair": "^2.1.0",
29
+ "ethers": "^6.0.0",
30
+ "micro-key-producer": "^0.7.6",
31
+ "near-api-js": "^6.1.0",
32
+ "near-sdk-js": "^2.0.0",
33
+ "near-seed-phrase": "^0.2.1",
34
+ "protobufjs": "^7.5.0",
35
+ "tronweb": "^6.0.0",
36
+ "ts-pattern": "^5.0.0",
37
+ "xrpl": "^4.3.0"
38
+ },
39
+ "description": "SwapKit - Toolboxes",
40
+ "devDependencies": {
8
41
  "@bitcoinerlab/secp256k1": "1.2.0",
9
42
  "@cosmjs/amino": "0.33.1",
10
43
  "@cosmjs/crypto": "0.33.1",
11
44
  "@cosmjs/proto-signing": "0.33.1",
12
45
  "@cosmjs/stargate": "0.33.1",
46
+ "@nomicfoundation/hardhat-ethers": "3.0.9",
47
+ "@nomicfoundation/hardhat-toolbox": "5.0.0",
13
48
  "@polkadot/api": "15.9.2",
14
- "@polkadot/keyring": "13.4.4",
15
- "@polkadot/util": "13.4.4",
16
- "@polkadot/util-crypto": "13.4.4",
49
+ "@polkadot/keyring": "13.5.3",
50
+ "@polkadot/types": "15.9.2",
51
+ "@polkadot/util": "13.5.3",
52
+ "@polkadot/util-crypto": "13.5.3",
17
53
  "@psf/bitcoincashjs-lib": "4.0.3",
18
54
  "@radixdlt/babylon-gateway-api-sdk": "1.10.1",
19
55
  "@radixdlt/radix-dapp-toolkit": "2.2.1",
20
- "@scure/base": "1.2.4",
21
- "@scure/bip32": "1.6.2",
22
- "@scure/bip39": "1.5.4",
56
+ "@scure/base": "1.2.6",
57
+ "@scure/bip32": "1.7.0",
58
+ "@scure/bip39": "1.6.0",
23
59
  "@solana/spl-memo": "0.2.5",
24
60
  "@solana/spl-token": "0.4.13",
25
61
  "@solana/web3.js": "1.98.2",
26
- "@swapkit/helpers": "3.0.0-beta.8",
62
+ "@swapkit/helpers": "4.0.0-beta.24",
63
+ "@types/bn.js": "5.2.0",
64
+ "@types/crypto-js": "4.2.2",
65
+ "@types/elliptic": "6.4.18",
27
66
  "base64-js": "1.5.1",
28
67
  "bitcoinjs-lib": "6.1.7",
29
68
  "bs58check": "4.0.0",
@@ -31,63 +70,73 @@
31
70
  "coininfo": "5.2.1",
32
71
  "cosmjs-types": "0.9.0",
33
72
  "ecpair": "2.1.0",
34
- "ethers": "6.13.5",
35
- "micro-key-producer": "0.7.5",
36
- "protobufjs": "7.4.0",
37
- "ts-pattern": "5.7.0",
38
- "xrpl": "4.2.0"
39
- },
40
- "devDependencies": {
41
- "@nomicfoundation/hardhat-ethers": "3.0.8",
42
- "@nomicfoundation/hardhat-toolbox": "5.0.0",
43
- "@polkadot/types": "15.9.2",
44
- "@types/bn.js": "5.1.6",
45
- "@types/crypto-js": "4.2.2",
46
- "@types/elliptic": "6.4.18",
47
- "hardhat": "2.23.0"
73
+ "ethers": "6.14.3",
74
+ "hardhat": "2.25.0",
75
+ "micro-key-producer": "0.7.6",
76
+ "near-api-js": "6.1.0",
77
+ "near-sdk-js": "2.0.0",
78
+ "near-seed-phrase": "0.2.1",
79
+ "protobufjs": "7.5.3",
80
+ "tronweb": "6.0.3",
81
+ "ts-pattern": "5.7.1",
82
+ "xrpl": "4.3.0"
48
83
  },
49
84
  "exports": {
50
85
  ".": {
51
- "default": "./dist/index.js",
52
- "require": "./dist/index.cjs",
86
+ "default": "./dist/src/index.js",
87
+ "require": "./dist/src/index.cjs",
53
88
  "types": "./src/index.ts"
54
89
  },
55
90
  "./cosmos": {
56
- "default": "./dist/cosmos/index.js",
57
- "require": "./dist/cosmos/index.cjs",
91
+ "default": "./dist/src/cosmos/index.js",
92
+ "require": "./dist/src/cosmos/index.cjs",
58
93
  "types": "./src/cosmos/index.ts"
59
94
  },
60
95
  "./evm": {
61
- "default": "./dist/evm/index.js",
62
- "require": "./dist/evm/index.cjs",
96
+ "default": "./dist/src/evm/index.js",
97
+ "require": "./dist/src/evm/index.cjs",
63
98
  "types": "./src/evm/index.ts"
64
99
  },
100
+ "./near": {
101
+ "default": "./dist/src/near/index.js",
102
+ "require": "./dist/src/near/index.cjs",
103
+ "types": "./src/near/index.ts"
104
+ },
65
105
  "./radix": {
66
- "default": "./dist/radix/index.js",
67
- "require": "./dist/radix/index.cjs",
106
+ "default": "./dist/src/radix/index.js",
107
+ "require": "./dist/src/radix/index.cjs",
68
108
  "types": "./src/radix/index.ts"
69
109
  },
70
110
  "./ripple": {
71
- "default": "./dist/ripple/index.js",
72
- "require": "./dist/ripple/index.cjs",
111
+ "default": "./dist/src/ripple/index.js",
112
+ "require": "./dist/src/ripple/index.cjs",
73
113
  "types": "./src/ripple/index.ts"
74
114
  },
75
115
  "./solana": {
76
- "default": "./dist/solana/index.js",
77
- "require": "./dist/solana/index.cjs",
116
+ "default": "./dist/src/solana/index.js",
117
+ "require": "./dist/src/solana/index.cjs",
78
118
  "types": "./src/solana/index.ts"
79
119
  },
80
120
  "./substrate": {
81
- "default": "./dist/substrate/index.js",
82
- "require": "./dist/substrate/index.cjs",
121
+ "default": "./dist/src/substrate/index.js",
122
+ "require": "./dist/src/substrate/index.cjs",
83
123
  "types": "./src/substrate/index.ts"
84
124
  },
125
+ "./tron": {
126
+ "default": "./dist/src/tron/index.js",
127
+ "require": "./dist/src/tron/index.cjs",
128
+ "types": "./src/tron/index.ts"
129
+ },
85
130
  "./utxo": {
86
- "default": "./dist/utxo/index.js",
87
- "require": "./dist/utxo/index.cjs",
131
+ "default": "./dist/src/utxo/index.js",
132
+ "require": "./dist/src/utxo/index.cjs",
88
133
  "types": "./src/utxo/index.ts"
89
134
  }
90
135
  },
136
+ "files": [
137
+ "src/",
138
+ "dist/"
139
+ ],
91
140
  "homepage": "https://github.com/thorswap/SwapKit",
92
141
  "license": "Apache-2.0",
93
142
  "name": "@swapkit/toolboxes",
@@ -105,5 +154,5 @@
105
154
  "type-check:go": "tsgo"
106
155
  },
107
156
  "type": "module",
108
- "version": "1.0.0-beta.9"
157
+ "version": "4.0.0-beta.36"
109
158
  }
@@ -1,4 +1,5 @@
1
1
  import { base64, bech32 } from "@scure/base";
2
+ import { SwapKitError } from "@swapkit/helpers";
2
3
  import { fromByteArray, toByteArray } from "base64-js";
3
4
 
4
5
  export function bech32ToBase64(address: string) {
@@ -17,7 +18,9 @@ export function toBase64(data: Uint8Array) {
17
18
 
18
19
  export function fromBase64(base64String: string) {
19
20
  if (!base64String.match(/^[a-zA-Z0-9+/]*={0,2}$/)) {
20
- throw new Error("Invalid base64 string format");
21
+ throw new SwapKitError("toolbox_cosmos_invalid_params", {
22
+ error: "Invalid base64 string format",
23
+ });
21
24
  }
22
25
  return toByteArray(base64String);
23
26
  }
@@ -1,5 +1,5 @@
1
1
  import type { TxBodyEncodeObject } from "@cosmjs/proto-signing";
2
- import { AssetValue, Chain, ChainToChainId } from "@swapkit/helpers";
2
+ import { AssetValue, Chain, ChainToChainId, SwapKitError } from "@swapkit/helpers";
3
3
 
4
4
  import {
5
5
  createStargateClient,
@@ -104,7 +104,7 @@ const getAccount = async ({ rpcUrl, sender }: { sender: string; rpcUrl: string }
104
104
  const account = await client.getAccount(sender);
105
105
 
106
106
  if (!account) {
107
- throw new Error("Account does not exist");
107
+ throw new SwapKitError("toolbox_cosmos_account_not_found", { sender });
108
108
  }
109
109
 
110
110
  return account;
@@ -3,8 +3,8 @@ import { base64ToBech32, bech32ToBase64 } from "./addressFormat";
3
3
 
4
4
  export async function createDefaultRegistry() {
5
5
  const { $root } = await import("./types/MsgCompiled");
6
- const { Registry } = await import("@cosmjs/proto-signing");
7
- const { defaultRegistryTypes } = await import("@cosmjs/stargate");
6
+ const { Registry } = (await import("@cosmjs/proto-signing")).default;
7
+ const { defaultRegistryTypes } = (await import("@cosmjs/stargate")).default;
8
8
 
9
9
  return new Registry([
10
10
  ...defaultRegistryTypes,
@@ -14,7 +14,7 @@ export async function createDefaultRegistry() {
14
14
  }
15
15
 
16
16
  export async function createDefaultAminoTypes(chain: Chain.THORChain | Chain.Maya) {
17
- const { AminoTypes } = await import("@cosmjs/stargate");
17
+ const { AminoTypes } = (await import("@cosmjs/stargate")).default;
18
18
  const aminoTypePrefix = chain === Chain.THORChain ? "thorchain" : "mayachain";
19
19
 
20
20
  return new AminoTypes({
@@ -17,17 +17,18 @@ import {
17
17
  SKConfig,
18
18
  SwapKitError,
19
19
  SwapKitNumber,
20
+ applyFeeMultiplier,
20
21
  derivationPathToString,
21
22
  updateDerivationPath,
22
23
  } from "@swapkit/helpers";
23
24
  import { SwapKitApi } from "@swapkit/helpers/api";
24
25
  import { P, match } from "ts-pattern";
25
- import { getBalance } from "../../utils";
26
26
  import type { CosmosToolboxParams } from "../types";
27
27
  import {
28
28
  cosmosCreateTransaction,
29
29
  createSigningStargateClient,
30
30
  createStargateClient,
31
+ getAssetFromDenom,
31
32
  getDenomWithChain,
32
33
  getMsgSendDenom,
33
34
  } from "../util";
@@ -38,8 +39,7 @@ export async function fetchFeeRateFromSwapKit(chainId: ChainId, safeDefault: num
38
39
  const responseGasRate = response.find((gas) => gas.chainId === chainId)?.value;
39
40
 
40
41
  return responseGasRate ? Number.parseFloat(responseGasRate) : safeDefault;
41
- } catch (e) {
42
- console.error(e);
42
+ } catch (_e) {
43
43
  return safeDefault;
44
44
  }
45
45
  }
@@ -52,8 +52,8 @@ export async function getSignerFromPhrase({
52
52
  | { chain: Chain; index?: number }
53
53
  | { derivationPath: string }
54
54
  )) {
55
- const { DirectSecp256k1HdWallet } = await import("@cosmjs/proto-signing");
56
- const { stringToPath } = await import("@cosmjs/crypto");
55
+ const { DirectSecp256k1HdWallet } = (await import("@cosmjs/proto-signing")).default;
56
+ const { stringToPath } = (await import("@cosmjs/crypto")).default;
57
57
 
58
58
  const derivationPath =
59
59
  "derivationPath" in derivationParams
@@ -73,7 +73,7 @@ export async function getSignerFromPrivateKey({
73
73
  privateKey: Uint8Array;
74
74
  prefix: string;
75
75
  }) {
76
- const { DirectSecp256k1Wallet } = await import("@cosmjs/proto-signing");
76
+ const { DirectSecp256k1Wallet } = (await import("@cosmjs/proto-signing")).default;
77
77
 
78
78
  return DirectSecp256k1Wallet.fromKey(privateKey, prefix);
79
79
  }
@@ -97,7 +97,7 @@ export function verifySignature(getAccount: (address: string) => Promise<Account
97
97
  }) {
98
98
  const account = await getAccount(address);
99
99
  if (!account?.pubkey) throw new SwapKitError("toolbox_cosmos_verify_signature_no_pubkey");
100
- const { Secp256k1Signature, Secp256k1 } = await import("@cosmjs/crypto");
100
+ const { Secp256k1Signature, Secp256k1 } = (await import("@cosmjs/crypto")).default;
101
101
 
102
102
  const secpSignature = Secp256k1Signature.fromFixedLength(base64.decode(signature));
103
103
  return Secp256k1.verifySignature(secpSignature, base64.decode(message), account.pubkey.value);
@@ -185,7 +185,21 @@ export async function createCosmosToolbox({ chain, ...toolboxParams }: CosmosToo
185
185
  transfer,
186
186
  getAddress,
187
187
  getAccount,
188
- getBalance: getBalance(chain),
188
+ getBalance: async (address: string, _potentialScamFilter?: boolean) => {
189
+ const denomBalances = await cosmosBalanceDenomsGetter(rpcUrl)(address);
190
+ return await Promise.all(
191
+ denomBalances
192
+ .filter(({ denom }) => denom && !denom.includes("IBC/"))
193
+ .map(({ denom, amount }) => {
194
+ const fullDenom =
195
+ [Chain.THORChain, Chain.Maya].includes(chain) &&
196
+ (denom.includes("/") || denom.includes("˜"))
197
+ ? `${chain}.${denom}`
198
+ : denom;
199
+ return getAssetFromDenom(fullDenom, amount);
200
+ }),
201
+ );
202
+ },
189
203
  getSignerFromPhrase: async ({
190
204
  phrase,
191
205
  derivationPath,
@@ -197,7 +211,7 @@ export async function createCosmosToolbox({ chain, ...toolboxParams }: CosmosToo
197
211
  index,
198
212
  }),
199
213
  getSignerFromPrivateKey: async (privateKey: Uint8Array) => {
200
- const { DirectSecp256k1Wallet } = await import("@cosmjs/proto-signing");
214
+ const { DirectSecp256k1Wallet } = (await import("@cosmjs/proto-signing")).default;
201
215
  return DirectSecp256k1Wallet.fromKey(privateKey, chainPrefix);
202
216
  },
203
217
  createPrivateKeyFromPhrase: createPrivateKeyFromPhrase(derivationPath),
@@ -217,8 +231,7 @@ export async function getFeeRateFromThorswap(chainId: ChainId, safeDefault: numb
217
231
  const responseGasRate = response.find((gas) => gas.chainId === chainId)?.value;
218
232
 
219
233
  return responseGasRate ? Number.parseFloat(responseGasRate) : safeDefault;
220
- } catch (e) {
221
- console.error(e);
234
+ } catch (_e) {
222
235
  return safeDefault;
223
236
  }
224
237
  }
@@ -262,8 +275,14 @@ async function getFees(chain: Chain, safeDefault: number) {
262
275
  const baseFee = await fetchFeeRateFromSwapKit(ChainToChainId[chain], safeDefault);
263
276
  return {
264
277
  average: SwapKitNumber.fromBigInt(BigInt(baseFee), BaseDecimal[chain]),
265
- fast: SwapKitNumber.fromBigInt(BigInt(Math.floor(baseFee * 1.5)), BaseDecimal[chain]),
266
- fastest: SwapKitNumber.fromBigInt(BigInt(Math.floor(baseFee * 2)), BaseDecimal[chain]),
278
+ fast: SwapKitNumber.fromBigInt(
279
+ BigInt(applyFeeMultiplier(baseFee, FeeOption.Fast, true)),
280
+ BaseDecimal[chain],
281
+ ),
282
+ fastest: SwapKitNumber.fromBigInt(
283
+ BigInt(applyFeeMultiplier(baseFee, FeeOption.Fastest, true)),
284
+ BaseDecimal[chain],
285
+ ),
267
286
  } as { [key in FeeOption]: SwapKitNumber };
268
287
  }
269
288
 
@@ -316,9 +335,9 @@ function cosmosBalanceDenomsGetter(rpcUrl: string) {
316
335
 
317
336
  function createPrivateKeyFromPhrase(derivationPath: string) {
318
337
  return async function createPrivateKeyFromPhrase(phrase: string) {
319
- const { Bip39, EnglishMnemonic, Slip10, Slip10Curve, stringToPath } = await import(
320
- "@cosmjs/crypto"
321
- );
338
+ const { Bip39, EnglishMnemonic, Slip10, Slip10Curve, stringToPath } = (
339
+ await import("@cosmjs/crypto")
340
+ ).default;
322
341
 
323
342
  const mnemonicChecked = new EnglishMnemonic(phrase);
324
343
  const seed = await Bip39.mnemonicToSeed(mnemonicChecked);
@@ -1,4 +1,4 @@
1
- import { Chain, type CosmosChain } from "@swapkit/helpers";
1
+ import { Chain, type CosmosChain, SwapKitError } from "@swapkit/helpers";
2
2
 
3
3
  import type { CosmosToolboxParams } from "../types";
4
4
  import { createCosmosToolbox } from "./cosmos";
@@ -25,7 +25,7 @@ export const getCosmosToolbox = <T extends CosmosChain>(
25
25
  return createThorchainToolbox({ chain, ...params }) as CosmosToolboxes[T];
26
26
 
27
27
  default:
28
- throw new Error(`Chain ${chain} is not supported`);
28
+ throw new SwapKitError("toolbox_cosmos_not_supported", { chain });
29
29
  }
30
30
  };
31
31
 
@@ -9,6 +9,7 @@ import {
9
9
  NetworkDerivationPath,
10
10
  RequestClient,
11
11
  SKConfig,
12
+ SwapKitError,
12
13
  SwapKitNumber,
13
14
  derivationPathToString,
14
15
  updateDerivationPath,
@@ -43,8 +44,8 @@ function secp256k1HdWalletFromMnemonic({
43
44
  derivationPath?: string;
44
45
  }) {
45
46
  return async function secp256k1HdWalletFromMnemonic(mnemonic: string, index = 0) {
46
- const { Secp256k1HdWallet } = await import("@cosmjs/amino");
47
- const { stringToPath } = await import("@cosmjs/crypto");
47
+ const { Secp256k1HdWallet } = (await import("@cosmjs/amino")).default;
48
+ const { stringToPath } = (await import("@cosmjs/crypto")).default;
48
49
 
49
50
  return Secp256k1HdWallet.fromMnemonic(mnemonic, {
50
51
  hdPaths: [stringToPath(`${derivationPath}/${index}`)],
@@ -114,8 +115,8 @@ function broadcastMultisigTx({
114
115
  threshold: number,
115
116
  bodyBytes: Uint8Array,
116
117
  ) {
117
- const { encodeSecp256k1Pubkey, pubkeyToAddress } = await import("@cosmjs/amino");
118
- const { makeMultisignedTxBytes } = await import("@cosmjs/stargate");
118
+ const { encodeSecp256k1Pubkey, pubkeyToAddress } = (await import("@cosmjs/amino")).default;
119
+ const { makeMultisignedTxBytes } = (await import("@cosmjs/stargate")).default;
119
120
 
120
121
  const { sequence, fee } = JSON.parse(tx);
121
122
  const multisigPubkey = await createMultisig(membersPubKeys, threshold);
@@ -142,7 +143,8 @@ function broadcastMultisigTx({
142
143
  }
143
144
 
144
145
  async function createMultisig(pubKeys: string[], threshold: number, noSortPubKeys = true) {
145
- const { createMultisigThresholdPubkey, encodeSecp256k1Pubkey } = await import("@cosmjs/amino");
146
+ const { createMultisigThresholdPubkey, encodeSecp256k1Pubkey } = (await import("@cosmjs/amino"))
147
+ .default;
146
148
  return createMultisigThresholdPubkey(
147
149
  pubKeys.map((pubKey) => encodeSecp256k1Pubkey(base64.decode(pubKey))),
148
150
  threshold,
@@ -161,7 +163,7 @@ async function signWithPrivateKey({
161
163
  privateKey: Uint8Array;
162
164
  message: string;
163
165
  }) {
164
- const { Secp256k1 } = await import("@cosmjs/crypto");
166
+ const { Secp256k1 } = (await import("@cosmjs/crypto")).default;
165
167
 
166
168
  const signature = await Secp256k1.createSignature(base64.decode(message), privateKey);
167
169
  return base64.encode(Buffer.concat([signature.r(32), signature.s(32)]));
@@ -209,7 +211,7 @@ export async function createThorchainToolbox({
209
211
  } = await RequestClient.get<ThorchainConstantsResponse>(constantsUrl);
210
212
 
211
213
  if (!nativeFee || Number.isNaN(nativeFee) || nativeFee < 0) {
212
- throw new Error(`Invalid nativeFee: ${nativeFee.toString()}`);
214
+ throw new SwapKitError("toolbox_cosmos_invalid_fee", { nativeFee: nativeFee.toString() });
213
215
  }
214
216
 
215
217
  fee = new SwapKitNumber(nativeFee);
@@ -230,7 +232,7 @@ export async function createThorchainToolbox({
230
232
  }: Omit<GenericTransferParams, "recipient"> & { recipient?: string }) {
231
233
  const { TxRaw } = await import("cosmjs-types/cosmos/tx/v1beta1/tx");
232
234
  const sender = (await signer?.getAccounts())?.[0]?.address;
233
- if (!(sender && signer)) throw new Error("Signer not defined");
235
+ if (!(sender && signer)) throw new SwapKitError("toolbox_cosmos_no_signer");
234
236
 
235
237
  const isAminoSigner = "signAmino" in signer;
236
238
  const registry = await createDefaultRegistry();
@@ -301,7 +303,7 @@ export async function createThorchainToolbox({
301
303
  signWithPrivateKey,
302
304
  transfer,
303
305
  pubkeyToAddress: async (pubkey: Pubkey) => {
304
- const { pubkeyToAddress } = await import("@cosmjs/amino");
306
+ const { pubkeyToAddress } = (await import("@cosmjs/amino")).default;
305
307
  return pubkeyToAddress(pubkey, chainPrefix);
306
308
  },
307
309
  };
@@ -1,6 +1,14 @@
1
1
  import type { OfflineSigner } from "@cosmjs/proto-signing";
2
2
  import type { SigningStargateClientOptions } from "@cosmjs/stargate";
3
- import { AssetValue, Chain, ChainId, type CosmosChain, SKConfig } from "@swapkit/helpers";
3
+ import {
4
+ AssetValue,
5
+ BaseDecimal,
6
+ Chain,
7
+ ChainId,
8
+ type CosmosChain,
9
+ SKConfig,
10
+ SwapKitError,
11
+ } from "@swapkit/helpers";
4
12
 
5
13
  import type { CosmosCreateTransactionParams } from "./thorchainUtils";
6
14
 
@@ -62,7 +70,9 @@ export const getDenomWithChain = ({ symbol, chain }: AssetValue) => {
62
70
  }
63
71
  if (chain === Chain.THORChain) {
64
72
  return (
65
- symbol.toUpperCase() !== "RUNE" ? symbol : `${Chain.THORChain}.${symbol}`
73
+ ["RUNE", "TCY", "RUJI"].includes(symbol.toUpperCase())
74
+ ? `${Chain.THORChain}.${symbol}`
75
+ : symbol
66
76
  ).toUpperCase();
67
77
  }
68
78
  return getMsgSendDenom(symbol, false);
@@ -71,7 +81,15 @@ export const getDenomWithChain = ({ symbol, chain }: AssetValue) => {
71
81
  export async function createStargateClient(url: string) {
72
82
  const { StargateClient } = await import("@cosmjs/stargate");
73
83
 
74
- return StargateClient.connect(url);
84
+ const defaultRequestHeaders =
85
+ typeof window !== "undefined"
86
+ ? ({} as Record<string, string>)
87
+ : { referrer: "https://sk.thorswap.net", referer: "https://sk.thorswap.net" };
88
+
89
+ return StargateClient.connect({
90
+ url,
91
+ headers: defaultRequestHeaders,
92
+ });
75
93
  }
76
94
 
77
95
  export async function createSigningStargateClient(
@@ -79,7 +97,7 @@ export async function createSigningStargateClient(
79
97
  signer: any,
80
98
  optionsOrBaseGas: string | SigningStargateClientOptions = {},
81
99
  ) {
82
- const { SigningStargateClient, GasPrice } = await import("@cosmjs/stargate");
100
+ const { SigningStargateClient, GasPrice } = (await import("@cosmjs/stargate")).default;
83
101
  const gasPrice = typeof optionsOrBaseGas === "string" ? optionsOrBaseGas : "0.0003uatom";
84
102
  const options = typeof optionsOrBaseGas === "string" ? {} : optionsOrBaseGas;
85
103
 
@@ -93,7 +111,7 @@ export async function createOfflineStargateClient(
93
111
  wallet: OfflineSigner,
94
112
  registry?: SigningStargateClientOptions,
95
113
  ) {
96
- const { SigningStargateClient } = await import("@cosmjs/stargate");
114
+ const { SigningStargateClient } = (await import("@cosmjs/stargate")).default;
97
115
 
98
116
  return SigningStargateClient.offline(wallet, registry);
99
117
  }
@@ -126,7 +144,7 @@ const getTransferMsgTypeByChain = (chain: CosmosChain) => {
126
144
  case Chain.Kujira:
127
145
  return "/cosmos.bank.v1beta1.MsgSend";
128
146
  default:
129
- throw new Error("Unsupported chain");
147
+ throw new SwapKitError("toolbox_cosmos_not_supported", { chain });
130
148
  }
131
149
  };
132
150
 
@@ -149,7 +167,7 @@ export const cosmosCreateTransaction = async ({
149
167
  const accountOnChain = await client.getAccount(sender);
150
168
 
151
169
  if (!accountOnChain) {
152
- throw new Error("Account does not exist");
170
+ throw new SwapKitError("toolbox_cosmos_account_not_found", { sender });
153
171
  }
154
172
 
155
173
  const gasAsset = AssetValue.from({ chain });
@@ -178,3 +196,65 @@ export const cosmosCreateTransaction = async ({
178
196
  msgs: [{ typeUrl: getTransferMsgTypeByChain(chain as CosmosChain), value: msgSend }],
179
197
  };
180
198
  };
199
+
200
+ // Map of known denoms to their asset configurations
201
+ const DENOM_MAP = {
202
+ // THORChain denoms
203
+ rune: { chain: Chain.THORChain, decimals: BaseDecimal[Chain.THORChain] },
204
+ tcy: { asset: "THOR.TCY", decimals: BaseDecimal[Chain.THORChain] },
205
+ "x/kuji": { asset: "THOR.KUJI", decimals: BaseDecimal[Chain.THORChain] },
206
+
207
+ // Cosmos denoms
208
+ uatom: { chain: Chain.Cosmos, decimals: BaseDecimal[Chain.Cosmos] },
209
+ atom: { chain: Chain.Cosmos, decimals: BaseDecimal[Chain.Cosmos] },
210
+
211
+ // Maya denoms
212
+ cacao: { chain: Chain.Maya, decimals: 10 }, // Maya uses 10 decimals for CACAO
213
+ maya: { asset: `${Chain.Maya}.${Chain.Maya}`, decimals: 4 }, // MAYA token uses 4 decimals
214
+
215
+ // Kujira denoms
216
+ ukuji: { chain: Chain.Kujira, decimals: BaseDecimal[Chain.Kujira] },
217
+ kuji: { chain: Chain.Kujira, decimals: BaseDecimal[Chain.Kujira] },
218
+
219
+ // USK on Kujira (lowercase version of the factory denom)
220
+ [USK_KUJIRA_FACTORY_DENOM.toLowerCase()]: {
221
+ asset: `${Chain.Kujira}.USK`,
222
+ decimals: BaseDecimal[Chain.Kujira],
223
+ },
224
+ };
225
+
226
+ /**
227
+ * Converts a Cosmos denom and amount to an AssetValue with proper decimal handling
228
+ * @param denom - The denomination string
229
+ * @param amount - The amount in base units as a string
230
+ * @returns AssetValue with the correct decimal conversion
231
+ */
232
+ export const getAssetFromDenom = (denom: string, amount: string) => {
233
+ const config = DENOM_MAP[denom.toLowerCase()];
234
+
235
+ if (!config) {
236
+ // For unknown denoms, default to 8 decimals (common for many Cosmos chains)
237
+ // This preserves the original behavior while using fromBaseDecimal
238
+ return AssetValue.from({
239
+ asset: denom,
240
+ value: amount,
241
+ fromBaseDecimal: 8,
242
+ });
243
+ }
244
+
245
+ const { chain, asset, decimals } = config;
246
+
247
+ const assetOrChain = (
248
+ chain
249
+ ? {
250
+ chain,
251
+ }
252
+ : { asset }
253
+ ) as { asset: string } | { chain: CosmosChain };
254
+
255
+ return AssetValue.from({
256
+ ...assetOrChain,
257
+ value: amount,
258
+ fromBaseDecimal: decimals,
259
+ });
260
+ };