@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,156 +0,0 @@
1
- import type {
2
- FungibleResourcesCollectionItem,
3
- GatewayApiClient,
4
- StateEntityDetailsVaultResponseItem,
5
- StateEntityFungiblesPageRequest,
6
- StateEntityFungiblesPageResponse,
7
- } from "@radixdlt/babylon-gateway-api-sdk";
8
- import {
9
- AssetValue,
10
- Chain,
11
- SKConfig,
12
- type SKConfigIntegrations,
13
- SwapKitError,
14
- } from "@swapkit/helpers";
15
-
16
- export type RadixWallet = Awaited<ReturnType<typeof RadixToolbox>>;
17
-
18
- type RadixGetBalanceParams = {
19
- address: string;
20
- networkApi: GatewayApiClient;
21
- };
22
- // Could not find anything sync in SDK, ask Radix team
23
- export function radixValidateAddress(address: string) {
24
- return address.startsWith("account_rdx1") && address.length === 66;
25
- }
26
-
27
- function getBalance({ networkApi }: { networkApi: GatewayApiClient }) {
28
- return async function getBalance(address: string) {
29
- const fungibleResources = await fetchFungibleResources({ address, networkApi });
30
- const fungibleBalances = convertResourcesToBalances({
31
- resources: fungibleResources,
32
- networkApi,
33
- });
34
- return fungibleBalances;
35
- };
36
- }
37
-
38
- async function fetchFungibleResources({
39
- address,
40
- networkApi,
41
- }: RadixGetBalanceParams): Promise<FungibleResourcesCollectionItem[]> {
42
- let hasNextPage = true;
43
- let nextCursor: string | undefined;
44
- let fungibleResources: FungibleResourcesCollectionItem[] = [];
45
- const stateVersion = await currentStateVersion(networkApi);
46
- while (hasNextPage) {
47
- const stateEntityFungiblesPageRequest: StateEntityFungiblesPageRequest = {
48
- address: address,
49
- limit_per_page: 100,
50
- cursor: nextCursor,
51
- at_ledger_state: {
52
- state_version: stateVersion,
53
- },
54
- };
55
-
56
- const stateEntityFungiblesPageResponse: StateEntityFungiblesPageResponse =
57
- await networkApi.state.innerClient.entityFungiblesPage({
58
- stateEntityFungiblesPageRequest: stateEntityFungiblesPageRequest,
59
- });
60
-
61
- fungibleResources = fungibleResources.concat(stateEntityFungiblesPageResponse.items);
62
- if (stateEntityFungiblesPageResponse.next_cursor) {
63
- nextCursor = stateEntityFungiblesPageResponse.next_cursor;
64
- } else {
65
- hasNextPage = false;
66
- }
67
- }
68
- return fungibleResources;
69
- }
70
-
71
- // biome-ignore lint/complexity/noExcessiveCognitiveComplexity: <explanation>
72
- async function convertResourcesToBalances({
73
- resources,
74
- networkApi,
75
- }: {
76
- resources: FungibleResourcesCollectionItem[]; //| NonFungibleResourcesCollectionItem[];
77
- networkApi: GatewayApiClient;
78
- }): Promise<AssetValue[]> {
79
- const balances: AssetValue[] = [];
80
- const BATCH_SIZE = 50;
81
-
82
- // Split resources into batches of up to 50 items
83
- const resourceBatches: FungibleResourcesCollectionItem[][] = [];
84
- for (let i = 0; i < resources.length; i += BATCH_SIZE) {
85
- resourceBatches.push(resources.slice(i, i + BATCH_SIZE));
86
- }
87
-
88
- for (const batch of resourceBatches) {
89
- const addresses = batch.map((item) => item.resource_address);
90
- const response: StateEntityDetailsVaultResponseItem[] =
91
- await networkApi.state.getEntityDetailsVaultAggregated(addresses);
92
-
93
- const divisibilities = new Map<string, { decimals: number; symbol: string }>();
94
-
95
- for (const result of response) {
96
- if (result.details !== undefined) {
97
- const metaDataSymbol = result.metadata?.items.find((item) => item.key === "symbol");
98
- const symbol =
99
- metaDataSymbol?.value.typed.type === "String" ? metaDataSymbol.value.typed.value : "?";
100
-
101
- if (result.details.type === "FungibleResource") {
102
- divisibilities.set(result.address, {
103
- decimals: result.details.divisibility,
104
- symbol,
105
- });
106
- }
107
- }
108
- }
109
-
110
- for (const item of batch) {
111
- if (item.aggregation_level === "Global") {
112
- const assetInfo = divisibilities.get(item.resource_address) || { decimals: 0, symbol: "?" };
113
-
114
- const balance = AssetValue.from({
115
- asset:
116
- assetInfo.symbol !== Chain.Radix
117
- ? `${Chain.Radix}.${assetInfo.symbol}-${item.resource_address}`
118
- : "XRD.XRD",
119
- value: item.amount,
120
- });
121
- balances.push(balance);
122
- }
123
- }
124
- }
125
-
126
- return balances;
127
- }
128
-
129
- async function currentStateVersion(networkApi: GatewayApiClient) {
130
- return networkApi.status.getCurrent().then((status) => status.ledger_state.state_version);
131
- }
132
-
133
- export const RadixToolbox = async ({
134
- dappConfig,
135
- }: { dappConfig?: SKConfigIntegrations["radix"] } = {}) => {
136
- const { RadixDappToolkit } = await import("@radixdlt/radix-dapp-toolkit");
137
- const { GatewayApiClient } = await import("@radixdlt/babylon-gateway-api-sdk");
138
- const config = dappConfig || SKConfig.get("integrations").radix;
139
-
140
- const radixToolkit = RadixDappToolkit({
141
- ...config,
142
- networkId: config.network?.networkId || 1,
143
- });
144
-
145
- const networkApi = GatewayApiClient.initialize(radixToolkit.gatewayApi.clientConfig);
146
-
147
- return {
148
- getAddress: () => "",
149
- getBalance: getBalance({ networkApi }),
150
- networkApi,
151
- validateAddress: radixValidateAddress,
152
- signAndBroadcast: (() => {
153
- throw new SwapKitError("toolbox_radix_method_not_supported", { method: "signAndBroadcast" });
154
- }) as (params: any) => Promise<string>,
155
- };
156
- };
@@ -1,192 +0,0 @@
1
- import {
2
- AssetValue,
3
- BaseDecimal,
4
- Chain,
5
- type ChainSigner,
6
- type GenericTransferParams,
7
- SKConfig,
8
- SwapKitError,
9
- SwapKitNumber,
10
- } from "@swapkit/helpers";
11
- import type { Transaction } from "xrpl";
12
- import { Client, type Payment, Wallet, isValidAddress, xrpToDrops } from "xrpl";
13
-
14
- export type RippleWallet = Awaited<ReturnType<typeof getRippleToolbox>>;
15
-
16
- export { hashes, type Transaction } from "xrpl";
17
-
18
- const RIPPLE_ERROR_CODES = {
19
- ACCOUNT_NOT_FOUND: 19,
20
- } as const;
21
-
22
- // Note: Ripple seeds generate a single address, no derivation path/index support.
23
- function createSigner(phrase: string): ChainSigner<Transaction, { tx_blob: string; hash: string }> {
24
- const wallet = Wallet.fromMnemonic(phrase);
25
- return {
26
- // publicKey: wallet.publicKey,
27
- // Address is sync, but interface requires async
28
- getAddress: () => Promise.resolve(wallet.address),
29
- // Signing is sync, but interface requires async
30
- signTransaction: (tx: Transaction) => Promise.resolve(wallet.sign(tx as Transaction)), // Cast needed as Wallet.sign expects Transaction
31
- };
32
- }
33
-
34
- export function rippleValidateAddress(address: string) {
35
- return isValidAddress(address);
36
- }
37
-
38
- type RippleToolboxParams =
39
- | { phrase: string }
40
- | { signer: ChainSigner<Transaction, { tx_blob: string; hash: string }> }
41
- | {};
42
-
43
- export const getRippleToolbox = async (params: RippleToolboxParams = {}) => {
44
- const signer =
45
- "signer" in params && params.signer
46
- ? params.signer
47
- : "phrase" in params && params.phrase
48
- ? createSigner(params.phrase)
49
- : undefined;
50
-
51
- const rpcUrl = SKConfig.get("rpcUrls")[Chain.Ripple];
52
- if (!rpcUrl) {
53
- throw new SwapKitError({
54
- errorKey: "toolbox_ripple_rpc_not_configured",
55
- info: { chain: Chain.Ripple },
56
- });
57
- }
58
-
59
- const client = new Client(rpcUrl);
60
- await client.connect();
61
-
62
- const getAddress = () => {
63
- if (!signer) {
64
- throw new SwapKitError({ errorKey: "toolbox_ripple_signer_not_found" });
65
- }
66
- return signer.getAddress();
67
- };
68
-
69
- const getBalance = async (address?: string) => {
70
- const addr = address || (await getAddress());
71
-
72
- try {
73
- const accountInfo = await client.request({ command: "account_info", account: addr });
74
-
75
- const balance = accountInfo.result.account_data.Balance;
76
-
77
- return [
78
- AssetValue.from({
79
- chain: Chain.Ripple,
80
- value: balance,
81
- fromBaseDecimal: BaseDecimal[Chain.Ripple],
82
- }),
83
- ];
84
- } catch (error) {
85
- // empty account
86
- if ((error as any).data.error_code === RIPPLE_ERROR_CODES.ACCOUNT_NOT_FOUND) {
87
- return [
88
- AssetValue.from({
89
- chain: Chain.Ripple,
90
- value: 0,
91
- }),
92
- ];
93
- }
94
- throw new SwapKitError("toolbox_ripple_get_balance_error", {
95
- info: { address: addr, error },
96
- });
97
- }
98
- };
99
-
100
- const estimateTransactionFee = async () => {
101
- const feeResponse = await client.request({ command: "fee" });
102
- const feeDrops = feeResponse.result.drops.open_ledger_fee; // Fee in drops
103
-
104
- return AssetValue.from({
105
- chain: Chain.Ripple,
106
- value: SwapKitNumber.fromBigInt(BigInt(feeDrops), BaseDecimal[Chain.Ripple]),
107
- });
108
- };
109
-
110
- const createTransaction = async ({
111
- assetValue,
112
- recipient,
113
- memo,
114
- sender,
115
- }: { assetValue: AssetValue; recipient: string; sender?: string; memo?: string }) => {
116
- if (!rippleValidateAddress(recipient)) {
117
- throw new SwapKitError({ errorKey: "core_transaction_invalid_recipient_address" });
118
- }
119
-
120
- const senderAddress = sender || (await getAddress());
121
-
122
- if (!assetValue.isGasAsset || assetValue.chain !== Chain.Ripple) {
123
- throw new SwapKitError({
124
- errorKey: "toolbox_ripple_asset_not_supported",
125
- info: { asset: assetValue.toString() },
126
- });
127
- }
128
-
129
- const transaction: Payment = {
130
- TransactionType: "Payment",
131
- Account: senderAddress,
132
- Amount: xrpToDrops(assetValue.getValue("string")),
133
- Destination: recipient,
134
- };
135
-
136
- if (memo) {
137
- transaction.Memos = [{ Memo: { MemoData: Buffer.from(memo).toString("hex") } }];
138
- }
139
-
140
- const preparedTx = await client.autofill(transaction);
141
- return preparedTx;
142
- };
143
-
144
- const signTransaction = (tx: Transaction) => {
145
- if (!signer) {
146
- throw new SwapKitError({ errorKey: "toolbox_ripple_signer_not_found" });
147
- }
148
- return signer.signTransaction(tx);
149
- };
150
-
151
- const broadcastTransaction = async (signedTxHex: string) => {
152
- const submitResult = await client.submitAndWait(signedTxHex);
153
- const result = submitResult.result;
154
-
155
- if (result.validated) {
156
- return result.hash;
157
- }
158
-
159
- throw new SwapKitError({
160
- errorKey: "toolbox_ripple_broadcast_error",
161
- info: { chain: Chain.Ripple },
162
- });
163
- };
164
-
165
- const transfer = async (params: GenericTransferParams) => {
166
- if (!signer) {
167
- throw new SwapKitError({ errorKey: "toolbox_ripple_signer_not_found" });
168
- }
169
- const sender = await signer.getAddress();
170
- const tx = await createTransaction({ ...params, sender });
171
- const signedTx = await signTransaction(tx);
172
- return broadcastTransaction(signedTx.tx_blob);
173
- };
174
-
175
- const disconnect = () => client.disconnect();
176
-
177
- return {
178
- // Signer related
179
- signer, // Expose the signer instance if created/provided
180
- createSigner, // Expose the helper
181
- // Core methods
182
- getAddress,
183
- validateAddress: rippleValidateAddress,
184
- getBalance,
185
- createTransaction,
186
- signTransaction,
187
- broadcastTransaction,
188
- transfer,
189
- estimateTransactionFee,
190
- disconnect,
191
- };
192
- };
@@ -1,55 +0,0 @@
1
- import type { PublicKey, SendOptions, Transaction, VersionedTransaction } from "@solana/web3.js";
2
- import type { GenericCreateTransactionParams, GenericTransferParams } from "@swapkit/helpers";
3
- import type { getSolanaToolbox } from "./toolbox";
4
-
5
- type DisplayEncoding = "utf8" | "hex";
6
-
7
- type PhantomEvent = "connect" | "disconnect" | "accountChanged";
8
-
9
- type PhantomRequestMethod =
10
- | "connect"
11
- | "disconnect"
12
- | "signAndSendTransaction"
13
- | "signAndSendTransactionV0"
14
- | "signAndSendTransactionV0WithLookupTable"
15
- | "signTransaction"
16
- | "signAllTransactions"
17
- | "signMessage";
18
-
19
- interface ConnectOpts {
20
- onlyIfTrusted: boolean;
21
- }
22
-
23
- export * from "./toolbox";
24
-
25
- export type SolanaWallet = Awaited<ReturnType<typeof getSolanaToolbox>>;
26
-
27
- export interface SolanaProvider {
28
- connect: (opts?: Partial<ConnectOpts>) => Promise<{ publicKey: PublicKey }>;
29
- disconnect: () => Promise<void>;
30
- getAddress: () => Promise<string>;
31
- isConnected: boolean | null;
32
- isPhantom: boolean;
33
- on: (event: PhantomEvent, handler: (args: any) => void) => void;
34
- publicKey: PublicKey | null;
35
- request: (method: PhantomRequestMethod, params: any) => Promise<unknown>;
36
- signMessage: (message: Uint8Array | string, display?: DisplayEncoding) => Promise<any>;
37
- signAndSendTransaction: (
38
- transaction: Transaction | VersionedTransaction,
39
- opts?: SendOptions,
40
- ) => Promise<{ signature: string; publicKey: PublicKey }>;
41
- signTransaction: <T extends Transaction | VersionedTransaction = Transaction>(
42
- transaction: T,
43
- ) => Promise<T>;
44
- signAllTransactions: <T extends Transaction | VersionedTransaction = Transaction>(
45
- transactions: T[],
46
- ) => Promise<T[]>;
47
- }
48
-
49
- export type SolanaCreateTransactionParams = Omit<GenericCreateTransactionParams, "feeRate"> & {
50
- isProgramDerivedAddress?: boolean;
51
- };
52
-
53
- export type SolanaTransferParams = Omit<GenericTransferParams, "feeRate"> & {
54
- isProgramDerivedAddress?: boolean;
55
- };