@swapkit/toolboxes 0.0.0-rc-20260713121307 → 0.0.0-rc-20260728115044

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 (72) hide show
  1. package/CHANGELOG.md +138 -4
  2. package/dist/chunk-55jkfkar.js +2 -0
  3. package/dist/{chunk-jdh5asaw.js → chunk-nvfkjbyq.js} +1 -1
  4. package/dist/chunk-v9dcj9m7.js +1 -0
  5. package/dist/{chunk-fjyc6m34.js → chunk-xbdjxeqd.js} +1 -1
  6. package/dist/src/aleo/index.js +1 -0
  7. package/dist/src/aptos/index.js +1 -1
  8. package/dist/src/cardano/index.js +1 -1
  9. package/dist/src/cosmos/index.js +1 -1
  10. package/dist/src/evm/index.js +1 -1
  11. package/dist/src/hypercore/index.js +1 -1
  12. package/dist/src/index.js +1 -1
  13. package/dist/src/near/index.js +1 -1
  14. package/dist/src/radix/index.js +1 -1
  15. package/dist/src/ripple/index.js +1 -1
  16. package/dist/src/solana/index.js +1 -1
  17. package/dist/src/starknet/index.js +1 -1
  18. package/dist/src/stellar/index.js +1 -1
  19. package/dist/src/substrate/index.js +1 -1
  20. package/dist/src/sui/index.js +1 -1
  21. package/dist/src/ton/index.js +1 -1
  22. package/dist/src/tron/index.js +1 -1
  23. package/dist/src/utxo/index.js +1 -1
  24. package/dist/types/aleo/helpers.d.ts +62 -0
  25. package/dist/types/aleo/index.d.ts +3 -0
  26. package/dist/types/aleo/toolbox.d.ts +45 -0
  27. package/dist/types/aleo/types.d.ts +32 -0
  28. package/dist/types/aptos/toolbox.d.ts +5 -5
  29. package/dist/types/aptos/types.d.ts +4 -0
  30. package/dist/types/cosmos/thorchainUtils/messages.d.ts +30 -6
  31. package/dist/types/cosmos/thorchainUtils/registry.d.ts +72 -2
  32. package/dist/types/cosmos/thorchainUtils/types/client-types.d.ts +6 -1
  33. package/dist/types/cosmos/toolbox/cosmos.d.ts +9 -11
  34. package/dist/types/cosmos/toolbox/thorchain.d.ts +83 -14
  35. package/dist/types/cosmos/types.d.ts +69 -3
  36. package/dist/types/cosmos/util.d.ts +150 -6
  37. package/dist/types/evm/toolbox/evm.d.ts +172 -0
  38. package/dist/types/evm/types.d.ts +2 -1
  39. package/dist/types/hypercore/toolbox.d.ts +1 -1
  40. package/dist/types/hypercore/types.d.ts +2 -0
  41. package/dist/types/index.d.ts +4 -0
  42. package/dist/types/ripple/index.d.ts +5 -1
  43. package/dist/types/solana/index.d.ts +2 -0
  44. package/dist/types/solana/toolbox.d.ts +1 -1
  45. package/dist/types/stellar/toolbox.d.ts +7 -3
  46. package/dist/types/ton/toolbox.d.ts +2 -0
  47. package/dist/types/tron/toolbox.d.ts +1 -1
  48. package/dist/types/tron/types.d.ts +2 -0
  49. package/dist/types/types.d.ts +2 -0
  50. package/dist/types/utxo/hdWallet.d.ts +1 -1
  51. package/dist/types/utxo/helpers/api.d.ts +2 -0
  52. package/package.json +26 -93
  53. package/dist/chunk-9psy287z.js +0 -1
  54. package/dist/chunk-whx98j97.js +0 -1
  55. package/dist/chunk-z7wazgbg.js +0 -2
  56. package/dist/src/aptos/index.cjs +0 -1
  57. package/dist/src/cardano/index.cjs +0 -1
  58. package/dist/src/cosmos/index.cjs +0 -1
  59. package/dist/src/evm/index.cjs +0 -1
  60. package/dist/src/hypercore/index.cjs +0 -1
  61. package/dist/src/index.cjs +0 -1
  62. package/dist/src/near/index.cjs +0 -1
  63. package/dist/src/radix/index.cjs +0 -1
  64. package/dist/src/ripple/index.cjs +0 -1
  65. package/dist/src/solana/index.cjs +0 -1
  66. package/dist/src/starknet/index.cjs +0 -1
  67. package/dist/src/stellar/index.cjs +0 -1
  68. package/dist/src/substrate/index.cjs +0 -1
  69. package/dist/src/sui/index.cjs +0 -1
  70. package/dist/src/ton/index.cjs +0 -1
  71. package/dist/src/tron/index.cjs +0 -1
  72. package/dist/src/utxo/index.cjs +0 -1
package/CHANGELOG.md CHANGED
@@ -1,15 +1,149 @@
1
1
  # @swapkit/toolboxes
2
2
 
3
- ## 0.0.0-rc-20260713121307
3
+ ## 0.0.0-rc-20260728115044
4
+
5
+ ### Major Changes
6
+
7
+ - [#249](https://github.com/swapkit/sdk/pull/249) [`41505dc`](https://github.com/swapkit/sdk/commit/41505dc0f4f77dd301cfced063013efb6307b9bb) Thanks [@ice-chillios](https://github.com/ice-chillios)! - Replace `@cosmjs/{amino,crypto,proto-signing,stargate}@0.39.0` with native `@swapkit/cosmos-signer` package. The new signer is ESM-native (no CJS↔ESM-only-noble breakage), uses only `@noble/curves`, `@noble/hashes`, `@scure/{base,bip32,bip39}` + `cosmjs-types` for proto encoders. **No `@cosmjs/*` runtime dependency.**
8
+
9
+ **Public API preserved**: all `@swapkit/toolboxes/cosmos` exports keep their signatures (`getCosmosToolbox`, `getThorchainToolbox`, `signTransaction`, `signAndBroadcastTransaction`, `transfer`, `signMultisigTx`, `broadcastMultisigTx`, etc.). Wallet adapter interfaces (`OfflineDirectSigner` / `OfflineAminoSigner`) keep the same shape so Keplr/Leap/Ledger integrations compile unchanged.
10
+
11
+ **Why major on `@swapkit/toolboxes`**: removes `@cosmjs/*` from `peerDependencies` — downstream consumers no longer need to install them. Anyone explicitly importing cosmjs types via toolboxes' transitive deps (none expected, but possible) must now depend on cosmjs directly or migrate to `@swapkit/cosmos-signer` types.
12
+
13
+ **New package**: `@swapkit/cosmos-signer@0.1.0` exposes HD wallet derivation, bech32 address helpers, direct/amino signing (byte-equal vs cosmjs), proto tx encoding (TxBody/AuthInfo/TxRaw/MsgSend), multi-sig (byte-exact fixture from cosmjs@0.39 over a known THORChain 2-of-3 set), Tendermint JSON-RPC client with optional URL-array failover, and typed queries (`getAccount`, `getBalances`, `broadcastTx`).
14
+
15
+ - [#344](https://github.com/swapkit/sdk/pull/344) [`7f99d74`](https://github.com/swapkit/sdk/commit/7f99d74ec21d58d07b2cccc5b111f8fdae6c7afb) Thanks [@ice-chillios](https://github.com/ice-chillios)! - **ESM-only packages.** CommonJS output (`.cjs`) and `require` export conditions have been removed; every package now ships ESM only (code-splitting stays enabled), with a uniform `{ default, types }` exports shape. `buildPackage` from `@swapkit/tools-builder` no longer emits CJS and the unused `esmOnly` option has been removed.
16
+
17
+ For CommonJS consumers: on Node >= 20.19 / >= 22.12, `require()` of these packages continues to work via Node's native require(ESM) support (the entrypoints contain no top-level `await`). On older Node versions, `require()` throws `ERR_REQUIRE_ESM` — migrate to `import` or dynamic `import()`.
18
+
19
+ ### Minor Changes
20
+
21
+ - [#298](https://github.com/swapkit/sdk/pull/298) [`3017621`](https://github.com/swapkit/sdk/commit/3017621ee5c2da15550036853df74d81f59d6ffb) Thanks [@ice-chillios](https://github.com/ice-chillios)! - Speed up `createTransaction` across toolboxes by removing serial and redundant network round-trips from the build path. Two techniques, both backward-compatible:
22
+
23
+ **Parallelize independent round-trips**
24
+
25
+ - **UTXO** (Bitcoin/Litecoin/Dogecoin/Dash/BCH/Zcash): the per-input raw-tx fetch in `getUtxos` ran in a serial `for…await` loop — now `Promise.all`'d into a single wave. Shared across every UTXO chain.
26
+ - **EVM**: the contract-call send path (`getCall`) issued fee-data, gas-limit and nonce requests sequentially — now one `Promise.all` wave; `sendTransaction` fetches nonce and chainId concurrently.
27
+ - **NEAR**: access-key (publicKey/nonce) and latest-block lookups were sequential — now fetched together.
28
+ - **Stellar**: base-fee and account load were sequential — now concurrent.
29
+
30
+ **Hoist network-derived inputs out (zero round-trips when supplied)** — a fully-specified `createTransaction` no longer hits the network:
31
+
32
+ - **UTXO**: a provided `feeRate` is now honored instead of being ignored and re-fetched from the fee API.
33
+ - **Cosmos** (incl. THORChain/Maya transfer + deposit): when `sequence` and `accountNumber` are both passed, the `StargateClient` connect + `getAccount` round-trips are skipped entirely (previously always run).
34
+ - **Solana**: new optional `recentBlockhash` skips `getLatestBlockhash`; a native SOL transfer also no longer opens an (unused) RPC connection, removing a stray RPC-URL health-check round-trip.
35
+ - **HyperCore**: new optional `endpoint` skips `getExchangeEndpoint`.
36
+ - **TON**: new optional `jettonWalletAddress` skips the jetton-wallet derivation RPC for token transfers.
37
+ - **Aptos**: new optional `accountSequenceNumber` / `gasUnitPrice` are passed through to the SDK, skipping its internal account-sequence and gas-price lookups.
38
+ - **Tron**: new optional `recipientExists` skips the account-existence lookup for TRC20 transfers.
39
+ - **Ripple**: new optional `sequence` / `fee` / `lastLedgerSequence` are pre-set so `autofill` skips the matching lookups; an injected `lastLedgerSequence` is used as-is (not buffer-extended).
40
+
41
+ Already-optimal build paths are unchanged (Cardano and Sui already `Promise.all`; Substrate/Starknet and native Solana/TON are local-only).
42
+
43
+ Example, measured against a mocked network at 50 ms/call latency: a Bitcoin transfer with a provided fee rate drops from **10 serial round-trips (≈525 ms) to 7 round-trips in 2 waves (≈105 ms)** — the redundant fee fetch is gone and the raw-tx fetches run in parallel.
44
+
45
+ ### Patch Changes
46
+
47
+ - Updated dependencies [[`41505dc`](https://github.com/swapkit/sdk/commit/41505dc0f4f77dd301cfced063013efb6307b9bb), [`fd1d5d7`](https://github.com/swapkit/sdk/commit/fd1d5d7304eda3ff20c53b14d0eb5998fb6b8250), [`7f99d74`](https://github.com/swapkit/sdk/commit/7f99d74ec21d58d07b2cccc5b111f8fdae6c7afb), [`bd408bd`](https://github.com/swapkit/sdk/commit/bd408bdb42f6464fa17c36383ee8d37f35f9e779), [`fd1d5d7`](https://github.com/swapkit/sdk/commit/fd1d5d7304eda3ff20c53b14d0eb5998fb6b8250)]:
48
+ - @swapkit/cosmos-signer@0.0.0-rc-20260728115044
49
+ - @swapkit/helpers@0.0.0-rc-20260728115044
50
+ - @swapkit/utxo-signer@0.0.0-rc-20260728115044
51
+
52
+ ## 4.28.0
53
+
54
+ ### Minor Changes
55
+
56
+ - [#335](https://github.com/swapkit/sdk/pull/335) [`d724200`](https://github.com/swapkit/sdk/commit/d7242000b765b5090013740dab893960bee1744c) Thanks [@towanTG](https://github.com/towanTG)! - Support the Zcash NU6.3 "Ironwood" network upgrade (mainnet activation at block 3,428,143, ~2026-07-28; testnet activated 2026-07-01).
57
+ - Update generated token lists. (via @swapkit/helpers@4.20.1)
58
+
59
+ ## 4.27.1
60
+
61
+ ### Patch Changes
62
+
63
+ - [#340](https://github.com/swapkit/sdk/pull/340) [`13fc5d3`](https://github.com/swapkit/sdk/commit/13fc5d399e7bd3cf0b64326c0b97066a22ff8a2e) Thanks [@towanTG](https://github.com/towanTG)! - Load environment-specific static assets and add the SwapKit token search endpoint. (via @swapkit/helpers@4.20.0)
64
+ - [#340](https://github.com/swapkit/sdk/pull/340) [`13fc5d3`](https://github.com/swapkit/sdk/commit/13fc5d399e7bd3cf0b64326c0b97066a22ff8a2e) Thanks [@towanTG](https://github.com/towanTG)! - Add development token lists and a source option for loading prod or dev token data. Remove the unused hand-maintained static TON list; keep the hypercore list as a documented exception until the api serves the Hypercore-native tokens — token lists come exclusively from the api providers (TON tokens are served via /tokens/search). THORChain and MayaChain lists now regenerate from their streaming providers, and the dead HyperCore list is removed alongside TON, making static lists 100% provider-generated. (via @swapkit/helpers@4.20.0)
65
+
66
+ ## 4.27.0
67
+
68
+ ### Minor Changes
69
+
70
+ - [#338](https://github.com/swapkit/sdk/pull/338) [`b93b9cd`](https://github.com/swapkit/sdk/commit/b93b9cd04730e728cb2c9de0b7e1e19a0951e46b) Thanks [@towanTG](https://github.com/towanTG)! - Allow already-fetched Aleo records to be passed directly to `unshield({ records })` as an alternative to the transaction-scoped `unshield({ transactionId })` form. Callers that fetch records for display (e.g. a wallet UI showing shielded balances from known swap-delivery transactions via `getRecords`) can unshield those exact records without a second lookup. Spent records are filtered out; the split/fee-record/prove/broadcast flow and the `splitTransactionId` resume semantics are unchanged.
71
+
72
+ ### Patch Changes
73
+
74
+ - Updated dependencies []:
75
+ - @swapkit/helpers@4.19.1
76
+
77
+ ## 4.26.1
78
+
79
+ ### Patch Changes
80
+
81
+ - [#336](https://github.com/swapkit/sdk/pull/336) [`82ddf32`](https://github.com/swapkit/sdk/commit/82ddf329eba718c23239bdea60dc070f4c8b4b34) Thanks [@towanTG](https://github.com/towanTG)! - Upgrade `@stellar/stellar-sdk` from 15.1.0 to 16.1.0 to fix Stellar in browser bundles. v15 mapped the `browser` export condition to a minified UMD bundle, so bundlers like Vite resolved a namespace without named exports — every lazy `const { Keypair } = await import("@stellar/stellar-sdk")` yielded `undefined` in the browser. The fallout was silent: XLM keystore wallets registered with an empty address, `getBalance` failed with `toolbox_stellar_account_not_found` without a Horizon call ever firing, and transaction signing (including the trustline approval flow) was broken in web apps, while Node/Bun (and therefore all tests) resolved the `default` condition and worked. v16 ships native ESM with no `browser` condition, restoring correct named-export resolution everywhere. No SwapKit API changes.
82
+ - Update generated token lists. (via @swapkit/helpers@4.19.1)
83
+
84
+ ## 4.26.0
85
+
86
+ ### Minor Changes
87
+
88
+ - [#331](https://github.com/swapkit/sdk/pull/331) [`f740a74`](https://github.com/swapkit/sdk/commit/f740a742a0cf879b4e56bb73647d21642bc22e9d) Thanks [@towanTG](https://github.com/towanTG)! - Add client-side support for the Stellar trustline approval flow: swap response types model the `approvalTx` union (EVM | Stellar changeTrust XDR) and `nextActions`, `approveAssetValue`/`isAssetValueApproved` switch between EVM allowances and Stellar trustlines (checking via the new Stellar toolbox `hasTrustline({ address, assetValue })`, approving by signing the API-provided changeTrust XDR with the destination wallet). The swap method itself is unchanged — integrators approve first, re-fetch the route, then swap.
89
+ - Update generated token lists. (via @swapkit/helpers@4.19.0)
90
+ - [#329](https://github.com/swapkit/sdk/pull/329) [`55d9edc`](https://github.com/swapkit/sdk/commit/55d9edcc603e0139588c905e41a59eaaa3275cda) Thanks [@towanTG](https://github.com/towanTG)! - Update NEAR provider token list: add Stellar assets (XLM.XLM, XLM.USDC) and latest NEAR-intents listings (SWEAT, GMX, KAITO, AAVE, LINK, UNI, and more); remove BTC.BTC(OMNI) (via @swapkit/helpers@4.19.0)
91
+
92
+ ## 4.25.0
93
+
94
+ ### Minor Changes
95
+
96
+ - [#319](https://github.com/swapkit/sdk/pull/319) [`67445d1`](https://github.com/swapkit/sdk/commit/67445d13c963492bbe4283f098b959de010ed0a7) Thanks [@towanTG](https://github.com/towanTG)! - Add Aleo chain metadata, assets, public-balance support, HD derivation, public transfers, fee estimates, broadcasting, transaction status, and keystore/server registration.
97
+ - [#328](https://github.com/swapkit/sdk/pull/328) [`0794dd0`](https://github.com/swapkit/sdk/commit/0794dd0d92a4ab1808c42069d483b91e5ae35f4a) Thanks [@towanTG](https://github.com/towanTG)! - Aleo review follow-up: surface `splitTransactionId` in unshield failure errors so an interrupted unshield is resumable, treat a 404 on the serial-number lookup as the authoritative unspent answer across RPC failover, filter record extraction to `credits.aleo` in `getRecords`, reject toolbox params carrying both a phrase and an external signer (`toolbox_aleo_conflicting_signers`), validate `feeRecordCredits`, and throw a clear `toolbox_aleo_no_rpc_urls` error when no RPC URL is configured.
98
+ - [#325](https://github.com/swapkit/sdk/pull/325) [`88aa0cc`](https://github.com/swapkit/sdk/commit/88aa0cc308af1010e5632a7fd9136e43ddbed6a4) Thanks [@paz-ts](https://github.com/paz-ts)! - toSignificant no longer corrupts values with long decimal parts: leading zeros are stripped as a string instead of through Number.parseInt, whose float round-trip rendered full-precision balances on 24-decimal chains like NEAR with two decimal points ("0.0003.2238") and silently lost digits past 2^53 on 18-decimal chains. (via @swapkit/helpers@4.18.0)
99
+ - Update generated token lists. (via @swapkit/helpers@4.18.0)
100
+
101
+ ## 4.24.1
102
+
103
+ ### Patch Changes
104
+
105
+ - [#306](https://github.com/swapkit/sdk/pull/306) [`be7e885`](https://github.com/swapkit/sdk/commit/be7e885d3779005b4a2e2e4d6560b2a1031994a3) Thanks [@towanTG](https://github.com/towanTG)! - Update generated token lists and preserve Maya address prefixes when signing THOR/Maya Amino messages.
106
+ - [#324](https://github.com/swapkit/sdk/pull/324) [`9641c5d`](https://github.com/swapkit/sdk/commit/9641c5d55b12e7e7263f4ef4d1c276eff9c866a9) Thanks [@towanTG](https://github.com/towanTG)! - Sweep hardening from post-merge adversarial review: EVM sweeps fail closed when the near-final gas probe is unaffordable instead of broadcasting with an under-validated gas limit; clamped Sui sweep budgets are dry-run verified so dust wallets cannot burn their balance on an insufficient budget; native TON sweeps throw the shared sweep guard for empty wallets; NEAR token-sweep gas shortfalls use the standard sweep error key.
107
+ - Update generated token lists. (via @swapkit/helpers@4.17.1)
108
+
109
+ ## 4.24.0
110
+
111
+ ### Minor Changes
112
+
113
+ - [#311](https://github.com/swapkit/sdk/pull/311) [`d787a38`](https://github.com/swapkit/sdk/commit/d787a38c6c96f36afde3964957409f4b2e4356a3) Thanks [@towanTG](https://github.com/towanTG)! - Add a `sweep` flag to `createTransaction` and `transfer` across all toolboxes. For native/gas assets, sweep sends the maximum spendable amount while keeping the sender account alive (fees, reserves, rent, existential deposits, and storage stakes are reserved per chain); for tokens, sweep resolves the full token balance. Also fixes Starknet balance decoding (uint256 halves order and decimals), the shared `GenericCreateTransactionParams` Omit, and the Chainflip EIP-7702 authorization signature type.
114
+
115
+ ### Patch Changes
116
+
117
+ - Updated dependencies [[`d787a38`](https://github.com/swapkit/sdk/commit/d787a38c6c96f36afde3964957409f4b2e4356a3)]:
118
+ - @swapkit/helpers@4.17.0
119
+
120
+ ## 4.23.1
121
+
122
+ ### Patch Changes
123
+
124
+ - [#317](https://github.com/swapkit/sdk/pull/317) [`41978a5`](https://github.com/swapkit/sdk/commit/41978a5601851ff5a72cb2a59495294dd04059a2) Thanks [@towanTG](https://github.com/towanTG)! - Replace dead THORChain default endpoints (thorchain.network, Nine Realms) with the official Liquify public gateway (gateway.liquify.com) for THORNode API, Tendermint RPC and Midgard (via @swapkit/helpers@4.16.2)
125
+
126
+ ## 4.23.0
127
+
128
+ ### Minor Changes
129
+
130
+ - [#315](https://github.com/swapkit/sdk/pull/315) [`b42ef37`](https://github.com/swapkit/sdk/commit/b42ef37d2510ffa6ffaf5f9e36ad13fa4881bbf7) Thanks [@towanTG](https://github.com/towanTG)! - Rename Robinhood Chain string identifier from RBH to HOOD. `Chain.Robinhood` now equals `"HOOD"`, the gas asset identifier is `HOOD.ETH`, and the EVM toolbox export is `HOODToolbox` (previously `RBHToolbox`). Chain ID (4663) and all other chain config values are unchanged. Anyone consuming the short-lived `"RBH"` string or `RBHToolbox` export from 4.16.0 must switch to `"HOOD"` / `HOODToolbox`.
131
+
132
+ ### Patch Changes
133
+
134
+ - Updated dependencies []:
135
+ - @swapkit/helpers@4.16.1
136
+
137
+ ## 4.22.0
4
138
 
5
139
  ### Minor Changes
6
140
 
7
- - [#311](https://github.com/swapkit/sdk/pull/311) [`d239525`](https://github.com/swapkit/sdk/commit/d239525d13b2855bff17130de2839fc06e440279) Thanks [@towanTG](https://github.com/towanTG)! - Add a `sweep` flag to `createTransaction` and `transfer` across all toolboxes. For native/gas assets, sweep sends the maximum spendable amount while keeping the sender account alive (fees, reserves, rent, existential deposits, and storage stakes are reserved per chain); for tokens, sweep resolves the full token balance. Also fixes Starknet balance decoding (uint256 halves order and decimals), the shared `GenericCreateTransactionParams` Omit, and the Chainflip EIP-7702 authorization signature type.
141
+ - [#313](https://github.com/swapkit/sdk/pull/313) [`d800a41`](https://github.com/swapkit/sdk/commit/d800a41b60219f2e792fd9e68761b4ae87240d4c) Thanks [@towanTG](https://github.com/towanTG)! - Add support for Robinhood Chain (RBH) — an Ethereum-compatible Arbitrum Orbit L2 (chain ID 4663) with ETH as the native gas token. Includes chain config, EVM toolbox (RBHToolbox), gas asset resolution (RBH.ETH), wallet network params, and explorer URLs via Blockscout. Default RPC is the public endpoint; production apps should configure a provider endpoint (e.g. QuickNode robinhood-mainnet) via SKConfig.setRpcUrl.
8
142
 
9
143
  ### Patch Changes
10
144
 
11
- - Updated dependencies [[`d239525`](https://github.com/swapkit/sdk/commit/d239525d13b2855bff17130de2839fc06e440279)]:
12
- - @swapkit/helpers@0.0.0-rc-20260713121307
145
+ - Updated dependencies [[`d800a41`](https://github.com/swapkit/sdk/commit/d800a41b60219f2e792fd9e68761b4ae87240d4c)]:
146
+ - @swapkit/helpers@4.16.0
13
147
 
14
148
  ## 4.21.0
15
149
 
@@ -0,0 +1,2 @@
1
+ import{fa as Ny}from"./chunk-nvfkjbyq.js";import{ga as Uy}from"./chunk-xbdjxeqd.js";import{Chain as H}from"@swapkit/helpers";import{match as b5}from"ts-pattern";import{Chain as $,getChainConfig as p,getRPCUrl as Wu,SKConfig as Qu,SwapKitError as c}from"@swapkit/helpers";import{FallbackProvider as Xu,getAddress as Hy,Interface as Yu,JsonRpcProvider as ty,Network as Zu}from"ethers";import{match as Ry}from"ts-pattern";function $u(y){return new ty(y)}async function X5(y,u){return $u(u||await Wu(y))}function ky(y){let u=Qu.get("rpcUrls")[y]?.filter(Boolean)??[];if(u.length===0)throw new c("helpers_chain_no_public_or_set_rpc_url",{chain:y});let{chainId:n}=p(y),t=Zu.from(Number(n)),[T]=u;if(u.length===1)return new ty(T,t,{staticNetwork:t});return new Xu(u.map((M,b)=>({priority:b+1,provider:new ty(M,t,{staticNetwork:t}),stallTimeout:2000})),t,{quorum:1})}function l(y){return y>0n?`0x${y.toString(16)}`:"0x0"}function Dy(y){let{explorerUrl:u,chainIdHex:n,rpcUrls:t}=p(y);return function(){return y!==$.Ethereum?{...Bu({chain:y}),blockExplorerUrls:[u],chainId:n,rpcUrls:t}:void 0}}function Ly(y){return![$.Adi,$.Arbitrum,$.BinanceSmartChain,$.Robinhood].includes(y)}function Bu({chain:y}){let{name:u,nativeCurrency:n,baseDecimal:t}=p(y);return Ry(y).with($.Arbitrum,()=>({chainName:"Arbitrum One",nativeCurrency:{decimals:t,name:"Ethereum",symbol:$.Ethereum}})).with($.Aurora,()=>({chainName:"Aurora Mainnet",nativeCurrency:{decimals:t,name:"Ethereum",symbol:$.Ethereum}})).with($.Avalanche,()=>({chainName:"Avalanche Network",nativeCurrency:{decimals:t,name:"Avalanche",symbol:y}})).with($.Base,()=>({chainName:"Base Mainnet",nativeCurrency:{decimals:t,name:"Ethereum",symbol:$.Ethereum}})).with($.Berachain,()=>({chainName:"Berachain",nativeCurrency:{decimals:t,name:"Berachain",symbol:"BERA"}})).with($.XLayer,()=>({chainName:"X Layer",nativeCurrency:{decimals:t,name:"OKB",symbol:"OKB"}})).with($.BinanceSmartChain,()=>({chainName:"BNB Smart Chain Mainnet",nativeCurrency:{decimals:t,name:"Binance Coin",symbol:"BNB"}})).with($.Gnosis,()=>({chainName:"Gnosis",nativeCurrency:{decimals:t,name:"xDAI",symbol:"XDAI"}})).with($.Optimism,()=>({chainName:"OP Mainnet",nativeCurrency:{decimals:t,name:"Ethereum",symbol:$.Ethereum}})).with($.Polygon,()=>({chainName:"Polygon Mainnet",nativeCurrency:{decimals:t,name:"Polygon",symbol:$.Polygon}})).with($.Robinhood,()=>({chainName:"Robinhood Chain",nativeCurrency:{decimals:t,name:"Ethereum",symbol:$.Ethereum}})).otherwise(()=>({chainName:u,nativeCurrency:{decimals:t,name:n,symbol:n}}))}async function zy(y,u){if(!("authorize"in y))throw Error("Signer does not support EIP-7702 authorization. Requires ethers.js v6.14+");let n={...u,nonce:u.nonce!==void 0?BigInt(u.nonce):void 0};return await y.authorize(n)}var Jy=(y)=>typeof y==="string"&&/^0x[a-fA-F0-9]{64}$/.test(y),Ju=(y)=>{try{return typeof y==="string"&&!!Hy(y)}catch{return!1}};function Hu(y,u){let n=u!==void 0?`index ${u}: `:"",t=(T,M)=>{throw new c({errorKey:"toolbox_evm_invalid_eip7702_authorization",info:{field:T,message:`${n}${M}`}})};Ry(y).when(({chainId:T})=>typeof T!=="bigint",()=>t("chainId","chainId must be a bigint")).when(({address:T})=>!Ju(T),()=>t("address","address must be a valid checksummed address")).when(({nonce:T})=>typeof T!=="bigint"||T<0n,()=>t("nonce","nonce must be a non-negative bigint")).when(({signature:T})=>!T,()=>t("signature","signature is required")).when(({signature:T})=>typeof T?.yParity!=="number"||![0,1].includes(T.yParity),()=>t("signature.yParity","yParity must be 0 or 1")).when(({signature:T})=>!Jy(T?.r),()=>t("signature.r","r must be a 32-byte hex string")).when(({signature:T})=>!Jy(T?.s),()=>t("signature.s","s must be a 32-byte hex string")).otherwise(()=>{})}function Ru(y){return[{key:"name",type:"string"},{key:"version",type:"string"},{key:"chainId",type:"uint256"},{key:"verifyingContract",type:"address"},{key:"salt",type:"bytes32"}].filter(({key:u})=>y[u]!=null).map(({key:u,type:n})=>({name:u,type:n}))}function Ty(y){return y.charAt(0).toUpperCase()+y.slice(1)}function My(y,u){if(y.isTuple()&&y.components){let n=Ty(y.name);return u[n]=y.components.map((t)=>({name:t.name,type:My(t,u)})),n}if(y.isArray()){let n=y.arrayChildren;if(n?.isTuple()&&n.components){let t=Ty(y.name.replace(/s$/,""));return u[t]=n.components.map((T)=>({name:T.name,type:My(T,u)})),`${t}[]`}return`${n?.type??"bytes"}[]`}return y.type}function by(y,u){if(typeof y==="bigint")return y;if(u?.isTuple()&&typeof y?.toObject==="function"){let n=y.toObject(),t={};for(let[T,M]of(u.components??[]).entries())t[M.name]=by(n[M.name]??y[T],M);return t}if(Array.isArray(y)){let n=u?.arrayChildren;return y.map((t)=>by(t,n??void 0))}return y}function Y5({chain:y,abi:u,data:n,to:t}){let M=new Yu(u).parseTransaction({data:n});if(!M)throw new c({errorKey:"toolbox_evm_invalid_params",info:{error:"Could not decode calldata"}});let b={},q=Ty(M.name);b[q]=M.fragment.inputs.map((X)=>({name:X.name,type:My(X,b)}));let W={};for(let[X,B]of M.fragment.inputs.entries())W[B.name]=by(M.args[X],B);let{chainId:Q}=p(y),U={chainId:Number(Q),verifyingContract:Hy(t)},k=Ru(U);return{domain:U,message:W,primaryType:q,types:{EIP712Domain:k,...b}}}function jy(y,u){if(!Array.isArray(y)||y.length===0)throw new c({errorKey:"toolbox_evm_invalid_eip7702_authorization",info:{message:"EIP-7702 transactions require at least one authorization"}});for(let[n,t]of y.entries())if(Hu(t,n),u!==void 0&&t.chainId!==u)throw new c({errorKey:"toolbox_evm_invalid_eip7702_authorization",info:{field:"chainId",message:`index ${n}: authorization chainId (${t.chainId}) does not match transaction chainId (${u})`}})}import{Chain as R,FeeOption as n5}from"@swapkit/helpers";import{HDNodeWallet as t5}from"ethers";import{match as T5,P as oy}from"ts-pattern";var Gy=[{inputs:[{components:[{internalType:"address",name:"target",type:"address"},{internalType:"bytes",name:"callData",type:"bytes"}],internalType:"struct Multicall2.Call[]",name:"calls",type:"tuple[]"}],name:"aggregate",outputs:[{internalType:"uint256",name:"blockNumber",type:"uint256"},{internalType:"bytes[]",name:"returnData",type:"bytes[]"}],stateMutability:"nonpayable",type:"function"},{inputs:[{components:[{internalType:"address",name:"target",type:"address"},{internalType:"bytes",name:"callData",type:"bytes"}],internalType:"struct Multicall2.Call[]",name:"calls",type:"tuple[]"}],name:"blockAndAggregate",outputs:[{internalType:"uint256",name:"blockNumber",type:"uint256"},{internalType:"bytes32",name:"blockHash",type:"bytes32"},{components:[{internalType:"bool",name:"success",type:"bool"},{internalType:"bytes",name:"returnData",type:"bytes"}],internalType:"struct Multicall2.Result[]",name:"returnData",type:"tuple[]"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"uint256",name:"blockNumber",type:"uint256"}],name:"getBlockHash",outputs:[{internalType:"bytes32",name:"blockHash",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[],name:"getBlockNumber",outputs:[{internalType:"uint256",name:"blockNumber",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"getCurrentBlockCoinbase",outputs:[{internalType:"address",name:"coinbase",type:"address"}],stateMutability:"view",type:"function"},{inputs:[],name:"getCurrentBlockDifficulty",outputs:[{internalType:"uint256",name:"difficulty",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"getCurrentBlockGasLimit",outputs:[{internalType:"uint256",name:"gaslimit",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"getCurrentBlockTimestamp",outputs:[{internalType:"uint256",name:"timestamp",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"addr",type:"address"}],name:"getEthBalance",outputs:[{internalType:"uint256",name:"balance",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"getLastBlockHash",outputs:[{internalType:"bytes32",name:"blockHash",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"bool",name:"requireSuccess",type:"bool"},{components:[{internalType:"address",name:"target",type:"address"},{internalType:"bytes",name:"callData",type:"bytes"}],internalType:"struct Multicall2.Call[]",name:"calls",type:"tuple[]"}],name:"tryAggregate",outputs:[{components:[{internalType:"bool",name:"success",type:"bool"},{internalType:"bytes",name:"returnData",type:"bytes"}],internalType:"struct Multicall2.Result[]",name:"returnData",type:"tuple[]"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bool",name:"requireSuccess",type:"bool"},{components:[{internalType:"address",name:"target",type:"address"},{internalType:"bytes",name:"callData",type:"bytes"}],internalType:"struct Multicall2.Call[]",name:"calls",type:"tuple[]"}],name:"tryBlockAndAggregate",outputs:[{internalType:"uint256",name:"blockNumber",type:"uint256"},{internalType:"bytes32",name:"blockHash",type:"bytes32"},{components:[{internalType:"bool",name:"success",type:"bool"},{internalType:"bytes",name:"returnData",type:"bytes"}],internalType:"struct Multicall2.Result[]",name:"returnData",type:"tuple[]"}],stateMutability:"nonpayable",type:"function"}];import{AssetValue as ku,applyFeeMultiplierToBigInt as j,Chain as K,EVMChains as Du,FeeOption as Y,isGasAsset as Lu,SwapKitError as Z,SwapKitNumber as s}from"@swapkit/helpers";import{erc20ABI as C}from"@swapkit/helpers/contracts";import{BrowserProvider as zu,Contract as _y,getAddress as i,getBytes as ju,Interface as Vy}from"ethers";import{match as wy}from"ts-pattern";function d(y){return{getBalance:Ny(y)}}function J5(y){return y}var Wy=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");function a({chain:y=K.Ethereum,provider:u,signer:n,isEIP1559Compatible:t=!0,estimateGasPrices:T,estimateAdditionalFee:M}){let b=T??m({chain:y,isEIP1559Compatible:t,provider:u}),q=fy({chain:y,estimateAdditionalFee:M,estimateGasPrices:b,isEIP1559Compatible:t,provider:u,signer:n});return{approve:Ou({chain:y,isEIP1559Compatible:t,provider:u,signer:n}),approvedAmount:ly({chain:y,provider:u}),broadcastTransaction:u.broadcastTransaction,call:yy({chain:y,isEIP1559Compatible:t,provider:u,signer:n}),createApprovalTx:hu({chain:y,provider:u,signer:n}),createContract:Nu({chain:y,provider:u}),createContractTxObject:h({chain:y,provider:u}),createTransaction:q,createTransferTx:q,EIP1193SendTransaction:r(u),estimateCall:Sy({provider:u,signer:n}),estimateGasLimit:xu({chain:y,provider:u,signer:n}),estimateGasPrices:b,estimateTransactionFee:mu({chain:y,isEIP1559Compatible:t,provider:u}),getAddress:()=>{return n?n.getAddress():void 0},getBalance:d(y).getBalance,getNetworkParams:Dy(y),isApproved:Ku({chain:y,provider:u}),sendTransaction:Oy({chain:y,estimateGasPrices:b,isEIP1559Compatible:t,provider:u,signer:n}),signAuthorization:Fu({signer:n}),signMessage:n?(W)=>n.signMessage(W):void 0,signTypedData:n?({domain:W,types:Q,value:U})=>n.signTypedData(W,Q,U):void 0,transfer:fu({chain:y,estimateAdditionalFee:M,estimateGasPrices:b,isEIP1559Compatible:t,provider:u,signer:n}),validateAddress:Gu}}function Gu(y){try{return i(y),!0}catch{return!1}}function e(y){return y instanceof zu}function Qy(y,u,n){return new _y(y,Vy.from(u),n)}function Nu({provider:y}){return function(n,t){return new _y(n,Vy.from(t),y)}}var _u=["payable","nonpayable"];function Vu({abi:y,funcName:u}){let n=y.find((t)=>t.name===u);if(!n)throw new Z("toolbox_evm_no_abi_fragment",{funcName:u});return n.stateMutability&&_u.includes(n.stateMutability)}function G5(y){return i(y)}function r(y,u=!1){return function({value:t,...T}){if(!e(y))throw new Z("toolbox_evm_provider_not_eip1193_compatible");let M={...T,gasPrice:"gasPrice"in T?T.gasPrice:void 0,maxFeePerGas:"maxFeePerGas"in T?T.maxFeePerGas:void 0,maxPriorityFeePerGas:"maxPriorityFeePerGas"in T?T.maxPriorityFeePerGas:void 0},{gasLimit:b,gasPrice:q,maxFeePerGas:W,maxPriorityFeePerGas:Q,...U}=M,k={...U,...u&&b!==void 0&&{gas:l(BigInt(b))},...u&&q!==void 0&&{gasPrice:l(BigInt(q))},...u&&W!==void 0&&{maxFeePerGas:l(BigInt(W))},...u&&Q!==void 0&&{maxPriorityFeePerGas:l(BigInt(Q))},value:l(BigInt(t||0))};return y.send("eth_sendTransaction",[k])}}function N5(y,u){let n=Xy(y,u);if(n)return i(n.toLowerCase());throw new Z("toolbox_evm_invalid_gas_asset_address")}var wu=Du.reduce((y,u)=>{return y[u]="0x0000000000000000000000000000000000000000",y},{}),lu={...wu,[K.Optimism]:"0x4200000000000000000000000000000000000042",[K.Polygon]:"0x0000000000000000000000000000000000001010"},Su=[K.Arbitrum,K.Aurora,K.Base,K.Optimism,K.Robinhood];function Xy({chain:y,symbol:u,ticker:n},t){try{let T=y===K.BinanceSmartChain&&u==="BNB"&&n==="BNB",M=y===K.Hyperevm&&u==="HYPE"&&n==="HYPE",b=y===t&&u===t&&n===t,q=Su.includes(y)&&u==="ETH"&&n==="ETH";if(b||T||M||q)return lu[t];return i(u.slice(n.length+1).replace(/^0X/,""))}catch{return null}}function h({provider:y}){return async({contractAddress:u,abi:n,funcName:t,funcParams:T=[],txOverrides:M})=>{let b=await Qy(u,n,y).getFunction(t).populateTransaction(...T.concat(M).filter((q)=>typeof q<"u"));return{...b,value:l(BigInt(b.value||0))}}}function m({chain:y,provider:u,isEIP1559Compatible:n=!0}){return wy(y).with(K.Gnosis,()=>{return async function(){try{let{gasPrice:T,maxPriorityFeePerGas:M}=await u.getFeeData();if(!T||M===null)throw new Z("toolbox_evm_no_fee_data");return{[Y.Average]:{maxFeePerGas:j(T,Y.Average),maxPriorityFeePerGas:j(M,Y.Average)},[Y.Fast]:{maxFeePerGas:j(T,Y.Fast),maxPriorityFeePerGas:j(M,Y.Fast)},[Y.Fastest]:{maxFeePerGas:j(T,Y.Fastest),maxPriorityFeePerGas:j(M,Y.Fastest)}}}catch(T){throw new Z("toolbox_evm_gas_estimation_error",{error:T.msg??T.toString()})}}}).with(K.Arbitrum,()=>{return async function(){try{let{gasPrice:T}=await u.getFeeData();if(!T)throw new Z("toolbox_evm_no_fee_data");let M=T*12n/10n;return{[Y.Average]:{gasPrice:M},[Y.Fast]:{gasPrice:j(M,Y.Fast)},[Y.Fastest]:{gasPrice:j(M,Y.Fastest)}}}catch(T){throw new Z("toolbox_evm_gas_estimation_error",{error:T.msg??T.toString()})}}}).otherwise(()=>{return async function(){try{let{maxFeePerGas:T,maxPriorityFeePerGas:M,gasPrice:b}=await u.getFeeData();if(n){if(T===null||M===null)throw new Z("toolbox_evm_no_fee_data");return{[Y.Average]:{maxFeePerGas:T,maxPriorityFeePerGas:M},[Y.Fast]:{maxFeePerGas:j(T,Y.Fast),maxPriorityFeePerGas:j(M,Y.Fast)},[Y.Fastest]:{maxFeePerGas:j(T,Y.Fastest),maxPriorityFeePerGas:j(M,Y.Fastest)}}}if(!b)throw new Z("toolbox_evm_no_gas_price");return{[Y.Average]:{gasPrice:b},[Y.Fast]:{gasPrice:j(b,Y.Fast)},[Y.Fastest]:{gasPrice:j(b,Y.Fastest)}}}catch(T){throw new Z("toolbox_evm_gas_estimation_error",{error:T.msg??T.toString()})}}})}function yy({provider:y,isEIP1559Compatible:u,signer:n,chain:t}){return async function({callProvider:M,contractAddress:b,abi:q,funcName:W,funcParams:Q=[],txOverrides:U={},feeOption:k=Y.Fast}){let X=M||y;if(!b)throw new Z("toolbox_evm_invalid_params",{error:"contractAddress must be provided"});let B=Vu({abi:q,funcName:W});if(B&&e(X)&&n){let z=h({chain:t,provider:X}),O=U?.from||await n?.getAddress(),G=await z({abi:q,contractAddress:b,funcName:W,funcParams:Q,txOverrides:{...U,from:O}});return r(X)(G)}let J=Qy(b,q,X);if(B){if(!n)throw new Z("toolbox_evm_no_signer");let z=U?.from||await n.getAddress();if(!z)throw new Z("toolbox_evm_no_signer_address");let O=J.connect(n),G=m({chain:t,isEIP1559Compatible:u,provider:y}),[{maxFeePerGas:N,maxPriorityFeePerGas:I,gasPrice:x},_,F]=await Promise.all([G().then((V)=>V[k]),J.getFunction(W).estimateGas(...Q,U),U?.nonce!==void 0?Promise.resolve(U.nonce):X.getTransactionCount(z)]),S=await O[W](...Q,{...U,gasLimit:_,gasPrice:x,maxFeePerGas:N,maxPriorityFeePerGas:I,nonce:F});return typeof S?.hash==="string"?S?.hash:S}let D=await J[W]?.(...Q);return typeof D?.hash==="string"?D?.hash:D}}function ly({provider:y,chain:u}){return function({assetAddress:t,spenderAddress:T,from:M}){return yy({chain:u,isEIP1559Compatible:!0,provider:y})({abi:C,contractAddress:t,funcName:"allowance",funcParams:[M,T]})}}function Ku({provider:y,chain:u}){return async function({assetAddress:t,spenderAddress:T,from:M,amount:b=Wy}){let q=await ly({chain:u,provider:y})({assetAddress:t,from:M,spenderAddress:T});return s.fromBigInt(q).gte(s.fromBigInt(BigInt(b)))}}function Ou({signer:y,isEIP1559Compatible:u=!0,provider:n,chain:t}){return async function({assetAddress:M,spenderAddress:b,feeOptionKey:q=Y.Fast,amount:W,gasLimitFallback:Q,from:U,nonce:k}){let X=[b,BigInt(W||Wy)],B=await y?.getAddress()||U,J={abi:C,contractAddress:M,funcName:"approve",funcParams:X,signer:y,txOverrides:{from:B}};if(e(n)){let z=h({chain:t,provider:n}),O=r(n),G=await z(J);return O(G)}return yy({chain:t,isEIP1559Compatible:u,provider:n,signer:y})({...J,feeOption:q,funcParams:X,txOverrides:{from:B,gasLimit:Q?BigInt(Q.toString()):void 0,nonce:k}})}}function fu({chain:y,estimateGasPrices:u,estimateAdditionalFee:n,signer:t,isEIP1559Compatible:T=!0,provider:M}){return async function({assetValue:q,memo:W,recipient:Q,feeOptionKey:U=Y.Fast,sender:k,sweep:X,...B}){let J=k||await t?.getAddress(),D=Oy({chain:y,estimateGasPrices:u,isEIP1559Compatible:T,provider:M,signer:t});if(!J)throw new Z("toolbox_evm_no_from_address");let z=await fy({chain:y,estimateAdditionalFee:n,estimateGasPrices:u,isEIP1559Compatible:T,provider:M,signer:t})({assetValue:q,feeOptionKey:U,memo:W,recipient:Q,sender:J,sweep:X,...B});return D({...z,feeOptionKey:U,sweep:X})}}function Sy({provider:y,signer:u}){return function({contractAddress:t,abi:T,funcName:M,funcParams:b=[],txOverrides:q}){if(!t)throw new Z("toolbox_evm_no_contract_address");let W=Qy(t,T,y);return u?W.connect(u).getFunction(M).estimateGas(...b,q):W.getFunction(M).estimateGas(...b,q)}}function xu({provider:y,signer:u}){return async function({assetValue:t,recipient:T,memo:M,data:b,sender:q,funcName:W,funcParams:Q,txOverrides:U}){let k=t.bigIntValue,X=t.isGasAsset?null:Xy(t,t.chain);if(X&&W)return Sy({provider:y,signer:u})({abi:C,contractAddress:X,funcName:W,funcParams:Q,txOverrides:U});let{hexlify:B,toUtf8Bytes:J}=await import("ethers");return y.estimateGas({data:b?b:M?B(J(M)):void 0,from:q,to:T,value:k})}}function Fu({signer:y}){if(!y)return;return(u)=>zy(y,u)}var Ky=(y)=>y.type===4||(y.authorizations?.length??0)>0,Iu=(y)=>!Ky(y)&&(y.type===2||!!y.maxFeePerGas||!!y.maxPriorityFeePerGas),Eu=(y,u=!0)=>{if(Ky(y))return"eip7702";if(Iu(y)||u)return"eip1559";return"legacy"};function Au(y,u){if(y==="legacy"){if(u.gasPrice===void 0)throw new Z("toolbox_evm_no_fee_data");return{gasPrice:l(u.gasPrice)}}if(u.maxFeePerGas===void 0||u.maxPriorityFeePerGas===void 0)throw new Z("toolbox_evm_no_fee_data");return{maxFeePerGas:l(u.maxFeePerGas),maxPriorityFeePerGas:l(u.maxPriorityFeePerGas)}}function Oy({chain:y,estimateGasPrices:u,provider:n,signer:t,isEIP1559Compatible:T=!0}){return async function({feeOptionKey:b=Y.Fast,sweep:q,...W}){let{from:Q,to:U,data:k,value:X,...B}=W;if(!t)throw new Z("toolbox_evm_no_signer");if(!U)throw new Z("toolbox_evm_no_to_address");let J={...B,data:k||"0x",from:Q,to:U,value:BigInt(X||0)};if(e(n))return r(n,q)(J);let D=Q||await t.getAddress(),[z,O]=await Promise.all([W.nonce!==void 0?Promise.resolve(W.nonce):n.getTransactionCount(D),n.getNetwork()]),G=O.chainId,N=Eu(J,T);if(N==="eip7702")jy(J.authorizations||[],G);let I=wy(N).with("eip7702",()=>4).with("eip1559",()=>2).otherwise(()=>0),x={...J,chainId:G,nonce:z,type:I,...N==="eip7702"&&{authorizationList:J.authorizations}},_=u??m({chain:y,isEIP1559Compatible:T,provider:n}),S=(N==="legacy"?J.gasPrice!==void 0:J.maxFeePerGas!==void 0&&J.maxPriorityFeePerGas!==void 0)?{}:Au(N,(await _())[b]),V;try{V=l(J.gasLimit?BigInt(J.gasLimit):await n.estimateGas(x)*11n/10n)}catch(w){throw new Z("toolbox_evm_error_estimating_gas_limit",{error:w})}try{let w={...x,gasLimit:V,...S};try{return(await t.sendTransaction(w)).hash}catch{let E=await t.signTransaction({...w,from:D});return(await n.broadcastTransaction(E)).hash}}catch(w){throw new Z("toolbox_evm_error_sending_transaction",{error:w})}}}function A(y,u){throw new Z({errorKey:"toolbox_sweep_amount_too_low",info:{balance:y.toString(),fee:u.toString()}})}function Pu(y,u){if(u){if(y.maxFeePerGas===void 0||y.maxPriorityFeePerGas===void 0)throw new Z("toolbox_evm_no_fee_data");return{feeFields:{maxFeePerGas:y.maxFeePerGas,maxPriorityFeePerGas:y.maxPriorityFeePerGas},feePerGas:y.maxFeePerGas}}if(y.gasPrice===void 0)throw new Z("toolbox_evm_no_fee_data");return{feeFields:{gasPrice:y.gasPrice},feePerGas:y.gasPrice}}function Cu(y,u){if(y>u)return y;return u}function ou(y){return ju(y).reduce((u,n)=>u+(n===0?4n:16n),21000n)}function qy(y){let n=(y instanceof Error?y.message:String(y)).toLowerCase();return n.includes("insufficient funds")||n.includes("insufficient balance")||n.includes("gas required exceeds allowance")}async function gu({balance:y,estimateAdditionalFee:u,feeOptionKey:n,l2Reserve:t,sweepTx:T,valueBeforeL1Fee:M}){if(!u)return 0n;let b=await u({...T,value:M})??0n,q=j(b,n),W=M-q;if(W<=0n)A(y,t+q);let Q=await u({...T,value:W})??b;return j(Cu(b,Q),n)}async function vu({chain:y,data:u,estimateGasPrices:n,estimateAdditionalFee:t,feeOptionKey:T,from:M,isEIP1559Compatible:b,provider:q,recipient:W,transaction:Q}){let U=await q.getBalance(M),k=n??m({chain:y,isEIP1559Compatible:b,provider:q}),{feeFields:X,feePerGas:B}=Pu((await k())[T],b),D={...t&&Q.nonce===void 0?{...Q,nonce:await q.getTransactionCount(M)}:Q,...X,data:u,from:M,to:W},z=ou(u)*B;if(U-z<=0n)A(U,z);let O=(U-z)/2n,G;try{G=await q.estimateGas({...D,value:O})}catch(v){if(!qy(v))throw v;try{G=await q.estimateGas({...D,value:0n})}catch(By){if(qy(By))A(U,z);throw By}}let N=G*B;if(U-N<=0n)A(U,N);let _=G*11n/10n*B,F=U>_?U-_:0n,S;try{S=await q.estimateGas({...D,value:F})}catch(v){if(!qy(v))throw v;A(U,_)}let V=S*B,w=U-V;if(w<=0n)A(U,V);let E=await gu({balance:U,estimateAdditionalFee:t,feeOptionKey:T,l2Reserve:V,sweepTx:{...D,gasLimit:S},valueBeforeL1Fee:w}),P=w-E;if(P<=0n)A(U,V+E);return{...D,gasLimit:S,value:l(P)}}async function cu({chain:y,contractAddress:u,from:n,provider:t}){let T=await yy({chain:y,provider:t})({abi:C,contractAddress:u,funcName:"balanceOf",funcParams:[n]});if(typeof T!=="bigint")throw new Z({errorKey:"toolbox_evm_invalid_transaction",info:{error:"Invalid ERC20 balance"}});return T}function fy({chain:y,estimateAdditionalFee:u,estimateGasPrices:n,isEIP1559Compatible:t=!0,provider:T,signer:M}){return async function({assetValue:q,authorizations:W,memo:Q,recipient:U,data:k,feeOptionKey:X=Y.Fast,gasLimit:B,sender:J,sweep:D,type:z,maxFeePerGas:O,maxPriorityFeePerGas:G,gasPrice:N,...I}){let x=q.getBaseValue("bigint"),_=J||await M?.getAddress();if(!_)throw new Z("toolbox_evm_no_from_address");if(D&&(z===4||(W?.length??0)>0))throw new Z({errorKey:"toolbox_not_supported",info:{chain:y,reason:"EIP-7702 sweep transactions are not supported"}});if(Lu(q)){let{hexlify:w,toUtf8Bytes:E}=await import("ethers"),P=k||w(E(Q||""));if(!D)return{...I,...W!==void 0&&{authorizations:W},data:P,from:_,...B!==void 0&&{gasLimit:B},to:U,...z!==void 0&&{type:z},value:l(x)};return vu({chain:y,data:P,estimateAdditionalFee:u,estimateGasPrices:n,feeOptionKey:X,from:_,isEIP1559Compatible:t,provider:T,recipient:U,transaction:{nonce:I.nonce,type:z}})}let F=Xy(q,y);if(!F)throw new Z("toolbox_evm_no_contract_address");let S=h({chain:y,provider:T}),V=D?await cu({chain:y,contractAddress:F,from:_,provider:T}):x;if(D&&V<=0n)throw new Z({errorKey:"toolbox_sweep_amount_too_low",info:{asset:q.toString(),balance:V.toString()}});return S({abi:C,contractAddress:F,funcName:"transfer",funcParams:[U,V],txOverrides:{from:_,gasLimit:B,gasPrice:N,maxFeePerGas:O,maxPriorityFeePerGas:G}})}}function hu({provider:y,signer:u,chain:n}){return async function({assetAddress:T,spenderAddress:M,amount:b,from:q}){let W=await u?.getAddress()||q,Q=h({chain:n,provider:y}),U=["bigint","number"].includes(typeof b)?b:b||Wy;return await Q({abi:C,contractAddress:T,funcName:"approve",funcParams:[M,BigInt(U)],txOverrides:{from:W}})}}function mu({provider:y,isEIP1559Compatible:u=!0,chain:n}){return async function({feeOption:T=Y.Fast,...M}){let q=await m({chain:n,isEIP1559Compatible:u,provider:y})(),W=await y.estimateGas(M),Q=ku.from({chain:n}),{gasPrice:U,maxFeePerGas:k,maxPriorityFeePerGas:X}=q[T];if(!u&&U)return Q.set(s.fromBigInt(U*W,Q.decimal));if(k&&X){let B=(k+X)*W;return Q.set(s.fromBigInt(B,Q.decimal))}throw new Z("toolbox_evm_no_gas_price")}}import{applyFeeMultiplierToBigInt as o,Chain as Iy,FeeOption as f,getChainConfig as pu,SwapKitError as g}from"@swapkit/helpers";import{Contract as du,HDNodeWallet as su}from"ethers";import{match as iu,P as Fy}from"ts-pattern";var xy=[{inputs:[{internalType:"address",name:"_owner",type:"address"}],stateMutability:"nonpayable",type:"constructor"},{anonymous:!1,inputs:[{indexed:!1,internalType:"uint256",name:"",type:"uint256"}],name:"DecimalsUpdated",type:"event"},{anonymous:!1,inputs:[{indexed:!1,internalType:"uint256",name:"",type:"uint256"}],name:"GasPriceUpdated",type:"event"},{anonymous:!1,inputs:[{indexed:!1,internalType:"uint256",name:"",type:"uint256"}],name:"L1BaseFeeUpdated",type:"event"},{anonymous:!1,inputs:[{indexed:!1,internalType:"uint256",name:"",type:"uint256"}],name:"OverheadUpdated",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"previousOwner",type:"address"},{indexed:!0,internalType:"address",name:"newOwner",type:"address"}],name:"OwnershipTransferred",type:"event"},{anonymous:!1,inputs:[{indexed:!1,internalType:"uint256",name:"",type:"uint256"}],name:"ScalarUpdated",type:"event"},{inputs:[],name:"decimals",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"gasPrice",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"bytes",name:"_data",type:"bytes"}],name:"getL1Fee",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"bytes",name:"_data",type:"bytes"}],name:"getL1GasUsed",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"uint256",name:"_gasUsed",type:"uint256"}],name:"getOperatorFee",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"l1BaseFee",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"overhead",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"owner",outputs:[{internalType:"address",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[],name:"renounceOwnership",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"scalar",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"uint256",name:"_decimals",type:"uint256"}],name:"setDecimals",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"uint256",name:"_gasPrice",type:"uint256"}],name:"setGasPrice",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"uint256",name:"_baseFee",type:"uint256"}],name:"setL1BaseFee",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"uint256",name:"_overhead",type:"uint256"}],name:"setOverhead",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"uint256",name:"_scalar",type:"uint256"}],name:"setScalar",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"newOwner",type:"address"}],name:"transferOwnership",outputs:[],stateMutability:"nonpayable",type:"function"}];var au="0x420000000000000000000000000000000000000f";function uy(y){return new du(au,xy,y)}function Ey(y){return async function(){let n=uy(y);if(n&&"l1BaseFee"in n)return await n?.l1BaseFee();return}}function Ay(y){return async function({from:n,to:t,nonce:T,...M}){let{Transaction:b}=await import("ethers");if(!t)throw new g("toolbox_evm_invalid_transaction",{error:"Missing to address"});return b.from({...M,authorizationList:M.authorizationList,nonce:T??(n?await y.getTransactionCount(n):0),to:t}).unsignedSerialized}}function Yy(y,u){return async function(t){let T=uy(y),M=t.chainId??u??(await y.getNetwork()).chainId,b=await Ay(y)({...t,chainId:M});if(T&&"getL1Fee"in T){let q=await T.getL1Fee(b);if(typeof q!=="bigint")throw new g({errorKey:"toolbox_evm_invalid_transaction",info:{error:"Invalid OP-stack L1 fee"}});return q}return}}function Zy(y){return async function(n){let t=uy(y);if(t&&"getOperatorFee"in t){let T=await t.getOperatorFee(n);if(typeof T!=="bigint")throw new g({errorKey:"toolbox_evm_invalid_transaction",info:{error:"Invalid OP-stack operator fee"}});return T}return 0n}}function eu(y,u){let n=Yy(y,u),t=Zy(y);return async function(M){if(M.gasLimit===void 0||M.gasLimit===null)throw new g({errorKey:"toolbox_evm_invalid_transaction",info:{error:"Missing gas limit for OP-stack fee estimation"}});let[b,q]=await Promise.all([n(M),t(BigInt(M.gasLimit.toString()))]);return(b??0n)+q}}function Py(y){return async function(n){let T=(await y.getFeeData()).gasPrice??0n,M=await y.estimateGas(n);return T*M}}function ru(y){return async function(n){let t=await Yy(y)(n)??0n,T=await Py(y)(n),M=n.gasLimit??await y.estimateGas(n),b=await Zy(y)(BigInt(M.toString()));return t+T+b}}function y5(y){return async function(n){let t=uy(y),T=await Ay(y)(n);if(t&&"getL1GasUsed"in t)return t.getL1GasUsed(T)}}function u5(y){return async function(){try{let{maxFeePerGas:n,maxPriorityFeePerGas:t,gasPrice:T}=await y.getFeeData(),M=await Ey(y)(),b=T;if(!(n&&t))throw new g("toolbox_evm_no_fee_data");return{[f.Average]:{gasPrice:b,l1GasPrice:M,maxFeePerGas:n,maxPriorityFeePerGas:t},[f.Fast]:{gasPrice:o(b,f.Fast),l1GasPrice:o(M||0n,f.Fast),maxFeePerGas:n,maxPriorityFeePerGas:o(t,f.Fast)},[f.Fastest]:{gasPrice:o(b,f.Fastest),l1GasPrice:o(M||0n,f.Fastest),maxFeePerGas:n,maxPriorityFeePerGas:o(t,f.Fastest)}}}catch(n){throw new g("toolbox_evm_gas_estimation_error",{error:n.msg??n.toString()})}}}function ny(y){return function({provider:n,...t}){let T=iu(t).with({phrase:Fy.string},({phrase:X})=>su.fromPhrase(X).connect(n)).with({signer:Fy.any},({signer:X})=>X).otherwise(()=>{return}),M=Ey(n),b=BigInt(pu(y).chainId),q=Yy(n,b),W=eu(n,b),Q=Zy(n),U=y===Iy.Optimism?u5(n):void 0;return{...a({chain:y,estimateAdditionalFee:W,estimateGasPrices:U,provider:n,signer:T}),estimateL1Gas:y5(n),estimateL1GasCost:q,estimateL2GasCost:Py(n),estimateOperatorFee:Q,estimateTotalGasCost:ru(n),getBalance:d(y).getBalance,getL1GasPrice:M}}}var Cy=ny(Iy.Optimism);function gy(y){let u=L(R.Ethereum)(y);async function n(t,T="0x5ba1e12693dc8f9c48aad8770482f4739beed696",M="aggregate",b=n5.Fast){let q=await u.createContractTxObject({abi:Gy,contractAddress:T,funcName:M,funcParams:[t]});return u.sendTransaction({...q,feeOptionKey:b})}return{...u,multicall:n}}var vy=L(R.Adi),cy=L(R.Arbitrum),hy=L(R.Aurora),my=L(R.Avalanche),py=ny(R.Base),dy=L(R.Berachain),sy=L(R.BinanceSmartChain),g5=L(R.Botanix),iy=L(R.Core),ay=L(R.Corn),ey=L(R.Cronos),ry=L(R.Gnosis),yu=L(R.Robinhood),uu=L(R.Hyperevm),nu=L(R.Linea),tu=L(R.Polygon),Tu=L(R.MegaETH),Mu=L(R.Monad),bu=L(R.Plasma),$y=L(R.Sonic),qu=ny(R.Unichain),Uu=L(R.XLayer);function L(y){return function({provider:n,...t}){let T=Ly(y),M=T5(t).with({phrase:oy.string},({phrase:q})=>t5.fromPhrase(q).connect(n)).with({signer:oy.any},({signer:q})=>q).otherwise(()=>{return});return a({chain:y,isEIP1559Compatible:T,provider:n,signer:M})}}function q5(y,u){return b5(y).with(H.Adi,()=>vy(u)).with(H.Arbitrum,()=>cy(u)).with(H.Aurora,()=>hy(u)).with(H.Avalanche,()=>my(u)).with(H.Base,()=>py(u)).with(H.Berachain,()=>dy(u)).with(H.BinanceSmartChain,()=>sy(u)).with(H.Botanix,()=>$y(u)).with(H.Core,()=>iy(u)).with(H.Corn,()=>ay(u)).with(H.Cronos,()=>ey(u)).with(H.Ethereum,()=>gy(u)).with(H.Gnosis,()=>ry(u)).with(H.Hyperevm,()=>uu(u)).with(H.Linea,()=>nu(u)).with(H.MegaETH,()=>Tu(u)).with(H.Monad,()=>Mu(u)).with(H.Optimism,()=>Cy(u)).with(H.Plasma,()=>bu(u)).with(H.Polygon,()=>tu(u)).with(H.Robinhood,()=>yu(u)).with(H.Sonic,()=>$y(u)).with(H.Unichain,()=>qu(u)).with(H.XLayer,()=>Uu(u)).exhaustive()}async function p5(y,u){let n={...u,provider:u?.provider||ky(y)};return q5(y,n)}
2
+ export{d as b,J5 as c,$u as d,X5 as e,ky as f,l as g,Dy as h,Ly as i,zy as j,Hu as k,Ru as l,Y5 as m,jy as n,Wy as o,a as p,Gu as q,e as r,Qy as s,Nu as t,Vu as u,G5 as v,r as w,N5 as x,lu as y,Xy as z,h as A,m as B,Ky as C,Iu as D,Eu as E,ny as F,Cy as G,gy as H,vy as I,cy as J,hy as K,my as L,py as M,dy as N,sy as O,g5 as P,iy as Q,ay as R,ey as S,ry as T,yu as U,uu as V,nu as W,tu as X,Tu as Y,Mu as Z,bu as _,$y as $,qu as aa,Uu as ba,q5 as ca,p5 as da};
@@ -1,2 +1,2 @@
1
1
  import{AssetValue as o,getChainConfig as l}from"@swapkit/helpers";import{SwapKitApi as m}from"@swapkit/helpers/api";var d=typeof process<"u"&&process.pid?process.pid.toString(36):"",i=0;function C(){function t(){let e=Date.now(),n=i||e;return i=n,e>i?e:n+1}return d+t().toString(36)}function h(t){return async function(n,r=!0){let c=await m.getChainBalance({address:n,chain:t,scamFilter:r}),{baseDecimal:p}=l(t),s=c.map(({identifier:a,value:u,decimal:f})=>{return new o({decimal:f||p,identifier:a,value:u})});if(!s.some((a)=>a.isGasAsset))return[o.from({chain:t}),...s];return s}}
2
- export{C as da,h as ea};
2
+ export{C as ea,h as fa};
@@ -0,0 +1 @@
1
+ import{$ as N,A as m,B as n,C as o,D as p,E as q,F as r,G as s,H as t,I as u,J as v,K as w,L as x,M as y,N as z,O as A,P as B,Q as C,R as D,S as E,T as F,U as G,V as H,W as I,X as J,Y as K,Z as L,_ as M,aa as O,ba as P,ca as Q,da as R,o as a,p as b,q as c,r as d,s as e,t as f,u as g,v as h,w as i,x as j,y as k,z as l}from"./chunk-55jkfkar.js";import"./chunk-nvfkjbyq.js";import"./chunk-xbdjxeqd.js";export{c as validateEVMAddress,h as toChecksumAddress,g as isStateChangingCall,o as isEIP7702Transaction,p as isEIP1559Transaction,d as isBrowserProvider,l as getTokenAddress,R as getEvmToolboxAsync,Q as getEvmToolbox,n as getEstimateGasPrices,q as getEVMTxType,i as getEIP1193SendTransaction,m as getCreateContractTxObject,f as getCreateContract,j as getChecksumAddressFromAsset,r as createOPStackToolbox,e as createContract,P as XLayerToolbox,O as UNIToolbox,N as SONICToolbox,M as PLASMAToolbox,s as OPToolbox,L as MONADToolbox,K as MEGAETHToolbox,a as MAX_APPROVAL,J as MATICToolbox,I as LINEAToolbox,H as HYPEREVMToolbox,G as HOODToolbox,F as GNOToolbox,t as ETHToolbox,k as ContractAddress,E as CROToolbox,D as CORNToolbox,C as COREToolbox,B as BotanixToolbox,b as BaseEVMToolbox,A as BSCToolbox,z as BERAToolbox,y as BASEToolbox,x as AVAXToolbox,w as AURORAToolbox,v as ARBToolbox,u as ADIToolbox};
@@ -1,2 +1,2 @@
1
1
  var d=((a)=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(a,{get:(b,c)=>(typeof require<"u"?require:b)[c]}):a)(function(a){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+a+'" is not supported')});
2
- export{d as fa};
2
+ export{d as ga};
@@ -0,0 +1 @@
1
+ import{fa as zJ}from"../../chunk-nvfkjbyq.js";import{ga as b}from"../../chunk-xbdjxeqd.js";import{hmac as s}from"@noble/hashes/hmac.js";import{sha512 as t}from"@noble/hashes/sha2.js";import{Chain as h,getChainConfig as BJ,SKConfig as DJ,SwapKitError as B}from"@swapkit/helpers";var kJ=/^aleo1[ac-hj-np-z02-9]{58}$/,MJ=/^[a-z0-9_]+\.aleo$/,T=/^at1[ac-hj-np-z02-9]+$/,xJ=new TextEncoder().encode("bls12_377 seed"),o=2147483648,A=1e6,f="credits.aleo",R="transfer_public",a=1e6,e=2000000;function r(J,Z){if(!M(J))return[];let Y=M(J.transaction)?J.transaction:J,W=Y.execution,z=M(Y.fee)?Y.fee.transition:void 0;return[...M(W)&&Array.isArray(W.transitions)?W.transitions:[],...M(z)?[z]:[]].flatMap((P)=>{if(!M(P)||!Array.isArray(P.outputs))return[];if(Z&&P.program!==Z)return[];return P.outputs.flatMap((O)=>M(O)&&O.type==="record"&&typeof O.value==="string"?[O.value]:[])})}function JJ(J){return J.reduce((Z,Y)=>Y.spent?Z:Z+Y.microcredits,0n)}function x(J,Z){return Z instanceof B&&Z.errorKey.startsWith("toolbox_aleo_")?Z:new B(J,Z)}function OJ(...J){let Z=J.reduce((z,U)=>z+U.length,0),Y=new Uint8Array(Z),W=0;for(let z of J)Y.set(z,W),W+=z.length;return Y}function bJ(J){let Z=new Uint8Array(4);return new DataView(Z.buffer).setUint32(0,J,!1),Z}function PJ(J){let Z=s(t,xJ,J);return{chainCode:Z.slice(32),key:Z.slice(0,32)}}function yJ(J,Z){if(!Number.isSafeInteger(Z)||Z<0||Z>=o)throw new B("toolbox_aleo_wasm_init_failed",{index:Z});let Y=Z+o,W=OJ(Uint8Array.of(0),J.key,bJ(Y)),z=s(t,J.chainCode,W);return{chainCode:z.slice(32),key:z.slice(0,32)}}function QJ(J,Z){let Y=J.split("/");if(Y.shift()!=="m"||Y.length===0)throw new B("toolbox_aleo_wasm_init_failed",{path:J});return Y.reduce((W,z)=>{if(!/^\d+'$/.test(z))throw new B("toolbox_aleo_wasm_init_failed",{path:J,segment:z});return yJ(W,Number.parseInt(z.slice(0,-1),10))},PJ(Z))}function S(J){return typeof J==="string"&&kJ.test(J)}async function ZJ(J){if(!S(J))return!1;try{let{Account:Z}=await import("@provablehq/sdk/mainnet.js");return Z.isValidAddress(J)}catch{return!1}}function VJ(J){return MJ.test(J)}function $J(J,Z){if(J===null)return 0n;if(typeof J!=="string")throw new B("toolbox_aleo_balance_error",{integerType:Z,value:J});let Y=J.match(new RegExp(`^(\\d+)${Z}$`));if(!Y?.[1])throw new B("toolbox_aleo_balance_error",{integerType:Z,value:J});return BigInt(Y[1])}function E(J){if(J.chain!==h.Aleo)throw new B("toolbox_aleo_unsupported_token",{asset:J.toString()});let Z=J.getBaseValue("bigint");if(J.isGasAsset)return{amount:`${Z}u64`,functionName:R,isTokenTransfer:!1,programName:f};if(!J.address||!VJ(J.address))throw new B("toolbox_aleo_unsupported_token",{asset:J.toString()});return{amount:`${Z}u128`,functionName:R,isTokenTransfer:!0,programName:J.address}}function K(){let J=[...new Set([...DJ.get("rpcUrls")[h.Aleo],...BJ(h.Aleo).rpcUrls])].filter(Boolean);if(J.length===0)throw new B("toolbox_aleo_no_rpc_urls");return J}function m(J){if(typeof J==="object"&&J!==null&&"status"in J&&J.status===404)return!0;return J instanceof Error&&J.message.includes("404")}function M(J){return typeof J==="object"&&J!==null}function fJ(J){if(!M(J))return!1;return[J.transaction,J.rejected].some((Z)=>{if(!M(Z)||!M(Z.execution))return!1;let{transitions:Y}=Z.execution;return Array.isArray(Y)&&Y.some((W)=>M(W)&&W.function===R&&typeof W.program==="string"&&W.program!==f)})}function KJ(J,Z){if(!M(J)||typeof J.status!=="string")throw new B("toolbox_aleo_transaction_failed",{response:J,transactionId:Z});let Y=J.status.toLowerCase();if(Y==="rejected"){let W=fJ(J)?"toolbox_aleo_token_transfer_rejected":"toolbox_aleo_transaction_failed";throw new B(W,{transactionId:Z})}return Y==="accepted"?"accepted":"pending"}async function FJ(J){if(!T.test(J))throw new B("toolbox_aleo_transaction_failed",{transactionId:J});let Z,Y=!0;for(let W of K())try{let{AleoNetworkClient:z}=await import("@provablehq/sdk/mainnet.js"),U=await new z(W).getConfirmedTransaction(J);return KJ(U,J)}catch(z){if(z instanceof B)throw z;Z=z,Y=Y&&m(z)}if(Y)return"pending";throw x("toolbox_aleo_transaction_failed",Z)}async function g(J,{intervalMs:Z=5000,timeoutMs:Y=60000}={}){let W=Date.now();while(Date.now()-W<Y){let z=await FJ(J);if(z==="accepted")return z;await new Promise((U)=>setTimeout(U,Z))}throw new B("toolbox_aleo_transaction_failed",{reason:"confirmation_timeout",transactionId:J})}import{AssetValue as _,Chain as F,derivationPathToString as wJ,NetworkDerivationPath as NJ,SwapKitError as L}from"@swapkit/helpers";async function HJ(J,Z){try{let{Account:Y}=await import("@provablehq/sdk/mainnet.js"),{mnemonicToSeedSync:W}=await import("@scure/bip39"),z=wJ(Z||NJ[F.Aleo],{allHardened:!0}),{key:U}=QJ(z,W(J));return new Y({seed:U})}catch(Y){throw x("toolbox_aleo_wasm_init_failed",Y)}}function YJ(J,Z){let Y,W=()=>{return Y??=HJ(J,Z),Y};return{getAddress:async()=>(await W()).address().to_string(),signTransaction:async(z)=>{let U=await W();if(z.sender!==U.address().to_string())throw new L("toolbox_aleo_invalid_address",{address:z.sender});let P;for(let O of K())try{let{ProgramManager:y}=await import("@provablehq/sdk/mainnet.js"),N=new y(O);return N.setAccount(U),await N.buildExecutionTransaction({functionName:z.functionName,inputs:z.inputs,priorityFee:z.priorityFee/A,privateFee:!1,programName:z.programName})}catch(y){P=y}throw P}}}function _J(J={}){if("phrase"in J&&J.phrase&&"signer"in J&&J.signer)throw new L("toolbox_aleo_conflicting_signers");let Z;async function Y(){if(Z)return Z;let $="phrase"in J?J.phrase:void 0;if(!$)throw new L("toolbox_aleo_no_signer");let Q="derivationPath"in J?J.derivationPath:void 0;return Z=await HJ($,Q),Z}let W;function z(){let $="signer"in J?J.signer:void 0;if($)return $;let Q="phrase"in J?J.phrase:void 0;if(!Q)throw new L("toolbox_aleo_no_signer");return W??=YJ(Q,"derivationPath"in J?J.derivationPath:void 0),W}async function U($){let Q;for(let X of K())try{let{AleoNetworkClient:H}=await import("@provablehq/sdk/mainnet.js");return await $(new H(X))}catch(H){Q=H}throw Q}async function P($){let Q;for(let X of K())try{let{AleoNetworkClient:H}=await import("@provablehq/sdk/mainnet.js");return await new H(X).getTransitionId($),!0}catch(H){if(m(H))return!1;Q=H}throw Q}async function O(){let $=z();try{return await $.getAddress()}catch(Q){throw x("toolbox_aleo_wasm_init_failed",Q)}}async function y($){let Q=await U((X)=>X.getProgramMappingValue(f,"account",$));return $J(Q,"u64")}async function N($){try{let Q=await y($);return[_.from({chain:F.Aleo,fromBaseDecimal:6,value:Q})]}catch(Q){throw x("toolbox_aleo_balance_error",Q)}}let u=zJ(F.Aleo);async function p($,Q=!0){try{return await u($,Q)}catch{return N($)}}async function WJ(){return p(await O())}async function v({transactionIds:$}){try{let Q=await Y(),X=[];for(let H of $){if(!T.test(H))throw new L("toolbox_aleo_transaction_failed",{transactionId:H});let D=await U((j)=>j.getTransaction(H));for(let j of r(D,f)){if(!Q.ownsRecordCiphertext(j))continue;let{RecordPlaintext:G}=await import("@provablehq/sdk/mainnet.js"),q=Q.decryptRecord(j).toString(),k=G.fromString(q),w=k.microcredits();if(w===0n)continue;let C=Q.generateRecordViewKey(j).toString(),V=k.serialNumberString(Q.privateKey(),f,"credits",C);X.push({microcredits:w,plaintext:q,spent:await P(V),transactionId:H})}}return X}catch(Q){throw x("toolbox_aleo_balance_error",Q)}}async function XJ({transactionIds:$}){let Q=await v({transactionIds:$});return _.from({chain:F.Aleo,fromBaseDecimal:6,value:JJ(Q)})}async function qJ($,Q){if(!Number.isSafeInteger(Q)||Q<=0)throw new L("toolbox_aleo_insufficient_fee_balance",{feeRecordCredits:Q});let X=await Y();if(!$||$.microcredits<=BigInt(Q)*BigInt(A))throw new L("toolbox_aleo_insufficient_fee_balance",{available:$?.microcredits.toString(),required:`${Q} credits fee record`});let{ProgramManager:H,RecordPlaintext:D}=await import("@provablehq/sdk/mainnet.js"),j;for(let G of K())try{let q=new H(G);return q.setAccount(X),await q.split(Q,D.fromString($.plaintext))}catch(q){j=q}throw j}async function jJ($,Q,X){let H=await Y(),{ProgramManager:D,RecordPlaintext:j}=await import("@provablehq/sdk/mainnet.js"),G;for(let q of K())try{let k=new D(q);return k.setAccount(H),await k.buildExecutionTransaction({feeRecord:j.fromString(Q.plaintext),functionName:"transfer_private_to_public",inputs:[$.plaintext,X,`${$.microcredits}u64`],priorityFee:0,privateFee:!0,programName:f})}catch(k){G=k}throw G}async function l($,Q,X){let H;try{let j=(await Y()).address().to_string(),G=$.filter((V)=>!V.spent);if(G.length===0)throw new L("toolbox_aleo_no_unspent_records",{transactionId:X});if(G.length===1){if(H=await qJ(G[0],Q),await g(H),G=(await v({transactionIds:[H]})).filter((V)=>!V.spent),G.length<2)throw new L("toolbox_aleo_transaction_failed",{transactionId:H})}let q=[...G].sort((V,UJ)=>V.microcredits<UJ.microcredits?-1:1),k=q[0],w=q[q.length-1];if(!k||!w||k===w)throw new L("toolbox_aleo_no_unspent_records",{transactionId:X});let C=await I(await jJ(w,k,j));return await g(C),{publicBalance:_.from({chain:F.Aleo,fromBaseDecimal:6,value:await y(j)}),splitTransactionId:H,unshieldTransactionId:C}}catch(D){if(H)throw new L("toolbox_aleo_transaction_failed",{error:D,splitTransactionId:H});throw x("toolbox_aleo_transaction_failed",D)}}async function GJ($){try{if("records"in $&&$.records)return await l($.records,$.feeRecordCredits??4);let Q=await v({transactionIds:[$.transactionId]});return await l(Q,$.feeRecordCredits??4,$.transactionId)}catch(Q){throw x("toolbox_aleo_transaction_failed",Q)}}function c({assetValue:$,priorityFee:Q=0}){try{if(!Number.isSafeInteger(Q)||Q<0)throw new L("toolbox_aleo_fee_estimation_failed",{priorityFee:Q});let H=E($).isTokenTransfer?e:a;return _.from({chain:F.Aleo,fromBaseDecimal:6,value:BigInt(H)+BigInt(Q)})}catch(X){throw x("toolbox_aleo_fee_estimation_failed",X)}}async function d({assetValue:$,priorityFee:Q=0,recipient:X,sender:H}){if(!await ZJ(X))throw new L("toolbox_aleo_invalid_address",{address:X});let D=H||await O();if(!S(D))throw new L("toolbox_aleo_invalid_address",{address:D});let j=E($),G=await c({assetValue:$,priorityFee:Q,recipient:X});try{let q=await y(D);if(_.from({chain:F.Aleo,fromBaseDecimal:6,value:q}).lt(G))throw new L("toolbox_aleo_insufficient_fee_balance",{available:q.toString(),required:G.getBaseValue("string")});return{functionName:j.functionName,inputs:[X,j.amount],priorityFee:Q,programName:j.programName,sender:D}}catch(q){throw x("toolbox_aleo_transaction_failed",q)}}async function i($){try{return await z().signTransaction($)}catch(Q){throw x("toolbox_aleo_transaction_failed",Q)}}async function n($){return I(await i($))}async function I($){try{let Q=typeof $==="string"?$:$.toString(),X=await U((H)=>H.submitTransaction(Q));if(!T.test(X))throw new L("toolbox_aleo_broadcast_error",{transactionId:X});return X}catch(Q){throw x("toolbox_aleo_broadcast_error",Q)}}async function LJ($){let Q=await d({...$,sender:await O()});return n(Q)}return{broadcastTransaction:I,createSigner:YJ,createTransaction:d,estimateTransactionFee:c,getAddress:O,getBalance:u,getBalanceFromRpc:N,getBalances:WJ,getBalanceWithFallback:p,getRecords:v,getShieldedBalance:XJ,signAndBroadcastTransaction:n,signTransaction:i,transfer:LJ,unshield:GJ,validateAddress:S}}export{g as waitForAleoTransaction,VJ as validateAleoProgramId,ZJ as validateAleoAddressWithChecksum,S as validateAleoAddress,JJ as sumUnspentRecords,KJ as parseAleoTransactionStatus,$J as parseAleoMappingValue,M as isRecord,m as isNotFoundError,fJ as isAleoTokenTransferResponse,K as getConfiguredAleoUrls,E as getAleoTransferRoute,FJ as getAleoTransactionStatus,_J as getAleoToolbox,PJ as getAleoMasterSeed,x as getAleoError,r as extractAleoRecordCiphertexts,QJ as deriveAleoPath,yJ as deriveAleoChildKey,R as TRANSFER_PUBLIC_FUNCTION,f as NATIVE_PROGRAM_ID,A as MICRO_CREDITS_PER_CREDIT,o as HARDENED_OFFSET,a as ALEO_TRANSFER_PUBLIC_FEE,T as ALEO_TRANSACTION_ID_REGEX,e as ALEO_TOKEN_TRANSFER_PUBLIC_FEE,MJ as ALEO_PROGRAM_ID_REGEX,xJ as ALEO_HD_KEY,kJ as ALEO_ADDRESS_REGEX};
@@ -1 +1 @@
1
- import{fa as x}from"../../chunk-fjyc6m34.js";import{AssetValue as P,Chain as Q,derivationPathToString as t,getChainConfig as v,getRPCUrlSync as l,NetworkDerivationPath as a,SwapKitError as z}from"@swapkit/helpers";import{match as p,P as G}from"ts-pattern";var N={COIN_TYPE:"0x1::aptos_coin::AptosCoin",FUNGIBLE_ASSET_METADATA:"0x1::fungible_asset::Metadata",FUNGIBLE_STORE_TRANSFER:"0x1::primary_fungible_store::transfer",TRANSFER:"0x1::aptos_account::transfer"},s=2000,e=/^[0-9a-fA-F]+$/;function B(J){if(!J||typeof J!=="string"||!J.startsWith("0x"))return!1;let Z=J.slice(2);if(Z.length===0||Z.length>64)return!1;return e.test(Z)}function c(J,Z,L){if(J<=0n)throw new z({errorKey:"toolbox_sweep_amount_too_low",info:{amount:J.toString(),asset:Z.toString(),...L}});return J}async function jj({aptos:J,assetValue:Z,senderAddress:L}){let $=Z.address;if(!$)throw new z("toolbox_aptos_missing_asset_type");let[M]=await J.getCurrentFungibleAssetBalances({options:{limit:1,where:{asset_type:{_eq:$},is_primary:{_eq:!0},owner_address:{_eq:L}}}});return c(BigInt(M?.amount??0),Z)}function qj({derivationPath:J,provider:Z,...L}={}){let $,M=t(J||a[Q.Aptos],{allHardened:!0});async function y(){if($)return $;return $=await p(L).with({phrase:G.string},async({phrase:q})=>{let{Ed25519Account:j}=await import("@aptos-labs/ts-sdk");return j.fromDerivationPath({mnemonic:q,path:M})}).with({signer:G.any},({signer:q})=>q).otherwise(()=>{return}),$}async function D(){let{Aptos:q,AptosConfig:j,Network:H}=await import("@aptos-labs/ts-sdk"),W=new j({clientConfig:{http2:!1},fullnode:Z||l(Q.Aptos),network:H.MAINNET});return new q(W)}async function _(){return(await y())?.accountAddress.toString()||""}async function h(q){let j=q||await _();if(!j)throw new z("toolbox_aptos_address_required");let{baseDecimal:H,chain:W}=v(Q.Aptos);try{let X=await D(),R=await X.getAccountAPTAmount({accountAddress:j}),k=[P.from({chain:W,fromBaseDecimal:H,value:R.toString()})],F=await X.getCurrentFungibleAssetBalances({options:{where:{owner_address:{_eq:j}}}});for(let Y of F){if(Y.asset_type===N.COIN_TYPE||Number(Y.amount)<=0)continue;let I=Y.asset_type;if(I){let U=("metadata"in Y&&typeof Y.metadata==="object"&&Y.metadata!==null?Y.metadata:void 0)?.decimals??H;k.push(P.from({asset:`${Q.Aptos}.APT-${I}`,fromBaseDecimal:U,value:String(Y.amount)}))}}return k}catch{return[P.from({chain:W})]}}async function u(q){if(!q){let{baseDecimal:k}=v(Q.Aptos),F=Z||l(Q.Aptos),Y=await fetch(`${F}/estimate_gas_price`),{gas_estimate:I}=await Y.json();return P.from({chain:Q.Aptos,fromBaseDecimal:k,value:String(I)})}let j=await O(q),H=await D(),[W]=await H.transaction.simulate.simple({transaction:j});if(!W)throw new z("toolbox_aptos_transaction_creation_error");let X=BigInt(W.gas_used)*BigInt(W.gas_unit_price),{baseDecimal:R}=v(Q.Aptos);return P.from({chain:Q.Aptos,fromBaseDecimal:R,value:X.toString()})}async function O({recipient:q,assetValue:j,maxGasAmount:H,sender:W,sweep:X}){if(!B(q))throw new z("core_transaction_invalid_recipient_address");let R=W||await _();if(!R)throw new z("toolbox_aptos_no_sender");let{AccountAddress:k}=await import("@aptos-labs/ts-sdk"),F=await D(),Y=k.from(R);try{let I=j.isGasAsset?N.TRANSFER:N.FUNGIBLE_STORE_TRANSFER,E=j.address,U=(f,b)=>{let m=p({address:E,isGasAsset:j.isGasAsset}).with({isGasAsset:!0},()=>[k.from(q),f]).with({address:G.string},({address:r})=>[k.from(r),k.from(q),f]).otherwise(()=>null);if(!m)throw new z("toolbox_aptos_missing_asset_type");let A=b?.maxGasAmount??H;return F.transaction.build.simple({data:{function:I,functionArguments:m,typeArguments:j.isGasAsset?[]:[N.FUNGIBLE_ASSET_METADATA]},options:A!==void 0||b?.gasUnitPrice!==void 0?{gasUnitPrice:b?.gasUnitPrice,maxGasAmount:A}:void 0,sender:Y})};if(!X)return U(j.getBaseValue("bigint"));if(!j.isGasAsset){let f=await jj({aptos:F,assetValue:j,senderAddress:R});return U(f)}let w=BigInt(await F.getAccountAPTAmount({accountAddress:R})),i=await U(1n,{maxGasAmount:H??s}),[C]=await F.transaction.simulate.simple({options:{estimateMaxGasAmount:H===void 0},transaction:i});if(!C)throw new z("toolbox_aptos_transaction_creation_error");if(!C.success)throw new z({errorKey:"toolbox_aptos_transaction_creation_error",info:{vmStatus:C.vm_status}});let S=BigInt(C.gas_used),V=S>0n?(S*6n+4n)/5n:1n,g=V*BigInt(C.gas_unit_price),n=c(w-g,j,{balance:w.toString(),fee:g.toString()});return U(n,{gasUnitPrice:Number(C.gas_unit_price),maxGasAmount:Number(V)})}catch(I){if(I instanceof z)throw I;throw new z("toolbox_aptos_transaction_creation_error",I)}}async function T(q){let j=await y();if(!j)throw new z("toolbox_aptos_no_signer");return(await D()).transaction.sign({signer:j,transaction:q})}async function d({assetValue:q,maxGasAmount:j,recipient:H,sweep:W}){let X=await y();if(!X)throw new z("toolbox_aptos_no_signer");if(!B(H))throw new z("core_transaction_invalid_recipient_address");try{let R=X.accountAddress.toString(),k=await O({assetValue:q,maxGasAmount:j,recipient:H,sender:R,sweep:W});return(await(await D()).signAndSubmitTransaction({signer:X,transaction:k})).hash}catch(R){if(R instanceof z)throw R;throw new z("toolbox_aptos_transaction_creation_error",R)}}async function K({senderAuthenticator:q,transaction:j}){try{return(await(await D()).transaction.submit.simple({senderAuthenticator:q,transaction:j})).hash}catch(H){throw new z("toolbox_aptos_broadcast_error",H)}}async function o(q){let j=await T(q);return K({senderAuthenticator:j,transaction:q})}return{broadcastTransaction:K,createTransaction:O,estimateTransactionFee:u,getAddress:_,getBalance:h,signAndBroadcastTransaction:o,signTransaction:T,transfer:d,validateAddress:B}}function zj({provider:J}){return async function({assetValue:L,recipient:$,sweep:M}){if(M)throw new z({errorKey:"toolbox_not_supported",info:{chain:Q.Aptos,feature:"extension_provider_sweep",reason:"Aptos extension providers cannot query balances or simulate transactions"}});if(!B($))throw new z("core_transaction_invalid_recipient_address");let{AccountAddress:y}=await import("@aptos-labs/ts-sdk");if(L.isGasAsset)return(await J.signAndSubmitTransaction({arguments:[y.from($).toString(),L.getBaseValue("string")],function:N.TRANSFER,type:"entry_function_payload",type_arguments:[]})).hash;let D=L.address;if(!D)throw new z("toolbox_aptos_missing_asset_type");return(await J.signAndSubmitTransaction({arguments:[D,y.from($).toString(),L.getBaseValue("string")],function:N.FUNGIBLE_STORE_TRANSFER,type:"entry_function_payload",type_arguments:[N.FUNGIBLE_ASSET_METADATA]})).hash}}export{B as validateAptosAddress,qj as getAptosToolbox,zj as createAptosExtensionTransfer};
1
+ import{ga as v}from"../../chunk-xbdjxeqd.js";import{AssetValue as N,Chain as I,derivationPathToString as e,getChainConfig as b,getRPCUrlSync as c,NetworkDerivationPath as jj,SwapKitError as H}from"@swapkit/helpers";import{match as d,P as G}from"ts-pattern";var C={COIN_TYPE:"0x1::aptos_coin::AptosCoin",FUNGIBLE_ASSET_METADATA:"0x1::fungible_asset::Metadata",FUNGIBLE_STORE_TRANSFER:"0x1::primary_fungible_store::transfer",TRANSFER:"0x1::aptos_account::transfer"},zj=2000,Hj=/^[0-9a-fA-F]+$/;function _(W){if(!W||typeof W!=="string"||!W.startsWith("0x"))return!1;let Z=W.slice(2);if(Z.length===0||Z.length>64)return!1;return Hj.test(Z)}function u(W,Z,X){if(W<=0n)throw new H({errorKey:"toolbox_sweep_amount_too_low",info:{amount:W.toString(),asset:Z.toString(),...X}});return W}async function Jj({aptos:W,assetValue:Z,senderAddress:X}){let $=Z.address;if(!$)throw new H("toolbox_aptos_missing_asset_type");let[B]=await W.getCurrentFungibleAssetBalances({options:{limit:1,where:{asset_type:{_eq:$},is_primary:{_eq:!0},owner_address:{_eq:X}}}});return u(BigInt(B?.amount??0),Z)}function Rj({derivationPath:W,provider:Z,...X}={}){let $,B=e(W||jj[I.Aptos],{allHardened:!0});async function M(){if($)return $;return $=await d(X).with({phrase:G.string},async({phrase:z})=>{let{Ed25519Account:j}=await import("@aptos-labs/ts-sdk");return j.fromDerivationPath({mnemonic:z,path:B})}).with({signer:G.any},({signer:z})=>z).otherwise(()=>{return}),$}async function Q(){let{Aptos:z,AptosConfig:j,Network:J}=await import("@aptos-labs/ts-sdk"),Y=new j({clientConfig:{http2:!1},fullnode:Z||c(I.Aptos),network:J.MAINNET});return new z(Y)}async function f(){return(await M())?.accountAddress.toString()||""}async function h(z){let j=z||await f();if(!j)throw new H("toolbox_aptos_address_required");let{baseDecimal:J,chain:Y}=b(I.Aptos);try{let k=await Q(),L=await k.getAccountAPTAmount({accountAddress:j}),F=[N.from({chain:Y,fromBaseDecimal:J,value:L.toString()})],q=await k.getCurrentFungibleAssetBalances({options:{where:{owner_address:{_eq:j}}}});for(let R of q){if(R.asset_type===C.COIN_TYPE||Number(R.amount)<=0)continue;let D=R.asset_type;if(D){let y=("metadata"in R&&typeof R.metadata==="object"&&R.metadata!==null?R.metadata:void 0)?.decimals??J;F.push(N.from({asset:`${I.Aptos}.APT-${D}`,fromBaseDecimal:y,value:String(R.amount)}))}}return F}catch{return[N.from({chain:Y})]}}async function o(z){if(!z){let{baseDecimal:F}=b(I.Aptos),q=Z||c(I.Aptos),R=await fetch(`${q}/estimate_gas_price`),{gas_estimate:D}=await R.json();return N.from({chain:I.Aptos,fromBaseDecimal:F,value:String(D)})}let j=await P(z),J=await Q(),[Y]=await J.transaction.simulate.simple({transaction:j});if(!Y)throw new H("toolbox_aptos_transaction_creation_error");let k=BigInt(Y.gas_used)*BigInt(Y.gas_unit_price),{baseDecimal:L}=b(I.Aptos);return N.from({chain:I.Aptos,fromBaseDecimal:L,value:k.toString()})}async function P({recipient:z,assetValue:j,maxGasAmount:J,sender:Y,accountSequenceNumber:k,gasUnitPrice:L,sweep:F}){if(!_(z))throw new H("core_transaction_invalid_recipient_address");let q=Y||await f();if(!q)throw new H("toolbox_aptos_no_sender");let{AccountAddress:R}=await import("@aptos-labs/ts-sdk"),D=await Q(),E=R.from(q);try{let y=j.isGasAsset?C.TRANSFER:C.FUNGIBLE_STORE_TRANSFER,r=j.address,x=(U,A)=>{let m=d({address:r,isGasAsset:j.isGasAsset}).with({isGasAsset:!0},()=>[R.from(z),U]).with({address:G.string},({address:a})=>[R.from(a),R.from(z),U]).otherwise(()=>null);if(!m)throw new H("toolbox_aptos_missing_asset_type");let l=A?.maxGasAmount??J,p=A?.gasUnitPrice??L;return D.transaction.build.simple({data:{function:y,functionArguments:m,typeArguments:j.isGasAsset?[]:[C.FUNGIBLE_ASSET_METADATA]},options:l!==void 0||p!==void 0||k!==void 0?{accountSequenceNumber:k,gasUnitPrice:p,maxGasAmount:l}:void 0,sender:E})};if(!F)return x(j.getBaseValue("bigint"));if(!j.isGasAsset){let U=await Jj({aptos:D,assetValue:j,senderAddress:q});return x(U)}let w=BigInt(await D.getAccountAPTAmount({accountAddress:q})),t=await x(1n,{maxGasAmount:J??zj}),[O]=await D.transaction.simulate.simple({options:{estimateMaxGasAmount:J===void 0},transaction:t});if(!O)throw new H("toolbox_aptos_transaction_creation_error");if(!O.success)throw new H({errorKey:"toolbox_aptos_transaction_creation_error",info:{vmStatus:O.vm_status}});let V=BigInt(O.gas_used),S=V>0n?(V*6n+4n)/5n:1n,g=S*BigInt(O.gas_unit_price),s=u(w-g,j,{balance:w.toString(),fee:g.toString()});return x(s,{gasUnitPrice:Number(O.gas_unit_price),maxGasAmount:Number(S)})}catch(y){if(y instanceof H)throw y;throw new H("toolbox_aptos_transaction_creation_error",y)}}async function T(z){let j=await M();if(!j)throw new H("toolbox_aptos_no_signer");return(await Q()).transaction.sign({signer:j,transaction:z})}async function i({assetValue:z,maxGasAmount:j,recipient:J,sweep:Y}){let k=await M();if(!k)throw new H("toolbox_aptos_no_signer");if(!_(J))throw new H("core_transaction_invalid_recipient_address");try{let L=k.accountAddress.toString(),F=await P({assetValue:z,maxGasAmount:j,recipient:J,sender:L,sweep:Y});return(await(await Q()).signAndSubmitTransaction({signer:k,transaction:F})).hash}catch(L){if(L instanceof H)throw L;throw new H("toolbox_aptos_transaction_creation_error",L)}}async function K({senderAuthenticator:z,transaction:j}){try{return(await(await Q()).transaction.submit.simple({senderAuthenticator:z,transaction:j})).hash}catch(J){throw new H("toolbox_aptos_broadcast_error",J)}}async function n(z){let j=await T(z);return K({senderAuthenticator:j,transaction:z})}return{broadcastTransaction:K,createTransaction:P,estimateTransactionFee:o,getAddress:f,getBalance:h,signAndBroadcastTransaction:n,signTransaction:T,transfer:i,validateAddress:_}}function Wj({provider:W}){return async function({assetValue:X,recipient:$,sweep:B}){if(B)throw new H({errorKey:"toolbox_not_supported",info:{chain:I.Aptos,feature:"extension_provider_sweep",reason:"Aptos extension providers cannot query balances or simulate transactions"}});if(!_($))throw new H("core_transaction_invalid_recipient_address");let{AccountAddress:M}=await import("@aptos-labs/ts-sdk");if(X.isGasAsset)return(await W.signAndSubmitTransaction({arguments:[M.from($).toString(),X.getBaseValue("string")],function:C.TRANSFER,type:"entry_function_payload",type_arguments:[]})).hash;let Q=X.address;if(!Q)throw new H("toolbox_aptos_missing_asset_type");return(await W.signAndSubmitTransaction({arguments:[Q,M.from($).toString(),X.getBaseValue("string")],function:C.FUNGIBLE_STORE_TRANSFER,type:"entry_function_payload",type_arguments:[C.FUNGIBLE_ASSET_METADATA]})).hash}}export{_ as validateAptosAddress,Rj as getAptosToolbox,Wj as createAptosExtensionTransfer};
@@ -1 +1 @@
1
- import{fa as b}from"../../chunk-fjyc6m34.js";import{bech32 as JG}from"@scure/base";import{mnemonicToEntropy as QG}from"@scure/bip39";import{wordlist as ZG}from"@scure/bip39/wordlists/english.js";import{AssetValue as B,Chain as D,getChainConfig as $G,SwapKitError as N}from"@swapkit/helpers";import U from"bignumber.js";var t="mainnet3YT7XK6NidLPlkHxxyBB5V0WzXUOTIJS",r="https://cardano-mainnet.blockfrost.io/api/v0",p=2147483648,n=0;async function c(G,J){let Z=await fetch(`${r}${G}`,{...J,headers:{project_id:t,...J?.headers}});if(!Z.ok)throw Error(`Blockfrost API error: ${Z.status} ${Z.statusText}`);return Z.json()}async function s(G){try{return await c(`/addresses/${G}/utxos`)}catch{return[]}}async function zG(){return(await c("/blocks/latest")).slot}async function XG(){let G=await c("/epochs/latest/parameters"),J={PlutusScriptV1:G.cost_models.PlutusV1?Object.values(G.cost_models.PlutusV1):[],PlutusScriptV2:G.cost_models.PlutusV2?Object.values(G.cost_models.PlutusV2):[],PlutusScriptV3:G.cost_models.PlutusV3?Object.values(G.cost_models.PlutusV3):[]};return{collateralPercent:new U(G.collateral_percent),languageView:J,maxValueSize:Number.parseInt(G.max_val_size,10),minFeeA:new U(G.min_fee_a),minFeeB:new U(G.min_fee_b),minFeeRefScriptCostPerByte:new U(15),priceMem:new U(G.price_mem),priceSteps:new U(G.price_step),stakeKeyDeposit:new U(2000000),utxoCostPerByte:new U(G.coins_per_utxo_size)}}async function o(G){let J=await fetch(`${r}/tx/submit`,{body:Buffer.from(G,"hex"),headers:{"Content-Type":"application/cbor",project_id:t},method:"POST"});if(!J.ok){let Z=await J.text();throw Error(`Transaction submission failed: ${Z}`)}return J.json()}function jG(G,J){return G.map((Z)=>{let W=Z.amount.find((Q)=>Q.unit==="lovelace"),X=W?new U(W.quantity):new U(0),q=Z.amount.filter((Q)=>Q.unit!=="lovelace").map((Q)=>({amount:new U(Q.quantity),assetName:Q.unit.slice(56),policyId:Q.unit.slice(0,56)}));return{address:J,amount:X,index:Z.output_index,tokens:q,txId:Z.tx_hash}})}function WG({TransactionConstructor:G,auxiliaryData:J,bufferedParams:Z,currentSlot:W,inputs:X,recipientAddress:q}){let Q=X.reduce(($,z)=>$.plus(z.amount),new U(0));if(!Q.isPositive())throw new N({errorKey:"toolbox_sweep_amount_too_low",info:{available:Q.toString()}});let j=new G({protocolParams:Z});for(let $ of X)j.addInput($);if(j.addOutput({address:q,amount:Q,tokens:[]}),j.setTTL(W+3600),J)j.setAuxiliaryData(J);j.setFee(j.calculateFee());let H=j.getFee(),F=Q.minus(H),Y={address:q,amount:F,tokens:[]},I=j.calculateMinUtxoAmountBabbage(Y);if(!F.isPositive()||F.lt(I))throw new N({errorKey:"toolbox_sweep_amount_too_low",info:{available:Q.toString(),fee:H.toString(),minimumOutput:I.toString()}});return new G({protocolParams:Z}).paymentTransaction({auxiliaryData:J,changeAddress:q,inputs:X,outputs:[Y],ttl:W+3600})}async function qG(G){try{let J=await s(G),Z=0n,W=new Map;for(let Q of J){if(!Q.amount||!Array.isArray(Q.amount))continue;for(let j of Q.amount){let{unit:H,quantity:F}=j;if(H==="lovelace")Z+=BigInt(F);else{let Y=W.get(H)||0n;W.set(H,Y+BigInt(F))}}}let X=[],{baseDecimal:q}=$G(D.Cardano);if(Z>0n)X.push(B.from({chain:D.Cardano,fromBaseDecimal:q,value:Z.toString()}));for(let[Q,j]of W)X.push(B.from({asset:`${D.Cardano}.${Q}`,value:j.toString()}));if(X.length===0)return[B.from({chain:D.Cardano})];return X}catch(J){let Z=J instanceof Error?J.message:String(J);return console.error(`Cardano balance fetch error: ${Z}`),[B.from({chain:D.Cardano})]}}function FG(G){if(!G||typeof G!=="string")return!1;try{let J=JG.decode(G,120);return J.prefix==="addr"||J.prefix==="addr_test"}catch{return!1}}async function UG(G,J=0,Z=0){let{Bip32PrivateKey:W}=await import("@stricahq/bip32ed25519"),{types:X,address:q,crypto:Q}=await import("@stricahq/typhonjs"),j=QG(G,ZG),F=(await W.fromEntropy(Buffer.from(Array.from(j)))).derive(p+1852).derive(p+1815).derive(p+J),Y=F.derive(0).derive(Z),I=Y.toBip32PublicKey().toPublicKey().toBytes(),C=Q.hash28(I),z=F.derive(2).derive(0).toBip32PublicKey().toPublicKey().toBytes(),M=Q.hash28(z),k={hash:C,type:X.HashType.ADDRESS},O={hash:M,type:X.HashType.ADDRESS},V=new q.BaseAddress(X.NetworkId.MAINNET,k,O).getBech32(),K=Y.toPrivateKey();return{getAddress:()=>V,publicKey:I,publicKeyHash:C,signTransaction:async(w)=>{try{let v=await import("@stricahq/cbors"),T=Buffer.from(w,"hex"),f=v.Decoder.decode(T),[S,h,m,P]=f.value,g=v.Encoder.encode(S),y=Q.hash32(g),A=K.sign(y),E=h instanceof Map?h:new Map,x=E.get(n)||[];x.push([I,A]),E.set(n,x);let l=[S,E,m,P];return v.Encoder.encode(l).toString("hex")}catch(v){throw new N("toolbox_cardano_sign_transaction_failed",{message:String(v)})}}}}function IG(G){let J,Z,W;async function X(){if(!W)W=await XG();return W}async function q(){if(J!==void 0)return J;if(G&&"phrase"in G&&G.phrase){let $=G.index??0;return J=await UG(G.phrase,0,$),J}if(G&&"signer"in G&&G.signer)return J=G.signer,J;return}async function Q(){if(Z)return Z;let $=await q();if(!$)return"";if("getAddress"in $)return Z=await $.getAddress(),Z;return""}async function j($){let z=$||await Q();if(!z)throw new N("core_wallet_connection_not_found");return qG(z)}async function H($){if($)try{let{tx:O}=await F($),L=O.getFee();return B.from({chain:D.Cardano,fromBaseDecimal:6,value:L.toString()})}catch{}let z=await X(),M=400,k=z.minFeeB.plus(z.minFeeA.times(M));return B.from({chain:D.Cardano,fromBaseDecimal:6,value:k.toString()})}async function F({sender:$="",recipient:z,assetValue:M,memo:k,pureLovelaceOnly:O=!1,sweep:L=!1}){let{Transaction:V,utils:K}=await import("@stricahq/typhonjs"),w=$||await Q();if(!w)throw new N("core_wallet_connection_not_found");let[v,T,f]=await Promise.all([s(w),zG(),X()]);if(L&&!M.isGasAsset)throw new N({errorKey:"toolbox_not_supported",info:{asset:M.toString(),chain:D.Cardano,feature:"token_sweep"}});let S=L&&M.isGasAsset,h=O||S,m=v.filter((R)=>h?R.amount.some((_)=>_.unit==="lovelace")&&R.amount.every((_)=>_.unit==="lovelace"):R.amount.some((_)=>_.unit==="lovelace")).sort((R,_)=>{let i=R.amount.some((u)=>u.unit!=="lovelace"),GG=_.amount.some((u)=>u.unit!=="lovelace");if(i===GG)return 0;return i?1:-1}),P=K.getAddressFromString(w),g=K.getAddressFromString(z),y=jG(m,P),A;if(k){let R=new Map;R.set("msg",[k]),A={metadata:[{data:R,label:674}]}}let E={...f,minFeeB:f.minFeeB.plus(f.minFeeA.times(4))};if(S){let R=WG({auxiliaryData:A,bufferedParams:E,currentSlot:T,inputs:y,recipientAddress:g,TransactionConstructor:V}),{payload:_}=R.buildTransaction();return{tx:R,unsignedTx:_}}let x=new U(M.getBaseValue("string")),l=[{address:g,amount:x,tokens:[]}],d=new V({protocolParams:E}).paymentTransaction({auxiliaryData:A,changeAddress:P,inputs:y,outputs:l,ttl:T+3600}),{payload:e}=d.buildTransaction();return{tx:d,unsignedTx:e}}async function Y($){let z=await q();if(!z||!("signTransaction"in z))throw new N("core_wallet_connection_not_found");return z.signTransaction($)}async function I({recipient:$,assetValue:z,memo:M,sweep:k}){let O=await q();if(!O||!("signTransaction"in O))throw new N("core_wallet_connection_not_found");let{unsignedTx:L}=await F({assetValue:z,memo:M,recipient:$,sender:await Q(),sweep:k}),V=await Y(L);return await o(V)}async function C($){let z=await Y($);return await o(z)}return{createTransaction:F,estimateTransactionFee:H,getAddress:Q,getBalance:j,signAndBroadcastTransaction:C,signTransaction:Y,transfer:I,validateAddress:FG}}export{FG as validateCardanoAddress,IG as getCardanoToolbox};
1
+ import{ga as b}from"../../chunk-xbdjxeqd.js";import{bech32 as JG}from"@scure/base";import{mnemonicToEntropy as QG}from"@scure/bip39";import{wordlist as ZG}from"@scure/bip39/wordlists/english.js";import{AssetValue as B,Chain as D,getChainConfig as $G,SwapKitError as N}from"@swapkit/helpers";import U from"bignumber.js";var t="mainnet3YT7XK6NidLPlkHxxyBB5V0WzXUOTIJS",r="https://cardano-mainnet.blockfrost.io/api/v0",p=2147483648,n=0;async function c(G,J){let Z=await fetch(`${r}${G}`,{...J,headers:{project_id:t,...J?.headers}});if(!Z.ok)throw Error(`Blockfrost API error: ${Z.status} ${Z.statusText}`);return Z.json()}async function s(G){try{return await c(`/addresses/${G}/utxos`)}catch{return[]}}async function zG(){return(await c("/blocks/latest")).slot}async function XG(){let G=await c("/epochs/latest/parameters"),J={PlutusScriptV1:G.cost_models.PlutusV1?Object.values(G.cost_models.PlutusV1):[],PlutusScriptV2:G.cost_models.PlutusV2?Object.values(G.cost_models.PlutusV2):[],PlutusScriptV3:G.cost_models.PlutusV3?Object.values(G.cost_models.PlutusV3):[]};return{collateralPercent:new U(G.collateral_percent),languageView:J,maxValueSize:Number.parseInt(G.max_val_size,10),minFeeA:new U(G.min_fee_a),minFeeB:new U(G.min_fee_b),minFeeRefScriptCostPerByte:new U(15),priceMem:new U(G.price_mem),priceSteps:new U(G.price_step),stakeKeyDeposit:new U(2000000),utxoCostPerByte:new U(G.coins_per_utxo_size)}}async function o(G){let J=await fetch(`${r}/tx/submit`,{body:Buffer.from(G,"hex"),headers:{"Content-Type":"application/cbor",project_id:t},method:"POST"});if(!J.ok){let Z=await J.text();throw Error(`Transaction submission failed: ${Z}`)}return J.json()}function jG(G,J){return G.map((Z)=>{let W=Z.amount.find((Q)=>Q.unit==="lovelace"),X=W?new U(W.quantity):new U(0),q=Z.amount.filter((Q)=>Q.unit!=="lovelace").map((Q)=>({amount:new U(Q.quantity),assetName:Q.unit.slice(56),policyId:Q.unit.slice(0,56)}));return{address:J,amount:X,index:Z.output_index,tokens:q,txId:Z.tx_hash}})}function WG({TransactionConstructor:G,auxiliaryData:J,bufferedParams:Z,currentSlot:W,inputs:X,recipientAddress:q}){let Q=X.reduce(($,z)=>$.plus(z.amount),new U(0));if(!Q.isPositive())throw new N({errorKey:"toolbox_sweep_amount_too_low",info:{available:Q.toString()}});let j=new G({protocolParams:Z});for(let $ of X)j.addInput($);if(j.addOutput({address:q,amount:Q,tokens:[]}),j.setTTL(W+3600),J)j.setAuxiliaryData(J);j.setFee(j.calculateFee());let H=j.getFee(),F=Q.minus(H),Y={address:q,amount:F,tokens:[]},I=j.calculateMinUtxoAmountBabbage(Y);if(!F.isPositive()||F.lt(I))throw new N({errorKey:"toolbox_sweep_amount_too_low",info:{available:Q.toString(),fee:H.toString(),minimumOutput:I.toString()}});return new G({protocolParams:Z}).paymentTransaction({auxiliaryData:J,changeAddress:q,inputs:X,outputs:[Y],ttl:W+3600})}async function qG(G){try{let J=await s(G),Z=0n,W=new Map;for(let Q of J){if(!Q.amount||!Array.isArray(Q.amount))continue;for(let j of Q.amount){let{unit:H,quantity:F}=j;if(H==="lovelace")Z+=BigInt(F);else{let Y=W.get(H)||0n;W.set(H,Y+BigInt(F))}}}let X=[],{baseDecimal:q}=$G(D.Cardano);if(Z>0n)X.push(B.from({chain:D.Cardano,fromBaseDecimal:q,value:Z.toString()}));for(let[Q,j]of W)X.push(B.from({asset:`${D.Cardano}.${Q}`,value:j.toString()}));if(X.length===0)return[B.from({chain:D.Cardano})];return X}catch(J){let Z=J instanceof Error?J.message:String(J);return console.error(`Cardano balance fetch error: ${Z}`),[B.from({chain:D.Cardano})]}}function FG(G){if(!G||typeof G!=="string")return!1;try{let J=JG.decode(G,120);return J.prefix==="addr"||J.prefix==="addr_test"}catch{return!1}}async function UG(G,J=0,Z=0){let{Bip32PrivateKey:W}=await import("@stricahq/bip32ed25519"),{types:X,address:q,crypto:Q}=await import("@stricahq/typhonjs"),j=QG(G,ZG),F=(await W.fromEntropy(Buffer.from(Array.from(j)))).derive(p+1852).derive(p+1815).derive(p+J),Y=F.derive(0).derive(Z),I=Y.toBip32PublicKey().toPublicKey().toBytes(),C=Q.hash28(I),z=F.derive(2).derive(0).toBip32PublicKey().toPublicKey().toBytes(),M=Q.hash28(z),k={hash:C,type:X.HashType.ADDRESS},O={hash:M,type:X.HashType.ADDRESS},V=new q.BaseAddress(X.NetworkId.MAINNET,k,O).getBech32(),K=Y.toPrivateKey();return{getAddress:()=>V,publicKey:I,publicKeyHash:C,signTransaction:async(w)=>{try{let v=await import("@stricahq/cbors"),T=Buffer.from(w,"hex"),f=v.Decoder.decode(T),[S,h,m,P]=f.value,g=v.Encoder.encode(S),y=Q.hash32(g),A=K.sign(y),E=h instanceof Map?h:new Map,x=E.get(n)||[];x.push([I,A]),E.set(n,x);let l=[S,E,m,P];return v.Encoder.encode(l).toString("hex")}catch(v){throw new N("toolbox_cardano_sign_transaction_failed",{message:String(v)})}}}}function IG(G){let J,Z,W;async function X(){if(!W)W=await XG();return W}async function q(){if(J!==void 0)return J;if(G&&"phrase"in G&&G.phrase){let $=G.index??0;return J=await UG(G.phrase,0,$),J}if(G&&"signer"in G&&G.signer)return J=G.signer,J;return}async function Q(){if(Z)return Z;let $=await q();if(!$)return"";if("getAddress"in $)return Z=await $.getAddress(),Z;return""}async function j($){let z=$||await Q();if(!z)throw new N("core_wallet_connection_not_found");return qG(z)}async function H($){if($)try{let{tx:O}=await F($),L=O.getFee();return B.from({chain:D.Cardano,fromBaseDecimal:6,value:L.toString()})}catch{}let z=await X(),M=400,k=z.minFeeB.plus(z.minFeeA.times(M));return B.from({chain:D.Cardano,fromBaseDecimal:6,value:k.toString()})}async function F({sender:$="",recipient:z,assetValue:M,memo:k,pureLovelaceOnly:O=!1,sweep:L=!1}){let{Transaction:V,utils:K}=await import("@stricahq/typhonjs"),w=$||await Q();if(!w)throw new N("core_wallet_connection_not_found");let[v,T,f]=await Promise.all([s(w),zG(),X()]);if(L&&!M.isGasAsset)throw new N({errorKey:"toolbox_not_supported",info:{asset:M.toString(),chain:D.Cardano,feature:"token_sweep"}});let S=L&&M.isGasAsset,h=O||S,m=v.filter((R)=>h?R.amount.some((_)=>_.unit==="lovelace")&&R.amount.every((_)=>_.unit==="lovelace"):R.amount.some((_)=>_.unit==="lovelace")).sort((R,_)=>{let i=R.amount.some((u)=>u.unit!=="lovelace"),GG=_.amount.some((u)=>u.unit!=="lovelace");if(i===GG)return 0;return i?1:-1}),P=K.getAddressFromString(w),g=K.getAddressFromString(z),y=jG(m,P),A;if(k){let R=new Map;R.set("msg",[k]),A={metadata:[{data:R,label:674}]}}let E={...f,minFeeB:f.minFeeB.plus(f.minFeeA.times(4))};if(S){let R=WG({auxiliaryData:A,bufferedParams:E,currentSlot:T,inputs:y,recipientAddress:g,TransactionConstructor:V}),{payload:_}=R.buildTransaction();return{tx:R,unsignedTx:_}}let x=new U(M.getBaseValue("string")),l=[{address:g,amount:x,tokens:[]}],d=new V({protocolParams:E}).paymentTransaction({auxiliaryData:A,changeAddress:P,inputs:y,outputs:l,ttl:T+3600}),{payload:e}=d.buildTransaction();return{tx:d,unsignedTx:e}}async function Y($){let z=await q();if(!z||!("signTransaction"in z))throw new N("core_wallet_connection_not_found");return z.signTransaction($)}async function I({recipient:$,assetValue:z,memo:M,sweep:k}){let O=await q();if(!O||!("signTransaction"in O))throw new N("core_wallet_connection_not_found");let{unsignedTx:L}=await F({assetValue:z,memo:M,recipient:$,sender:await Q(),sweep:k}),V=await Y(L);return await o(V)}async function C($){let z=await Y($);return await o(z)}return{createTransaction:F,estimateTransactionFee:H,getAddress:Q,getBalance:j,signAndBroadcastTransaction:C,signTransaction:Y,transfer:I,validateAddress:FG}}export{FG as validateCardanoAddress,IG as getCardanoToolbox};
@@ -1 +1 @@
1
- import{fa as m}from"../../chunk-fjyc6m34.js";import{base64 as M,bech32 as E}from"@scure/base";import{SwapKitError as Ao}from"@swapkit/helpers";function b(o){return M.encode(Uint8Array.from(E.fromWords(E.decode(o).words)))}function l(o,t="thor"){return E.encode(t,E.toWords(M.decode(o)))}function Gt(o){return M.encode(o)}function Zt(o){if(!o.match(/^[a-zA-Z0-9+/]*={0,2}$/))throw new Ao("toolbox_cosmos_invalid_params",{error:"Invalid base64 string format"});return M.decode(o)}import{AssetValue as ao,Chain as h,getChainConfig as Ro,getRPCUrl as yo,SwapKitError as ot}from"@swapkit/helpers";import{AssetValue as po,Chain as n,getChainConfig as C,getRPCUrl as Eo,RequestClient as Mo,SKConfig as Bo,SwapKitError as s,SwapKitNumber as fo}from"@swapkit/helpers";var Io="FACTORY/KUJIRA1QK00H5ATUTPSV900X202PXX42NPJR9THG58DNQPA72F2P7M2LUASE444A7/UUSK",bo="FACTORY/KUJIRA1YGFXN0ER40KLCNCK8THLTUPRDXLCK6WVNPKF2K/UYUM",lo={amount:[{amount:"500",denom:"uatom"}],gas:"200000"},so={amount:[{amount:"1000",denom:"ukuji"}],gas:"200000"},Vo={amount:[{amount:"1000",denom:"uusdc"}],gas:"200000"};function L(o){switch(o){case n.Maya:return{amount:[],gas:"10000000000"};case n.THORChain:return{amount:[],gas:"500000000"};case n.Kujira:return so;case n.Noble:return Vo;default:return lo}}async function V(o){let{isStagenet:t}=Bo.get("envs"),r=Bo.get("thornodeUrls"),p=o===n.Maya,c=`${p?t?r.MAYA_STAGENET:r.MAYA:t?r.THOR_STAGENET:r.THOR}/${p?"mayachain":"thorchain"}/constants`,y=C(o).baseDecimal;try{let{int_64_values:{NativeTransactionFee:w}}=await Mo.get(c);if(!Number.isInteger(w)||w<=0)throw new s("toolbox_cosmos_invalid_fee",{nativeFee:w.toString()});return fo.fromBigInt(BigInt(w),y)}catch{let w=p?10000000000n:2000000n;return fo.fromBigInt(w,y)}}var z=(o,t=!1)=>{if(t)return o.toLowerCase();switch(o){case"uUSK":case"USK":return Io;case"uYUM":case"YUM":return bo;case"uKUJI":case"KUJI":return"ukuji";case"ATOM":case"uATOM":return"uatom";case"uUSDC":case"USDC":case"NOBLE":return"uusdc";default:return o}},g=({symbol:o,chain:t})=>{if(t===n.Maya)return(o.toUpperCase()!=="CACAO"?o:`${n.Maya}.${o}`).toUpperCase();if(t===n.THORChain)return(["RUNE","TCY","RUJI"].includes(o.toUpperCase())?`${n.THORChain}.${o}`:o).toUpperCase();return z(o,!1)};async function P(o){let t=await import("@cosmjs/stargate"),r=t.StargateClient??t.default?.StargateClient,p=typeof window<"u"?{}:{referer:"https://sdk.swapkit.dev",referrer:"https://sdk.swapkit.dev"};return r.connect({headers:p,url:o})}async function J(o,t,r={}){let p=await import("@cosmjs/stargate"),f=p.SigningStargateClient??p.default?.SigningStargateClient,c=p.GasPrice??p.default?.GasPrice,y=typeof r==="string"?r:"0.0003uatom",w=typeof r==="string"?{}:r;return f.connectWithSigner(o,t,{gasPrice:c.fromString(y),...w})}async function _o(o,t){let r=await import("@cosmjs/stargate");return(r.SigningStargateClient??r.default?.SigningStargateClient).offline(o,t)}var go=(o)=>{switch(o){case n.Maya:case n.THORChain:return"/types.MsgSend";case n.Cosmos:case n.Kujira:case n.Noble:return"/cosmos.bank.v1beta1.MsgSend";default:throw new s("toolbox_cosmos_not_supported",{chain:o})}};async function $o({sender:o,recipient:t,assetValue:r,memo:p="",feeRate:f,sequence:c,accountNumber:y,sweep:w}){let{chain:W,chainId:B}=r,_=await Eo(W),I=await P(_),$=await I.getAccount(o);if(!$)throw new s("toolbox_cosmos_account_not_found",{sender:o});let T=po.from({chain:W}),k=z(T.symbol),x=L(W),v=k&&f?{amount:[{amount:f.toString(),denom:k}],gas:x.gas}:x,u=z(r.symbol),R={amount:[{amount:(w?K({assetValue:r,balances:await I.getAllBalances(o),denom:u,feeAmount:co(v.amount,u)}):r).getBaseValue("string"),denom:u}],fromAddress:o,toAddress:t};return{accountNumber:y??Number($.accountNumber),chainId:B,fee:v,memo:p,msgs:[{typeUrl:go(W),value:R}],sequence:c??$.sequence}}function co(o,t){let r=t.toLowerCase();return o.reduce((p,f)=>f.denom.toLowerCase()===r?p+BigInt(f.amount):p,0n)}function K({assetValue:o,balances:t,denom:r,feeAmount:p=0n}){let f=r.toLowerCase(),c=t.find(({denom:W})=>W.toLowerCase()===f),y=BigInt(c?.amount??"0"),w=y-p;if(w<=0n)throw new s("toolbox_sweep_amount_too_low",{asset:o.toString(),balance:y.toString(),fee:p.toString()});return o.set(fo.fromBigInt(w,o.decimal))}var ho={atom:{chain:n.Cosmos,decimals:C(n.Cosmos).baseDecimal},cacao:{chain:n.Maya,decimals:10},kuji:{chain:n.Kujira,decimals:C(n.Kujira).baseDecimal},maya:{asset:`${n.Maya}.${n.Maya}`,decimals:4},rune:{chain:n.THORChain,decimals:C(n.THORChain).baseDecimal},tcy:{asset:"THOR.TCY",decimals:C(n.THORChain).baseDecimal},uatom:{chain:n.Cosmos,decimals:C(n.Cosmos).baseDecimal},ukuji:{chain:n.Kujira,decimals:C(n.Kujira).baseDecimal},usdc:{chain:n.Noble,decimals:C(n.Noble).baseDecimal},uusdc:{chain:n.Noble,decimals:C(n.Noble).baseDecimal},"x/kuji":{asset:"THOR.KUJI",decimals:C(n.THORChain).baseDecimal},[Io.toLowerCase()]:{asset:`${n.Kujira}.USK`,decimals:C(n.Kujira).baseDecimal}},io=(o,t)=>{let r=ho[o.toLowerCase()];if(!r)return po.from({asset:o,fromBaseDecimal:8,value:t});let{chain:p,asset:f,decimals:c}=r,y=p?{chain:p}:{asset:f};return po.from({...y,fromBaseDecimal:c,value:t})};import{Chain as eo}from"@swapkit/helpers";async function Y(){let{$root:o}=await import("../../chunk-9psy287z.js"),t=await import("@cosmjs/proto-signing"),r=await import("@cosmjs/stargate"),p=t.Registry??t.default?.Registry,f=r.defaultRegistryTypes??r.default?.defaultRegistryTypes;return new p([...f,["/types.MsgSend",o.types.MsgSend],["/types.MsgDeposit",o.types.MsgDeposit]])}async function G(o){let t=await import("@cosmjs/stargate"),r=t.AminoTypes??t.default?.AminoTypes,p=o===eo.THORChain?"thorchain":"mayachain";return new r({"/types.MsgDeposit":{aminoType:`${p}/MsgDeposit`,fromAmino:({signer:f,...c})=>({...c,signer:b(f)}),toAmino:({signer:f,...c})=>({...c,signer:l(f)})},"/types.MsgSend":{aminoType:`${p}/MsgSend`,fromAmino:({from_address:f,to_address:c,...y})=>({...y,fromAddress:b(f),toAddress:b(c)}),toAmino:({fromAddress:f,toAddress:c,...y})=>({...y,from_address:l(f),to_address:l(c)})}})}var Ot=L(h.THORChain).gas,Nt=L(h.Maya).gas,Co=({sender:o,recipient:t,assetValue:r})=>{return{type:`${r.chain===h.Maya?"mayachain":"thorchain"}/MsgSend`,value:{amount:[{amount:r.getBaseValue("string"),denom:z(r.symbol,!0)}],from_address:o,to_address:t}}},Lo=({sender:o,assetValue:t,memo:r=""})=>{return{type:`${t.chain===h.Maya?"mayachain":"thorchain"}/MsgDeposit`,value:{coins:[{amount:t.getBaseValue("string"),asset:g(t)}],memo:r,signer:o}}},wo=({sender:o,recipient:t,assetValue:r,memo:p})=>{return!t?Lo({assetValue:r,memo:p,sender:o}):Co({assetValue:r,recipient:t,sender:o})},Z=async(o,t)=>{return(await G(t)).fromAmino(o)},jo=async({rpcUrl:o,sender:t})=>{let p=await(await P(o)).getAccount(t);if(!p)throw new ot("toolbox_cosmos_account_not_found",{sender:t});return p};async function Po(o){let{assetValue:t,recipient:r,memo:p,sender:f,asSignable:c,asAminoMessage:y}=o,w=o.sweep?await xo({assetValue:t,sender:f}):t;if(r)return tt({asAminoMessage:y,asSignable:c,assetValue:w,memo:p,recipient:r,sender:f});return rt({asAminoMessage:y,asSignable:c,assetValue:w,memo:p,sender:f})}async function xo({assetValue:o,sender:t}){let r=o.chain,p=await yo(r),c=await(await P(p)).getAllBalances(t),y=o.isGasAsset?(await V(r)).getBaseValue("bigint"):0n;return K({assetValue:o,balances:c,denom:z(o.symbol,!0),feeAmount:y})}async function tt({sender:o,recipient:t,assetValue:r,memo:p="",asSignable:f=!0,asAminoMessage:c=!1,sequence:y,accountNumber:w}){let W=r.chain,B=await yo(W),_=await jo({rpcUrl:B,sender:o}),{chainId:I}=Ro(W),$=Co({assetValue:r,recipient:t,sender:o}),T=f?await Z(c?$:Q($),W):$;return{accountNumber:w||Number(_.accountNumber),chainId:I,fee:L(W),memo:p,msgs:[T],sequence:y||_.sequence}}async function rt({sender:o,assetValue:t,memo:r="",asSignable:p=!0,asAminoMessage:f=!1,sequence:c,accountNumber:y}){let w=t.chain,W=await yo(w),B=await jo({rpcUrl:W,sender:o}),{chainId:_}=Ro(w),I=Lo({assetValue:t,memo:r,sender:o}),$=p?await Z(f?I:Q(I),w):I;return{accountNumber:y||Number(B.accountNumber),chainId:_,fee:L(w),memo:r,msgs:[$],sequence:c||B.sequence}}function Q(o){if(o.type==="thorchain/MsgSend"||o.type==="mayachain/MsgSend")return o;return{...o,value:{...o.value,coins:o.value.coins.map((t)=>{let r=ao.from({asset:t.asset}),p=(r.isSynthetic?r.symbol.split("/")?.[1]:r.symbol)?.toUpperCase(),f=(r.isSynthetic?r.symbol.split("/")?.[0]:r.chain)?.toUpperCase();return{...t,asset:{chain:f,symbol:p,synth:r.isSynthetic,ticker:r.ticker}}})}}}async function e({chain:o,memo:t,msgs:r}){let p=await Y(),f=await G(o),c={typeUrl:"/cosmos.tx.v1beta1.TxBody",value:{memo:t,messages:r.map((y)=>f.fromAmino(y))}};return p.encode(c)}import{Chain as U,SwapKitError as dt}from"@swapkit/helpers";import{base64 as Wo,bech32 as To}from"@scure/base";import{AssetValue as vo,applyFeeMultiplier as zo,Chain as i,CosmosChainPrefixes as Jo,DerivationPath as pt,derivationPathToString as Go,FeeOption as uo,getChainConfig as ft,getRPCUrl as O,NetworkDerivationPath as ct,SwapKitError as D,SwapKitNumber as no,updateDerivationPath as yt}from"@swapkit/helpers";import{SwapKitApi as Yo}from"@swapkit/helpers/api";import{match as wt,P as Zo}from"ts-pattern";async function Do(o,t){try{let p=(await Yo.getGasRate()).find((f)=>f.chainId===o)?.value;return p?Number.parseFloat(p):t}catch{return t}}async function Qo({phrase:o,prefix:t,...r}){let p=await import("@cosmjs/proto-signing"),f=await import("@cosmjs/crypto"),c=p.DirectSecp256k1HdWallet??p.default?.DirectSecp256k1HdWallet,y=f.stringToPath??f.default?.stringToPath,w="derivationPath"in r?r.derivationPath:`${pt[r.chain]}/${r.index}`;return await c.fromMnemonic(o,{hdPaths:[y(w)],prefix:t})}async function or({privateKey:o,prefix:t}){let r=await import("@cosmjs/proto-signing");return(r.DirectSecp256k1Wallet??r.default?.DirectSecp256k1Wallet).fromKey(o,t)}var So={[i.Cosmos]:1000,[i.Kujira]:1000,[i.Noble]:1000,[i.THORChain]:5000000,[i.Maya]:5000000,[i.Harbor]:5000000};function xt(o){return async function({signature:r,message:p,address:f}){let c=await o(f);if(!c?.pubkey)throw new D("toolbox_cosmos_verify_signature_no_pubkey");let y=await import("@cosmjs/crypto"),w=y.Secp256k1Signature??y.default?.Secp256k1Signature,W=y.Secp256k1??y.default?.Secp256k1,B=w.fromFixedLength(Wo.decode(r));return W.verifySignature(B,Wo.decode(p),c.pubkey.value)}}function a({chain:o,...t}){let r=Jo[o],p="index"in t?t.index||0:0,f=Go("derivationPath"in t&&t.derivationPath?t.derivationPath:yt(ct[o],{index:p})),c;async function y(){if(c)return c;return c=await wt(t).with({phrase:Zo.string},({phrase:T})=>Qo({derivationPath:f,phrase:T,prefix:r})).with({signer:Zo.any},({signer:T})=>T).otherwise(()=>{return}),c}async function w(T){let k=await O(o);return(await P(k)).getAccount(T)}async function W(){let T=await y(),[k]=await T?.getAccounts()||[];return k?.address}async function B(){let T=await y(),[k]=await T?.getAccounts()||[];if(!k?.pubkey)throw new D("toolbox_cosmos_signer_not_defined");return Wo.encode(k?.pubkey)}async function _(T){let k=await y(),x=await W(),v=await O(o);if(!(k&&x))throw new D("toolbox_cosmos_signer_not_defined");return await(await J(v,k)).sign(x,T.msgs,T.fee,T.memo,{accountNumber:BigInt(T.accountNumber),chainId:T.chainId,sequence:T.sequence})}async function I(T){let k=await y(),x=await W(),v=await O(o);if(!(k&&x))throw new D("toolbox_cosmos_signer_not_defined");let H=await(await J(v,k)).signAndBroadcast(x,T.msgs,T.fee,T.memo);if(H.code!==0)throw new D("core_swap_transaction_error",{code:H.code,message:H.rawLog});return H.transactionHash}async function $({recipient:T,assetValue:k,memo:x="",feeRate:v,feeOptionKey:u=uo.Fast,sweep:H}){let R=await y(),d=await W();if(!(R&&d))throw new D("toolbox_cosmos_signer_not_defined");let j=await O(o),X=vo.from({chain:o}),oo=g(X),A=Tt(v||(await Xo(o,So[o]))[u],oo,o),q=await J(j,R),F=z(k.symbol),to=[{amount:(H?K({assetValue:k,balances:await ko(o)(d),denom:F,feeAmount:co(A.amount,F)}):k).getBaseValue("string"),denom:F}],{transactionHash:ro}=await q.sendTokens(d,T,to,A,x);return ro}return{createPrivateKeyFromPhrase:Wt(f),createTransaction:$o,fetchFeeRateFromSwapKit:Do,getAccount:w,getAddress:W,getBalance:async(T,k)=>{let x=await ko(o)(T),v=await Promise.all(x.filter(({denom:u})=>u&&!u.includes("IBC/")&&!([i.THORChain,i.Maya].includes(o)&&u.split("-").length>2)).map(({denom:u,amount:H})=>{let R=[i.THORChain,i.Maya].includes(o)&&(u.includes("/")||u.includes("˜"))?`${o}.${u}`:u;return io(R,H)}));if(v.length===0)return[vo.from({chain:o})];return v},getBalanceAsDenoms:ko(o),getFees:()=>Xo(o,So[o]),getPubKey:B,getSignerFromPhrase:({phrase:T,derivationPath:k})=>Qo({derivationPath:Go(k),index:p,phrase:T,prefix:r}),getSignerFromPrivateKey:async(T)=>{let k=await import("@cosmjs/proto-signing");return(k.DirectSecp256k1Wallet??k.default?.DirectSecp256k1Wallet).fromKey(T,r)},signAndBroadcastTransaction:I,signTransaction:_,transfer:$,validateAddress:kt(o),verifySignature:xt(w)}}async function tr(o,t){try{let p=(await Yo.getGasRate()).find((f)=>f.chainId===o)?.value;return p?Number.parseFloat(p):t}catch{return t}}function rr({assetValue:{chain:o}}){return vo.from({chain:o,value:nt(o)})}async function Xo(o,t){let{chainId:r,baseDecimal:p}=ft(o),f=await Do(r,t);return{average:no.fromBigInt(BigInt(f),p),fast:no.fromBigInt(BigInt(zo(f,uo.Fast,!0)),p),fastest:no.fromBigInt(BigInt(zo(f,uo.Fastest,!0)),p)}}function Tt(o,t,r){return{amount:[{amount:typeof o==="number"?o.toString():o.getBaseValue("string"),denom:t}],gas:L(r).gas}}function nt(o){return{[i.Cosmos]:0.007,[i.Kujira]:0.02,[i.Noble]:0.01,[i.THORChain]:0.02,[i.Maya]:0.02,[i.Harbor]:0.02}[o]||0}function kt(o){let t=Jo[o];return function(p){if(!p.startsWith(t))return!1;try{let{prefix:f,words:c}=To.decode(p);return To.encode(f,c)===p.toLocaleLowerCase()}catch{return!1}}}function ko(o){return async function(r){let p=await O(o);return(await(await P(p)).getAllBalances(r)).map((w)=>({...w,denom:w.denom.includes("/")?w.denom.toUpperCase():w.denom}))}}function Wt(o){return async function(r){let p=await import("@cosmjs/crypto"),f=p.stringToPath??p.default?.stringToPath,c=p.Slip10Curve??p.default?.Slip10Curve,y=p.Slip10??p.default?.Slip10,w=p.EnglishMnemonic??p.default?.EnglishMnemonic,W=p.Bip39??p.default?.Bip39,B=new w(r),_=await W.mnemonicToSeed(B),{privkey:I}=y.derivePath(c.Secp256k1,_,f(o));return I}}import{base64 as S}from"@scure/base";import{CosmosChainPrefixes as vt,derivationPathToString as ut,FeeOption as Ho,getRPCUrl as Fo,NetworkDerivationPath as Ht,SKConfig as mt,SwapKitError as N,updateDerivationPath as Bt}from"@swapkit/helpers";import{match as It,P as qo}from"ts-pattern";function _t({prefix:o,derivationPath:t}){return async function(p,f=0){let c=await import("@cosmjs/amino"),y=c.Secp256k1HdWallet??c.default?.Secp256k1HdWallet,w=await import("@cosmjs/crypto"),W=w.stringToPath??w.default?.stringToPath;return y.fromMnemonic(p,{hdPaths:[W(`${t}/${f}`)],prefix:o})}}function $t(o){return S.encode(o)}function it(o){return async function({wallet:r,tx:p}){let{msgs:f,accountNumber:c,sequence:y,chainId:w,fee:W,memo:B}=typeof p==="string"?JSON.parse(p):p,_=(await r.getAccounts())?.[0]?.address||"",I=await G(o),$=await Y(),T=await _o(r,{aminoTypes:I,registry:$}),k=[];for(let u of f){let H=await Z(u,o);k.push(H)}let{signatures:[x]}=await T.sign(_,k,W,B,{accountNumber:BigInt(c),chainId:w,sequence:y});return{bodyBytes:await e({chain:o,memo:B,msgs:f.map(Q)}),signature:$t(x)}}}function Rt({prefix:o,chain:t}){return async function(p,f,c,y,w){let W=await Fo(t),{encodeSecp256k1Pubkey:B,pubkeyToAddress:_}=(await import("@cosmjs/amino")).default,{makeMultisignedTxBytes:I}=(await import("@cosmjs/stargate")).default,{sequence:$,fee:T}=JSON.parse(p),k=await Ko(c,y),x=f.map((H)=>[_(B(S.decode(H.pubKey)),o),S.decode(H.signature)]),v=await P(W),{transactionHash:u}=await v.broadcastTx(I(k,$,T,w,new Map(x)));return u}}async function Ko(o,t,r=!0){let{createMultisigThresholdPubkey:p,encodeSecp256k1Pubkey:f}=(await import("@cosmjs/amino")).default;return p(o.map((c)=>f(S.decode(c))),t,r)}function Ct(o){return S.decode(o)}async function Lt({privateKey:o,message:t}){let{Secp256k1:r}=(await import("@cosmjs/crypto")).default,p=await r.createSignature(S.decode(t),o);return S.encode(Buffer.concat([p.r(32),p.s(32)]))}function Oo({chain:o,...t}){let{isStagenet:r}=mt.get("envs"),p=`${r?"s":""}${vt[o]}`,f="index"in t?t.index||0:0,c="derivationPath"in t&&t.derivationPath?t.derivationPath:Bt(Ht[o],{index:f}),y=a({chain:o,...t}),w=L(o),W;function B(){return W??=It(t).with({phrase:qo.string},({phrase:x})=>y.getSignerFromPhrase({derivationPath:c,phrase:x})).with({signer:qo.any},({signer:x})=>Promise.resolve(x)).otherwise(()=>Promise.resolve(void 0)),W}async function _(){let x=await Fo(o),v=await B();if(!v)throw new N("toolbox_cosmos_no_signer");let u=await Y(),H=await G(o),R=await J(x,v,{aminoTypes:H,registry:u});return{signer:v,signingClient:R}}async function I({fee:x,memo:v,msgs:u}){let{signer:H,signingClient:R}=await _(),d=(await H.getAccounts())?.[0]?.address;if(!d)throw new N("toolbox_cosmos_signer_not_defined");let j=await R.signAndBroadcast(d,u,x,v);if(j.code!==0)throw new N("core_swap_transaction_error",{code:j.code,message:j.rawLog});return j.transactionHash}async function $(){let x=await V(o);return{[Ho.Average]:x,[Ho.Fast]:x,[Ho.Fastest]:x}}async function T({assetValue:x,memo:v="",recipient:u,sweep:H}){let{TxRaw:R}=await import("cosmjs-types/cosmos/tx/v1beta1/tx"),{signer:d,signingClient:j}=await _(),X=(await d.getAccounts())?.[0]?.address;if(!X)throw new N("toolbox_cosmos_no_signer");let oo="signAmino"in d,A=H?await xo({assetValue:x,sender:X}):x,q=wo({assetValue:A,memo:v,recipient:u,sender:X});if(oo){let to=await Z(q,o),{signatures:ro,authInfoBytes:No}=await j.sign(X,[to],w,v),Uo=R.encode({authInfoBytes:No,bodyBytes:await e({chain:o,memo:v,msgs:[q].map(Q)}),signatures:ro}).finish();return(await j.broadcastTx(Uo)).transactionHash}let F=Q(q),mo=await Z(F,o);return I({fee:w,memo:v,msgs:[mo]})}async function k(x){let{signer:v,signingClient:u}=await _(),H=(await v.getAccounts())?.[0]?.address;if(!H)throw new N("toolbox_cosmos_signer_not_defined");return u.sign(H,x.msgs,x.fee,x.memo,{accountNumber:BigInt(x.accountNumber),chainId:x.chainId,sequence:x.sequence})}return{...y,broadcastMultisigTx:Rt({chain:o,prefix:p}),buildAminoMsg:wo,buildEncodedTxBody:e,convertToSignable:Z,createDefaultAminoTypes:()=>G(o),createDefaultRegistry:Y,createMultisig:Ko,createTransaction:Po,deposit:T,getFees:$,importSignature:Ct,parseAminoMessageForDirectSigning:Q,pubkeyToAddress:async(x)=>{let{pubkeyToAddress:v}=(await import("@cosmjs/amino")).default;return v(x,p)},secp256k1HdWalletFromMnemonic:_t({derivationPath:ut(c),prefix:p}),signAndBroadcastTransaction:I,signMultisigTx:it(o),signTransaction:k,signWithPrivateKey:Lt,transfer:T}}var ur=(o,t)=>{switch(o){case U.Cosmos:case U.Kujira:case U.Noble:return a({chain:o,...t});case U.Maya:case U.THORChain:return Oo({chain:o,...t});default:throw new dt("toolbox_cosmos_not_supported",{chain:o})}};export{xt as verifySignature,Co as transferMsgAmino,Gt as toBase64,xo as resolveThorchainSweepAssetValue,Q as parseAminoMessageForDirectSigning,V as getThorchainNativeFee,K as getSweepAssetValue,or as getSignerFromPrivateKey,Qo as getSignerFromPhrase,z as getMsgSendDenom,tr as getFeeRateFromSwapKit,co as getFeeAmountForDenom,g as getDenomWithChain,L as getDefaultChainFee,ur as getCosmosToolbox,kt as getCosmosAddressValidator,io as getAssetFromDenom,Zt as fromBase64,Do as fetchFeeRateFromSwapKit,rr as estimateTransactionFee,Lo as depositMsgAmino,Po as createTransaction,Oo as createThorchainToolbox,P as createStargateClient,J as createSigningStargateClient,_o as createOfflineStargateClient,Y as createDefaultRegistry,G as createDefaultAminoTypes,a as createCosmosToolbox,$o as cosmosCreateTransaction,Z as convertToSignable,tt as buildTransferTx,e as buildEncodedTxBody,rt as buildDepositTx,wo as buildAminoMsg,b as bech32ToBase64,l as base64ToBech32,bo as YUM_KUJIRA_FACTORY_DENOM,Io as USK_KUJIRA_FACTORY_DENOM,Ot as THORCHAIN_GAS_VALUE,Nt as MAYA_GAS_VALUE,Vo as DEFAULT_NOBLE_FEE_MAINNET,so as DEFAULT_KUJI_FEE_MAINNET,lo as DEFAULT_COSMOS_FEE_MAINNET};
1
+ import"../../chunk-xbdjxeqd.js";import{base64 as o,bech32 as i}from"@scure/base";import{SwapKitError as L0}from"@swapkit/helpers";function t(Y){return o.encode(Uint8Array.from(i.fromWords(i.decode(Y).words)))}function r(Y,z="thor"){return i.encode(z,i.toWords(o.decode(Y)))}function P8(Y){return o.encode(Y)}function A8(Y){if(!Y.match(/^[a-zA-Z0-9+/]*={0,2}$/))throw new L0("toolbox_cosmos_invalid_params",{error:"Invalid base64 string format"});return o.decode(Y)}import{encodeMessage as f0,encodeTxBody as w0}from"@swapkit/cosmos-signer";import{AssetValue as j0,Chain as Z6,getChainConfig as h6,getRPCUrl as N6,SwapKitError as B6}from"@swapkit/helpers";import{base64 as G6}from"@scure/base";import{broadcastTx as a,getAccount as P6,getBalances as J0,createTendermintRpc as G0,defaultEncoders as q0,encodeAuthInfo as F6,encodeMessage as _0,encodePubkey as W0,encodeTxBody as O0,encodeTxRaw as v6,makeStdSignDoc as N0}from"@swapkit/cosmos-signer";import{AssetValue as q6,Chain as K,getChainConfig as S,getRPCUrl as B0,RequestClient as I0,SKConfig as D6,SwapKitError as D,SwapKitNumber as _6}from"@swapkit/helpers";var A6="FACTORY/KUJIRA1QK00H5ATUTPSV900X202PXX42NPJR9THG58DNQPA72F2P7M2LUASE444A7/UUSK",E0="FACTORY/KUJIRA1YGFXN0ER40KLCNCK8THLTUPRDXLCK6WVNPKF2K/UYUM",U0={amount:[{amount:"500",denom:"uatom"}],gas:"200000"},K0={amount:[{amount:"1000",denom:"ukuji"}],gas:"200000"},R0={amount:[{amount:"1000",denom:"uusdc"}],gas:"200000"};function C(Y){switch(Y){case K.Maya:return{amount:[],gas:"10000000000"};case K.THORChain:return{amount:[],gas:"500000000"};case K.Kujira:return K0;case K.Noble:return R0;default:return U0}}async function s(Y){let{isStagenet:z}=D6.get("envs"),H=D6.get("thornodeUrls"),Z=Y===K.Maya,X=`${Z?z?H.MAYA_STAGENET:H.MAYA:z?H.THOR_STAGENET:H.THOR}/${Z?"mayachain":"thorchain"}/constants`,L=S(Y).baseDecimal;try{let{int_64_values:{NativeTransactionFee:J}}=await I0.get(X);if(!Number.isInteger(J)||J<=0)throw new D("toolbox_cosmos_invalid_fee",{nativeFee:J.toString()});return _6.fromBigInt(BigInt(J),L)}catch{let J=Z?10000000000n:2000000n;return _6.fromBigInt(J,L)}}var y=(Y,z=!1)=>{if(z)return Y.toLowerCase();switch(Y){case"uUSK":case"USK":return A6;case"uYUM":case"YUM":return E0;case"uKUJI":case"KUJI":return"ukuji";case"ATOM":case"uATOM":return"uatom";case"uUSDC":case"USDC":case"NOBLE":return"uusdc";default:return Y}},e=({symbol:Y,chain:z})=>{if(z===K.Maya)return(Y.toUpperCase()!=="CACAO"?Y:`${K.Maya}.${Y}`).toUpperCase();if(z===K.THORChain)return(["RUNE","TCY","RUJI"].includes(Y.toUpperCase())?`${K.THORChain}.${Y}`:Y).toUpperCase();return y(Y,!1)},V0=()=>typeof window<"u"?{}:{referer:"https://sdk.swapkit.dev",referrer:"https://sdk.swapkit.dev"};function S6(Y){return G0(Y,{headers:V0()})}function C6(Y){return{amount:Y.amount,denom:Y.denom}}function M0(Y,z){if(!Y)return null;if("toAmino"in Y&&typeof Y.toAmino==="function")return null;let Z=Y[z];return Z?{aminoType:Z.aminoType,toAmino:Z.toAmino}:null}async function $(Y){let z=S6(Y);return{async broadcastTx(H){let Z=await a(z,H,"sync");if(Z.code!==0)throw new D("core_swap_transaction_error",{code:Z.code,message:Z.log});return{code:Z.code,rawLog:Z.log,transactionHash:Z.hash}},async getAccount(H){let Z=await P6(z,H);if(!Z)return null;return{accountNumber:Number(Z.accountNumber),address:Z.address,pubkey:Z.pubKey?{type:Z.pubKey.typeUrl,value:Z.pubKey.key}:null,sequence:Number(Z.sequence)}},async getAllBalances(H){return(await J0(z,H)).map((Q)=>({amount:Q.amount,denom:Q.denom}))}}}function $6(Y,z={}){let H=T0(Y);async function Z(Q,X,L,J,G){let U=(await Y.getAccounts()).find((E)=>E.address===Q);if(!U)throw new D("toolbox_cosmos_signer_not_defined");let V=D0({memo:J,messages:X,registry:z.registry}),T=W0({type:"tendermint/PubKeySecp256k1",value:G6.encode(U.pubkey)});if(H){let E=X.map((v)=>v0(v,z.aminoTypes)),R=N0({accountNumber:G.accountNumber,chainId:G.chainId,fee:x0(L),memo:J,msgs:E,sequence:G.sequence}),M=await Y.signAmino(Q,R),x=F6({fee:F0(M.signed.fee,L),signerInfos:[{mode:"amino",pubkey:T,sequence:BigInt(M.signed.sequence)}]}),A=G6.decode(M.signature.signature);return{authInfoBytes:x,bodyBytes:V,signatures:[A]}}let N=F6({fee:k0(L),signerInfos:[{mode:"direct",pubkey:T,sequence:BigInt(G.sequence)}]}),I=await Y.signDirect(Q,{accountNumber:G.accountNumber,authInfoBytes:N,bodyBytes:V,chainId:G.chainId}),W=G6.decode(I.signature.signature);return{authInfoBytes:N,bodyBytes:V,signatures:[W]}}return{signWithRegistry:Z}}function T0(Y){return typeof Y.signAmino==="function"}function x0(Y){return{amount:Y.amount.map((z)=>({amount:z.amount,denom:z.denom})),gas:Y.gas,...Y.granter?{granter:Y.granter}:{},...Y.payer?{payer:Y.payer}:{}}}function k0(Y){return{amount:Y.amount.map(C6),gasLimit:BigInt(Y.gas),...Y.granter?{granter:Y.granter}:{},...Y.payer?{payer:Y.payer}:{}}}function F0(Y,z){return{amount:Y.amount.map(C6),gasLimit:BigInt(Y.gas),...Y.granter??z.granter?{granter:Y.granter??z.granter}:{},...Y.payer??z.payer?{payer:Y.payer??z.payer}:{}}}function v0(Y,z){if(z&&"toAmino"in z&&typeof z.toAmino==="function")return z.toAmino(Y);let H=M0(z,Y.typeUrl);if(!H){if(Y.typeUrl==="/cosmos.bank.v1beta1.MsgSend"){let Z=Y.value;return{type:"cosmos-sdk/MsgSend",value:{amount:Z.amount,from_address:Z.fromAddress,to_address:Z.toAddress}}}throw new D("toolbox_cosmos_invalid_params",{error:`No amino converter for ${Y.typeUrl}`})}return{type:H.aminoType,value:H.toAmino(Y.value)}}function D0(Y){let{memo:z,messages:H,registry:Z}=Y;if(Z&&"encode"in Z&&typeof Z.encode==="function")return Z.encode({typeUrl:"/cosmos.tx.v1beta1.TxBody",value:{memo:z,messages:H}});let Q={...q0,...Z??{}},X=H.map((L)=>_0(L,Q));return O0({memo:z,messages:X})}async function p(Y,z,H={}){let Z=typeof H==="string"?{}:H,Q=S6(Y),X=$6(z,Z);async function L(J,G){let B=await P6(Q,J);if(!B)throw new D("toolbox_cosmos_account_not_found",{sender:J});let U=G?.chainId??(await Q.status()).chainId;return{accountNumber:G?.accountNumber??B.accountNumber,chainId:U,sequence:G?.sequence??B.sequence}}return{async broadcastTx(J){let G=await a(Q,J,"sync");if(G.code!==0)throw new D("core_swap_transaction_error",{code:G.code,message:G.log});return{code:G.code,rawLog:G.log,transactionHash:G.hash}},async sendTokens(J,G,B,U,V=""){let T=[{typeUrl:"/cosmos.bank.v1beta1.MsgSend",value:{amount:B.map((R)=>({amount:R.amount,denom:R.denom})),fromAddress:J,toAddress:G}}],N=await L(J),I=await X.signWithRegistry(J,T,U,V,N),W=v6({authInfoBytes:I.authInfoBytes,bodyBytes:I.bodyBytes,signatures:I.signatures}),E=await a(Q,W,"sync");if(E.code!==0)throw new D("core_swap_transaction_error",{code:E.code,message:E.log});return{code:E.code,rawLog:E.log,transactionHash:E.hash}},async sign(J,G,B,U,V){let T=V??await L(J);return X.signWithRegistry(J,G,B,U,T)},async signAndBroadcast(J,G,B,U=""){let V=await L(J),T=await X.signWithRegistry(J,G,B,U,V),N=v6({authInfoBytes:T.authInfoBytes,bodyBytes:T.bodyBytes,signatures:T.signatures}),I=await a(Q,N,"sync");return{code:I.code,rawLog:I.log,transactionHash:I.hash}}}}async function y6(Y,z){let H=$6(Y,z??{});return{sign(Z,Q,X,L,J){if(!J)throw new D("toolbox_cosmos_invalid_params",{error:"createOfflineStargateClient.sign requires signerData"});return H.signWithRegistry(Z,Q,X,L,J)}}}var P0=(Y)=>{switch(Y){case K.Maya:case K.THORChain:return"/types.MsgSend";case K.Cosmos:case K.Kujira:case K.Noble:return"/cosmos.bank.v1beta1.MsgSend";default:throw new D("toolbox_cosmos_not_supported",{chain:Y})}};async function A0({client:Y,sender:z}){let H=await Y.getAccount(z);if(!H)throw new D("toolbox_cosmos_account_not_found",{sender:z});return H}async function f6({sender:Y,recipient:z,assetValue:H,memo:Z="",feeRate:Q,sequence:X,accountNumber:L,sweep:J}){let{chain:G,chainId:B}=H,U=L===void 0||X===void 0,V=J||U?await $(await B0(G)):void 0,T=U&&V?await A0({client:V,sender:Y}):void 0,N=q6.from({chain:G}),I=y(N.symbol),W=C(G),E=I&&Q?{amount:[{amount:Q.toString(),denom:I}],gas:W.gas}:W,R=y(H.symbol),M=H;if(J){if(!V)throw new D("toolbox_cosmos_account_not_found",{sender:Y});M=m({assetValue:H,balances:await V.getAllBalances(Y),denom:R,feeAmount:W6(E.amount,R)})}let x={amount:[{amount:M.getBaseValue("string"),denom:R}],fromAddress:Y,toAddress:z};return{accountNumber:L??Number(T?.accountNumber),chainId:B,fee:E,memo:Z,msgs:[{typeUrl:P0(G),value:x}],sequence:X??Number(T?.sequence)}}function W6(Y,z){let H=z.toLowerCase();return Y.reduce((Z,Q)=>Q.denom.toLowerCase()===H?Z+BigInt(Q.amount):Z,0n)}function m({assetValue:Y,balances:z,denom:H,feeAmount:Z=0n}){let Q=H.toLowerCase(),X=z.find(({denom:G})=>G.toLowerCase()===Q),L=BigInt(X?.amount??"0"),J=L-Z;if(J<=0n)throw new D("toolbox_sweep_amount_too_low",{asset:Y.toString(),balance:L.toString(),fee:Z.toString()});return Y.set(_6.fromBigInt(J,Y.decimal))}var S0={atom:{chain:K.Cosmos,decimals:S(K.Cosmos).baseDecimal},cacao:{chain:K.Maya,decimals:10},kuji:{chain:K.Kujira,decimals:S(K.Kujira).baseDecimal},maya:{asset:`${K.Maya}.${K.Maya}`,decimals:4},rune:{chain:K.THORChain,decimals:S(K.THORChain).baseDecimal},tcy:{asset:"THOR.TCY",decimals:S(K.THORChain).baseDecimal},uatom:{chain:K.Cosmos,decimals:S(K.Cosmos).baseDecimal},ukuji:{chain:K.Kujira,decimals:S(K.Kujira).baseDecimal},usdc:{chain:K.Noble,decimals:S(K.Noble).baseDecimal},uusdc:{chain:K.Noble,decimals:S(K.Noble).baseDecimal},"x/kuji":{asset:"THOR.KUJI",decimals:S(K.THORChain).baseDecimal},[A6.toLowerCase()]:{asset:`${K.Kujira}.USK`,decimals:S(K.Kujira).baseDecimal}},w6=(Y,z)=>{let H=S0[Y.toLowerCase()];if(!H)return q6.from({asset:Y,fromBaseDecimal:8,value:z});let{chain:Z,asset:Q,decimals:X}=H,L=Z?{chain:Z}:{asset:Q};return q6.from({...L,fromBaseDecimal:X,value:z})};import{defaultEncoders as C0}from"@swapkit/cosmos-signer";import{Chain as j6}from"@swapkit/helpers";import k from"protobufjs/minimal.js";var O=k.Reader,P=k.Writer,_=k.util,q=k.roots.default||(k.roots.default={});q.common=(()=>{let Y={};return Y.Asset=(()=>{function z(H){if(H){for(let Z=Object.keys(H),Q=0;Q<Z.length;++Q)if(H[Z[Q]]!=null)this[Z[Q]]=H[Z[Q]]}}return z.prototype.chain="",z.prototype.symbol="",z.prototype.ticker="",z.prototype.synth=!1,z.create=function(Z){return new z(Z)},z.encode=function(Z,Q){if(!Q)Q=P.create();if(Z.chain!=null&&Object.hasOwnProperty.call(Z,"chain"))Q.uint32(10).string(Z.chain);if(Z.symbol!=null&&Object.hasOwnProperty.call(Z,"symbol"))Q.uint32(18).string(Z.symbol);if(Z.ticker!=null&&Object.hasOwnProperty.call(Z,"ticker"))Q.uint32(26).string(Z.ticker);if(Z.synth!=null&&Object.hasOwnProperty.call(Z,"synth"))Q.uint32(32).bool(Z.synth);return Q},z.encodeDelimited=function(Z,Q){return this.encode(Z,Q).ldelim()},z.decode=function(Z,Q){if(!(Z instanceof O))Z=O.create(Z);let X=Q===void 0?Z.len:Z.pos+Q,L=new q.common.Asset;while(Z.pos<X){let J=Z.uint32();switch(J>>>3){case 1:L.chain=Z.string();break;case 2:L.symbol=Z.string();break;case 3:L.ticker=Z.string();break;case 4:L.synth=Z.bool();break;default:Z.skipType(J&7);break}}return L},z.decodeDelimited=function(Z){if(!(Z instanceof O))Z=new O(Z);return this.decode(Z,Z.uint32())},z.verify=function(Z){if(typeof Z!=="object"||Z===null)return"object expected";if(Z.chain!=null&&Z.hasOwnProperty("chain")){if(!_.isString(Z.chain))return"chain: string expected"}if(Z.symbol!=null&&Z.hasOwnProperty("symbol")){if(!_.isString(Z.symbol))return"symbol: string expected"}if(Z.ticker!=null&&Z.hasOwnProperty("ticker")){if(!_.isString(Z.ticker))return"ticker: string expected"}if(Z.synth!=null&&Z.hasOwnProperty("synth")){if(typeof Z.synth!=="boolean")return"synth: boolean expected"}return null},z.fromObject=function(Z){if(Z instanceof q.common.Asset)return Z;let Q=new q.common.Asset;if(Z.chain!=null)Q.chain=String(Z.chain);if(Z.symbol!=null)Q.symbol=String(Z.symbol);if(Z.ticker!=null)Q.ticker=String(Z.ticker);if(Z.synth!=null)Q.synth=Boolean(Z.synth);return Q},z.toObject=function(Z,Q){if(!Q)Q={};let X={};if(Q.defaults)X.chain="",X.symbol="",X.ticker="",X.synth=!1;if(Z.chain!=null&&Z.hasOwnProperty("chain"))X.chain=Z.chain;if(Z.symbol!=null&&Z.hasOwnProperty("symbol"))X.symbol=Z.symbol;if(Z.ticker!=null&&Z.hasOwnProperty("ticker"))X.ticker=Z.ticker;if(Z.synth!=null&&Z.hasOwnProperty("synth"))X.synth=Z.synth;return X},z.prototype.toJSON=function(){return this.constructor.toObject(this,k.util.toJSONOptions)},z})(),Y.Coin=(()=>{function z(H){if(H){for(let Z=Object.keys(H),Q=0;Q<Z.length;++Q)if(H[Z[Q]]!=null)this[Z[Q]]=H[Z[Q]]}}return z.prototype.asset=null,z.prototype.amount="",z.prototype.decimals=_.Long?_.Long.fromBits(0,0,!1):0,z.create=function(Z){return new z(Z)},z.encode=function(Z,Q){if(!Q)Q=P.create();if(Z.asset!=null&&Object.hasOwnProperty.call(Z,"asset"))q.common.Asset.encode(Z.asset,Q.uint32(10).fork()).ldelim();if(Z.amount!=null&&Object.hasOwnProperty.call(Z,"amount"))Q.uint32(18).string(Z.amount);if(Z.decimals!=null&&Object.hasOwnProperty.call(Z,"decimals"))Q.uint32(24).int64(Z.decimals);return Q},z.encodeDelimited=function(Z,Q){return this.encode(Z,Q).ldelim()},z.decode=function(Z,Q){if(!(Z instanceof O))Z=O.create(Z);let X=Q===void 0?Z.len:Z.pos+Q,L=new q.common.Coin;while(Z.pos<X){let J=Z.uint32();switch(J>>>3){case 1:L.asset=q.common.Asset.decode(Z,Z.uint32());break;case 2:L.amount=Z.string();break;case 3:L.decimals=Z.int64();break;default:Z.skipType(J&7);break}}return L},z.decodeDelimited=function(Z){if(!(Z instanceof O))Z=new O(Z);return this.decode(Z,Z.uint32())},z.verify=function(Z){if(typeof Z!=="object"||Z===null)return"object expected";if(Z.asset!=null&&Z.hasOwnProperty("asset")){let Q=q.common.Asset.verify(Z.asset);if(Q)return"asset."+Q}if(Z.amount!=null&&Z.hasOwnProperty("amount")){if(!_.isString(Z.amount))return"amount: string expected"}if(Z.decimals!=null&&Z.hasOwnProperty("decimals")){if(!_.isInteger(Z.decimals)&&!(Z.decimals&&_.isInteger(Z.decimals.low)&&_.isInteger(Z.decimals.high)))return"decimals: integer|Long expected"}return null},z.fromObject=function(Z){if(Z instanceof q.common.Coin)return Z;let Q=new q.common.Coin;if(Z.asset!=null){if(typeof Z.asset!=="object")throw TypeError(".common.Coin.asset: object expected");Q.asset=q.common.Asset.fromObject(Z.asset)}if(Z.amount!=null)Q.amount=String(Z.amount);if(Z.decimals!=null){if(_.Long)(Q.decimals=_.Long.fromValue(Z.decimals)).unsigned=!1;else if(typeof Z.decimals==="string")Q.decimals=Number.parseInt(Z.decimals,10);else if(typeof Z.decimals==="number")Q.decimals=Z.decimals;else if(typeof Z.decimals==="object")Q.decimals=new _.LongBits(Z.decimals.low>>>0,Z.decimals.high>>>0).toNumber()}return Q},z.toObject=function(Z,Q){if(!Q)Q={};let X={};if(Q.defaults)if(X.asset=null,X.amount="",_.Long){let L=new _.Long(0,0,!1);X.decimals=Q.longs===String?L.toString():Q.longs===Number?L.toNumber():L}else X.decimals=Q.longs===String?"0":0;if(Z.asset!=null&&Z.hasOwnProperty("asset"))X.asset=q.common.Asset.toObject(Z.asset,Q);if(Z.amount!=null&&Z.hasOwnProperty("amount"))X.amount=Z.amount;if(Z.decimals!=null&&Z.hasOwnProperty("decimals"))if(typeof Z.decimals==="number")X.decimals=Q.longs===String?String(Z.decimals):Z.decimals;else X.decimals=Q.longs===String?_.Long.prototype.toString.call(Z.decimals):Q.longs===Number?new _.LongBits(Z.decimals.low>>>0,Z.decimals.high>>>0).toNumber():Z.decimals;return X},z.prototype.toJSON=function(){return this.constructor.toObject(this,k.util.toJSONOptions)},z})(),Y.PubKeySet=(()=>{function z(H){if(H){for(let Z=Object.keys(H),Q=0;Q<Z.length;++Q)if(H[Z[Q]]!=null)this[Z[Q]]=H[Z[Q]]}}return z.prototype.secp256k1="",z.prototype.ed25519="",z.create=function(Z){return new z(Z)},z.encode=function(Z,Q){if(!Q)Q=P.create();if(Z.secp256k1!=null&&Object.hasOwnProperty.call(Z,"secp256k1"))Q.uint32(10).string(Z.secp256k1);if(Z.ed25519!=null&&Object.hasOwnProperty.call(Z,"ed25519"))Q.uint32(18).string(Z.ed25519);return Q},z.encodeDelimited=function(Z,Q){return this.encode(Z,Q).ldelim()},z.decode=function(Z,Q){if(!(Z instanceof O))Z=O.create(Z);let X=Q===void 0?Z.len:Z.pos+Q,L=new q.common.PubKeySet;while(Z.pos<X){let J=Z.uint32();switch(J>>>3){case 1:L.secp256k1=Z.string();break;case 2:L.ed25519=Z.string();break;default:Z.skipType(J&7);break}}return L},z.decodeDelimited=function(Z){if(!(Z instanceof O))Z=new O(Z);return this.decode(Z,Z.uint32())},z.verify=function(Z){if(typeof Z!=="object"||Z===null)return"object expected";if(Z.secp256k1!=null&&Z.hasOwnProperty("secp256k1")){if(!_.isString(Z.secp256k1))return"secp256k1: string expected"}if(Z.ed25519!=null&&Z.hasOwnProperty("ed25519")){if(!_.isString(Z.ed25519))return"ed25519: string expected"}return null},z.fromObject=function(Z){if(Z instanceof q.common.PubKeySet)return Z;let Q=new q.common.PubKeySet;if(Z.secp256k1!=null)Q.secp256k1=String(Z.secp256k1);if(Z.ed25519!=null)Q.ed25519=String(Z.ed25519);return Q},z.toObject=function(Z,Q){if(!Q)Q={};let X={};if(Q.defaults)X.secp256k1="",X.ed25519="";if(Z.secp256k1!=null&&Z.hasOwnProperty("secp256k1"))X.secp256k1=Z.secp256k1;if(Z.ed25519!=null&&Z.hasOwnProperty("ed25519"))X.ed25519=Z.ed25519;return X},z.prototype.toJSON=function(){return this.constructor.toObject(this,k.util.toJSONOptions)},z})(),Y.Tx=(()=>{function z(H){if(this.coins=[],this.gas=[],H){for(let Z=Object.keys(H),Q=0;Q<Z.length;++Q)if(H[Z[Q]]!=null)this[Z[Q]]=H[Z[Q]]}}return z.prototype.id="",z.prototype.chain="",z.prototype.fromAddress="",z.prototype.toAddress="",z.prototype.coins=_.emptyArray,z.prototype.gas=_.emptyArray,z.prototype.memo="",z.create=function(Z){return new z(Z)},z.encode=function(Z,Q){if(!Q)Q=P.create();if(Z.id!=null&&Object.hasOwnProperty.call(Z,"id"))Q.uint32(10).string(Z.id);if(Z.chain!=null&&Object.hasOwnProperty.call(Z,"chain"))Q.uint32(18).string(Z.chain);if(Z.fromAddress!=null&&Object.hasOwnProperty.call(Z,"fromAddress"))Q.uint32(26).string(Z.fromAddress);if(Z.toAddress!=null&&Object.hasOwnProperty.call(Z,"toAddress"))Q.uint32(34).string(Z.toAddress);if(Z.coins?.length)for(let X=0;X<Z.coins.length;++X)q.common.Coin.encode(Z.coins[X],Q.uint32(42).fork()).ldelim();if(Z.gas?.length)for(let X=0;X<Z.gas.length;++X)q.common.Coin.encode(Z.gas[X],Q.uint32(50).fork()).ldelim();if(Z.memo!=null&&Object.hasOwnProperty.call(Z,"memo"))Q.uint32(58).string(Z.memo);return Q},z.encodeDelimited=function(Z,Q){return this.encode(Z,Q).ldelim()},z.decode=function(Z,Q){if(!(Z instanceof O))Z=O.create(Z);let X=Q===void 0?Z.len:Z.pos+Q,L=new q.common.Tx;while(Z.pos<X){let J=Z.uint32();switch(J>>>3){case 1:L.id=Z.string();break;case 2:L.chain=Z.string();break;case 3:L.fromAddress=Z.string();break;case 4:L.toAddress=Z.string();break;case 5:if(!L.coins?.length)L.coins=[];L.coins.push(q.common.Coin.decode(Z,Z.uint32()));break;case 6:if(!L.gas?.length)L.gas=[];L.gas.push(q.common.Coin.decode(Z,Z.uint32()));break;case 7:L.memo=Z.string();break;default:Z.skipType(J&7);break}}return L},z.decodeDelimited=function(Z){if(!(Z instanceof O))Z=new O(Z);return this.decode(Z,Z.uint32())},z.verify=function(Z){if(typeof Z!=="object"||Z===null)return"object expected";if(Z.id!=null&&Z.hasOwnProperty("id")){if(!_.isString(Z.id))return"id: string expected"}if(Z.chain!=null&&Z.hasOwnProperty("chain")){if(!_.isString(Z.chain))return"chain: string expected"}if(Z.fromAddress!=null&&Z.hasOwnProperty("fromAddress")){if(!_.isString(Z.fromAddress))return"fromAddress: string expected"}if(Z.toAddress!=null&&Z.hasOwnProperty("toAddress")){if(!_.isString(Z.toAddress))return"toAddress: string expected"}if(Z.coins!=null&&Z.hasOwnProperty("coins")){if(!Array.isArray(Z.coins))return"coins: array expected";for(let Q=0;Q<Z.coins.length;++Q){let X=q.common.Coin.verify(Z.coins[Q]);if(X)return"coins."+X}}if(Z.gas!=null&&Z.hasOwnProperty("gas")){if(!Array.isArray(Z.gas))return"gas: array expected";for(let Q=0;Q<Z.gas.length;++Q){let X=q.common.Coin.verify(Z.gas[Q]);if(X)return"gas."+X}}if(Z.memo!=null&&Z.hasOwnProperty("memo")){if(!_.isString(Z.memo))return"memo: string expected"}return null},z.fromObject=function(Z){if(Z instanceof q.common.Tx)return Z;let Q=new q.common.Tx;if(Z.id!=null)Q.id=String(Z.id);if(Z.chain!=null)Q.chain=String(Z.chain);if(Z.fromAddress!=null)Q.fromAddress=String(Z.fromAddress);if(Z.toAddress!=null)Q.toAddress=String(Z.toAddress);if(Z.coins){if(!Array.isArray(Z.coins))throw TypeError(".common.Tx.coins: array expected");Q.coins=[];for(let X=0;X<Z.coins.length;++X){if(typeof Z.coins[X]!=="object")throw TypeError(".common.Tx.coins: object expected");Q.coins[X]=q.common.Coin.fromObject(Z.coins[X])}}if(Z.gas){if(!Array.isArray(Z.gas))throw TypeError(".common.Tx.gas: array expected");Q.gas=[];for(let X=0;X<Z.gas.length;++X){if(typeof Z.gas[X]!=="object")throw TypeError(".common.Tx.gas: object expected");Q.gas[X]=q.common.Coin.fromObject(Z.gas[X])}}if(Z.memo!=null)Q.memo=String(Z.memo);return Q},z.toObject=function(Z,Q){if(!Q)Q={};let X={};if(Q.arrays||Q.defaults)X.coins=[],X.gas=[];if(Q.defaults)X.id="",X.chain="",X.fromAddress="",X.toAddress="",X.memo="";if(Z.id!=null&&Z.hasOwnProperty("id"))X.id=Z.id;if(Z.chain!=null&&Z.hasOwnProperty("chain"))X.chain=Z.chain;if(Z.fromAddress!=null&&Z.hasOwnProperty("fromAddress"))X.fromAddress=Z.fromAddress;if(Z.toAddress!=null&&Z.hasOwnProperty("toAddress"))X.toAddress=Z.toAddress;if(Z.coins?.length){X.coins=[];for(let L=0;L<Z.coins.length;++L)X.coins[L]=q.common.Coin.toObject(Z.coins[L],Q)}if(Z.gas?.length){X.gas=[];for(let L=0;L<Z.gas.length;++L)X.gas[L]=q.common.Coin.toObject(Z.gas[L],Q)}if(Z.memo!=null&&Z.hasOwnProperty("memo"))X.memo=Z.memo;return X},z.prototype.toJSON=function(){return this.constructor.toObject(this,k.util.toJSONOptions)},z})(),Y.Fee=(()=>{function z(H){if(this.coins=[],H){for(let Z=Object.keys(H),Q=0;Q<Z.length;++Q)if(H[Z[Q]]!=null)this[Z[Q]]=H[Z[Q]]}}return z.prototype.coins=_.emptyArray,z.prototype.poolDeduct="",z.create=function(Z){return new z(Z)},z.encode=function(Z,Q){if(!Q)Q=P.create();if(Z.coins?.length)for(let X=0;X<Z.coins.length;++X)q.common.Coin.encode(Z.coins[X],Q.uint32(10).fork()).ldelim();if(Z.poolDeduct!=null&&Object.hasOwnProperty.call(Z,"poolDeduct"))Q.uint32(18).string(Z.poolDeduct);return Q},z.encodeDelimited=function(Z,Q){return this.encode(Z,Q).ldelim()},z.decode=function(Z,Q){if(!(Z instanceof O))Z=O.create(Z);let X=Q===void 0?Z.len:Z.pos+Q,L=new q.common.Fee;while(Z.pos<X){let J=Z.uint32();switch(J>>>3){case 1:if(!L.coins?.length)L.coins=[];L.coins.push(q.common.Coin.decode(Z,Z.uint32()));break;case 2:L.poolDeduct=Z.string();break;default:Z.skipType(J&7);break}}return L},z.decodeDelimited=function(Z){if(!(Z instanceof O))Z=new O(Z);return this.decode(Z,Z.uint32())},z.verify=function(Z){if(typeof Z!=="object"||Z===null)return"object expected";if(Z.coins!=null&&Z.hasOwnProperty("coins")){if(!Array.isArray(Z.coins))return"coins: array expected";for(let Q=0;Q<Z.coins.length;++Q){let X=q.common.Coin.verify(Z.coins[Q]);if(X)return"coins."+X}}if(Z.poolDeduct!=null&&Z.hasOwnProperty("poolDeduct")){if(!_.isString(Z.poolDeduct))return"poolDeduct: string expected"}return null},z.fromObject=function(Z){if(Z instanceof q.common.Fee)return Z;let Q=new q.common.Fee;if(Z.coins){if(!Array.isArray(Z.coins))throw TypeError(".common.Fee.coins: array expected");Q.coins=[];for(let X=0;X<Z.coins.length;++X){if(typeof Z.coins[X]!=="object")throw TypeError(".common.Fee.coins: object expected");Q.coins[X]=q.common.Coin.fromObject(Z.coins[X])}}if(Z.poolDeduct!=null)Q.poolDeduct=String(Z.poolDeduct);return Q},z.toObject=function(Z,Q){if(!Q)Q={};let X={};if(Q.arrays||Q.defaults)X.coins=[];if(Q.defaults)X.poolDeduct="";if(Z.coins?.length){X.coins=[];for(let L=0;L<Z.coins.length;++L)X.coins[L]=q.common.Coin.toObject(Z.coins[L],Q)}if(Z.poolDeduct!=null&&Z.hasOwnProperty("poolDeduct"))X.poolDeduct=Z.poolDeduct;return X},z.prototype.toJSON=function(){return this.constructor.toObject(this,k.util.toJSONOptions)},z})(),Y.ProtoUint=(()=>{function z(H){if(H){for(let Z=Object.keys(H),Q=0;Q<Z.length;++Q)if(H[Z[Q]]!=null)this[Z[Q]]=H[Z[Q]]}}return z.prototype.value="",z.create=function(Z){return new z(Z)},z.encode=function(Z,Q){if(!Q)Q=P.create();if(Z.value!=null&&Object.hasOwnProperty.call(Z,"value"))Q.uint32(10).string(Z.value);return Q},z.encodeDelimited=function(Z,Q){return this.encode(Z,Q).ldelim()},z.decode=function(Z,Q){if(!(Z instanceof O))Z=O.create(Z);let X=Q===void 0?Z.len:Z.pos+Q,L=new q.common.ProtoUint;while(Z.pos<X){let J=Z.uint32();switch(J>>>3){case 1:L.value=Z.string();break;default:Z.skipType(J&7);break}}return L},z.decodeDelimited=function(Z){if(!(Z instanceof O))Z=new O(Z);return this.decode(Z,Z.uint32())},z.verify=function(Z){if(typeof Z!=="object"||Z===null)return"object expected";if(Z.value!=null&&Z.hasOwnProperty("value")){if(!_.isString(Z.value))return"value: string expected"}return null},z.fromObject=function(Z){if(Z instanceof q.common.ProtoUint)return Z;let Q=new q.common.ProtoUint;if(Z.value!=null)Q.value=String(Z.value);return Q},z.toObject=function(Z,Q){if(!Q)Q={};let X={};if(Q.defaults)X.value="";if(Z.value!=null&&Z.hasOwnProperty("value"))X.value=Z.value;return X},z.prototype.toJSON=function(){return this.constructor.toObject(this,k.util.toJSONOptions)},z})(),Y})();q.types=(()=>{let Y={};return Y.MsgDeposit=(()=>{function z(H){if(this.coins=[],H){for(let Z=Object.keys(H),Q=0;Q<Z.length;++Q)if(H[Z[Q]]!=null)this[Z[Q]]=H[Z[Q]]}}return z.prototype.coins=_.emptyArray,z.prototype.memo="",z.prototype.signer=_.newBuffer([]),z.create=function(Z){return new z(Z)},z.encode=function(Z,Q){if(!Q)Q=P.create();if(Z.coins?.length)for(let X=0;X<Z.coins.length;++X)q.common.Coin.encode(Z.coins[X],Q.uint32(10).fork()).ldelim();if(Z.memo!=null&&Object.hasOwnProperty.call(Z,"memo"))Q.uint32(18).string(Z.memo);if(Z.signer!=null&&Object.hasOwnProperty.call(Z,"signer"))Q.uint32(26).bytes(Z.signer);return Q},z.encodeDelimited=function(Z,Q){return this.encode(Z,Q).ldelim()},z.decode=function(Z,Q){if(!(Z instanceof O))Z=O.create(Z);let X=Q===void 0?Z.len:Z.pos+Q,L=new q.types.MsgDeposit;while(Z.pos<X){let J=Z.uint32();switch(J>>>3){case 1:if(!L.coins?.length)L.coins=[];L.coins.push(q.common.Coin.decode(Z,Z.uint32()));break;case 2:L.memo=Z.string();break;case 3:L.signer=Z.bytes();break;default:Z.skipType(J&7);break}}return L},z.decodeDelimited=function(Z){if(!(Z instanceof O))Z=new O(Z);return this.decode(Z,Z.uint32())},z.verify=function(Z){if(typeof Z!=="object"||Z===null)return"object expected";if(Z.coins!=null&&Z.hasOwnProperty("coins")){if(!Array.isArray(Z.coins))return"coins: array expected";for(let Q=0;Q<Z.coins.length;++Q){let X=q.common.Coin.verify(Z.coins[Q]);if(X)return"coins."+X}}if(Z.memo!=null&&Z.hasOwnProperty("memo")){if(!_.isString(Z.memo))return"memo: string expected"}if(Z.signer!=null&&Z.hasOwnProperty("signer")){if(!(Z.signer&&typeof Z.signer.length==="number"||_.isString(Z.signer)))return"signer: buffer expected"}return null},z.fromObject=function(Z){if(Z instanceof q.types.MsgDeposit)return Z;let Q=new q.types.MsgDeposit;if(Z.coins){if(!Array.isArray(Z.coins))throw TypeError(".types.MsgDeposit.coins: array expected");Q.coins=[];for(let X=0;X<Z.coins.length;++X){if(typeof Z.coins[X]!=="object")throw TypeError(".types.MsgDeposit.coins: object expected");Q.coins[X]=q.common.Coin.fromObject(Z.coins[X])}}if(Z.memo!=null)Q.memo=String(Z.memo);if(Z.signer!=null){if(typeof Z.signer==="string")_.base64.decode(Z.signer,Q.signer=_.newBuffer(_.base64.length(Z.signer)),0);else if(Z.signer.length)Q.signer=Z.signer}return Q},z.toObject=function(Z,Q){if(!Q)Q={};let X={};if(Q.arrays||Q.defaults)X.coins=[];if(Q.defaults){if(X.memo="",Q.bytes===String)X.signer="";else if(X.signer=[],Q.bytes!==Array)X.signer=_.newBuffer(X.signer)}if(Z.coins?.length){X.coins=[];for(let L=0;L<Z.coins.length;++L)X.coins[L]=q.common.Coin.toObject(Z.coins[L],Q)}if(Z.memo!=null&&Z.hasOwnProperty("memo"))X.memo=Z.memo;if(Z.signer!=null&&Z.hasOwnProperty("signer"))X.signer=Q.bytes===String?_.base64.encode(Z.signer,0,Z.signer.length):Q.bytes===Array?Array.prototype.slice.call(Z.signer):Z.signer;return X},z.prototype.toJSON=function(){return this.constructor.toObject(this,k.util.toJSONOptions)},z})(),Y.MsgSend=(()=>{function z(H){if(this.amount=[],H){for(let Z=Object.keys(H),Q=0;Q<Z.length;++Q)if(H[Z[Q]]!=null)this[Z[Q]]=H[Z[Q]]}}return z.prototype.fromAddress=_.newBuffer([]),z.prototype.toAddress=_.newBuffer([]),z.prototype.amount=_.emptyArray,z.create=function(Z){return new z(Z)},z.encode=function(Z,Q){if(!Q)Q=P.create();if(Z.fromAddress!=null&&Object.hasOwnProperty.call(Z,"fromAddress"))Q.uint32(10).bytes(Z.fromAddress);if(Z.toAddress!=null&&Object.hasOwnProperty.call(Z,"toAddress"))Q.uint32(18).bytes(Z.toAddress);if(Z.amount?.length)for(let X=0;X<Z.amount.length;++X)q.cosmos.base.v1beta1.Coin.encode(Z.amount[X],Q.uint32(26).fork()).ldelim();return Q},z.encodeDelimited=function(Z,Q){return this.encode(Z,Q).ldelim()},z.decode=function(Z,Q){if(!(Z instanceof O))Z=O.create(Z);let X=Q===void 0?Z.len:Z.pos+Q,L=new q.types.MsgSend;while(Z.pos<X){let J=Z.uint32();switch(J>>>3){case 1:L.fromAddress=Z.bytes();break;case 2:L.toAddress=Z.bytes();break;case 3:if(!L.amount?.length)L.amount=[];L.amount.push(q.cosmos.base.v1beta1.Coin.decode(Z,Z.uint32()));break;default:Z.skipType(J&7);break}}return L},z.decodeDelimited=function(Z){if(!(Z instanceof O))Z=new O(Z);return this.decode(Z,Z.uint32())},z.verify=function(Z){if(typeof Z!=="object"||Z===null)return"object expected";if(Z.fromAddress!=null&&Z.hasOwnProperty("fromAddress")){if(!(Z.fromAddress&&typeof Z.fromAddress.length==="number"||_.isString(Z.fromAddress)))return"fromAddress: buffer expected"}if(Z.toAddress!=null&&Z.hasOwnProperty("toAddress")){if(!(Z.toAddress&&typeof Z.toAddress.length==="number"||_.isString(Z.toAddress)))return"toAddress: buffer expected"}if(Z.amount!=null&&Z.hasOwnProperty("amount")){if(!Array.isArray(Z.amount))return"amount: array expected";for(let Q=0;Q<Z.amount.length;++Q){let X=q.cosmos.base.v1beta1.Coin.verify(Z.amount[Q]);if(X)return"amount."+X}}return null},z.fromObject=function(Z){if(Z instanceof q.types.MsgSend)return Z;let Q=new q.types.MsgSend;if(Z.fromAddress!=null){if(typeof Z.fromAddress==="string")_.base64.decode(Z.fromAddress,Q.fromAddress=_.newBuffer(_.base64.length(Z.fromAddress)),0);else if(Z.fromAddress.length)Q.fromAddress=Z.fromAddress}if(Z.toAddress!=null){if(typeof Z.toAddress==="string")_.base64.decode(Z.toAddress,Q.toAddress=_.newBuffer(_.base64.length(Z.toAddress)),0);else if(Z.toAddress.length)Q.toAddress=Z.toAddress}if(Z.amount){if(!Array.isArray(Z.amount))throw TypeError(".types.MsgSend.amount: array expected");Q.amount=[];for(let X=0;X<Z.amount.length;++X){if(typeof Z.amount[X]!=="object")throw TypeError(".types.MsgSend.amount: object expected");Q.amount[X]=q.cosmos.base.v1beta1.Coin.fromObject(Z.amount[X])}}return Q},z.toObject=function(Z,Q){if(!Q)Q={};let X={};if(Q.arrays||Q.defaults)X.amount=[];if(Q.defaults){if(Q.bytes===String)X.fromAddress="";else if(X.fromAddress=[],Q.bytes!==Array)X.fromAddress=_.newBuffer(X.fromAddress);if(Q.bytes===String)X.toAddress="";else if(X.toAddress=[],Q.bytes!==Array)X.toAddress=_.newBuffer(X.toAddress)}if(Z.fromAddress!=null&&Z.hasOwnProperty("fromAddress"))X.fromAddress=Q.bytes===String?_.base64.encode(Z.fromAddress,0,Z.fromAddress.length):Q.bytes===Array?Array.prototype.slice.call(Z.fromAddress):Z.fromAddress;if(Z.toAddress!=null&&Z.hasOwnProperty("toAddress"))X.toAddress=Q.bytes===String?_.base64.encode(Z.toAddress,0,Z.toAddress.length):Q.bytes===Array?Array.prototype.slice.call(Z.toAddress):Z.toAddress;if(Z.amount?.length){X.amount=[];for(let L=0;L<Z.amount.length;++L)X.amount[L]=q.cosmos.base.v1beta1.Coin.toObject(Z.amount[L],Q)}return X},z.prototype.toJSON=function(){return this.constructor.toObject(this,k.util.toJSONOptions)},z})(),Y})();q.cosmos=(()=>{let Y={};return Y.base=(()=>{let z={};return z.v1beta1=(()=>{let H={};return H.Coin=(()=>{function Z(Q){if(Q){for(let X=Object.keys(Q),L=0;L<X.length;++L)if(Q[X[L]]!=null)this[X[L]]=Q[X[L]]}}return Z.prototype.denom="",Z.prototype.amount="",Z.create=function(X){return new Z(X)},Z.encode=function(X,L){if(!L)L=P.create();if(X.denom!=null&&Object.hasOwnProperty.call(X,"denom"))L.uint32(10).string(X.denom);if(X.amount!=null&&Object.hasOwnProperty.call(X,"amount"))L.uint32(18).string(X.amount);return L},Z.encodeDelimited=function(X,L){return this.encode(X,L).ldelim()},Z.decode=function(X,L){if(!(X instanceof O))X=O.create(X);let J=L===void 0?X.len:X.pos+L,G=new q.cosmos.base.v1beta1.Coin;while(X.pos<J){let B=X.uint32();switch(B>>>3){case 1:G.denom=X.string();break;case 2:G.amount=X.string();break;default:X.skipType(B&7);break}}return G},Z.decodeDelimited=function(X){if(!(X instanceof O))X=new O(X);return this.decode(X,X.uint32())},Z.verify=function(X){if(typeof X!=="object"||X===null)return"object expected";if(X.denom!=null&&X.hasOwnProperty("denom")){if(!_.isString(X.denom))return"denom: string expected"}if(X.amount!=null&&X.hasOwnProperty("amount")){if(!_.isString(X.amount))return"amount: string expected"}return null},Z.fromObject=function(X){if(X instanceof q.cosmos.base.v1beta1.Coin)return X;let L=new q.cosmos.base.v1beta1.Coin;if(X.denom!=null)L.denom=String(X.denom);if(X.amount!=null)L.amount=String(X.amount);return L},Z.toObject=function(X,L){if(!L)L={};let J={};if(L.defaults)J.denom="",J.amount="";if(X.denom!=null&&X.hasOwnProperty("denom"))J.denom=X.denom;if(X.amount!=null&&X.hasOwnProperty("amount"))J.amount=X.amount;return J},Z.prototype.toJSON=function(){return this.constructor.toObject(this,k.util.toJSONOptions)},Z})(),H.DecCoin=(()=>{function Z(Q){if(Q){for(let X=Object.keys(Q),L=0;L<X.length;++L)if(Q[X[L]]!=null)this[X[L]]=Q[X[L]]}}return Z.prototype.denom="",Z.prototype.amount="",Z.create=function(X){return new Z(X)},Z.encode=function(X,L){if(!L)L=P.create();if(X.denom!=null&&Object.hasOwnProperty.call(X,"denom"))L.uint32(10).string(X.denom);if(X.amount!=null&&Object.hasOwnProperty.call(X,"amount"))L.uint32(18).string(X.amount);return L},Z.encodeDelimited=function(X,L){return this.encode(X,L).ldelim()},Z.decode=function(X,L){if(!(X instanceof O))X=O.create(X);let J=L===void 0?X.len:X.pos+L,G=new q.cosmos.base.v1beta1.DecCoin;while(X.pos<J){let B=X.uint32();switch(B>>>3){case 1:G.denom=X.string();break;case 2:G.amount=X.string();break;default:X.skipType(B&7);break}}return G},Z.decodeDelimited=function(X){if(!(X instanceof O))X=new O(X);return this.decode(X,X.uint32())},Z.verify=function(X){if(typeof X!=="object"||X===null)return"object expected";if(X.denom!=null&&X.hasOwnProperty("denom")){if(!_.isString(X.denom))return"denom: string expected"}if(X.amount!=null&&X.hasOwnProperty("amount")){if(!_.isString(X.amount))return"amount: string expected"}return null},Z.fromObject=function(X){if(X instanceof q.cosmos.base.v1beta1.DecCoin)return X;let L=new q.cosmos.base.v1beta1.DecCoin;if(X.denom!=null)L.denom=String(X.denom);if(X.amount!=null)L.amount=String(X.amount);return L},Z.toObject=function(X,L){if(!L)L={};let J={};if(L.defaults)J.denom="",J.amount="";if(X.denom!=null&&X.hasOwnProperty("denom"))J.denom=X.denom;if(X.amount!=null&&X.hasOwnProperty("amount"))J.amount=X.amount;return J},Z.prototype.toJSON=function(){return this.constructor.toObject(this,k.util.toJSONOptions)},Z})(),H.IntProto=(()=>{function Z(Q){if(Q){for(let X=Object.keys(Q),L=0;L<X.length;++L)if(Q[X[L]]!=null)this[X[L]]=Q[X[L]]}}return Z.prototype.int="",Z.create=function(X){return new Z(X)},Z.encode=function(X,L){if(!L)L=P.create();if(X.int!=null&&Object.hasOwnProperty.call(X,"int"))L.uint32(10).string(X.int);return L},Z.encodeDelimited=function(X,L){return this.encode(X,L).ldelim()},Z.decode=function(X,L){if(!(X instanceof O))X=O.create(X);let J=L===void 0?X.len:X.pos+L,G=new q.cosmos.base.v1beta1.IntProto;while(X.pos<J){let B=X.uint32();switch(B>>>3){case 1:G.int=X.string();break;default:X.skipType(B&7);break}}return G},Z.decodeDelimited=function(X){if(!(X instanceof O))X=new O(X);return this.decode(X,X.uint32())},Z.verify=function(X){if(typeof X!=="object"||X===null)return"object expected";if(X.int!=null&&X.hasOwnProperty("int")){if(!_.isString(X.int))return"int: string expected"}return null},Z.fromObject=function(X){if(X instanceof q.cosmos.base.v1beta1.IntProto)return X;let L=new q.cosmos.base.v1beta1.IntProto;if(X.int!=null)L.int=String(X.int);return L},Z.toObject=function(X,L){if(!L)L={};let J={};if(L.defaults)J.int="";if(X.int!=null&&X.hasOwnProperty("int"))J.int=X.int;return J},Z.prototype.toJSON=function(){return this.constructor.toObject(this,k.util.toJSONOptions)},Z})(),H.DecProto=(()=>{function Z(Q){if(Q){for(let X=Object.keys(Q),L=0;L<X.length;++L)if(Q[X[L]]!=null)this[X[L]]=Q[X[L]]}}return Z.prototype.dec="",Z.create=function(X){return new Z(X)},Z.encode=function(X,L){if(!L)L=P.create();if(X.dec!=null&&Object.hasOwnProperty.call(X,"dec"))L.uint32(10).string(X.dec);return L},Z.encodeDelimited=function(X,L){return this.encode(X,L).ldelim()},Z.decode=function(X,L){if(!(X instanceof O))X=O.create(X);let J=L===void 0?X.len:X.pos+L,G=new q.cosmos.base.v1beta1.DecProto;while(X.pos<J){let B=X.uint32();switch(B>>>3){case 1:G.dec=X.string();break;default:X.skipType(B&7);break}}return G},Z.decodeDelimited=function(X){if(!(X instanceof O))X=new O(X);return this.decode(X,X.uint32())},Z.verify=function(X){if(typeof X!=="object"||X===null)return"object expected";if(X.dec!=null&&X.hasOwnProperty("dec")){if(!_.isString(X.dec))return"dec: string expected"}return null},Z.fromObject=function(X){if(X instanceof q.cosmos.base.v1beta1.DecProto)return X;let L=new q.cosmos.base.v1beta1.DecProto;if(X.dec!=null)L.dec=String(X.dec);return L},Z.toObject=function(X,L){if(!L)L={};let J={};if(L.defaults)J.dec="";if(X.dec!=null&&X.hasOwnProperty("dec"))J.dec=X.dec;return J},Z.prototype.toJSON=function(){return this.constructor.toObject(this,k.util.toJSONOptions)},Z})(),H})(),z})(),Y})();function O6(Y){if(Y instanceof Uint8Array)return Y;if(typeof Y==="string")return Uint8Array.from(globalThis.atob(Y),(H)=>H.charCodeAt(0));throw TypeError("address must be Uint8Array or base64 string")}var $0=(Y)=>{let z=Y;return q.types.MsgSend.encode({amount:z.amount,fromAddress:O6(z.fromAddress),toAddress:O6(z.toAddress)}).finish()},y0=(Y)=>{let z=Y;return q.types.MsgDeposit.encode({coins:z.coins.map((H)=>({amount:H.amount,asset:H.asset})),memo:z.memo,signer:O6(z.signer)}).finish()};function d(){return{...C0,"/types.MsgDeposit":y0,"/types.MsgSend":$0}}function j(Y,z=Y===j6.THORChain?"thor":"maya"){let H=Y===j6.THORChain?"thorchain":"mayachain",Z={"/types.MsgDeposit":{aminoType:`${H}/MsgDeposit`,fromAmino:({signer:Q,...X})=>({...X,signer:t(Q)}),toAmino:({signer:Q,...X})=>({...X,signer:typeof Q==="string"?r(Q,z):Q})},"/types.MsgSend":{aminoType:`${H}/MsgSend`,fromAmino:({from_address:Q,to_address:X,...L})=>({...L,fromAddress:t(Q),toAddress:t(X)}),toAmino:({fromAddress:Q,toAddress:X,...L})=>({...L,from_address:typeof Q==="string"?r(Q,z):Q,to_address:typeof X==="string"?r(X,z):X})}};return Object.assign(Z,{fromAmino(Q){let X=Object.entries(Z).find(([,G])=>G.aminoType===Q.type);if(!X)throw TypeError(`No converter for amino type ${Q.type}`);let[L,J]=X;return{typeUrl:L,value:J.fromAmino(Q.value)}},toAmino(Q){let X=Z[Q.typeUrl];if(!X)throw TypeError(`No converter for type URL ${Q.typeUrl}`);return{type:X.aminoType,value:X.toAmino(Q.value)}}})}var g8=C(Z6.THORChain).gas,i8=C(Z6.Maya).gas,u6=({sender:Y,recipient:z,assetValue:H})=>{return{type:`${H.chain===Z6.Maya?"mayachain":"thorchain"}/MsgSend`,value:{amount:[{amount:H.getBaseValue("string"),denom:y(H.symbol,!0)}],from_address:Y,to_address:z}}},l6=({sender:Y,assetValue:z,memo:H=""})=>{return{type:`${z.chain===Z6.Maya?"mayachain":"thorchain"}/MsgDeposit`,value:{coins:[{amount:z.getBaseValue("string"),asset:e(z)}],memo:H,signer:Y}}},I6=({sender:Y,recipient:z,assetValue:H,memo:Z})=>{return!z?l6({assetValue:H,memo:Z,sender:Y}):u6({assetValue:H,recipient:z,sender:Y})};function b6(Y,z){for(let H of["/types.MsgDeposit","/types.MsgSend"]){let Z=Y[H];if(Z.aminoType===z)return{fromAmino:Z.fromAmino,typeUrl:H}}return null}var h=(Y,z)=>{let H=j(z),Z=b6(H,Y.type);if(!Z)throw new B6("toolbox_cosmos_invalid_params",{error:`No converter for amino type ${Y.type}`});return{typeUrl:Z.typeUrl,value:Z.fromAmino(Y.value)}},p6=async({rpcUrl:Y,sender:z})=>{let Z=await(await $(Y)).getAccount(z);if(!Z)throw new B6("toolbox_cosmos_account_not_found",{sender:z});return Z};async function d6(Y){let{assetValue:z,recipient:H,memo:Z,sender:Q,asSignable:X,asAminoMessage:L,sequence:J,accountNumber:G}=Y,B=Y.sweep?await E6({assetValue:z,sender:Q}):z;if(H)return h0({accountNumber:G,asAminoMessage:L,asSignable:X,assetValue:B,memo:Z,recipient:H,sender:Q,sequence:J});return u0({accountNumber:G,asAminoMessage:L,asSignable:X,assetValue:B,memo:Z,sender:Q,sequence:J})}async function E6({assetValue:Y,sender:z}){let H=Y.chain,Z=await N6(H),X=await(await $(Z)).getAllBalances(z),L=Y.isGasAsset?(await s(H)).getBaseValue("bigint"):0n;return m({assetValue:Y,balances:X,denom:y(Y.symbol,!0),feeAmount:L})}async function h0({sender:Y,recipient:z,assetValue:H,memo:Z="",asSignable:Q=!0,asAminoMessage:X=!1,sequence:L,accountNumber:J}){let G=H.chain,B=J!==void 0&&L!==void 0?void 0:await p6({rpcUrl:await N6(G),sender:Y}),{chainId:U}=h6(G),V=u6({assetValue:H,recipient:z,sender:Y}),T=Q?h(X?V:u(V),G):V;return{accountNumber:J??Number(B?.accountNumber),chainId:U,fee:C(G),memo:Z,msgs:[T],sequence:L??Number(B?.sequence)}}async function u0({sender:Y,assetValue:z,memo:H="",asSignable:Z=!0,asAminoMessage:Q=!1,sequence:X,accountNumber:L}){let J=z.chain,G=L!==void 0&&X!==void 0?void 0:await p6({rpcUrl:await N6(J),sender:Y}),{chainId:B}=h6(J),U=l6({assetValue:z,memo:H,sender:Y}),V=Z?h(Q?U:u(U),J):U;return{accountNumber:L??Number(G?.accountNumber),chainId:B,fee:C(J),memo:H,msgs:[V],sequence:X??Number(G?.sequence)}}function u(Y){if(Y.type==="thorchain/MsgSend"||Y.type==="mayachain/MsgSend")return Y;return{...Y,value:{...Y.value,coins:Y.value.coins.map((z)=>{let H=j0.from({asset:z.asset}),Z=(H.isSynthetic?H.symbol.split("/")?.[1]:H.symbol)?.toUpperCase(),Q=(H.isSynthetic?H.symbol.split("/")?.[0]:H.chain)?.toUpperCase();return{...z,asset:{chain:Q,symbol:Z,synth:H.isSynthetic,ticker:H.ticker}}})}}}function Q6({chain:Y,memo:z,msgs:H}){let Z=d(),Q=j(Y),L=H.map((J)=>{let G=b6(Q,J.type);if(!G)throw new B6("toolbox_cosmos_invalid_params",{error:`No converter for amino type ${J.type}`});return{typeUrl:G.typeUrl,value:G.fromAmino(J.value)}}).map((J)=>f0(J,Z));return w0({memo:z,messages:L})}import{Chain as g,SwapKitError as k8}from"@swapkit/helpers";import{secp256k1 as l0}from"@noble/curves/secp256k1.js";import{base64 as V6,bech32 as U6}from"@scure/base";import{HDKey as b0}from"@scure/bip32";import{verifySignature as p0,createWalletFromMnemonic as d0,createWalletFromPrivateKey as c0,mnemonicToSeed as m0,signDirect as n0}from"@swapkit/cosmos-signer";import{AssetValue as M6,applyFeeMultiplier as c6,Chain as F,CosmosChainPrefixes as t6,DerivationPath as g0,derivationPathToString as m6,FeeOption as T6,getChainConfig as i0,getRPCUrl as n,NetworkDerivationPath as o0,SwapKitError as f,SwapKitNumber as K6,updateDerivationPath as t0}from"@swapkit/helpers";import{SwapKitApi as r6}from"@swapkit/helpers/api";import{PubKey as r0}from"cosmjs-types/cosmos/crypto/secp256k1/keys";import{match as a0,P as n6}from"ts-pattern";async function a6(Y,z){try{let Z=(await r6.getGasRate()).find((Q)=>Q.chainId===Y)?.value;return Z?Number.parseFloat(Z):z}catch{return z}}function s6(Y){let z=[{address:Y.address,algo:"secp256k1",pubkey:Y.publicKey}];return{getAccounts:()=>Promise.resolve(z),async signDirect(H,Z){if(H!==Y.address)throw new f("toolbox_cosmos_signer_not_defined");let Q=await n0(Y.privateKey,Y.publicKey,{accountNumber:Z.accountNumber,authInfoBytes:Z.authInfoBytes,bodyBytes:Z.bodyBytes,chainId:Z.chainId});return{signature:Q.signature,signed:{accountNumber:Q.signed.accountNumber,authInfoBytes:Q.signed.authInfoBytes,bodyBytes:Q.signed.bodyBytes,chainId:Q.signed.chainId}}}}}async function g6({phrase:Y,prefix:z,...H}){let Z="derivationPath"in H?H.derivationPath:`${g0[H.chain]}/${H.index}`,Q=await d0({hdPath:Z,mnemonic:Y,prefix:z??""});return s6(Q)}async function s0({privateKey:Y,prefix:z}){let H=c0({prefix:z,privateKey:Y});return s6(H)}var i6={[F.Cosmos]:1000,[F.Kujira]:1000,[F.Noble]:1000,[F.THORChain]:5000000,[F.Maya]:5000000,[F.Harbor]:5000000};function e0(Y){return async function({signature:H,message:Z,address:Q}){let X=await Y(Q);if(!X?.pubkey)throw new f("toolbox_cosmos_verify_signature_no_pubkey");let L=X.pubkey.type==="/cosmos.crypto.secp256k1.PubKey"?r0.decode(X.pubkey.value).key:X.pubkey.value;return p0(V6.decode(Z),V6.decode(H),L)}}function X6({chain:Y,...z}){let H=t6[Y],Z="index"in z?z.index||0:0,Q=m6("derivationPath"in z&&z.derivationPath?z.derivationPath:t0(o0[Y],{index:Z})),X;async function L(){if(X)return X;return X=await a0(z).with({phrase:n6.string},({phrase:N})=>g6({derivationPath:Q,phrase:N,prefix:H})).with({signer:n6.any},({signer:N})=>N).otherwise(()=>{return}),X}async function J(N){let I=await n(Y);return(await $(I)).getAccount(N)}async function G(){let N=await L(),[I]=await N?.getAccounts()||[];return I?.address}async function B(){let N=await L(),[I]=await N?.getAccounts()||[];if(!I?.pubkey)throw new f("toolbox_cosmos_signer_not_defined");return V6.encode(I?.pubkey)}async function U(N){let I=await L(),W=await G(),E=await n(Y);if(!(I&&W))throw new f("toolbox_cosmos_signer_not_defined");return(await p(E,I)).sign(W,N.msgs,N.fee,N.memo,{accountNumber:BigInt(N.accountNumber),chainId:N.chainId,sequence:N.sequence})}async function V(N){let I=await L(),W=await G(),E=await n(Y);if(!(I&&W))throw new f("toolbox_cosmos_signer_not_defined");let M=await(await p(E,I)).signAndBroadcast(W,N.msgs,N.fee,N.memo);if(M.code!==0)throw new f("core_swap_transaction_error",{code:M.code,message:M.rawLog});return M.transactionHash}async function T({recipient:N,assetValue:I,memo:W="",feeRate:E,feeOptionKey:R=T6.Fast,sweep:M}){let x=await L(),A=await G();if(!(x&&A))throw new f("toolbox_cosmos_signer_not_defined");let v=await n(Y),z6=M6.from({chain:Y}),Y6=e(z6),b=Z8(E||(await o6(Y,i6[Y]))[R],Y6,Y),H6=await p(v,x),c=y(I.symbol),L6=[{amount:(M?m({assetValue:I,balances:await R6(Y)(A),denom:c,feeAmount:W6(b.amount,c)}):I).getBaseValue("string"),denom:c}],{transactionHash:J6}=await H6.sendTokens(A,N,L6,b,W);return J6}return{createPrivateKeyFromPhrase:z8(Q),createTransaction:f6,fetchFeeRateFromSwapKit:a6,getAccount:J,getAddress:G,getBalance:async(N,I)=>{let W=await R6(Y)(N),E=await Promise.all(W.filter(({denom:R})=>R&&!R.includes("IBC/")&&!([F.THORChain,F.Maya].includes(Y)&&R.split("-").length>2)).map(({denom:R,amount:M})=>{let x=[F.THORChain,F.Maya].includes(Y)&&(R.includes("/")||R.includes("˜"))?`${Y}.${R}`:R;return w6(x,M)}));if(E.length===0)return[M6.from({chain:Y})];return E},getBalanceAsDenoms:R6(Y),getFees:()=>o6(Y,i6[Y]),getPubKey:B,getSignerFromPhrase:({phrase:N,derivationPath:I})=>g6({derivationPath:m6(I),index:Z,phrase:N,prefix:H}),getSignerFromPrivateKey:(N)=>s0({prefix:H,privateKey:N}),signAndBroadcastTransaction:V,signTransaction:U,transfer:T,validateAddress:X8(Y),verifySignature:e0(J)}}async function _Z(Y,z){try{let Z=(await r6.getGasRate()).find((Q)=>Q.chainId===Y)?.value;return Z?Number.parseFloat(Z):z}catch{return z}}function WZ({assetValue:{chain:Y}}){return M6.from({chain:Y,value:Q8(Y)})}async function o6(Y,z){let{chainId:H,baseDecimal:Z}=i0(Y),Q=await a6(H,z);return{average:K6.fromBigInt(BigInt(Q),Z),fast:K6.fromBigInt(BigInt(c6(Q,T6.Fast,!0)),Z),fastest:K6.fromBigInt(BigInt(c6(Q,T6.Fastest,!0)),Z)}}function Z8(Y,z,H){return{amount:[{amount:typeof Y==="number"?Y.toString():Y.getBaseValue("string"),denom:z}],gas:C(H).gas}}function Q8(Y){return{[F.Cosmos]:0.007,[F.Kujira]:0.02,[F.Noble]:0.01,[F.THORChain]:0.02,[F.Maya]:0.02,[F.Harbor]:0.02}[Y]||0}function X8(Y){let z=t6[Y];return function(Z){if(!Z.startsWith(z))return!1;try{let{prefix:Q,words:X}=U6.decode(Z);return U6.encode(Q,X)===Z.toLocaleLowerCase()}catch{return!1}}}function R6(Y){return async function(H){let Z=await n(Y);return(await(await $(Z)).getAllBalances(H)).map((J)=>({...J,denom:J.denom.includes("/")?J.denom.toUpperCase():J.denom}))}}function z8(Y){return async function(H){let Z=await m0(H),X=b0.fromMasterSeed(Z).derive(Y);if(!X.privateKey)throw new f("toolbox_cosmos_invalid_params",{error:"HDKey derivation produced no private key"});return l0.getPublicKey(X.privateKey,!0),Uint8Array.from(X.privateKey)}}import{secp256k1 as Y8}from"@noble/curves/secp256k1.js";import{base64 as w}from"@scure/base";import{buildMultisignedTx as H8,createMultisigThresholdPubkey as L8,signAmino as J8,createWalletFromMnemonic as G8,encodeTxRaw as q8,multisigPubkeyToAddress as _8,singlePubkeyToAddress as Z0}from"@swapkit/cosmos-signer";import{CosmosChainPrefixes as W8,derivationPathToString as O8,FeeOption as x6,getRPCUrl as Q0,NetworkDerivationPath as N8,SKConfig as B8,SwapKitError as l,updateDerivationPath as I8}from"@swapkit/helpers";import{match as E8,P as e6}from"ts-pattern";function U8(Y){let z=[{address:Y.address,algo:"secp256k1",pubkey:Y.publicKey}];return{accounts:z,getAccounts:()=>Promise.resolve(z),async signAmino(H,Z){if(H!==Y.address)throw new l("toolbox_cosmos_signer_not_defined");let Q=await J8(Y.privateKey,Y.publicKey,{signDoc:Z});return{signature:Q.signature,signed:Q.signed}}}}function K8({prefix:Y,derivationPath:z}){return async function(Z,Q=0){let X=await G8({hdPath:`${z}/${Q}`,mnemonic:Z,prefix:Y});return U8(X)}}function R8(Y){return w.encode(Y)}function V8(Y,z){return async function({wallet:Z,tx:Q}){let{msgs:X,accountNumber:L,sequence:J,chainId:G,fee:B,memo:U}=typeof Q==="string"?JSON.parse(Q):Q,V=(await Z.getAccounts())?.[0]?.address||"",T=j(Y,z),N=d(),I=await y6(Z,{aminoTypes:T,registry:N}),W=[];for(let M of X){let x=h(M,Y);W.push(x)}let{signatures:[E]}=await I.sign(V,W,B,U,{accountNumber:BigInt(L),chainId:G,sequence:J});return{bodyBytes:Q6({chain:Y,memo:U,msgs:X.map(u)}),signature:R8(E)}}}function X0(Y){if(Y.length!==33||Y[0]!==2&&Y[0]!==3)throw new l("toolbox_cosmos_invalid_params",{error:"Invalid compressed secp256k1 pubkey (must be 33 bytes starting with 0x02 or 0x03)"});return{type:"tendermint/PubKeySecp256k1",value:w.encode(Y)}}function M8({prefix:Y,chain:z}){return async function(Z,Q,X,L,J){let G=await Q0(z),{sequence:B,fee:U}=JSON.parse(Z),V=z0(X,L),T=Q.map((W)=>[Z0(X0(w.decode(W.pubKey)),Y),w.decode(W.signature)]),N=await $(G),{transactionHash:I}=await N.broadcastTx(H8({bodyBytes:J,fee:{amount:U.amount,gasLimit:BigInt(U.gas),...U.payer?{payer:U.payer}:{},...U.granter?{granter:U.granter}:{}},multisigPubkey:V,prefix:Y,sequence:B,signatures:new Map(T)}));return I}}function z0(Y,z,H=!0){return L8(Y.map((Z)=>X0(w.decode(Z))),z,H)}function T8(Y){return w.decode(Y)}function x8({privateKey:Y,message:z}){let H=Y8.sign(w.decode(z),Y,{lowS:!0,prehash:!1});return Promise.resolve(w.encode(H))}function Y0({chain:Y,...z}){let{isStagenet:H}=B8.get("envs"),Z=`${H?"s":""}${W8[Y]}`,Q="index"in z?z.index||0:0,X="derivationPath"in z&&z.derivationPath?z.derivationPath:I8(N8[Y],{index:Q}),L=X6({chain:Y,...z}),J=C(Y),G;function B(){return G??=E8(z).with({phrase:e6.string},({phrase:W})=>L.getSignerFromPhrase({derivationPath:X,phrase:W})).with({signer:e6.any},({signer:W})=>Promise.resolve(W)).otherwise(()=>Promise.resolve(void 0)),G}async function U(){let W=await Q0(Y),E=await B();if(!E)throw new l("toolbox_cosmos_no_signer");let R=d(),M=j(Y,Z),x=await p(W,E,{aminoTypes:M,registry:R});return{signer:E,signingClient:x}}async function V({fee:W,memo:E,msgs:R}){let{signer:M,signingClient:x}=await U(),A=(await M.getAccounts())?.[0]?.address;if(!A)throw new l("toolbox_cosmos_signer_not_defined");let v=await x.signAndBroadcast(A,R,W,E);if(v.code!==0)throw new l("core_swap_transaction_error",{code:v.code,message:v.rawLog});return v.transactionHash}async function T(){let W=await s(Y);return{[x6.Average]:W,[x6.Fast]:W,[x6.Fastest]:W}}async function N({assetValue:W,memo:E="",recipient:R,sweep:M}){let{signer:x,signingClient:A}=await U(),v=(await x.getAccounts())?.[0]?.address;if(!v)throw new l("toolbox_cosmos_no_signer");let z6="signAmino"in x,Y6=M?await E6({assetValue:W,sender:v}):W,b=I6({assetValue:Y6,memo:E,recipient:R,sender:v});if(z6){let k6=h(b,Y),{signatures:L6,authInfoBytes:J6}=await A.sign(v,[k6],J,E),H0=q8({authInfoBytes:J6,bodyBytes:Q6({chain:Y,memo:E,msgs:[b].map(u)}),signatures:L6});return(await A.broadcastTx(H0)).transactionHash}let H6=u(b),c=h(H6,Y);return V({fee:J,memo:E,msgs:[c]})}async function I(W){let{signer:E,signingClient:R}=await U(),M=(await E.getAccounts())?.[0]?.address;if(!M)throw new l("toolbox_cosmos_signer_not_defined");return R.sign(M,W.msgs,W.fee,W.memo,{accountNumber:BigInt(W.accountNumber),chainId:W.chainId,sequence:W.sequence})}return{...L,broadcastMultisigTx:M8({chain:Y,prefix:Z}),buildAminoMsg:I6,buildEncodedTxBody:Q6,convertToSignable:h,createDefaultAminoTypes:()=>j(Y,Z),createDefaultRegistry:d,createMultisig:z0,createTransaction:d6,deposit:N,getFees:T,importSignature:T8,parseAminoMessageForDirectSigning:u,pubkeyToAddress:(W)=>{if(W.type==="tendermint/PubKeyMultisigThreshold")return _8(W,Z);return Z0(W,Z)},secp256k1HdWalletFromMnemonic:K8({derivationPath:O8(X),prefix:Z}),signAndBroadcastTransaction:V,signMultisigTx:V8(Y,Z),signTransaction:I,signWithPrivateKey:x8,transfer:N}}var FZ=(Y,z)=>{switch(Y){case g.Cosmos:case g.Kujira:case g.Noble:return X6({chain:Y,...z});case g.Maya:case g.THORChain:return Y0({chain:Y,...z});default:throw new k8("toolbox_cosmos_not_supported",{chain:Y})}};export{e0 as verifySignature,u6 as transferMsgAmino,P8 as toBase64,E6 as resolveThorchainSweepAssetValue,u as parseAminoMessageForDirectSigning,s as getThorchainNativeFee,m as getSweepAssetValue,s0 as getSignerFromPrivateKey,g6 as getSignerFromPhrase,y as getMsgSendDenom,_Z as getFeeRateFromSwapKit,W6 as getFeeAmountForDenom,e as getDenomWithChain,C as getDefaultChainFee,FZ as getCosmosToolbox,X8 as getCosmosAddressValidator,w6 as getAssetFromDenom,A8 as fromBase64,a6 as fetchFeeRateFromSwapKit,WZ as estimateTransactionFee,l6 as depositMsgAmino,d6 as createTransaction,Y0 as createThorchainToolbox,$ as createStargateClient,p as createSigningStargateClient,y6 as createOfflineStargateClient,d as createDefaultRegistry,j as createDefaultAminoTypes,X6 as createCosmosToolbox,f6 as cosmosCreateTransaction,h as convertToSignable,h0 as buildTransferTx,Q6 as buildEncodedTxBody,u0 as buildDepositTx,I6 as buildAminoMsg,t as bech32ToBase64,r as base64ToBech32,E0 as YUM_KUJIRA_FACTORY_DENOM,A6 as USK_KUJIRA_FACTORY_DENOM,g8 as THORCHAIN_GAS_VALUE,i8 as MAYA_GAS_VALUE,R0 as DEFAULT_NOBLE_FEE_MAINNET,K0 as DEFAULT_KUJI_FEE_MAINNET,U0 as DEFAULT_COSMOS_FEE_MAINNET};