@swapkit/toolboxes 4.0.0-beta.50 → 4.0.0-beta.52

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 (232) hide show
  1. package/dist/src/cosmos/index.cjs +2 -2
  2. package/dist/src/cosmos/index.cjs.map +10 -6
  3. package/dist/src/cosmos/index.js +2 -2
  4. package/dist/src/cosmos/index.js.map +10 -6
  5. package/dist/src/evm/index.cjs +2 -2
  6. package/dist/src/evm/index.cjs.map +10 -8
  7. package/dist/src/evm/index.js +2 -2
  8. package/dist/src/evm/index.js.map +10 -8
  9. package/dist/src/index.cjs +4 -2
  10. package/dist/src/index.cjs.map +54 -4
  11. package/dist/src/index.js +4 -2
  12. package/dist/src/index.js.map +54 -4
  13. package/dist/src/near/index.cjs +2 -2
  14. package/dist/src/near/index.cjs.map +7 -5
  15. package/dist/src/near/index.js +2 -2
  16. package/dist/src/near/index.js.map +7 -5
  17. package/dist/src/radix/index.cjs +2 -2
  18. package/dist/src/radix/index.cjs.map +2 -2
  19. package/dist/src/radix/index.js +2 -2
  20. package/dist/src/radix/index.js.map +2 -2
  21. package/dist/src/ripple/index.cjs +2 -2
  22. package/dist/src/ripple/index.cjs.map +2 -2
  23. package/dist/src/ripple/index.js +2 -2
  24. package/dist/src/ripple/index.js.map +2 -2
  25. package/dist/src/solana/index.cjs +2 -2
  26. package/dist/src/solana/index.cjs.map +5 -4
  27. package/dist/src/solana/index.js +2 -2
  28. package/dist/src/solana/index.js.map +5 -4
  29. package/dist/src/substrate/index.cjs +2 -2
  30. package/dist/src/substrate/index.cjs.map +6 -5
  31. package/dist/src/substrate/index.js +2 -2
  32. package/dist/src/substrate/index.js.map +6 -5
  33. package/dist/src/tron/index.cjs +2 -2
  34. package/dist/src/tron/index.cjs.map +6 -5
  35. package/dist/src/tron/index.js +2 -2
  36. package/dist/src/tron/index.js.map +6 -5
  37. package/dist/src/utxo/index.cjs +4 -4
  38. package/dist/src/utxo/index.cjs.map +10 -7
  39. package/dist/src/utxo/index.js +4 -4
  40. package/dist/src/utxo/index.js.map +10 -7
  41. package/{src/cosmos/index.ts → dist/types/cosmos/index.d.ts} +1 -0
  42. package/dist/types/cosmos/index.d.ts.map +1 -0
  43. package/dist/types/cosmos/thorchainUtils/addressFormat.d.ts +5 -0
  44. package/dist/types/cosmos/thorchainUtils/addressFormat.d.ts.map +1 -0
  45. package/{src/cosmos/thorchainUtils/index.ts → dist/types/cosmos/thorchainUtils/index.d.ts} +1 -0
  46. package/dist/types/cosmos/thorchainUtils/index.d.ts.map +1 -0
  47. package/dist/types/cosmos/thorchainUtils/messages.d.ts +208 -0
  48. package/dist/types/cosmos/thorchainUtils/messages.d.ts.map +1 -0
  49. package/dist/types/cosmos/thorchainUtils/registry.d.ts +4 -0
  50. package/dist/types/cosmos/thorchainUtils/registry.d.ts.map +1 -0
  51. package/dist/types/cosmos/thorchainUtils/types/MsgCompiled.d.ts +2 -0
  52. package/dist/types/cosmos/thorchainUtils/types/MsgCompiled.d.ts.map +1 -0
  53. package/dist/types/cosmos/thorchainUtils/types/client-types.d.ts +66 -0
  54. package/dist/types/cosmos/thorchainUtils/types/client-types.d.ts.map +1 -0
  55. package/dist/types/cosmos/thorchainUtils/types/index.d.ts +2 -0
  56. package/dist/types/cosmos/thorchainUtils/types/index.d.ts.map +1 -0
  57. package/dist/types/cosmos/toolbox/cosmos.d.ts +93 -0
  58. package/dist/types/cosmos/toolbox/cosmos.d.ts.map +1 -0
  59. package/dist/types/cosmos/toolbox/index.d.ts +14 -0
  60. package/dist/types/cosmos/toolbox/index.d.ts.map +1 -0
  61. package/dist/types/cosmos/toolbox/thorchain.d.ts +158 -0
  62. package/dist/types/cosmos/toolbox/thorchain.d.ts.map +1 -0
  63. package/{src/cosmos/types.ts → dist/types/cosmos/types.d.ts} +24 -29
  64. package/dist/types/cosmos/types.d.ts.map +1 -0
  65. package/dist/types/cosmos/util.d.ts +68 -0
  66. package/dist/types/cosmos/util.d.ts.map +1 -0
  67. package/dist/types/evm/api.d.ts +8 -0
  68. package/dist/types/evm/api.d.ts.map +1 -0
  69. package/dist/types/evm/contracts/eth/multicall.d.ts +36 -0
  70. package/dist/types/evm/contracts/eth/multicall.d.ts.map +1 -0
  71. package/dist/types/evm/contracts/op/gasOracle.d.ts +40 -0
  72. package/dist/types/evm/contracts/op/gasOracle.d.ts.map +1 -0
  73. package/dist/types/evm/helpers.d.ts +20 -0
  74. package/dist/types/evm/helpers.d.ts.map +1 -0
  75. package/{src/evm/index.ts → dist/types/evm/index.d.ts} +1 -0
  76. package/dist/types/evm/index.d.ts.map +1 -0
  77. package/dist/types/evm/toolbox/baseEVMToolbox.d.ts +82 -0
  78. package/dist/types/evm/toolbox/baseEVMToolbox.d.ts.map +1 -0
  79. package/dist/types/evm/toolbox/evm.d.ts +367 -0
  80. package/dist/types/evm/toolbox/evm.d.ts.map +1 -0
  81. package/dist/types/evm/toolbox/index.d.ts +89 -0
  82. package/dist/types/evm/toolbox/index.d.ts.map +1 -0
  83. package/dist/types/evm/toolbox/op.d.ts +62 -0
  84. package/dist/types/evm/toolbox/op.d.ts.map +1 -0
  85. package/dist/types/evm/types.d.ts +98 -0
  86. package/dist/types/evm/types.d.ts.map +1 -0
  87. package/dist/types/index.d.ts +63 -0
  88. package/dist/types/index.d.ts.map +1 -0
  89. package/dist/types/near/helpers/core.d.ts +15 -0
  90. package/dist/types/near/helpers/core.d.ts.map +1 -0
  91. package/dist/types/near/helpers/gasEstimation.d.ts +41 -0
  92. package/dist/types/near/helpers/gasEstimation.d.ts.map +1 -0
  93. package/dist/types/near/helpers/nep141.d.ts +72 -0
  94. package/dist/types/near/helpers/nep141.d.ts.map +1 -0
  95. package/dist/types/near/index.d.ts +10 -0
  96. package/dist/types/near/index.d.ts.map +1 -0
  97. package/dist/types/near/toolbox.d.ts +4 -0
  98. package/dist/types/near/toolbox.d.ts.map +1 -0
  99. package/dist/types/near/types/contract.d.ts +38 -0
  100. package/dist/types/near/types/contract.d.ts.map +1 -0
  101. package/dist/types/near/types/nep141.d.ts +56 -0
  102. package/dist/types/near/types/nep141.d.ts.map +1 -0
  103. package/dist/types/near/types/toolbox.d.ts +57 -0
  104. package/dist/types/near/types/toolbox.d.ts.map +1 -0
  105. package/dist/types/near/types.d.ts +44 -0
  106. package/dist/types/near/types.d.ts.map +1 -0
  107. package/dist/types/radix/index.d.ts +14 -0
  108. package/dist/types/radix/index.d.ts.map +1 -0
  109. package/dist/types/ripple/index.d.ts +43 -0
  110. package/dist/types/ripple/index.d.ts.map +1 -0
  111. package/dist/types/solana/index.d.ts +37 -0
  112. package/dist/types/solana/index.d.ts.map +1 -0
  113. package/dist/types/solana/toolbox.d.ts +41 -0
  114. package/dist/types/solana/toolbox.d.ts.map +1 -0
  115. package/dist/types/substrate/balance.d.ts +17 -0
  116. package/dist/types/substrate/balance.d.ts.map +1 -0
  117. package/{src/substrate/index.ts → dist/types/substrate/index.d.ts} +1 -0
  118. package/dist/types/substrate/index.d.ts.map +1 -0
  119. package/dist/types/substrate/substrate.d.ts +148 -0
  120. package/dist/types/substrate/substrate.d.ts.map +1 -0
  121. package/dist/types/substrate/types.d.ts +100 -0
  122. package/dist/types/substrate/types.d.ts.map +1 -0
  123. package/dist/types/tron/helpers/trc20.abi.d.ts +156 -0
  124. package/dist/types/tron/helpers/trc20.abi.d.ts.map +1 -0
  125. package/dist/types/tron/helpers/trongrid.d.ts +8 -0
  126. package/dist/types/tron/helpers/trongrid.d.ts.map +1 -0
  127. package/dist/types/tron/index.d.ts +6 -0
  128. package/dist/types/tron/index.d.ts.map +1 -0
  129. package/dist/types/tron/toolbox.d.ts +26 -0
  130. package/dist/types/tron/toolbox.d.ts.map +1 -0
  131. package/dist/types/tron/types.d.ts +101 -0
  132. package/dist/types/tron/types.d.ts.map +1 -0
  133. package/dist/types/types.d.ts +18 -0
  134. package/dist/types/types.d.ts.map +1 -0
  135. package/dist/types/utils.d.ts +4 -0
  136. package/dist/types/utils.d.ts.map +1 -0
  137. package/dist/types/utxo/helpers/api.d.ts +133 -0
  138. package/dist/types/utxo/helpers/api.d.ts.map +1 -0
  139. package/dist/types/utxo/helpers/bchaddrjs.d.ts +10 -0
  140. package/dist/types/utxo/helpers/bchaddrjs.d.ts.map +1 -0
  141. package/dist/types/utxo/helpers/coinselect.d.ts +16 -0
  142. package/dist/types/utxo/helpers/coinselect.d.ts.map +1 -0
  143. package/{src/utxo/helpers/index.ts → dist/types/utxo/helpers/index.d.ts} +1 -0
  144. package/dist/types/utxo/helpers/index.d.ts.map +1 -0
  145. package/dist/types/utxo/helpers/txSize.d.ts +21 -0
  146. package/dist/types/utxo/helpers/txSize.d.ts.map +1 -0
  147. package/{src/utxo/index.ts → dist/types/utxo/index.d.ts} +1 -0
  148. package/dist/types/utxo/index.d.ts.map +1 -0
  149. package/dist/types/utxo/toolbox/bitcoinCash.d.ts +104 -0
  150. package/dist/types/utxo/toolbox/bitcoinCash.d.ts.map +1 -0
  151. package/dist/types/utxo/toolbox/index.d.ts +50 -0
  152. package/dist/types/utxo/toolbox/index.d.ts.map +1 -0
  153. package/dist/types/utxo/toolbox/utxo.d.ts +102 -0
  154. package/dist/types/utxo/toolbox/utxo.d.ts.map +1 -0
  155. package/dist/types/utxo/toolbox/zcash.d.ts +83 -0
  156. package/dist/types/utxo/toolbox/zcash.d.ts.map +1 -0
  157. package/dist/types/utxo/types.d.ts +46 -0
  158. package/dist/types/utxo/types.d.ts.map +1 -0
  159. package/package.json +15 -18
  160. package/dist/chunk-0h4xdrwz.js +0 -5
  161. package/dist/chunk-0h4xdrwz.js.map +0 -10
  162. package/dist/chunk-4yap1fvd.js +0 -4
  163. package/dist/chunk-4yap1fvd.js.map +0 -10
  164. package/dist/chunk-9bqegm61.js +0 -4
  165. package/dist/chunk-9bqegm61.js.map +0 -10
  166. package/dist/chunk-fazw0jvt.js +0 -4
  167. package/dist/chunk-fazw0jvt.js.map +0 -9
  168. package/dist/chunk-fjfxga2v.js +0 -4
  169. package/dist/chunk-fjfxga2v.js.map +0 -10
  170. package/dist/chunk-s47y8512.js +0 -5
  171. package/dist/chunk-s47y8512.js.map +0 -9
  172. package/dist/chunk-vtd17cje.js +0 -4
  173. package/dist/chunk-vtd17cje.js.map +0 -10
  174. package/dist/chunk-zcdeg6h9.js +0 -5
  175. package/dist/chunk-zcdeg6h9.js.map +0 -10
  176. package/src/cosmos/thorchainUtils/addressFormat.ts +0 -26
  177. package/src/cosmos/thorchainUtils/messages.ts +0 -262
  178. package/src/cosmos/thorchainUtils/registry.ts +0 -44
  179. package/src/cosmos/thorchainUtils/types/MsgCompiled.ts +0 -2800
  180. package/src/cosmos/thorchainUtils/types/client-types.ts +0 -73
  181. package/src/cosmos/thorchainUtils/types/index.ts +0 -1
  182. package/src/cosmos/toolbox/cosmos.ts +0 -375
  183. package/src/cosmos/toolbox/index.ts +0 -33
  184. package/src/cosmos/toolbox/thorchain.ts +0 -313
  185. package/src/cosmos/util.ts +0 -266
  186. package/src/evm/__tests__/address-validation.test.ts +0 -86
  187. package/src/evm/__tests__/ethereum.test.ts +0 -141
  188. package/src/evm/api.ts +0 -21
  189. package/src/evm/contracts/eth/multicall.ts +0 -165
  190. package/src/evm/contracts/op/gasOracle.ts +0 -151
  191. package/src/evm/helpers.ts +0 -194
  192. package/src/evm/toolbox/baseEVMToolbox.ts +0 -762
  193. package/src/evm/toolbox/evm.ts +0 -66
  194. package/src/evm/toolbox/index.ts +0 -52
  195. package/src/evm/toolbox/op.ts +0 -131
  196. package/src/evm/types.ts +0 -146
  197. package/src/index.ts +0 -263
  198. package/src/near/__tests__/core.test.ts +0 -80
  199. package/src/near/helpers/contractFactory.ts +0 -22
  200. package/src/near/helpers/core.ts +0 -91
  201. package/src/near/helpers/gasEstimation.ts +0 -110
  202. package/src/near/helpers/index.ts +0 -5
  203. package/src/near/helpers/nep141.ts +0 -110
  204. package/src/near/index.ts +0 -24
  205. package/src/near/toolbox.ts +0 -509
  206. package/src/near/types/contract.ts +0 -48
  207. package/src/near/types/nep141.ts +0 -66
  208. package/src/near/types.ts +0 -57
  209. package/src/radix/index.ts +0 -156
  210. package/src/ripple/index.ts +0 -192
  211. package/src/solana/index.ts +0 -55
  212. package/src/solana/toolbox.ts +0 -433
  213. package/src/substrate/balance.ts +0 -92
  214. package/src/substrate/substrate.ts +0 -320
  215. package/src/substrate/types.ts +0 -120
  216. package/src/tron/__tests__/toolbox.test.ts +0 -147
  217. package/src/tron/helpers/trc20.abi.ts +0 -107
  218. package/src/tron/helpers/trongrid.ts +0 -54
  219. package/src/tron/index.ts +0 -17
  220. package/src/tron/toolbox.ts +0 -650
  221. package/src/tron/types.ts +0 -120
  222. package/src/utils.ts +0 -27
  223. package/src/utxo/__tests__/zcash-integration.test.ts +0 -114
  224. package/src/utxo/helpers/api.ts +0 -560
  225. package/src/utxo/helpers/bchaddrjs.ts +0 -183
  226. package/src/utxo/helpers/coinselect.ts +0 -98
  227. package/src/utxo/helpers/txSize.ts +0 -104
  228. package/src/utxo/toolbox/bitcoinCash.ts +0 -320
  229. package/src/utxo/toolbox/index.ts +0 -90
  230. package/src/utxo/toolbox/utxo.ts +0 -525
  231. package/src/utxo/toolbox/zcash.ts +0 -208
  232. package/src/utxo/types.ts +0 -57
@@ -1,80 +0,0 @@
1
- import { beforeAll, beforeEach, describe, expect, test } from "bun:test";
2
- import { AssetValue, Chain, SKConfig } from "@swapkit/helpers";
3
- import { providers } from "near-api-js";
4
- import { getFullAccessPublicKey } from "../helpers/core";
5
- import { getNearToolbox } from "../toolbox";
6
-
7
- const accountId = "ea03292d08136cca439513a33c76af083e5204eceb4ce720320fff84071a447f";
8
-
9
- const context: {
10
- provider: providers.JsonRpcProvider;
11
- toolbox: Awaited<ReturnType<typeof getNearToolbox>>;
12
- } = {} as any;
13
-
14
- beforeAll(() => {
15
- context.provider = new providers.JsonRpcProvider({
16
- url: SKConfig.get("rpcUrls")[Chain.Near],
17
- });
18
- });
19
-
20
- beforeEach(async () => {
21
- context.toolbox = await getNearToolbox();
22
- });
23
-
24
- describe("NEAR createTransaction", () => {
25
- test("should retrieve full access public key for valid account", async () => {
26
- const toolbox = context.toolbox;
27
-
28
- const transaction = await toolbox.createTransaction({
29
- recipient: accountId, // Self transfer
30
- assetValue: AssetValue.from({
31
- chain: Chain.Near,
32
- value: "0.001", // Small amount
33
- }),
34
- sender: accountId,
35
- feeRate: 300000000000000, // 300 TGas
36
- });
37
-
38
- expect(transaction).toBeDefined();
39
- expect(transaction.publicKey).toBeDefined();
40
- expect(transaction.serialized).toBeDefined();
41
- }, 30000);
42
-
43
- test("should throw error for invalid account", async () => {
44
- const provider = context.provider;
45
- const invalidAccountId = "non-existent-account-12345.testnet";
46
-
47
- await expect(async () => {
48
- await getFullAccessPublicKey(provider, invalidAccountId);
49
- }).toThrow();
50
- }, 10000);
51
-
52
- test("should handle network errors gracefully", async () => {
53
- const invalidProvider = new providers.JsonRpcProvider({ url: "https://invalid-rpc-url.test" });
54
-
55
- await expect(async () => {
56
- await getFullAccessPublicKey(invalidProvider, "any-account.testnet");
57
- }).toThrow();
58
- }, 10000);
59
-
60
- test("should work with contract function call transaction", async () => {
61
- const toolbox = context.toolbox;
62
- const provider = context.provider;
63
-
64
- const contractTransaction = await toolbox.createContractFunctionCall({
65
- sender: accountId,
66
- contractId: "wrap.testnet", // Known testnet contract
67
- methodName: "storage_deposit",
68
- args: { account_id: accountId },
69
- gas: "300000000000000", // 300 TGas
70
- attachedDeposit: "1250000000000000000000", // 0.00125 NEAR for storage
71
- });
72
-
73
- expect(contractTransaction).toBeDefined();
74
- expect(contractTransaction.publicKey).toBeDefined();
75
-
76
- // Verify the public key can be retrieved directly
77
- const { publicKey } = await getFullAccessPublicKey(provider, accountId);
78
- expect(publicKey.toString()).toBe(contractTransaction.publicKey);
79
- }, 30000);
80
- });
@@ -1,22 +0,0 @@
1
- import type { Account, Contract } from "near-api-js";
2
-
3
- // Create a Near contract instance
4
- export async function createNearContract<T extends Contract>({
5
- account,
6
- contractId,
7
- viewMethods,
8
- changeMethods,
9
- }: {
10
- account: Account;
11
- contractId: string;
12
- viewMethods: string[];
13
- changeMethods: string[];
14
- }): Promise<T> {
15
- const { Contract } = await import("near-api-js");
16
-
17
- return new Contract(account, contractId, {
18
- viewMethods,
19
- changeMethods,
20
- useLocalViewExecution: true, // Enable local view execution for efficiency
21
- }) as T;
22
- }
@@ -1,91 +0,0 @@
1
- import type { Provider } from "@near-js/providers";
2
- import { type DerivationPathArray, SwapKitError, derivationPathToString } from "@swapkit/helpers";
3
- import { type KeyPair, KeyPairSigner } from "near-api-js";
4
- import type { NearSigner } from "../types";
5
-
6
- export async function getValidateNearAddress() {
7
- const { validateAccountId } = await import("near-sdk-js");
8
- return (address: string) => {
9
- // Use the official NEAR SDK validation function if available
10
- try {
11
- return validateAccountId(address);
12
- } catch {
13
- const ACCOUNT_ID_REGEX = /^(([a-z\d]+[-_])*[a-z\d]+\.)*([a-z\d]+[-_])*[a-z\d]+$/;
14
-
15
- return address.length >= 2 && address.length <= 64 && ACCOUNT_ID_REGEX.test(address);
16
- }
17
- };
18
- }
19
-
20
- export async function getNearSignerFromPhrase(params: {
21
- phrase: string;
22
- derivationPath?: DerivationPathArray;
23
- index?: number;
24
- }) {
25
- const { parseSeedPhrase } = await import("near-seed-phrase");
26
- const { KeyPair } = await import("near-api-js");
27
-
28
- // Handle derivation path logic here
29
- // NEAR uses a 3-level derivation path: m/44'/397'/index'
30
- const index = params.index || 0;
31
- const derivationPath = params.derivationPath
32
- ? derivationPathToString(params.derivationPath.slice(0, 3) as [number, number, number])
33
- : `m/44'/397'/${index}'`;
34
-
35
- const { secretKey } = parseSeedPhrase(params.phrase, derivationPath);
36
- const keyPair = KeyPair.fromString(secretKey as any);
37
-
38
- return createNearSignerFromKeyPair(keyPair);
39
- }
40
-
41
- export async function getNearSignerFromPrivateKey(privateKey: string) {
42
- const { KeyPair } = await import("near-api-js/lib/utils");
43
- const keyPair = KeyPair.fromString(privateKey as any);
44
- return createNearSignerFromKeyPair(keyPair);
45
- }
46
-
47
- class SKKeyPairSigner extends KeyPairSigner {
48
- #keyPair: KeyPair;
49
-
50
- constructor(keyPair: KeyPair) {
51
- super(keyPair);
52
- this.#keyPair = keyPair;
53
- }
54
-
55
- getAddress(): Promise<string> {
56
- // For implicit accounts, derive account ID from public key
57
- // NEAR implicit accounts use hex representation of the public key
58
- const publicKey = this.#keyPair.getPublicKey();
59
- const hexAddress = Buffer.from(publicKey.data).toString("hex");
60
- return Promise.resolve(hexAddress);
61
- }
62
- }
63
-
64
- function createNearSignerFromKeyPair(keyPair: KeyPair): NearSigner {
65
- const keyPairSigner = new SKKeyPairSigner(keyPair);
66
-
67
- return keyPairSigner;
68
- }
69
-
70
- export async function getFullAccessPublicKey(provider: Provider, accountId: string) {
71
- // Get the first full access key for the account
72
- const response = await provider.query({
73
- request_type: "view_access_key_list",
74
- finality: "final",
75
- account_id: accountId,
76
- });
77
-
78
- const fullAccessKey = (response as any).keys.find(
79
- (key: any) => key.access_key.permission === "FullAccess",
80
- );
81
-
82
- if (!fullAccessKey) {
83
- throw new SwapKitError("toolbox_near_invalid_address");
84
- }
85
-
86
- const { utils } = await import("near-api-js");
87
- const publicKey = utils.PublicKey.fromString(fullAccessKey.public_key);
88
- const nonce = (fullAccessKey.access_key.nonce as number) || 0;
89
-
90
- return { publicKey, nonce };
91
- }
@@ -1,110 +0,0 @@
1
- import type { Account } from "near-api-js";
2
- import type { NearGasEstimateParams } from "../types/contract";
3
-
4
- // Gas constants (in TGas - 10^12 gas units)
5
- export const GAS_COSTS = {
6
- SIMPLE_TRANSFER: "1", // 1 TGas
7
- TOKEN_TRANSFER: "100", // 100 TGas
8
- CONTRACT_CALL: "100", // 100 TGas base
9
- ACCOUNT_CREATION: "30", // 30 TGas
10
- CONTRACT_DEPLOYMENT: "200", // 200 TGas
11
- ACCESS_KEY_ADDITION: "5", // 5 TGas
12
- ACCESS_KEY_DELETION: "5", // 5 TGas
13
- STAKE: "10", // 10 TGas
14
- STORAGE_DEPOSIT: "100", // 100 TGas
15
- } as const;
16
-
17
- // Type guards for discriminated union
18
- export function isSimpleTransfer(
19
- params: NearGasEstimateParams,
20
- ): params is { recipient: string; amount: string } {
21
- return "recipient" in params && "amount" in params && !("contractId" in params);
22
- }
23
-
24
- export function isContractCall(params: NearGasEstimateParams): params is {
25
- contractId: string;
26
- methodName: string;
27
- args?: Record<string, any>;
28
- attachedDeposit?: string;
29
- } {
30
- return "contractId" in params && "methodName" in params;
31
- }
32
-
33
- export function isBatchTransaction(params: NearGasEstimateParams): params is { actions: any[] } {
34
- return "actions" in params;
35
- }
36
-
37
- export function isAccountCreation(params: NearGasEstimateParams): params is {
38
- newAccountId: string;
39
- publicKey?: string;
40
- } {
41
- return "newAccountId" in params;
42
- }
43
-
44
- export function isContractDeployment(
45
- params: NearGasEstimateParams,
46
- ): params is { contractCode: Uint8Array } {
47
- return "contractCode" in params;
48
- }
49
-
50
- export function isCustomEstimator(params: NearGasEstimateParams): params is {
51
- customEstimator: (account: Account) => Promise<string>;
52
- } {
53
- return "customEstimator" in params;
54
- }
55
-
56
- // Helper function to estimate gas for batch actions
57
- export function estimateBatchGas(actions: any[]) {
58
- let totalGas = 0;
59
-
60
- for (const action of actions) {
61
- switch (action.enum) {
62
- case "transfer":
63
- totalGas += Number(GAS_COSTS.SIMPLE_TRANSFER);
64
- break;
65
- case "functionCall":
66
- totalGas += Number(GAS_COSTS.CONTRACT_CALL);
67
- break;
68
- case "createAccount":
69
- totalGas += Number(GAS_COSTS.ACCOUNT_CREATION);
70
- break;
71
- case "deployContract":
72
- totalGas += Number(GAS_COSTS.CONTRACT_DEPLOYMENT);
73
- break;
74
- case "addKey":
75
- totalGas += Number(GAS_COSTS.ACCESS_KEY_ADDITION);
76
- break;
77
- case "deleteKey":
78
- totalGas += Number(GAS_COSTS.ACCESS_KEY_DELETION);
79
- break;
80
- case "stake":
81
- totalGas += Number(GAS_COSTS.STAKE);
82
- break;
83
- default:
84
- totalGas += Number(GAS_COSTS.CONTRACT_CALL);
85
- }
86
- }
87
-
88
- return totalGas.toString();
89
- }
90
-
91
- // Helper function to get gas cost for contract methods
92
- export function getContractMethodGas(methodName: string) {
93
- if (methodName === "ft_transfer" || methodName === "ft_transfer_call") {
94
- return GAS_COSTS.TOKEN_TRANSFER;
95
- }
96
- if (methodName === "storage_deposit") {
97
- return GAS_COSTS.STORAGE_DEPOSIT;
98
- }
99
- return GAS_COSTS.CONTRACT_CALL;
100
- }
101
-
102
- // Convert TGas string to gas units
103
- export function tgasToGas(tgas: string): string {
104
- return (BigInt(tgas) * BigInt(10 ** 12)).toString();
105
- }
106
-
107
- // Convert gas units to TGas
108
- export function gasToTGas(gas: string): string {
109
- return (BigInt(gas) / BigInt(10 ** 12)).toString();
110
- }
@@ -1,5 +0,0 @@
1
- export * from "./core";
2
-
3
- export { createNearContract } from "./contractFactory";
4
- export * from "./gasEstimation";
5
- export { createNEP141Token } from "./nep141";
@@ -1,110 +0,0 @@
1
- import type { Account, Contract } from "near-api-js";
2
- import { createNearContract } from "./contractFactory";
3
-
4
- const DEFAULT_STORAGE_DEPOSIT = "1250000000000000000000"; // 0.00125 NEAR
5
-
6
- // Define NEP-141 contract interface
7
- interface NEP141Contract extends Contract {
8
- // View methods
9
- ft_balance_of(args: { account_id: string }): Promise<string>;
10
- ft_total_supply(): Promise<string>;
11
- ft_metadata(): Promise<any>;
12
- storage_balance_of(args: { account_id: string }): Promise<any>;
13
- storage_balance_bounds(): Promise<any>;
14
-
15
- // Change methods
16
- ft_transfer(args: any, gas: any, deposit: any): Promise<any>;
17
- ft_transfer_call(args: any, gas: any, deposit: any): Promise<any>;
18
- storage_deposit(args: any, gas: any, deposit: any): Promise<any>;
19
- storage_withdraw(args: any, gas: any, deposit: any): Promise<any>;
20
- storage_unregister(force?: boolean, gas?: any): Promise<any>;
21
- }
22
-
23
- export async function createNEP141Token({
24
- contractId,
25
- account,
26
- }: {
27
- contractId: string;
28
- account: Account;
29
- }) {
30
- const BN = (await import("bn.js")).default;
31
-
32
- const contract = await createNearContract<NEP141Contract>({
33
- account,
34
- contractId,
35
- viewMethods: [
36
- "ft_balance_of",
37
- "ft_total_supply",
38
- "ft_metadata",
39
- "storage_balance_of",
40
- "storage_balance_bounds",
41
- ],
42
- changeMethods: [
43
- "ft_transfer",
44
- "ft_transfer_call",
45
- "storage_deposit",
46
- "storage_withdraw",
47
- "storage_unregister",
48
- ],
49
- });
50
-
51
- // Helper to ensure storage before transfers
52
- const ensureStorageFor = async (accountId: string) => {
53
- const balance = await contract.storage_balance_of({ account_id: accountId });
54
- if (!balance) {
55
- // Get minimum storage requirement
56
- const bounds = await contract.storage_balance_bounds();
57
- const deposit = bounds?.min || DEFAULT_STORAGE_DEPOSIT;
58
-
59
- await contract.storage_deposit(
60
- { account_id: accountId },
61
- new BN("100000000000000"), // 100 TGas
62
- new BN(deposit),
63
- );
64
- }
65
- };
66
-
67
- return {
68
- transfer: async (receiverId: string, amount: string, memo?: string) => {
69
- // Ensure recipient has storage before transfer
70
- await ensureStorageFor(receiverId);
71
-
72
- return contract.ft_transfer(
73
- { receiver_id: receiverId, amount, memo },
74
- new BN("100000000000000"), // 100 TGas
75
- new BN("1"), // 1 yoctoNEAR for security
76
- );
77
- },
78
-
79
- transferCall: async (receiverId: string, amount: string, msg: string, memo?: string) => {
80
- // Ensure recipient has storage before transfer
81
- await ensureStorageFor(receiverId);
82
-
83
- return contract.ft_transfer_call(
84
- { receiver_id: receiverId, amount, memo, msg },
85
- new BN("100000000000000"), // 100 TGas
86
- new BN("1"), // 1 yoctoNEAR for security
87
- );
88
- },
89
-
90
- balanceOf: (accountId: string) => contract.ft_balance_of({ account_id: accountId }),
91
-
92
- totalSupply: () => contract.ft_total_supply(),
93
-
94
- metadata: () => contract.ft_metadata(),
95
-
96
- storageBalanceOf: (accountId: string) => contract.storage_balance_of({ account_id: accountId }),
97
-
98
- storageDeposit: (accountId?: string, amount?: string) =>
99
- contract.storage_deposit(
100
- { account_id: accountId },
101
- new BN("100000000000000"),
102
- new BN(amount || DEFAULT_STORAGE_DEPOSIT),
103
- ),
104
-
105
- ensureStorage: ensureStorageFor,
106
-
107
- // Raw contract access for advanced use cases
108
- contract,
109
- };
110
- }
package/src/near/index.ts DELETED
@@ -1,24 +0,0 @@
1
- export * from "./toolbox";
2
- export * from "./types";
3
- export * from "./helpers";
4
-
5
- import type { getNearToolbox } from "./toolbox";
6
-
7
- export type NearWallet = Awaited<ReturnType<typeof getNearToolbox>>;
8
-
9
- export type {
10
- NearContractInterface,
11
- NearCallParams,
12
- NearGasEstimateParams,
13
- } from "./types/contract";
14
- export type {
15
- FungibleTokenMetadata,
16
- StorageBalance,
17
- StorageBalanceBounds,
18
- NEP141Contract,
19
- TokenTransferParams,
20
- } from "./types/nep141";
21
-
22
- export { createNEP141Token } from "./helpers/nep141";
23
- export { tgasToGas, gasToTGas } from "./helpers/gasEstimation";
24
- export { createNearContract } from "./helpers/contractFactory";