edge-currency-accountbased 2.2.3 → 2.3.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 (88) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/android/src/main/assets/edge-currency-accountbased/234.chunk.js +35 -0
  3. package/android/src/main/assets/edge-currency-accountbased/248.chunk.js +35 -0
  4. package/android/src/main/assets/edge-currency-accountbased/336.chunk.js +9 -0
  5. package/android/src/main/assets/edge-currency-accountbased/612.chunk.js +1 -0
  6. package/android/src/main/assets/edge-currency-accountbased/{945.chunk.js → 814.chunk.js} +8 -8
  7. package/android/src/main/assets/edge-currency-accountbased/935.chunk.js +1 -1
  8. package/android/src/main/assets/edge-currency-accountbased/94.chunk.js +8 -0
  9. package/android/src/main/assets/edge-currency-accountbased/algorand.chunk.js +2 -2
  10. package/android/src/main/assets/edge-currency-accountbased/bnb.chunk.js +4 -4
  11. package/android/src/main/assets/edge-currency-accountbased/edge-currency-accountbased.js +10 -10
  12. package/android/src/main/assets/edge-currency-accountbased/eos.chunk.js +12 -12
  13. package/android/src/main/assets/edge-currency-accountbased/ethereum.chunk.js +5 -5
  14. package/android/src/main/assets/edge-currency-accountbased/filecoin.chunk.js +1 -1
  15. package/android/src/main/assets/edge-currency-accountbased/fio.chunk.js +2 -2
  16. package/android/src/main/assets/edge-currency-accountbased/hedera.chunk.js +2 -2
  17. package/android/src/main/assets/edge-currency-accountbased/polkadot.chunk.js +2 -2
  18. package/android/src/main/assets/edge-currency-accountbased/ripple.chunk.js +5 -5
  19. package/android/src/main/assets/edge-currency-accountbased/solana.chunk.js +3 -3
  20. package/android/src/main/assets/edge-currency-accountbased/stellar.chunk.js +4 -4
  21. package/android/src/main/assets/edge-currency-accountbased/tezos.chunk.js +3 -3
  22. package/android/src/main/assets/edge-currency-accountbased/tron.chunk.js +1 -1
  23. package/android/src/main/assets/edge-currency-accountbased/zcash.chunk.js +2 -2
  24. package/lib/algorand/AlgorandEngine.js +46 -24
  25. package/lib/algorand/algorandInfo.js +8 -7
  26. package/lib/algorand/algorandTestnetInfo.js +8 -7
  27. package/lib/binance/BinanceEngine.js +19 -17
  28. package/lib/binance/binanceInfo.js +10 -7
  29. package/lib/common/types.js +10 -0
  30. package/lib/common/upgradeMemos.js +52 -0
  31. package/lib/common/utf8.js +32 -0
  32. package/lib/common/validateMemos.js +107 -0
  33. package/lib/eos/EosEngine.js +42 -41
  34. package/lib/eos/info/eosCommonInfo.js +10 -0
  35. package/lib/eos/info/eosInfo.js +15 -17
  36. package/lib/eos/info/telosInfo.js +15 -15
  37. package/lib/eos/info/waxInfo.js +15 -16
  38. package/lib/ethereum/EthereumEngine.js +13 -12
  39. package/lib/ethereum/EthereumNetwork.js +16 -14
  40. package/lib/ethereum/info/avalancheInfo.js +17 -7
  41. package/lib/ethereum/info/binancesmartchainInfo.js +9 -7
  42. package/lib/ethereum/info/celoInfo.js +9 -7
  43. package/lib/ethereum/info/ethDevInfo.js +9 -7
  44. package/lib/ethereum/info/ethereumCommonInfo.js +10 -0
  45. package/lib/ethereum/info/ethereumInfo.js +17 -7
  46. package/lib/ethereum/info/ethereumclassicInfo.js +9 -7
  47. package/lib/ethereum/info/ethereumpowInfo.js +9 -7
  48. package/lib/ethereum/info/fantomInfo.js +9 -7
  49. package/lib/ethereum/info/goerliInfo.js +9 -7
  50. package/lib/ethereum/info/kovanInfo.js +9 -7
  51. package/lib/ethereum/info/optimismInfo.js +9 -7
  52. package/lib/ethereum/info/polygonInfo.js +9 -7
  53. package/lib/ethereum/info/pulsechainInfo.js +9 -7
  54. package/lib/ethereum/info/rinkebyInfo.js +9 -7
  55. package/lib/ethereum/info/ropstenInfo.js +9 -7
  56. package/lib/ethereum/info/rskInfo.js +9 -7
  57. package/lib/ethereum/info/zksyncInfo.js +9 -7
  58. package/lib/filecoin/FilecoinEngine.js +125 -87
  59. package/lib/filecoin/Filfox.js +68 -1
  60. package/lib/filecoin/filecoinInfo.js +5 -7
  61. package/lib/fio/FioEngine.js +25 -17
  62. package/lib/fio/fioInfo.js +8 -6
  63. package/lib/hedera/HederaEngine.js +22 -18
  64. package/lib/hedera/hederaInfo.js +11 -8
  65. package/lib/hedera/hederaTestnetInfo.js +6 -6
  66. package/lib/polkadot/PolkadotEngine.js +15 -9
  67. package/lib/polkadot/info/liberlandInfo.js +3 -2
  68. package/lib/polkadot/info/liberlandTestnetInfo.js +3 -2
  69. package/lib/polkadot/info/polkadotInfo.js +8 -5
  70. package/lib/ripple/RippleEngine.js +53 -75
  71. package/lib/ripple/rippleInfo.js +16 -8
  72. package/lib/solana/SolanaEngine.js +17 -12
  73. package/lib/solana/solanaInfo.js +9 -5
  74. package/lib/stellar/StellarEngine.js +31 -22
  75. package/lib/stellar/stellarInfo.js +16 -7
  76. package/lib/tezos/TezosEngine.js +17 -11
  77. package/lib/tezos/tezosInfo.js +8 -5
  78. package/lib/tron/TronEngine.js +85 -68
  79. package/lib/tron/tronInfo.js +8 -7
  80. package/lib/zcash/ZcashEngine.js +23 -23
  81. package/lib/zcash/piratechainInfo.js +8 -6
  82. package/lib/zcash/zcashInfo.js +7 -6
  83. package/package.json +2 -2
  84. package/android/src/main/assets/edge-currency-accountbased/124.chunk.js +0 -35
  85. package/android/src/main/assets/edge-currency-accountbased/223.chunk.js +0 -9
  86. package/android/src/main/assets/edge-currency-accountbased/650.chunk.js +0 -1
  87. package/android/src/main/assets/edge-currency-accountbased/689.chunk.js +0 -8
  88. package/android/src/main/assets/edge-currency-accountbased/826.chunk.js +0 -35
@@ -1,4 +1,4 @@
1
- "use strict";(self.webpackChunkedge_currency_accountbased=self.webpackChunkedge_currency_accountbased||[]).push([[679],{79014:function(ut,H,C){C.d(H,{Q:function(){return tt},k:function(){return Y}});var g=C(77591),P=C.n(g),U=C(24350),X=C(84564),m=C.n(X),n=C(76714),V=Object.defineProperty,B=Object.getOwnPropertySymbols,Q=Object.prototype.hasOwnProperty,M=Object.prototype.propertyIsEnumerable,J=(p,A,I)=>A in p?V(p,A,{enumerable:!0,configurable:!0,writable:!0,value:I}):p[A]=I,Z=(p,A)=>{for(var I in A||(A={}))Q.call(A,I)&&J(p,I,A[I]);if(B)for(var I of B(A))M.call(A,I)&&J(p,I,A[I]);return p};function Y(p,A,I,T,j=[]){const b=Z({},m()(A,{},!0)),K=A.startsWith(`${p.pluginId}://`);if(b.protocol!=null&&(b.protocol=b.protocol.replace(":","")),b.protocol!=null&&b.protocol!==""&&!I[b.protocol])throw new Error(`Uri protocol '${b.protocol}' is not supported for ${p.pluginId}.`);if(b.host===""&&b.pathname==="")throw new Error("Path and host not found in uri.");const D={publicAddress:b.host!==""?b.host:b.pathname.split("/")[0]},$=b.query.label,F=b.query.message,W=b.query.category;($!=null||F!=null||W!=null||K)&&(D.metadata={},D.metadata.name=$,D.metadata.notes=F,D.metadata.category=W,D.metadata.gateway=K!=null?K:!1);const L=b.query.amount;if(L!=null&&typeof L=="string"){T==null&&(T=p.currencyCode);const q=(0,n.Qs)(T!=null?T:"",p,j);if(q==null)throw new Error("InternalErrorInvalidCurrencyCode");let R=(0,g.mul)(L,q.multiplier);R=(0,g.toFixed)(R,0,0),D.nativeAmount=R,D.currencyCode=T}return{edgeParsedUri:D,parsedUri:b}}function tt(p,A,I){if(p.publicAddress==null)throw new Error("InvalidPublicAddressError");if(I==null&&p.label==null&&p.message==null)return p.publicAddress;{let T="";I!=null&&(T+="amount="+I+"&"),(p.label!=null||p.message!=null)&&(typeof p.label=="string"&&(T+="label="+p.label+"&"),typeof p.message=="string"&&(T+="message="+p.message+"&")),T=T.substr(0,T.length-1);const j={scheme:A,path:p.publicAddress,query:T};return(0,U.qC)(j)}}},58684:function(ut,H,C){C.r(H),C.d(H,{EosTools:function(){return at},checkAddress:function(){return x},getClient:function(){return N},makeCurrencyEngine:function(){return kt},makeCurrencyTools:function(){return Ct}});var g=C(15179),P=C(77591),U=C(20918),X=C(79014),m=C(76714),n=C(82448);const V=(0,n.su)({amount:n.XC,currencyCode:n.XC,expireTime:n.mH,paymentAddress:n.XC}),B=(0,n.su)({result:(0,n.su)(n.jK)}),Q=(0,n.su)({cpu:n.mH,net:n.mH,ram:n.mH}),M=(0,n.su)({trx_id:n.XC,"@timestamp":n.XC,block_num:n.mH,act:(0,n.su)({data:(0,n.su)({from:n.XC,to:n.XC,amount:n.mH,symbol:n.XC,memo:n.XC})})}),J=(0,n.su)({actions:(0,n._2)(M)}),Z=(0,n.su)({account_names:(0,n._2)(n.XC)}),Y=(0,n.su)({trace:(0,n.su)({block:(0,n.su)({num:n.mH,timestamp:n.XC}),id:n.XC,matchingActions:(0,n._2)((0,n.su)({json:(0,n.su)({from:n.XC,memo:n.XC,quantity:n.XC,to:n.XC})}))})}),tt=(0,n.su)({data:(0,n.su)({searchTransactionsBackward:(0,n.su)({results:(0,n._2)(Y)})})}),p=(0,n.su)({errors:(0,n._2)((0,n.su)({message:n.XC,extensions:(0,n.su)({code:n.XC,terminal:n.jK})}))}),A=`
1
+ "use strict";(self.webpackChunkedge_currency_accountbased=self.webpackChunkedge_currency_accountbased||[]).push([[679],{79014:function(ut,H,C){C.d(H,{Q:function(){return tt},k:function(){return Y}});var v=C(77591),P=C.n(v),U=C(24350),X=C(84564),y=C.n(X),n=C(76714),V=Object.defineProperty,B=Object.getOwnPropertySymbols,M=Object.prototype.hasOwnProperty,Q=Object.prototype.propertyIsEnumerable,J=(g,A,I)=>A in g?V(g,A,{enumerable:!0,configurable:!0,writable:!0,value:I}):g[A]=I,Z=(g,A)=>{for(var I in A||(A={}))M.call(A,I)&&J(g,I,A[I]);if(B)for(var I of B(A))Q.call(A,I)&&J(g,I,A[I]);return g};function Y(g,A,I,T,j=[]){const b=Z({},y()(A,{},!0)),K=A.startsWith(`${g.pluginId}://`);if(b.protocol!=null&&(b.protocol=b.protocol.replace(":","")),b.protocol!=null&&b.protocol!==""&&!I[b.protocol])throw new Error(`Uri protocol '${b.protocol}' is not supported for ${g.pluginId}.`);if(b.host===""&&b.pathname==="")throw new Error("Path and host not found in uri.");const D={publicAddress:b.host!==""?b.host:b.pathname.split("/")[0]},x=b.query.label,F=b.query.message,W=b.query.category;(x!=null||F!=null||W!=null||K)&&(D.metadata={},D.metadata.name=x,D.metadata.notes=F,D.metadata.category=W,D.metadata.gateway=K!=null?K:!1);const L=b.query.amount;if(L!=null&&typeof L=="string"){T==null&&(T=g.currencyCode);const G=(0,n.Qs)(T!=null?T:"",g,j);if(G==null)throw new Error("InternalErrorInvalidCurrencyCode");let R=(0,v.mul)(L,G.multiplier);R=(0,v.toFixed)(R,0,0),D.nativeAmount=R,D.currencyCode=T}return{edgeParsedUri:D,parsedUri:b}}function tt(g,A,I){if(g.publicAddress==null)throw new Error("InvalidPublicAddressError");if(I==null&&g.label==null&&g.message==null)return g.publicAddress;{let T="";I!=null&&(T+="amount="+I+"&"),(g.label!=null||g.message!=null)&&(typeof g.label=="string"&&(T+="label="+g.label+"&"),typeof g.message=="string"&&(T+="message="+g.message+"&")),T=T.substr(0,T.length-1);const j={scheme:A,path:g.publicAddress,query:T};return(0,U.qC)(j)}}},58684:function(ut,H,C){C.r(H),C.d(H,{EosTools:function(){return ct},checkAddress:function(){return $},getClient:function(){return N},makeCurrencyEngine:function(){return Ct},makeCurrencyTools:function(){return bt}});var v=C(45234),P=C(77591),U=C(20918),X=C(79014),y=C(76714),n=C(82448);const V=(0,n.su)({amount:n.XC,currencyCode:n.XC,expireTime:n.mH,paymentAddress:n.XC}),B=(0,n.su)({result:(0,n.su)(n.jK)}),M=(0,n.su)({cpu:n.mH,net:n.mH,ram:n.mH}),Q=(0,n.su)({trx_id:n.XC,"@timestamp":n.XC,block_num:n.mH,act:(0,n.su)({data:(0,n.su)({from:n.XC,to:n.XC,amount:n.mH,symbol:n.XC,memo:n.XC})})}),J=(0,n.su)({actions:(0,n._2)(Q)}),Z=(0,n.su)({account_names:(0,n._2)(n.XC)}),Y=(0,n.su)({trace:(0,n.su)({block:(0,n.su)({num:n.mH,timestamp:n.XC}),id:n.XC,matchingActions:(0,n._2)((0,n.su)({json:(0,n.su)({from:n.XC,memo:n.XC,quantity:n.XC,to:n.XC})}))})}),tt=(0,n.su)({data:(0,n.su)({searchTransactionsBackward:(0,n.su)({results:(0,n._2)(Y)})})}),g=(0,n.su)({errors:(0,n._2)((0,n.su)({message:n.XC,extensions:(0,n.su)({code:n.XC,terminal:n.jK})}))}),A=`
2
2
  query ($query: String!, $limit: Int64, $low: Int64, $high: Int64) {
3
3
  searchTransactionsBackward(query: $query, lowBlockNum: $low, highBlockNum: $high, limit: $limit) {
4
4
  results {
@@ -15,19 +15,19 @@ query ($query: String!, $limit: Int64, $low: Int64, $high: Int64) {
15
15
  }
16
16
  }
17
17
  }
18
- `,I=(0,n.su)({act:(0,n.su)({data:(0,n.su)({from:n.XC,to:n.XC,amount:n.mH,symbol:n.XC,memo:(0,n.Zz)(n.XC)})}),trx_id:n.XC,"@timestamp":n.XC,block_num:n.mH}),T=(0,n.su)({account:n.XC,name:(0,n.Wf)("transfer"),authorization:(0,n.vq)((0,n.su)({actor:n.XC,permission:(0,n.Wf)("active")})),data:(0,n.su)({from:n.XC,to:n.XC,quantity:n.XC,memo:(0,n.Zz)(n.XC)})}),j=(0,n.su)({actions:(0,n._2)(T),signatures:(0,n._2)(n.XC)}),b={structs:[{base:"",name:"transfer",fields:[{name:"from",type:"name"},{name:"to",type:"name"},{name:"quantity",type:"asset"},{name:"memo",type:"string"}]}],actions:[{name:"transfer",type:"transfer",ricardian_contract:""}]},K={structs:[{base:"",name:"powerup",fields:[{name:"payer",type:"name"},{name:"receiver",type:"name"},{name:"days",type:"int32"},{name:"net_frac",type:"int64"},{name:"cpu_frac",type:"int64"},{name:"max_payment",type:"asset"}]}],actions:[{name:"powerup",type:"powerup",ricardian_contract:""}]};var O=C(83718),D=C(51124),$=C(94935),F=C(84564),W=C.n(F),L=C(84650),q=Object.defineProperty,R=Object.defineProperties,lt=Object.getOwnPropertyDescriptors,rt=Object.getOwnPropertySymbols,ht=Object.getPrototypeOf,dt=Object.prototype.hasOwnProperty,ft=Object.prototype.propertyIsEnumerable,mt=Reflect.get,ot=(w,e,t)=>e in w?q(w,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):w[e]=t,et=(w,e)=>{for(var t in e||(e={}))dt.call(e,t)&&ot(w,t,e[t]);if(rt)for(var t of rt(e))ft.call(e,t)&&ot(w,t,e[t]);return w},nt=(w,e)=>R(w,lt(e)),st=(w,e,t)=>mt(ht(w),t,e),f=(w,e,t)=>new Promise((o,i)=>{var r=s=>{try{u(t.next(s))}catch(c){i(c)}},a=s=>{try{u(t.throw(s))}catch(c){i(c)}},u=s=>s.done?o(s.value):Promise.resolve(s.value).then(r,a);u((t=t.apply(w,e)).next())});const pt=1e4,yt=15e3,gt=1e4,wt=!0,vt=!0,it={ramdeathtest:!0,krpj4avazggi:!0,fobleos13125:!0};class G extends L.P{constructor(e,t,o,i){super(e,t,o,i);const{networkInfo:r}=e;this.fetchCors=(0,m.zR)(e.io),this.networkInfo=r,this.activatedAccountsCache={};const{currencyCode:a,denominations:u}=this.currencyInfo;this.referenceBlock={ref_block_num:0,ref_block_prefix:0},this.accountResources={cpu:0,net:0},this.accountNameChecked=!1,this.getResourcesMutex=!1,this.allTokens.push(nt(et({},u[0]),{currencyCode:a,currencyName:a,contractAddress:"eosio.token",denominations:u})),this.otherMethods={getAccountActivationQuote:s=>f(this,null,function*(){const{requestedAccountName:c,currencyCode:h,ownerPublicKey:l,activePublicKey:d,requestedAccountCurrencyCode:v}=s;if(h==null||c==null)throw new Error("ErrorInvalidParams");if(l==null&&d==null)throw new Error("ErrorInvalidParams");if(!x(c)){const y=new Error("ErrorInvalidAccountName");throw y.name="ErrorInvalidAccountName",y}const k={method:"POST",headers:{Accept:"application/json","Content-Type":"application/json"},body:JSON.stringify({requestedAccountName:c,currencyCode:h,ownerPublicKey:l,activePublicKey:d,requestedAccountCurrencyCode:v})};try{const y=yield(0,m.QJ)(this.networkInfo.eosActivationServers.map(_=>()=>f(this,null,function*(){const E=`${_}/api/v1/activateAccount`;return yield(yield this.fetchCors(E,k)).json()})),15e3);return V(y)}catch(y){throw this.error("getAccountActivationQuoteError: ",y),new Error("getAccountActivationQuoteError")}})}}setOtherData(e){this.otherData=(0,O.sr)(e)}checkBlockchainInnerLoop(){return f(this,null,function*(){try{const e=yield this.multicastServers("getInfo"),t=e.head_block_num.toNumber();this.walletLocalData.blockHeight!==t&&(this.checkDroppedTransactionsThrottled(),this.walletLocalData.blockHeight=t,this.walletLocalDataDirty=!0,this.currencyEngineCallbacks.onBlockHeightChanged(this.walletLocalData.blockHeight));const o=e.getTransactionHeader();this.referenceBlock={ref_block_num:o.ref_block_num.toNumber(),ref_block_prefix:o.ref_block_prefix.toNumber()}}catch(e){this.error("Error fetching height: ",e)}})}processIncomingTransaction(e){const t=(0,n.Vk)(I)(e);if(t==null)return this.error("Invalid supernode tx"),0;const{act:o,trx_id:i,block_num:r}=t,a=t["@timestamp"],{from:u,to:s,memo:c,symbol:h}=o.data,l=o.data.amount.toString(),d=h,v=[],k=(0,m.aL)(d,this.currencyInfo,this.allTokensMap);if(k==null)return this.log(`processIncomingTransaction Received unsupported currencyCode: ${d}`),0;let y=(0,P.mul)(l,k.multiplier),_="";s===this.otherData.accountName?(_=u,v.push(s),u===this.otherData.accountName&&(y="0")):(_=s,y=`-${y}`);const E={txid:i,date:Date.parse(a)/1e3,currencyCode:d,blockHeight:r>0?r:0,nativeAmount:y,isSend:y.startsWith("-"),networkFee:"0",parentNetworkFee:"0",ourReceiveAddresses:v,signedTx:"",otherParams:{},metadata:{name:_,notes:c},walletId:this.walletId};return this.addTransaction(d,E),E.blockHeight}processOutgoingTransaction(e){const t=[],o=e["@timestamp"].includes("Z")?e["@timestamp"]:e["@timestamp"]+"Z",i=Date.parse(o)/1e3,r=e.block_num>0?e.block_num:0;if(e.block_num==null)return this.error(`Invalid ${this.currencyInfo.currencyCode} transaction data. No tx block_num`),0;const a=e.trx_id;if(e.act==null)return this.error(`Invalid ${this.currencyInfo.currencyCode} transaction data. No action.act`),0;if(e.act.name==="transfer"){if(e.act.data==null)return this.error(`Invalid ${this.currencyInfo.currencyCode} transaction data. No action.act.data`),0;const{from:s,to:c,memo:h,amount:l,symbol:d}=e.act.data,v=l.toString(),k=d,y=(0,m.aL)(k,this.currencyInfo,this.allTokensMap);if(y==null)return this.error(`processOutgoingTransaction Received unsupported currencyCode: ${k}`),0;let _=(0,P.mul)(v,y.multiplier);c===this.otherData.accountName?(t.push(c),s===this.otherData.accountName&&(_="0")):_=`-${_}`;const E={txid:a,date:i,currencyCode:k,blockHeight:r,nativeAmount:_,isSend:_.startsWith("-"),networkFee:"0",parentNetworkFee:"0",ourReceiveAddresses:t,signedTx:"",metadata:{notes:h},otherParams:{fromAddress:s,toAddress:c},walletId:this.walletId};this.addTransaction(k,E)}return r}checkOutgoingTransactions(e,t){return f(this,null,function*(){var o,i;if(!vt)throw new Error("Dont use full node API");const r=10;let a=0,u=!1,s=(o=this.otherData.lastQueryActionSeq[t])!=null?o:0;for(;!u;){const c={direction:"outgoing",acct:e,currencyCode:t,skip:a,limit:r,low:s+1},h=yield this.multicastServers("getOutgoingTransactions",c);let l=[];if(h.actions!=null&&h.actions.length>0)l=h.actions;else break;for(let d=0;d<l.length;d++){const v=l[d],k=this.processOutgoingTransaction(v);if(k>s)s=k;else if(k===s&&d===0&&a===0){u=!0;break}}if(l==null||l.length<r)break;a+=10}s>((i=this.otherData.lastQueryActionSeq[t])!=null?i:0)&&(this.otherData.lastQueryActionSeq[t]=s,this.walletLocalDataDirty=!0)})}checkIncomingTransactions(e,t){return f(this,null,function*(){var o,i;if(!wt)throw new Error("Dont use Hyperion API");let r=(o=this.otherData.highestTxHeight[t])!=null?o:0;const a=10;let u=0,s=!1;for(;!s;){this.log("looping through checkIncomingTransactions, newHighestTxHeight: ",r);const c={direction:"incoming",acct:e,currencyCode:t,skip:u,limit:a,low:r+1},h=yield this.multicastServers("getIncomingTransactions",c);let l=[];if(h.actions.sort((d,v)=>v.block_num-d.block_num),h.actions.length>0)l=h.actions;else break;for(let d=0;d<l.length;d++){const v=l[d],k=this.processIncomingTransaction(v);if(k>r)r=k;else if(k===r&&d===0&&u===0){s=!0;break}}if(l.length===0||l.length<a)break;u+=10}r>((i=this.otherData.highestTxHeight[t])!=null?i:0)&&(this.otherData.highestTxHeight[t]=r,this.walletLocalDataDirty=!0)})}checkTransactionsInnerLoop(){return f(this,null,function*(){if(!this.accountNameChecked)return;const e=this.otherData.accountName;for(const t of this.enabledTokens){try{yield this.checkIncomingTransactions(e,t),yield this.checkOutgoingTransactions(e,t)}catch(o){if(e!==""){this.error("checkTransactionsInnerLoop fetches failed with error: ",o);return}}this.tokenCheckTransactionsStatus[t]=1,this.updateOnAddressesChecked(),this.transactionsChangedArray.length>0&&(this.currencyEngineCallbacks.onTransactionsChanged(this.transactionsChangedArray),this.transactionsChangedArray=[])}})}multicastServers(e,...t){return f(this,null,function*(){const{currencyCode:o}=this.currencyInfo;let i={result:"",server:"no server"};switch(e){case"getAccount":{i=yield(0,m.QJ)(this.networkInfo.eosNodes.map(r=>()=>f(this,null,function*(){const u=yield N(this.fetchCors,r).v1.chain.get_account(this.otherData.accountName);return{server:r,result:u}})));break}case"getIncomingTransactions":case"getOutgoingTransactions":{const{direction:r,acct:a,currencyCode:u,skip:s,limit:c,low:h}=t[0],l=this.networkInfo.eosHyperionNodes.map(v=>()=>f(this,null,function*(){const k=v+`/v2/history/get_actions?transfer.${r==="outgoing"?"from":"to"}=${a}&transfer.symbol=${u}&skip=${s}&limit=${c}&sort=desc`,y=yield this.fetchCors(k),_=W()(k,{},!0);if(!y.ok)throw this.error(`multicast in / out tx server error: ${v}`),new Error(`The server returned error code ${y.status} for ${_.hostname}`);const E=J(yield y.json());return{server:v,result:E}})),d=this.networkInfo.eosDfuseServers.map(v=>()=>f(this,null,function*(){if(this.currencyInfo.currencyCode!=="EOS")throw new Error("dfuse only supports EOS");const k=yield this.fetchCors(`${v}/graphql`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({query:A,variables:{query:`${r==="outgoing"?"auth":"receiver"}:${a} action:transfer`,limit:c,low:h}})}),y=(0,n._C)(tt,p)(yield k.json());if("errors"in y)throw this.warn(`dfuse ${v} get transactions failed: ${JSON.stringify(y.errors[0])}`),new Error(y.errors[0].message);const _=y.data.searchTransactionsBackward.results.map(E=>M({trx_id:E.trace.id,"@timestamp":E.trace.block.timestamp,block_num:E.trace.block.num,act:{data:{from:E.trace.matchingActions[0].json.from,to:E.trace.matchingActions[0].json.to,amount:Number(E.trace.matchingActions[0].json.quantity.split(" ")[0]),symbol:E.trace.matchingActions[0].json.quantity.split(" ")[1],memo:E.trace.matchingActions[0].json.memo}}}));return{server:v,result:{actions:_}}}));i=yield(0,m.QJ)([...l,...d]);break}case"getKeyAccounts":{const r=t[0],a=this.networkInfo.eosHyperionNodes.map(s=>()=>f(this,null,function*(){const h=yield N(this.fetchCors,s).v1.history.get_key_accounts(r);if(h.account_names.length===0)throw new Error(`${s} could not find account with public key: ${r}`);return{server:s,result:h.account_names[0].toString()}})),u=this.networkInfo.eosDfuseServers.map(s=>()=>f(this,null,function*(){if(this.currencyInfo.currencyCode!=="EOS")throw new Error("dfuse only supports EOS");const c=yield this.fetchCors(`${s}/v0/state/key_accounts?public_key=${r}`);if(!c.ok)throw new Error(`${s} get_account failed with ${c.status}`);const h=Z(yield c.json());if(h.account_names.length===0)throw new Error("dfuse returned empty array");return{server:s,result:h.account_names[0]}}));i=yield(0,m.QJ)([...a,...u]);break}case"getCurrencyBalance":{const r=t[0];i=yield(0,m.QJ)(this.networkInfo.eosNodes.map(a=>()=>f(this,null,function*(){const s=yield N(this.fetchCors,a).v1.chain.get_currency_balance(r,this.otherData.accountName);return{server:a,result:s}})));break}case"getInfo":{const{eosNodes:r}=this.networkInfo,a=(0,m.sD)(r,3);i=yield(0,m.QJ)(a.map(u=>()=>f(this,null,function*(){const c=yield N(this.fetchCors,u).v1.chain.get_info();return{server:u,result:c}})));break}case"getPowerUpState":{i=yield(0,m.QJ)(this.networkInfo.eosNodes.map(r=>()=>f(this,null,function*(){const a=N(this.fetchCors,r),s=yield new D._B({api:a}).v1.powerup.get_state();return{server:r,result:s}})));break}case"getResourceUsage":{i=yield(0,m.QJ)(this.networkInfo.eosNodes.map(r=>()=>f(this,null,function*(){const a=N(this.fetchCors,r),s=yield new D._B({api:a}).getSampledUsage();return{server:r,result:s}})));break}case"transact":{const{eosNodes:r}=this.networkInfo,a=(0,m.sD)(r,30);i=yield(0,m.QJ)(a.map(u=>()=>f(this,null,function*(){const s=t[0],h=yield N(this.fetchCors,u).v1.chain.send_transaction(s);return{server:u,result:h}})));break}}return this.log(`${o} multicastServers ${e} ${i.server} won`),i.result})}checkAccountInnerLoop(){return f(this,null,function*(){var e,t,o,i;const r=this.walletLocalData.publicKey;try{if(it[(e=this.otherData.accountName)!=null?e:""]&&(this.otherData.accountName="",this.walletLocalDataDirty=!0,this.currencyEngineCallbacks.onAddressChanged()),this.otherData.accountName===""){const a=yield this.multicastServers("getKeyAccounts",r);a!=null&&it[a]==null&&(this.otherData.accountName=a,this.accountNameChecked=!0,this.walletLocalDataDirty=!0,this.currencyEngineCallbacks.onAddressChanged())}}catch(a){/get_account failed with 400/.test(a==null?void 0:a.message)?this.accountNameChecked=!0:this.error("getKeyAccounts error: ",a)}try{if(this.otherData.accountName===""){for(const c of this.allTokens)this.updateBalance(c.currencyCode,"0");return}for(const c of this.allTokens)if(this.enabledTokens.includes(c.currencyCode)){const l=(i=(o=(t=(yield this.multicastServers("getCurrencyBalance",c.contractAddress))[0])==null?void 0:t.units)==null?void 0:o.toString())!=null?i:"0";this.updateBalance(c.currencyCode,l)}const a=yield this.multicastServers("getAccount"),{cpu_limit:u,net_limit:s}=a;this.accountResources={cpu:u.available.toNumber(),net:s.available.toNumber()}}catch(a){this.error("Error fetching account: ",a)}})}getResources(e){return f(this,null,function*(){if(this.getResourcesMutex)return;const{cpu:t,net:o}=this.accountResources;if(!(t>500&&o>500)){if(this.otherData.lastFreePowerUp>Date.now()-1e3*60*60*12){const i=(0,m.sD)(this.networkInfo.powerUpServers,1);try{const r=yield this.fetchCors(`${i}/${this.otherData.accountName}`);if(!r.ok)throw new Error(`getResources error ${r.status}`);this.otherData.lastFreePowerUp=Date.now(),this.walletLocalDataDirty=!0,this.log.warn("getResources freePowerUp SUCCESS");return}catch(r){this.log.warn("getResources lastFreePowerUp error",r)}}try{const i=yield this.multicastServers("getPowerUpState"),r=yield this.multicastServers("getResourceUsage"),a=i.cpu.frac(r,1e3),u=i.net.frac(r,1e3),s=[{account:"eosio",name:"powerup",authorization:[{actor:this.otherData.accountName,permission:"active"}],data:{payer:this.otherData.accountName,receiver:this.otherData.accountName,days:1,cpu_frac:a,net_frac:u,max_payment:"0.0003 EOS"}}],c={txid:"",date:0,currencyCode:this.currencyInfo.currencyCode,blockHeight:0,nativeAmount:"-3",isSend:!0,networkFee:"0",ourReceiveAddresses:[],signedTx:"",otherParams:{actions:s,signatures:[]},walletId:this.walletId},h=yield this.signTx(c,e);this.getResourcesMutex=!0,yield this.broadcastTx(h,{privateKeys:e}),this.log.warn("getResources purchase SUCCESS")}catch(i){this.log.warn(`getResources purchase FAILURE
19
- `,i)}finally{this.getResourcesMutex=!1}}})}clearBlockchainCache(){return f(this,null,function*(){this.activatedAccountsCache={},yield st(G.prototype,this,"clearBlockchainCache").call(this),this.otherData.lastQueryActionSeq={},this.otherData.highestTxHeight={},this.otherData.accountName="",this.accountNameChecked=!1})}startEngine(){return f(this,null,function*(){this.engineOn=!0,this.accountNameChecked=this.otherData.accountName!=="",this.addToLoop("checkBlockchainInnerLoop",yt).catch(()=>{}),this.addToLoop("checkAccountInnerLoop",pt).catch(()=>{}),this.addToLoop("checkTransactionsInnerLoop",gt).catch(()=>{}),yield st(G.prototype,this,"startEngine").call(this)})}resyncBlockchain(){return f(this,null,function*(){yield this.killEngine(),yield this.clearBlockchainCache(),yield this.startEngine()})}getFreshAddress(){return f(this,null,function*(){return this.otherData.accountName!=null?{publicAddress:this.otherData.accountName}:{publicAddress:"",publicKey:this.walletInfo.keys.publicKey,ownerPublicKey:this.walletInfo.keys.ownerPublicKey}})}makeSpend(e){return f(this,null,function*(){const{edgeSpendInfo:t,currencyCode:o,nativeBalance:i,denom:r}=this.makeSpendCheck(e),a=this.getTokenInfo(o);if(a==null)throw new Error("Unable to find token info");const{contractAddress:u="eosio.token"}=a,s=(0,m.aL)(o,this.currencyInfo,this.allTokensMap);if(s==null)throw new Error(`Error: no native denomination found for ${o}`);const c=s.multiplier.length-1;if(t.spendTargets.length!==1)throw new Error("Error: only one output allowed");const{publicAddress:h}=t.spendTargets[0];let{nativeAmount:l}=t.spendTargets[0];if(h==null)throw new Error("makeSpend Missing publicAddress");if(l==null)throw new $.$D;let d=!1;const v=this.activatedAccountsCache[h];if(v!==void 0&&!v)d=!0;else if(v===void 0)try{yield this.tools.getAccSystemStats(h),this.activatedAccountsCache[h]=!0}catch(z){if(z instanceof g.Hx&&z.details[0].message.includes("unknown key"))this.activatedAccountsCache[h]=!1,d=!0;else throw this.error("makeSpend eosPlugin.getAccSystemStats Error ",z),z}if(d)throw new Error("ErrorAccountNotActivated");if((0,P.eq)(l,"0"))throw new $.$D;const k=(0,P.div)(l,r.multiplier,c),y="0";if((0,P.gt)(l,i))throw new $.C_;const _=(0,P.toFixed)(k,c)+` ${o}`;let E="";t.spendTargets[0].otherParams!=null&&typeof t.spendTargets[0].otherParams.uniqueIdentifier=="string"&&(E=t.spendTargets[0].otherParams.uniqueIdentifier);const ct=[{account:u,name:"transfer",authorization:[{actor:this.otherData.accountName,permission:"active"}],data:{from:this.otherData.accountName,to:h,quantity:_,memo:E}}];l=`-${l}`;const bt={txid:"",date:0,currencyCode:o,blockHeight:0,nativeAmount:l,isSend:l.startsWith("-"),networkFee:y,ourReceiveAddresses:[],signedTx:"",otherParams:{actions:ct,signatures:[]},walletId:this.walletId};return this.warn(`${this.currencyInfo.currencyCode} tx prepared: ${l} ${this.walletLocalData.publicKey} -> ${h}`),bt})}signTx(e,t){return f(this,null,function*(){const o=(0,O.Vo)(t),i=(0,m.Xp)(e),r=i.actions[0].name==="transfer"?b:K,a=g.YW.from(nt(et({},this.referenceBlock),{expiration:new Date(new Date().getTime()+3e4),actions:i.actions}),r),u=a.signingDigest(this.networkInfo.chainId),c=g._q.from(o.eosKey).signDigest(u),h=g.uQ.from(nt(et({},a),{signatures:[c]}));i.signatures.push(c.toString());const d=g.f1.fromSigned(h).packed_trx.hexString;return e.signedTx=d,e.otherParams=i,e})}broadcastTx(e,t){return f(this,null,function*(){var o,i,r;const a=(0,O.Vo)(t==null?void 0:t.privateKeys);yield this.getResources(a);const u=(0,m.Xp)(e),{signatures:s}=u,c=g.f1.from({signatures:s,packed_trx:e.signedTx});try{const h=yield this.multicastServers("transact",c);return e.date=Date.now()/1e3,e.txid=h.transaction_id,this.warn(`SUCCESS broadcastTx
20
- ${(0,m.oX)(e)}`),e}catch(h){this.error(`
21
- Caught exception: `,h),h instanceof g.Hx&&this.error(JSON.stringify(h.error,null,2));let l=h;l.error!=null&&(this.error(`err.error= ${l.error}`),this.error(`err.error.name= ${l.error.name}`));try{l=JSON.parse(h)}catch{throw h}throw((o=l.error)==null?void 0:o.name)==="tx_net_usage_exceeded"?(l=new Error("Insufficient NET available to send EOS transaction"),l.name="ErrorEosInsufficientNet"):((i=l.error)==null?void 0:i.name)==="tx_cpu_usage_exceeded"?(l=new Error("Insufficient CPU available to send EOS transaction"),l.name="ErrorEosInsufficientCpu"):((r=l.error)==null?void 0:r.name)==="ram_usage_exceeded"&&(l=new Error("Insufficient RAM available to send EOS transaction"),l.name="ErrorEosInsufficientRam"),l}})}}function kt(w,e,t,o){return f(this,null,function*(){const i=(0,O.fz)(t),r=new G(w,e,i,o);return yield r.loadEngine(),r})}var S=(w,e,t)=>new Promise((o,i)=>{var r=s=>{try{u(t.next(s))}catch(c){i(c)}},a=s=>{try{u(t.throw(s))}catch(c){i(c)}},u=s=>s.done?o(s.value):Promise.resolve(s.value).then(r,a);u((t=t.apply(w,e)).next())});function x(w){return g.VG.pattern.test(w)}function N(w,e){const t=new g.c6(e,{fetch:w});return new g.lP({provider:t})}class at{constructor(e){const{builtinTokens:t,currencyInfo:o,io:i,log:r,networkInfo:a}=e;this.builtinTokens=t,this.currencyInfo=o,this.fetchCors=(0,m.zR)(e.io),this.io=i,this.log=r,this.networkInfo=a}getDisplayPrivateKey(e){return S(this,null,function*(){const t=(0,O.Vo)(e.keys);let o="";return o+=`owner key
22
- `+String(t.eosOwnerKey)+`
18
+ `,I=(0,n.su)({act:(0,n.su)({data:(0,n.su)({from:n.XC,to:n.XC,amount:n.mH,symbol:n.XC,memo:(0,n.Zz)(n.XC)})}),trx_id:n.XC,"@timestamp":n.XC,block_num:n.mH}),T=(0,n.su)({account:n.XC,name:(0,n.Wf)("transfer"),authorization:(0,n.vq)((0,n.su)({actor:n.XC,permission:(0,n.Wf)("active")})),data:(0,n.su)({from:n.XC,to:n.XC,quantity:n.XC,memo:(0,n.Zz)(n.XC)})}),j=(0,n.su)({actions:(0,n._2)(T),signatures:(0,n._2)(n.XC)}),b={structs:[{base:"",name:"transfer",fields:[{name:"from",type:"name"},{name:"to",type:"name"},{name:"quantity",type:"asset"},{name:"memo",type:"string"}]}],actions:[{name:"transfer",type:"transfer",ricardian_contract:""}]},K={structs:[{base:"",name:"powerup",fields:[{name:"payer",type:"name"},{name:"receiver",type:"name"},{name:"days",type:"int32"},{name:"net_frac",type:"int64"},{name:"cpu_frac",type:"int64"},{name:"max_payment",type:"asset"}]}],actions:[{name:"powerup",type:"powerup",ricardian_contract:""}]};var O=C(83718),D=C(84248),x=C(94935),F=C(84564),W=C.n(F),L=C(84650),G=C(72681),R=Object.defineProperty,lt=Object.defineProperties,ht=Object.getOwnPropertyDescriptors,rt=Object.getOwnPropertySymbols,dt=Object.getPrototypeOf,mt=Object.prototype.hasOwnProperty,ft=Object.prototype.propertyIsEnumerable,pt=Reflect.get,ot=(k,t,e)=>t in k?R(k,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):k[t]=e,et=(k,t)=>{for(var e in t||(t={}))mt.call(t,e)&&ot(k,e,t[e]);if(rt)for(var e of rt(t))ft.call(t,e)&&ot(k,e,t[e]);return k},nt=(k,t)=>lt(k,ht(t)),st=(k,t,e)=>pt(dt(k),e,t),p=(k,t,e)=>new Promise((o,s)=>{var r=i=>{try{u(e.next(i))}catch(a){s(a)}},c=i=>{try{u(e.throw(i))}catch(a){s(a)}},u=i=>i.done?o(i.value):Promise.resolve(i.value).then(r,c);u((e=e.apply(k,t)).next())});const yt=1e4,gt=15e3,wt=1e4,vt=!0,kt=!0,it={ramdeathtest:!0,krpj4avazggi:!0,fobleos13125:!0};class q extends L.P{constructor(t,e,o,s){super(t,e,o,s);const{networkInfo:r}=t;this.fetchCors=(0,y.zR)(t.io),this.networkInfo=r,this.activatedAccountsCache={};const{currencyCode:c,denominations:u}=this.currencyInfo;this.referenceBlock={ref_block_num:0,ref_block_prefix:0},this.accountResources={cpu:0,net:0},this.accountNameChecked=!1,this.getResourcesMutex=!1,this.allTokens.push(nt(et({},u[0]),{currencyCode:c,currencyName:c,contractAddress:"eosio.token",denominations:u})),this.otherMethods={getAccountActivationQuote:i=>p(this,null,function*(){const{requestedAccountName:a,currencyCode:h,ownerPublicKey:l,activePublicKey:d,requestedAccountCurrencyCode:m}=i;if(h==null||a==null)throw new Error("ErrorInvalidParams");if(l==null&&d==null)throw new Error("ErrorInvalidParams");if(!$(a)){const f=new Error("ErrorInvalidAccountName");throw f.name="ErrorInvalidAccountName",f}const w={method:"POST",headers:{Accept:"application/json","Content-Type":"application/json"},body:JSON.stringify({requestedAccountName:a,currencyCode:h,ownerPublicKey:l,activePublicKey:d,requestedAccountCurrencyCode:m})};try{const f=yield(0,y.QJ)(this.networkInfo.eosActivationServers.map(_=>()=>p(this,null,function*(){const E=`${_}/api/v1/activateAccount`;return yield(yield this.fetchCors(E,w)).json()})),15e3);return V(f)}catch(f){throw this.error("getAccountActivationQuoteError: ",f),new Error("getAccountActivationQuoteError")}})}}setOtherData(t){this.otherData=(0,O.sr)(t)}checkBlockchainInnerLoop(){return p(this,null,function*(){try{const t=yield this.multicastServers("getInfo"),e=t.head_block_num.toNumber();this.walletLocalData.blockHeight!==e&&(this.checkDroppedTransactionsThrottled(),this.walletLocalData.blockHeight=e,this.walletLocalDataDirty=!0,this.currencyEngineCallbacks.onBlockHeightChanged(this.walletLocalData.blockHeight));const o=t.getTransactionHeader();this.referenceBlock={ref_block_num:o.ref_block_num.toNumber(),ref_block_prefix:o.ref_block_prefix.toNumber()}}catch(t){this.error("Error fetching height: ",t)}})}processIncomingTransaction(t){const e=(0,n.Vk)(I)(t);if(e==null)return this.error("Invalid supernode tx"),0;const{act:o,trx_id:s,block_num:r}=e,c=e["@timestamp"],{from:u,to:i,memo:a,symbol:h}=o.data,l=o.data.amount.toString(),d=h,m=[],w=(0,y.aL)(d,this.currencyInfo,this.allTokensMap);if(w==null)return this.log(`processIncomingTransaction Received unsupported currencyCode: ${d}`),0;let f=(0,P.mul)(l,w.multiplier),_="";i===this.otherData.accountName?(_=u,m.push(i),u===this.otherData.accountName&&(f="0")):(_=i,f=`-${f}`);const E={blockHeight:r>0?r:0,currencyCode:d,date:Date.parse(c)/1e3,isSend:f.startsWith("-"),memos:[],metadata:{name:_,notes:a},nativeAmount:f,networkFee:"0",otherParams:{},ourReceiveAddresses:m,parentNetworkFee:"0",signedTx:"",txid:s,walletId:this.walletId};return this.addTransaction(d,E),E.blockHeight}processOutgoingTransaction(t){const e=[],o=t["@timestamp"].includes("Z")?t["@timestamp"]:t["@timestamp"]+"Z",s=Date.parse(o)/1e3,r=t.block_num>0?t.block_num:0;if(t.block_num==null)return this.error(`Invalid ${this.currencyInfo.currencyCode} transaction data. No tx block_num`),0;const c=t.trx_id;if(t.act==null)return this.error(`Invalid ${this.currencyInfo.currencyCode} transaction data. No action.act`),0;if(t.act.name==="transfer"){if(t.act.data==null)return this.error(`Invalid ${this.currencyInfo.currencyCode} transaction data. No action.act.data`),0;const{from:i,to:a,memo:h,amount:l,symbol:d}=t.act.data,m=l.toString(),w=d,f=(0,y.aL)(w,this.currencyInfo,this.allTokensMap);if(f==null)return this.error(`processOutgoingTransaction Received unsupported currencyCode: ${w}`),0;let _=(0,P.mul)(m,f.multiplier);a===this.otherData.accountName?(e.push(a),i===this.otherData.accountName&&(_="0")):_=`-${_}`;const E={blockHeight:r,currencyCode:w,date:s,isSend:_.startsWith("-"),memos:[],metadata:{notes:h},nativeAmount:_,networkFee:"0",otherParams:{fromAddress:i,toAddress:a},ourReceiveAddresses:e,parentNetworkFee:"0",signedTx:"",txid:c,walletId:this.walletId};this.addTransaction(w,E)}return r}checkOutgoingTransactions(t,e){return p(this,null,function*(){var o,s;if(!kt)throw new Error("Dont use full node API");const r=10;let c=0,u=!1,i=(o=this.otherData.lastQueryActionSeq[e])!=null?o:0;for(;!u;){const a={direction:"outgoing",acct:t,currencyCode:e,skip:c,limit:r,low:i+1},h=yield this.multicastServers("getOutgoingTransactions",a);let l=[];if(h.actions!=null&&h.actions.length>0)l=h.actions;else break;for(let d=0;d<l.length;d++){const m=l[d],w=this.processOutgoingTransaction(m);if(w>i)i=w;else if(w===i&&d===0&&c===0){u=!0;break}}if(l==null||l.length<r)break;c+=10}i>((s=this.otherData.lastQueryActionSeq[e])!=null?s:0)&&(this.otherData.lastQueryActionSeq[e]=i,this.walletLocalDataDirty=!0)})}checkIncomingTransactions(t,e){return p(this,null,function*(){var o,s;if(!vt)throw new Error("Dont use Hyperion API");let r=(o=this.otherData.highestTxHeight[e])!=null?o:0;const c=10;let u=0,i=!1;for(;!i;){this.log("looping through checkIncomingTransactions, newHighestTxHeight: ",r);const a={direction:"incoming",acct:t,currencyCode:e,skip:u,limit:c,low:r+1},h=yield this.multicastServers("getIncomingTransactions",a);let l=[];if(h.actions.sort((d,m)=>m.block_num-d.block_num),h.actions.length>0)l=h.actions;else break;for(let d=0;d<l.length;d++){const m=l[d],w=this.processIncomingTransaction(m);if(w>r)r=w;else if(w===r&&d===0&&u===0){i=!0;break}}if(l.length===0||l.length<c)break;u+=10}r>((s=this.otherData.highestTxHeight[e])!=null?s:0)&&(this.otherData.highestTxHeight[e]=r,this.walletLocalDataDirty=!0)})}checkTransactionsInnerLoop(){return p(this,null,function*(){if(!this.accountNameChecked)return;const t=this.otherData.accountName;for(const e of this.enabledTokens){try{yield this.checkIncomingTransactions(t,e),yield this.checkOutgoingTransactions(t,e)}catch(o){if(t!==""){this.error("checkTransactionsInnerLoop fetches failed with error: ",o);return}}this.tokenCheckTransactionsStatus[e]=1,this.updateOnAddressesChecked(),this.transactionsChangedArray.length>0&&(this.currencyEngineCallbacks.onTransactionsChanged(this.transactionsChangedArray),this.transactionsChangedArray=[])}})}multicastServers(t,...e){return p(this,null,function*(){const{currencyCode:o}=this.currencyInfo;let s={result:"",server:"no server"};switch(t){case"getAccount":{s=yield(0,y.QJ)(this.networkInfo.eosNodes.map(r=>()=>p(this,null,function*(){const u=yield N(this.fetchCors,r).v1.chain.get_account(this.otherData.accountName);return{server:r,result:u}})));break}case"getIncomingTransactions":case"getOutgoingTransactions":{const{direction:r,acct:c,currencyCode:u,skip:i,limit:a,low:h}=e[0],l=this.networkInfo.eosHyperionNodes.map(m=>()=>p(this,null,function*(){const w=m+`/v2/history/get_actions?transfer.${r==="outgoing"?"from":"to"}=${c}&transfer.symbol=${u}&skip=${i}&limit=${a}&sort=desc`,f=yield this.fetchCors(w),_=W()(w,{},!0);if(!f.ok)throw this.error(`multicast in / out tx server error: ${m}`),new Error(`The server returned error code ${f.status} for ${_.hostname}`);const E=J(yield f.json());return{server:m,result:E}})),d=this.networkInfo.eosDfuseServers.map(m=>()=>p(this,null,function*(){if(this.currencyInfo.currencyCode!=="EOS")throw new Error("dfuse only supports EOS");const w=yield this.fetchCors(`${m}/graphql`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({query:A,variables:{query:`${r==="outgoing"?"auth":"receiver"}:${c} action:transfer`,limit:a,low:h}})}),f=(0,n._C)(tt,g)(yield w.json());if("errors"in f)throw this.warn(`dfuse ${m} get transactions failed: ${JSON.stringify(f.errors[0])}`),new Error(f.errors[0].message);const _=f.data.searchTransactionsBackward.results.map(E=>Q({trx_id:E.trace.id,"@timestamp":E.trace.block.timestamp,block_num:E.trace.block.num,act:{data:{from:E.trace.matchingActions[0].json.from,to:E.trace.matchingActions[0].json.to,amount:Number(E.trace.matchingActions[0].json.quantity.split(" ")[0]),symbol:E.trace.matchingActions[0].json.quantity.split(" ")[1],memo:E.trace.matchingActions[0].json.memo}}}));return{server:m,result:{actions:_}}}));s=yield(0,y.QJ)([...l,...d]);break}case"getKeyAccounts":{const r=e[0],c=this.networkInfo.eosHyperionNodes.map(i=>()=>p(this,null,function*(){const h=yield N(this.fetchCors,i).v1.history.get_key_accounts(r);if(h.account_names.length===0)throw new Error(`${i} could not find account with public key: ${r}`);return{server:i,result:h.account_names[0].toString()}})),u=this.networkInfo.eosDfuseServers.map(i=>()=>p(this,null,function*(){if(this.currencyInfo.currencyCode!=="EOS")throw new Error("dfuse only supports EOS");const a=yield this.fetchCors(`${i}/v0/state/key_accounts?public_key=${r}`);if(!a.ok)throw new Error(`${i} get_account failed with ${a.status}`);const h=Z(yield a.json());if(h.account_names.length===0)throw new Error("dfuse returned empty array");return{server:i,result:h.account_names[0]}}));s=yield(0,y.QJ)([...c,...u]);break}case"getCurrencyBalance":{const r=e[0];s=yield(0,y.QJ)(this.networkInfo.eosNodes.map(c=>()=>p(this,null,function*(){const i=yield N(this.fetchCors,c).v1.chain.get_currency_balance(r,this.otherData.accountName);return{server:c,result:i}})));break}case"getInfo":{const{eosNodes:r}=this.networkInfo,c=(0,y.sD)(r,3);s=yield(0,y.QJ)(c.map(u=>()=>p(this,null,function*(){const a=yield N(this.fetchCors,u).v1.chain.get_info();return{server:u,result:a}})));break}case"getPowerUpState":{s=yield(0,y.QJ)(this.networkInfo.eosNodes.map(r=>()=>p(this,null,function*(){const c=N(this.fetchCors,r),i=yield new D._B({api:c}).v1.powerup.get_state();return{server:r,result:i}})));break}case"getResourceUsage":{s=yield(0,y.QJ)(this.networkInfo.eosNodes.map(r=>()=>p(this,null,function*(){const c=N(this.fetchCors,r),i=yield new D._B({api:c}).getSampledUsage();return{server:r,result:i}})));break}case"transact":{const{eosNodes:r}=this.networkInfo,c=(0,y.sD)(r,30);s=yield(0,y.QJ)(c.map(u=>()=>p(this,null,function*(){const i=e[0],h=yield N(this.fetchCors,u).v1.chain.send_transaction(i);return{server:u,result:h}})));break}}return this.log(`${o} multicastServers ${t} ${s.server} won`),s.result})}checkAccountInnerLoop(){return p(this,null,function*(){var t,e,o,s;const r=this.walletLocalData.publicKey;try{if(it[(t=this.otherData.accountName)!=null?t:""]&&(this.otherData.accountName="",this.walletLocalDataDirty=!0,this.currencyEngineCallbacks.onAddressChanged()),this.otherData.accountName===""){const c=yield this.multicastServers("getKeyAccounts",r);c!=null&&it[c]==null&&(this.otherData.accountName=c,this.accountNameChecked=!0,this.walletLocalDataDirty=!0,this.currencyEngineCallbacks.onAddressChanged())}}catch(c){/get_account failed with 400/.test(c==null?void 0:c.message)?this.accountNameChecked=!0:this.error("getKeyAccounts error: ",c)}try{if(this.otherData.accountName===""){for(const a of this.allTokens)this.updateBalance(a.currencyCode,"0");return}for(const a of this.allTokens)if(this.enabledTokens.includes(a.currencyCode)){const l=(s=(o=(e=(yield this.multicastServers("getCurrencyBalance",a.contractAddress))[0])==null?void 0:e.units)==null?void 0:o.toString())!=null?s:"0";this.updateBalance(a.currencyCode,l)}const c=yield this.multicastServers("getAccount"),{cpu_limit:u,net_limit:i}=c;this.accountResources={cpu:u.available.toNumber(),net:i.available.toNumber()}}catch(c){this.error("Error fetching account: ",c)}})}getResources(t){return p(this,null,function*(){if(this.getResourcesMutex)return;const{cpu:e,net:o}=this.accountResources;if(!(e>500&&o>500)){if(this.otherData.lastFreePowerUp>Date.now()-1e3*60*60*12){const s=(0,y.sD)(this.networkInfo.powerUpServers,1);try{const r=yield this.fetchCors(`${s}/${this.otherData.accountName}`);if(!r.ok)throw new Error(`getResources error ${r.status}`);this.otherData.lastFreePowerUp=Date.now(),this.walletLocalDataDirty=!0,this.log.warn("getResources freePowerUp SUCCESS");return}catch(r){this.log.warn("getResources lastFreePowerUp error",r)}}try{const s=yield this.multicastServers("getPowerUpState"),r=yield this.multicastServers("getResourceUsage"),c=s.cpu.frac(r,1e3),u=s.net.frac(r,1e3),i=[{account:"eosio",name:"powerup",authorization:[{actor:this.otherData.accountName,permission:"active"}],data:{payer:this.otherData.accountName,receiver:this.otherData.accountName,days:1,cpu_frac:c,net_frac:u,max_payment:"0.0003 EOS"}}],a={blockHeight:0,currencyCode:this.currencyInfo.currencyCode,date:0,isSend:!0,memos:[],nativeAmount:"-3",networkFee:"0",otherParams:{actions:i,signatures:[]},ourReceiveAddresses:[],signedTx:"",txid:"",walletId:this.walletId},h=yield this.signTx(a,t);this.getResourcesMutex=!0,yield this.broadcastTx(h,{privateKeys:t}),this.log.warn("getResources purchase SUCCESS")}catch(s){this.log.warn(`getResources purchase FAILURE
19
+ `,s)}finally{this.getResourcesMutex=!1}}})}clearBlockchainCache(){return p(this,null,function*(){this.activatedAccountsCache={},yield st(q.prototype,this,"clearBlockchainCache").call(this),this.otherData.lastQueryActionSeq={},this.otherData.highestTxHeight={},this.otherData.accountName="",this.accountNameChecked=!1})}startEngine(){return p(this,null,function*(){this.engineOn=!0,this.accountNameChecked=this.otherData.accountName!=="",this.addToLoop("checkBlockchainInnerLoop",gt).catch(()=>{}),this.addToLoop("checkAccountInnerLoop",yt).catch(()=>{}),this.addToLoop("checkTransactionsInnerLoop",wt).catch(()=>{}),yield st(q.prototype,this,"startEngine").call(this)})}resyncBlockchain(){return p(this,null,function*(){yield this.killEngine(),yield this.clearBlockchainCache(),yield this.startEngine()})}getFreshAddress(){return p(this,null,function*(){return this.otherData.accountName!=null?{publicAddress:this.otherData.accountName}:{publicAddress:"",publicKey:this.walletInfo.keys.publicKey,ownerPublicKey:this.walletInfo.keys.ownerPublicKey}})}makeSpend(t){return p(this,null,function*(){var e;t=(0,G.s)(t,this.currencyInfo);const{edgeSpendInfo:o,currencyCode:s,nativeBalance:r,denom:c}=this.makeSpendCheck(t),{memos:u=[]}=o,i=this.getTokenInfo(s);if(i==null)throw new Error("Unable to find token info");const{contractAddress:a="eosio.token"}=i,h=(0,y.aL)(s,this.currencyInfo,this.allTokensMap);if(h==null)throw new Error(`Error: no native denomination found for ${s}`);const l=h.multiplier.length-1;if(o.spendTargets.length!==1)throw new Error("Error: only one output allowed");const{publicAddress:d}=o.spendTargets[0];let{nativeAmount:m}=o.spendTargets[0];if(d==null)throw new Error("makeSpend Missing publicAddress");if(m==null)throw new x.$D;let w=!1;const f=this.activatedAccountsCache[d];if(f!==void 0&&!f)w=!0;else if(f===void 0)try{yield this.tools.getAccSystemStats(d),this.activatedAccountsCache[d]=!0}catch(z){if(z instanceof v.Hx&&z.details[0].message.includes("unknown key"))this.activatedAccountsCache[d]=!1,w=!0;else throw this.error("makeSpend eosPlugin.getAccSystemStats Error ",z),z}if(w)throw new Error("ErrorAccountNotActivated");if((0,P.eq)(m,"0"))throw new x.$D;const _=(0,P.div)(m,c.multiplier,l),E="0";if((0,P.gt)(m,r))throw new x.C_;const at=(0,P.toFixed)(_,l)+` ${s}`,Et=((e=u[0])==null?void 0:e.type)==="text"?u[0].value:void 0,At=[{account:a,name:"transfer",authorization:[{actor:this.otherData.accountName,permission:"active"}],data:{from:this.otherData.accountName,to:d,quantity:at,memo:Et}}];m=`-${m}`;const It={blockHeight:0,currencyCode:s,date:0,isSend:m.startsWith("-"),memos:u,nativeAmount:m,networkFee:E,otherParams:{actions:At,signatures:[]},ourReceiveAddresses:[],signedTx:"",txid:"",walletId:this.walletId};return this.warn(`${this.currencyInfo.currencyCode} tx prepared: ${m} ${this.walletLocalData.publicKey} -> ${d}`),It})}signTx(t,e){return p(this,null,function*(){const o=(0,O.Vo)(e),s=(0,y.Xp)(t),r=s.actions[0].name==="transfer"?b:K,c=v.YW.from(nt(et({},this.referenceBlock),{expiration:new Date(new Date().getTime()+3e4),actions:s.actions}),r),u=c.signingDigest(this.networkInfo.chainId),a=v._q.from(o.eosKey).signDigest(u),h=v.uQ.from(nt(et({},c),{signatures:[a]}));s.signatures.push(a.toString());const d=v.f1.fromSigned(h).packed_trx.hexString;return t.signedTx=d,t.otherParams=s,t})}broadcastTx(t,e){return p(this,null,function*(){var o,s,r;const c=(0,O.Vo)(e==null?void 0:e.privateKeys);yield this.getResources(c);const u=(0,y.Xp)(t),{signatures:i}=u,a=v.f1.from({signatures:i,packed_trx:t.signedTx});try{const h=yield this.multicastServers("transact",a);return t.date=Date.now()/1e3,t.txid=h.transaction_id,this.warn(`SUCCESS broadcastTx
20
+ ${(0,y.oX)(t)}`),t}catch(h){this.error(`
21
+ Caught exception: `,h),h instanceof v.Hx&&this.error(JSON.stringify(h.error,null,2));let l=h;l.error!=null&&(this.error(`err.error= ${l.error}`),this.error(`err.error.name= ${l.error.name}`));try{l=JSON.parse(h)}catch{throw h}throw((o=l.error)==null?void 0:o.name)==="tx_net_usage_exceeded"?(l=new Error("Insufficient NET available to send EOS transaction"),l.name="ErrorEosInsufficientNet"):((s=l.error)==null?void 0:s.name)==="tx_cpu_usage_exceeded"?(l=new Error("Insufficient CPU available to send EOS transaction"),l.name="ErrorEosInsufficientCpu"):((r=l.error)==null?void 0:r.name)==="ram_usage_exceeded"&&(l=new Error("Insufficient RAM available to send EOS transaction"),l.name="ErrorEosInsufficientRam"),l}})}}function Ct(k,t,e,o){return p(this,null,function*(){const s=(0,O.fz)(e),r=new q(k,t,s,o);return yield r.loadEngine(),r})}var S=(k,t,e)=>new Promise((o,s)=>{var r=i=>{try{u(e.next(i))}catch(a){s(a)}},c=i=>{try{u(e.throw(i))}catch(a){s(a)}},u=i=>i.done?o(i.value):Promise.resolve(i.value).then(r,c);u((e=e.apply(k,t)).next())});function $(k){return v.VG.pattern.test(k)}function N(k,t){const e=new v.c6(t,{fetch:k});return new v.lP({provider:e})}class ct{constructor(t){const{builtinTokens:e,currencyInfo:o,io:s,log:r,networkInfo:c}=t;this.builtinTokens=e,this.currencyInfo=o,this.fetchCors=(0,y.zR)(t.io),this.io=s,this.log=r,this.networkInfo=c}getDisplayPrivateKey(t){return S(this,null,function*(){const e=(0,O.Vo)(t.keys);let o="";return o+=`owner key
22
+ `+String(e.eosOwnerKey)+`
23
23
 
24
24
  `,o+=`active key
25
- `+String(t.eosKey)+`
25
+ `+String(e.eosKey)+`
26
26
 
27
- `,o})}getDisplayPublicKey(e){return S(this,null,function*(){const{keys:t}=(0,O.fz)(e);let o="";return(t==null?void 0:t.ownerPublicKey)!=null&&(o+=`owner publicKey
28
- `+String(t.ownerPublicKey)+`
27
+ `,o})}getDisplayPublicKey(t){return S(this,null,function*(){const{keys:e}=(0,O.fz)(t);let o="";return(e==null?void 0:e.ownerPublicKey)!=null&&(o+=`owner publicKey
28
+ `+String(e.ownerPublicKey)+`
29
29
 
30
- `),(t==null?void 0:t.publicKey)!=null&&(o+=`active publicKey
31
- `+String(t.publicKey)+`
30
+ `),(e==null?void 0:e.publicKey)!=null&&(o+=`active publicKey
31
+ `+String(e.publicKey)+`
32
32
 
33
- `),o})}importPrivateKey(e){return S(this,null,function*(){const t=e.replace(/ /g,"");if(t.length!==51)throw new Error("Private key wrong length");return g._q.fromString(t),{eosKey:t}})}createPrivateKey(e){return S(this,null,function*(){const t=e.replace("wallet:",""),o=this.currencyInfo.walletType.replace("wallet:","");if(t===o){const i=new g._q(g.Jz.K1,g.Jj.from(this.io.random(32))).toWif(),r=new g._q(g.Jz.K1,g.Jj.from(this.io.random(32))).toWif();return{eosOwnerKey:i,eosKey:r}}else throw new Error("InvalidWalletType")})}derivePublicKey(e){return S(this,null,function*(){if(e.type!==this.currencyInfo.walletType)throw new Error("InvalidWalletType");const t=g._q.from(e.keys.eosKey).toPublic().toLegacyString();let o;return e.keys.eosOwnerKey!=null&&(o=g._q.from(e.keys.eosOwnerKey).toPublic().toLegacyString()),{publicKey:t,ownerPublicKey:o}})}parseUri(e){return S(this,null,function*(){var t;const{edgeParsedUri:o}=(0,X.k)(this.currencyInfo,e,{[this.networkInfo.uriProtocol]:!0});if(!x((t=o.publicAddress)!=null?t:""))throw new Error("InvalidPublicAddressError");return o})}encodeUri(e){return S(this,arguments,function*(t,o=[]){if(!x(t.publicAddress))throw new Error("InvalidPublicAddressError");let r;if(typeof t.nativeAmount=="string"){const u=this.currencyInfo.currencyCode,s=t.nativeAmount,c=(0,m.Qs)(u,this.currencyInfo,o);if(c==null)throw new Error("InternalErrorInvalidCurrencyCode");r=(0,P.div)(s,c.multiplier,4)}return(0,X.Q)(t,this.networkInfo.uriProtocol,r)})}getTokenId(e){return S(this,null,function*(){(0,U.Rp)(e);const t=(0,U.Oj)(e.networkLocation);if(t==null||!x(t.contractAddress))throw new Error("ErrorInvalidContractAddress");return t.contractAddress.toLowerCase()})}getAccSystemStats(e){return S(this,null,function*(){return yield(0,m.QJ)(this.networkInfo.eosNodes.map(t=>()=>S(this,null,function*(){return yield N(this.fetchCors,t).v1.chain.get_account(e)})))})}getActivationSupportedCurrencies(){return S(this,null,function*(){try{const e=yield(0,m.QJ)(this.networkInfo.eosActivationServers.map(t=>()=>S(this,null,function*(){const o=`${t}/api/v1/getSupportedCurrencies`;return{result:yield(yield this.fetchCors(o)).json()}})));return B(e)}catch(e){throw this.log.error("UnableToGetSupportedCurrencies error: ",e),new Error("UnableToGetSupportedCurrencies")}})}getActivationCost(e){return S(this,null,function*(){try{return yield(0,m.QJ)(this.networkInfo.eosActivationServers.map(o=>()=>S(this,null,function*(){const i=`${o}/api/v1/eosPrices/${e}`,r=yield this.fetchCors(i),a=Q(yield r.json()),u=`${o}/api/v1/startingResources/${e}`,s=yield this.fetchCors(u),c=Q(yield s.json()),l=(Number(a.ram)*c.ram+Number(a.net)*c.net+Number(a.cpu)*c.cpu).toString();return(0,P.toFixed)(l,0,4)})))}catch(t){throw this.log.error("ErrorUnableToGetCost: ",t),new Error("ErrorUnableToGetCost")}})}validateAccount(e){return S(this,null,function*(){const t=x(e)&&e.length===12,o={result:""};if(!t){const i=new Error("ErrorInvalidAccountName");throw i.name="ErrorInvalidAccountName",i}try{if((yield this.getAccSystemStats(e))!=null){const r=new Error("ErrorAccountUnavailable");throw r.name="ErrorAccountUnavailable",r}throw new Error("ErrorUnknownError")}catch(i){if(i instanceof g.Hx&&i.details[0].message.includes("unknown key"))o.result="AccountAvailable";else throw i}return this.log(`validateAccount: result=${o.result}`),o})}}function Ct(w){return S(this,null,function*(){return new at(w)})}}}]);
33
+ `),o})}importPrivateKey(t){return S(this,null,function*(){const e=t.replace(/ /g,"");if(e.length!==51)throw new Error("Private key wrong length");return v._q.fromString(e),{eosKey:e}})}createPrivateKey(t){return S(this,null,function*(){const e=t.replace("wallet:",""),o=this.currencyInfo.walletType.replace("wallet:","");if(e===o){const s=new v._q(v.Jz.K1,v.Jj.from(this.io.random(32))).toWif(),r=new v._q(v.Jz.K1,v.Jj.from(this.io.random(32))).toWif();return{eosOwnerKey:s,eosKey:r}}else throw new Error("InvalidWalletType")})}derivePublicKey(t){return S(this,null,function*(){if(t.type!==this.currencyInfo.walletType)throw new Error("InvalidWalletType");const e=v._q.from(t.keys.eosKey).toPublic().toLegacyString();let o;return t.keys.eosOwnerKey!=null&&(o=v._q.from(t.keys.eosOwnerKey).toPublic().toLegacyString()),{publicKey:e,ownerPublicKey:o}})}parseUri(t){return S(this,null,function*(){var e;const{edgeParsedUri:o}=(0,X.k)(this.currencyInfo,t,{[this.networkInfo.uriProtocol]:!0});if(!$((e=o.publicAddress)!=null?e:""))throw new Error("InvalidPublicAddressError");return o})}encodeUri(t){return S(this,arguments,function*(e,o=[]){if(!$(e.publicAddress))throw new Error("InvalidPublicAddressError");let r;if(typeof e.nativeAmount=="string"){const u=this.currencyInfo.currencyCode,i=e.nativeAmount,a=(0,y.Qs)(u,this.currencyInfo,o);if(a==null)throw new Error("InternalErrorInvalidCurrencyCode");r=(0,P.div)(i,a.multiplier,4)}return(0,X.Q)(e,this.networkInfo.uriProtocol,r)})}getTokenId(t){return S(this,null,function*(){(0,U.Rp)(t);const e=(0,U.Oj)(t.networkLocation);if(e==null||!$(e.contractAddress))throw new Error("ErrorInvalidContractAddress");return e.contractAddress.toLowerCase()})}getAccSystemStats(t){return S(this,null,function*(){return yield(0,y.QJ)(this.networkInfo.eosNodes.map(e=>()=>S(this,null,function*(){return yield N(this.fetchCors,e).v1.chain.get_account(t)})))})}getActivationSupportedCurrencies(){return S(this,null,function*(){try{const t=yield(0,y.QJ)(this.networkInfo.eosActivationServers.map(e=>()=>S(this,null,function*(){const o=`${e}/api/v1/getSupportedCurrencies`;return{result:yield(yield this.fetchCors(o)).json()}})));return B(t)}catch(t){throw this.log.error("UnableToGetSupportedCurrencies error: ",t),new Error("UnableToGetSupportedCurrencies")}})}getActivationCost(t){return S(this,null,function*(){try{return yield(0,y.QJ)(this.networkInfo.eosActivationServers.map(o=>()=>S(this,null,function*(){const s=`${o}/api/v1/eosPrices/${t}`,r=yield this.fetchCors(s),c=M(yield r.json()),u=`${o}/api/v1/startingResources/${t}`,i=yield this.fetchCors(u),a=M(yield i.json()),l=(Number(c.ram)*a.ram+Number(c.net)*a.net+Number(c.cpu)*a.cpu).toString();return(0,P.toFixed)(l,0,4)})))}catch(e){throw this.log.error("ErrorUnableToGetCost: ",e),new Error("ErrorUnableToGetCost")}})}validateAccount(t){return S(this,null,function*(){const e=$(t)&&t.length===12,o={result:""};if(!e){const s=new Error("ErrorInvalidAccountName");throw s.name="ErrorInvalidAccountName",s}try{if((yield this.getAccSystemStats(t))!=null){const r=new Error("ErrorAccountUnavailable");throw r.name="ErrorAccountUnavailable",r}throw new Error("ErrorUnknownError")}catch(s){if(s instanceof v.Hx&&s.details[0].message.includes("unknown key"))o.result="AccountAvailable";else throw s}return this.log(`validateAccount: result=${o.result}`),o})}}function bt(k){return S(this,null,function*(){return new ct(k)})}}}]);
@@ -1,11 +1,11 @@
1
- (self.webpackChunkedge_currency_accountbased=self.webpackChunkedge_currency_accountbased||[]).push([[513],{86352:function(Se,oe,P){"use strict";P.d(oe,{Vn:function(){return ae},lF:function(){return A},sp:function(){return ee}});var g=P(76714),J=(j,p,D)=>new Promise((n,M)=>{var Z=S=>{try{F(D.next(S))}catch(O){M(O)}},T=S=>{try{F(D.throw(S))}catch(O){M(O)}},F=S=>S.done?n(S.value):Promise.resolve(S.value).then(Z,T);F((D=D.apply(j,p)).next())});const q=["https://info1.edge.app","https://info2.edge.app"];function ie(j,p,D){return J(this,arguments,function*(n,M,Z,T=5e3,F=fetch){const S=n.map(O=>()=>J(this,null,function*(){const Q=yield F(O+"/"+M,Z);if(typeof Q!="object"){const B=`Invalid return value ${M} in ${O}`;throw console.log(B),new Error(B)}return Q}));return yield(0,g.QJ)(S,T)})}function A(j,p,D,n,M=5e3,Z){return J(this,null,function*(){const T=yield ie((0,g.Sy)(p),D,n,M,Z);if(!T.ok){const O=yield T.text();throw console.error(O),new Error(`Error fetching ${D}: ${O}`)}const F=yield T.json();return j(F)})}function le(j,p,D,n=5e3,M){return J(this,null,function*(){return yield ie((0,g.Sy)(j),p,D,n,M)})}const ae=(j,p,D,n)=>J(void 0,null,function*(){return yield le(q,j,p,D,n)}),ee=j=>Object.keys(j).map(p=>{const D=j[p];return D==null?p:`${p}=${encodeURIComponent(D)}`}).join("&")},79014:function(Se,oe,P){"use strict";P.d(oe,{Q:function(){return Z},k:function(){return M}});var g=P(77591),J=P.n(g),q=P(24350),ie=P(84564),A=P.n(ie),le=P(76714),ae=Object.defineProperty,ee=Object.getOwnPropertySymbols,j=Object.prototype.hasOwnProperty,p=Object.prototype.propertyIsEnumerable,D=(T,F,S)=>F in T?ae(T,F,{enumerable:!0,configurable:!0,writable:!0,value:S}):T[F]=S,n=(T,F)=>{for(var S in F||(F={}))j.call(F,S)&&D(T,S,F[S]);if(ee)for(var S of ee(F))p.call(F,S)&&D(T,S,F[S]);return T};function M(T,F,S,O,Q=[]){const B=n({},A()(F,{},!0)),he=F.startsWith(`${T.pluginId}://`);if(B.protocol!=null&&(B.protocol=B.protocol.replace(":","")),B.protocol!=null&&B.protocol!==""&&!S[B.protocol])throw new Error(`Uri protocol '${B.protocol}' is not supported for ${T.pluginId}.`);if(B.host===""&&B.pathname==="")throw new Error("Path and host not found in uri.");const W={publicAddress:B.host!==""?B.host:B.pathname.split("/")[0]},ge=B.query.label,ue=B.query.message,be=B.query.category;(ge!=null||ue!=null||be!=null||he)&&(W.metadata={},W.metadata.name=ge,W.metadata.notes=ue,W.metadata.category=be,W.metadata.gateway=he!=null?he:!1);const te=B.query.amount;if(te!=null&&typeof te=="string"){O==null&&(O=T.currencyCode);const pe=(0,le.Qs)(O!=null?O:"",T,Q);if(pe==null)throw new Error("InternalErrorInvalidCurrencyCode");let de=(0,g.mul)(te,pe.multiplier);de=(0,g.toFixed)(de,0,0),W.nativeAmount=de,W.currencyCode=O}return{edgeParsedUri:W,parsedUri:B}}function Z(T,F,S){if(T.publicAddress==null)throw new Error("InvalidPublicAddressError");if(S==null&&T.label==null&&T.message==null)return T.publicAddress;{let O="";S!=null&&(O+="amount="+S+"&"),(T.label!=null||T.message!=null)&&(typeof T.label=="string"&&(O+="label="+T.label+"&"),typeof T.message=="string"&&(O+="message="+T.message+"&")),O=O.substr(0,O.length-1);const Q={scheme:F,path:T.publicAddress,query:O};return(0,q.qC)(Q)}}},55773:function(Se,oe,P){"use strict";P.r(oe),P.d(oe,{EthereumTools:function(){return Ve},makeCurrencyEngine:function(){return Wt},makeCurrencyTools:function(){return en}});var g=P(77591),J=P(2153),q=P(48764),ie=P(21964),A=P.n(ie),le=P(48367),ae=P.n(le),ee=P(20918),j=P(79014),p=P(76714),D=P(4583),n=P(82448),M=P(62177);const Z=(0,n.su)({evmScanApiKey:(0,n.Zz)((0,n._C)(n.XC,(0,n._2)(n.XC))),blockcypherApiKey:(0,n.Zz)(n.XC),infuraProjectId:(0,n.Zz)(n.XC),blockchairApiKey:(0,n.Zz)(n.XC),alethioApiKey:(0,n.Zz)(n.XC),amberdataApiKey:(0,n.Zz)(n.XC),gasStationApiKey:(0,n.Zz)(n.XC),quiknodeApiKey:(0,n.Zz)(n.XC),alchemyApiKey:(0,n.Zz)(n.XC),poktPortalApiKey:(0,n.Zz)(n.XC)});function T(m){return m in Z.shape}const F=m=>{if(typeof m!="string")throw new Error("key must be a string");if(T(m))return m;throw new Error(`${m} not a key of EthereumInitOptions`)},S=(0,n.su)({minGasLimit:(0,n.Zz)(n.XC),regularTransaction:n.XC,tokenTransaction:n.XC}),O=(0,n.su)({highFee:n.XC,lowFee:n.XC,minGasPrice:(0,n.Zz)(n.XC),standardFeeLow:n.XC,standardFeeHigh:n.XC,standardFeeLowAmount:n.XC,standardFeeHighAmount:n.XC}),Q=(0,n.su)({lowFee:n.XC,standardFeeLow:n.XC,standardFeeHigh:n.XC,highFee:n.XC}),B=(0,n.su)({baseFeeMultiplier:(0,n.Zz)(Q),gasLimit:(0,n.Zz)(S),gasPrice:(0,n.Zz)(O),minPriorityFee:(0,n.Zz)(n.XC)}),he=(0,n.su)(B),Ie=(0,n.su)({blockNumber:n.XC,timeStamp:n.XC,hash:(0,n.Zz)(n.XC),transactionHash:(0,n.Zz)(n.XC),to:n.XC,from:n.XC,value:n.XC,nonce:n.XC,gasPrice:n.XC,gas:n.XC,gasUsed:n.XC,confirmations:n.XC,contractAddress:n.XC,tokenName:n.XC,tokenSymbol:n.XC,tokenDecimal:n.XC}),W=(0,n.su)({hash:(0,n.Zz)(n.XC),transactionHash:(0,n.Zz)(n.XC),blockNumber:n.XC,timeStamp:n.XC,gasPrice:n.XC,gasUsed:n.XC,value:n.XC,nonce:n.XC,from:n.XC,to:n.XC,gas:n.XC,isError:n.XC,confirmations:(0,n.Zz)(n.XC)}),ge=(0,n.su)({hash:(0,n.Zz)(n.XC),transactionHash:(0,n.Zz)(n.XC),blockNumber:n.XC,timeStamp:n.XC,gasUsed:n.XC,value:n.XC,from:n.XC,to:n.XC,gas:n.XC,isError:n.XC,contractAddress:(0,n.Zz)(n.XC)}),ue=(0,n.su)({LastBlock:n.XC,SafeGasPrice:n.XC,ProposeGasPrice:n.XC,FastGasPrice:n.XC,suggestBaseFee:(0,n.Vk)(n.XC),gasUsedRatio:(0,n.Vk)((0,n._2)(n.XC))}),be=(0,n.su)({status:n.XC,message:n.XC,result:(0,n._C)(n.XC,(0,n.su)(ue))}),te=(0,n.su)({from:(0,n._2)(n.XC),to:(0,n._2)(n.XC),gas:n.XC,gasPrice:n.XC,gasUsed:n.XC,tokenRecipientAddress:(0,n.Zz)(n.XC),nonceUsed:(0,n.Zz)(n.XC),replacedTxid:(0,n.Zz)(n.XC),data:(0,n.Zz)((0,n._C)(n.XC,n.gu)),isFromMakeSpend:(0,n.Zz)(n.jK,!1)}),pe=(0,n.su)({nextNonce:(0,n.Vk)(n.XC,"0"),unconfirmedNextNonce:(0,n.Vk)(n.XC,"0")}),de=(0,n.su)({blockbook:(0,n.su)({bestHeight:n.mH})}),Le=(0,n.su)({symbol:n.XC,contract:n.XC,balance:n.XC}),Qe=(0,n.su)({balance:n.XC,unconfirmedBalance:n.XC,unconfirmedTxs:n.mH,nonce:n.XC,tokens:(0,n.Vk)((0,n._2)(Le),()=>[])}),Ye=(0,n.su)({balance:n.XC,token_address:n.XC,token_symbol:n.XC}),qe=(0,n.su)({data:(0,n.su)((0,n.su)({address:(0,n.su)({balance:n.XC}),layer_2:(0,n.su)({erc_20:(0,n._2)((0,n.Zz)(n.XC))})}))}),et=(0,n.su)({data:(0,n.su)({blocks:n.mH})}),tn=(0,n.su)({hash:n.XC,timestamp:n.XC,blockNumber:n.XC,value:n.XC,fee:n.XC,gasLimit:n.XC,gasPrice:n.XC,gasUsed:n.XC,from:(0,n._2)((0,n.su)({address:n.XC})),to:(0,n._2)((0,n.su)({address:n.XC}))}),Y=(0,n.su)({result:n.XC}),tt=(0,n.su)({l1Fee:n.XC}),nn=(0,n.su)({id:(0,n._C)(n.XC,n.mH),method:(0,n.Wf)("personal_sign","eth_sign","eth_signTypedData","eth_signTypedData_v4","eth_sendTransaction","eth_signTransaction","eth_sendRawTransaction"),params:(0,n._2)(n.JC)}),nt=(0,n.Zz)((0,n.su)({typedData:(0,n.Zz)(n.jK,!1)}),{typedData:!1}),Fe=M.BQ,Ce=m=>{const e=m,t=(0,n.su)({[`${e}Mnemonic`]:(0,n.Zz)(n.XC),[`${e}Key`]:n.XC}),s=(0,n.su)({keys:t});return(0,n.W1)(r=>{const i=(0,n.Vk)(s)(r);if(i!=null)return{mnemonic:i.keys[`${e}Mnemonic`],privateKey:i.keys[`${e}Key`]};const u=t(r);return{mnemonic:u[`${e}Mnemonic`],privateKey:u[`${e}Key`]}},r=>({[`${e}Mnemonic`]:r.mnemonic,[`${e}Key`]:r.privateKey}))};var st=P(2832),Oe=P.n(st),xe=P(66052),ne=P(94935),rt=P(50144),ot=P(68142),Pe=P.n(ot),it=P(37217),at=P.n(it),ct=P(84650);const se=1e9,ye=1e8,ke=3e4,lt=.75,ht=60*10*1e3,ut=5*60*1e3;var dt=P(84564),U=P.n(dt);const ft=m=>{const e=(0,n.XC)(m);if(/0[xX][0-9a-fA-F]+/.test(e))return parseInt(e,16);throw new TypeError("Expected a hex number")},mt=m=>{const e=(0,n.XC)(m);if(/0[xX][0-9a-fA-F]+/.test(e))return(0,g.add)(m,"0");throw new TypeError("Expected a hex number")},gt=(0,n.su)({result:ft}),pt=(0,n.su)({result:mt}),yt=(0,n.su)({safeLow:n.mH,average:n.mH,fast:n.mH,fastest:n.mH}),kt=(0,n.su)({types:(0,n.su)((0,n._2)((0,n.su)({name:n.XC,type:n.XC}))),primaryType:n.XC,domain:n.JC,message:n.JC});var Et=P(86352),ce=(m,e,t)=>new Promise((s,r)=>{var i=h=>{try{a(t.next(h))}catch(o){r(o)}},u=h=>{try{a(t.throw(h))}catch(o){r(o)}},a=h=>h.done?s(h.value):Promise.resolve(h.value).then(i,u);a((t=t.apply(m,e)).next())});const Ee=(m,e)=>{const t=Object.keys(e);for(const s of t){const r=e[s];typeof r=="string"&&m(` ${s}: ${(0,g.div)(r,"1000000000",18)} gwei`)}},wt=(m,e,t,s,r)=>({infoFeeProvider:()=>ce(void 0,null,function*(){return yield Pt(m,e)}),externalFeeProviders:[bt,Ct,vt].map(u=>()=>ce(void 0,null,function*(){return yield u(m,e,t,s,r)}))}),vt=(m,e,t,s,r)=>ce(void 0,null,function*(){const{rpcServers:i,supportsEIP1559:u=!1}=r;if(u)return;const a=(0,p.sD)(i,1)[0],h={headers:{Accept:"application/json","Content-Type":"application/json"},method:"POST",body:JSON.stringify({method:"eth_gasPrice",params:[],id:1,jsonrpc:"2.0"})},o=yield m(a,h);if(!o.ok){const k=yield o.text();throw new Error(`fetchFeesFromRpc fetch error: ${k}`)}const l=yield o.json(),c=(0,n.Vk)(Y)(l);if(c==null)throw new Error(`fetchFeesFromRpc ${a} returned invalid json: ${l}`);const{result:d}=c,f=(0,p.Z8)(d),y={lowFee:(0,g.mul)(f,"1"),standardFeeLow:(0,g.mul)(f,"1.06"),standardFeeHigh:(0,g.mul)(f,"1.12"),highFee:(0,g.mul)(f,"1.25")};return s(`fetchFeesFromRpc: ${e.currencyCode}`),Ee(s,y),y}),bt=(m,e,t,s,r)=>ce(void 0,null,function*(){const i=r.evmScanApiServers,u=Be(t,e,s);if(i==null||u==null)return;const a=`&apikey=${Array.isArray(u)?(0,p.sD)(u,1)[0]:u!=null?u:""}`,h=`${(0,p.sD)(i,1)[0]}/api?module=gastracker&action=gasoracle${a}`,o=yield m(h);if(!o.ok)throw new Error(`EvmScan fetch error: ${JSON.stringify(o)}`);const l=yield o.json(),c=l.message.includes("NOTOK");if(!(l!=null&&!c))throw new Error(`fetchFeesFromEvmScan unrecognized response message: ${l.message}`);const{SafeGasPrice:f,ProposeGasPrice:y,FastGasPrice:k}=ue(l.result),b=parseInt(f);let v=parseInt(y),E=parseInt(k);v<=b&&(v=b+1),E<=v&&(E=v+1);const C=`${b*se}`,I=`${(b+v)/2*se}`,_=`${E*se}`,X=`${E*se/lt}`,H={lowFee:C,standardFeeLow:I,standardFeeHigh:_,highFee:X};return s(`fetchFeesFromEvmScan: ${e.currencyCode}`),Ee(s,H),H}),Ct=(m,e,t,s,r)=>ce(void 0,null,function*(){const{ethGasStationUrl:i}=r,u=Tt(t,e,s);if(i==null||u==null)return;const a=u?`?api-key=${u||""}`:"",o=yield(yield m(`${i}${a}`)).json(),l=yt(o);if(e.currencyCode==="MATIC"&&(l.safeLow*=10,l.average=(o.fast+o.safeLow)/2*10,l.fast=o.standard*10,l.fastest*=10),l.safeLow<=0||l.safeLow>ke)throw new Error("Invalid safeLow value from Gas Station");if(l.average<1||l.average>ke)throw new Error("Invalid average value from Gas Station");if(l.fast<1||l.fast>ke)throw new Error("Invalid fastest value from Gas Station");if(l.fastest<1||l.fastest>ke)throw new Error("Invalid fastest value from Gas Station");l.average<=l.safeLow&&(l.average=l.safeLow+1),l.fast<=l.average&&(l.fast=l.average+1),l.fastest<=l.fast&&(l.fastest=l.fast+1);let c=l.safeLow,d=l.fast,f=((l.fast+l.fastest)*.5+l.fastest)*.5,y=f>l.fastest?f:l.fastest;c=Math.round(c)*ye,d=Math.round(d)*ye,f=Math.round(f)*ye,y=Math.round(y)*ye;const k={lowFee:c.toString(),standardFeeLow:d.toString(),standardFeeHigh:f.toString(),highFee:y.toString()};return s(`fetchFeesFromEvmGasStation: ${e.currencyCode}`),Ee(s,k),k}),Pt=(m,e)=>ce(void 0,[m,e],function*(t,{pluginId:s}){const i=yield(yield(0,Et.Vn)(`v1/networkFees/${s}`,void 0,void 0,t)).json();return he(i)}),Be=(m,e,t)=>{const{evmScanApiKey:s,etherscanApiKey:r,ftmscanApiKey:i,bscscanApiKey:u,polygonscanApiKey:a}=m;if(s!=null)return s;const{currencyCode:h}=e;if(h==="ETH"&&r!=null)return t.warn("INIT OPTION 'etherscanApiKey' IS DEPRECATED. USE 'evmScanApiKey' INSTEAD"),r;if(h==="FTM"&&i!=null)return t.warn("INIT OPTION 'ftmscanApiKey' IS DEPRECATED. USE 'evmScanApiKey' INSTEAD"),i;if(h==="BNB"&&u!=null)return t.warn("INIT OPTION 'bscscanApiKey' IS DEPRECATED. USE 'evmScanApiKey' INSTEAD"),u;if(h==="MATIC"&&a!=null)return t.warn("INIT OPTION 'polygonscanApiKey' IS DEPRECATED. USE 'evmScanApiKey' INSTEAD"),a},Tt=(m,e,t)=>{const{gasStationApiKey:s,ethGasStationApiKey:r}=m;if(s!=null)return s;const{currencyCode:i}=e;if(i==="ETH"&&r!=null)return t.warn("INIT OPTION 'ethGasStationApiKey' IS DEPRECATED. USE 'gasStationApiKey' INSTEAD"),r};var At=Object.defineProperty,St=Object.defineProperties,It=Object.getOwnPropertyDescriptors,Ne=Object.getOwnPropertySymbols,Lt=Object.prototype.hasOwnProperty,Ft=Object.prototype.propertyIsEnumerable,$e=(m,e,t)=>e in m?At(m,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):m[e]=t,Re=(m,e)=>{for(var t in e||(e={}))Lt.call(e,t)&&$e(m,t,e[t]);if(Ne)for(var t of Ne(e))Ft.call(e,t)&&$e(m,t,e[t]);return m},_e=(m,e)=>St(m,It(e)),w=(m,e,t)=>new Promise((s,r)=>{var i=h=>{try{a(t.next(h))}catch(o){r(o)}},u=h=>{try{a(t.throw(h))}catch(o){r(o)}},a=h=>h.done?s(h.value):Promise.resolve(h.value).then(i,u);a((t=t.apply(m,e)).next())});const Ot=2e4,xt=2e4,Bt=2e4,Nt=2e4,De=4*2,Xe=2*60,$t=50;function we(m,e){return w(this,null,function*(){return{result:yield m,server:e}})}const Te=(m,e,t)=>{let s={};try{s=_e(Re({gasPrice:(0,g.div)(m,se.toString(),se.toString().length-1)},t!==void 0?{gasUsed:t}:{}),{gasLimit:e})}catch(r){console.log(`Failed to construct feeRateUssed: ${r}`)}return s};class Rt{constructor(e){this.ethEngine=e,this.ethNeeds={blockHeightLastChecked:0,nonceLastChecked:0,tokenBalLastChecked:{},tokenTxsLastChecked:{}},this.fetchGetEtherscan=this.fetchGetEtherscan.bind(this),this.multicastServers=this.multicastServers.bind(this),this.checkAddressBlockbook=this.checkAddressBlockbook.bind(this),this.checkBlockHeightEthscan=this.checkBlockHeightEthscan.bind(this),this.checkBlockHeightBlockchair=this.checkBlockHeightBlockchair.bind(this),this.checkBlockHeightAmberdata=this.checkBlockHeightAmberdata.bind(this),this.checkBlockHeightBlockbook=this.checkBlockHeightBlockbook.bind(this),this.checkNonceRpc=this.checkNonceRpc.bind(this),this.checkNonceEthscan=this.checkNonceEthscan.bind(this),this.checkNonceAmberdata=this.checkNonceAmberdata.bind(this),this.checkTokenBalEthscan=this.checkTokenBalEthscan.bind(this),this.checkTokenBalBlockchair=this.checkTokenBalBlockchair.bind(this),this.checkTokenBalRpc=this.checkTokenBalRpc.bind(this),this.checkTxsEthscan=this.checkTxsEthscan.bind(this),this.processEthereumNetworkUpdate=this.processEthereumNetworkUpdate.bind(this),this.queryFuncs=this.buildQueryFuncs(this.ethEngine.networkInfo),this.walletId=e.walletInfo.id}processEvmScanTransaction(e,t){return w(this,null,function*(){var s;const r=[],i=(s=e.hash)!=null?s:e.transactionHash;if(i==null)throw new Error("Invalid transaction result format");const u=e.from.toLowerCase()===this.ethEngine.walletLocalData.publicKey.toLowerCase(),a=t!==this.ethEngine.currencyInfo.currencyCode,h="gasPrice"in e?e.gasPrice:void 0,o=h!=null?(0,g.mul)(h,e.gasUsed):"0";let l="0";if(u&&this.ethEngine.networkInfo.l1RollupParams!=null){const v=yield this.multicastServers("eth_getTransactionReceipt",[i]),E=tt(v.result.result);l=(0,g.add)(l,(0,p.X0)(E.l1Fee))}let c,d,f;u?a?(c=(0,g.sub)("0",e.value),d="0",f=(0,g.add)(o,l)):e.from.toLowerCase()===e.to.toLowerCase()?(c=(0,g.sub)((0,g.sub)("0",o),l),d=(0,g.add)(o,l)):(c=(0,g.sub)((0,g.sub)((0,g.sub)("0",e.value),o),l),d=(0,g.add)(o,l)):(c=e.value,d="0",r.push(this.ethEngine.walletLocalData.publicKey));const y={from:[e.from],to:[e.to],gas:e.gas,gasPrice:h!=null?h:"",gasUsed:e.gasUsed,isFromMakeSpend:!1};let k=parseInt(e.blockNumber);return k<0&&(k=0),{txid:i,date:parseInt(e.timeStamp),currencyCode:t,blockHeight:k,nativeAmount:c,isSend:c.startsWith("-"),networkFee:d,feeRateUsed:h!=null?Te(h,e.gas,e.gasUsed):void 0,parentNetworkFee:f,ourReceiveAddresses:r,signedTx:"",otherParams:y,walletId:this.walletId}})}processAlethioTransaction(e,t){let s;const r=[];let i;const u=t!==this.ethEngine.currencyInfo.currencyCode,a=e.attributes.value,h=e.attributes.fee?e.attributes.fee:"0",o=e.relationships.from.data.id,l=e.relationships.to.data.id;t===this.ethEngine.currencyInfo.currencyCode?i=h:i="0";const c=o.toLowerCase()===this.ethEngine.walletLocalData.publicKey.toLowerCase();if(c)o.toLowerCase()===l.toLowerCase()?s=(0,g.mul)(i,"-1"):(s=(0,g.sub)("0",a),u||(s=(0,g.sub)(s,i)));else if(l.toLowerCase()===this.ethEngine.walletLocalData.publicKey.toLowerCase())s=a,r.push(this.ethEngine.walletLocalData.publicKey.toLowerCase());else return null;const d={from:[o],to:[l],gas:"0",gasPrice:"0",gasUsed:"0",isFromMakeSpend:!1};let f=e.attributes.globalRank[0];f<0&&(f=0);let y,k="0";return u&&c?y=i:k=i,{txid:e.relationships.transaction.data.id,date:e.attributes.blockCreationTime,currencyCode:t,blockHeight:f,nativeAmount:s,isSend:s.startsWith("-"),networkFee:k,ourReceiveAddresses:r,signedTx:"",parentNetworkFee:y,otherParams:d,walletId:this.walletId}}fetchGetEtherscan(e,t){return w(this,null,function*(){const s=Be(this.ethEngine.initOptions,this.ethEngine.currencyInfo,this.ethEngine.log);e.indexOf("cors-http")===0&&(e=e.replace(/^cors-http/,"http"));const i=Array.isArray(s)?(0,p.sD)(s,1)[0]:s!=null?s:"",u=i!==""?`&apikey=${i}`:"",a=`${e}/api${t}`,h=yield this.ethEngine.fetchCors(`${a}${u}`);return h.ok||this.throwError(h,"fetchGetEtherscan",a),yield h.json()})}fetchGetBlockbook(e,t){return w(this,null,function*(){const s=e+t;return yield(e.includes("trezor")?yield this.ethEngine.fetchCors(s,{headers:{"User-Agent":"http.agent"}}):yield this.ethEngine.fetchCors(s)).json()})}fetchPostRPC(e,t,s,r){return w(this,null,function*(){const i={id:s,jsonrpc:"2.0",method:e,params:t},a=/{{(.*?)}}/g.exec(r);if(a!=null){const l=a[1],c=F(l),d=this.ethEngine.initOptions[c];if(typeof d=="string")r=r.replace(a[0],d);else throw d==null?new Error(`Missing ${c} in 'initOptions' for ${this.ethEngine.currencyInfo.pluginId}`):new Error("Incorrect apikey type for RPC")}const h=yield this.ethEngine.fetchCors(r,{headers:{Accept:"application/json","Content-Type":"application/json"},method:"POST",body:JSON.stringify(i)}),o=U()(r,{},!0);return h.ok||this.throwError(h,"fetchPostRPC",o.hostname),yield h.json()})}fetchPostBlockcypher(e,t,s){return w(this,null,function*(){const{blockcypherApiKey:r}=this.ethEngine.initOptions;let i="";r&&r.length>5&&(i="&token="+r);const u=`${s}/${e}${i}`,a=yield this.ethEngine.fetchCors(u,{headers:{Accept:"application/json","Content-Type":"application/json"},method:"POST",body:JSON.stringify(t)}),h=U()(u,{},!0);return a.ok||this.throwError(a,"fetchPostBlockcypher",h.hostname),yield a.json()})}fetchGetBlockchair(e,t=!1){return w(this,null,function*(){const{blockchairApiKey:s}=this.ethEngine.initOptions,{blockchairApiServers:r}=this.ethEngine.networkInfo,i=t&&s?`&key=${s}`:"",u=`${r[0]}${e}`,a=yield this.ethEngine.fetchCors(`${u}${i}`);return a.ok||this.throwError(a,"fetchGetBlockchair",u),yield a.json()})}fetchPostAmberdataRpc(e){return w(this,arguments,function*(t,s=[]){const{amberdataApiKey:r=""}=this.ethEngine.initOptions,{amberdataRpcServers:i}=this.ethEngine.networkInfo,u=`${i[0]}`,a={jsonrpc:"2.0",method:t,params:s,id:1},h=yield this.ethEngine.fetchCors(u,{headers:{"x-amberdata-blockchain-id":this.ethEngine.networkInfo.amberDataBlockchainId,"x-api-key":r,"Content-Type":"application/json"},method:"POST",body:JSON.stringify(a)}),o=U()(u,{},!0);return h.ok||this.throwError(h,"fetchPostAmberdataRpc",o),yield h.json()})}fetchGetAmberdataApi(e){return w(this,null,function*(){const{amberdataApiKey:t=""}=this.ethEngine.initOptions,{amberdataApiServers:s}=this.ethEngine.networkInfo,r=`${s[0]}${e}`,i=yield this.ethEngine.fetchCors(r,{headers:{"x-amberdata-blockchain-id":this.ethEngine.networkInfo.amberDataBlockchainId,"x-api-key":t}});return i.ok||this.throwError(i,"fetchGetAmberdata",r),yield i.json()})}fetchGetAlethio(e,t=!0,s){return w(this,null,function*(){const{alethioApiKey:r=""}=this.ethEngine.initOptions,{alethioApiServers:i}=this.ethEngine.networkInfo,u=t?`${i[0]}${e}`:e,a=yield this.ethEngine.fetchCors(u,r?{headers:{Authorization:`Bearer ${r}`}}:void 0);return a.ok||this.throwError(a,"fetchGetAlethio",u),yield a.json()})}broadcastEtherscan(e,t){return w(this,null,function*(){const s=`?module=proxy&action=eth_sendRawTransaction&hex=${e.signedTx}`,r=yield this.fetchGetEtherscan(t,s);return this.broadcastResponseHandler(r,t,e)})}broadcastRPC(e,t,s){return w(this,null,function*(){const r="eth_sendRawTransaction",i=[e.signedTx],u=yield this.fetchPostRPC(r,i,t,s),a=U()(s,{},!0);return this.broadcastResponseHandler(u,a,e)})}broadcastBlockCypher(e,t){return w(this,null,function*(){const s=`v1/${this.ethEngine.currencyInfo.currencyCode.toLowerCase()}/main/txs/push`,r=e.signedTx.replace("0x",""),i=yield this.fetchPostBlockcypher(s,{tx:r},t);return this.broadcastResponseHandler(i,t,e)})}broadcastBlockbook(e,t){return w(this,null,function*(){const s=yield this.fetchGetBlockbook(t,`/api/v2/sendtx/${e.signedTx}`);return this.broadcastResponseHandler(s,t,e)})}broadcastResponseHandler(e,t,s){if(typeof e.error<"u")throw this.ethEngine.error(`FAILURE ${t}
1
+ (self.webpackChunkedge_currency_accountbased=self.webpackChunkedge_currency_accountbased||[]).push([[513],{86352:function(Se,oe,P){"use strict";P.d(oe,{Vn:function(){return ae},lF:function(){return S},sp:function(){return ee}});var g=P(76714),J=(G,p,X)=>new Promise((n,j)=>{var Z=I=>{try{F(X.next(I))}catch(O){j(O)}},T=I=>{try{F(X.throw(I))}catch(O){j(O)}},F=I=>I.done?n(I.value):Promise.resolve(I.value).then(Z,T);F((X=X.apply(G,p)).next())});const q=["https://info1.edge.app","https://info2.edge.app"];function ie(G,p,X){return J(this,arguments,function*(n,j,Z,T=5e3,F=fetch){const I=n.map(O=>()=>J(this,null,function*(){const Q=yield F(O+"/"+j,Z);if(typeof Q!="object"){const B=`Invalid return value ${j} in ${O}`;throw console.log(B),new Error(B)}return Q}));return yield(0,g.QJ)(I,T)})}function S(G,p,X,n,j=5e3,Z){return J(this,null,function*(){const T=yield ie((0,g.Sy)(p),X,n,j,Z);if(!T.ok){const O=yield T.text();throw console.error(O),new Error(`Error fetching ${X}: ${O}`)}const F=yield T.json();return G(F)})}function le(G,p,X,n=5e3,j){return J(this,null,function*(){return yield ie((0,g.Sy)(G),p,X,n,j)})}const ae=(G,p,X,n)=>J(void 0,null,function*(){return yield le(q,G,p,X,n)}),ee=G=>Object.keys(G).map(p=>{const X=G[p];return X==null?p:`${p}=${encodeURIComponent(X)}`}).join("&")},79014:function(Se,oe,P){"use strict";P.d(oe,{Q:function(){return Z},k:function(){return j}});var g=P(77591),J=P.n(g),q=P(24350),ie=P(84564),S=P.n(ie),le=P(76714),ae=Object.defineProperty,ee=Object.getOwnPropertySymbols,G=Object.prototype.hasOwnProperty,p=Object.prototype.propertyIsEnumerable,X=(T,F,I)=>F in T?ae(T,F,{enumerable:!0,configurable:!0,writable:!0,value:I}):T[F]=I,n=(T,F)=>{for(var I in F||(F={}))G.call(F,I)&&X(T,I,F[I]);if(ee)for(var I of ee(F))p.call(F,I)&&X(T,I,F[I]);return T};function j(T,F,I,O,Q=[]){const B=n({},S()(F,{},!0)),he=F.startsWith(`${T.pluginId}://`);if(B.protocol!=null&&(B.protocol=B.protocol.replace(":","")),B.protocol!=null&&B.protocol!==""&&!I[B.protocol])throw new Error(`Uri protocol '${B.protocol}' is not supported for ${T.pluginId}.`);if(B.host===""&&B.pathname==="")throw new Error("Path and host not found in uri.");const W={publicAddress:B.host!==""?B.host:B.pathname.split("/")[0]},ge=B.query.label,ue=B.query.message,be=B.query.category;(ge!=null||ue!=null||be!=null||he)&&(W.metadata={},W.metadata.name=ge,W.metadata.notes=ue,W.metadata.category=be,W.metadata.gateway=he!=null?he:!1);const te=B.query.amount;if(te!=null&&typeof te=="string"){O==null&&(O=T.currencyCode);const pe=(0,le.Qs)(O!=null?O:"",T,Q);if(pe==null)throw new Error("InternalErrorInvalidCurrencyCode");let de=(0,g.mul)(te,pe.multiplier);de=(0,g.toFixed)(de,0,0),W.nativeAmount=de,W.currencyCode=O}return{edgeParsedUri:W,parsedUri:B}}function Z(T,F,I){if(T.publicAddress==null)throw new Error("InvalidPublicAddressError");if(I==null&&T.label==null&&T.message==null)return T.publicAddress;{let O="";I!=null&&(O+="amount="+I+"&"),(T.label!=null||T.message!=null)&&(typeof T.label=="string"&&(O+="label="+T.label+"&"),typeof T.message=="string"&&(O+="message="+T.message+"&")),O=O.substr(0,O.length-1);const Q={scheme:F,path:T.publicAddress,query:O};return(0,q.qC)(Q)}}},55773:function(Se,oe,P){"use strict";P.r(oe),P.d(oe,{EthereumTools:function(){return Qe},makeCurrencyEngine:function(){return zt},makeCurrencyTools:function(){return tn}});var g=P(77591),J=P(2153),q=P(48764),ie=P(21964),S=P.n(ie),le=P(48367),ae=P.n(le),ee=P(20918),G=P(79014),p=P(76714),X=P(74296),n=P(82448),j=P(62177);const Z=(0,n.su)({evmScanApiKey:(0,n.Zz)((0,n._C)(n.XC,(0,n._2)(n.XC))),blockcypherApiKey:(0,n.Zz)(n.XC),infuraProjectId:(0,n.Zz)(n.XC),blockchairApiKey:(0,n.Zz)(n.XC),alethioApiKey:(0,n.Zz)(n.XC),amberdataApiKey:(0,n.Zz)(n.XC),gasStationApiKey:(0,n.Zz)(n.XC),quiknodeApiKey:(0,n.Zz)(n.XC),alchemyApiKey:(0,n.Zz)(n.XC),poktPortalApiKey:(0,n.Zz)(n.XC)});function T(m){return m in Z.shape}const F=m=>{if(typeof m!="string")throw new Error("key must be a string");if(T(m))return m;throw new Error(`${m} not a key of EthereumInitOptions`)},I=(0,n.su)({minGasLimit:(0,n.Zz)(n.XC),regularTransaction:n.XC,tokenTransaction:n.XC}),O=(0,n.su)({highFee:n.XC,lowFee:n.XC,minGasPrice:(0,n.Zz)(n.XC),standardFeeLow:n.XC,standardFeeHigh:n.XC,standardFeeLowAmount:n.XC,standardFeeHighAmount:n.XC}),Q=(0,n.su)({lowFee:n.XC,standardFeeLow:n.XC,standardFeeHigh:n.XC,highFee:n.XC}),B=(0,n.su)({baseFeeMultiplier:(0,n.Zz)(Q),gasLimit:(0,n.Zz)(I),gasPrice:(0,n.Zz)(O),minPriorityFee:(0,n.Zz)(n.XC)}),he=(0,n.su)(B),Ie=(0,n.su)({blockNumber:n.XC,timeStamp:n.XC,hash:(0,n.Zz)(n.XC),transactionHash:(0,n.Zz)(n.XC),to:n.XC,from:n.XC,value:n.XC,nonce:n.XC,gasPrice:n.XC,gas:n.XC,gasUsed:n.XC,confirmations:n.XC,contractAddress:n.XC,tokenName:n.XC,tokenSymbol:n.XC,tokenDecimal:n.XC}),W=(0,n.su)({hash:(0,n.Zz)(n.XC),transactionHash:(0,n.Zz)(n.XC),blockNumber:n.XC,timeStamp:n.XC,gasPrice:n.XC,gasUsed:n.XC,value:n.XC,nonce:n.XC,from:n.XC,to:n.XC,gas:n.XC,isError:n.XC,confirmations:(0,n.Zz)(n.XC)}),ge=(0,n.su)({hash:(0,n.Zz)(n.XC),transactionHash:(0,n.Zz)(n.XC),blockNumber:n.XC,timeStamp:n.XC,gasUsed:n.XC,value:n.XC,from:n.XC,to:n.XC,gas:n.XC,isError:n.XC,contractAddress:(0,n.Zz)(n.XC)}),ue=(0,n.su)({LastBlock:n.XC,SafeGasPrice:n.XC,ProposeGasPrice:n.XC,FastGasPrice:n.XC,suggestBaseFee:(0,n.Vk)(n.XC),gasUsedRatio:(0,n.Vk)((0,n._2)(n.XC))}),be=(0,n.su)({status:n.XC,message:n.XC,result:(0,n._C)(n.XC,(0,n.su)(ue))}),te=(0,n.su)({from:(0,n._2)(n.XC),to:(0,n._2)(n.XC),gas:n.XC,gasPrice:n.XC,gasUsed:n.XC,tokenRecipientAddress:(0,n.Zz)(n.XC),nonceUsed:(0,n.Zz)(n.XC),replacedTxid:(0,n.Zz)(n.XC),data:(0,n.Zz)((0,n._C)(n.XC,n.gu)),isFromMakeSpend:(0,n.Zz)(n.jK,!1)}),pe=(0,n.su)({nextNonce:(0,n.Vk)(n.XC,"0"),unconfirmedNextNonce:(0,n.Vk)(n.XC,"0")}),de=(0,n.su)({blockbook:(0,n.su)({bestHeight:n.mH})}),Le=(0,n.su)({symbol:n.XC,contract:n.XC,balance:n.XC}),Ye=(0,n.su)({balance:n.XC,unconfirmedBalance:n.XC,unconfirmedTxs:n.mH,nonce:n.XC,tokens:(0,n.Vk)((0,n._2)(Le),()=>[])}),qe=(0,n.su)({balance:n.XC,token_address:n.XC,token_symbol:n.XC}),et=(0,n.su)({data:(0,n.su)((0,n.su)({address:(0,n.su)({balance:n.XC}),layer_2:(0,n.su)({erc_20:(0,n._2)((0,n.Zz)(n.XC))})}))}),tt=(0,n.su)({data:(0,n.su)({blocks:n.mH})}),nn=(0,n.su)({hash:n.XC,timestamp:n.XC,blockNumber:n.XC,value:n.XC,fee:n.XC,gasLimit:n.XC,gasPrice:n.XC,gasUsed:n.XC,from:(0,n._2)((0,n.su)({address:n.XC})),to:(0,n._2)((0,n.su)({address:n.XC}))}),Y=(0,n.su)({result:n.XC}),nt=(0,n.su)({l1Fee:n.XC}),sn=(0,n.su)({id:(0,n._C)(n.XC,n.mH),method:(0,n.Wf)("personal_sign","eth_sign","eth_signTypedData","eth_signTypedData_v4","eth_sendTransaction","eth_signTransaction","eth_sendRawTransaction"),params:(0,n._2)(n.JC)}),st=(0,n.Zz)((0,n.su)({typedData:(0,n.Zz)(n.jK,!1)}),{typedData:!1}),Fe=j.BQ,Ce=m=>{const e=m,t=(0,n.su)({[`${e}Mnemonic`]:(0,n.Zz)(n.XC),[`${e}Key`]:n.XC}),s=(0,n.su)({keys:t});return(0,n.W1)(r=>{const i=(0,n.Vk)(s)(r);if(i!=null)return{mnemonic:i.keys[`${e}Mnemonic`],privateKey:i.keys[`${e}Key`]};const h=t(r);return{mnemonic:h[`${e}Mnemonic`],privateKey:h[`${e}Key`]}},r=>({[`${e}Mnemonic`]:r.mnemonic,[`${e}Key`]:r.privateKey}))};var rt=P(2832),Oe=P.n(rt),xe=P(66052),ne=P(94935),ot=P(50144),it=P(68142),Pe=P.n(it),at=P(37217),ct=P.n(at),lt=P(84650),Be=P(72681);const se=1e9,ye=1e8,ke=3e4,ht=.75,ut=60*10*1e3,dt=5*60*1e3;var ft=P(84564),U=P.n(ft);const mt=m=>{const e=(0,n.XC)(m);if(/0[xX][0-9a-fA-F]+/.test(e))return parseInt(e,16);throw new TypeError("Expected a hex number")},gt=m=>{const e=(0,n.XC)(m);if(/0[xX][0-9a-fA-F]+/.test(e))return(0,g.add)(m,"0");throw new TypeError("Expected a hex number")},pt=(0,n.su)({result:mt}),yt=(0,n.su)({result:gt}),kt=(0,n.su)({safeLow:n.mH,average:n.mH,fast:n.mH,fastest:n.mH}),Et=(0,n.su)({types:(0,n.su)((0,n._2)((0,n.su)({name:n.XC,type:n.XC}))),primaryType:n.XC,domain:n.JC,message:n.JC});var wt=P(86352),ce=(m,e,t)=>new Promise((s,r)=>{var i=l=>{try{c(t.next(l))}catch(o){r(o)}},h=l=>{try{c(t.throw(l))}catch(o){r(o)}},c=l=>l.done?s(l.value):Promise.resolve(l.value).then(i,h);c((t=t.apply(m,e)).next())});const Ee=(m,e)=>{const t=Object.keys(e);for(const s of t){const r=e[s];typeof r=="string"&&m(` ${s}: ${(0,g.div)(r,"1000000000",18)} gwei`)}},vt=(m,e,t,s,r)=>({infoFeeProvider:()=>ce(void 0,null,function*(){return yield Tt(m,e)}),externalFeeProviders:[Ct,Pt,bt].map(h=>()=>ce(void 0,null,function*(){return yield h(m,e,t,s,r)}))}),bt=(m,e,t,s,r)=>ce(void 0,null,function*(){const{rpcServers:i,supportsEIP1559:h=!1}=r;if(h)return;const c=(0,p.sD)(i,1)[0],l={headers:{Accept:"application/json","Content-Type":"application/json"},method:"POST",body:JSON.stringify({method:"eth_gasPrice",params:[],id:1,jsonrpc:"2.0"})},o=yield m(c,l);if(!o.ok){const k=yield o.text();throw new Error(`fetchFeesFromRpc fetch error: ${k}`)}const d=yield o.json(),a=(0,n.Vk)(Y)(d);if(a==null)throw new Error(`fetchFeesFromRpc ${c} returned invalid json: ${d}`);const{result:u}=a,f=(0,p.Z8)(u),y={lowFee:(0,g.mul)(f,"1"),standardFeeLow:(0,g.mul)(f,"1.06"),standardFeeHigh:(0,g.mul)(f,"1.12"),highFee:(0,g.mul)(f,"1.25")};return s(`fetchFeesFromRpc: ${e.currencyCode}`),Ee(s,y),y}),Ct=(m,e,t,s,r)=>ce(void 0,null,function*(){const i=r.evmScanApiServers,h=Ne(t,e,s);if(i==null||h==null)return;const c=`&apikey=${Array.isArray(h)?(0,p.sD)(h,1)[0]:h!=null?h:""}`,l=`${(0,p.sD)(i,1)[0]}/api?module=gastracker&action=gasoracle${c}`,o=yield m(l);if(!o.ok)throw new Error(`EvmScan fetch error: ${JSON.stringify(o)}`);const d=yield o.json(),a=d.message.includes("NOTOK");if(!(d!=null&&!a))throw new Error(`fetchFeesFromEvmScan unrecognized response message: ${d.message}`);const{SafeGasPrice:f,ProposeGasPrice:y,FastGasPrice:k}=ue(d.result),C=parseInt(f);let v=parseInt(y),E=parseInt(k);v<=C&&(v=C+1),E<=v&&(E=v+1);const b=`${C*se}`,L=`${(C+v)/2*se}`,D=`${E*se}`,K=`${E*se/ht}`,M={lowFee:b,standardFeeLow:L,standardFeeHigh:D,highFee:K};return s(`fetchFeesFromEvmScan: ${e.currencyCode}`),Ee(s,M),M}),Pt=(m,e,t,s,r)=>ce(void 0,null,function*(){const{ethGasStationUrl:i}=r,h=At(t,e,s);if(i==null||h==null)return;const c=h?`?api-key=${h||""}`:"",o=yield(yield m(`${i}${c}`)).json(),d=kt(o);if(e.currencyCode==="MATIC"&&(d.safeLow*=10,d.average=(o.fast+o.safeLow)/2*10,d.fast=o.standard*10,d.fastest*=10),d.safeLow<=0||d.safeLow>ke)throw new Error("Invalid safeLow value from Gas Station");if(d.average<1||d.average>ke)throw new Error("Invalid average value from Gas Station");if(d.fast<1||d.fast>ke)throw new Error("Invalid fastest value from Gas Station");if(d.fastest<1||d.fastest>ke)throw new Error("Invalid fastest value from Gas Station");d.average<=d.safeLow&&(d.average=d.safeLow+1),d.fast<=d.average&&(d.fast=d.average+1),d.fastest<=d.fast&&(d.fastest=d.fast+1);let a=d.safeLow,u=d.fast,f=((d.fast+d.fastest)*.5+d.fastest)*.5,y=f>d.fastest?f:d.fastest;a=Math.round(a)*ye,u=Math.round(u)*ye,f=Math.round(f)*ye,y=Math.round(y)*ye;const k={lowFee:a.toString(),standardFeeLow:u.toString(),standardFeeHigh:f.toString(),highFee:y.toString()};return s(`fetchFeesFromEvmGasStation: ${e.currencyCode}`),Ee(s,k),k}),Tt=(m,e)=>ce(void 0,[m,e],function*(t,{pluginId:s}){const i=yield(yield(0,wt.Vn)(`v1/networkFees/${s}`,void 0,void 0,t)).json();return he(i)}),Ne=(m,e,t)=>{const{evmScanApiKey:s,etherscanApiKey:r,ftmscanApiKey:i,bscscanApiKey:h,polygonscanApiKey:c}=m;if(s!=null)return s;const{currencyCode:l}=e;if(l==="ETH"&&r!=null)return t.warn("INIT OPTION 'etherscanApiKey' IS DEPRECATED. USE 'evmScanApiKey' INSTEAD"),r;if(l==="FTM"&&i!=null)return t.warn("INIT OPTION 'ftmscanApiKey' IS DEPRECATED. USE 'evmScanApiKey' INSTEAD"),i;if(l==="BNB"&&h!=null)return t.warn("INIT OPTION 'bscscanApiKey' IS DEPRECATED. USE 'evmScanApiKey' INSTEAD"),h;if(l==="MATIC"&&c!=null)return t.warn("INIT OPTION 'polygonscanApiKey' IS DEPRECATED. USE 'evmScanApiKey' INSTEAD"),c},At=(m,e,t)=>{const{gasStationApiKey:s,ethGasStationApiKey:r}=m;if(s!=null)return s;const{currencyCode:i}=e;if(i==="ETH"&&r!=null)return t.warn("INIT OPTION 'ethGasStationApiKey' IS DEPRECATED. USE 'gasStationApiKey' INSTEAD"),r};var St=Object.defineProperty,It=Object.defineProperties,Lt=Object.getOwnPropertyDescriptors,$e=Object.getOwnPropertySymbols,Ft=Object.prototype.hasOwnProperty,Ot=Object.prototype.propertyIsEnumerable,Re=(m,e,t)=>e in m?St(m,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):m[e]=t,De=(m,e)=>{for(var t in e||(e={}))Ft.call(e,t)&&Re(m,t,e[t]);if($e)for(var t of $e(e))Ot.call(e,t)&&Re(m,t,e[t]);return m},_e=(m,e)=>It(m,Lt(e)),w=(m,e,t)=>new Promise((s,r)=>{var i=l=>{try{c(t.next(l))}catch(o){r(o)}},h=l=>{try{c(t.throw(l))}catch(o){r(o)}},c=l=>l.done?s(l.value):Promise.resolve(l.value).then(i,h);c((t=t.apply(m,e)).next())});const xt=2e4,Bt=2e4,Nt=2e4,$t=2e4,Xe=4*2,Ke=2*60,Rt=50;function we(m,e){return w(this,null,function*(){return{result:yield m,server:e}})}const Te=(m,e,t)=>{let s={};try{s=_e(De({gasPrice:(0,g.div)(m,se.toString(),se.toString().length-1)},t!==void 0?{gasUsed:t}:{}),{gasLimit:e})}catch(r){console.log(`Failed to construct feeRateUssed: ${r}`)}return s};class Dt{constructor(e){this.ethEngine=e,this.ethNeeds={blockHeightLastChecked:0,nonceLastChecked:0,tokenBalLastChecked:{},tokenTxsLastChecked:{}},this.fetchGetEtherscan=this.fetchGetEtherscan.bind(this),this.multicastServers=this.multicastServers.bind(this),this.checkAddressBlockbook=this.checkAddressBlockbook.bind(this),this.checkBlockHeightEthscan=this.checkBlockHeightEthscan.bind(this),this.checkBlockHeightBlockchair=this.checkBlockHeightBlockchair.bind(this),this.checkBlockHeightAmberdata=this.checkBlockHeightAmberdata.bind(this),this.checkBlockHeightBlockbook=this.checkBlockHeightBlockbook.bind(this),this.checkNonceRpc=this.checkNonceRpc.bind(this),this.checkNonceEthscan=this.checkNonceEthscan.bind(this),this.checkNonceAmberdata=this.checkNonceAmberdata.bind(this),this.checkTokenBalEthscan=this.checkTokenBalEthscan.bind(this),this.checkTokenBalBlockchair=this.checkTokenBalBlockchair.bind(this),this.checkTokenBalRpc=this.checkTokenBalRpc.bind(this),this.checkTxsEthscan=this.checkTxsEthscan.bind(this),this.processEthereumNetworkUpdate=this.processEthereumNetworkUpdate.bind(this),this.queryFuncs=this.buildQueryFuncs(this.ethEngine.networkInfo),this.walletId=e.walletInfo.id}processEvmScanTransaction(e,t){return w(this,null,function*(){var s;const r=[],i=(s=e.hash)!=null?s:e.transactionHash;if(i==null)throw new Error("Invalid transaction result format");const h=e.from.toLowerCase()===this.ethEngine.walletLocalData.publicKey.toLowerCase(),c=t!==this.ethEngine.currencyInfo.currencyCode,l="gasPrice"in e?e.gasPrice:void 0,o=l!=null?(0,g.mul)(l,e.gasUsed):"0";let d="0";if(h&&this.ethEngine.networkInfo.l1RollupParams!=null){const v=yield this.multicastServers("eth_getTransactionReceipt",[i]),E=nt(v.result.result);d=(0,g.add)(d,(0,p.X0)(E.l1Fee))}let a,u,f;h?c?(a=(0,g.sub)("0",e.value),u="0",f=(0,g.add)(o,d)):e.from.toLowerCase()===e.to.toLowerCase()?(a=(0,g.sub)((0,g.sub)("0",o),d),u=(0,g.add)(o,d)):(a=(0,g.sub)((0,g.sub)((0,g.sub)("0",e.value),o),d),u=(0,g.add)(o,d)):(a=e.value,u="0",r.push(this.ethEngine.walletLocalData.publicKey));const y={from:[e.from],to:[e.to],gas:e.gas,gasPrice:l!=null?l:"",gasUsed:e.gasUsed,isFromMakeSpend:!1};let k=parseInt(e.blockNumber);return k<0&&(k=0),{blockHeight:k,currencyCode:t,date:parseInt(e.timeStamp),feeRateUsed:l!=null?Te(l,e.gas,e.gasUsed):void 0,isSend:a.startsWith("-"),memos:[],nativeAmount:a,networkFee:u,otherParams:y,ourReceiveAddresses:r,parentNetworkFee:f,signedTx:"",txid:i,walletId:this.walletId}})}processAlethioTransaction(e,t){let s;const r=[];let i;const h=t!==this.ethEngine.currencyInfo.currencyCode,c=e.attributes.value,l=e.attributes.fee?e.attributes.fee:"0",o=e.relationships.from.data.id,d=e.relationships.to.data.id;t===this.ethEngine.currencyInfo.currencyCode?i=l:i="0";const a=o.toLowerCase()===this.ethEngine.walletLocalData.publicKey.toLowerCase();if(a)o.toLowerCase()===d.toLowerCase()?s=(0,g.mul)(i,"-1"):(s=(0,g.sub)("0",c),h||(s=(0,g.sub)(s,i)));else if(d.toLowerCase()===this.ethEngine.walletLocalData.publicKey.toLowerCase())s=c,r.push(this.ethEngine.walletLocalData.publicKey.toLowerCase());else return null;const u={from:[o],to:[d],gas:"0",gasPrice:"0",gasUsed:"0",isFromMakeSpend:!1};let f=e.attributes.globalRank[0];f<0&&(f=0);let y,k="0";return h&&a?y=i:k=i,{blockHeight:f,currencyCode:t,date:e.attributes.blockCreationTime,isSend:s.startsWith("-"),memos:[],nativeAmount:s,networkFee:k,otherParams:u,ourReceiveAddresses:r,parentNetworkFee:y,signedTx:"",txid:e.relationships.transaction.data.id,walletId:this.walletId}}fetchGetEtherscan(e,t){return w(this,null,function*(){const s=Ne(this.ethEngine.initOptions,this.ethEngine.currencyInfo,this.ethEngine.log);e.indexOf("cors-http")===0&&(e=e.replace(/^cors-http/,"http"));const i=Array.isArray(s)?(0,p.sD)(s,1)[0]:s!=null?s:"",h=i!==""?`&apikey=${i}`:"",c=`${e}/api${t}`,l=yield this.ethEngine.fetchCors(`${c}${h}`);return l.ok||this.throwError(l,"fetchGetEtherscan",c),yield l.json()})}fetchGetBlockbook(e,t){return w(this,null,function*(){const s=e+t;return yield(e.includes("trezor")?yield this.ethEngine.fetchCors(s,{headers:{"User-Agent":"http.agent"}}):yield this.ethEngine.fetchCors(s)).json()})}fetchPostRPC(e,t,s,r){return w(this,null,function*(){const i={id:s,jsonrpc:"2.0",method:e,params:t},c=/{{(.*?)}}/g.exec(r);if(c!=null){const d=c[1],a=F(d),u=this.ethEngine.initOptions[a];if(typeof u=="string")r=r.replace(c[0],u);else throw u==null?new Error(`Missing ${a} in 'initOptions' for ${this.ethEngine.currencyInfo.pluginId}`):new Error("Incorrect apikey type for RPC")}const l=yield this.ethEngine.fetchCors(r,{headers:{Accept:"application/json","Content-Type":"application/json"},method:"POST",body:JSON.stringify(i)}),o=U()(r,{},!0);return l.ok||this.throwError(l,"fetchPostRPC",o.hostname),yield l.json()})}fetchPostBlockcypher(e,t,s){return w(this,null,function*(){const{blockcypherApiKey:r}=this.ethEngine.initOptions;let i="";r&&r.length>5&&(i="&token="+r);const h=`${s}/${e}${i}`,c=yield this.ethEngine.fetchCors(h,{headers:{Accept:"application/json","Content-Type":"application/json"},method:"POST",body:JSON.stringify(t)}),l=U()(h,{},!0);return c.ok||this.throwError(c,"fetchPostBlockcypher",l.hostname),yield c.json()})}fetchGetBlockchair(e,t=!1){return w(this,null,function*(){const{blockchairApiKey:s}=this.ethEngine.initOptions,{blockchairApiServers:r}=this.ethEngine.networkInfo,i=t&&s?`&key=${s}`:"",h=`${r[0]}${e}`,c=yield this.ethEngine.fetchCors(`${h}${i}`);return c.ok||this.throwError(c,"fetchGetBlockchair",h),yield c.json()})}fetchPostAmberdataRpc(e){return w(this,arguments,function*(t,s=[]){const{amberdataApiKey:r=""}=this.ethEngine.initOptions,{amberdataRpcServers:i}=this.ethEngine.networkInfo,h=`${i[0]}`,c={jsonrpc:"2.0",method:t,params:s,id:1},l=yield this.ethEngine.fetchCors(h,{headers:{"x-amberdata-blockchain-id":this.ethEngine.networkInfo.amberDataBlockchainId,"x-api-key":r,"Content-Type":"application/json"},method:"POST",body:JSON.stringify(c)}),o=U()(h,{},!0);return l.ok||this.throwError(l,"fetchPostAmberdataRpc",o),yield l.json()})}fetchGetAmberdataApi(e){return w(this,null,function*(){const{amberdataApiKey:t=""}=this.ethEngine.initOptions,{amberdataApiServers:s}=this.ethEngine.networkInfo,r=`${s[0]}${e}`,i=yield this.ethEngine.fetchCors(r,{headers:{"x-amberdata-blockchain-id":this.ethEngine.networkInfo.amberDataBlockchainId,"x-api-key":t}});return i.ok||this.throwError(i,"fetchGetAmberdata",r),yield i.json()})}fetchGetAlethio(e,t=!0,s){return w(this,null,function*(){const{alethioApiKey:r=""}=this.ethEngine.initOptions,{alethioApiServers:i}=this.ethEngine.networkInfo,h=t?`${i[0]}${e}`:e,c=yield this.ethEngine.fetchCors(h,r?{headers:{Authorization:`Bearer ${r}`}}:void 0);return c.ok||this.throwError(c,"fetchGetAlethio",h),yield c.json()})}broadcastEtherscan(e,t){return w(this,null,function*(){const s=`?module=proxy&action=eth_sendRawTransaction&hex=${e.signedTx}`,r=yield this.fetchGetEtherscan(t,s);return this.broadcastResponseHandler(r,t,e)})}broadcastRPC(e,t,s){return w(this,null,function*(){const r="eth_sendRawTransaction",i=[e.signedTx],h=yield this.fetchPostRPC(r,i,t,s),c=U()(s,{},!0);return this.broadcastResponseHandler(h,c,e)})}broadcastBlockCypher(e,t){return w(this,null,function*(){const s=`v1/${this.ethEngine.currencyInfo.currencyCode.toLowerCase()}/main/txs/push`,r=e.signedTx.replace("0x",""),i=yield this.fetchPostBlockcypher(s,{tx:r},t);return this.broadcastResponseHandler(i,t,e)})}broadcastBlockbook(e,t){return w(this,null,function*(){const s=yield this.fetchGetBlockbook(t,`/api/v2/sendtx/${e.signedTx}`);return this.broadcastResponseHandler(s,t,e)})}broadcastResponseHandler(e,t,s){if(typeof e.error<"u")throw this.ethEngine.error(`FAILURE ${t}
2
2
  ${JSON.stringify(e.error)}
3
3
  ${(0,p.oX)(s)}`),e.error;if(typeof e.result=="string")return this.ethEngine.warn(`SUCCESS ${t}
4
4
  ${(0,p.oX)(s)}`),e;throw this.ethEngine.error(`FAILURE ${t}
5
5
  Invalid return value ${JSON.stringify(e)}
6
- ${(0,p.oX)(s)}`),new Error("Invalid return value on transaction send")}multicastServers(e,...t){return w(this,null,function*(){const{rpcServers:s,blockcypherApiServers:r,evmScanApiServers:i,blockbookServers:u,chainParams:{chainId:a}}=this.ethEngine.networkInfo;let h={result:"",server:"no server"},o,l;switch(e){case"broadcastTx":{const c=[];s.forEach(d=>{const f=U()(d,{},!0);c.push(we(this.broadcastRPC(t[0],a,d),f.hostname))}),i.forEach(d=>{c.push(we(this.broadcastEtherscan(t[0],d),"etherscan"))}),u.forEach(d=>{c.push(we(this.broadcastBlockbook(t[0],d),"blockbook"))}),r.forEach(d=>{c.push(we(this.broadcastBlockCypher(t[0],d),"blockcypher"))}),h=yield(0,p.Wp)(c),this.ethEngine.log(`${this.ethEngine.currencyInfo.currencyCode} multicastServers ${e} ${h.server} won`);break}case"eth_blockNumber":o=i.map(c=>()=>w(this,null,function*(){if(!c.includes("etherscan")&&!c.includes("blockscout"))throw new Error(`Unsupported command eth_blockNumber in ${c}`);let d="?module=proxy&action=eth_blockNumber";c.includes("blockscout")&&(d="?module=block&action=eth_block_number");const f=yield this.fetchGetEtherscan(c,d);if(typeof f.result!="string"){const y=`Invalid return value eth_blockNumber in ${c}`;throw this.ethEngine.error(y),new Error(y)}return{server:c,result:f}})),o.push(...s.map(c=>()=>w(this,null,function*(){const d=yield this.fetchPostRPC("eth_blockNumber",[],a,c);if(d.error!=null)throw this.ethEngine.error(`Successful eth_blockNumber response object from ${c} included an error ${JSON.stringify(d.error)}`),new Error("Successful eth_blockNumber response object included an error");return{server:U()(c).hostname,result:d}}))),o=(0,p.Sy)(o),h=yield(0,p.QJ)(o);break;case"eth_estimateGas":o=s.map(c=>()=>w(this,null,function*(){const d=yield this.fetchPostRPC("eth_estimateGas",t[0],a,c);if(d.error!=null)throw this.ethEngine.error(`Successful eth_estimateGas response object from ${c} included an error ${JSON.stringify(d.error)}`),new Error("Successful eth_estimateGas response object included an error");return{server:U()(c).hostname,result:d}})),h=yield(0,p.QJ)(o);break;case"eth_getTransactionReceipt":case"eth_getCode":o=s.map(c=>()=>w(this,null,function*(){const d=yield this.fetchPostRPC(e,t[0],a,c);if(d.error!=null)throw this.ethEngine.error(`Successful ${e} response object from ${c} included an error ${d.error}`),new Error(`Successful ${e} response object included an error`);return{server:U()(c).hostname,result:d}})),h=yield(0,p.QJ)(o);break;case"eth_getTransactionCount":l=`?module=proxy&action=eth_getTransactionCount&address=${t[0]}&tag=latest`,o=i.map(c=>()=>w(this,null,function*(){if(!c.includes("etherscan")&&!c.includes("blockscout"))throw new Error(`Unsupported command eth_getTransactionCount in ${c}`);const d=yield this.fetchGetEtherscan(c,l);if(typeof d.result!="string"){const f=`Invalid return value eth_getTransactionCount in ${c}`;throw this.ethEngine.error(f),new Error(f)}return{server:c,result:d}})),o=(0,p.Sy)(o),h=yield(0,p.QJ)(o);break;case"eth_getTransactionCount_RPC":o=s.map(c=>()=>w(this,null,function*(){const d=yield this.fetchPostRPC("eth_getTransactionCount",[t[0],"latest"],a,c);if(d.error!=null)throw this.ethEngine.error(`Successful eth_getTransactionCount_RPC response object from ${c} included an error ${JSON.stringify(d.error)}`),new Error("Successful eth_getTransactionCount_RPC response object included an error");return{server:U()(c).hostname,result:d}})),o=(0,p.Sy)(o),h=yield(0,p.QJ)(o);break;case"eth_getBalance":l=`?module=account&action=balance&address=${t[0]}&tag=latest`,o=i.map(c=>()=>w(this,null,function*(){const d=yield this.fetchGetEtherscan(c,l);if(!d.result||typeof d.result!="string"){const f=`Invalid return value eth_getBalance in ${c}`;throw this.ethEngine.error(f),new Error(f)}return{server:c,result:d}})),o.push(...s.map(c=>()=>w(this,null,function*(){const d=yield this.fetchPostRPC("eth_getBalance",[t[0],"latest"],a,c);if(d.error!=null)throw this.ethEngine.error(`Successful eth_getBalance response object from ${c} included an error ${JSON.stringify(d.error)}`),new Error("Successful eth_getBalance response object included an error");if(!(0,p.vq)(d.result))throw new Error(`eth_getBalance not hex for ${U()(c).hostname}`);return d.result=(0,p.Z8)(d.result),{server:U()(c).hostname,result:d}}))),o=(0,p.Sy)(o),h=yield(0,p.QJ)(o);break;case"getTokenBalance":l=`?module=account&action=tokenbalance&contractaddress=${t[1]}&address=${t[0]}&tag=latest`,o=i.map(c=>()=>w(this,null,function*(){const d=yield this.fetchGetEtherscan(c,l);if(!d.result||typeof d.result!="string"){const f=`Invalid return value getTokenBalance in ${c}`;throw this.ethEngine.error(f),new Error(f)}return{server:c,result:d}})),o=(0,p.Sy)(o),h=yield(0,p.QJ)(o);break;case"getTransactions":{const{currencyCode:c,address:d,startBlock:f,page:y,offset:k,contractAddress:b,searchRegularTxs:v}=t[0];let E;c===this.ethEngine.currencyInfo.currencyCode?E=`?action=${v?"txlist":"txlistinternal"}&module=account`:E=`?action=tokentx&contractaddress=${b}&module=account`,l=`${E}&address=${d}&startblock=${f}&endblock=999999999&sort=asc&page=${y}&offset=${k}`,o=i.map(C=>()=>w(this,null,function*(){const I=yield this.fetchGetEtherscan(C,l);if(typeof I.result!="object"||typeof I.result.length!="number"){const _=`Invalid return value getTransactions in ${C}`;throw I.result!=="Max rate limit reached"&&this.ethEngine.error(_),new Error(_)}return{server:C,result:I}})),o=(0,p.Sy)(o),o.length>0?h=yield(0,p.QJ)(o):h=_e(Re({},h),{result:{result:[]}});break}case"blockbookBlockHeight":o=u.map(c=>()=>w(this,null,function*(){const d=yield this.fetchGetBlockbook(c,t[0]);return{server:c,result:d}})),o=(0,p.Sy)(o),h=yield(0,p.QJ)(o);break;case"blockbookAddress":o=u.map(c=>()=>w(this,null,function*(){const d=yield this.fetchGetBlockbook(c,t[0]);return{server:c,result:d}})),o=(0,p.Sy)(o),h=yield(0,p.QJ)(o);break;case"eth_call":o=s.map(c=>()=>w(this,null,function*(){const d=yield this.fetchPostRPC("eth_call",[t[0],"latest"],a,c);if(d.error!=null)throw this.ethEngine.error(`Successful eth_call response object from ${c} included an error ${JSON.stringify(d.error)}`),new Error("Successful eth_call response object included an error");return{server:U()(c).hostname,result:d}})),h=yield(0,p.QJ)(o);break}return h})}getBaseFeePerGas(){return w(this,null,function*(){const{rpcServers:e,chainParams:{chainId:t}}=this.ethEngine.networkInfo,s=e.map(r=>()=>w(this,null,function*(){return yield this.fetchPostRPC("eth_getBlockByNumber",["latest",!1],t,r).then(i=>{if(i.error!=null){const a=`multicast get_baseFeePerGas error response from ${r}: ${JSON.stringify(i.error)}`;throw this.ethEngine.warn(a),new Error(a)}return{baseFeePerGas:i.result.baseFeePerGas}})}));return yield(0,p.QJ)(s)})}checkBlockHeightEthscan(){return w(this,null,function*(){const{result:e,server:t}=yield this.multicastServers("eth_blockNumber");return{blockHeight:gt(e).result,server:t}})}checkBlockHeightBlockbook(){return w(this,null,function*(){try{const{result:e,server:t}=yield this.multicastServers("blockbookBlockHeight","/api/v2");return{blockHeight:de(e).blockbook.bestHeight,server:t}}catch(e){throw this.ethEngine.log("checkBlockHeightBlockbook blockHeight ",e),new Error("checkBlockHeightBlockbook returned invalid JSON")}})}checkBlockHeightBlockchair(){return w(this,null,function*(){try{const e=yield this.fetchGetBlockchair(`/${this.ethEngine.currencyInfo.pluginId}/stats`,!1);return{blockHeight:parseInt(et(e).data.blocks,10),server:"blockchair"}}catch(e){throw this.logError(e),new Error("checkBlockHeightBlockchair returned invalid JSON")}})}checkBlockHeightAmberdata(){return w(this,null,function*(){try{const e=yield this.fetchPostAmberdataRpc("eth_blockNumber",[]);return{blockHeight:parseInt(Y(e).result,16),server:"amberdata"}}catch(e){throw this.logError("checkBlockHeightAmberdata",e),new Error("checkTxsAmberdata (regular tx) response is invalid")}})}checkNonceRpc(){return w(this,null,function*(){const e=this.ethEngine.walletLocalData.publicKey,{result:t,server:s}=yield this.multicastServers("eth_getTransactionCount_RPC",e),r=Y(t);if(/0[xX][0-9a-fA-F]+/.test(r.result))return{newNonce:(0,g.add)("0",r.result),server:s};throw new Error("checkNonceRpc returned invalid JSON")})}checkNonceEthscan(){return w(this,null,function*(){const e=this.ethEngine.walletLocalData.publicKey,{result:t,server:s}=yield this.multicastServers("eth_getTransactionCount",e);return{newNonce:pt(t).result,server:s}})}checkNonceAmberdata(){return w(this,null,function*(){const e=this.ethEngine.walletLocalData.publicKey;try{const t=yield this.fetchPostAmberdataRpc("eth_getTransactionCount",[e,"latest"]);return{newNonce:`${parseInt(Y(t).result,16)}`,server:"amberdata"}}catch(t){throw this.logError("checkNonceAmberdata",t),new Error("Amberdata returned invalid JSON")}})}check(e,...t){return w(this,null,function*(){return yield(0,p.QJ)(this.queryFuncs[e].map(s=>()=>w(this,null,function*(){return yield s(...t)}))).catch(s=>({}))})}getAllTxsEthscan(e,t,s,r){return w(this,null,function*(){const i=this.ethEngine.walletLocalData.publicKey;let u=1;const a=[];let h="";const o=r.contractAddress,l=r.searchRegularTxs;for(;;){const c=$t,d=yield this.multicastServers("getTransactions",{currencyCode:t,address:i,startBlock:e,page:u,offset:c,contractAddress:o,searchRegularTxs:l});h=d.server;const f=d.result.result;for(let y=0;y<f.length;y++)try{const k=s(f[y]),b=yield this.processEvmScanTransaction(k,t);a.push(b)}catch(k){throw this.ethEngine.error(`getAllTxsEthscan ${s.name}
6
+ ${(0,p.oX)(s)}`),new Error("Invalid return value on transaction send")}multicastServers(e,...t){return w(this,null,function*(){const{rpcServers:s,blockcypherApiServers:r,evmScanApiServers:i,blockbookServers:h,chainParams:{chainId:c}}=this.ethEngine.networkInfo;let l={result:"",server:"no server"},o,d;switch(e){case"broadcastTx":{const a=[];s.forEach(u=>{const f=U()(u,{},!0);a.push(we(this.broadcastRPC(t[0],c,u),f.hostname))}),i.forEach(u=>{a.push(we(this.broadcastEtherscan(t[0],u),"etherscan"))}),h.forEach(u=>{a.push(we(this.broadcastBlockbook(t[0],u),"blockbook"))}),r.forEach(u=>{a.push(we(this.broadcastBlockCypher(t[0],u),"blockcypher"))}),l=yield(0,p.Wp)(a),this.ethEngine.log(`${this.ethEngine.currencyInfo.currencyCode} multicastServers ${e} ${l.server} won`);break}case"eth_blockNumber":o=i.map(a=>()=>w(this,null,function*(){if(!a.includes("etherscan")&&!a.includes("blockscout"))throw new Error(`Unsupported command eth_blockNumber in ${a}`);let u="?module=proxy&action=eth_blockNumber";a.includes("blockscout")&&(u="?module=block&action=eth_block_number");const f=yield this.fetchGetEtherscan(a,u);if(typeof f.result!="string"){const y=`Invalid return value eth_blockNumber in ${a}`;throw this.ethEngine.error(y),new Error(y)}return{server:a,result:f}})),o.push(...s.map(a=>()=>w(this,null,function*(){const u=yield this.fetchPostRPC("eth_blockNumber",[],c,a);if(u.error!=null)throw this.ethEngine.error(`Successful eth_blockNumber response object from ${a} included an error ${JSON.stringify(u.error)}`),new Error("Successful eth_blockNumber response object included an error");return{server:U()(a).hostname,result:u}}))),o=(0,p.Sy)(o),l=yield(0,p.QJ)(o);break;case"eth_estimateGas":o=s.map(a=>()=>w(this,null,function*(){const u=yield this.fetchPostRPC("eth_estimateGas",t[0],c,a);if(u.error!=null)throw this.ethEngine.error(`Successful eth_estimateGas response object from ${a} included an error ${JSON.stringify(u.error)}`),new Error("Successful eth_estimateGas response object included an error");return{server:U()(a).hostname,result:u}})),l=yield(0,p.QJ)(o);break;case"eth_getTransactionReceipt":case"eth_getCode":o=s.map(a=>()=>w(this,null,function*(){const u=yield this.fetchPostRPC(e,t[0],c,a);if(u.error!=null)throw this.ethEngine.error(`Successful ${e} response object from ${a} included an error ${u.error}`),new Error(`Successful ${e} response object included an error`);return{server:U()(a).hostname,result:u}})),l=yield(0,p.QJ)(o);break;case"eth_getTransactionCount":d=`?module=proxy&action=eth_getTransactionCount&address=${t[0]}&tag=latest`,o=i.map(a=>()=>w(this,null,function*(){if(!a.includes("etherscan")&&!a.includes("blockscout"))throw new Error(`Unsupported command eth_getTransactionCount in ${a}`);const u=yield this.fetchGetEtherscan(a,d);if(typeof u.result!="string"){const f=`Invalid return value eth_getTransactionCount in ${a}`;throw this.ethEngine.error(f),new Error(f)}return{server:a,result:u}})),o=(0,p.Sy)(o),l=yield(0,p.QJ)(o);break;case"eth_getTransactionCount_RPC":o=s.map(a=>()=>w(this,null,function*(){const u=yield this.fetchPostRPC("eth_getTransactionCount",[t[0],"latest"],c,a);if(u.error!=null)throw this.ethEngine.error(`Successful eth_getTransactionCount_RPC response object from ${a} included an error ${JSON.stringify(u.error)}`),new Error("Successful eth_getTransactionCount_RPC response object included an error");return{server:U()(a).hostname,result:u}})),o=(0,p.Sy)(o),l=yield(0,p.QJ)(o);break;case"eth_getBalance":d=`?module=account&action=balance&address=${t[0]}&tag=latest`,o=i.map(a=>()=>w(this,null,function*(){const u=yield this.fetchGetEtherscan(a,d);if(!u.result||typeof u.result!="string"){const f=`Invalid return value eth_getBalance in ${a}`;throw this.ethEngine.error(f),new Error(f)}return{server:a,result:u}})),o.push(...s.map(a=>()=>w(this,null,function*(){const u=yield this.fetchPostRPC("eth_getBalance",[t[0],"latest"],c,a);if(u.error!=null)throw this.ethEngine.error(`Successful eth_getBalance response object from ${a} included an error ${JSON.stringify(u.error)}`),new Error("Successful eth_getBalance response object included an error");if(!(0,p.vq)(u.result))throw new Error(`eth_getBalance not hex for ${U()(a).hostname}`);return u.result=(0,p.Z8)(u.result),{server:U()(a).hostname,result:u}}))),o=(0,p.Sy)(o),l=yield(0,p.QJ)(o);break;case"getTokenBalance":d=`?module=account&action=tokenbalance&contractaddress=${t[1]}&address=${t[0]}&tag=latest`,o=i.map(a=>()=>w(this,null,function*(){const u=yield this.fetchGetEtherscan(a,d);if(!u.result||typeof u.result!="string"){const f=`Invalid return value getTokenBalance in ${a}`;throw this.ethEngine.error(f),new Error(f)}return{server:a,result:u}})),o=(0,p.Sy)(o),l=yield(0,p.QJ)(o);break;case"getTransactions":{const{currencyCode:a,address:u,startBlock:f,page:y,offset:k,contractAddress:C,searchRegularTxs:v}=t[0];let E;a===this.ethEngine.currencyInfo.currencyCode?E=`?action=${v?"txlist":"txlistinternal"}&module=account`:E=`?action=tokentx&contractaddress=${C}&module=account`,d=`${E}&address=${u}&startblock=${f}&endblock=999999999&sort=asc&page=${y}&offset=${k}`,o=i.map(b=>()=>w(this,null,function*(){const L=yield this.fetchGetEtherscan(b,d);if(typeof L.result!="object"||typeof L.result.length!="number"){const D=`Invalid return value getTransactions in ${b}`;throw L.result!=="Max rate limit reached"&&this.ethEngine.error(D),new Error(D)}return{server:b,result:L}})),o=(0,p.Sy)(o),o.length>0?l=yield(0,p.QJ)(o):l=_e(De({},l),{result:{result:[]}});break}case"blockbookBlockHeight":o=h.map(a=>()=>w(this,null,function*(){const u=yield this.fetchGetBlockbook(a,t[0]);return{server:a,result:u}})),o=(0,p.Sy)(o),l=yield(0,p.QJ)(o);break;case"blockbookAddress":o=h.map(a=>()=>w(this,null,function*(){const u=yield this.fetchGetBlockbook(a,t[0]);return{server:a,result:u}})),o=(0,p.Sy)(o),l=yield(0,p.QJ)(o);break;case"eth_call":o=s.map(a=>()=>w(this,null,function*(){const u=yield this.fetchPostRPC("eth_call",[t[0],"latest"],c,a);if(u.error!=null)throw this.ethEngine.error(`Successful eth_call response object from ${a} included an error ${JSON.stringify(u.error)}`),new Error("Successful eth_call response object included an error");return{server:U()(a).hostname,result:u}})),l=yield(0,p.QJ)(o);break}return l})}getBaseFeePerGas(){return w(this,null,function*(){const{rpcServers:e,chainParams:{chainId:t}}=this.ethEngine.networkInfo,s=e.map(r=>()=>w(this,null,function*(){return yield this.fetchPostRPC("eth_getBlockByNumber",["latest",!1],t,r).then(i=>{if(i.error!=null){const c=`multicast get_baseFeePerGas error response from ${r}: ${JSON.stringify(i.error)}`;throw this.ethEngine.warn(c),new Error(c)}return{baseFeePerGas:i.result.baseFeePerGas}})}));return yield(0,p.QJ)(s)})}checkBlockHeightEthscan(){return w(this,null,function*(){const{result:e,server:t}=yield this.multicastServers("eth_blockNumber");return{blockHeight:pt(e).result,server:t}})}checkBlockHeightBlockbook(){return w(this,null,function*(){try{const{result:e,server:t}=yield this.multicastServers("blockbookBlockHeight","/api/v2");return{blockHeight:de(e).blockbook.bestHeight,server:t}}catch(e){throw this.ethEngine.log("checkBlockHeightBlockbook blockHeight ",e),new Error("checkBlockHeightBlockbook returned invalid JSON")}})}checkBlockHeightBlockchair(){return w(this,null,function*(){try{const e=yield this.fetchGetBlockchair(`/${this.ethEngine.currencyInfo.pluginId}/stats`,!1);return{blockHeight:parseInt(tt(e).data.blocks,10),server:"blockchair"}}catch(e){throw this.logError(e),new Error("checkBlockHeightBlockchair returned invalid JSON")}})}checkBlockHeightAmberdata(){return w(this,null,function*(){try{const e=yield this.fetchPostAmberdataRpc("eth_blockNumber",[]);return{blockHeight:parseInt(Y(e).result,16),server:"amberdata"}}catch(e){throw this.logError("checkBlockHeightAmberdata",e),new Error("checkTxsAmberdata (regular tx) response is invalid")}})}checkNonceRpc(){return w(this,null,function*(){const e=this.ethEngine.walletLocalData.publicKey,{result:t,server:s}=yield this.multicastServers("eth_getTransactionCount_RPC",e),r=Y(t);if(/0[xX][0-9a-fA-F]+/.test(r.result))return{newNonce:(0,g.add)("0",r.result),server:s};throw new Error("checkNonceRpc returned invalid JSON")})}checkNonceEthscan(){return w(this,null,function*(){const e=this.ethEngine.walletLocalData.publicKey,{result:t,server:s}=yield this.multicastServers("eth_getTransactionCount",e);return{newNonce:yt(t).result,server:s}})}checkNonceAmberdata(){return w(this,null,function*(){const e=this.ethEngine.walletLocalData.publicKey;try{const t=yield this.fetchPostAmberdataRpc("eth_getTransactionCount",[e,"latest"]);return{newNonce:`${parseInt(Y(t).result,16)}`,server:"amberdata"}}catch(t){throw this.logError("checkNonceAmberdata",t),new Error("Amberdata returned invalid JSON")}})}check(e,...t){return w(this,null,function*(){return yield(0,p.QJ)(this.queryFuncs[e].map(s=>()=>w(this,null,function*(){return yield s(...t)}))).catch(s=>({}))})}getAllTxsEthscan(e,t,s,r){return w(this,null,function*(){const i=this.ethEngine.walletLocalData.publicKey;let h=1;const c=[];let l="";const o=r.contractAddress,d=r.searchRegularTxs;for(;;){const a=Rt,u=yield this.multicastServers("getTransactions",{currencyCode:t,address:i,startBlock:e,page:h,offset:a,contractAddress:o,searchRegularTxs:d});l=u.server;const f=u.result.result;for(let y=0;y<f.length;y++)try{const k=s(f[y]),C=yield this.processEvmScanTransaction(k,t);c.push(C)}catch(k){throw this.ethEngine.error(`getAllTxsEthscan ${s.name}
7
7
  ${(0,p.HY)(k)}
8
- ${JSON.stringify(f[y])}`),new Error(`getAllTxsEthscan ${s.name} is invalid`)}if(f.length===0)break;u++}return{allTransactions:a,server:h}})}checkTxsEthscan(e){return w(this,null,function*(){const{startBlock:t,currencyCode:s}=e;let r,i;if(s===this.ethEngine.currencyInfo.currencyCode){const a=yield this.getAllTxsEthscan(t,s,W,{searchRegularTxs:!0}),h=yield this.getAllTxsEthscan(t,s,ge,{searchRegularTxs:!1});r=a.server||h.server,i=[...a.allTransactions,...h.allTransactions]}else{const a=this.ethEngine.getTokenInfo(s);if(a!=null&&typeof a.contractAddress=="string"){const h=a.contractAddress,o=yield this.getAllTxsEthscan(t,s,Ie,{contractAddress:h});r=o.server,i=o.allTransactions}else return{}}const u={blockHeight:t,edgeTransactions:i};return{tokenTxs:{[s]:u},server:r}})}getTokenCurrencyCode(e){const t=this.ethEngine.walletLocalData.publicKey;if(e.toLowerCase()===t.toLowerCase())return this.ethEngine.currencyInfo.currencyCode;for(const s of this.ethEngine.enabledTokens){const r=this.ethEngine.getTokenInfo(s);if(r!=null){const i=r.contractAddress;if(e&&typeof i=="string"&&i.toLowerCase()===e.toLowerCase())return s}}}checkAddressBlockbook(e){return w(this,null,function*(){const t=this.ethEngine.walletLocalData.publicKey.toLowerCase(),s={newNonce:"0",tokenBal:{},server:""},r="/api/v2/address/"+t+"?&details=tokenBalances",{result:i,server:u}=yield this.multicastServers("blockbookAddress",r);let a;try{a=Qe(i)}catch{throw this.ethEngine.error(`checkTxsBlockbook ${u} error BlockbookAddress ${JSON.stringify(i)}`),new Error(`checkTxsBlockbook ${u} returned invalid JSON for BlockbookAddress`)}const{nonce:h,tokens:o,balance:l}=a;s.newNonce=h,s.tokenBal!=null&&(s.tokenBal[this.ethEngine.currencyInfo.currencyCode]=l),s.server=u;for(const c of o)try{const{symbol:d,balance:f}=Le(c);s.tokenBal[d]=f}catch{throw this.ethEngine.error(`checkTxsBlockbook ${u} BlockbookTokenBalance ${JSON.stringify(c)}`),new Error(`checkTxsBlockbook ${u} returned invalid JSON for BlockbookTokenBalance`)}return s})}checkTokenBalEthscan(e){return w(this,null,function*(){const t=this.ethEngine.walletLocalData.publicKey;let s,r,i,u;try{if(e===this.ethEngine.currencyInfo.currencyCode)s=yield this.multicastServers("eth_getBalance",t),r=s.result,i=s.server;else{const a=this.ethEngine.getTokenInfo(e);if(a!=null&&typeof a.contractAddress=="string"){const h=a.contractAddress,o=yield this.multicastServers("getTokenBalance",t,h);r=o.result,i=o.server}}u=Y(r)}catch(a){throw this.ethEngine.error(`checkTokenBalEthscan token ${e} response ${s||""} `,a),new Error(`checkTokenBalEthscan invalid ${e} response ${JSON.stringify(r)}`)}if(/^\d+$/.test(u.result)){const a=u.result;return{tokenBal:{[e]:a},server:i}}else throw new Error(`checkTokenBalEthscan returned invalid JSON for ${e}`)})}checkTokenBalBlockchair(){return w(this,null,function*(){let e;const t=this.ethEngine.walletLocalData.publicKey,s=`/${this.ethEngine.currencyInfo.pluginId}/dashboards/address/${t}?erc_20=true`;try{const i=yield this.fetchGetBlockchair(s,!1);e=qe(i)}catch(i){throw this.logError("checkTokenBalBlockchair",i),new Error("checkTokenBalBlockchair response is invalid")}const r={[this.ethEngine.currencyInfo.currencyCode]:e.data[t].address.balance};for(const i of e.data[t].layer_2.erc_20)try{const u=Ye(i),a=u.balance,h=u.token_address,o=u.token_symbol,l=this.ethEngine.getTokenInfo(o);l!=null&&l.contractAddress===h&&(r[o]=a)}catch(u){throw this.ethEngine.error(`checkTokenBalBlockchair tokenData ${(0,p.HY)(u)}
9
- ${JSON.stringify(i)}`),new Error("checkTokenBalBlockchair tokenData is invalid")}return{tokenBal:r,server:"blockchair"}})}checkTokenBalRpc(e){return w(this,null,function*(){let t,s,r,i;const u=this.ethEngine.walletLocalData.publicKey;try{if(e===this.ethEngine.currencyInfo.currencyCode)s=yield this.multicastServers("eth_getBalance",u),r=s.result,i=s.server;else{const a=this.ethEngine.getTokenInfo(e);if(a!=null&&typeof a.contractAddress=="string"){const h={data:`0x70a08231${(0,p.gc)((0,p.KT)(u),32)}`,to:a.contractAddress},o=yield this.multicastServers("eth_call",h),l=o.result.result;if(!l.startsWith("0x"))throw new Error("Invalid return value. Result not hex");o.result.result=(0,p.Z8)(l),r=o.result,i=o.server}}t=Y(r)}catch(a){throw this.ethEngine.error(`checkTokenBalRpc token ${e} response ${s||""} `,a),new Error(`checkTokenBalRpc invalid ${e} response ${JSON.stringify(r)}`)}return{tokenBal:{[e]:t.result},server:i}})}checkAndUpdate(e=0,t,s,r){return w(this,null,function*(){const i=Date.now();if(i-e>t)try{const u=yield r();this.processEthereumNetworkUpdate(i,u,s)}catch(u){this.ethEngine.error("checkAndUpdate ",u)}})}getQueryHeightWithLookback(e){return e>De?e-De:0}getQueryDateWithLookback(e){return e>Xe?e-Xe:0}needsLoop(){return w(this,null,function*(){for(;this.ethEngine.engineOn;){const e=this.ethEngine.walletLocalData.blockHeight;yield this.checkAndUpdate(this.ethNeeds.blockHeightLastChecked,Ot,e,()=>w(this,null,function*(){return yield this.check("blockheight")})),yield this.checkAndUpdate(this.ethNeeds.nonceLastChecked,xt,e,()=>w(this,null,function*(){return yield this.check("nonce")}));const{currencyCode:t}=this.ethEngine.currencyInfo,s=this.ethEngine.enabledTokens;s.includes(t)||s.push(t);for(const r of s)yield this.checkAndUpdate(this.ethNeeds.tokenBalLastChecked[r],Bt,e,()=>w(this,null,function*(){return yield this.check("tokenBal",r)})),yield this.checkAndUpdate(this.ethNeeds.tokenTxsLastChecked[r],Nt,e,()=>w(this,null,function*(){return yield this.check("txs",{startBlock:this.getQueryHeightWithLookback(this.ethEngine.walletLocalData.lastTransactionQueryHeight[r]),startDate:this.getQueryDateWithLookback(this.ethEngine.walletLocalData.lastTransactionDate[r]),currencyCode:r})}));yield(0,p.HB)(1e3)}})}processEthereumNetworkUpdate(e,t,s){if(!!t){if(t.blockHeight){this.ethEngine.log(`${this.ethEngine.currencyInfo.currencyCode} processEthereumNetworkUpdate blockHeight ${t.server||"no server"} won`);const r=t.blockHeight;this.ethEngine.log(`Got block height ${r||"no blockheight"}`),typeof r=="number"&&this.ethEngine.walletLocalData.blockHeight!==r&&(this.ethNeeds.blockHeightLastChecked=e,this.ethEngine.checkDroppedTransactionsThrottled(),this.ethEngine.walletLocalData.blockHeight=r,this.ethEngine.walletLocalDataDirty=!0,this.ethEngine.currencyEngineCallbacks.onBlockHeightChanged(this.ethEngine.walletLocalData.blockHeight))}if(t.newNonce&&(this.ethEngine.log(`${this.ethEngine.currencyInfo.currencyCode} processEthereumNetworkUpdate nonce ${t.server||"no server"} won`),this.ethNeeds.nonceLastChecked=e,this.ethEngine.otherData.nextNonce=t.newNonce,this.ethEngine.walletLocalDataDirty=!0),t.tokenBal!=null){const r=t.tokenBal;this.ethEngine.log(`${this.ethEngine.currencyInfo.currencyCode} processEthereumNetworkUpdate tokenBal ${t.server||"no server"} won`);for(const i of Object.keys(r))this.ethNeeds.tokenBalLastChecked[i]=e,this.ethEngine.updateBalance(i,r[i])}if(t.tokenTxs!=null){const r=t.tokenTxs;this.ethEngine.log(`${this.ethEngine.currencyInfo.currencyCode} processEthereumNetworkUpdate tokenTxs ${t.server||"no server"} won`);for(const i of Object.keys(r)){this.ethNeeds.tokenTxsLastChecked[i]=e,this.ethEngine.tokenCheckTransactionsStatus[i]=1;const u=r[i];if(u.edgeTransactions){for(const a of u.edgeTransactions)this.ethEngine.addTransaction(i,a);this.ethEngine.walletLocalData.lastTransactionQueryHeight[i]=s,this.ethEngine.walletLocalData.lastTransactionDate[i]=e}}this.ethEngine.updateOnAddressesChecked()}this.ethEngine.transactionsChangedArray.length>0&&(this.ethEngine.currencyEngineCallbacks.onTransactionsChanged(this.ethEngine.transactionsChangedArray),this.ethEngine.transactionsChangedArray=[])}}buildQueryFuncs(e){const{rpcServers:t,evmScanApiServers:s,blockbookServers:r,blockchairApiServers:i,amberdataRpcServers:u,amberdataApiServers:a}=e,h=[],o=[],l=[],c=[];return s.length>0&&(h.push(this.checkBlockHeightEthscan),o.push(this.checkNonceEthscan),c.push(this.checkTokenBalEthscan)),l.push(this.checkTxsEthscan),r.length>0&&(h.push(this.checkBlockHeightBlockbook),c.push(this.checkAddressBlockbook),o.push(this.checkAddressBlockbook)),i.length>0&&(h.push(this.checkBlockHeightBlockchair),c.push(this.checkTokenBalBlockchair)),u.length>0&&(h.push(this.checkBlockHeightAmberdata),o.push(this.checkNonceAmberdata)),a.length>0,t.length>0&&(o.push(this.checkNonceRpc),c.push(this.checkTokenBalRpc)),{blockheight:h,nonce:o,txs:l,tokenBal:c}}throwError(e,t,s){switch(e.status){case 402:case 429:case 432:throw new Error("rateLimited");default:throw new Error(`${t} The server returned error code ${e.status} for ${s}`)}}logError(e,t){(0,p.HY)(t).includes("rateLimited")?this.ethEngine.log(e,t):this.ethEngine.error(e,t)}}const _t="low",Dt="standard",Xt="high",Ke="custom",He="1000000000";function Ge(m,e,t,s){var r,i,u,a,h,o,l,c,d;let f=!0,y,k;const{customNetworkFee:b}=m!=null?m:{};if(m.networkFeeOption===Ke&&b!=null){const{gasLimit:x,gasPrice:N}=b;if((isNaN(x)||x==="")&&(isNaN(N)||N==="")){const $=new Error("Custom Fee must have at least gasLimit or gasPrice specified");throw $.name="ErrorBelowMinimumFee",$}if(N!=null&&N!==""){const $=(a=(i=(r=e.default)==null?void 0:r.gasPrice)==null?void 0:i.minGasPrice)!=null?a:(u=s.defaultNetworkFees.default.gasPrice)==null?void 0:u.minGasPrice;if($!=null){const G=(0,g.mul)(N,He);if((0,g.lt)(G,$)||/^\s*$/.test(N)){const ve=new Error(`Gas price ${G} wei below minimum ${$} wei`);throw ve.name="ErrorBelowMinimumFee",ve}}k=(0,g.mul)(N,He)}if(x!=null&&x!==""){const $=(c=(o=(h=e.default)==null?void 0:h.gasLimit)==null?void 0:o.minGasLimit)!=null?c:(l=s.defaultNetworkFees.default.gasLimit)==null?void 0:l.minGasLimit;if($!=null&&(0,g.lt)(x,$)||/^\s*$/.test(x)){const G=new Error(`Gas limit ${x} below minimum ${$}`);throw G.name="ErrorBelowMinimumFee",G}y=x,f=!1}}if(y!=null&&k!=null)return{gasLimit:y,gasPrice:k,useEstimatedGasLimit:!1};let v=e.default,E=e.default;if(typeof((d=m.spendTargets[0])==null?void 0:d.publicAddress)=="string"){const x=(0,p.f0)(m.spendTargets[0].publicAddress);typeof e[x]<"u"&&(E=e[x],f=!1,typeof E.gasPrice<"u"&&(v=E))}let C="regularTransaction";m.currencyCode!=null&&m.currencyCode!==t.currencyCode&&(C="tokenTransaction");let I="standard";typeof m.networkFeeOption=="string"&&m.networkFeeOption!==Ke&&(I=m.networkFeeOption);const _=E.gasLimit!=null?E.gasLimit[C]:"21000";let X="";if(m.spendTargets[0].nativeAmount==null)throw new Error("ErrorInvalidNativeAmount");let H=m.spendTargets[0].nativeAmount;if(C==="tokenTransaction"&&(H=(0,g.div)(H,"10")),v.gasPrice==null)throw new Error("ErrorInvalidGasPrice");const L=v.gasPrice;switch(I){case _t:X=L.lowFee;break;case Dt:{if((0,g.gte)(H,v.gasPrice.standardFeeHighAmount)){X=L.standardFeeHigh;break}if((0,g.lte)(H,L.standardFeeLowAmount)){if(v.gasPrice==null)throw new Error("ErrorInvalidGasPrice");X=v.gasPrice.standardFeeLow;break}const x=(0,g.sub)(L.standardFeeHighAmount,L.standardFeeLowAmount),N=(0,g.sub)(L.standardFeeHigh,L.standardFeeLow),$=(0,g.sub)(H,L.standardFeeLowAmount),G=(0,g.mul)($,N),ve=(0,g.div)(G,x);X=(0,g.add)(L.standardFeeLow,ve);break}case Xt:X=v.gasPrice.highFee;break;default:throw new Error("Invalid networkFeeOption")}return{gasLimit:y!=null?y:_,gasPrice:k!=null?k:X,useEstimatedGasLimit:f}}const Kt="1040",je=m=>{const{chainParams:e,data:t,dynamicOverhead:s,fixedOverhead:r,gasPriceL1Wei:i,gasLimit:u,nonce:a,to:h,value:o="0x0"}=m,l=Oe().custom(e),f=xe.Transaction.fromTxData({nonce:a!=null?(0,p.X0)(a):void 0,gasPrice:(0,p.X0)(i),gasLimit:(0,p.X0)(u),to:h,value:o,data:t},{common:l}).raw().map(E=>E.toString("hex")).join().match(/(.{1,2})/g);if(f==null)throw new Error("Invalid rawTx string");let y=0;for(let E=0;E<f.length;E++)f[E]==="00"?y+=4:y+=16;const k=(0,g.add)((0,g.add)(y.toString(),r),Kt),b=(0,g.div)(s,"1000000",18);return(0,g.mul)((0,g.mul)(i,k),b)};var V=P(48764).Buffer,Ht=Object.defineProperty,Gt=Object.defineProperties,jt=Object.getOwnPropertyDescriptors,Me=Object.getOwnPropertySymbols,Mt=Object.getPrototypeOf,Ut=Object.prototype.hasOwnProperty,Jt=Object.prototype.propertyIsEnumerable,Zt=Reflect.get,Ue=(m,e,t)=>e in m?Ht(m,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):m[e]=t,re=(m,e)=>{for(var t in e||(e={}))Ut.call(e,t)&&Ue(m,t,e[t]);if(Me)for(var t of Me(e))Jt.call(e,t)&&Ue(m,t,e[t]);return m},fe=(m,e)=>Gt(m,jt(e)),Ae=(m,e,t)=>Zt(Mt(m),t,e),R=(m,e,t)=>new Promise((s,r)=>{var i=h=>{try{a(t.next(h))}catch(o){r(o)}},u=h=>{try{a(t.throw(h))}catch(o){r(o)}},a=h=>h.done?s(h.value):Promise.resolve(h.value).then(i,u);a((t=t.apply(m,e)).next())});class me extends ct.P{constructor(e,t,s,r,i,u){super(e,t,s,i),this.updateNetworkFeesFromBaseFeePerGas=()=>R(this,null,function*(){var o;const{supportsEIP1559:l=!1}=this.networkInfo;if(!l)return;const{baseFeePerGas:c}=yield this.ethNetwork.getBaseFeePerGas();if(c==null)return;const d=(0,p.Z8)(c),f=this.networkFees;if(f.default==null||f.default.gasPrice==null)return;const y=this.networkInfo.defaultNetworkFees.default,k=f.default.minPriorityFee||y.minPriorityFee,b=(o=f.default.baseFeeMultiplier)!=null?o:y.baseFeeMultiplier;if(k==null||b==null)return;const v={lowFee:"",standardFeeLow:"",standardFeeHigh:"",highFee:""};for(const E of Object.keys(b)){const C=(0,g.mul)(b[E],d),I=(0,g.add)(C,k);v[E]=(0,g.div)(I,"1")}return this.log(`updateNetworkFeesFromBaseFeePerGas ${this.currencyInfo.currencyCode}`),Ee(this.log,v),v}),this.initOptions=r,this.networkInfo=e.networkInfo,this.ethNetwork=new Rt(this),this.lastEstimatedGasLimit={publicAddress:"",contractAddress:"",gasLimit:""},this.networkInfo.l1RollupParams!=null&&(this.l1RollupParams=this.networkInfo.l1RollupParams),this.networkFees=this.networkInfo.defaultNetworkFees,this.fetchCors=(0,p.zR)(e.io);const{infoFeeProvider:a,externalFeeProviders:h}=wt(this.fetchCors,this.currencyInfo,this.initOptions,this.log,this.networkInfo);this.infoFeeProvider=a,this.externalFeeProviders=[...h,this.updateNetworkFeesFromBaseFeePerGas],this.utils={signMessage:(o,l)=>{if(!(0,p.vq)(o))throw new Error("ErrorInvalidMessage");const c=V.from(l.privateKey,"hex"),d=(0,p.ah)(o),f=A().hashPersonalMessage(d),{v:y,r:k,s:b}=A().ecsign(f,c);return A().toRpcSig(y,k,b)},signTypedData:(o,l)=>{const c=kt(o),d=V.from(l.privateKey,"hex"),{types:f}=c;function y(L,K=[]){if(K.includes(L)||f[L]===void 0)return K;K.push(L);for(const x of f[L])for(const N of y(x.type,K))K.includes(N)||K.push(N);return K}function k(L){let K=y(L);K=K.filter(N=>N!==L),K=[L].concat(K.sort());let x="";for(const N of K)x+=`${N}(${f[N].map(({name:$,type:G})=>`${G} ${$}`).join(",")})`;return x}function b(L){return A().keccak256(k(L))}function v(L,K){const x=[],N=[];x.push("bytes32"),N.push(b(L));for(const $ of f[L]){let G=K[$.name];if($.type==="string"||$.type==="bytes")x.push("bytes32"),G=A().keccak256(G),N.push(G);else if(f[$.type]!==void 0)x.push("bytes32"),G=A().keccak256(v($.type,G)),N.push(G);else{if($.type.lastIndexOf("]")===$.type.length-1)throw new Error("Arrays currently unimplemented in encodeData");x.push($.type),N.push(G)}}return Pe().rawEncode(x,N)}function E(L,K){return A().keccak256(v(L,K))}function C(){return A().keccak256(V.concat([V.from("1901","hex"),E("EIP712Domain",c.domain),E(c.primaryType,c.message)]))}const I=A().ecsign(C(),d),{v:_,r:X,s:H}=I;return A().bufferToHex(V.concat([A().setLengthLeft(X,32),A().setLengthLeft(H,32),A().toBuffer(_)]))},txRpcParamsToSpendInfo:o=>{const l={otherParams:o};o.to!=null&&(l.publicAddress=o.to),o.value!=null?l.nativeAmount=(0,p.Z8)(o.value):l.nativeAmount="0";let c,d,f;return o.gas!=null&&(d=(0,p.Z8)(o.gas),c="custom"),o.gasPrice!=null&&(f=(0,g.div)((0,p.Z8)(o.gasPrice),se.toString(),18),c="custom"),{currencyCode:this.currencyInfo.currencyCode,spendTargets:[l],networkFeeOption:c,customNetworkFee:{gasLimit:d,gasPrice:f},otherParams:o}}},this.otherMethods={parseWalletConnectV2Payload:o=>R(this,null,function*(){var l,c;try{let d="0",f="0";switch(o.method){case"eth_sendTransaction":case"eth_signTransaction":{const y=(0,n.su)({from:n.XC,to:(0,n.Zz)(n.XC),data:n.XC,gas:(0,n.Zz)(n.XC),gasPrice:(0,n.Zz)(n.XC),value:(0,n.Zz)(n.XC)})(o.params[0]),{gas:k,gasPrice:b,value:v}=y,E=C=>{var I,_;k==null?y.gas=(0,p.X0)(C):C=(0,p.Z8)(k);let X=(_=(I=this.networkFees.default.gasPrice)==null?void 0:I.standardFeeHigh)!=null?_:"0";b==null?y.gasPrice=(0,p.X0)(X):X=(0,p.Z8)(b),f=(0,g.mul)(C,X)};v!=null&&(d=(0,p.Z8)(v)),((l=this.networkFees.default.gasLimit)==null?void 0:l.tokenTransaction)==null?this.ethNetwork.multicastServers("eth_estimateGas",y).then(C=>{const I=(0,g.add)(parseInt(C.result.result,16).toString(),"0");E(I)}).catch(C=>{this.warn("Wallet connect call_request failed to get gas limit",C)}):E((c=this.networkFees.default.gasLimit)==null?void 0:c.tokenTransaction);break}}return{nativeAmount:d,networkFee:f}}catch(d){throw this.warn("Wallet connect call_request ",d),d}}),txRpcParamsToSpendInfo:o=>R(this,null,function*(){return this.utils.txRpcParamsToSpendInfo(o)})}}estimateGasLimit(e){return R(this,null,function*(){var t,s;const{contractAddress:r,estimateGasParams:i,miningFees:u,publicAddress:a}=e,h=i[0].data!=null;if(this.lastEstimatedGasLimit.gasLimit!==""&&this.lastEstimatedGasLimit.publicAddress===a&&this.lastEstimatedGasLimit.contractAddress===r)return this.lastEstimatedGasLimit.gasLimit;let o=u.gasLimit;try{const c=(yield this.ethNetwork.multicastServers("eth_getCode",[i[0].to,"latest"])).result.result!=="0x",d=(f=0)=>R(this,null,function*(){const y=this.networkInfo.defaultNetworkFees.default.gasLimit;try{if(y!=null&&!c&&!h)o=y.regularTransaction;else{const k=yield this.ethNetwork.multicastServers("eth_estimateGas",i);o=(0,g.add)(parseInt(k.result.result,16).toString(),"0"),c&&(o=(0,g.mul)(o,"2"))}this.lastEstimatedGasLimit={publicAddress:a,contractAddress:r,gasLimit:o}}catch{if(y==null){if(f>5)throw new Error("Unable to estimate gas limit after 5 tries. Please try again later");return yield d(f+1)}if(h)throw new Error("Unable to estimate gas limit. Please try again later");y.tokenTransaction!=null&&(o=y.tokenTransaction)}});if(yield d(),(0,g.lt)(o,(s=(t=this.networkFees.default.gasLimit)==null?void 0:t.minGasLimit)!=null?s:"21000"))throw o=u.gasLimit,this.lastEstimatedGasLimit.gasLimit="",new Error("Calculated gasLimit less than minimum")}catch(l){this.error("makeSpend Error determining gas limit ",l)}return o})}setOtherData(e){this.otherData=pe(e)}updateNetworkFees(){return R(this,null,function*(){for(const e of this.externalFeeProviders)try{const t=yield e();if(t==null)continue;const s={};Object.keys(t).forEach(r=>{const i=r;s[i]=(0,p.Y7)(t[i])}),this.networkFees.default.gasPrice!=null&&(this.networkFees.default.gasPrice=re(re({},this.networkFees.default.gasPrice),s));break}catch(t){this.error(`Error fetching fees from ${e.name}. ${JSON.stringify(t)}`)}})}updateL1RollupParams(){return R(this,null,function*(){if(this.l1RollupParams!=null){try{const e={to:this.l1RollupParams.oracleContractAddress,data:this.l1RollupParams.gasPricel1BaseFeeMethod},t=yield this.ethNetwork.multicastServers("eth_call",e),s=Y(t.result);this.l1RollupParams=fe(re({},this.l1RollupParams),{gasPriceL1Wei:(0,g.ceil)((0,g.mul)((0,p.Z8)(s.result),this.l1RollupParams.maxGasPriceL1Multiplier),0)})}catch(e){this.log.warn("Failed to update l1GasPrice",e)}try{const e={to:this.l1RollupParams.oracleContractAddress,data:this.l1RollupParams.dynamicOverheadMethod},t=yield this.ethNetwork.multicastServers("eth_call",e),s=Y(t.result);this.l1RollupParams=fe(re({},this.l1RollupParams),{dynamicOverhead:(0,p.Z8)(s.result)})}catch(e){this.log.warn("Failed to update dynamicOverhead",e)}}})}clearBlockchainCache(){return R(this,null,function*(){yield Ae(me.prototype,this,"clearBlockchainCache").call(this),this.otherData.nextNonce="0",this.otherData.unconfirmedNextNonce="0"})}startEngine(){return R(this,null,function*(){var e;this.engineOn=!0;const t=(e=this.networkInfo.feeUpdateFrequencyMs)!=null?e:ht;this.infoFeeProvider().then(s=>{this.log.warn("infoFeeProvider:",JSON.stringify(s,null,2)),this.networkFees=(0,p.nu)(this.networkFees,s)}).catch(()=>this.warn("Error fetching fees from Info Server")).finally(()=>R(this,null,function*(){return yield this.addToLoop("updateNetworkFees",t)})),this.addToLoop("updateL1RollupParams",ut).catch(()=>{}),this.ethNetwork.needsLoop(),Ae(me.prototype,this,"startEngine").call(this)})}resyncBlockchain(){return R(this,null,function*(){yield this.killEngine(),yield this.clearBlockchainCache(),yield this.startEngine()})}getFreshAddress(){return R(this,null,function*(){const{publicKey:e}=this.walletLocalData;return{publicAddress:/[A-F]/.test(e)?e:A().toChecksumAddress(e.replace("0x",""))}})}getMaxSpendable(e){return R(this,null,function*(){const{edgeSpendInfo:t,currencyCode:s}=this.makeSpendCheck(e),r=this.getBalance({currencyCode:e.currencyCode}),u=e.spendTargets[0].publicAddress;if(u==null)throw new Error("makeSpend Missing publicAddress");const{contractAddress:a,data:h,value:o}=this.getTxParameterInformation(t,s,this.currencyInfo);if(e.currencyCode===this.currencyInfo.currencyCode){const l=(c,d)=>R(this,null,function*(){const f=(0,g.sub)(d,c);if((0,g.lte)(f,"1"))return c;const y=(0,g.add)(c,(0,g.div)(f,"2"));e.spendTargets[0].nativeAmount=y;const k=Ge(e,this.networkFees,this.currencyInfo,this.networkInfo);k.useEstimatedGasLimit&&(k.gasLimit=yield this.estimateGasLimit({contractAddress:a,estimateGasParams:[{to:a!=null?a:u,from:this.walletLocalData.publicKey,gas:"0xffffff",value:o,data:h},"latest"],miningFees:k,publicAddress:u}));const b=(0,g.mul)(k.gasPrice,k.gasLimit);let v="0";if(this.l1RollupParams!=null){const C={nonce:this.otherData.unconfirmedNextNonce,gasPriceL1Wei:this.l1RollupParams.gasPriceL1Wei,gasLimit:k.gasLimit,to:u,value:(0,p.X0)(y),chainParams:this.networkInfo.chainParams,dynamicOverhead:this.l1RollupParams.dynamicOverhead,fixedOverhead:this.l1RollupParams.fixedOverhead};v=je(C)}const E=(0,g.add)((0,g.add)(y,b),v);return(0,g.gt)(E,r)?yield l(c,y):yield l(y,d)});return yield l("0",(0,g.add)(r,"1"))}else return e.spendTargets[0].nativeAmount=r,yield this.makeSpend(e),this.getBalance({currencyCode:e.currencyCode})})}getTxParameterInformation(e,t,s){var r,i;const{spendTargets:u}=e,a=u[0],{publicAddress:h,nativeAmount:o}=a;let l=(i=a.memo)!=null?i:(r=a.otherParams)==null?void 0:r.data;if(l!=null&&l.length>0&&!(0,p.vq)(l))throw new Error("Memo/data field must be of type 'hex'");l===""&&(l=void 0);let c;if(t===s.currencyCode)return c=o==null?void 0:(0,p.X0)(o),{data:l,value:c};{let d;if(l!=null)d=h;else{const f=this.getTokenInfo(t);if(f==null||typeof f.contractAddress!="string")throw new Error("Error: Token not supported or invalid contract address");d=f.contractAddress;const y=Pe().simpleEncode("transfer(address,uint256):(uint256)",h,(0,p.X0)(o!=null?o:"0"));c="0x0",l="0x"+V.from(y).toString("hex")}return{contractAddress:d,data:l,value:c}}}makeSpend(e){return R(this,null,function*(){var t,s;const{edgeSpendInfo:r,currencyCode:i,skipChecks:u}=this.makeSpendCheck(e),{pendingTxs:a=[]}=r;if(r.spendTargets.length!==1)throw new Error("Error: only one output allowed");const h=r.spendTargets[0],{publicAddress:o}=h;let{nativeAmount:l}=h;if(o==null)throw new Error("makeSpend Missing publicAddress");if(l==null)throw new ne.$D;if(!A().isValidAddress(o))throw new TypeError(`Invalid ${this.currencyInfo.pluginId} address`);let c;const d=Ge(r,this.networkFees,this.currencyInfo,this.networkInfo);let f;if(a.length>0){const H=this.walletLocalData.otherData,L=this.walletLocalData.numUnconfirmedSpendTxs>0?H.unconfirmedNextNonce:H.nextNonce;f=(0,g.add)(L,a.length.toString())}const{contractAddress:y,data:k,value:b}=this.getTxParameterInformation(r,i,this.currencyInfo);y==null?c={from:[this.walletLocalData.publicKey],to:[o],gas:d.gasLimit,gasPrice:d.gasPrice,gasUsed:"0",nonceUsed:f,data:k,isFromMakeSpend:!0}:c={from:[this.walletLocalData.publicKey],to:[y],gas:d.gasLimit,gasPrice:d.gasPrice,gasUsed:"0",tokenRecipientAddress:o,nonceUsed:f,data:k,isFromMakeSpend:!0},d.useEstimatedGasLimit&&(c.gas=yield this.estimateGasLimit({contractAddress:y,estimateGasParams:[{to:y!=null?y:o,from:this.walletLocalData.publicKey,gas:"0xffffff",value:b,data:k},"latest"],miningFees:d,publicAddress:o}));const v=(t=this.walletLocalData.totalBalances[this.currencyInfo.currencyCode])!=null?t:"0";let E=(0,g.mul)(d.gasPrice,c.gas),C="0",I=null,_="0";if(this.l1RollupParams!=null){const H={nonce:c.nonceUsed,gasPriceL1Wei:this.l1RollupParams.gasPriceL1Wei,gasLimit:c.gas,to:c.to[0],value:b,data:c.data,chainParams:this.networkInfo.chainParams,dynamicOverhead:this.l1RollupParams.dynamicOverhead,fixedOverhead:this.l1RollupParams.fixedOverhead};_=je(H)}if(i===this.currencyInfo.currencyCode){if(E=(0,g.add)(E,_),C=(0,g.add)(E,l),!u&&(0,g.gt)(C,v))throw new ne.C_;l=(0,g.mul)(C,"-1")}else{if(I=(0,g.add)(E,_),!u&&(0,g.gt)(E,v))throw new ne.C_({currencyCode:this.currencyInfo.currencyCode,networkFee:E});const H=(s=this.walletLocalData.totalBalances[i])!=null?s:"0";if(!u&&(0,g.gt)(l,H))throw new ne.C_;E="0",l=(0,g.mul)(l,"-1")}const X={txid:"",date:0,currencyCode:i,blockHeight:0,nativeAmount:l,isSend:l.startsWith("-"),networkFee:E,feeRateUsed:Te(d.gasPrice,c.gas),ourReceiveAddresses:[],signedTx:"",otherParams:c,walletId:this.walletId};return I&&(X.parentNetworkFee=I),X})}signMessage(e,t,s){return R(this,null,function*(){const r=Ce(this.currencyInfo.pluginId)(t);if(nt(s.otherParams).typedData){const u=JSON.parse(e);try{return this.utils.signTypedData(u,r)}catch{return(0,rt.signTypedData_v4)(V.from(r.privateKey,"hex"),{data:u})}}return this.utils.signMessage(e,r)})}signTx(e,t){return R(this,null,function*(){const s=Ce(this.currencyInfo.pluginId)(t),r=(0,p.Xp)(e),i=(0,p.NC)(r.gas),u=(0,p.NC)(r.gasPrice);let a;if(e.currencyCode===this.currencyInfo.currencyCode){const E=(0,g.add)(e.nativeAmount,e.networkFee);a=(0,g.mul)("-1",E,16)}else a=(0,g.mul)("-1",e.nativeAmount,16);(0,g.lt)(a,"0")&&(a="0x00");let h=r.nonceUsed;if(!h)if(this.walletLocalData.numUnconfirmedSpendTxs&&(0,g.gt)(this.otherData.unconfirmedNextNonce,this.otherData.nextNonce)){const E=(0,g.sub)(this.otherData.unconfirmedNextNonce,this.otherData.nextNonce);if((0,g.lte)(E,"5"))h=this.otherData.unconfirmedNextNonce,this.walletLocalDataDirty=!0;else{const C=new Error("Excessive pending spend transactions");throw C.name="ErrorExcessivePendingSpends",C}}else h=this.otherData.nextNonce;const o=(0,p.NC)(h);let l;if(r.data!=null)l=r.data,e.currencyCode!==this.currencyInfo.currencyCode&&(a="0x00");else if(e.currencyCode===this.currencyInfo.currencyCode)l="";else{const E=Pe().simpleEncode("transfer(address,uint256):(uint256)",r.tokenRecipientAddress,a);l="0x"+V.from(E).toString("hex"),a="0x00"}const{chainParams:c}=this.networkInfo,d=Oe().custom(c),f={nonce:o,gasPrice:u,gasLimit:i,to:r.to[0],value:a,data:l},y=V.from(s.privateKey,"hex"),k=at().fromPrivateKey(y);this.warn(`signTx getAddressString ${k.getAddressString()}`);const v=xe.Transaction.fromTxData(f,{common:d}).sign(y);return e.signedTx=(0,p.$9)(v.serialize()),e.txid=(0,p.$9)(v.hash()),e.date=Date.now()/1e3,e.otherParams!=null&&(e.otherParams.nonceUsed=h),this.warn(`signTx
8
+ ${JSON.stringify(f[y])}`),new Error(`getAllTxsEthscan ${s.name} is invalid`)}if(f.length===0)break;h++}return{allTransactions:c,server:l}})}checkTxsEthscan(e){return w(this,null,function*(){const{startBlock:t,currencyCode:s}=e;let r,i;if(s===this.ethEngine.currencyInfo.currencyCode){const c=yield this.getAllTxsEthscan(t,s,W,{searchRegularTxs:!0}),l=yield this.getAllTxsEthscan(t,s,ge,{searchRegularTxs:!1});r=c.server||l.server,i=[...c.allTransactions,...l.allTransactions]}else{const c=this.ethEngine.getTokenInfo(s);if(c!=null&&typeof c.contractAddress=="string"){const l=c.contractAddress,o=yield this.getAllTxsEthscan(t,s,Ie,{contractAddress:l});r=o.server,i=o.allTransactions}else return{}}const h={blockHeight:t,edgeTransactions:i};return{tokenTxs:{[s]:h},server:r}})}getTokenCurrencyCode(e){const t=this.ethEngine.walletLocalData.publicKey;if(e.toLowerCase()===t.toLowerCase())return this.ethEngine.currencyInfo.currencyCode;for(const s of this.ethEngine.enabledTokens){const r=this.ethEngine.getTokenInfo(s);if(r!=null){const i=r.contractAddress;if(e&&typeof i=="string"&&i.toLowerCase()===e.toLowerCase())return s}}}checkAddressBlockbook(e){return w(this,null,function*(){const t=this.ethEngine.walletLocalData.publicKey.toLowerCase(),s={newNonce:"0",tokenBal:{},server:""},r="/api/v2/address/"+t+"?&details=tokenBalances",{result:i,server:h}=yield this.multicastServers("blockbookAddress",r);let c;try{c=Ye(i)}catch{throw this.ethEngine.error(`checkTxsBlockbook ${h} error BlockbookAddress ${JSON.stringify(i)}`),new Error(`checkTxsBlockbook ${h} returned invalid JSON for BlockbookAddress`)}const{nonce:l,tokens:o,balance:d}=c;s.newNonce=l,s.tokenBal!=null&&(s.tokenBal[this.ethEngine.currencyInfo.currencyCode]=d),s.server=h;for(const a of o)try{const{symbol:u,balance:f}=Le(a);s.tokenBal[u]=f}catch{throw this.ethEngine.error(`checkTxsBlockbook ${h} BlockbookTokenBalance ${JSON.stringify(a)}`),new Error(`checkTxsBlockbook ${h} returned invalid JSON for BlockbookTokenBalance`)}return s})}checkTokenBalEthscan(e){return w(this,null,function*(){const t=this.ethEngine.walletLocalData.publicKey;let s,r,i,h;try{if(e===this.ethEngine.currencyInfo.currencyCode)s=yield this.multicastServers("eth_getBalance",t),r=s.result,i=s.server;else{const c=this.ethEngine.getTokenInfo(e);if(c!=null&&typeof c.contractAddress=="string"){const l=c.contractAddress,o=yield this.multicastServers("getTokenBalance",t,l);r=o.result,i=o.server}}h=Y(r)}catch(c){throw this.ethEngine.error(`checkTokenBalEthscan token ${e} response ${s||""} `,c),new Error(`checkTokenBalEthscan invalid ${e} response ${JSON.stringify(r)}`)}if(/^\d+$/.test(h.result)){const c=h.result;return{tokenBal:{[e]:c},server:i}}else throw new Error(`checkTokenBalEthscan returned invalid JSON for ${e}`)})}checkTokenBalBlockchair(){return w(this,null,function*(){let e;const t=this.ethEngine.walletLocalData.publicKey,s=`/${this.ethEngine.currencyInfo.pluginId}/dashboards/address/${t}?erc_20=true`;try{const i=yield this.fetchGetBlockchair(s,!1);e=et(i)}catch(i){throw this.logError("checkTokenBalBlockchair",i),new Error("checkTokenBalBlockchair response is invalid")}const r={[this.ethEngine.currencyInfo.currencyCode]:e.data[t].address.balance};for(const i of e.data[t].layer_2.erc_20)try{const h=qe(i),c=h.balance,l=h.token_address,o=h.token_symbol,d=this.ethEngine.getTokenInfo(o);d!=null&&d.contractAddress===l&&(r[o]=c)}catch(h){throw this.ethEngine.error(`checkTokenBalBlockchair tokenData ${(0,p.HY)(h)}
9
+ ${JSON.stringify(i)}`),new Error("checkTokenBalBlockchair tokenData is invalid")}return{tokenBal:r,server:"blockchair"}})}checkTokenBalRpc(e){return w(this,null,function*(){let t,s,r,i;const h=this.ethEngine.walletLocalData.publicKey;try{if(e===this.ethEngine.currencyInfo.currencyCode)s=yield this.multicastServers("eth_getBalance",h),r=s.result,i=s.server;else{const c=this.ethEngine.getTokenInfo(e);if(c!=null&&typeof c.contractAddress=="string"){const l={data:`0x70a08231${(0,p.gc)((0,p.KT)(h),32)}`,to:c.contractAddress},o=yield this.multicastServers("eth_call",l),d=o.result.result;if(!d.startsWith("0x"))throw new Error("Invalid return value. Result not hex");o.result.result=(0,p.Z8)(d),r=o.result,i=o.server}}t=Y(r)}catch(c){throw this.ethEngine.error(`checkTokenBalRpc token ${e} response ${s||""} `,c),new Error(`checkTokenBalRpc invalid ${e} response ${JSON.stringify(r)}`)}return{tokenBal:{[e]:t.result},server:i}})}checkAndUpdate(e=0,t,s,r){return w(this,null,function*(){const i=Date.now();if(i-e>t)try{const h=yield r();this.processEthereumNetworkUpdate(i,h,s)}catch(h){this.ethEngine.error("checkAndUpdate ",h)}})}getQueryHeightWithLookback(e){return e>Xe?e-Xe:0}getQueryDateWithLookback(e){return e>Ke?e-Ke:0}needsLoop(){return w(this,null,function*(){for(;this.ethEngine.engineOn;){const e=this.ethEngine.walletLocalData.blockHeight;yield this.checkAndUpdate(this.ethNeeds.blockHeightLastChecked,xt,e,()=>w(this,null,function*(){return yield this.check("blockheight")})),yield this.checkAndUpdate(this.ethNeeds.nonceLastChecked,Bt,e,()=>w(this,null,function*(){return yield this.check("nonce")}));const{currencyCode:t}=this.ethEngine.currencyInfo,s=this.ethEngine.enabledTokens;s.includes(t)||s.push(t);for(const r of s)yield this.checkAndUpdate(this.ethNeeds.tokenBalLastChecked[r],Nt,e,()=>w(this,null,function*(){return yield this.check("tokenBal",r)})),yield this.checkAndUpdate(this.ethNeeds.tokenTxsLastChecked[r],$t,e,()=>w(this,null,function*(){return yield this.check("txs",{startBlock:this.getQueryHeightWithLookback(this.ethEngine.walletLocalData.lastTransactionQueryHeight[r]),startDate:this.getQueryDateWithLookback(this.ethEngine.walletLocalData.lastTransactionDate[r]),currencyCode:r})}));yield(0,p.HB)(1e3)}})}processEthereumNetworkUpdate(e,t,s){if(!!t){if(t.blockHeight){this.ethEngine.log(`${this.ethEngine.currencyInfo.currencyCode} processEthereumNetworkUpdate blockHeight ${t.server||"no server"} won`);const r=t.blockHeight;this.ethEngine.log(`Got block height ${r||"no blockheight"}`),typeof r=="number"&&this.ethEngine.walletLocalData.blockHeight!==r&&(this.ethNeeds.blockHeightLastChecked=e,this.ethEngine.checkDroppedTransactionsThrottled(),this.ethEngine.walletLocalData.blockHeight=r,this.ethEngine.walletLocalDataDirty=!0,this.ethEngine.currencyEngineCallbacks.onBlockHeightChanged(this.ethEngine.walletLocalData.blockHeight))}if(t.newNonce&&(this.ethEngine.log(`${this.ethEngine.currencyInfo.currencyCode} processEthereumNetworkUpdate nonce ${t.server||"no server"} won`),this.ethNeeds.nonceLastChecked=e,this.ethEngine.otherData.nextNonce=t.newNonce,this.ethEngine.walletLocalDataDirty=!0),t.tokenBal!=null){const r=t.tokenBal;this.ethEngine.log(`${this.ethEngine.currencyInfo.currencyCode} processEthereumNetworkUpdate tokenBal ${t.server||"no server"} won`);for(const i of Object.keys(r))this.ethNeeds.tokenBalLastChecked[i]=e,this.ethEngine.updateBalance(i,r[i])}if(t.tokenTxs!=null){const r=t.tokenTxs;this.ethEngine.log(`${this.ethEngine.currencyInfo.currencyCode} processEthereumNetworkUpdate tokenTxs ${t.server||"no server"} won`);for(const i of Object.keys(r)){this.ethNeeds.tokenTxsLastChecked[i]=e,this.ethEngine.tokenCheckTransactionsStatus[i]=1;const h=r[i];if(h.edgeTransactions){for(const c of h.edgeTransactions)this.ethEngine.addTransaction(i,c);this.ethEngine.walletLocalData.lastTransactionQueryHeight[i]=s,this.ethEngine.walletLocalData.lastTransactionDate[i]=e}}this.ethEngine.updateOnAddressesChecked()}this.ethEngine.transactionsChangedArray.length>0&&(this.ethEngine.currencyEngineCallbacks.onTransactionsChanged(this.ethEngine.transactionsChangedArray),this.ethEngine.transactionsChangedArray=[])}}buildQueryFuncs(e){const{rpcServers:t,evmScanApiServers:s,blockbookServers:r,blockchairApiServers:i,amberdataRpcServers:h,amberdataApiServers:c}=e,l=[],o=[],d=[],a=[];return s.length>0&&(l.push(this.checkBlockHeightEthscan),o.push(this.checkNonceEthscan),a.push(this.checkTokenBalEthscan)),d.push(this.checkTxsEthscan),r.length>0&&(l.push(this.checkBlockHeightBlockbook),a.push(this.checkAddressBlockbook),o.push(this.checkAddressBlockbook)),i.length>0&&(l.push(this.checkBlockHeightBlockchair),a.push(this.checkTokenBalBlockchair)),h.length>0&&(l.push(this.checkBlockHeightAmberdata),o.push(this.checkNonceAmberdata)),c.length>0,t.length>0&&(o.push(this.checkNonceRpc),a.push(this.checkTokenBalRpc)),{blockheight:l,nonce:o,txs:d,tokenBal:a}}throwError(e,t,s){switch(e.status){case 402:case 429:case 432:throw new Error("rateLimited");default:throw new Error(`${t} The server returned error code ${e.status} for ${s}`)}}logError(e,t){(0,p.HY)(t).includes("rateLimited")?this.ethEngine.log(e,t):this.ethEngine.error(e,t)}}const _t="low",Xt="standard",Kt="high",He="custom",Ge="1000000000";function je(m,e,t,s){var r,i,h,c,l,o,d,a,u;let f=!0,y,k;const{customNetworkFee:C}=m!=null?m:{};if(m.networkFeeOption===He&&C!=null){const{gasLimit:x,gasPrice:N}=C;if((isNaN(x)||x==="")&&(isNaN(N)||N==="")){const $=new Error("Custom Fee must have at least gasLimit or gasPrice specified");throw $.name="ErrorBelowMinimumFee",$}if(N!=null&&N!==""){const $=(c=(i=(r=e.default)==null?void 0:r.gasPrice)==null?void 0:i.minGasPrice)!=null?c:(h=s.defaultNetworkFees.default.gasPrice)==null?void 0:h.minGasPrice;if($!=null){const H=(0,g.mul)(N,Ge);if((0,g.lt)(H,$)||/^\s*$/.test(N)){const ve=new Error(`Gas price ${H} wei below minimum ${$} wei`);throw ve.name="ErrorBelowMinimumFee",ve}}k=(0,g.mul)(N,Ge)}if(x!=null&&x!==""){const $=(a=(o=(l=e.default)==null?void 0:l.gasLimit)==null?void 0:o.minGasLimit)!=null?a:(d=s.defaultNetworkFees.default.gasLimit)==null?void 0:d.minGasLimit;if($!=null&&(0,g.lt)(x,$)||/^\s*$/.test(x)){const H=new Error(`Gas limit ${x} below minimum ${$}`);throw H.name="ErrorBelowMinimumFee",H}y=x,f=!1}}if(y!=null&&k!=null)return{gasLimit:y,gasPrice:k,useEstimatedGasLimit:!1};let v=e.default,E=e.default;if(typeof((u=m.spendTargets[0])==null?void 0:u.publicAddress)=="string"){const x=(0,p.f0)(m.spendTargets[0].publicAddress);typeof e[x]<"u"&&(E=e[x],f=!1,typeof E.gasPrice<"u"&&(v=E))}let b="regularTransaction";m.currencyCode!=null&&m.currencyCode!==t.currencyCode&&(b="tokenTransaction");let L="standard";typeof m.networkFeeOption=="string"&&m.networkFeeOption!==He&&(L=m.networkFeeOption);const D=E.gasLimit!=null?E.gasLimit[b]:"21000";let K="";if(m.spendTargets[0].nativeAmount==null)throw new Error("ErrorInvalidNativeAmount");let M=m.spendTargets[0].nativeAmount;if(b==="tokenTransaction"&&(M=(0,g.div)(M,"10")),v.gasPrice==null)throw new Error("ErrorInvalidGasPrice");const A=v.gasPrice;switch(L){case _t:K=A.lowFee;break;case Xt:{if((0,g.gte)(M,v.gasPrice.standardFeeHighAmount)){K=A.standardFeeHigh;break}if((0,g.lte)(M,A.standardFeeLowAmount)){if(v.gasPrice==null)throw new Error("ErrorInvalidGasPrice");K=v.gasPrice.standardFeeLow;break}const x=(0,g.sub)(A.standardFeeHighAmount,A.standardFeeLowAmount),N=(0,g.sub)(A.standardFeeHigh,A.standardFeeLow),$=(0,g.sub)(M,A.standardFeeLowAmount),H=(0,g.mul)($,N),ve=(0,g.div)(H,x);K=(0,g.add)(A.standardFeeLow,ve);break}case Kt:K=v.gasPrice.highFee;break;default:throw new Error("Invalid networkFeeOption")}return{gasLimit:y!=null?y:D,gasPrice:k!=null?k:K,useEstimatedGasLimit:f}}const Ht="1040",Me=m=>{const{chainParams:e,data:t,dynamicOverhead:s,fixedOverhead:r,gasPriceL1Wei:i,gasLimit:h,nonce:c,to:l,value:o="0x0"}=m,d=Oe().custom(e),f=xe.Transaction.fromTxData({nonce:c!=null?(0,p.X0)(c):void 0,gasPrice:(0,p.X0)(i),gasLimit:(0,p.X0)(h),to:l,value:o,data:t},{common:d}).raw().map(E=>E.toString("hex")).join().match(/(.{1,2})/g);if(f==null)throw new Error("Invalid rawTx string");let y=0;for(let E=0;E<f.length;E++)f[E]==="00"?y+=4:y+=16;const k=(0,g.add)((0,g.add)(y.toString(),r),Ht),C=(0,g.div)(s,"1000000",18);return(0,g.mul)((0,g.mul)(i,k),C)};var V=P(48764).Buffer,Gt=Object.defineProperty,jt=Object.defineProperties,Mt=Object.getOwnPropertyDescriptors,Ue=Object.getOwnPropertySymbols,Ut=Object.getPrototypeOf,Jt=Object.prototype.hasOwnProperty,Zt=Object.prototype.propertyIsEnumerable,Wt=Reflect.get,Je=(m,e,t)=>e in m?Gt(m,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):m[e]=t,re=(m,e)=>{for(var t in e||(e={}))Jt.call(e,t)&&Je(m,t,e[t]);if(Ue)for(var t of Ue(e))Zt.call(e,t)&&Je(m,t,e[t]);return m},fe=(m,e)=>jt(m,Mt(e)),Ae=(m,e,t)=>Wt(Ut(m),t,e),R=(m,e,t)=>new Promise((s,r)=>{var i=l=>{try{c(t.next(l))}catch(o){r(o)}},h=l=>{try{c(t.throw(l))}catch(o){r(o)}},c=l=>l.done?s(l.value):Promise.resolve(l.value).then(i,h);c((t=t.apply(m,e)).next())});class me extends lt.P{constructor(e,t,s,r,i,h){super(e,t,s,i),this.updateNetworkFeesFromBaseFeePerGas=()=>R(this,null,function*(){var o;const{supportsEIP1559:d=!1}=this.networkInfo;if(!d)return;const{baseFeePerGas:a}=yield this.ethNetwork.getBaseFeePerGas();if(a==null)return;const u=(0,p.Z8)(a),f=this.networkFees;if(f.default==null||f.default.gasPrice==null)return;const y=this.networkInfo.defaultNetworkFees.default,k=f.default.minPriorityFee||y.minPriorityFee,C=(o=f.default.baseFeeMultiplier)!=null?o:y.baseFeeMultiplier;if(k==null||C==null)return;const v={lowFee:"",standardFeeLow:"",standardFeeHigh:"",highFee:""};for(const E of Object.keys(C)){const b=(0,g.mul)(C[E],u),L=(0,g.add)(b,k);v[E]=(0,g.div)(L,"1")}return this.log(`updateNetworkFeesFromBaseFeePerGas ${this.currencyInfo.currencyCode}`),Ee(this.log,v),v}),this.initOptions=r,this.networkInfo=e.networkInfo,this.ethNetwork=new Dt(this),this.lastEstimatedGasLimit={publicAddress:"",contractAddress:"",gasLimit:""},this.networkInfo.l1RollupParams!=null&&(this.l1RollupParams=this.networkInfo.l1RollupParams),this.networkFees=this.networkInfo.defaultNetworkFees,this.fetchCors=(0,p.zR)(e.io);const{infoFeeProvider:c,externalFeeProviders:l}=vt(this.fetchCors,this.currencyInfo,this.initOptions,this.log,this.networkInfo);this.infoFeeProvider=c,this.externalFeeProviders=[...l,this.updateNetworkFeesFromBaseFeePerGas],this.utils={signMessage:(o,d)=>{if(!(0,p.vq)(o))throw new Error("ErrorInvalidMessage");const a=V.from(d.privateKey,"hex"),u=(0,p.ah)(o),f=S().hashPersonalMessage(u),{v:y,r:k,s:C}=S().ecsign(f,a);return S().toRpcSig(y,k,C)},signTypedData:(o,d)=>{const a=Et(o),u=V.from(d.privateKey,"hex"),{types:f}=a;function y(A,_=[]){if(_.includes(A)||f[A]===void 0)return _;_.push(A);for(const x of f[A])for(const N of y(x.type,_))_.includes(N)||_.push(N);return _}function k(A){let _=y(A);_=_.filter(N=>N!==A),_=[A].concat(_.sort());let x="";for(const N of _)x+=`${N}(${f[N].map(({name:$,type:H})=>`${H} ${$}`).join(",")})`;return x}function C(A){return S().keccak256(k(A))}function v(A,_){const x=[],N=[];x.push("bytes32"),N.push(C(A));for(const $ of f[A]){let H=_[$.name];if($.type==="string"||$.type==="bytes")x.push("bytes32"),H=S().keccak256(H),N.push(H);else if(f[$.type]!==void 0)x.push("bytes32"),H=S().keccak256(v($.type,H)),N.push(H);else{if($.type.lastIndexOf("]")===$.type.length-1)throw new Error("Arrays currently unimplemented in encodeData");x.push($.type),N.push(H)}}return Pe().rawEncode(x,N)}function E(A,_){return S().keccak256(v(A,_))}function b(){return S().keccak256(V.concat([V.from("1901","hex"),E("EIP712Domain",a.domain),E(a.primaryType,a.message)]))}const L=S().ecsign(b(),u),{v:D,r:K,s:M}=L;return S().bufferToHex(V.concat([S().setLengthLeft(K,32),S().setLengthLeft(M,32),S().toBuffer(D)]))},txRpcParamsToSpendInfo:o=>{const d={otherParams:o};o.to!=null&&(d.publicAddress=o.to),o.value!=null?d.nativeAmount=(0,p.Z8)(o.value):d.nativeAmount="0";let a,u,f;return o.gas!=null&&(u=(0,p.Z8)(o.gas),a="custom"),o.gasPrice!=null&&(f=(0,g.div)((0,p.Z8)(o.gasPrice),se.toString(),18),a="custom"),{currencyCode:this.currencyInfo.currencyCode,spendTargets:[d],networkFeeOption:a,customNetworkFee:{gasLimit:u,gasPrice:f},otherParams:o}}},this.otherMethods={parseWalletConnectV2Payload:o=>R(this,null,function*(){var d,a;try{let u="0",f="0";switch(o.method){case"eth_sendTransaction":case"eth_signTransaction":{const y=(0,n.su)({from:n.XC,to:(0,n.Zz)(n.XC),data:n.XC,gas:(0,n.Zz)(n.XC),gasPrice:(0,n.Zz)(n.XC),value:(0,n.Zz)(n.XC)})(o.params[0]),{gas:k,gasPrice:C,value:v}=y,E=b=>{var L,D;k==null?y.gas=(0,p.X0)(b):b=(0,p.Z8)(k);let K=(D=(L=this.networkFees.default.gasPrice)==null?void 0:L.standardFeeHigh)!=null?D:"0";C==null?y.gasPrice=(0,p.X0)(K):K=(0,p.Z8)(C),f=(0,g.mul)(b,K)};v!=null&&(u=(0,p.Z8)(v)),((d=this.networkFees.default.gasLimit)==null?void 0:d.tokenTransaction)==null?this.ethNetwork.multicastServers("eth_estimateGas",y).then(b=>{const L=(0,g.add)(parseInt(b.result.result,16).toString(),"0");E(L)}).catch(b=>{this.warn("Wallet connect call_request failed to get gas limit",b)}):E((a=this.networkFees.default.gasLimit)==null?void 0:a.tokenTransaction);break}}return{nativeAmount:u,networkFee:f}}catch(u){throw this.warn("Wallet connect call_request ",u),u}}),txRpcParamsToSpendInfo:o=>R(this,null,function*(){return this.utils.txRpcParamsToSpendInfo(o)})}}estimateGasLimit(e){return R(this,null,function*(){var t,s;const{contractAddress:r,estimateGasParams:i,miningFees:h,publicAddress:c}=e,l=i[0].data!=null;if(this.lastEstimatedGasLimit.gasLimit!==""&&this.lastEstimatedGasLimit.publicAddress===c&&this.lastEstimatedGasLimit.contractAddress===r)return this.lastEstimatedGasLimit.gasLimit;let o=h.gasLimit;try{const a=(yield this.ethNetwork.multicastServers("eth_getCode",[i[0].to,"latest"])).result.result!=="0x",u=(f=0)=>R(this,null,function*(){const y=this.networkInfo.defaultNetworkFees.default.gasLimit;try{if(y!=null&&!a&&!l)o=y.regularTransaction;else{const k=yield this.ethNetwork.multicastServers("eth_estimateGas",i);o=(0,g.add)(parseInt(k.result.result,16).toString(),"0"),a&&(o=(0,g.mul)(o,"2"))}this.lastEstimatedGasLimit={publicAddress:c,contractAddress:r,gasLimit:o}}catch{if(y==null){if(f>5)throw new Error("Unable to estimate gas limit after 5 tries. Please try again later");return yield u(f+1)}if(l)throw new Error("Unable to estimate gas limit. Please try again later");y.tokenTransaction!=null&&(o=y.tokenTransaction)}});if(yield u(),(0,g.lt)(o,(s=(t=this.networkFees.default.gasLimit)==null?void 0:t.minGasLimit)!=null?s:"21000"))throw o=h.gasLimit,this.lastEstimatedGasLimit.gasLimit="",new Error("Calculated gasLimit less than minimum")}catch(d){this.error("makeSpend Error determining gas limit ",d)}return o})}setOtherData(e){this.otherData=pe(e)}updateNetworkFees(){return R(this,null,function*(){for(const e of this.externalFeeProviders)try{const t=yield e();if(t==null)continue;const s={};Object.keys(t).forEach(r=>{const i=r;s[i]=(0,p.Y7)(t[i])}),this.networkFees.default.gasPrice!=null&&(this.networkFees.default.gasPrice=re(re({},this.networkFees.default.gasPrice),s));break}catch(t){this.error(`Error fetching fees from ${e.name}. ${JSON.stringify(t)}`)}})}updateL1RollupParams(){return R(this,null,function*(){if(this.l1RollupParams!=null){try{const e={to:this.l1RollupParams.oracleContractAddress,data:this.l1RollupParams.gasPricel1BaseFeeMethod},t=yield this.ethNetwork.multicastServers("eth_call",e),s=Y(t.result);this.l1RollupParams=fe(re({},this.l1RollupParams),{gasPriceL1Wei:(0,g.ceil)((0,g.mul)((0,p.Z8)(s.result),this.l1RollupParams.maxGasPriceL1Multiplier),0)})}catch(e){this.log.warn("Failed to update l1GasPrice",e)}try{const e={to:this.l1RollupParams.oracleContractAddress,data:this.l1RollupParams.dynamicOverheadMethod},t=yield this.ethNetwork.multicastServers("eth_call",e),s=Y(t.result);this.l1RollupParams=fe(re({},this.l1RollupParams),{dynamicOverhead:(0,p.Z8)(s.result)})}catch(e){this.log.warn("Failed to update dynamicOverhead",e)}}})}clearBlockchainCache(){return R(this,null,function*(){yield Ae(me.prototype,this,"clearBlockchainCache").call(this),this.otherData.nextNonce="0",this.otherData.unconfirmedNextNonce="0"})}startEngine(){return R(this,null,function*(){var e;this.engineOn=!0;const t=(e=this.networkInfo.feeUpdateFrequencyMs)!=null?e:ut;this.infoFeeProvider().then(s=>{this.log.warn("infoFeeProvider:",JSON.stringify(s,null,2)),this.networkFees=(0,p.nu)(this.networkFees,s)}).catch(()=>this.warn("Error fetching fees from Info Server")).finally(()=>R(this,null,function*(){return yield this.addToLoop("updateNetworkFees",t)})),this.addToLoop("updateL1RollupParams",dt).catch(()=>{}),this.ethNetwork.needsLoop(),Ae(me.prototype,this,"startEngine").call(this)})}resyncBlockchain(){return R(this,null,function*(){yield this.killEngine(),yield this.clearBlockchainCache(),yield this.startEngine()})}getFreshAddress(){return R(this,null,function*(){const{publicKey:e}=this.walletLocalData;return{publicAddress:/[A-F]/.test(e)?e:S().toChecksumAddress(e.replace("0x",""))}})}getMaxSpendable(e){return R(this,null,function*(){e=(0,Be.s)(e,this.currencyInfo);const{edgeSpendInfo:t,currencyCode:s}=this.makeSpendCheck(e),r=this.getBalance({currencyCode:e.currencyCode}),h=e.spendTargets[0].publicAddress;if(h==null)throw new Error("makeSpend Missing publicAddress");const{contractAddress:c,data:l,value:o}=this.getTxParameterInformation(t,s,this.currencyInfo);if(e.currencyCode===this.currencyInfo.currencyCode){const d=(a,u)=>R(this,null,function*(){const f=(0,g.sub)(u,a);if((0,g.lte)(f,"1"))return a;const y=(0,g.add)(a,(0,g.div)(f,"2"));e.spendTargets[0].nativeAmount=y;const k=je(e,this.networkFees,this.currencyInfo,this.networkInfo);k.useEstimatedGasLimit&&(k.gasLimit=yield this.estimateGasLimit({contractAddress:c,estimateGasParams:[{to:c!=null?c:h,from:this.walletLocalData.publicKey,gas:"0xffffff",value:o,data:l},"latest"],miningFees:k,publicAddress:h}));const C=(0,g.mul)(k.gasPrice,k.gasLimit);let v="0";if(this.l1RollupParams!=null){const b={nonce:this.otherData.unconfirmedNextNonce,gasPriceL1Wei:this.l1RollupParams.gasPriceL1Wei,gasLimit:k.gasLimit,to:h,value:(0,p.X0)(y),chainParams:this.networkInfo.chainParams,dynamicOverhead:this.l1RollupParams.dynamicOverhead,fixedOverhead:this.l1RollupParams.fixedOverhead};v=Me(b)}const E=(0,g.add)((0,g.add)(y,C),v);return(0,g.gt)(E,r)?yield d(a,y):yield d(y,u)});return yield d("0",(0,g.add)(r,"1"))}else return e.spendTargets[0].nativeAmount=r,yield this.makeSpend(e),this.getBalance({currencyCode:e.currencyCode})})}getTxParameterInformation(e,t,s){var r;const{memos:i=[]}=e,{spendTargets:h}=e,c=h[0],{publicAddress:l,nativeAmount:o}=c;let d=((r=i[0])==null?void 0:r.type)==="hex"?i[0].value:void 0,a;if(t===s.currencyCode)return a=o==null?void 0:(0,p.X0)(o),{data:d,value:a};{let u;if(d!=null)u=l;else{const f=this.getTokenInfo(t);if(f==null||typeof f.contractAddress!="string")throw new Error("Error: Token not supported or invalid contract address");u=f.contractAddress;const y=Pe().simpleEncode("transfer(address,uint256):(uint256)",l,(0,p.X0)(o!=null?o:"0"));a="0x0",d="0x"+V.from(y).toString("hex")}return{contractAddress:u,data:d,value:a}}}makeSpend(e){return R(this,null,function*(){var t,s;e=(0,Be.s)(e,this.currencyInfo);const{edgeSpendInfo:r,currencyCode:i,skipChecks:h}=this.makeSpendCheck(e),{memos:c=[]}=r,{pendingTxs:l=[]}=r;if(r.spendTargets.length!==1)throw new Error("Error: only one output allowed");const o=r.spendTargets[0],{publicAddress:d}=o;let{nativeAmount:a}=o;if(d==null)throw new Error("makeSpend Missing publicAddress");if(a==null)throw new ne.$D;if(!S().isValidAddress(d))throw new TypeError(`Invalid ${this.currencyInfo.pluginId} address`);let u;const f=je(r,this.networkFees,this.currencyInfo,this.networkInfo);let y;if(l.length>0){const A=this.walletLocalData.otherData,_=this.walletLocalData.numUnconfirmedSpendTxs>0?A.unconfirmedNextNonce:A.nextNonce;y=(0,g.add)(_,l.length.toString())}const{contractAddress:k,data:C,value:v}=this.getTxParameterInformation(r,i,this.currencyInfo);k==null?u={from:[this.walletLocalData.publicKey],to:[d],gas:f.gasLimit,gasPrice:f.gasPrice,gasUsed:"0",nonceUsed:y,data:C,isFromMakeSpend:!0}:u={from:[this.walletLocalData.publicKey],to:[k],gas:f.gasLimit,gasPrice:f.gasPrice,gasUsed:"0",tokenRecipientAddress:d,nonceUsed:y,data:C,isFromMakeSpend:!0},f.useEstimatedGasLimit&&(u.gas=yield this.estimateGasLimit({contractAddress:k,estimateGasParams:[{to:k!=null?k:d,from:this.walletLocalData.publicKey,gas:"0xffffff",value:v,data:C},"latest"],miningFees:f,publicAddress:d}));const E=(t=this.walletLocalData.totalBalances[this.currencyInfo.currencyCode])!=null?t:"0";let b=(0,g.mul)(f.gasPrice,u.gas),L="0",D=null,K="0";if(this.l1RollupParams!=null){const A={nonce:u.nonceUsed,gasPriceL1Wei:this.l1RollupParams.gasPriceL1Wei,gasLimit:u.gas,to:u.to[0],value:v,data:u.data,chainParams:this.networkInfo.chainParams,dynamicOverhead:this.l1RollupParams.dynamicOverhead,fixedOverhead:this.l1RollupParams.fixedOverhead};K=Me(A)}if(i===this.currencyInfo.currencyCode){if(b=(0,g.add)(b,K),L=(0,g.add)(b,a),!h&&(0,g.gt)(L,E))throw new ne.C_;a=(0,g.mul)(L,"-1")}else{if(D=(0,g.add)(b,K),!h&&(0,g.gt)(b,E))throw new ne.C_({currencyCode:this.currencyInfo.currencyCode,networkFee:b});const A=(s=this.walletLocalData.totalBalances[i])!=null?s:"0";if(!h&&(0,g.gt)(a,A))throw new ne.C_;b="0",a=(0,g.mul)(a,"-1")}const M={blockHeight:0,currencyCode:i,date:0,feeRateUsed:Te(f.gasPrice,u.gas),isSend:a.startsWith("-"),memos:c,nativeAmount:a,networkFee:b,otherParams:u,ourReceiveAddresses:[],signedTx:"",txid:"",walletId:this.walletId};return D&&(M.parentNetworkFee=D),M})}signMessage(e,t,s){return R(this,null,function*(){const r=Ce(this.currencyInfo.pluginId)(t);if(st(s.otherParams).typedData){const h=JSON.parse(e);try{return this.utils.signTypedData(h,r)}catch{return(0,ot.signTypedData_v4)(V.from(r.privateKey,"hex"),{data:h})}}return this.utils.signMessage(e,r)})}signTx(e,t){return R(this,null,function*(){const s=Ce(this.currencyInfo.pluginId)(t),r=(0,p.Xp)(e),i=(0,p.NC)(r.gas),h=(0,p.NC)(r.gasPrice);let c;if(e.currencyCode===this.currencyInfo.currencyCode){const E=(0,g.add)(e.nativeAmount,e.networkFee);c=(0,g.mul)("-1",E,16)}else c=(0,g.mul)("-1",e.nativeAmount,16);(0,g.lt)(c,"0")&&(c="0x00");let l=r.nonceUsed;if(!l)if(this.walletLocalData.numUnconfirmedSpendTxs&&(0,g.gt)(this.otherData.unconfirmedNextNonce,this.otherData.nextNonce)){const E=(0,g.sub)(this.otherData.unconfirmedNextNonce,this.otherData.nextNonce);if((0,g.lte)(E,"5"))l=this.otherData.unconfirmedNextNonce,this.walletLocalDataDirty=!0;else{const b=new Error("Excessive pending spend transactions");throw b.name="ErrorExcessivePendingSpends",b}}else l=this.otherData.nextNonce;const o=(0,p.NC)(l);let d;if(r.data!=null)d=r.data,e.currencyCode!==this.currencyInfo.currencyCode&&(c="0x00");else if(e.currencyCode===this.currencyInfo.currencyCode)d="";else{const E=Pe().simpleEncode("transfer(address,uint256):(uint256)",r.tokenRecipientAddress,c);d="0x"+V.from(E).toString("hex"),c="0x00"}const{chainParams:a}=this.networkInfo,u=Oe().custom(a),f={nonce:o,gasPrice:h,gasLimit:i,to:r.to[0],value:c,data:d},y=V.from(s.privateKey,"hex"),k=ct().fromPrivateKey(y);this.warn(`signTx getAddressString ${k.getAddressString()}`);const v=xe.Transaction.fromTxData(f,{common:u}).sign(y);return e.signedTx=(0,p.$9)(v.serialize()),e.txid=(0,p.$9)(v.hash()),e.date=Date.now()/1e3,e.otherParams!=null&&(e.otherParams.nonceUsed=l),this.warn(`signTx
10
10
  ${(0,p.oX)(e)}`),e})}broadcastTx(e){return R(this,null,function*(){return yield this.ethNetwork.multicastServers("broadcastTx",e),this.warn(`SUCCESS broadcastTx
11
- ${(0,p.oX)(e)}`),e})}accelerate(e){return R(this,null,function*(){var t,s,r;const{currencyCode:i}=e,u=(0,n.Vk)(te)(e.otherParams);let a=e.txid,h=yield this.findTransaction(i,(0,p.f0)(a));if(h===-1&&((u==null?void 0:u.replacedTxid)!=null&&u.replacedTxid!==""&&(a=u.replacedTxid,h=yield this.findTransaction(i,(0,p.f0)(a))),h===-1))return null;const o=this.transactionList[i][h],l=(0,n.Vk)(te)(o.otherParams);if(o==null||o.blockHeight!==0||l==null||l.nonceUsed==null||!l.isFromMakeSpend)return null;const c=((t=o.spendTargets)!=null?t:[])[0];if(c==null)return null;const d=(0,g.mul)(l.gasPrice,"2"),f=l.gas,y=fe(re({},l),{gas:f,gasPrice:d,replacedTxid:a});let{nativeAmount:k}=c,b=(0,g.mul)(d,f),v="0",E;const C=(s=this.walletLocalData.totalBalances[this.currencyInfo.currencyCode])!=null?s:"0";if(i===this.currencyInfo.currencyCode){if(v=(0,g.add)(b,k),(0,g.gt)(v,C))throw new ne.C_;k=(0,g.mul)(v,"-1")}else{if(E=b,(0,g.gt)(b,C))throw new ne.C_({currencyCode:this.currencyInfo.currencyCode,networkFee:b});const I=(r=this.walletLocalData.totalBalances[i])!=null?r:"0";if((0,g.gt)(k,I))throw new ne.C_;b="0",k=(0,g.mul)(k,"-1")}return fe(re({},e),{txid:"",feeRateUsed:Te(d,f),nativeAmount:k,networkFee:b,otherParams:y,parentNetworkFee:E})})}saveTx(e){return R(this,null,function*(){var t;const s=(0,n.Vk)(te)(e.otherParams);if((s==null?void 0:s.replacedTxid)!=null){const{currencyCode:r}=e,i=(0,p.f0)(s.replacedTxid),u=this.findTransaction(r,i);if(u!==-1){const a=this.transactionList[r][u],h=e.metadata,o=fe(re({},a),{metadata:h,blockHeight:-1});this.addTransaction(r,o)}}if(e.blockHeight===0){const r=(t=e.otherParams)==null?void 0:t.nonceUsed;r!=null&&(this.otherData.unconfirmedNextNonce=(0,g.add)(r,"1"))}Ae(me.prototype,this,"saveTx").call(this,e)})}}function Wt(m,e,t,s){return R(this,null,function*(){const{currencyInfo:r,initOptions:i}=m,u=Fe(t),a=new me(m,e,u,Z(i),s,r);return yield a.loadEngine(),a})}var zt=Object.defineProperty,Vt=Object.defineProperties,Qt=Object.getOwnPropertyDescriptors,Je=Object.getOwnPropertySymbols,Yt=Object.prototype.hasOwnProperty,qt=Object.prototype.propertyIsEnumerable,Ze=(m,e,t)=>e in m?zt(m,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):m[e]=t,We=(m,e)=>{for(var t in e||(e={}))Yt.call(e,t)&&Ze(m,t,e[t]);if(Je)for(var t of Je(e))qt.call(e,t)&&Ze(m,t,e[t]);return m},ze=(m,e)=>Vt(m,Qt(e)),z=(m,e,t)=>new Promise((s,r)=>{var i=h=>{try{a(t.next(h))}catch(o){r(o)}},u=h=>{try{a(t.throw(h))}catch(o){r(o)}},a=h=>h.done?s(h.value):Promise.resolve(h.value).then(i,u);a((t=t.apply(m,e)).next())});class Ve{constructor(e){const{builtinTokens:t,currencyInfo:s,io:r,networkInfo:i}=e;this.builtinTokens=t,this.currencyInfo=s,this.io=r,this.networkInfo=i}getDisplayPrivateKey(e){return z(this,null,function*(){const{pluginId:t}=this.currencyInfo;return Ce(t)(e.keys).privateKey})}getDisplayPublicKey(e){return z(this,null,function*(){const{keys:t}=Fe(e);return t.publicKey})}importPrivateKey(e){return z(this,null,function*(){const{pluginId:t}=this.currencyInfo,{pluginMnemonicKeyName:s,pluginRegularKeyName:r}=this.networkInfo;if(/^(0x)?[0-9a-fA-F]{64}$/.test(e)){const i=q.Buffer.from(e.replace(/^0x/,""),"hex");if(!A().isValidPrivate(i))throw new Error("Invalid private key");const u=i.toString("hex"),a={[r]:u};return this.derivePublicKey({type:`wallet:${t}`,id:"fake",keys:a}),a}else{if(!(0,J.validateMnemonic)(e))throw new Error("Invalid input");const i=yield this._mnemonicToHex(e);return{[s]:e,[r]:i}}})}createPrivateKey(e){return z(this,null,function*(){const{pluginMnemonicKeyName:t,pluginRegularKeyName:s}=this.networkInfo;if(e.replace("wallet:","")!==this.currencyInfo.pluginId)throw new Error("InvalidWalletType");const i=q.Buffer.from(this.io.random(32)),u=(0,J.entropyToMnemonic)(i),a=yield this._mnemonicToHex(u);return{[t]:u,[s]:a}})}derivePublicKey(e){return z(this,null,function*(){const{pluginId:t}=this.currencyInfo,{hdPathCoinType:s,pluginMnemonicKeyName:r,pluginRegularKeyName:i}=this.networkInfo;if(e.type!==`wallet:${t}`)throw new Error("Invalid wallet type");let u;if(e.keys[r]!=null){const a=(0,J.mnemonicToSeedSync)(e.keys[r]),h=ae().fromMasterSeed(a),o=`m/44'/${s}'/0'/0`,d=h.derivePath(`${o}/0`).getWallet().getPublicKey(),f=A().pubToAddress(d).toString("hex");u=A().toChecksumAddress(f)}else{const a=q.Buffer.from(e.keys[i].replace(/^0x/,""),"hex");if(!A().isValidPrivate(a))throw new Error("Invalid private key");u=`0x${A().privateToAddress(a).toString("hex")}`}if(!A().isValidAddress(u))throw new Error("Invalid address");return{publicKey:u}})}_mnemonicToHex(e){return z(this,null,function*(){const{hdPathCoinType:t}=this.networkInfo,s=ae().fromMasterSeed((0,J.mnemonicToSeedSync)(e)),r=`m/44'/${t}'/0'/0`;return s.derivePath(`${r}/0`).getWallet().getPrivateKeyString().replace(/^0x/,"")})}parseUri(e,t,s){return z(this,null,function*(){var r,i,u,a,h;const o={};this.networkInfo.uriNetworks.forEach(k=>{o[k]=!0});const{parsedUri:l,edgeParsedUri:c}=(0,j.k)(this.currencyInfo,e,o,t||this.currencyInfo.currencyCode,s);let d="";c.publicAddress&&(d=c.publicAddress,c.publicAddress=c.publicAddress.toLowerCase());let[f,y]=d.split("-");if(y||(y=f,f="pay"),d=y,/[A-F]/.test(d)&&!A().isValidChecksumAddress(d))throw new Error("InvalidPublicAddressError");if(d=d.toLowerCase(),!A().isValidAddress(d||""))throw new Error("InvalidPublicAddressError");if(f==="token"||f==="token_info"){if(!l.query)throw new Error("InvalidUriError");const k=(r=l.query.symbol)!=null?r:"SYM";if(k.length<2||k.length>5)throw new Error("Wrong Token symbol");const b=(i=l.query.name)!=null?i:k,v=(u=l.query.decimals)!=null?u:"18";let E="1000000000000000000";const C=parseInt(v);if(C<0||C>18)throw new Error("Wrong number of decimals");E="1"+"0".repeat(C);const I=(a=l.query.type)!=null?a:this.networkInfo.ercTokenStandard;return{token:{currencyCode:k,contractAddress:y.toLowerCase(),currencyName:b,multiplier:E,denominations:[{name:k,multiplier:E}],type:I.toUpperCase()}}}if(f==="pay"){const k=d,b=l.pathname.split("/")[1],v=l.query;switch(b){case"transfer":{const E=(h=v.address)!=null?h:"",C=k!=null?k:"",I=v.uint256!=null?(0,p.EE)(v.uint256):c.nativeAmount,_=this.currencyInfo.metaTokens.find(X=>X.contractAddress===C);if(t!=null&&(_==null||_.currencyCode!==t))throw new Error("InternalErrorInvalidCurrencyCode");if(!A().isValidAddress(E))throw new Error("InvalidPublicAddressError");if(!A().isValidAddress(C))throw new Error("InvalidContractAddressError");return ze(We({},c),{currencyCode:_==null?void 0:_.currencyCode,nativeAmount:I,publicAddress:E})}case void 0:{const E=k,C=v.value!=null?(0,p.EE)(v.value):c.nativeAmount;return ze(We({},c),{publicAddress:E,nativeAmount:C})}default:throw new Error("UnsupportedContractFunction")}}throw new Error("InvalidUriError")})}encodeUri(e){return z(this,arguments,function*(t,s=[]){const{publicAddress:r,nativeAmount:i,currencyCode:u}=t;if(!A().isValidAddress(r))throw new Error("InvalidPublicAddressError");let h;if(typeof i=="string"){const l=(0,p.Qs)(u!=null?u:this.currencyInfo.currencyCode,this.currencyInfo,s);if(l==null)throw new Error("InternalErrorInvalidCurrencyCode");h=(0,g.div)(i,l.multiplier,18)}return(0,j.Q)(t,this.currencyInfo.pluginId,h)})}getSplittableTypes(e){return Object.keys(D.s).map(t=>`wallet:${t}`)}getTokenId(e){return z(this,null,function*(){(0,ee.Rp)(e);const t=(0,ee.Oj)(e.networkLocation);if(t==null||!A().isValidAddress(t.contractAddress))throw new Error("ErrorInvalidContractAddress");return t.contractAddress.toLowerCase().replace(/^0x/,"")})}}function en(m){return z(this,null,function*(){return new Ve(m)})}},88924:function(){},55024:function(){}}]);
11
+ ${(0,p.oX)(e)}`),e})}accelerate(e){return R(this,null,function*(){var t,s,r;const{currencyCode:i}=e,h=(0,n.Vk)(te)(e.otherParams);let c=e.txid,l=yield this.findTransaction(i,(0,p.f0)(c));if(l===-1&&((h==null?void 0:h.replacedTxid)!=null&&h.replacedTxid!==""&&(c=h.replacedTxid,l=yield this.findTransaction(i,(0,p.f0)(c))),l===-1))return null;const o=this.transactionList[i][l],d=(0,n.Vk)(te)(o.otherParams);if(o==null||o.blockHeight!==0||d==null||d.nonceUsed==null||!d.isFromMakeSpend)return null;const a=((t=o.spendTargets)!=null?t:[])[0];if(a==null)return null;const u=(0,g.mul)(d.gasPrice,"2"),f=d.gas,y=fe(re({},d),{gas:f,gasPrice:u,replacedTxid:c});let{nativeAmount:k}=a,C=(0,g.mul)(u,f),v="0",E;const b=(s=this.walletLocalData.totalBalances[this.currencyInfo.currencyCode])!=null?s:"0";if(i===this.currencyInfo.currencyCode){if(v=(0,g.add)(C,k),(0,g.gt)(v,b))throw new ne.C_;k=(0,g.mul)(v,"-1")}else{if(E=C,(0,g.gt)(C,b))throw new ne.C_({currencyCode:this.currencyInfo.currencyCode,networkFee:C});const L=(r=this.walletLocalData.totalBalances[i])!=null?r:"0";if((0,g.gt)(k,L))throw new ne.C_;C="0",k=(0,g.mul)(k,"-1")}return fe(re({},e),{txid:"",feeRateUsed:Te(u,f),nativeAmount:k,networkFee:C,otherParams:y,parentNetworkFee:E})})}saveTx(e){return R(this,null,function*(){var t;const s=(0,n.Vk)(te)(e.otherParams);if((s==null?void 0:s.replacedTxid)!=null){const{currencyCode:r}=e,i=(0,p.f0)(s.replacedTxid),h=this.findTransaction(r,i);if(h!==-1){const c=this.transactionList[r][h],l=e.metadata,o=fe(re({},c),{metadata:l,blockHeight:-1});this.addTransaction(r,o)}}if(e.blockHeight===0){const r=(t=e.otherParams)==null?void 0:t.nonceUsed;r!=null&&(this.otherData.unconfirmedNextNonce=(0,g.add)(r,"1"))}Ae(me.prototype,this,"saveTx").call(this,e)})}}function zt(m,e,t,s){return R(this,null,function*(){const{currencyInfo:r,initOptions:i}=m,h=Fe(t),c=new me(m,e,h,Z(i),s,r);return yield c.loadEngine(),c})}var Vt=Object.defineProperty,Qt=Object.defineProperties,Yt=Object.getOwnPropertyDescriptors,Ze=Object.getOwnPropertySymbols,qt=Object.prototype.hasOwnProperty,en=Object.prototype.propertyIsEnumerable,We=(m,e,t)=>e in m?Vt(m,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):m[e]=t,ze=(m,e)=>{for(var t in e||(e={}))qt.call(e,t)&&We(m,t,e[t]);if(Ze)for(var t of Ze(e))en.call(e,t)&&We(m,t,e[t]);return m},Ve=(m,e)=>Qt(m,Yt(e)),z=(m,e,t)=>new Promise((s,r)=>{var i=l=>{try{c(t.next(l))}catch(o){r(o)}},h=l=>{try{c(t.throw(l))}catch(o){r(o)}},c=l=>l.done?s(l.value):Promise.resolve(l.value).then(i,h);c((t=t.apply(m,e)).next())});class Qe{constructor(e){const{builtinTokens:t,currencyInfo:s,io:r,networkInfo:i}=e;this.builtinTokens=t,this.currencyInfo=s,this.io=r,this.networkInfo=i}getDisplayPrivateKey(e){return z(this,null,function*(){const{pluginId:t}=this.currencyInfo;return Ce(t)(e.keys).privateKey})}getDisplayPublicKey(e){return z(this,null,function*(){const{keys:t}=Fe(e);return t.publicKey})}importPrivateKey(e){return z(this,null,function*(){const{pluginId:t}=this.currencyInfo,{pluginMnemonicKeyName:s,pluginRegularKeyName:r}=this.networkInfo;if(/^(0x)?[0-9a-fA-F]{64}$/.test(e)){const i=q.Buffer.from(e.replace(/^0x/,""),"hex");if(!S().isValidPrivate(i))throw new Error("Invalid private key");const h=i.toString("hex"),c={[r]:h};return this.derivePublicKey({type:`wallet:${t}`,id:"fake",keys:c}),c}else{if(!(0,J.validateMnemonic)(e))throw new Error("Invalid input");const i=yield this._mnemonicToHex(e);return{[s]:e,[r]:i}}})}createPrivateKey(e){return z(this,null,function*(){const{pluginMnemonicKeyName:t,pluginRegularKeyName:s}=this.networkInfo;if(e.replace("wallet:","")!==this.currencyInfo.pluginId)throw new Error("InvalidWalletType");const i=q.Buffer.from(this.io.random(32)),h=(0,J.entropyToMnemonic)(i),c=yield this._mnemonicToHex(h);return{[t]:h,[s]:c}})}derivePublicKey(e){return z(this,null,function*(){const{pluginId:t}=this.currencyInfo,{hdPathCoinType:s,pluginMnemonicKeyName:r,pluginRegularKeyName:i}=this.networkInfo;if(e.type!==`wallet:${t}`)throw new Error("Invalid wallet type");let h;if(e.keys[r]!=null){const c=(0,J.mnemonicToSeedSync)(e.keys[r]),l=ae().fromMasterSeed(c),o=`m/44'/${s}'/0'/0`,u=l.derivePath(`${o}/0`).getWallet().getPublicKey(),f=S().pubToAddress(u).toString("hex");h=S().toChecksumAddress(f)}else{const c=q.Buffer.from(e.keys[i].replace(/^0x/,""),"hex");if(!S().isValidPrivate(c))throw new Error("Invalid private key");h=`0x${S().privateToAddress(c).toString("hex")}`}if(!S().isValidAddress(h))throw new Error("Invalid address");return{publicKey:h}})}_mnemonicToHex(e){return z(this,null,function*(){const{hdPathCoinType:t}=this.networkInfo,s=ae().fromMasterSeed((0,J.mnemonicToSeedSync)(e)),r=`m/44'/${t}'/0'/0`;return s.derivePath(`${r}/0`).getWallet().getPrivateKeyString().replace(/^0x/,"")})}parseUri(e,t,s){return z(this,null,function*(){var r,i,h,c,l;const o={};this.networkInfo.uriNetworks.forEach(k=>{o[k]=!0});const{parsedUri:d,edgeParsedUri:a}=(0,G.k)(this.currencyInfo,e,o,t||this.currencyInfo.currencyCode,s);let u="";a.publicAddress&&(u=a.publicAddress,a.publicAddress=a.publicAddress.toLowerCase());let[f,y]=u.split("-");if(y||(y=f,f="pay"),u=y,/[A-F]/.test(u)&&!S().isValidChecksumAddress(u))throw new Error("InvalidPublicAddressError");if(u=u.toLowerCase(),!S().isValidAddress(u||""))throw new Error("InvalidPublicAddressError");if(f==="token"||f==="token_info"){if(!d.query)throw new Error("InvalidUriError");const k=(r=d.query.symbol)!=null?r:"SYM";if(k.length<2||k.length>5)throw new Error("Wrong Token symbol");const C=(i=d.query.name)!=null?i:k,v=(h=d.query.decimals)!=null?h:"18";let E="1000000000000000000";const b=parseInt(v);if(b<0||b>18)throw new Error("Wrong number of decimals");E="1"+"0".repeat(b);const L=(c=d.query.type)!=null?c:this.networkInfo.ercTokenStandard;return{token:{currencyCode:k,contractAddress:y.toLowerCase(),currencyName:C,multiplier:E,denominations:[{name:k,multiplier:E}],type:L.toUpperCase()}}}if(f==="pay"){const k=u,C=d.pathname.split("/")[1],v=d.query;switch(C){case"transfer":{const E=(l=v.address)!=null?l:"",b=k!=null?k:"",L=v.uint256!=null?(0,p.EE)(v.uint256):a.nativeAmount,D=this.currencyInfo.metaTokens.find(K=>K.contractAddress===b);if(t!=null&&(D==null||D.currencyCode!==t))throw new Error("InternalErrorInvalidCurrencyCode");if(!S().isValidAddress(E))throw new Error("InvalidPublicAddressError");if(!S().isValidAddress(b))throw new Error("InvalidContractAddressError");return Ve(ze({},a),{currencyCode:D==null?void 0:D.currencyCode,nativeAmount:L,publicAddress:E})}case void 0:{const E=k,b=v.value!=null?(0,p.EE)(v.value):a.nativeAmount;return Ve(ze({},a),{publicAddress:E,nativeAmount:b})}default:throw new Error("UnsupportedContractFunction")}}throw new Error("InvalidUriError")})}encodeUri(e){return z(this,arguments,function*(t,s=[]){const{publicAddress:r,nativeAmount:i,currencyCode:h}=t;if(!S().isValidAddress(r))throw new Error("InvalidPublicAddressError");let l;if(typeof i=="string"){const d=(0,p.Qs)(h!=null?h:this.currencyInfo.currencyCode,this.currencyInfo,s);if(d==null)throw new Error("InternalErrorInvalidCurrencyCode");l=(0,g.div)(i,d.multiplier,18)}return(0,G.Q)(t,this.currencyInfo.pluginId,l)})}getSplittableTypes(e){return Object.keys(X.s).map(t=>`wallet:${t}`)}getTokenId(e){return z(this,null,function*(){(0,ee.Rp)(e);const t=(0,ee.Oj)(e.networkLocation);if(t==null||!S().isValidAddress(t.contractAddress))throw new Error("ErrorInvalidContractAddress");return t.contractAddress.toLowerCase().replace(/^0x/,"")})}}function tn(m){return z(this,null,function*(){return new Qe(m)})}},88924:function(){},55024:function(){}}]);