@meteraprotocol/sdk
Version:
SDK to interact with Metera's API & a UI component that will create orders into the Metera Protocol
119 lines • 57.3 kB
JavaScript
import {g,e}from'./chunk-S7BPVYZK.js';import {Button,ModalContent,Flex,Image,useToast,useDisclosure,Box,Tooltip,Collapse,Text,Link,Modal,ModalOverlay,ModalBody,Switch,IconButton,TableContainer,Table,Thead,Tr,Td,Circle}from'@chakra-ui/react';export{ChakraProvider as MeteraProvider}from'@chakra-ui/react';import X from'bignumber.js';import {createContext,forwardRef,useState,useMemo,useEffect}from'react';import {MTK_DECIMALS,computeFees,computeInteraction}from'@meteraprotocol/core';import'@nufi/dapp-client-cardano';import'@nufi/dapp-client-core';import Rr from'axios';import {BigRational}from'big-rational-ts';import Pr from'json-bigint';import {getAddressDetails,fromHex,C,toHex}from'lucid-txpipe';import {z as z$1}from'zod';import {decode}from'cbor2';import {CML}from'@lucid-evolution/lucid';import {keyframes}from'@emotion/react';import {jsxs,jsx,Fragment}from'react/jsx-runtime';import {NumericFormat}from'react-number-format';import {InfoIcon,CloseIcon}from'@chakra-ui/icons';import {MdSwapHoriz,MdWest}from'react-icons/md/index.js';import tr from'@emotion/styled';var ot=(m=>(m.BAD_REQUEST="Bad request",m.UNKNOWN="There was a problem when building your transaction. Please try again",m.NOT_ENOUGH_MONEY="You don't have enough tokens for this.",m.INVALID_IMAGE="Image format is not valid",m.INVALID_ORDER="Invalid order",m.CANT_CANCEL_IN_PROGRESS="Order being processed. Can't cancel right now",m.ORDER_NOT_FOUND="Order not found",m.ALREADY_CANCELLING="Order already in cancelling process",m.ALREADY_CANCELLED="Order already cancelled",m.ORDER_CBOR_INVALID="The provided order is not valid",m.SERVER_DOWN="Our servers are currently down. Please try again later",m.UNAUTHORIZED="Unauthorized",m.ORDER_EXPIRED="This order expired",m.ORDER_MIGHT_HAVE_BEEN_CANCELLED="Can't cancel this order",m.PORTFOLIO_NOT_FOUND="The portfolio you requested doesn't exist",m.PORTFOLIO_CBOR_INVALID="The provided transaction is not valid",m.RUN_OUT_OF_FUNDS="Your request might have clashed with someone else's. Try again",m.OVER_BUDGET="You requested too much for today. Try with other tokens or tomorrow.",m))(ot||{});function Fe(e){if(e.eq(0))return new BigRational(0n,1n);let[t,r]=e.toFraction().map(o=>BigInt(o.toFixed(0)));return new BigRational(t,r).reduce()}function z(e){let t=X(e.getNumerator().toString()),r=X(e.getDenominator().toString());return t.div(r)}function vt(e){return Fe(Cr(e))}function Cr(e){return X(e)}Pr({alwaysParseAsBig:!0,useNativeBigInt:!0,strict:!0});async function Ce(e){let t=getAddressDetails(await e.getChangeAddress()).address.bech32,r=await e.getUtxos();if(!r)return {};let o=r.map(fromHex).map(C.TransactionUnspentOutput.from_bytes).filter(s=>JSON.parse(s.output().address().to_json())===t),i={lovelace:0n};for(let s of o){let p=s.output(),u=p.amount().coin();i.lovelace+=BigInt(u.to_str());let h=p.amount().multiasset()?.to_js_value()||{};for(let[g,l]of Object.entries(h))for(let[a,d]of Object.entries(l)){let c=`${g}${a}`;i[c]||(i[c]=BigInt(0)),i[c]+=BigInt(d);}}return i}function At(e){return e.assets.reduce((r,{price:o,amount:i,asset:{decimals:s}})=>Fe(X(o)).mul(new BigRational(i,1n)).mul(new BigRational(1n,BigInt(10**s))).add(r),new BigRational(0n,1n)).div(new BigRational(e.supply,1n)).reduce()}function Le(e,t){let r={floor:X.ROUND_FLOOR,ceil:X.ROUND_CEIL};return BigInt(e.toFixed(0,r[t]))}function Nr(e,t){return Object.entries(t).every(([r,o])=>(e[r]||BigInt(0))>=o)}function j(e){return e.currencySymbol===""?"lovelace":`${e.currencySymbol}${e.name}`}var Ie=e=>{if(e instanceof Rr.AxiosError&&e.response?.data&&Object.values(ot).includes(e.response?.data)){let t=e.response.data;switch(t){case"Invalid order":return {error:"The data in your order is probably outdated. Refresh the page and try again"};case"This order expired":return {error:"This order expired, try again."};case"Order already cancelled":return {error:"This order was cancelled already"};case"You don't have enough tokens for this.":return {error:"You ran out of tokens. Refresh your wallet and try again if you recharged"};case"Bad request":return {error:"Some of your input is wrong"};case"Order already in cancelling process":return {error:"In process of cancelling"};default:return {error:t}}}else if(e.message.includes("ECONNREFUSED"))return {error:"Our servers are currently down. Please try again later"};return {error:"Unknown error. Try again"}};function Ft(e,t,r,o,i){let s=Object.fromEntries(Object.entries(t).map(([p,u])=>{let f=i.assets.find(h=>h.asset.id===p);return [j(f.asset),u]}));return r==="mint"?Nr(e,s):X((e[i.portfolio.mtkUnit]||0n).toString()).div(10**MTK_DECIMALS).gte(o)}var Re=e=>Object(e).hasOwnProperty("error");z$1.string();z$1.string();z$1.object({address:z$1.string(),tokens:z$1.record(z$1.bigint().positive())}).strict();var Ct=z$1.object({cbor:z$1.string({description:"Unsigned transaction cbor"}),txId:z$1.string({description:"Transaction hash"})}),It=z$1.object({cbor:z$1.string(),id:z$1.string()}).strict();z$1.object({cbor:z$1.string()});createContext(void 0);function Pt(e){e.length%2!==0&&(e="0"+e);let t=new Uint8Array(e.length/2);for(let r=0;r<e.length;r+=2)t[r/2]=parseInt(e.slice(r,r+2),16);return t}async function it(e,t,r=!1,o="legacy"){return o==="conway"?Er(e,t,r):_r(e,t,r)}async function _r(e,t,r=!1){let o=C.Transaction.from_bytes(Pt(t)),i=await e.signTx(t,r),s=decode(i,{encoding:"hex"});if(s.size===0)throw new Error("Empty witness set after signTx");if(!s.has(0))throw new Error("Incorrect vkey witness CBOR format");let p=s.get(0),[u,f]=Array.from(p)[0],h=C.PublicKey.from_bytes(u),g=C.Vkey.new(h),l=C.Ed25519Signature.from_bytes(f),a=C.Vkeywitnesses.new();a.add(C.Vkeywitness.new(g,l));let d=o.witness_set();d.set_vkeys(a);let c=C.Transaction.new(o.body(),d,o.auxiliary_data());return toHex(c.to_bytes())}async function Er(e,t,r=!1){let o=CML.Transaction.from_cbor_bytes(Pt(t)),i=await e.signTx(t,r),s=decode(i,{encoding:"hex"});if(s.size===0)throw new Error("Empty witness set after signTx");if(!s.has(0))throw new Error("Incorrect vkey witness CBOR format");let p=s.get(0),[u,f]=Array.from(p)[0],h=CML.PublicKey.from_bytes(u),g=CML.Ed25519Signature.from_raw_bytes(f),l=CML.VkeywitnessList.new();l.add(CML.Vkeywitness.new(h,g));let a=o.witness_set();return a.set_vkeywitnesses(l),CML.Transaction.new(o.body(),a,!0,o.auxiliary_data()).to_cbor_hex()}function Wt(e){let t={},r={},o={};for(let i of e.assets)r[i.asset.id]=vt(i.price).mul(new BigRational(1n,BigInt(10**i.asset.decimals))),t[i.asset.id]=new BigRational(i.weightNum,i.weightDenom),o[i.asset.id]=BigInt(i.amount);return {prices:r,weights:t,state:{assets:o,mtkSupply:e.supply}}}function Nt(e,t){if(e.eq(new BigRational(0n,1n))){let p={};for(let[u]of Object.entries(t.state.assets))p[u]=0n;return {assets:p,mtkSupply:0n}}let r=computeInteraction(t.prices,t.weights,t.state,e),o=e.gte(new BigRational(0n,1n))?"ceil":"floor",i={};for(let[p,u]of Object.entries(t.state.assets)){let f=r.assets[p].subtract(new BigRational(u,1n));i[p]=Le(z(f),o);}let s=Le(z(r.mtkSupply),o)-t.state.mtkSupply;return {assets:i,mtkSupply:s}}async function Ot(e$1,t,r,o,i,s,{onError:p,onSuccess:u}){let f=new g({basePath:i}),h=e(f);try{if((await Ce(e$1.wallet)).lovelace<10000000n)return p("You need more tADA in your wallet to do this");let l,a=Object.entries(r.assets).map(([D,R])=>({id:D,amount:R.toString()}));o.gt(0)?l={address:getAddressDetails(await e$1.wallet.getChangeAddress()).address.bech32,portfolioId:t.portfolio.id,maxBatcherFee:t.batcherFee.toString(),minMtkAcceptable:"1",tokens:a}:l={address:getAddressDetails(await e$1.wallet.getChangeAddress()).address.bech32,portfolioId:t.portfolio.id,amount:Le(o.times(10**MTK_DECIMALS).abs(),"floor").toString(),tokens:a,maxBatcherFee:t.batcherFee.toString(),minWorthAcceptable:"1"};let d=await h.ordersCreatePost(l).catch(Ie);if(Re(d))return p(d.error);let{cbor:c,id:y}=It.parse(d.data),F=await it(e$1.wallet,c,!1),C={id:y,cbor:F},m=await h.ordersSubmitPost(C).catch(Ie);return Re(m)?p(m.error):(u(y),y)}catch(g){console.error(g),p("Unknown error. Try again later");}}function Mt(e,t){let r={...e};for(let[o,i]of Object.entries(t))e[o]&&(r[o]=e[o]-i);return r}function Dt(e){for(let[t,r]of Object.entries(e))r<=0&&delete e[t];}async function zt(e$1,t,r,o,i,s,p,{onError:u,onSuccess:f}){let h=new g({basePath:p}),g$1=e(h);try{if((await Ce(e$1.wallet)).lovelace<10000000n)return u("You need more ADA in your wallet to do this");let a={...o},d={};s&&(a=Mt(o,r),d=Mt(o,a),Dt(d)),Dt(a);let c={address:getAddressDetails(await e$1.wallet.getChangeAddress()).address.bech32,maxBatcherFee:t.batcherFee.toString(),totalAmount:i.toString(),userAssets:Object.entries(d).map(([L,S])=>({id:L,amount:S.toString()})),swap:Object.entries(a).map(([L,S])=>({id:L,amount:S.toString()})),portfolioId:t.portfolio.id},y=await g$1.swapCreatePost(c).catch(Ie);if(Re(y))return u(y.error);let{cbor:F,txId:C}=Ct.parse(y.data),D={cbor:await it(e$1.wallet,F,!1,"conway")},R=await g$1.swapSubmitPost(D).catch(Ie);return Re(R)?u(R.error):(f(C),C)}catch(l){console.error(l),u("Unknown error. Try again later");}}var n={background:{purple100:`linear-gradient(
180deg,
rgba(139, 92, 246, 0.01) 0%,
rgba(255, 255, 255, 0) 100%
),
rgba(27, 27, 30, 0.1)`,purple200:`linear-gradient(
180deg,
rgba(139, 92, 246, 0.03) 0%,
rgba(255, 255, 255, 0) 100%
),
rgba(27, 27, 30, 1)`,solid:"rgba(27, 27, 30, 0.9)",modal:"#08040f",homeCards:`radial-gradient(
50% 50% at 20% 20%,
rgba(125, 70, 250, 0.18) 0%,
rgba(69, 44, 126, 0) 100%
),
linear-gradient(
180deg,
rgba(139, 92, 246, 0.03),
rgba(255, 255, 255, 0)
),
rgba(27, 27, 30, 0.9)`,topPortfolios:`radial-gradient(
50% 50% at 50% 50%,
rgba(125, 70, 250, 0.12) 0%,
rgba(69, 44, 126, 0) 100%
),
linear-gradient(
180deg,
rgba(139, 92, 246, 0.03),
rgba(255, 255, 255, 0)
),
rgba(27, 27, 30, 0.9)`,join:`radial-gradient(
50% 50% at 50% 50%,
rgba(125, 70, 250, 0.15) 47%,
rgba(69, 44, 126, 0) 100%
),
linear-gradient(
180deg,
rgba(139, 92, 246, 0.03),
rgba(255, 255, 255, 0)
),
rgba(27, 27, 30, 0.9)`,middleBlub:`radial-gradient(
50% 50% at 50% 50%,
rgba(125, 70, 250, 0.12) 63.5%,
rgba(69, 44, 126, 0) 100%
),
linear-gradient(
180deg,
rgba(139, 92, 246, 0.03),
rgba(255, 255, 255, 0)
),
rgba(27, 27, 30, 0.9)`,card:`linear-gradient(
180deg,
rgba(139, 92, 246, 0.03),
rgba(255, 255, 255, 0)
),
rgba(27, 27, 30, 0.9)`,tableModals:`linear-gradient(
180deg,
rgba(139, 92, 246, 0.03) 0%,
rgba(255, 255, 255, 0) 100%
),
rgba(27, 27, 30, 0.9)`},gradient:{start:"rgba(139, 92, 246, 0.03)",end:"rgba(255, 255, 255, 0)",angle:"180deg",button:`linear-gradient(
87deg,
rgba(76, 29, 149, 0.2) 0%,
rgba(124, 58, 237, 0.2) 100%
)`,button100:`linear-gradient(
87deg,
rgba(77, 29, 149, 0.794) 0%,
rgba(124, 58, 237, 0.2) 100%
)`,table:`linear-gradient(
87deg,
rgba(76, 29, 149, 0.05) 0%,
rgba(124, 58, 237, 0.05) 100%
)`},purple:{divider:"#3a2e5c",subtext:"#a78bfa",button100:"#8b5cf6",button200:"#8a5cf6c7",metera:"#8b5cf6",metera100:"#c4b5fd",metera200:"#8b5cf669",metera300:"rgba(76, 29, 149, 0.4)"},distribution:{one:"#4c1d95",two:"#6d28d9",three:"#8b5cf6",four:"#a78bfa",five:"#c4b5fd"},neutral:{1e3:"rgba(23, 23, 23, 1)",900:"rgba(23, 23, 23, 1)",800:"#262626",600:"#525252",500:"#737373",400:"#a3a3a3",300:"#d4d4d4",200:"#e5e5e5"},cards:{stroke:"rgba(192, 166, 253, 0.25)",stroke2:"rgba(192, 166, 253, 0.2)",background:"#ef4444"},error:{error500:"#ef4444"},success:{success500:"#22c55e"},offWhite:{offWhite400:"#fafaf4"},primary:{primary50:"#f5f3ff"},header:{table:"#2c2658"},circle:{fill:"#83d2ff"},backgrounds:{one:"#3b2b67",two:"#270e45"},animatedBorder:{initialValue:"0turn",animationTo:"1turn",bgSpin:keyframes`
to {
--animated-border: 1turn;
}
`},blinkAnimation:keyframes`
{
0%,
100% {
transform: scale(1);
}
50% {
transform: scale(0.7);
}
}
`,opacityAnimation:keyframes`
{
0%,
100% {
opacity: 1;
}
50% {
opacity: 0.6;
}
}
`};var _t=forwardRef(({color:e="#FAFAFA"},t)=>jsxs("svg",{ref:t,width:"15",height:"15",viewBox:"0 0 20 20",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[jsx("g",{clipPath:"url(#clip0_785_532)",children:jsx("path",{d:"M7.57499 7.49984C7.77091 6.94289 8.15762 6.47326 8.66662 6.17411C9.17562 5.87497 9.77407 5.76562 10.356 5.86543C10.9379 5.96524 11.4657 6.26777 11.8459 6.71944C12.2261 7.17111 12.4342 7.74277 12.4333 8.33317C12.4333 9.99984 9.93332 10.8332 9.93332 10.8332M9.99999 14.1665H10.0083M18.3333 9.99984C18.3333 14.6022 14.6024 18.3332 9.99999 18.3332C5.39762 18.3332 1.66666 14.6022 1.66666 9.99984C1.66666 5.39746 5.39762 1.6665 9.99999 1.6665C14.6024 1.6665 18.3333 5.39746 18.3333 9.99984Z",stroke:"#A3A3A3",strokeWidth:"1.66667",strokeLinecap:"round",strokeLinejoin:"round"})}),jsx("defs",{children:jsx("clipPath",{id:"clip0_785_532",children:jsx("rect",{width:"20",height:"20",fill:"white"})})})]}));_t.displayName="InfoSVG";var De=_t;var P=(e,t=2,r=void 0,o=void 0)=>Number(e).toLocaleString("en-US",{useGrouping:!0,minimumFractionDigits:r!==void 0?r:t,maximumFractionDigits:o!==void 0?o:t});function $r(e){e.batcherFee.plus(e.managerFee).plus(e.platformFee).abs();let r=P(e.managerFee.abs().div(10**6).toFixed(6),6,0),o=P(e.batcherFee.abs().div(10**6).toFixed(6),6,0),i=P(e.platformFee.abs().div(10**6).toFixed(6),6,0),s=P(e.expectedAmount.abs().div(10**6).toFixed(6),6,0),p=P(e.withdrawLovelace.abs().div(10**6).toFixed(6),6,0),u=P(X(2e6).div(10**6).toFixed(6),6,0),f=P(X(2e6).div(10**6).toFixed(6),6,0),h=`- ${r} $${e.mtkTicker}`,g=`- ${o} \u20B3`,l=`- ${i} \u20B3`,a=`${s} $${e.mtkTicker}`,d=`${p} \u20B3`,c=e.type==="mint"?`$${e.mtkTicker} expected to go to your wallet`:"Expected worth of tokens you will receive",y=`${u} \u20B3`,F=`${f} \u20B3`;return jsx(Flex,{width:"100%",height:"fit-content",gap:"12px",justifyContent:"space-between",flexDirection:"column",children:e.hasInsuficientToken&&e.type==="mint"?jsxs(Fragment,{children:[jsx(ae,{label:"Zapping via",info:"You are submitting a bulk order via Minswap. Fees are calculated based on Minswap fees",imageSrc:"https://sqvzfgobtlzbovqbkaax.supabase.co/storage/v1/object/public/sdk-assets//minswap_horizontal.svg"}),jsx(ae,{label:"Batching Fees",info:"Batching fees might be lower if you hold MIN in your wallet",value:y}),jsx(ae,{label:"Minimum UTxO deposit",info:"This amount of ADA will be held as minimum UTxO ADA and will be returned when your orders are processed or cancelled",value:F})]}):jsxs(Fragment,{children:[jsx(ae,{label:"Manager Fee",info:`$${e.mtkTicker} paid to the Manager`,value:h}),jsx(ae,{label:"Batcher Fee",info:"ADA paid for processing",value:g}),jsx(ae,{label:"Platform Fee",info:"ADA paid for placing orders",value:l}),e.type==="mint"?jsx(ae,{label:"Expected Amount",info:c,value:a}):jsx(ae,{label:"Expected worth of tokens",info:c,value:d})]})})}function ae({label:e,value:t,info:r,imageSrc:o}){return jsxs(Flex,{justifyContent:"space-between",width:"100%",fontSize:"14px",fontWeight:"400",lineHeight:"20px",children:[jsxs(Flex,{gap:2,alignItems:"center",children:[jsx(Text,{color:"#A3A3A3",children:e}),jsx(Tooltip,{placement:"top",sx:{background:"var(--bg-200)",border:"0.5px solid var(--cards-stroke)",borderRadius:"0.75rem",color:"var(--off-white-400)",fontWeight:"600",padding:"1rem",backdropFilter:"blur(30px)"},label:r||e,children:jsx(Flex,{display:"flex",align:"center",cursor:"ponter",children:jsx(De,{})})})]}),o?jsx("img",{src:o,alt:e,style:{width:"6rem"}}):jsxs(Text,{color:"#FAFAFA",children:[t," "]})]})}var Ut=$r;var Yr=({color:e="#FAFAFA"})=>jsx("svg",{width:"18",height:"18",viewBox:"0 0 18 18",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:jsx("path",{d:"M12 6.00024V3.37573C12 2.75192 12 2.44002 11.8686 2.24834C11.7538 2.08087 11.576 1.96711 11.3758 1.93305C11.1467 1.89406 10.8635 2.02477 10.2971 2.28618L3.64426 5.35673C3.13913 5.58987 2.88656 5.70644 2.70158 5.88723C2.53804 6.04705 2.41321 6.24215 2.33663 6.45761C2.25 6.70133 2.25 6.9795 2.25 7.53583V11.2502M12.375 10.8752H12.3825M2.25 8.40024L2.25 13.3502C2.25 14.1903 2.25 14.6104 2.41349 14.9312C2.5573 15.2135 2.78677 15.4429 3.06901 15.5867C3.38988 15.7502 3.80992 15.7502 4.65 15.7502H13.35C14.1901 15.7502 14.6101 15.7502 14.931 15.5867C15.2132 15.4429 15.4427 15.2135 15.5865 14.9312C15.75 14.6104 15.75 14.1903 15.75 13.3502V8.40024C15.75 7.56016 15.75 7.14012 15.5865 6.81925C15.4427 6.53701 15.2132 6.30754 14.931 6.16373C14.6101 6.00024 14.1901 6.00024 13.35 6.00024L4.65 6.00024C3.80992 6.00024 3.38988 6.00024 3.06901 6.16373C2.78677 6.30754 2.5573 6.53701 2.41349 6.81925C2.25 7.14012 2.25 7.56016 2.25 8.40024ZM12.75 10.8752C12.75 11.0823 12.5821 11.2502 12.375 11.2502C12.1679 11.2502 12 11.0823 12 10.8752C12 10.6681 12.1679 10.5002 12.375 10.5002C12.5821 10.5002 12.75 10.6681 12.75 10.8752Z",stroke:e,strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),lt=Yr;var Kr=({status:e,showStatus:t})=>{let r={Confirmed:"#22C55E",Failed:"#EF4444",Invalid:"#EF4444",Cancelled:"#EF4444",Pending:"#FCD34D",Confirming:"#FCD34D",Processing:"#FCD34D",Cancelling:"#EF4444",Insufficient:"#FBBF24"},o=e==="Pending"||e==="Cancelling"||e==="Processing";return jsxs(Flex,{align:"center",gap:2,children:[jsx(Box,{style:o?{animation:`${n.blinkAnimation} 1s infinite`}:{},children:jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"6",height:"6",viewBox:"0 0 6 6",fill:"none",children:jsx("circle",{cx:"3",cy:"3",r:"3",fill:r[e]})})}),t&&jsx(Box,{style:o?{animation:`${n.opacityAnimation} 1s infinite`}:{},children:e})]})},U=Kr;var Jr=({step:e,hasBorder:t=!1,circlePadding:r="0.6rem"})=>{let o=parseInt(e,10);return jsxs(Flex,{justify:"space-between",position:"relative",alignItems:"center",width:"100%",padding:t?"1rem":"",borderRadius:"0.75rem",border:t?`1px solid ${n.cards.stroke}`:"",sx:{fontSize:{lg:"0.875rem",sm:"10px"}},fontWeight:500,children:[jsx(Circle,{padding:r,bg:o>=1?n.purple.metera:"#E2E8F0",color:o>=1?"white":"#262626",zIndex:1,children:"1. Zap-in"}),jsx(Circle,{padding:r,bg:o>=2?n.purple.metera:"#E2E8F0",color:o>=2?"white":"#262626",zIndex:1,children:"2. Track & Receive"}),jsx(Circle,{padding:r,bg:o>=3?n.purple.metera:"#E2E8F0",color:o>=3?"white":"#262626",fontWeight:500,zIndex:1,children:"3. Mint MTKs"}),jsx(Box,{position:"absolute",width:t?"80%":"100%",top:"50%",h:"2px",bg:o>=1?n.purple.metera:"#E2E8F0",zIndex:0})]})},$t=Jr;var Kt="https://sqvzfgobtlzbovqbkaax.supabase.co/storage/v1/object/public/sdk-assets//cardanoimage.png",eo="https://sqvzfgobtlzbovqbkaax.supabase.co/storage/v1/object/public/sdk-assets//swap-arrow.svg";function to({type:e,portfolioTicker:t,portfolioImageUrl:r,balance:o,inputValue:i,setInputValue:s,mtkUnit:p,expectedAmount:u,withdrawLovelace:f,switchType:h,showBreakdown:g,hasInsufficientToken:l,portfolioAssets:a,background:d}){let c=()=>{},y=S=>{S.target.value===""&&s(new X(0));},F=()=>{o&&s(X(o[p]?.toString()||0).div(10**MTK_DECIMALS));},R=()=>jsx(Flex,{border:`1px solid ${n.cards.stroke}`,_hover:{border:`1px solid ${n.purple.metera}`},_focusWithin:{border:`1px solid ${n.purple.metera}`},height:"105px",borderRadius:"1rem",padding:"1.5rem",width:"full",align:"center",children:jsxs(Flex,{justifyContent:"space-between",alignItems:"center",width:"100%",gap:"8px",children:[jsx(Flex,{position:"relative",width:"full",flex:1,alignItems:"flex-start",children:jsxs(Flex,{flexDir:"column",gap:1,children:[jsx(Box,{fontSize:"0.875rem",color:"#A3A3A3",children:"Send"}),jsx(NumericFormat,{className:"mint-input",value:i.gt(0)?i.toString():"",placeholder:e==="mint"?l?"0.0":"ADA":"0.0",valueIsNumericString:!0,onFocus:c,onBlur:y,thousandSeparator:!0,isAllowed:({floatValue:S})=>(S||0)<=1e7,max:1e7,decimalScale:MTK_DECIMALS,style:{width:"100%",color:n.offWhite.offWhite400,fontSize:"32px",fontWeight:"500",lineHeight:"32px",letterSpacing:"-0.02em",textAlign:"left",backgroundColor:"transparent",border:"none",borderRadius:0,outline:"none"},onValueChange:S=>{s(new X(Number(S.floatValue?S.value:0)));}})]})}),jsxs(Flex,{flexDirection:"column",color:"#A3A3A3",children:[jsx(Flex,{justify:"right",cursor:"pointer",children:e==="burn"&&jsxs(Flex,{justify:"right",fontSize:"0.75rem",color:n.neutral[400],fontWeight:400,cursor:"pointer",onClick:F,display:"flex",flexDirection:"row",gap:2,alignItems:"flex-end",children:[jsx(lt,{color:"#A3A3A3"}),jsx("span",{children:X(o?.[p]?.toString()||0).div(10**MTK_DECIMALS).toFixed(2)})]})}),jsxs(Flex,{flexDirection:"row",color:"#A3A3A3",align:"center",gap:1,children:[e==="burn"?jsx(Box,{width:"1.25rem",children:jsx(Image,{objectFit:"cover",src:r})}):l&&jsx(Box,{width:"1.25rem",children:jsx(Image,{objectFit:"cover",src:Kt})}),e==="mint"&&!l&&jsxs(Flex,{justify:"right",fontSize:"0.65rem",color:"#a3a3a3",fontWeight:400,display:"flex",flexDirection:"row",align:"center",flexDir:"column",children:[!i.eq(0,10)&&jsx(Box,{children:"ADA worth of"}),jsxs(Flex,{align:"center",children:[a.sort((S,I)=>S.asset.ticker.localeCompare(I.asset.ticker)).slice(0,2).map((S,I)=>jsx(Box,{width:"2rem",height:"2rem",overflow:"hidden",borderRadius:"50%",ml:"-0.5rem",zIndex:3+I,position:"relative",children:jsx(Image,{src:S.asset.imageUrl,alt:S.asset.ticker},S.asset.id+I)},S.asset.id+I)),a.length>2&&jsx(Box,{fontSize:"0.725rem",alignItems:"center",justifyContent:"center",color:"white",background:n.purple.metera,width:"28px",height:"28px",borderRadius:"full",padding:"0.3rem",marginLeft:"-1rem",zIndex:4,children:jsxs(Flex,{align:"center",height:"full",justify:"center",fontWeight:700,children:["+",a.length-2]})})]})]}),jsxs(Text,{fontSize:"1.5rem",fontWeight:"500",lineHeight:"32px",letterSpacing:"-0.02em",textAlign:"right",paddingY:"4px",children:[e==="mint"?"":t,e==="mint"&&l&&"ADA"]})]})]})]})}),L=()=>{let S=e==="mint"?u:f;return jsx(Flex,{border:`1px solid ${n.cards.stroke}`,bg:`${n.cards.background}, linear-gradient(180deg, rgba(139, 92, 246, 0.03) 0%, rgba(255, 255, 255, 0.00) 100%), rgba(27, 27, 30, 0.90)`,_hover:{border:`1px solid ${n.purple.metera}`},_focusWithin:{border:`1px solid ${n.purple.metera}`},height:"105px",borderRadius:"1rem",padding:"1.5rem",width:"full",align:"center",children:jsxs(Flex,{justifyContent:"space-between",alignItems:"center",width:"100%",gap:"8px",children:[jsx(Flex,{position:"relative",width:"full",flex:1,alignItems:"flex-start",children:jsxs(Flex,{flexDir:"column",gap:1,children:[jsx(Box,{color:"#A3A3A3",children:"Receive"}),jsx(NumericFormat,{className:"mint-input",value:S.gt(0)?S.abs().div(10**MTK_DECIMALS).toString():"",valueIsNumericString:!0,placeholder:e==="mint"?"0.0":"ADA",thousandSeparator:!0,readOnly:!0,decimalScale:MTK_DECIMALS,style:{width:"100%",color:n.offWhite.offWhite400,fontSize:"32px",fontWeight:"500",lineHeight:"32px",letterSpacing:"-0.02em",textAlign:"left",backgroundColor:"transparent",border:"none",borderRadius:0,outline:"none"}})]})}),jsxs(Flex,{flexDirection:"column",height:"full",justify:"center",color:"#A3A3A3",children:[jsxs(Flex,{flexDirection:"row",color:"#A3A3A3",gap:1,align:"center",children:[e==="burn"?jsxs(Flex,{justify:"right",fontSize:"0.65rem",color:"#a3a3a3",fontWeight:400,display:"flex",flexDirection:"row",align:"center",flexDir:"column",children:[!i.eq(0,10)&&jsx(Box,{children:"ADA worth of"}),jsxs(Flex,{align:"center",children:[a.sort((I,_)=>I.asset.ticker.localeCompare(_.asset.ticker)).slice(0,2).map((I,_)=>jsx(Box,{width:"2rem",height:"2rem",overflow:"hidden",borderRadius:"50%",ml:"-0.5rem",zIndex:3+_,position:"relative",children:jsx(Image,{src:I.asset.imageUrl,alt:I.asset.ticker},I.asset.id+_)},I.asset.id+_)),a.length>2&&jsx(Box,{fontSize:"0.725rem",alignItems:"center",justifyContent:"center",color:"white",background:n.purple.metera,width:"28px",height:"28px",borderRadius:"full",padding:"0.3rem",marginLeft:"-1rem",zIndex:4,children:jsxs(Flex,{align:"center",height:"full",justify:"center",fontWeight:700,children:["+",a.length-2]})})]})]}):jsx(Box,{width:"1.25rem",children:jsx(Image,{objectFit:"cover",src:e==="mint"?r:Kt})}),jsx(Text,{fontSize:"1.5rem",fontWeight:"500",lineHeight:"32px",letterSpacing:"-0.02em",textAlign:"right",paddingY:"4px",children:e==="mint"?t:""})]}),jsx(Flex,{justify:"right",children:e==="mint"&&jsxs(Flex,{justify:"right",fontSize:"0.65rem",color:"#a3a3a3",fontWeight:400,display:"flex",flexDirection:"row",gap:2,align:"center",children:[jsx(lt,{color:"#A3A3A3"}),jsx("span",{children:X(o?.[p]?.toString()||0).div(10**MTK_DECIMALS).toFixed(2)})]})})]})]})})};return jsxs(Flex,{flexDirection:"column",alignItems:"center",children:[jsxs(Flex,{position:"relative",width:"full",alignItems:"center",flexDirection:"column",gap:"0.3rem",children:[R(),jsx(Flex,{position:"absolute",background:d||"#08040f",top:"50%",left:"50%",transform:"translate(-50%, -50%)",width:"2rem",height:"2rem",borderRadius:"50%",border:`1px solid ${n.cards.stroke}`,justify:"center",align:"center",cursor:"pointer",_hover:{border:`1px solid ${n.purple.metera}`},onClick:S=>{h(e==="mint"?"burn":"mint"),s(new X(0));},children:jsx(Image,{src:eo,objectFit:"cover"})}),L()]}),jsx(Flex,{alignItems:"center",width:"full",gap:"0.5rem",onClick:g,cursor:"pointer",paddingY:"0.5rem",height:"100%",align:"center",children:!i.eq(0,10)&&jsxs(Flex,{flexDir:"column",gap:"0.5rem",width:"full",children:[jsxs(Box,{height:"auto",width:"auto",padding:"0rem",border:`1px solid ${n.cards.stroke}`,sx:{cursor:"pointer",border:"2px solid transparent",transition:"border 0.2s, transform 0.2s",position:"relative",borderRadius:"0.75rem"},children:[" ",jsx(Flex,{align:"center",gap:2,border:`1px solid ${n.cards.stroke}`,borderRadius:"0.75rem",padding:"1rem",fontSize:"0.875rem",width:"100%",justify:"center",bg:"var(--bg-100)",children:l?jsx(Box,{color:"#39b75a",fontSize:"1rem",fontWeight:500,children:"Mint MTKs by providing ADA. Click for details."}):jsxs(Fragment,{children:[" ",jsx(U,{showStatus:!1,status:"confirmed"}),jsx(Box,{fontSize:"1rem",color:"#39b75a",children:"Assets found in wallet. View breakdown."})]})})]}),e==="mint"&&l?jsx($t,{step:"1",hasBorder:!0}):""]})})]})}var Gt=to;var io=forwardRef(({primaryButtonColor:e=n.purple.button100,hoverButtonColor:t=n.purple.button200,...r},o)=>jsx(Button,{textColor:n.primary.primary50,background:e,fontSize:".875rem",borderRadius:"0.75rem",isDisabled:r.disabled,_hover:{background:t},_active:{bg:"#414a60"},_disabled:{filter:"grayscale(100%)"},ref:o,...r})),Xt=io;var co=forwardRef((e,t)=>jsx(Button,{ref:t,textColor:n.primary.primary50,fontSize:".875rem",borderRadius:"22px",background:n.gradient.button,border:`1px solid ${n.cards.stroke}, rgba(139, 93, 247, 0.35)`,_hover:{background:n.gradient.button100},_active:{bg:"#414a60"},...e})),Zt=co;var uo="https://bjlavcngusgdszvtjwdr.supabase.co/storage/v1/object/public/Images//powered_white_stacked.png";function go(e){let{leftOnclick:t,leftText:r,rightOnclick:o,rightText:i,pb:s="1rem",pt:p="1rem",disableLeft:u=!1,disableRight:f=!1,rightBtnProps:h={},leftBtnProps:g={},poweredBy:l,primaryButtonColor:a,hoverButtonColor:d}=e;return jsxs(Flex,{gap:"8px",pb:s,pt:p,height:"full",mt:"auto",justify:"space-between",align:"center",children:[jsx(Flex,{children:r&&jsx(Zt,{onClick:t,disabled:u,width:"100%",borderRadius:"60rem",border:`1.5px solid ${n.purple.metera}`,fontSize:"0.875rem",color:n.primary.primary50,fontWeight:"700",cursor:u?"not-allowed":"pointer",...g,children:r})}),i&&jsx(Xt,{flex:"2",width:"100%",onClick:o,disabled:f,cursor:f?"not-allowed":"pointer",...h,primaryButtonColor:a,hoverButtonColor:d,children:i}),l&&jsx(Flex,{flex:1,children:jsx("a",{href:"https://test.meteraprotocol.io/",target:"blank",children:jsx("img",{height:"80%",src:uo,alt:"Powered by Metera"})})})]})}var Te=go;var Y=({children:e,...t})=>jsx(Td,{overflow:"hidden",fontSize:"1rem",color:"white",cursor:"pointer",borderRadius:"2rem",...t,children:e});var So=e=>e<0n?-e:e;function yo(e){let t=new BigRational(0n,1n),{fontSize:r="12px"}=e,o=Object.entries(e.formattedState.state.assets).reduce((C,[m,D])=>{let R=new BigRational(D,1n).mul(e.formattedState.prices[m]);return C.add(R).reduce()},new BigRational(0n,1n)),i=e.formattedState.prices[e.item.asset.id].mul(new BigRational(e.formattedState.state.assets[e.item.asset.id],1n)).reduce();e.formattedState.state.assets[e.item.asset.id];i.div(o).mul(new BigRational(100n,1n).reduce());let u=Object.entries(e.amountsToModify).reduce((C,[m,D])=>{let R=new BigRational(D,1n).mul(e.formattedState.prices[m]);return C.add(R).reduce()},new BigRational(0n,1n)),f=e.formattedState.prices[e.item.asset.id].mul(new BigRational(e.amountsToModify[e.item.asset.id],1n)).reduce();u.eq(t)?t:f.div(u).mul(new BigRational(100n,1n)).reduce();e.amountsToModify[e.item.asset.id];let l=u.add(o).reduce(),a=i.add(f).reduce();l.eq(t)?t:a.div(l).mul(new BigRational(100n,1n)).reduce();let y=So(e.amountsToModify[e.item.asset.id]||0n).toString(),F=X((e.amountsToModify[e.item.asset.id]||0n).toString()).lte(X((e.balance?.[j(e.item.asset)]||0n).toString()));return jsxs(Tr,{verticalAlign:"middle",fontSize:r,children:[jsx(Td,{textAlign:"left",align:"center",flexDir:"row",paddingX:"6px",paddingY:"12px",paddingLeft:"10px",width:"fit-content",children:jsx(Flex,{justify:"left",children:jsx(Flex,{justify:"left",children:jsxs(Flex,{flexDir:"row",gap:2,align:"center",children:[jsxs(Box,{width:"1.75rem",height:"1.75rem",overflow:"hidden",borderRadius:"full",background:n.purple.metera200,children:[jsx(Image,{boxSize:"100%",objectFit:"cover",src:e.item.asset.imageUrl,alt:e.item.asset.ticker}),"-"]}),jsx(Box,{fontSize:"0.785rem",color:n.primary.primary50,fontWeight:"600",children:e.item.asset.ticker})]})})})}),jsx(Td,{align:"center",fontSize:r==="12px"?"1rem":r,paddingX:"6px",paddingY:"12px",children:jsx(Flex,{gap:2,justify:"flex-end",children:jsx(mt,{color:n.primary.primary50,value:X(y.toString()),decimals:e.item.asset.decimals})})}),jsx(Td,{align:"center",fontSize:r==="12px"?"1rem":r,paddingX:"6px",paddingY:"12px",children:jsxs(Flex,{gap:1,justify:"right",children:[jsx(Box,{children:"\u20B3"}),jsx(mt,{color:n.primary.primary50,value:z(f).abs(),decimals:0})]})}),e.type==="mint"&&jsx(Td,{align:"center",fontSize:r==="12px"?"1rem":r,paddingX:"6px",paddingY:"12px",children:jsxs(Flex,{align:"center",justifyContent:"flex-end",gap:2,children:[F?jsx(U,{showStatus:!1,status:"Confirmed"}):jsx(Tooltip,{sx:{background:n.cards.background,border:"0.5px solid ",borderRadius:"1rem",color:n.offWhite.offWhite400,fontWeight:"600",padding:"1rem",backdropFilter:"blur(30px)"},label:`You don't have enough ${e.item.asset.name}. Click the dot to visit our faucet.`,children:jsx("button",{children:jsx("a",{href:"/faucet",style:{color:"var(--link-color)"},children:jsx(U,{showStatus:!1,status:"Cancelled"})})})}),jsx(mt,{value:X((e.balance?.[j(e.item.asset)]||0n).toString()),decimals:e.item.asset.decimals,color:n.primary.primary50})]})})]})}var mt=e=>jsx(Flex,{flexDir:"column",whiteSpace:"nowrap",children:jsx(Box,{color:e.color,children:P(e.value.div(10**e.decimals).toString())})}),Jt=yo;var Io=({type:e,portfolioAssets:t,balance:r,amountsToModify:o,formattedState:i,hideBreakdown:s,from:p,to:u,portfolioTicker:f,hasInsufficientToken:h,isModal:g=!0,background:l})=>jsxs(Flex,{width:"full",height:"full",flexDirection:"column",padding:"1rem",background:l||n.background.modal,children:[jsxs(Flex,{alignItems:"flex-end",width:"100%",flexDirection:"column",gap:1,padding:"8px",children:[jsx(IconButton,{"aria-label":"Close",borderRadius:"100%",fill:"#a78bfa",color:"#a78bfa;",size:"sm",onClick:s,background:"transparent",icon:jsx(CloseIcon,{}),alignSelf:"flex-end"}),jsxs(Flex,{width:"100%",justifyContent:"center",gap:"1rem",children:[jsxs(Flex,{fontSize:"24px",lineHeight:"24px",gap:"4px",children:[jsx(Text,{fontWeight:"500",letterSpacing:"-0.02em",color:"#A3A3A3",children:e==="mint"?"ADA":f}),P(p.abs().toString())]}),jsx(MdSwapHoriz,{}),jsxs(Flex,{fontSize:"24px",lineHeight:"24px",gap:"4px",children:[jsx(Text,{fontWeight:"500",letterSpacing:"-0.02em",color:"#A3A3A3",children:e==="mint"?f:"ADA"}),P(u.abs().div(10**6).toFixed(6),4)]})]}),jsxs(Flex,{paddingX:"0.5rem",gap:2,width:"100%",height:"2.5rem",justifyContent:"center",alignItems:"center",children:[jsx(U,{showStatus:!1,status:h?"Insufficient":"Confirmed"}),jsx(Text,{fontSize:"14px",fontWeight:"400",lineHeight:"20px",textAlign:"left",children:"Tokens breakdown"})]})]}),jsx(Box,{overflowY:"auto",borderRadius:"0.75rem",width:"full",paddingTop:"0.15rem",children:jsx(Flex,{gap:3,overflow:"auto",children:jsx(TableContainer,{overflowY:"auto",sx:{"&::-webkit-scrollbar":{width:"0px"},"&::-webkit-scrollbar-track":{background:"none"},"&::-webkit-scrollbar-thumb":{background:"none"},"&::-webkit-scrollbar-thumb:hover":{background:"none"}},children:jsxs(Table,{variant:"unstyled",sx:{tableLayout:"fixed"},children:[jsx(Thead,{position:"sticky",top:0,left:0,zIndex:1,borderBottom:"none",children:jsxs(Tr,{children:[jsx(Y,{textAlign:"left",paddingX:"8px",paddingY:"1rem",paddingLeft:"10px",fontSize:"0.875rem",color:n.neutral[400],borderTopLeftRadius:"full",children:"Name"}),jsx(Y,{textAlign:"right",paddingX:0,paddingY:"1rem",fontSize:"0.875rem",color:n.neutral[400],children:jsxs(Flex,{gap:2,children:[jsx(Box,{children:"Amount"}),jsx(Tooltip,{sx:{background:n.cards.background,border:`0.5px solid ${n.cards.stroke}`,borderRadius:"1rem",color:n.offWhite.offWhite400,fontWeight:"600",padding:"1rem",backdropFilter:"blur(30px)"},label:`This is the amount of tokens you${e==="mint"?" need to deposit into":"'ll receive from"} the instrument. `,children:jsx("button",{children:jsx(De,{})})})]})}),jsx(Y,{textAlign:"right",paddingX:0,paddingY:"1rem",fontSize:"0.875rem",color:n.neutral[400],children:jsxs(Flex,{width:"full",justify:"center",gap:2,children:[jsx(Box,{children:"Worth"}),jsx(Tooltip,{sx:{background:n.cards.background,border:`0.5px solid ${n.cards.stroke}`,borderRadius:"1rem",color:n.offWhite.offWhite400,fontWeight:"600",padding:"1rem",backdropFilter:"blur(30px)"},label:"Value in ADA of each asset",children:jsx("button",{children:jsx(De,{})})})]})}),e==="mint"&&jsx(Y,{textAlign:"right",paddingX:0,paddingY:"1rem",fontSize:"0.875rem",color:n.neutral[400],paddingRight:"6px",children:"Balance"})]})}),jsx("tbody",{style:{maxHeight:"286px"},children:t.sort((a,d)=>a.asset.ticker.localeCompare(d.asset.ticker)).map((a,d)=>jsx(Jt,{item:a,type:e,balance:r,amountsToModify:o,formattedState:i,...g?{}:{fontSize:"12.5px"}},a.asset.id+d))})]})})})})]});var er=Io;var Wo=tr.default||tr,No=Wo(ModalContent)`
@property --animated-border {
syntax: '<angle>';
inherits: true;
initial-value: 0turn;
}
`,rr=({children:e,minHeight:t="15rem",minWidth:r="50%",...o})=>jsxs(Modal,{isCentered:!0,...o,children:[jsx(ModalOverlay,{bg:"#171717B3"}),jsx(No,{background:n.cards.background,minHeight:t,minWidth:r,padding:"0rem",borderRadius:"1.25rem",border:`1px solid ${n.cards.stroke}`,sx:{cursor:"pointer",border:"2px solid transparent",transition:"border 0.2s, transform 0.2s",borderRadius:"10px !important","--animated-border":n.animatedBorder.initialValue,background:`
conic-gradient(
from var(--animated-border),
#171717a3,
#171717a3 5%,
#171717a3 60%,
#171717a3 95%
)
padding-box,
conic-gradient(
from var(--animated-border),
transparent 25%,
#6d28d9,
#a78bfa 99%,
transparent
)
border-box`,animation:`${n.animatedBorder.bgSpin} 3s linear infinite`},children:jsx(ModalBody,{padding:0,children:e})})]});var bt=({title:e="Metera Order in Progress",description:t="Confirm the transaction in your wallet",isSwap:r,background:o})=>jsxs(Flex,{flexDir:"column",gap:"2rem",minHeight:"264px",align:"center",justify:"center",padding:"24px",background:o||n.background.modal,borderRadius:"10px",width:"100%",color:n.offWhite.offWhite400,children:[jsxs(Flex,{flexDir:"column",gap:"1rem",align:"center",justify:"center",padding:"24px",borderRadius:"0.75rem",width:"100%",cursor:"default",children:[jsx(Text,{fontSize:"18px",fontWeight:"500",lineHeight:"28px",textAlign:"center",children:e}),jsx(Flex,{children:r?jsx(Flex,{flexDir:"column",width:"25rem",gap:"1rem",children:jsx(Flex,{justify:"center",color:n.neutral[400],fontSize:"16px",fontWeight:400,lineHeight:"24px",textAlign:"center",children:t})}):jsx(Flex,{justify:"center",color:n.neutral[400],fontSize:"16px",fontWeight:400,lineHeight:"24px",textAlign:"center",children:t})})]}),jsxs(Flex,{fontSize:"12px",fontWeight:400,lineHeight:"20px",textAlign:"left",gap:1,children:[jsx(Text,{as:"span",children:"Do you need help?"}),jsx(Link,{href:"https://discord.com/invite/Ws5Z5ZACme",color:n.purple.button100,target:"blank",children:"Contact support"})]})]});function _o(e){return jsx(rr,{...e.disc,minWidth:"376px",minHeight:"274px",children:jsx(bt,{title:e.title,description:e.description,isSwap:e.isSwap})})}var nr=_o;var ir=({children:e,minHeight:t,maxWidth:r,p:o="",...i})=>jsxs(Modal,{isCentered:!0,...i,children:[jsx(ModalOverlay,{bg:"#171717B3"}),jsx(ModalContent,{background:n.background.purple200,minHeight:t||"23rem",maxWidth:r||"40%",borderRadius:"1.25rem",border:`1px solid ${n.cards.stroke}`,sx:{backdropFilter:"blur(60px)"},children:jsx(ModalBody,{p:o||0,children:e})})]});var Yo="https://bjlavcngusgdszvtjwdr.supabase.co/storage/v1/object/public/Images//powered_white_stacked.png",xt=({onClose:e,title:t="Transaction Submitted",description:r="Please allow some minutes for your transaction to process on-chain",route:o="orders",routeText:i="Order",background:s})=>jsx(Fragment,{children:jsxs(Flex,{background:s||n.background.modal,flexDir:"column",width:"full",height:"full",maxWidth:"376px",minHeight:"274px",gap:"1.5rem",padding:"1rem 2.5rem",alignItems:"center",mx:"auto",children:[jsx(Box,{children:jsx(Image,{src:Yo})}),jsxs(Flex,{flexDirection:"column",gap:"5px",width:"100%",alignItems:"center",children:[jsx(Text,{fontSize:"18px",fontWeight:"500",lineHeight:"28px",textAlign:"center",color:n.offWhite.offWhite400,children:t}),jsx(Text,{color:n.neutral[400],fontSize:"16px",fontWeight:400,lineHeight:"24px",textAlign:"center",children:r})]}),jsx(Te,{poweredBy:!1,rightText:`View ${i}`,rightOnclick:()=>{window.open(`https://preprod.meteraprotocol.io/me/${o}`,"_blank");},leftText:"Close",leftOnclick:e})]})});function qo({disc:e,onClose:t,title:r,description:o,route:i,routeText:s}){return jsx(ir,{...e,isOpen:e.isOpen,maxWidth:"376px",minHeight:"274px",children:jsx(xt,{onClose:t})})}var dr=qo;function Zo({inputValue:e,portfolio:t,type:r}){let o=useMemo(()=>Wt(t),[t]),{amountsPerAsset:i,mintedMicroMTK:s,userReceiveMTK:p,fees:u,withdrawLovelace:f,withdrawUserLvc:h}=useMemo(()=>{let g=Fe(e),l=At(t),a=r==="mint"?g:g.negate().mul(new BigRational(BigInt(10**MTK_DECIMALS),1n)).mul(l).reduce(),d=Nt(a,o),c=computeFees({portfolioState:{batcherFee:X(t.batcherFee.toString()),entryFee:X(t.entryFee.toString()),exitFee:X(t.exitFee.toString()),platformFee:X(t.platformFee.toString()),microMtkPrice:z(l).multipliedBy(10**6)},amount:z(a.mul(new BigRational(BigInt(10**6),1n)).reduce()),type:r}),y=z(a).multipliedBy(10**6).negated(),F=e.div(z(l));return {amountsPerAsset:d,mintedMicroMTK:F,userReceiveMTK:F.minus(c.userFee),withdrawLovelace:y,withdrawUserLvc:y.minus(c.userFee.multipliedBy(z(l)).multipliedBy(10**6)),fees:c}},[e,t,r]);return {amountsPerAsset:i,fees:u,formattedState:o,mintedMicroMTK:s,userReceiveMTK:p,withdrawLovelace:f,withdrawUserLvc:h}}var ur=Zo;function Qo({children:e,background:t=n.background.modal,width:r="530px",color:o=n.offWhite.offWhite400}){return jsx(Box,{minWidth:"530px",background:t,transition:"0.25s",borderRadius:"1.25rem",border:`1px solid ${n.cards.stroke}`,sx:{backdropFilter:"blur(60px)"},width:r,padding:"1rem",height:"fit-content",color:o,children:e})}var gr=Qo;var on=e=>e<0n?-e:e;function nn(e){let t=new BigRational(0n,1n),o=Object.entries(e.formattedState.state.assets).reduce((H,[te,he])=>{let V=new BigRational(he,1n).mul(e.formattedState.prices[te]);return H.add(V).reduce()},new BigRational(0n,1n)),i=e.formattedState.prices[e.item.asset.id].mul(new BigRational(e.formattedState.state.assets[e.item.asset.id],1n)).reduce();e.formattedState.state.assets[e.item.asset.id];i.div(o).mul(new BigRational(100n,1n).reduce());let u=Object.entries(e.amountsToModify).reduce((H,[te,he])=>{let V=new BigRational(he,1n).mul(e.formattedState.prices[te]);return H.add(V).reduce()},new BigRational(0n,1n)),f=e.formattedState.prices[e.item.asset.id].mul(new BigRational(e.amountsToModify[e.item.asset.id],1n)).reduce();u.eq(t)?t:f.div(u).mul(new BigRational(100n,1n)).reduce();e.amountsToModify[e.item.asset.id];let l=u.add(o).reduce(),a=i.add(f).reduce();l.eq(t)?t:a.div(l).mul(new BigRational(100n,1n)).reduce();let y=on(e.amountsToModify[e.item.asset.id]||0n).toString(),F=X((e.amountsToModify[e.item.asset.id]||0n).toString()).lte(X((e.balance?.[j(e.item.asset)]||0n).toString())),C=e.swapDeficit,m=X((e.balance?.[j(e.item.asset)]||0n).toString()),D=X(y.toString()),R=C?X.max(D.minus(m),0):D,L=new X(e.item.price);function S(H,te){return H.multipliedBy(te).div(new X(10).pow(e.item.asset.decimals))}let I=S(m,L);function _(H,te){return H.multipliedBy(te).div(new X(10).pow(e.item.asset.decimals))}let ve=_(R,L);return jsxs(Tr,{paddingX:"0.5rem",children:[jsx(Td,{textAlign:"left",flexDir:"row",width:"fit-content",paddingX:2,paddingY:3,alignContent:"flex-start",children:jsxs(Flex,{justify:"left",gap:2,children:[jsxs(Box,{width:"1.5rem",height:"1.5rem",overflow:"hidden",borderRadius:"full",background:"var(--metera-purple-200)",children:[jsx(Image,{boxSize:"100%",objectFit:"cover",src:e.item.asset.imageUrl,alt:e.item.asset.ticker}),"-"]}),jsxs(Flex,{flexDir:"column",children:[jsx(Box,{fontSize:"0.875rem",color:"var(--primary-50)",children:e.item.asset.ticker}),jsx(Flex,{gap:1,justify:"right",children:jsxs(Box,{color:"var(--neutral-400)",fontSize:"0.7rem",children:["\u2248 \u20B3",X(e.item.price).toFixed(4)]})})]})]})}),jsx(Td,{paddingX:0,paddingY:3,alignContent:"flex-start",justifyContent:"flex-end",children:jsxs(Flex,{flexDir:"column",align:"flex-start",children:[jsx(wt,{fontSize:"0.875rem",color:"var(--primary-50)",value:X(y.toString()),decimals:e.item.asset.decimals}),jsxs(Flex,{gap:0,justify:"right",children:[jsx(Box,{color:"var(--neutral-400)",fontSize:"0.7rem",children:"\u2248 \u20B3"}),jsx(wt,{fontSize:"0.7rem",color:"var(--neutral-400)",value:z(f).abs(),decimals:0})]})]})}),jsx(Td,{fontSize:"0.875rem",paddingX:0,paddingY:3,alignContent:"flex-start",justifyContent:"center",textAlign:"center",children:jsxs(Flex,{flexDir:"column",alignContent:"center",justify:"center",children:[jsxs(Flex,{gap:1,justify:"center",children:[F?jsx(U,{showStatus:!1,status:"Confirmed"}):jsx(U,{showStatus:!1,status:"Cancelled"}),jsx(wt,{fontSize:"0.875rem",value:m,decimals:e.item.asset.decimals,color:"var(--primary-50)"})]}),jsxs(Box,{color:"var(--neutral-400)",fontSize:"0.7rem",children:["\u2248 \u20B3",I.toFixed(2)]})]})}),jsx(Td,{alignContent:"flex-start",fontSize:"0.875rem",paddingY:3,children:jsxs(Flex,{flexDir:"column",align:"flex-end",children:[jsx(Flex,{children:P(R.div(10**e.item.asset.decimals).toString())}),jsxs(Box,{color:"var(--neutral-400)",fontSize:"0.7rem",children:["\u2248 \u20B3",ve.toFixed(2)]})]})})]})}var wt=e=>jsx(Flex,{flexDir:"column",whiteSpace:"nowrap",children:jsx(Box,{color:e.color,fontSize:e.fontSize,children:P(e.value.div(10**e.decimals).toString())})}),pr=nn;var un="https://sqvzfgobtlzbovqbkaax.supabase.co/storage/v1/object/public/sdk-assets//minswap_horizontal.svg",gn={MINSWAP:{title:jsxs(Flex,{color:"white",fontSize:"0.875rem",gap:2,children:["Zap-in via ",jsx(Image,{src:un,alt:"minswap",width:85})]}),description:"Metera orders require you to deposit the underlying assets yourself. To obtain the necessary assets for minting MTKs, you can swap directly with one of our providers"},SWAP_DEFICIT:{title:"Swap Only Missing Tokens",description:"If turned on, Minswap will only swap the difference between assets required for your Metera Order and your balance."},ORDER_PROTECTION:{title:"Metera Order Protection",description:"Buy extra tokens to cover potential changes in asset requirements during order processing. Unused assets stay in your wallet."}},Xe=({children:e,minWidth:t="fit-content",minHeight:r="fit-content",padding:o=void 0,background:i="#08040f",controls:s,...p})=>jsxs(Modal,{isCentered:!0,...p,children:[jsx(ModalOverlay,{})," ",jsx(ModalContent,{background:i,minHeight:r,transition:"0.2s",minWidth:"30rem",padding:"1rem",borderRadius:"0.75rem",sx:{backdropFilter:"blur(60px)",maxWidth:"30rem !important"},children:jsx(ModalBody,{children:jsxs(Flex,{flexDir:"column",width:"100%",height:"100%",gap:"0.5rem",children:[jsxs(Flex,{justify:"space-between",children:[jsx(Box,{color:"white",fontSize:"1rem",fontWeight:500,children:"Order Settings"}),jsx(Box,{as:"button",children:jsx("img",{})})]}),Object.entries(gn).map(([u,{title:f,description:h}])=>{let{value:g,setValue:l,disabled:a}=s[u]||{value:!0,setValue:()=>{},disabled:!0};return jsxs(Flex,{flexDir:"column",gap:"0.2rem",children:[jsxs(Flex,{justify:"space-between",align:"center",alignContent:"center",children:[jsx(Box,{color:"white",fontSize:"0.875rem",children:f}),jsx(Switch,{sx:{".chakra-switch__track":{bg:"#ccc"},".chakra-switch__thumb":{bg:"white"},"&[data-checked] .chakra-switch__track":{bg:"#e8a92d"},display:"flex",alignItems:"center"},checked:g,defaultChecked:g,onChange:d=>l(d.target.checked),disabled:a})]}),jsx(Box,{fontSize:"0.875rem",color:"#a3a3a3",children:h})]},u)})]})})})]});var yn="https://sqvzfgobtlzbovqbkaax.supabase.co/storage/v1/object/public/sdk-assets//settings.svg",Bn="https://sqvzfgobtlzbovqbkaax.supabase.co/storage/v1/object/public/sdk-assets//cardanoimage.png",Tn="https://sqvzfgobtlzbovqbkaax.supabase.co/storage/v1/object/public/sdk-assets//minswap_horizontal.svg",kn=({type:e,portfolioAssets:t,balance:r,amountsToModify:o,formattedState:i,hideBreakdown:s,isModal:p=!0,setSwapDeficit:u,swapDeficit:f,background:h})=>{let[g,l]=useState(!1),a=()=>{l(!0);};return jsxs(Flex,{width:"full",height:"full",flexDirection:"column",padding:"1rem",background:h||n.background.modal,children:[jsxs(Flex,{width:"100%",flexDirection:"column",gap:1,padding:"8px",children:[jsxs(Flex,{justify:"space-between",children:[jsxs(Flex,{as:"button",onClick:s,justify:"left",gap:2,align:"center",children:[jsx(MdWest,{fontSize:"1.5rem",color:"#a78bfa",onClick:s,cursor:"pointer"}),jsx(Box,{fontSize:"0.75rem",color:"var(--off-white)",children:"Go back"})]}),jsx(Box,{as:"button",onClick:a,display:"flex",alignItems:"center",justifyContent:"center",borderRadius:"50%",bg:"var(--bg-200)",_hover:{transform:"scale(1.1)"},p:2,children:jsx(Image,{src:yn,objectFit:"contain",alt:"settings",display:"block"})}),jsx(Xe,{children:void 0,isOpen:g,onClose:()=>l(!1),controls:{SWAP_DEFICIT:{value:f,setValue:u}}})]}),jsxs(Flex,{width:"100%",justifyContent:"left",gap:"1rem",align:"center",children:[jsx(Box,{width:"2rem",height:"2rem",overflow:"hidden",borderRadius:"50%",position:"relative",children:jsx(Image,{src:Bn,alt:"ADA"})}),jsx(MdSwapHoriz,{fontSize:"2rem",color:"var(--neutral-400)"}),jsxs(Flex,{align:"center",children:[t.sort((d,c)=>d.asset.ticker.localeCompare(c.asset.ticker)).slice(0,3).map((d,c)=>jsx(Box,{width:"2rem",height:"2rem",overflow:"hidden",borderRadius:"50%",ml:"-0.5rem",zIndex:3+c,position:"relative",children:jsx(Image,{src:d.asset.imageUrl,alt:d.asset.ticker},d.asset.id+c)},d.asset.id+c)),t.length>3&&jsx(Box,{fontSize:"0.725rem",alignItems:"center",justifyContent:"center",color:"var(--off-white-400)",background:"var(--purple-button-100)",width:"28px",height:"28px",borderRadius:"full",padding:"0.3rem",marginLeft:"-1rem",zIndex:10,children:jsxs(Flex,{align:"center",height:"full",justify:"center",fontWeight:700,children:["+",t.length-3]})})]}),jsx(Box,{color:"var(--neutral-400)",fontSize:"0.875rem",children:"via"}),jsx(Box,{width:"7rem",overflow:"hidden",position:"relative",children:jsx(Image,{src:Tn,alt:"minswap"})})]})]}),jsx(Box,{overflowY:"auto",background:"var(--table-modals)",borderRadius:"0.75rem",width:"full",height:"full",paddingTop:"0.15rem",children:jsx(Flex,{gap:3,overflow:"auto",children:jsx(TableContainer,{overflowY:"auto",sx:{"&::-webkit-scrollbar":{width:"0px"},"&::-webkit-scrollbar-track":{background:"none"},"&::-webkit-scrollbar-thumb":{background:"none"},"&::-webkit-scrollbar-thumb:hover":{background:"none"}},children:jsxs(Table,{variant:"unstyled",sx:{tableLayout:"fixed"},children:[jsx(Thead,{position:"sticky",top:0,left:0,zIndex:1,borderBottom:"none",children:jsxs(Tr,{children:[jsx(Y,{textAlign:"left",paddingX:"8px",paddingY:"1rem",paddingLeft:"10px",fontSize:"0.875rem",color:"var(--neutral-400)",borderTopLeftRadius:"full",children:"Token"}),jsx(Y,{paddingX:0,paddingY:"1rem",fontSize:"0.875rem",color:"var(--neutral-400)",children:e==="mint"?jsx(Flex,{width:"full",justify:"left",gap:2,children:jsx(Box,{children:"You Deposit"})}):jsx(Flex,{width:"full",justify:"left",gap:2,children:jsx(Box,{children:"You Withdraw"})})}),jsx(Y,{textAlign:"center",paddingX:"8px",paddingY:"1rem",paddingLeft:"10px",fontSize:"0.875rem",color:"var(--neutral-400)",children:"Your Balance"}),jsx(Y,{textAlign:"center",paddingX:0,paddingY:"1rem",fontSize:"0.875rem",color:"var(--neutral-400)",paddingRight:"6px",children:"You Swap"})]})}),jsx("tbody",{style:{maxHeight:"286px"},children:t.sort((d,c)=>d.asset.ticker.localeCompare(c.asset.ticker)).map((d,c)=>jsx(pr,{item:d,type:e,balance:r,amountsToModify:o,formattedState:i,swapDeficit:f},d.asset.id+c))})]})})})})]})};var fr=kn;var Fn=({wallet:e,apiBaseUrl:t,portfolio:r,totalInput:o,setSwapDeficit:i,swapDeficit:s,swapBalances:p,setLoading:u,setTxHash:f})=>{let h=useToast(),g=(a,d)=>h({title:a,