@swapkit/toolboxes 4.3.10 → 4.13.2

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 (266) hide show
  1. package/dist/LICENSE +246 -0
  2. package/dist/src/aptos/index.cjs +1 -0
  3. package/dist/src/aptos/index.js +1 -0
  4. package/dist/src/cardano/index.cjs +1 -4
  5. package/dist/src/cardano/index.js +1 -4
  6. package/dist/src/cosmos/index.cjs +1 -4
  7. package/dist/src/cosmos/index.js +1 -4
  8. package/dist/src/evm/index.cjs +1 -4
  9. package/dist/src/evm/index.js +1 -4
  10. package/dist/src/index.cjs +1 -5
  11. package/dist/src/index.js +1 -5
  12. package/dist/src/near/index.cjs +1 -4
  13. package/dist/src/near/index.js +1 -4
  14. package/dist/src/radix/index.cjs +1 -4
  15. package/dist/src/radix/index.js +1 -4
  16. package/dist/src/ripple/index.cjs +1 -4
  17. package/dist/src/ripple/index.js +1 -4
  18. package/dist/src/solana/index.cjs +1 -4
  19. package/dist/src/solana/index.js +1 -4
  20. package/dist/src/starknet/index.cjs +1 -0
  21. package/dist/src/starknet/index.js +1 -0
  22. package/dist/src/stellar/index.cjs +1 -0
  23. package/dist/src/stellar/index.js +1 -0
  24. package/dist/src/substrate/index.cjs +1 -4
  25. package/dist/src/substrate/index.js +1 -4
  26. package/dist/src/sui/index.cjs +1 -4
  27. package/dist/src/sui/index.js +1 -4
  28. package/dist/src/ton/index.cjs +1 -4
  29. package/dist/src/ton/index.js +1 -4
  30. package/dist/src/tron/index.cjs +1 -4
  31. package/dist/src/tron/index.js +1 -4
  32. package/dist/src/utxo/index.cjs +1 -5
  33. package/dist/src/utxo/index.js +1 -5
  34. package/dist/types/aptos/index.d.ts +3 -0
  35. package/dist/types/aptos/index.d.ts.map +1 -0
  36. package/dist/types/aptos/toolbox.d.ts +21 -0
  37. package/dist/types/aptos/toolbox.d.ts.map +1 -0
  38. package/dist/types/aptos/types.d.ts +27 -0
  39. package/dist/types/aptos/types.d.ts.map +1 -0
  40. package/dist/types/cardano/toolbox.d.ts +19 -22
  41. package/dist/types/cardano/toolbox.d.ts.map +1 -1
  42. package/dist/types/cardano/types.d.ts +8 -3
  43. package/dist/types/cardano/types.d.ts.map +1 -1
  44. package/dist/types/cosmos/thorchainUtils/addressFormat.d.ts.map +1 -1
  45. package/dist/types/cosmos/thorchainUtils/messages.d.ts +3 -3
  46. package/dist/types/cosmos/thorchainUtils/messages.d.ts.map +1 -1
  47. package/dist/types/cosmos/toolbox/cosmos.d.ts +11 -9
  48. package/dist/types/cosmos/toolbox/cosmos.d.ts.map +1 -1
  49. package/dist/types/cosmos/toolbox/thorchain.d.ts +6 -51
  50. package/dist/types/cosmos/toolbox/thorchain.d.ts.map +1 -1
  51. package/dist/types/cosmos/types.d.ts +2 -2
  52. package/dist/types/cosmos/types.d.ts.map +1 -1
  53. package/dist/types/evm/helpers.d.ts +34 -1
  54. package/dist/types/evm/helpers.d.ts.map +1 -1
  55. package/dist/types/evm/toolbox/baseEVMToolbox.d.ts +14 -7
  56. package/dist/types/evm/toolbox/baseEVMToolbox.d.ts.map +1 -1
  57. package/dist/types/evm/toolbox/evm.d.ts +236 -96
  58. package/dist/types/evm/toolbox/evm.d.ts.map +1 -1
  59. package/dist/types/evm/toolbox/index.d.ts +3 -2
  60. package/dist/types/evm/toolbox/index.d.ts.map +1 -1
  61. package/dist/types/evm/toolbox/op.d.ts +13 -8
  62. package/dist/types/evm/toolbox/op.d.ts.map +1 -1
  63. package/dist/types/evm/types.d.ts +49 -27
  64. package/dist/types/evm/types.d.ts.map +1 -1
  65. package/dist/types/index.d.ts +31 -25
  66. package/dist/types/index.d.ts.map +1 -1
  67. package/dist/types/near/helpers/core.d.ts +1 -1
  68. package/dist/types/near/helpers/core.d.ts.map +1 -1
  69. package/dist/types/near/index.d.ts +1 -1
  70. package/dist/types/near/index.d.ts.map +1 -1
  71. package/dist/types/near/toolbox.d.ts +13 -10
  72. package/dist/types/near/toolbox.d.ts.map +1 -1
  73. package/dist/types/near/types/index.d.ts +4 -0
  74. package/dist/types/near/types/index.d.ts.map +1 -0
  75. package/dist/types/near/types/toolbox.d.ts +2 -0
  76. package/dist/types/near/types/toolbox.d.ts.map +1 -1
  77. package/dist/types/radix/index.d.ts +7 -7
  78. package/dist/types/radix/index.d.ts.map +1 -1
  79. package/dist/types/ripple/currency.d.ts +5 -0
  80. package/dist/types/ripple/currency.d.ts.map +1 -0
  81. package/dist/types/ripple/index.d.ts +60 -17
  82. package/dist/types/ripple/index.d.ts.map +1 -1
  83. package/dist/types/ripple/tokens.d.ts +15 -0
  84. package/dist/types/ripple/tokens.d.ts.map +1 -0
  85. package/dist/types/solana/index.d.ts +1 -1
  86. package/dist/types/solana/index.d.ts.map +1 -1
  87. package/dist/types/solana/toolbox.d.ts +12 -10
  88. package/dist/types/solana/toolbox.d.ts.map +1 -1
  89. package/dist/types/starknet/index.d.ts +5 -0
  90. package/dist/types/starknet/index.d.ts.map +1 -0
  91. package/dist/types/starknet/toolbox.d.ts +34 -0
  92. package/dist/types/starknet/toolbox.d.ts.map +1 -0
  93. package/dist/types/starknet/types.d.ts +26 -0
  94. package/dist/types/starknet/types.d.ts.map +1 -0
  95. package/dist/types/stellar/index.d.ts +3 -0
  96. package/dist/types/stellar/index.d.ts.map +1 -0
  97. package/dist/types/stellar/toolbox.d.ts +21 -0
  98. package/dist/types/stellar/toolbox.d.ts.map +1 -0
  99. package/dist/types/stellar/types.d.ts +10 -0
  100. package/dist/types/stellar/types.d.ts.map +1 -0
  101. package/dist/types/substrate/balance.d.ts +3 -3
  102. package/dist/types/substrate/balance.d.ts.map +1 -1
  103. package/dist/types/substrate/substrate.d.ts +22 -97
  104. package/dist/types/substrate/substrate.d.ts.map +1 -1
  105. package/dist/types/substrate/types.d.ts +2 -2
  106. package/dist/types/substrate/types.d.ts.map +1 -1
  107. package/dist/types/sui/toolbox.d.ts +17 -8
  108. package/dist/types/sui/toolbox.d.ts.map +1 -1
  109. package/dist/types/sui/types.d.ts +11 -3
  110. package/dist/types/sui/types.d.ts.map +1 -1
  111. package/dist/types/ton/toolbox.d.ts +23 -13
  112. package/dist/types/ton/toolbox.d.ts.map +1 -1
  113. package/dist/types/ton/types.d.ts +9 -8
  114. package/dist/types/ton/types.d.ts.map +1 -1
  115. package/dist/types/tron/helpers/proto.d.ts +9 -0
  116. package/dist/types/tron/helpers/proto.d.ts.map +1 -0
  117. package/dist/types/tron/helpers/trongrid.d.ts +43 -3
  118. package/dist/types/tron/helpers/trongrid.d.ts.map +1 -1
  119. package/dist/types/tron/helpers/utils.d.ts +17 -0
  120. package/dist/types/tron/helpers/utils.d.ts.map +1 -0
  121. package/dist/types/tron/index.d.ts +4 -5
  122. package/dist/types/tron/index.d.ts.map +1 -1
  123. package/dist/types/tron/toolbox.d.ts +20 -18
  124. package/dist/types/tron/toolbox.d.ts.map +1 -1
  125. package/dist/types/tron/types.d.ts +31 -57
  126. package/dist/types/tron/types.d.ts.map +1 -1
  127. package/dist/types/types.d.ts +6 -0
  128. package/dist/types/types.d.ts.map +1 -1
  129. package/dist/types/utxo/hdWallet.d.ts +33 -0
  130. package/dist/types/utxo/hdWallet.d.ts.map +1 -0
  131. package/dist/types/utxo/helpers/api.d.ts +49 -1
  132. package/dist/types/utxo/helpers/api.d.ts.map +1 -1
  133. package/dist/types/utxo/helpers/bchaddrjs.d.ts.map +1 -1
  134. package/dist/types/utxo/helpers/cashaddr.d.ts +13 -0
  135. package/dist/types/utxo/helpers/cashaddr.d.ts.map +1 -0
  136. package/dist/types/utxo/helpers/coinselect.d.ts +9 -5
  137. package/dist/types/utxo/helpers/coinselect.d.ts.map +1 -1
  138. package/dist/types/utxo/helpers/txSize.d.ts +4 -3
  139. package/dist/types/utxo/helpers/txSize.d.ts.map +1 -1
  140. package/dist/types/utxo/index.d.ts +2 -1
  141. package/dist/types/utxo/index.d.ts.map +1 -1
  142. package/dist/types/utxo/toolbox/bitcoinCash.d.ts +75 -15
  143. package/dist/types/utxo/toolbox/bitcoinCash.d.ts.map +1 -1
  144. package/dist/types/utxo/toolbox/index.d.ts +6 -5
  145. package/dist/types/utxo/toolbox/index.d.ts.map +1 -1
  146. package/dist/types/utxo/toolbox/params.d.ts +8 -16
  147. package/dist/types/utxo/toolbox/params.d.ts.map +1 -1
  148. package/dist/types/utxo/toolbox/utxo.d.ts +135 -46
  149. package/dist/types/utxo/toolbox/utxo.d.ts.map +1 -1
  150. package/dist/types/utxo/toolbox/validators.d.ts +1 -1
  151. package/dist/types/utxo/toolbox/validators.d.ts.map +1 -1
  152. package/dist/types/utxo/toolbox/zcash.d.ts +63 -10
  153. package/dist/types/utxo/toolbox/zcash.d.ts.map +1 -1
  154. package/dist/types/utxo/types.d.ts +78 -15
  155. package/dist/types/utxo/types.d.ts.map +1 -1
  156. package/package.json +43 -53
  157. package/dist/src/cardano/index.cjs.map +0 -11
  158. package/dist/src/cardano/index.js.map +0 -11
  159. package/dist/src/cosmos/index.cjs.map +0 -20
  160. package/dist/src/cosmos/index.js.map +0 -20
  161. package/dist/src/evm/index.cjs.map +0 -20
  162. package/dist/src/evm/index.js.map +0 -20
  163. package/dist/src/index.cjs.map +0 -67
  164. package/dist/src/index.js.map +0 -67
  165. package/dist/src/near/index.cjs.map +0 -16
  166. package/dist/src/near/index.js.map +0 -16
  167. package/dist/src/radix/index.cjs.map +0 -10
  168. package/dist/src/radix/index.js.map +0 -10
  169. package/dist/src/ripple/index.cjs.map +0 -10
  170. package/dist/src/ripple/index.js.map +0 -10
  171. package/dist/src/solana/index.cjs.map +0 -11
  172. package/dist/src/solana/index.js.map +0 -11
  173. package/dist/src/substrate/index.cjs.map +0 -13
  174. package/dist/src/substrate/index.js.map +0 -13
  175. package/dist/src/sui/index.cjs.map +0 -11
  176. package/dist/src/sui/index.js.map +0 -11
  177. package/dist/src/ton/index.cjs.map +0 -11
  178. package/dist/src/ton/index.js.map +0 -11
  179. package/dist/src/tron/index.cjs.map +0 -13
  180. package/dist/src/tron/index.js.map +0 -13
  181. package/dist/src/utxo/index.cjs.map +0 -21
  182. package/dist/src/utxo/index.js.map +0 -21
  183. package/dist/types/tron/helpers/trc20.abi.d.ts +0 -156
  184. package/dist/types/tron/helpers/trc20.abi.d.ts.map +0 -1
  185. package/src/__tests__/address-validation-all-chains.test.ts +0 -162
  186. package/src/__tests__/addressValidator.test.ts +0 -162
  187. package/src/cardano/__tests__/toolbox.test.ts +0 -48
  188. package/src/cardano/index.ts +0 -2
  189. package/src/cardano/toolbox.ts +0 -168
  190. package/src/cardano/types.ts +0 -10
  191. package/src/cosmos/__tests__/toolbox.test.ts +0 -95
  192. package/src/cosmos/index.ts +0 -4
  193. package/src/cosmos/thorchainUtils/addressFormat.ts +0 -22
  194. package/src/cosmos/thorchainUtils/index.ts +0 -4
  195. package/src/cosmos/thorchainUtils/messages.ts +0 -212
  196. package/src/cosmos/thorchainUtils/registry.ts +0 -43
  197. package/src/cosmos/thorchainUtils/types/MsgCompiled.ts +0 -2800
  198. package/src/cosmos/thorchainUtils/types/client-types.ts +0 -54
  199. package/src/cosmos/thorchainUtils/types/index.ts +0 -1
  200. package/src/cosmos/toolbox/cosmos.ts +0 -350
  201. package/src/cosmos/toolbox/index.ts +0 -35
  202. package/src/cosmos/toolbox/thorchain.ts +0 -249
  203. package/src/cosmos/types.ts +0 -48
  204. package/src/cosmos/util.ts +0 -214
  205. package/src/evm/__tests__/address-validation.test.ts +0 -84
  206. package/src/evm/__tests__/ethereum.test.ts +0 -137
  207. package/src/evm/__tests__/signMessage.test.ts +0 -60
  208. package/src/evm/api.ts +0 -10
  209. package/src/evm/contracts/eth/multicall.ts +0 -165
  210. package/src/evm/contracts/op/gasOracle.ts +0 -145
  211. package/src/evm/helpers.ts +0 -71
  212. package/src/evm/index.ts +0 -4
  213. package/src/evm/toolbox/baseEVMToolbox.ts +0 -698
  214. package/src/evm/toolbox/evm.ts +0 -66
  215. package/src/evm/toolbox/index.ts +0 -44
  216. package/src/evm/toolbox/op.ts +0 -143
  217. package/src/evm/types.ts +0 -146
  218. package/src/index.ts +0 -260
  219. package/src/near/__tests__/core.test.ts +0 -70
  220. package/src/near/helpers/core.ts +0 -85
  221. package/src/near/helpers/gasEstimation.ts +0 -96
  222. package/src/near/helpers/nep141.ts +0 -50
  223. package/src/near/index.ts +0 -21
  224. package/src/near/toolbox.ts +0 -421
  225. package/src/near/types/contract.ts +0 -32
  226. package/src/near/types/nep141.ts +0 -34
  227. package/src/near/types/toolbox.ts +0 -55
  228. package/src/near/types.ts +0 -44
  229. package/src/radix/index.ts +0 -138
  230. package/src/ripple/index.ts +0 -179
  231. package/src/solana/index.ts +0 -36
  232. package/src/solana/toolbox.ts +0 -409
  233. package/src/substrate/balance.ts +0 -88
  234. package/src/substrate/index.ts +0 -2
  235. package/src/substrate/substrate.ts +0 -281
  236. package/src/substrate/types.ts +0 -115
  237. package/src/sui/__tests__/toolbox.test.ts +0 -86
  238. package/src/sui/index.ts +0 -2
  239. package/src/sui/toolbox.ts +0 -166
  240. package/src/sui/types.ts +0 -11
  241. package/src/ton/__tests__/toolbox.test.ts +0 -67
  242. package/src/ton/index.ts +0 -2
  243. package/src/ton/toolbox.ts +0 -136
  244. package/src/ton/types.ts +0 -13
  245. package/src/tron/__tests__/toolbox.test.ts +0 -221
  246. package/src/tron/helpers/trc20.abi.ts +0 -107
  247. package/src/tron/helpers/trongrid.ts +0 -53
  248. package/src/tron/index.ts +0 -21
  249. package/src/tron/toolbox.ts +0 -585
  250. package/src/tron/types.ts +0 -83
  251. package/src/types.ts +0 -28
  252. package/src/utils.ts +0 -34
  253. package/src/utxo/__tests__/zcash-integration.test.ts +0 -97
  254. package/src/utxo/helpers/api.ts +0 -471
  255. package/src/utxo/helpers/bchaddrjs.ts +0 -166
  256. package/src/utxo/helpers/coinselect.ts +0 -92
  257. package/src/utxo/helpers/index.ts +0 -4
  258. package/src/utxo/helpers/txSize.ts +0 -137
  259. package/src/utxo/index.ts +0 -6
  260. package/src/utxo/toolbox/bitcoinCash.ts +0 -243
  261. package/src/utxo/toolbox/index.ts +0 -59
  262. package/src/utxo/toolbox/params.ts +0 -18
  263. package/src/utxo/toolbox/utxo.ts +0 -439
  264. package/src/utxo/toolbox/validators.ts +0 -36
  265. package/src/utxo/toolbox/zcash.ts +0 -242
  266. package/src/utxo/types.ts +0 -39
@@ -1,70 +0,0 @@
1
- import { beforeAll, beforeEach, describe, expect, test } from "bun:test";
2
- import { JsonRpcProvider } from "@near-js/providers";
3
- import { AssetValue, Chain, getRPCUrl } from "@swapkit/helpers";
4
- import { getFullAccessPublicKey } from "../helpers/core";
5
- import { getNearToolbox } from "../toolbox";
6
-
7
- const accountId = "ea03292d08136cca439513a33c76af083e5204eceb4ce720320fff84071a447f";
8
-
9
- const context: { provider: JsonRpcProvider; toolbox: Awaited<ReturnType<typeof getNearToolbox>> } = {} as any;
10
-
11
- beforeAll(async () => {
12
- const rpcUrl = await getRPCUrl(Chain.Near);
13
- context.provider = new JsonRpcProvider({ url: rpcUrl });
14
- });
15
-
16
- beforeEach(async () => {
17
- context.toolbox = await getNearToolbox();
18
- });
19
-
20
- describe("NEAR createTransaction", () => {
21
- test("should retrieve full access public key for valid account", async () => {
22
- const toolbox = context.toolbox;
23
-
24
- const transaction = await toolbox.createTransaction({
25
- assetValue: AssetValue.from({ chain: Chain.Near, value: "0.001" }),
26
- recipient: accountId,
27
- sender: accountId,
28
- });
29
-
30
- expect(transaction).toBeDefined();
31
- expect(transaction.publicKey).toBeDefined();
32
- }, 30000);
33
-
34
- test("should throw error for invalid account", async () => {
35
- const provider = context.provider;
36
- const invalidAccountId = "non-existent-account-12345.testnet";
37
-
38
- await expect(async () => {
39
- await getFullAccessPublicKey(provider, invalidAccountId);
40
- }).toThrow();
41
- }, 10000);
42
-
43
- test("should handle network errors gracefully", async () => {
44
- const invalidProvider = new JsonRpcProvider({ url: "https://invalid-rpc-url.test" });
45
-
46
- await expect(async () => {
47
- await getFullAccessPublicKey(invalidProvider, "any-account.testnet");
48
- }).toThrow();
49
- }, 10000);
50
-
51
- test("should work with contract function call transaction", async () => {
52
- const toolbox = context.toolbox;
53
- const provider = context.provider;
54
-
55
- const contractTransaction = await toolbox.createContractFunctionCall({
56
- args: { account_id: accountId },
57
- attachedDeposit: "1250000000000000000000",
58
- contractId: "wrap.testnet",
59
- gas: "300000000000000",
60
- methodName: "storage_deposit",
61
- sender: accountId,
62
- });
63
-
64
- expect(contractTransaction).toBeDefined();
65
- expect(contractTransaction.publicKey).toBeDefined();
66
-
67
- const { publicKey } = await getFullAccessPublicKey(provider, accountId);
68
- expect(publicKey.toString()).toBe(contractTransaction.publicKey.toString());
69
- }, 30000);
70
- });
@@ -1,85 +0,0 @@
1
- import type { KeyPair } from "@near-js/crypto";
2
- import type { Provider } from "@near-js/providers";
3
- import { KeyPairSigner } from "@near-js/signers";
4
- import { type DerivationPathArray, derivationPathToString, SwapKitError } from "@swapkit/helpers";
5
- import type { NearSigner } from "../types";
6
-
7
- export async function getValidateNearAddress() {
8
- const { validateAccountId } = await import("near-sdk-js");
9
- return (address: string) => {
10
- // Use the official NEAR SDK validation function if available
11
- try {
12
- return validateAccountId(address);
13
- } catch {
14
- const ACCOUNT_ID_REGEX = /^(([a-z\d]+[-_])*[a-z\d]+\.)*([a-z\d]+[-_])*[a-z\d]+$/;
15
-
16
- return address.length >= 2 && address.length <= 64 && ACCOUNT_ID_REGEX.test(address);
17
- }
18
- };
19
- }
20
-
21
- export async function getNearSignerFromPhrase(params: {
22
- phrase: string;
23
- derivationPath?: DerivationPathArray;
24
- index?: number;
25
- }) {
26
- const { parseSeedPhrase } = await import("near-seed-phrase");
27
- const { KeyPair } = await import("@near-js/crypto");
28
-
29
- const index = params.index || 0;
30
- const derivationPath = params.derivationPath
31
- ? derivationPathToString(params.derivationPath.slice(0, 3) as [number, number, number])
32
- : `m/44'/397'/${index}'`;
33
-
34
- const { secretKey } = parseSeedPhrase(params.phrase, derivationPath);
35
- const keyPair = KeyPair.fromString(secretKey as any);
36
-
37
- return createNearSignerFromKeyPair(keyPair);
38
- }
39
-
40
- export async function getNearSignerFromPrivateKey(privateKey: string) {
41
- const { KeyPair } = await import("@near-js/crypto");
42
- const keyPair = KeyPair.fromString(privateKey as any);
43
- return createNearSignerFromKeyPair(keyPair);
44
- }
45
-
46
- class SKKeyPairSigner extends KeyPairSigner {
47
- #keyPair: KeyPair;
48
-
49
- constructor(keyPair: KeyPair) {
50
- super(keyPair);
51
- this.#keyPair = keyPair;
52
- }
53
-
54
- getAddress(): Promise<string> {
55
- const publicKey = this.#keyPair.getPublicKey();
56
- const hexAddress = Buffer.from(publicKey.data).toString("hex");
57
- return Promise.resolve(hexAddress);
58
- }
59
- }
60
-
61
- function createNearSignerFromKeyPair(keyPair: KeyPair): NearSigner {
62
- const keyPairSigner = new SKKeyPairSigner(keyPair);
63
-
64
- return keyPairSigner;
65
- }
66
-
67
- export async function getFullAccessPublicKey(provider: Provider, accountId: string) {
68
- const response = await provider.query({
69
- account_id: accountId,
70
- finality: "final",
71
- request_type: "view_access_key_list",
72
- });
73
-
74
- const fullAccessKey = (response as any).keys.find((key: any) => key.access_key.permission === "FullAccess");
75
-
76
- if (!fullAccessKey) {
77
- throw new SwapKitError("toolbox_near_no_public_key_found");
78
- }
79
- const { PublicKey } = await import("@near-js/crypto");
80
-
81
- const publicKey = PublicKey.fromString(fullAccessKey.public_key);
82
- const nonce = (fullAccessKey.access_key.nonce as number) || 0;
83
-
84
- return { nonce, publicKey };
85
- }
@@ -1,96 +0,0 @@
1
- import type { Account } from "@near-js/accounts";
2
- import type { NearGasEstimateParams } from "../types/contract";
3
-
4
- export const GAS_COSTS = {
5
- ACCESS_KEY_ADDITION: "5",
6
- ACCESS_KEY_DELETION: "5",
7
- ACCOUNT_CREATION: "30",
8
- CONTRACT_CALL: "150",
9
- CONTRACT_DEPLOYMENT: "200",
10
- SIMPLE_TRANSFER: "1",
11
- STAKE: "10",
12
- STORAGE_DEPOSIT: "150",
13
- TOKEN_TRANSFER: "150",
14
- } as const;
15
-
16
- export function isSimpleTransfer(params: NearGasEstimateParams): params is { recipient: string; amount: string } {
17
- return "recipient" in params && "amount" in params && !("contractId" in params);
18
- }
19
-
20
- export function isContractCall(
21
- params: NearGasEstimateParams,
22
- ): params is { contractId: string; methodName: string; args?: Record<string, any>; attachedDeposit?: string } {
23
- return "contractId" in params && "methodName" in params;
24
- }
25
-
26
- export function isBatchTransaction(params: NearGasEstimateParams): params is { actions: any[] } {
27
- return "actions" in params;
28
- }
29
-
30
- export function isAccountCreation(
31
- params: NearGasEstimateParams,
32
- ): params is { newAccountId: string; publicKey?: string } {
33
- return "newAccountId" in params;
34
- }
35
-
36
- export function isContractDeployment(params: NearGasEstimateParams): params is { contractCode: Uint8Array } {
37
- return "contractCode" in params;
38
- }
39
-
40
- export function isCustomEstimator(
41
- params: NearGasEstimateParams,
42
- ): params is { customEstimator: (account: Account) => Promise<string> } {
43
- return "customEstimator" in params;
44
- }
45
-
46
- export function estimateBatchGas(actions: any[]) {
47
- let totalGas = 0;
48
-
49
- for (const action of actions) {
50
- switch (action.enum) {
51
- case "transfer":
52
- totalGas += Number(GAS_COSTS.SIMPLE_TRANSFER);
53
- break;
54
- case "functionCall":
55
- totalGas += Number(GAS_COSTS.CONTRACT_CALL);
56
- break;
57
- case "createAccount":
58
- totalGas += Number(GAS_COSTS.ACCOUNT_CREATION);
59
- break;
60
- case "deployContract":
61
- totalGas += Number(GAS_COSTS.CONTRACT_DEPLOYMENT);
62
- break;
63
- case "addKey":
64
- totalGas += Number(GAS_COSTS.ACCESS_KEY_ADDITION);
65
- break;
66
- case "deleteKey":
67
- totalGas += Number(GAS_COSTS.ACCESS_KEY_DELETION);
68
- break;
69
- case "stake":
70
- totalGas += Number(GAS_COSTS.STAKE);
71
- break;
72
- default:
73
- totalGas += Number(GAS_COSTS.CONTRACT_CALL);
74
- }
75
- }
76
-
77
- return totalGas.toString();
78
- }
79
-
80
- export function getContractMethodGas(methodName: string) {
81
- if (methodName === "ft_transfer" || methodName === "ft_transfer_call") {
82
- return GAS_COSTS.TOKEN_TRANSFER;
83
- }
84
- if (methodName === "storage_deposit") {
85
- return GAS_COSTS.STORAGE_DEPOSIT;
86
- }
87
- return GAS_COSTS.CONTRACT_CALL;
88
- }
89
-
90
- export function tgasToGas(tgas: string): string {
91
- return (BigInt(tgas) * BigInt(10 ** 12)).toString();
92
- }
93
-
94
- export function gasToTGas(gas: string): string {
95
- return (BigInt(gas) / BigInt(10 ** 12)).toString();
96
- }
@@ -1,50 +0,0 @@
1
- import type { Account, Contract } from "@near-js/accounts";
2
-
3
- export interface NEP141Metadata {
4
- spec: string;
5
- name: string;
6
- symbol: string;
7
- icon?: string;
8
- reference?: string;
9
- reference_hash?: string;
10
- decimals: number;
11
- }
12
-
13
- export interface StorageBalance {
14
- total: string;
15
- available: string;
16
- }
17
-
18
- export interface StorageBalanceBounds {
19
- min: string;
20
- max?: string;
21
- }
22
-
23
- export type NEP141Token = {
24
- transfer: (receiverId: string, amount: string, memo?: string) => Promise<void>;
25
- transferCall: (receiverId: string, amount: string, msg: string, memo?: string) => Promise<void>;
26
- balanceOf: (accountId: string) => Promise<string>;
27
- totalSupply: () => Promise<string>;
28
- metadata: () => Promise<NEP141Metadata>;
29
- storageBalanceOf: (accountId: string) => Promise<StorageBalance | null>;
30
- storageDeposit: (accountId?: string, amount?: string) => Promise<StorageBalance>;
31
- ensureStorage: (accountId: string) => Promise<void>;
32
- contract: Contract;
33
- };
34
-
35
- // Create a Near contract instance
36
- export async function createNearContract<T extends Contract>({
37
- account,
38
- contractId,
39
- viewMethods,
40
- changeMethods,
41
- }: {
42
- account: Account;
43
- contractId: string;
44
- viewMethods: string[];
45
- changeMethods: string[];
46
- }) {
47
- const { Contract } = await import("@near-js/accounts");
48
-
49
- return new Contract(account, contractId, { changeMethods, useLocalViewExecution: true, viewMethods }) as T;
50
- }
package/src/near/index.ts DELETED
@@ -1,21 +0,0 @@
1
- import type { getNearToolbox } from "./toolbox";
2
-
3
- export * from "./helpers/core";
4
- export * from "./helpers/gasEstimation";
5
- export * from "./helpers/nep141";
6
- export * from "./toolbox";
7
- export * from "./types";
8
-
9
- export type NearWallet = Awaited<ReturnType<typeof getNearToolbox>>;
10
-
11
- export type {
12
- NearCallParams,
13
- NearContractInterface,
14
- NearGasEstimateParams,
15
- } from "./types/contract";
16
- export type {
17
- FungibleTokenMetadata,
18
- StorageBalance,
19
- StorageBalanceBounds,
20
- TokenTransferParams,
21
- } from "./types/nep141";