1import{aY as an,f_ as rs,f$ as un,m as r,aW as cn,aX as ln,g0 as as,g1 as is,g2 as dn,J as qe,g3 as us,g4 as ft,g5 as cs,g6 as ls,g7 as ds,g8 as fs,g9 as ps,ga as ms,gb as ws,gc as gs,aV as me,u as at,dT as Ee,b as $e,ae as fn,a as Le,r as O,gd as we,ge as pn,gf as J,gg as q,gh as te,a3 as U,bL as T,gi as ee,gj as Se,a8 as Ve,bJ as xs,gk as mn,gl as Je,gm as wn,gn as Ze,go as bs,aj as _e,gp as Ue,a0 as je,ak as et,gq as ys,gr as hs,a2 as Ss,gs as vt,gt as gn,eQ as gt,gu as vs,d as be,B as W,F as _,T as A,S as Ie,aE as xn,I as ce,gv as Os,_ as Fs,q as pe,cp as Fe,cq as Ae,cr as Ce,gw as As,gx as Cs,bG as bn,o as js,aG as yn,aH as hn,gy as Es,gz as Ls,by as Sn,aI as Ot,x as xt,dZ as ks,w as Ft,ad as pt,ei as vn,ej as On,ek as Fn,gA as Ts,el as An,gB as bt,bd as Ns,a1 as $t,cI as Ds,gC as Cn,gD as Rs,gE as Ps,gF as jn,gG as En,gH as Vs,gI as _s,gJ as Us,aC as Ms,gK as zs,gL as Bs,Z as Ln,gM as $s,e1 as Is,aN as Ws,dC as Gs,bM as Hs,gN as Qs,gO as Ys,dD as Xs,bO as Ks,bH as Zs,bF as qs,aL as Js,gP as eo,gQ as to,cG as no,as as so,gR as oo,eh as ro,at as ao}from"./index-B_Mn5R45.js";import{u as io}from"./util-Cl-Auk87.js";import{S as tt}from"./chunk-3GRGLNAR-BkAfakiY.js";import{P as uo,b as co,c as lo,d as fo,e as po}from"./chunk-KVBLLJMP-SJmgF5NS.js";import{L as mo}from"./LogoReveal-WqKg3izM.js";import{a as wo}from"./VyMark-P4RYb-jg.js";/* empty css */import{M as kn}from"./chunk-XY72533R-DvOmvu1Y.js";import{M as go}from"./chunk-PXDTSMWR-iZsVX_sC.js";import{T as xo}from"./chunk-ZWLVZLKQ-CgnkdqDY.js";import{D as Tn}from"./chunk-YGVX4ESO-CZTYMTQ0.js";import{B as bo}from"./chunk-FQXH56BT-BNiISX37.js";import"./surfaces-D3KSvQgQ.js";var Nn=an(function(e,n){const s=rs({...e,ref:n}),o=un();return r.jsx(cn.div,{outline:"0",...s,className:ln("chakra-tabs__tab-panel",e.className),__css:o.tabpanel})});Nn.displayName="TabPanel";var Dn=an(function(e,n){const s=as(e),o=un();return r.jsx(cn.div,{...s,width:"100%",ref:n,className:ln("chakra-tabs__tab-panels",e.className),__css:o.tabpanels})});Dn.displayName="TabPanels";function yo(t,e){if(t.length!==e.length)throw new is({expectedLength:t.length,givenLength:e.length});const n=[];for(let s=0;s<t.length;s++){const o=t[s],a=e[s];n.push(Rn(o,a))}return dn(n)}function Rn(t,e,n=!1){if(t==="address"){const i=e;if(!qe(i))throw new us({address:i});return ft(i.toLowerCase(),{size:n?32:null})}if(t==="string")return cs(e);if(t==="bytes")return e;if(t==="bool")return ft(ls(e),{size:n?32:1});const s=t.match(ds);if(s){const[i,u,d="256"]=s,c=Number.parseInt(d,10)/8;return fs(e,{size:n?32:c,signed:u==="int"})}const o=t.match(ps);if(o){const[i,u]=o;if(Number.parseInt(u,10)!==(e.length-2)/2)throw new ms({expectedSize:Number.parseInt(u,10),givenSize:(e.length-2)/2});return ft(e,{dir:"right",size:n?32:null})}const a=t.match(ws);if(a&&Array.isArray(e)){const[i,u]=a,d=[];for(let c=0;c<e.length;c++)d.push(Rn(u,e[c],!0));return d.length===0?"0x":dn(d)}throw new gs(t)}const Pn=6;function ho(t,e){return t===""?!0:/^\d*\.?\d*$/.test(t)?e===void 0?!0:(t.split(".")[1]??"").length<=e:!1}function It(t,e,n=Pn){const[s,o=""]=me(t,e).split("."),a=o.slice(0,n).replace(/0+$/,"");return a?`${s}.${a}`:s}function Wt(t,e,n){if(e===void 0||!Number.isFinite(e)||e<=0)return null;const s=Number(t);if(t===""||!Number.isFinite(s)||s<=0)return null;const o=s*e;return o<.01?`< ${.01.toLocaleString(n,{style:"currency",currency:"USD"})}`:`â ${o.toLocaleString(n,{style:"currency",currency:"USD",minimumFractionDigits:2,maximumFractionDigits:2})}`}const So=10n,vo=4,Oo=10n,Fo=1000n;async function Ao({target:t,seedAmountIn:e,quote:n,snapUp:s=a=>a,maxQuotes:o=vo}){if(t<=0n)throw new Error("Enter an amount to receive");const a=t*So/10000n,i=t-a,u=t+a,d=t+a/2n,c=p=>{const w=s(p>0n?p:1n);return w>0n?w:1n},f=[];let l=c(e);for(;f.length<o&&!f.some(w=>w.amountIn===l);){let p;try{p=await n(l)}catch(w){if(f.length===0)throw w;break}if(f.push(p),p.amountOut>=i&&p.amountOut<=u)return p;l=c(Co(f,d))}return jo(f,t)}function Co(t,e){const n=t[t.length-1];if(t.length>=2){const s=t[t.length-2],o=n.amountIn-s.amountIn,a=n.amountOut-s.amountOut;if(o!==0n&&a!==0n&&o>0n==a>0n){const i=n.amountIn+(e-n.amountOut)*o/a,u=n.amountIn*Oo;if(i>0n)return i<u?i:u}}return n.amountOut<=0n?n.amountIn*Fo:n.amountIn*e/n.amountOut+1n}function jo(t,e){const n=t.filter(s=>s.amountOut>=e);return n.length>0?n.reduce((s,o)=>o.amountIn<s.amountIn?o:s):t.reduce((s,o)=>o.amountOut>s.amountOut?o:s)}function Eo(t,e,n){if(e<=n)return t;const s=10n**BigInt(e-n);return(t+s-1n)/s*s}const Lo=[0,3e3,1e4];function ko(t,e=Lo){const n=()=>{t.invalidateQueries({queryKey:["balance"]}),t.invalidateQueries({queryKey:["readContract"]}),t.invalidateQueries({queryKey:["readContracts"]}),t.invalidateQueries({queryKey:["swap","allowance"]})};for(const s of e)s<=0?n():setTimeout(n,s)}const We=60n,Ge=60n,Te="0x0000000000000000000000000000000000000000";function Me(t){var e;return(e=Ve[t.toString()])==null?void 0:e.ValinityExchangeOfficer}function it(t){var e;return(e=Ve[t.toString()])==null?void 0:e.UniswapV3QuoterV2}function He(t){var e;return(e=Ve[t.toString()])==null?void 0:e.UniswapV2Router02}function To(t){var e;return(e=Ve[t.toString()])==null?void 0:e.ValinityDAX}async function No(t,e,n){const s=Me(e);if(!s)return!0;try{if(!await U(t,{abi:T.ValinityExchangeOfficer,address:s,chainId:e,functionName:"daxLockedPool",args:[n]}))return!0;const a=vs(t).address;return a?await U(t,{abi:T.ValinityExchangeOfficer,address:s,chainId:e,functionName:"daxAllowed",args:[a]}):!1}catch{return!0}}async function ae(t,e,n){const s=To(e);if(!s)return{found:!1};try{const[o,a]=await Promise.all([U(t,{abi:T.ValinityDAX,address:s,functionName:"assetToPoolId",args:[n],chainId:e}),U(t,{abi:T.ValinityDAX,address:s,functionName:"getNumPools",chainId:e})]);if(o>=a)return{found:!1};const[i]=await U(t,{abi:T.ValinityDAX,address:s,functionName:"getPoolReserves",args:[o],chainId:e});return i.toLowerCase()!==n.toLowerCase()?{found:!1}:await No(t,e,o)?{found:!0,poolId:o}:{found:!1}}catch{return{found:!1}}}function ze(t){return mn[t]}function le(t,e){if(we(t)){const n=ze(e);if(!n)throw new Error("WETH is not configured for this chain");return n}return t}function Do(t,e){const{address:n}=at(),s=Ee(),o=$e(),a=fn(),i=Me(s),u=e==null?void 0:e.address,d=t==null?void 0:t.amountIn.toString(),c=t==null?void 0:t.route.kind,l=Le({queryKey:["swap","allowance",s,n,u,d,c],queryFn:async()=>!n||!i||!e||!t||we(e.address)||t.route.kind==="wrap"?!1:await U(o,{abi:T.ERC20,address:e.address,functionName:"allowance",args:[n,i],chainId:s})<t.amountIn,enabled:!!n&&!!i&&!!e&&!!t,staleTime:15e3}),p=O.useCallback(()=>{a.setQueryData(["swap","allowance",s,n,u,d,c],!1)},[a,s,n,u,d,c]),w=l.isSuccess||l.isError,g=!!e&&we(e.address),m=(t==null?void 0:t.route.kind)==="wrap";return{needsApproval:l.data===!0||l.isError&&!g&&!m,isResolved:w,markApproved:p}}function Ro(t){var d;const e=Ee(),n=$e(),{address:s}=at(),o=t?t.side==="in"?t.amountIn:t.amountOut:void 0,a=t?`${t.tokenIn.address}>${t.tokenOut.address}`.toLowerCase():"",i=O.useRef(null),u=Le({queryKey:["swap","quote",e,t==null?void 0:t.tokenIn.address,t==null?void 0:t.tokenOut.address,t==null?void 0:t.side,o==null?void 0:o.toString(),s??""],queryFn:async()=>{var f;if(!t)throw new Error("Missing quote params");if(t.side==="in")return await At(n,e,t);const c=((f=i.current)==null?void 0:f.pair)===a?i.current:void 0;return await Vo(n,e,{...t,rateHint:c})},enabled:o!==void 0&&o>0n&&pn(e),staleTime:0,gcTime:3*60*1e3,refetchOnWindowFocus:!1,retry:!1});return O.useEffect(()=>{u.data&&a&&(i.current={pair:a,amountIn:u.data.amountIn,amountOut:u.data.amountOut})},[u.data,a]),O.useEffect(()=>{var l;if(!((l=u.data)!=null&&l.expiresAt))return;const c=u.data.expiresAt-5e3-Date.now();if(c<=0){u.refetch();return}const f=setTimeout(()=>u.refetch(),c);return()=>clearTimeout(f)},[(d=u.data)==null?void 0:d.expiresAt]),u}async function At(t,e,n){const s=Me(e),o=it(e);if(!s||!o)throw new Error("Swap is not supported on this network");const{tokenIn:a,tokenOut:i,amountIn:u}=n,d=le(a.address,e),c=le(i.address,e),f=ze(e),l=we(a.address),p=we(i.address),w=!!f&&!l&&a.address.toLowerCase()===f.toLowerCase(),g=!!f&&!p&&i.address.toLowerCase()===f.toLowerCase();if(l&&g||w&&p){const k=l?"deposit":"withdraw";return{amountIn:u,amountAfterFee:u,feeAmountIn:0n,feeBps:0,feeSide:"input",feeRoute:ge,feeDaxPoolId:0n,uniFeeForFeeLeg:0,amountOut:u,route:{kind:"wrap",direction:k},routeLabel:k==="deposit"?"Wrap · ETH â WETH":"Unwrap · WETH â ETH",expiresAt:Date.now()+J}}const m=await Wo(t,e,s,a,i,u);if(m)return m;const x=await Go(t,e,s,o,a,i,u);if(x)return x;const y=await Ho(t,e,s,a,i,u);if(y)return y;const h=await Qo(t,e,s,o,a,i,u);if(h)return h;const S=await Yo(t,e,s,a,i,u);if(S)return S;if(a.category==="stock"||i.category==="stock")return await Io(t,e,n,s,o);const L=await qo(t,e,s,a,i,u);if(L)return L;const F=await Un(t,e,d,c,u);if(F){const k={kind:"v2",router:F.router,path:F.path},D=await Gt(t,e,s,k,d,c);let Q,G,ne,Y;if(D.feeSide==="input"){const Z=await K(t,e,s,F.path,u);G=Z.fee,Q=Z.amountAfterFee,Y=Z.bps,ne=await de(t,e,F.router,F.path,Q)}else{Q=u;const Z=F.amountOut,X=await K(t,e,s,F.path,Z);G=X.fee,Y=X.bps,ne=X.amountAfterFee}return{amountIn:u,amountAfterFee:Q,feeAmountIn:G,feeBps:Y,feeSide:D.feeSide,feeRoute:D.feeRoute,feeDaxPoolId:D.feeDaxPoolId,uniFeeForFeeLeg:D.uniFeeForFeeLeg,amountOut:ne,route:k,routeLabel:F.path.length===2?`Uniswap V2 · ${a.symbol} â ${i.symbol}`:`Uniswap V2 · ${a.symbol} â ${F.midSymbol} â ${i.symbol}`,expiresAt:Date.now()+J}}const b=await Xo(t,e,s,d,c,u),j=await Gt(t,e,s,b,d,c),B=b.kind==="bridged"?[d,b.midToken,c]:[d,c];let v,N,z,R,M,P;if(j.feeSide==="input"){const k=await K(t,e,s,B,u);if(N=k.fee,v=k.amountAfterFee,z=k.bps,b.kind==="dax")R=await ie(t,e,b,d,v),P=`VDAX pool #${b.poolId.toString()}`;else if(b.kind==="uniV3"){const D=await Yt(t,e,o,d,c,b.poolFee,v);R=D.amountOut,M=D.priceImpact,P=`Uniswap V3 · ${(b.poolFee/1e4).toFixed(2)}%`}else if(b.kind==="bridged")R=await Xt(t,e,o,b.path,v),P=`Uniswap V3 · ${a.symbol} â USDC â ${i.symbol}`;else throw new Error("Unsupported route in VEO quote branch")}else{v=u;let k;if(b.kind==="dax")k=await ie(t,e,b,d,u),P=`VDAX pool #${b.poolId.toString()}`;else if(b.kind==="uniV3"){const Q=await Yt(t,e,o,d,c,b.poolFee,u);k=Q.amountOut,M=Q.priceImpact,P=`Uniswap V3 · ${(b.poolFee/1e4).toFixed(2)}%`}else if(b.kind==="bridged")k=await Xt(t,e,o,b.path,u),P=`Uniswap V3 · ${a.symbol} â USDC â ${i.symbol}`;else throw new Error("Unsupported route in VEO quote branch");const D=await K(t,e,s,B,k);N=D.fee,z=D.bps,R=D.amountAfterFee}if(R<=0n)throw new Error("No liquidity for this pair");return{amountIn:u,amountAfterFee:v,feeAmountIn:N,feeBps:z,feeSide:j.feeSide,feeRoute:j.feeRoute,feeDaxPoolId:j.feeDaxPoolId,uniFeeForFeeLeg:j.uniFeeForFeeLeg,amountOut:R,priceImpact:M,route:b,routeLabel:P,expiresAt:Date.now()+J}}const Po=100n;async function Vo(t,e,n){const{tokenIn:s,tokenOut:o,amountOut:a,rateHint:i}=n,u=await Ao({target:a,seedAmountIn:i&&i.amountOut>0n?i.amountIn*a/i.amountOut+1n:await _o(t,e,n),quote:d=>At(t,e,{tokenIn:s,tokenOut:o,amountIn:d}),snapUp:d=>Eo(d,s.decimals,Pn)});if(u.amountOut*10000n<a*(10000n-Po))throw new Error("Not enough liquidity to receive that amount");return u}async function _o(t,e,{tokenIn:n,tokenOut:s,amountOut:o}){try{const a=await At(t,e,{tokenIn:s,tokenOut:n,amountIn:o});if(a.amountOut>0n){const i=10000n-BigInt(a.feeBps);return a.amountOut*100000000n/(i*i)}}catch{}return 10n**BigInt(n.decimals)}const ge=1,Uo=2,Pe=3,Ct=4,Be=0,nt=1,ue=3,Ne=4,De=5,I="0x";function Vn(t,e){const n=t*BigInt(e)/10000n;return{amountAfterFee:t-n,fee:n,bps:e}}async function _n(t,e,n){return Number(await U(t,{abi:T.ValinityExchangeOfficer,address:n,functionName:"feeBps",chainId:e}))}async function Mo(t,e,n,s,o,a){try{const[i,u,d]=await U(t,{abi:T.ValinityExchangeOfficer,address:n,functionName:"previewFeeFor",args:[s,o,a],chainId:e});return{amountAfterFee:i,fee:u,bps:Number(d)}}catch{return Vn(a,await _n(t,e,n))}}async function jt(t,e,n,s){try{return await U(t,{abi:T.ValinityExchangeOfficer,address:n,functionName:"isStableAsset",args:[s],chainId:e})}catch{return!1}}async function K(t,e,n,s,o){const a=s[0],i=s[s.length-1],u=await Mo(t,e,n,a,i,o),d=s.slice(1,-1);if(d.length===0)return u;const[c,f]=await Promise.all([_n(t,e,n),Promise.all(d.map(l=>jt(t,e,n,l)))]);return u.bps>=c||f.every(Boolean)?u:Vn(o,c)}async function yt(t,e,n,s){return Je(s,e)||await jt(t,e,n,s)}
1async function zo(t,e,n,s,o){if(Je(s,e)&&Je(o,e))return!0;const[a,i]=await Promise.all([yt(t,e,n,s),yt(t,e,n,o)]);return a&&i}async function ht(t,e,n){if(wn(n,e))return{route:ge,daxPoolId:0n};const s=q[e];if(s&&n.toLowerCase()===s.toLowerCase())return{route:Pe,daxPoolId:0n};const o=await ae(t,e,n);return o.found?{route:Uo,daxPoolId:o.poolId}:{route:Ct,daxPoolId:0n}}async function Bo(t,e,n,s){const o=q[e];if(!o)throw new Error("USDC is not configured for this chain");const a=it(e);if(!a)throw new Error("Uniswap V3 quoter is not configured for this chain");try{const f=Number(await U(t,{abi:T.ValinityExchangeOfficer,address:n,functionName:"uniFeeOf",args:[s],chainId:e}));if(f>0)return f}catch{}const i=Je(s,e)||await jt(t,e,n,s),u=i?[Ze,...Se.filter(f=>f!==Ze)]:[...Se],d=await xe(t,e,a,s,o,10000n,u);if(d)return d.fee;const c=await $o(t,e,s);if(c!=null){const f=10n**BigInt(c),l=await xe(t,e,a,s,o,f,u);if(l)return l.fee}if(i)return Ze;throw new Error("No Uniswap V3 pool exists for the fee-leg token â USDC. Pick a different pair.")}async function $o(t,e,n){try{return Number(await U(t,{abi:T.ERC20,address:n,functionName:"decimals",chainId:e}))}catch{return null}}async function Gt(t,e,n,s,o,a){const i=await ht(t,e,o);let u,d,c;if(s.kind==="bridged")u=!0,d=o,c=i;else{const l=await ht(t,e,a);u=i.route<=l.route,d=u?o:a,c=u?i:l}const f=c.route===Ct?await Bo(t,e,n,d):0;return{feeSide:u?"input":"output",feeRoute:c.route,feeDaxPoolId:c.daxPoolId,uniFeeForFeeLeg:f}}async function Io(t,e,n,s,o){const{tokenIn:a,tokenOut:i,amountIn:u}=n,d=q[e];if(!d)throw new Error("USDC is not configured for this chain");const c=i.category==="stock",f=c?i:a,l=c?a:i,p=le(l.address,e),w=p.toLowerCase()===d.toLowerCase(),g=await te.getOndoPrice(f.symbol),m=g.price?Number(g.price):NaN;if(!isFinite(m)||m<=0)throw new Error(`No Ondo price for ${f.symbol}`);const x=f.address;if(c){const N=w?[p,x]:[p,d,x],{amountAfterFee:z,fee:R,bps:M}=await K(t,e,s,N,u);let P,k=0;if(w)P=z;else{const Y=await U(t,{abi:T.ValinityExchangeOfficer,address:s,functionName:"defaultUniFee",chainId:e}),Z=[Y,...Se.filter(ye=>ye!==Y)],X=await xe(t,e,o,p,d,z,Z);if(X==null)throw new Error(`No Uniswap V3 pool for ${l.symbol} â USDC`);k=X.fee,P=X.amountOut}const D=BigInt(Math.round(m*1e8)),Q=P*10n**20n/D;let G=Q-Q*We/10000n;if(G=G/10n**14n*10n**14n,G<=0n)throw new Error(`Amount too small to mint ${f.symbol}`);const ne=await ht(t,e,p);return{amountIn:u,amountAfterFee:z,feeAmountIn:R,feeBps:M,feeSide:"input",feeRoute:ne.route,feeDaxPoolId:ne.daxPoolId,uniFeeForFeeLeg:ne.route===Ct?k:0,amountOut:G,route:{kind:"ondoMint",gmToken:f.address,symbol:f.symbol,uniFeeForUSDC:k,minUsdcAfterSwap:P},routeLabel:`Ondo · ${l.symbol} â ${f.symbol}`,expiresAt:Date.now()+J}}const y=BigInt(Math.round(m*1e8)),h=u*y/10n**20n,S=h-h*Ge/10000n;if(S<=0n)throw new Error("Redeem amount too small");const L=w?[x,d]:[x,d,p],{amountAfterFee:F,fee:b,bps:j}=await K(t,e,s,L,S);let B=0,v=F;if(!w){const N=await U(t,{abi:T.ValinityExchangeOfficer,address:s,functionName:"defaultUniFee",chainId:e}),z=[N,...Se.filter(M=>M!==N)],R=await xe(t,e,o,d,p,F,z);if(R==null)throw new Error(`No Uniswap V3 pool for USDC â ${l.symbol}`);B=R.fee,v=R.amountOut}return{amountIn:u,amountAfterFee:F,feeAmountIn:w?b:0n,feeBps:j,feeSide:"output",feeRoute:Pe,feeDaxPoolId:0n,uniFeeForFeeLeg:0,amountOut:v,route:{kind:"ondoRedeem",gmToken:f.address,symbol:f.symbol,uniFeeForOut:B,minUsdcFromOndo:S},routeLabel:`Ondo · ${f.symbol} â ${l.symbol}`,expiresAt:Date.now()+J}}const Re=70n;function Xe(t){return t-t*Re/10000n}async function st(t,e,n,s){const a=await U(t,{abi:T.ValinityExchangeOfficer,address:n,functionName:"vdaoCreator",args:[s],chainId:e})!==Te;if(!a)return{isVdao:!1,isGovernance:!1};let i=!0;try{i=await U(t,{abi:T.ValinityExchangeOfficer,address:n,functionName:"isGovernanceVDAO",args:[s],chainId:e})}catch{}return{isVdao:a,isGovernance:i}}async function Ht(t,e,n,s,o,a,i){const u=ee[e],d=q[e],c=He(e);if(!u)return null;if(n.toLowerCase()===u.toLowerCase())return{legs:[],amountOut:i};if(s){if(!d||!c)return null;const l=await te.getOndoPrice(o),p=l.price?Number(l.price):NaN;if(!isFinite(p)||p<=0)return null;const w=BigInt(Math.round(p*1e8));if(a){const h=i*w/10n**20n,S=h-h*Ge/10000n;if(S<=0n)return null;const L=await de(t,e,c,[d,u],S);return L<=0n?null:{legs:[{venue:De,tokenOut:d,poolId:0n,uniFee:0,minOut:0n,data:I},{venue:ue,tokenOut:u,poolId:0n,uniFee:0,minOut:0n,data:I}
1],amountOut:L,ondoLeg:{side:"redeem",symbol:o,gmToken:n,usdcMid:S,gmOut:0n}}}const g=await de(t,e,c,[u,d],i);if(g<=0n)return null;const m=g*10n**20n/w;let x=m-m*We/10000n;return x=x/10n**14n*10n**14n,x<=0n?null:{legs:[{venue:ue,tokenOut:d,poolId:0n,uniFee:0,minOut:0n,data:I},{venue:Ne,tokenOut:n,poolId:0n,uniFee:0,minOut:0n,data:I}],amountOut:x,ondoLeg:{side:"mint",symbol:o,gmToken:n,usdcMid:g,gmOut:x}}}const f=await ot(t,e,n,a,i);return f?{legs:f.legs,amountOut:f.amountOut}:null}async function Wo(t,e,n,s,o,a){const i=ee[e];if(!i)return null;const u=le(s.address,e),d=le(o.address,e),[c,f]=await Promise.all([st(t,e,n,u),st(t,e,n,d)]);if(c.isVdao&&c.isGovernance||f.isVdao&&f.isGovernance)return null;const l=c.isVdao,p=f.isVdao;if(!l&&!p)return null;const w=l?u:Te,g=p?d:Te;if(l&&p){const L=await ae(t,e,w),F=await ae(t,e,g);if(!L.found||!F.found)return null;const b=Xe(a),j=await ie(t,e,{kind:"dax",poolId:L.poolId,asset:w},w,b);if(j<=0n)return null;const B=await ie(t,e,{kind:"dax",poolId:F.poolId,asset:g},i,j),v=Xe(B);return v<=0n?null:{amountIn:a,amountAfterFee:b,feeAmountIn:0n,feeBps:Number(Re)*2,feeSide:"input",feeRoute:ge,feeDaxPoolId:0n,uniFeeForFeeLeg:0,amountOut:v,route:{kind:"vdao",vdaoIn:w,vdaoOut:g,sideToken:Te,legs:[]},routeLabel:`${s.symbol} â VY â ${o.symbol}`,expiresAt:Date.now()+J}}if(l){const L=await ae(t,e,w);if(!L.found)return null;const F=Xe(a),b=await ie(t,e,{kind:"dax",poolId:L.poolId,asset:w},w,F);if(b<=0n)return null;const j=await Ht(t,e,d,o.category==="stock",o.symbol,!1,b);return!j||j.amountOut<=0n?null:{amountIn:a,amountAfterFee:F,feeAmountIn:a*Re/10000n,feeBps:Number(Re),feeSide:"input",feeRoute:ge,feeDaxPoolId:0n,uniFeeForFeeLeg:0,amountOut:j.amountOut,route:{kind:"vdao",vdaoIn:w,vdaoOut:Te,sideToken:d,legs:j.legs,ondoLeg:j.ondoLeg},routeLabel:`${s.symbol} â VY â ${o.symbol}`,expiresAt:Date.now()+J}}const m=await ae(t,e,g);if(!m.found)return null;const x=await Ht(t,e,u,s.category==="stock",s.symbol,!0,a);if(!x)return null;const y=x.amountOut;if(y<=0n)return null;const h=await ie(t,e,{kind:"dax",poolId:m.poolId,asset:g},i,y),S=Xe(h);return S<=0n?null:{amountIn:a,amountAfterFee:a,feeAmountIn:h*Re/10000n,feeBps:Number(Re),feeSide:"output",feeRoute:ge,feeDaxPoolId:0n,uniFeeForFeeLeg:0,amountOut:S,route:{kind:"vdao",vdaoIn:Te,vdaoOut:g,sideToken:u,legs:x.legs,ondoLeg:x.ondoLeg},routeLabel:`${s.symbol} â VY â ${o.symbol}`,expiresAt:Date.now()+J}}async function Go(t,e,n,s,o,a,i){var v;const u=(v=ee[e])==null?void 0:v.toLowerCase();if(!u)return null;const d=o.address.toLowerCase()===u,c=a.address.toLowerCase()===u,f=o.category==="stock",l=a.category==="stock";if(!(d&&l||f&&c))return null;const p=q[e],w=He(e),g=ee[e];if(!p||!w||!g)return null;const m=f?o:a,x=await te.getOndoPrice(m.symbol),y=x.price?Number(x.price):NaN;if(!isFinite(y)||y<=0)throw new Error(`No Ondo price for ${m.symbol}`);const h=BigInt(Math.round(y*1e8));if(d){const N=[g,p],z=await de(t,e,w,N,i);if(z<=0n)throw new Error("No VY â USDC liquidity for this trade");const{amountAfterFee:R,bps:M}=await K(t,e,n,[g,p,m.address],z),P=R*10n**20n/h;let k=P-P*We/10000n;if(k=k/10n**14n*10n**14n,k<=0n)throw new Error(`Amount too small to mint ${m.symbol}`);return{amountIn:i,amountAfterFee:i,feeAmountIn:0n,feeBps:M,feeSide:"input",feeRoute:Pe,feeDaxPoolId:0n,uniFeeForFeeLeg:0,amountOut:k,route:{kind:"vyStock",side:"mint",v2Router:w,v2Path:N,gmToken:m.address,symbol:m.symbol,usdcMid:z},routeLabel:`VY â USDC â ${m.symbol}`,expiresAt:Date.now()+J}}const S=i*h/10n**20n,L=S-S*Ge/10000n;if(L<=0n)throw new Error("Redeem amount too small");const{amountAfterFee:F,bps:b}=await K(t,e,n,[m.address,p,g],L),j=[p,g],B=await de(t,e,w,j,F);if(B<=0n)throw new Error("No USDC â VY liquidity for this trade");return{amountIn:i,amountAfterFee:i,feeAmountIn:0n,feeBps:b,feeSide:"output",feeRoute:Pe,feeDaxPoolId:0n,uniFeeForFeeLeg:0,amountOut:B,route:{kind:"vyStock",side:"redeem",v2Router:w,v2Path:j,gmToken:m.address,symbol:m.symbol,usdcMid:L},routeLabel:`${m.symbol} â USDC â VY`,expiresAt:Date.now()+J}}async function Ho(t,e,n,s,o,a){if(s.category!=="stock"||o.category!=="stock")return null;const i=q[e];if(!i)return null;const[u,d]=await Promise.all([te.getOndoPrice(s.symbol),te.getOndoPrice(o.symbol)]),c=u.price?Number(u.price):NaN,f=d.price?Number(d.price):NaN;if(!isFinite(c)||c<=0||!isFinite(f)||f<=0)return null;const l=BigInt(Math.round(c*1e8)),p=BigInt(Math.round(f*1e8)),w=a*l/10n**20n,g=w-w*Ge/10000n;if(g<=0n)return null;const{amountAfterFee:m,bps:x}=await K(t,e,n,[s.address,i,o.address],g),y=m*10n**20n/p;let h=y-y*We/10000n;return h=h/10n**14n*10n**14n,h<=0n?null:{amountIn:a,amountAfterFee:a,feeAmountIn:0n,feeBps:x,feeSide:"output",feeRoute:Pe,feeDaxPoolId:0n,uniFeeForFeeLeg:0,amountOut:h,route:{kind:"stockStock",gmIn:s.address,symbolIn:s.symbol,gmOut:o.address,symbolOut:o.symbol,usdcMid:g,gmOutAmount:h},routeLabel:`${s.symbol} â USDC â ${o.symbol}`,expiresAt:Date.now()+J}}async function Qo(t,e,n,s,o,a,i){const u=o.category==="stock",d=a.category==="stock";if(u===d)return null;const c=ee[e],f=q[e],l=He(e);if(!c||!f||!l)return null;const p=u?o:a,w=u?a:o,g=le(w.address,e);if(g.toLowerCase()===c.toLowerCase()||g.toLowerCase()===f.toLowerCase())return null;const m=await ae(t,e,g);if(!m.found||await Ko(t,e,s,g,f,[...Se])!=null)return null;const y=await te.getOndoPrice(p.symbol),h=y.price?Number(y.price):NaN;if(!isFinite(h)||h<=0)return null;const S=BigInt(Math.round(h*1e8)),L={kind:"dax",poolId:m.poolId,asset:g};if(u){const z=i*S/10n**20n,R=z-z*Ge/10000n;if(R<=0n)return null;const{amountAfterFee:M,bps:P}=await K(t,e,n,[p.address,f,c,g],R),k=await de(t,e,l,[f,c],M);if(k<=0n)return null;const D=await ie(t,e,L,c,k);return D<=0n?null:{amountIn:i,amountAfterFee:i,feeAmountIn:0n,feeBps:P,feeSide:"output",feeRoute:Pe,feeDaxPoolId:0n,uniFeeForFeeLeg:0,amountOut:D,route:{kind:"daxStock",side:"sell",counter:g,daxPoolId:m.poolId,gmToken:p.address,symbol:p.symbol,usdcMid:R,gmOutAmount:0n},routeLabel:`${p.symbol} â USDC â VY â ${w.symbol}`,expiresAt:Date.now()+J}}const F=await ie(t,e,L,g,i);if(F<=0n)return null;const{amountAfterFee:b,bps:j}=await K(t,e,n,[g,c,f,p.address],F),B=await de(t,e,l,[c,f],b);if(B<=0n)return null;const v=B*10n**20n/S;let N=v-v*We/10000n;return N=N/10n**14n*10n**14n,N<=0n?null:{amountIn:i,amountAfterFee:i,feeAmountIn:0n,feeBps:j,feeSide:"input",feeRoute:ge,feeDaxPoolId:0n,uniFeeForFeeLeg:0,amountOut:N,route:{kind:"daxStock",side:"buy",counter:g,daxPoolId:m.poolId,gmToken:p.address,symbol:p.symbol,usdcMid:B,gmOutAmount:N},routeLabel:`${w.symbol} â VY â USDC â ${p.symbol}`,expiresAt:Date.now()+J}}async function Qt(t,e,n,s,o){const a=ee[e];if(!a)return null;if(n.toLowerCase()===a.toLowerCase())return{legs:[],amountOut:o};const i=await ae(t,e,n);if(i.found){const d=s?n:a,c=s?a:n,f=await ie(t,e,{kind:"dax",poolId:i.poolId,asset:n},d,o);return f<=0n?null:{legs:[{venue:Be,tokenOut:c,poolId:i.poolId,uniFee:0,minOut:0n,data:I}],amountOut:f}}const u=await ot(t,e,n,s,o);return u?{legs:u.legs,amountOut:u.amountOut}:null}async function Yo(t,e,n,s,o,a){const i=ee[e];if(!i)return null;const u=le(s.address,e),d=le(o.address,e),[c,f]=await Promise.all([st(t,e,n,u),st(t,e,n,d)]),l=c.isVdao&&c.isGovernance,p=f.isVdao&&f.isGovernance;if(l===p)return null;const w=l?u:d,g=l?d:u,m=l?o:s;if(g.toLowerCase()===i.toLowerCase()||m.category==="stock")return null;const x=await ae(t,e,w);if(!x.found)return null;const y={kind:"dax",poolId:x.poolId,asset:w};if(l){const j=await ie(t,e,y,w,a);if(j<=0n)return null;const{amountAfterFee:B,bps:v}=await K(t,e,n,[w,i,g],j),N=await Qt(t,e,g,!1,B);if(!N||N.amountOut<=0n)return null;const z=[{venue:Be,tokenOut:i,poolId:x.poolId,uniFee:0,minOut:0n,data:I},...N.legs];return{amountIn:a,amountAfterFee:a,feeAmountIn:0n,feeBps:v,feeSide:"input",feeRoute:ge,feeDaxPoolId:0n,uniFeeForFeeLeg:0,amountOut:N.amountOut,route:{kind:"govVdao",side:"sell",gov:w,govPoolId:x.poolId,counter:g,legs:z,feeCheckpoint:1},routeLabel:`${s.symbol} â VY â ${o.symbol}`,expiresAt:Date.now()+J}}const h=await Qt(t,e,g,!0,a);if(!h||h.amountOut<=0n)return null;const{amountAfterFee:S,bps:L}=await K(t,e,n,[g,i,w],h.amountOut),F=await ie(t,e,y,i,S);if(F<=0n)return null;const b=[...h.legs,{venue:Be,tokenOut:w,poolId:x.poolId,uniFee:0,minOut:0n,data:I}];return{amountIn:a,amountAfterFee:a,feeAmountIn:0n,feeBps:L,feeSide:"input",feeRoute:ge,feeDaxPoolId:0n,uniFeeForFeeLeg:0,amountOut:F,route:{kind:"govVdao",side:"buy",gov:w,govPoolId:x.poolId,counter:g,legs:b,feeCheckpoint:h.legs.length},routeLabel:`${s.symbol} â VY â ${o.symbol}`,expiresAt:Date.now()+J}}async function Xo(t,e,n,s,o,a){var F;const i=(F=ee[e])==null?void 0:F.toLowerCase(),u=s.toLowerCase(),d=o.toLowerCase();if(i&&(u===i||d===i)){const b=u===i?o:s,j=await ae(t,e,b);if(j.found)return{kind:"dax",poolId:j.poolId,asset:b}}const c=await U(t,{abi:T.ValinityExchangeOfficer,address:n,chainId:e,functionName:"defaultUniFee"}),f=await zo(t,e,n,s,o),l=f?Ze:c,p=[l,...Se.filter(b=>b!==l)],w=it(e),g=q[e],m=!f||!!g&&await yt(t,e,n,g),[x,y]=await Promise.all([xe(t,e,w,s,o,a,p),g&&m&&u!==g.toLowerCase()&&d!==g.toLowerCase()?xe(t,e,w,s,g,a,p):Promise.resolve(null)]);let h=null;if(y&&g){const b=await xe(t,e,w,g,o,y.amountOut,p);b&&(h={feeIn:y.fee,feeOut:b.fee,amountOut:b.amountOut})}const S=(x==null?void 0:x.amountOut)??-1n,L=(h==null?void 0:h.amountOut)??-1n;if(x&&S>=L)return{kind:"uniV3",poolFee:x.fee};if(h&&g)return{kind:"bridged",path:yo(["address","uint24","address","uint24","address"],[s,h.feeIn,g,h.feeOut,o]),midToken:g,feeIn:h.feeIn,feeOut:h.feeOut};throw g?new Error("No Uniswap V3 pool found for this pair"):new Error("No bridge token configured for this chain")}async function Ko(t,e,n,s,o,a){for(const i of a)if(await Lt(t,e,n,s,o,i,10000n)!=null)return i;return null}function Et(t,e){const n=bs(t,{chainId:e});if(!n)throw new Error("Swap is not supported on this network");return n}async function Lt(t,e,n,s,o,a,i){try{const{result:u}=await Et(t,e).simulateContract({abi:T.UniswapV3QuoterV2,address:n,functionName:"quoteExactInputSingle",args:[{tokenIn:s,tokenOut:o,amountIn:i,fee:a,sqrtPriceLimitX96:0n}]}),[d]=u;return d>0n?d:null}catch{return null}}async function xe(t,e,n,s,o,a,i){const u=await Promise.all(i.map(async c=>({fee:c,out:await Lt(t,e,n,s,o,c,a)})));let d=null;for(const c of u)c.out!=null&&(d===null||c.out>d.amountOut)&&(d={fee:c.fee,amountOut:c.out});return d}async function Yt(t,e,n,s,o,a,i){const u=i/1000n,[{result:d},c]=await Promise.all([Et(t,e).simulateContract({abi:T.UniswapV3QuoterV2,address:n,functionName:"quoteExactInputSingle",args:[{tokenIn:s,tokenOut:o,amountIn:i,fee:a,sqrtPriceLimitX96:0n}]}),u>0n?Lt(t,e,n,s,o,a,u):Promise.resolve(null)]),[f]=d;return{amountOut:f,priceImpact:Zo(i,f,u,c)}}function Zo(t,e,n,s){if(t<=0n||e<=0n||n<=0n||s==null||s<=0n||s<1000n)return;const o=10n**36n,a=e*o/t,i=s*o/n;if(i<=0n||a<=0n)return;const u=Number((i-a)*10000n/i)/100;return u>0?u:0}
1async function Xt(t,e,n,s,o){const{result:a}=await Et(t,e).simulateContract({abi:T.UniswapV3QuoterV2,address:n,functionName:"quoteExactInput",args:[s,o]}),[i]=a;return i}async function de(t,e,n,s,o){try{const a=await U(t,{abi:T.UniswapV2Router02,address:n,functionName:"getAmountsOut",args:[o,[...s]],chainId:e});return a[a.length-1]??0n}catch{return 0n}}async function qo(t,e,n,s,o,a){const i=ee[e],u=q[e];if(!i||!u)return null;const d=le(s.address,e),c=le(o.address,e),f=d.toLowerCase()===i.toLowerCase(),l=c.toLowerCase()===i.toLowerCase();if(f===l)return null;const p=f?c:d;if(p.toLowerCase()===u.toLowerCase()||(await ae(t,e,p)).found)return null;const g=f?"sell":"buy";let m,x,y,h,S,L,F;if(g==="buy"){const b=await ot(t,e,p,!0,a);if(!b||b.assetTier==null)return null;const j=await K(t,e,n,[p,u,i],b.amountOut);x=b.assetTier,h=a,S=j.fee,L=j.bps,y=j.amountAfterFee,F=b.legs.length,m=b.legs}else{const b=await K(t,e,n,[i,u,p],a),j=await ot(t,e,p,!1,b.amountAfterFee);if(!j||j.assetTier==null)return null;x=j.assetTier,h=b.amountAfterFee,S=b.fee,L=b.bps,y=j.amountOut,F=0,m=j.legs}return{amountIn:a,amountAfterFee:h,feeAmountIn:S,feeBps:L,feeSide:g==="buy"?"output":"input",feeRoute:ge,feeDaxPoolId:0n,uniFeeForFeeLeg:0,amountOut:y,route:{kind:"publicVy",side:g,asset:p,assetTier:x,legs:m,feeCheckpoint:F},routeLabel:g==="buy"?`${s.symbol} â USDC â VY`:`VY â USDC â ${o.symbol}`,expiresAt:Date.now()+J}}async function Un(t,e,n,s,o){var g;const a=(g=ee[e])==null?void 0:g.toLowerCase();if(!a)return null;const i=n.toLowerCase(),u=s.toLowerCase();if(i!==a&&u!==a||(await ae(t,e,i===a?s:n)).found)return null;const f=He(e);if(!f)return null;const l=q[e],p=ze(e),w=[{path:[n,s],midSymbol:""}];l&&i!==l.toLowerCase()&&u!==l.toLowerCase()&&w.push({path:[n,l,s],midSymbol:"USDC"}),p&&i!==p.toLowerCase()&&u!==p.toLowerCase()&&w.push({path:[n,p,s],midSymbol:"WETH"});for(const m of w){const x=await de(t,e,f,m.path,o);if(x>0n)return{router:f,path:m.path,amountOut:x,midSymbol:m.midSymbol}}return null}async function ot(t,e,n,s,o){const a=ee[e],i=q[e],u=it(e),d=He(e);if(!a||!i||!d)return null;const c=s?n:a,f=s?a:n;if((await ae(t,e,n)).found)return null;const l=await Un(t,e,c,f,o),p=l?{legs:l.path.slice(1).map(g=>({venue:ue,tokenOut:g,poolId:0n,uniFee:0,minOut:0n,data:I})),amountOut:l.amountOut,assetTier:null}:null;if(!u||n.toLowerCase()===i.toLowerCase())return p;const w=s?await(async()=>{const g=await xe(t,e,u,n,i,o,[...Se]);if(!g||g.amountOut<=0n)return null;const m=await de(t,e,d,[i,a],g.amountOut);return m<=0n?null:{legs:[{venue:nt,tokenOut:i,poolId:0n,uniFee:g.fee,minOut:0n,data:I},{venue:ue,tokenOut:a,poolId:0n,uniFee:0,minOut:0n,data:I}],amountOut:m,assetTier:g.fee}})():await(async()=>{const g=await de(t,e,d,[a,i],o);if(g<=0n)return null;const m=await xe(t,e,u,i,n,g,[...Se]);return!m||m.amountOut<=0n?null:{legs:[{venue:ue,tokenOut:i,poolId:0n,uniFee:0,minOut:0n,data:I},{venue:nt,tokenOut:n,poolId:0n,uniFee:m.fee,minOut:0n,data:I}],amountOut:m.amountOut,assetTier:m.fee}})();return!w||p&&p.amountOut>=w.amountOut?p:w}async function ie(t,e,n,s,o){var p,w;const a=(p=Ve[e.toString()])==null?void 0:p.ValinityDAX;if(!a)throw new Error("DAX is not configured for this chain");const[,i,u]=await U(t,{abi:T.ValinityDAX,address:a,functionName:"getPoolReserves",args:[n.poolId],chainId:e}),d=(w=ee[e])==null?void 0:w.toLowerCase(),c=s.toLowerCase()===d,f=c?i:u,l=c?u:i;return f===0n||l===0n?0n:l*o/(f+o)}
1const Kt=new Set(["registering","wrapping","approving","sending","unwrapping"]);function Jo(){const t=$e(),{address:e}=at(),n=Ee(),s=xs(),[o,a]=O.useState("idle"),[i,u]=O.useState(null),[d,c]=O.useState(null);O.useEffect(()=>{s({transactionBusy:Kt.has(o)})},[o]),O.useEffect(()=>()=>s({transactionBusy:!1}),[]);const f=fn(),l=O.useRef("idle");O.useEffect(()=>{const m=Kt.has(l.current)&&(o==="success"||o==="error");l.current=o,m&&ko(f)},[o,f]);const p=()=>{a("idle"),u(null),c(null)};return{approve:async(m,x)=>{if(we(x.address)||m.route.kind==="wrap")return!0;const y=Me(n);if(!e||!y)return c(new Error(e?"Swap is not supported on this network":"No wallet connected")),a("error"),!1;c(null);try{return await nr(t,n,e,x.address,y,m.amountIn,a),!0}catch(h){return a("error"),c(h instanceof Error?h:new Error(String(h))),!1}},execute:async(m,x,y,h="auto")=>{if(!e)throw new Error("No wallet connected");if(p(),m.route.kind==="wrap"){try{const v=ze(n);if(!v)throw new Error("WETH is not configured for this chain");let N;m.route.direction==="deposit"?(a("wrapping"),N=await _e(t,{abi:T.WETH,address:v,functionName:"deposit",args:[],value:m.amountIn,chainId:n,...await Ue(t,{chainId:n,call:{to:v,data:je({abi:T.WETH,functionName:"deposit",args:[]}),value:m.amountIn}})})):(a("unwrapping"),N=await _e(t,{abi:T.WETH,address:v,functionName:"withdraw",args:[m.amountIn],chainId:n,...await Ue(t,{chainId:n,call:{to:v,data:je({abi:T.WETH,functionName:"withdraw",args:[m.amountIn]})}})})),u(N),await et(t,{hash:N,chainId:n}),a("success")}catch(v){a("error"),c(v instanceof Error?v:new Error(String(v)))}return}const S=Me(n);if(!S)throw new Error("Swap is not supported on this network");const L=we(x.address),F=we(y.address),b=ze(n);if((L||F)&&!b)throw new Error("WETH is not configured for this chain");const j=L?b:x.address,B=F?b:y.address;try{const[v,N]=await Promise.all([U(t,{abi:T.ValinityExchangeOfficer,address:S,functionName:"isRegistered",args:[e],chainId:n}),U(t,{abi:T.ValinityExchangeOfficer,address:S,functionName:"openTrading",chainId:n})]);if(!N&&!v)throw new Error("This wallet is not registered on the Valinity Exchange. Purchase VARO Tier 1 to enable swaps.");const z=er(m.priceImpact,h),R=ys(m.amountOut,z),M=0n,P=hs(),k=L?[]:await tr(t,n,e,j,S,m.amountIn),D=await sr({config:t,chainId:n,veo:S,quote:m,tokenInAddress:j,tokenOutAddress:B,minAmountOut:R,minFeeVYOut:M,ethIn:L,unwrapOut:F,deadline:P}),Q=je({abi:T.ValinityExchangeOfficer,functionName:D.functionName,args:D.args}),G=[...k],ne=G.length;G.push({to:D.address,data:Q,value:D.value}),a(k.length?"approving":"sending");const Y=await Ss(t,{chainId:n,from:e,calls:G}),Z=ke=>{if(ke.status!=="success")throw new Error("The swap transaction reverted on-chain. Please try again.");u(ke.transactionHash),a("success")},X=Y.receipts[ne];if(X){Z(X);return}if(Y.status===200)throw new Error("Your swap was submitted but we could not read the result â check your balance before trying again.");const ye=k.length?Y.receipts[k.length-1]:void 0;if(ye&&ye.status!=="success")throw new Error("The token approval reverted on-chain. Please try again.");a("sending");const oe=await _e(t,{abi:T.ValinityExchangeOfficer,address:D.address,functionName:D.functionName,args:D.args,value:D.value,chainId:n,...await Ue(t,{chainId:n,call:{to:D.address,data:Q,value:D.value}})});u(oe);const ve=await et(t,{hash:oe,chainId:n});Z(ve)}catch(v){a("error"),c(v instanceof Error?v:new Error(String(v)))}},step:o,txHash:i,error:d,reset:p}}function er(t,e){return vt(t,e)}async function tr(t,e,n,s,o,a){const i=await U(t,{abi:T.ERC20,address:s,functionName:"allowance",args:[n,o],chainId:e});if(i>=a)return[];const u=[];return gn(s,e)&&i>0n&&u.push({to:s,data:je({abi:T.ERC20,functionName:"approve",args:[o,0n]})}),u.push({to:s,data:je({abi:T.ERC20,functionName:"approve",args:[o,gt]})}),u}async function nr(t,e,n,s,o,a,i){const u=await U(t,{abi:T.ERC20,address:s,functionName:"allowance",args:[n,o],chainId:e});if(u>=a)return;if(i("approving"),gn(s,e)&&u>0n){const c=await _e(t,{abi:T.ERC20,address:s,functionName:"approve",args:[o,0n],chainId:e,...await Ue(t,{chainId:e,call:{to:s,data:je({abi:T.ERC20,functionName:"approve",args:[o,0n]})}})});await et(t,{hash:c,chainId:e})}const d=await _e(t,{abi:T.ERC20,address:s,functionName:"approve",args:[o,gt],chainId:e,...await Ue(t,{chainId:e,call:{to:s,data:je({abi:T.ERC20,functionName:"approve",args:[o,gt]})}})});await et(t,{hash:d,chainId:e})}async function sr(t){const{chainId:e,veo:n,quote:s,tokenInAddress:o,tokenOutAddress:a,minAmountOut:i,minFeeVYOut:u,ethIn:d,unwrapOut:c,deadline:f}=t,{route:l,amountIn:p}=s,w={fromInput:s.feeSide==="input",route:s.feeRoute,daxPoolId:s.feeDaxPoolId,uniFee:s.uniFeeForFeeLeg,minVYOut:u},g=d?p:void 0;if(l.kind==="uniV3")return{address:n,functionName:"vySwapUniV3",args:[o,a,l.poolFee,p,i,w,d,c,f],value:g};if(l.kind==="bridged")return{address:n,functionName:"vySwapBridged",args:[l.path,o,p,i,w,d,c,f],value:g};if(l.kind==="dax"){const m=wn(o,e);return{address:n,functionName:"vySwapDAX",args:[o,m?l.asset:ee[e],p,i,l.poolId,w,d,c,f],value:g}}if(l.kind==="vdao"){let m=l.legs;if(l.ondoLeg){const x=l.ondoLeg,y=await te.postOndoQuote({side:x.side,symbol
1:x.symbol,gmAmount:(x.side==="redeem"?p:x.gmOut).toString(),counterAmount:x.usdcMid.toString()}),h=x.side==="redeem"?De:Ne;m=l.legs.map(S=>S.venue===h?{...S,data:y.calldata}:S)}return{address:n,functionName:"vySwapVDAO",args:[l.vdaoIn,l.vdaoOut,l.sideToken,p,m,d,c,i,f],value:g}}if(l.kind==="v2"){const m=[];for(let y=1;y<l.path.length;y++)m.push({venue:ue,tokenOut:l.path[y],poolId:0n,uniFee:0,minOut:y===l.path.length-1?i:0n,data:I});const x=s.feeSide==="input"?0n:BigInt(m.length);return{address:n,functionName:"vySwapRoute",args:[o,p,m,w,x,d,c,i,f],value:g}}if(l.kind==="vyStock"){const m=q[e];if(!m)throw new Error("Swap is not supported on this network");const x=ee[e];if(l.side==="redeem"){const L=await te.postOndoQuote({side:"redeem",symbol:l.symbol,gmAmount:p.toString(),counterAmount:l.usdcMid.toString()}),F=[{venue:De,tokenOut:m,poolId:0n,uniFee:0,minOut:0n,data:L.calldata},{venue:ue,tokenOut:x,poolId:0n,uniFee:0,minOut:i,data:I}];return{address:n,functionName:"vySwapRoute",args:[l.gmToken,p,F,w,1n,!1,!1,i,f]}}const{amountAfterFee:y}=await K(t.config,e,n,[x,m,l.gmToken],l.usdcMid),h=await te.postOndoQuote({side:"mint",symbol:l.symbol,gmAmount:s.amountOut.toString(),counterAmount:y.toString()}),S=[{venue:ue,tokenOut:m,poolId:0n,uniFee:0,minOut:0n,data:I},{venue:Ne,tokenOut:l.gmToken,poolId:0n,uniFee:0,minOut:i,data:h.calldata}];return{address:n,functionName:"vySwapRoute",args:[x,p,S,w,1n,!1,!1,i,f]}}if(l.kind==="stockStock"){const m=q[e];if(!m)throw new Error("Swap is not supported on this network");const x=await te.postOndoQuote({side:"redeem",symbol:l.symbolIn,gmAmount:p.toString(),counterAmount:l.usdcMid.toString()}),{amountAfterFee:y}=await K(t.config,e,n,[l.gmIn,m,l.gmOut],l.usdcMid),h=await te.postOndoQuote({side:"mint",symbol:l.symbolOut,gmAmount:l.gmOutAmount.toString(),counterAmount:y.toString()}),S=[{venue:De,tokenOut:m,poolId:0n,uniFee:0,minOut:0n,data:x.calldata},{venue:Ne,tokenOut:l.gmOut,poolId:0n,uniFee:0,minOut:i,data:h.calldata}];return{address:n,functionName:"vySwapRoute",args:[l.gmIn,p,S,w,1n,!1,!1,i,f]}}if(l.kind==="daxStock"){const m=q[e];if(!m)throw new Error("Swap is not supported on this network");const x=ee[e];if(l.side==="sell"){const S=await te.postOndoQuote({side:"redeem",symbol:l.symbol,gmAmount:p.toString(),counterAmount:l.usdcMid.toString()}),L=[{venue:De,tokenOut:m,poolId:0n,uniFee:0,minOut:0n,data:S.calldata},{venue:ue,tokenOut:x,poolId:0n,uniFee:0,minOut:0n,data:I},{venue:Be,tokenOut:l.counter,poolId:l.daxPoolId,uniFee:0,minOut:i,data:I}];return{address:n,functionName:"vySwapRoute",args:[l.gmToken,p,L,w,1n,!1,!1,i,f]}}const y=await te.postOndoQuote({side:"mint",symbol:l.symbol,gmAmount:l.gmOutAmount.toString(),counterAmount:l.usdcMid.toString()}),h=[{venue:Be,tokenOut:x,poolId:l.daxPoolId,uniFee:0,minOut:0n,data:I},{venue:ue,tokenOut:m,poolId:0n,uniFee:0,minOut:0n,data:I},{venue:Ne,tokenOut:l.gmToken,poolId:0n,uniFee:0,minOut:i,data:y.calldata}];return{address:n,functionName:"vySwapRoute",args:[l.counter,p,h,w,1n,d,!1,i,f],value:g}}if(l.kind==="publicVy"){const m=l.legs.map((x,y)=>y===l.legs.length-1?{...x,minOut:i}:x);return{address:n,functionName:"vySwapRoute",args:[o,p,m,w,BigInt(l.feeCheckpoint),d,c,i,f],value:g}}if(l.kind==="govVdao"){const m=l.side==="buy"?l.counter:l.gov;return{address:n,functionName:"vySwapRoute",args:[m,p,l.legs,w,BigInt(l.feeCheckpoint),d,c,i,f],value:g}}if(l.kind==="ondoRedeem"){const m=q[e],x=await te.postOndoQuote({side:"redeem",symbol:l.symbol,gmAmount:p.toString(),counterAmount:l.minUsdcFromOndo.toString()}),y=[{venue:De,tokenOut:m,poolId:0n,uniFee:0,minOut:0n,data:x.calldata}];return a.toLowerCase()===m.toLowerCase()?y[0].minOut=i:y.push({venue:nt,tokenOut:a,poolId:0n,uniFee:l.uniFeeForOut,minOut:i,data:I}),{address:n,functionName:"vySwapRoute",args:[l.gmToken,p,y,w,1n,!1,c,i,f]}}if(l.kind==="ondoMint"){const m=q[e],x=await te.postOndoQuote({side:"mint",symbol:l.symbol,gmAmount:s.amountOut.toString(),counterAmount:l.minUsdcAfterSwap.toString()}),y=[];return o.toLowerCase()===m.toLowerCase()||y.push({venue:nt,tokenOut:m,poolId:0n,uniFee:l.uniFeeForUSDC,minOut:0n,data:I}),y.push({venue:Ne,tokenOut:l.gmToken,poolId:0n,uniFee:0,minOut:i,data:x.calldata}),{address:n,functionName:"vySwapRoute",args:[o,p,y,w,0n,d,!1,i,f],value:g}}throw new Error("Unsupported route for VEO broadcast")}const or=({quote:t,tokenIn:e,tokenOut:n,isFetching:s,effectiveSlippage:o})=>{const{t:a}=be(),[i,u]=O.useState(0);O.useEffect(()=>{const S=()=>{const F=Math.max(0,Math.round((t.expiresAt-Date.now())/1e3));u(F)};S();const L=setInterval(S,1e3);return()=>clearInterval(L)},[t.expiresAt]);const d=t.priceImpact,c=d===void 0?"gray.600":d>=5?"red.500":d>=1?"orange.400":"green.500",f=me(t.amountOut,n.decimals),l=parseFloat(f).toLocaleStr
1ing(void 0,{maximumFractionDigits:6}),p=t.feeSide==="input"?e:n,w=`${(t.feeBps/100).toFixed(2)}%`,g=t.feeAmountIn>0n?`${parseFloat(me(t.feeAmountIn,p.decimals)).toLocaleString(void 0,{maximumFractionDigits:6})} ${p.symbol} · `:"",m=Number(me(t.amountIn,e.decimals)),x=Number(me(t.amountOut,n.decimals)),y=m>0?x/m:0,h=y>0?`1 ${e.symbol} = ${y.toLocaleString(void 0,{maximumSignificantDigits:6})} ${n.symbol}`:"â";return r.jsxs(W,{bg:"gray.50",borderRadius:"xl",px:4,py:3,fontSize:"sm",children:[r.jsxs(_,{justify:"space-between",align:"center",mb:2,children:[r.jsx(A,{color:"gray.600",children:a("views.swap.youReceive")}),s?r.jsx(tt,{h:"18px",w:"80px"}):r.jsxs(A,{fontWeight:"bold",children:[l," ",n.symbol]})]}),r.jsxs(_,{justify:"space-between",align:"center",mb:2,children:[r.jsx(A,{color:"gray.600",children:a("views.swap.rate")}),r.jsx(A,{color:"gray.700",fontSize:"xs",textAlign:"right",maxW:"60%",children:h})]}),r.jsxs(_,{justify:"space-between",align:"center",mb:2,children:[r.jsx(A,{color:"gray.600",children:a("views.swap.route")}),r.jsx(A,{color:"gray.700",fontSize:"xs",textAlign:"right",maxW:"60%",children:t.routeLabel})]}),r.jsxs(_,{justify:"space-between",align:"center",mb:2,children:[r.jsx(A,{color:"gray.600",children:a("views.swap.protocolFee")}),r.jsxs(A,{color:"gray.700",fontSize:"xs",textAlign:"right",maxW:"60%",children:[g,w]})]}),r.jsxs(_,{justify:"space-between",align:"center",mb:2,children:[r.jsx(A,{color:"gray.600",children:a("views.swap.priceImpact")}),r.jsxs(_,{align:"center",gap:1,children:[r.jsx(A,{fontWeight:"semibold",color:c,children:d===void 0?"â":`${d.toFixed(2)}%`}),d!==void 0&&d>=5&&r.jsx(A,{fontSize:"xs",color:"red.500",children:"â "})]})]}),r.jsxs(_,{justify:"space-between",align:"center",mb:2,children:[r.jsx(A,{color:"gray.600",children:a("views.swap.slippageTolerance")}),r.jsxs(A,{color:"gray.700",children:[o.toFixed(1),"%"]})]}),r.jsxs(_,{justify:"space-between",align:"center",children:[r.jsx(A,{color:"gray.600",children:a("views.swap.quoteExpires")}),r.jsxs(_,{align:"center",gap:1,children:[s&&r.jsx(Ie,{size:"xs",color:"blue.400"}),r.jsxs(A,{color:i<=15?"orange.500":"gray.600",children:[i,"s"]})]})]})]})},rr=()=>r.jsx(W,{bg:"gray.50",borderRadius:"xl",px:4,py:3,children:[...Array(7)].map((t,e)=>r.jsxs(_,{justify:"space-between",align:"center",mb:e<6?2:0,children:[r.jsx(tt,{h:"14px",w:"80px"}),r.jsx(tt,{h:"14px",w:"80px"})]},e))}),ar=[.5,1,2.5,5],ir=({value:t,priceImpact:e,onChange:n})=>{const{t:s}=be(),o=e!==void 0?vt(e,t):t==="auto"?As:t,a=t==="auto"?`${s("views.swap.slippageAuto")} (${o.toFixed(1)}%)`:`${t}%`,i=o>=Cs;return r.jsxs(uo,{placement:"bottom-end",children:[r.jsx(co,{children:r.jsxs(_,{align:"center",gap:1,cursor:"pointer",color:"gray.500",_hover:{color:"blue.500"},role:"button",children:[r.jsx(A,{fontSize:"xs",children:a}),r.jsx(xn,{"aria-label":s("views.swap.slippageSettings"),icon:r.jsx(ce,{as:Os,boxSize:3.5}),size:"xs",variant:"ghost",color:"inherit",minW:"auto",h:"auto"})]})}),r.jsxs(lo,{w:"240px",shadow:"lg",children:[r.jsx(fo,{fontSize:"sm",fontWeight:"semibold",children:s("views.swap.slippageSettings")}),r.jsxs(po,{children:[r.jsxs(Fs,{size:"xs",isAttached:!0,variant:"outline",w:"full",mb:i?3:0,children:[r.jsx(pe,{onClick:()=>n("auto"),colorScheme:t==="auto"?"blue":void 0,variant:t==="auto"?"solid":"outline",flex:1,children:s("views.swap.slippageAuto")}),ar.map(u=>r.jsxs(pe,{onClick:()=>n(u),colorScheme:t===u?"blue":void 0,variant:t===u?"solid":"outline",flex:1,children:[u,"%"]},u))]}),i&&r.jsxs(Fe,{status:"warning",borderRadius:"md",fontSize:"xs",py:1.5,px:2,mb:t==="auto"&&e!==void 0?2:0,children:[r.jsx(Ae,{boxSize:3}),r.jsx(Ce,{children:s("views.swap.slippageHighWarning")})]}),t==="auto"&&e!==void 0&&r.jsx(W,{mt:i?0:2,children:r.jsxs(A,{fontSize:"xs",color:"gray.500",children:[s("views.swap.slippageEffective"),": ",o.toFixed(1),"%"," ","(impact ",e.toFixed(2),"% + 1%)"]})})]})]})]})},Zt={idle:"views.swap.swapNow",registering:"views.swap.registering",wrapping:"views.swap.wrapping",approving:"views.swap.approving",sending:"views.swap.sending",unwrapping:"views.swap.unwrapping",success:"views.swap.success",error:"views.swap.swapNow"},ur=({step:t,txHash:e,isDisabled:n,needsApproval:s,approveSymbol:o,insufficientBalanceSymbol
1:a,onApprove:i,onClick:u,onNewSwap:d})=>{const{t:c}=be(),f=Ee(),l=["registering","wrapping","approving","sending","unwrapping"].includes(t);if(t==="success"&&e){const w=f===bn.id?"https://etherscan.io/tx/":"https://sepolia.etherscan.io/tx/";return r.jsxs(_,{direction:"column",align:"center",gap:3,children:[r.jsxs(_,{align:"center",gap:2,children:[r.jsx(ce,{as:js,color:"green.500",boxSize:6}),r.jsx(A,{fontWeight:"semibold",color:"green.600",children:c("views.swap.transactionSent")})]}),r.jsxs(yn,{href:`${w}${e}`,isExternal:!0,color:"blue.600",fontSize:"sm",display:"flex",alignItems:"center",gap:1,children:[c("views.swap.viewOnEtherscan"),r.jsx(ce,{as:hn,boxSize:3})]}),r.jsx(pe,{w:"full",size:"lg",variant:"outline",colorScheme:"blue",leftIcon:r.jsx(ce,{as:Es,boxSize:5}),onClick:d,children:c("views.swap.newSwap")})]})}return l?r.jsx(pe,{w:"full",size:"lg",colorScheme:"blue",isDisabled:!0,leftIcon:r.jsx(Ie,{size:"sm"}),children:c(Zt[t])}):a?r.jsx(pe,{w:"full",size:"lg",colorScheme:"blue",isDisabled:!0,children:c("views.swap.insufficientBalance",{symbol:a})}):s?r.jsx(pe,{w:"full",size:"lg",colorScheme:"blue",isDisabled:n,onClick:i,leftIcon:r.jsx(ce,{as:Ls,boxSize:5}),children:c("views.swap.approveToken",{symbol:o??""})}):r.jsx(pe,{w:"full",size:"lg",colorScheme:"blue",isDisabled:n,onClick:u,children:c(Zt[t])})};function cr(t){if(t.category!=="stock")return t.logoUrl?[t.logoUrl]:[];const e=[`https://cdn.ondo.finance/tokens/logos/${t.symbol.toLowerCase()}_160x160.png`],n=t.symbol.replace(/on$/i,"").toUpperCase();return n&&(e.push(`https://assets.parqet.com/logos/symbol/${n}`),e.push(`https://financialmodelingprep.com/image-stock/${n}.png`),e.push(`https://eodhd.com/img/logos/US/${n.toLowerCase()}.png`)),e}const rt=({token:t,boxSize:e="36px",fontSize:n})=>r.jsx(Sn,{symbol:t.symbol,address:t.category==="stock"?void 0:t.address,src:cr(t),boxSize:e,borderRadius:"full",chipFontSize:n}),lr=Ot` 2 0%, 100% { box-shadow: 0 0 22px 0 rgba(222, 203, 156, 0.40); } 3 50% { box-shadow: 0 0 42px 8px rgba(222, 203, 156, 0.72); } 4`,dr="0 0 0 1px rgba(0,0,0,0.05), 0 4px 10px -5px rgba(15,23,42,0.25)",St=t=>t.toLocaleString(void 0,{maximumFractionDigits:6}),fr=({isOpen:t,onClose:e,onTradeAgain:n,tokenIn:s,tokenOut:o,amountInDisplay:a,amountOutDisplay:i,routeLabel:u,txHash:d})=>{const{t:c}=be(),l=Ee()===bn.id?"https://etherscan.io/tx/":"https://sepolia.etherscan.io/tx/",p=parseFloat(a)||0,w=parseFloat(i)||0,g=p>0?w/p:0;return r.jsxs(mo,{isOpen:t,onClose:e,children:[r.jsx(A,{fontSize:"xs",letterSpacing:"0.22em",textTransform:"uppercase",fontWeight:"bold",color:"gold.600",children:c("views.swap.successCard.eyebrow")}),r.jsxs(xt,{spacing:4,justify:"center",children:[r.jsx(W,{borderRadius:"full",boxShadow:dr,children:r.jsx(rt,{token:s,boxSize:"56px",fontSize:"14px"})}),r.jsx(ce,{as:ks,boxSize:6,color:"gold.600"}),r.jsx(W,{borderRadius:"full",animation:`${lr} 2.4s ease-in-out infinite`,children:r.jsx(rt,{token:o,boxSize:"56px",fontSize:"14px"})})]}),r.jsxs(W,{children:[r.jsxs(xt,{spacing:2,justify:"center",align:"baseline",children:[r.jsx(pr,{value:w}),r.jsx(A,{fontSize:"2xl",fontWeight:"extrabold",bgGradient:"linear(to-r, gold.400, gold.600)",bgClip:"text",children:o.symbol})]}),r.jsx(A,{mt:1,fontSize:"sm",color:"gray.600",children:c("views.swap.successCard.received")}),r.jsx(A,{mt:1,fontSize:"sm",color:"gray.500",children:c("views.swap.successCard.forAmount",{amount:St(p),symbol:s.symbol})})]}),r.jsxs(Ft,{spacing:2,w:"full",children:[r.jsx(qt,{label:c("views.swap.successCard.route"),value:u}),g>0&&r.jsx(qt,{label:c("views.swap.successCard.rate"),value:`1 ${s.symbol} â ${St(g)} ${o.symbol}`})]}),d&&r.jsxs(yn,{href:`${l}${d}`,isExternal:!0,color:"blue.600",fontSize:"sm",display:"flex",alignItems:"center",gap:1,children:[c("views.swap.viewOnEtherscan"),r.jsx(ce,{as:hn,boxSize:3})]}),r.jsx(pe,{w:"full",size:"lg",color:"white",fontWeight:"bold",border:"none",textShadow:"0 1px 2px rgba(0,0,0,0.4)",_hover:{filter:"brightness(1.06)"},_active:{filter:"brightness(0.97)"},sx:{backgroundImage:"linear-gradient(120deg, #AE905D, #C4A76F, #D4B978, #C4A76F, #AE905D, #977B4B, #AE905D, #C4A76F, #D4B978, #C4A76F, #AE905D)",backgroundSize:"200% 100%",animation:`${mr} 4s ease-in-out infinite alternate`,boxShadow:"0 10px 26px -8px rgba(151,123,75,0.6)"},onClick:n,children:c("views.swap.successCard.tradeAgain")})]})},qt=({label:t,value:e})=>r.jsxs(_,{className:"vy-gold-frame",position:"relative",w:"full",justify:"space-between",align:"center",px:3.5,py:2.5,borderRadius:"lg",bgGradient:"linear(to-b, #FFFFFF, #EEF0F2)",boxShadow:"inset 0 1px 0 rgba(255,255,255,0.9), 0 1px 2px rgba(15,23,42,0.06)",children:[r.jsx(A,{fontSize:"xs",fontWeight:"medium",color:"gray.600",children:t}),r.jsx(A,{fontSize:"sm",fontWeight:"bold",color:"blue.800",noOfLines:1,ml:3,children:e})]}),pr=({value:t})=>{const[e,n]=O.useState("0");return O.useEffect(()=>{const s=wo(0,t,{duration:1.1,ease:"easeOut",onUpdate:o=>n(St(o))});return()=>s.stop()},[t]),r.jsx(A,{fontSize:"4xl",fontWeight:"extrabold",lineHeight:"1.05",bgGradient:"linear(to-r, gold.400, gold.600)",bgClip:"text",sx:{fontVariantNumeric:"tabular-nums"},children:e})},mr=Ot` 5 0% { background-position: 0% 50%; } 6 100% { background-position: 100% 50%; } 7`,wr="https://tokens.uniswap.org";function gr(t){return t?t.startsWith("ipfs://")?`https://ipfs.io/ipfs/${t.replace(/^ipfs:\/\/(ipfs\/)?/,"")}`:t:""}function xr(t,e=!0){return Le({queryKey:["uniswap","tokenList",t],queryFn:async()=>{const n=await fetch(wr);if(!n.ok)throw new Error("Failed to load Uniswap token list");return(await n.json()).tokens.filter(o=>o.chainId===t).map(o=>
7({address:o.address,symbol:o.symbol,name:o.name,decimals:o.decimals,logoUrl:gr(o.logoURI),category:"crypto"}))},staleTime:60*60*1e3,gcTime:24*60*60*1e3,enabled:e})}function br(t,e){const n=$e(),s=qe(t);return Le({queryKey:["erc20","lookup",e,t.toLowerCase()],queryFn:async()=>{const o=t,[a,i,u]=await Promise.all([U(n,{abi:pt,address:o,functionName:"symbol",chainId:e}),U(n,{abi:pt,address:o,functionName:"name",chainId:e}),U(n,{abi:pt,address:o,functionName:"decimals",chainId:e})]);return{address:o,symbol:String(a),name:String(i),decimals:Number(u),logoUrl:"",category:"crypto",unverified:!0}},enabled:s,staleTime:60*60*1e3})}const yr="America/New_York";function hr(t){const e=new Intl.DateTimeFormat("en-US",{timeZone:yr,hour12:!1,weekday:"short",year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit"}),n={};for(const o of e.formatToParts(t))o.type!=="literal"&&(n[o.type]=o.value);return{weekday:{Sun:0,Mon:1,Tue:2,Wed:3,Thu:4,Fri:5,Sat:6}[n.weekday??"Sun"]??0,year:Number(n.year),month:Number(n.month),day:Number(n.day),hour:Number(n.hour==="24"?"0":n.hour),minute:Number(n.minute)}}const Mn=["SPYon","QQQon","CRCLon","NVDAon","TSLAon","GOOGLon"],Sr=new Set(Mn.map(t=>t.toLowerCase()));function zn(t){return!!t&&Sr.has(t.toLowerCase())}function Bn(t=new Date,e){if(zn(e))return{isOpen:!0,hoursLabel:"24/7"};const n=hr(t),s="Sun 8 PM â Fri 8 PM ET",o=n.hour*60+n.minute,a=20*60;return n.weekday===6?{isOpen:!1,reason:"weekend",hoursLabel:s}:n.weekday===0&&o<a?{isOpen:!1,reason:"weekend",hoursLabel:s}:n.weekday===5&&o>=a?{isOpen:!1,reason:"weekend",hoursLabel:s}:{isOpen:!0,hoursLabel:s}}function vr(t){const e=Math.floor(Math.max(0,t)/1e3);return{days:Math.floor(e/86400),hours:Math.floor(e%86400/3600),minutes:Math.floor(e%3600/60),seconds:e%60}}const mt=t=>t.toString().padStart(2,"0"),Or=Ot` 8 0%, 100% { box-shadow: 0 0 22px 0 rgba(222, 203, 156, 0.40); } 9 50% { box-shadow: 0 0 42px 8px rgba(222, 203, 156, 0.72); } 10`,Fr="0 0 0 1px rgba(0,0,0,0.05), 0 4px 10px -5px rgba(15,23,42,0.25)",$n=({isOpen:t,onClose:e,token:n,launchAt:s})=>{const{t:o,i18n:a}=be(),[i,u]=O.useState(()=>Date.now());if(O.useEffect(()=>{if(!t)return;u(Date.now());const p=setInterval(()=>u(Date.now()),1e3);return()=>clearInterval(p)},[t]),!n)return null;const d=s-i,c=d<=0,f=vr(d),l=new Date(s).toLocaleDateString(a.language,{year:"numeric",month:"long",day:"numeric"});return r.jsxs(vn,{isOpen:t,onClose:e,isCentered:!0,motionPreset:"scale",children:[r.jsx(On,{bg:"blackAlpha.700",backdropFilter:"blur(6px)"}),r.jsxs(Fn,{className:"vy-beam-border-light",position:"relative",overflow:"visible",mx:4,color:"blue.800",borderRadius:"2xl",borderWidth:"1px",borderColor:"spaceGray.300",bgGradient:Ts,boxShadow:"0 30px 70px -24px rgba(15,23,42,0.55), 0 0 30px -12px rgba(222,203,156,0.5), inset 0 1px 0 rgba(255,255,255,0.9)",children:[r.jsx(W,{position:"absolute",inset:0,rounded:"2xl",pointerEvents:"none",bgGradient:"radial(120% 80% at 16% -12%, rgba(222,203,156,0.22), transparent 58%)"}),r.jsx(kn,{color:"gray.500",zIndex:2}),r.jsx(An,{px:6,py:8,children:r.jsxs(Ft,{spacing:5,textAlign:"center",children:[r.jsx(A,{fontSize:"xs",letterSpacing:"0.22em",textTransform:"uppercase",fontWeight:"bold",color:"gold.600",children:o("views.swap.launch.eyebrow")}),r.jsx(W,{borderRadius:"full",boxShadow:Fr,animation:c?void 0:`${Or} 2.4s ease-in-out infinite`,children:r.jsx(Sn,{symbol:n.symbol,address:n.address,src:n.logoUrl,boxSize:"84px"})}),r.jsxs(W,{children:[r.jsx(A,{fontSize:"3xl",fontWeight:"extrabold",lineHeight:"1.1",children:n.symbol}),r.jsx(A,{mt:1,fontSize:"lg",fontWeight:"bold",bgGradient:"linear(to-r, gold.400, gold.600)",bgClip:"text",children:o("views.swap.launch.title")}),r.jsx(A,{mt:1.5,fontSize:"sm",color:"gray.600",children:o("views.swap.launch.listingOn")})]}),c?r.jsx(W,{w:"full",px:4,py:3,borderRadius:"lg",bg:"green.500",children:r.jsx(A,{fontWeight:"bold",color:"white",children:o("views.swap.launch.liveNow")})}):r.jsxs(xt,{spacing:3,justify:"center",w:"full",children:[r.jsx(Ke,{value:f.days,label:o("views.swap.launch.days")}),r.jsx(Ke,{value:mt(f.hours),label:o("views.swap.launch.hours")}),r.jsx(Ke,{value:mt(f.minutes),label:o("views.swap.launch.minutes")}),r.jsx(Ke,{value:mt(f.seconds),label:o("views.swap.launch.seconds")})]}),r.jsx(A,{fontSize:"sm",fontWeight:"semibold",color:"gold.600",children:o("views.swap.launch.tradingOpens",{date:l})}),r.jsx(A,{fontSize:"xs",color:"white",textShadow:"0 1px 2px rgba(0,0,0,0.3)",maxW:"sm",children:o("views.swap.launch.blurb")})]})})]})]})},Ke=({value:t,label:e})=>r.jsxs(Ft,{spacing:1.5,flex:"1",maxW:"64px",children:[r.jsx(W,{className:"vy-gold-frame",position:"relative",w:"full",py:2.5,borderRadius:"lg",bgGradient:"linear(to-b, #FFFFFF, #EEF0F2)",boxShadow:"inset 0 1px 0 rgba(255,255,255,0.9), 0 1px 2px rgba(15,23,42,0.06)",children:r.jsx(A,{fontSize:"2xl",fontWeight:"extrabold",color:"blue.800",sx:{fontVariantNumeric:"tabular-nums"},children:t})}),r.jsx(A,{fontSize:"10px",textTransform:"uppercase",letterSpacing:"0.08em",color:"white",textShadow:"0 1px 2px rgba(0,0,0,0.3)",children:e})]}),Jt="0x597b29520098d6aaca3b2e0d1a380315c9240454",en="0xf96cCac0bfd5de8d1F69EA9F9f43ed3B174c270
105",Ar={[bt.toLowerCase()]:"ethereum","0x2260fac5e5542a773aa44fbcfedf7c193bc2c599":"wrapped-bitcoin","0x45804880de22913dafe09f4980848ece6ecbaf78":"pax-gold","0x514910771af9ca656af840dff83e8264ecf986ca":"chainlink"},Cr=new Set(["0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48","0xdac17f958d2ee523a2206206994597c13d831ec7","0x6b175474e89094c44da98b954eedeac495271d0f"]);function jr(){return Le({queryKey:["coingecko","markets","top250"],queryFn:async()=>{const e=await fetch("https://api.coingecko.com/api/v3/coins/markets?vs_currency=usd&order=market_cap_desc&per_page=250&page=1&sparkline=false");if(!e.ok)throw new Error(`CoinGecko markets: ${e.status}`);return e.json()},staleTime:60*1e3,gcTime:5*60*1e3,retry:1,refetchInterval:60*1e3})}function Er(t){return Le({queryKey:["ondo","prices"],queryFn:async()=>{const e=await fetch(`${Ds}/ondo/prices`);if(!e.ok)throw new Error(`Ondo prices: ${e.status}`);const n=await e.json(),s=Array.isArray(n)?n:n.data??[],o={};for(const a of s){if(!a.address)continue;const i=typeof a.price=="string"?Number(a.price):a.price;Number.isFinite(i)&&(o[a.address.toLowerCase()]={price:i})}return o},staleTime:60*1e3,gcTime:5*60*1e3,retry:1,refetchInterval:60*1e3,enabled:t})}function Lr(t){return Ns({contracts:[{address:en,abi:$t.UniswapV2Pair,functionName:"getReserves"},{address:en,abi:$t.UniswapV2Pair,functionName:"token0"}],query:{enabled:t,staleTime:60*1e3,gcTime:5*60*1e3,refetchInterval:60*1e3}})}function In(t){const e=jr(),n=Er(!1),s=Lr(t===1);return O.useMemo(()=>{var d,c,f,l;const o=new Map,a=new Map;if(e.data){const p={};for(const w of e.data){p[w.id]=w;const g=w.symbol.toLowerCase();a.has(g)||a.set(g,{price:w.current_price,change24h:w.price_change_percentage_24h??void 0,rank:w.market_cap_rank??Number.MAX_SAFE_INTEGER})}for(const[w,g]of Object.entries(Ar)){const m=p[g];m&&o.set(w,{price:m.current_price,change24h:m.price_change_percentage_24h??void 0})}}const i=(c=(d=s.data)==null?void 0:d[0])==null?void 0:c.result,u=(l=(f=s.data)==null?void 0:f[1])==null?void 0:l.result;if(i&&u){const p=u.toLowerCase()===Jt,w=p?i[0]:i[1],g=p?i[1]:i[0];if(w>0n){const m=g*10n**18n/w,x=Number(m)/1e6;Number.isFinite(x)&&x>0&&o.set(Jt,{price:x})}}for(const p of Cr)o.set(p,{price:1,change24h:0});if(n.data)for(const[p,w]of Object.entries(n.data))o.set(p,w);return{get:p=>{const w=p.address.toLowerCase(),g=o.get(w);if(g)return g;if(p.category==="stock"||p.category==="usd"||p.unverified)return;const m=a.get(p.symbol.toLowerCase());if(m)return{price:m.price,change24h:m.change24h}},rank:p=>{const w=a.get(p.symbol.toLowerCase());return(w==null?void 0:w.rank)??Number.POSITIVE_INFINITY}}},[e.data,n.data,s.data])}const kr=({isOpen:t,onClose:e,selected:n,excluded:s,onChange:o,label:a,market:i})=>{const{t:u}=be(),d=Ee(),c=i==="stocks",f=O.useMemo(()=>c?["stocks","usd"]:["crypto","usd"],[c]),[l,p]=O.useState(f[0]),[w,g]=O.useState(""),[m,x]=O.useState(null),y=jn[d]??[],h=En[d]??[],S=Vs[d]??[],L=_s[d]??new Set,F=Us[d]??{},b=C=>{var E;return(E=F[C.address.toLowerCase()])==null?void 0:E.launchAt},j=C=>{const E=b(C);return E!==void 0&&E>Date.now()},B=O.useMemo(()=>{const C={};for(const[E,H]of Object.entries(F))H.launchAt>Date.now()&&(C[E.toLowerCase()]=H.launchAt);return C},[F]),v=xr(d,!c),N=Cn(d,c),z=br(w.trim(),d),R=O.useMemo(()=>{const C=[...S,...N.data??[]],E=new Set;return C.filter(H=>{const se=H.address.toLowerCase();return E.has(se)?!1:(E.add(se),!0)})},[S,N.data]),M=Bn(),P=In(d),k=s==null?void 0:s.address.toLowerCase(),D=C=>k===C.address.toLowerCase(),Q=C=>L.has(C.address.toLowerCase()),G=C=>{if(j(C)){x(C);return}o(C),g(""),e()},ne=C=>{const E=new Set,H=[];for(const se of C){const $=se.address.toLowerCase();E.has($)||(E.add($),H.push(se))}return H},Y=O.useMemo(()=>{const C=new Set(y.map($=>$.address.toLowerCase())),E=(v.data??[]).filter($=>!C.has($.address.toLowerCase())).filter($=>!Q($)&&!D($)).sort(($,ut)=>P.rank($)-P.rank(ut)),H=ne([...y,...E]).filter($=>!Q($)&&!D($)),se=w.trim().toLowerCase();return se?qe(se)?H.filter($=>$.address.toLowerCase()===se):H.filter($=>$.symbol.toLowerCase().includes(se)||$.name.toLowerCase().includes(se)):H},[y,v.data,L,k,w,P]),Z=O.useMemo(()=>{const C=R.filter(H=>
10!D(H)),E=w.trim().toLowerCase();return E?C.filter(H=>H.symbol.toLowerCase().includes(E)||H.name.toLowerCase().includes(E)||H.address.toLowerCase()===E):C},[R,k,w]),X=h.filter(C=>!D(C)),ye=l==="crypto"?Y:l==="stocks"?Z:X,ve=l!=="usd"&&qe(w.trim())&&ye.length===0&&z.data&&z.data?r.jsxs(r.Fragment,{children:[r.jsx(Tn,{}),r.jsxs(W,{px:4,py:2,children:[r.jsx(A,{fontSize:"xs",color:"gray.500",mb:1,children:u("views.swap.unverifiedToken")}),r.jsx(Wn,{token:z.data,selected:n,onSelect:G,marketData:P})]})]}):null,ke=C=>C==="crypto"?u("views.swap.tabCrypto"):C==="usd"?u("views.swap.tabUsd"):r.jsxs(_,{align:"center",gap:1.5,children:[r.jsx(A,{as:"span",children:u("views.swap.tabStocks")}),r.jsx(W,{w:"6px",h:"6px",borderRadius:"full",bg:M.isOpen?"green.400":"orange.400",title:M.isOpen?u("views.swap.marketOpen"):u(`views.swap.marketClosed.${M.reason??"after-hours"}`)})]}),Oe=C=>C==="crypto"?r.jsxs(r.Fragment,{children:[r.jsx(tn,{value:w,onChange:g,placeholder:u("views.swap.searchOrPaste")}),r.jsx(wt,{isLoading:v.isLoading&&Y.length===0,emptyText:u("views.swap.noTokensFound"),list:Y,selected:n,onSelect:G,pinnedCount:y.length,marketData:P,launchAtByAddr:B,comingSoonLabel:u("views.swap.launch.comingSoon")}),ve]}):C==="usd"?r.jsx(wt,{isLoading:!1,emptyText:u("views.swap.noTokensFound"),list:X,selected:n,onSelect:G,marketData:P}):r.jsxs(r.Fragment,{children:[!M.isOpen&&r.jsxs(W,{mx:4,mt:2,px:3,py:2,bg:"orange.50",borderRadius:"md",borderLeftWidth:"3px",borderLeftColor:"orange.400",children:[r.jsx(A,{fontSize:"xs",fontWeight:"semibold",color:"orange.700",children:u(`views.swap.marketClosed.${M.reason??"after-hours"}`)}),r.jsx(A,{fontSize:"xs",color:"orange.600",children:u("views.swap.marketHoursLabel",{hours:u("views.swap.ondoTradingHours")})}),r.jsx(A,{fontSize:"xs",color:"orange.600",mt:1,children:u("views.swap.alwaysOnHint",{symbols:Tr})})]}),r.jsx(tn,{value:w,onChange:g,placeholder:u("views.swap.searchOrPaste")}),N.isLoading&&R.length===0?r.jsx(_,{justify:"center",py:6,children:r.jsx(Ie,{size:"sm",color:"gray.400"})}):N.isError&&R.length===0?r.jsx(W,{px:4,py:6,textAlign:"center",children:r.jsx(A,{fontSize:"sm",color:"gray.500",children:u("views.swap.stocksComingSoon")})}):r.jsx(wt,{isLoading:!1,emptyText:u("views.swap.noTokensFound"),list:Z,selected:n,onSelect:G,marketData:P}),ve]});return r.jsxs(r.Fragment,{children:[r.jsxs(vn,{isOpen:t,onClose:e,isCentered:!0,scrollBehavior:"inside",children:[r.jsx(On,{}),r.jsxs(Fn,{mx:4,maxH:"80vh",children:[r.jsx(go,{pb:2,children:a}),r.jsx(kn,{}),r.jsx(An,{px:0,pb:4,children:r.jsxs(Rs,{index:Math.max(0,f.indexOf(l)),onChange:C=>{p(f[C]??f[0]),g("")},variant:"soft-rounded",colorScheme:"blue",isFitted:!0,children:[r.jsx(xo,{px:4,mb:3,children:f.map(C=>r.jsx(Ps,{children:ke(C)},C))}),r.jsx(Dn,{children:f.map(C=>r.jsx(Nn,{px:0,py:0,children:Oe(C)},C))})]})})]})]}),r.jsx($n,{isOpen:!!m,onClose:()=>x(null),token:m,launchAt:m?b(m)??0:0})]})},Tr=Mn.map(t=>t.replace(/on$/,"")).join(", "),tn=({value:t,onChange:e,placeholder:n})=>r.jsx(W,{px:4,mb:3,children:r.jsxs(Ms,{children:[r.jsx(zs,{pointerEvents:"none",children:r.jsx(ce,{as:Bs,color:"gray.400"})}),r.jsx(Ln,{placeholder:n,value:t,onChange:s=>e(s.target.value),autoFocus:!0})]})}),wt=({isLoading:t,emptyText:e,list:n,selected:s,onSelect:o,pinnedCount:a,marketData:i,launchAtByAddr:u,comingSoonLabel:d})=>t?r.jsx(_,{justify:"center",py:6,children:r.jsx(Ie,{size:"sm",color:"gray.400"})}):n.length===0?r.jsx(A,{px:4,color:"gray.500",fontSize:"sm",children:e}):r.jsx(r.Fragment,{children:n.map((c,f)=>r.jsxs(W,{children:[a&&f===a&&r.jsx(Tn,{my:1}),r.jsx(Wn,{token:c,selected:s,onSelect:o,marketData:i,launchAt:u==null?void 0:u[c.address.toLowerCase()],comingSoonLabel:d})]},c.address))}),Wn=({token:t,selected:e,onSelect:n,marketData:s,launchAt:o,comingSoonLabel:a})=>{const{i18n:i}=be(),u=s==null?void 0:s.get(t),d=(u==null?void 0:u.change24h)!==void 0,c=(u==null?void 0:u.price)!==void 0,f=o!==void 0,l=f?new Date(o).toLocaleDateString(i.language,{month:"short",day:"numeric",year:"numeric"}):"";return r.jsxs(_,{align:"center",gap:3,px:4,py:3,cursor:"pointer",_hover:{bg:"gray.50"},onClick:()=>n(t),bg:(e==null?void 0:e.address.toLowerCase())===t.address.toLowerCase()?"blue.50":void 0,children:[r.jsx(rt,{token:t,boxSize:"36px",fontSize:"10px"}),r.jsxs(W,{flex:"1",minW:0,children:[r.jsx(A,{fontWeight:"semibold",fontSize:"sm",children:t.symbol}),r.jsx(A,{fontSize:"xs",color:"gray.500",noOfLines:1,children:t.name})]}),f?r.jsx(bo,{title:a,flexShrink:0,px:2.5,py:1,borderRadius:"full",textTransform:"none",fontSize:"11px",fontWeight:"bold",color:"white",border:"none",boxShadow:"0 1px 6px -1px rgba(151,123,75,0.5)",sx:{backgroundImage:"linear-gradient(120deg, #AE905D, #C4A76F, #D4B978, #C4A76F, #AE905D, #977B4B, #AE905D, #C4A76F, #D4B978, #C4A76F, #AE905D)",backgroundSize:"200% 100%",animation:"vgcGoldFlow 4s ease-in-out infinite alternate","@keyframes vgcGoldFlow":{"0%":{backgroundPosition:"0% 50%"},"100%":{backgroundPosition:"100% 50%"}}},children:l}):r.jsxs(r.Fragment,{children:[d&&r.jsx(A,{fontSize:"sm",fontWeight:"medium",color:u.change24h>=0?"green.500":"red.500",flexShrink:0,mr:2,children:Dr(u.change24h)}),c&&r.jsx(A,{fontWeight:"semibold",fontSize:"sm",flexShrink:0,textAlign:"right",children:Nr(u.price)})]})]})};function Nr(t){if(!Number.isFinite(t))return"";const e=t>=1?2:t>=.01?4:6;
10return`$${t.toLocaleString(void 0,{minimumFractionDigits:e,maximumFractionDigits:e})}`}function Dr(t){return`${t>=0?"+":""}${t.toFixed(2)}%`}const nn=({selected:t,excluded:e,isLoading:n,onChange:s,label:o,market:a})=>{const{t:i}=be(),{isOpen:u,onOpen:d,onClose:c}=$s();return r.jsxs(r.Fragment,{children:[r.jsxs(_,{align:"center",gap:2,px:3,py:2,bg:"gray.100",borderRadius:"xl",cursor:"pointer",_hover:{bg:"gray.200"},onClick:d,minW:"120px",flexShrink:0,children:[n?r.jsx(tt,{h:"24px",w:"80px",borderRadius:"md"}):t?r.jsxs(r.Fragment,{children:[r.jsx(rt,{token:t,boxSize:"24px",fontSize:"8px"}),r.jsx(A,{fontWeight:"bold",fontSize:"sm",children:t.symbol})]}):r.jsx(A,{fontWeight:"semibold",fontSize:"sm",color:"blue.600",children:i("views.swap.selectToken")}),r.jsx(ce,{as:Is,color:"gray.500",boxSize:4})]}),r.jsx(kr,{isOpen:u,onClose:c,selected:t,excluded:e,onChange:s,label:o,market:a})]})};function sn(t,e,n){var l,p,w;const s=$e(),o=e?(l=t.get(e))==null?void 0:l.price:void 0,a=ee[n],i=a?(p=t.get({address:a,symbol:"VY",name:"Valinity",decimals:18,logoUrl:"",category:"crypto"}))==null?void 0:p.price:void 0,u=(w=Ve[n.toString()])==null?void 0:w.ValinityDAX,d=e&&we(e.address)?mn[n]:e==null?void 0:e.address,c=!!e&&!!u&&!!d&&o===void 0&&!e.unverified&&e.category!=="stock"&&e.category!=="usd"&&d.toLowerCase()!==(a==null?void 0:a.toLowerCase()),f=Le({queryKey:["swap","daxVyPerToken",n,d==null?void 0:d.toLowerCase()],queryFn:async()=>{if(!e||!u||!d)return null;const g=d,[m,x]=await Promise.all([U(s,{abi:T.ValinityDAX,address:u,functionName:"assetToPoolId",args:[g],chainId:n}),U(s,{abi:T.ValinityDAX,address:u,functionName:"getNumPools",chainId:n})]);if(m>=x)return null;const[y,h,S]=await U(s,{abi:T.ValinityDAX,address:u,functionName:"getPoolReserves",args:[m],chainId:n});return y.toLowerCase()!==g.toLowerCase()||S===0n?null:Number(h)/1e18/(Number(S)/10**e.decimals)},enabled:c,staleTime:6e4,refetchInterval:6e4,retry:!1});if(o!==void 0)return o;if(c&&i!==void 0&&f.data)return f.data*i}const Yr=()=>r.jsx(Rr,{market:"stocks"}),Rr=({market:t="crypto"})=>{var zt;const e=t==="stocks",{t:n}=be(),[s]=Ws(),o=!e&&s.get("market")==="stocks",{address:a,isConnected:i}=at(),u=Ee(),d=Gs(),[c,f]=O.useState(null),[l,p]=O.useState(null),[w,g]=O.useState("in"),[m,x]=O.useState(""),y=`${w}:${m}`,{value:h}=io(y,500),S=h!==y,{approve:L,execute:F,step:b,txHash:j,error:B,reset:v}=Jo(),[N,z]=O.useState("auto"),R=O.useRef(null),[M,P]=O.useState(null),{requireRegistration:k}=Hs(),D=O.useMemo(()=>e?null:Qs(d),[d,e]),[Q,G]=O.useState(!1),ne=O.useRef(!1);O.useEffect(()=>{D&&!ne.current&&G(!0)},[D]);const Y=Ys();O.useEffect(()=>{b==="success"&&(l==null?void 0:l.category)==="stock"&&Y(l)},[b,l,Y]),O.useEffect(()=>{b==="success"&&R.current&&(P({...R.current,txHash:j}),R.current=null)},[b,j]),O.useEffect(()=>{if(c??l)return;const V=jn[d]??[],re=En[d]??[],Ye=V.find(dt=>dt.address===bt)??V[0]??null,Bt=re.find(dt=>dt.symbol==="USDC")??re[0]??null;if(e){f(Bt);return}f(Ye),p(Bt)},[d,c,l,e]);const Z=Cn(d,e),X=O.useMemo(()=>(Z.data??[]).find(V=>V.symbol.toLowerCase()==="spyon")??null,[Z.data]);O.useEffect(()=>{!e||!X||l||p(X)},[e,l,X]);const ye=(c==null?void 0:c.address)===bt,{data:oe}=Xs({address:a,token:!ye&&c?c.address:void 0,chainId:d,query:{enabled:!!a&&!!c}}),ve=O.useMemo(()=>!oe||!c?null:parseFloat(me(oe.value,c.decimals)).toLocaleString(void 0,{maximumFractionDigits:6}),[oe,c]),ke=O.useCallback(()=>{!oe||!c||(g("in"),x(me(oe.value,c.decimals)),b!=="idle"&&v())},[oe,c,b,v]),Oe=O.useMemo(()=>{if(!c||!l||!m||S)return null;const V=w==="in"?c:l;let re;try{re=Ks(m,V.decimals)}catch{return null}return re<=0n?null:w==="in"?{side:"in",tokenIn:c,tokenOut:l,amountIn:re}:{side:"out",tokenIn:c,tokenOut:l,amountOut:re}},[c,l,m,w,S]),C=Ro(Oe),E=C.data,{needsApproval:H,isResolved:se,markApproved:$}=Do(E,c),ut=H&&!Zs(),fe=S||C.isFetching&&!E||!!Oe&&C.isLoading,kt=C.isError?((zt=C.error)==null?void 0:zt.message)??"":"",ct=C.isError&&/no liquidity|no direct uniswap|InvalidPool|InvalidRoute/i.test(kt),Gn=C.isError&&!ct,Tt=i&&!pn(u),Nt=w==="in"?m:E&&!fe&&c?It(E.amountIn,c.decimals):"",Dt=w==="out"?m:E&&!fe&&l?It(E.amountOut,l.decimals):"",Hn=w==="out"&&!!m&&fe,Qn=w==="in"&&!!m&&fe,Rt=In(d),Yn=sn(Rt,c,d),Xn=sn(Rt,l,d),Kn=Wt(Nt,Yn),Zn=Wt(Dt,Xn),Pt=!!E&&!fe&&!!oe&&E.amountIn>oe.value,lt=O.useMemo(()=>[c,l].some(V=>(V==null?void 0:V.category)==="stock"&&!zn(V.symbol)),[c,l]),[Qe,Vt]=O.useState(null);O.useEffect(()=>{if(!lt){Vt(null);return}const V=()=>Vt(Bn());V();const re=setInterval(V,3e4);return()=>clearInterval(re)},[lt]);const he=O.useCallback(()=>{x(""),g("in")},[]),qn=O.useCallback(V=>{f(V),he(),v()},[he,v]),Jn=O.useCallback(V=>{p(V),he(),v()},[he,v]),_t=(V,re)=>{const Ye=V==="in"?c:l;!Ye||!ho(re,Ye.decimals)||(g(V),x(re),b!=="idle"&&v())},es=O.useCallback(()=>{f(l),p(c),g(V=>V==="in"?"out":"in"),v()},[c,l,v]),ts=O.useCallback(()=>{he(),v()},[he,v]),ns=O.useCallback(async()=>{!E||!c||!l||!Oe||await k()&&(R.current={tokenIn:c,tokenOut:l,amountInDisplay:me(E.amountIn,c.decimals),amountOutDisplay:me(E.amountOut,l.decimals),routeLabel:E.routeLabel},await F(E,c,l,N))},[E,c,l,Oe,F,N,k]),ss=O.useCallback(async()=>{!E||!c||!await k()||!await L(E,c)||($(),v())},[E,c,L,$,v,k]),Ut=O.useCallback(()=>{P(null),he(),v()},[he,v]),Mt=lt&&Qe!==null&&!Qe.isOpen,os=!i||Tt||!c||!l||!Oe||!E||fe||ct||Mt||Pt||!se;return o?r.jsx(qs,{to:"/stocks",replace:!0}):r.jsxs(Js,{title:n(e?"views.swap.titleStocks":"views.swap.title"),bgGradient:eo,children:[r.jsxs(_,{direction:"column",gap:3,p:4,flex:1,children:[r.jsxs(W,{bg:"white",borderRadius:"2xl",p:4,boxShadow:"sm",children:[r.jsxs(_,{justify:"space-between",align:"center",mb:2,children:[r.jsx(A,{fontSize:"xs",color:"gray.500",children:n("views.swap.youPay")}),i&&ve&&r.jsxs(_,{align:"center",gap:1,children:[r.jsxs(A,{fontSize:"xs",color:"gray.400",children:[n("views.swap.balance")," ",ve," ",c==null?void 0:c.symbol]}),r.jsx(pe,{size:"xs",variant:"link",colorScheme:"blue",fontSize:"xs",fontWeight:"semibold",onClick:ke,children:n("views.swap.max")})]})]}),r.jsxs(_,{align:"center",gap:3,children:[r.jsx(nn,{selected:c,excluded:l,onChange:qn,label:n("views.swap.selectTokenIn"),market:t}),r.jsx(on,{value:Nt,onChange:V=>_t("in",V),isComputing:Hn,usd:Kn})]})]}),r.jsx(_,{justify:"center",my:-2,zIndex:1,children:r.jsx(xn,{"aria-label":n("views.swap.flipTokens"),icon:r.jsx(ce,{as:to,boxSize:5,color:"gray.600"}),size:"sm",variant:"ghost",borderRadius:"full",bg:"white",boxShadow:"md",onClick:es,_hover:{bg:"gray.100"}})}),r.jsxs(W,{bg:"white",borderRadius:"2xl",p:4,boxShadow:"sm",children:[r.jsx(A,{fontSize:"xs",color:"gray.500",mb:2,children:n("views.swap.youReceiveApprox")}),r.jsxs(_,{align:"center",gap:3,children:[r.jsx(nn,{selected:l,excluded:c,onChange:Jn,label:n("views.swap.selectTokenOut"),market:t}),r.jsx(on,{value:Dt,onChange:V=>_t("out",V),isComputing:Qn,usd:Zn})]})]}),ct&&r.jsxs(Fe,{status:"warning",borderRadius:"xl",fontSize:"sm",children:[r.jsx(Ae,{}),r.jsx(Ce,{children:n("views.swap.noLiquidity")})]}),Gn&&r.jsxs(Fe,{status:"error",borderRadius:"xl",fontSize:"sm",children:[r.jsx(Ae,{}),r.jsxs(Ce,{children:[n("views.swap.quoteError",{defaultValue:"Could not fetch quote"}),": ",rn(C.error??new Error(kt),n)]})]}),(fe||E)&&r.jsx(_,{justify:"flex-end",align:"center",px:1,children:r.jsx(ir,{value:N,priceImpact:E==null?void 0:E.priceImpact,onChange:z})}),fe&&!!m&&r.jsx(rr,{}),E&&c&&l&&!fe&&r.jsx(or,{quote:E,tokenIn:c,tokenOut:l,isFetching:C.isFetching,effectiveSlippage:vt(E.priceImpact,N)}),Tt&&r.jsxs(Fe,{status:"warning",borderRadius:"xl",fontSize:"sm",children:[r.jsx(Ae,{}),r.jsx(Ce,{children:n("views.swap.unsupportedNetwork")})]}),B&&r.jsxs(Fe,{status:"error",borderRadius:"xl",fontSize:"sm",children:[r.jsx(Ae,{}),r.jsx(Ce,{children:rn(B,n)})]}),!i&&r.jsxs(Fe,{status:"info",borderRadius:"xl",fontSize:"sm",children:[r.jsx(Ae,{}),r.jsx(Ce,{children:n("views.swap.connectWalletPrompt")})]}),Mt&&Qe&&b==="idle"&&r.jsxs(Fe,{status:"warning",borderRadius:"xl",fontSize:"sm",children:[r.jsx(Ae,{}),r.jsxs(Ce,{children:[n(`views.swap.marketClosed.${Qe.reason??"after-hours"}`)," · ",n("views.swap.marketHoursLabel",{hours:n("views.swap.ondoTradingHours")})]})]}),r.jsx(W,{mt:"auto",pt:2,children:r.jsx(ur,{step:b,txHash:j,isDisabled:os,needsApproval:ut,approveSymbol:c==null?void 0:c.symbol,insufficientBalanceSymbol
10:Pt?c==null?void 0:c.symbol:void 0,onApprove:ss,onClick:ns,onNewSwap:ts})})]}),D&&r.jsx($n,{isOpen:Q,onClose:()=>{ne.current=!0,G(!1)},token:D.token,launchAt:D.launchAt}),M&&r.jsx(fr,{isOpen:!0,onClose:Ut,onTradeAgain:Ut,tokenIn:M.tokenIn,tokenOut:M.tokenOut,amountInDisplay:M.amountInDisplay,amountOutDisplay:M.amountOutDisplay,routeLabel:M.routeLabel,txHash:M.txHash})]})},on=({value:t,onChange:e,isComputing:n,usd:s})=>r.jsxs(_,{direction:"column",align:"flex-end",flex:1,minW:0,children:[r.jsx(_,{h:10,w:"full",align:"center",justify:"flex-end",children:n?r.jsx(Ie,{size:"sm",color:"gray.400"}):r.jsx(Ln,{variant:"unstyled",placeholder:"0.0",value:t,onChange:o=>e(o.target.value),fontSize:"2xl",fontWeight:"semibold",textAlign:"right",type:"text",inputMode:"decimal"})}),r.jsx(A,{fontSize:"xs",color:"gray.500",minH:4,lineHeight:4,children:s??""})]});function rn(t,e){var o,a;if(t instanceof no)return((o=t.details)==null?void 0:o.code)==="ONDO_ATTESTATION_FAILED"||t.status===502?e("views.swap.marketClosed.unavailable"):((a=t.details)==null?void 0:a.message)??t.message;if(so(t))return e("messages.wallet.cancelled");const n=t.message;return n.includes("Chain ID mismatch")||n.includes("Untrusted router")?n:n.includes("Quote has expired")?e("views.swap.errors.quoteExpired"):n.includes("Quote not found")?e("views.swap.errors.quoteNotFound"):t instanceof oo||ro(t)!=null?ao(t,{chain:"ethereum"}).message:n}export{Yr as Stocks,Rr as Swap};
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.