edge-currency-accountbased 4.3.2 → 4.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/android/src/main/assets/edge-currency-accountbased/algorand.chunk.js +2 -2
  3. package/android/src/main/assets/edge-currency-accountbased/axelar.chunk.js +2 -2
  4. package/android/src/main/assets/edge-currency-accountbased/edge-currency-accountbased.js +2 -2
  5. package/android/src/main/assets/edge-currency-accountbased/polkadot.chunk.js +2 -2
  6. package/android/src/main/assets/edge-currency-accountbased/ripple.chunk.js +4 -4
  7. package/android/src/main/assets/edge-currency-accountbased/solana.chunk.js +3 -3
  8. package/android/src/main/assets/edge-currency-accountbased/tron.chunk.js +1 -1
  9. package/lib/algorand/AlgorandEngine.js +22 -19
  10. package/lib/algorand/algorandInfo.js +7 -0
  11. package/lib/algorand/algorandTestnetInfo.js +7 -0
  12. package/lib/cosmos/CosmosEngine.js +12 -2
  13. package/lib/cosmos/info/axelarInfo.js +1 -0
  14. package/lib/cosmos/info/coreumInfo.js +1 -0
  15. package/lib/cosmos/info/cosmosCommonInfo.js +9 -0
  16. package/lib/cosmos/info/cosmoshubInfo.js +1 -0
  17. package/lib/cosmos/info/osmosisInfo.js +2 -0
  18. package/lib/cosmos/info/thorchainruneInfo.js +1 -0
  19. package/lib/declare-modules.d.js +8 -0
  20. package/lib/eos/info/eosCommonInfo.js +8 -0
  21. package/lib/eos/info/eosInfo.js +1 -0
  22. package/lib/eos/info/telosInfo.js +1 -0
  23. package/lib/eos/info/waxInfo.js +1 -0
  24. package/lib/ethereum/info/arbitrumInfo.js +2 -0
  25. package/lib/ethereum/info/avalancheInfo.js +2 -0
  26. package/lib/ethereum/info/baseInfo.js +2 -0
  27. package/lib/ethereum/info/binancesmartchainInfo.js +2 -0
  28. package/lib/ethereum/info/celoInfo.js +2 -0
  29. package/lib/ethereum/info/ethDevInfo.js +2 -0
  30. package/lib/ethereum/info/ethereumCommonInfo.js +8 -0
  31. package/lib/ethereum/info/ethereumInfo.js +2 -0
  32. package/lib/ethereum/info/ethereumclassicInfo.js +4 -1
  33. package/lib/ethereum/info/ethereumpowInfo.js +2 -0
  34. package/lib/ethereum/info/fantomInfo.js +2 -0
  35. package/lib/ethereum/info/filecoinFevmCalibrationInfo.js +1 -0
  36. package/lib/ethereum/info/filecoinFevmInfo.js +1 -0
  37. package/lib/ethereum/info/goerliInfo.js +4 -1
  38. package/lib/ethereum/info/kovanInfo.js +4 -1
  39. package/lib/ethereum/info/optimismInfo.js +2 -0
  40. package/lib/ethereum/info/polygonInfo.js +2 -0
  41. package/lib/ethereum/info/pulsechainInfo.js +2 -0
  42. package/lib/ethereum/info/rinkebyInfo.js +4 -1
  43. package/lib/ethereum/info/ropstenInfo.js +4 -1
  44. package/lib/ethereum/info/rskInfo.js +2 -0
  45. package/lib/ethereum/info/zksyncInfo.js +5 -0
  46. package/lib/filecoin/filecoinInfo.js +7 -0
  47. package/lib/polkadot/PolkadotEngine.js +7 -4
  48. package/lib/ripple/RippleEngine.js +9 -0
  49. package/lib/solana/SolanaEngine.js +9 -0
  50. package/lib/solana/solanaInfo.js +7 -0
  51. package/lib/tron/TronEngine.js +42 -25
  52. package/lib/tron/tronInfo.js +9 -1
  53. package/lib/tron/tronTypes.js +1 -0
  54. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -2,6 +2,16 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 4.4.0 (2024-05-14)
6
+
7
+ - added: `EdgeCurrencyInfo.customTokenTemplate` fields for all chains that support custom templates.
8
+ - added: Add bulk balance fetching and `onNewTokens` callback to Algorand, Cosmos, Solana, XRP, and Tron engines
9
+ - fixed: (Polkadot) Show unsuccessful transactions that were charged a fee
10
+
11
+ ## 4.3.3 (2024-05-10)
12
+
13
+ - fixed: (DOT) Fix incorrect insufficient funds error for max spend of native DOT currency in Polkadot engine
14
+
5
15
  ## 4.3.2 (2024-05-09)
6
16
 
7
17
  - changed: Update Zcash and Tezos nodes.
@@ -1,2 +1,2 @@
1
- (self.webpackChunkedge_currency_accountbased=self.webpackChunkedge_currency_accountbased||[]).push([[7741],{37011:function(ae,_,p){"use strict";p.r(_),p.d(_,{AlgorandTools:function(){return he},makeCurrencyEngine:function(){return Ee},makeCurrencyTools:function(){return De}});var I=p(88814),f=p(77591),S=p(20918),b=p(79014),v=p(76714),e=p(82448),F=p(62177);const Q=(0,e.su)({latestRound:(0,e.Vk)(e.mH,0),latestTxid:(0,e.Vk)(e.XC,"")}),J=(0,e.su)({amount:e.mH,assets:(0,e._2)((0,e.su)({amount:e.mH,"asset-id":e.mH})),"min-balance":e.mH,round:e.mH}),Y=(0,e.su)({"confirmed-round":e.mH,fee:e.mH,"first-valid":e.mH,id:e.XC,note:(0,e.Zz)(e.XC),"round-time":e.mH,sender:e.XC,"tx-type":e.XC}).withRest,N=(0,e.Wf)("pay"),G=(0,e.su)({"payment-transaction":(0,e.su)({amount:e.mH,"close-amount":e.mH,receiver:e.XC}),"tx-type":N}),ee=(0,e.Wf)("axfer"),te=(0,e.su)({"asset-transfer-transaction":(0,e.su)({amount:e.mH,"asset-id":e.mH,receiver:e.XC}),"tx-type":ee}),y=(0,e.su)({"confirmed-round":e.mH,fee:e.mH,"first-valid":e.mH,note:(0,e.Zz)(e.XC),"round-time":e.mH,sender:e.XC,"tx-type":e.XC}).withRest,k=(0,e.Wf)("appl"),x=(0,e.su)({"inner-txns":(0,e.Zz)((0,e._2)(y)),"tx-type":k}).withRest,O=(0,e.su)({"current-round":e.mH,"next-token":(0,e.Zz)(e.XC),transactions:(0,e._2)(Y)}),B=(0,e.su)({flatFee:e.jK,fee:e.mH,firstRound:e.mH,lastRound:e.mH,genesisID:e.XC,genesisHash:e.XC}),j=(0,e.su)({type:e.XC}).withRest,w=(0,e.su)({encodedTx:e.XC,recipient:(0,e.Zz)(e.XC)}),V=(0,e.su)({type:N,to:e.XC,amount:e.mH}).withRest,ne=(0,e.Vk)((0,e.su)({fee:(0,e.Zz)(e.XC)}),{fee:void 0}),D=(0,e.Vk)((0,e.su)({contractAddress:F.jD})),Z=F.BQ,W=g=>{const t=(0,e.su)({[`${g}Mnemonic`]:e.XC});return(0,e.W1)(n=>({mnemonic:t(n)[`${g}Mnemonic`]}),n=>({[`${g}Mnemonic`]:n.mnemonic}))},se=(0,e.su)({id:(0,e._C)(e.XC,e.mH),method:(0,e.Wf)("algo_signTxn"),params:(0,e.vq)((0,e.vq)((0,e.su)({txn:e.XC,message:(0,e.Zz)(e.XC)})))}),z=(0,e.su)({id:e.mH,jsonrpc:(0,e.Wf)("2.0"),method:(0,e.Wf)("algo_signTxn"),params:(0,e.vq)((0,e._2)((0,e.su)({txn:e.XC,message:(0,e.Zz)(e.XC)})))}).withRest;var X=p(94935),P=p(79325),pe=p(16757),ie=p(99599),ge=Object.defineProperty,we=Object.defineProperties,Te=Object.getOwnPropertyDescriptors,le=Object.getOwnPropertySymbols,Ie=Object.getPrototypeOf,ve=Object.prototype.hasOwnProperty,ke=Object.prototype.propertyIsEnumerable,xe=Reflect.get,ce=(g,t,n)=>t in g?ge(g,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):g[t]=n,q=(g,t)=>{for(var n in t||(t={}))ve.call(t,n)&&ce(g,n,t[n]);if(le)for(var n of le(t))ke.call(t,n)&&ce(g,n,t[n]);return g},Ce=(g,t)=>we(g,Te(t)),Ae=(g,t,n)=>xe(Ie(g),n,t),m=(g,t,n)=>new Promise((s,i)=>{var o=r=>{try{a(n.next(r))}catch(c){i(c)}},l=r=>{try{a(n.throw(r))}catch(c){i(c)}},a=r=>r.done?s(r.value):Promise.resolve(r.value).then(o,l);a((n=n.apply(g,t)).next())});const{Algodv2:re,Indexer:Pe}=I.ZP,ue=5e3,be=3e3;class oe extends pe.P{constructor(t,n,s,i){super(t,n,s,i),this.getRecipientBalance=o=>m(this,null,function*(){try{return(yield this.fetchAccountInfo(o)).amount.toString()}catch{return this.minimumAddressBalance}}),this.engineGetActivationAssets=o=>m(this,null,function*(){return{assetOptions:[{tokenId:null,paymentWalletId:this.walletId,currencyPluginId:this.currencyInfo.pluginId}]}}),this.engineActivateWallet=o=>m(this,[o],function*({activateTokenIds:l,paymentInfo:a}){var r;if(l==null)throw new Error(`Must specify activateTokenIds for ${this.currencyInfo.currencyCode}`);const{tokenId:c,wallet:d}=a!=null?a:{tokenId:null};if(c!=null)throw new Error(`Must activate with ${this.currencyInfo.currencyCode}`);if((d==null?void 0:d.id)!==this.walletId)throw new Error("Must pay with same wallet you are activating token with");const u=this.networkInfo.minimumTxFee.toFixed();let h="0";const A=[];for(const E of l){if(E!==null&&this.allTokensMap[E]==null)throw new Error(`Invalid tokenId to activate ${E}`);const M={tokenId:E,skipChecks:!0,spendTargets:[{publicAddress:this.walletInfo.keys.publicKey,nativeAmount:"0"}]};try{const U=yield this.makeSpend(M);h=(0,f.add)(h,(r=U.parentNetworkFee)!=null?r:u)}catch{h=(0,f.add)(h,u)}A.push(M)}return{paymentTokenId:c,paymentWalletId:this.walletId,fromNativeAmount:"0",networkFee:{tokenId:null,nativeAmount:h,currencyPluginId:this.currencyInfo.pluginId},approve:(...E)=>m(this,[...E],function*(M={}){const{metadata:U}=M,T=[];for(const C of A){const L=yield this.makeSpend(C);L.metadata=q({},U);let H=yield d.signTx(L);H=yield d.broadcastTx(H),T.push(H),yield d.saveTx(H)}return{transactions:T}}),close:()=>m(this,null,function*(){})}}),this.networkInfo=t.networkInfo,this.queryTxMutex=(0,v.jT)(),this.suggestedTransactionParams={flatFee:!1,fee:0,firstRound:0,lastRound:0,genesisID:this.networkInfo.genesisID,genesisHash:this.networkInfo.genesisHash},this.minimumAddressBalance=this.networkInfo.minimumAddressBalance,this.totalReserve=this.minimumAddressBalance,this.otherMethods={parseWalletConnectV2Payload:o=>m(this,null,function*(){try{const a=z(o).params[0][0],r=(0,I.wj)(P.US.parse(a.txn)),c=r.amount!=null?r.amount.toString():"0",d=r.fee.toFixed();let u=null;if(r.type==="axfer"){const h=r.assetIndex.toString();if(this.allTokensMap[h]==null)throw new Error("Unrecognized token");u=h}return{nativeAmount:c,networkFee:d,tokenId:u}}catch(l){throw this.warn("Wallet connect call_request ",l),l}})}}setOtherData(t){this.otherData=Q(t)}fetchAccountInfo(t){return m(this,null,function*(){return yield(0,v.QJ)(this.networkInfo.algodServers.map(n=>()=>m(this,null,function*(){const i=yield new re("",n,"").accountInformation(t).do();return J(i)})))})}queryBalance(){return m(this,null,function*(){try{const t=yield this.fetchAccountInfo(this.walletLocalData.publicKey),{assets:n,amount:s,"min-balance":i,round:o}=t;this.totalReserve=i.toString();const l=[];for(const a of this.enabledTokens)if(a===this.currencyInfo.currencyCode)this.updateBalance(this.currencyInfo.currencyCode,s.toString());else{const r=Object.keys(this.allTokensMap).find(d=>this.allTokensMap[d].currencyCode===a);if(r==null){this.updateBalance(a,"0");continue}const c=n.find(d=>d["asset-id"].toFixed()===r);if(c==null){l.push(r),this.updateBalance(a,"0");continue}this.updateBalance(a,c.amount.toString())}o>this.walletLocalData.blockHeight&&(this.walletLocalData.blockHeight=o,this.walletLocalDataDirty=!0,this.currencyEngineCallbacks.onBlockHeightChanged(this.walletLocalData.blockHeight)),(0,v.dQ)(l,this.walletLocalData.unactivatedTokenIds)||(this.walletLocalData.unactivatedTokenIds=l,this.walletLocalDataDirty=!0,this.currencyEngineCallbacks.onUnactivatedTokenIdsChanged(this.walletLocalData.unactivatedTokenIds))}catch(t){this.log.warn("queryBalance Error ",t)}})}queryTransactionParams(){return m(this,null,function*(){try{const t=yield(0,v.QJ)(this.networkInfo.algodServers.map(n=>()=>m(this,null,function*(){const i=yield new re("",n,"").getTransactionParams().do(),o=B(i);if(o.genesisHash!==this.networkInfo.genesisHash)throw new Error("Server genesisHash mismatch");return o})));this.suggestedTransactionParams=t}catch(t){this.log.warn("queryTransactionParams error:",t)}})}processAlgorandTransaction(t){const{"confirmed-round":n,"round-time":s,"tx-type":i,fee:o,id:l,note:a,sender:r}=t;let c,d,u,h,A,R=!1;const E=[];switch(i){case"pay":{const{amount:T,receiver:C}=G(t)["payment-transaction"];if(u=T.toString(),h=o.toString(),r===this.walletInfo.keys.publicKey)u=`-${(0,f.add)(u,h)}`,R=!0;else if(C===this.walletInfo.keys.publicKey)h="0",E.push(this.walletInfo.keys.publicKey);else return;c=this.currencyInfo.currencyCode,d=null;break}case"axfer":{const{amount:T,"asset-id":C,receiver:L}=te(t)["asset-transfer-transaction"];if(u=T.toString(),h="0",r===this.walletInfo.keys.publicKey)u=`-${u}`,A=o.toString(),R=!0;else if(L===this.walletInfo.keys.publicKey)E.push(this.walletInfo.keys.publicKey);else return;const H=this.allTokensMap[C];if(H==null)return;c=H.currencyCode,d=C.toString();break}case"appl":{const{"inner-txns":T=[]}=x(t);if(T.forEach(C=>this.processAlgorandTransaction(Ce(q({},C),{id:l}))),u="0",h=o.toString(),r===this.walletInfo.keys.publicKey)u=`-${(0,f.add)(u,h)}`,R=!0;else return;c=this.currencyInfo.currencyCode,d=null;break}default:return}const M=[];if(a!=null){const T=P.US.parse(a);try{M.push({memoName:"note",type:"text",value:ie.K.stringify(T)})}catch{M.push({memoName:"note",type:"hex",value:P.YU.stringify(T).toLowerCase()})}}const U={blockHeight:n,currencyCode:c,date:s,isSend:R,memos:M,nativeAmount:u,networkFee:h,ourReceiveAddresses:E,parentNetworkFee:A,signedTx:"",tokenId:d,txid:l,walletId:this.walletId};this.addTransaction(this.currencyInfo.currencyCode,U)}queryTransactions(){return m(this,null,function*(){return yield this.queryTxMutex(()=>m(this,null,function*(){return yield this.queryTransactionsInner()}))})}queryTransactionsInner(){return m(this,null,function*(){const t=this.otherData.latestRound;let n,s=this.otherData.latestRound,i=0,o,l=!0;do{const a=yield(0,v.QJ)(this.networkInfo.indexerServers.map(u=>()=>m(this,null,function*(){const A=yield new Pe({},u,"").lookupAccountTransactions(this.walletLocalData.publicKey).minRound(t).nextToken(o!=null?o:"").do();return O(A)}))),{"next-token":r,transactions:c}=a;if(c.length===0)break;for(const u of c){if(n==null&&(n=u.id,s=u["confirmed-round"]),i=u["confirmed-round"],u.id===this.otherData.latestTxid){l=!1;break}try{this.processAlgorandTransaction(u)}catch(h){this.log.warn("processAlgorandTransaction error:",h)}}s=s!=null?s:this.walletLocalData.blockHeight;const d=(s-i)/(s-t);this.tokenCheckTransactionsStatus[this.currencyInfo.currencyCode]=d,this.updateOnAddressesChecked(),o=r}while(o!=null&&l);n!=null&&this.otherData.latestTxid!==n&&(this.otherData.latestTxid=n,this.otherData.latestRound=s,this.walletLocalDataDirty=!0);for(const a of this.enabledTokens)this.tokenCheckTransactionsStatus[a]=1;this.updateOnAddressesChecked(),this.transactionsChangedArray.length>0&&(this.walletLocalDataDirty=!0,this.currencyEngineCallbacks.onTransactionsChanged(this.transactionsChangedArray),this.transactionsChangedArray=[])})}startEngine(){return m(this,null,function*(){this.engineOn=!0,this.addToLoop("queryBalance",ue).catch(()=>{}),this.addToLoop("queryTransactionParams",ue).catch(()=>{}),this.addToLoop("queryTransactions",be).catch(()=>{}),yield Ae(oe.prototype,this,"startEngine").call(this)})}resyncBlockchain(){return m(this,null,function*(){yield this.killEngine(),yield this.clearBlockchainCache(),yield this.startEngine()})}calcFee(t){const n=t.estimateSize();return Math.max(this.suggestedTransactionParams.fee*n,this.networkInfo.minimumTxFee).toString()}getMaxSpendable(t){return m(this,null,function*(){const{tokenId:n}=t;let s=this.getBalance({tokenId:n});if(n==null&&(s=(0,f.sub)(s,this.totalReserve)),t.spendTargets[0].publicAddress==null)throw new Error("makeSpend Missing publicAddress");const{customNetworkFee:o}=t;let a=ne(o).fee;a==null&&(t.spendTargets[0].nativeAmount="1",a=(yield this.makeSpend(t)).networkFee);const r=(c,d)=>m(this,null,function*(){const u=(0,f.sub)(d,c);if((0,f.lte)(u,"1"))return c;const h=(0,f.add)(c,(0,f.div)(u,"2"));t.spendTargets[0].nativeAmount=h;const A=(0,f.add)(h,a!=null?a:this.networkInfo.minimumTxFee.toString());return(0,f.gt)(A,s)?yield r(c,h):yield r(h,d)});return yield r("0",(0,f.add)(s,"1"))})}makeSpend(t){return m(this,null,function*(){var n,s,i,o;const{edgeSpendInfo:l,currencyCode:a,nativeBalance:r}=this.makeSpendCheck(t),{customNetworkFee:c,memos:d=[],tokenId:u}=l,h=(0,f.sub)(this.getBalance({tokenId:u}),this.totalReserve);if(l.spendTargets.length!==1)throw new Error("Error: only one output allowed");const{nativeAmount:A,publicAddress:R}=l.spendTargets[0];if(R==null)throw new Error("makeSpend Missing publicAddress");if(A==null)throw new X.$D;const{type:E}=(n=(0,e.Vk)(j)(l.otherParams))!=null?n:{type:a===this.currencyInfo.currencyCode?"pay":"axfer"},M=((s=d[0])==null?void 0:s.type)==="text"?ie.K.parse(d[0].value):void 0,U=ne(c).fee;let T,C=A,L="0",H,$,fe;switch(E){case"pay":{if(T=I.ZP.makePaymentTxnWithSuggestedParamsFromObject({to:R,from:this.walletInfo.keys.publicKey,amount:BigInt(A),note:M,suggestedParams:q({},this.suggestedTransactionParams)}),$=U!=null?U:this.calcFee(T),L=$,C=`-${(0,f.add)(C,L)}`,fe=R,(0,f.gt)((0,f.abs)(C),h))throw new X.C_({tokenId:u});break}case"axfer":{const ye=Object.keys(this.allTokensMap).find(Me=>this.allTokensMap[Me].currencyCode===a);if(ye==null)throw new Error("Unrecognized asset");const me=D((o=(i=this.allTokensMap)==null?void 0:i[ye])==null?void 0:o.networkLocation);if(me==null)throw new Error("Unrecognized asset");if(T=I.ZP.makeAssetTransferTxnWithSuggestedParamsFromObject({assetIndex:parseInt(me.contractAddress),to:R,from:this.walletInfo.keys.publicKey,amount:BigInt(A),note:M,suggestedParams:q({},this.suggestedTransactionParams)}),$=U!=null?U:this.calcFee(T),C=`-${C}`,H=$,(0,f.gt)(H,h))throw new X.C_({networkFee:$,tokenId:u});if((0,f.gt)((0,f.abs)(C),r))throw new X.C_({tokenId:u});break}default:throw new Error("Unrecognized transaction type")}T.flatFee=!0,T.fee=parseInt($);const Re={encodedTx:P.YU.stringify((0,I.nJ)(T)),recipient:fe};return{blockHeight:0,currencyCode:a,date:0,isSend:!0,memos:d,nativeAmount:C,networkFee:L,otherParams:Re,ourReceiveAddresses:[],parentNetworkFee:H,signedTx:"",tokenId:u,txid:"",walletId:this.walletId}})}signMessage(t,n){return m(this,null,function*(){const s=W(this.currencyInfo.pluginId)(n),i=(0,I.wj)(P.US.parse(t)),o=I.ZP.mnemonicToSecretKey(s.mnemonic),l=i.signTxn(o.sk);return P.US.stringify(l)})}signTx(t,n){return m(this,null,function*(){const{encodedTx:s,recipient:i}=w((0,v.Xp)(t)),o=(0,I.wj)(Uint8Array.from(P.YU.parse(s)));i!=null&&(yield this.checkRecipientMinimumBalance(this.getRecipientBalance,o.amount.toString(),i));const l=W(this.currencyInfo.pluginId)(n),a=I.ZP.mnemonicToSecretKey(l.mnemonic),r=o.signTxn(a.sk),c=P.YU.stringify(r);return t.signedTx=c,t})}broadcastTx(t){return m(this,null,function*(){const n=Uint8Array.from(P.YU.parse(t.signedTx));try{const{txId:s}=yield(0,v.QJ)(this.networkInfo.algodServers.map(i=>()=>m(this,null,function*(){return yield new re("",i,"").sendRawTransaction(n).do()})));t.txid=s,t.date=Date.now()/1e3}catch(s){throw this.warn("FAILURE broadcastTx failed: ",s),s}return this.warn(`SUCCESS broadcastTx
2
- ${(0,v.oX)(t)}`),t})}}function Ee(g,t,n,s){return m(this,null,function*(){const i=Z(n),o=new oe(g,t,i,s);return yield o.loadEngine(),o})}var Se=p(48764).Buffer,K=(g,t,n)=>new Promise((s,i)=>{var o=r=>{try{a(n.next(r))}catch(c){i(c)}},l=r=>{try{a(n.throw(r))}catch(c){i(c)}},a=r=>r.done?s(r.value):Promise.resolve(r.value).then(o,l);a((n=n.apply(g,t)).next())});const{isValidAddress:de,mnemonicFromSeed:Oe}=I.ZP;class he{constructor(t){const{builtinTokens:n,currencyInfo:s,io:i}=t;this.io=i,this.currencyInfo=s,this.builtinTokens=n}getDisplayPrivateKey(t){return K(this,null,function*(){const{pluginId:n}=this.currencyInfo;return W(n)(t.keys).mnemonic})}getDisplayPublicKey(t){return K(this,null,function*(){const{keys:n}=Z(t);return n.publicKey})}importPrivateKey(t){return K(this,null,function*(){const{pluginId:n}=this.currencyInfo;return I.ZP.mnemonicToSecretKey(t),{[`${n}Mnemonic`]:t}})}createPrivateKey(t){return K(this,null,function*(){if(t!==this.currencyInfo.walletType)throw new Error("InvalidWalletType");const n=Se.from(this.io.random(32)),s=Oe(n);return yield this.importPrivateKey(s)})}derivePublicKey(t){return K(this,null,function*(){const{pluginId:n}=this.currencyInfo;if(t.type!==this.currencyInfo.walletType)throw new Error("InvalidWalletType");const s=W(n)(t.keys);return{publicKey:I.ZP.mnemonicToSecretKey(s.mnemonic).addr}})}parseUri(t,n,s){return K(this,null,function*(){const{pluginId:i}=this.currencyInfo,o={[i]:!0},{parsedUri:l,edgeParsedUri:a}=(0,b.k)(this.currencyInfo,t,o,this.builtinTokens,n!=null?n:this.currencyInfo.currencyCode,s);let r="";if(a.publicAddress!=null&&(r=a.publicAddress),!de(r))throw new Error("InvalidPublicAddressError");return a.uniqueIdentifier=l.query.memo,a})}encodeUri(t){return K(this,arguments,function*(n,s=[]){const{pluginId:i}=this.currencyInfo,{nativeAmount:o,currencyCode:l,publicAddress:a}=n;if(!de(a))throw new Error("InvalidPublicAddressError");let r;if(typeof o=="string"){const d=(0,v.Qs)(l!=null?l:this.currencyInfo.currencyCode,this.currencyInfo,s,this.builtinTokens);if(d==null)throw new Error("InternalErrorInvalidCurrencyCode");r=(0,f.div)(o,d.multiplier,18)}return(0,b.Q)(n,i,r)})}getTokenId(t){return K(this,null,function*(){(0,S.Rp)(t);const n=D(t.networkLocation);if(n==null)throw new Error("ErrorInvalidContractAddress");return n.contractAddress})}}function De(g){return K(this,null,function*(){return new he(g)})}},79014:function(ae,_,p){"use strict";p.d(_,{Q:function(){return te},k:function(){return ee}});var I=p(77591),f=p.n(I),S=p(24350),b=p(84564),v=p.n(b),e=p(76714),F=Object.defineProperty,Q=Object.getOwnPropertySymbols,J=Object.prototype.hasOwnProperty,Y=Object.prototype.propertyIsEnumerable,N=(y,k,x)=>k in y?F(y,k,{enumerable:!0,configurable:!0,writable:!0,value:x}):y[k]=x,G=(y,k)=>{for(var x in k||(k={}))J.call(k,x)&&N(y,x,k[x]);if(Q)for(var x of Q(k))Y.call(k,x)&&N(y,x,k[x]);return y};function ee(y,k,x,O,B,j=[]){const w=G({},v()(k,{},!0)),V=k.startsWith(`${y.pluginId}://`);if(w.protocol!=null&&(w.protocol=w.protocol.replace(":","")),w.protocol!=null&&w.protocol!==""&&!x[w.protocol])throw new Error(`Uri protocol '${w.protocol}' is not supported for ${y.pluginId}.`);if(w.host===""&&w.pathname==="")throw new Error("Path and host not found in uri.");const D={publicAddress:w.host!==""?w.host:w.pathname.split("/")[0]},Z=w.query.label,W=w.query.message,se=w.query.category;(Z!=null||W!=null||se!=null||V)&&(D.metadata={},D.metadata.name=Z,D.metadata.notes=W,D.metadata.category=se,D.metadata.gateway=V!=null?V:!1);const z=w.query.amount;if(z!=null&&typeof z=="string"){B==null&&(B=y.currencyCode);const X=(0,e.Qs)(B!=null?B:"",y,j,O);if(X==null)throw new Error("InternalErrorInvalidCurrencyCode");let P=(0,I.mul)(z,X.multiplier);P=(0,I.toFixed)(P,0,0),D.nativeAmount=P,D.currencyCode=B}return{edgeParsedUri:D,parsedUri:w}}function te(y,k,x){if(y.publicAddress==null)throw new Error("InvalidPublicAddressError");if(x==null&&y.label==null&&y.message==null)return y.publicAddress;{let O="";x!=null&&(O+="amount="+x+"&"),(y.label!=null||y.message!=null)&&(typeof y.label=="string"&&(O+="label="+y.label+"&"),typeof y.message=="string"&&(O+="message="+y.message+"&")),O=O.substr(0,O.length-1);const B={scheme:k,path:y.publicAddress,query:O};return(0,S.qC)(B)}}},99599:function(ae,_,p){"use strict";p.d(_,{K:function(){return I}});const I={parse(f){const S=encodeURI(f),b=new Uint8Array(S.length);let v=0;for(let e=0;e<S.length;++e){const F=S.charCodeAt(e);F===37?(b[v++]=parseInt(S.slice(e+1,e+3),16),e+=2):b[v++]=F}return b.subarray(0,v)},stringify(f){let S="";for(let b=0;b<f.length;++b){const v=f[b];S+="%"+(v>>4).toString(16)+(v&15).toString(16)}return decodeURIComponent(S)}}},55024:function(){}}]);
1
+ (self.webpackChunkedge_currency_accountbased=self.webpackChunkedge_currency_accountbased||[]).push([[7741],{37011:function(ae,_,p){"use strict";p.r(_),p.d(_,{AlgorandTools:function(){return he},makeCurrencyEngine:function(){return Ee},makeCurrencyTools:function(){return De}});var I=p(88814),d=p(77591),S=p(20918),b=p(79014),k=p(76714),e=p(82448),F=p(62177);const Q=(0,e.su)({latestRound:(0,e.Vk)(e.mH,0),latestTxid:(0,e.Vk)(e.XC,"")}),J=(0,e.su)({amount:e.mH,assets:(0,e._2)((0,e.su)({amount:e.mH,"asset-id":e.mH})),"min-balance":e.mH,round:e.mH}),Y=(0,e.su)({"confirmed-round":e.mH,fee:e.mH,"first-valid":e.mH,id:e.XC,note:(0,e.Zz)(e.XC),"round-time":e.mH,sender:e.XC,"tx-type":e.XC}).withRest,$=(0,e.Wf)("pay"),G=(0,e.su)({"payment-transaction":(0,e.su)({amount:e.mH,"close-amount":e.mH,receiver:e.XC}),"tx-type":$}),ee=(0,e.Wf)("axfer"),te=(0,e.su)({"asset-transfer-transaction":(0,e.su)({amount:e.mH,"asset-id":e.mH,receiver:e.XC}),"tx-type":ee}),y=(0,e.su)({"confirmed-round":e.mH,fee:e.mH,"first-valid":e.mH,note:(0,e.Zz)(e.XC),"round-time":e.mH,sender:e.XC,"tx-type":e.XC}).withRest,v=(0,e.Wf)("appl"),x=(0,e.su)({"inner-txns":(0,e.Zz)((0,e._2)(y)),"tx-type":v}).withRest,O=(0,e.su)({"current-round":e.mH,"next-token":(0,e.Zz)(e.XC),transactions:(0,e._2)(Y)}),K=(0,e.su)({flatFee:e.jK,fee:e.mH,firstRound:e.mH,lastRound:e.mH,genesisID:e.XC,genesisHash:e.XC}),j=(0,e.su)({type:e.XC}).withRest,w=(0,e.su)({encodedTx:e.XC,recipient:(0,e.Zz)(e.XC)}),V=(0,e.su)({type:$,to:e.XC,amount:e.mH}).withRest,ne=(0,e.Vk)((0,e.su)({fee:(0,e.Zz)(e.XC)}),{fee:void 0}),D=(0,e.Vk)((0,e.su)({contractAddress:F.jD})),Z=F.BQ,W=g=>{const t=(0,e.su)({[`${g}Mnemonic`]:e.XC});return(0,e.W1)(n=>({mnemonic:t(n)[`${g}Mnemonic`]}),n=>({[`${g}Mnemonic`]:n.mnemonic}))},se=(0,e.su)({id:(0,e._C)(e.XC,e.mH),method:(0,e.Wf)("algo_signTxn"),params:(0,e.vq)((0,e.vq)((0,e.su)({txn:e.XC,message:(0,e.Zz)(e.XC)})))}),z=(0,e.su)({id:e.mH,jsonrpc:(0,e.Wf)("2.0"),method:(0,e.Wf)("algo_signTxn"),params:(0,e.vq)((0,e._2)((0,e.su)({txn:e.XC,message:(0,e.Zz)(e.XC)})))}).withRest;var X=p(94935),P=p(79325),pe=p(16757),ie=p(99599),ge=Object.defineProperty,we=Object.defineProperties,Te=Object.getOwnPropertyDescriptors,le=Object.getOwnPropertySymbols,Ie=Object.getPrototypeOf,ke=Object.prototype.hasOwnProperty,ve=Object.prototype.propertyIsEnumerable,xe=Reflect.get,ce=(g,t,n)=>t in g?ge(g,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):g[t]=n,q=(g,t)=>{for(var n in t||(t={}))ke.call(t,n)&&ce(g,n,t[n]);if(le)for(var n of le(t))ve.call(t,n)&&ce(g,n,t[n]);return g},Ce=(g,t)=>we(g,Te(t)),Ae=(g,t,n)=>xe(Ie(g),n,t),m=(g,t,n)=>new Promise((s,i)=>{var o=r=>{try{a(n.next(r))}catch(u){i(u)}},c=r=>{try{a(n.throw(r))}catch(u){i(u)}},a=r=>r.done?s(r.value):Promise.resolve(r.value).then(o,c);a((n=n.apply(g,t)).next())});const{Algodv2:re,Indexer:Pe}=I.ZP,ue=5e3,be=3e3;class oe extends pe.P{constructor(t,n,s,i){super(t,n,s,i),this.getRecipientBalance=o=>m(this,null,function*(){try{return(yield this.fetchAccountInfo(o)).amount.toString()}catch{return this.minimumAddressBalance}}),this.engineGetActivationAssets=o=>m(this,null,function*(){return{assetOptions:[{tokenId:null,paymentWalletId:this.walletId,currencyPluginId:this.currencyInfo.pluginId}]}}),this.engineActivateWallet=o=>m(this,[o],function*({activateTokenIds:c,paymentInfo:a}){var r;if(c==null)throw new Error(`Must specify activateTokenIds for ${this.currencyInfo.currencyCode}`);const{tokenId:u,wallet:h}=a!=null?a:{tokenId:null};if(u!=null)throw new Error(`Must activate with ${this.currencyInfo.currencyCode}`);if((h==null?void 0:h.id)!==this.walletId)throw new Error("Must pay with same wallet you are activating token with");const l=this.networkInfo.minimumTxFee.toFixed();let f="0";const A=[];for(const E of c){if(E!==null&&this.allTokensMap[E]==null)throw new Error(`Invalid tokenId to activate ${E}`);const U={tokenId:E,skipChecks:!0,spendTargets:[{publicAddress:this.walletInfo.keys.publicKey,nativeAmount:"0"}]};try{const H=yield this.makeSpend(U);f=(0,d.add)(f,(r=H.parentNetworkFee)!=null?r:l)}catch{f=(0,d.add)(f,l)}A.push(U)}return{paymentTokenId:u,paymentWalletId:this.walletId,fromNativeAmount:"0",networkFee:{tokenId:null,nativeAmount:f,currencyPluginId:this.currencyInfo.pluginId},approve:(...E)=>m(this,[...E],function*(U={}){const{metadata:H}=U,T=[];for(const C of A){const L=yield this.makeSpend(C);L.metadata=q({},H);let M=yield h.signTx(L);M=yield h.broadcastTx(M),T.push(M),yield h.saveTx(M)}return{transactions:T}}),close:()=>m(this,null,function*(){})}}),this.networkInfo=t.networkInfo,this.queryTxMutex=(0,k.jT)(),this.suggestedTransactionParams={flatFee:!1,fee:0,firstRound:0,lastRound:0,genesisID:this.networkInfo.genesisID,genesisHash:this.networkInfo.genesisHash},this.minimumAddressBalance=this.networkInfo.minimumAddressBalance,this.totalReserve=this.minimumAddressBalance,this.otherMethods={parseWalletConnectV2Payload:o=>m(this,null,function*(){try{const a=z(o).params[0][0],r=(0,I.wj)(P.US.parse(a.txn)),u=r.amount!=null?r.amount.toString():"0",h=r.fee.toFixed();let l=null;if(r.type==="axfer"){const f=r.assetIndex.toString();if(this.allTokensMap[f]==null)throw new Error("Unrecognized token");l=f}return{nativeAmount:u,networkFee:h,tokenId:l}}catch(c){throw this.warn("Wallet connect call_request ",c),c}})}}setOtherData(t){this.otherData=Q(t)}fetchAccountInfo(t){return m(this,null,function*(){return yield(0,k.QJ)(this.networkInfo.algodServers.map(n=>()=>m(this,null,function*(){const i=yield new re("",n,"").accountInformation(t).do();return J(i)})))})}queryBalance(){return m(this,null,function*(){try{const t=yield this.fetchAccountInfo(this.walletLocalData.publicKey),{assets:n,amount:s,"min-balance":i,round:o}=t;this.updateBalance(this.currencyInfo.currencyCode,s.toString()),this.totalReserve=i.toString();const c=[],a=[];for(const[r,u]of Object.entries(this.allTokensMap)){const h=n.find(l=>l["asset-id"].toFixed()===r);if(h!=null){const l=h.amount.toString();this.updateBalance(u.currencyCode,l),(0,d.gt)(l,"0")&&!this.enabledTokenIds.includes(r)&&c.push(r)}else this.updateBalance(u.currencyCode,"0"),this.enabledTokenIds.includes(r)&&a.push(r)}c.length>0&&this.currencyEngineCallbacks.onNewTokens(c),o>this.walletLocalData.blockHeight&&(this.walletLocalData.blockHeight=o,this.walletLocalDataDirty=!0,this.currencyEngineCallbacks.onBlockHeightChanged(this.walletLocalData.blockHeight)),(0,k.dQ)(a,this.walletLocalData.unactivatedTokenIds)||(this.walletLocalData.unactivatedTokenIds=a,this.walletLocalDataDirty=!0,this.currencyEngineCallbacks.onUnactivatedTokenIdsChanged(this.walletLocalData.unactivatedTokenIds))}catch(t){this.log.warn("queryBalance Error ",t)}})}queryTransactionParams(){return m(this,null,function*(){try{const t=yield(0,k.QJ)(this.networkInfo.algodServers.map(n=>()=>m(this,null,function*(){const i=yield new re("",n,"").getTransactionParams().do(),o=K(i);if(o.genesisHash!==this.networkInfo.genesisHash)throw new Error("Server genesisHash mismatch");return o})));this.suggestedTransactionParams=t}catch(t){this.log.warn("queryTransactionParams error:",t)}})}processAlgorandTransaction(t){const{"confirmed-round":n,"round-time":s,"tx-type":i,fee:o,id:c,note:a,sender:r}=t;let u,h,l,f,A,R=!1;const E=[];switch(i){case"pay":{const{amount:T,receiver:C}=G(t)["payment-transaction"];if(l=T.toString(),f=o.toString(),r===this.walletInfo.keys.publicKey)l=`-${(0,d.add)(l,f)}`,R=!0;else if(C===this.walletInfo.keys.publicKey)f="0",E.push(this.walletInfo.keys.publicKey);else return;u=this.currencyInfo.currencyCode,h=null;break}case"axfer":{const{amount:T,"asset-id":C,receiver:L}=te(t)["asset-transfer-transaction"];if(l=T.toString(),f="0",r===this.walletInfo.keys.publicKey)l=`-${l}`,A=o.toString(),R=!0;else if(L===this.walletInfo.keys.publicKey)E.push(this.walletInfo.keys.publicKey);else return;const M=this.allTokensMap[C];if(M==null)return;u=M.currencyCode,h=C.toString();break}case"appl":{const{"inner-txns":T=[]}=x(t);if(T.forEach(C=>this.processAlgorandTransaction(Ce(q({},C),{id:c}))),l="0",f=o.toString(),r===this.walletInfo.keys.publicKey)l=`-${(0,d.add)(l,f)}`,R=!0;else return;u=this.currencyInfo.currencyCode,h=null;break}default:return}const U=[];if(a!=null){const T=P.US.parse(a);try{U.push({memoName:"note",type:"text",value:ie.K.stringify(T)})}catch{U.push({memoName:"note",type:"hex",value:P.YU.stringify(T).toLowerCase()})}}const H={blockHeight:n,currencyCode:u,date:s,isSend:R,memos:U,nativeAmount:l,networkFee:f,ourReceiveAddresses:E,parentNetworkFee:A,signedTx:"",tokenId:h,txid:c,walletId:this.walletId};this.addTransaction(this.currencyInfo.currencyCode,H)}queryTransactions(){return m(this,null,function*(){return yield this.queryTxMutex(()=>m(this,null,function*(){return yield this.queryTransactionsInner()}))})}queryTransactionsInner(){return m(this,null,function*(){const t=this.otherData.latestRound;let n,s=this.otherData.latestRound,i=0,o,c=!0;do{const a=yield(0,k.QJ)(this.networkInfo.indexerServers.map(l=>()=>m(this,null,function*(){const A=yield new Pe({},l,"").lookupAccountTransactions(this.walletLocalData.publicKey).minRound(t).nextToken(o!=null?o:"").do();return O(A)}))),{"next-token":r,transactions:u}=a;if(u.length===0)break;for(const l of u){if(n==null&&(n=l.id,s=l["confirmed-round"]),i=l["confirmed-round"],l.id===this.otherData.latestTxid){c=!1;break}try{this.processAlgorandTransaction(l)}catch(f){this.log.warn("processAlgorandTransaction error:",f)}}s=s!=null?s:this.walletLocalData.blockHeight;const h=(s-i)/(s-t);this.tokenCheckTransactionsStatus[this.currencyInfo.currencyCode]=h,this.updateOnAddressesChecked(),o=r}while(o!=null&&c);n!=null&&this.otherData.latestTxid!==n&&(this.otherData.latestTxid=n,this.otherData.latestRound=s,this.walletLocalDataDirty=!0);for(const a of this.enabledTokens)this.tokenCheckTransactionsStatus[a]=1;this.updateOnAddressesChecked(),this.transactionsChangedArray.length>0&&(this.walletLocalDataDirty=!0,this.currencyEngineCallbacks.onTransactionsChanged(this.transactionsChangedArray),this.transactionsChangedArray=[])})}startEngine(){return m(this,null,function*(){this.engineOn=!0,this.addToLoop("queryBalance",ue).catch(()=>{}),this.addToLoop("queryTransactionParams",ue).catch(()=>{}),this.addToLoop("queryTransactions",be).catch(()=>{}),yield Ae(oe.prototype,this,"startEngine").call(this)})}resyncBlockchain(){return m(this,null,function*(){yield this.killEngine(),yield this.clearBlockchainCache(),yield this.startEngine()})}calcFee(t){const n=t.estimateSize();return Math.max(this.suggestedTransactionParams.fee*n,this.networkInfo.minimumTxFee).toString()}getMaxSpendable(t){return m(this,null,function*(){const{tokenId:n}=t;let s=this.getBalance({tokenId:n});if(n==null&&(s=(0,d.sub)(s,this.totalReserve)),t.spendTargets[0].publicAddress==null)throw new Error("makeSpend Missing publicAddress");const{customNetworkFee:o}=t;let a=ne(o).fee;a==null&&(t.spendTargets[0].nativeAmount="1",a=(yield this.makeSpend(t)).networkFee);const r=(u,h)=>m(this,null,function*(){const l=(0,d.sub)(h,u);if((0,d.lte)(l,"1"))return u;const f=(0,d.add)(u,(0,d.div)(l,"2"));t.spendTargets[0].nativeAmount=f;const A=(0,d.add)(f,a!=null?a:this.networkInfo.minimumTxFee.toString());return(0,d.gt)(A,s)?yield r(u,f):yield r(f,h)});return yield r("0",(0,d.add)(s,"1"))})}makeSpend(t){return m(this,null,function*(){var n,s,i,o;const{edgeSpendInfo:c,currencyCode:a,nativeBalance:r}=this.makeSpendCheck(t),{customNetworkFee:u,memos:h=[],tokenId:l}=c,f=(0,d.sub)(this.getBalance({tokenId:l}),this.totalReserve);if(c.spendTargets.length!==1)throw new Error("Error: only one output allowed");const{nativeAmount:A,publicAddress:R}=c.spendTargets[0];if(R==null)throw new Error("makeSpend Missing publicAddress");if(A==null)throw new X.$D;const{type:E}=(n=(0,e.Vk)(j)(c.otherParams))!=null?n:{type:a===this.currencyInfo.currencyCode?"pay":"axfer"},U=((s=h[0])==null?void 0:s.type)==="text"?ie.K.parse(h[0].value):void 0,H=ne(u).fee;let T,C=A,L="0",M,N,fe;switch(E){case"pay":{if(T=I.ZP.makePaymentTxnWithSuggestedParamsFromObject({to:R,from:this.walletInfo.keys.publicKey,amount:BigInt(A),note:U,suggestedParams:q({},this.suggestedTransactionParams)}),N=H!=null?H:this.calcFee(T),L=N,C=`-${(0,d.add)(C,L)}`,fe=R,(0,d.gt)((0,d.abs)(C),f))throw new X.C_({tokenId:l});break}case"axfer":{const ye=Object.keys(this.allTokensMap).find(Ue=>this.allTokensMap[Ue].currencyCode===a);if(ye==null)throw new Error("Unrecognized asset");const me=D((o=(i=this.allTokensMap)==null?void 0:i[ye])==null?void 0:o.networkLocation);if(me==null)throw new Error("Unrecognized asset");if(T=I.ZP.makeAssetTransferTxnWithSuggestedParamsFromObject({assetIndex:parseInt(me.contractAddress),to:R,from:this.walletInfo.keys.publicKey,amount:BigInt(A),note:U,suggestedParams:q({},this.suggestedTransactionParams)}),N=H!=null?H:this.calcFee(T),C=`-${C}`,M=N,(0,d.gt)(M,f))throw new X.C_({networkFee:N,tokenId:l});if((0,d.gt)((0,d.abs)(C),r))throw new X.C_({tokenId:l});break}default:throw new Error("Unrecognized transaction type")}T.flatFee=!0,T.fee=parseInt(N);const Re={encodedTx:P.YU.stringify((0,I.nJ)(T)),recipient:fe};return{blockHeight:0,currencyCode:a,date:0,isSend:!0,memos:h,nativeAmount:C,networkFee:L,otherParams:Re,ourReceiveAddresses:[],parentNetworkFee:M,signedTx:"",tokenId:l,txid:"",walletId:this.walletId}})}signMessage(t,n){return m(this,null,function*(){const s=W(this.currencyInfo.pluginId)(n),i=(0,I.wj)(P.US.parse(t)),o=I.ZP.mnemonicToSecretKey(s.mnemonic),c=i.signTxn(o.sk);return P.US.stringify(c)})}signTx(t,n){return m(this,null,function*(){const{encodedTx:s,recipient:i}=w((0,k.Xp)(t)),o=(0,I.wj)(Uint8Array.from(P.YU.parse(s)));i!=null&&(yield this.checkRecipientMinimumBalance(this.getRecipientBalance,o.amount.toString(),i));const c=W(this.currencyInfo.pluginId)(n),a=I.ZP.mnemonicToSecretKey(c.mnemonic),r=o.signTxn(a.sk),u=P.YU.stringify(r);return t.signedTx=u,t})}broadcastTx(t){return m(this,null,function*(){const n=Uint8Array.from(P.YU.parse(t.signedTx));try{const{txId:s}=yield(0,k.QJ)(this.networkInfo.algodServers.map(i=>()=>m(this,null,function*(){return yield new re("",i,"").sendRawTransaction(n).do()})));t.txid=s,t.date=Date.now()/1e3}catch(s){throw this.warn("FAILURE broadcastTx failed: ",s),s}return this.warn(`SUCCESS broadcastTx
2
+ ${(0,k.oX)(t)}`),t})}}function Ee(g,t,n,s){return m(this,null,function*(){const i=Z(n),o=new oe(g,t,i,s);return yield o.loadEngine(),o})}var Se=p(48764).Buffer,B=(g,t,n)=>new Promise((s,i)=>{var o=r=>{try{a(n.next(r))}catch(u){i(u)}},c=r=>{try{a(n.throw(r))}catch(u){i(u)}},a=r=>r.done?s(r.value):Promise.resolve(r.value).then(o,c);a((n=n.apply(g,t)).next())});const{isValidAddress:de,mnemonicFromSeed:Oe}=I.ZP;class he{constructor(t){const{builtinTokens:n,currencyInfo:s,io:i}=t;this.io=i,this.currencyInfo=s,this.builtinTokens=n}getDisplayPrivateKey(t){return B(this,null,function*(){const{pluginId:n}=this.currencyInfo;return W(n)(t.keys).mnemonic})}getDisplayPublicKey(t){return B(this,null,function*(){const{keys:n}=Z(t);return n.publicKey})}importPrivateKey(t){return B(this,null,function*(){const{pluginId:n}=this.currencyInfo;return I.ZP.mnemonicToSecretKey(t),{[`${n}Mnemonic`]:t}})}createPrivateKey(t){return B(this,null,function*(){if(t!==this.currencyInfo.walletType)throw new Error("InvalidWalletType");const n=Se.from(this.io.random(32)),s=Oe(n);return yield this.importPrivateKey(s)})}derivePublicKey(t){return B(this,null,function*(){const{pluginId:n}=this.currencyInfo;if(t.type!==this.currencyInfo.walletType)throw new Error("InvalidWalletType");const s=W(n)(t.keys);return{publicKey:I.ZP.mnemonicToSecretKey(s.mnemonic).addr}})}parseUri(t,n,s){return B(this,null,function*(){const{pluginId:i}=this.currencyInfo,o={[i]:!0},{parsedUri:c,edgeParsedUri:a}=(0,b.k)(this.currencyInfo,t,o,this.builtinTokens,n!=null?n:this.currencyInfo.currencyCode,s);let r="";if(a.publicAddress!=null&&(r=a.publicAddress),!de(r))throw new Error("InvalidPublicAddressError");return a.uniqueIdentifier=c.query.memo,a})}encodeUri(t){return B(this,arguments,function*(n,s=[]){const{pluginId:i}=this.currencyInfo,{nativeAmount:o,currencyCode:c,publicAddress:a}=n;if(!de(a))throw new Error("InvalidPublicAddressError");let r;if(typeof o=="string"){const h=(0,k.Qs)(c!=null?c:this.currencyInfo.currencyCode,this.currencyInfo,s,this.builtinTokens);if(h==null)throw new Error("InternalErrorInvalidCurrencyCode");r=(0,d.div)(o,h.multiplier,18)}return(0,b.Q)(n,i,r)})}getTokenId(t){return B(this,null,function*(){(0,S.Rp)(t);const n=D(t.networkLocation);if(n==null)throw new Error("ErrorInvalidContractAddress");return n.contractAddress})}}function De(g){return B(this,null,function*(){return new he(g)})}},79014:function(ae,_,p){"use strict";p.d(_,{Q:function(){return te},k:function(){return ee}});var I=p(77591),d=p.n(I),S=p(24350),b=p(84564),k=p.n(b),e=p(76714),F=Object.defineProperty,Q=Object.getOwnPropertySymbols,J=Object.prototype.hasOwnProperty,Y=Object.prototype.propertyIsEnumerable,$=(y,v,x)=>v in y?F(y,v,{enumerable:!0,configurable:!0,writable:!0,value:x}):y[v]=x,G=(y,v)=>{for(var x in v||(v={}))J.call(v,x)&&$(y,x,v[x]);if(Q)for(var x of Q(v))Y.call(v,x)&&$(y,x,v[x]);return y};function ee(y,v,x,O,K,j=[]){const w=G({},k()(v,{},!0)),V=v.startsWith(`${y.pluginId}://`);if(w.protocol!=null&&(w.protocol=w.protocol.replace(":","")),w.protocol!=null&&w.protocol!==""&&!x[w.protocol])throw new Error(`Uri protocol '${w.protocol}' is not supported for ${y.pluginId}.`);if(w.host===""&&w.pathname==="")throw new Error("Path and host not found in uri.");const D={publicAddress:w.host!==""?w.host:w.pathname.split("/")[0]},Z=w.query.label,W=w.query.message,se=w.query.category;(Z!=null||W!=null||se!=null||V)&&(D.metadata={},D.metadata.name=Z,D.metadata.notes=W,D.metadata.category=se,D.metadata.gateway=V!=null?V:!1);const z=w.query.amount;if(z!=null&&typeof z=="string"){K==null&&(K=y.currencyCode);const X=(0,e.Qs)(K!=null?K:"",y,j,O);if(X==null)throw new Error("InternalErrorInvalidCurrencyCode");let P=(0,I.mul)(z,X.multiplier);P=(0,I.toFixed)(P,0,0),D.nativeAmount=P,D.currencyCode=K}return{edgeParsedUri:D,parsedUri:w}}function te(y,v,x){if(y.publicAddress==null)throw new Error("InvalidPublicAddressError");if(x==null&&y.label==null&&y.message==null)return y.publicAddress;{let O="";x!=null&&(O+="amount="+x+"&"),(y.label!=null||y.message!=null)&&(typeof y.label=="string"&&(O+="label="+y.label+"&"),typeof y.message=="string"&&(O+="message="+y.message+"&")),O=O.substr(0,O.length-1);const K={scheme:v,path:y.publicAddress,query:O};return(0,S.qC)(K)}}},99599:function(ae,_,p){"use strict";p.d(_,{K:function(){return I}});const I={parse(d){const S=encodeURI(d),b=new Uint8Array(S.length);let k=0;for(let e=0;e<S.length;++e){const F=S.charCodeAt(e);F===37?(b[k++]=parseInt(S.slice(e+1,e+3),16),e+=2):b[k++]=F}return b.subarray(0,k)},stringify(d){let S="";for(let b=0;b<d.length;++b){const k=d[b];S+="%"+(k>>4).toString(16)+(k&15).toString(16)}return decodeURIComponent(S)}}},55024:function(){}}]);
@@ -1,2 +1,2 @@
1
- (self.webpackChunkedge_currency_accountbased=self.webpackChunkedge_currency_accountbased||[]).push([[8222],{79014:function(Qe,ne,y){"use strict";y.d(ne,{Q:function(){return K},k:function(){return re}});var q=y(77591),Te=y.n(q),M=y(24350),L=y(84564),S=y.n(L),te=y(76714),J=Object.defineProperty,I=Object.getOwnPropertySymbols,Y=Object.prototype.hasOwnProperty,oe=Object.prototype.propertyIsEnumerable,z=(k,C,p)=>C in k?J(k,C,{enumerable:!0,configurable:!0,writable:!0,value:p}):k[C]=p,se=(k,C)=>{for(var p in C||(C={}))Y.call(C,p)&&z(k,p,C[p]);if(I)for(var p of I(C))oe.call(C,p)&&z(k,p,C[p]);return k};function re(k,C,p,x,c,ie=[]){const A=se({},S()(C,{},!0)),Z=C.startsWith(`${k.pluginId}://`);if(A.protocol!=null&&(A.protocol=A.protocol.replace(":","")),A.protocol!=null&&A.protocol!==""&&!p[A.protocol])throw new Error(`Uri protocol '${A.protocol}' is not supported for ${k.pluginId}.`);if(A.host===""&&A.pathname==="")throw new Error("Path and host not found in uri.");const B={publicAddress:A.host!==""?A.host:A.pathname.split("/")[0]},ae=A.query.label,ce=A.query.message,le=A.query.category;(ae!=null||ce!=null||le!=null||Z)&&(B.metadata={},B.metadata.name=ae,B.metadata.notes=ce,B.metadata.category=le,B.metadata.gateway=Z!=null?Z:!1);const G=A.query.amount;if(G!=null&&typeof G=="string"){c==null&&(c=k.currencyCode);const ue=(0,te.Qs)(c!=null?c:"",k,ie,x);if(ue==null)throw new Error("InternalErrorInvalidCurrencyCode");let Q=(0,q.mul)(G,ue.multiplier);Q=(0,q.toFixed)(Q,0,0),B.nativeAmount=Q,B.currencyCode=c}return{edgeParsedUri:B,parsedUri:A}}function K(k,C,p){if(k.publicAddress==null)throw new Error("InvalidPublicAddressError");if(p==null&&k.label==null&&k.message==null)return k.publicAddress;{let x="";p!=null&&(x+="amount="+p+"&"),(k.label!=null||k.message!=null)&&(typeof k.label=="string"&&(x+="label="+k.label+"&"),typeof k.message=="string"&&(x+="message="+k.message+"&")),x=x.substr(0,x.length-1);const c={scheme:C,path:k.publicAddress,query:x};return(0,M.qC)(c)}}},94831:function(Qe,ne,y){"use strict";y.r(ne),y.d(ne,{CosmosTools:function(){return Ge},makeCurrencyEngine:function(){return Kn},makeCurrencyTools:function(){return Xn}});var q=y(87137),Te=y(79562),M=y(28972),L=y(74087),S=y(77591),te=y(2153),J=y(42150),I=y(79325),Y=y(20918),oe=y(79014),z=y(76714),se=y(98994),re=y(2387),K=y(39385),k=y(7416),C=y(33359),p=y(24658),x=y(73034),c=y(82448),ie=y(62177);const A=["coin_spent.spender","coin_received.receiver"],Z=(0,c.su)({archivedTxLastCheckTime:(0,c.Vk)(c.mH,0),"coin_spent.spender":(0,c.Vk)(c.XC),"coin_received.receiver":(0,c.Vk)(c.XC)}),pe=(0,ie.jd)((0,c.su)({bech32Address:c.XC,publicKey:c.XC})),B=e=>{const n=(0,c.su)({[`${e}Mnemonic`]:c.XC});return(0,c.W1)(t=>({mnemonic:n(t)[`${e}Mnemonic`]}),t=>({[`${e}Mnemonic`]:t.mnemonic}))},ae=(0,c.su)({ninerealmsClientId:(0,c.Zz)(c.XC)}),ce=(0,c.su)({denom:c.XC,amount:c.XC}),le=(0,c.su)({gasFeeCoin:ce,gasLimit:c.XC,unsignedTxHex:c.XC}),G=(0,c.su)({native_outbound_fee_rune:c.XC,native_tx_fee_rune:c.XC}),ue=(0,c.su)({method:(0,c.Wf)("cosmos_getAccounts"),params:(0,c.su)({})}),Q=(0,c.Wf)("cosmos_signDirect"),we=(0,c.su)({method:Q,params:(0,c.su)({signerAddress:c.XC,signDoc:(0,c.su)({chainId:c.XC,accountNumber:c.XC,authInfoBytes:c.XC,bodyBytes:c.XC})})}),Ae=(0,c.su)({method:(0,c.Wf)("cosmos_signAmino"),params:(0,c.su)({signerAddress:c.XC,signDoc:(0,c.su)({chain_id:c.XC,account_number:c.XC,sequence:c.XC,memo:c.XC,msgs:(0,c._2)((0,c.su)({type:c.XC,value:c.JC})),fee:(0,c.su)({amount:(0,c._2)((0,c.su)({denom:c.XC,amount:c.XC})),gas:c.XC})})})});var ve=(e,n,t)=>new Promise((r,s)=>{var o=a=>{try{i(t.next(a))}catch(u){s(u)}},l=a=>{try{i(t.throw(a))}catch(u){s(u)}},i=a=>a.done?r(a.value):Promise.resolve(a.value).then(o,l);i((t=t.apply(e,n)).next())});const ke=(e,n)=>{const t=ae(n),r={},s=/{{(.*?)}}/g;for(const[o,l]of Object.entries(e.headers)){const i=s.exec(l);i!=null&&(r[o]=t[i[1]])}return{url:e.url,headers:r}},je=(e,n)=>{const{url:t,headers:r}=n;return{execute:s=>ve(void 0,null,function*(){const o={method:"POST",headers:r,body:JSON.stringify(s)};return yield(yield e(t,o)).json()}),disconnect:()=>{}}},en=e=>ve(void 0,null,function*(){const n=yield x.Comet38Client.create(e),t=(yield n.status()).nodeInfo.version;return t.startsWith("0.38.")?n:t.startsWith("0.37.")?yield x.Tendermint37Client.create(e):yield x.Tendermint34Client.create(e)}),be=(e,n)=>ve(void 0,null,function*(){const t=yield p.StargateClient.create(yield en(je(e,n))),r=t.forceGetCometClient();return{queryClient:p.QueryClient.withExtensions(r,p.setupAuthExtension,p.setupBankExtension,p.setupStakingExtension,p.setupTxExtension,p.setupIbcExtension),stargateClient:t,cometClient:r}}),nn=e=>{var n;const[t,...r]=e.split("."),s=e.includes("/"),o=r.join("."),l=(n=o==null?void 0:o.split("-"))==null?void 0:n[0];return{chain:t,symbol:o,ticker:l,synth:s}},$=e=>e.reduce((n,t)=>{try{return(0,C.addCoins)(n,t)}catch{}return n}),Se=(0,c.Wf)("amount"),tn=(0,c.Wf)("receiver"),on=(0,c.Wf)("spender"),sn=(0,c.Wf)("amount","receiver","spender"),rn=(0,c.su)({type:(0,c.Wf)("coin_received"),attributes:(0,c.vq)((0,c.su)({key:Se,value:c.XC}),(0,c.su)({key:tn,value:c.XC}))}),an=(0,c.su)({type:(0,c.Wf)("coin_spent"),attributes:(0,c.vq)((0,c.su)({key:Se,value:c.XC}),(0,c.su)({key:on,value:c.XC}))}),cn=(e,n)=>{const t=new Map;for(const s of e){const o={type:s.type,attributes:s.attributes.filter(a=>(0,c.Vk)(sn)(a.key)!=null).sort((a,u)=>a.key<u.key?-1:1)},l=(0,c.Vk)(rn)(o);if(l!=null){const[a,u]=l.attributes.map(d=>d.value);if(u!==n)continue;Ie(a).forEach(d=>{var v;const g=d.amount,m=(v=t.get(d.denom))!=null?v:"0";t.set(d.denom,(0,S.add)(g,m))});continue}const i=(0,c.Vk)(an)(o);if(i!=null){const[a,u]=i.attributes.map(d=>d.value);if(u!==n)continue;Ie(a).forEach(d=>{var v;const g=`-${d.amount}`,m=(v=t.get(d.denom))!=null?v:"0";t.set(d.denom,(0,S.add)(g,m))})}}const r=[];return t.forEach((s,o)=>{s!=="0"&&r.push({denom:o,amount:s})}),r},de=e=>{try{return I.YU.parse(e)}catch{return I.US.parse(e)}},Ie=e=>e.replace(/\s/g,"").split(",").filter(Boolean).map(n=>{var t;const r=n.match(/^([0-9]+)([a-zA-Z][a-zA-Z0-9/-]{2,127})$/);if(r==null)throw new Error(`Got an invalid coin string: ${e}`);return{amount:(t=r[1].replace(/^0+/,""))!=null?t:"0",denom:r[2]}}),ln=(e,n)=>{const t=J.chains.find(l=>l.bech32_prefix===(0,M.fromBech32)(n).prefix);if(t==null)throw new Error("Unrecognized denom");const r=t.chain_name,s=(0,k.getIbcInfo)(J.ibc,e,r);if(s==null)throw new Error(`No IBC channels between ${e} and ${r}`);const o=(0,k.getTransferChannel)(s);return e<r?{channel:o.chain_1.channel_id,port:o.chain_1.port_id}:{channel:o.chain_2.channel_id,port:o.chain_2.port_id}};var un=y(43720),E=y.n(un),dn=y(62100),h=y.n(dn);const Hn="common";function Pe(){return{chain:"",symbol:"",ticker:"",synth:!1}}const X={encode(e,n=h().Writer.create()){return e.chain!==""&&n.uint32(10).string(e.chain),e.symbol!==""&&n.uint32(18).string(e.symbol),e.ticker!==""&&n.uint32(26).string(e.ticker),e.synth===!0&&n.uint32(32).bool(e.synth),n},decode(e,n){const t=e instanceof h().Reader?e:h().Reader.create(e);let r=n===void 0?t.len:t.pos+n;const s=Pe();for(;t.pos<r;){const o=t.uint32();switch(o>>>3){case 1:if(o!==10)break;s.chain=t.string();continue;case 2:if(o!==18)break;s.symbol=t.string();continue;case 3:if(o!==26)break;s.ticker=t.string();continue;case 4:if(o!==32)break;s.synth=t.bool();continue}if((o&7)===4||o===0)break;t.skipType(o&7)}return s},fromJSON(e){return{chain:P(e.chain)?globalThis.String(e.chain):"",symbol:P(e.symbol)?globalThis.String(e.symbol):"",ticker:P(e.ticker)?globalThis.String(e.ticker):"",synth:P(e.synth)?globalThis.Boolean(e.synth):!1}},toJSON(e){const n={};return e.chain!==""&&(n.chain=e.chain),e.symbol!==""&&(n.symbol=e.symbol),e.ticker!==""&&(n.ticker=e.ticker),e.synth===!0&&(n.synth=e.synth),n},create(e){return X.fromPartial(e!=null?e:{})},fromPartial(e){var n,t,r,s;const o=Pe();return o.chain=(n=e.chain)!=null?n:"",o.symbol=(t=e.symbol)!=null?t:"",o.ticker=(r=e.ticker)!=null?r:"",o.synth=(s=e.synth)!=null?s:!1,o}};function xe(){return{asset:void 0,amount:"",decimals:E().ZERO}}const w={encode(e,n=h().Writer.create()){return e.asset!==void 0&&X.encode(e.asset,n.uint32(10).fork()).ldelim(),e.amount!==""&&n.uint32(18).string(e.amount),e.decimals.isZero()||n.uint32(24).int64(e.decimals),n},decode(e,n){const t=e instanceof h().Reader?e:h().Reader.create(e);let r=n===void 0?t.len:t.pos+n;const s=xe();for(;t.pos<r;){const o=t.uint32();switch(o>>>3){case 1:if(o!==10)break;s.asset=X.decode(t,t.uint32());continue;case 2:if(o!==18)break;s.amount=t.string();continue;case 3:if(o!==24)break;s.decimals=t.int64();continue}if((o&7)===4||o===0)break;t.skipType(o&7)}return s},fromJSON(e){return{asset:P(e.asset)?X.fromJSON(e.asset):void 0,amount:P(e.amount)?globalThis.String(e.amount):"",decimals:P(e.decimals)?E().fromValue(e.decimals):E().ZERO}},toJSON(e){const n={};return e.asset!==void 0&&(n.asset=X.toJSON(e.asset)),e.amount!==""&&(n.amount=e.amount),e.decimals.isZero()||(n.decimals=(e.decimals||E().ZERO).toString()),n},create(e){return w.fromPartial(e!=null?e:{})},fromPartial(e){var n;const t=xe();return t.asset=e.asset!==void 0&&e.asset!==null?X.fromPartial(e.asset):void 0,t.amount=(n=e.amount)!=null?n:"",t.decimals=e.decimals!==void 0&&e.decimals!==null?E().fromValue(e.decimals):E().ZERO,t}};function Ee(){return{secp256k1:"",ed25519:""}}const hn={encode(e,n=h().Writer.create()){return e.secp256k1!==""&&n.uint32(10).string(e.secp256k1),e.ed25519!==""&&n.uint32(18).string(e.ed25519),n},decode(e,n){const t=e instanceof h().Reader?e:h().Reader.create(e);let r=n===void 0?t.len:t.pos+n;const s=Ee();for(;t.pos<r;){const o=t.uint32();switch(o>>>3){case 1:if(o!==10)break;s.secp256k1=t.string();continue;case 2:if(o!==18)break;s.ed25519=t.string();continue}if((o&7)===4||o===0)break;t.skipType(o&7)}return s},fromJSON(e){return{secp256k1:P(e.secp256k1)?globalThis.String(e.secp256k1):"",ed25519:P(e.ed25519)?globalThis.String(e.ed25519):""}},toJSON(e){const n={};return e.secp256k1!==""&&(n.secp256k1=e.secp256k1),e.ed25519!==""&&(n.ed25519=e.ed25519),n},create(e){return hn.fromPartial(e!=null?e:{})},fromPartial(e){var n,t;const r=Ee();return r.secp256k1=(n=e.secp256k1)!=null?n:"",r.ed25519=(t=e.ed25519)!=null?t:"",r}};function Oe(){return{id:"",chain:"",fromAddress:"",toAddress:"",coins:[],gas:[],memo:""}}const fn={encode(e,n=h().Writer.create()){e.id!==""&&n.uint32(10).string(e.id),e.chain!==""&&n.uint32(18).string(e.chain),e.fromAddress!==""&&n.uint32(26).string(e.fromAddress),e.toAddress!==""&&n.uint32(34).string(e.toAddress);for(const t of e.coins)w.encode(t,n.uint32(42).fork()).ldelim();for(const t of e.gas)w.encode(t,n.uint32(50).fork()).ldelim();return e.memo!==""&&n.uint32(58).string(e.memo),n},decode(e,n){const t=e instanceof h().Reader?e:h().Reader.create(e);let r=n===void 0?t.len:t.pos+n;const s=Oe();for(;t.pos<r;){const o=t.uint32();switch(o>>>3){case 1:if(o!==10)break;s.id=t.string();continue;case 2:if(o!==18)break;s.chain=t.string();continue;case 3:if(o!==26)break;s.fromAddress=t.string();continue;case 4:if(o!==34)break;s.toAddress=t.string();continue;case 5:if(o!==42)break;s.coins.push(w.decode(t,t.uint32()));continue;case 6:if(o!==50)break;s.gas.push(w.decode(t,t.uint32()));continue;case 7:if(o!==58)break;s.memo=t.string();continue}if((o&7)===4||o===0)break;t.skipType(o&7)}return s},fromJSON(e){return{id:P(e.id)?globalThis.String(e.id):"",chain:P(e.chain)?globalThis.String(e.chain):"",fromAddress:P(e.fromAddress)?globalThis.String(e.fromAddress):"",toAddress:P(e.toAddress)?globalThis.String(e.toAddress):"",coins:globalThis.Array.isArray(e==null?void 0:e.coins)?e.coins.map(n=>w.fromJSON(n)):[],gas:globalThis.Array.isArray(e==null?void 0:e.gas)?e.gas.map(n=>w.fromJSON(n)):[],memo:P(e.memo)?globalThis.String(e.memo):""}},toJSON(e){var n,t;const r={};return e.id!==""&&(r.id=e.id),e.chain!==""&&(r.chain=e.chain),e.fromAddress!==""&&(r.fromAddress=e.fromAddress),e.toAddress!==""&&(r.toAddress=e.toAddress),(n=e.coins)!=null&&n.length&&(r.coins=e.coins.map(s=>w.toJSON(s))),(t=e.gas)!=null&&t.length&&(r.gas=e.gas.map(s=>w.toJSON(s))),e.memo!==""&&(r.memo=e.memo),r},create(e){return fn.fromPartial(e!=null?e:{})},fromPartial(e){var n,t,r,s,o,l,i;const a=Oe();return a.id=(n=e.id)!=null?n:"",a.chain=(t=e.chain)!=null?t:"",a.fromAddress=(r=e.fromAddress)!=null?r:"",a.toAddress=(s=e.toAddress)!=null?s:"",a.coins=((o=e.coins)==null?void 0:o.map(u=>w.fromPartial(u)))||[],a.gas=((l=e.gas)==null?void 0:l.map(u=>w.fromPartial(u)))||[],a.memo=(i=e.memo)!=null?i:"",a}};function De(){return{coins:[],poolDeduct:""}}const mn={encode(e,n=h().Writer.create()){for(const t of e.coins)w.encode(t,n.uint32(10).fork()).ldelim();return e.poolDeduct!==""&&n.uint32(18).string(e.poolDeduct),n},decode(e,n){const t=e instanceof h().Reader?e:h().Reader.create(e);let r=n===void 0?t.len:t.pos+n;const s=De();for(;t.pos<r;){const o=t.uint32();switch(o>>>3){case 1:if(o!==10)break;s.coins.push(w.decode(t,t.uint32()));continue;case 2:if(o!==18)break;s.poolDeduct=t.string();continue}if((o&7)===4||o===0)break;t.skipType(o&7)}return s},fromJSON(e){return{coins:globalThis.Array.isArray(e==null?void 0:e.coins)?e.coins.map(n=>w.fromJSON(n)):[],poolDeduct:P(e.poolDeduct)?globalThis.String(e.poolDeduct):""}},toJSON(e){var n;const t={};return(n=e.coins)!=null&&n.length&&(t.coins=e.coins.map(r=>w.toJSON(r))),e.poolDeduct!==""&&(t.poolDeduct=e.poolDeduct),t},create(e){return mn.fromPartial(e!=null?e:{})},fromPartial(e){var n,t;const r=De();return r.coins=((n=e.coins)==null?void 0:n.map(s=>w.fromPartial(s)))||[],r.poolDeduct=(t=e.poolDeduct)!=null?t:"",r}};function Be(){return{value:""}}const gn={encode(e,n=h().Writer.create()){return e.value!==""&&n.uint32(10).string(e.value),n},decode(e,n){const t=e instanceof h().Reader?e:h().Reader.create(e);let r=n===void 0?t.len:t.pos+n;const s=Be();for(;t.pos<r;){const o=t.uint32();switch(o>>>3){case 1:if(o!==10)break;s.value=t.string();continue}if((o&7)===4||o===0)break;t.skipType(o&7)}return s},fromJSON(e){return{value:P(e.value)?globalThis.String(e.value):""}},toJSON(e){const n={};return e.value!==""&&(n.value=e.value),n},create(e){return gn.fromPartial(e!=null?e:{})},fromPartial(e){var n;const t=Be();return t.value=(n=e.value)!=null?n:"",t}};h().util.Long!==E()&&(h().util.Long=E(),h().configure());function P(e){return e!=null}const Vn="types";function Ue(){return{coins:[],memo:"",signer:new Uint8Array(0)}}const he={encode(e,n=h().Writer.create()){for(const t of e.coins)w.encode(t,n.uint32(10).fork()).ldelim();return e.memo!==""&&n.uint32(18).string(e.memo),e.signer.length!==0&&n.uint32(26).bytes(e.signer),n},decode(e,n){const t=e instanceof h().Reader?e:h().Reader.create(e);let r=n===void 0?t.len:t.pos+n;const s=Ue();for(;t.pos<r;){const o=t.uint32();switch(o>>>3){case 1:if(o!==10)break;s.coins.push(w.decode(t,t.uint32()));continue;case 2:if(o!==18)break;s.memo=t.string();continue;case 3:if(o!==26)break;s.signer=t.bytes();continue}if((o&7)===4||o===0)break;t.skipType(o&7)}return s},fromJSON(e){return{coins:globalThis.Array.isArray(e==null?void 0:e.coins)?e.coins.map(n=>w.fromJSON(n)):[],memo:Ne(e.memo)?globalThis.String(e.memo):"",signer:Ne(e.signer)?yn(e.signer):new Uint8Array(0)}},toJSON(e){var n;const t={};return(n=e.coins)!=null&&n.length&&(t.coins=e.coins.map(r=>w.toJSON(r))),e.memo!==""&&(t.memo=e.memo),e.signer.length!==0&&(t.signer=pn(e.signer)),t},create(e){return he.fromPartial(e!=null?e:{})},fromPartial(e){var n,t,r;const s=Ue();return s.coins=((n=e.coins)==null?void 0:n.map(o=>w.fromPartial(o)))||[],s.memo=(t=e.memo)!=null?t:"",s.signer=(r=e.signer)!=null?r:new Uint8Array(0),s}};function yn(e){if(globalThis.Buffer)return Uint8Array.from(globalThis.Buffer.from(e,"base64"));{const n=globalThis.atob(e),t=new Uint8Array(n.length);for(let r=0;r<n.length;++r)t[r]=n.charCodeAt(r);return t}}function pn(e){if(globalThis.Buffer)return globalThis.Buffer.from(e).toString("base64");{const n=[];return e.forEach(t=>{n.push(globalThis.String.fromCharCode(t))}),globalThis.btoa(n.join(""))}}h().util.Long!==E()&&(h().util.Long=E(),h().configure());function Ne(e){return e!=null}const qn="cosmos.base.v1beta1";function Re(){return{denom:"",amount:""}}const H={encode(e,n=h().Writer.create()){return e.denom!==""&&n.uint32(10).string(e.denom),e.amount!==""&&n.uint32(18).string(e.amount),n},decode(e,n){const t=e instanceof h().Reader?e:h().Reader.create(e);let r=n===void 0?t.len:t.pos+n;const s=Re();for(;t.pos<r;){const o=t.uint32();switch(o>>>3){case 1:if(o!==10)break;s.denom=t.string();continue;case 2:if(o!==18)break;s.amount=t.string();continue}if((o&7)===4||o===0)break;t.skipType(o&7)}return s},fromJSON(e){return{denom:V(e.denom)?globalThis.String(e.denom):"",amount:V(e.amount)?globalThis.String(e.amount):""}},toJSON(e){const n={};return e.denom!==""&&(n.denom=e.denom),e.amount!==""&&(n.amount=e.amount),n},create(e){return H.fromPartial(e!=null?e:{})},fromPartial(e){var n,t;const r=Re();return r.denom=(n=e.denom)!=null?n:"",r.amount=(t=e.amount)!=null?t:"",r}};function Me(){return{denom:"",amount:""}}const vn={encode(e,n=h().Writer.create()){return e.denom!==""&&n.uint32(10).string(e.denom),e.amount!==""&&n.uint32(18).string(e.amount),n},decode(e,n){const t=e instanceof h().Reader?e:h().Reader.create(e);let r=n===void 0?t.len:t.pos+n;const s=Me();for(;t.pos<r;){const o=t.uint32();switch(o>>>3){case 1:if(o!==10)break;s.denom=t.string();continue;case 2:if(o!==18)break;s.amount=t.string();continue}if((o&7)===4||o===0)break;t.skipType(o&7)}return s},fromJSON(e){return{denom:V(e.denom)?globalThis.String(e.denom):"",amount:V(e.amount)?globalThis.String(e.amount):""}},toJSON(e){const n={};return e.denom!==""&&(n.denom=e.denom),e.amount!==""&&(n.amount=e.amount),n},create(e){return vn.fromPartial(e!=null?e:{})},fromPartial(e){var n,t;const r=Me();return r.denom=(n=e.denom)!=null?n:"",r.amount=(t=e.amount)!=null?t:"",r}};function _e(){return{int:""}}const kn={encode(e,n=h().Writer.create()){return e.int!==""&&n.uint32(10).string(e.int),n},decode(e,n){const t=e instanceof h().Reader?e:h().Reader.create(e);let r=n===void 0?t.len:t.pos+n;const s=_e();for(;t.pos<r;){const o=t.uint32();switch(o>>>3){case 1:if(o!==10)break;s.int=t.string();continue}if((o&7)===4||o===0)break;t.skipType(o&7)}return s},fromJSON(e){return{int:V(e.int)?globalThis.String(e.int):""}},toJSON(e){const n={};return e.int!==""&&(n.int=e.int),n},create(e){return kn.fromPartial(e!=null?e:{})},fromPartial(e){var n;const t=_e();return t.int=(n=e.int)!=null?n:"",t}};function Fe(){return{dec:""}}const Cn={encode(e,n=h().Writer.create()){return e.dec!==""&&n.uint32(10).string(e.dec),n},decode(e,n){const t=e instanceof h().Reader?e:h().Reader.create(e);let r=n===void 0?t.len:t.pos+n;const s=Fe();for(;t.pos<r;){const o=t.uint32();switch(o>>>3){case 1:if(o!==10)break;s.dec=t.string();continue}if((o&7)===4||o===0)break;t.skipType(o&7)}return s},fromJSON(e){return{dec:V(e.dec)?globalThis.String(e.dec):""}},toJSON(e){const n={};return e.dec!==""&&(n.dec=e.dec),n},create(e){return Cn.fromPartial(e!=null?e:{})},fromPartial(e){var n;const t=Fe();return t.dec=(n=e.dec)!=null?n:"",t}};h().util.Long!==E()&&(h().util.Long=E(),h().configure());function V(e){return e!=null}const Yn="types";function Le(){return{fromAddress:new Uint8Array(0),toAddress:new Uint8Array(0),amount:[]}}const fe={encode(e,n=h().Writer.create()){e.fromAddress.length!==0&&n.uint32(10).bytes(e.fromAddress),e.toAddress.length!==0&&n.uint32(18).bytes(e.toAddress);for(const t of e.amount)H.encode(t,n.uint32(26).fork()).ldelim();return n},decode(e,n){const t=e instanceof h().Reader?e:h().Reader.create(e);let r=n===void 0?t.len:t.pos+n;const s=Le();for(;t.pos<r;){const o=t.uint32();switch(o>>>3){case 1:if(o!==10)break;s.fromAddress=t.bytes();continue;case 2:if(o!==18)break;s.toAddress=t.bytes();continue;case 3:if(o!==26)break;s.amount.push(H.decode(t,t.uint32()));continue}if((o&7)===4||o===0)break;t.skipType(o&7)}return s},fromJSON(e){return{fromAddress:Ke(e.fromAddress)?We(e.fromAddress):new Uint8Array(0),toAddress:Ke(e.toAddress)?We(e.toAddress):new Uint8Array(0),amount:globalThis.Array.isArray(e==null?void 0:e.amount)?e.amount.map(n=>H.fromJSON(n)):[]}},toJSON(e){var n;const t={};return e.fromAddress.length!==0&&(t.fromAddress=Je(e.fromAddress)),e.toAddress.length!==0&&(t.toAddress=Je(e.toAddress)),(n=e.amount)!=null&&n.length&&(t.amount=e.amount.map(r=>H.toJSON(r))),t},create(e){return fe.fromPartial(e!=null?e:{})},fromPartial(e){var n,t,r;const s=Le();return s.fromAddress=(n=e.fromAddress)!=null?n:new Uint8Array(0),s.toAddress=(t=e.toAddress)!=null?t:new Uint8Array(0),s.amount=((r=e.amount)==null?void 0:r.map(o=>H.fromPartial(o)))||[],s}};function We(e){if(globalThis.Buffer)return Uint8Array.from(globalThis.Buffer.from(e,"base64"));{const n=globalThis.atob(e),t=new Uint8Array(n.length);for(let r=0;r<n.length;++r)t[r]=n.charCodeAt(r);return t}}function Je(e){if(globalThis.Buffer)return globalThis.Buffer.from(e).toString("base64");{const n=[];return e.forEach(t=>{n.push(globalThis.String.fromCharCode(t))}),globalThis.btoa(n.join(""))}}h().util.Long!==E()&&(h().util.Long=E(),h().configure());function Ke(e){return e!=null}var Tn=Object.defineProperty,wn=Object.defineProperties,An=Object.getOwnPropertyDescriptors,$e=Object.getOwnPropertySymbols,bn=Object.prototype.hasOwnProperty,Sn=Object.prototype.propertyIsEnumerable,Xe=(e,n,t)=>n in e?Tn(e,n,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[n]=t,In=(e,n)=>{for(var t in n||(n={}))bn.call(n,t)&&Xe(e,t,n[t]);if($e)for(var t of $e(n))Sn.call(n,t)&&Xe(e,t,n[t]);return e},Pn=(e,n)=>wn(e,An(n));const xn=1e3*60*60*24,En=e=>{const n=new L.Registry([["/ibc.applications.transfer.v1.MsgTransfer",K.MsgTransfer],["/cosmwasm.wasm.v1.MsgExecuteContract",re.$n]]);let t=s=>{const{amount:o,fromAddress:l,toAddress:i}=s;return{typeUrl:"/cosmos.bank.v1beta1.MsgSend",value:se.MsgSend.encode(se.MsgSend.fromPartial({fromAddress:l,toAddress:i,amount:o})).finish()}};const r=s=>{const{memo:o,toAddress:l,fromAddress:i,channel:a,port:u,amount:f}=s;return{typeUrl:"/ibc.applications.transfer.v1.MsgTransfer",value:K.MsgTransfer.encode(K.MsgTransfer.fromPartial({memo:o,receiver:l,sender:i,sourceChannel:a,sourcePort:u,token:f,timeoutTimestamp:BigInt((Date.now()+xn)*1e6)})).finish()}};switch(e){case"thorchainrune":{const s="/types.MsgDeposit";n.register(s,he);const o=i=>{const{assets:a,memo:u,signer:f}=i,d=a.map(g=>Pn(In({},g),{asset:nn(g.asset)}));return{typeUrl:s,value:he.encode(he.fromPartial({coins:d,memo:u,signer:(0,M.fromBech32)(f).data})).finish()}},l="/types.MsgSend";return n.register(l,fe),t=i=>{const{amount:a,fromAddress:u,toAddress:f}=i;return{typeUrl:l,value:fe.encode(fe.fromPartial({fromAddress:(0,M.fromBech32)(u).data,toAddress:(0,M.fromBech32)(f).data,amount:a})).finish()}},{methods:{deposit:o,ibcTransfer:r,transfer:t},registry:n}}}return{methods:{ibcTransfer:r,transfer:t},registry:n}};var He=y(45504),O=y(29639),On=y(94935),Dn=y(16757),Bn=Object.defineProperty,Un=Object.defineProperties,Nn=Object.getOwnPropertyDescriptors,Ve=Object.getOwnPropertySymbols,Rn=Object.getPrototypeOf,Mn=Object.prototype.hasOwnProperty,_n=Object.prototype.propertyIsEnumerable,Fn=Reflect.get,qe=(e,n,t)=>n in e?Bn(e,n,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[n]=t,me=(e,n)=>{for(var t in n||(n={}))Mn.call(n,t)&&qe(e,t,n[t]);if(Ve)for(var t of Ve(n))_n.call(n,t)&&qe(e,t,n[t]);return e},Ye=(e,n)=>Un(e,Nn(n)),ze=(e,n,t)=>Fn(Rn(e),t,n),b=(e,n,t)=>new Promise((r,s)=>{var o=a=>{try{i(t.next(a))}catch(u){s(u)}},l=a=>{try{i(t.throw(a))}catch(u){s(u)}},i=a=>a.done?r(a.value):Promise.resolve(a.value).then(o,l);i((t=t.apply(e,n)).next())});const Ze=5e3,Ln=3e3,Wn=1e3*60*60*24*14,Jn=1e3*60*2;class ge extends Dn.P{constructor(n,t,r,s){super(n,t,r,s),this.networkInfo=n.networkInfo,this.fetchCors=n.io.fetchCors,this.accountNumber=0,this.sequence=0,this.unconfirmedTransactionCache={cacheSequence:0,txids:new Map},this.feeCache=new Map,this.stakedBalanceCache="0",this.stakingSupported=!0,this.otherMethods={getMaxTx:o=>b(this,null,function*(){switch(o.type){case"MakeTxDeposit":{if(this.tools.methods.deposit==null)throw new Error(`${this.currencyInfo.displayName} does not support the deposit method`);const{assets:l,memo:i}=o;if(l.length!==1)throw new Error("Cannot calculate max tx for more than one asset");const a=this.tools.methods.deposit({assets:l,memo:i,signer:this.walletInfo.keys.bech32Address}),{networkFee:u}=yield this.calculateFee({messages:[a],memo:i}),f=this.getBalance({tokenId:null});return(0,S.sub)(f,u)}default:throw new Error(`Invalid type: ${o.type}`)}}),makeTx:o=>b(this,null,function*(){switch(o.type){case"MakeTxDeposit":{if(this.tools.methods.deposit==null)throw new Error(`${this.currencyInfo.displayName} does not support the deposit method`);const{assets:l,memo:i,metadata:a}=o,u=this.tools.methods.deposit({assets:l,memo:i,signer:this.walletInfo.keys.bech32Address}),f=this.createUnsignedTxHex([u],i),{gasFeeCoin:d,gasLimit:v,networkFee:g}=yield this.calculateFee({messages:[u],memo:i}),m={gasFeeCoin:d,gasLimit:v,unsignedTxHex:f};return{blockHeight:0,currencyCode:this.currencyInfo.currencyCode,date:Date.now()/1e3,isSend:!0,memos:[],metadata:a,nativeAmount:`-${g}`,networkFee:g,otherParams:m,ourReceiveAddresses:[],signedTx:"",tokenId:null,txid:"",walletId:this.walletId}}default:throw new Error(`Invalid type: ${o.type}`)}}),parseWalletConnectV2Payload:o=>b(this,null,function*(){try{switch(o==null?void 0:o.method){case"cosmos_getAccounts":return{nativeAmount:"0",networkFee:"0",tokenId:null};case"cosmos_signDirect":{const l=we(o),{authInfoBytes:i,bodyBytes:a}=l.params.signDoc,u=O.TxBody.decode(de(a)),{nativeAmount:f,tokenId:d}=this.getAmountAndTokenIdFromKnownMessageTypes(u.messages),v=O.AuthInfo.decode(de(i));let g="0";const m=v.fee;return m!=null&&(g=$([(0,p.coin)("0",this.networkInfo.nativeDenom),...m.amount]).amount),{nativeAmount:f,networkFee:g,tokenId:d}}case"cosmos_signAmino":{const l=Ae(o),{signDoc:i}=l.params,a=(0,C.makeSignDoc)(i.msgs,i.fee,i.chain_id,i.memo,i.account_number,i.sequence),u=new p.AminoTypes(me(me({},p.createBankAminoConverters),p.createIbcAminoConverters)),f=a.msgs.map(T=>u.fromAmino(T)),{nativeAmount:d,tokenId:v}=this.getAmountAndTokenIdFromKnownMessageTypes(f);let g="0";const m=i.fee;return m!=null&&(g=$([(0,p.coin)("0",this.networkInfo.nativeDenom),...m.amount]).amount),{nativeAmount:d,networkFee:g,tokenId:v}}default:throw new Error(`Invalid method: ${o==null?void 0:o.method}`)}}catch(l){throw this.warn("Wallet connect call_request ",l),l}})}}tokenIdFromDenom(n){if(this.networkInfo.nativeDenom===n)return null;const t=Object.keys(this.allTokensMap).find(r=>{var s;return((s=this.allTokensMap[r].networkLocation)==null?void 0:s.contractAddress)===n});if(t===void 0)throw new Error(`Unrecognized denom: ${n}`);return t}getAmountAndTokenIdFromKnownMessageTypes(n){var t;let r=null,s;for(const o of n)switch(o.typeUrl){case"/ibc.applications.transfer.v1.MsgTransfer":{const l=this.tools.registry.decode(o),i=K.MsgTransfer.fromPartial(l);r===void 0&&(r=this.tokenIdFromDenom(i.token.denom));const a=(0,p.coin)(i.token.amount,i.token.denom);s==null?s=a:s=$([s,a]);break}case"/cosmwasm.wasm.v1.MsgExecuteContract":{const l=this.tools.registry.decode(o),i=re.$n.fromPartial(l),{funds:a}=i;if(a.length>0){const{denom:u}=a[0];r===void 0&&(r=this.tokenIdFromDenom(u));let f=(0,p.coin)("0",u);for(const d of a)f=$([f,d]);s==null?s=f:s=$([s,f])}break}default:}return{nativeAmount:(t=s==null?void 0:s.amount)!=null?t:"0",tokenId:r}}setOtherData(n){this.otherData=Z(n)}getClients(){if(this.tools.clients==null)throw new Error("No StargateClient");return this.tools.clients}queryBalance(){return b(this,null,function*(){var n;try{const{stargateClient:t}=this.getClients(),r=yield t.getAllBalances(this.walletInfo.keys.bech32Address),s=r.find(i=>i.denom===this.networkInfo.nativeDenom);if(this.updateBalance(this.currencyInfo.currencyCode,(n=s==null?void 0:s.amount)!=null?n:"0"),this.enabledTokenIds.forEach(i=>{var a;const u=this.allTokensMap[i],f=r.find(d=>{var v;return d.denom===((v=u.networkLocation)==null?void 0:v.contractAddress)});this.updateBalance(u.currencyCode,(a=f==null?void 0:f.amount)!=null?a:"0")}),this.stakingSupported)try{const i=yield t.getBalanceStaked(this.walletInfo.keys.bech32Address);if(i!=null&&this.stakedBalanceCache!==i.amount){const a={stakedAmounts:[{nativeAmount:i.amount}]};this.currencyEngineCallbacks.onStakingStatusChanged(a),this.stakedBalanceCache=i.amount}}catch(i){if(String(i).includes("unknown query path"))this.stakingSupported=!1;else throw i}const{accountNumber:o,sequence:l}=yield t.getSequence(this.walletInfo.keys.bech32Address);this.accountNumber=o,this.sequence=l}catch(t){String(t).includes("does not exist on chain")?this.updateBalance(this.currencyInfo.currencyCode,"0"):this.log.warn("queryBalance error:",t)}})}queryBlockheight(){return b(this,null,function*(){try{const{stargateClient:n}=this.getClients(),t=yield n.getHeight();t>this.walletLocalData.blockHeight&&(this.walletLocalData.blockHeight=t,this.walletLocalDataDirty=!0,this.currencyEngineCallbacks.onBlockHeightChanged(this.walletLocalData.blockHeight))}catch(n){this.error("queryBlockheight Error ",n)}})}queryTransactions(){return b(this,null,function*(){let n=0;const t=[this.currencyInfo.currencyCode,...this.enabledTokenIds.map(s=>this.allTokensMap[s].currencyCode)],r=Date.now()-Wn>this.otherData.archivedTxLastCheckTime?yield be(this.fetchCors,ke(this.networkInfo.archiveNode,this.tools.initOptions)):this.getClients();for(const s of A){const o=yield this.queryTransactionsInner(s,r);o!=null&&this.otherData[s]!==o&&(this.otherData[s]=o,this.walletLocalDataDirty=!0),n+=.5,t.forEach(l=>this.tokenCheckTransactionsStatus[l]=n),this.updateOnAddressesChecked()}this.otherData.archivedTxLastCheckTime=Date.now(),this.transactionsChangedArray.length>0&&(this.currencyEngineCallbacks.onTransactionsChanged(this.transactionsChangedArray),this.transactionsChangedArray=[])})}queryTransactionsInner(n,t){return b(this,null,function*(){const r={query:`${n}='${this.walletInfo.keys.bech32Address}'`,per_page:50,order_by:"desc"};let s,o=0,l,i=0,a=!1;try{do{const u=yield t.cometClient.txSearch(Ye(me({},r),{page:++o})),{totalCount:f,txs:d}=u;l==null&&(l=f),i=i+d.length;for(const v of d){const g=(0,M.toHex)(v.hash).toUpperCase();if(this.removeFromUnconfirmedCache(g),s==null&&(s=g),g===this.otherData[n]){a=!0;break}const m=v.result.events.map(p.fromTendermintEvent);let T=[];try{T=cn(m,this.walletInfo.keys.bech32Address)}catch(ee){this.log.warn("reduceCoinEventsForAddress error:",String(ee))}if(T.length===0)continue;const D=yield t.stargateClient.getBlock(v.height),U=(0,x.toSeconds)((0,x.fromRfc3339WithNanoseconds)(D.header.time)).seconds,{height:N,tx:W}=v,j=I.YU.stringify(W),{authInfo:{fee:_},body:{memo:ye,messages:F}}=(0,L.decodeTxRaw)(W),Ce=yield this.totalDynamicNetworkFee(F,D.header.height);T.forEach(ee=>{this.processCosmosTransaction(g,U,j,ee,ye,N,Ce,_)})}}while(l>i&&!a)}catch(u){throw this.log.warn("queryTransactions error:",u),u}return s})}processCosmosTransaction(n,t,r,s,o,l,i,a){const{amount:u,denom:f}=s,d=this.networkInfo.nativeDenom===f;let v;try{v=this.tokenIdFromDenom(f)}catch{return}const{currencyCode:g}=v==null?this.currencyInfo:this.allTokensMap[v];let m="0";if(a!=null){const{amount:_}=a,ye=$([(0,p.coin)("0",this.networkInfo.nativeDenom),..._]);m=(0,S.add)(m,ye.amount)}const T=(0,S.lt)(u,"0"),D=[];let U=u,N;T?d?(m=(0,S.add)(m,i),U=(0,S.sub)(U,m)):(m="0",N=i!=="0"?i:void 0):(D.push(this.walletInfo.keys.bech32Address),m="0");const W=[];o!==""&&W.push({type:"text",value:o});const j={blockHeight:l,currencyCode:g,date:t,isSend:T,memos:W,nativeAmount:U,networkFee:m,ourReceiveAddresses:D,parentNetworkFee:N,signedTx:r,tokenId:v,txid:n,walletId:this.walletId};this.addTransaction(g,j)}createUnsignedTxHex(n,t){const r=O.TxBody.fromPartial({messages:n,memo:t}),s=O.TxBody.encode(r).finish(),o=O.TxRaw.fromPartial({bodyBytes:s});return I.YU.stringify(O.TxRaw.encode(o).finish())}addToUnconfirmedCache(n){const t=new Date(new Date().getTime()+Jn);this.unconfirmedTransactionCache.txids.size===0&&(this.unconfirmedTransactionCache.cacheSequence=this.sequence),this.unconfirmedTransactionCache.txids.set(n,t)}removeFromUnconfirmedCache(n){this.unconfirmedTransactionCache.txids.has(n)&&(this.unconfirmedTransactionCache.cacheSequence=this.unconfirmedTransactionCache.cacheSequence+1,this.sequence=this.unconfirmedTransactionCache.cacheSequence,this.unconfirmedTransactionCache.txids.delete(n))}getSequence(){return this.unconfirmedTransactionCache.txids.size===0?this.sequence:[...this.unconfirmedTransactionCache.txids.values()].some(n=>n<new Date)?(this.unconfirmedTransactionCache.txids=new Map,this.sequence):this.unconfirmedTransactionCache.cacheSequence+this.unconfirmedTransactionCache.txids.size}totalDynamicNetworkFee(n,t){return b(this,null,function*(){let r="0";if(this.networkInfo.defaultTransactionFeeUrl==null)return r;const{url:s,headers:o}=ke(this.networkInfo.defaultTransactionFeeUrl,this.tools.initOptions),l=t==null?"":`?height=${t}`,a=yield(yield this.fetchCors(`${s}${l}`,{method:"GET",headers:o})).json(),u=G(a);for(const f of n)switch(f.typeUrl){case"/types.MsgDeposit":r=(0,S.add)(r,u.native_outbound_fee_rune);break;case"/types.MsgSend":r=(0,S.add)(r,u.native_tx_fee_rune)}return r})}calculateFee(n){return b(this,null,function*(){const{messages:t,memo:r,networkFeeOption:s}=n;let o=(0,p.coin)("0",this.networkInfo.nativeDenom),l="0",i="0";if(this.networkInfo.defaultTransactionFeeUrl==null){const{queryClient:a}=this.getClients(),{gasInfo:u}=yield a.tx.simulate(t,r,(0,C.encodeSecp256k1Pubkey)(I.YU.parse(this.walletInfo.keys.publicKey)),this.getSequence());if((u==null?void 0:u.gasUsed)==null)throw new Error("simulate didn't return gasUsed ");l=(0,S.ceil)((0,S.mul)(u==null?void 0:u.gasUsed.toString(),"1.5"),0);const{low:f,average:d,high:v}=(0,k.getGasPriceStep)(this.tools.chainData);let g=d;switch(s){case"low":{g=f;break}case"high":{g=v;break}case"custom":throw new Error("Custom fee not supported")}const m=(0,S.ceil)((0,S.mul)(l,g.toString()),0);o=(0,p.coin)(m,this.networkInfo.nativeDenom),i=o.amount}else i=yield this.totalDynamicNetworkFee(t),i=(0,S.mul)(i,"1.01");return{gasFeeCoin:o,gasLimit:l,networkFee:i}})}startEngine(){return b(this,null,function*(){this.engineOn=!0,yield this.tools.connectClient(),this.addToLoop("queryBalance",Ze).catch(()=>{}),this.addToLoop("queryBlockheight",Ze).catch(()=>{}),this.addToLoop("queryTransactions",Ln).catch(()=>{}),yield ze(ge.prototype,this,"startEngine").call(this)})}killEngine(){return b(this,null,function*(){yield this.tools.disconnectClient(),yield ze(ge.prototype,this,"killEngine").call(this)})}resyncBlockchain(){return b(this,null,function*(){yield this.killEngine(),yield this.clearBlockchainCache(),yield this.startEngine()})}validateTransfer(n,t,r){return b(this,null,function*(){var s;if(t==null)return;const o=this.allTokensMap[t],l=(0,Y.Oj)(o.networkLocation),i=l==null?void 0:l.contractAddress;if(i==null)throw new Error("Unknown denom");const{queryClient:a}=this.getClients();try{yield a.bank.denomMetadata(i);return}catch{const d=(s=(yield a.ibc.transfer.denomTrace(i)).denomTrace)==null?void 0:s.path.match(/transfer\/channel-\d+/);if(d==null||`${r.port}/${r.channel}`===d[0])return}throw new Error("Invalid transfer")})}makeSpend(n){return b(this,null,function*(){var t,r;const{edgeSpendInfo:s,currencyCode:o}=this.makeSpendCheck(n),{memos:l=[],networkFeeOption:i,tokenId:a}=s,u=(t=l[0])==null?void 0:t.value;if(s.spendTargets.length!==1)throw new Error("Error: only one output allowed");const{nativeAmount:f,publicAddress:d}=s.spendTargets[0];if(f==null)throw new On.$D;if(d==null)throw new Error("makeSpend Missing publicAddress");const v=a!=null?(r=this.allTokensMap[a].networkLocation)==null?void 0:r.contractAddress:this.networkInfo.nativeDenom;if(v==null)throw new Error("Unknown denom");let g;if(this.networkInfo.bech32AddressPrefix!==(0,M.fromBech32)(d).prefix){const F=ln(this.tools.chainData.chain_name,d);yield this.validateTransfer(d,a,F);const{channel:Ce,port:ee}=F;g=this.tools.methods.ibcTransfer({channel:Ce,port:ee,memo:u,amount:(0,p.coin)(f,v),fromAddress:this.walletInfo.keys.bech32Address,toAddress:d})}else g=this.tools.methods.transfer({amount:[(0,p.coin)(f,v)],fromAddress:this.walletInfo.keys.bech32Address,toAddress:d});let m,T,D;const U=`${d}${String(i)}`,N=this.feeCache.get(U);if(f==="0")m=(0,p.coin)("0",this.networkInfo.nativeDenom),T="0",D="0";else if(N==null){const F=yield this.calculateFee({messages:[g],memo:u,networkFeeOption:i});m=F.gasFeeCoin,T=F.gasLimit,D=F.networkFee,this.feeCache.set(U,F)}else m=N.gasFeeCoin,T=N.gasLimit,D=N.networkFee;const W=this.createUnsignedTxHex([g],u),j={gasFeeCoin:m,gasLimit:T,unsignedTxHex:W},_=this.makeEdgeTransactionAmounts(f,D,a);return this.checkBalances(_,a),{blockHeight:0,currencyCode:o,date:0,isSend:!0,memos:l,nativeAmount:_.nativeAmount,networkFee:_.networkFee,otherParams:j,ourReceiveAddresses:[],parentNetworkFee:_.parentNetworkFee,signedTx:"",tokenId:a,txid:"",walletId:this.walletId}})}signMessage(n,t,r){return b(this,null,function*(){const s=B(this.currencyInfo.pluginId)(t),o=yield this.tools.createSigner(s.mnemonic);if((r==null?void 0:r.otherParams)!=null)switch(r.otherParams.method){case"cosmos_getAccounts":{ue(r.otherParams);const m=(yield o.getAccounts()).map(T=>Ye(me({},T),{pubkey:I.US.stringify(T.pubkey)}));return JSON.stringify(m)}case"cosmos_signDirect":{const g=we(r.otherParams),{signDoc:m}=g.params,T=O.SignDoc.fromPartial({accountNumber:(0,He.longify)(m.accountNumber),authInfoBytes:de(m.authInfoBytes),bodyBytes:de(m.bodyBytes),chainId:m.chainId}),U={signature:(yield o.signDirect(this.walletInfo.keys.bech32Address,T)).signature,signed:g.params.signDoc};return JSON.stringify(U)}case"cosmos_signAmino":{const g=Ae(r.otherParams),{signDoc:m}=g.params,T=(0,C.makeSignDoc)(m.msgs,m.fee,m.chain_id,m.memo,m.account_number,m.sequence),N={signature:(yield(yield C.Secp256k1HdWallet.fromMnemonic(o.mnemonic)).signAmino(this.walletInfo.keys.bech32Address,T)).signature,signed:m};return JSON.stringify(N)}default:throw new Error(`Invalid method: ${r.method}`)}const l=I.YU.parse(n),i=O.SignDoc.decode(l),a=yield o.signDirect(this.walletInfo.keys.bech32Address,i),u=(0,C.decodeSignature)(a.signature),f=O.TxRaw.fromPartial({authInfoBytes:i.authInfoBytes,bodyBytes:i.bodyBytes,signatures:[u.signature]}),d=O.TxRaw.encode(f).finish();return I.YU.stringify(d)})}signTx(n,t){return b(this,null,function*(){const{gasFeeCoin:r,gasLimit:s,unsignedTxHex:o}=le(n.otherParams),l=B(this.currencyInfo.pluginId)(t),i=I.YU.parse(o),{bodyBytes:a}=O.TxRaw.decode(i),u=I.YU.parse(this.walletInfo.keys.publicKey),f=(0,C.encodeSecp256k1Pubkey)(u),d=(0,L.makeAuthInfoBytes)([{pubkey:(0,L.encodePubkey)(f),sequence:this.getSequence()}],[r],parseInt(s),void 0,void 0,1),v=O.SignDoc.fromPartial({accountNumber:(0,He.longify)(this.accountNumber),authInfoBytes:d,bodyBytes:a,chainId:this.tools.chainData.chain_id}),m=yield(yield this.tools.createSigner(l.mnemonic)).signDirect(this.walletInfo.keys.bech32Address,v),T=(0,C.decodeSignature)(m.signature),D=O.TxRaw.fromPartial({authInfoBytes:d,bodyBytes:a,signatures:[T.signature]}),U=O.TxRaw.encode(D).finish(),N=I.YU.stringify(U);return n.signedTx=N,n})}broadcastTx(n){return b(this,null,function*(){try{const t=I.YU.parse(n.signedTx),{stargateClient:r}=this.getClients(),s=yield r.broadcastTxSync(t);return this.warn(`SUCCESS broadcastTx
2
- ${(0,z.oX)(n)}`),n.txid=s,n.date=Date.now()/1e3,this.addToUnconfirmedCache(s),n}catch(t){throw this.warn("FAILURE broadcastTx failed: ",t),t}})}getFreshAddress(n){return b(this,null,function*(){const{bech32Address:t}=this.walletInfo.keys;return{publicAddress:t}})}}function Kn(e,n,t,r){return b(this,null,function*(){const s=pe(t),o=new ge(e,n,s,r);return yield o.loadEngine(),o})}var $n=y(48764).Buffer,R=(e,n,t)=>new Promise((r,s)=>{var o=a=>{try{i(t.next(a))}catch(u){s(u)}},l=a=>{try{i(t.throw(a))}catch(u){s(u)}},i=a=>a.done?r(a.value):Promise.resolve(a.value).then(o,l);i((t=t.apply(e,n)).next())});class Ge{constructor(n){const{builtinTokens:t,currencyInfo:r,initOptions:s,io:o,networkInfo:l}=n;this.io=o,this.currencyInfo=r,this.builtinTokens=t,this.networkInfo=l,this.initOptions=s,this.clientCount=0;const{methods:i,registry:a}=En(r.pluginId);this.methods=i,this.registry=a;const{chainId:u,url:f}=this.networkInfo.chainInfo,d=J.chains.find(g=>g.chain_id===u&&g.network_type==="mainnet");if(d==null)throw new Error("Unknown chain");this.chainData=d;const v=new q.ChainRegistryFetcher;v.fetch(f).then(()=>{this.chainData=v.getChain(this.chainData.chain_name)}).catch(g=>{})}createSigner(n){return R(this,null,function*(){const{bech32AddressPrefix:t,bip39Path:r}=this.networkInfo,s=(0,Te.stringToPath)(r);return yield L.DirectSecp256k1HdWallet.fromMnemonic(n,{hdPaths:[s],prefix:t})})}getDisplayPrivateKey(n){return R(this,null,function*(){const{pluginId:t}=this.currencyInfo;return B(t)(n.keys).mnemonic})}getDisplayPublicKey(n){return R(this,null,function*(){const{keys:t}=pe(n);return t.publicKey})}importPrivateKey(n){return R(this,null,function*(){if(!(0,te.validateMnemonic)(n))throw new Error("Invalid mnemonic");return yield this.createSigner(n),{[this.networkInfo.pluginMnemonicKeyName]:n}})}createPrivateKey(n){return R(this,null,function*(){if(n!==this.currencyInfo.walletType)throw new Error("InvalidWalletType");const t=$n.from(this.io.random(32)),r=(0,te.entropyToMnemonic)(t);return yield this.importPrivateKey(r)})}derivePublicKey(n){return R(this,null,function*(){if(n.type!==this.currencyInfo.walletType)throw new Error("InvalidWalletType");const{mnemonic:t}=B(this.currencyInfo.pluginId)(n.keys),s=yield(yield this.createSigner(t)).getAccounts(),{address:o,pubkey:l}=s[0],i=I.YU.stringify(l);return{bech32Address:o,publicKey:i}})}isValidOurAddress(n){try{if((0,M.fromBech32)(n).prefix===this.networkInfo.bech32AddressPrefix)return!0}catch{}return!1}isValidTargetAddress(n){try{const t=(0,M.fromBech32)(n);if(J.chains.find(s=>s.bech32_prefix===t.prefix)!=null)return!0}catch{}return!1}parseUri(n,t,r){return R(this,null,function*(){const{pluginId:s}=this.currencyInfo,o={[s]:!0},{parsedUri:l,edgeParsedUri:i}=(0,oe.k)(this.currencyInfo,n,o,this.builtinTokens,t!=null?t:this.currencyInfo.currencyCode,r);let a="";if(i.publicAddress!=null&&(a=i.publicAddress),!this.isValidTargetAddress(a))throw new Error("InvalidPublicAddressError");return i.uniqueIdentifier=l.query.memo,i})}encodeUri(n){return R(this,arguments,function*(t,r=[]){const{pluginId:s}=this.currencyInfo,{nativeAmount:o,currencyCode:l,publicAddress:i}=t;if(!this.isValidOurAddress(i))throw new Error("InvalidPublicAddressError");let a;if(typeof o=="string"){const f=(0,z.Qs)(l!=null?l:this.currencyInfo.currencyCode,this.currencyInfo,r,this.builtinTokens);if(f==null)throw new Error("InternalErrorInvalidCurrencyCode");a=(0,S.div)(o,f.multiplier,18)}return(0,oe.Q)(t,s,a)})}connectClient(){return R(this,null,function*(){this.clients==null&&(this.clients=yield be(this.io.fetchCors,ke(this.networkInfo.rpcNode,this.initOptions))),++this.clientCount})}disconnectClient(){return R(this,null,function*(){var n,t;--this.clientCount,this.clientCount===0&&(yield(t=(n=this.clients)==null?void 0:n.stargateClient)==null?void 0:t.disconnect(),this.clients=void 0)})}getTokenId(n){return R(this,null,function*(){(0,Y.Rp)(n);const t=(0,Y.Oj)(n.networkLocation);if(t==null)throw new Error("ErrorInvalidContractAddress");return t.contractAddress.toLowerCase().replace(/^ibc[/]/,"ibc")})}}function Xn(e){return R(this,null,function*(){return new Ge(e)})}},89214:function(){},20131:function(){},16026:function(){},52361:function(){},94616:function(){}}]);
1
+ (self.webpackChunkedge_currency_accountbased=self.webpackChunkedge_currency_accountbased||[]).push([[8222],{79014:function(Qe,ne,y){"use strict";y.d(ne,{Q:function(){return K},k:function(){return re}});var q=y(77591),Te=y.n(q),M=y(24350),L=y(84564),S=y.n(L),te=y(76714),J=Object.defineProperty,I=Object.getOwnPropertySymbols,Y=Object.prototype.hasOwnProperty,oe=Object.prototype.propertyIsEnumerable,z=(k,C,p)=>C in k?J(k,C,{enumerable:!0,configurable:!0,writable:!0,value:p}):k[C]=p,se=(k,C)=>{for(var p in C||(C={}))Y.call(C,p)&&z(k,p,C[p]);if(I)for(var p of I(C))oe.call(C,p)&&z(k,p,C[p]);return k};function re(k,C,p,E,c,ie=[]){const A=se({},S()(C,{},!0)),Z=C.startsWith(`${k.pluginId}://`);if(A.protocol!=null&&(A.protocol=A.protocol.replace(":","")),A.protocol!=null&&A.protocol!==""&&!p[A.protocol])throw new Error(`Uri protocol '${A.protocol}' is not supported for ${k.pluginId}.`);if(A.host===""&&A.pathname==="")throw new Error("Path and host not found in uri.");const B={publicAddress:A.host!==""?A.host:A.pathname.split("/")[0]},ae=A.query.label,ce=A.query.message,le=A.query.category;(ae!=null||ce!=null||le!=null||Z)&&(B.metadata={},B.metadata.name=ae,B.metadata.notes=ce,B.metadata.category=le,B.metadata.gateway=Z!=null?Z:!1);const G=A.query.amount;if(G!=null&&typeof G=="string"){c==null&&(c=k.currencyCode);const ue=(0,te.Qs)(c!=null?c:"",k,ie,E);if(ue==null)throw new Error("InternalErrorInvalidCurrencyCode");let Q=(0,q.mul)(G,ue.multiplier);Q=(0,q.toFixed)(Q,0,0),B.nativeAmount=Q,B.currencyCode=c}return{edgeParsedUri:B,parsedUri:A}}function K(k,C,p){if(k.publicAddress==null)throw new Error("InvalidPublicAddressError");if(p==null&&k.label==null&&k.message==null)return k.publicAddress;{let E="";p!=null&&(E+="amount="+p+"&"),(k.label!=null||k.message!=null)&&(typeof k.label=="string"&&(E+="label="+k.label+"&"),typeof k.message=="string"&&(E+="message="+k.message+"&")),E=E.substr(0,E.length-1);const c={scheme:C,path:k.publicAddress,query:E};return(0,M.qC)(c)}}},94831:function(Qe,ne,y){"use strict";y.r(ne),y.d(ne,{CosmosTools:function(){return Ge},makeCurrencyEngine:function(){return Kn},makeCurrencyTools:function(){return Xn}});var q=y(87137),Te=y(79562),M=y(28972),L=y(74087),S=y(77591),te=y(2153),J=y(42150),I=y(79325),Y=y(20918),oe=y(79014),z=y(76714),se=y(98994),re=y(2387),K=y(39385),k=y(7416),C=y(33359),p=y(24658),E=y(73034),c=y(82448),ie=y(62177);const A=["coin_spent.spender","coin_received.receiver"],Z=(0,c.su)({archivedTxLastCheckTime:(0,c.Vk)(c.mH,0),"coin_spent.spender":(0,c.Vk)(c.XC),"coin_received.receiver":(0,c.Vk)(c.XC)}),pe=(0,ie.jd)((0,c.su)({bech32Address:c.XC,publicKey:c.XC})),B=e=>{const n=(0,c.su)({[`${e}Mnemonic`]:c.XC});return(0,c.W1)(t=>({mnemonic:n(t)[`${e}Mnemonic`]}),t=>({[`${e}Mnemonic`]:t.mnemonic}))},ae=(0,c.su)({ninerealmsClientId:(0,c.Zz)(c.XC)}),ce=(0,c.su)({denom:c.XC,amount:c.XC}),le=(0,c.su)({gasFeeCoin:ce,gasLimit:c.XC,unsignedTxHex:c.XC}),G=(0,c.su)({native_outbound_fee_rune:c.XC,native_tx_fee_rune:c.XC}),ue=(0,c.su)({method:(0,c.Wf)("cosmos_getAccounts"),params:(0,c.su)({})}),Q=(0,c.Wf)("cosmos_signDirect"),we=(0,c.su)({method:Q,params:(0,c.su)({signerAddress:c.XC,signDoc:(0,c.su)({chainId:c.XC,accountNumber:c.XC,authInfoBytes:c.XC,bodyBytes:c.XC})})}),Ae=(0,c.su)({method:(0,c.Wf)("cosmos_signAmino"),params:(0,c.su)({signerAddress:c.XC,signDoc:(0,c.su)({chain_id:c.XC,account_number:c.XC,sequence:c.XC,memo:c.XC,msgs:(0,c._2)((0,c.su)({type:c.XC,value:c.JC})),fee:(0,c.su)({amount:(0,c._2)((0,c.su)({denom:c.XC,amount:c.XC})),gas:c.XC})})})});var ve=(e,n,t)=>new Promise((r,s)=>{var o=i=>{try{a(t.next(i))}catch(u){s(u)}},l=i=>{try{a(t.throw(i))}catch(u){s(u)}},a=i=>i.done?r(i.value):Promise.resolve(i.value).then(o,l);a((t=t.apply(e,n)).next())});const ke=(e,n)=>{const t=ae(n),r={},s=/{{(.*?)}}/g;for(const[o,l]of Object.entries(e.headers)){const a=s.exec(l);a!=null&&(r[o]=t[a[1]])}return{url:e.url,headers:r}},je=(e,n)=>{const{url:t,headers:r}=n;return{execute:s=>ve(void 0,null,function*(){const o={method:"POST",headers:r,body:JSON.stringify(s)};return yield(yield e(t,o)).json()}),disconnect:()=>{}}},en=e=>ve(void 0,null,function*(){const n=yield E.Comet38Client.create(e),t=(yield n.status()).nodeInfo.version;return t.startsWith("0.38.")?n:t.startsWith("0.37.")?yield E.Tendermint37Client.create(e):yield E.Tendermint34Client.create(e)}),be=(e,n)=>ve(void 0,null,function*(){const t=yield p.StargateClient.create(yield en(je(e,n))),r=t.forceGetCometClient();return{queryClient:p.QueryClient.withExtensions(r,p.setupAuthExtension,p.setupBankExtension,p.setupStakingExtension,p.setupTxExtension,p.setupIbcExtension),stargateClient:t,cometClient:r}}),nn=e=>{var n;const[t,...r]=e.split("."),s=e.includes("/"),o=r.join("."),l=(n=o==null?void 0:o.split("-"))==null?void 0:n[0];return{chain:t,symbol:o,ticker:l,synth:s}},$=e=>e.reduce((n,t)=>{try{return(0,C.addCoins)(n,t)}catch{}return n}),Se=(0,c.Wf)("amount"),tn=(0,c.Wf)("receiver"),on=(0,c.Wf)("spender"),sn=(0,c.Wf)("amount","receiver","spender"),rn=(0,c.su)({type:(0,c.Wf)("coin_received"),attributes:(0,c.vq)((0,c.su)({key:Se,value:c.XC}),(0,c.su)({key:tn,value:c.XC}))}),an=(0,c.su)({type:(0,c.Wf)("coin_spent"),attributes:(0,c.vq)((0,c.su)({key:Se,value:c.XC}),(0,c.su)({key:on,value:c.XC}))}),cn=(e,n)=>{const t=new Map;for(const s of e){const o={type:s.type,attributes:s.attributes.filter(i=>(0,c.Vk)(sn)(i.key)!=null).sort((i,u)=>i.key<u.key?-1:1)},l=(0,c.Vk)(rn)(o);if(l!=null){const[i,u]=l.attributes.map(d=>d.value);if(u!==n)continue;Ie(i).forEach(d=>{var v;const g=d.amount,h=(v=t.get(d.denom))!=null?v:"0";t.set(d.denom,(0,S.add)(g,h))});continue}const a=(0,c.Vk)(an)(o);if(a!=null){const[i,u]=a.attributes.map(d=>d.value);if(u!==n)continue;Ie(i).forEach(d=>{var v;const g=`-${d.amount}`,h=(v=t.get(d.denom))!=null?v:"0";t.set(d.denom,(0,S.add)(g,h))})}}const r=[];return t.forEach((s,o)=>{s!=="0"&&r.push({denom:o,amount:s})}),r},de=e=>{try{return I.YU.parse(e)}catch{return I.US.parse(e)}},Ie=e=>e.replace(/\s/g,"").split(",").filter(Boolean).map(n=>{var t;const r=n.match(/^([0-9]+)([a-zA-Z][a-zA-Z0-9/-]{2,127})$/);if(r==null)throw new Error(`Got an invalid coin string: ${e}`);return{amount:(t=r[1].replace(/^0+/,""))!=null?t:"0",denom:r[2]}}),ln=(e,n)=>{const t=J.chains.find(l=>l.bech32_prefix===(0,M.fromBech32)(n).prefix);if(t==null)throw new Error("Unrecognized denom");const r=t.chain_name,s=(0,k.getIbcInfo)(J.ibc,e,r);if(s==null)throw new Error(`No IBC channels between ${e} and ${r}`);const o=(0,k.getTransferChannel)(s);return e<r?{channel:o.chain_1.channel_id,port:o.chain_1.port_id}:{channel:o.chain_2.channel_id,port:o.chain_2.port_id}};var un=y(43720),x=y.n(un),dn=y(62100),f=y.n(dn);const Hn="common";function Pe(){return{chain:"",symbol:"",ticker:"",synth:!1}}const X={encode(e,n=f().Writer.create()){return e.chain!==""&&n.uint32(10).string(e.chain),e.symbol!==""&&n.uint32(18).string(e.symbol),e.ticker!==""&&n.uint32(26).string(e.ticker),e.synth===!0&&n.uint32(32).bool(e.synth),n},decode(e,n){const t=e instanceof f().Reader?e:f().Reader.create(e);let r=n===void 0?t.len:t.pos+n;const s=Pe();for(;t.pos<r;){const o=t.uint32();switch(o>>>3){case 1:if(o!==10)break;s.chain=t.string();continue;case 2:if(o!==18)break;s.symbol=t.string();continue;case 3:if(o!==26)break;s.ticker=t.string();continue;case 4:if(o!==32)break;s.synth=t.bool();continue}if((o&7)===4||o===0)break;t.skipType(o&7)}return s},fromJSON(e){return{chain:P(e.chain)?globalThis.String(e.chain):"",symbol:P(e.symbol)?globalThis.String(e.symbol):"",ticker:P(e.ticker)?globalThis.String(e.ticker):"",synth:P(e.synth)?globalThis.Boolean(e.synth):!1}},toJSON(e){const n={};return e.chain!==""&&(n.chain=e.chain),e.symbol!==""&&(n.symbol=e.symbol),e.ticker!==""&&(n.ticker=e.ticker),e.synth===!0&&(n.synth=e.synth),n},create(e){return X.fromPartial(e!=null?e:{})},fromPartial(e){var n,t,r,s;const o=Pe();return o.chain=(n=e.chain)!=null?n:"",o.symbol=(t=e.symbol)!=null?t:"",o.ticker=(r=e.ticker)!=null?r:"",o.synth=(s=e.synth)!=null?s:!1,o}};function Ee(){return{asset:void 0,amount:"",decimals:x().ZERO}}const w={encode(e,n=f().Writer.create()){return e.asset!==void 0&&X.encode(e.asset,n.uint32(10).fork()).ldelim(),e.amount!==""&&n.uint32(18).string(e.amount),e.decimals.isZero()||n.uint32(24).int64(e.decimals),n},decode(e,n){const t=e instanceof f().Reader?e:f().Reader.create(e);let r=n===void 0?t.len:t.pos+n;const s=Ee();for(;t.pos<r;){const o=t.uint32();switch(o>>>3){case 1:if(o!==10)break;s.asset=X.decode(t,t.uint32());continue;case 2:if(o!==18)break;s.amount=t.string();continue;case 3:if(o!==24)break;s.decimals=t.int64();continue}if((o&7)===4||o===0)break;t.skipType(o&7)}return s},fromJSON(e){return{asset:P(e.asset)?X.fromJSON(e.asset):void 0,amount:P(e.amount)?globalThis.String(e.amount):"",decimals:P(e.decimals)?x().fromValue(e.decimals):x().ZERO}},toJSON(e){const n={};return e.asset!==void 0&&(n.asset=X.toJSON(e.asset)),e.amount!==""&&(n.amount=e.amount),e.decimals.isZero()||(n.decimals=(e.decimals||x().ZERO).toString()),n},create(e){return w.fromPartial(e!=null?e:{})},fromPartial(e){var n;const t=Ee();return t.asset=e.asset!==void 0&&e.asset!==null?X.fromPartial(e.asset):void 0,t.amount=(n=e.amount)!=null?n:"",t.decimals=e.decimals!==void 0&&e.decimals!==null?x().fromValue(e.decimals):x().ZERO,t}};function xe(){return{secp256k1:"",ed25519:""}}const hn={encode(e,n=f().Writer.create()){return e.secp256k1!==""&&n.uint32(10).string(e.secp256k1),e.ed25519!==""&&n.uint32(18).string(e.ed25519),n},decode(e,n){const t=e instanceof f().Reader?e:f().Reader.create(e);let r=n===void 0?t.len:t.pos+n;const s=xe();for(;t.pos<r;){const o=t.uint32();switch(o>>>3){case 1:if(o!==10)break;s.secp256k1=t.string();continue;case 2:if(o!==18)break;s.ed25519=t.string();continue}if((o&7)===4||o===0)break;t.skipType(o&7)}return s},fromJSON(e){return{secp256k1:P(e.secp256k1)?globalThis.String(e.secp256k1):"",ed25519:P(e.ed25519)?globalThis.String(e.ed25519):""}},toJSON(e){const n={};return e.secp256k1!==""&&(n.secp256k1=e.secp256k1),e.ed25519!==""&&(n.ed25519=e.ed25519),n},create(e){return hn.fromPartial(e!=null?e:{})},fromPartial(e){var n,t;const r=xe();return r.secp256k1=(n=e.secp256k1)!=null?n:"",r.ed25519=(t=e.ed25519)!=null?t:"",r}};function Oe(){return{id:"",chain:"",fromAddress:"",toAddress:"",coins:[],gas:[],memo:""}}const fn={encode(e,n=f().Writer.create()){e.id!==""&&n.uint32(10).string(e.id),e.chain!==""&&n.uint32(18).string(e.chain),e.fromAddress!==""&&n.uint32(26).string(e.fromAddress),e.toAddress!==""&&n.uint32(34).string(e.toAddress);for(const t of e.coins)w.encode(t,n.uint32(42).fork()).ldelim();for(const t of e.gas)w.encode(t,n.uint32(50).fork()).ldelim();return e.memo!==""&&n.uint32(58).string(e.memo),n},decode(e,n){const t=e instanceof f().Reader?e:f().Reader.create(e);let r=n===void 0?t.len:t.pos+n;const s=Oe();for(;t.pos<r;){const o=t.uint32();switch(o>>>3){case 1:if(o!==10)break;s.id=t.string();continue;case 2:if(o!==18)break;s.chain=t.string();continue;case 3:if(o!==26)break;s.fromAddress=t.string();continue;case 4:if(o!==34)break;s.toAddress=t.string();continue;case 5:if(o!==42)break;s.coins.push(w.decode(t,t.uint32()));continue;case 6:if(o!==50)break;s.gas.push(w.decode(t,t.uint32()));continue;case 7:if(o!==58)break;s.memo=t.string();continue}if((o&7)===4||o===0)break;t.skipType(o&7)}return s},fromJSON(e){return{id:P(e.id)?globalThis.String(e.id):"",chain:P(e.chain)?globalThis.String(e.chain):"",fromAddress:P(e.fromAddress)?globalThis.String(e.fromAddress):"",toAddress:P(e.toAddress)?globalThis.String(e.toAddress):"",coins:globalThis.Array.isArray(e==null?void 0:e.coins)?e.coins.map(n=>w.fromJSON(n)):[],gas:globalThis.Array.isArray(e==null?void 0:e.gas)?e.gas.map(n=>w.fromJSON(n)):[],memo:P(e.memo)?globalThis.String(e.memo):""}},toJSON(e){var n,t;const r={};return e.id!==""&&(r.id=e.id),e.chain!==""&&(r.chain=e.chain),e.fromAddress!==""&&(r.fromAddress=e.fromAddress),e.toAddress!==""&&(r.toAddress=e.toAddress),(n=e.coins)!=null&&n.length&&(r.coins=e.coins.map(s=>w.toJSON(s))),(t=e.gas)!=null&&t.length&&(r.gas=e.gas.map(s=>w.toJSON(s))),e.memo!==""&&(r.memo=e.memo),r},create(e){return fn.fromPartial(e!=null?e:{})},fromPartial(e){var n,t,r,s,o,l,a;const i=Oe();return i.id=(n=e.id)!=null?n:"",i.chain=(t=e.chain)!=null?t:"",i.fromAddress=(r=e.fromAddress)!=null?r:"",i.toAddress=(s=e.toAddress)!=null?s:"",i.coins=((o=e.coins)==null?void 0:o.map(u=>w.fromPartial(u)))||[],i.gas=((l=e.gas)==null?void 0:l.map(u=>w.fromPartial(u)))||[],i.memo=(a=e.memo)!=null?a:"",i}};function De(){return{coins:[],poolDeduct:""}}const mn={encode(e,n=f().Writer.create()){for(const t of e.coins)w.encode(t,n.uint32(10).fork()).ldelim();return e.poolDeduct!==""&&n.uint32(18).string(e.poolDeduct),n},decode(e,n){const t=e instanceof f().Reader?e:f().Reader.create(e);let r=n===void 0?t.len:t.pos+n;const s=De();for(;t.pos<r;){const o=t.uint32();switch(o>>>3){case 1:if(o!==10)break;s.coins.push(w.decode(t,t.uint32()));continue;case 2:if(o!==18)break;s.poolDeduct=t.string();continue}if((o&7)===4||o===0)break;t.skipType(o&7)}return s},fromJSON(e){return{coins:globalThis.Array.isArray(e==null?void 0:e.coins)?e.coins.map(n=>w.fromJSON(n)):[],poolDeduct:P(e.poolDeduct)?globalThis.String(e.poolDeduct):""}},toJSON(e){var n;const t={};return(n=e.coins)!=null&&n.length&&(t.coins=e.coins.map(r=>w.toJSON(r))),e.poolDeduct!==""&&(t.poolDeduct=e.poolDeduct),t},create(e){return mn.fromPartial(e!=null?e:{})},fromPartial(e){var n,t;const r=De();return r.coins=((n=e.coins)==null?void 0:n.map(s=>w.fromPartial(s)))||[],r.poolDeduct=(t=e.poolDeduct)!=null?t:"",r}};function Be(){return{value:""}}const gn={encode(e,n=f().Writer.create()){return e.value!==""&&n.uint32(10).string(e.value),n},decode(e,n){const t=e instanceof f().Reader?e:f().Reader.create(e);let r=n===void 0?t.len:t.pos+n;const s=Be();for(;t.pos<r;){const o=t.uint32();switch(o>>>3){case 1:if(o!==10)break;s.value=t.string();continue}if((o&7)===4||o===0)break;t.skipType(o&7)}return s},fromJSON(e){return{value:P(e.value)?globalThis.String(e.value):""}},toJSON(e){const n={};return e.value!==""&&(n.value=e.value),n},create(e){return gn.fromPartial(e!=null?e:{})},fromPartial(e){var n;const t=Be();return t.value=(n=e.value)!=null?n:"",t}};f().util.Long!==x()&&(f().util.Long=x(),f().configure());function P(e){return e!=null}const Vn="types";function Ue(){return{coins:[],memo:"",signer:new Uint8Array(0)}}const he={encode(e,n=f().Writer.create()){for(const t of e.coins)w.encode(t,n.uint32(10).fork()).ldelim();return e.memo!==""&&n.uint32(18).string(e.memo),e.signer.length!==0&&n.uint32(26).bytes(e.signer),n},decode(e,n){const t=e instanceof f().Reader?e:f().Reader.create(e);let r=n===void 0?t.len:t.pos+n;const s=Ue();for(;t.pos<r;){const o=t.uint32();switch(o>>>3){case 1:if(o!==10)break;s.coins.push(w.decode(t,t.uint32()));continue;case 2:if(o!==18)break;s.memo=t.string();continue;case 3:if(o!==26)break;s.signer=t.bytes();continue}if((o&7)===4||o===0)break;t.skipType(o&7)}return s},fromJSON(e){return{coins:globalThis.Array.isArray(e==null?void 0:e.coins)?e.coins.map(n=>w.fromJSON(n)):[],memo:Ne(e.memo)?globalThis.String(e.memo):"",signer:Ne(e.signer)?yn(e.signer):new Uint8Array(0)}},toJSON(e){var n;const t={};return(n=e.coins)!=null&&n.length&&(t.coins=e.coins.map(r=>w.toJSON(r))),e.memo!==""&&(t.memo=e.memo),e.signer.length!==0&&(t.signer=pn(e.signer)),t},create(e){return he.fromPartial(e!=null?e:{})},fromPartial(e){var n,t,r;const s=Ue();return s.coins=((n=e.coins)==null?void 0:n.map(o=>w.fromPartial(o)))||[],s.memo=(t=e.memo)!=null?t:"",s.signer=(r=e.signer)!=null?r:new Uint8Array(0),s}};function yn(e){if(globalThis.Buffer)return Uint8Array.from(globalThis.Buffer.from(e,"base64"));{const n=globalThis.atob(e),t=new Uint8Array(n.length);for(let r=0;r<n.length;++r)t[r]=n.charCodeAt(r);return t}}function pn(e){if(globalThis.Buffer)return globalThis.Buffer.from(e).toString("base64");{const n=[];return e.forEach(t=>{n.push(globalThis.String.fromCharCode(t))}),globalThis.btoa(n.join(""))}}f().util.Long!==x()&&(f().util.Long=x(),f().configure());function Ne(e){return e!=null}const qn="cosmos.base.v1beta1";function Re(){return{denom:"",amount:""}}const H={encode(e,n=f().Writer.create()){return e.denom!==""&&n.uint32(10).string(e.denom),e.amount!==""&&n.uint32(18).string(e.amount),n},decode(e,n){const t=e instanceof f().Reader?e:f().Reader.create(e);let r=n===void 0?t.len:t.pos+n;const s=Re();for(;t.pos<r;){const o=t.uint32();switch(o>>>3){case 1:if(o!==10)break;s.denom=t.string();continue;case 2:if(o!==18)break;s.amount=t.string();continue}if((o&7)===4||o===0)break;t.skipType(o&7)}return s},fromJSON(e){return{denom:V(e.denom)?globalThis.String(e.denom):"",amount:V(e.amount)?globalThis.String(e.amount):""}},toJSON(e){const n={};return e.denom!==""&&(n.denom=e.denom),e.amount!==""&&(n.amount=e.amount),n},create(e){return H.fromPartial(e!=null?e:{})},fromPartial(e){var n,t;const r=Re();return r.denom=(n=e.denom)!=null?n:"",r.amount=(t=e.amount)!=null?t:"",r}};function Me(){return{denom:"",amount:""}}const vn={encode(e,n=f().Writer.create()){return e.denom!==""&&n.uint32(10).string(e.denom),e.amount!==""&&n.uint32(18).string(e.amount),n},decode(e,n){const t=e instanceof f().Reader?e:f().Reader.create(e);let r=n===void 0?t.len:t.pos+n;const s=Me();for(;t.pos<r;){const o=t.uint32();switch(o>>>3){case 1:if(o!==10)break;s.denom=t.string();continue;case 2:if(o!==18)break;s.amount=t.string();continue}if((o&7)===4||o===0)break;t.skipType(o&7)}return s},fromJSON(e){return{denom:V(e.denom)?globalThis.String(e.denom):"",amount:V(e.amount)?globalThis.String(e.amount):""}},toJSON(e){const n={};return e.denom!==""&&(n.denom=e.denom),e.amount!==""&&(n.amount=e.amount),n},create(e){return vn.fromPartial(e!=null?e:{})},fromPartial(e){var n,t;const r=Me();return r.denom=(n=e.denom)!=null?n:"",r.amount=(t=e.amount)!=null?t:"",r}};function _e(){return{int:""}}const kn={encode(e,n=f().Writer.create()){return e.int!==""&&n.uint32(10).string(e.int),n},decode(e,n){const t=e instanceof f().Reader?e:f().Reader.create(e);let r=n===void 0?t.len:t.pos+n;const s=_e();for(;t.pos<r;){const o=t.uint32();switch(o>>>3){case 1:if(o!==10)break;s.int=t.string();continue}if((o&7)===4||o===0)break;t.skipType(o&7)}return s},fromJSON(e){return{int:V(e.int)?globalThis.String(e.int):""}},toJSON(e){const n={};return e.int!==""&&(n.int=e.int),n},create(e){return kn.fromPartial(e!=null?e:{})},fromPartial(e){var n;const t=_e();return t.int=(n=e.int)!=null?n:"",t}};function Fe(){return{dec:""}}const Cn={encode(e,n=f().Writer.create()){return e.dec!==""&&n.uint32(10).string(e.dec),n},decode(e,n){const t=e instanceof f().Reader?e:f().Reader.create(e);let r=n===void 0?t.len:t.pos+n;const s=Fe();for(;t.pos<r;){const o=t.uint32();switch(o>>>3){case 1:if(o!==10)break;s.dec=t.string();continue}if((o&7)===4||o===0)break;t.skipType(o&7)}return s},fromJSON(e){return{dec:V(e.dec)?globalThis.String(e.dec):""}},toJSON(e){const n={};return e.dec!==""&&(n.dec=e.dec),n},create(e){return Cn.fromPartial(e!=null?e:{})},fromPartial(e){var n;const t=Fe();return t.dec=(n=e.dec)!=null?n:"",t}};f().util.Long!==x()&&(f().util.Long=x(),f().configure());function V(e){return e!=null}const Yn="types";function Le(){return{fromAddress:new Uint8Array(0),toAddress:new Uint8Array(0),amount:[]}}const fe={encode(e,n=f().Writer.create()){e.fromAddress.length!==0&&n.uint32(10).bytes(e.fromAddress),e.toAddress.length!==0&&n.uint32(18).bytes(e.toAddress);for(const t of e.amount)H.encode(t,n.uint32(26).fork()).ldelim();return n},decode(e,n){const t=e instanceof f().Reader?e:f().Reader.create(e);let r=n===void 0?t.len:t.pos+n;const s=Le();for(;t.pos<r;){const o=t.uint32();switch(o>>>3){case 1:if(o!==10)break;s.fromAddress=t.bytes();continue;case 2:if(o!==18)break;s.toAddress=t.bytes();continue;case 3:if(o!==26)break;s.amount.push(H.decode(t,t.uint32()));continue}if((o&7)===4||o===0)break;t.skipType(o&7)}return s},fromJSON(e){return{fromAddress:Ke(e.fromAddress)?We(e.fromAddress):new Uint8Array(0),toAddress:Ke(e.toAddress)?We(e.toAddress):new Uint8Array(0),amount:globalThis.Array.isArray(e==null?void 0:e.amount)?e.amount.map(n=>H.fromJSON(n)):[]}},toJSON(e){var n;const t={};return e.fromAddress.length!==0&&(t.fromAddress=Je(e.fromAddress)),e.toAddress.length!==0&&(t.toAddress=Je(e.toAddress)),(n=e.amount)!=null&&n.length&&(t.amount=e.amount.map(r=>H.toJSON(r))),t},create(e){return fe.fromPartial(e!=null?e:{})},fromPartial(e){var n,t,r;const s=Le();return s.fromAddress=(n=e.fromAddress)!=null?n:new Uint8Array(0),s.toAddress=(t=e.toAddress)!=null?t:new Uint8Array(0),s.amount=((r=e.amount)==null?void 0:r.map(o=>H.fromPartial(o)))||[],s}};function We(e){if(globalThis.Buffer)return Uint8Array.from(globalThis.Buffer.from(e,"base64"));{const n=globalThis.atob(e),t=new Uint8Array(n.length);for(let r=0;r<n.length;++r)t[r]=n.charCodeAt(r);return t}}function Je(e){if(globalThis.Buffer)return globalThis.Buffer.from(e).toString("base64");{const n=[];return e.forEach(t=>{n.push(globalThis.String.fromCharCode(t))}),globalThis.btoa(n.join(""))}}f().util.Long!==x()&&(f().util.Long=x(),f().configure());function Ke(e){return e!=null}var Tn=Object.defineProperty,wn=Object.defineProperties,An=Object.getOwnPropertyDescriptors,$e=Object.getOwnPropertySymbols,bn=Object.prototype.hasOwnProperty,Sn=Object.prototype.propertyIsEnumerable,Xe=(e,n,t)=>n in e?Tn(e,n,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[n]=t,In=(e,n)=>{for(var t in n||(n={}))bn.call(n,t)&&Xe(e,t,n[t]);if($e)for(var t of $e(n))Sn.call(n,t)&&Xe(e,t,n[t]);return e},Pn=(e,n)=>wn(e,An(n));const En=1e3*60*60*24,xn=e=>{const n=new L.Registry([["/ibc.applications.transfer.v1.MsgTransfer",K.MsgTransfer],["/cosmwasm.wasm.v1.MsgExecuteContract",re.$n]]);let t=s=>{const{amount:o,fromAddress:l,toAddress:a}=s;return{typeUrl:"/cosmos.bank.v1beta1.MsgSend",value:se.MsgSend.encode(se.MsgSend.fromPartial({fromAddress:l,toAddress:a,amount:o})).finish()}};const r=s=>{const{memo:o,toAddress:l,fromAddress:a,channel:i,port:u,amount:m}=s;return{typeUrl:"/ibc.applications.transfer.v1.MsgTransfer",value:K.MsgTransfer.encode(K.MsgTransfer.fromPartial({memo:o,receiver:l,sender:a,sourceChannel:i,sourcePort:u,token:m,timeoutTimestamp:BigInt((Date.now()+En)*1e6)})).finish()}};switch(e){case"thorchainrune":{const s="/types.MsgDeposit";n.register(s,he);const o=a=>{const{assets:i,memo:u,signer:m}=a,d=i.map(g=>Pn(In({},g),{asset:nn(g.asset)}));return{typeUrl:s,value:he.encode(he.fromPartial({coins:d,memo:u,signer:(0,M.fromBech32)(m).data})).finish()}},l="/types.MsgSend";return n.register(l,fe),t=a=>{const{amount:i,fromAddress:u,toAddress:m}=a;return{typeUrl:l,value:fe.encode(fe.fromPartial({fromAddress:(0,M.fromBech32)(u).data,toAddress:(0,M.fromBech32)(m).data,amount:i})).finish()}},{methods:{deposit:o,ibcTransfer:r,transfer:t},registry:n}}}return{methods:{ibcTransfer:r,transfer:t},registry:n}};var He=y(45504),O=y(29639),On=y(94935),Dn=y(16757),Bn=Object.defineProperty,Un=Object.defineProperties,Nn=Object.getOwnPropertyDescriptors,Ve=Object.getOwnPropertySymbols,Rn=Object.getPrototypeOf,Mn=Object.prototype.hasOwnProperty,_n=Object.prototype.propertyIsEnumerable,Fn=Reflect.get,qe=(e,n,t)=>n in e?Bn(e,n,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[n]=t,me=(e,n)=>{for(var t in n||(n={}))Mn.call(n,t)&&qe(e,t,n[t]);if(Ve)for(var t of Ve(n))_n.call(n,t)&&qe(e,t,n[t]);return e},Ye=(e,n)=>Un(e,Nn(n)),ze=(e,n,t)=>Fn(Rn(e),t,n),b=(e,n,t)=>new Promise((r,s)=>{var o=i=>{try{a(t.next(i))}catch(u){s(u)}},l=i=>{try{a(t.throw(i))}catch(u){s(u)}},a=i=>i.done?r(i.value):Promise.resolve(i.value).then(o,l);a((t=t.apply(e,n)).next())});const Ze=5e3,Ln=3e3,Wn=1e3*60*60*24*14,Jn=1e3*60*2;class ge extends Dn.P{constructor(n,t,r,s){super(n,t,r,s),this.networkInfo=n.networkInfo,this.fetchCors=n.io.fetchCors,this.accountNumber=0,this.sequence=0,this.unconfirmedTransactionCache={cacheSequence:0,txids:new Map},this.feeCache=new Map,this.stakedBalanceCache="0",this.stakingSupported=!0,this.otherMethods={getMaxTx:o=>b(this,null,function*(){switch(o.type){case"MakeTxDeposit":{if(this.tools.methods.deposit==null)throw new Error(`${this.currencyInfo.displayName} does not support the deposit method`);const{assets:l,memo:a}=o;if(l.length!==1)throw new Error("Cannot calculate max tx for more than one asset");const i=this.tools.methods.deposit({assets:l,memo:a,signer:this.walletInfo.keys.bech32Address}),{networkFee:u}=yield this.calculateFee({messages:[i],memo:a}),m=this.getBalance({tokenId:null});return(0,S.sub)(m,u)}default:throw new Error(`Invalid type: ${o.type}`)}}),makeTx:o=>b(this,null,function*(){switch(o.type){case"MakeTxDeposit":{if(this.tools.methods.deposit==null)throw new Error(`${this.currencyInfo.displayName} does not support the deposit method`);const{assets:l,memo:a,metadata:i}=o,u=this.tools.methods.deposit({assets:l,memo:a,signer:this.walletInfo.keys.bech32Address}),m=this.createUnsignedTxHex([u],a),{gasFeeCoin:d,gasLimit:v,networkFee:g}=yield this.calculateFee({messages:[u],memo:a}),h={gasFeeCoin:d,gasLimit:v,unsignedTxHex:m};return{blockHeight:0,currencyCode:this.currencyInfo.currencyCode,date:Date.now()/1e3,isSend:!0,memos:[],metadata:i,nativeAmount:`-${g}`,networkFee:g,otherParams:h,ourReceiveAddresses:[],signedTx:"",tokenId:null,txid:"",walletId:this.walletId}}default:throw new Error(`Invalid type: ${o.type}`)}}),parseWalletConnectV2Payload:o=>b(this,null,function*(){try{switch(o==null?void 0:o.method){case"cosmos_getAccounts":return{nativeAmount:"0",networkFee:"0",tokenId:null};case"cosmos_signDirect":{const l=we(o),{authInfoBytes:a,bodyBytes:i}=l.params.signDoc,u=O.TxBody.decode(de(i)),{nativeAmount:m,tokenId:d}=this.getAmountAndTokenIdFromKnownMessageTypes(u.messages),v=O.AuthInfo.decode(de(a));let g="0";const h=v.fee;return h!=null&&(g=$([(0,p.coin)("0",this.networkInfo.nativeDenom),...h.amount]).amount),{nativeAmount:m,networkFee:g,tokenId:d}}case"cosmos_signAmino":{const l=Ae(o),{signDoc:a}=l.params,i=(0,C.makeSignDoc)(a.msgs,a.fee,a.chain_id,a.memo,a.account_number,a.sequence),u=new p.AminoTypes(me(me({},p.createBankAminoConverters),p.createIbcAminoConverters)),m=i.msgs.map(T=>u.fromAmino(T)),{nativeAmount:d,tokenId:v}=this.getAmountAndTokenIdFromKnownMessageTypes(m);let g="0";const h=a.fee;return h!=null&&(g=$([(0,p.coin)("0",this.networkInfo.nativeDenom),...h.amount]).amount),{nativeAmount:d,networkFee:g,tokenId:v}}default:throw new Error(`Invalid method: ${o==null?void 0:o.method}`)}}catch(l){throw this.warn("Wallet connect call_request ",l),l}})}}tokenIdFromDenom(n){if(this.networkInfo.nativeDenom===n)return null;const t=Object.keys(this.allTokensMap).find(r=>{var s;return((s=this.allTokensMap[r].networkLocation)==null?void 0:s.contractAddress)===n});if(t===void 0)throw new Error(`Unrecognized denom: ${n}`);return t}getAmountAndTokenIdFromKnownMessageTypes(n){var t;let r=null,s;for(const o of n)switch(o.typeUrl){case"/ibc.applications.transfer.v1.MsgTransfer":{const l=this.tools.registry.decode(o),a=K.MsgTransfer.fromPartial(l);r===void 0&&(r=this.tokenIdFromDenom(a.token.denom));const i=(0,p.coin)(a.token.amount,a.token.denom);s==null?s=i:s=$([s,i]);break}case"/cosmwasm.wasm.v1.MsgExecuteContract":{const l=this.tools.registry.decode(o),a=re.$n.fromPartial(l),{funds:i}=a;if(i.length>0){const{denom:u}=i[0];r===void 0&&(r=this.tokenIdFromDenom(u));let m=(0,p.coin)("0",u);for(const d of i)m=$([m,d]);s==null?s=m:s=$([s,m])}break}default:}return{nativeAmount:(t=s==null?void 0:s.amount)!=null?t:"0",tokenId:r}}setOtherData(n){this.otherData=Z(n)}getClients(){if(this.tools.clients==null)throw new Error("No StargateClient");return this.tools.clients}queryBalance(){return b(this,null,function*(){var n;try{const{stargateClient:t}=this.getClients(),r=yield t.getAllBalances(this.walletInfo.keys.bech32Address),s=r.find(i=>i.denom===this.networkInfo.nativeDenom);this.updateBalance(this.currencyInfo.currencyCode,(n=s==null?void 0:s.amount)!=null?n:"0");const o=[];if(Object.keys(this.allTokensMap).forEach(i=>{var u;const m=this.allTokensMap[i],d=r.find(g=>{var h;return g.denom===((h=m.networkLocation)==null?void 0:h.contractAddress)}),v=(u=d==null?void 0:d.amount)!=null?u:"0";this.updateBalance(m.currencyCode,v),(0,S.gt)(v,"0")&&!this.enabledTokenIds.includes(i)&&o.push(i)}),o.length>0&&this.currencyEngineCallbacks.onNewTokens(o),this.stakingSupported)try{const i=yield t.getBalanceStaked(this.walletInfo.keys.bech32Address);if(i!=null&&this.stakedBalanceCache!==i.amount){const u={stakedAmounts:[{nativeAmount:i.amount}]};this.currencyEngineCallbacks.onStakingStatusChanged(u),this.stakedBalanceCache=i.amount}}catch(i){if(String(i).includes("unknown query path"))this.stakingSupported=!1;else throw i}const{accountNumber:l,sequence:a}=yield t.getSequence(this.walletInfo.keys.bech32Address);this.accountNumber=l,this.sequence=a}catch(t){String(t).includes("does not exist on chain")?this.updateBalance(this.currencyInfo.currencyCode,"0"):this.log.warn("queryBalance error:",t)}})}queryBlockheight(){return b(this,null,function*(){try{const{stargateClient:n}=this.getClients(),t=yield n.getHeight();t>this.walletLocalData.blockHeight&&(this.walletLocalData.blockHeight=t,this.walletLocalDataDirty=!0,this.currencyEngineCallbacks.onBlockHeightChanged(this.walletLocalData.blockHeight))}catch(n){this.error("queryBlockheight Error ",n)}})}queryTransactions(){return b(this,null,function*(){let n=0;const t=[this.currencyInfo.currencyCode,...this.enabledTokenIds.map(s=>this.allTokensMap[s].currencyCode)],r=Date.now()-Wn>this.otherData.archivedTxLastCheckTime?yield be(this.fetchCors,ke(this.networkInfo.archiveNode,this.tools.initOptions)):this.getClients();for(const s of A){const o=yield this.queryTransactionsInner(s,r);o!=null&&this.otherData[s]!==o&&(this.otherData[s]=o,this.walletLocalDataDirty=!0),n+=.5,t.forEach(l=>this.tokenCheckTransactionsStatus[l]=n),this.updateOnAddressesChecked()}this.otherData.archivedTxLastCheckTime=Date.now(),this.transactionsChangedArray.length>0&&(this.currencyEngineCallbacks.onTransactionsChanged(this.transactionsChangedArray),this.transactionsChangedArray=[])})}queryTransactionsInner(n,t){return b(this,null,function*(){const r={query:`${n}='${this.walletInfo.keys.bech32Address}'`,per_page:50,order_by:"desc"};let s,o=0,l,a=0,i=!1;try{do{const u=yield t.cometClient.txSearch(Ye(me({},r),{page:++o})),{totalCount:m,txs:d}=u;l==null&&(l=m),a=a+d.length;for(const v of d){const g=(0,M.toHex)(v.hash).toUpperCase();if(this.removeFromUnconfirmedCache(g),s==null&&(s=g),g===this.otherData[n]){i=!0;break}const h=v.result.events.map(p.fromTendermintEvent);let T=[];try{T=cn(h,this.walletInfo.keys.bech32Address)}catch(ee){this.log.warn("reduceCoinEventsForAddress error:",String(ee))}if(T.length===0)continue;const D=yield t.stargateClient.getBlock(v.height),U=(0,E.toSeconds)((0,E.fromRfc3339WithNanoseconds)(D.header.time)).seconds,{height:N,tx:W}=v,j=I.YU.stringify(W),{authInfo:{fee:_},body:{memo:ye,messages:F}}=(0,L.decodeTxRaw)(W),Ce=yield this.totalDynamicNetworkFee(F,D.header.height);T.forEach(ee=>{this.processCosmosTransaction(g,U,j,ee,ye,N,Ce,_)})}}while(l>a&&!i)}catch(u){throw this.log.warn("queryTransactions error:",u),u}return s})}processCosmosTransaction(n,t,r,s,o,l,a,i){const{amount:u,denom:m}=s,d=this.networkInfo.nativeDenom===m;let v;try{v=this.tokenIdFromDenom(m)}catch{return}const{currencyCode:g}=v==null?this.currencyInfo:this.allTokensMap[v];let h="0";if(i!=null){const{amount:_}=i,ye=$([(0,p.coin)("0",this.networkInfo.nativeDenom),..._]);h=(0,S.add)(h,ye.amount)}const T=(0,S.lt)(u,"0"),D=[];let U=u,N;T?d?(h=(0,S.add)(h,a),U=(0,S.sub)(U,h)):(h="0",N=a!=="0"?a:void 0):(D.push(this.walletInfo.keys.bech32Address),h="0");const W=[];o!==""&&W.push({type:"text",value:o});const j={blockHeight:l,currencyCode:g,date:t,isSend:T,memos:W,nativeAmount:U,networkFee:h,ourReceiveAddresses:D,parentNetworkFee:N,signedTx:r,tokenId:v,txid:n,walletId:this.walletId};this.addTransaction(g,j)}createUnsignedTxHex(n,t){const r=O.TxBody.fromPartial({messages:n,memo:t}),s=O.TxBody.encode(r).finish(),o=O.TxRaw.fromPartial({bodyBytes:s});return I.YU.stringify(O.TxRaw.encode(o).finish())}addToUnconfirmedCache(n){const t=new Date(new Date().getTime()+Jn);this.unconfirmedTransactionCache.txids.size===0&&(this.unconfirmedTransactionCache.cacheSequence=this.sequence),this.unconfirmedTransactionCache.txids.set(n,t)}removeFromUnconfirmedCache(n){this.unconfirmedTransactionCache.txids.has(n)&&(this.unconfirmedTransactionCache.cacheSequence=this.unconfirmedTransactionCache.cacheSequence+1,this.sequence=this.unconfirmedTransactionCache.cacheSequence,this.unconfirmedTransactionCache.txids.delete(n))}getSequence(){return this.unconfirmedTransactionCache.txids.size===0?this.sequence:[...this.unconfirmedTransactionCache.txids.values()].some(n=>n<new Date)?(this.unconfirmedTransactionCache.txids=new Map,this.sequence):this.unconfirmedTransactionCache.cacheSequence+this.unconfirmedTransactionCache.txids.size}totalDynamicNetworkFee(n,t){return b(this,null,function*(){let r="0";if(this.networkInfo.defaultTransactionFeeUrl==null)return r;const{url:s,headers:o}=ke(this.networkInfo.defaultTransactionFeeUrl,this.tools.initOptions),l=t==null?"":`?height=${t}`,i=yield(yield this.fetchCors(`${s}${l}`,{method:"GET",headers:o})).json(),u=G(i);for(const m of n)switch(m.typeUrl){case"/types.MsgDeposit":r=(0,S.add)(r,u.native_outbound_fee_rune);break;case"/types.MsgSend":r=(0,S.add)(r,u.native_tx_fee_rune)}return r})}calculateFee(n){return b(this,null,function*(){const{messages:t,memo:r,networkFeeOption:s}=n;let o=(0,p.coin)("0",this.networkInfo.nativeDenom),l="0",a="0";if(this.networkInfo.defaultTransactionFeeUrl==null){const{queryClient:i}=this.getClients(),{gasInfo:u}=yield i.tx.simulate(t,r,(0,C.encodeSecp256k1Pubkey)(I.YU.parse(this.walletInfo.keys.publicKey)),this.getSequence());if((u==null?void 0:u.gasUsed)==null)throw new Error("simulate didn't return gasUsed ");l=(0,S.ceil)((0,S.mul)(u==null?void 0:u.gasUsed.toString(),"1.5"),0);const{low:m,average:d,high:v}=(0,k.getGasPriceStep)(this.tools.chainData);let g=d;switch(s){case"low":{g=m;break}case"high":{g=v;break}case"custom":throw new Error("Custom fee not supported")}const h=(0,S.ceil)((0,S.mul)(l,g.toString()),0);o=(0,p.coin)(h,this.networkInfo.nativeDenom),a=o.amount}else a=yield this.totalDynamicNetworkFee(t),a=(0,S.mul)(a,"1.01");return{gasFeeCoin:o,gasLimit:l,networkFee:a}})}startEngine(){return b(this,null,function*(){this.engineOn=!0,yield this.tools.connectClient(),this.addToLoop("queryBalance",Ze).catch(()=>{}),this.addToLoop("queryBlockheight",Ze).catch(()=>{}),this.addToLoop("queryTransactions",Ln).catch(()=>{}),yield ze(ge.prototype,this,"startEngine").call(this)})}killEngine(){return b(this,null,function*(){yield this.tools.disconnectClient(),yield ze(ge.prototype,this,"killEngine").call(this)})}resyncBlockchain(){return b(this,null,function*(){yield this.killEngine(),yield this.clearBlockchainCache(),yield this.startEngine()})}validateTransfer(n,t,r){return b(this,null,function*(){var s;if(t==null)return;const o=this.allTokensMap[t],l=(0,Y.Oj)(o.networkLocation),a=l==null?void 0:l.contractAddress;if(a==null)throw new Error("Unknown denom");const{queryClient:i}=this.getClients();try{yield i.bank.denomMetadata(a);return}catch{const d=(s=(yield i.ibc.transfer.denomTrace(a)).denomTrace)==null?void 0:s.path.match(/transfer\/channel-\d+/);if(d==null||`${r.port}/${r.channel}`===d[0])return}throw new Error("Invalid transfer")})}makeSpend(n){return b(this,null,function*(){var t,r;const{edgeSpendInfo:s,currencyCode:o}=this.makeSpendCheck(n),{memos:l=[],networkFeeOption:a,tokenId:i}=s,u=(t=l[0])==null?void 0:t.value;if(s.spendTargets.length!==1)throw new Error("Error: only one output allowed");const{nativeAmount:m,publicAddress:d}=s.spendTargets[0];if(m==null)throw new On.$D;if(d==null)throw new Error("makeSpend Missing publicAddress");const v=i!=null?(r=this.allTokensMap[i].networkLocation)==null?void 0:r.contractAddress:this.networkInfo.nativeDenom;if(v==null)throw new Error("Unknown denom");let g;if(this.networkInfo.bech32AddressPrefix!==(0,M.fromBech32)(d).prefix){const F=ln(this.tools.chainData.chain_name,d);yield this.validateTransfer(d,i,F);const{channel:Ce,port:ee}=F;g=this.tools.methods.ibcTransfer({channel:Ce,port:ee,memo:u,amount:(0,p.coin)(m,v),fromAddress:this.walletInfo.keys.bech32Address,toAddress:d})}else g=this.tools.methods.transfer({amount:[(0,p.coin)(m,v)],fromAddress:this.walletInfo.keys.bech32Address,toAddress:d});let h,T,D;const U=`${d}${String(a)}`,N=this.feeCache.get(U);if(m==="0")h=(0,p.coin)("0",this.networkInfo.nativeDenom),T="0",D="0";else if(N==null){const F=yield this.calculateFee({messages:[g],memo:u,networkFeeOption:a});h=F.gasFeeCoin,T=F.gasLimit,D=F.networkFee,this.feeCache.set(U,F)}else h=N.gasFeeCoin,T=N.gasLimit,D=N.networkFee;const W=this.createUnsignedTxHex([g],u),j={gasFeeCoin:h,gasLimit:T,unsignedTxHex:W},_=this.makeEdgeTransactionAmounts(m,D,i);return this.checkBalances(_,i),{blockHeight:0,currencyCode:o,date:0,isSend:!0,memos:l,nativeAmount:_.nativeAmount,networkFee:_.networkFee,otherParams:j,ourReceiveAddresses:[],parentNetworkFee:_.parentNetworkFee,signedTx:"",tokenId:i,txid:"",walletId:this.walletId}})}signMessage(n,t,r){return b(this,null,function*(){const s=B(this.currencyInfo.pluginId)(t),o=yield this.tools.createSigner(s.mnemonic);if((r==null?void 0:r.otherParams)!=null)switch(r.otherParams.method){case"cosmos_getAccounts":{ue(r.otherParams);const h=(yield o.getAccounts()).map(T=>Ye(me({},T),{pubkey:I.US.stringify(T.pubkey)}));return JSON.stringify(h)}case"cosmos_signDirect":{const g=we(r.otherParams),{signDoc:h}=g.params,T=O.SignDoc.fromPartial({accountNumber:(0,He.longify)(h.accountNumber),authInfoBytes:de(h.authInfoBytes),bodyBytes:de(h.bodyBytes),chainId:h.chainId}),U={signature:(yield o.signDirect(this.walletInfo.keys.bech32Address,T)).signature,signed:g.params.signDoc};return JSON.stringify(U)}case"cosmos_signAmino":{const g=Ae(r.otherParams),{signDoc:h}=g.params,T=(0,C.makeSignDoc)(h.msgs,h.fee,h.chain_id,h.memo,h.account_number,h.sequence),N={signature:(yield(yield C.Secp256k1HdWallet.fromMnemonic(o.mnemonic)).signAmino(this.walletInfo.keys.bech32Address,T)).signature,signed:h};return JSON.stringify(N)}default:throw new Error(`Invalid method: ${r.method}`)}const l=I.YU.parse(n),a=O.SignDoc.decode(l),i=yield o.signDirect(this.walletInfo.keys.bech32Address,a),u=(0,C.decodeSignature)(i.signature),m=O.TxRaw.fromPartial({authInfoBytes:a.authInfoBytes,bodyBytes:a.bodyBytes,signatures:[u.signature]}),d=O.TxRaw.encode(m).finish();return I.YU.stringify(d)})}signTx(n,t){return b(this,null,function*(){const{gasFeeCoin:r,gasLimit:s,unsignedTxHex:o}=le(n.otherParams),l=B(this.currencyInfo.pluginId)(t),a=I.YU.parse(o),{bodyBytes:i}=O.TxRaw.decode(a),u=I.YU.parse(this.walletInfo.keys.publicKey),m=(0,C.encodeSecp256k1Pubkey)(u),d=(0,L.makeAuthInfoBytes)([{pubkey:(0,L.encodePubkey)(m),sequence:this.getSequence()}],[r],parseInt(s),void 0,void 0,1),v=O.SignDoc.fromPartial({accountNumber:(0,He.longify)(this.accountNumber),authInfoBytes:d,bodyBytes:i,chainId:this.tools.chainData.chain_id}),h=yield(yield this.tools.createSigner(l.mnemonic)).signDirect(this.walletInfo.keys.bech32Address,v),T=(0,C.decodeSignature)(h.signature),D=O.TxRaw.fromPartial({authInfoBytes:d,bodyBytes:i,signatures:[T.signature]}),U=O.TxRaw.encode(D).finish(),N=I.YU.stringify(U);return n.signedTx=N,n})}broadcastTx(n){return b(this,null,function*(){try{const t=I.YU.parse(n.signedTx),{stargateClient:r}=this.getClients(),s=yield r.broadcastTxSync(t);return this.warn(`SUCCESS broadcastTx
2
+ ${(0,z.oX)(n)}`),n.txid=s,n.date=Date.now()/1e3,this.addToUnconfirmedCache(s),n}catch(t){throw this.warn("FAILURE broadcastTx failed: ",t),t}})}getFreshAddress(n){return b(this,null,function*(){const{bech32Address:t}=this.walletInfo.keys;return{publicAddress:t}})}}function Kn(e,n,t,r){return b(this,null,function*(){const s=pe(t),o=new ge(e,n,s,r);return yield o.loadEngine(),o})}var $n=y(48764).Buffer,R=(e,n,t)=>new Promise((r,s)=>{var o=i=>{try{a(t.next(i))}catch(u){s(u)}},l=i=>{try{a(t.throw(i))}catch(u){s(u)}},a=i=>i.done?r(i.value):Promise.resolve(i.value).then(o,l);a((t=t.apply(e,n)).next())});class Ge{constructor(n){const{builtinTokens:t,currencyInfo:r,initOptions:s,io:o,networkInfo:l}=n;this.io=o,this.currencyInfo=r,this.builtinTokens=t,this.networkInfo=l,this.initOptions=s,this.clientCount=0;const{methods:a,registry:i}=xn(r.pluginId);this.methods=a,this.registry=i;const{chainId:u,url:m}=this.networkInfo.chainInfo,d=J.chains.find(g=>g.chain_id===u&&g.network_type==="mainnet");if(d==null)throw new Error("Unknown chain");this.chainData=d;const v=new q.ChainRegistryFetcher;v.fetch(m).then(()=>{this.chainData=v.getChain(this.chainData.chain_name)}).catch(g=>{})}createSigner(n){return R(this,null,function*(){const{bech32AddressPrefix:t,bip39Path:r}=this.networkInfo,s=(0,Te.stringToPath)(r);return yield L.DirectSecp256k1HdWallet.fromMnemonic(n,{hdPaths:[s],prefix:t})})}getDisplayPrivateKey(n){return R(this,null,function*(){const{pluginId:t}=this.currencyInfo;return B(t)(n.keys).mnemonic})}getDisplayPublicKey(n){return R(this,null,function*(){const{keys:t}=pe(n);return t.publicKey})}importPrivateKey(n){return R(this,null,function*(){if(!(0,te.validateMnemonic)(n))throw new Error("Invalid mnemonic");return yield this.createSigner(n),{[this.networkInfo.pluginMnemonicKeyName]:n}})}createPrivateKey(n){return R(this,null,function*(){if(n!==this.currencyInfo.walletType)throw new Error("InvalidWalletType");const t=$n.from(this.io.random(32)),r=(0,te.entropyToMnemonic)(t);return yield this.importPrivateKey(r)})}derivePublicKey(n){return R(this,null,function*(){if(n.type!==this.currencyInfo.walletType)throw new Error("InvalidWalletType");const{mnemonic:t}=B(this.currencyInfo.pluginId)(n.keys),s=yield(yield this.createSigner(t)).getAccounts(),{address:o,pubkey:l}=s[0],a=I.YU.stringify(l);return{bech32Address:o,publicKey:a}})}isValidOurAddress(n){try{if((0,M.fromBech32)(n).prefix===this.networkInfo.bech32AddressPrefix)return!0}catch{}return!1}isValidTargetAddress(n){try{const t=(0,M.fromBech32)(n);if(J.chains.find(s=>s.bech32_prefix===t.prefix)!=null)return!0}catch{}return!1}parseUri(n,t,r){return R(this,null,function*(){const{pluginId:s}=this.currencyInfo,o={[s]:!0},{parsedUri:l,edgeParsedUri:a}=(0,oe.k)(this.currencyInfo,n,o,this.builtinTokens,t!=null?t:this.currencyInfo.currencyCode,r);let i="";if(a.publicAddress!=null&&(i=a.publicAddress),!this.isValidTargetAddress(i))throw new Error("InvalidPublicAddressError");return a.uniqueIdentifier=l.query.memo,a})}encodeUri(n){return R(this,arguments,function*(t,r=[]){const{pluginId:s}=this.currencyInfo,{nativeAmount:o,currencyCode:l,publicAddress:a}=t;if(!this.isValidOurAddress(a))throw new Error("InvalidPublicAddressError");let i;if(typeof o=="string"){const m=(0,z.Qs)(l!=null?l:this.currencyInfo.currencyCode,this.currencyInfo,r,this.builtinTokens);if(m==null)throw new Error("InternalErrorInvalidCurrencyCode");i=(0,S.div)(o,m.multiplier,18)}return(0,oe.Q)(t,s,i)})}connectClient(){return R(this,null,function*(){this.clients==null&&(this.clients=yield be(this.io.fetchCors,ke(this.networkInfo.rpcNode,this.initOptions))),++this.clientCount})}disconnectClient(){return R(this,null,function*(){var n,t;--this.clientCount,this.clientCount===0&&(yield(t=(n=this.clients)==null?void 0:n.stargateClient)==null?void 0:t.disconnect(),this.clients=void 0)})}getTokenId(n){return R(this,null,function*(){(0,Y.Rp)(n);const t=(0,Y.Oj)(n.networkLocation);if(t==null)throw new Error("ErrorInvalidContractAddress");return t.contractAddress.toLowerCase().replace(/^ibc[/]/,"ibc")})}}function Xn(e){return R(this,null,function*(){return new Ge(e)})}},89214:function(){},20131:function(){},16026:function(){},52361:function(){},94616:function(){}}]);