@swapkit/toolboxes 5.3.0 → 5.4.1
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.
- package/CHANGELOG.md +23 -0
- package/dist/{chunk-k50sjysj.js → chunk-4428244x.js} +1 -1
- package/dist/{chunk-s1528ghz.js → chunk-as9fracn.js} +1 -1
- package/dist/chunk-dssawneq.js +1 -0
- package/dist/chunk-rn33j2bm.js +2 -0
- package/dist/src/aleo/index.js +1 -1
- package/dist/src/aptos/index.js +1 -1
- package/dist/src/cardano/index.js +1 -1
- package/dist/src/cosmos/index.js +1 -1
- package/dist/src/evm/index.js +1 -1
- package/dist/src/hypercore/index.js +1 -1
- package/dist/src/index.js +1 -1
- package/dist/src/near/index.js +1 -1
- package/dist/src/radix/index.js +1 -1
- package/dist/src/ripple/index.js +1 -1
- package/dist/src/solana/index.js +1 -1
- package/dist/src/starknet/index.js +1 -1
- package/dist/src/stellar/index.js +1 -1
- package/dist/src/substrate/index.js +1 -1
- package/dist/src/sui/index.js +1 -1
- package/dist/src/ton/index.js +1 -1
- package/dist/src/tron/index.js +1 -1
- package/dist/src/utxo/index.js +1 -1
- package/dist/types/evm/toolbox/evm.d.ts +172 -0
- package/dist/types/evm/types.d.ts +2 -1
- package/dist/types/utxo/__tests__/fixtures/utxo.d.ts +178 -0
- package/dist/types/utxo/helpers/bchaddrjs.d.ts +17 -1
- package/dist/types/utxo/helpers/txSize.d.ts +7 -5
- package/dist/types/utxo/index.d.ts +1 -1
- package/dist/types/utxo/toolbox/bitcoinCash.d.ts +1 -0
- package/dist/types/utxo/toolbox/index.d.ts +1 -1
- package/dist/types/utxo/toolbox/utxo.d.ts +6 -0
- package/dist/types/utxo/toolbox/validators.d.ts +2 -1
- package/dist/types/utxo/toolbox/zcash.d.ts +1 -0
- package/package.json +2 -2
- package/dist/chunk-1ma8fv42.js +0 -2
- package/dist/chunk-z8n8qjs5.js +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,28 @@
|
|
|
1
1
|
# @swapkit/toolboxes
|
|
2
2
|
|
|
3
|
+
## 5.4.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#404](https://github.com/swapkit/sdk/pull/404) [`ce7f02d`](https://github.com/swapkit/sdk/commit/ce7f02def2c25307c403b20f213a383834ab8bcc) Thanks [@towanTG](https://github.com/towanTG)! - Changes base url for token icons (via @swapkit/helpers@5.4.1)
|
|
8
|
+
- [#401](https://github.com/swapkit/sdk/pull/401) [`7f87112`](https://github.com/swapkit/sdk/commit/7f871121b2949d12de4e5809be7fb544f119dec8) Thanks [@ice-chillios](https://github.com/ice-chillios)! - `generatePhrase` now defaults to a 24-word (256-bit entropy) seed phrase, accepts every BIP39 length (12, 15, 18, 21 or 24 words) and throws `wallet_keystore_invalid_word_count` (21903, added to `@swapkit/helpers`) for anything else instead of silently using 256 bits. New `generateKeystore({ password, wordCount })` creates a phrase and its encrypted keystore in one call; `PhraseWordCount` is exported for wallet-creation UIs offering the choice. (via @swapkit/helpers@5.4.1)
|
|
9
|
+
- [#405](https://github.com/swapkit/sdk/pull/405) [`cbbfdcf`](https://github.com/swapkit/sdk/commit/cbbfdcfbf676855f5bff53547854a725b29f1a7b) Thanks [@hippocampusSK](https://github.com/hippocampusSK)! - Add public Arc mainnet RPC (`https://rpc.mainnet.arc.io`) as the default `rpcUrls` entry for `Chain.Arc` (via @swapkit/helpers@5.4.1)
|
|
10
|
+
- [#399](https://github.com/swapkit/sdk/pull/399) [`70749e7`](https://github.com/swapkit/sdk/commit/70749e7899630daabc371a36c498f62b9da1c62f) Thanks [@github-actions](https://github.com/apps/github-actions)! - Update generated token lists. (via @swapkit/helpers@5.4.1)
|
|
11
|
+
|
|
12
|
+
## 5.4.0
|
|
13
|
+
|
|
14
|
+
### Minor Changes
|
|
15
|
+
|
|
16
|
+
- [#382](https://github.com/swapkit/sdk/pull/382) [`2ef09ec`](https://github.com/swapkit/sdk/commit/2ef09ec782e61176e2576554c25cca6d8f2374de) Thanks [@hippocampusSK](https://github.com/hippocampusSK)! - Add Arc (`5042`) EVM chain: chain/chainId enums, chain config, EVM toolbox wiring, and native `ARC.USDC` gas-asset handling in `isGasAsset` / `getCommonAssetInfo` / `getAssetType` / `getTokenAddress`. Arc ships with rpcUrls: [], so connectKeystore skips it and toolbox calls fail with helpers_chain_no_public_or_set_rpc_url until SKConfig.setRpcUrl(Chain.Arc, […]) is set
|
|
17
|
+
- [#385](https://github.com/swapkit/sdk/pull/385) [`c8e9da7`](https://github.com/swapkit/sdk/commit/c8e9da74d13ad5b8c533d626400feff9364420fa) Thanks [@hippocampusSK](https://github.com/hippocampusSK)! - Expose the address form an address string decodes to, instead of discarding it behind a boolean. Address validation already computed the script type; new siblings surface it without changing any existing validator's return type:
|
|
18
|
+
- [#374](https://github.com/swapkit/sdk/pull/374) [`54d0f14`](https://github.com/swapkit/sdk/commit/54d0f14ec3d58e66b0036ad6c8dcfd0f823dbd2a) Thanks [@ice-chillios](https://github.com/ice-chillios)! - `getAddressValidator` now handles the Substrate chains. Polkadot (DOT) and Chainflip (FLIP) had no arm in the chain match, so they fell through to the catch-all and every address — including valid ones — was reported as invalid. Consumers of `swapKit.validateAddress`, which is built on this validator, were affected; the server-side `validateChainAddress` already covered these chains.
|
|
19
|
+
- [#393](https://github.com/swapkit/sdk/pull/393) [`25570ca`](https://github.com/swapkit/sdk/commit/25570ca23f90b4ed104061b5561c35ab1c47f1c6) Thanks [@hippocampusSK](https://github.com/hippocampusSK)! - **One table describes the UTXO script types.** `@swapkit/helpers` now exports `UTXOScriptType` (with `P2SH_P2WPKH` and `P2TR` alongside `P2PKH` and `P2WPKH`), `UTXO_SCRIPT_TYPES` (BIP43 purpose, input and output size in vBytes, witness flag per type), `UTXO_SCRIPT_TYPE_LIST`, and the path helpers `getPurposeFromPath`, `getUTXOScriptTypeForPurpose` and `getUTXOScriptTypeForPath`. Error key `toolbox_utxo_unsupported_script_type` (50315) is reserved for the toolboxes.
|
|
20
|
+
- [#391](https://github.com/swapkit/sdk/pull/391) [`cf94a27`](https://github.com/swapkit/sdk/commit/cf94a27a52ac37c78d3a72bbbe7ee3acf14c192e) Thanks [@hippocampusSK](https://github.com/hippocampusSK)! - **Eight fixes to the UTXO send path**, reached today by external signers spending from legacy Bitcoin and Litecoin addresses, and by every chain without segwit.
|
|
21
|
+
- [#391](https://github.com/swapkit/sdk/pull/391) [`cf94a27`](https://github.com/swapkit/sdk/commit/cf94a27a52ac37c78d3a72bbbe7ee3acf14c192e) Thanks [@hippocampusSK](https://github.com/hippocampusSK)! - **Three fixes to `createReplacementTransaction`/`bumpFee`** (Bitcoin, the only chain in `rbfSupportedChains`):
|
|
22
|
+
- [#379](https://github.com/swapkit/sdk/pull/379) [`4450ac4`](https://github.com/swapkit/sdk/commit/4450ac4200a565d5ce38a26d31f3836a3713ff75) Thanks [@ice-chillios](https://github.com/ice-chillios)! - `derivationPathToString` now accepts sliced derivation paths through the new `DerivationPathLike` (`readonly (number | undefined)[]`) type, so prefixes no longer need to be cast to `DerivationPathArray`. (via @swapkit/helpers@5.4.0)
|
|
23
|
+
- [#362](https://github.com/swapkit/sdk/pull/362) [`cbbfccd`](https://github.com/swapkit/sdk/commit/cbbfccdcbbe3e5ad3ffb531a030e2562c8e3f470) Thanks [@towanTG](https://github.com/towanTG)! - Preserve stored numeric precision across comparisons, arithmetic operands, copies, `set`, and AssetValue conversion instead of converting through display-rounded strings. Compare exact values regardless of declared asset decimals, and cap arithmetic results at 64 decimal places without mis-scaling longer inputs or turning small nonzero divisors into zero. Fix half-up display carries and explicit base-unit rescaling while preserving asset identity and destination decimals. (via @swapkit/helpers@5.4.0)
|
|
24
|
+
- [#399](https://github.com/swapkit/sdk/pull/399) [`70749e7`](https://github.com/swapkit/sdk/commit/70749e7899630daabc371a36c498f62b9da1c62f) Thanks [@github-actions](https://github.com/apps/github-actions)! - Update generated token lists. (via @swapkit/helpers@5.4.0)
|
|
25
|
+
|
|
3
26
|
## 5.3.0
|
|
4
27
|
|
|
5
28
|
### Minor Changes
|
|
@@ -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
|
|
2
|
+
export{d as ha};
|
|
@@ -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})=>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
|
|
2
|
+
export{C as fa,h as ga};
|
|
@@ -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,ea as S,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-rn33j2bm.js";import"./chunk-as9fracn.js";import"./chunk-4428244x.js";export{u as ADIToolbox,v as ARBToolbox,w as ARCToolbox,x as AURORAToolbox,y as AVAXToolbox,z as BASEToolbox,A as BERAToolbox,B as BSCToolbox,b as BaseEVMToolbox,C as BotanixToolbox,D as COREToolbox,E as CORNToolbox,F as CROToolbox,k as ContractAddress,t as ETHToolbox,G as GNOToolbox,H as HOODToolbox,I as HYPEREVMToolbox,J as LINEAToolbox,K as MATICToolbox,a as MAX_APPROVAL,L as MEGAETHToolbox,M as MONADToolbox,s as OPToolbox,N as PLASMAToolbox,O as SONICToolbox,P as UNIToolbox,Q as XLayerToolbox,e as createContract,r as createOPStackToolbox,j as getChecksumAddressFromAsset,f as getCreateContract,m as getCreateContractTxObject,i as getEIP1193SendTransaction,q as getEVMTxType,n as getEstimateGasPrices,R as getEvmToolbox,S as getEvmToolboxAsync,l as getTokenAddress,d as isBrowserProvider,p as isEIP1559Transaction,o as isEIP7702Transaction,g as isStateChangingCall,h as toChecksumAddress,c as validateEVMAddress};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{ga as Be}from"./chunk-as9fracn.js";import{ha as ye}from"./chunk-4428244x.js";import{Chain as P}from"@swapkit/helpers";import{match as Gn}from"ts-pattern";import{Chain as g,getChainConfig as J,getRPCUrl as ht,SKConfig as vt,SwapKitError as j}from"@swapkit/helpers";import{FallbackProvider as Et,getAddress as ve,Interface as _t,JsonRpcProvider as se,Network as Ct}from"ethers";import{match as Ee}from"ts-pattern";function At(e){return new se(e)}async function Sn(e,t){return At(t||await ht(e))}function _e(e){let t=vt.get("rpcUrls")[e]?.filter(Boolean)??[];if(t.length===0)throw new j("helpers_chain_no_public_or_set_rpc_url",{chain:e});let{chainId:n}=J(e),o=Ct.from(Number(n)),[a]=t;if(t.length===1)return new se(a,o,{staticNetwork:o});return new Et(t.map((r,i)=>({priority:i+1,provider:new se(r,o,{staticNetwork:o}),stallTimeout:2000})),o,{quorum:1})}function B(e){return e>0n?`0x${e.toString(16)}`:"0x0"}function Ce(e){let{explorerUrl:t,chainIdHex:n,rpcUrls:o}=J(e);return function(){return e!==g.Ethereum?{...Ft({chain:e}),blockExplorerUrls:[t],chainId:n,rpcUrls:o}:void 0}}function Ae(e){return![g.Adi,g.Arbitrum,g.BinanceSmartChain,g.Robinhood].includes(e)}function Ft({chain:e}){let{name:t,nativeCurrency:n,baseDecimal:o}=J(e);return Ee(e).with(g.Arbitrum,()=>({chainName:"Arbitrum One",nativeCurrency:{decimals:o,name:"Ethereum",symbol:g.Ethereum}})).with(g.Aurora,()=>({chainName:"Aurora Mainnet",nativeCurrency:{decimals:o,name:"Ethereum",symbol:g.Ethereum}})).with(g.Avalanche,()=>({chainName:"Avalanche Network",nativeCurrency:{decimals:o,name:"Avalanche",symbol:e}})).with(g.Base,()=>({chainName:"Base Mainnet",nativeCurrency:{decimals:o,name:"Ethereum",symbol:g.Ethereum}})).with(g.Berachain,()=>({chainName:"Berachain",nativeCurrency:{decimals:o,name:"Berachain",symbol:"BERA"}})).with(g.XLayer,()=>({chainName:"X Layer",nativeCurrency:{decimals:o,name:"OKB",symbol:"OKB"}})).with(g.BinanceSmartChain,()=>({chainName:"BNB Smart Chain Mainnet",nativeCurrency:{decimals:o,name:"Binance Coin",symbol:"BNB"}})).with(g.Gnosis,()=>({chainName:"Gnosis",nativeCurrency:{decimals:o,name:"xDAI",symbol:"XDAI"}})).with(g.Optimism,()=>({chainName:"OP Mainnet",nativeCurrency:{decimals:o,name:"Ethereum",symbol:g.Ethereum}})).with(g.Polygon,()=>({chainName:"Polygon Mainnet",nativeCurrency:{decimals:o,name:"Polygon",symbol:g.Polygon}})).with(g.Robinhood,()=>({chainName:"Robinhood Chain",nativeCurrency:{decimals:o,name:"Ethereum",symbol:g.Ethereum}})).otherwise(()=>({chainName:t,nativeCurrency:{decimals:o,name:n,symbol:n}}))}async function Fe(e,t){if(!("authorize"in e))throw Error("Signer does not support EIP-7702 authorization. Requires ethers.js v6.14+");let n={...t,nonce:t.nonce!==void 0?BigInt(t.nonce):void 0};return await e.authorize(n)}var he=(e)=>typeof e==="string"&&/^0x[a-fA-F0-9]{64}$/.test(e),Mt=(e)=>{try{return typeof e==="string"&&!!ve(e)}catch{return!1}};function Gt(e,t){let n=t!==void 0?`index ${t}: `:"",o=(a,r)=>{throw new j({errorKey:"toolbox_evm_invalid_eip7702_authorization",info:{field:a,message:`${n}${r}`}})};Ee(e).when(({chainId:a})=>typeof a!=="bigint",()=>o("chainId","chainId must be a bigint")).when(({address:a})=>!Mt(a),()=>o("address","address must be a valid checksummed address")).when(({nonce:a})=>typeof a!=="bigint"||a<0n,()=>o("nonce","nonce must be a non-negative bigint")).when(({signature:a})=>!a,()=>o("signature","signature is required")).when(({signature:a})=>typeof a?.yParity!=="number"||![0,1].includes(a.yParity),()=>o("signature.yParity","yParity must be 0 or 1")).when(({signature:a})=>!he(a?.r),()=>o("signature.r","r must be a 32-byte hex string")).when(({signature:a})=>!he(a?.s),()=>o("signature.s","s must be a 32-byte hex string")).otherwise(()=>{})}function Bt(e){return[{key:"name",type:"string"},{key:"version",type:"string"},{key:"chainId",type:"uint256"},{key:"verifyingContract",type:"address"},{key:"salt",type:"bytes32"}].filter(({key:t})=>e[t]!=null).map(({key:t,type:n})=>({name:t,type:n}))}function ce(e){return e.charAt(0).toUpperCase()+e.slice(1)}function ue(e,t){if(e.isTuple()&&e.components){let n=ce(e.name);return t[n]=e.components.map((o)=>({name:o.name,type:ue(o,t)})),n}if(e.isArray()){let n=e.arrayChildren;if(n?.isTuple()&&n.components){let o=ce(e.name.replace(/s$/,""));return t[o]=n.components.map((a)=>({name:a.name,type:ue(a,t)})),`${o}[]`}return`${n?.type??"bytes"}[]`}return e.type}function le(e,t){if(typeof e==="bigint")return e;if(t?.isTuple()&&typeof e?.toObject==="function"){let n=e.toObject(),o={};for(let[a,r]of(t.components??[]).entries())o[r.name]=le(n[r.name]??e[a],r);return o}if(Array.isArray(e)){let n=t?.arrayChildren;return e.map((o)=>le(o,n??void 0))}return e}function Rn({chain:e,abi:t,data:n,to:o}){let r=new _t(t).parseTransaction({data:n});if(!r)throw new j({errorKey:"toolbox_evm_invalid_params",info:{error:"Could not decode calldata"}});let i={},s=ce(r.name);i[s]=r.fragment.inputs.map((p)=>({name:p.name,type:ue(p,i)}));let c={};for(let[p,y]of r.fragment.inputs.entries())c[y.name]=le(r.args[p],y);let{chainId:l}=J(e),u={chainId:Number(l),verifyingContract:ve(o)},b=Bt(u);return{domain:u,message:c,primaryType:s,types:{EIP712Domain:b,...i}}}function Me(e,t){if(!Array.isArray(e)||e.length===0)throw new j({errorKey:"toolbox_evm_invalid_eip7702_authorization",info:{message:"EIP-7702 transactions require at least one authorization"}});for(let[n,o]of e.entries())if(Gt(o,n),t!==void 0&&o.chainId!==t)throw new j({errorKey:"toolbox_evm_invalid_eip7702_authorization",info:{field:"chainId",message:`index ${n}: authorization chainId (${o.chainId}) does not match transaction chainId (${t})`}})}import{Chain as T,derivationPathToString as En,FeeOption as _n,resolveDerivationPath as Cn}from"@swapkit/helpers";import{HDNodeWallet as An}from"ethers";import{match as Fn,P as Ze}from"ts-pattern";var Ge=[{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 Ot,applyFeeMultiplierToBigInt as M,Chain as O,EVMChains as It,FeeOption as d,isGasAsset as Vt,SwapKitError as m,SwapKitNumber as Q}from"@swapkit/helpers";import{erc20ABI as z}from"@swapkit/helpers/contracts";import{BrowserProvider as St,Contract as Ve,getAddress as ee,getBytes as Rt,Interface as Se,isError as U,resolveAddress as Nt,Transaction as pe}from"ethers";import{match as Re}from"ts-pattern";function Y(e){return{getBalance:Be(e)}}function Dn(e){return e}var be=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");function te({chain:e=O.Ethereum,provider:t,signer:n,isEIP1559Compatible:o=!0,estimateGasPrices:a,estimateAdditionalFee:r}){let i=a??X({chain:e,isEIP1559Compatible:o,provider:t}),s=qe({chain:e,estimateAdditionalFee:r,estimateGasPrices:i,isEIP1559Compatible:o,provider:t,signer:n});return{approve:Yt({chain:e,isEIP1559Compatible:o,provider:t,signer:n}),approvedAmount:Ue({chain:e,provider:t}),broadcastTransaction:(c)=>t.broadcastTransaction(c),call:ae({chain:e,isEIP1559Compatible:o,provider:t,signer:n}),createApprovalTx:mn({chain:e,provider:t,signer:n}),createContract:Lt({chain:e,provider:t}),createContractTxObject:W({chain:e,provider:t}),createTransaction:s,createTransferTx:s,EIP1193SendTransaction:oe(t),estimateCall:He({provider:t,signer:n}),estimateGasLimit:Zt({chain:e,provider:t,signer:n}),estimateGasPrices:i,estimateTransactionFee:pn({chain:e,isEIP1559Compatible:o,provider:t}),getAddress:()=>n?n.getAddress():void 0,getBalance:Y(e).getBalance,getNetworkParams:Ce(e),isApproved:Jt({chain:e,provider:t}),sendTransaction:Ke({chain:e,estimateGasPrices:i,isEIP1559Compatible:o,provider:t,signer:n}),signAuthorization:en({signer:n}),signMessage:n?(c)=>n.signMessage(c):void 0,signTypedData:n?({domain:c,types:l,value:u})=>n.signTypedData(c,l,u):void 0,transfer:Qt({chain:e,estimateAdditionalFee:r,estimateGasPrices:i,isEIP1559Compatible:o,provider:t,signer:n}),validateAddress:kt}}function kt(e){try{return ee(e),!0}catch{return!1}}function ne(e){return e instanceof St}function ge(e,t,n){return new Ve(e,Se.from(t),n)}function Lt({provider:e}){return function(n,o){return new Ve(n,Se.from(o),e)}}var Dt=["payable","nonpayable"];function Ut({abi:e,funcName:t}){let n=e.find((o)=>o.name===t);if(!n)throw new m("toolbox_evm_no_abi_fragment",{funcName:t});return n.stateMutability&&Dt.includes(n.stateMutability)}function Xn(e){return ee(e)}var Ht=30000,Oe=new WeakMap,Ie=()=>{};function zt(e,t,n){let o=Date.now();for(let[r,i]of e)if(i.held===0&&o-i.at>Ht)e.delete(r);let a=e.get(t);if(!a||n>=a.next){let r={at:o,held:1,next:n+1,released:new Set};return e.set(t,r),{floor:r,nonce:n}}a.held+=1;for(let r of[...a.released].sort((i,s)=>i-s))if(a.released.delete(r),r>=n)return{floor:a,nonce:r};return{floor:a,nonce:a.next++}}async function Ne({address:e,nonce:t,provider:n}){if(t!==void 0&&t!==null)return{nonce:t,release:Ie,settle:Ie};let{chainId:o}=await n.getNetwork(),a=Oe.get(n)??new Map;Oe.set(n,a);let r=`${o}:${e.toLowerCase()}`,i=await n.getTransactionCount(e,"pending"),{floor:s,nonce:c}=zt(a,r,i),l=!1,u=(b)=>{if(l)return;if(l=!0,s.held-=1,s.at=Date.now(),b)s.released.add(c)};return{nonce:c,release:()=>u(!0),settle:()=>u(!1)}}function Z(e,t=0){if(!e||t>3)return"";if(typeof e==="string")return e.toLowerCase();if(typeof e!=="object")return"";let{error:n,info:o,message:a,shortMessage:r}=e;return[(typeof r==="string"?r:typeof a==="string"?a:"").toLowerCase(),Z(n,t+1),Z(o?.error,t+1)].filter(Boolean).join(" ")}function fe(e){if(U(e,"NONCE_EXPIRED")||U(e,"REPLACEMENT_UNDERPRICED"))return!0;let t=Z(e);return/nonce (?:is )?too low/.test(t)||t.includes("replacement transaction underpriced")}function de(e){let t=Z(e);return t.includes("already known")||t.includes("known transaction")||t.includes("already imported")}function ke(e){return U(e,"NETWORK_ERROR")||U(e,"SERVER_ERROR")||U(e,"TIMEOUT")}function Kt(e){return ke(e)||U(e,"UNSUPPORTED_OPERATION")}function Le(e){return ke(e)||de(e)}function De(e,t){return e.getTransaction(t).then((n)=>n!==null,()=>!1)}async function qt({provider:e,signer:t,txObject:n}){try{let o=pe.from(await t.signTransaction(n)).hash;return o&&await De(e,o)?o:null}catch{return null}}function oe(e,t=!1){return function({value:o,...a}){if(!ne(e))throw new m("toolbox_evm_provider_not_eip1193_compatible");let r={...a,gasPrice:"gasPrice"in a?a.gasPrice:void 0,maxFeePerGas:"maxFeePerGas"in a?a.maxFeePerGas:void 0,maxPriorityFeePerGas:"maxPriorityFeePerGas"in a?a.maxPriorityFeePerGas:void 0},{gasLimit:i,gasPrice:s,maxFeePerGas:c,maxPriorityFeePerGas:l,...u}=r,b={...u,...t&&i!==void 0&&{gas:B(BigInt(i))},...t&&s!==void 0&&{gasPrice:B(BigInt(s))},...t&&c!==void 0&&{maxFeePerGas:B(BigInt(c))},...t&&l!==void 0&&{maxPriorityFeePerGas:B(BigInt(l))},value:B(BigInt(o||0))};return e.send("eth_sendTransaction",[b])}}function $n(e,t){let n=Pe(e,t);if(n)return ee(n.toLowerCase());throw new m("toolbox_evm_invalid_gas_asset_address")}var jt=It.reduce((e,t)=>(e[t]="0x0000000000000000000000000000000000000000",e),{}),Wt={...jt,[O.Optimism]:"0x4200000000000000000000000000000000000042",[O.Polygon]:"0x0000000000000000000000000000000000001010"},Xt=[O.Arbitrum,O.Aurora,O.Base,O.Optimism,O.Robinhood];function Pe({chain:e,symbol:t,ticker:n},o){try{let a=e===O.BinanceSmartChain&&t==="BNB"&&n==="BNB",r=e===O.Hyperevm&&t==="HYPE"&&n==="HYPE",i=e===o&&t===o&&n===o,s=Xt.includes(e)&&t==="ETH"&&n==="ETH",c=e===O.Arc&&t==="USDC"&&n==="USDC";if(i||a||r||s||c)return Wt[o];return ee(t.slice(n.length+1).replace(/^0X/,""))}catch{return null}}function W({provider:e}){return async({contractAddress:t,abi:n,funcName:o,funcParams:a=[],txOverrides:r})=>{let i=await ge(t,n,e).getFunction(o).populateTransaction(...a.concat(r).filter((s)=>typeof s<"u"));return{...i,value:B(BigInt(i.value||0))}}}function X({chain:e,provider:t,isEIP1559Compatible:n=!0}){return Re(e).with(O.Gnosis,()=>async function(){try{let{gasPrice:a,maxPriorityFeePerGas:r}=await t.getFeeData();if(!a||r===null)throw new m("toolbox_evm_no_fee_data");return{[d.Average]:{maxFeePerGas:M(a,d.Average),maxPriorityFeePerGas:M(r,d.Average)},[d.Fast]:{maxFeePerGas:M(a,d.Fast),maxPriorityFeePerGas:M(r,d.Fast)},[d.Fastest]:{maxFeePerGas:M(a,d.Fastest),maxPriorityFeePerGas:M(r,d.Fastest)}}}catch(a){throw new m("toolbox_evm_gas_estimation_error",{error:a.msg??a.toString()})}}).with(O.Arbitrum,()=>async function(){try{let{gasPrice:a}=await t.getFeeData();if(!a)throw new m("toolbox_evm_no_fee_data");let r=a*12n/10n;return{[d.Average]:{gasPrice:r},[d.Fast]:{gasPrice:M(r,d.Fast)},[d.Fastest]:{gasPrice:M(r,d.Fastest)}}}catch(a){throw new m("toolbox_evm_gas_estimation_error",{error:a.msg??a.toString()})}}).otherwise(()=>async function(){try{let{maxFeePerGas:a,maxPriorityFeePerGas:r,gasPrice:i}=await t.getFeeData();if(n){if(a===null||r===null)throw new m("toolbox_evm_no_fee_data");return{[d.Average]:{maxFeePerGas:a,maxPriorityFeePerGas:r},[d.Fast]:{maxFeePerGas:M(a,d.Fast),maxPriorityFeePerGas:M(r,d.Fast)},[d.Fastest]:{maxFeePerGas:M(a,d.Fastest),maxPriorityFeePerGas:M(r,d.Fastest)}}}if(!i)throw new m("toolbox_evm_no_gas_price");return{[d.Average]:{gasPrice:i},[d.Fast]:{gasPrice:M(i,d.Fast)},[d.Fastest]:{gasPrice:M(i,d.Fastest)}}}catch(a){throw new m("toolbox_evm_gas_estimation_error",{error:a.msg??a.toString()})}})}async function $t({chain:e,contract:t,contractProvider:n,feeOption:o,funcName:a,funcParams:r,isEIP1559Compatible:i,provider:s,signer:c,txOverrides:l}){let u=l?.from||await c.getAddress();if(!u)throw new m("toolbox_evm_no_signer_address");let b=t.connect(c),p=X({chain:e,isEIP1559Compatible:i,provider:s}),[{maxFeePerGas:y,maxPriorityFeePerGas:f,gasPrice:x},F]=await Promise.all([p().then((_)=>_[o]),t.getFunction(a).estimateGas(...r,l)]),C=typeof u==="string"?u:await Nt(u,n),{nonce:G,release:R,settle:k}=await Ne({address:C,nonce:l?.nonce,provider:c.provider??s});try{let _=await b[a](...r,{...l,gasLimit:F,gasPrice:x,maxFeePerGas:y,maxPriorityFeePerGas:f,nonce:G});return typeof _?.hash==="string"?_?.hash:_}catch(_){if(fe(_)){let E=l?.nonce!=null?"caller":"pending",w={address:C,error:_,nonce:G,nonceSource:E};throw new m({errorKey:"toolbox_evm_nonce_conflict",info:w},w)}if(!Le(_))R();throw _}finally{k()}}function ae({provider:e,isEIP1559Compatible:t,signer:n,chain:o}){return async function({callProvider:r,contractAddress:i,abi:s,funcName:c,funcParams:l=[],txOverrides:u={},feeOption:b=d.Fast}){let p=r||e;if(!i)throw new m("toolbox_evm_invalid_params",{error:"contractAddress must be provided"});let y=Ut({abi:s,funcName:c});if(y&&ne(p)&&n){let F=W({chain:o,provider:p}),C=u?.from||await n?.getAddress(),G=await F({abi:s,contractAddress:i,funcName:c,funcParams:l,txOverrides:{...u,from:C}});return oe(p)(G)}let f=ge(i,s,p);if(y){if(!n)throw new m("toolbox_evm_no_signer");return $t({chain:o,contract:f,contractProvider:p,feeOption:b,funcName:c,funcParams:l,isEIP1559Compatible:t,provider:e,signer:n,txOverrides:u})}let x=await f[c]?.(...l);return typeof x?.hash==="string"?x?.hash:x}}function Ue({provider:e,chain:t}){return function({assetAddress:o,spenderAddress:a,from:r}){return ae({chain:t,isEIP1559Compatible:!0,provider:e})({abi:z,contractAddress:o,funcName:"allowance",funcParams:[r,a]})}}function Jt({provider:e,chain:t}){return async function({assetAddress:o,spenderAddress:a,from:r,amount:i=be}){let s=await Ue({chain:t,provider:e})({assetAddress:o,from:r,spenderAddress:a});return Q.fromBigInt(s).gte(Q.fromBigInt(BigInt(i)))}}function Yt({signer:e,isEIP1559Compatible:t=!0,provider:n,chain:o}){return async function({assetAddress:r,spenderAddress:i,feeOptionKey:s=d.Fast,amount:c,gasLimitFallback:l,from:u,nonce:b}){let p=[i,BigInt(c||be)],y=await e?.getAddress()||u,f={abi:z,contractAddress:r,funcName:"approve",funcParams:p,signer:e,txOverrides:{from:y}};if(ne(n)){let F=W({chain:o,provider:n}),C=oe(n),G=await F(f);return C(G)}return ae({chain:o,isEIP1559Compatible:t,provider:n,signer:e})({...f,feeOption:s,funcParams:p,txOverrides:{from:y,gasLimit:l?BigInt(l.toString()):void 0,nonce:b}})}}function Qt({chain:e,estimateGasPrices:t,estimateAdditionalFee:n,signer:o,isEIP1559Compatible:a=!0,provider:r}){return async function({assetValue:s,memo:c,recipient:l,feeOptionKey:u=d.Fast,sender:b,sweep:p,...y}){let f=b||await o?.getAddress(),x=Ke({chain:e,estimateGasPrices:t,isEIP1559Compatible:a,provider:r,signer:o});if(!f)throw new m("toolbox_evm_no_from_address");let F=await qe({chain:e,estimateAdditionalFee:n,estimateGasPrices:t,isEIP1559Compatible:a,provider:r,signer:o})({assetValue:s,feeOptionKey:u,memo:c,recipient:l,sender:f,sweep:p,...y});return x({...F,feeOptionKey:u,sweep:p})}}function He({provider:e,signer:t}){return function({contractAddress:o,abi:a,funcName:r,funcParams:i=[],txOverrides:s}){if(!o)throw new m("toolbox_evm_no_contract_address");let c=ge(o,a,e);return t?c.connect(t).getFunction(r).estimateGas(...i,s):c.getFunction(r).estimateGas(...i,s)}}function Zt({provider:e,signer:t}){return async function({assetValue:o,recipient:a,memo:r,data:i,sender:s,funcName:c,funcParams:l,txOverrides:u}){let b=o.bigIntValue,p=o.isGasAsset?null:Pe(o,o.chain);if(p&&c)return He({provider:e,signer:t})({abi:z,contractAddress:p,funcName:c,funcParams:l,txOverrides:u});let{hexlify:y,toUtf8Bytes:f}=await import("ethers");return e.estimateGas({data:i?i:r?y(f(r)):void 0,from:s,to:a,value:b})}}function en({signer:e}){if(!e)return;return(t)=>Fe(e,t)}var ze=(e)=>e.type===4||(e.authorizations?.length??0)>0,tn=(e)=>!ze(e)&&(e.type===2||!!e.maxFeePerGas||!!e.maxPriorityFeePerGas),nn=(e,t=!0)=>{if(ze(e))return"eip7702";if(tn(e)||t)return"eip1559";return"legacy"};function on(e,t){if(e==="legacy"){if(t.gasPrice===void 0)throw new m("toolbox_evm_no_fee_data");return{gasPrice:B(t.gasPrice)}}if(t.maxFeePerGas===void 0||t.maxPriorityFeePerGas===void 0)throw new m("toolbox_evm_no_fee_data");return{maxFeePerGas:B(t.maxFeePerGas),maxPriorityFeePerGas:B(t.maxPriorityFeePerGas)}}function Ke({chain:e,estimateGasPrices:t,provider:n,signer:o,isEIP1559Compatible:a=!0}){return async function({feeOptionKey:i=d.Fast,sweep:s,...c}){let{from:l,to:u,data:b,value:p,...y}=c;if(!o)throw new m("toolbox_evm_no_signer");if(!u)throw new m("toolbox_evm_no_to_address");let f={...y,data:b||"0x",from:l,to:u,value:BigInt(p||0)};if(ne(n))return oe(n,s)(f);let x=l||await o.getAddress(),{chainId:F}=await n.getNetwork(),C=o.provider??n,{nonce:G,release:R,settle:k}=await Ne({address:x,nonce:c.nonce,provider:C}),_=async()=>{let E=nn(f,a);if(E==="eip7702")Me(f.authorizations||[],F);let w=Re(E).with("eip7702",()=>4).with("eip1559",()=>2).otherwise(()=>0),V={...f,chainId:F,nonce:G,type:w,...E==="eip7702"&&{authorizationList:f.authorizations}},A=t??X({chain:e,isEIP1559Compatible:a,provider:n}),S=(E==="legacy"?f.gasPrice!==void 0:f.maxFeePerGas!==void 0&&f.maxPriorityFeePerGas!==void 0)?{}:on(E,(await A())[i]),h;try{h=B(f.gasLimit?BigInt(f.gasLimit):await n.estimateGas(V)*11n/10n)}catch(I){throw new m("toolbox_evm_error_estimating_gas_limit",{error:I})}return{...V,gasLimit:h,...S}};try{let E=await _().catch((w)=>{throw R(),w});try{return(await o.sendTransaction(E)).hash}catch(w){let V=c.nonce!=null?"caller":"pending",A={address:x,error:w,nonce:G,nonceSource:V};if(fe(w))throw new m({errorKey:"toolbox_evm_nonce_conflict",info:A},A);if(de(w)){let h=await qt({provider:C,signer:o,txObject:{...E,from:x}});if(h)return h;throw new m({errorKey:"toolbox_evm_tx_already_known",info:A},A)}if(!Kt(w))throw R(),new m({errorKey:"toolbox_evm_error_sending_transaction",info:A},A);let L=U(w,"UNSUPPORTED_OPERATION"),S;try{S=await o.signTransaction({...E,from:x})}catch(h){if(L)R();let I={...A,fallbackError:h};throw new m({errorKey:"toolbox_evm_error_sending_transaction",info:I},I)}try{return(await C.broadcastTransaction(S)).hash}catch(h){let I={...A,fallbackError:h};if(de(h)){let H=pe.from(S).hash;if(H)return H}if(fe(h)){let H=pe.from(S).hash;if(H&&await De(C,H))return H;throw new m({errorKey:"toolbox_evm_nonce_conflict",info:I},I)}if(L&&!Le(h))R();throw new m({errorKey:"toolbox_evm_error_sending_transaction",info:I},I)}}}finally{k()}}}function D(e,t){throw new m({errorKey:"toolbox_sweep_amount_too_low",info:{balance:e.toString(),fee:t.toString()}})}function an(e,t){if(t){if(e.maxFeePerGas===void 0||e.maxPriorityFeePerGas===void 0)throw new m("toolbox_evm_no_fee_data");return{feeFields:{maxFeePerGas:e.maxFeePerGas,maxPriorityFeePerGas:e.maxPriorityFeePerGas},feePerGas:e.maxFeePerGas}}if(e.gasPrice===void 0)throw new m("toolbox_evm_no_fee_data");return{feeFields:{gasPrice:e.gasPrice},feePerGas:e.gasPrice}}function rn(e,t){if(e>t)return e;return t}function sn(e){return Rt(e).reduce((t,n)=>t+(n===0?4n:16n),21000n)}function me(e){let n=(e instanceof Error?e.message:String(e)).toLowerCase();return n.includes("insufficient funds")||n.includes("insufficient balance")||n.includes("gas required exceeds allowance")}async function cn({balance:e,estimateAdditionalFee:t,feeOptionKey:n,l2Reserve:o,sweepTx:a,valueBeforeL1Fee:r}){if(!t)return 0n;let i=await t({...a,value:r})??0n,s=M(i,n),c=r-s;if(c<=0n)D(e,o+s);let l=await t({...a,value:c})??i;return M(rn(i,l),n)}async function un({chain:e,data:t,estimateGasPrices:n,estimateAdditionalFee:o,feeOptionKey:a,from:r,isEIP1559Compatible:i,provider:s,recipient:c,transaction:l}){let u=await s.getBalance(r),b=n??X({chain:e,isEIP1559Compatible:i,provider:s}),{feeFields:p,feePerGas:y}=an((await b())[a],i),f={...l,...p,data:t,from:r,to:c},x=sn(t)*y;if(u-x<=0n)D(u,x);let F=(u-x)/2n,C;try{C=await s.estimateGas({...f,value:F})}catch(h){if(!me(h))throw h;try{C=await s.estimateGas({...f,value:0n})}catch(I){if(me(I))D(u,x);throw I}}let G=C*y;if(u-G<=0n)D(u,G);let _=C*11n/10n*y,E=u>_?u-_:0n,w;try{w=await s.estimateGas({...f,value:E})}catch(h){if(!me(h))throw h;D(u,_)}let V=w*y,A=u-V;if(A<=0n)D(u,V);let L=await cn({balance:u,estimateAdditionalFee:o,feeOptionKey:a,l2Reserve:V,sweepTx:{...f,gasLimit:w},valueBeforeL1Fee:A}),S=A-L;if(S<=0n)D(u,V+L);return{...f,gasLimit:w,value:B(S)}}async function ln({chain:e,contractAddress:t,from:n,provider:o}){let a=await ae({chain:e,provider:o})({abi:z,contractAddress:t,funcName:"balanceOf",funcParams:[n]});if(typeof a!=="bigint")throw new m({errorKey:"toolbox_evm_invalid_transaction",info:{error:"Invalid ERC20 balance"}});return a}function qe({chain:e,estimateAdditionalFee:t,estimateGasPrices:n,isEIP1559Compatible:o=!0,provider:a,signer:r}){return async function({assetValue:s,authorizations:c,memo:l,recipient:u,data:b,feeOptionKey:p=d.Fast,gasLimit:y,sender:f,sweep:x,type:F,maxFeePerGas:C,maxPriorityFeePerGas:G,gasPrice:R,...k}){let _=s.getBaseValue("bigint"),E=f||await r?.getAddress();if(!E)throw new m("toolbox_evm_no_from_address");if(x&&(F===4||(c?.length??0)>0))throw new m({errorKey:"toolbox_not_supported",info:{chain:e,reason:"EIP-7702 sweep transactions are not supported"}});if(Vt(s)){let{hexlify:L,toUtf8Bytes:S}=await import("ethers"),h=b||L(S(l||""));if(!x)return{...k,...c!==void 0&&{authorizations:c},data:h,from:E,...y!==void 0&&{gasLimit:y},to:u,...F!==void 0&&{type:F},value:B(_)};return un({chain:e,data:h,estimateAdditionalFee:t,estimateGasPrices:n,feeOptionKey:p,from:E,isEIP1559Compatible:o,provider:a,recipient:u,transaction:{nonce:k.nonce,type:F}})}let w=Pe(s,e);if(!w)throw new m("toolbox_evm_no_contract_address");let V=W({chain:e,provider:a}),A=x?await ln({chain:e,contractAddress:w,from:E,provider:a}):_;if(x&&A<=0n)throw new m({errorKey:"toolbox_sweep_amount_too_low",info:{asset:s.toString(),balance:A.toString()}});return V({abi:z,contractAddress:w,funcName:"transfer",funcParams:[u,A],txOverrides:{from:E,gasLimit:y,gasPrice:R,maxFeePerGas:C,maxPriorityFeePerGas:G,nonce:k.nonce}})}}function mn({provider:e,signer:t,chain:n}){return async function({assetAddress:a,spenderAddress:r,amount:i,from:s,nonce:c}){let l=await t?.getAddress()||s,u=W({chain:n,provider:e}),b=["bigint","number"].includes(typeof i)?i:i||be;return await u({abi:z,contractAddress:a,funcName:"approve",funcParams:[r,BigInt(b)],txOverrides:{from:l,nonce:c}})}}function pn({provider:e,isEIP1559Compatible:t=!0,chain:n}){return async function({feeOption:a=d.Fast,...r}){let s=await X({chain:n,isEIP1559Compatible:t,provider:e})(),c=await e.estimateGas(r),l=Ot.from({chain:n}),{gasPrice:u,maxFeePerGas:b,maxPriorityFeePerGas:p}=s[a];if(!t&&u)return l.set(Q.fromBigInt(u*c,l.decimal));if(b&&p){let y=(b+p)*c;return l.set(Q.fromBigInt(y,l.decimal))}throw new m("toolbox_evm_no_gas_price")}}import{applyFeeMultiplierToBigInt as K,Chain as Xe,derivationPathToString as fn,FeeOption as N,getChainConfig as dn,resolveDerivationPath as yn,SwapKitError as q}from"@swapkit/helpers";import{Contract as bn,HDNodeWallet as gn}from"ethers";import{match as Pn,P as We}from"ts-pattern";var je=[{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 xn="0x420000000000000000000000000000000000000f";function re(e){return new bn(xn,je,e)}function $e(e){return async function(){let n=re(e);if(n&&"l1BaseFee"in n)return await n?.l1BaseFee();return}}function Je(e){return async function({from:n,to:o,nonce:a,...r}){let{Transaction:i}=await import("ethers");if(!o)throw new q("toolbox_evm_invalid_transaction",{error:"Missing to address"});return i.from({...r,authorizationList:r.authorizationList,nonce:a??(n?await e.getTransactionCount(n,"pending"):0),to:o}).unsignedSerialized}}function xe(e,t){return async function(o){let a=re(e),r=o.chainId??t??(await e.getNetwork()).chainId,i=await Je(e)({...o,chainId:r});if(a&&"getL1Fee"in a){let s=await a.getL1Fee(i);if(typeof s!=="bigint")throw new q({errorKey:"toolbox_evm_invalid_transaction",info:{error:"Invalid OP-stack L1 fee"}});return s}return}}function Te(e){return async function(n){let o=re(e);if(o&&"getOperatorFee"in o){let a=await o.getOperatorFee(n);if(typeof a!=="bigint")throw new q({errorKey:"toolbox_evm_invalid_transaction",info:{error:"Invalid OP-stack operator fee"}});return a}return 0n}}function Tn(e,t){let n=xe(e,t),o=Te(e);return async function(r){if(r.gasLimit===void 0||r.gasLimit===null)throw new q({errorKey:"toolbox_evm_invalid_transaction",info:{error:"Missing gas limit for OP-stack fee estimation"}});let[i,s]=await Promise.all([n(r),o(BigInt(r.gasLimit.toString()))]);return(i??0n)+s}}function Ye(e){return async function(n){let a=(await e.getFeeData()).gasPrice??0n,r=await e.estimateGas(n);return a*r}}function wn(e){return async function(n){let o=await xe(e)(n)??0n,a=await Ye(e)(n),r=n.gasLimit??await e.estimateGas(n),i=await Te(e)(BigInt(r.toString()));return o+a+i}}function hn(e){return async function(n){let o=re(e),a=await Je(e)(n);if(o&&"getL1GasUsed"in o)return o.getL1GasUsed(a)}}function vn(e){return async function(){try{let{maxFeePerGas:n,maxPriorityFeePerGas:o,gasPrice:a}=await e.getFeeData(),r=await $e(e)(),i=a;if(!(n&&o))throw new q("toolbox_evm_no_fee_data");return{[N.Average]:{gasPrice:i,l1GasPrice:r,maxFeePerGas:n,maxPriorityFeePerGas:o},[N.Fast]:{gasPrice:K(i,N.Fast),l1GasPrice:K(r||0n,N.Fast),maxFeePerGas:n,maxPriorityFeePerGas:K(o,N.Fast)},[N.Fastest]:{gasPrice:K(i,N.Fastest),l1GasPrice:K(r||0n,N.Fastest),maxFeePerGas:n,maxPriorityFeePerGas:K(o,N.Fastest)}}}catch(n){throw new q("toolbox_evm_gas_estimation_error",{error:n.msg??n.toString()})}}}function ie(e){return function({provider:n,...o}){let a=Pn(o).with({phrase:We.string},({phrase:p,derivationPath:y,index:f=0})=>gn.fromPhrase(p,void 0,fn(yn({chain:e,derivationPath:y,index:f}))).connect(n)).with({signer:We.any},({signer:p})=>p).otherwise(()=>{return}),r=$e(n),i=BigInt(dn(e).chainId),s=xe(n,i),c=Tn(n,i),l=Te(n),u=e===Xe.Optimism?vn(n):void 0;return{...te({chain:e,estimateAdditionalFee:c,estimateGasPrices:u,provider:n,signer:a}),estimateL1Gas:hn(n),estimateL1GasCost:s,estimateL2GasCost:Ye(n),estimateOperatorFee:l,estimateTotalGasCost:wn(n),getBalance:Y(e).getBalance,getL1GasPrice:r}}}var Qe=ie(Xe.Optimism);function et(e){let t=v(T.Ethereum)(e);async function n(o,a="0x5ba1e12693dc8f9c48aad8770482f4739beed696",r="aggregate",i=_n.Fast){let s=await t.createContractTxObject({abi:Ge,contractAddress:a,funcName:r,funcParams:[o]});return t.sendTransaction({...s,feeOptionKey:i})}return{...t,multicall:n}}var tt=v(T.Adi),nt=v(T.Arbitrum),ot=v(T.Arc),at=v(T.Aurora),rt=v(T.Avalanche),it=ie(T.Base),st=v(T.Berachain),ct=v(T.BinanceSmartChain),po=v(T.Botanix),ut=v(T.Core),lt=v(T.Corn),mt=v(T.Cronos),pt=v(T.Gnosis),ft=v(T.Robinhood),dt=v(T.Hyperevm),yt=v(T.Linea),bt=v(T.Polygon),gt=v(T.MegaETH),Pt=v(T.Monad),xt=v(T.Plasma),we=v(T.Sonic),Tt=ie(T.Unichain),wt=v(T.XLayer);function v(e){return function({provider:n,...o}){let a=Ae(e),r=Fn(o).with({phrase:Ze.string},({phrase:s,derivationPath:c,index:l=0})=>An.fromPhrase(s,void 0,En(Cn({chain:e,derivationPath:c,index:l}))).connect(n)).with({signer:Ze.any},({signer:s})=>s).otherwise(()=>{return});return te({chain:e,isEIP1559Compatible:a,provider:n,signer:r})}}function Bn(e,t){return Gn(e).with(P.Adi,()=>tt(t)).with(P.Arbitrum,()=>nt(t)).with(P.Arc,()=>ot(t)).with(P.Aurora,()=>at(t)).with(P.Avalanche,()=>rt(t)).with(P.Base,()=>it(t)).with(P.Berachain,()=>st(t)).with(P.BinanceSmartChain,()=>ct(t)).with(P.Botanix,()=>we(t)).with(P.Core,()=>ut(t)).with(P.Corn,()=>lt(t)).with(P.Cronos,()=>mt(t)).with(P.Ethereum,()=>et(t)).with(P.Gnosis,()=>pt(t)).with(P.Hyperevm,()=>dt(t)).with(P.Linea,()=>yt(t)).with(P.MegaETH,()=>gt(t)).with(P.Monad,()=>Pt(t)).with(P.Optimism,()=>Qe(t)).with(P.Plasma,()=>xt(t)).with(P.Polygon,()=>bt(t)).with(P.Robinhood,()=>ft(t)).with(P.Sonic,()=>we(t)).with(P.Unichain,()=>Tt(t)).with(P.XLayer,()=>wt(t)).exhaustive()}async function Po(e,t){let n={...t,provider:t?.provider||_e(e)};return Bn(e,n)}
|
|
2
|
+
export{Y as b,Dn as c,At as d,Sn as e,_e as f,B as g,Ce as h,Ae as i,Fe as j,Gt as k,Bt as l,Rn as m,Me as n,be as o,te as p,kt as q,ne as r,ge as s,Lt as t,Ut as u,Xn as v,oe as w,$n as x,Wt as y,Pe as z,W as A,X as B,ze as C,tn as D,nn as E,ie as F,Qe as G,et as H,tt as I,nt as J,ot as K,at as L,rt as M,it as N,st as O,ct as P,po as Q,ut as R,lt as S,mt as T,pt as U,ft as V,dt as W,yt as X,bt as Y,gt as Z,Pt as _,xt as $,we as aa,Tt as ba,wt as ca,Bn as da,Po as ea};
|
package/dist/src/aleo/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{fa as it}from"../../chunk-s1528ghz.js";import{ga as x}from"../../chunk-k50sjysj.js";import{hmac as Y}from"@noble/hashes/hmac.js";import{sha512 as J}from"@noble/hashes/sha2.js";import{Chain as F,getChainConfig as gt,SKConfig as At,SwapKitError as w}from"@swapkit/helpers";var mt=/^aleo1[ac-hj-np-z02-9]{58}$/,pt=/^[a-z0-9_]+\.aleo$/,v=/^at1[ac-hj-np-z02-9]+$/,ht=new TextEncoder().encode("bls12_377 seed"),H=2147483648,O=1e6,E="credits.aleo",U="transfer_public",Q=1e6,Z=2000000;function tt(t,n){if(!m(t))return[];let r=m(t.transaction)?t.transaction:t,s=r.execution,a=m(r.fee)?r.fee.transition:void 0;return[...m(s)&&Array.isArray(s.transitions)?s.transitions:[],...m(a)?[a]:[]].flatMap((y)=>{if(!m(y)||!Array.isArray(y.outputs))return[];if(n&&y.program!==n)return[];return y.outputs.flatMap((h)=>m(h)&&h.type==="record"&&typeof h.value==="string"?[h.value]:[])})}function et(t){return t.reduce((n,r)=>r.spent?n:n+r.microcredits,0n)}function p(t,n){return n instanceof w&&n.errorKey.startsWith("toolbox_aleo_")?n:new w(t,n)}function xt(...t){let n=t.reduce((a,_)=>a+_.length,0),r=new Uint8Array(n),s=0;for(let a of t)r.set(a,s),s+=a.length;return r}function yt(t){let n=new Uint8Array(4);return new DataView(n.buffer).setUint32(0,t,!1),n}function bt(t){let n=Y(J,ht,t);return{chainCode:n.slice(32),key:n.slice(0,32)}}function Tt(t,n){if(!Number.isSafeInteger(n)||n<0||n>=H)throw new w("toolbox_aleo_wasm_init_failed",{index:n});let r=n+H,s=xt(Uint8Array.of(0),t.key,yt(r)),a=Y(J,t.chainCode,s);return{chainCode:a.slice(32),key:a.slice(0,32)}}function nt(t,n){let r=t.split("/");if(r.shift()!=="m"||r.length===0)throw new w("toolbox_aleo_wasm_init_failed",{path:t});return r.reduce((s,a)=>{if(!/^\d+'$/.test(a))throw new w("toolbox_aleo_wasm_init_failed",{path:t,segment:a});return Tt(s,Number.parseInt(a.slice(0,-1),10))},bt(n))}function B(t){return typeof t==="string"&&mt.test(t)}async function ot(t){if(!B(t))return!1;try{let{Account:n}=await import("@provablehq/sdk/mainnet.js");return n.isValidAddress(t)}catch{return!1}}function Et(t){return pt.test(t)}function rt(t,n){if(t===null)return 0n;if(typeof t!=="string")throw new w("toolbox_aleo_balance_error",{integerType:n,value:t});let r=t.match(new RegExp(`^(\\d+)${n}$`));if(!r?.[1])throw new w("toolbox_aleo_balance_error",{integerType:n,value:t});return BigInt(r[1])}function M(t){if(t.chain!==F.Aleo)throw new w("toolbox_aleo_unsupported_token",{asset:t.toString()});let n=t.getBaseValue("bigint");if(t.isGasAsset)return{amount:`${n}u64`,functionName:U,isTokenTransfer:!1,programName:E};if(!t.address||!Et(t.address))throw new w("toolbox_aleo_unsupported_token",{asset:t.toString()});return{amount:`${n}u128`,functionName:U,isTokenTransfer:!0,programName:t.address}}function R(){let t=[...new Set([...At.get("rpcUrls")[F.Aleo],...gt(F.Aleo).rpcUrls])].filter(Boolean);if(t.length===0)throw new w("toolbox_aleo_no_rpc_urls");return t}function L(t){if(typeof t==="object"&&t!==null&&"status"in t&&t.status===404)return!0;return t instanceof Error&&t.message.includes("404")}function m(t){return typeof t==="object"&&t!==null}function Rt(t){if(!m(t))return!1;return[t.transaction,t.rejected].some((n)=>{if(!m(n)||!m(n.execution))return!1;let{transitions:r}=n.execution;return Array.isArray(r)&&r.some((s)=>m(s)&&s.function===U&&typeof s.program==="string"&&s.program!==E)})}function Pt(t,n){if(!m(t)||typeof t.status!=="string")throw new w("toolbox_aleo_transaction_failed",{response:t,transactionId:n});let r=t.status.toLowerCase();if(r==="rejected"){let s=Rt(t)?"toolbox_aleo_token_transfer_rejected":"toolbox_aleo_transaction_failed";throw new w(s,{transactionId:n})}return r==="accepted"?"accepted":"pending"}async function kt(t){if(!v.test(t))throw new w("toolbox_aleo_transaction_failed",{transactionId:t});let n,r=!0;for(let s of R())try{let{AleoNetworkClient:a}=await import("@provablehq/sdk/mainnet.js"),_=await new a(s).getConfirmedTransaction(t);return Pt(_,t)}catch(a){if(a instanceof w)throw a;n=a,r=r&&L(a)}if(r)return"pending";throw p("toolbox_aleo_transaction_failed",n)}async function K(t,{intervalMs:n=5000,timeoutMs:r=60000}={}){let s=Date.now();while(Date.now()-s<r){let a=await kt(t);if(a==="accepted")return a;await new Promise((_)=>setTimeout(_,n))}throw new w("toolbox_aleo_transaction_failed",{reason:"confirmation_timeout",transactionId:t})}import{AssetValue as C,Chain as P,derivationPathToString as Nt,NetworkDerivationPath as Ct,SwapKitError as d}from"@swapkit/helpers";async function st(t,n){try{let{Account:r}=await import("@provablehq/sdk/mainnet.js"),{mnemonicToSeedSync:s}=await import("@scure/bip39"),a=Nt(n||Ct[P.Aleo],{allHardened:!0}),{key:_}=nt(a,s(t));return new r({seed:_})}catch(r){throw p("toolbox_aleo_wasm_init_failed",r)}}function at(t,n){let r,s=()=>(r??=st(t,n),r);return{getAddress:async()=>(await s()).address().to_string(),signTransaction:async(a)=>{let _=await s();if(a.sender!==_.address().to_string())throw new d("toolbox_aleo_invalid_address",{address:a.sender});let y;for(let h of R())try{let{ProgramManager:b}=await import("@provablehq/sdk/mainnet.js"),N=new b(h);return N.setAccount(_),await N.buildExecutionTransaction({functionName:a.functionName,inputs:a.inputs,priorityFee:a.priorityFee/O,privateFee:!1,programName:a.programName})}catch(b){y=b}throw y}}}function St(t={}){if("phrase"in t&&t.phrase&&"signer"in t&&t.signer)throw new d("toolbox_aleo_conflicting_signers");let n;async function r(){if(n)return n;let o="phrase"in t?t.phrase:void 0;if(!o)throw new d("toolbox_aleo_no_signer");let e="derivationPath"in t?t.derivationPath:void 0;return n=await st(o,e),n}let s;function a(){let o="signer"in t?t.signer:void 0;if(o)return o;let e="phrase"in t?t.phrase:void 0;if(!e)throw new d("toolbox_aleo_no_signer");return s??=at(e,"derivationPath"in t?t.derivationPath:void 0),s}async function _(o){let e;for(let c of R())try{let{AleoNetworkClient:i}=await import("@provablehq/sdk/mainnet.js");return await o(new i(c))}catch(i){e=i}throw e}async function y(o){let e;for(let c of R())try{let{AleoNetworkClient:i}=await import("@provablehq/sdk/mainnet.js");return await new i(c).getTransitionId(o),!0}catch(i){if(L(i))return!1;e=i}throw e}async function h(){let o=a();try{return await o.getAddress()}catch(e){throw p("toolbox_aleo_wasm_init_failed",e)}}async function b(o){let e=await _((c)=>c.getProgramMappingValue(E,"account",o));return rt(e,"u64")}async function N(o){try{let e=await b(o);return[C.from({chain:P.Aleo,fromBaseDecimal:6,value:e})]}catch(e){throw p("toolbox_aleo_balance_error",e)}}let j=it(P.Aleo);async function G(o,e=!0){try{return await j(o,e)}catch{return N(o)}}async function ct(){return G(await h())}async function S({transactionIds:o}){try{let e=await r(),c=[];for(let i of o){if(!v.test(i))throw new d("toolbox_aleo_transaction_failed",{transactionId:i});let g=await _((u)=>u.getTransaction(i));for(let u of tt(g,E)){if(!e.ownsRecordCiphertext(u))continue;let{RecordPlaintext:f}=await import("@provablehq/sdk/mainnet.js"),l=e.decryptRecord(u).toString(),A=f.fromString(l),k=A.microcredits();if(k===0n)continue;let I=e.generateRecordViewKey(u).toString(),T=A.serialNumberString(e.privateKey(),E,"credits",I);c.push({microcredits:k,plaintext:l,spent:await y(T),transactionId:i})}}return c}catch(e){throw p("toolbox_aleo_balance_error",e)}}async function lt({transactionIds:o}){let e=await S({transactionIds:o});return C.from({chain:P.Aleo,fromBaseDecimal:6,value:et(e)})}async function ut(o,e){if(!Number.isSafeInteger(e)||e<=0)throw new d("toolbox_aleo_insufficient_fee_balance",{feeRecordCredits:e});let c=await r();if(!o||o.microcredits<=BigInt(e)*BigInt(O))throw new d("toolbox_aleo_insufficient_fee_balance",{available:o?.microcredits.toString(),required:`${e} credits fee record`});let{ProgramManager:i,RecordPlaintext:g}=await import("@provablehq/sdk/mainnet.js"),u;for(let f of R())try{let l=new i(f);return l.setAccount(c),await l.split(e,g.fromString(o.plaintext))}catch(l){u=l}throw u}async function ft(o,e,c){let i=await r(),{ProgramManager:g,RecordPlaintext:u}=await import("@provablehq/sdk/mainnet.js"),f;for(let l of R())try{let A=new g(l);return A.setAccount(i),await A.buildExecutionTransaction({feeRecord:u.fromString(e.plaintext),functionName:"transfer_private_to_public",inputs:[o.plaintext,c,`${o.microcredits}u64`],priorityFee:0,privateFee:!0,programName:E})}catch(A){f=A}throw f}async function V(o,e,c){let i;try{let u=(await r()).address().to_string(),f=o.filter((T)=>!T.spent);if(f.length===0)throw new d("toolbox_aleo_no_unspent_records",{transactionId:c});if(f.length===1){if(i=await ut(f[0],e),await K(i),f=(await S({transactionIds:[i]})).filter((T)=>!T.spent),f.length<2)throw new d("toolbox_aleo_transaction_failed",{transactionId:i})}let l=[...f].sort((T,wt)=>T.microcredits<wt.microcredits?-1:1),A=l[0],k=l[l.length-1];if(!A||!k||A===k)throw new d("toolbox_aleo_no_unspent_records",{transactionId:c});let I=await D(await ft(k,A,u));return await K(I),{publicBalance:C.from({chain:P.Aleo,fromBaseDecimal:6,value:await b(u)}),splitTransactionId:i,unshieldTransactionId:I}}catch(g){if(i)throw new d("toolbox_aleo_transaction_failed",{error:g,splitTransactionId:i});throw p("toolbox_aleo_transaction_failed",g)}}async function dt(o){try{if("records"in o&&o.records)return await V(o.records,o.feeRecordCredits??4);let e=await S({transactionIds:[o.transactionId]});return await V(e,o.feeRecordCredits??4,o.transactionId)}catch(e){throw p("toolbox_aleo_transaction_failed",e)}}function W({assetValue:o,priorityFee:e=0}){try{if(!Number.isSafeInteger(e)||e<0)throw new d("toolbox_aleo_fee_estimation_failed",{priorityFee:e});let i=M(o).isTokenTransfer?Z:Q;return C.from({chain:P.Aleo,fromBaseDecimal:6,value:BigInt(i)+BigInt(e)})}catch(c){throw p("toolbox_aleo_fee_estimation_failed",c)}}async function z({assetValue:o,priorityFee:e=0,recipient:c,sender:i}){if(!await ot(c))throw new d("toolbox_aleo_invalid_address",{address:c});let g=i||await h();if(!B(g))throw new d("toolbox_aleo_invalid_address",{address:g});let u=M(o),f=await W({assetValue:o,priorityFee:e,recipient:c});try{let l=await b(g);if(C.from({chain:P.Aleo,fromBaseDecimal:6,value:l}).lt(f))throw new d("toolbox_aleo_insufficient_fee_balance",{available:l.toString(),required:f.getBaseValue("string")});return{functionName:u.functionName,inputs:[c,u.amount],priorityFee:e,programName:u.programName,sender:g}}catch(l){throw p("toolbox_aleo_transaction_failed",l)}}async function X(o){try{return await a().signTransaction(o)}catch(e){throw p("toolbox_aleo_transaction_failed",e)}}async function q(o){return D(await X(o))}async function D(o){try{let e=typeof o==="string"?o:o.toString(),c=await _((i)=>i.submitTransaction(e));if(!v.test(c))throw new d("toolbox_aleo_broadcast_error",{transactionId:c});return c}catch(e){throw p("toolbox_aleo_broadcast_error",e)}}async function _t(o){let e=await z({...o,sender:await h()});return q(e)}return{broadcastTransaction:D,createSigner:at,createTransaction:z,estimateTransactionFee:W,getAddress:h,getBalance:j,getBalanceFromRpc:N,getBalances:ct,getBalanceWithFallback:G,getRecords:S,getShieldedBalance:lt,signAndBroadcastTransaction:q,signTransaction:X,transfer:_t,unshield:dt,validateAddress:B}}export{mt as ALEO_ADDRESS_REGEX,ht as ALEO_HD_KEY,pt as ALEO_PROGRAM_ID_REGEX,Z as ALEO_TOKEN_TRANSFER_PUBLIC_FEE,v as ALEO_TRANSACTION_ID_REGEX,Q as ALEO_TRANSFER_PUBLIC_FEE,H as HARDENED_OFFSET,O as MICRO_CREDITS_PER_CREDIT,E as NATIVE_PROGRAM_ID,U as TRANSFER_PUBLIC_FUNCTION,Tt as deriveAleoChildKey,nt as deriveAleoPath,tt as extractAleoRecordCiphertexts,p as getAleoError,bt as getAleoMasterSeed,St as getAleoToolbox,kt as getAleoTransactionStatus,M as getAleoTransferRoute,R as getConfiguredAleoUrls,Rt as isAleoTokenTransferResponse,L as isNotFoundError,m as isRecord,rt as parseAleoMappingValue,Pt as parseAleoTransactionStatus,et as sumUnspentRecords,B as validateAleoAddress,ot as validateAleoAddressWithChecksum,Et as validateAleoProgramId,K as waitForAleoTransaction};
|
|
1
|
+
import{ga as it}from"../../chunk-as9fracn.js";import{ha as x}from"../../chunk-4428244x.js";import{hmac as Y}from"@noble/hashes/hmac.js";import{sha512 as J}from"@noble/hashes/sha2.js";import{Chain as F,getChainConfig as gt,SKConfig as At,SwapKitError as w}from"@swapkit/helpers";var mt=/^aleo1[ac-hj-np-z02-9]{58}$/,pt=/^[a-z0-9_]+\.aleo$/,v=/^at1[ac-hj-np-z02-9]+$/,ht=new TextEncoder().encode("bls12_377 seed"),H=2147483648,O=1e6,E="credits.aleo",U="transfer_public",Q=1e6,Z=2000000;function tt(t,n){if(!m(t))return[];let r=m(t.transaction)?t.transaction:t,s=r.execution,a=m(r.fee)?r.fee.transition:void 0;return[...m(s)&&Array.isArray(s.transitions)?s.transitions:[],...m(a)?[a]:[]].flatMap((y)=>{if(!m(y)||!Array.isArray(y.outputs))return[];if(n&&y.program!==n)return[];return y.outputs.flatMap((h)=>m(h)&&h.type==="record"&&typeof h.value==="string"?[h.value]:[])})}function et(t){return t.reduce((n,r)=>r.spent?n:n+r.microcredits,0n)}function p(t,n){return n instanceof w&&n.errorKey.startsWith("toolbox_aleo_")?n:new w(t,n)}function xt(...t){let n=t.reduce((a,_)=>a+_.length,0),r=new Uint8Array(n),s=0;for(let a of t)r.set(a,s),s+=a.length;return r}function yt(t){let n=new Uint8Array(4);return new DataView(n.buffer).setUint32(0,t,!1),n}function bt(t){let n=Y(J,ht,t);return{chainCode:n.slice(32),key:n.slice(0,32)}}function Tt(t,n){if(!Number.isSafeInteger(n)||n<0||n>=H)throw new w("toolbox_aleo_wasm_init_failed",{index:n});let r=n+H,s=xt(Uint8Array.of(0),t.key,yt(r)),a=Y(J,t.chainCode,s);return{chainCode:a.slice(32),key:a.slice(0,32)}}function nt(t,n){let r=t.split("/");if(r.shift()!=="m"||r.length===0)throw new w("toolbox_aleo_wasm_init_failed",{path:t});return r.reduce((s,a)=>{if(!/^\d+'$/.test(a))throw new w("toolbox_aleo_wasm_init_failed",{path:t,segment:a});return Tt(s,Number.parseInt(a.slice(0,-1),10))},bt(n))}function B(t){return typeof t==="string"&&mt.test(t)}async function ot(t){if(!B(t))return!1;try{let{Account:n}=await import("@provablehq/sdk/mainnet.js");return n.isValidAddress(t)}catch{return!1}}function Et(t){return pt.test(t)}function rt(t,n){if(t===null)return 0n;if(typeof t!=="string")throw new w("toolbox_aleo_balance_error",{integerType:n,value:t});let r=t.match(new RegExp(`^(\\d+)${n}$`));if(!r?.[1])throw new w("toolbox_aleo_balance_error",{integerType:n,value:t});return BigInt(r[1])}function M(t){if(t.chain!==F.Aleo)throw new w("toolbox_aleo_unsupported_token",{asset:t.toString()});let n=t.getBaseValue("bigint");if(t.isGasAsset)return{amount:`${n}u64`,functionName:U,isTokenTransfer:!1,programName:E};if(!t.address||!Et(t.address))throw new w("toolbox_aleo_unsupported_token",{asset:t.toString()});return{amount:`${n}u128`,functionName:U,isTokenTransfer:!0,programName:t.address}}function R(){let t=[...new Set([...At.get("rpcUrls")[F.Aleo],...gt(F.Aleo).rpcUrls])].filter(Boolean);if(t.length===0)throw new w("toolbox_aleo_no_rpc_urls");return t}function L(t){if(typeof t==="object"&&t!==null&&"status"in t&&t.status===404)return!0;return t instanceof Error&&t.message.includes("404")}function m(t){return typeof t==="object"&&t!==null}function Rt(t){if(!m(t))return!1;return[t.transaction,t.rejected].some((n)=>{if(!m(n)||!m(n.execution))return!1;let{transitions:r}=n.execution;return Array.isArray(r)&&r.some((s)=>m(s)&&s.function===U&&typeof s.program==="string"&&s.program!==E)})}function Pt(t,n){if(!m(t)||typeof t.status!=="string")throw new w("toolbox_aleo_transaction_failed",{response:t,transactionId:n});let r=t.status.toLowerCase();if(r==="rejected"){let s=Rt(t)?"toolbox_aleo_token_transfer_rejected":"toolbox_aleo_transaction_failed";throw new w(s,{transactionId:n})}return r==="accepted"?"accepted":"pending"}async function kt(t){if(!v.test(t))throw new w("toolbox_aleo_transaction_failed",{transactionId:t});let n,r=!0;for(let s of R())try{let{AleoNetworkClient:a}=await import("@provablehq/sdk/mainnet.js"),_=await new a(s).getConfirmedTransaction(t);return Pt(_,t)}catch(a){if(a instanceof w)throw a;n=a,r=r&&L(a)}if(r)return"pending";throw p("toolbox_aleo_transaction_failed",n)}async function K(t,{intervalMs:n=5000,timeoutMs:r=60000}={}){let s=Date.now();while(Date.now()-s<r){let a=await kt(t);if(a==="accepted")return a;await new Promise((_)=>setTimeout(_,n))}throw new w("toolbox_aleo_transaction_failed",{reason:"confirmation_timeout",transactionId:t})}import{AssetValue as C,Chain as P,derivationPathToString as Nt,NetworkDerivationPath as Ct,SwapKitError as d}from"@swapkit/helpers";async function st(t,n){try{let{Account:r}=await import("@provablehq/sdk/mainnet.js"),{mnemonicToSeedSync:s}=await import("@scure/bip39"),a=Nt(n||Ct[P.Aleo],{allHardened:!0}),{key:_}=nt(a,s(t));return new r({seed:_})}catch(r){throw p("toolbox_aleo_wasm_init_failed",r)}}function at(t,n){let r,s=()=>(r??=st(t,n),r);return{getAddress:async()=>(await s()).address().to_string(),signTransaction:async(a)=>{let _=await s();if(a.sender!==_.address().to_string())throw new d("toolbox_aleo_invalid_address",{address:a.sender});let y;for(let h of R())try{let{ProgramManager:b}=await import("@provablehq/sdk/mainnet.js"),N=new b(h);return N.setAccount(_),await N.buildExecutionTransaction({functionName:a.functionName,inputs:a.inputs,priorityFee:a.priorityFee/O,privateFee:!1,programName:a.programName})}catch(b){y=b}throw y}}}function St(t={}){if("phrase"in t&&t.phrase&&"signer"in t&&t.signer)throw new d("toolbox_aleo_conflicting_signers");let n;async function r(){if(n)return n;let o="phrase"in t?t.phrase:void 0;if(!o)throw new d("toolbox_aleo_no_signer");let e="derivationPath"in t?t.derivationPath:void 0;return n=await st(o,e),n}let s;function a(){let o="signer"in t?t.signer:void 0;if(o)return o;let e="phrase"in t?t.phrase:void 0;if(!e)throw new d("toolbox_aleo_no_signer");return s??=at(e,"derivationPath"in t?t.derivationPath:void 0),s}async function _(o){let e;for(let c of R())try{let{AleoNetworkClient:i}=await import("@provablehq/sdk/mainnet.js");return await o(new i(c))}catch(i){e=i}throw e}async function y(o){let e;for(let c of R())try{let{AleoNetworkClient:i}=await import("@provablehq/sdk/mainnet.js");return await new i(c).getTransitionId(o),!0}catch(i){if(L(i))return!1;e=i}throw e}async function h(){let o=a();try{return await o.getAddress()}catch(e){throw p("toolbox_aleo_wasm_init_failed",e)}}async function b(o){let e=await _((c)=>c.getProgramMappingValue(E,"account",o));return rt(e,"u64")}async function N(o){try{let e=await b(o);return[C.from({chain:P.Aleo,fromBaseDecimal:6,value:e})]}catch(e){throw p("toolbox_aleo_balance_error",e)}}let j=it(P.Aleo);async function G(o,e=!0){try{return await j(o,e)}catch{return N(o)}}async function ct(){return G(await h())}async function S({transactionIds:o}){try{let e=await r(),c=[];for(let i of o){if(!v.test(i))throw new d("toolbox_aleo_transaction_failed",{transactionId:i});let g=await _((u)=>u.getTransaction(i));for(let u of tt(g,E)){if(!e.ownsRecordCiphertext(u))continue;let{RecordPlaintext:f}=await import("@provablehq/sdk/mainnet.js"),l=e.decryptRecord(u).toString(),A=f.fromString(l),k=A.microcredits();if(k===0n)continue;let I=e.generateRecordViewKey(u).toString(),T=A.serialNumberString(e.privateKey(),E,"credits",I);c.push({microcredits:k,plaintext:l,spent:await y(T),transactionId:i})}}return c}catch(e){throw p("toolbox_aleo_balance_error",e)}}async function lt({transactionIds:o}){let e=await S({transactionIds:o});return C.from({chain:P.Aleo,fromBaseDecimal:6,value:et(e)})}async function ut(o,e){if(!Number.isSafeInteger(e)||e<=0)throw new d("toolbox_aleo_insufficient_fee_balance",{feeRecordCredits:e});let c=await r();if(!o||o.microcredits<=BigInt(e)*BigInt(O))throw new d("toolbox_aleo_insufficient_fee_balance",{available:o?.microcredits.toString(),required:`${e} credits fee record`});let{ProgramManager:i,RecordPlaintext:g}=await import("@provablehq/sdk/mainnet.js"),u;for(let f of R())try{let l=new i(f);return l.setAccount(c),await l.split(e,g.fromString(o.plaintext))}catch(l){u=l}throw u}async function ft(o,e,c){let i=await r(),{ProgramManager:g,RecordPlaintext:u}=await import("@provablehq/sdk/mainnet.js"),f;for(let l of R())try{let A=new g(l);return A.setAccount(i),await A.buildExecutionTransaction({feeRecord:u.fromString(e.plaintext),functionName:"transfer_private_to_public",inputs:[o.plaintext,c,`${o.microcredits}u64`],priorityFee:0,privateFee:!0,programName:E})}catch(A){f=A}throw f}async function V(o,e,c){let i;try{let u=(await r()).address().to_string(),f=o.filter((T)=>!T.spent);if(f.length===0)throw new d("toolbox_aleo_no_unspent_records",{transactionId:c});if(f.length===1){if(i=await ut(f[0],e),await K(i),f=(await S({transactionIds:[i]})).filter((T)=>!T.spent),f.length<2)throw new d("toolbox_aleo_transaction_failed",{transactionId:i})}let l=[...f].sort((T,wt)=>T.microcredits<wt.microcredits?-1:1),A=l[0],k=l[l.length-1];if(!A||!k||A===k)throw new d("toolbox_aleo_no_unspent_records",{transactionId:c});let I=await D(await ft(k,A,u));return await K(I),{publicBalance:C.from({chain:P.Aleo,fromBaseDecimal:6,value:await b(u)}),splitTransactionId:i,unshieldTransactionId:I}}catch(g){if(i)throw new d("toolbox_aleo_transaction_failed",{error:g,splitTransactionId:i});throw p("toolbox_aleo_transaction_failed",g)}}async function dt(o){try{if("records"in o&&o.records)return await V(o.records,o.feeRecordCredits??4);let e=await S({transactionIds:[o.transactionId]});return await V(e,o.feeRecordCredits??4,o.transactionId)}catch(e){throw p("toolbox_aleo_transaction_failed",e)}}function W({assetValue:o,priorityFee:e=0}){try{if(!Number.isSafeInteger(e)||e<0)throw new d("toolbox_aleo_fee_estimation_failed",{priorityFee:e});let i=M(o).isTokenTransfer?Z:Q;return C.from({chain:P.Aleo,fromBaseDecimal:6,value:BigInt(i)+BigInt(e)})}catch(c){throw p("toolbox_aleo_fee_estimation_failed",c)}}async function z({assetValue:o,priorityFee:e=0,recipient:c,sender:i}){if(!await ot(c))throw new d("toolbox_aleo_invalid_address",{address:c});let g=i||await h();if(!B(g))throw new d("toolbox_aleo_invalid_address",{address:g});let u=M(o),f=await W({assetValue:o,priorityFee:e,recipient:c});try{let l=await b(g);if(C.from({chain:P.Aleo,fromBaseDecimal:6,value:l}).lt(f))throw new d("toolbox_aleo_insufficient_fee_balance",{available:l.toString(),required:f.getBaseValue("string")});return{functionName:u.functionName,inputs:[c,u.amount],priorityFee:e,programName:u.programName,sender:g}}catch(l){throw p("toolbox_aleo_transaction_failed",l)}}async function X(o){try{return await a().signTransaction(o)}catch(e){throw p("toolbox_aleo_transaction_failed",e)}}async function q(o){return D(await X(o))}async function D(o){try{let e=typeof o==="string"?o:o.toString(),c=await _((i)=>i.submitTransaction(e));if(!v.test(c))throw new d("toolbox_aleo_broadcast_error",{transactionId:c});return c}catch(e){throw p("toolbox_aleo_broadcast_error",e)}}async function _t(o){let e=await z({...o,sender:await h()});return q(e)}return{broadcastTransaction:D,createSigner:at,createTransaction:z,estimateTransactionFee:W,getAddress:h,getBalance:j,getBalanceFromRpc:N,getBalances:ct,getBalanceWithFallback:G,getRecords:S,getShieldedBalance:lt,signAndBroadcastTransaction:q,signTransaction:X,transfer:_t,unshield:dt,validateAddress:B}}export{mt as ALEO_ADDRESS_REGEX,ht as ALEO_HD_KEY,pt as ALEO_PROGRAM_ID_REGEX,Z as ALEO_TOKEN_TRANSFER_PUBLIC_FEE,v as ALEO_TRANSACTION_ID_REGEX,Q as ALEO_TRANSFER_PUBLIC_FEE,H as HARDENED_OFFSET,O as MICRO_CREDITS_PER_CREDIT,E as NATIVE_PROGRAM_ID,U as TRANSFER_PUBLIC_FUNCTION,Tt as deriveAleoChildKey,nt as deriveAleoPath,tt as extractAleoRecordCiphertexts,p as getAleoError,bt as getAleoMasterSeed,St as getAleoToolbox,kt as getAleoTransactionStatus,M as getAleoTransferRoute,R as getConfiguredAleoUrls,Rt as isAleoTokenTransferResponse,L as isNotFoundError,m as isRecord,rt as parseAleoMappingValue,Pt as parseAleoTransactionStatus,et as sumUnspentRecords,B as validateAleoAddress,ot as validateAleoAddressWithChecksum,Et as validateAleoProgramId,K as waitForAleoTransaction};
|
package/dist/src/aptos/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{ha as B}from"../../chunk-4428244x.js";import{AssetValue as b,Chain as A,derivationPathToString as tt,getChainConfig as v,getRPCUrlSync as W,NetworkDerivationPath as nt,SwapKitError as s}from"@swapkit/helpers";import{match as j,P as R}from"ts-pattern";var w={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"},st=2000,at=/^[0-9a-fA-F]+$/;function x(e){if(!e||typeof e!=="string"||!e.startsWith("0x"))return!1;let i=e.slice(2);if(i.length===0||i.length>64)return!1;return at.test(i)}function Y(e,i,d){if(e<=0n)throw new s({errorKey:"toolbox_sweep_amount_too_low",info:{amount:e.toString(),asset:i.toString(),...d}});return e}async function ot({aptos:e,assetValue:i,senderAddress:d}){let c=i.address;if(!c)throw new s("toolbox_aptos_missing_asset_type");let[y]=await e.getCurrentFungibleAssetBalances({options:{limit:1,where:{asset_type:{_eq:c},is_primary:{_eq:!0},owner_address:{_eq:d}}}});return Y(BigInt(y?.amount??0),i)}function et({derivationPath:e,provider:i,...d}={}){let c,y=tt(e||nt[A.Aptos],{allHardened:!0});async function T(){if(c)return c;return c=await j(d).with({phrase:R.string},async({phrase:n})=>{let{Ed25519Account:t}=await import("@aptos-labs/ts-sdk");return t.fromDerivationPath({mnemonic:n,path:y})}).with({signer:R.any},({signer:n})=>n).otherwise(()=>{return}),c}async function _(){let{Aptos:n,AptosConfig:t,Network:a}=await import("@aptos-labs/ts-sdk"),r=new t({clientConfig:{http2:!1},fullnode:i||W(A.Aptos),network:a.MAINNET});return new n(r)}async function S(){return(await T())?.accountAddress.toString()||""}async function G(n){let t=n||await S();if(!t)throw new s("toolbox_aptos_address_required");let{baseDecimal:a,chain:r}=v(A.Aptos);try{let u=await _(),p=await u.getAccountAPTAmount({accountAddress:t}),g=[b.from({chain:r,fromBaseDecimal:a,value:p.toString()})],f=await u.getCurrentFungibleAssetBalances({options:{where:{owner_address:{_eq:t}}}});for(let o of f){if(o.asset_type===w.COIN_TYPE||Number(o.amount)<=0)continue;let m=o.asset_type;if(m){let l=("metadata"in o&&typeof o.metadata==="object"&&o.metadata!==null?o.metadata:void 0)?.decimals??a;g.push(b.from({asset:`${A.Aptos}.APT-${m}`,fromBaseDecimal:l,value:String(o.amount)}))}}return g}catch{return[b.from({chain:r})]}}async function H(n){if(!n){let{baseDecimal:g}=v(A.Aptos),f=i||W(A.Aptos),o=await fetch(`${f}/estimate_gas_price`),{gas_estimate:m}=await o.json();return b.from({chain:A.Aptos,fromBaseDecimal:g,value:String(m)})}let t=await N(n),a=await _(),[r]=await a.transaction.simulate.simple({transaction:t});if(!r)throw new s("toolbox_aptos_transaction_creation_error");let u=BigInt(r.gas_used)*BigInt(r.gas_unit_price),{baseDecimal:p}=v(A.Aptos);return b.from({chain:A.Aptos,fromBaseDecimal:p,value:u.toString()})}async function N({recipient:n,assetValue:t,maxGasAmount:a,sender:r,accountSequenceNumber:u,gasUnitPrice:p,sweep:g}){if(!x(n))throw new s("core_transaction_invalid_recipient_address");let f=r||await S();if(!f)throw new s("toolbox_aptos_no_sender");let{AccountAddress:o}=await import("@aptos-labs/ts-sdk"),m=await _(),C=o.from(f);try{let l=t.isGasAsset?w.TRANSFER:w.FUNGIBLE_STORE_TRANSFER,z=t.address,E=(P,O)=>{let k=j({address:z,isGasAsset:t.isGasAsset}).with({isGasAsset:!0},()=>[o.from(n),P]).with({address:R.string},({address:V})=>[o.from(V),o.from(n),P]).otherwise(()=>null);if(!k)throw new s("toolbox_aptos_missing_asset_type");let q=O?.maxGasAmount??a,K=O?.gasUnitPrice??p;return m.transaction.build.simple({data:{function:l,functionArguments:k,typeArguments:t.isGasAsset?[]:[w.FUNGIBLE_ASSET_METADATA]},options:q!==void 0||K!==void 0||u!==void 0?{accountSequenceNumber:u,gasUnitPrice:K,maxGasAmount:q}:void 0,sender:C})};if(!g)return E(t.getBaseValue("bigint"));if(!t.isGasAsset){let P=await ot({aptos:m,assetValue:t,senderAddress:f});return E(P)}let U=BigInt(await m.getAccountAPTAmount({accountAddress:f})),J=await E(1n,{maxGasAmount:a??st}),[h]=await m.transaction.simulate.simple({options:{estimateMaxGasAmount:a===void 0},transaction:J});if(!h)throw new s("toolbox_aptos_transaction_creation_error");if(!h.success)throw new s({errorKey:"toolbox_aptos_transaction_creation_error",info:{vmStatus:h.vm_status}});let D=BigInt(h.gas_used),M=D>0n?(D*6n+4n)/5n:1n,L=M*BigInt(h.gas_unit_price),Z=Y(U-L,t,{balance:U.toString(),fee:L.toString()});return E(Z,{gasUnitPrice:Number(h.gas_unit_price),maxGasAmount:Number(M)})}catch(l){if(l instanceof s)throw l;throw new s("toolbox_aptos_transaction_creation_error",l)}}async function F(n){let t=await T();if(!t)throw new s("toolbox_aptos_no_signer");return(await _()).transaction.sign({signer:t,transaction:n})}async function Q({assetValue:n,maxGasAmount:t,recipient:a,sweep:r}){let u=await T();if(!u)throw new s("toolbox_aptos_no_signer");if(!x(a))throw new s("core_transaction_invalid_recipient_address");try{let p=u.accountAddress.toString(),g=await N({assetValue:n,maxGasAmount:t,recipient:a,sender:p,sweep:r});return(await(await _()).signAndSubmitTransaction({signer:u,transaction:g})).hash}catch(p){if(p instanceof s)throw p;throw new s("toolbox_aptos_transaction_creation_error",p)}}async function I({senderAuthenticator:n,transaction:t}){try{return(await(await _()).transaction.submit.simple({senderAuthenticator:n,transaction:t})).hash}catch(a){throw new s("toolbox_aptos_broadcast_error",a)}}async function X(n){let t=await F(n);return I({senderAuthenticator:t,transaction:n})}return{broadcastTransaction:I,createTransaction:N,estimateTransactionFee:H,getAddress:S,getBalance:G,signAndBroadcastTransaction:X,signTransaction:F,transfer:Q,validateAddress:x}}function rt({provider:e}){return async function({assetValue:d,recipient:c,sweep:y}){if(y)throw new s({errorKey:"toolbox_not_supported",info:{chain:A.Aptos,feature:"extension_provider_sweep",reason:"Aptos extension providers cannot query balances or simulate transactions"}});if(!x(c))throw new s("core_transaction_invalid_recipient_address");let{AccountAddress:T}=await import("@aptos-labs/ts-sdk");if(d.isGasAsset)return(await e.signAndSubmitTransaction({arguments:[T.from(c).toString(),d.getBaseValue("string")],function:w.TRANSFER,type:"entry_function_payload",type_arguments:[]})).hash;let _=d.address;if(!_)throw new s("toolbox_aptos_missing_asset_type");return(await e.signAndSubmitTransaction({arguments:[_,T.from(c).toString(),d.getBaseValue("string")],function:w.FUNGIBLE_STORE_TRANSFER,type:"entry_function_payload",type_arguments:[w.FUNGIBLE_ASSET_METADATA]})).hash}}export{rt as createAptosExtensionTransfer,et as getAptosToolbox,x as validateAptosAddress};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{ha as R}from"../../chunk-4428244x.js";import{bech32 as ne}from"@scure/base";import{mnemonicToEntropy as re}from"@scure/bip39";import{wordlist as oe}from"@scure/bip39/wordlists/english.js";import{AssetValue as S,Chain as w,getChainConfig as se,SwapKitError as h}from"@swapkit/helpers";import m from"bignumber.js";var X="mainnet3YT7XK6NidLPlkHxxyBB5V0WzXUOTIJS",J="https://cardano-mainnet.blockfrost.io/api/v0",U=2147483648,W=0;async function z(e,t){let o=await fetch(`${J}${e}`,{...t,headers:{project_id:X,...t?.headers}});if(!o.ok)throw Error(`Blockfrost API error: ${o.status} ${o.statusText}`);return o.json()}async function Q(e){try{return await z(`/addresses/${e}/utxos`)}catch{return[]}}async function ae(){return(await z("/blocks/latest")).slot}async function ie(){let e=await z("/epochs/latest/parameters"),t={PlutusScriptV1:e.cost_models.PlutusV1?Object.values(e.cost_models.PlutusV1):[],PlutusScriptV2:e.cost_models.PlutusV2?Object.values(e.cost_models.PlutusV2):[],PlutusScriptV3:e.cost_models.PlutusV3?Object.values(e.cost_models.PlutusV3):[]};return{collateralPercent:new m(e.collateral_percent),languageView:t,maxValueSize:Number.parseInt(e.max_val_size,10),minFeeA:new m(e.min_fee_a),minFeeB:new m(e.min_fee_b),minFeeRefScriptCostPerByte:new m(15),priceMem:new m(e.price_mem),priceSteps:new m(e.price_step),stakeKeyDeposit:new m(2000000),utxoCostPerByte:new m(e.coins_per_utxo_size)}}async function Y(e){let t=await fetch(`${J}/tx/submit`,{body:Buffer.from(e,"hex"),headers:{"Content-Type":"application/cbor",project_id:X},method:"POST"});if(!t.ok){let o=await t.text();throw Error(`Transaction submission failed: ${o}`)}return t.json()}function ce(e,t){return e.map((o)=>{let c=o.amount.find((r)=>r.unit==="lovelace"),a=c?new m(c.quantity):new m(0),u=o.amount.filter((r)=>r.unit!=="lovelace").map((r)=>({amount:new m(r.quantity),assetName:r.unit.slice(56),policyId:r.unit.slice(0,56)}));return{address:t,amount:a,index:o.output_index,tokens:u,txId:o.tx_hash}})}function ue({TransactionConstructor:e,auxiliaryData:t,bufferedParams:o,currentSlot:c,inputs:a,recipientAddress:u}){let r=a.reduce((n,s)=>n.plus(s.amount),new m(0));if(!r.isPositive())throw new h({errorKey:"toolbox_sweep_amount_too_low",info:{available:r.toString()}});let i=new e({protocolParams:o});for(let n of a)i.addInput(n);if(i.addOutput({address:u,amount:r,tokens:[]}),i.setTTL(c+3600),t)i.setAuxiliaryData(t);i.setFee(i.calculateFee());let y=i.getFee(),d=r.minus(y),p={address:u,amount:d,tokens:[]},P=i.calculateMinUtxoAmountBabbage(p);if(!d.isPositive()||d.lt(P))throw new h({errorKey:"toolbox_sweep_amount_too_low",info:{available:r.toString(),fee:y.toString(),minimumOutput:P.toString()}});return new e({protocolParams:o}).paymentTransaction({auxiliaryData:t,changeAddress:u,inputs:a,outputs:[p],ttl:c+3600})}async function de(e){try{let t=await Q(e),o=0n,c=new Map;for(let r of t){if(!r.amount||!Array.isArray(r.amount))continue;for(let i of r.amount){let{unit:y,quantity:d}=i;if(y==="lovelace")o+=BigInt(d);else{let p=c.get(y)||0n;c.set(y,p+BigInt(d))}}}let a=[],{baseDecimal:u}=se(w.Cardano);if(o>0n)a.push(S.from({chain:w.Cardano,fromBaseDecimal:u,value:o.toString()}));for(let[r,i]of c)a.push(S.from({asset:`${w.Cardano}.${r}`,value:i.toString()}));if(a.length===0)return[S.from({chain:w.Cardano})];return a}catch(t){let o=t instanceof Error?t.message:String(t);return console.error(`Cardano balance fetch error: ${o}`),[S.from({chain:w.Cardano})]}}function le(e){if(!e||typeof e!=="string")return!1;try{let t=ne.decode(e,120);return t.prefix==="addr"||t.prefix==="addr_test"}catch{return!1}}async function me(e,t=0,o=0){let{Bip32PrivateKey:c}=await import("@stricahq/bip32ed25519"),{types:a,address:u,crypto:r}=await import("@stricahq/typhonjs"),i=re(e,oe),d=(await c.fromEntropy(Buffer.from(Array.from(i)))).derive(U+1852).derive(U+1815).derive(U+t),p=d.derive(0).derive(o),P=p.toBip32PublicKey().toPublicKey().toBytes(),A=r.hash28(P),s=d.derive(2).derive(0).toBip32PublicKey().toPublicKey().toBytes(),l=r.hash28(s),_={hash:A,type:a.HashType.ADDRESS},T={hash:l,type:a.HashType.ADDRESS},C=new u.BaseAddress(a.NetworkId.MAINNET,_,T).getBech32(),B=p.toPrivateKey();return{getAddress:()=>C,publicKey:P,publicKeyHash:A,signTransaction:async(k)=>{try{let b=await import("@stricahq/cbors"),I=Buffer.from(k,"hex"),K=b.Decoder.decode(I),[D,O,L,V]=K.value,F=b.Encoder.encode(D),H=r.hash32(F),E=B.sign(H),v=O instanceof Map?O:new Map,M=v.get(W)||[];M.push([P,E]),v.set(W,M);let j=[D,v,L,V];return b.Encoder.encode(j).toString("hex")}catch(b){throw new h("toolbox_cardano_sign_transaction_failed",{message:String(b)})}}}}function we(e){let t,o,c;async function a(){if(!c)c=await ie();return c}async function u(){if(t!==void 0)return t;if(e&&"phrase"in e&&e.phrase){let{derivationPath:n}=e;if(n&&(n.length!==5||n[3]!==0||n[4]===void 0))throw new h("toolbox_derivation_slot_unsupported",{chain:w.Cardano,derivationPath:n});let s=n?.[2]??0,l=n?.[4]??e.index??0;return t=await me(e.phrase,s,l),t}if(e&&"signer"in e&&e.signer)return t=e.signer,t;return}async function r(){if(o)return o;let n=await u();if(!n)return"";if("getAddress"in n)return o=await n.getAddress(),o;return""}async function i(n){let s=n||await r();if(!s)throw new h("core_wallet_connection_not_found");return de(s)}async function y(n){if(n)try{let{tx:T}=await d(n),x=T.getFee();return S.from({chain:w.Cardano,fromBaseDecimal:6,value:x.toString()})}catch{}let s=await a(),l=400,_=s.minFeeB.plus(s.minFeeA.times(l));return S.from({chain:w.Cardano,fromBaseDecimal:6,value:_.toString()})}async function d({sender:n="",recipient:s,assetValue:l,memo:_,pureLovelaceOnly:T=!1,sweep:x=!1}){let{Transaction:C,utils:B}=await import("@stricahq/typhonjs"),k=n||await r();if(!k)throw new h("core_wallet_connection_not_found");let[b,I,K]=await Promise.all([Q(k),ae(),a()]);if(x&&!l.isGasAsset)throw new h({errorKey:"toolbox_not_supported",info:{asset:l.toString(),chain:w.Cardano,feature:"token_sweep"}});let D=x&&l.isGasAsset,O=T||D,L=b.filter((f)=>O?f.amount.some((g)=>g.unit==="lovelace")&&f.amount.every((g)=>g.unit==="lovelace"):f.amount.some((g)=>g.unit==="lovelace")).sort((f,g)=>{let G=f.amount.some((N)=>N.unit!=="lovelace"),te=g.amount.some((N)=>N.unit!=="lovelace");if(G===te)return 0;return G?1:-1}),V=B.getAddressFromString(k),F=B.getAddressFromString(s),H=ce(L,V),E;if(_){let f=new Map;f.set("msg",[_]),E={metadata:[{data:f,label:674}]}}let v={...K,minFeeB:K.minFeeB.plus(K.minFeeA.times(4))};if(D){let f=ue({auxiliaryData:E,bufferedParams:v,currentSlot:I,inputs:H,recipientAddress:F,TransactionConstructor:C}),{payload:g}=f.buildTransaction();return{tx:f,unsignedTx:g}}let M=new m(l.getBaseValue("string")),j=[{address:F,amount:M,tokens:[]}],q=new C({protocolParams:v}).paymentTransaction({auxiliaryData:E,changeAddress:V,inputs:H,outputs:j,ttl:I+3600}),{payload:ee}=q.buildTransaction();return{tx:q,unsignedTx:ee}}async function p(n){let s=await u();if(!s||!("signTransaction"in s))throw new h("core_wallet_connection_not_found");return s.signTransaction(n)}async function P({recipient:n,assetValue:s,memo:l,sweep:_}){let T=await u();if(!T||!("signTransaction"in T))throw new h("core_wallet_connection_not_found");let{unsignedTx:x}=await d({assetValue:s,memo:l,recipient:n,sender:await r(),sweep:_}),C=await p(x);return await Y(C)}async function A(n){let s=await p(n);return await Y(s)}return{createTransaction:d,estimateTransactionFee:y,getAddress:r,getBalance:i,signAndBroadcastTransaction:A,signTransaction:p,transfer:P,validateAddress:le}}export{we as getCardanoToolbox,le as validateCardanoAddress};
|
package/dist/src/cosmos/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import"../../chunk-k50sjysj.js";import{base64 as Y,bech32 as G}from"@scure/base";import{SwapKitError as at}from"@swapkit/helpers";function z(i){return Y.encode(Uint8Array.from(G.fromWords(G.decode(i).words)))}function X(i,o="thor"){return G.encode(o,G.toWords(Y.decode(i)))}function Me(i){return Y.encode(i)}function _e(i){if(!i.match(/^[a-zA-Z0-9+/]*={0,2}$/))throw new at("toolbox_cosmos_invalid_params",{error:"Invalid base64 string format"});return Y.decode(i)}import{encodeMessage as It,encodeTxBody as Rt}from"@swapkit/cosmos-signer";import{AssetValue as Kt,Chain as tn,getChainConfig as Ln,getRPCUrl as yn,SwapKitError as gn}from"@swapkit/helpers";import{base64 as ln}from"@scure/base";import{broadcastTx as Q,getAccount as Mn,getBalances as ut,createTendermintRpc as lt,defaultEncoders as ft,encodeAuthInfo as Pn,encodeMessage as dt,encodePubkey as mt,encodeTxBody as pt,encodeTxRaw as vn,makeStdSignDoc as yt}from"@swapkit/cosmos-signer";import{AssetValue as fn,Chain as b,getChainConfig as M,getRPCUrl as gt,RequestClient as ht,SKConfig as Dn,SwapKitError as P,SwapKitNumber as dn}from"@swapkit/helpers";var _n="FACTORY/KUJIRA1QK00H5ATUTPSV900X202PXX42NPJR9THG58DNQPA72F2P7M2LUASE444A7/UUSK",bt="FACTORY/KUJIRA1YGFXN0ER40KLCNCK8THLTUPRDXLCK6WVNPKF2K/UYUM",At={amount:[{amount:"500",denom:"uatom"}],gas:"200000"},wt={amount:[{amount:"1000",denom:"ukuji"}],gas:"200000"},St={amount:[{amount:"1000",denom:"uusdc"}],gas:"200000"};function _(i){switch(i){case b.Maya:return{amount:[],gas:"10000000000"};case b.THORChain:return{amount:[],gas:"500000000"};case b.Kujira:return wt;case b.Noble:return St;default:return At}}async function Z(i){let{isStagenet:o}=Dn.get("envs"),r=Dn.get("thornodeUrls"),n=i===b.Maya,e=`${n?o?r.MAYA_STAGENET:r.MAYA:o?r.THOR_STAGENET:r.THOR}/${n?"mayachain":"thorchain"}/constants`,s=M(i).baseDecimal;try{let{int_64_values:{NativeTransactionFee:c}}=await ht.get(e);if(!Number.isInteger(c)||c<=0)throw new P("toolbox_cosmos_invalid_fee",{nativeFee:c.toString()});return dn.fromBigInt(BigInt(c),s)}catch{let c=n?10000000000n:2000000n;return dn.fromBigInt(c,s)}}var U=(i,o=!1)=>{if(o)return i.toLowerCase();switch(i){case"uUSK":case"USK":return _n;case"uYUM":case"YUM":return bt;case"uKUJI":case"KUJI":return"ukuji";case"ATOM":case"uATOM":return"uatom";case"uUSDC":case"USDC":case"NOBLE":return"uusdc";default:return i}},nn=({symbol:i,chain:o})=>{if(o===b.Maya)return(i.toUpperCase()!=="CACAO"?i:`${b.Maya}.${i}`).toUpperCase();if(o===b.THORChain)return(["RUNE","TCY","RUJI"].includes(i.toUpperCase())?`${b.THORChain}.${i}`:i).toUpperCase();return U(i,!1)},Ct=()=>typeof window<"u"?{}:{referer:"https://sdk.swapkit.dev",referrer:"https://sdk.swapkit.dev"};function Nn(i){return lt(i,{headers:Ct()})}function Un(i){return{amount:i.amount,denom:i.denom}}function Ot(i,o){if(!i)return null;if("toAmino"in i&&typeof i.toAmino==="function")return null;let n=i[o];return n?{aminoType:n.aminoType,toAmino:n.toAmino}:null}async function N(i){let o=Nn(i);return{async broadcastTx(r){let n=await Q(o,r,"sync");if(n.code!==0)throw new P("core_swap_transaction_error",{code:n.code,message:n.log});return{code:n.code,rawLog:n.log,transactionHash:n.hash}},async getAccount(r){let n=await Mn(o,r);if(!n)return null;return{accountNumber:Number(n.accountNumber),address:n.address,pubkey:n.pubKey?{type:n.pubKey.typeUrl,value:n.pubKey.key}:null,sequence:Number(n.sequence)}},async getAllBalances(r){return(await ut(o,r)).map((t)=>({amount:t.amount,denom:t.denom}))}}}function Bn(i,o={}){let r=Tt(i);async function n(t,e,s,c,a){let h=(await i.getAccounts()).find((g)=>g.address===t);if(!h)throw new P("toolbox_cosmos_signer_not_defined");let w=Dt({memo:c,messages:e,registry:o.registry}),C=mt({type:"tendermint/PubKeySecp256k1",value:ln.encode(h.pubkey)});if(r){let g=e.map((k)=>vt(k,o.aminoTypes)),A=yt({accountNumber:a.accountNumber,chainId:a.chainId,fee:xt(s),memo:c,msgs:g,sequence:a.sequence}),S=await i.signAmino(t,A),O=Pn({fee:Pt(S.signed.fee,s),signerInfos:[{mode:"amino",pubkey:C,sequence:BigInt(S.signed.sequence)}]}),D=ln.decode(S.signature.signature);return{authInfoBytes:O,bodyBytes:w,signatures:[D]}}let m=Pn({fee:kt(s),signerInfos:[{mode:"direct",pubkey:C,sequence:BigInt(a.sequence)}]}),y=await i.signDirect(t,{accountNumber:a.accountNumber,authInfoBytes:m,bodyBytes:w,chainId:a.chainId}),f=ln.decode(y.signature.signature);return{authInfoBytes:m,bodyBytes:w,signatures:[f]}}return{signWithRegistry:n}}function Tt(i){return typeof i.signAmino==="function"}function xt(i){return{amount:i.amount.map((o)=>({amount:o.amount,denom:o.denom})),gas:i.gas,...i.granter?{granter:i.granter}:{},...i.payer?{payer:i.payer}:{}}}function kt(i){return{amount:i.amount.map(Un),gasLimit:BigInt(i.gas),...i.granter?{granter:i.granter}:{},...i.payer?{payer:i.payer}:{}}}function Pt(i,o){return{amount:i.amount.map(Un),gasLimit:BigInt(i.gas),...i.granter??o.granter?{granter:i.granter??o.granter}:{},...i.payer??o.payer?{payer:i.payer??o.payer}:{}}}function vt(i,o){if(o&&"toAmino"in o&&typeof o.toAmino==="function")return o.toAmino(i);let r=Ot(o,i.typeUrl);if(!r){if(i.typeUrl==="/cosmos.bank.v1beta1.MsgSend"){let n=i.value;return{type:"cosmos-sdk/MsgSend",value:{amount:n.amount,from_address:n.fromAddress,to_address:n.toAddress}}}throw new P("toolbox_cosmos_invalid_params",{error:`No amino converter for ${i.typeUrl}`})}return{type:r.aminoType,value:r.toAmino(i.value)}}function Dt(i){let{memo:o,messages:r,registry:n}=i;if(n&&"encode"in n&&typeof n.encode==="function")return n.encode({typeUrl:"/cosmos.tx.v1beta1.TxBody",value:{memo:o,messages:r}});let t={...ft,...n??{}},e=r.map((s)=>dt(s,t));return pt({memo:o,messages:e})}async function E(i,o,r={}){let n=typeof r==="string"?{}:r,t=Nn(i),e=Bn(o,n);async function s(c,a){let p=await Mn(t,c);if(!p)throw new P("toolbox_cosmos_account_not_found",{sender:c});let h=a?.chainId??(await t.status()).chainId;return{accountNumber:a?.accountNumber??p.accountNumber,chainId:h,sequence:a?.sequence??p.sequence}}return{async broadcastTx(c){let a=await Q(t,c,"sync");if(a.code!==0)throw new P("core_swap_transaction_error",{code:a.code,message:a.log});return{code:a.code,rawLog:a.log,transactionHash:a.hash}},async sendTokens(c,a,p,h,w=""){let C=[{typeUrl:"/cosmos.bank.v1beta1.MsgSend",value:{amount:p.map((A)=>({amount:A.amount,denom:A.denom})),fromAddress:c,toAddress:a}}],m=await s(c),y=await e.signWithRegistry(c,C,h,w,m),f=vn({authInfoBytes:y.authInfoBytes,bodyBytes:y.bodyBytes,signatures:y.signatures}),g=await Q(t,f,"sync");if(g.code!==0)throw new P("core_swap_transaction_error",{code:g.code,message:g.log});return{code:g.code,rawLog:g.log,transactionHash:g.hash}},async sign(c,a,p,h,w){let C=w??await s(c);return e.signWithRegistry(c,a,p,h,C)},async signAndBroadcast(c,a,p,h=""){let w=await s(c),C=await e.signWithRegistry(c,a,p,h,w),m=vn({authInfoBytes:C.authInfoBytes,bodyBytes:C.bodyBytes,signatures:C.signatures}),y=await Q(t,m,"sync");return{code:y.code,rawLog:y.log,transactionHash:y.hash}}}}async function Fn(i,o){let r=Bn(i,o??{});return{sign(n,t,e,s,c){if(!c)throw new P("toolbox_cosmos_invalid_params",{error:"createOfflineStargateClient.sign requires signerData"});return r.signWithRegistry(n,t,e,s,c)}}}var Mt=(i)=>{switch(i){case b.Maya:case b.THORChain:return"/types.MsgSend";case b.Cosmos:case b.Kujira:case b.Noble:return"/cosmos.bank.v1beta1.MsgSend";default:throw new P("toolbox_cosmos_not_supported",{chain:i})}};async function _t({client:i,sender:o}){let r=await i.getAccount(o);if(!r)throw new P("toolbox_cosmos_account_not_found",{sender:o});return r}async function In({sender:i,recipient:o,assetValue:r,memo:n="",feeRate:t,sequence:e,accountNumber:s,sweep:c}){let{chain:a,chainId:p}=r,h=s===void 0||e===void 0,w=c||h?await N(await gt(a)):void 0,C=h&&w?await _t({client:w,sender:i}):void 0,m=fn.from({chain:a}),y=U(m.symbol),f=_(a),g=y&&t?{amount:[{amount:t.toString(),denom:y}],gas:f.gas}:f,A=U(r.symbol),S=r;if(c){if(!w)throw new P("toolbox_cosmos_account_not_found",{sender:i});S=W({assetValue:r,balances:await w.getAllBalances(i),denom:A,feeAmount:mn(g.amount,A)})}let O={amount:[{amount:S.getBaseValue("string"),denom:A}],fromAddress:i,toAddress:o};return{accountNumber:s??Number(C?.accountNumber),chainId:p,fee:g,memo:n,msgs:[{typeUrl:Mt(a),value:O}],sequence:e??Number(C?.sequence)}}function mn(i,o){let r=o.toLowerCase();return i.reduce((n,t)=>t.denom.toLowerCase()===r?n+BigInt(t.amount):n,0n)}function W({assetValue:i,balances:o,denom:r,feeAmount:n=0n}){let t=r.toLowerCase(),e=o.find(({denom:a})=>a.toLowerCase()===t),s=BigInt(e?.amount??"0"),c=s-n;if(c<=0n)throw new P("toolbox_sweep_amount_too_low",{asset:i.toString(),balance:s.toString(),fee:n.toString()});return i.set(dn.fromBigInt(c,i.decimal))}var Nt={atom:{chain:b.Cosmos,decimals:M(b.Cosmos).baseDecimal},cacao:{chain:b.Maya,decimals:10},kuji:{chain:b.Kujira,decimals:M(b.Kujira).baseDecimal},maya:{asset:`${b.Maya}.${b.Maya}`,decimals:4},rune:{chain:b.THORChain,decimals:M(b.THORChain).baseDecimal},tcy:{asset:"THOR.TCY",decimals:M(b.THORChain).baseDecimal},uatom:{chain:b.Cosmos,decimals:M(b.Cosmos).baseDecimal},ukuji:{chain:b.Kujira,decimals:M(b.Kujira).baseDecimal},usdc:{chain:b.Noble,decimals:M(b.Noble).baseDecimal},uusdc:{chain:b.Noble,decimals:M(b.Noble).baseDecimal},"x/kuji":{asset:"THOR.KUJI",decimals:M(b.THORChain).baseDecimal},[_n.toLowerCase()]:{asset:`${b.Kujira}.USK`,decimals:M(b.Kujira).baseDecimal}},Rn=(i,o)=>{let r=Nt[i.toLowerCase()];if(!r)return fn.from({asset:i,fromBaseDecimal:8,value:o});let{chain:n,asset:t,decimals:e}=r,s=n?{chain:n}:{asset:t};return fn.from({...s,fromBaseDecimal:e,value:o})};import{defaultEncoders as Ut}from"@swapkit/cosmos-signer";import{Chain as Kn}from"@swapkit/helpers";import T from"protobufjs/minimal.js";var d=T.Reader,v=T.Writer,l=T.util,u=T.roots.default||(T.roots.default={});u.common=(()=>{let i={};return i.Asset=(()=>{function o(r){if(r){for(let n=Object.keys(r),t=0;t<n.length;++t)if(r[n[t]]!=null)this[n[t]]=r[n[t]]}}return o.prototype.chain="",o.prototype.symbol="",o.prototype.ticker="",o.prototype.synth=!1,o.create=function(n){return new o(n)},o.encode=function(n,t){if(!t)t=v.create();if(n.chain!=null&&Object.hasOwnProperty.call(n,"chain"))t.uint32(10).string(n.chain);if(n.symbol!=null&&Object.hasOwnProperty.call(n,"symbol"))t.uint32(18).string(n.symbol);if(n.ticker!=null&&Object.hasOwnProperty.call(n,"ticker"))t.uint32(26).string(n.ticker);if(n.synth!=null&&Object.hasOwnProperty.call(n,"synth"))t.uint32(32).bool(n.synth);return t},o.encodeDelimited=function(n,t){return this.encode(n,t).ldelim()},o.decode=function(n,t){if(!(n instanceof d))n=d.create(n);let e=t===void 0?n.len:n.pos+t,s=new u.common.Asset;while(n.pos<e){let c=n.uint32();switch(c>>>3){case 1:s.chain=n.string();break;case 2:s.symbol=n.string();break;case 3:s.ticker=n.string();break;case 4:s.synth=n.bool();break;default:n.skipType(c&7);break}}return s},o.decodeDelimited=function(n){if(!(n instanceof d))n=new d(n);return this.decode(n,n.uint32())},o.verify=function(n){if(typeof n!=="object"||n===null)return"object expected";if(n.chain!=null&&n.hasOwnProperty("chain")){if(!l.isString(n.chain))return"chain: string expected"}if(n.symbol!=null&&n.hasOwnProperty("symbol")){if(!l.isString(n.symbol))return"symbol: string expected"}if(n.ticker!=null&&n.hasOwnProperty("ticker")){if(!l.isString(n.ticker))return"ticker: string expected"}if(n.synth!=null&&n.hasOwnProperty("synth")){if(typeof n.synth!=="boolean")return"synth: boolean expected"}return null},o.fromObject=function(n){if(n instanceof u.common.Asset)return n;let t=new u.common.Asset;if(n.chain!=null)t.chain=String(n.chain);if(n.symbol!=null)t.symbol=String(n.symbol);if(n.ticker!=null)t.ticker=String(n.ticker);if(n.synth!=null)t.synth=Boolean(n.synth);return t},o.toObject=function(n,t){if(!t)t={};let e={};if(t.defaults)e.chain="",e.symbol="",e.ticker="",e.synth=!1;if(n.chain!=null&&n.hasOwnProperty("chain"))e.chain=n.chain;if(n.symbol!=null&&n.hasOwnProperty("symbol"))e.symbol=n.symbol;if(n.ticker!=null&&n.hasOwnProperty("ticker"))e.ticker=n.ticker;if(n.synth!=null&&n.hasOwnProperty("synth"))e.synth=n.synth;return e},o.prototype.toJSON=function(){return this.constructor.toObject(this,T.util.toJSONOptions)},o})(),i.Coin=(()=>{function o(r){if(r){for(let n=Object.keys(r),t=0;t<n.length;++t)if(r[n[t]]!=null)this[n[t]]=r[n[t]]}}return o.prototype.asset=null,o.prototype.amount="",o.prototype.decimals=l.Long?l.Long.fromBits(0,0,!1):0,o.create=function(n){return new o(n)},o.encode=function(n,t){if(!t)t=v.create();if(n.asset!=null&&Object.hasOwnProperty.call(n,"asset"))u.common.Asset.encode(n.asset,t.uint32(10).fork()).ldelim();if(n.amount!=null&&Object.hasOwnProperty.call(n,"amount"))t.uint32(18).string(n.amount);if(n.decimals!=null&&Object.hasOwnProperty.call(n,"decimals"))t.uint32(24).int64(n.decimals);return t},o.encodeDelimited=function(n,t){return this.encode(n,t).ldelim()},o.decode=function(n,t){if(!(n instanceof d))n=d.create(n);let e=t===void 0?n.len:n.pos+t,s=new u.common.Coin;while(n.pos<e){let c=n.uint32();switch(c>>>3){case 1:s.asset=u.common.Asset.decode(n,n.uint32());break;case 2:s.amount=n.string();break;case 3:s.decimals=n.int64();break;default:n.skipType(c&7);break}}return s},o.decodeDelimited=function(n){if(!(n instanceof d))n=new d(n);return this.decode(n,n.uint32())},o.verify=function(n){if(typeof n!=="object"||n===null)return"object expected";if(n.asset!=null&&n.hasOwnProperty("asset")){let t=u.common.Asset.verify(n.asset);if(t)return"asset."+t}if(n.amount!=null&&n.hasOwnProperty("amount")){if(!l.isString(n.amount))return"amount: string expected"}if(n.decimals!=null&&n.hasOwnProperty("decimals")){if(!l.isInteger(n.decimals)&&!(n.decimals&&l.isInteger(n.decimals.low)&&l.isInteger(n.decimals.high)))return"decimals: integer|Long expected"}return null},o.fromObject=function(n){if(n instanceof u.common.Coin)return n;let t=new u.common.Coin;if(n.asset!=null){if(typeof n.asset!=="object")throw TypeError(".common.Coin.asset: object expected");t.asset=u.common.Asset.fromObject(n.asset)}if(n.amount!=null)t.amount=String(n.amount);if(n.decimals!=null){if(l.Long)(t.decimals=l.Long.fromValue(n.decimals)).unsigned=!1;else if(typeof n.decimals==="string")t.decimals=Number.parseInt(n.decimals,10);else if(typeof n.decimals==="number")t.decimals=n.decimals;else if(typeof n.decimals==="object")t.decimals=new l.LongBits(n.decimals.low>>>0,n.decimals.high>>>0).toNumber()}return t},o.toObject=function(n,t){if(!t)t={};let e={};if(t.defaults)if(e.asset=null,e.amount="",l.Long){let s=new l.Long(0,0,!1);e.decimals=t.longs===String?s.toString():t.longs===Number?s.toNumber():s}else e.decimals=t.longs===String?"0":0;if(n.asset!=null&&n.hasOwnProperty("asset"))e.asset=u.common.Asset.toObject(n.asset,t);if(n.amount!=null&&n.hasOwnProperty("amount"))e.amount=n.amount;if(n.decimals!=null&&n.hasOwnProperty("decimals"))if(typeof n.decimals==="number")e.decimals=t.longs===String?String(n.decimals):n.decimals;else e.decimals=t.longs===String?l.Long.prototype.toString.call(n.decimals):t.longs===Number?new l.LongBits(n.decimals.low>>>0,n.decimals.high>>>0).toNumber():n.decimals;return e},o.prototype.toJSON=function(){return this.constructor.toObject(this,T.util.toJSONOptions)},o})(),i.PubKeySet=(()=>{function o(r){if(r){for(let n=Object.keys(r),t=0;t<n.length;++t)if(r[n[t]]!=null)this[n[t]]=r[n[t]]}}return o.prototype.secp256k1="",o.prototype.ed25519="",o.create=function(n){return new o(n)},o.encode=function(n,t){if(!t)t=v.create();if(n.secp256k1!=null&&Object.hasOwnProperty.call(n,"secp256k1"))t.uint32(10).string(n.secp256k1);if(n.ed25519!=null&&Object.hasOwnProperty.call(n,"ed25519"))t.uint32(18).string(n.ed25519);return t},o.encodeDelimited=function(n,t){return this.encode(n,t).ldelim()},o.decode=function(n,t){if(!(n instanceof d))n=d.create(n);let e=t===void 0?n.len:n.pos+t,s=new u.common.PubKeySet;while(n.pos<e){let c=n.uint32();switch(c>>>3){case 1:s.secp256k1=n.string();break;case 2:s.ed25519=n.string();break;default:n.skipType(c&7);break}}return s},o.decodeDelimited=function(n){if(!(n instanceof d))n=new d(n);return this.decode(n,n.uint32())},o.verify=function(n){if(typeof n!=="object"||n===null)return"object expected";if(n.secp256k1!=null&&n.hasOwnProperty("secp256k1")){if(!l.isString(n.secp256k1))return"secp256k1: string expected"}if(n.ed25519!=null&&n.hasOwnProperty("ed25519")){if(!l.isString(n.ed25519))return"ed25519: string expected"}return null},o.fromObject=function(n){if(n instanceof u.common.PubKeySet)return n;let t=new u.common.PubKeySet;if(n.secp256k1!=null)t.secp256k1=String(n.secp256k1);if(n.ed25519!=null)t.ed25519=String(n.ed25519);return t},o.toObject=function(n,t){if(!t)t={};let e={};if(t.defaults)e.secp256k1="",e.ed25519="";if(n.secp256k1!=null&&n.hasOwnProperty("secp256k1"))e.secp256k1=n.secp256k1;if(n.ed25519!=null&&n.hasOwnProperty("ed25519"))e.ed25519=n.ed25519;return e},o.prototype.toJSON=function(){return this.constructor.toObject(this,T.util.toJSONOptions)},o})(),i.Tx=(()=>{function o(r){if(this.coins=[],this.gas=[],r){for(let n=Object.keys(r),t=0;t<n.length;++t)if(r[n[t]]!=null)this[n[t]]=r[n[t]]}}return o.prototype.id="",o.prototype.chain="",o.prototype.fromAddress="",o.prototype.toAddress="",o.prototype.coins=l.emptyArray,o.prototype.gas=l.emptyArray,o.prototype.memo="",o.create=function(n){return new o(n)},o.encode=function(n,t){if(!t)t=v.create();if(n.id!=null&&Object.hasOwnProperty.call(n,"id"))t.uint32(10).string(n.id);if(n.chain!=null&&Object.hasOwnProperty.call(n,"chain"))t.uint32(18).string(n.chain);if(n.fromAddress!=null&&Object.hasOwnProperty.call(n,"fromAddress"))t.uint32(26).string(n.fromAddress);if(n.toAddress!=null&&Object.hasOwnProperty.call(n,"toAddress"))t.uint32(34).string(n.toAddress);if(n.coins?.length)for(let e=0;e<n.coins.length;++e)u.common.Coin.encode(n.coins[e],t.uint32(42).fork()).ldelim();if(n.gas?.length)for(let e=0;e<n.gas.length;++e)u.common.Coin.encode(n.gas[e],t.uint32(50).fork()).ldelim();if(n.memo!=null&&Object.hasOwnProperty.call(n,"memo"))t.uint32(58).string(n.memo);return t},o.encodeDelimited=function(n,t){return this.encode(n,t).ldelim()},o.decode=function(n,t){if(!(n instanceof d))n=d.create(n);let e=t===void 0?n.len:n.pos+t,s=new u.common.Tx;while(n.pos<e){let c=n.uint32();switch(c>>>3){case 1:s.id=n.string();break;case 2:s.chain=n.string();break;case 3:s.fromAddress=n.string();break;case 4:s.toAddress=n.string();break;case 5:if(!s.coins?.length)s.coins=[];s.coins.push(u.common.Coin.decode(n,n.uint32()));break;case 6:if(!s.gas?.length)s.gas=[];s.gas.push(u.common.Coin.decode(n,n.uint32()));break;case 7:s.memo=n.string();break;default:n.skipType(c&7);break}}return s},o.decodeDelimited=function(n){if(!(n instanceof d))n=new d(n);return this.decode(n,n.uint32())},o.verify=function(n){if(typeof n!=="object"||n===null)return"object expected";if(n.id!=null&&n.hasOwnProperty("id")){if(!l.isString(n.id))return"id: string expected"}if(n.chain!=null&&n.hasOwnProperty("chain")){if(!l.isString(n.chain))return"chain: string expected"}if(n.fromAddress!=null&&n.hasOwnProperty("fromAddress")){if(!l.isString(n.fromAddress))return"fromAddress: string expected"}if(n.toAddress!=null&&n.hasOwnProperty("toAddress")){if(!l.isString(n.toAddress))return"toAddress: string expected"}if(n.coins!=null&&n.hasOwnProperty("coins")){if(!Array.isArray(n.coins))return"coins: array expected";for(let t=0;t<n.coins.length;++t){let e=u.common.Coin.verify(n.coins[t]);if(e)return"coins."+e}}if(n.gas!=null&&n.hasOwnProperty("gas")){if(!Array.isArray(n.gas))return"gas: array expected";for(let t=0;t<n.gas.length;++t){let e=u.common.Coin.verify(n.gas[t]);if(e)return"gas."+e}}if(n.memo!=null&&n.hasOwnProperty("memo")){if(!l.isString(n.memo))return"memo: string expected"}return null},o.fromObject=function(n){if(n instanceof u.common.Tx)return n;let t=new u.common.Tx;if(n.id!=null)t.id=String(n.id);if(n.chain!=null)t.chain=String(n.chain);if(n.fromAddress!=null)t.fromAddress=String(n.fromAddress);if(n.toAddress!=null)t.toAddress=String(n.toAddress);if(n.coins){if(!Array.isArray(n.coins))throw TypeError(".common.Tx.coins: array expected");t.coins=[];for(let e=0;e<n.coins.length;++e){if(typeof n.coins[e]!=="object")throw TypeError(".common.Tx.coins: object expected");t.coins[e]=u.common.Coin.fromObject(n.coins[e])}}if(n.gas){if(!Array.isArray(n.gas))throw TypeError(".common.Tx.gas: array expected");t.gas=[];for(let e=0;e<n.gas.length;++e){if(typeof n.gas[e]!=="object")throw TypeError(".common.Tx.gas: object expected");t.gas[e]=u.common.Coin.fromObject(n.gas[e])}}if(n.memo!=null)t.memo=String(n.memo);return t},o.toObject=function(n,t){if(!t)t={};let e={};if(t.arrays||t.defaults)e.coins=[],e.gas=[];if(t.defaults)e.id="",e.chain="",e.fromAddress="",e.toAddress="",e.memo="";if(n.id!=null&&n.hasOwnProperty("id"))e.id=n.id;if(n.chain!=null&&n.hasOwnProperty("chain"))e.chain=n.chain;if(n.fromAddress!=null&&n.hasOwnProperty("fromAddress"))e.fromAddress=n.fromAddress;if(n.toAddress!=null&&n.hasOwnProperty("toAddress"))e.toAddress=n.toAddress;if(n.coins?.length){e.coins=[];for(let s=0;s<n.coins.length;++s)e.coins[s]=u.common.Coin.toObject(n.coins[s],t)}if(n.gas?.length){e.gas=[];for(let s=0;s<n.gas.length;++s)e.gas[s]=u.common.Coin.toObject(n.gas[s],t)}if(n.memo!=null&&n.hasOwnProperty("memo"))e.memo=n.memo;return e},o.prototype.toJSON=function(){return this.constructor.toObject(this,T.util.toJSONOptions)},o})(),i.Fee=(()=>{function o(r){if(this.coins=[],r){for(let n=Object.keys(r),t=0;t<n.length;++t)if(r[n[t]]!=null)this[n[t]]=r[n[t]]}}return o.prototype.coins=l.emptyArray,o.prototype.poolDeduct="",o.create=function(n){return new o(n)},o.encode=function(n,t){if(!t)t=v.create();if(n.coins?.length)for(let e=0;e<n.coins.length;++e)u.common.Coin.encode(n.coins[e],t.uint32(10).fork()).ldelim();if(n.poolDeduct!=null&&Object.hasOwnProperty.call(n,"poolDeduct"))t.uint32(18).string(n.poolDeduct);return t},o.encodeDelimited=function(n,t){return this.encode(n,t).ldelim()},o.decode=function(n,t){if(!(n instanceof d))n=d.create(n);let e=t===void 0?n.len:n.pos+t,s=new u.common.Fee;while(n.pos<e){let c=n.uint32();switch(c>>>3){case 1:if(!s.coins?.length)s.coins=[];s.coins.push(u.common.Coin.decode(n,n.uint32()));break;case 2:s.poolDeduct=n.string();break;default:n.skipType(c&7);break}}return s},o.decodeDelimited=function(n){if(!(n instanceof d))n=new d(n);return this.decode(n,n.uint32())},o.verify=function(n){if(typeof n!=="object"||n===null)return"object expected";if(n.coins!=null&&n.hasOwnProperty("coins")){if(!Array.isArray(n.coins))return"coins: array expected";for(let t=0;t<n.coins.length;++t){let e=u.common.Coin.verify(n.coins[t]);if(e)return"coins."+e}}if(n.poolDeduct!=null&&n.hasOwnProperty("poolDeduct")){if(!l.isString(n.poolDeduct))return"poolDeduct: string expected"}return null},o.fromObject=function(n){if(n instanceof u.common.Fee)return n;let t=new u.common.Fee;if(n.coins){if(!Array.isArray(n.coins))throw TypeError(".common.Fee.coins: array expected");t.coins=[];for(let e=0;e<n.coins.length;++e){if(typeof n.coins[e]!=="object")throw TypeError(".common.Fee.coins: object expected");t.coins[e]=u.common.Coin.fromObject(n.coins[e])}}if(n.poolDeduct!=null)t.poolDeduct=String(n.poolDeduct);return t},o.toObject=function(n,t){if(!t)t={};let e={};if(t.arrays||t.defaults)e.coins=[];if(t.defaults)e.poolDeduct="";if(n.coins?.length){e.coins=[];for(let s=0;s<n.coins.length;++s)e.coins[s]=u.common.Coin.toObject(n.coins[s],t)}if(n.poolDeduct!=null&&n.hasOwnProperty("poolDeduct"))e.poolDeduct=n.poolDeduct;return e},o.prototype.toJSON=function(){return this.constructor.toObject(this,T.util.toJSONOptions)},o})(),i.ProtoUint=(()=>{function o(r){if(r){for(let n=Object.keys(r),t=0;t<n.length;++t)if(r[n[t]]!=null)this[n[t]]=r[n[t]]}}return o.prototype.value="",o.create=function(n){return new o(n)},o.encode=function(n,t){if(!t)t=v.create();if(n.value!=null&&Object.hasOwnProperty.call(n,"value"))t.uint32(10).string(n.value);return t},o.encodeDelimited=function(n,t){return this.encode(n,t).ldelim()},o.decode=function(n,t){if(!(n instanceof d))n=d.create(n);let e=t===void 0?n.len:n.pos+t,s=new u.common.ProtoUint;while(n.pos<e){let c=n.uint32();switch(c>>>3){case 1:s.value=n.string();break;default:n.skipType(c&7);break}}return s},o.decodeDelimited=function(n){if(!(n instanceof d))n=new d(n);return this.decode(n,n.uint32())},o.verify=function(n){if(typeof n!=="object"||n===null)return"object expected";if(n.value!=null&&n.hasOwnProperty("value")){if(!l.isString(n.value))return"value: string expected"}return null},o.fromObject=function(n){if(n instanceof u.common.ProtoUint)return n;let t=new u.common.ProtoUint;if(n.value!=null)t.value=String(n.value);return t},o.toObject=function(n,t){if(!t)t={};let e={};if(t.defaults)e.value="";if(n.value!=null&&n.hasOwnProperty("value"))e.value=n.value;return e},o.prototype.toJSON=function(){return this.constructor.toObject(this,T.util.toJSONOptions)},o})(),i})();u.types=(()=>{let i={};return i.MsgDeposit=(()=>{function o(r){if(this.coins=[],r){for(let n=Object.keys(r),t=0;t<n.length;++t)if(r[n[t]]!=null)this[n[t]]=r[n[t]]}}return o.prototype.coins=l.emptyArray,o.prototype.memo="",o.prototype.signer=l.newBuffer([]),o.create=function(n){return new o(n)},o.encode=function(n,t){if(!t)t=v.create();if(n.coins?.length)for(let e=0;e<n.coins.length;++e)u.common.Coin.encode(n.coins[e],t.uint32(10).fork()).ldelim();if(n.memo!=null&&Object.hasOwnProperty.call(n,"memo"))t.uint32(18).string(n.memo);if(n.signer!=null&&Object.hasOwnProperty.call(n,"signer"))t.uint32(26).bytes(n.signer);return t},o.encodeDelimited=function(n,t){return this.encode(n,t).ldelim()},o.decode=function(n,t){if(!(n instanceof d))n=d.create(n);let e=t===void 0?n.len:n.pos+t,s=new u.types.MsgDeposit;while(n.pos<e){let c=n.uint32();switch(c>>>3){case 1:if(!s.coins?.length)s.coins=[];s.coins.push(u.common.Coin.decode(n,n.uint32()));break;case 2:s.memo=n.string();break;case 3:s.signer=n.bytes();break;default:n.skipType(c&7);break}}return s},o.decodeDelimited=function(n){if(!(n instanceof d))n=new d(n);return this.decode(n,n.uint32())},o.verify=function(n){if(typeof n!=="object"||n===null)return"object expected";if(n.coins!=null&&n.hasOwnProperty("coins")){if(!Array.isArray(n.coins))return"coins: array expected";for(let t=0;t<n.coins.length;++t){let e=u.common.Coin.verify(n.coins[t]);if(e)return"coins."+e}}if(n.memo!=null&&n.hasOwnProperty("memo")){if(!l.isString(n.memo))return"memo: string expected"}if(n.signer!=null&&n.hasOwnProperty("signer")){if(!(n.signer&&typeof n.signer.length==="number"||l.isString(n.signer)))return"signer: buffer expected"}return null},o.fromObject=function(n){if(n instanceof u.types.MsgDeposit)return n;let t=new u.types.MsgDeposit;if(n.coins){if(!Array.isArray(n.coins))throw TypeError(".types.MsgDeposit.coins: array expected");t.coins=[];for(let e=0;e<n.coins.length;++e){if(typeof n.coins[e]!=="object")throw TypeError(".types.MsgDeposit.coins: object expected");t.coins[e]=u.common.Coin.fromObject(n.coins[e])}}if(n.memo!=null)t.memo=String(n.memo);if(n.signer!=null){if(typeof n.signer==="string")l.base64.decode(n.signer,t.signer=l.newBuffer(l.base64.length(n.signer)),0);else if(n.signer.length)t.signer=n.signer}return t},o.toObject=function(n,t){if(!t)t={};let e={};if(t.arrays||t.defaults)e.coins=[];if(t.defaults){if(e.memo="",t.bytes===String)e.signer="";else if(e.signer=[],t.bytes!==Array)e.signer=l.newBuffer(e.signer)}if(n.coins?.length){e.coins=[];for(let s=0;s<n.coins.length;++s)e.coins[s]=u.common.Coin.toObject(n.coins[s],t)}if(n.memo!=null&&n.hasOwnProperty("memo"))e.memo=n.memo;if(n.signer!=null&&n.hasOwnProperty("signer"))e.signer=t.bytes===String?l.base64.encode(n.signer,0,n.signer.length):t.bytes===Array?Array.prototype.slice.call(n.signer):n.signer;return e},o.prototype.toJSON=function(){return this.constructor.toObject(this,T.util.toJSONOptions)},o})(),i.MsgSend=(()=>{function o(r){if(this.amount=[],r){for(let n=Object.keys(r),t=0;t<n.length;++t)if(r[n[t]]!=null)this[n[t]]=r[n[t]]}}return o.prototype.fromAddress=l.newBuffer([]),o.prototype.toAddress=l.newBuffer([]),o.prototype.amount=l.emptyArray,o.create=function(n){return new o(n)},o.encode=function(n,t){if(!t)t=v.create();if(n.fromAddress!=null&&Object.hasOwnProperty.call(n,"fromAddress"))t.uint32(10).bytes(n.fromAddress);if(n.toAddress!=null&&Object.hasOwnProperty.call(n,"toAddress"))t.uint32(18).bytes(n.toAddress);if(n.amount?.length)for(let e=0;e<n.amount.length;++e)u.cosmos.base.v1beta1.Coin.encode(n.amount[e],t.uint32(26).fork()).ldelim();return t},o.encodeDelimited=function(n,t){return this.encode(n,t).ldelim()},o.decode=function(n,t){if(!(n instanceof d))n=d.create(n);let e=t===void 0?n.len:n.pos+t,s=new u.types.MsgSend;while(n.pos<e){let c=n.uint32();switch(c>>>3){case 1:s.fromAddress=n.bytes();break;case 2:s.toAddress=n.bytes();break;case 3:if(!s.amount?.length)s.amount=[];s.amount.push(u.cosmos.base.v1beta1.Coin.decode(n,n.uint32()));break;default:n.skipType(c&7);break}}return s},o.decodeDelimited=function(n){if(!(n instanceof d))n=new d(n);return this.decode(n,n.uint32())},o.verify=function(n){if(typeof n!=="object"||n===null)return"object expected";if(n.fromAddress!=null&&n.hasOwnProperty("fromAddress")){if(!(n.fromAddress&&typeof n.fromAddress.length==="number"||l.isString(n.fromAddress)))return"fromAddress: buffer expected"}if(n.toAddress!=null&&n.hasOwnProperty("toAddress")){if(!(n.toAddress&&typeof n.toAddress.length==="number"||l.isString(n.toAddress)))return"toAddress: buffer expected"}if(n.amount!=null&&n.hasOwnProperty("amount")){if(!Array.isArray(n.amount))return"amount: array expected";for(let t=0;t<n.amount.length;++t){let e=u.cosmos.base.v1beta1.Coin.verify(n.amount[t]);if(e)return"amount."+e}}return null},o.fromObject=function(n){if(n instanceof u.types.MsgSend)return n;let t=new u.types.MsgSend;if(n.fromAddress!=null){if(typeof n.fromAddress==="string")l.base64.decode(n.fromAddress,t.fromAddress=l.newBuffer(l.base64.length(n.fromAddress)),0);else if(n.fromAddress.length)t.fromAddress=n.fromAddress}if(n.toAddress!=null){if(typeof n.toAddress==="string")l.base64.decode(n.toAddress,t.toAddress=l.newBuffer(l.base64.length(n.toAddress)),0);else if(n.toAddress.length)t.toAddress=n.toAddress}if(n.amount){if(!Array.isArray(n.amount))throw TypeError(".types.MsgSend.amount: array expected");t.amount=[];for(let e=0;e<n.amount.length;++e){if(typeof n.amount[e]!=="object")throw TypeError(".types.MsgSend.amount: object expected");t.amount[e]=u.cosmos.base.v1beta1.Coin.fromObject(n.amount[e])}}return t},o.toObject=function(n,t){if(!t)t={};let e={};if(t.arrays||t.defaults)e.amount=[];if(t.defaults){if(t.bytes===String)e.fromAddress="";else if(e.fromAddress=[],t.bytes!==Array)e.fromAddress=l.newBuffer(e.fromAddress);if(t.bytes===String)e.toAddress="";else if(e.toAddress=[],t.bytes!==Array)e.toAddress=l.newBuffer(e.toAddress)}if(n.fromAddress!=null&&n.hasOwnProperty("fromAddress"))e.fromAddress=t.bytes===String?l.base64.encode(n.fromAddress,0,n.fromAddress.length):t.bytes===Array?Array.prototype.slice.call(n.fromAddress):n.fromAddress;if(n.toAddress!=null&&n.hasOwnProperty("toAddress"))e.toAddress=t.bytes===String?l.base64.encode(n.toAddress,0,n.toAddress.length):t.bytes===Array?Array.prototype.slice.call(n.toAddress):n.toAddress;if(n.amount?.length){e.amount=[];for(let s=0;s<n.amount.length;++s)e.amount[s]=u.cosmos.base.v1beta1.Coin.toObject(n.amount[s],t)}return e},o.prototype.toJSON=function(){return this.constructor.toObject(this,T.util.toJSONOptions)},o})(),i})();u.cosmos=(()=>{let i={};return i.base=(()=>{let o={};return o.v1beta1=(()=>{let r={};return r.Coin=(()=>{function n(t){if(t){for(let e=Object.keys(t),s=0;s<e.length;++s)if(t[e[s]]!=null)this[e[s]]=t[e[s]]}}return n.prototype.denom="",n.prototype.amount="",n.create=function(e){return new n(e)},n.encode=function(e,s){if(!s)s=v.create();if(e.denom!=null&&Object.hasOwnProperty.call(e,"denom"))s.uint32(10).string(e.denom);if(e.amount!=null&&Object.hasOwnProperty.call(e,"amount"))s.uint32(18).string(e.amount);return s},n.encodeDelimited=function(e,s){return this.encode(e,s).ldelim()},n.decode=function(e,s){if(!(e instanceof d))e=d.create(e);let c=s===void 0?e.len:e.pos+s,a=new u.cosmos.base.v1beta1.Coin;while(e.pos<c){let p=e.uint32();switch(p>>>3){case 1:a.denom=e.string();break;case 2:a.amount=e.string();break;default:e.skipType(p&7);break}}return a},n.decodeDelimited=function(e){if(!(e instanceof d))e=new d(e);return this.decode(e,e.uint32())},n.verify=function(e){if(typeof e!=="object"||e===null)return"object expected";if(e.denom!=null&&e.hasOwnProperty("denom")){if(!l.isString(e.denom))return"denom: string expected"}if(e.amount!=null&&e.hasOwnProperty("amount")){if(!l.isString(e.amount))return"amount: string expected"}return null},n.fromObject=function(e){if(e instanceof u.cosmos.base.v1beta1.Coin)return e;let s=new u.cosmos.base.v1beta1.Coin;if(e.denom!=null)s.denom=String(e.denom);if(e.amount!=null)s.amount=String(e.amount);return s},n.toObject=function(e,s){if(!s)s={};let c={};if(s.defaults)c.denom="",c.amount="";if(e.denom!=null&&e.hasOwnProperty("denom"))c.denom=e.denom;if(e.amount!=null&&e.hasOwnProperty("amount"))c.amount=e.amount;return c},n.prototype.toJSON=function(){return this.constructor.toObject(this,T.util.toJSONOptions)},n})(),r.DecCoin=(()=>{function n(t){if(t){for(let e=Object.keys(t),s=0;s<e.length;++s)if(t[e[s]]!=null)this[e[s]]=t[e[s]]}}return n.prototype.denom="",n.prototype.amount="",n.create=function(e){return new n(e)},n.encode=function(e,s){if(!s)s=v.create();if(e.denom!=null&&Object.hasOwnProperty.call(e,"denom"))s.uint32(10).string(e.denom);if(e.amount!=null&&Object.hasOwnProperty.call(e,"amount"))s.uint32(18).string(e.amount);return s},n.encodeDelimited=function(e,s){return this.encode(e,s).ldelim()},n.decode=function(e,s){if(!(e instanceof d))e=d.create(e);let c=s===void 0?e.len:e.pos+s,a=new u.cosmos.base.v1beta1.DecCoin;while(e.pos<c){let p=e.uint32();switch(p>>>3){case 1:a.denom=e.string();break;case 2:a.amount=e.string();break;default:e.skipType(p&7);break}}return a},n.decodeDelimited=function(e){if(!(e instanceof d))e=new d(e);return this.decode(e,e.uint32())},n.verify=function(e){if(typeof e!=="object"||e===null)return"object expected";if(e.denom!=null&&e.hasOwnProperty("denom")){if(!l.isString(e.denom))return"denom: string expected"}if(e.amount!=null&&e.hasOwnProperty("amount")){if(!l.isString(e.amount))return"amount: string expected"}return null},n.fromObject=function(e){if(e instanceof u.cosmos.base.v1beta1.DecCoin)return e;let s=new u.cosmos.base.v1beta1.DecCoin;if(e.denom!=null)s.denom=String(e.denom);if(e.amount!=null)s.amount=String(e.amount);return s},n.toObject=function(e,s){if(!s)s={};let c={};if(s.defaults)c.denom="",c.amount="";if(e.denom!=null&&e.hasOwnProperty("denom"))c.denom=e.denom;if(e.amount!=null&&e.hasOwnProperty("amount"))c.amount=e.amount;return c},n.prototype.toJSON=function(){return this.constructor.toObject(this,T.util.toJSONOptions)},n})(),r.IntProto=(()=>{function n(t){if(t){for(let e=Object.keys(t),s=0;s<e.length;++s)if(t[e[s]]!=null)this[e[s]]=t[e[s]]}}return n.prototype.int="",n.create=function(e){return new n(e)},n.encode=function(e,s){if(!s)s=v.create();if(e.int!=null&&Object.hasOwnProperty.call(e,"int"))s.uint32(10).string(e.int);return s},n.encodeDelimited=function(e,s){return this.encode(e,s).ldelim()},n.decode=function(e,s){if(!(e instanceof d))e=d.create(e);let c=s===void 0?e.len:e.pos+s,a=new u.cosmos.base.v1beta1.IntProto;while(e.pos<c){let p=e.uint32();switch(p>>>3){case 1:a.int=e.string();break;default:e.skipType(p&7);break}}return a},n.decodeDelimited=function(e){if(!(e instanceof d))e=new d(e);return this.decode(e,e.uint32())},n.verify=function(e){if(typeof e!=="object"||e===null)return"object expected";if(e.int!=null&&e.hasOwnProperty("int")){if(!l.isString(e.int))return"int: string expected"}return null},n.fromObject=function(e){if(e instanceof u.cosmos.base.v1beta1.IntProto)return e;let s=new u.cosmos.base.v1beta1.IntProto;if(e.int!=null)s.int=String(e.int);return s},n.toObject=function(e,s){if(!s)s={};let c={};if(s.defaults)c.int="";if(e.int!=null&&e.hasOwnProperty("int"))c.int=e.int;return c},n.prototype.toJSON=function(){return this.constructor.toObject(this,T.util.toJSONOptions)},n})(),r.DecProto=(()=>{function n(t){if(t){for(let e=Object.keys(t),s=0;s<e.length;++s)if(t[e[s]]!=null)this[e[s]]=t[e[s]]}}return n.prototype.dec="",n.create=function(e){return new n(e)},n.encode=function(e,s){if(!s)s=v.create();if(e.dec!=null&&Object.hasOwnProperty.call(e,"dec"))s.uint32(10).string(e.dec);return s},n.encodeDelimited=function(e,s){return this.encode(e,s).ldelim()},n.decode=function(e,s){if(!(e instanceof d))e=d.create(e);let c=s===void 0?e.len:e.pos+s,a=new u.cosmos.base.v1beta1.DecProto;while(e.pos<c){let p=e.uint32();switch(p>>>3){case 1:a.dec=e.string();break;default:e.skipType(p&7);break}}return a},n.decodeDelimited=function(e){if(!(e instanceof d))e=new d(e);return this.decode(e,e.uint32())},n.verify=function(e){if(typeof e!=="object"||e===null)return"object expected";if(e.dec!=null&&e.hasOwnProperty("dec")){if(!l.isString(e.dec))return"dec: string expected"}return null},n.fromObject=function(e){if(e instanceof u.cosmos.base.v1beta1.DecProto)return e;let s=new u.cosmos.base.v1beta1.DecProto;if(e.dec!=null)s.dec=String(e.dec);return s},n.toObject=function(e,s){if(!s)s={};let c={};if(s.defaults)c.dec="";if(e.dec!=null&&e.hasOwnProperty("dec"))c.dec=e.dec;return c},n.prototype.toJSON=function(){return this.constructor.toObject(this,T.util.toJSONOptions)},n})(),r})(),o})(),i})();function pn(i){if(i instanceof Uint8Array)return i;if(typeof i==="string")return Uint8Array.from(globalThis.atob(i),(r)=>r.charCodeAt(0));throw TypeError("address must be Uint8Array or base64 string")}var Bt=(i)=>{let o=i;return u.types.MsgSend.encode({amount:o.amount,fromAddress:pn(o.fromAddress),toAddress:pn(o.toAddress)}).finish()},Ft=(i)=>{let o=i;return u.types.MsgDeposit.encode({coins:o.coins.map((r)=>({amount:r.amount,asset:r.asset})),memo:o.memo,signer:pn(o.signer)}).finish()};function H(){return{...Ut,"/types.MsgDeposit":Ft,"/types.MsgSend":Bt}}function I(i,o=i===Kn.THORChain?"thor":"maya"){let r=i===Kn.THORChain?"thorchain":"mayachain",n={"/types.MsgDeposit":{aminoType:`${r}/MsgDeposit`,fromAmino:({signer:t,...e})=>({...e,signer:z(t)}),toAmino:({signer:t,...e})=>({...e,signer:typeof t==="string"?X(t,o):t})},"/types.MsgSend":{aminoType:`${r}/MsgSend`,fromAmino:({from_address:t,to_address:e,...s})=>({...s,fromAddress:z(t),toAddress:z(e)}),toAmino:({fromAddress:t,toAddress:e,...s})=>({...s,from_address:typeof t==="string"?X(t,o):t,to_address:typeof e==="string"?X(e,o):e})}};return Object.assign(n,{fromAmino(t){let e=Object.entries(n).find(([,a])=>a.aminoType===t.type);if(!e)throw TypeError(`No converter for amino type ${t.type}`);let[s,c]=e;return{typeUrl:s,value:c.fromAmino(t.value)}},toAmino(t){let e=n[t.typeUrl];if(!e)throw TypeError(`No converter for type URL ${t.typeUrl}`);return{type:e.aminoType,value:e.toAmino(t.value)}}})}var Ge=_(tn.THORChain).gas,Ye=_(tn.Maya).gas,jn=({sender:i,recipient:o,assetValue:r})=>({type:`${r.chain===tn.Maya?"mayachain":"thorchain"}/MsgSend`,value:{amount:[{amount:r.getBaseValue("string"),denom:U(r.symbol,!0)}],from_address:i,to_address:o}}),En=({sender:i,assetValue:o,memo:r=""})=>({type:`${o.chain===tn.Maya?"mayachain":"thorchain"}/MsgDeposit`,value:{coins:[{amount:o.getBaseValue("string"),asset:nn(o)}],memo:r,signer:i}}),hn=({sender:i,recipient:o,assetValue:r,memo:n})=>!o?En({assetValue:r,memo:n,sender:i}):jn({assetValue:r,recipient:o,sender:i});function Hn(i,o){for(let r of["/types.MsgDeposit","/types.MsgSend"]){let n=i[r];if(n.aminoType===o)return{fromAmino:n.fromAmino,typeUrl:r}}return null}var R=(i,o)=>{let r=I(o),n=Hn(r,i.type);if(!n)throw new gn("toolbox_cosmos_invalid_params",{error:`No converter for amino type ${i.type}`});return{typeUrl:n.typeUrl,value:n.fromAmino(i.value)}},Jn=async({rpcUrl:i,sender:o})=>{let n=await(await N(i)).getAccount(o);if(!n)throw new gn("toolbox_cosmos_account_not_found",{sender:o});return n};async function $n(i){let{assetValue:o,recipient:r,memo:n,sender:t,asSignable:e,asAminoMessage:s,sequence:c,accountNumber:a}=i,p=i.sweep?await bn({assetValue:o,sender:t}):o;if(r)return Lt({accountNumber:a,asAminoMessage:s,asSignable:e,assetValue:p,memo:n,recipient:r,sender:t,sequence:c});return jt({accountNumber:a,asAminoMessage:s,asSignable:e,assetValue:p,memo:n,sender:t,sequence:c})}async function bn({assetValue:i,sender:o}){let r=i.chain,n=await yn(r),e=await(await N(n)).getAllBalances(o),s=i.isGasAsset?(await Z(r)).getBaseValue("bigint"):0n;return W({assetValue:i,balances:e,denom:U(i.symbol,!0),feeAmount:s})}async function Lt({sender:i,recipient:o,assetValue:r,memo:n="",asSignable:t=!0,asAminoMessage:e=!1,sequence:s,accountNumber:c}){let a=r.chain,p=c!==void 0&&s!==void 0?void 0:await Jn({rpcUrl:await yn(a),sender:i}),{chainId:h}=Ln(a),w=jn({assetValue:r,recipient:o,sender:i}),C=t?R(e?w:K(w),a):w;return{accountNumber:c??Number(p?.accountNumber),chainId:h,fee:_(a),memo:n,msgs:[C],sequence:s??Number(p?.sequence)}}async function jt({sender:i,assetValue:o,memo:r="",asSignable:n=!0,asAminoMessage:t=!1,sequence:e,accountNumber:s}){let c=o.chain,a=s!==void 0&&e!==void 0?void 0:await Jn({rpcUrl:await yn(c),sender:i}),{chainId:p}=Ln(c),h=En({assetValue:o,memo:r,sender:i}),w=n?R(t?h:K(h),c):h;return{accountNumber:s??Number(a?.accountNumber),chainId:p,fee:_(c),memo:r,msgs:[w],sequence:e??Number(a?.sequence)}}function K(i){if(i.type==="thorchain/MsgSend"||i.type==="mayachain/MsgSend")return i;return{...i,value:{...i.value,coins:i.value.coins.map((o)=>{let r=Kt.from({asset:o.asset}),n=(r.isSynthetic?r.symbol.split("/")?.[1]:r.symbol)?.toUpperCase(),t=(r.isSynthetic?r.symbol.split("/")?.[0]:r.chain)?.toUpperCase();return{...o,asset:{chain:t,symbol:n,synth:r.isSynthetic,ticker:r.ticker}}})}}}function en({chain:i,memo:o,msgs:r}){let n=H(),t=I(i),s=r.map((c)=>{let a=Hn(t,c.type);if(!a)throw new gn("toolbox_cosmos_invalid_params",{error:`No converter for amino type ${c.type}`});return{typeUrl:a.typeUrl,value:a.fromAmino(c.value)}}).map((c)=>It(c,n));return Rt({memo:o,messages:s})}import{Chain as V,SwapKitError as ke}from"@swapkit/helpers";import{secp256k1 as Et}from"@noble/curves/secp256k1.js";import{base64 as Cn,bech32 as An}from"@scure/base";import{HDKey as Ht}from"@scure/bip32";import{verifySignature as Jt,createWalletFromMnemonic as $t,createWalletFromPrivateKey as Wt,mnemonicToSeed as qt,signDirect as Vt}from"@swapkit/cosmos-signer";import{AssetValue as On,applyFeeMultiplier as Wn,Chain as x,CosmosChainPrefixes as Xn,DerivationPath as Gt,derivationPathToString as qn,FeeOption as Tn,getChainConfig as Yt,getRPCUrl as q,NetworkDerivationPath as zt,SwapKitError as B,SwapKitNumber as wn,updateDerivationPath as Xt}from"@swapkit/helpers";import{SwapKitApi as Qn}from"@swapkit/helpers/api";import{PubKey as Qt}from"cosmjs-types/cosmos/crypto/secp256k1/keys";import{match as Zt,P as Vn}from"ts-pattern";async function Zn(i,o){try{let n=(await Qn.getGasRate()).find((t)=>t.chainId===i)?.value;return n?Number.parseFloat(n):o}catch{return o}}function nt(i){let o=[{address:i.address,algo:"secp256k1",pubkey:i.publicKey}];return{getAccounts:()=>Promise.resolve(o),async signDirect(r,n){if(r!==i.address)throw new B("toolbox_cosmos_signer_not_defined");let t=await Vt(i.privateKey,i.publicKey,{accountNumber:n.accountNumber,authInfoBytes:n.authInfoBytes,bodyBytes:n.bodyBytes,chainId:n.chainId});return{signature:t.signature,signed:{accountNumber:t.signed.accountNumber,authInfoBytes:t.signed.authInfoBytes,bodyBytes:t.signed.bodyBytes,chainId:t.signed.chainId}}}}}async function Gn({phrase:i,prefix:o,...r}){let n="derivationPath"in r?r.derivationPath:`${Gt[r.chain]}/${r.index??0}`,t=await $t({hdPath:n,mnemonic:i,prefix:o??""});return nt(t)}async function ne({privateKey:i,prefix:o}){let r=Wt({prefix:o,privateKey:i});return nt(r)}var Yn={[x.Cosmos]:1000,[x.Kujira]:1000,[x.Noble]:1000,[x.THORChain]:5000000,[x.Maya]:5000000,[x.Harbor]:5000000};function te(i){return async function({signature:r,message:n,address:t}){let e=await i(t);if(!e?.pubkey)throw new B("toolbox_cosmos_verify_signature_no_pubkey");let s=e.pubkey.type==="/cosmos.crypto.secp256k1.PubKey"?Qt.decode(e.pubkey.value).key:e.pubkey.value;return Jt(Cn.decode(n),Cn.decode(r),s)}}function on({chain:i,...o}){let r=Xn[i],n="index"in o?o.index||0:0,t=qn("derivationPath"in o&&o.derivationPath?o.derivationPath:Xt(zt[i],{index:n})),e;async function s(){if(e)return e;return e=await Zt(o).with({phrase:Vn.string},({phrase:m})=>Gn({derivationPath:t,phrase:m,prefix:r})).with({signer:Vn.any},({signer:m})=>m).otherwise(()=>{return}),e}async function c(m){let y=await q(i);return(await N(y)).getAccount(m)}async function a(){let m=await s(),[y]=await m?.getAccounts()||[];return y?.address}async function p(){let m=await s(),[y]=await m?.getAccounts()||[];if(!y?.pubkey)throw new B("toolbox_cosmos_signer_not_defined");return Cn.encode(y?.pubkey)}async function h(m){let y=await s(),f=await a(),g=await q(i);if(!(y&&f))throw new B("toolbox_cosmos_signer_not_defined");return(await E(g,y)).sign(f,m.msgs,m.fee,m.memo,{accountNumber:BigInt(m.accountNumber),chainId:m.chainId,sequence:m.sequence})}async function w(m){let y=await s(),f=await a(),g=await q(i);if(!(y&&f))throw new B("toolbox_cosmos_signer_not_defined");let S=await(await E(g,y)).signAndBroadcast(f,m.msgs,m.fee,m.memo);if(S.code!==0)throw new B("core_swap_transaction_error",{code:S.code,message:S.rawLog});return S.transactionHash}async function C({recipient:m,assetValue:y,memo:f="",feeRate:g,feeOptionKey:A=Tn.Fast,sweep:S}){let O=await s(),D=await a();if(!(O&&D))throw new B("toolbox_cosmos_signer_not_defined");let k=await q(i),rn=On.from({chain:i}),sn=nn(rn),j=ee(g||(await zn(i,Yn[i]))[A],sn,i),cn=await E(k,O),J=U(y.symbol),an=[{amount:(S?W({assetValue:y,balances:await Sn(i)(D),denom:J,feeAmount:mn(j.amount,J)}):y).getBaseValue("string"),denom:J}],{transactionHash:un}=await cn.sendTokens(D,m,an,j,f);return un}return{createPrivateKeyFromPhrase:re(t),createTransaction:In,fetchFeeRateFromSwapKit:Zn,getAccount:c,getAddress:a,getBalance:async(m,y)=>{let f=await Sn(i)(m),g=await Promise.all(f.filter(({denom:A})=>A&&!A.includes("IBC/")&&!([x.THORChain,x.Maya].includes(i)&&A.split("-").length>2)).map(({denom:A,amount:S})=>{let O=[x.THORChain,x.Maya].includes(i)&&(A.includes("/")||A.includes("˜"))?`${i}.${A}`:A;return Rn(O,S)}));if(g.length===0)return[On.from({chain:i})];return g},getBalanceAsDenoms:Sn(i),getFees:()=>zn(i,Yn[i]),getPubKey:p,getSignerFromPhrase:({phrase:m,derivationPath:y})=>Gn({derivationPath:qn(y),index:n,phrase:m,prefix:r}),getSignerFromPrivateKey:(m)=>ne({prefix:r,privateKey:m}),signAndBroadcastTransaction:w,signTransaction:h,transfer:C,validateAddress:ie(i),verifySignature:te(c)}}async function mo(i,o){try{let n=(await Qn.getGasRate()).find((t)=>t.chainId===i)?.value;return n?Number.parseFloat(n):o}catch{return o}}function po({assetValue:{chain:i}}){return On.from({chain:i,value:oe(i)})}async function zn(i,o){let{chainId:r,baseDecimal:n}=Yt(i),t=await Zn(r,o);return{average:wn.fromBigInt(BigInt(t),n),fast:wn.fromBigInt(BigInt(Wn(t,Tn.Fast,!0)),n),fastest:wn.fromBigInt(BigInt(Wn(t,Tn.Fastest,!0)),n)}}function ee(i,o,r){return{amount:[{amount:typeof i==="number"?i.toString():i.getBaseValue("string"),denom:o}],gas:_(r).gas}}function oe(i){return{[x.Cosmos]:0.007,[x.Kujira]:0.02,[x.Noble]:0.01,[x.THORChain]:0.02,[x.Maya]:0.02,[x.Harbor]:0.02}[i]||0}function ie(i){let o=Xn[i];return function(n){if(!n.startsWith(o))return!1;try{let{prefix:t,words:e}=An.decode(n);return An.encode(t,e)===n.toLocaleLowerCase()}catch{return!1}}}function Sn(i){return async function(r){let n=await q(i);return(await(await N(n)).getAllBalances(r)).map((c)=>({...c,denom:c.denom.includes("/")?c.denom.toUpperCase():c.denom}))}}function re(i){return async function(r){let n=await qt(r),e=Ht.fromMasterSeed(n).derive(i);if(!e.privateKey)throw new B("toolbox_cosmos_invalid_params",{error:"HDKey derivation produced no private key"});return Et.getPublicKey(e.privateKey,!0),Uint8Array.from(e.privateKey)}}import{secp256k1 as se}from"@noble/curves/secp256k1.js";import{base64 as F}from"@scure/base";import{buildMultisignedTx as ce,createMultisigThresholdPubkey as ae,signAmino as ue,createWalletFromMnemonic as le,encodeTxRaw as fe,multisigPubkeyToAddress as de,singlePubkeyToAddress as et}from"@swapkit/cosmos-signer";import{CosmosChainPrefixes as me,derivationPathToString as pe,FeeOption as xn,getRPCUrl as ot,NetworkDerivationPath as ye,SKConfig as ge,SwapKitError as L,updateDerivationPath as he}from"@swapkit/helpers";import{match as be,P as tt}from"ts-pattern";function Ae(i){let o=[{address:i.address,algo:"secp256k1",pubkey:i.publicKey}];return{accounts:o,getAccounts:()=>Promise.resolve(o),async signAmino(r,n){if(r!==i.address)throw new L("toolbox_cosmos_signer_not_defined");let t=await ue(i.privateKey,i.publicKey,{signDoc:n});return{signature:t.signature,signed:t.signed}}}}function we({prefix:i,derivationPath:o}){return async function(n,t=0){let e=await le({hdPath:`${o}/${t}`,mnemonic:n,prefix:i});return Ae(e)}}function Se(i){return F.encode(i)}function Ce(i,o){return async function({wallet:n,tx:t}){let{msgs:e,accountNumber:s,sequence:c,chainId:a,fee:p,memo:h}=typeof t==="string"?JSON.parse(t):t,w=(await n.getAccounts())?.[0]?.address||"",C=I(i,o),m=H(),y=await Fn(n,{aminoTypes:C,registry:m}),f=[];for(let S of e){let O=R(S,i);f.push(O)}let{signatures:[g]}=await y.sign(w,f,p,h,{accountNumber:BigInt(s),chainId:a,sequence:c});return{bodyBytes:en({chain:i,memo:h,msgs:e.map(K)}),signature:Se(g)}}}function it(i){if(i.length!==33||i[0]!==2&&i[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:F.encode(i)}}function Oe({prefix:i,chain:o}){return async function(n,t,e,s,c){let a=await ot(o),{sequence:p,fee:h}=JSON.parse(n),w=rt(e,s),C=t.map((f)=>[et(it(F.decode(f.pubKey)),i),F.decode(f.signature)]),m=await N(a),{transactionHash:y}=await m.broadcastTx(ce({bodyBytes:c,fee:{amount:h.amount,gasLimit:BigInt(h.gas),...h.payer?{payer:h.payer}:{},...h.granter?{granter:h.granter}:{}},multisigPubkey:w,prefix:i,sequence:p,signatures:new Map(C)}));return y}}function rt(i,o,r=!0){return ae(i.map((n)=>it(F.decode(n))),o,r)}function Te(i){return F.decode(i)}function xe({privateKey:i,message:o}){let r=se.sign(F.decode(o),i,{lowS:!0,prehash:!1});return Promise.resolve(F.encode(r))}function st({chain:i,...o}){let{isStagenet:r}=ge.get("envs"),n=`${r?"s":""}${me[i]}`,t="index"in o?o.index||0:0,e="derivationPath"in o&&o.derivationPath?o.derivationPath:he(ye[i],{index:t}),s=on({chain:i,...o}),c=_(i),a;function p(){return a??=be(o).with({phrase:tt.string},({phrase:f})=>s.getSignerFromPhrase({derivationPath:e,phrase:f})).with({signer:tt.any},({signer:f})=>Promise.resolve(f)).otherwise(()=>Promise.resolve(void 0)),a}async function h(){let f=await ot(i),g=await p();if(!g)throw new L("toolbox_cosmos_no_signer");let A=H(),S=I(i,n),O=await E(f,g,{aminoTypes:S,registry:A});return{signer:g,signingClient:O}}async function w({fee:f,memo:g,msgs:A}){let{signer:S,signingClient:O}=await h(),D=(await S.getAccounts())?.[0]?.address;if(!D)throw new L("toolbox_cosmos_signer_not_defined");let k=await O.signAndBroadcast(D,A,f,g);if(k.code!==0)throw new L("core_swap_transaction_error",{code:k.code,message:k.rawLog});return k.transactionHash}async function C(){let f=await Z(i);return{[xn.Average]:f,[xn.Fast]:f,[xn.Fastest]:f}}async function m({assetValue:f,memo:g="",recipient:A,sweep:S}){let{signer:O,signingClient:D}=await h(),k=(await O.getAccounts())?.[0]?.address;if(!k)throw new L("toolbox_cosmos_no_signer");let rn="signAmino"in O,sn=S?await bn({assetValue:f,sender:k}):f,j=hn({assetValue:sn,memo:g,recipient:A,sender:k});if(rn){let kn=R(j,i),{signatures:an,authInfoBytes:un}=await D.sign(k,[kn],c,g),ct=fe({authInfoBytes:un,bodyBytes:en({chain:i,memo:g,msgs:[j].map(K)}),signatures:an});return(await D.broadcastTx(ct)).transactionHash}let cn=K(j),J=R(cn,i);return w({fee:c,memo:g,msgs:[J]})}async function y(f){let{signer:g,signingClient:A}=await h(),S=(await g.getAccounts())?.[0]?.address;if(!S)throw new L("toolbox_cosmos_signer_not_defined");return A.sign(S,f.msgs,f.fee,f.memo,{accountNumber:BigInt(f.accountNumber),chainId:f.chainId,sequence:f.sequence})}return{...s,broadcastMultisigTx:Oe({chain:i,prefix:n}),buildAminoMsg:hn,buildEncodedTxBody:en,convertToSignable:R,createDefaultAminoTypes:()=>I(i,n),createDefaultRegistry:H,createMultisig:rt,createTransaction:$n,deposit:m,getFees:C,importSignature:Te,parseAminoMessageForDirectSigning:K,pubkeyToAddress:(f)=>{if(f.type==="tendermint/PubKeyMultisigThreshold")return de(f,n);return et(f,n)},secp256k1HdWalletFromMnemonic:we({derivationPath:pe(e),prefix:n}),signAndBroadcastTransaction:w,signMultisigTx:Ce(i,n),signTransaction:y,signWithPrivateKey:xe,transfer:m}}var vo=(i,o)=>{switch(i){case V.Cosmos:case V.Kujira:case V.Noble:return on({chain:i,...o});case V.Maya:case V.THORChain:return st({chain:i,...o});default:throw new ke("toolbox_cosmos_not_supported",{chain:i})}};export{At as DEFAULT_COSMOS_FEE_MAINNET,wt as DEFAULT_KUJI_FEE_MAINNET,St as DEFAULT_NOBLE_FEE_MAINNET,Ye as MAYA_GAS_VALUE,Ge as THORCHAIN_GAS_VALUE,_n as USK_KUJIRA_FACTORY_DENOM,bt as YUM_KUJIRA_FACTORY_DENOM,X as base64ToBech32,z as bech32ToBase64,hn as buildAminoMsg,jt as buildDepositTx,en as buildEncodedTxBody,Lt as buildTransferTx,R as convertToSignable,In as cosmosCreateTransaction,on as createCosmosToolbox,I as createDefaultAminoTypes,H as createDefaultRegistry,Fn as createOfflineStargateClient,E as createSigningStargateClient,N as createStargateClient,st as createThorchainToolbox,$n as createTransaction,En as depositMsgAmino,po as estimateTransactionFee,Zn as fetchFeeRateFromSwapKit,_e as fromBase64,Rn as getAssetFromDenom,ie as getCosmosAddressValidator,vo as getCosmosToolbox,_ as getDefaultChainFee,nn as getDenomWithChain,mn as getFeeAmountForDenom,mo as getFeeRateFromSwapKit,U as getMsgSendDenom,Gn as getSignerFromPhrase,ne as getSignerFromPrivateKey,W as getSweepAssetValue,Z as getThorchainNativeFee,K as parseAminoMessageForDirectSigning,bn as resolveThorchainSweepAssetValue,Me as toBase64,jn as transferMsgAmino,te as verifySignature};
|
|
1
|
+
import"../../chunk-4428244x.js";import{base64 as Y,bech32 as G}from"@scure/base";import{SwapKitError as at}from"@swapkit/helpers";function z(i){return Y.encode(Uint8Array.from(G.fromWords(G.decode(i).words)))}function X(i,o="thor"){return G.encode(o,G.toWords(Y.decode(i)))}function Me(i){return Y.encode(i)}function _e(i){if(!i.match(/^[a-zA-Z0-9+/]*={0,2}$/))throw new at("toolbox_cosmos_invalid_params",{error:"Invalid base64 string format"});return Y.decode(i)}import{encodeMessage as It,encodeTxBody as Rt}from"@swapkit/cosmos-signer";import{AssetValue as Kt,Chain as tn,getChainConfig as Ln,getRPCUrl as yn,SwapKitError as gn}from"@swapkit/helpers";import{base64 as ln}from"@scure/base";import{broadcastTx as Q,getAccount as Mn,getBalances as ut,createTendermintRpc as lt,defaultEncoders as ft,encodeAuthInfo as Pn,encodeMessage as dt,encodePubkey as mt,encodeTxBody as pt,encodeTxRaw as vn,makeStdSignDoc as yt}from"@swapkit/cosmos-signer";import{AssetValue as fn,Chain as b,getChainConfig as M,getRPCUrl as gt,RequestClient as ht,SKConfig as Dn,SwapKitError as P,SwapKitNumber as dn}from"@swapkit/helpers";var _n="FACTORY/KUJIRA1QK00H5ATUTPSV900X202PXX42NPJR9THG58DNQPA72F2P7M2LUASE444A7/UUSK",bt="FACTORY/KUJIRA1YGFXN0ER40KLCNCK8THLTUPRDXLCK6WVNPKF2K/UYUM",At={amount:[{amount:"500",denom:"uatom"}],gas:"200000"},wt={amount:[{amount:"1000",denom:"ukuji"}],gas:"200000"},St={amount:[{amount:"1000",denom:"uusdc"}],gas:"200000"};function _(i){switch(i){case b.Maya:return{amount:[],gas:"10000000000"};case b.THORChain:return{amount:[],gas:"500000000"};case b.Kujira:return wt;case b.Noble:return St;default:return At}}async function Z(i){let{isStagenet:o}=Dn.get("envs"),r=Dn.get("thornodeUrls"),n=i===b.Maya,e=`${n?o?r.MAYA_STAGENET:r.MAYA:o?r.THOR_STAGENET:r.THOR}/${n?"mayachain":"thorchain"}/constants`,s=M(i).baseDecimal;try{let{int_64_values:{NativeTransactionFee:c}}=await ht.get(e);if(!Number.isInteger(c)||c<=0)throw new P("toolbox_cosmos_invalid_fee",{nativeFee:c.toString()});return dn.fromBigInt(BigInt(c),s)}catch{let c=n?10000000000n:2000000n;return dn.fromBigInt(c,s)}}var U=(i,o=!1)=>{if(o)return i.toLowerCase();switch(i){case"uUSK":case"USK":return _n;case"uYUM":case"YUM":return bt;case"uKUJI":case"KUJI":return"ukuji";case"ATOM":case"uATOM":return"uatom";case"uUSDC":case"USDC":case"NOBLE":return"uusdc";default:return i}},nn=({symbol:i,chain:o})=>{if(o===b.Maya)return(i.toUpperCase()!=="CACAO"?i:`${b.Maya}.${i}`).toUpperCase();if(o===b.THORChain)return(["RUNE","TCY","RUJI"].includes(i.toUpperCase())?`${b.THORChain}.${i}`:i).toUpperCase();return U(i,!1)},Ct=()=>typeof window<"u"?{}:{referer:"https://sdk.swapkit.dev",referrer:"https://sdk.swapkit.dev"};function Nn(i){return lt(i,{headers:Ct()})}function Un(i){return{amount:i.amount,denom:i.denom}}function Ot(i,o){if(!i)return null;if("toAmino"in i&&typeof i.toAmino==="function")return null;let n=i[o];return n?{aminoType:n.aminoType,toAmino:n.toAmino}:null}async function N(i){let o=Nn(i);return{async broadcastTx(r){let n=await Q(o,r,"sync");if(n.code!==0)throw new P("core_swap_transaction_error",{code:n.code,message:n.log});return{code:n.code,rawLog:n.log,transactionHash:n.hash}},async getAccount(r){let n=await Mn(o,r);if(!n)return null;return{accountNumber:Number(n.accountNumber),address:n.address,pubkey:n.pubKey?{type:n.pubKey.typeUrl,value:n.pubKey.key}:null,sequence:Number(n.sequence)}},async getAllBalances(r){return(await ut(o,r)).map((t)=>({amount:t.amount,denom:t.denom}))}}}function Bn(i,o={}){let r=Tt(i);async function n(t,e,s,c,a){let h=(await i.getAccounts()).find((g)=>g.address===t);if(!h)throw new P("toolbox_cosmos_signer_not_defined");let w=Dt({memo:c,messages:e,registry:o.registry}),C=mt({type:"tendermint/PubKeySecp256k1",value:ln.encode(h.pubkey)});if(r){let g=e.map((k)=>vt(k,o.aminoTypes)),A=yt({accountNumber:a.accountNumber,chainId:a.chainId,fee:xt(s),memo:c,msgs:g,sequence:a.sequence}),S=await i.signAmino(t,A),O=Pn({fee:Pt(S.signed.fee,s),signerInfos:[{mode:"amino",pubkey:C,sequence:BigInt(S.signed.sequence)}]}),D=ln.decode(S.signature.signature);return{authInfoBytes:O,bodyBytes:w,signatures:[D]}}let m=Pn({fee:kt(s),signerInfos:[{mode:"direct",pubkey:C,sequence:BigInt(a.sequence)}]}),y=await i.signDirect(t,{accountNumber:a.accountNumber,authInfoBytes:m,bodyBytes:w,chainId:a.chainId}),f=ln.decode(y.signature.signature);return{authInfoBytes:m,bodyBytes:w,signatures:[f]}}return{signWithRegistry:n}}function Tt(i){return typeof i.signAmino==="function"}function xt(i){return{amount:i.amount.map((o)=>({amount:o.amount,denom:o.denom})),gas:i.gas,...i.granter?{granter:i.granter}:{},...i.payer?{payer:i.payer}:{}}}function kt(i){return{amount:i.amount.map(Un),gasLimit:BigInt(i.gas),...i.granter?{granter:i.granter}:{},...i.payer?{payer:i.payer}:{}}}function Pt(i,o){return{amount:i.amount.map(Un),gasLimit:BigInt(i.gas),...i.granter??o.granter?{granter:i.granter??o.granter}:{},...i.payer??o.payer?{payer:i.payer??o.payer}:{}}}function vt(i,o){if(o&&"toAmino"in o&&typeof o.toAmino==="function")return o.toAmino(i);let r=Ot(o,i.typeUrl);if(!r){if(i.typeUrl==="/cosmos.bank.v1beta1.MsgSend"){let n=i.value;return{type:"cosmos-sdk/MsgSend",value:{amount:n.amount,from_address:n.fromAddress,to_address:n.toAddress}}}throw new P("toolbox_cosmos_invalid_params",{error:`No amino converter for ${i.typeUrl}`})}return{type:r.aminoType,value:r.toAmino(i.value)}}function Dt(i){let{memo:o,messages:r,registry:n}=i;if(n&&"encode"in n&&typeof n.encode==="function")return n.encode({typeUrl:"/cosmos.tx.v1beta1.TxBody",value:{memo:o,messages:r}});let t={...ft,...n??{}},e=r.map((s)=>dt(s,t));return pt({memo:o,messages:e})}async function E(i,o,r={}){let n=typeof r==="string"?{}:r,t=Nn(i),e=Bn(o,n);async function s(c,a){let p=await Mn(t,c);if(!p)throw new P("toolbox_cosmos_account_not_found",{sender:c});let h=a?.chainId??(await t.status()).chainId;return{accountNumber:a?.accountNumber??p.accountNumber,chainId:h,sequence:a?.sequence??p.sequence}}return{async broadcastTx(c){let a=await Q(t,c,"sync");if(a.code!==0)throw new P("core_swap_transaction_error",{code:a.code,message:a.log});return{code:a.code,rawLog:a.log,transactionHash:a.hash}},async sendTokens(c,a,p,h,w=""){let C=[{typeUrl:"/cosmos.bank.v1beta1.MsgSend",value:{amount:p.map((A)=>({amount:A.amount,denom:A.denom})),fromAddress:c,toAddress:a}}],m=await s(c),y=await e.signWithRegistry(c,C,h,w,m),f=vn({authInfoBytes:y.authInfoBytes,bodyBytes:y.bodyBytes,signatures:y.signatures}),g=await Q(t,f,"sync");if(g.code!==0)throw new P("core_swap_transaction_error",{code:g.code,message:g.log});return{code:g.code,rawLog:g.log,transactionHash:g.hash}},async sign(c,a,p,h,w){let C=w??await s(c);return e.signWithRegistry(c,a,p,h,C)},async signAndBroadcast(c,a,p,h=""){let w=await s(c),C=await e.signWithRegistry(c,a,p,h,w),m=vn({authInfoBytes:C.authInfoBytes,bodyBytes:C.bodyBytes,signatures:C.signatures}),y=await Q(t,m,"sync");return{code:y.code,rawLog:y.log,transactionHash:y.hash}}}}async function Fn(i,o){let r=Bn(i,o??{});return{sign(n,t,e,s,c){if(!c)throw new P("toolbox_cosmos_invalid_params",{error:"createOfflineStargateClient.sign requires signerData"});return r.signWithRegistry(n,t,e,s,c)}}}var Mt=(i)=>{switch(i){case b.Maya:case b.THORChain:return"/types.MsgSend";case b.Cosmos:case b.Kujira:case b.Noble:return"/cosmos.bank.v1beta1.MsgSend";default:throw new P("toolbox_cosmos_not_supported",{chain:i})}};async function _t({client:i,sender:o}){let r=await i.getAccount(o);if(!r)throw new P("toolbox_cosmos_account_not_found",{sender:o});return r}async function In({sender:i,recipient:o,assetValue:r,memo:n="",feeRate:t,sequence:e,accountNumber:s,sweep:c}){let{chain:a,chainId:p}=r,h=s===void 0||e===void 0,w=c||h?await N(await gt(a)):void 0,C=h&&w?await _t({client:w,sender:i}):void 0,m=fn.from({chain:a}),y=U(m.symbol),f=_(a),g=y&&t?{amount:[{amount:t.toString(),denom:y}],gas:f.gas}:f,A=U(r.symbol),S=r;if(c){if(!w)throw new P("toolbox_cosmos_account_not_found",{sender:i});S=W({assetValue:r,balances:await w.getAllBalances(i),denom:A,feeAmount:mn(g.amount,A)})}let O={amount:[{amount:S.getBaseValue("string"),denom:A}],fromAddress:i,toAddress:o};return{accountNumber:s??Number(C?.accountNumber),chainId:p,fee:g,memo:n,msgs:[{typeUrl:Mt(a),value:O}],sequence:e??Number(C?.sequence)}}function mn(i,o){let r=o.toLowerCase();return i.reduce((n,t)=>t.denom.toLowerCase()===r?n+BigInt(t.amount):n,0n)}function W({assetValue:i,balances:o,denom:r,feeAmount:n=0n}){let t=r.toLowerCase(),e=o.find(({denom:a})=>a.toLowerCase()===t),s=BigInt(e?.amount??"0"),c=s-n;if(c<=0n)throw new P("toolbox_sweep_amount_too_low",{asset:i.toString(),balance:s.toString(),fee:n.toString()});return i.set(dn.fromBigInt(c,i.decimal))}var Nt={atom:{chain:b.Cosmos,decimals:M(b.Cosmos).baseDecimal},cacao:{chain:b.Maya,decimals:10},kuji:{chain:b.Kujira,decimals:M(b.Kujira).baseDecimal},maya:{asset:`${b.Maya}.${b.Maya}`,decimals:4},rune:{chain:b.THORChain,decimals:M(b.THORChain).baseDecimal},tcy:{asset:"THOR.TCY",decimals:M(b.THORChain).baseDecimal},uatom:{chain:b.Cosmos,decimals:M(b.Cosmos).baseDecimal},ukuji:{chain:b.Kujira,decimals:M(b.Kujira).baseDecimal},usdc:{chain:b.Noble,decimals:M(b.Noble).baseDecimal},uusdc:{chain:b.Noble,decimals:M(b.Noble).baseDecimal},"x/kuji":{asset:"THOR.KUJI",decimals:M(b.THORChain).baseDecimal},[_n.toLowerCase()]:{asset:`${b.Kujira}.USK`,decimals:M(b.Kujira).baseDecimal}},Rn=(i,o)=>{let r=Nt[i.toLowerCase()];if(!r)return fn.from({asset:i,fromBaseDecimal:8,value:o});let{chain:n,asset:t,decimals:e}=r,s=n?{chain:n}:{asset:t};return fn.from({...s,fromBaseDecimal:e,value:o})};import{defaultEncoders as Ut}from"@swapkit/cosmos-signer";import{Chain as Kn}from"@swapkit/helpers";import T from"protobufjs/minimal.js";var d=T.Reader,v=T.Writer,l=T.util,u=T.roots.default||(T.roots.default={});u.common=(()=>{let i={};return i.Asset=(()=>{function o(r){if(r){for(let n=Object.keys(r),t=0;t<n.length;++t)if(r[n[t]]!=null)this[n[t]]=r[n[t]]}}return o.prototype.chain="",o.prototype.symbol="",o.prototype.ticker="",o.prototype.synth=!1,o.create=function(n){return new o(n)},o.encode=function(n,t){if(!t)t=v.create();if(n.chain!=null&&Object.hasOwnProperty.call(n,"chain"))t.uint32(10).string(n.chain);if(n.symbol!=null&&Object.hasOwnProperty.call(n,"symbol"))t.uint32(18).string(n.symbol);if(n.ticker!=null&&Object.hasOwnProperty.call(n,"ticker"))t.uint32(26).string(n.ticker);if(n.synth!=null&&Object.hasOwnProperty.call(n,"synth"))t.uint32(32).bool(n.synth);return t},o.encodeDelimited=function(n,t){return this.encode(n,t).ldelim()},o.decode=function(n,t){if(!(n instanceof d))n=d.create(n);let e=t===void 0?n.len:n.pos+t,s=new u.common.Asset;while(n.pos<e){let c=n.uint32();switch(c>>>3){case 1:s.chain=n.string();break;case 2:s.symbol=n.string();break;case 3:s.ticker=n.string();break;case 4:s.synth=n.bool();break;default:n.skipType(c&7);break}}return s},o.decodeDelimited=function(n){if(!(n instanceof d))n=new d(n);return this.decode(n,n.uint32())},o.verify=function(n){if(typeof n!=="object"||n===null)return"object expected";if(n.chain!=null&&n.hasOwnProperty("chain")){if(!l.isString(n.chain))return"chain: string expected"}if(n.symbol!=null&&n.hasOwnProperty("symbol")){if(!l.isString(n.symbol))return"symbol: string expected"}if(n.ticker!=null&&n.hasOwnProperty("ticker")){if(!l.isString(n.ticker))return"ticker: string expected"}if(n.synth!=null&&n.hasOwnProperty("synth")){if(typeof n.synth!=="boolean")return"synth: boolean expected"}return null},o.fromObject=function(n){if(n instanceof u.common.Asset)return n;let t=new u.common.Asset;if(n.chain!=null)t.chain=String(n.chain);if(n.symbol!=null)t.symbol=String(n.symbol);if(n.ticker!=null)t.ticker=String(n.ticker);if(n.synth!=null)t.synth=Boolean(n.synth);return t},o.toObject=function(n,t){if(!t)t={};let e={};if(t.defaults)e.chain="",e.symbol="",e.ticker="",e.synth=!1;if(n.chain!=null&&n.hasOwnProperty("chain"))e.chain=n.chain;if(n.symbol!=null&&n.hasOwnProperty("symbol"))e.symbol=n.symbol;if(n.ticker!=null&&n.hasOwnProperty("ticker"))e.ticker=n.ticker;if(n.synth!=null&&n.hasOwnProperty("synth"))e.synth=n.synth;return e},o.prototype.toJSON=function(){return this.constructor.toObject(this,T.util.toJSONOptions)},o})(),i.Coin=(()=>{function o(r){if(r){for(let n=Object.keys(r),t=0;t<n.length;++t)if(r[n[t]]!=null)this[n[t]]=r[n[t]]}}return o.prototype.asset=null,o.prototype.amount="",o.prototype.decimals=l.Long?l.Long.fromBits(0,0,!1):0,o.create=function(n){return new o(n)},o.encode=function(n,t){if(!t)t=v.create();if(n.asset!=null&&Object.hasOwnProperty.call(n,"asset"))u.common.Asset.encode(n.asset,t.uint32(10).fork()).ldelim();if(n.amount!=null&&Object.hasOwnProperty.call(n,"amount"))t.uint32(18).string(n.amount);if(n.decimals!=null&&Object.hasOwnProperty.call(n,"decimals"))t.uint32(24).int64(n.decimals);return t},o.encodeDelimited=function(n,t){return this.encode(n,t).ldelim()},o.decode=function(n,t){if(!(n instanceof d))n=d.create(n);let e=t===void 0?n.len:n.pos+t,s=new u.common.Coin;while(n.pos<e){let c=n.uint32();switch(c>>>3){case 1:s.asset=u.common.Asset.decode(n,n.uint32());break;case 2:s.amount=n.string();break;case 3:s.decimals=n.int64();break;default:n.skipType(c&7);break}}return s},o.decodeDelimited=function(n){if(!(n instanceof d))n=new d(n);return this.decode(n,n.uint32())},o.verify=function(n){if(typeof n!=="object"||n===null)return"object expected";if(n.asset!=null&&n.hasOwnProperty("asset")){let t=u.common.Asset.verify(n.asset);if(t)return"asset."+t}if(n.amount!=null&&n.hasOwnProperty("amount")){if(!l.isString(n.amount))return"amount: string expected"}if(n.decimals!=null&&n.hasOwnProperty("decimals")){if(!l.isInteger(n.decimals)&&!(n.decimals&&l.isInteger(n.decimals.low)&&l.isInteger(n.decimals.high)))return"decimals: integer|Long expected"}return null},o.fromObject=function(n){if(n instanceof u.common.Coin)return n;let t=new u.common.Coin;if(n.asset!=null){if(typeof n.asset!=="object")throw TypeError(".common.Coin.asset: object expected");t.asset=u.common.Asset.fromObject(n.asset)}if(n.amount!=null)t.amount=String(n.amount);if(n.decimals!=null){if(l.Long)(t.decimals=l.Long.fromValue(n.decimals)).unsigned=!1;else if(typeof n.decimals==="string")t.decimals=Number.parseInt(n.decimals,10);else if(typeof n.decimals==="number")t.decimals=n.decimals;else if(typeof n.decimals==="object")t.decimals=new l.LongBits(n.decimals.low>>>0,n.decimals.high>>>0).toNumber()}return t},o.toObject=function(n,t){if(!t)t={};let e={};if(t.defaults)if(e.asset=null,e.amount="",l.Long){let s=new l.Long(0,0,!1);e.decimals=t.longs===String?s.toString():t.longs===Number?s.toNumber():s}else e.decimals=t.longs===String?"0":0;if(n.asset!=null&&n.hasOwnProperty("asset"))e.asset=u.common.Asset.toObject(n.asset,t);if(n.amount!=null&&n.hasOwnProperty("amount"))e.amount=n.amount;if(n.decimals!=null&&n.hasOwnProperty("decimals"))if(typeof n.decimals==="number")e.decimals=t.longs===String?String(n.decimals):n.decimals;else e.decimals=t.longs===String?l.Long.prototype.toString.call(n.decimals):t.longs===Number?new l.LongBits(n.decimals.low>>>0,n.decimals.high>>>0).toNumber():n.decimals;return e},o.prototype.toJSON=function(){return this.constructor.toObject(this,T.util.toJSONOptions)},o})(),i.PubKeySet=(()=>{function o(r){if(r){for(let n=Object.keys(r),t=0;t<n.length;++t)if(r[n[t]]!=null)this[n[t]]=r[n[t]]}}return o.prototype.secp256k1="",o.prototype.ed25519="",o.create=function(n){return new o(n)},o.encode=function(n,t){if(!t)t=v.create();if(n.secp256k1!=null&&Object.hasOwnProperty.call(n,"secp256k1"))t.uint32(10).string(n.secp256k1);if(n.ed25519!=null&&Object.hasOwnProperty.call(n,"ed25519"))t.uint32(18).string(n.ed25519);return t},o.encodeDelimited=function(n,t){return this.encode(n,t).ldelim()},o.decode=function(n,t){if(!(n instanceof d))n=d.create(n);let e=t===void 0?n.len:n.pos+t,s=new u.common.PubKeySet;while(n.pos<e){let c=n.uint32();switch(c>>>3){case 1:s.secp256k1=n.string();break;case 2:s.ed25519=n.string();break;default:n.skipType(c&7);break}}return s},o.decodeDelimited=function(n){if(!(n instanceof d))n=new d(n);return this.decode(n,n.uint32())},o.verify=function(n){if(typeof n!=="object"||n===null)return"object expected";if(n.secp256k1!=null&&n.hasOwnProperty("secp256k1")){if(!l.isString(n.secp256k1))return"secp256k1: string expected"}if(n.ed25519!=null&&n.hasOwnProperty("ed25519")){if(!l.isString(n.ed25519))return"ed25519: string expected"}return null},o.fromObject=function(n){if(n instanceof u.common.PubKeySet)return n;let t=new u.common.PubKeySet;if(n.secp256k1!=null)t.secp256k1=String(n.secp256k1);if(n.ed25519!=null)t.ed25519=String(n.ed25519);return t},o.toObject=function(n,t){if(!t)t={};let e={};if(t.defaults)e.secp256k1="",e.ed25519="";if(n.secp256k1!=null&&n.hasOwnProperty("secp256k1"))e.secp256k1=n.secp256k1;if(n.ed25519!=null&&n.hasOwnProperty("ed25519"))e.ed25519=n.ed25519;return e},o.prototype.toJSON=function(){return this.constructor.toObject(this,T.util.toJSONOptions)},o})(),i.Tx=(()=>{function o(r){if(this.coins=[],this.gas=[],r){for(let n=Object.keys(r),t=0;t<n.length;++t)if(r[n[t]]!=null)this[n[t]]=r[n[t]]}}return o.prototype.id="",o.prototype.chain="",o.prototype.fromAddress="",o.prototype.toAddress="",o.prototype.coins=l.emptyArray,o.prototype.gas=l.emptyArray,o.prototype.memo="",o.create=function(n){return new o(n)},o.encode=function(n,t){if(!t)t=v.create();if(n.id!=null&&Object.hasOwnProperty.call(n,"id"))t.uint32(10).string(n.id);if(n.chain!=null&&Object.hasOwnProperty.call(n,"chain"))t.uint32(18).string(n.chain);if(n.fromAddress!=null&&Object.hasOwnProperty.call(n,"fromAddress"))t.uint32(26).string(n.fromAddress);if(n.toAddress!=null&&Object.hasOwnProperty.call(n,"toAddress"))t.uint32(34).string(n.toAddress);if(n.coins?.length)for(let e=0;e<n.coins.length;++e)u.common.Coin.encode(n.coins[e],t.uint32(42).fork()).ldelim();if(n.gas?.length)for(let e=0;e<n.gas.length;++e)u.common.Coin.encode(n.gas[e],t.uint32(50).fork()).ldelim();if(n.memo!=null&&Object.hasOwnProperty.call(n,"memo"))t.uint32(58).string(n.memo);return t},o.encodeDelimited=function(n,t){return this.encode(n,t).ldelim()},o.decode=function(n,t){if(!(n instanceof d))n=d.create(n);let e=t===void 0?n.len:n.pos+t,s=new u.common.Tx;while(n.pos<e){let c=n.uint32();switch(c>>>3){case 1:s.id=n.string();break;case 2:s.chain=n.string();break;case 3:s.fromAddress=n.string();break;case 4:s.toAddress=n.string();break;case 5:if(!s.coins?.length)s.coins=[];s.coins.push(u.common.Coin.decode(n,n.uint32()));break;case 6:if(!s.gas?.length)s.gas=[];s.gas.push(u.common.Coin.decode(n,n.uint32()));break;case 7:s.memo=n.string();break;default:n.skipType(c&7);break}}return s},o.decodeDelimited=function(n){if(!(n instanceof d))n=new d(n);return this.decode(n,n.uint32())},o.verify=function(n){if(typeof n!=="object"||n===null)return"object expected";if(n.id!=null&&n.hasOwnProperty("id")){if(!l.isString(n.id))return"id: string expected"}if(n.chain!=null&&n.hasOwnProperty("chain")){if(!l.isString(n.chain))return"chain: string expected"}if(n.fromAddress!=null&&n.hasOwnProperty("fromAddress")){if(!l.isString(n.fromAddress))return"fromAddress: string expected"}if(n.toAddress!=null&&n.hasOwnProperty("toAddress")){if(!l.isString(n.toAddress))return"toAddress: string expected"}if(n.coins!=null&&n.hasOwnProperty("coins")){if(!Array.isArray(n.coins))return"coins: array expected";for(let t=0;t<n.coins.length;++t){let e=u.common.Coin.verify(n.coins[t]);if(e)return"coins."+e}}if(n.gas!=null&&n.hasOwnProperty("gas")){if(!Array.isArray(n.gas))return"gas: array expected";for(let t=0;t<n.gas.length;++t){let e=u.common.Coin.verify(n.gas[t]);if(e)return"gas."+e}}if(n.memo!=null&&n.hasOwnProperty("memo")){if(!l.isString(n.memo))return"memo: string expected"}return null},o.fromObject=function(n){if(n instanceof u.common.Tx)return n;let t=new u.common.Tx;if(n.id!=null)t.id=String(n.id);if(n.chain!=null)t.chain=String(n.chain);if(n.fromAddress!=null)t.fromAddress=String(n.fromAddress);if(n.toAddress!=null)t.toAddress=String(n.toAddress);if(n.coins){if(!Array.isArray(n.coins))throw TypeError(".common.Tx.coins: array expected");t.coins=[];for(let e=0;e<n.coins.length;++e){if(typeof n.coins[e]!=="object")throw TypeError(".common.Tx.coins: object expected");t.coins[e]=u.common.Coin.fromObject(n.coins[e])}}if(n.gas){if(!Array.isArray(n.gas))throw TypeError(".common.Tx.gas: array expected");t.gas=[];for(let e=0;e<n.gas.length;++e){if(typeof n.gas[e]!=="object")throw TypeError(".common.Tx.gas: object expected");t.gas[e]=u.common.Coin.fromObject(n.gas[e])}}if(n.memo!=null)t.memo=String(n.memo);return t},o.toObject=function(n,t){if(!t)t={};let e={};if(t.arrays||t.defaults)e.coins=[],e.gas=[];if(t.defaults)e.id="",e.chain="",e.fromAddress="",e.toAddress="",e.memo="";if(n.id!=null&&n.hasOwnProperty("id"))e.id=n.id;if(n.chain!=null&&n.hasOwnProperty("chain"))e.chain=n.chain;if(n.fromAddress!=null&&n.hasOwnProperty("fromAddress"))e.fromAddress=n.fromAddress;if(n.toAddress!=null&&n.hasOwnProperty("toAddress"))e.toAddress=n.toAddress;if(n.coins?.length){e.coins=[];for(let s=0;s<n.coins.length;++s)e.coins[s]=u.common.Coin.toObject(n.coins[s],t)}if(n.gas?.length){e.gas=[];for(let s=0;s<n.gas.length;++s)e.gas[s]=u.common.Coin.toObject(n.gas[s],t)}if(n.memo!=null&&n.hasOwnProperty("memo"))e.memo=n.memo;return e},o.prototype.toJSON=function(){return this.constructor.toObject(this,T.util.toJSONOptions)},o})(),i.Fee=(()=>{function o(r){if(this.coins=[],r){for(let n=Object.keys(r),t=0;t<n.length;++t)if(r[n[t]]!=null)this[n[t]]=r[n[t]]}}return o.prototype.coins=l.emptyArray,o.prototype.poolDeduct="",o.create=function(n){return new o(n)},o.encode=function(n,t){if(!t)t=v.create();if(n.coins?.length)for(let e=0;e<n.coins.length;++e)u.common.Coin.encode(n.coins[e],t.uint32(10).fork()).ldelim();if(n.poolDeduct!=null&&Object.hasOwnProperty.call(n,"poolDeduct"))t.uint32(18).string(n.poolDeduct);return t},o.encodeDelimited=function(n,t){return this.encode(n,t).ldelim()},o.decode=function(n,t){if(!(n instanceof d))n=d.create(n);let e=t===void 0?n.len:n.pos+t,s=new u.common.Fee;while(n.pos<e){let c=n.uint32();switch(c>>>3){case 1:if(!s.coins?.length)s.coins=[];s.coins.push(u.common.Coin.decode(n,n.uint32()));break;case 2:s.poolDeduct=n.string();break;default:n.skipType(c&7);break}}return s},o.decodeDelimited=function(n){if(!(n instanceof d))n=new d(n);return this.decode(n,n.uint32())},o.verify=function(n){if(typeof n!=="object"||n===null)return"object expected";if(n.coins!=null&&n.hasOwnProperty("coins")){if(!Array.isArray(n.coins))return"coins: array expected";for(let t=0;t<n.coins.length;++t){let e=u.common.Coin.verify(n.coins[t]);if(e)return"coins."+e}}if(n.poolDeduct!=null&&n.hasOwnProperty("poolDeduct")){if(!l.isString(n.poolDeduct))return"poolDeduct: string expected"}return null},o.fromObject=function(n){if(n instanceof u.common.Fee)return n;let t=new u.common.Fee;if(n.coins){if(!Array.isArray(n.coins))throw TypeError(".common.Fee.coins: array expected");t.coins=[];for(let e=0;e<n.coins.length;++e){if(typeof n.coins[e]!=="object")throw TypeError(".common.Fee.coins: object expected");t.coins[e]=u.common.Coin.fromObject(n.coins[e])}}if(n.poolDeduct!=null)t.poolDeduct=String(n.poolDeduct);return t},o.toObject=function(n,t){if(!t)t={};let e={};if(t.arrays||t.defaults)e.coins=[];if(t.defaults)e.poolDeduct="";if(n.coins?.length){e.coins=[];for(let s=0;s<n.coins.length;++s)e.coins[s]=u.common.Coin.toObject(n.coins[s],t)}if(n.poolDeduct!=null&&n.hasOwnProperty("poolDeduct"))e.poolDeduct=n.poolDeduct;return e},o.prototype.toJSON=function(){return this.constructor.toObject(this,T.util.toJSONOptions)},o})(),i.ProtoUint=(()=>{function o(r){if(r){for(let n=Object.keys(r),t=0;t<n.length;++t)if(r[n[t]]!=null)this[n[t]]=r[n[t]]}}return o.prototype.value="",o.create=function(n){return new o(n)},o.encode=function(n,t){if(!t)t=v.create();if(n.value!=null&&Object.hasOwnProperty.call(n,"value"))t.uint32(10).string(n.value);return t},o.encodeDelimited=function(n,t){return this.encode(n,t).ldelim()},o.decode=function(n,t){if(!(n instanceof d))n=d.create(n);let e=t===void 0?n.len:n.pos+t,s=new u.common.ProtoUint;while(n.pos<e){let c=n.uint32();switch(c>>>3){case 1:s.value=n.string();break;default:n.skipType(c&7);break}}return s},o.decodeDelimited=function(n){if(!(n instanceof d))n=new d(n);return this.decode(n,n.uint32())},o.verify=function(n){if(typeof n!=="object"||n===null)return"object expected";if(n.value!=null&&n.hasOwnProperty("value")){if(!l.isString(n.value))return"value: string expected"}return null},o.fromObject=function(n){if(n instanceof u.common.ProtoUint)return n;let t=new u.common.ProtoUint;if(n.value!=null)t.value=String(n.value);return t},o.toObject=function(n,t){if(!t)t={};let e={};if(t.defaults)e.value="";if(n.value!=null&&n.hasOwnProperty("value"))e.value=n.value;return e},o.prototype.toJSON=function(){return this.constructor.toObject(this,T.util.toJSONOptions)},o})(),i})();u.types=(()=>{let i={};return i.MsgDeposit=(()=>{function o(r){if(this.coins=[],r){for(let n=Object.keys(r),t=0;t<n.length;++t)if(r[n[t]]!=null)this[n[t]]=r[n[t]]}}return o.prototype.coins=l.emptyArray,o.prototype.memo="",o.prototype.signer=l.newBuffer([]),o.create=function(n){return new o(n)},o.encode=function(n,t){if(!t)t=v.create();if(n.coins?.length)for(let e=0;e<n.coins.length;++e)u.common.Coin.encode(n.coins[e],t.uint32(10).fork()).ldelim();if(n.memo!=null&&Object.hasOwnProperty.call(n,"memo"))t.uint32(18).string(n.memo);if(n.signer!=null&&Object.hasOwnProperty.call(n,"signer"))t.uint32(26).bytes(n.signer);return t},o.encodeDelimited=function(n,t){return this.encode(n,t).ldelim()},o.decode=function(n,t){if(!(n instanceof d))n=d.create(n);let e=t===void 0?n.len:n.pos+t,s=new u.types.MsgDeposit;while(n.pos<e){let c=n.uint32();switch(c>>>3){case 1:if(!s.coins?.length)s.coins=[];s.coins.push(u.common.Coin.decode(n,n.uint32()));break;case 2:s.memo=n.string();break;case 3:s.signer=n.bytes();break;default:n.skipType(c&7);break}}return s},o.decodeDelimited=function(n){if(!(n instanceof d))n=new d(n);return this.decode(n,n.uint32())},o.verify=function(n){if(typeof n!=="object"||n===null)return"object expected";if(n.coins!=null&&n.hasOwnProperty("coins")){if(!Array.isArray(n.coins))return"coins: array expected";for(let t=0;t<n.coins.length;++t){let e=u.common.Coin.verify(n.coins[t]);if(e)return"coins."+e}}if(n.memo!=null&&n.hasOwnProperty("memo")){if(!l.isString(n.memo))return"memo: string expected"}if(n.signer!=null&&n.hasOwnProperty("signer")){if(!(n.signer&&typeof n.signer.length==="number"||l.isString(n.signer)))return"signer: buffer expected"}return null},o.fromObject=function(n){if(n instanceof u.types.MsgDeposit)return n;let t=new u.types.MsgDeposit;if(n.coins){if(!Array.isArray(n.coins))throw TypeError(".types.MsgDeposit.coins: array expected");t.coins=[];for(let e=0;e<n.coins.length;++e){if(typeof n.coins[e]!=="object")throw TypeError(".types.MsgDeposit.coins: object expected");t.coins[e]=u.common.Coin.fromObject(n.coins[e])}}if(n.memo!=null)t.memo=String(n.memo);if(n.signer!=null){if(typeof n.signer==="string")l.base64.decode(n.signer,t.signer=l.newBuffer(l.base64.length(n.signer)),0);else if(n.signer.length)t.signer=n.signer}return t},o.toObject=function(n,t){if(!t)t={};let e={};if(t.arrays||t.defaults)e.coins=[];if(t.defaults){if(e.memo="",t.bytes===String)e.signer="";else if(e.signer=[],t.bytes!==Array)e.signer=l.newBuffer(e.signer)}if(n.coins?.length){e.coins=[];for(let s=0;s<n.coins.length;++s)e.coins[s]=u.common.Coin.toObject(n.coins[s],t)}if(n.memo!=null&&n.hasOwnProperty("memo"))e.memo=n.memo;if(n.signer!=null&&n.hasOwnProperty("signer"))e.signer=t.bytes===String?l.base64.encode(n.signer,0,n.signer.length):t.bytes===Array?Array.prototype.slice.call(n.signer):n.signer;return e},o.prototype.toJSON=function(){return this.constructor.toObject(this,T.util.toJSONOptions)},o})(),i.MsgSend=(()=>{function o(r){if(this.amount=[],r){for(let n=Object.keys(r),t=0;t<n.length;++t)if(r[n[t]]!=null)this[n[t]]=r[n[t]]}}return o.prototype.fromAddress=l.newBuffer([]),o.prototype.toAddress=l.newBuffer([]),o.prototype.amount=l.emptyArray,o.create=function(n){return new o(n)},o.encode=function(n,t){if(!t)t=v.create();if(n.fromAddress!=null&&Object.hasOwnProperty.call(n,"fromAddress"))t.uint32(10).bytes(n.fromAddress);if(n.toAddress!=null&&Object.hasOwnProperty.call(n,"toAddress"))t.uint32(18).bytes(n.toAddress);if(n.amount?.length)for(let e=0;e<n.amount.length;++e)u.cosmos.base.v1beta1.Coin.encode(n.amount[e],t.uint32(26).fork()).ldelim();return t},o.encodeDelimited=function(n,t){return this.encode(n,t).ldelim()},o.decode=function(n,t){if(!(n instanceof d))n=d.create(n);let e=t===void 0?n.len:n.pos+t,s=new u.types.MsgSend;while(n.pos<e){let c=n.uint32();switch(c>>>3){case 1:s.fromAddress=n.bytes();break;case 2:s.toAddress=n.bytes();break;case 3:if(!s.amount?.length)s.amount=[];s.amount.push(u.cosmos.base.v1beta1.Coin.decode(n,n.uint32()));break;default:n.skipType(c&7);break}}return s},o.decodeDelimited=function(n){if(!(n instanceof d))n=new d(n);return this.decode(n,n.uint32())},o.verify=function(n){if(typeof n!=="object"||n===null)return"object expected";if(n.fromAddress!=null&&n.hasOwnProperty("fromAddress")){if(!(n.fromAddress&&typeof n.fromAddress.length==="number"||l.isString(n.fromAddress)))return"fromAddress: buffer expected"}if(n.toAddress!=null&&n.hasOwnProperty("toAddress")){if(!(n.toAddress&&typeof n.toAddress.length==="number"||l.isString(n.toAddress)))return"toAddress: buffer expected"}if(n.amount!=null&&n.hasOwnProperty("amount")){if(!Array.isArray(n.amount))return"amount: array expected";for(let t=0;t<n.amount.length;++t){let e=u.cosmos.base.v1beta1.Coin.verify(n.amount[t]);if(e)return"amount."+e}}return null},o.fromObject=function(n){if(n instanceof u.types.MsgSend)return n;let t=new u.types.MsgSend;if(n.fromAddress!=null){if(typeof n.fromAddress==="string")l.base64.decode(n.fromAddress,t.fromAddress=l.newBuffer(l.base64.length(n.fromAddress)),0);else if(n.fromAddress.length)t.fromAddress=n.fromAddress}if(n.toAddress!=null){if(typeof n.toAddress==="string")l.base64.decode(n.toAddress,t.toAddress=l.newBuffer(l.base64.length(n.toAddress)),0);else if(n.toAddress.length)t.toAddress=n.toAddress}if(n.amount){if(!Array.isArray(n.amount))throw TypeError(".types.MsgSend.amount: array expected");t.amount=[];for(let e=0;e<n.amount.length;++e){if(typeof n.amount[e]!=="object")throw TypeError(".types.MsgSend.amount: object expected");t.amount[e]=u.cosmos.base.v1beta1.Coin.fromObject(n.amount[e])}}return t},o.toObject=function(n,t){if(!t)t={};let e={};if(t.arrays||t.defaults)e.amount=[];if(t.defaults){if(t.bytes===String)e.fromAddress="";else if(e.fromAddress=[],t.bytes!==Array)e.fromAddress=l.newBuffer(e.fromAddress);if(t.bytes===String)e.toAddress="";else if(e.toAddress=[],t.bytes!==Array)e.toAddress=l.newBuffer(e.toAddress)}if(n.fromAddress!=null&&n.hasOwnProperty("fromAddress"))e.fromAddress=t.bytes===String?l.base64.encode(n.fromAddress,0,n.fromAddress.length):t.bytes===Array?Array.prototype.slice.call(n.fromAddress):n.fromAddress;if(n.toAddress!=null&&n.hasOwnProperty("toAddress"))e.toAddress=t.bytes===String?l.base64.encode(n.toAddress,0,n.toAddress.length):t.bytes===Array?Array.prototype.slice.call(n.toAddress):n.toAddress;if(n.amount?.length){e.amount=[];for(let s=0;s<n.amount.length;++s)e.amount[s]=u.cosmos.base.v1beta1.Coin.toObject(n.amount[s],t)}return e},o.prototype.toJSON=function(){return this.constructor.toObject(this,T.util.toJSONOptions)},o})(),i})();u.cosmos=(()=>{let i={};return i.base=(()=>{let o={};return o.v1beta1=(()=>{let r={};return r.Coin=(()=>{function n(t){if(t){for(let e=Object.keys(t),s=0;s<e.length;++s)if(t[e[s]]!=null)this[e[s]]=t[e[s]]}}return n.prototype.denom="",n.prototype.amount="",n.create=function(e){return new n(e)},n.encode=function(e,s){if(!s)s=v.create();if(e.denom!=null&&Object.hasOwnProperty.call(e,"denom"))s.uint32(10).string(e.denom);if(e.amount!=null&&Object.hasOwnProperty.call(e,"amount"))s.uint32(18).string(e.amount);return s},n.encodeDelimited=function(e,s){return this.encode(e,s).ldelim()},n.decode=function(e,s){if(!(e instanceof d))e=d.create(e);let c=s===void 0?e.len:e.pos+s,a=new u.cosmos.base.v1beta1.Coin;while(e.pos<c){let p=e.uint32();switch(p>>>3){case 1:a.denom=e.string();break;case 2:a.amount=e.string();break;default:e.skipType(p&7);break}}return a},n.decodeDelimited=function(e){if(!(e instanceof d))e=new d(e);return this.decode(e,e.uint32())},n.verify=function(e){if(typeof e!=="object"||e===null)return"object expected";if(e.denom!=null&&e.hasOwnProperty("denom")){if(!l.isString(e.denom))return"denom: string expected"}if(e.amount!=null&&e.hasOwnProperty("amount")){if(!l.isString(e.amount))return"amount: string expected"}return null},n.fromObject=function(e){if(e instanceof u.cosmos.base.v1beta1.Coin)return e;let s=new u.cosmos.base.v1beta1.Coin;if(e.denom!=null)s.denom=String(e.denom);if(e.amount!=null)s.amount=String(e.amount);return s},n.toObject=function(e,s){if(!s)s={};let c={};if(s.defaults)c.denom="",c.amount="";if(e.denom!=null&&e.hasOwnProperty("denom"))c.denom=e.denom;if(e.amount!=null&&e.hasOwnProperty("amount"))c.amount=e.amount;return c},n.prototype.toJSON=function(){return this.constructor.toObject(this,T.util.toJSONOptions)},n})(),r.DecCoin=(()=>{function n(t){if(t){for(let e=Object.keys(t),s=0;s<e.length;++s)if(t[e[s]]!=null)this[e[s]]=t[e[s]]}}return n.prototype.denom="",n.prototype.amount="",n.create=function(e){return new n(e)},n.encode=function(e,s){if(!s)s=v.create();if(e.denom!=null&&Object.hasOwnProperty.call(e,"denom"))s.uint32(10).string(e.denom);if(e.amount!=null&&Object.hasOwnProperty.call(e,"amount"))s.uint32(18).string(e.amount);return s},n.encodeDelimited=function(e,s){return this.encode(e,s).ldelim()},n.decode=function(e,s){if(!(e instanceof d))e=d.create(e);let c=s===void 0?e.len:e.pos+s,a=new u.cosmos.base.v1beta1.DecCoin;while(e.pos<c){let p=e.uint32();switch(p>>>3){case 1:a.denom=e.string();break;case 2:a.amount=e.string();break;default:e.skipType(p&7);break}}return a},n.decodeDelimited=function(e){if(!(e instanceof d))e=new d(e);return this.decode(e,e.uint32())},n.verify=function(e){if(typeof e!=="object"||e===null)return"object expected";if(e.denom!=null&&e.hasOwnProperty("denom")){if(!l.isString(e.denom))return"denom: string expected"}if(e.amount!=null&&e.hasOwnProperty("amount")){if(!l.isString(e.amount))return"amount: string expected"}return null},n.fromObject=function(e){if(e instanceof u.cosmos.base.v1beta1.DecCoin)return e;let s=new u.cosmos.base.v1beta1.DecCoin;if(e.denom!=null)s.denom=String(e.denom);if(e.amount!=null)s.amount=String(e.amount);return s},n.toObject=function(e,s){if(!s)s={};let c={};if(s.defaults)c.denom="",c.amount="";if(e.denom!=null&&e.hasOwnProperty("denom"))c.denom=e.denom;if(e.amount!=null&&e.hasOwnProperty("amount"))c.amount=e.amount;return c},n.prototype.toJSON=function(){return this.constructor.toObject(this,T.util.toJSONOptions)},n})(),r.IntProto=(()=>{function n(t){if(t){for(let e=Object.keys(t),s=0;s<e.length;++s)if(t[e[s]]!=null)this[e[s]]=t[e[s]]}}return n.prototype.int="",n.create=function(e){return new n(e)},n.encode=function(e,s){if(!s)s=v.create();if(e.int!=null&&Object.hasOwnProperty.call(e,"int"))s.uint32(10).string(e.int);return s},n.encodeDelimited=function(e,s){return this.encode(e,s).ldelim()},n.decode=function(e,s){if(!(e instanceof d))e=d.create(e);let c=s===void 0?e.len:e.pos+s,a=new u.cosmos.base.v1beta1.IntProto;while(e.pos<c){let p=e.uint32();switch(p>>>3){case 1:a.int=e.string();break;default:e.skipType(p&7);break}}return a},n.decodeDelimited=function(e){if(!(e instanceof d))e=new d(e);return this.decode(e,e.uint32())},n.verify=function(e){if(typeof e!=="object"||e===null)return"object expected";if(e.int!=null&&e.hasOwnProperty("int")){if(!l.isString(e.int))return"int: string expected"}return null},n.fromObject=function(e){if(e instanceof u.cosmos.base.v1beta1.IntProto)return e;let s=new u.cosmos.base.v1beta1.IntProto;if(e.int!=null)s.int=String(e.int);return s},n.toObject=function(e,s){if(!s)s={};let c={};if(s.defaults)c.int="";if(e.int!=null&&e.hasOwnProperty("int"))c.int=e.int;return c},n.prototype.toJSON=function(){return this.constructor.toObject(this,T.util.toJSONOptions)},n})(),r.DecProto=(()=>{function n(t){if(t){for(let e=Object.keys(t),s=0;s<e.length;++s)if(t[e[s]]!=null)this[e[s]]=t[e[s]]}}return n.prototype.dec="",n.create=function(e){return new n(e)},n.encode=function(e,s){if(!s)s=v.create();if(e.dec!=null&&Object.hasOwnProperty.call(e,"dec"))s.uint32(10).string(e.dec);return s},n.encodeDelimited=function(e,s){return this.encode(e,s).ldelim()},n.decode=function(e,s){if(!(e instanceof d))e=d.create(e);let c=s===void 0?e.len:e.pos+s,a=new u.cosmos.base.v1beta1.DecProto;while(e.pos<c){let p=e.uint32();switch(p>>>3){case 1:a.dec=e.string();break;default:e.skipType(p&7);break}}return a},n.decodeDelimited=function(e){if(!(e instanceof d))e=new d(e);return this.decode(e,e.uint32())},n.verify=function(e){if(typeof e!=="object"||e===null)return"object expected";if(e.dec!=null&&e.hasOwnProperty("dec")){if(!l.isString(e.dec))return"dec: string expected"}return null},n.fromObject=function(e){if(e instanceof u.cosmos.base.v1beta1.DecProto)return e;let s=new u.cosmos.base.v1beta1.DecProto;if(e.dec!=null)s.dec=String(e.dec);return s},n.toObject=function(e,s){if(!s)s={};let c={};if(s.defaults)c.dec="";if(e.dec!=null&&e.hasOwnProperty("dec"))c.dec=e.dec;return c},n.prototype.toJSON=function(){return this.constructor.toObject(this,T.util.toJSONOptions)},n})(),r})(),o})(),i})();function pn(i){if(i instanceof Uint8Array)return i;if(typeof i==="string")return Uint8Array.from(globalThis.atob(i),(r)=>r.charCodeAt(0));throw TypeError("address must be Uint8Array or base64 string")}var Bt=(i)=>{let o=i;return u.types.MsgSend.encode({amount:o.amount,fromAddress:pn(o.fromAddress),toAddress:pn(o.toAddress)}).finish()},Ft=(i)=>{let o=i;return u.types.MsgDeposit.encode({coins:o.coins.map((r)=>({amount:r.amount,asset:r.asset})),memo:o.memo,signer:pn(o.signer)}).finish()};function H(){return{...Ut,"/types.MsgDeposit":Ft,"/types.MsgSend":Bt}}function I(i,o=i===Kn.THORChain?"thor":"maya"){let r=i===Kn.THORChain?"thorchain":"mayachain",n={"/types.MsgDeposit":{aminoType:`${r}/MsgDeposit`,fromAmino:({signer:t,...e})=>({...e,signer:z(t)}),toAmino:({signer:t,...e})=>({...e,signer:typeof t==="string"?X(t,o):t})},"/types.MsgSend":{aminoType:`${r}/MsgSend`,fromAmino:({from_address:t,to_address:e,...s})=>({...s,fromAddress:z(t),toAddress:z(e)}),toAmino:({fromAddress:t,toAddress:e,...s})=>({...s,from_address:typeof t==="string"?X(t,o):t,to_address:typeof e==="string"?X(e,o):e})}};return Object.assign(n,{fromAmino(t){let e=Object.entries(n).find(([,a])=>a.aminoType===t.type);if(!e)throw TypeError(`No converter for amino type ${t.type}`);let[s,c]=e;return{typeUrl:s,value:c.fromAmino(t.value)}},toAmino(t){let e=n[t.typeUrl];if(!e)throw TypeError(`No converter for type URL ${t.typeUrl}`);return{type:e.aminoType,value:e.toAmino(t.value)}}})}var Ge=_(tn.THORChain).gas,Ye=_(tn.Maya).gas,jn=({sender:i,recipient:o,assetValue:r})=>({type:`${r.chain===tn.Maya?"mayachain":"thorchain"}/MsgSend`,value:{amount:[{amount:r.getBaseValue("string"),denom:U(r.symbol,!0)}],from_address:i,to_address:o}}),En=({sender:i,assetValue:o,memo:r=""})=>({type:`${o.chain===tn.Maya?"mayachain":"thorchain"}/MsgDeposit`,value:{coins:[{amount:o.getBaseValue("string"),asset:nn(o)}],memo:r,signer:i}}),hn=({sender:i,recipient:o,assetValue:r,memo:n})=>!o?En({assetValue:r,memo:n,sender:i}):jn({assetValue:r,recipient:o,sender:i});function Hn(i,o){for(let r of["/types.MsgDeposit","/types.MsgSend"]){let n=i[r];if(n.aminoType===o)return{fromAmino:n.fromAmino,typeUrl:r}}return null}var R=(i,o)=>{let r=I(o),n=Hn(r,i.type);if(!n)throw new gn("toolbox_cosmos_invalid_params",{error:`No converter for amino type ${i.type}`});return{typeUrl:n.typeUrl,value:n.fromAmino(i.value)}},Jn=async({rpcUrl:i,sender:o})=>{let n=await(await N(i)).getAccount(o);if(!n)throw new gn("toolbox_cosmos_account_not_found",{sender:o});return n};async function $n(i){let{assetValue:o,recipient:r,memo:n,sender:t,asSignable:e,asAminoMessage:s,sequence:c,accountNumber:a}=i,p=i.sweep?await bn({assetValue:o,sender:t}):o;if(r)return Lt({accountNumber:a,asAminoMessage:s,asSignable:e,assetValue:p,memo:n,recipient:r,sender:t,sequence:c});return jt({accountNumber:a,asAminoMessage:s,asSignable:e,assetValue:p,memo:n,sender:t,sequence:c})}async function bn({assetValue:i,sender:o}){let r=i.chain,n=await yn(r),e=await(await N(n)).getAllBalances(o),s=i.isGasAsset?(await Z(r)).getBaseValue("bigint"):0n;return W({assetValue:i,balances:e,denom:U(i.symbol,!0),feeAmount:s})}async function Lt({sender:i,recipient:o,assetValue:r,memo:n="",asSignable:t=!0,asAminoMessage:e=!1,sequence:s,accountNumber:c}){let a=r.chain,p=c!==void 0&&s!==void 0?void 0:await Jn({rpcUrl:await yn(a),sender:i}),{chainId:h}=Ln(a),w=jn({assetValue:r,recipient:o,sender:i}),C=t?R(e?w:K(w),a):w;return{accountNumber:c??Number(p?.accountNumber),chainId:h,fee:_(a),memo:n,msgs:[C],sequence:s??Number(p?.sequence)}}async function jt({sender:i,assetValue:o,memo:r="",asSignable:n=!0,asAminoMessage:t=!1,sequence:e,accountNumber:s}){let c=o.chain,a=s!==void 0&&e!==void 0?void 0:await Jn({rpcUrl:await yn(c),sender:i}),{chainId:p}=Ln(c),h=En({assetValue:o,memo:r,sender:i}),w=n?R(t?h:K(h),c):h;return{accountNumber:s??Number(a?.accountNumber),chainId:p,fee:_(c),memo:r,msgs:[w],sequence:e??Number(a?.sequence)}}function K(i){if(i.type==="thorchain/MsgSend"||i.type==="mayachain/MsgSend")return i;return{...i,value:{...i.value,coins:i.value.coins.map((o)=>{let r=Kt.from({asset:o.asset}),n=(r.isSynthetic?r.symbol.split("/")?.[1]:r.symbol)?.toUpperCase(),t=(r.isSynthetic?r.symbol.split("/")?.[0]:r.chain)?.toUpperCase();return{...o,asset:{chain:t,symbol:n,synth:r.isSynthetic,ticker:r.ticker}}})}}}function en({chain:i,memo:o,msgs:r}){let n=H(),t=I(i),s=r.map((c)=>{let a=Hn(t,c.type);if(!a)throw new gn("toolbox_cosmos_invalid_params",{error:`No converter for amino type ${c.type}`});return{typeUrl:a.typeUrl,value:a.fromAmino(c.value)}}).map((c)=>It(c,n));return Rt({memo:o,messages:s})}import{Chain as V,SwapKitError as ke}from"@swapkit/helpers";import{secp256k1 as Et}from"@noble/curves/secp256k1.js";import{base64 as Cn,bech32 as An}from"@scure/base";import{HDKey as Ht}from"@scure/bip32";import{verifySignature as Jt,createWalletFromMnemonic as $t,createWalletFromPrivateKey as Wt,mnemonicToSeed as qt,signDirect as Vt}from"@swapkit/cosmos-signer";import{AssetValue as On,applyFeeMultiplier as Wn,Chain as x,CosmosChainPrefixes as Xn,DerivationPath as Gt,derivationPathToString as qn,FeeOption as Tn,getChainConfig as Yt,getRPCUrl as q,NetworkDerivationPath as zt,SwapKitError as B,SwapKitNumber as wn,updateDerivationPath as Xt}from"@swapkit/helpers";import{SwapKitApi as Qn}from"@swapkit/helpers/api";import{PubKey as Qt}from"cosmjs-types/cosmos/crypto/secp256k1/keys";import{match as Zt,P as Vn}from"ts-pattern";async function Zn(i,o){try{let n=(await Qn.getGasRate()).find((t)=>t.chainId===i)?.value;return n?Number.parseFloat(n):o}catch{return o}}function nt(i){let o=[{address:i.address,algo:"secp256k1",pubkey:i.publicKey}];return{getAccounts:()=>Promise.resolve(o),async signDirect(r,n){if(r!==i.address)throw new B("toolbox_cosmos_signer_not_defined");let t=await Vt(i.privateKey,i.publicKey,{accountNumber:n.accountNumber,authInfoBytes:n.authInfoBytes,bodyBytes:n.bodyBytes,chainId:n.chainId});return{signature:t.signature,signed:{accountNumber:t.signed.accountNumber,authInfoBytes:t.signed.authInfoBytes,bodyBytes:t.signed.bodyBytes,chainId:t.signed.chainId}}}}}async function Gn({phrase:i,prefix:o,...r}){let n="derivationPath"in r?r.derivationPath:`${Gt[r.chain]}/${r.index??0}`,t=await $t({hdPath:n,mnemonic:i,prefix:o??""});return nt(t)}async function ne({privateKey:i,prefix:o}){let r=Wt({prefix:o,privateKey:i});return nt(r)}var Yn={[x.Cosmos]:1000,[x.Kujira]:1000,[x.Noble]:1000,[x.THORChain]:5000000,[x.Maya]:5000000,[x.Harbor]:5000000};function te(i){return async function({signature:r,message:n,address:t}){let e=await i(t);if(!e?.pubkey)throw new B("toolbox_cosmos_verify_signature_no_pubkey");let s=e.pubkey.type==="/cosmos.crypto.secp256k1.PubKey"?Qt.decode(e.pubkey.value).key:e.pubkey.value;return Jt(Cn.decode(n),Cn.decode(r),s)}}function on({chain:i,...o}){let r=Xn[i],n="index"in o?o.index||0:0,t=qn("derivationPath"in o&&o.derivationPath?o.derivationPath:Xt(zt[i],{index:n})),e;async function s(){if(e)return e;return e=await Zt(o).with({phrase:Vn.string},({phrase:m})=>Gn({derivationPath:t,phrase:m,prefix:r})).with({signer:Vn.any},({signer:m})=>m).otherwise(()=>{return}),e}async function c(m){let y=await q(i);return(await N(y)).getAccount(m)}async function a(){let m=await s(),[y]=await m?.getAccounts()||[];return y?.address}async function p(){let m=await s(),[y]=await m?.getAccounts()||[];if(!y?.pubkey)throw new B("toolbox_cosmos_signer_not_defined");return Cn.encode(y?.pubkey)}async function h(m){let y=await s(),f=await a(),g=await q(i);if(!(y&&f))throw new B("toolbox_cosmos_signer_not_defined");return(await E(g,y)).sign(f,m.msgs,m.fee,m.memo,{accountNumber:BigInt(m.accountNumber),chainId:m.chainId,sequence:m.sequence})}async function w(m){let y=await s(),f=await a(),g=await q(i);if(!(y&&f))throw new B("toolbox_cosmos_signer_not_defined");let S=await(await E(g,y)).signAndBroadcast(f,m.msgs,m.fee,m.memo);if(S.code!==0)throw new B("core_swap_transaction_error",{code:S.code,message:S.rawLog});return S.transactionHash}async function C({recipient:m,assetValue:y,memo:f="",feeRate:g,feeOptionKey:A=Tn.Fast,sweep:S}){let O=await s(),D=await a();if(!(O&&D))throw new B("toolbox_cosmos_signer_not_defined");let k=await q(i),rn=On.from({chain:i}),sn=nn(rn),j=ee(g||(await zn(i,Yn[i]))[A],sn,i),cn=await E(k,O),J=U(y.symbol),an=[{amount:(S?W({assetValue:y,balances:await Sn(i)(D),denom:J,feeAmount:mn(j.amount,J)}):y).getBaseValue("string"),denom:J}],{transactionHash:un}=await cn.sendTokens(D,m,an,j,f);return un}return{createPrivateKeyFromPhrase:re(t),createTransaction:In,fetchFeeRateFromSwapKit:Zn,getAccount:c,getAddress:a,getBalance:async(m,y)=>{let f=await Sn(i)(m),g=await Promise.all(f.filter(({denom:A})=>A&&!A.includes("IBC/")&&!([x.THORChain,x.Maya].includes(i)&&A.split("-").length>2)).map(({denom:A,amount:S})=>{let O=[x.THORChain,x.Maya].includes(i)&&(A.includes("/")||A.includes("˜"))?`${i}.${A}`:A;return Rn(O,S)}));if(g.length===0)return[On.from({chain:i})];return g},getBalanceAsDenoms:Sn(i),getFees:()=>zn(i,Yn[i]),getPubKey:p,getSignerFromPhrase:({phrase:m,derivationPath:y})=>Gn({derivationPath:qn(y),index:n,phrase:m,prefix:r}),getSignerFromPrivateKey:(m)=>ne({prefix:r,privateKey:m}),signAndBroadcastTransaction:w,signTransaction:h,transfer:C,validateAddress:ie(i),verifySignature:te(c)}}async function mo(i,o){try{let n=(await Qn.getGasRate()).find((t)=>t.chainId===i)?.value;return n?Number.parseFloat(n):o}catch{return o}}function po({assetValue:{chain:i}}){return On.from({chain:i,value:oe(i)})}async function zn(i,o){let{chainId:r,baseDecimal:n}=Yt(i),t=await Zn(r,o);return{average:wn.fromBigInt(BigInt(t),n),fast:wn.fromBigInt(BigInt(Wn(t,Tn.Fast,!0)),n),fastest:wn.fromBigInt(BigInt(Wn(t,Tn.Fastest,!0)),n)}}function ee(i,o,r){return{amount:[{amount:typeof i==="number"?i.toString():i.getBaseValue("string"),denom:o}],gas:_(r).gas}}function oe(i){return{[x.Cosmos]:0.007,[x.Kujira]:0.02,[x.Noble]:0.01,[x.THORChain]:0.02,[x.Maya]:0.02,[x.Harbor]:0.02}[i]||0}function ie(i){let o=Xn[i];return function(n){if(!n.startsWith(o))return!1;try{let{prefix:t,words:e}=An.decode(n);return An.encode(t,e)===n.toLocaleLowerCase()}catch{return!1}}}function Sn(i){return async function(r){let n=await q(i);return(await(await N(n)).getAllBalances(r)).map((c)=>({...c,denom:c.denom.includes("/")?c.denom.toUpperCase():c.denom}))}}function re(i){return async function(r){let n=await qt(r),e=Ht.fromMasterSeed(n).derive(i);if(!e.privateKey)throw new B("toolbox_cosmos_invalid_params",{error:"HDKey derivation produced no private key"});return Et.getPublicKey(e.privateKey,!0),Uint8Array.from(e.privateKey)}}import{secp256k1 as se}from"@noble/curves/secp256k1.js";import{base64 as F}from"@scure/base";import{buildMultisignedTx as ce,createMultisigThresholdPubkey as ae,signAmino as ue,createWalletFromMnemonic as le,encodeTxRaw as fe,multisigPubkeyToAddress as de,singlePubkeyToAddress as et}from"@swapkit/cosmos-signer";import{CosmosChainPrefixes as me,derivationPathToString as pe,FeeOption as xn,getRPCUrl as ot,NetworkDerivationPath as ye,SKConfig as ge,SwapKitError as L,updateDerivationPath as he}from"@swapkit/helpers";import{match as be,P as tt}from"ts-pattern";function Ae(i){let o=[{address:i.address,algo:"secp256k1",pubkey:i.publicKey}];return{accounts:o,getAccounts:()=>Promise.resolve(o),async signAmino(r,n){if(r!==i.address)throw new L("toolbox_cosmos_signer_not_defined");let t=await ue(i.privateKey,i.publicKey,{signDoc:n});return{signature:t.signature,signed:t.signed}}}}function we({prefix:i,derivationPath:o}){return async function(n,t=0){let e=await le({hdPath:`${o}/${t}`,mnemonic:n,prefix:i});return Ae(e)}}function Se(i){return F.encode(i)}function Ce(i,o){return async function({wallet:n,tx:t}){let{msgs:e,accountNumber:s,sequence:c,chainId:a,fee:p,memo:h}=typeof t==="string"?JSON.parse(t):t,w=(await n.getAccounts())?.[0]?.address||"",C=I(i,o),m=H(),y=await Fn(n,{aminoTypes:C,registry:m}),f=[];for(let S of e){let O=R(S,i);f.push(O)}let{signatures:[g]}=await y.sign(w,f,p,h,{accountNumber:BigInt(s),chainId:a,sequence:c});return{bodyBytes:en({chain:i,memo:h,msgs:e.map(K)}),signature:Se(g)}}}function it(i){if(i.length!==33||i[0]!==2&&i[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:F.encode(i)}}function Oe({prefix:i,chain:o}){return async function(n,t,e,s,c){let a=await ot(o),{sequence:p,fee:h}=JSON.parse(n),w=rt(e,s),C=t.map((f)=>[et(it(F.decode(f.pubKey)),i),F.decode(f.signature)]),m=await N(a),{transactionHash:y}=await m.broadcastTx(ce({bodyBytes:c,fee:{amount:h.amount,gasLimit:BigInt(h.gas),...h.payer?{payer:h.payer}:{},...h.granter?{granter:h.granter}:{}},multisigPubkey:w,prefix:i,sequence:p,signatures:new Map(C)}));return y}}function rt(i,o,r=!0){return ae(i.map((n)=>it(F.decode(n))),o,r)}function Te(i){return F.decode(i)}function xe({privateKey:i,message:o}){let r=se.sign(F.decode(o),i,{lowS:!0,prehash:!1});return Promise.resolve(F.encode(r))}function st({chain:i,...o}){let{isStagenet:r}=ge.get("envs"),n=`${r?"s":""}${me[i]}`,t="index"in o?o.index||0:0,e="derivationPath"in o&&o.derivationPath?o.derivationPath:he(ye[i],{index:t}),s=on({chain:i,...o}),c=_(i),a;function p(){return a??=be(o).with({phrase:tt.string},({phrase:f})=>s.getSignerFromPhrase({derivationPath:e,phrase:f})).with({signer:tt.any},({signer:f})=>Promise.resolve(f)).otherwise(()=>Promise.resolve(void 0)),a}async function h(){let f=await ot(i),g=await p();if(!g)throw new L("toolbox_cosmos_no_signer");let A=H(),S=I(i,n),O=await E(f,g,{aminoTypes:S,registry:A});return{signer:g,signingClient:O}}async function w({fee:f,memo:g,msgs:A}){let{signer:S,signingClient:O}=await h(),D=(await S.getAccounts())?.[0]?.address;if(!D)throw new L("toolbox_cosmos_signer_not_defined");let k=await O.signAndBroadcast(D,A,f,g);if(k.code!==0)throw new L("core_swap_transaction_error",{code:k.code,message:k.rawLog});return k.transactionHash}async function C(){let f=await Z(i);return{[xn.Average]:f,[xn.Fast]:f,[xn.Fastest]:f}}async function m({assetValue:f,memo:g="",recipient:A,sweep:S}){let{signer:O,signingClient:D}=await h(),k=(await O.getAccounts())?.[0]?.address;if(!k)throw new L("toolbox_cosmos_no_signer");let rn="signAmino"in O,sn=S?await bn({assetValue:f,sender:k}):f,j=hn({assetValue:sn,memo:g,recipient:A,sender:k});if(rn){let kn=R(j,i),{signatures:an,authInfoBytes:un}=await D.sign(k,[kn],c,g),ct=fe({authInfoBytes:un,bodyBytes:en({chain:i,memo:g,msgs:[j].map(K)}),signatures:an});return(await D.broadcastTx(ct)).transactionHash}let cn=K(j),J=R(cn,i);return w({fee:c,memo:g,msgs:[J]})}async function y(f){let{signer:g,signingClient:A}=await h(),S=(await g.getAccounts())?.[0]?.address;if(!S)throw new L("toolbox_cosmos_signer_not_defined");return A.sign(S,f.msgs,f.fee,f.memo,{accountNumber:BigInt(f.accountNumber),chainId:f.chainId,sequence:f.sequence})}return{...s,broadcastMultisigTx:Oe({chain:i,prefix:n}),buildAminoMsg:hn,buildEncodedTxBody:en,convertToSignable:R,createDefaultAminoTypes:()=>I(i,n),createDefaultRegistry:H,createMultisig:rt,createTransaction:$n,deposit:m,getFees:C,importSignature:Te,parseAminoMessageForDirectSigning:K,pubkeyToAddress:(f)=>{if(f.type==="tendermint/PubKeyMultisigThreshold")return de(f,n);return et(f,n)},secp256k1HdWalletFromMnemonic:we({derivationPath:pe(e),prefix:n}),signAndBroadcastTransaction:w,signMultisigTx:Ce(i,n),signTransaction:y,signWithPrivateKey:xe,transfer:m}}var vo=(i,o)=>{switch(i){case V.Cosmos:case V.Kujira:case V.Noble:return on({chain:i,...o});case V.Maya:case V.THORChain:return st({chain:i,...o});default:throw new ke("toolbox_cosmos_not_supported",{chain:i})}};export{At as DEFAULT_COSMOS_FEE_MAINNET,wt as DEFAULT_KUJI_FEE_MAINNET,St as DEFAULT_NOBLE_FEE_MAINNET,Ye as MAYA_GAS_VALUE,Ge as THORCHAIN_GAS_VALUE,_n as USK_KUJIRA_FACTORY_DENOM,bt as YUM_KUJIRA_FACTORY_DENOM,X as base64ToBech32,z as bech32ToBase64,hn as buildAminoMsg,jt as buildDepositTx,en as buildEncodedTxBody,Lt as buildTransferTx,R as convertToSignable,In as cosmosCreateTransaction,on as createCosmosToolbox,I as createDefaultAminoTypes,H as createDefaultRegistry,Fn as createOfflineStargateClient,E as createSigningStargateClient,N as createStargateClient,st as createThorchainToolbox,$n as createTransaction,En as depositMsgAmino,po as estimateTransactionFee,Zn as fetchFeeRateFromSwapKit,_e as fromBase64,Rn as getAssetFromDenom,ie as getCosmosAddressValidator,vo as getCosmosToolbox,_ as getDefaultChainFee,nn as getDenomWithChain,mn as getFeeAmountForDenom,mo as getFeeRateFromSwapKit,U as getMsgSendDenom,Gn as getSignerFromPhrase,ne as getSignerFromPrivateKey,W as getSweepAssetValue,Z as getThorchainNativeFee,K as parseAminoMessageForDirectSigning,bn as resolveThorchainSweepAssetValue,Me as toBase64,jn as transferMsgAmino,te as verifySignature};
|
package/dist/src/evm/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as
|
|
1
|
+
import{a as fa}from"../../chunk-qsbf0z90.js";import{$ as _,A as z,B as A,C as B,D as C,E as D,F as E,G as F,H as G,I as H,J as I,K as J,L as K,M as L,N as M,O as N,P as O,Q as P,R as Q,S as R,T as S,U as T,V as U,W as V,X as W,Y as X,Z as Y,_ as Z,aa,b as a,ba,c as b,ca,d as c,da,e as d,ea,f as e,g as f,h as g,i as h,j as i,k as j,l as k,m as l,n as m,o as n,p as o,q as p,r as q,s as r,t as s,u as t,v as u,w as v,x as w,y as x,z as y}from"../../chunk-rn33j2bm.js";import"../../chunk-as9fracn.js";import"../../chunk-4428244x.js";export{H as ADIToolbox,I as ARBToolbox,J as ARCToolbox,K as AURORAToolbox,L as AVAXToolbox,M as BASEToolbox,N as BERAToolbox,O as BSCToolbox,o as BaseEVMToolbox,P as BotanixToolbox,Q as COREToolbox,R as CORNToolbox,S as CROToolbox,x as ContractAddress,G as ETHToolbox,fa as EthNetwork,T as GNOToolbox,U as HOODToolbox,V as HYPEREVMToolbox,W as LINEAToolbox,X as MATICToolbox,n as MAX_APPROVAL,Y as MEGAETHToolbox,Z as MONADToolbox,F as OPToolbox,_ as PLASMAToolbox,aa as SONICToolbox,ba as UNIToolbox,ca as XLayerToolbox,k as buildEIP712DomainType,r as createContract,b as createCustomEvmApi,E as createOPStackToolbox,w as getChecksumAddressFromAsset,s as getCreateContract,z as getCreateContractTxObject,v as getEIP1193SendTransaction,D as getEVMTxType,A as getEstimateGasPrices,a as getEvmApi,da as getEvmToolbox,ea as getEvmToolboxAsync,e as getFallbackProvider,h as getIsEIP1559Compatible,g as getNetworkParams,d as getProvider,c as getProviderSync,y as getTokenAddress,q as isBrowserProvider,C as isEIP1559Transaction,B as isEIP7702Transaction,t as isStateChangingCall,l as parseEIP712FromEVMTx,i as signAuthorization,u as toChecksumAddress,f as toHexString,j as validateAuthorization,m as validateAuthorizations,p as validateEVMAddress};
|