var Q=Object.create;var g=Object.defineProperty;var Y=Object.getOwnPropertyDescriptor;var K=Object.getOwnPropertyNames;var L=Object.getPrototypeOf,b=Object.prototype.hasOwnProperty;var j=(t,e)=>{for(var o in e)g(t,o,{get:e[o],enumerable:!0})},v=(t,e,o,c)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of K(e))!b.call(t,n)&&n!==o&&g(t,n,{get:()=>e[n],enumerable:!(c=Y(e,n))||c.enumerable});return t};var D=(t,e,o)=>(o=t!=null?Q(L(t)):{},v(e||!t||!t.__esModule?g(o,"default",{value:t,enumerable:!0}):o,t)),y=t=>v(g({},"__esModule",{value:!0}),t);var m=(t,e,o)=>new Promise((c,n)=>{var E=i=>{try{d(o.next(i))}catch(u){n(u)}},w=i=>{try{d(o.throw(i))}catch(u){n(u)}},d=i=>i.done?c(i.value):Promise.resolve(i.value).then(E,w);d((o=o.apply(t,e)).next())});var J={};j(J,{default:()=>I});module.exports=y(J);var r=require("react"),q=require("@mayanfinance/swap-sdk"),B=require("@solana/wallet-adapter-react"),P=require("@chakra-ui/react"),A=D(require("bignumber.js"),1),R=D(require("axios"),1);var p=t=>{switch(t){case"BONK":return{token:"DezXAZ8z7PnrnRJjz3wXBoRgixCa6xjnB7YaB1pPB263",chain:"solana",quoteAmount:1e6};case"SOL":return{token:"0x0000000000000000000000000000000000000000",chain:"solana",quoteAmount:1};case"USDT":return{token:"Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB",chain:"solana",quoteAmount:1};case"ETH":return{token:"0x0000000000000000000000000000000000000000",chain:"ethereum",quoteAmount:1};default:return null}},H=({amountIn:t,fromCurrency:e,toCurrency:o})=>{var S;let[c,n]=(0,r.useState)({}),[E,w]=(0,r.useState)(!1),[d,i]=(0,r.useState)(0),{publicKey:u,signTransaction:z}=(0,B.useWallet)(),{connection:M}=(0,B.useConnection)(),N=(0,P.useToast)(),F=(0,r.useRef)(null),k=((S=p(e))==null?void 0:S.quoteAmount)||1;(0,r.useEffect)(()=>{let s=()=>m(void 0,null,function*(){try{w(!0);let a=yield T(k);n(a)}catch(a){N({title:"Failed to fetch price",description:a.reason||a.message,status:"error",duration:1e3})}finally{w(!1)}});return e&&o&&e!==o&&(s(),F.current=setInterval(s,3e4)),()=>{clearInterval(F.current)}},[e,o]);let T=s=>m(void 0,null,function*(){return yield(0,q.fetchQuote)({amount:s,fromToken:p(e).token,toToken:p(o).token,fromChain:p(e).chain,toChain:p(o).chain,slippage:3})}),f=(s,a,h="finalized")=>m(void 0,null,function*(){try{let l=yield R.default.get(`https://explorer-api.mayan.finance/v1/swap/trx/${s}`);return l.data.status==="REDEEMED_ON_EVM"||h==="processed"?l.data:(yield new Promise(x=>setTimeout(x,1e4)),f(s,0))}catch(l){if(console.log(l),a>0)return yield new Promise(x=>setTimeout(x,1e4)),f(s,a-1);throw new Error("Failed to swap")}}),O=s=>m(void 0,null,function*(){try{let a=yield T(s),h=yield(0,q.swapFromSolana)(a,u.toBase58(),u.toBase58(),1e5,z,M);return yield f(h,100,"processed"),h}catch(a){throw console.log(a),new Error(a)}}),_=e!==o&&c.expectedAmountOut?new A.default(t).multipliedBy(k).dividedBy(c.minAmountOut).toFixed(4):new A.default(t).toFixed(2);return{initSwap:O,verifySwapComplete:f,requiredAmount:_,isFetchingQuote:E}},I=H;
