1"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[633],{61426:function(e,t,o){o.d(t,{nY:function(){return C}});var r=o(50675),n=o(94856),a=o(29007),s=o(23846),i=o(70797),c=o(83543),l=o(95993),u=o(30867),d=o(7672),k=o(87880),T=o(39299),p=o(4041);let g={async getTokenList(){let e=T.R.state.activeCaipNetwork,t=await k.L.fetchSwapTokens({chainId:e?.caipNetworkId});return t?.tokens?.map(e=>({...e,eip2612:!1,quantity:{decimals:"0",numeric:"0"},price:0,value:0}))||[]},async fetchGasPrice(){let e=T.R.state.activeCaipNetwork;if(!e)return null;try{if("solana"===e.chainNamespace){let e=(await p.ConnectionController?.estimateGas({chainNamespace:"solana"}))?.toString();return{standard:e,fast:e,instant:e}}return await k.L.fetchGasPrice({chainId:e.caipNetworkId})}catch{return null}},async fetchSwapAllowance({tokenAddress:e,userAddress:t,sourceTokenAmount:o,sourceTokenDecimals:r}){let n=await k.L.fetchSwapAllowance({tokenAddress:e,userAddress:t});if(n?.allowance&&o&&r){let e=p.ConnectionController.parseUnits(o,r)||0;return BigInt(n.allowance)>=e}return!1},async getMyTokensWithBalance(e){let t=d.AccountController.state.address,o=T.R.state.activeCaipNetwork;if(!t||!o)return[];let r=(await k.L.getBalance(t,o.caipNetworkId,e)).balances.filter(e=>"0"!==e.quantity.decimals);return d.AccountController.setTokenBalance(r,T.R.state.activeChain),this.mapBalancesToSwapTokens(r)},mapBalancesToSwapTokens:e=>e?.map(e=>({...e,address:e?.address?e.address:T.R.getActiveNetworkTokenAddress(),decimals:parseInt(e.quantity.decimals,10),logoUri:e.iconUrl,eip2612:!1}))||[]},m={getGasPriceInEther:(e,t)=>Number(t*e)/1e18,getGasPriceInUSD(e,t,o){let r=m.getGasPriceInEther(t,o);return a.C.bigNumber(e).times(r).toNumber()},getPriceImpact({sourceTokenAmount:e,sourceTokenPriceInUSD:t,toTokenPriceInUSD:o,toTokenAmount:r}){let n=a.C.bigNumber(e).times(t),s=a.C.bigNumber(r).times(o);return n.minus(s).div(n).times(100).toNumber()},getMaxSlippage(e,t){let o=a.C.bigNumber(e).div(100);return a.C.multiply(t,o).toNumber()},getProviderFee:(e,t=.0085)=>a.C.bigNumber(e).times(t).toString(),isInsufficientNetworkTokenForGas:(e,t)=>!!a.C.bigNumber(e).eq(0)||a.C.bigNumber(a.C.bigNumber(t||"0")).gt(e),isInsufficientSourceTokenForSwap(e,t,o){let r=o?.find(e=>e.address===t)?.quantity?.numeric;return a.C.bigNumber(r||"0").lt(e)},getToTokenAmount({sourceToken:e,toToken:t,sourceTokenPrice:o,toTokenPrice:r,sourceTokenAmount:n}){if("0"===n||!e||!t)return"0";let s=e.decimals,i=t.decimals;if(r<=0)return"0";let c=a.C.bigNumber(n).times(.0085),l=a.C.bigNumber(n).minus(c).times(a.C.bigNumber(10).pow(s)),u=a.C.bigNumber(o).div(r),d=s-i;return l.times(u).div(a.C.bigNumber(10).pow(d)).div(a.C.bigNumber(10).pow(i)).toFixed(i).toString()}};var w=o(22904),h=o(98837),v=o(11902),A=o(97921),b=o(22948),S=o(7702);let f={initializing:!1,initialized:!1,loadingPrices:!1,loadingQuote:!1,loadingApprovalTransaction:!1,loadingBuildTransaction:!1,loadingTransaction:!1,fetchError:!1,approvalTransaction:void 0,swapTransaction:void 0,transactionError:void 0,sourceToken:void 0,sourceTokenAmount:"",sourceTokenPriceInUSD:0,toToken:void 0,toTokenAmount:"",toTokenPriceInUSD:0,networkPrice:"0",networkBalanceInUSD:"0",networkTokenSymbol:"",inputError:void 0,slippage:c.bq.CONVERT_SLIPPAGE_TOLERANCE,tokens:void 0,popularTokens:void 0,suggestedTokens:void 0,foundTokens:void 0,myTokensWithBalance:void 0,tokensPriceMap:{},gasFee:"0",gasPriceInUSD:0,priceImpact:void 0,maxSlippage:void 0,providerFee:void 0},P=(0,r.sj)(f),y={state:P,subscribe:e=>(0,r.Ld)(P,()=>e(P)),subscribeKey:(e,t)=>(0,n.VW)(P,e,t),getParams(){let e=T.R.state.activeCaipAddress,t=T.R.state.activeChain,o=l.j.getPlainAddress(e),r=T.R.getActiveNetworkTokenAddress(),n=v.ConnectorController.getConnectorId(t);if(!o)throw Error("No address found to swap the tokens from.");let i=!P.toToken?.address||!P.toToken?.decimals,c=!P.sourceToken?.address||!P.sourceToken?.decimals||!a.C.bigNumber(P.sourceTokenAmount).gt(0),u=!P.sourceTokenAmount;return{networkAddress:r,fromAddress:o,fromCaipAddress:e,sourceTokenAddress:P.sourceToken?.address,toTokenAddress:P.toToken?.address,toTokenAmount:P.toTokenAmount,toTokenDecimals:P.toToken?.decimals,sourceTokenAmount:P.sourceTokenAmount,sourceTokenDecimals:P.sourceToken?.decimals,invalidToToken:i,invalidSourceToken:c,invalidSourceTokenAmount:u,availableToSwap:e&&!i&&!c&&!u,isAuthConnector:n===s.b.CONNECTOR_ID.AUTH}},setSourceToken(e){if(!e){P.sourceToken=e,P.sourceTokenAmount="",P.sourceTokenPriceInUSD=0;return}P.sourceToken=e,C.setTokenPrice(e.address,"sourceToken")},setSourceTokenAmount(e){P.sourceTokenAmount=e},setToToken(e){if(!e){P.toToken=e,P.toTokenAmount="",P.toTokenPriceInUSD=0;return}P.toToken=e,C.setTokenPrice(e.address,"toToken")},setToTokenAmount(e){P.toTokenAmount=e?a.C.formatNumberToLocalString(e,6):""},async setTokenPrice(e,t){let o=P.tokensPriceMap[e]||0;o||(P.loadingPrices=!0,o=await C.getAddressPrice(e)),"sourceToken"===t?P.sourceTokenPriceInUSD=o:"toToken"===t&&(P.toTokenPriceInUSD=o),P.loadingPrices&&(P.loadingPrices=!1),C.getParams().availableToSwap&&C.swapTokens()},switchTokens(){if(P.initializing||!P.initialized)return;let e=P.toToken?{...P.toToken}
1:void 0,t=P.sourceToken?{...P.sourceToken}:void 0,o=e&&""===P.toTokenAmount?"1":P.toTokenAmount;C.setSourceToken(e),C.setToToken(t),C.setSourceTokenAmount(o),C.setToTokenAmount(""),C.swapTokens()},resetState(){P.myTokensWithBalance=f.myTokensWithBalance,P.tokensPriceMap=f.tokensPriceMap,P.initialized=f.initialized,P.sourceToken=f.sourceToken,P.sourceTokenAmount=f.sourceTokenAmount,P.sourceTokenPriceInUSD=f.sourceTokenPriceInUSD,P.toToken=f.toToken,P.toTokenAmount=f.toTokenAmount,P.toTokenPriceInUSD=f.toTokenPriceInUSD,P.networkPrice=f.networkPrice,P.networkTokenSymbol=f.networkTokenSymbol,P.networkBalanceInUSD=f.networkBalanceInUSD,P.inputError=f.inputError,P.myTokensWithBalance=f.myTokensWithBalance},resetValues(){let{networkAddress:e}=C.getParams(),t=P.tokens?.find(t=>t.address===e);C.setSourceToken(t),C.setToToken(void 0)},getApprovalLoadingState:()=>P.loadingApprovalTransaction,clearError(){P.transactionError=void 0},async initializeState(){if(!P.initializing){if(P.initializing=!0,!P.initialized)try{await C.fetchTokens(),P.initialized=!0}catch(e){P.initialized=!1,S.SnackController.showError("Failed to initialize swap"),b.RouterController.goBack()}P.initializing=!1}},async fetchTokens(){let{networkAddress:e}=C.getParams();await C.getTokenList(),await C.getNetworkTokenPrice(),await C.getMyTokensWithBalance();let t=P.tokens?.find(t=>t.address===e);t&&(P.networkTokenSymbol=t.symbol,C.setSourceToken(t),C.setSourceTokenAmount("1"))},async getTokenList(){let e=await g.getTokenList();P.tokens=e,P.popularTokens=e.sort((e,t)=>e.symbol<t.symbol?-1:e.symbol>t.symbol?1:0),P.suggestedTokens=e.filter(e=>!!c.bq.SWAP_SUGGESTED_TOKENS.includes(e.symbol),{})},async getAddressPrice(e){let t=P.tokensPriceMap[e];if(t)return t;let o=await k.L.fetchTokenPrice({addresses:[e]}),r=o?.fungibles||[],n=[...P.tokens||[],...P.myTokensWithBalance||[]],a=n?.find(t=>t.address===e)?.symbol,s=parseFloat((r.find(e=>e.symbol.toLowerCase()===a?.toLowerCase())?.price||0).toString());return P.tokensPriceMap[e]=s,s},async getNetworkTokenPrice(){let{networkAddress:e}=C.getParams(),t=await k.L.fetchTokenPrice({addresses:[e]}).catch(()=>(S.SnackController.showError("Failed to fetch network token price"),{fungibles:[]})),o=t.fungibles?.[0],r=o?.price.toString()||"0";P.tokensPriceMap[e]=parseFloat(r),P.networkTokenSymbol=o?.symbol||"",P.networkPrice=r},async getMyTokensWithBalance(e){let t=await u.y.getMyTokensWithBalance(e),o=u.y.mapBalancesToSwapTokens(t);o&&(await C.getInitialGasPrice(),C.setBalances(o))},setBalances(e){let{networkAddress:t}=C.getParams(),o=T.R.state.activeCaipNetwork;if(!o)return;let r=e.find(e=>e.address===t);e.forEach(e=>{P.tokensPriceMap[e.address]=e.price||0}),P.myTokensWithBalance=e.filter(e=>e.address.startsWith(o.caipNetworkId)),P.networkBalanceInUSD=r?a.C.multiply(r.quantity.numeric,r.price).toString():"0"},async getInitialGasPrice(){let e=await g.fetchGasPrice();if(!e)return{gasPrice:null,gasPriceInUSD:null};if(T.R.state?.activeCaipNetwork?.chainNamespace==="solana")return P.gasFee=e.standard??"0",P.gasPriceInUSD=a.C.multiply(e.standard,P.networkPrice).div(1e9).toNumber(),{gasPrice:BigInt(P.gasFee),gasPriceInUSD:Number(P.gasPriceInUSD)};{let t=e.standard??"0",o=BigInt(t),r=BigInt(15e4),n=m.getGasPriceInUSD(P.networkPrice,r,o);return P.gasFee=t,P.gasPriceInUSD=n,{gasPrice:o,gasPriceInUSD:n}}},async swapTokens(){let e=d.AccountController.state.address,t=P.sourceToken,o=P.toToken,r=a.C.bigNumber(P.sourceTokenAmount).gt(0);if(r||C.setToTokenAmount(""),!o||!t||P.loadingPrices||!r)return;P.loadingQuote=!0;let n=a.C.bigNumber(P.sourceTokenAmount).times(10**t.decimals).round(0);try{let r=await k.L.fetchSwapQuote({userAddress:e,from:t.address,to:o.address,gasPrice:P.gasFee,amount:n.toString()});P.loadingQuote=!1;let s=r?.quotes?.[0]?.toAmount;if(!s){h.AlertController.open({shortMessage:"Incorrect amount",longMessage:"Please enter a valid amount"},"error");return}let i=a.C.bigNumber(s).div(10**o.decimals).toString();C.setToTokenAmount(i),C.hasInsufficientToken(P.sourceTokenAmount,t.address)?P.inputError="Insufficient balance":(P.inputError=void 0,C.setTransactionDetail
1s())}catch(e){P.loadingQuote=!1,P.inputError="Insufficient balance"}},async getTransaction(){let{fromCaipAddress:e,availableToSwap:t}=C.getParams(),o=P.sourceToken,r=P.toToken;if(e&&t&&o&&r&&!P.loadingQuote)try{let t;return P.loadingBuildTransaction=!0,t=await g.fetchSwapAllowance({userAddress:e,tokenAddress:o.address,sourceTokenAmount:P.sourceTokenAmount,sourceTokenDecimals:o.decimals})?await C.createSwapTransaction():await C.createAllowanceTransaction(),P.loadingBuildTransaction=!1,P.fetchError=!1,t}catch(e){b.RouterController.goBack(),S.SnackController.showError("Failed to check allowance"),P.loadingBuildTransaction=!1,P.approvalTransaction=void 0,P.swapTransaction=void 0,P.fetchError=!0;return}},async createAllowanceTransaction(){let{fromCaipAddress:e,sourceTokenAddress:t,toTokenAddress:o}=C.getParams();if(e&&o){if(!t)throw Error("createAllowanceTransaction - No source token address found.");try{let r=await k.L.generateApproveCalldata({from:t,to:o,userAddress:e}),n={data:r.tx.data,to:l.j.getPlainAddress(r.tx.from),gasPrice:BigInt(r.tx.eip155.gasPrice),value:BigInt(r.tx.value),toAmount:P.toTokenAmount};return P.swapTransaction=void 0,P.approvalTransaction={data:n.data,to:n.to,gasPrice:n.gasPrice,value:n.value,toAmount:n.toAmount},{data:n.data,to:n.to,gasPrice:n.gasPrice,value:n.value,toAmount:n.toAmount}}catch(e){b.RouterController.goBack(),S.SnackController.showError("Failed to create approval transaction"),P.approvalTransaction=void 0,P.swapTransaction=void 0,P.fetchError=!0;return}}},async createSwapTransaction(){let{networkAddress:e,fromCaipAddress:t,sourceTokenAmount:o}=C.getParams(),r=P.sourceToken,n=P.toToken;if(!t||!o||!r||!n)return;let a=p.ConnectionController.parseUnits(o,r.decimals)?.toString();try{let o=await k.L.generateSwapCalldata({userAddress:t,from:r.address,to:n.address,amount:a,disableEstimate:!0}),s=r.address===e,i=BigInt(o.tx.eip155.gas),c=BigInt(o.tx.eip155.gasPrice),u={data:o.tx.data,to:l.j.getPlainAddress(o.tx.to),gas:i,gasPrice:c,value:s?BigInt(a??"0"):BigInt("0"),toAmount:P.toTokenAmount};return P.gasPriceInUSD=m.getGasPriceInUSD(P.networkPrice,i,c),P.approvalTransaction=void 0,P.swapTransaction=u,u}catch(e){b.RouterController.goBack(),S.SnackController.showError("Failed to create transaction"),P.approvalTransaction=void 0,P.swapTransaction=void 0,P.fetchError=!0;return}},async sendTransactionForApproval(e){let{fromAddress:t,isAuthConnector:o}=C.getParams();P.loadingApprovalTransaction=!0;let r="Approve limit increase in your wallet";o?b.RouterController.pushTransactionStack({view:null,goBack:!0,onSuccess(){S.SnackController.showLoading(r)}}):S.SnackController.showLoading(r);try{await p.ConnectionController.sendTransaction({address:t,to:e.to,data:e.data,value:e.value,chainNamespace:"eip155"}),await C.swapTokens(),await C.getTransaction(),P.approvalTransaction=void 0,P.loadingApprovalTransaction=!1}catch(e){P.transactionError=e?.shortMessage,P.loadingApprovalTransaction=!1,S.SnackController.showError(e?.shortMessage||"Transaction error"),A.X.sendEvent({type:"track",event:"SWAP_APPROVAL_ERROR",properties:{message:e?.shortMessage||e?.message||"Unknown",network:T.R.state.activeCaipNetwork?.caipNetworkId||"",swapFromToken:C.state.sourceToken?.symbol||"",swapToToken:C.state.toToken?.symbol||"",swapFromAmount:C.state.sourceTokenAmount||"",swapToAmount:C.state.toTokenAmount||"",isSmartAccount:d.AccountController.state.preferredAccountTypes?.eip155===i.y_.ACCOUNT_TYPES.SMART_ACCOUNT}})}},async sendTransactionForSwap(e){if(!e)return;let{fromAddress:t,toTokenAmount:o,isAuthConnector:r}=C.getParams();P.loadingTransaction=!0;let n=`Swapping ${P.sourceToken?.symbol} to ${a.C.formatNumberToLocalString(o,3)} ${P.toToken?.symbol}`,s=`Swapped ${P.sourceToken?.symbol} to ${a.C.formatNumberToLocalString(o,3)} ${P.toToken?.symbol}`;r?b.RouterController.pushTransactionStack({view:"Account",goBack:!1,onSuccess(){S.SnackController.showLoading(n),y.resetState()}}):S.SnackController.showLoading("Confirm transaction in your wallet");try{let o=[P.sourceToken?.address,P.toToken?.address].join(","),n=await p.ConnectionController.sendTransaction({address:t,to:e.to,data:e.data,value:e.value,chainNamespace:"eip155"});return P.loadingTransaction=!1,S.SnackController.showSuccess(s),A.X.sendEvent({type:"track",event:"SWAP_SUCCESS",properties:{network:T.R.state.activeCaipNetwork?.caipNetworkId||"",swapFromToken:C.state.sourceToken?.symbol||"",swapToToken:C.state.toToken?.symbol||"",swapFromAmount:C.state.sourceTokenAmount||"",swapToAmount:C.state.toTokenAmount||"",isSmartAccount:d.AccountController.state.preferredAccountTypes?.eip155===i.y_.ACCOUNT_TYPES.SMART_ACCOUNT}}),y.resetState(),r||b.RouterController.replace("Account"),y.getMyTokensWithBalance(o),n}catch(e){P.transactionError=e?.shortMessage,P.loadingTransaction=!1,S.SnackController.showError(e?.shortMessage||"Transaction error"),A.X.sendEvent({type:"track",event:"SWAP_ERROR",properties:{message:e?.shortMessage||e?.message||"Unknown",network:T.R.state.activeCaipNetwork?.caipNetworkId||"",swapFromToken:C.state.sourceToken?.symbol||"",swapToToken:C.state.toToken?.symbol||"",swapFromAmount:C.state.sourceTokenAmount||"",swapToAmount:C.state.toTokenAmount||"",isSmartAccount:d.AccountController.state.preferredAccountTypes?.eip155===i.y_.ACCOUNT_TYPES.SMART_ACCOUNT}});return}},hasInsufficientToken:(e,t)=>m.isInsufficientSourceTokenForSwap(e,t,P.myTokensWithBalance),setTransactionDetail
1s(){let{toTokenAddress:e,toTokenDecimals:t}=C.getParams();e&&t&&(P.gasPriceInUSD=m.getGasPriceInUSD(P.networkPrice,BigInt(P.gasFee),BigInt(15e4)),P.priceImpact=m.getPriceImpact({sourceTokenAmount:P.sourceTokenAmount,sourceTokenPriceInUSD:P.sourceTokenPriceInUSD,toTokenPriceInUSD:P.toTokenPriceInUSD,toTokenAmount:P.toTokenAmount}),P.maxSlippage=m.getMaxSlippage(P.slippage,P.toTokenAmount),P.providerFee=m.getProviderFee(P.sourceTokenAmount))}},C=(0,w.P)(y)},74334:function(e,t,o){o(71347)},6159:function(e,t,o){o(52992)},16026:function(e,t,o){var r=o(42843),n=o(66358);o(36535),o(50612);var a=o(51466),s=o(83189);o(50521);var i=(0,r.iv)` 2 :host { 3 display: block; 4 } 5 6 :host > button { 7 gap: var(--wui-spacing-xxs); 8 padding: var(--wui-spacing-xs); 9 padding-right: var(--wui-spacing-1xs); 10 height: 40px; 11 border-radius: var(--wui-border-radius-l); 12 background: var(--wui-color-gray-glass-002); 13 border-width: 0px; 14 box-shadow: inset 0 0 0 1px var(--wui-color-gray-glass-002); 15 } 16 17 :host > button wui-image { 18 width: 24px; 19 height: 24px; 20 border-radius: var(--wui-border-radius-s); 21 box-shadow: inset 0 0 0 1px var(--wui-color-gray-glass-010); 22 } 23`,c=function(e,t,o,r){var n,a=arguments.length,s=a<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,o):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,o,r);else for(var i=e.length-1;i>=0;i--)(n=e[i])&&(s=(a<3?n(s):a>3?n(t,o,s):n(t,o))||s);return a>3&&s&&Object.defineProperty(t,o,s),s};let l=class extends r.oi{constructor(){super(...arguments),this.text=""}render(){return(0,r.dy)` 24 <button> 25 ${this.tokenTemplate()} 26 <wui-text variant="paragraph-600" color="fg-100">${this.text}</wui-text> 27 </button> 28 `}tokenTemplate(){return this.imageSrc?(0,r.dy)`<wui-image src=${this.imageSrc}></wui-image>`:(0,r.dy)` 29 <wui-icon-box 30 size="sm" 31 iconColor="fg-200" 32 backgroundColor="fg-300" 33 icon="networkPlaceholder" 34 ></wui-icon-box> 35 `}};l.styles=[a.ET,a.ZM,i],c([(0,n.Cb)()],l.prototype,"imageSrc",void 0),c([(0,n.Cb)()],l.prototype,"text",void 0),c([(0,s.M)("wui-token-button")],l)},36535:function(e,t,o){var r=o(42843),n=o(66358),a=o(51466),s=o(83189),i=(0,r.iv)` 36 :host { 37 display: block; 38 width: var(--local-width); 39 height: var(--local-height); 40 } 41 42 img { 43 display: block; 44 width: 100%; 45 height: 100%; 46 object-fit: cover; 47 object-position: center center; 48 border-radius: inherit; 49 } 50`,c=function(e,t,o,r){var n,a=arguments.length,s=a<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,o):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,o,r);else for(var i=e.length-1;i>=0;i--)(n=e[i])&&(s=(a<3?n(s):a>3?n(t,o,s):n(t,o))||s);return a>3&&s&&Object.defineProperty(t,o,s),s};let l=class extends r.oi{constructor(){super(...arguments),this.src="./path/to/image.jpg",this.alt="Image",this.size=void 0}render(){return this.style.cssText=` 51 --local-width: ${this.size?`var(--wui-icon-size-${this.size});`:"100%"}; 52 --local-height: ${this.size?`var(--wui-icon-size-${this.size});`:"100%"}; 53 `,(0,r.dy)`<img src=${this.src} alt=${this.alt} @error=${this.handleImageError} />`}handleImageError(){this.dispatchEvent(new CustomEvent("onLoadError",{bubbles:!0,composed:!0}))}};l.styles=[a.ET,a.Bp,i],c([(0,n.Cb)()],l.prototype,"src",void 0),c([(0,n.Cb)()],l.prototype,"alt",void 0),c([(0,n.Cb)()],l.prototype,"size",void 0),c([(0,s.M)("wui-image")],l)}}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.