@imtbl/checkout-sdk 2.23.1-0 → 2.24.1-0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- import{Environment as e,ImmutableConfiguration as t}from"@imtbl/config";import n,{HttpStatusCode as r}from"axios";import{BrowserProvider as i,Contract as a,JsonRpcProvider as o,formatUnits as s,parseUnits as c}from"ethers";import{BridgeConfiguration as l,BridgeFeeActions as u,ETH_MAINNET_TO_ZKEVM_MAINNET as d,ETH_SEPOLIA_TO_ZKEVM_DEVNET as f,ETH_SEPOLIA_TO_ZKEVM_TESTNET as p,TokenBridge as m}from"@imtbl/bridge-sdk";import{Exchange as h}from"@imtbl/dex-sdk";import{ActionType as g,OrderStatusName as _,Orderbook as v,SignablePurpose as y,TransactionPurpose as b,constants as x}from"@imtbl/orderbook";import{BlockchainData as S}from"@imtbl/blockchain-data";import C from"@metamask/detect-provider";import{track as ee}from"@imtbl/metrics";let w=function(e){e[`IMTBL_WIDGETS_PROVIDER`]=`imtbl-widgets-provider`;e[`IMTBL_CONNECT_WIDGET_EVENT`]=`imtbl-connect-widget`;e[`IMTBL_WALLET_WIDGET_EVENT`]=`imtbl-wallet-widget`;e[`IMTBL_SWAP_WIDGET_EVENT`]=`imtbl-swap-widget`;e[`IMTBL_BRIDGE_WIDGET_EVENT`]=`imtbl-bridge-widget`;e[`IMTBL_ONRAMP_WIDGET_EVENT`]=`imtbl-onramp-widget`;e[`IMTBL_SALE_WIDGET_EVENT`]=`imtbl-sale-widget`;e[`IMTBL_COMMERCE_WIDGET_EVENT`]=`imtbl-commerce-widget`;e[`IMTBL_ADD_TOKENS_WIDGET_EVENT`]=`imtbl-add-tokens-widget`;e[`IMTBL_PURCHASE_WIDGET_EVENT`]=`imtbl-purchase-widget`;e[`IMTBL_TRANSFER_WIDGET_EVENT`]=`imtbl-transfer-widget`;return e}({});let T=function(e){e[`PROVIDER_UPDATED`]=`PROVIDER_UPDATED`;return e}({});let E=function(e){e[`CLOSE_WIDGET`]=`close-widget`;e[`SUCCESS`]=`success`;e[`FAILURE`]=`failure`;e[`LANGUAGE_CHANGED`]=`language-changed`;e[`WALLETCONNECT_PROVIDER_UPDATED`]=`walletconnect-provider-updated`;return e}({});let D=function(e){e[`CLOSE_WIDGET`]=`close-widget`;e[`NETWORK_SWITCH`]=`network-switch`;e[`DISCONNECT_WALLET`]=`disconnect-wallet`;e[`LANGUAGE_CHANGED`]=`language-changed`;return e}({});let te=function(e){e[`CLOSE_WIDGET`]=`close-widget`;e[`SUCCESS`]=`success`;e[`FAILURE`]=`failure`;e[`REJECTED`]=`rejected`;e[`LANGUAGE_CHANGED`]=`language-changed`;return e}({});let ne=function(e){e[`CLOSE_WIDGET`]=`close-widget`;e[`SUCCESS`]=`success`;e[`FAILURE`]=`failure`;e[`REJECTED`]=`rejected`;e[`TRANSACTION_SUCCESS`]=`transaction-success`;e[`LANGUAGE_CHANGED`]=`language-changed`;e[`PAYMENT_METHOD`]=`payment-method`;e[`REQUEST_BRIDGE`]=`request-bridge`;e[`REQUEST_ONRAMP`]=`request-onramp`;e[`REQUEST_SWAP`]=`request-swap`;e[`PAYMENT_TOKEN`]=`payment-token`;return e}({});let re=function(e){e[`CRYPTO`]=`crypto`;e[`DEBIT`]=`debit`;e[`CREDIT`]=`credit`;return e}({});let ie=function(e){e[`CLOSE_WIDGET`]=`close-widget`;e[`FAILURE`]=`failure`;e[`TRANSACTION_SENT`]=`transaction-sent`;e[`LANGUAGE_CHANGED`]=`language-changed`;e[`CLAIM_WITHDRAWAL_SUCCESS`]=`claim-withdrawal-success`;e[`CLAIM_WITHDRAWAL_FAILURE`]=`claim-withdrawal-failure`;return e}({});let ae=function(e){e[`REQUEST_CONNECT`]=`request-connect`;e[`REQUEST_WALLET`]=`request-wallet`;e[`REQUEST_SWAP`]=`request-swap`;e[`REQUEST_BRIDGE`]=`request-bridge`;e[`REQUEST_ONRAMP`]=`request-onramp`;e[`REQUEST_ADD_TOKENS`]=`request-add-tokens`;e[`REQUEST_PURCHASE`]=`request-purchase`;e[`REQUEST_GO_BACK`]=`request-go-back`;return e}({});let oe=function(e){e[`CLOSE_WIDGET`]=`close-widget`;e[`SUCCESS`]=`success`;e[`FAILURE`]=`failure`;e[`LANGUAGE_CHANGED`]=`language-changed`;return e}({});let se=function(e){e[`INITIALISED`]=`INITIALISED`;e[`PROVIDER_UPDATED`]=`PROVIDER_UPDATED`;e[`CLOSE`]=`CLOSE`;e[`SUCCESS`]=`SUCCESS`;e[`FAILURE`]=`FAILURE`;e[`DISCONNECTED`]=`DISCONNECTED`;e[`USER_ACTION`]=`USER_ACTION`;return e}({});let ce=function(e){e[`SWAP_SUCCESS`]=`SWAP_SUCCESS`;e[`ONRAMP_SUCCESS`]=`ONRAMP_SUCCESS`;e[`CONNECT_SUCCESS`]=`CONNECT_SUCCESS`;e[`SALE_SUCCESS`]=`SALE_SUCCESS`;e[`SALE_TRANSACTION_SUCCESS`]=`SALE_TRANSACTION_SUCCESS`;e[`BRIDGE_SUCCESS`]=`BRIDGE_SUCCESS`;e[`BRIDGE_CLAIM_WITHDRAWAL_SUCCESS`]=`BRIDGE_CLAIM_WITHDRAWAL_SUCCESS`;e[`ADD_TOKENS_SUCCESS`]=`ADD_TOKENS_SUCCESS`;e[`ADD_TOKENS_CONNECT_SUCCESS`]=`ADD_TOKENS_CONNECT_SUCCESS`;e[`TRANSFER_SUCCESS`]=`TRANSFER_SUCCESS`;return e}({});let le=function(e){e[`BRIDGE_FAILED`]=`BRIDGE_FAILED`;e[`BRIDGE_CLAIM_WITHDRAWAL_FAILED`]=`BRIDGE_CLAIM_WITHDRAWAL_FAILED`;e[`SWAP_FAILED`]=`SWAP_FAILED`;e[`SWAP_REJECTED`]=`SWAP_REJECTED`;e[`CONNECT_FAILED`]=`CONNECT_FAILED`;e[`SALE_FAILED`]=`SALE_FAILED`;e[`ONRAMP_FAILED`]=`ONRAMP_FAILED`;e[`ADD_TOKENS_FAILED`]=`ADD_TOKENS_FAILED`;e[`TRANSFER_FAILED`]=`TRANSFER_FAILED`;return e}({});let ue=function(e){e[`PAYMENT_METHOD_SELECTED`]=`PAYMENT_METHOD_SELECTED`;e[`PAYMENT_TOKEN_SELECTED`]=`PAYMENT_TOKEN_SELECTED`;e[`NETWORK_SWITCH`]=`NETWORK_SWITCH`;return e}({});let de=function(e){e[`CLOSE_WIDGET`]=`close-widget`;e[`LANGUAGE_CHANGED`]=`language-changed`;e[`CONNECT_SUCCESS`]=`connect-success`;e[`SUCCESS`]=`success`;e[`FAILURE`]=`failure`;return e}({});let fe=function(e){e[`CLOSE_WIDGET`]=`close-widget`;e[`CONNECT_SUCCESS`]=`connect-success`;e[`SUCCESS`]=`success`;e[`FAILURE`]=`failure`;return e}({});let pe=function(e){e[`CLOSE_WIDGET`]=`close-widget`;e[`REJECTED`]=`rejected`;e[`SUCCESS`]=`success`;e[`FAILURE`]=`failure`;return e}({});let me=function(e){e[`CONNECT`]=`connect`;e[`WALLET`]=`wallet`;e[`SWAP`]=`swap`;e[`BRIDGE`]=`bridge`;e[`ONRAMP`]=`onramp`;e[`SALE`]=`sale`;e[`IMMUTABLE_COMMERCE`]=`immutableCommerce`;e[`ADD_TOKENS`]=`addTokens`;e[`PURCHASE`]=`purchase`;e[`TRANSFER`]=`transfer`;return e}({});let he=function(e){e[`LAYER1`]=`LAYER1`;e[`LAYER2`]=`LAYER2`;return e}({});let ge=function(e){e[`FROM`]=`FROM`;e[`TO`]=`TO`;return e}({});let _e=function(e){e[`CONNECT`]=`CONNECT`;e[`WALLET`]=`WALLET`;e[`SALE`]=`SALE`;e[`SWAP`]=`SWAP`;e[`BRIDGE`]=`BRIDGE`;e[`ONRAMP`]=`ONRAMP`;e[`ADD_TOKENS`]=`ADD_TOKENS`;e[`PURCHASE`]=`PURCHASE`;e[`TRANSFER`]=`TRANSFER`;return e}({});let ve=function(e){e[`LIGHT`]=`light`;e[`DARK`]=`dark`;return e}({});const ye=`pk_imapik-`;const be=[`https://checkout-api.dev.immutable.com`,`https://checkout-api.sandbox.immutable.com`,`https://checkout-api.immutable.com`];var xe=class{config;axiosInstance;constructor(e){this.config=e;this.axiosInstance=n.create();this.setupInterceptors()}shouldAddPublishableKey(e){return be.some(t=>e.startsWith(t))}setupInterceptors(){this.axiosInstance.interceptors.request.use(e=>{const t=this.config?.baseConfig?.publishableKey;if(t&&this.shouldAddPublishableKey(e.url||``)){if(!t.startsWith(ye))throw new Error(`Invalid Publishable key. Create your Publishable key in Immutable developer hub. https://hub.immutable.com`);e.headers[`x-immutable-publishable-key`]=t}return e},e=>Promise.reject(e))}async request(e){return await this.axiosInstance.request(e)}async get(e,t){const n={...t,url:e};return await this.request(n)}async post(e,t,n){const r={...n,data:t,url:e};return await this.request(r)}async put(e,t,n){const r={...n,data:t,url:e};return await this.request(r)}async delete(e,t,n){const r={...n,data:t,url:e};return await this.request(r)}};let Se=function(e){e[`MISSING_PARAMS`]=`MISSING_PARAMS`;e[`WEB3_PROVIDER_ERROR`]=`WEB3_PROVIDER_ERROR`;e[`PROVIDER_ERROR`]=`PROVIDER_ERROR`;e[`DEFAULT_PROVIDER_ERROR`]=`DEFAULT_PROVIDER_ERROR`;e[`CONNECT_PROVIDER_ERROR`]=`CONNECT_PROVIDER_ERROR`;e[`GET_BALANCE_ERROR`]=`GET_BALANCE_ERROR`;e[`GET_INDEXER_BALANCE_ERROR`]=`GET_INDEXER_BALANCE_ERROR`;e[`GET_ERC20_INFO_ERROR`]=`GET_ERC20_INFO_ERROR`;e[`GET_ERC20_BALANCE_ERROR`]=`GET_ERC20_BALANCE_ERROR`;e[`GET_ERC721_BALANCE_ERROR`]=`GET_ERC721_BALANCE_ERROR`;e[`GET_NETWORK_INFO_ERROR`]=`GET_NETWORK_INFO_ERROR`;e[`METAMASK_PROVIDER_ERROR`]=`METAMASK_PROVIDER_ERROR`;e[`CHAIN_NOT_SUPPORTED_ERROR`]=`CHAIN_NOT_SUPPORTED_ERROR`;e[`PROVIDER_REQUEST_MISSING_ERROR`]=`PROVIDER_REQUEST_MISSING_ERROR`;e[`PROVIDER_REQUEST_FAILED_ERROR`]=`PROVIDER_REQUEST_FAILED_ERROR`;e[`USER_REJECTED_REQUEST_ERROR`]=`USER_REJECTED_REQUEST_ERROR`;e[`TRANSACTION_FAILED`]=`TRANSACTION_FAILED`;e[`INSUFFICIENT_FUNDS`]=`INSUFFICIENT_FUNDS`;e[`UNPREDICTABLE_GAS_LIMIT`]=`UNPREDICTABLE_GAS_LIMIT`;e[`INVALID_GAS_ESTIMATE_TYPE`]=`INVALID_GAS_ESTIMATE_TYPE`;e[`UNSUPPORTED_TOKEN_TYPE_ERROR`]=`UNSUPPORTED_TOKEN_TYPE_ERROR`;e[`UNSUPPORTED_BALANCE_REQUIREMENT_ERROR`]=`UNSUPPORTED_BALANCE_REQUIREMENT_ERROR`;e[`GET_ORDER_LISTING_ERROR`]=`GET_ORDER_LISTING_ERROR`;e[`CANCEL_ORDER_LISTING_ERROR`]=`CANCEL_ORDER_LISTING_ERROR`;e[`PREPARE_ORDER_LISTING_ERROR`]=`PREPARE_ORDER_LISTING_ERROR`;e[`CREATE_ORDER_LISTING_ERROR`]=`CREATE_ORDER_LISTING_ERROR`;e[`FULFILL_ORDER_LISTING_ERROR`]=`FULFILL_ORDER_LISTING_ERROR`;e[`SWITCH_NETWORK_UNSUPPORTED`]=`SWITCH_NETWORK_UNSUPPORTED`;e[`GET_ERC20_ALLOWANCE_ERROR`]=`GET_ERC20_ALLOWANCE_ERROR`;e[`GET_ERC721_ALLOWANCE_ERROR`]=`GET_ERC721_ALLOWANCE_ERROR`;e[`GET_ERC1155_ALLOWANCE_ERROR`]=`GET_ERC1155_ALLOWANCE_ERROR`;e[`EXECUTE_APPROVAL_TRANSACTION_ERROR`]=`EXECUTE_APPROVAL_TRANSACTION_ERROR`;e[`EXECUTE_FULFILLMENT_TRANSACTION_ERROR`]=`EXECUTE_FULFILLMENT_TRANSACTION_ERROR`;e[`SIGN_MESSAGE_ERROR`]=`SIGN_MESSAGE_ERROR`;e[`BRIDGE_GAS_ESTIMATE_ERROR`]=`BRIDGE_GAS_ESTIMATE_ERROR`;e[`ORDER_FEE_ERROR`]=`ORDER_FEE_ERROR`;e[`ITEM_REQUIREMENTS_ERROR`]=`ITEM_REQUIREMENTS_ERROR`;e[`API_ERROR`]=`API_ERROR`;e[`ORDER_EXPIRED_ERROR`]=`ORDER_EXPIRED_ERROR`;e[`WIDGETS_SCRIPT_LOAD_ERROR`]=`WIDGETS_SCRIPT_LOAD_ERROR`;e[`APPROVAL_TRANSACTION_FAILED`]=`APPROVAL_TRANSACTION_FAILED`;return e}({});var O=class extends Error{message;type;data;constructor(e,t,n){super(e);this.message=e;this.type=t;this.data=n}};const k=async(e,t)=>{try{return await e()}catch(e){const n=e?.error?.message??(e.message||`UnknownError`);const r=t.message?`[${t.type}]:${t.message}. Cause:${n}`:`[${t.type}] Cause:${n}`;if(e instanceof O)throw new O(r,t.type,{...t.data,innerErrorType:e.type,...e.data});throw new O(r,t.type,{...t.data})}};let Ce=function(e){e[e[`IMTBL_ZKEVM_MAINNET`]=13371]=`IMTBL_ZKEVM_MAINNET`;e[e[`IMTBL_ZKEVM_TESTNET`]=13473]=`IMTBL_ZKEVM_TESTNET`;e[e[`IMTBL_ZKEVM_DEVNET`]=15003]=`IMTBL_ZKEVM_DEVNET`;e[e[`ETHEREUM`]=1]=`ETHEREUM`;e[e[`SEPOLIA`]=11155111]=`SEPOLIA`;return e}({});let we=function(e){e[`ETHEREUM`]=`Ethereum`;e[`SEPOLIA`]=`Sepolia`;e[`IMTBL_ZKEVM_TESTNET`]=`Immutable zkEVM Testnet`;e[`IMTBL_ZKEVM_DEVNET`]=`Immutable zkEVM Dev`;e[`IMTBL_ZKEVM_MAINNET`]=`Immutable zkEVM`;return e}({});let Te=function(e){e[`ETHEREUM`]=`ethereum`;e[`SEPOLIA`]=`sepolia`;e[`IMTBL_ZKEVM_MAINNET`]=`imtbl-zkevm-mainnet`;e[`IMTBL_ZKEVM_TESTNET`]=`imtbl-zkevm-testnet`;e[`IMTBL_ZKEVM_DEVNET`]=`imtbl-zkevm-devnet`;return e}({});const A=`development`;const Ee=18;const j=`native`;const De={name:`IMX`,symbol:`IMX`,decimals:18,address:j};const Oe={name:`tIMX`,symbol:`tIMX`,decimals:18,address:j};const M={[A]:`https://api.dev.immutable.com`,[e.SANDBOX]:`https://api.sandbox.immutable.com`,[e.PRODUCTION]:`https://api.immutable.com`};const ke={[A]:`https://checkout-api.dev.immutable.com`,[e.SANDBOX]:`https://checkout-api.sandbox.immutable.com`,[e.PRODUCTION]:`https://checkout-api.immutable.com`};const Ae={[e.SANDBOX]:`https://global-stg.transak.com`,[e.PRODUCTION]:`https://global.transak.com/`};const je=new Map([[1,{chainIdHex:`0x${1 .toString(16)}`,chainName:`Ethereum`,rpcUrls:[`https://checkout-api.immutable.com/v1/rpc/eth-mainnet`],nativeCurrency:{name:`Ethereum`,symbol:`ETH`,decimals:18},blockExplorerUrls:[`https://etherscan.io/`]}],[13371,{chainIdHex:`0x${13371 .toString(16)}`,chainName:`Immutable zkEVM`,rpcUrls:[`https://rpc.immutable.com`],nativeCurrency:De}]]);const Me=new Map([[11155111,{chainIdHex:`0x${11155111 .toString(16)}`,chainName:`Sepolia`,rpcUrls:[`https://checkout-api.sandbox.immutable.com/v1/rpc/eth-sepolia`],nativeCurrency:{name:`Sep Eth`,symbol:`ETH`,decimals:18},blockExplorerUrls:[`https://sepolia.etherscan.io/`]}],[13473,{chainIdHex:`0x${13473 .toString(16)}`,chainName:`Immutable zkEVM Testnet`,rpcUrls:[`https://rpc.testnet.immutable.com`],nativeCurrency:Oe}]]);const Ne=new Map([[11155111,{chainIdHex:`0x${11155111 .toString(16)}`,chainName:`Sepolia`,rpcUrls:[`https://checkout-api.dev.immutable.com/v1/rpc/eth-sepolia`],nativeCurrency:{name:`Sep Eth`,symbol:`ETH`,decimals:18},blockExplorerUrls:[`https://sepolia.etherscan.io/`]}],[15003,{chainIdHex:`0x${15003 .toString(16)}`,chainName:`Immutable zkEVM Dev`,rpcUrls:[`https://rpc.dev.immutable.com`],nativeCurrency:De}]]);const N={[13473]:{url:`https://explorer.testnet.immutable.com`,nativeToken:Me.get(13473).nativeCurrency},[13371]:{url:`https://explorer.immutable.com`,nativeToken:je.get(13371).nativeCurrency},[11155111]:{url:`https://eth-sepolia.blockscout.com`,nativeToken:Me.get(11155111).nativeCurrency},[1]:{url:`https://eth.blockscout.com/`,nativeToken:je.get(1).nativeCurrency}};const P=[{constant:true,inputs:[],name:`name`,outputs:[{name:``,type:`string`}],payable:false,type:`function`},{constant:true,inputs:[],name:`decimals`,outputs:[{name:``,type:`uint8`}],payable:false,type:`function`},{constant:true,inputs:[{name:`_owner`,type:`address`}],name:`balanceOf`,outputs:[{name:`balance`,type:`uint256`}],payable:false,type:`function`},{constant:true,inputs:[],name:`symbol`,outputs:[{name:``,type:`string`}],payable:false,type:`function`},{constant:true,inputs:[{name:`_owner`,type:`address`},{name:`_spender`,type:`address`}],name:`allowance`,outputs:[{name:``,type:`uint256`}],payable:false,stateMutability:`view`,type:`function`},{constant:false,inputs:[{name:`_spender`,type:`address`},{name:`_value`,type:`uint256`}],name:`approve`,outputs:[{name:``,type:`bool`}],payable:false,stateMutability:`nonpayable`,type:`function`}];const F=[{constant:false,inputs:[{internalType:`address`,name:`to`,type:`address`},{internalType:`uint256`,name:`tokenId`,type:`uint256`}],name:`approve`,outputs:[],payable:false,stateMutability:`nonpayable`,type:`function`},{constant:true,inputs:[{internalType:`address`,name:`owner`,type:`address`},{internalType:`address`,name:`operator`,type:`address`}],name:`isApprovedForAll`,outputs:[{internalType:`bool`,name:``,type:`bool`}],payable:false,stateMutability:`view`,type:`function`},{constant:true,inputs:[{internalType:`uint256`,name:`tokenId`,type:`uint256`}],name:`getApproved`,outputs:[{internalType:`address`,name:``,type:`address`}],payable:false,stateMutability:`view`,type:`function`},{inputs:[{internalType:`uint256`,name:`tokenId`,type:`uint256`}],name:`ownerOf`,outputs:[{internalType:`address`,name:``,type:`address`}],stateMutability:`view`,type:`function`}];const Pe=[{inputs:[{internalType:`address`,name:`account`,type:`address`},{internalType:`address`,name:`operator`,type:`address`}],name:`isApprovedForAll`,outputs:[{internalType:`bool`,name:``,type:`bool`}],stateMutability:`view`,type:`function`},{inputs:[{internalType:`address`,name:`operator`,type:`address`},{internalType:`bool`,name:`approved`,type:`bool`}],name:`setApprovalForAll`,outputs:[],stateMutability:`nonpayable`,type:`function`},{inputs:[{internalType:`address`,name:`account`,type:`address`},{internalType:`uint256`,name:`id`,type:`uint256`}],name:`balanceOf`,outputs:[{internalType:`uint256`,name:``,type:`uint256`}],stateMutability:`view`,type:`function`}];const Fe={maxFeePerGas:BigInt(15e9),maxPriorityFeePerGas:BigInt(1e10)};const Ie=`2.23.1-0`;const I=()=>Ie;const Le=(t,r)=>{const i=()=>{if(t)return M[A];if(r)return M[e.PRODUCTION];return M[e.SANDBOX]};const a=async()=>{let e;try{e=await n.post(`${i()}/v1/availability/checkout/swap`)}catch(t){e=t.response;if(e.status===403)return false;throw new O(`Error fetching from api: ${e.status} ${e.statusText}`,`API_ERROR`,{error:t})}return true};return{checkDexAvailability:a}};let Re=function(e){e[`BRIDGE_TO_L2`]=`BRIDGE_TO_L2`;e[`SWAP`]=`SWAP`;return e}({});let ze=function(e){e[`ALL`]=`all`;return e}({});let Be=function(e){e[`ALL`]=`all`;e[`SWAP`]=`swap`;e[`BRIDGE`]=`bridge`;e[`ONRAMP`]=`onramp`;return e}({});let Ve=function(e){e[`ALL`]=`all`;return e}({});let He=function(e){e[`PASSPORT`]=`passport`;e[`METAMASK`]=`metamask`;e[`WALLETCONNECT`]=`walletconnect`;return e}({});let Ue=function(e){e[`PASSPORT`]=`com.immutable.passport`;e[`METAMASK`]=`io.metamask`;e[`WALLETCONNECT`]=`walletconnect`;return e}({});const We={allowMistmatchedChainId:false,allowUnsupportedProvider:false};var L=class extends i{ethereumProvider;constructor(e,t,n){super(e,t,n);this.#e(e)}#e(e){if(!(`request`in e)||typeof e.request!==`function`)return;this.ethereumProvider=e}};let Ge=function(e){e[`SUCCESS`]=`SUCCESS`;e[`FAILED`]=`FAILED`;e[`INSUFFICIENT_FUNDS`]=`INSUFFICIENT_FUNDS`;e[`FULFILLMENTS_UNSETTLED`]=`FULFILLMENTS_UNSETTLED`;return e}({});let Ke=function(e){e[`NATIVE`]=`NATIVE`;e[`ERC20`]=`ERC20`;e[`ERC721`]=`ERC721`;e[`ERC1155`]=`ERC1155`;return e}({});let qe=function(e){e[`TRANSACTION`]=`TRANSACTION`;e[`GAS`]=`GAS`;return e}({});let Je=function(e){e[`NATIVE`]=`NATIVE`;e[`ERC20`]=`ERC20`;return e}({});let Ye=function(e){e[`ROUTES_FOUND`]=`ROUTES_FOUND`;e[`NO_ROUTES_FOUND`]=`NO_ROUTES_FOUND`;e[`NO_ROUTE_OPTIONS`]=`NO_ROUTE_OPTIONS`;return e}({});let Xe=function(e){e[`GAS`]=`GAS`;e[`BRIDGE_FEE`]=`BRIDGE_FEE`;e[`SWAP_FEE`]=`SWAP_FEE`;e[`IMMUTABLE_FEE`]=`IMMUTABLE_FEE`;return e}({});let Ze=function(e){e[`BRIDGE`]=`BRIDGE`;e[`SWAP`]=`SWAP`;e[`ONRAMP`]=`ONRAMP`;return e}({});let Qe=function(e){e[`ONRAMP`]=`onramp`;return e}({});async function $e(e){if(!e.send)throw new O(`Parsed provider is not a valid WrappedBrowserProvider`,`WEB3_PROVIDER_ERROR`);const t=await e.send(`eth_chainId`,[]);if(typeof t!==`bigint`)throw new O(`Invalid chainId`,`WEB3_PROVIDER_ERROR`);return t}async function R(e){const t=await e.getNetwork();if(t.chainId&&typeof t.chainId===`bigint`)return t.chainId;return $e(e)}const et=4902;async function tt(e,t,n){return await t.send(`wallet_switchEthereumChain`,[{chainId:e.get(n)?.chainIdHex}])}async function nt(e,t,n){if(t.send){const r=e.get(n);const i={chainId:r?.chainIdHex,chainName:r?.chainName,rpcUrls:r?.rpcUrls,nativeCurrency:r?.nativeCurrency,blockExplorerUrls:r?.blockExplorerUrls};return await t.send(`wallet_addEthereumChain`,[i])}return Promise.reject(`Provider does not support request method`)}async function z(e,{type:t=`all`,exclude:n}){const{networkMap:r}=e;const i=await e.remote.getConfig(`allowedNetworks`);if(!i)console.warn(`No allowed networks configured`);const a=(i||[]).filter(e=>{const r=t===`all`;const i=!(n||[]).map(e=>e.chainId).includes(e.chainId);return r&&i});const o=[];a.forEach(e=>{const t=r.get(e.chainId);if(t)o.push({name:t.chainName,chainId:parseInt(t.chainIdHex,16),nativeCurrency:t.nativeCurrency,isSupported:true})});return{networks:o}}async function B(e,t){const{networkMap:n}=e;return k(async()=>{try{const e=await t.getNetwork();if(Array.from(n.keys()).includes(Number(e.chainId))){const t=n.get(Number(e.chainId));return{name:t.chainName,chainId:parseInt(t.chainIdHex,16),nativeCurrency:t.nativeCurrency,isSupported:true}}return{chainId:Number(e.chainId),name:e.name,isSupported:false}}catch(e){const r=await R(t);const i=Array.from(n.keys()).includes(Number(r));return{chainId:Number(r),isSupported:i}}},{type:`GET_NETWORK_INFO_ERROR`})}const rt=e=>e.error?.data?.originalError?.code===et||e.error?.code===et;async function it(e,t,n){const{networkMap:r}=e;if(!(await z(e,{type:`all`})).networks.some(e=>e.chainId===n))throw new O(`Chain:${n} is not a supported chain`,`CHAIN_NOT_SUPPORTED_ERROR`);if(t.ethereumProvider?.isPassport)throw new O(`Switching networks with Passport provider is not supported`,`SWITCH_NETWORK_UNSUPPORTED`);try{await tt(r,t,n)}catch(e){console.error(e);if(rt(e))try{await nt(r,t,n)}catch(e){throw new O(`User cancelled add network request`,`USER_REJECTED_REQUEST_ERROR`,{error:e})}else throw new O(`User cancelled switch network request`,`USER_REJECTED_REQUEST_ERROR`)}const i=new L(t.ethereumProvider);const a=await i.getNetwork();if(Number(a.chainId)!==n)throw new O(`User cancelled switch network request`,`USER_REJECTED_REQUEST_ERROR`);return{network:await B(e,i),provider:i}}var at=class{httpClient;endpoint;configCache;version=`v1`;constructor(e,t){this.endpoint=t.remoteConfigEndpoint;this.httpClient=e}parseResponse(e){let t=e.data;if(e.data&&typeof e.data!==`object`)try{t=JSON.parse(e.data)}catch(e){throw new O(`Invalid configuration`,`API_ERROR`,{error:e})}return t}async loadConfig(){if(this.configCache)return this.configCache;let e;try{e=await this.httpClient.get(`${this.endpoint}/${this.version}/config`)}catch(e){throw new O(`Error: ${e.message}`,`API_ERROR`,{error:e})}this.configCache=this.parseResponse(e);return this.configCache}async getConfig(e){const t=await this.loadConfig();if(!t)return void 0;if(!e)return t;return t[e]}getHttpClient=()=>this.httpClient};const ot=`0x0000000000000000000000000000000000000eee`;var st=class{httpClient;remoteConfig;baseUrl;chainSlug;tokensCache;constructor(e,t,n){this.baseUrl=n.baseUrl;this.chainSlug=n.chainSlug;this.httpClient=e;this.remoteConfig=t}async loadTokens(){if(this.tokensCache)return this.tokensCache;let e;try{e=await this.httpClient.get(`${this.baseUrl}/v1/chains/${this.chainSlug}/tokens?verification_status=verified&is_canonical=true`)}catch(e){throw new O(`Error: ${e.message}`,`API_ERROR`,{error:e})}const t=this.parseResponse(e);this.tokensCache=await this.getMappingsForTokensResponse(t?.result||[]);return this.tokensCache}async getChainTokensConfig(){return await this.loadTokens()??{}}async getTokensConfig(e){const t=await this.loadTokens();if(!t||!t[e])return[];return t[e]??[]}async getMappingsForTokensResponse(e){const t={};const n=await this.fetchIMXTokenMappings();Object.keys(n).forEach(e=>{const r=parseInt(e,10);t[r]=[];t[r]?.push({address:n[e],decimals:18,name:`IMX`,symbol:`IMX`,bridge:`native`})});e.forEach(e=>{const n=parseInt(e.chain.id.split(`eip155:`).pop()||``,10);if(!e.symbol||!e.decimals)return;if(!t[n])t[n]=[];const r={address:e.contract_address.toLowerCase(),decimals:e.decimals,name:e.name,symbol:e.symbol,icon:e.image_url??void 0,bridge:e.bridge_used??null};t[n]?.push(r);const i=parseInt(e.root_chain_id?.split(`eip155:`).pop()||``,10);let a=e.root_contract_address?.toLowerCase();if(i&&a){if(!t[i])t[i]=[];if(a===ot)a=`native`;t[i]?.push({...r,address:a})}});return t}parseResponse(e){let t=e.data;if(e.data&&typeof e.data!==`object`)try{t=JSON.parse(e.data)}catch(e){throw new O(`Invalid token data`,`API_ERROR`,{error:e})}return t}async fetchIMXTokenMappings(){return await this.remoteConfig.getConfig(`imxAddressMapping`)}};var ct=class extends Error{message;constructor(e){super(e);this.message=e}};const lt=(e,t)=>{if(t)return Ne;if(e)return je;return Me};const ut=(t,n)=>{if(n)return M[A];if(t)return M[e.PRODUCTION];return M[e.SANDBOX]};const dt=(e,t)=>{if(t)return`imtbl-zkevm-devnet`;if(e)return`imtbl-zkevm-mainnet`;return`imtbl-zkevm-testnet`};const V=e=>{if(!e.isProduction)return 11155111;return 1};const H=e=>{if(e.isDevelopment)return 15003;if(e.isProduction)return 13371;return 13473};const ft=(t,n)=>{if(n)return ke[A];if(t)return ke[e.PRODUCTION];return ke[e.SANDBOX]};var pt=class{isDevelopment=false;isProduction;isOnRampEnabled;isSwapEnabled;isBridgeEnabled;remote;tokens;environment;networkMap;publishableKey;l1ChainId;l2ChainId;overrides;constructor(t,n){if(!Object.values(e).includes(t.baseConfig.environment))throw new ct(`Invalid checkout configuration of environment`);this.environment=t.baseConfig.environment;this.isProduction=!this.isDevelopment&&this.environment===e.PRODUCTION;this.isOnRampEnabled=t.onRamp?.enable??true;this.isSwapEnabled=t.swap?.enable??true;this.isBridgeEnabled=t.bridge?.enable??true;this.publishableKey=t.publishableKey??`<no-publishable-key>`;this.networkMap=t.overrides?.networkMap??lt(this.isProduction,this.isDevelopment);const r=t.overrides?.remoteConfigEndpoint??ft(this.isProduction,this.isDevelopment);this.remote=new at(n,{remoteConfigEndpoint:r});this.tokens=new st(n,this.remote,{baseUrl:t.overrides?.baseUrl??ut(this.isProduction,this.isDevelopment),chainSlug:t.overrides?.chainSlug??dt(this.isProduction,this.isDevelopment)});this.l1ChainId=V(this);this.l2ChainId=t.overrides?.l2ChainId??H(this);this.overrides=t.overrides??{}}get sdkVersion(){return I()}};const U=(e=``,t=``)=>e.toLowerCase()===t.toLowerCase();const mt=e=>e===15003||e===13473||e===13371;const ht=(e,t)=>{const n=e.indexOf(`.`);const r=e.substring(n+t+1);if(r&&parseFloat(r)>=1){const r=e.substring(0,n+t+1);const i=1/10**t;return(parseFloat(r)+i).toString()}return parseFloat(e.substring(0,n+t+1)).toString()};const W=(e,t=6)=>{if(e.indexOf(`.`)===-1)return e;return ht(e,t)};const gt=`native`;const G=async(e,{type:t=`all`,chainId:n,exclude:r})=>{let i=[];let a;let o;const s=n??V(e);const c=H(e);switch(t){case`swap`:i=await e.tokens.getTokensConfig(c);o=((await e.remote.getConfig(`dex`))?.blocklist||[]).map(e=>e.address.toLowerCase());i=i.filter(e=>e.address&&!o.includes(e.address));break;case`onramp`:a=await e.remote.getConfig(`onramp`);if(!a)i=[];i=a[`201811419111`]?.tokens||[];break;case`bridge`:i=(await e.tokens.getTokensConfig(s)).filter(e=>e.bridge===gt);break;case`all`:default:i=await e.tokens.getTokensConfig(s)}if(!r||r?.length===0)return{tokens:i};return{tokens:i.filter(e=>!r.map(e=>e.address).includes(e.address||``))}};const K=e=>!e||U(e,`native`);async function _t(e,t){return await k(async()=>{const n=new a(t,JSON.stringify(P),e);const[r,i,o]=await Promise.all([n.name(),n.symbol(),n.decimals()]);return{name:r,symbol:i,decimals:o,address:t}},{type:`GET_ERC20_INFO_ERROR`})}const vt=5;var yt=class{url;nativeToken;ttl;chainId;cacheMap;httpClient;setCache(e,t){this.cacheMap[e]={data:t,ttl:new Date().getTime()+this.ttl*1e3}}getCache(e){const t=this.cacheMap[e];if(!t||t.ttl<=new Date().getTime())return null;return t.data}constructor(e,t,n){this.httpClient=e;this.chainId=t;this.url=N[this.chainId].url;const r=N[this.chainId].nativeToken;this.nativeToken={address:r.address??``,decimals:r.decimals.toString(),name:r.name,symbol:r.symbol};this.cacheMap={};this.ttl=n!==void 0?n:vt}static isChainSupported=e=>Boolean(N[e]);static isBlockscoutError=e=>`code`in e;async getTokensByWalletAddress(e){try{let t=`${this.url}/api/v2/addresses/${e.walletAddress}/tokens?type=${e.tokenType}`;if(e.nextPage)t+=`&${new URLSearchParams(e.nextPage)}`;const n=this.getCache(t);if(n)return Promise.resolve(n);const r=await this.httpClient.get(t);const i={items:(r.data?.items?.map(e=>{const t={...e.token,address:e.token.address_hash,holders:e.token.holders_count};return{...e,token:t}})||[]).filter(e=>e.token.address&&e.token.address!==this.nativeToken.address),next_page_params:r.data?.next_page_params};this.setCache(t,i);return Promise.resolve(i)}catch(e){let t=r.InternalServerError;let i=`InternalServerError`;if(n.isAxiosError(e)){t=e.response?.status||t;i=e.message}return Promise.reject({code:t,message:i})}}async getNativeTokenByWalletAddress(e){try{const t=`${this.url}/api/v2/addresses/${e.walletAddress}`;const n=this.getCache(t);if(n)return Promise.resolve(n);const r=await this.httpClient.get(t);const i={token:this.nativeToken,value:r.data.coin_balance};this.setCache(t,i);return Promise.resolve(i)}catch(e){let t=r.InternalServerError;let i=`InternalServerError`;if(n.isAxiosError(e)){t=e.response?.status||t;i=e.message}return Promise.reject({code:t,message:i})}}};const bt=(e,t,n)=>{if(!e.isProduction)console.info(t,n)};const q=async(e,t,n)=>{const r=performance.now();const i=await n;const a=(performance.now()-r)/1e3;bt(e,t,a);return i};const xt=async(e,t,n)=>await k(async()=>{const r=await B(e,t);if(!r.isSupported)throw new O(`Chain:${r.chainId} is not a supported chain`,`CHAIN_NOT_SUPPORTED_ERROR`,{chainName:r.name});const i=await t.getBalance(n);return{balance:i,formattedBalance:s(i,r.nativeCurrency.decimals),token:r.nativeCurrency}},{type:`GET_BALANCE_ERROR`});async function St(e,t,n){return await k(async()=>{const r=new a(n,JSON.stringify(P),e);return Promise.all([_t(e,n),r.balanceOf(t)]).then(([e,t])=>{return{balance:t,formattedBalance:s(t,e.decimals),token:{name:e.name,symbol:e.symbol,decimals:e.decimals,address:n}}})},{type:`GET_ERC20_BALANCE_ERROR`})}const Ct=new Map;const wt=()=>Ct.clear();const Tt=async(e,t,n,i)=>{const a=i!==void 0;const o=Object.assign({},...(i??[]).map(e=>({[e.address?.toLowerCase()||`native`]:e})));let c=Ct.get(n);if(!c){c=new yt(e.remote.getHttpClient(),n);Ct.set(n,c)}const l=[];const u=`ERC-20`;const d=async e=>{let n;try{do{n=await e.getTokensByWalletAddress({walletAddress:t,tokenType:u,nextPage:n?.next_page_params});l.push(...n.items)}while(n.next_page_params)}catch(e){if(e?.code!==r.NotFound)throw new O(e.message||`InternalServerError | getTokensByWalletAddress`,`GET_INDEXER_BALANCE_ERROR`,{error:e})}};const f=async e=>{try{const n=await e.getNativeTokenByWalletAddress({walletAddress:t});n.token.address||=j;l.push(n)}catch(e){if(e?.code!==r.NotFound)throw new O(e.message||`InternalServerError | getNativeTokenByWalletAddress`,`GET_INDEXER_BALANCE_ERROR`,{error:e})}};await Promise.all([d(c),f(c)]);const p=[];l.forEach(e=>{const t=o[e.token.address.toLowerCase()];if(a&&!t)return;const n=e.token||{};if(e.value==null)return;const r=BigInt(e.value);let i=parseInt(n.decimals,10);if(Number.isNaN(i))i=18;const c=n.icon_url??t.icon;const l={...n,decimals:i,icon:c};const u=s(e.value,l.decimals);p.push({balance:r,formattedBalance:u,token:l})});return{balances:p}};const Et=async(e,t,n,r)=>{const i=[];r.forEach(r=>{if(!r.address||U(r.address,`native`))i.push(xt(e,t,n));else i.push(St(t,n,r.address))});return(await Promise.allSettled(i)).reduce((e,t)=>{if(t.status!==`fulfilled`||t.value.balance===0n)return e;const{value:n}=t;if(!n.token.address||U(n.token.address,`native`))n.token.address=j;e.balances.push(n);return e},{balances:new Array})};const Dt=async(e,t,n,r,i)=>{if(!t)throw new O(`indexer is disabled for this chain, you must provide a provider.`,`MISSING_PARAMS`);let a=n;if(!a)a=await(await t.getSigner()).getAddress();return await q(e,`Time to fetch balances using RPC for ${r}`,Et(e,t,a,i))};const J=async(e,t,n,i,a=false)=>{if(!n&&!t)throw new O(`both walletAddress and provider are missing. At least one must be provided.`,`MISSING_PARAMS`);if(!e.networkMap.get(i))throw new O(`chain ID ${i} not supported by the environment`,`CHAIN_NOT_SUPPORTED_ERROR`);const{tokens:o}=await G(e,{type:`all`,chainId:i});if(a)wt();if(yt.isChainSupported(i)){const a=n??await(await t?.getSigner())?.getAddress();try{return await q(e,`Time to fetch balances using blockscout for ${i}`,Tt(e,a,i,o))}catch(a){if(a.type===`GET_INDEXER_BALANCE_ERROR`&&a.data?.error?.code===r.TooManyRequests)return Dt(e,t,n,i,o);throw a}}return Dt(e,t,n,i,o)};async function Ot(e){if(!e?.send)throw new O(`Check wallet connection request failed`,`PROVIDER_REQUEST_FAILED_ERROR`,{rpcMethod:`eth_accounts`});let t=[];try{t=await e.send(`eth_accounts`,[])}catch(e){throw new O(`Check wallet connection request failed`,`PROVIDER_REQUEST_FAILED_ERROR`,{error:e,rpcMethod:`eth_accounts`})}return{isConnected:t&&t.length>0,walletAddress:t[0]??``}}async function kt(e){if(!e||!e.send)throw new O(`Incompatible provider`,`PROVIDER_REQUEST_MISSING_ERROR`,{details:`Attempting to connect with an incompatible provider`});await k(async()=>{if(!e.send)return;await e.send(`eth_requestAccounts`,[])},{type:`USER_REJECTED_REQUEST_ERROR`});return e}async function At(e){if(!e||!e.send)throw new O(`Incompatible provider`,`PROVIDER_REQUEST_MISSING_ERROR`,{details:`Attempting to connect with an incompatible provider`});await k(async()=>{if(!e.send)return;await e.send(`wallet_requestPermissions`,[{eth_accounts:{}}])},{type:`USER_REJECTED_REQUEST_ERROR`});return e}var jt=class{config;constructor(e){this.config=e}async feeEstimate(){return(await this.config.remote.getConfig(`onramp`))[`201811419111`]?.fees}async createWidgetUrl(e,t=new xe){return await this.getTransakWidgetUrl(e,t)}async getTransakWidgetUrl(e,t){const n=await this.config.remote.getConfig(`onramp`);const r=`${M[this.config.environment]}/checkout/v1/widget-url`;let i={api_key:n[`201811419111`].publishableApiKey,network:`immutablezkevm`,default_payment_method:`credit_debit_card`,disable_payment_methods:``,products_availed:`buy`,exchange_screen_title:e.customSubTitle===``?` `:e.customSubTitle??`Buy`,theme_color:`FFFFFF`,default_crypto_currency:e.tokenSymbol||`IMX`,hide_menu:!(e.showMenu??true),referrer_domain:window.location.origin};if(e.isPassport&&e.email)i={...i,email:e.email,is_auto_fill_user_data:true,disable_wallet_address_form:true};if(e.tokenAmount&&e.tokenSymbol)i={...i,default_crypto_amount:e.tokenAmount,crypto_currency_code:e.tokenSymbol};else i={...i,default_fiat_amount:50,default_fiat_currency:`usd`};if(e.walletAddress)i={...i,wallet_address:e.walletAddress};if(e.allowedTokens)i={...i,crypto_currency_list:e.allowedTokens?.join(`,`).toLowerCase()};return(await t.post(r,i,{method:`POST`})).data.url}};async function Mt(e,t,n,r){const i=t===V(r)?u.DEPOSIT:u.WITHDRAW;return await e.getFee({action:i,gasMultiplier:`auto`,sourceChainId:t.toString(),destinationChainId:n.toString(),token:j.toUpperCase(),amount:BigInt(0)})}function Nt(e,n,r,i){const a=r.get(e);const o=r.get(n);if(!a)throw new O(`Chain:${e} is not a supported chain`,`CHAIN_NOT_SUPPORTED_ERROR`);if(!o)throw new O(`Chain:${n} is not a supported chain`,`CHAIN_NOT_SUPPORTED_ERROR`);let s=p;if(i.isDevelopment)s=f;if(i.isProduction)s=d;return new m(new l({baseConfig:new t({environment:i.environment}),bridgeInstance:s,rootProvider:a,childProvider:o}))}async function Pt(e,n){const r=await n.remote.getConfig(`dex`);return new h({chainId:e,baseConfig:new t({environment:n.environment}),overrides:r?.overrides,secondaryFees:r?.secondaryFees})}function Ft(e){return new v({baseConfig:{environment:e.environment}})}function It(e){return new S({baseConfig:{environment:e.environment}})}function Lt(e,t,n){return new a(e,t,n)}const Rt=`0x0000000000000000000000000000000000000001`;const zt=18;async function Bt(e,t){const n=V(t);const r=H(t);if(!e.get(n))throw new Error(`Missing JsonRpcProvider for chain id: ${n}`);try{const i=await Mt(Nt(n,r,e,t),n,r,t);return{gasEstimateType:`BRIDGE_TO_L2`,fees:i,token:t.networkMap.get(n)?.nativeCurrency}}catch{return{gasEstimateType:`BRIDGE_TO_L2`,fees:{sourceChainGas:BigInt(0),approvalFee:BigInt(0),bridgeFee:BigInt(0),imtblFee:BigInt(0),totalFees:BigInt(0)},token:t.networkMap.get(n)?.nativeCurrency}}}async function Vt(e){const t=H(e);const{inAddress:n,outAddress:r}=(await e.remote.getConfig(`gasEstimateTokens`))[t].swapAddresses;try{const{swap:i}=await(await Pt(t,e)).getUnsignedSwapTxFromAmountIn(Rt,n,r,BigInt(c(`1`,zt)));if(!i.gasFeeEstimate)return{gasEstimateType:`SWAP`,fees:{}};return{gasEstimateType:`SWAP`,fees:{totalFees:i.gasFeeEstimate.value?BigInt(i.gasFeeEstimate.value):void 0,token:{address:i.gasFeeEstimate.token.address,symbol:i.gasFeeEstimate.token.symbol??``,name:i.gasFeeEstimate.token.name??``,decimals:i.gasFeeEstimate.token.decimals??zt}}}}catch{return{gasEstimateType:`SWAP`,fees:{}}}}async function Ht(e,t,n){switch(e.gasEstimateType){case`BRIDGE_TO_L2`:return await Bt(t,n);case`SWAP`:return await Vt(n);default:throw new O(`Invalid type provided for gasEstimateType`,`INVALID_GAS_ESTIMATE_TYPE`)}}const Ut=e=>!!e.maxFeePerGas&&!!e.maxPriorityFeePerGas;const Wt=e=>{if(Ut(e)){const{maxFeePerGas:t,maxPriorityFeePerGas:n}=e;if(t===null||n===null)return null;return n+(t-n)/BigInt(2)}if(e.gasPrice)return e.gasPrice;return null};function Gt(e){if(typeof window===`undefined`)return;const t=t=>e(t.detail);window.addEventListener(`eip6963:announceProvider`,t);window.dispatchEvent(new CustomEvent(`eip6963:requestProvider`));return()=>window.removeEventListener(`eip6963:announceProvider`,t)}function Kt(){const e=new Set;let t=[];const n=()=>Gt(n=>{if(t.some(({info:e})=>e.uuid===n.info.uuid))return;t=[...t,n];e.forEach(e=>e(t,{added:[n]}))});let r=n();return{_listeners(){return e},clear(){e.forEach(e=>e([],{removed:[...t]}));t=[]},destroy(){this.clear();e.clear();r?.()},findProvider({rdns:e}){return t.find(t=>t.info.rdns===e)},getProviders(){return t},reset(){this.clear();r?.();r=n()},subscribe(n,{emitImmediately:r}={}){e.add(n);if(r)n(t,{added:t});return()=>e.delete(n)}}}var Y=class e{static instance;store;resetTimeout;isInit=false;constructor(){this.store=Kt();this.store.reset()}static getInstance(){if(!e.instance)e.instance=new e;return e.instance}findProvider(e){return this.store.findProvider(e)}getProviders(){return this.store.getProviders()}subscribe(e){return this.store.subscribe(e)}clear(){this.store.clear()}reset(){clearTimeout(this.resetTimeout);this.resetTimeout=setTimeout(()=>{this.store.reset()},200)}initialise(){if(!this.isInit){this.isInit=true;this.reset()}}requestProviders(){window.dispatchEvent(new CustomEvent(`eip6963:requestProvider`))}destroy(){this.store.destroy()}};const qt={name:`MetaMask`,rdns:`io.metamask`,icon:`data:image/svg+xml;base64,PHN2ZyBmaWxsPSJub25lIiBoZWlnaHQ9IjMzIiB2aWV3Qm94PSIwIDAgMzUgMzMiIHdpZHRoPSIzNSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj48ZyBzdHJva2UtbGluZWNhcD0icm91bmQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiIHN0cm9rZS13aWR0aD0iLjI1Ij48cGF0aCBkPSJtMzIuOTU4MiAxLTEzLjEzNDEgOS43MTgzIDIuNDQyNC01LjcyNzMxeiIgZmlsbD0iI2UxNzcyNiIgc3Ryb2tlPSIjZTE3NzI2Ii8+PGcgZmlsbD0iI2UyNzYyNSIgc3Ryb2tlPSIjZTI3NjI1Ij48cGF0aCBkPSJtMi42NjI5NiAxIDEzLjAxNzE0IDkuODA5LTIuMzI1NC01LjgxODAyeiIvPjxwYXRoIGQ9Im0yOC4yMjk1IDIzLjUzMzUtMy40OTQ3IDUuMzM4NiA3LjQ4MjkgMi4wNjAzIDIuMTQzNi03LjI4MjN6Ii8+PHBhdGggZD0ibTEuMjcyODEgMjMuNjUwMSAyLjEzMDU1IDcuMjgyMyA3LjQ2OTk0LTIuMDYwMy0zLjQ4MTY2LTUuMzM4NnoiLz48cGF0aCBkPSJtMTAuNDcwNiAxNC41MTQ5LTIuMDc4NiAzLjEzNTggNy40MDUuMzM2OS0uMjQ2OS03Ljk2OXoiLz48cGF0aCBkPSJtMjUuMTUwNSAxNC41MTQ5LTUuMTU3NS00LjU4NzA0LS4xNjg4IDguMDU5NzQgNy40MDQ5LS4zMzY5eiIvPjxwYXRoIGQ9Im0xMC44NzMzIDI4Ljg3MjEgNC40ODE5LTIuMTYzOS0zLjg1ODMtMy4wMDYyeiIvPjxwYXRoIGQ9Im0yMC4yNjU5IDI2LjcwODIgNC40Njg5IDIuMTYzOS0uNjEwNS01LjE3MDF6Ii8+PC9nPjxwYXRoIGQ9Im0yNC43MzQ4IDI4Ljg3MjEtNC40NjktMi4xNjM5LjM2MzggMi45MDI1LS4wMzkgMS4yMzF6IiBmaWxsPSIjZDViZmIyIiBzdHJva2U9IiNkNWJmYjIiLz48cGF0aCBkPSJtMTAuODczMiAyOC44NzIxIDQuMTU3MiAxLjk2OTYtLjAyNi0xLjIzMS4zNTA4LTIuOTAyNXoiIGZpbGw9IiNkNWJmYjIiIHN0cm9rZT0iI2Q1YmZiMiIvPjxwYXRoIGQ9Im0xNS4xMDg0IDIxLjc4NDItMy43MTU1LTEuMDg4NCAyLjYyNDMtMS4yMDUxeiIgZmlsbD0iIzIzMzQ0NyIgc3Ryb2tlPSIjMjMzNDQ3Ii8+PHBhdGggZD0ibTIwLjUxMjYgMjEuNzg0MiAxLjA5MTMtMi4yOTM1IDIuNjM3MiAxLjIwNTF6IiBmaWxsPSIjMjMzNDQ3IiBzdHJva2U9IiMyMzM0NDciLz48cGF0aCBkPSJtMTAuODczMyAyOC44NzIxLjY0OTUtNS4zMzg2LTQuMTMxMTcuMTE2N3oiIGZpbGw9IiNjYzYyMjgiIHN0cm9rZT0iI2NjNjIyOCIvPjxwYXRoIGQ9Im0yNC4wOTgyIDIzLjUzMzUuNjM2NiA1LjMzODYgMy40OTQ2LTUuMjIxOXoiIGZpbGw9IiNjYzYyMjgiIHN0cm9rZT0iI2NjNjIyOCIvPjxwYXRoIGQ9Im0yNy4yMjkxIDE3LjY1MDctNy40MDUuMzM2OS42ODg1IDMuNzk2NiAxLjA5MTMtMi4yOTM1IDIuNjM3MiAxLjIwNTF6IiBmaWxsPSIjY2M2MjI4IiBzdHJva2U9IiNjYzYyMjgiLz48cGF0aCBkPSJtMTEuMzkyOSAyMC42OTU4IDIuNjI0Mi0xLjIwNTEgMS4wOTEzIDIuMjkzNS42ODg1LTMuNzk2Ni03LjQwNDk1LS4zMzY5eiIgZmlsbD0iI2NjNjIyOCIgc3Ryb2tlPSIjY2M2MjI4Ii8+PHBhdGggZD0ibTguMzkyIDE3LjY1MDcgMy4xMDQ5IDYuMDUxMy0uMTAzOS0zLjAwNjJ6IiBmaWxsPSIjZTI3NTI1IiBzdHJva2U9IiNlMjc1MjUiLz48cGF0aCBkPSJtMjQuMjQxMiAyMC42OTU4LS4xMTY5IDMuMDA2MiAzLjEwNDktNi4wNTEzeiIgZmlsbD0iI2UyNzUyNSIgc3Ryb2tlPSIjZTI3NTI1Ii8+PHBhdGggZD0ibTE1Ljc5NyAxNy45ODc2LS42ODg2IDMuNzk2Ny44NzA0IDQuNDgzMy4xOTQ5LTUuOTA4N3oiIGZpbGw9IiNlMjc1MjUiIHN0cm9rZT0iI2UyNzUyNSIvPjxwYXRoIGQ9Im0xOS44MjQyIDE3Ljk4NzYtLjM2MzggMi4zNTg0LjE4MTkgNS45MjE2Ljg3MDQtNC40ODMzeiIgZmlsbD0iI2UyNzUyNSIgc3Ryb2tlPSIjZTI3NTI1Ii8+PHBhdGggZD0ibTIwLjUxMjcgMjEuNzg0Mi0uODcwNCA0LjQ4MzQuNjIzNi40NDA2IDMuODU4NC0zLjAwNjIuMTE2OS0zLjAwNjJ6IiBmaWxsPSIjZjU4NDFmIiBzdHJva2U9IiNmNTg0MWYiLz48cGF0aCBkPSJtMTEuMzkyOSAyMC42OTU4LjEwNCAzLjAwNjIgMy44NTgzIDMuMDA2Mi42MjM2LS40NDA2LS44NzA0LTQuNDgzNHoiIGZpbGw9IiNmNTg0MWYiIHN0cm9rZT0iI2Y1ODQxZiIvPjxwYXRoIGQ9Im0yMC41OTA2IDMwLjg0MTcuMDM5LTEuMjMxLS4zMzc4LS4yODUxaC00Ljk2MjZsLS4zMjQ4LjI4NTEuMDI2IDEuMjMxLTQuMTU3Mi0xLjk2OTYgMS40NTUxIDEuMTkyMSAyLjk0ODkgMi4wMzQ0aDUuMDUzNmwyLjk2Mi0yLjAzNDQgMS40NDItMS4xOTIxeiIgZmlsbD0iI2MwYWM5ZCIgc3Ryb2tlPSIjYzBhYzlkIi8+PHBhdGggZD0ibTIwLjI2NTkgMjYuNzA4Mi0uNjIzNi0uNDQwNmgtMy42NjM1bC0uNjIzNi40NDA2LS4zNTA4IDIuOTAyNS4zMjQ4LS4yODUxaDQuOTYyNmwuMzM3OC4yODUxeiIgZmlsbD0iIzE2MTYxNiIgc3Ryb2tlPSIjMTYxNjE2Ii8+PHBhdGggZD0ibTMzLjUxNjggMTEuMzUzMiAxLjEwNDMtNS4zNjQ0Ny0xLjY2MjktNC45ODg3My0xMi42OTIzIDkuMzk0NCA0Ljg4NDYgNC4xMjA1IDYuODk4MyAyLjAwODUgMS41Mi0xLjc3NTItLjY2MjYtLjQ3OTUgMS4wNTIzLS45NTg4LS44MDU0LS42MjIgMS4wNTIzLS44MDM0eiIgZmlsbD0iIzc2M2UxYSIgc3Ryb2tlPSIjNzYzZTFhIi8+PHBhdGggZD0ibTEgNS45ODg3MyAxLjExNzI0IDUuMzY0NDctLjcxNDUxLjUzMTMgMS4wNjUyNy44MDM0LS44MDU0NS42MjIgMS4wNTIyOC45NTg4LS42NjI1NS40Nzk1IDEuNTE5OTcgMS43NzUyIDYuODk4MzUtMi4wMDg1IDQuODg0Ni00LjEyMDUtMTIuNjkyMzMtOS4zOTQ0eiIgZmlsbD0iIzc2M2UxYSIgc3Ryb2tlPSIjNzYzZTFhIi8+PHBhdGggZD0ibTMyLjA0ODkgMTYuNTIzNC02Ljg5ODMtMi4wMDg1IDIuMDc4NiAzLjEzNTgtMy4xMDQ5IDYuMDUxMyA0LjEwNTItLjA1MTloNi4xMzE4eiIgZmlsbD0iI2Y1ODQxZiIgc3Ryb2tlPSIjZjU4NDFmIi8+PHBhdGggZD0ibTEwLjQ3MDUgMTQuNTE0OS02Ljg5ODI4IDIuMDA4NS0yLjI5OTQ0IDcuMTI2N2g2LjExODgzbDQuMTA1MTkuMDUxOS0zLjEwNDg3LTYuMDUxM3oiIGZpbGw9IiNmNTg0MWYiIHN0cm9rZT0iI2Y1ODQxZiIvPjxwYXRoIGQ9Im0xOS44MjQxIDE3Ljk4NzYuNDQxNy03LjU5MzIgMi4wMDA3LTUuNDAzNGgtOC45MTE5bDIuMDAwNiA1LjQwMzQuNDQxNyA3LjU5MzIuMTY4OSAyLjM4NDIuMDEzIDUuODk1OGgzLjY2MzVsLjAxMy01Ljg5NTh6IiBmaWxsPSIjZjU4NDFmIiBzdHJva2U9IiNmNTg0MWYiLz48L2c+PC9zdmc+`,uuid:`fb8e904e-1a71-454a-af65-dc1ee86311c3`};const Jt={icon:`data:image/svg+xml,<svg viewBox="0 0 48 48" class="SvgIcon undefined Logo Logo--PassportSymbolOutlined css-1dn9atd" xmlns="http://www.w3.org/2000/svg"><g data-testid="undefined__g"><circle cx="24" cy="24" r="22.5" fill="url(%23paint0_radial_6324_83922)"></circle><circle cx="24" cy="24" r="22.5" fill="url(%23paint1_radial_6324_83922)"></circle><path d="M24 0C10.7452 0 0 10.7452 0 24C0 37.2548 10.7452 48 24 48C37.2548 48 48 37.2548 48 24C48 10.7452 37.2548 0 24 0ZM23.0718 9.16608C23.7383 8.83951 24.4406 8.86188 25.087 9.2287C27.3282 10.5059 29.5627 11.7942 31.786 13.096C32.5018 13.5165 32.8686 14.1897 32.8708 15.0173C32.8843 17.9184 32.8798 20.8171 32.8708 23.7182C32.8708 23.8255 32.8015 23.9821 32.7143 24.0335C31.8531 24.548 30.9808 25.0423 30.0347 25.5881V25.1318C30.0347 22.148 30.0257 19.1664 30.0414 16.1827C30.0436 15.6101 29.8468 15.241 29.339 14.9525C26.7377 13.474 24.1499 11.9687 21.5575 10.4723C21.4457 10.4075 21.3361 10.3381 21.1661 10.2352C21.8326 9.85722 22.4321 9.47698 23.0673 9.16608H23.0718ZM22.5953 38.8451C22.45 38.7713 22.3426 38.7198 22.2375 38.6595C18.8041 36.68 15.3752 34.687 11.9307 32.7232C10.9644 32.173 10.5238 31.3879 10.5349 30.2852C10.5551 27.9411 10.5484 25.597 10.5372 23.2507C10.5327 22.1927 10.9622 21.4255 11.8926 20.8977C14.3105 19.5221 16.715 18.1264 19.1195 16.7284C19.3275 16.6076 19.4796 16.5875 19.6965 16.7172C20.5264 17.216 21.3719 17.6924 22.2554 18.2024C22.0876 18.3031 21.9601 18.3791 21.8304 18.4552C19.2268 19.9582 16.6278 21.4658 14.0175 22.9599C13.5903 23.2037 13.3912 23.5213 13.3957 24.0179C13.4091 25.8654 13.4114 27.713 13.3957 29.5605C13.3912 30.0705 13.5948 30.3948 14.0332 30.6453C16.7866 32.2199 19.5288 33.8125 22.28 35.3916C22.5126 35.5258 22.611 35.6645 22.6065 35.9418C22.5864 36.888 22.5998 37.8363 22.5998 38.8473L22.5953 38.8451ZM22.5953 33.553C22.356 33.4166 22.1838 33.3204 22.0116 33.2198C19.8285 31.9605 17.6477 30.6967 15.4602 29.4464C15.2231 29.3122 15.1359 29.1668 15.1381 28.8917C15.1538 27.4714 15.1471 26.0511 15.1426 24.6308C15.1426 24.4384 15.1717 24.3064 15.3618 24.1991C16.167 23.7495 16.9633 23.2798 17.7618 22.8212C17.8199 22.7877 17.8826 22.7631 17.9877 22.7116V24.3064C17.9877 25.1698 18.0011 26.0354 17.9832 26.8988C17.972 27.3909 18.1622 27.7241 18.5916 27.9657C19.8285 28.6636 21.0498 29.3883 22.2867 30.0839C22.5305 30.2203 22.6043 30.3724 22.5998 30.6408C22.5842 31.5847 22.5931 32.5308 22.5931 33.5508L22.5953 33.553ZM20.0746 14.91C19.6116 14.6371 19.2157 14.6393 18.7527 14.91C16.1581 16.4265 13.5523 17.9228 10.9487 19.4259C10.8391 19.4908 10.7251 19.5489 10.5305 19.6541C10.5998 18.6654 10.3873 17.7327 10.7251 16.8291C10.9085 16.3348 11.2529 15.9635 11.7092 15.6995C13.8811 14.4447 16.0507 13.1877 18.227 11.9396C19.0211 11.4833 19.8308 11.4945 20.6248 11.953C23.0964 13.3756 25.5657 14.8026 28.0306 16.2341C28.1357 16.2945 28.2677 16.4309 28.2677 16.5338C28.2856 17.5493 28.2788 18.567 28.2788 19.6563C27.3819 19.1396 26.5543 18.6609 25.7267 18.1823C23.8412 17.093 21.9512 16.0149 20.0746 14.91ZM37.4427 30.8779C37.3778 31.6764 36.9103 32.2423 36.2192 32.6404C33.5732 34.1614 30.9294 35.6913 28.2856 37.2168C27.4557 37.6954 26.6259 38.1741 25.7938 38.6527C25.6932 38.7109 25.5903 38.7601 25.4539 38.8317C25.4449 38.693 25.4337 38.5924 25.4337 38.4917C25.4337 37.6149 25.4382 36.7404 25.4293 35.8636C25.4293 35.6645 25.4762 35.5437 25.6596 35.4386C29.5157 33.2198 33.3696 30.9942 37.2212 28.7709C37.2794 28.7374 37.3443 28.7105 37.4539 28.6591C37.4539 29.4375 37.4986 30.1622 37.4427 30.8779ZM37.4628 25.3577C37.4561 26.2658 36.9663 26.9033 36.1901 27.3506C33.175 29.0841 30.1622 30.8265 27.1493 32.5666C26.5991 32.8842 26.0466 33.1996 25.4561 33.5396C25.4472 33.3897 25.436 33.2913 25.436 33.1907C25.436 32.3273 25.4449 31.4617 25.4293 30.5983C25.4248 30.3523 25.5075 30.2226 25.72 30.0995C28.46 28.5271 31.1911 26.9368 33.9355 25.3733C34.4231 25.096 34.6378 24.7538 34.6334 24.1812C34.6132 21.1974 34.6244 18.2136 34.6244 15.2298V14.7087C35.3402 15.1404 36.0112 15.496 36.624 15.9299C37.1832 16.3258 37.465 16.9253 37.4673 17.6164C37.4762 20.1976 37.4829 22.7788 37.465 25.3599L37.4628 25.3577Z" fill="%230D0D0D"></path><path fill-rule="evenodd" d="M24 0C10.7452 0 0 10.7452 0 24C0 37.2548 10.7452 48 24 48C37.2548 48 48 37.2548 48 24C48 10.7452 37.2548 0 24 0ZM24 2C11.8497 2 2 11.8497 2 24C2 36.1503 11.8497 46 24 46C36.1503 46 46 36.1503 46 24C46 11.8497 36.1503 2 24 2Z" fill="url(%23paint2_radial_6324_83922)"></path><path fill-rule="evenodd" d="M24 0C10.7452 0 0 10.7452 0 24C0 37.2548 10.7452 48 24 48C37.2548 48 48 37.2548 48 24C48 10.7452 37.2548 0 24 0ZM24 2C11.8497 2 2 11.8497 2 24C2 36.1503 11.8497 46 24 46C36.1503 46 46 36.1503 46 24C46 11.8497 36.1503 2 24 2Z" fill="url(%23paint3_radial_6324_83922)"></path><defs><radialGradient id="paint0_radial_6324_83922" cx="0" cy="0" r="1" gradientUnits="userSpaceOnUse" gradientTransform="translate(13.4442 13.3899) rotate(44.9817) scale(46.7487 99.1435)"><stop stop-color="%23A3EEF8"></stop><stop offset="0.177083" stop-color="%23A4DCF5"></stop><stop offset="0.380208" stop-color="%23A6AEEC"></stop><stop offset="1" stop-color="%23ECBEE1"></stop></radialGradient><radialGradient id="paint1_radial_6324_83922" cx="0" cy="0" r="1" gradientUnits="userSpaceOnUse" gradientTransform="translate(25.9515 43.7068) rotate(84.265) scale(24.2138 46.3215)"><stop stop-color="%23FCF5EE"></stop><stop offset="0.715135" stop-color="%23ECBEE1" stop-opacity="0"></stop></radialGradient><radialGradient id="paint2_radial_6324_83922" cx="0" cy="0" r="1" gradientUnits="userSpaceOnUse" gradientTransform="translate(12.7405 12.6825) rotate(44.9817) scale(49.8653 105.753)"><stop stop-color="%23A3EEF8"></stop><stop offset="0.177083" stop-color="%23A4DCF5"></stop><stop offset="0.380208" stop-color="%23A6AEEC"></stop><stop offset="1" stop-color="%23ECBEE1"></stop></radialGradient><radialGradient id="paint3_radial_6324_83922" cx="0" cy="0" r="1" gradientUnits="userSpaceOnUse" gradientTransform="translate(26.0816 45.0206) rotate(84.265) scale(25.828 49.4096)"><stop stop-color="%23FCF5EE"></stop><stop offset="0.715135" stop-color="%23ECBEE1" stop-opacity="0"></stop></radialGradient></defs></g></svg>`,name:`Immutable Passport`,rdns:`com.immutable.passport`,uuid:`b90118be-7234-4c89-b89b-d5d267663eb5`};const Yt=e=>({info:Jt,provider:e});const Xt=e=>({info:qt,provider:e});async function Zt(){const e=await k(async()=>await C(),{type:`METAMASK_PROVIDER_ERROR`});if(!e||!e.request)throw new O(`No MetaMask provider installed.`,`METAMASK_PROVIDER_ERROR`);return new L(e)}async function Qt(e,t){let n=null;let r;switch(e){case`passport`:r=Y.getInstance().findProvider({rdns:Jt.rdns});if(!r)if(t)n=new L(await t.connectEvm({announceProvider:false}));else{console.error(`WalletProviderName was PASSPORT but the passport instance was not provided to the Checkout constructor`);throw new O(`Passport not provided`,`DEFAULT_PROVIDER_ERROR`)}break;case`metamask`:r=Y.getInstance().findProvider({rdns:qt.rdns});if(!r)n=await Zt();break;default:r=Y.getInstance().findProvider({rdns:e});if(!r){console.error(`The WalletProviderName that was provided is not supported`);throw new O(`Provider not supported`,`DEFAULT_PROVIDER_ERROR`)}}if(!n&&r)n=new L(r.provider);if(!n){console.error(`Failed to create provider`);throw new O(`Failed to create provider`,`DEFAULT_PROVIDER_ERROR`)}return{provider:n,walletProviderName:e}}function $t(e){return e&&`send`in e&&typeof e.send===`function`}async function X(e,t,n){return k(async()=>{if(`request`in t)return new L(t);if(t.ethereumProvider?.isPassport)return t;const r={...We,...n};const i=await R(t);let a=(await t.getNetwork()).chainId;try{if(!a)a=(await t.getNetwork()).chainId}catch(e){throw new O(`Unable to detect the browserProvider network`,`WEB3_PROVIDER_ERROR`,{error:e})}if(a!==BigInt(i)&&!r.allowMistmatchedChainId){console.error(`web3ChainId`,a,`underlyingChainId`,i,r);throw new O(`Your wallet has changed network, please switch to a supported network`,`WEB3_PROVIDER_ERROR`)}if(!(await z(e,{type:`all`})).networks.some(e=>e.chainId===Number(i))&&!r.allowUnsupportedProvider)throw new O(`Your wallet is connected to an unsupported network, please switch to a supported network`,`WEB3_PROVIDER_ERROR`);return t},{type:`WEB3_PROVIDER_ERROR`})}async function en(e,t){if(e.isProduction&&t?.has(1))return t;if(t?.has(11155111))return t;const n=new Map;(await z(e,{type:`all`})).networks.forEach(t=>{const r=e.networkMap.get(Number(t.chainId))?.rpcUrls[0];const i=new o(r);n.set(Number(t.chainId),i)});return n}const tn=(e,t,n)=>{const r=[];if(!e.sufficient){for(const t of e.allowances)if(!t.sufficient)r.push(t)}if(!t.sufficient){for(const e of t.allowances)if(!e.sufficient)r.push(e)}if(!n.sufficient){for(const e of n.allowances)if(!e.sufficient)r.push(e)}return r};const nn=e=>{const t=new Map;const n=[];e.forEach(e=>{const{type:r}=e;if(r!==`NATIVE`||e.isFee){n.push(e);return}const i={...e,isFee:`isFee`in e?e.isFee:false};const{amount:a}=i;const o=t.get(r);if(o&&o.type===`NATIVE`)o.amount+=a;else t.set(r,{...i})});return n.concat(Array.from(t.values()))};const rn=e=>{const t=new Map;const n=[];e.forEach(e=>{const{type:r}=e;if(r!==`ERC20`||e.isFee){n.push(e);return}const i={...e,isFee:`isFee`in e?e.isFee:false};const{tokenAddress:a,spenderAddress:o,amount:s}=i;const c=`${a}${o}`;const l=t.get(c);if(l&&l.type===`ERC20`)l.amount+=s;else t.set(c,{...i})});return n.concat(Array.from(t.values()))};const an=e=>{const t=new Map;const n=[];e.forEach(e=>{const{type:r}=e;if(r!==`ERC721`){n.push(e);return}const{contractAddress:i,spenderAddress:a,id:o}=e;const s=`${i}${a}${o}`;if(!t.get(s))t.set(s,{...e})});return n.concat(Array.from(t.values()))};const on=e=>{const t=new Map;const n=[];e.forEach(e=>{const{type:r}=e;if(r!==`ERC1155`){n.push(e);return}const{contractAddress:i,spenderAddress:a,id:o,amount:s}=e;const c=`${i}${a}${o}`;const l=t.get(c);if(l&&l.type===`ERC1155`)l.amount+=s;else t.set(c,{...e})});return n.concat(Array.from(t.values()))};const sn=e=>on(an(rn(nn(e))));const cn=async(e,t,n,r)=>{try{return await new a(n,JSON.stringify(P),e).allowance(t,r)}catch(e){throw new O(`Failed to get the allowance for ERC20`,`GET_ERC20_ALLOWANCE_ERROR`,{contractAddress:n,error:e})}};const ln=async(e,t,n,r,i)=>{try{const o=await new a(n,JSON.stringify(P),e).approve.populateTransaction(r,i);if(o)o.from=t;return o}catch(e){throw new O(`Failed to get the approval transaction for ERC20`,`GET_ERC20_ALLOWANCE_ERROR`,{contractAddress:n,error:e})}};const un=async(e,t,n)=>{let r=true;const i=[];const a=new Map;const o=new Map;const s=new Map;const c=new Map;for(const r of n){if(r.type!==`ERC20`)continue;const{tokenAddress:n,spenderAddress:i}=r;const s=`${n}${i}`;a.set(s,r);o.set(s,cn(e,t,n,i))}const l=await Promise.all(o.values());const u=Array.from(o.keys());for(let n=0;n<l.length;n++){const o=a.get(u[n]);if(!o||o.type!==`ERC20`)continue;if(l[n]>=o.amount){i.push({sufficient:true,itemRequirement:o});continue}r=false;const{tokenAddress:d,spenderAddress:f}=o;const p=`${d}${f}`;const m=o.amount-l[n];s.set(p,{type:`ERC20`,sufficient:false,delta:m,itemRequirement:o,approvalTransaction:void 0});c.set(p,ln(e,t,d,f,m))}const d=await Promise.all(c.values());const f=Array.from(c.keys());d.forEach((e,t)=>{const n=s.get(f[t]);if(!n)return;if(n.sufficient)return;n.approvalTransaction=e});return{sufficient:r,allowances:i.concat(Array.from(s.values()))}};const dn=async(e,t,n,r)=>{try{return await new a(n,JSON.stringify(F),e).isApprovedForAll(t,r)}catch(e){throw new O(`Failed to check approval for all ERC721s of collection`,`GET_ERC721_ALLOWANCE_ERROR`,{ownerAddress:t,contractAddress:n,spenderAddress:r,error:e})}};const fn=async(e,t,n,r,i)=>{try{const o=await new a(n,JSON.stringify(F),e).approve.populateTransaction(r,i);if(o)o.from=t;return o}catch(e){throw new O(`Failed to get the approval transaction for ERC721`,`GET_ERC721_ALLOWANCE_ERROR`,{id:i.toString(),contractAddress:n,spenderAddress:r,ownerAddress:t,error:e})}};const pn=async(e,t,n)=>{try{return await new a(t,JSON.stringify(F),e).getApproved(n)}catch(e){throw new O(`Failed to get approved address for ERC721`,`GET_ERC721_ALLOWANCE_ERROR`,{id:n.toString(),contractAddress:t,error:e})}};const mn=(e,t)=>{try{if(!e.trim())throw new O(`Invalid ERC721 ID`,`GET_ERC721_ALLOWANCE_ERROR`,{id:e,contractAddress:t});return BigInt(e)}catch(n){throw new O(`Invalid ERC721 ID`,`GET_ERC721_ALLOWANCE_ERROR`,{id:e,contractAddress:t})}};const hn=async(e,t,n)=>{const r=new Map;const i=new Map;for(const a of t){if(a.type!==`ERC721`)continue;const{contractAddress:t,spenderAddress:o}=a;const s=`${t}-${o}`;r.set(s,false);if(i.has(s))continue;i.set(s,dn(e,n,t,o))}const a=await Promise.all(i.values());const o=Array.from(i.keys());a.forEach((e,t)=>{r.set(o[t],e)});return r};const gn=async(e,t,n)=>{let r=true;const i=[];const a=new Map;const o=new Map;const s=new Map;const c=new Map;const l=await hn(e,n,t);for(const t of n){if(t.type!==`ERC721`)continue;const{contractAddress:n,id:r,spenderAddress:s}=t;const c=`${n}-${s}`;if(l.get(c)){i.push({sufficient:true,itemRequirement:t});continue}const u=`${n}-${r}`;const d=mn(r,n);a.set(u,t);o.set(u,pn(e,n,d))}const u=await Promise.all(o.values());const d=Array.from(o.keys());for(let n=0;n<u.length;n++){const o=a.get(d[n]);if(!o||o.type!==`ERC721`)continue;if(u[n]===o.spenderAddress){i.push({sufficient:true,itemRequirement:o});continue}r=false;const{contractAddress:l,id:f,spenderAddress:p}=o;const m=`${l}-${f}`;const h=mn(f,l);s.set(m,{type:`ERC721`,sufficient:false,itemRequirement:o,approvalTransaction:void 0});c.set(m,fn(e,t,l,p,h))}const f=await Promise.all(c.values());const p=Array.from(c.keys());f.forEach((e,t)=>{const n=s.get(p[t]);if(!n)return;if(n.sufficient)return;n.approvalTransaction=e});return{sufficient:r,allowances:i.concat(Array.from(s.values()))}};const _n=async(e,t,n,r)=>{try{return await new a(n,JSON.stringify(Pe),e).isApprovedForAll(t,r)}catch(e){throw new O(`Failed to check approval for all ERC1155s of collection`,`GET_ERC1155_ALLOWANCE_ERROR`,{ownerAddress:t,contractAddress:n,spenderAddress:r,error:e})}};const vn=async(e,t,n,r)=>{try{const i=await new a(n,JSON.stringify(Pe),e).setApprovalForAll.populateTransaction(r,true);if(i)i.from=t;return i}catch(e){throw new O(`Failed to get the approval transaction for ERC1155`,`GET_ERC1155_ALLOWANCE_ERROR`,{contractAddress:n,spenderAddress:r,ownerAddress:t,error:e})}};const yn=async(e,t,n)=>{const r=n.filter(e=>e.type===`ERC1155`);const i=await Promise.all(r.map(async n=>{if(await _n(e,t,n.contractAddress,n.spenderAddress))return{sufficient:true,itemRequirement:n};const r=await vn(e,t,n.contractAddress,n.spenderAddress);return{type:`ERC1155`,sufficient:false,itemRequirement:n,approvalTransaction:r}}));return{sufficient:i.some(e=>e.sufficient),allowances:i}};const bn=e=>{const t=new Map;const n=[];e.forEach(e=>{const{type:r}=e;if(r!==`NATIVE`||e.isFee){n.push(e);return}const{amount:i}=e;const a=t.get(r);if(a&&a.type===`NATIVE`)a.amount+=i;else t.set(r,{...e})});return n.concat(Array.from(t.values()))};const xn=e=>{const t=new Map;const n=[];e.forEach(e=>{const{type:r}=e;if(r!==`ERC20`||e.isFee){n.push(e);return}const{tokenAddress:i,amount:a}=e;const o=`${i}`;const s=t.get(o);if(s&&s.type===`ERC20`)s.amount+=a;else t.set(o,{...e})});return n.concat(Array.from(t.values()))};const Sn=e=>{const t=new Map;const n=[];e.forEach(e=>{const{type:r}=e;if(r!==`ERC721`){n.push(e);return}const{contractAddress:i,id:a}=e;const o=`${i}${a}`;if(!t.get(o))t.set(o,{...e})});return n.concat(Array.from(t.values()))};const Cn=e=>Sn(xn(bn(e)));const wn=e=>e.map(e=>{switch(e.type){case`ERC20`:return{address:e.tokenAddress};case`NATIVE`:return{address:j};case`ERC721`:default:return{address:e.contractAddress}}});const Tn=(e,t)=>{const n=BigInt(1);const r=t.find(t=>{const n=t;return U(n.contractAddress,e.contractAddress)&&n.id===e.id});const i=n<0||n===0n||r&&r.balance>=n;const a=n-(r?.balance??BigInt(0));let o=r;if(!o)o={type:`ERC721`,balance:BigInt(0),formattedBalance:`0`,contractAddress:e.contractAddress,id:e.id};return{sufficient:i??false,type:`ERC721`,delta:{balance:a,formattedBalance:a.toString()},current:o,required:{...o,balance:BigInt(1),formattedBalance:`1`},isFee:false}};const En=(e,t)=>{if(e.type===`ERC20`)return t.find(t=>{return U(t.token?.address,e.tokenAddress)});return t.find(e=>{return K(e.token?.address)})};const Dn=async(e,t,n)=>{const r={};for(const i of e){if(i.type===`NATIVE`){r[j]=De;continue}const e=En(i,t);let o=e?.token.address??``;let s=e?.token.name??``;let c=e?.token.symbol??``;let l=e?.token.decimals??18;if(!e&&i.type===`ERC20`){o=i.tokenAddress;if(o.toLowerCase()in r)continue;try{const e=new a(i.tokenAddress,JSON.stringify(P),n);const[t,r,u]=await Promise.all([e.name(),e.symbol(),e.decimals()]);o=i.tokenAddress;l=u;s=t;c=r}catch(e){console.error(`Failed to query contract information`,i.tokenAddress)}}r[o.toLowerCase()]={address:o,name:s,symbol:c,decimals:l}}return r};const On=(e,t,n)=>{let r=En(e,t);const i=e.amount;const a=i<0||i===0n||r&&r?.balance>=i;const o=i-(r?.balance??BigInt(0));if(e.type===`NATIVE`){if(!r)r={type:`NATIVE`,balance:BigInt(0),formattedBalance:`0`,token:n};return{sufficient:a??false,type:`NATIVE`,delta:{balance:o,formattedBalance:s(o,n.decimals)},current:{...r,type:`NATIVE`,token:n},required:{...r,type:`NATIVE`,balance:BigInt(e.amount),formattedBalance:s(e.amount,n.decimals),token:n},isFee:e.isFee}}if(!r)r={type:e.type,balance:BigInt(0),formattedBalance:`0`,token:n};return{sufficient:a??false,type:`ERC20`,delta:{balance:o,formattedBalance:s(o,n.decimals)},current:{...r,token:n},required:{...r,token:n,balance:BigInt(e.amount),formattedBalance:s(e.amount,n.decimals)},isFee:e.isFee}};const kn=async(e,t,n,r,i=false)=>{try{const a=new Map;wn(r).forEach(e=>{if(!e.address)return;a.set(e.address.toLocaleLowerCase(),e)});const{balances:o}=await J(e,t,n,H(e),i);return o.filter(e=>a.get((e.token.address||`native`).toLocaleLowerCase()))}catch(e){throw new O(`Failed to get balances`,`GET_BALANCE_ERROR`,{error:e})}};const An=async(e,t,n)=>{const r=[];const i=new Map;const o=new Map;n.forEach(t=>{if(t.type!==`ERC721`)return;const n=new a(t.contractAddress,JSON.stringify(F),e);i.set(t.contractAddress,t);o.set(t.contractAddress,n.ownerOf(t.id))});try{const e=await Promise.all(o.values());const n=Array.from(o.keys());e.forEach((e,a)=>{const o=i.get(n[a]);let s=0;if(o&&U(t,e))s=1;r.push({type:`ERC721`,balance:BigInt(s),formattedBalance:s.toString(),contractAddress:o.contractAddress,id:o.id})})}catch(e){throw new O(`Failed to get ERC721 balances`,`GET_ERC721_BALANCE_ERROR`,{error:e})}return r};const jn=async(e,t,n,r,i=false)=>{const a=Cn(r);const o=[];const c=[];a.forEach(e=>{switch(e.type){case`ERC20`:case`NATIVE`:o.push(e);break;case`ERC721`:c.push(e);break;default:}});o.sort(e=>`isFee`in e&&e.isFee?1:-1);if(c.length===0&&o.length===0)throw new O(`Unsupported item requirement balance check`,`UNSUPPORTED_BALANCE_REQUIREMENT_ERROR`);const l=[];if(o.length>0)l.push(kn(e,t,n,a,i));if(c.length>0)l.push(An(t,n,a));const u=await Promise.all(l);const d=[];if(o.length>0){const e=u.shift()??[];const n=new Map(e.map(e=>{return[e.type===`NATIVE`?j:e.token.address?.toLowerCase(),e]}));const r=await Dn(o,e,t);o.forEach(e=>{const t=(e.tokenAddress??`native`).toLowerCase();const i=r[t];const a=n.get(t);const o=On(e,[...n.values()],i);d.push(o);if(!a)return;const c=a.balance-o.required.balance;n.set(t,{...a,balance:c,formattedBalance:s(c,o.required.token.decimals)})})}if(c.length>0){const e=u.shift()??[];c.forEach(t=>{d.push(Tn(t,e))})}return{sufficient:d.find(e=>!e.sufficient)===void 0,balanceRequirements:d}};const Mn=async(e,t)=>{try{return await e.estimateGas(t)}catch(e){throw new O(`Failed to estimate gas for transaction`,`UNPREDICTABLE_GAS_LIMIT`,{error:e})}};const Nn=(e,t)=>{if(t.type===`TRANSACTION`||t.gasToken.type===`NATIVE`)return{type:`NATIVE`,amount:e,isFee:true};return{type:`ERC20`,amount:e,tokenAddress:t.gasToken.tokenAddress,spenderAddress:``,isFee:true}};const Pn=async(e,t,n)=>{const r=[];let i=BigInt(0);for(const n of t){if(n.approvalTransaction===void 0)continue;r.push(Mn(e,n.approvalTransaction))}if(n.type===`TRANSACTION`)r.push(Mn(e,n.transaction));else{const t=Wt(await e.getFeeData());if(t!==null){const e=t*n.gasToken.limit;if(e)i+=e}}(await Promise.all(r)).forEach(e=>{i+=e});if(i===0n)return null;return Nn(i,n)};const Fn=async()=>true;const In=async e=>{const t=Le(e.isDevelopment,e.isProduction);try{return await t.checkDexAvailability()}catch{return false}};function Ln(e){return e?.ethereumProvider?.isPassport===true}const Rn=async(e,t)=>{const n={onRamp:e.isOnRampEnabled,swap:e.isSwapEnabled,bridge:e.isBridgeEnabled};const r=[];if(n.onRamp)r.push({id:`onRamp`,promise:Fn()});if(n.swap)r.push({id:`swap`,promise:In(e)});if(r.length>0){const e=r.map(e=>e.promise);(await Promise.allSettled(e)).forEach((e,t)=>{const i=r[t].id;n[i]=n[i]&&e.status===`fulfilled`&&e.value})}n.bridge=n.bridge&&!Ln(t);return n};const zn=async(e,t,n,r)=>{const i=new Map;const a=new Map;if(t.size===0){const t={success:false,error:new O(`No L1 or L2 provider available`,`PROVIDER_ERROR`),balances:[]};i.set(V(e),t);i.set(H(e),t);return i}if(r.bridge){const r=V(e);if(t.has(r))a.set(r,J(e,t.get(r),n,r));else i.set(V(e),{success:false,error:new O(`No L1 provider available for ${r}`,`PROVIDER_ERROR`),balances:[]})}const o=H(e);if(t.has(o))a.set(o,J(e,t.get(o),n,o));else i.set(H(e),{success:false,error:new O(`No L2 provider available for ${o}`,`PROVIDER_ERROR`),balances:[]});if(a.size>0){const e=Array.from(a.keys());(await Promise.allSettled(a.values())).forEach((t,n)=>{const r=e[n];if(t.status===`fulfilled`)i.set(r,{success:true,balances:t.value.balances});else i.set(r,{success:false,error:new O(`Error getting ${o} balances`,`GET_BALANCE_ERROR`),balances:[]})})}return i};const Bn=async(e,t,n,r,i)=>{const a=new Map;const o=1;try{const s=await Pt(t,e);const c=[];const l=[];for(const e of i){if(e===r.address)continue;c.push(s.getUnsignedSwapTxFromAmountOut(n,e,r.address,r.amount,o));l.push(e)}(await q(e,`Time to resolve swap quotes from the dex`,Promise.allSettled(c))).forEach((e,t)=>{if(e.status===`rejected`)return;const n=l[t];a.set(n,{quote:e.value.quote,approval:e.value.approval?.gasFeeEstimate??null,swap:e.value.swap.gasFeeEstimate})});return a}catch{return a}};const Vn=(e,t,n)=>{let r=BigInt(0);let i=`0`;let a;if(e){r=e.value;i=s(e.value,e.token.decimals);a={name:e.token.name??``,symbol:e.token.symbol??``,address:e.token.address,decimals:e.token.decimals}}let o=BigInt(0);let c=`0`;let l;if(t){o=t.value;c=s(t.value,t.token.decimals);l={name:t.token.name??``,symbol:t.token.symbol??``,address:t.token.address,decimals:t.token.decimals}}const u=[];for(const e of n)u.push({type:`SWAP_FEE`,amount:e.amount.value,formattedAmount:s(e.amount.value,e.amount.token.decimals),basisPoints:e.basisPoints,token:{name:e.amount.token.name??``,symbol:e.amount.token.symbol??``,address:e.amount.token.address,decimals:e.amount.token.decimals}});return{approvalGasFee:{type:`GAS`,amount:r,formattedAmount:i,token:a},swapGasFee:{type:`GAS`,amount:o,formattedAmount:c,token:l},swapFees:u}};const Hn=(e,t,n,r)=>{const i=n.token.address;let a=`ERC20`;if(K(i))a=`NATIVE`;return{type:`SWAP`,chainId:e,fundingItem:{type:a,fundsRequired:{amount:t,formattedAmount:W(s(t,n.token.decimals))},userBalance:{balance:n.balance,formattedBalance:n.formattedBalance},token:n.token},fees:r}};const Un=e=>{if(e.type===`ERC20`)return!!e.required.token.address;if(e.type===`NATIVE`)return K(e.required.token.address);return false};const Wn=e=>{let t=``;let n=BigInt(0);switch(e.type){case`ERC20`:t=e.required.token.address;n=e.delta.balance;break;case`NATIVE`:n=e.delta.balance;break;default:break}return{address:t,amount:n}};const Gn=(e,t)=>{if(!t)return{sufficient:true,approvalGasFee:BigInt(0),approvalGasTokenAddress:``};const n=t.value;const r=t.token.address;if(e.length===0)return{sufficient:false,approvalGasFee:n,approvalGasTokenAddress:r};const i=e.find(e=>K(e.token.address)&&K(r)||U(e.token.address,r));if(!i)return{sufficient:false,approvalGasFee:n,approvalGasTokenAddress:r};if(i.balance<n)return{sufficient:false,approvalGasFee:n,approvalGasTokenAddress:r};return{sufficient:true,approvalGasFee:n,approvalGasTokenAddress:r}};const Kn=(e,t,n,r,i)=>{const a=new Map;if(t.approvalGasFee>BigInt(0))a.set(t.approvalGasTokenAddress,t.approvalGasFee);if(n){const e=a.get(n.token.address);if(e)a.set(n.token.address,e+n.value);else a.set(n.token.address,n.value)}if(i){const e=a.get(i.address);if(e)a.set(i.address,e+i.amount);else a.set(i.address,i.amount)}for(const e of r){const t=a.get(e.amount.token.address);if(t){a.set(e.amount.token.address,t+e.amount.value);continue}a.set(e.amount.token.address,e.amount.value)}for(const[t,n]of a.entries()){if(n===BigInt(0))continue;const r=e.find(e=>K(e.token.address)&&K(t)||U(e.token.address,t));if(!r)return false;if(r.balance<n)return false}return true};const qn=(e,t,n,r,i,a)=>{let o=BigInt(0);let s=``;let c=false;t.balanceRequirements.forEach(t=>{if(t.type===`NATIVE`||t.type===`ERC20`){if(t.required.token.address&&U(t.required.token.address,n)){s=t.required.token.address;c=true;o=e-t.required.balance}}});if(!c)return true;if(U(i.approvalGasTokenAddress,s))o-=i.approvalGasFee;for(const e of a)if(U(e.amount.token.address,s))o-=e.amount.value;return o>=r};const Jn=async(e,t,n,r,i,a,o)=>{const s=[];if(!t.swap)return s;if(a.length===0)return s;if(!Un(r))return s;const c=Wn(r);const l=H(e);const u=i.get(l);if(!u)return s;const d=u.balances;if(d.length===0)return s;const f=await Bn(e,H(e),n,c,a);const p=Array.from(f.keys());for(const e of p){const t=f.get(e);if(!t)continue;const n=d.find(t=>U(t.token.address,e));if(!n)continue;const r=t.quote.amountWithMaxSlippage;if(n.balance<r.value)continue;const i=Gn(d,t.approval);if(!i.sufficient)continue;if(!Kn(d,i,t.swap,t.quote.fees,{amount:r.value,address:e}))continue;if(!qn(n.balance,o,e,r.value,i,t.quote.fees))continue;const a=Vn(t.approval,t.swap,t.quote.fees);s.push(Hn(l,r.value,n,a))}return s};const Yn=(e,t)=>{if(t&&t.success)return e.filter(e=>{if(`address`in e)return t.balances.find(t=>U(t.token.address,e.address)&&t.balance>0);return t.balances.find(e=>!(`address`in e.token)&&e.balance>0)});return[]};const Xn=async(e,t)=>{if(t.onRamp)return(await G(e,{type:`onramp`})).tokens;return[]};const Zn=async(e,t,n)=>{if(n.bridge){const n=V(e);const r=(await G(e,{type:`bridge`,chainId:n})).tokens;const i=t.get(n);return Yn(r,i)}return[]};const Qn=async(e,t,n)=>{if(n.swap){const n=(await G(e,{type:`swap`})).tokens;const r=t.get(H(e));return Yn(n,r)}return[]};const $n=async(e,t,n)=>{const r={};r.swap=await Qn(e,t,n);r.bridge=await Zn(e,t,n);r.onRamp=await Xn(e,n);return r};const er=e=>{for(const t of e.balances)if(K(t.token.address))return t.balance;return BigInt(0)};const tr=async(e,t,n,r)=>{const i=Nt(n,r,t,e);try{return{...await i.getFee({action:u.DEPOSIT,gasMultiplier:`auto`,sourceChainId:n.toString(),destinationChainId:r.toString()}),approvalGas:BigInt(0)}}catch(e){throw new O(`Error estimating gas for bridge`,`BRIDGE_GAS_ESTIMATE_ERROR`,{error:e})}};const nr=`0x0000000000000000000000000000000000000eee`;const rr=e=>{if(e===13371)return`imtbl-zkevm-mainnet`;if(e===13473)return`imtbl-zkevm-testnet`;if(e===15003)return`imtbl-zkevm-devnet`;return``};const ir=async(e,t)=>{return(await t.remote.getConfig(`imxAddressMapping`))[e]??``};const ar=async(e,t)=>{if(K(t))return{l1address:await ir(V(e),e),l2address:j};const n=rr(H(e));const r=(await It(e).getToken({chainName:n,contractAddress:t})).result.root_contract_address;if(U(r??``,`0x0000000000000000000000000000000000000eee`))return{l1address:`native`,l2address:t};if(r===null)return void 0;return{l1address:r,l2address:t}};const or=(e,t)=>{return er(e)>=t};const sr=(e,t,n,r,i)=>{const a=i?.decimals??18;const o=[];if(t>0)o.push({type:`BRIDGE_FEE`,amount:t,formattedAmount:s(t,a),token:i});if(n>0)o.push({type:`IMMUTABLE_FEE`,amount:n,formattedAmount:s(n,a),token:i});return{approvalGasFee:{type:`GAS`,amount:r,formattedAmount:s(r,18),token:i},bridgeGasFee:{type:`GAS`,amount:e,formattedAmount:s(e,18),token:i},bridgeFees:o}};const cr=(e,t,n,r,i)=>({type:`BRIDGE`,chainId:e,fundingItem:{type:r,fundsRequired:{amount:n.amount,formattedAmount:W(n.formattedAmount)},userBalance:{balance:t.balance,formattedBalance:t.formattedBalance},token:{name:t.token.name,symbol:t.token.symbol,address:t.token.address,decimals:t.token.decimals}},fees:i});const lr=async(e,t,n,r,i)=>{if(!n.bridge)return void 0;const a=V(e);const o=H(e);const s=e.networkMap.get(a)?.nativeCurrency;const c=i.get(a);if(!t.get(a))throw new O(`No L1 provider available`,`PROVIDER_ERROR`,{chainId:a.toString()});if(c===void 0||c.success===false)return void 0;const l=await Zn(e,i,n);if(l.length===0)return void 0;const u=await ar(e,r.l2address);if(!u)return void 0;const{l1address:d}=u;if(K(d)){if(!l.find(e=>K(e.address)))return void 0}else if(!l.find(e=>U(e.address,d)))return;const{sourceChainGas:f,approvalGas:p,bridgeFee:m,imtblFee:h,totalFees:g}=await tr(e,t,a,o);if(!or(c,g))return void 0;if(K(d)){const e=c.balances.find(e=>K(e.token.address));if(e&&e.balance>=r.amount+g){const t=sr(f,m,h,p,s);return cr(a,e,r,`NATIVE`,t)}return}const _=c.balances.find(e=>U(e.token.address,d));if(_&&_.balance>=r.amount){const e=sr(f,m,h,p,s);return cr(a,_,r,`ERC20`,e)}};const ur=(e,t)=>{const n={l1balances:[],l2balances:[]};const r=t.get(V(e));const i=t.get(H(e));if(!r)return n;if(r.error!==void 0)return n;if(!r.success)return n;if(!i)return n;if(i.error!==void 0)return n;if(!i.success)return n;return{l1balances:r.balances,l2balances:i.balances}};const dr=(e,t)=>{let n=BigInt(0);e.quote.fees.forEach(e=>{if(U(e.amount.token.address,t))n+=e.amount.value});if(e.approval){if(U(e.approval.token.address,t))n+=e.approval.value}return n};const fr=(e,t)=>{for(const n of e.balanceRequirements)if(n.type===`NATIVE`||n.type===`ERC20`){if(U(n.required.token.address,t))return n.required.balance}return BigInt(0)};const pr=(e,t,n)=>{const r=n?.balance??BigInt(0);if(r>=e+t)return BigInt(0);if(r<=0)return e+t;const i=r-t;if(i>=0)return e-i;return e+t-r};const mr=(e,t,n,r,i)=>{const a=[];for(const[o,c]of e){const e=n.find(e=>U(e.token.address,o));const l=r.find(e=>U(e.l2address,o));if(!l)continue;const{l1address:u,l2address:d}=l;if(!u)continue;const f=t.find(e=>{if(e.token.address===void 0&&U(u,`0x0000000000000000000000000000000000000eee`))return true;return U(e.token.address,u)});if(!f)continue;const p=c.quote.amountWithMaxSlippage.value+dr(c,o);const m=fr(i,o);const h=pr(p,m,e);if(h<=0)continue;if(h>=f.balance)continue;a.push({amount:h,formattedAmount:W(s(h,f.token.decimals)),l2address:d})}return a};const hr=async(e,t)=>{const n=t.map(t=>ar(e,t.address??``));return(await Promise.all(n)).filter(e=>e!==void 0)};const gr=async(e,t,n,r,i)=>{const a=[];for(const e of i){if(!e.address)continue;a.push(e.address)}return await Bn(e,H(e),t,{address:n,amount:r.delta.balance},a)};const _r=(e,t,n,r,i,a)=>{if(e.length===0)return true;if(t.length===0)return true;if(n.length===0)return true;if(r.length===0)return true;if(!i.bridge)return true;if(!i.swap)return true;if(a===void 0)return true;if(a===``)return true;return false};const vr=(e,t,n,r)=>{const i=[];for(const a of r){if(!t.includes(a.l1address))continue;if(U(a.l2address,e))continue;const r=n.find(e=>U(e.address,a.l2address));if(!r)continue;i.push(r)}return i};const yr=(e,t,n,r,i)=>{const a=new Map;for(const[e,n]of t)a.set(e,{success:n.success,balances:n.balances});const o=new Map;for(const e of n){if(!e.token.address)continue;o.set(e.token.address,e)}for(const e of r){const{amount:t,l2address:n}=e;if(n===``)continue;let r=BigInt(0);const a=o.get(n);if(a)r=a.balance;const c=r+t;const l=i.find(e=>U(e.address,n));o.set(n,{balance:c,formattedBalance:s(c,l.decimals),token:l})}const c=Array.from(o.values());a.set(H(e),{success:true,balances:c});return a};const br=(e,t)=>{const n=[];for(const r of t){const{chainId:t,fundingItem:i}=r;const{userBalance:a}=r.fundingItem;const o=e.get(t);if(!o)continue;let s=BigInt(0);let c=`0`;const l=o.balances.find(e=>U(e.token.address,i.token.address));if(l){s=l.balance;c=l.formattedBalance}a.balance=s;a.formattedBalance=c;n.push(r)}return n};const xr=(e,t,n)=>{const r=[];for(const i of e){if(!i)continue;const e=n.find(e=>{if(i.fundingItem.token.address===void 0)return U(e.l1address,`0x0000000000000000000000000000000000000eee`)&&e.l2address;return U(e.l1address,i.fundingItem.token.address)&&e.l2address});if(!e)continue;const a=t.find(t=>U(t.fundingItem.token.address,e.l2address));if(!a)continue;r.push({bridgeFundingStep:i,swapFundingStep:a})}return r};const Sr=async(e,t,n,r,i,a,o,s,c)=>{const{l1balances:l,l2balances:u}=ur(e,a);const d=r.required.token.address;if(_r(o,s,l,u,n,d))return[];const f=await hr(e,s);const p=vr(d,o,s,f);if(p.length===0)return[];const m=mr(await gr(e,i,d,r,p),l,u,f,c);if(m.length===0)return[];const h=new Map;const g=new Map;const _=[];for(const r of m){if(!r.l2address)continue;h.set(r.l2address,lr(e,t,n,r,a));g.set(r.l2address,{amount:r.amount,formattedAmount:r.formattedAmount,l2address:r.l2address})}const v=await Promise.all(h.values());const y=Array.from(h.keys());const b=[];v.forEach((e,t)=>{const n=y[t];if(e===void 0)return;b.push(n);const r=g.get(n);if(!r)return;_.push({amount:r.amount,formattedAmount:r.formattedAmount,l2address:r.l2address})});if(b.length===0)return[];if(_.length===0)return[];const x=await Jn(e,n,i,r,yr(e,a,u,_,s),b,c);if(!x)return[];const S=br(a,x);return xr(v,S,f)};const Cr=async(e,t,n)=>{if(![`ERC20`,`NATIVE`].includes(n.type))return void 0;const{required:r,current:i,delta:a}=n;let o=false;(await Xn(e,t)).forEach(e=>{if(!e.address)return;if(!r.token)return;if(K(r.token.address)||U(e.address,r.token.address))o=true});if(!o)return void 0;return{type:`ONRAMP`,chainId:H(e),fundingItem:{type:K(r.token.address)?`NATIVE`:`ERC20`,fundsRequired:{amount:a.balance,formattedAmount:W(a.formattedBalance)},userBalance:{balance:i.balance,formattedBalance:i.formattedBalance},token:r.token}}};const wr=e=>e.bridge||e.swap||e.onRamp;const Tr=e=>{let t=0;let n;for(const r of e.balanceRequirements)if(!r.sufficient){t++;n=r}if(t===1)return n};const Er=async(e,t,n,r,i)=>{let a;if(r===void 0)return void 0;if(r.type!==`NATIVE`&&r.type!==`ERC20`)return;const o={amount:r.delta.balance,formattedAmount:r.delta.formattedBalance,l2address:r.required.token.address??``};if(n.bridge&&r)a=await lr(e,t,n,o,i);return a};const Dr=async(e,t,n,r,i,a,o)=>{const s=[];if(!t.swap)return s;if(n===void 0)return s;if(a===void 0)return s;const c=i.get(H(e));if(!c)return s;if(c.error!==void 0||!c.success)return s;if(a.length===0)return s;const l=a.filter(e=>e.address).map(e=>e.address);if(l.length===0)return s;return await Jn(e,t,r,n,i,l,o)};const Or=async(e,t,n,r,i,a,o,s)=>{if(!r)return[];const c=a.get(V(e));const l=a.get(H(e));if(!c)return[];if(c.error!==void 0||!c.success)return[];if(!l)return[];if(l.error!==void 0||!l.success)return[];const u=(o?.bridge??[]).map(e=>{if(e.address===void 0)return nr;return e.address});const d=o?.swap??[];if(r.type!==`NATIVE`&&r.type!==`ERC20`)return[];return await Sr(e,t,n,r,i,a,u,d,s)};const kr=async(e,t,n)=>{if(!t.onRamp)return void 0;if(n===void 0)return void 0;return await Cr(e,t,n)};const Z={swap:1,bridge:2,onRamp:3,bridgeAndSwap:4};const Q=(e,t,n,r)=>{if(!e)return;let i;if(`bridgeFundingStep`in e&&`swapFundingStep`in e)i=[e.bridgeFundingStep,e.swapFundingStep];else i=[e];const a={priority:t,steps:i};n.push(a);r?.(a)};const Ar=async(e,t,n,r,i)=>{if(!wr(r))return{type:`NO_ROUTE_OPTIONS`,message:`No routing options are available`};let a;try{a=await en(e)}catch(e){throw new O(`Error occurred while creating read only providers`,`PROVIDER_ERROR`,{error:e})}const o=await q(e,`Time to get token balances inside router`,zn(e,a,t,r));const s=await q(e,`Time to get routing allowlist`,$n(e,o,r));const c=Tr(n);const l=[];const u=[];if(r.swap)l.push(Dr(e,r,c,t,o,s.swap,n).then(e=>{e.forEach(e=>{Q(e,Z.swap,u,i)})}));if(r.bridge)l.push(Er(e,a,r,c,o).then(e=>{Q(e,Z.bridge,u,i)}));if(r.onRamp)l.push(kr(e,r,c).then(e=>{Q(e,Z.onRamp,u,i)}));if(r.swap&&r.bridge)l.push(Or(e,a,r,c,t,o,s,n).then(e=>{e.forEach(e=>{Q(e,Z.bridgeAndSwap,u,i)})}));await q(e,`Time to resolve all routes`,Promise.all(l));if(u.length===0)return{type:`NO_ROUTES_FOUND`,message:`Smart Checkout did not find any funding routes to fulfill the transaction`};return{type:`ROUTES_FOUND`,fundingRoutes:u}};const jr=e=>{return{sufficient:false,balanceRequirements:e.balanceRequirements.map(e=>{if(e.type===`ERC20`&&e.sufficient)return{...e,sufficient:false,delta:{balance:e.required.balance,formattedBalance:e.required.formattedBalance}};return e})}};const Mr=async(e,t,n,r,i,a,o,s,c)=>{const l=await q(e,`Total time to run the routing calculator`,Ar(e,t,!o||n&&s?jr(a):a,r,c));s?.({sufficient:n,transactionRequirements:i,router:{availableRoutingOptions:r,routingOutcome:l}});return l};const Nr=async(e,t,n,r,i,a,o,s=false)=>{const c=await(await t.getSigner()).getAddress();let l=sn(n);const u=un(t,c,l);const d=gn(t,c,l);const f=yn(t,c,l);const p=await q(e,`Time to calculate token allowances`,Promise.all([u,d,f]));const m=tn(p[0],p[1],p[2]);let h=null;if(r){h=await q(e,`Time to run gas calculator`,Pn(t,m,r));if(h!==null){l.push(h);l=sn(l)}}const g=await q(e,`Time to run balance checks`,jn(e,t,c,l,true));const{sufficient:_}=g;const v=g.balanceRequirements;const y=await q(e,`Time to fetch available routing options`,Rn(e,t));if(i?.onRamp===false)y.onRamp=false;if(i?.swap===false)y.swap=false;if(i?.bridge===false)y.bridge=false;if(a){Mr(e,c,_,y,v,g,s,a,o);return{sufficient:_,transactionRequirements:v}}if(_)return{sufficient:_,transactionRequirements:v};return{sufficient:_,transactionRequirements:v,router:{availableRoutingOptions:y,routingOutcome:await Mr(e,c,_,y,v,g,s,a,o)}}};function Pr(e){return e?.ethereumProvider?.isPassport===true}function Fr(e){return Pr(e)}const Ir=async(e,t)=>{const n=t;const{chainId:r}=await e.getNetwork();if(!mt(Number(r)))return n;if(typeof n.gasPrice!==`undefined`)return n;if(Fr(e))n.gasPrice=BigInt(0);else{n.maxFeePerGas=Fe.maxFeePerGas;n.maxPriorityFeePerGas=Fe.maxPriorityFeePerGas}return n};const Lr=e=>{if(e.code===`INSUFFICIENT_FUNDS`)return new O(e.message,`INSUFFICIENT_FUNDS`,{error:e});if(e.code===`ACTION_REJECTED`)return new O(e.message,`USER_REJECTED_REQUEST_ERROR`,{error:e});return new O(e.message,`TRANSACTION_FAILED`,{error:e})};const $=async(e,t)=>{try{const n=await e.getSigner();const r=await Ir(e,t);return{transactionResponse:await n.sendTransaction(r)}}catch(e){throw Lr(e)}};const Rr=async(e,t)=>{let n=[];try{const r=await Promise.all(t.map(t=>$(e,t)));n=await Promise.all(r.map(e=>e.transactionResponse.wait()))}catch(e){throw new O(`An error occurred while executing the approval transaction`,`EXECUTE_APPROVAL_TRANSACTION_ERROR`,{error:e})}for(const e of n)if(e?.status===0)return{type:`FAILED`,transactionHash:e.hash,reason:`Approval transaction failed and was reverted`};return{type:`SUCCESS`}};const zr=async(e,t)=>{let n=[];try{const r=await Promise.all(t.map(t=>$(e,t)));n=await Promise.all(r.map(e=>e.transactionResponse.wait()))}catch(e){throw new O(`An error occurred while executing the fulfillment transaction`,`EXECUTE_FULFILLMENT_TRANSACTION_ERROR`,{error:e})}for(const e of n)if(e?.status===0)return{type:`FAILED`,transactionHash:e.hash,reason:`Fulfillment transaction failed and was reverted`};return{type:`SUCCESS`}};const Br=async(e,t)=>{try{const n=await(await e.getSigner()).signTypedData(t.unsignedMessage.domain,t.unsignedMessage.types,t.unsignedMessage.value);return{orderComponents:t.orderComponents,orderHash:t.orderHash,signedMessage:n}}catch(e){throw new O(`An error occurred while signing the message`,`SIGN_MESSAGE_ERROR`,{error:e})}};const Vr=async e=>{let t=[];let n=[];const r=[];const i=[];for(const t of e){if(t.type!==g.TRANSACTION)continue;if(t.purpose===b.APPROVAL)r.push(t.buildTransaction());if(t.purpose===b.FULFILL_ORDER)i.push(t.buildTransaction())}t=await Promise.all(r);n=await Promise.all(i);return{approvalTransactions:t,fulfillmentTransactions:n}};const Hr=async e=>{let t=[];const n=[];for(const t of e){if(t.type!==g.TRANSACTION)continue;if(t.purpose===b.APPROVAL)n.push(t.buildTransaction())}t=await Promise.all(n);return t};const Ur=async e=>{let t=[];const n=[];for(const t of e){if(t.type!==g.TRANSACTION)continue;if(t.purpose===b.FULFILL_ORDER)n.push(t.buildTransaction())}t=await Promise.all(n);return t};const Wr=(e,t,n)=>{let r;for(const e of n){if(e.type!==g.SIGNABLE)continue;if(e.purpose===y.CREATE_LISTING)r={domain:e.message.domain,types:e.message.types,value:e.message.value}}if(!r)return void 0;return{orderHash:e,orderComponents:t,unsignedMessage:r}};const Gr=1;const Kr=6;const qr=(e,t,n=BigInt(1))=>{const r=e.amount;const i=Math.round(r.percentageDecimal*10**6);const a=t*BigInt(i)/BigInt(10**6);return a-a%n};const Jr=(e,t)=>{const n=e.amount;return c(n.token,t)};const Yr=(e,t,n=18,r=BigInt(1))=>{let i=BigInt(0);const a=BigInt(t);const o=a*BigInt(1*10**6)/BigInt(10**6);const s=[];for(const t of e){let e=BigInt(0);if(Object.hasOwn(t.amount,`percentageDecimal`)){e=qr(t,a,r);i+=e}else if(Object.hasOwn(t.amount,`token`)){e=Jr(t,n);i+=e}else throw new O(`Unknown fee type parsed, must be percentageDecimal or token`,`ORDER_FEE_ERROR`);if(i>o)throw new O(`The combined fees are above the allowed maximum of ${1*100}%`,`ORDER_FEE_ERROR`);if(e>0)s.push({amount:e.toString(),recipientAddress:t.recipient})}return s};const Xr=(e,t,n,r,i=false)=>{switch(e){case`ERC20`:return{type:e,amount:n,tokenAddress:t,spenderAddress:r,isFee:i};case`NATIVE`:default:return{type:`NATIVE`,amount:n,isFee:i}}};const Zr=(e,t)=>{if(t.length>0)return{type:`TRANSACTION`,transaction:t[0]};return{type:`GAS`,gasToken:{type:`NATIVE`,limit:BigInt(e)}}};const Qr=async(e,t,n,r={waitFulfillmentSettlements:true})=>{ee(`checkout_sdk`,`buy_initiated`);if(n.length===0)throw new O(`No orders were provided to the orders array. Please provide at least one order.`,`FULFILL_ORDER_LISTING_ERROR`);let i;let a=``;let o=18;const s=x.estimatedFulfillmentGasGwei;const c=Ft(e);const l=It(e);const u=await q(e,`Time to get the address from the provider`,(await t.getSigner()).getAddress());wt();J(e,t,u,V(e));J(e,t,u,H(e));const{id:d,takerFees:f,fillAmount:p}=n[0];let m;try{i=await q(e,`Time to fetch the listing from the orderbook`,c.getListing(d));const{seaportContractAddress:t,chainName:n}=c.config();m=n;a=t}catch(e){throw new O(`An error occurred while getting the order listing`,`GET_ORDER_LISTING_ERROR`,{error:e,orderId:d})}if(i.result.buy.length===0)throw new O(`An error occurred with the get order listing`,`GET_ORDER_LISTING_ERROR`,{orderId:d,message:`No buy side tokens found on order`});const h=i.result.buy[0];if(h.type===`ERC20`){const t=await q(e,`Time to get decimals of token contract for the buy token`,l.getToken({contractAddress:h.contractAddress,chainName:m}));if(t.result.decimals)o=t.result.decimals}let g=[];if(f&&f.length>0){const e=i.result.sell[0].type===`ERC721`?BigInt(1):BigInt(i.result.sell[0].amount);g=Yr(f,h.amount,o,e)}let v=[];let y=[];let b=[];const S=performance.now();try{const{actions:t}=await q(e,`Time to call fulfillOrder from the orderbook`,c.fulfillOrder(d,u,g,p));b=t;v=await q(e,`Time to construct the unsigned approval transactions`,Hr(t))}catch(t){bt(e,`Time to call fulfillOrder from the orderbook`,(performance.now()-S)/1e3);if(t.message.includes(_.EXPIRED))throw new O(`Order is expired`,`ORDER_EXPIRED_ERROR`,{orderId:d});if(!t.message.includes(`The fulfiller does not have the balances needed to fulfill`))throw new O(`Error occurred while trying to fulfill the order`,`FULFILL_ORDER_LISTING_ERROR`,{orderId:d,error:t})}try{y=await q(e,`Time to construct the unsigned fulfillment transactions`,Ur(b))}catch{}let C=BigInt(`0`);let w=`NATIVE`;let T=``;const E=i.result.buy;if(E.length>0)switch(E[0].type){case`NATIVE`:w=`NATIVE`;break;case`ERC20`:w=`ERC20`;T=E[0].contractAddress;break;default:throw new O(`Purchasing token type is unsupported`,`UNSUPPORTED_TOKEN_TYPE_ERROR`,{orderId:d})}E.forEach(e=>{if(e.type!==`ERC721`)C+=BigInt(e.amount)});i.result.fees.forEach(e=>{C+=BigInt(e.amount)});if(i.result.sell[0].type===`ERC1155`&&p)C=C*BigInt(p)/BigInt(i.result.sell[0].amount);const D=await q(e,`Total time running smart checkout`,Nr(e,t,[Xr(w,T,C,a)],Zr(s,y)));if(D.sufficient){const e=await Rr(t,v);if(e.type===`FAILED`)return{status:`FAILED`,transactionHash:e.transactionHash,reason:e.reason,smartCheckoutResult:D};try{if(y.length===0)y=await Ur(b)}catch(e){throw new O(`Error fetching fulfillment transaction`,`FULFILL_ORDER_LISTING_ERROR`,{error:e})}if(r.waitFulfillmentSettlements){const e=await zr(t,y);if(e.type===`FAILED`)return{status:`FAILED`,transactionHash:e.transactionHash,reason:e.reason,smartCheckoutResult:D};return{status:`SUCCESS`,smartCheckoutResult:D}}let n;try{n=(await Promise.all(y.map(e=>$(t,e)))).map(e=>e.transactionResponse)}catch(e){throw new O(`An error occurred while executing the fulfillment transaction`,`EXECUTE_FULFILLMENT_TRANSACTION_ERROR`,{message:e.message})}return{status:`FULFILLMENTS_UNSETTLED`,smartCheckoutResult:D,transactions:n}}return{status:`INSUFFICIENT_FUNDS`,smartCheckoutResult:D}};const $r=async(e,t,n,r,i)=>{let a;if(r.length===0)throw new O(`No orderIds were provided to the orderIds array. Please provide at least one orderId.`,`CANCEL_ORDER_LISTING_ERROR`);const o=r[0];try{const r=await q(e,`Time to get the address from the provider`,(await n.getSigner()).getAddress());a=await(await q(e,`Time to get the cancel order from the orderbook`,t.cancelOrdersOnChain([o],r))).cancellationAction.buildTransaction()}catch(e){throw new O(`An error occurred while cancelling the order listing`,`CANCEL_ORDER_LISTING_ERROR`,{orderId:o,error:e})}if(i){const e=await zr(n,[a]);if(e.type===`FAILED`)return{status:`FAILED`,transactionHash:e.transactionHash,reason:e.reason};return{status:`SUCCESS`}}let s;try{s=(await Promise.all([a].map(e=>$(n,e)))).map(e=>e.transactionResponse)}catch(e){throw new O(`An error occurred while executing the fulfillment transaction`,`EXECUTE_FULFILLMENT_TRANSACTION_ERROR`,{message:e.message})}return{status:`FULFILLMENTS_UNSETTLED`,transactions:s}};const ei=async(e,t,n)=>{try{const r=await t.getSigner();const i=await r.getAddress();const{signableAction:a}=await e.prepareOrderCancellations(n);const o=await r.signTypedData(a.message.domain,a.message.types,a.message.value);const{result:s}=await e.cancelOrders(n,i,o);const c=[];const l=[];const u=[];for(const e of s.successful_cancellations)c.push({orderId:e});for(const e of s.failed_cancellations)l.push({orderId:e.order,reason:e.reason_code});for(const e of s.pending_cancellations)u.push({orderId:e});return{successfulCancellations:c,failedCancellations:l,pendingCancellations:u}}catch(e){throw new O(`An error occurred while cancelling the order listing`,`CANCEL_ORDER_LISTING_ERROR`,{orderIds:n,error:e})}};const ti=async(e,t,n,r={waitFulfillmentSettlements:true,useGaslessCancel:false})=>{const i=Ft(e);if(r.useGaslessCancel)return await ei(i,t,n);return await $r(e,i,t,n,r.waitFulfillmentSettlements??true)};async function ni(e,t){const n=[];t.forEach(t=>{if(t.type===`ERC20`){const{tokenAddress:r}=t;n.push(Lt(r,P,e).decimals())}});const r=await Promise.all(n);return t.map((e,t)=>{if(e.type===`NATIVE`)return{...e,amount:c(e.amount,18)};if(e.type===`ERC20`)return{...e,amount:c(e.amount,r[t])};return e})}const ri=(e,t,n)=>({type:`ERC721`,id:e,contractAddress:t,spenderAddress:n});const ii=(e,t,n,r)=>({type:`ERC1155`,id:e,contractAddress:t,spenderAddress:n,amount:BigInt(r)});const ai=(e,t=18)=>{const n=c(e.amount,t);if(e.type===`NATIVE`)return{type:`NATIVE`,amount:n.toString()};return{type:`ERC20`,amount:n.toString(),contractAddress:e.tokenAddress}};const oi=async(e,t,n)=>{let r;let i;let o=``;ee(`checkout_sdk`,`sell_initiated`);if(n.length===0)throw new O(`No orders were provided to the orders array. Please provide at least one order.`,`PREPARE_ORDER_LISTING_ERROR`);const{buyToken:s,sellToken:c,makerFees:l,orderExpiry:u}=n[0];let d=18;if(s.type===`ERC20`)d=await q(e,`Time to get decimals of token contract for the buy token`,new a(s.tokenAddress,JSON.stringify(P),t).decimals());const f=ai(s,d);const p=`type`in c;try{const n=await q(e,`Time to get the address from the provider`,(await t.getSigner()).getAddress());r=Ft(e);const{seaportContractAddress:a}=r.config();o=a;const s=p&&c.type===`ERC1155`?{type:`ERC1155`,contractAddress:c.collectionAddress,tokenId:c.id,amount:c.amount}:{type:`ERC721`,contractAddress:c.collectionAddress,tokenId:c.id};i=await q(e,`Time to prepare the listing from the orderbook`,r.prepareListing({makerAddress:n,buy:f,sell:s,orderExpiry:u}))}catch(e){throw new O(`An error occurred while preparing the listing`,`PREPARE_ORDER_LISTING_ERROR`,{error:e,id:c.id,collectionAddress:c.collectionAddress})}const m=[];if(p&&c.type===`ERC1155`){const e=ii(c.id,c.collectionAddress,o,c.amount);m.push(e)}else{const e=ri(c.id,c.collectionAddress,o);m.push(e)}let h;if(!Ln(t))h=await q(e,`Total time running smart checkout`,Nr(e,t,m,{type:`GAS`,gasToken:{type:`NATIVE`,limit:BigInt(x.estimatedFulfillmentGasGwei)}}));else h={sufficient:true,transactionRequirements:[]};if(h.sufficient){const e=await Rr(t,(await Vr(i.actions)).approvalTransactions);if(e.type===`FAILED`)return{status:`FAILED`,transactionHash:e.transactionHash,reason:e.reason,smartCheckoutResult:h};const n=Wr(i.orderHash,i.orderComponents,i.actions);if(!n)throw new O(`The unsigned message is missing after preparing the listing`,`SIGN_MESSAGE_ERROR`,{id:c.id,collectionAddress:c.collectionAddress});const a=await Br(t,n);let o=``;const s={orderComponents:a.orderComponents,orderHash:a.orderHash,orderSignature:a.signedMessage,makerFees:[]};if(l!==void 0){let e=BigInt(1);if(p&&c.type===`ERC1155`)e=BigInt(c.amount);const t=Yr(l,f.amount,d,e);if(t.length!==l.length)throw new O(`One of the fees is too small, must be greater than 0.000001`,`CREATE_ORDER_LISTING_ERROR`);s.makerFees=t}try{o=(await r.createListing(s)).result.id}catch(e){throw new O(`An error occurred while creating the listing`,`CREATE_ORDER_LISTING_ERROR`,{error:e,collectionId:c.id,collectionAddress:c.collectionAddress})}return{status:`SUCCESS`,orderIds:[o],smartCheckoutResult:h}}return{status:`INSUFFICIENT_FUNDS`,smartCheckoutResult:h}};const si=async(e,t,n,r,i,a,o,s,l)=>{if(!n.address||n.decimals===0)throw new O(`fromToken address or decimals is missing.`,`MISSING_PARAMS`);if(!r.address||r.decimals===0)throw new O(`toToken address or decimals is missing.`,`MISSING_PARAMS`);if(i&&a)throw new O(`Only one of fromAmount or toAmount can be provided.`,`MISSING_PARAMS`);if(!i&&!a)throw new O(`fromAmount or toAmount must be provided.`,`MISSING_PARAMS`);const u=await Pt(H(e),e);const d=await(await t.getSigner()).getAddress();if(i)return u.getUnsignedSwapTxFromAmountIn(d,n.address,r.address,BigInt(c(i,n.decimals)),o,s,l);return u.getUnsignedSwapTxFromAmountOut(d,n.address,r.address,BigInt(c(a,r.decimals)),o,s,l)};const ci=async(e,t,n,r,i,a,o,s,c)=>{const l=await si(e,t,n,r,i,a,o,s,c);if(l.approval){if((await(await $(t,l.approval.transaction)).transactionResponse.wait())?.status===0)throw new O(`Approval transaction failed and was reverted`,`APPROVAL_TRANSACTION_FAILED`)}const u=await(await $(t,l.swap.transaction)).transactionResponse.wait();if(u?.status===0)throw new O(`Swap transaction failed and was reverted`,`TRANSACTION_FAILED`);return{swapReceipt:u,quote:l.quote,swap:l.swap}};async function li(e){const t=[];const n=e.exclude?.map(e=>e.walletProviderName)??[];let r=Object.values(He);if(n.length!==0)r=r.filter(e=>!n.includes(e));for(const e of r)t.push({walletProviderName:e});return{wallets:t}}const ui=async(e,t)=>Object.fromEntries(e.map(e=>[e.toLowerCase(),{sanctioned:false}]));const di=(e,t)=>false;const fi=(e,t)=>false;const pi=e=>false;const mi={baseConfig:{environment:e.SANDBOX},passport:void 0};var hi=class{readOnlyProviders;httpClient;config;fiatRampService;availability;passport;constructor(e=mi){this.httpClient=new xe(e);this.config=new pt(e,this.httpClient);this.fiatRampService=new jt(this.config);this.readOnlyProviders=new Map;this.availability=Le(this.config.isDevelopment,this.config.isProduction);this.passport=e.passport;Y.getInstance().initialise()}async widgets(e){const t=this;const n=I();try{const r=await import(`https://cdn.jsdelivr.net/npm/@imtbl/checkout-widgets@${I()}/dist/browser/index.js`);if(r&&r.WidgetsFactory)return new r.WidgetsFactory(t,e.config);throw new Error(`WidgetsFactory not found in loaded module for version: ${n}`)}catch(e){throw new O(`Failed to load widgets script`,`WIDGETS_SCRIPT_LOAD_ERROR`,{error:e})}}async createProvider(e){return await Qt(e.walletProviderName,this.passport)}getInjectedProviders(){return Y.getInstance().getProviders()}findInjectedProvider(e){return Y.getInstance().findProvider(e)}onInjectedProvidersChange(e){return Y.getInstance().subscribe(e)}clearInjectedProviders(){return Y.getInstance().clear()}async checkIsWalletConnected(e){const t=await X(this.config,e.provider,{allowMistmatchedChainId:true,allowUnsupportedProvider:true});return Ot(t)}async getRiskAssessment(e){return await ui(e,this.config)}checkIsAddressSanctioned(e,t){return di(e,t)}async connect(e){const t=await X(this.config,e.provider,{allowUnsupportedProvider:true,allowMistmatchedChainId:true});if(e.requestWalletPermissions&&!Pr(t))await At(t);else await kt(t);return t}async addNetwork(e){const t=await X(this.config,e.provider,{allowUnsupportedProvider:true,allowMistmatchedChainId:true});return await nt(this.config.networkMap,t,e.chainId)}async switchNetwork(e){const t=await X(this.config,e.provider,{allowUnsupportedProvider:true,allowMistmatchedChainId:true});return await it(this.config,t,e.chainId)}async getTokenInfo(e){return await _t(e.provider,e.tokenAddress)}async getBalance(e){const t=await X(this.config,e.provider);if(!e.tokenAddress||e.tokenAddress===``)return await xt(this.config,t,e.walletAddress);return await St(t,e.walletAddress,e.tokenAddress)}async getAllBalances(e){const t=!e.provider||`ethereumProvider`in e.provider?e.provider:new L(e.provider);return J(this.config,t,e.walletAddress,e.chainId)}async getNetworkAllowList(e){return await z(this.config,e)}async getTokenAllowList(e){return await G(this.config,e)}async getWalletAllowList(e){return await li(e)}async sendTransaction(e){const t=await X(this.config,e.provider,{allowUnsupportedProvider:true,allowMistmatchedChainId:true});return await $(t,e.transaction)}async providerCall(e,t){const n=await X(this.config,e,{allowUnsupportedProvider:true,allowMistmatchedChainId:true});try{return await t(n)}catch(e){throw Lr(e)}}async getNetworkInfo(e){const t=await X(this.config,e.provider,{allowUnsupportedProvider:true,allowMistmatchedChainId:true});return await B(this.config,t)}async buy(e){if(e.orders.length>1)console.warn(`This endpoint currently only processes the first order in the array.`);const t=await X(this.config,e.provider);return await Qr(this.config,t,e.orders,e.overrides)}async sell(e){if(e.orders.length>1)console.warn(`This endpoint currently only processes the first order in the array.`);const t=await X(this.config,e.provider);return await oi(this.config,t,e.orders)}async cancel(e){console.warn(`This endpoint currently only processes the first order in the array.`);const t=await X(this.config,e.provider);return await ti(this.config,t,e.orderIds,e.overrides)}async smartCheckout(e){const t=await X(this.config,e.provider);let n=[];try{n=await ni(t,e.itemRequirements)}catch(e){throw new O(`Failed to map item requirements`,`ITEM_REQUIREMENTS_ERROR`,{error:e})}return await Nr(this.config,t,n,e.transactionOrGasAmount,e.routingOptions,e.onComplete,e.onFundingRoute,e.fundingRouteFullAmount)}static isWrappedBrowserProvider(e){return $t(e)}async gasEstimate(e){this.readOnlyProviders=await en(this.config,this.readOnlyProviders);return await Ht(e,this.readOnlyProviders,this.config)}async createFiatRampUrl(e){let t;let n=`IMX`;let r;const i=`request`in e.browserProvider?new L(e.browserProvider):e.browserProvider;const a=await(await i.getSigner()).getAddress();const o=i.ethereumProvider?.isPassport||false;if(o&&e.passport)r=(await e.passport.getUserInfo())?.email;const s=await G(this.config,{type:`onramp`});const c=s.tokens?.find(t=>U(t.address,e.tokenAddress));if(c){t=e.tokenAmount;n=c.symbol}const l=s?.tokens?.filter(e=>e.symbol).map(e=>e.symbol);return await this.fiatRampService.createWidgetUrl({exchangeType:e.exchangeType,isPassport:o,walletAddress:a,tokenAmount:t,tokenSymbol:n,email:r,allowedTokens:l,showMenu:e.showMenu,customSubTitle:e.customSubTitle})}async getExchangeFeeEstimate(){return await this.fiatRampService.feeEstimate()}async isSwapAvailable(){return this.availability.checkDexAvailability()}async swap(e){const t=await X(this.config,e.provider);return ci(this.config,t,e.fromToken,e.toToken,e.fromAmount,e.toAmount,e.slippagePercent,e.maxHops,e.deadline)}async swapQuote(e){const t=await X(this.config,e.provider);return si(this.config,t,e.fromToken,e.toToken,e.fromAmount,e.toAmount,e.slippagePercent,e.maxHops,e.deadline)}};var gi=class{static getTransactionLink(e,t){const n=N?.[e]?.url;if(!n||!t)return void 0;return`${n}/tx/${t}`}};export{de as AddTokensEventType,gi as BlockExplorerService,ie as BridgeEventType,Ce as ChainId,we as ChainName,Te as ChainSlug,hi as Checkout,pt as CheckoutConfiguration,O as CheckoutError,Se as CheckoutErrorType,Ge as CheckoutStatus,se as CommerceEventType,le as CommerceFailureEventType,_e as CommerceFlowType,ce as CommerceSuccessEventType,ue as CommerceUserActionEventType,E as ConnectEventType,he as ConnectTargetLayer,Qe as ExchangeType,Xe as FeeType,Ze as FundingStepType,Re as GasEstimateType,Je as GasTokenType,M as IMMUTABLE_API_BASE_URL,w as IMTBLWidgetEvents,Ke as ItemType,ze as NetworkFilterTypes,oe as OnRampEventType,ae as OrchestrationEventType,T as ProviderEventType,fe as PurchaseEventType,Ye as RoutingOutcomeType,ne as SaleEventType,re as SalePaymentTypes,ge as SwapDirection,te as SwapEventType,Be as TokenFilterTypes,qe as TransactionOrGasType,pe as TransferEventType,D as WalletEventType,Ve as WalletFilterTypes,He as WalletProviderName,Ue as WalletProviderRdns,ve as WidgetTheme,me as WidgetType,L as WrappedBrowserProvider,ui as fetchRiskAssessment,Wt as getGasPriceInWei,Xt as getMetaMaskProviderDetail,Yt as getPassportProviderDetail,R as getUnderlyingChainId,di as isAddressSanctioned,fi as isSingleAddressSanctioned,qt as metaMaskProviderInfo,Jt as passportProviderInfo,pi as resultHasSanctionedWallets,X as validateProvider};
1
+ import{Environment as e,ImmutableConfiguration as t}from"@imtbl/config";import n,{HttpStatusCode as r}from"axios";import{BrowserProvider as i,Contract as a,JsonRpcProvider as o,formatUnits as s,parseUnits as c}from"ethers";import{BridgeConfiguration as l,BridgeFeeActions as u,ETH_MAINNET_TO_ZKEVM_MAINNET as d,ETH_SEPOLIA_TO_ZKEVM_DEVNET as f,ETH_SEPOLIA_TO_ZKEVM_TESTNET as p,TokenBridge as m}from"@imtbl/bridge-sdk";import{Exchange as h}from"@imtbl/dex-sdk";import{ActionType as g,OrderStatusName as _,Orderbook as v,SignablePurpose as y,TransactionPurpose as b,constants as x}from"@imtbl/orderbook";import{BlockchainData as S}from"@imtbl/blockchain-data";import C from"@metamask/detect-provider";import{track as ee}from"@imtbl/metrics";let w=function(e){e[`IMTBL_WIDGETS_PROVIDER`]=`imtbl-widgets-provider`;e[`IMTBL_CONNECT_WIDGET_EVENT`]=`imtbl-connect-widget`;e[`IMTBL_WALLET_WIDGET_EVENT`]=`imtbl-wallet-widget`;e[`IMTBL_SWAP_WIDGET_EVENT`]=`imtbl-swap-widget`;e[`IMTBL_BRIDGE_WIDGET_EVENT`]=`imtbl-bridge-widget`;e[`IMTBL_ONRAMP_WIDGET_EVENT`]=`imtbl-onramp-widget`;e[`IMTBL_SALE_WIDGET_EVENT`]=`imtbl-sale-widget`;e[`IMTBL_COMMERCE_WIDGET_EVENT`]=`imtbl-commerce-widget`;e[`IMTBL_ADD_TOKENS_WIDGET_EVENT`]=`imtbl-add-tokens-widget`;e[`IMTBL_PURCHASE_WIDGET_EVENT`]=`imtbl-purchase-widget`;e[`IMTBL_TRANSFER_WIDGET_EVENT`]=`imtbl-transfer-widget`;return e}({});let T=function(e){e[`PROVIDER_UPDATED`]=`PROVIDER_UPDATED`;return e}({});let E=function(e){e[`CLOSE_WIDGET`]=`close-widget`;e[`SUCCESS`]=`success`;e[`FAILURE`]=`failure`;e[`LANGUAGE_CHANGED`]=`language-changed`;e[`WALLETCONNECT_PROVIDER_UPDATED`]=`walletconnect-provider-updated`;return e}({});let D=function(e){e[`CLOSE_WIDGET`]=`close-widget`;e[`NETWORK_SWITCH`]=`network-switch`;e[`DISCONNECT_WALLET`]=`disconnect-wallet`;e[`LANGUAGE_CHANGED`]=`language-changed`;return e}({});let te=function(e){e[`CLOSE_WIDGET`]=`close-widget`;e[`SUCCESS`]=`success`;e[`FAILURE`]=`failure`;e[`REJECTED`]=`rejected`;e[`LANGUAGE_CHANGED`]=`language-changed`;return e}({});let ne=function(e){e[`CLOSE_WIDGET`]=`close-widget`;e[`SUCCESS`]=`success`;e[`FAILURE`]=`failure`;e[`REJECTED`]=`rejected`;e[`TRANSACTION_SUCCESS`]=`transaction-success`;e[`LANGUAGE_CHANGED`]=`language-changed`;e[`PAYMENT_METHOD`]=`payment-method`;e[`REQUEST_BRIDGE`]=`request-bridge`;e[`REQUEST_ONRAMP`]=`request-onramp`;e[`REQUEST_SWAP`]=`request-swap`;e[`PAYMENT_TOKEN`]=`payment-token`;return e}({});let re=function(e){e[`CRYPTO`]=`crypto`;e[`DEBIT`]=`debit`;e[`CREDIT`]=`credit`;return e}({});let ie=function(e){e[`CLOSE_WIDGET`]=`close-widget`;e[`FAILURE`]=`failure`;e[`TRANSACTION_SENT`]=`transaction-sent`;e[`LANGUAGE_CHANGED`]=`language-changed`;e[`CLAIM_WITHDRAWAL_SUCCESS`]=`claim-withdrawal-success`;e[`CLAIM_WITHDRAWAL_FAILURE`]=`claim-withdrawal-failure`;return e}({});let ae=function(e){e[`REQUEST_CONNECT`]=`request-connect`;e[`REQUEST_WALLET`]=`request-wallet`;e[`REQUEST_SWAP`]=`request-swap`;e[`REQUEST_BRIDGE`]=`request-bridge`;e[`REQUEST_ONRAMP`]=`request-onramp`;e[`REQUEST_ADD_TOKENS`]=`request-add-tokens`;e[`REQUEST_PURCHASE`]=`request-purchase`;e[`REQUEST_GO_BACK`]=`request-go-back`;return e}({});let oe=function(e){e[`CLOSE_WIDGET`]=`close-widget`;e[`SUCCESS`]=`success`;e[`FAILURE`]=`failure`;e[`LANGUAGE_CHANGED`]=`language-changed`;return e}({});let se=function(e){e[`INITIALISED`]=`INITIALISED`;e[`PROVIDER_UPDATED`]=`PROVIDER_UPDATED`;e[`CLOSE`]=`CLOSE`;e[`SUCCESS`]=`SUCCESS`;e[`FAILURE`]=`FAILURE`;e[`DISCONNECTED`]=`DISCONNECTED`;e[`USER_ACTION`]=`USER_ACTION`;return e}({});let ce=function(e){e[`SWAP_SUCCESS`]=`SWAP_SUCCESS`;e[`ONRAMP_SUCCESS`]=`ONRAMP_SUCCESS`;e[`CONNECT_SUCCESS`]=`CONNECT_SUCCESS`;e[`SALE_SUCCESS`]=`SALE_SUCCESS`;e[`SALE_TRANSACTION_SUCCESS`]=`SALE_TRANSACTION_SUCCESS`;e[`BRIDGE_SUCCESS`]=`BRIDGE_SUCCESS`;e[`BRIDGE_CLAIM_WITHDRAWAL_SUCCESS`]=`BRIDGE_CLAIM_WITHDRAWAL_SUCCESS`;e[`ADD_TOKENS_SUCCESS`]=`ADD_TOKENS_SUCCESS`;e[`ADD_TOKENS_CONNECT_SUCCESS`]=`ADD_TOKENS_CONNECT_SUCCESS`;e[`TRANSFER_SUCCESS`]=`TRANSFER_SUCCESS`;return e}({});let le=function(e){e[`BRIDGE_FAILED`]=`BRIDGE_FAILED`;e[`BRIDGE_CLAIM_WITHDRAWAL_FAILED`]=`BRIDGE_CLAIM_WITHDRAWAL_FAILED`;e[`SWAP_FAILED`]=`SWAP_FAILED`;e[`SWAP_REJECTED`]=`SWAP_REJECTED`;e[`CONNECT_FAILED`]=`CONNECT_FAILED`;e[`SALE_FAILED`]=`SALE_FAILED`;e[`ONRAMP_FAILED`]=`ONRAMP_FAILED`;e[`ADD_TOKENS_FAILED`]=`ADD_TOKENS_FAILED`;e[`TRANSFER_FAILED`]=`TRANSFER_FAILED`;return e}({});let ue=function(e){e[`PAYMENT_METHOD_SELECTED`]=`PAYMENT_METHOD_SELECTED`;e[`PAYMENT_TOKEN_SELECTED`]=`PAYMENT_TOKEN_SELECTED`;e[`NETWORK_SWITCH`]=`NETWORK_SWITCH`;return e}({});let de=function(e){e[`CLOSE_WIDGET`]=`close-widget`;e[`LANGUAGE_CHANGED`]=`language-changed`;e[`CONNECT_SUCCESS`]=`connect-success`;e[`SUCCESS`]=`success`;e[`FAILURE`]=`failure`;return e}({});let fe=function(e){e[`CLOSE_WIDGET`]=`close-widget`;e[`CONNECT_SUCCESS`]=`connect-success`;e[`SUCCESS`]=`success`;e[`FAILURE`]=`failure`;return e}({});let pe=function(e){e[`CLOSE_WIDGET`]=`close-widget`;e[`REJECTED`]=`rejected`;e[`SUCCESS`]=`success`;e[`FAILURE`]=`failure`;return e}({});let me=function(e){e[`CONNECT`]=`connect`;e[`WALLET`]=`wallet`;e[`SWAP`]=`swap`;e[`BRIDGE`]=`bridge`;e[`ONRAMP`]=`onramp`;e[`SALE`]=`sale`;e[`IMMUTABLE_COMMERCE`]=`immutableCommerce`;e[`ADD_TOKENS`]=`addTokens`;e[`PURCHASE`]=`purchase`;e[`TRANSFER`]=`transfer`;return e}({});let he=function(e){e[`LAYER1`]=`LAYER1`;e[`LAYER2`]=`LAYER2`;return e}({});let ge=function(e){e[`FROM`]=`FROM`;e[`TO`]=`TO`;return e}({});let _e=function(e){e[`CONNECT`]=`CONNECT`;e[`WALLET`]=`WALLET`;e[`SALE`]=`SALE`;e[`SWAP`]=`SWAP`;e[`BRIDGE`]=`BRIDGE`;e[`ONRAMP`]=`ONRAMP`;e[`ADD_TOKENS`]=`ADD_TOKENS`;e[`PURCHASE`]=`PURCHASE`;e[`TRANSFER`]=`TRANSFER`;return e}({});let ve=function(e){e[`LIGHT`]=`light`;e[`DARK`]=`dark`;return e}({});const ye=`pk_imapik-`;const be=[`https://checkout-api.dev.immutable.com`,`https://checkout-api.sandbox.immutable.com`,`https://checkout-api.immutable.com`];var xe=class{config;axiosInstance;constructor(e){this.config=e;this.axiosInstance=n.create();this.setupInterceptors()}shouldAddPublishableKey(e){return be.some(t=>e.startsWith(t))}setupInterceptors(){this.axiosInstance.interceptors.request.use(e=>{const t=this.config?.baseConfig?.publishableKey;if(t&&this.shouldAddPublishableKey(e.url||``)){if(!t.startsWith(ye))throw new Error(`Invalid Publishable key. Create your Publishable key in Immutable developer hub. https://hub.immutable.com`);e.headers[`x-immutable-publishable-key`]=t}return e},e=>Promise.reject(e))}async request(e){return await this.axiosInstance.request(e)}async get(e,t){const n={...t,url:e};return await this.request(n)}async post(e,t,n){const r={...n,data:t,url:e};return await this.request(r)}async put(e,t,n){const r={...n,data:t,url:e};return await this.request(r)}async delete(e,t,n){const r={...n,data:t,url:e};return await this.request(r)}};let Se=function(e){e[`MISSING_PARAMS`]=`MISSING_PARAMS`;e[`WEB3_PROVIDER_ERROR`]=`WEB3_PROVIDER_ERROR`;e[`PROVIDER_ERROR`]=`PROVIDER_ERROR`;e[`DEFAULT_PROVIDER_ERROR`]=`DEFAULT_PROVIDER_ERROR`;e[`CONNECT_PROVIDER_ERROR`]=`CONNECT_PROVIDER_ERROR`;e[`GET_BALANCE_ERROR`]=`GET_BALANCE_ERROR`;e[`GET_INDEXER_BALANCE_ERROR`]=`GET_INDEXER_BALANCE_ERROR`;e[`GET_ERC20_INFO_ERROR`]=`GET_ERC20_INFO_ERROR`;e[`GET_ERC20_BALANCE_ERROR`]=`GET_ERC20_BALANCE_ERROR`;e[`GET_ERC721_BALANCE_ERROR`]=`GET_ERC721_BALANCE_ERROR`;e[`GET_NETWORK_INFO_ERROR`]=`GET_NETWORK_INFO_ERROR`;e[`METAMASK_PROVIDER_ERROR`]=`METAMASK_PROVIDER_ERROR`;e[`CHAIN_NOT_SUPPORTED_ERROR`]=`CHAIN_NOT_SUPPORTED_ERROR`;e[`PROVIDER_REQUEST_MISSING_ERROR`]=`PROVIDER_REQUEST_MISSING_ERROR`;e[`PROVIDER_REQUEST_FAILED_ERROR`]=`PROVIDER_REQUEST_FAILED_ERROR`;e[`USER_REJECTED_REQUEST_ERROR`]=`USER_REJECTED_REQUEST_ERROR`;e[`TRANSACTION_FAILED`]=`TRANSACTION_FAILED`;e[`INSUFFICIENT_FUNDS`]=`INSUFFICIENT_FUNDS`;e[`UNPREDICTABLE_GAS_LIMIT`]=`UNPREDICTABLE_GAS_LIMIT`;e[`INVALID_GAS_ESTIMATE_TYPE`]=`INVALID_GAS_ESTIMATE_TYPE`;e[`UNSUPPORTED_TOKEN_TYPE_ERROR`]=`UNSUPPORTED_TOKEN_TYPE_ERROR`;e[`UNSUPPORTED_BALANCE_REQUIREMENT_ERROR`]=`UNSUPPORTED_BALANCE_REQUIREMENT_ERROR`;e[`GET_ORDER_LISTING_ERROR`]=`GET_ORDER_LISTING_ERROR`;e[`CANCEL_ORDER_LISTING_ERROR`]=`CANCEL_ORDER_LISTING_ERROR`;e[`PREPARE_ORDER_LISTING_ERROR`]=`PREPARE_ORDER_LISTING_ERROR`;e[`CREATE_ORDER_LISTING_ERROR`]=`CREATE_ORDER_LISTING_ERROR`;e[`FULFILL_ORDER_LISTING_ERROR`]=`FULFILL_ORDER_LISTING_ERROR`;e[`SWITCH_NETWORK_UNSUPPORTED`]=`SWITCH_NETWORK_UNSUPPORTED`;e[`GET_ERC20_ALLOWANCE_ERROR`]=`GET_ERC20_ALLOWANCE_ERROR`;e[`GET_ERC721_ALLOWANCE_ERROR`]=`GET_ERC721_ALLOWANCE_ERROR`;e[`GET_ERC1155_ALLOWANCE_ERROR`]=`GET_ERC1155_ALLOWANCE_ERROR`;e[`EXECUTE_APPROVAL_TRANSACTION_ERROR`]=`EXECUTE_APPROVAL_TRANSACTION_ERROR`;e[`EXECUTE_FULFILLMENT_TRANSACTION_ERROR`]=`EXECUTE_FULFILLMENT_TRANSACTION_ERROR`;e[`SIGN_MESSAGE_ERROR`]=`SIGN_MESSAGE_ERROR`;e[`BRIDGE_GAS_ESTIMATE_ERROR`]=`BRIDGE_GAS_ESTIMATE_ERROR`;e[`ORDER_FEE_ERROR`]=`ORDER_FEE_ERROR`;e[`ITEM_REQUIREMENTS_ERROR`]=`ITEM_REQUIREMENTS_ERROR`;e[`API_ERROR`]=`API_ERROR`;e[`ORDER_EXPIRED_ERROR`]=`ORDER_EXPIRED_ERROR`;e[`WIDGETS_SCRIPT_LOAD_ERROR`]=`WIDGETS_SCRIPT_LOAD_ERROR`;e[`APPROVAL_TRANSACTION_FAILED`]=`APPROVAL_TRANSACTION_FAILED`;return e}({});var O=class extends Error{message;type;data;constructor(e,t,n){super(e);this.message=e;this.type=t;this.data=n}};const k=async(e,t)=>{try{return await e()}catch(e){const n=e?.error?.message??(e.message||`UnknownError`);const r=t.message?`[${t.type}]:${t.message}. Cause:${n}`:`[${t.type}] Cause:${n}`;if(e instanceof O)throw new O(r,t.type,{...t.data,innerErrorType:e.type,...e.data});throw new O(r,t.type,{...t.data})}};let Ce=function(e){e[e[`IMTBL_ZKEVM_MAINNET`]=13371]=`IMTBL_ZKEVM_MAINNET`;e[e[`IMTBL_ZKEVM_TESTNET`]=13473]=`IMTBL_ZKEVM_TESTNET`;e[e[`IMTBL_ZKEVM_DEVNET`]=15003]=`IMTBL_ZKEVM_DEVNET`;e[e[`ETHEREUM`]=1]=`ETHEREUM`;e[e[`SEPOLIA`]=11155111]=`SEPOLIA`;return e}({});let we=function(e){e[`ETHEREUM`]=`Ethereum`;e[`SEPOLIA`]=`Sepolia`;e[`IMTBL_ZKEVM_TESTNET`]=`Immutable zkEVM Testnet`;e[`IMTBL_ZKEVM_DEVNET`]=`Immutable zkEVM Dev`;e[`IMTBL_ZKEVM_MAINNET`]=`Immutable zkEVM`;return e}({});let Te=function(e){e[`ETHEREUM`]=`ethereum`;e[`SEPOLIA`]=`sepolia`;e[`IMTBL_ZKEVM_MAINNET`]=`imtbl-zkevm-mainnet`;e[`IMTBL_ZKEVM_TESTNET`]=`imtbl-zkevm-testnet`;e[`IMTBL_ZKEVM_DEVNET`]=`imtbl-zkevm-devnet`;return e}({});const A=`development`;const Ee=18;const j=`native`;const De={name:`IMX`,symbol:`IMX`,decimals:18,address:j};const Oe={name:`tIMX`,symbol:`tIMX`,decimals:18,address:j};const M={[A]:`https://api.dev.immutable.com`,[e.SANDBOX]:`https://api.sandbox.immutable.com`,[e.PRODUCTION]:`https://api.immutable.com`};const ke={[A]:`https://checkout-api.dev.immutable.com`,[e.SANDBOX]:`https://checkout-api.sandbox.immutable.com`,[e.PRODUCTION]:`https://checkout-api.immutable.com`};const Ae={[e.SANDBOX]:`https://global-stg.transak.com`,[e.PRODUCTION]:`https://global.transak.com/`};const je=new Map([[1,{chainIdHex:`0x${1 .toString(16)}`,chainName:`Ethereum`,rpcUrls:[`https://checkout-api.immutable.com/v1/rpc/eth-mainnet`],nativeCurrency:{name:`Ethereum`,symbol:`ETH`,decimals:18},blockExplorerUrls:[`https://etherscan.io/`]}],[13371,{chainIdHex:`0x${13371 .toString(16)}`,chainName:`Immutable zkEVM`,rpcUrls:[`https://rpc.immutable.com`],nativeCurrency:De}]]);const Me=new Map([[11155111,{chainIdHex:`0x${11155111 .toString(16)}`,chainName:`Sepolia`,rpcUrls:[`https://checkout-api.sandbox.immutable.com/v1/rpc/eth-sepolia`],nativeCurrency:{name:`Sep Eth`,symbol:`ETH`,decimals:18},blockExplorerUrls:[`https://sepolia.etherscan.io/`]}],[13473,{chainIdHex:`0x${13473 .toString(16)}`,chainName:`Immutable zkEVM Testnet`,rpcUrls:[`https://rpc.testnet.immutable.com`],nativeCurrency:Oe}]]);const Ne=new Map([[11155111,{chainIdHex:`0x${11155111 .toString(16)}`,chainName:`Sepolia`,rpcUrls:[`https://checkout-api.dev.immutable.com/v1/rpc/eth-sepolia`],nativeCurrency:{name:`Sep Eth`,symbol:`ETH`,decimals:18},blockExplorerUrls:[`https://sepolia.etherscan.io/`]}],[15003,{chainIdHex:`0x${15003 .toString(16)}`,chainName:`Immutable zkEVM Dev`,rpcUrls:[`https://rpc.dev.immutable.com`],nativeCurrency:De}]]);const N={[13473]:{url:`https://explorer.testnet.immutable.com`,nativeToken:Me.get(13473).nativeCurrency},[13371]:{url:`https://explorer.immutable.com`,nativeToken:je.get(13371).nativeCurrency},[11155111]:{url:`https://eth-sepolia.blockscout.com`,nativeToken:Me.get(11155111).nativeCurrency},[1]:{url:`https://eth.blockscout.com/`,nativeToken:je.get(1).nativeCurrency}};const P=[{constant:true,inputs:[],name:`name`,outputs:[{name:``,type:`string`}],payable:false,type:`function`},{constant:true,inputs:[],name:`decimals`,outputs:[{name:``,type:`uint8`}],payable:false,type:`function`},{constant:true,inputs:[{name:`_owner`,type:`address`}],name:`balanceOf`,outputs:[{name:`balance`,type:`uint256`}],payable:false,type:`function`},{constant:true,inputs:[],name:`symbol`,outputs:[{name:``,type:`string`}],payable:false,type:`function`},{constant:true,inputs:[{name:`_owner`,type:`address`},{name:`_spender`,type:`address`}],name:`allowance`,outputs:[{name:``,type:`uint256`}],payable:false,stateMutability:`view`,type:`function`},{constant:false,inputs:[{name:`_spender`,type:`address`},{name:`_value`,type:`uint256`}],name:`approve`,outputs:[{name:``,type:`bool`}],payable:false,stateMutability:`nonpayable`,type:`function`}];const F=[{constant:false,inputs:[{internalType:`address`,name:`to`,type:`address`},{internalType:`uint256`,name:`tokenId`,type:`uint256`}],name:`approve`,outputs:[],payable:false,stateMutability:`nonpayable`,type:`function`},{constant:true,inputs:[{internalType:`address`,name:`owner`,type:`address`},{internalType:`address`,name:`operator`,type:`address`}],name:`isApprovedForAll`,outputs:[{internalType:`bool`,name:``,type:`bool`}],payable:false,stateMutability:`view`,type:`function`},{constant:true,inputs:[{internalType:`uint256`,name:`tokenId`,type:`uint256`}],name:`getApproved`,outputs:[{internalType:`address`,name:``,type:`address`}],payable:false,stateMutability:`view`,type:`function`},{inputs:[{internalType:`uint256`,name:`tokenId`,type:`uint256`}],name:`ownerOf`,outputs:[{internalType:`address`,name:``,type:`address`}],stateMutability:`view`,type:`function`}];const Pe=[{inputs:[{internalType:`address`,name:`account`,type:`address`},{internalType:`address`,name:`operator`,type:`address`}],name:`isApprovedForAll`,outputs:[{internalType:`bool`,name:``,type:`bool`}],stateMutability:`view`,type:`function`},{inputs:[{internalType:`address`,name:`operator`,type:`address`},{internalType:`bool`,name:`approved`,type:`bool`}],name:`setApprovalForAll`,outputs:[],stateMutability:`nonpayable`,type:`function`},{inputs:[{internalType:`address`,name:`account`,type:`address`},{internalType:`uint256`,name:`id`,type:`uint256`}],name:`balanceOf`,outputs:[{internalType:`uint256`,name:``,type:`uint256`}],stateMutability:`view`,type:`function`}];const Fe={maxFeePerGas:BigInt(15e9),maxPriorityFeePerGas:BigInt(1e10)};const Ie=`2.24.1-0`;const I=()=>Ie;const Le=(t,r)=>{const i=()=>{if(t)return M[A];if(r)return M[e.PRODUCTION];return M[e.SANDBOX]};const a=async()=>{let e;try{e=await n.post(`${i()}/v1/availability/checkout/swap`)}catch(t){e=t.response;if(e.status===403)return false;throw new O(`Error fetching from api: ${e.status} ${e.statusText}`,`API_ERROR`,{error:t})}return true};return{checkDexAvailability:a}};let Re=function(e){e[`BRIDGE_TO_L2`]=`BRIDGE_TO_L2`;e[`SWAP`]=`SWAP`;return e}({});let ze=function(e){e[`ALL`]=`all`;return e}({});let Be=function(e){e[`ALL`]=`all`;e[`SWAP`]=`swap`;e[`BRIDGE`]=`bridge`;e[`ONRAMP`]=`onramp`;return e}({});let Ve=function(e){e[`ALL`]=`all`;return e}({});let He=function(e){e[`PASSPORT`]=`passport`;e[`METAMASK`]=`metamask`;e[`WALLETCONNECT`]=`walletconnect`;return e}({});let Ue=function(e){e[`PASSPORT`]=`com.immutable.passport`;e[`METAMASK`]=`io.metamask`;e[`WALLETCONNECT`]=`walletconnect`;return e}({});const We={allowMistmatchedChainId:false,allowUnsupportedProvider:false};var L=class extends i{ethereumProvider;constructor(e,t,n){super(e,t,n);this.#e(e)}#e(e){if(!(`request`in e)||typeof e.request!==`function`)return;this.ethereumProvider=e}};let Ge=function(e){e[`SUCCESS`]=`SUCCESS`;e[`FAILED`]=`FAILED`;e[`INSUFFICIENT_FUNDS`]=`INSUFFICIENT_FUNDS`;e[`FULFILLMENTS_UNSETTLED`]=`FULFILLMENTS_UNSETTLED`;return e}({});let Ke=function(e){e[`NATIVE`]=`NATIVE`;e[`ERC20`]=`ERC20`;e[`ERC721`]=`ERC721`;e[`ERC1155`]=`ERC1155`;return e}({});let qe=function(e){e[`TRANSACTION`]=`TRANSACTION`;e[`GAS`]=`GAS`;return e}({});let Je=function(e){e[`NATIVE`]=`NATIVE`;e[`ERC20`]=`ERC20`;return e}({});let Ye=function(e){e[`ROUTES_FOUND`]=`ROUTES_FOUND`;e[`NO_ROUTES_FOUND`]=`NO_ROUTES_FOUND`;e[`NO_ROUTE_OPTIONS`]=`NO_ROUTE_OPTIONS`;return e}({});let Xe=function(e){e[`GAS`]=`GAS`;e[`BRIDGE_FEE`]=`BRIDGE_FEE`;e[`SWAP_FEE`]=`SWAP_FEE`;e[`IMMUTABLE_FEE`]=`IMMUTABLE_FEE`;return e}({});let Ze=function(e){e[`BRIDGE`]=`BRIDGE`;e[`SWAP`]=`SWAP`;e[`ONRAMP`]=`ONRAMP`;return e}({});let Qe=function(e){e[`ONRAMP`]=`onramp`;return e}({});async function $e(e){if(!e.send)throw new O(`Parsed provider is not a valid WrappedBrowserProvider`,`WEB3_PROVIDER_ERROR`);const t=await e.send(`eth_chainId`,[]);if(typeof t!==`bigint`)throw new O(`Invalid chainId`,`WEB3_PROVIDER_ERROR`);return t}async function R(e){const t=await e.getNetwork();if(t.chainId&&typeof t.chainId===`bigint`)return t.chainId;return $e(e)}const et=4902;async function tt(e,t,n){return await t.send(`wallet_switchEthereumChain`,[{chainId:e.get(n)?.chainIdHex}])}async function nt(e,t,n){if(t.send){const r=e.get(n);const i={chainId:r?.chainIdHex,chainName:r?.chainName,rpcUrls:r?.rpcUrls,nativeCurrency:r?.nativeCurrency,blockExplorerUrls:r?.blockExplorerUrls};return await t.send(`wallet_addEthereumChain`,[i])}return Promise.reject(`Provider does not support request method`)}async function z(e,{type:t=`all`,exclude:n}){const{networkMap:r}=e;const i=await e.remote.getConfig(`allowedNetworks`);if(!i)console.warn(`No allowed networks configured`);const a=(i||[]).filter(e=>{const r=t===`all`;const i=!(n||[]).map(e=>e.chainId).includes(e.chainId);return r&&i});const o=[];a.forEach(e=>{const t=r.get(e.chainId);if(t)o.push({name:t.chainName,chainId:parseInt(t.chainIdHex,16),nativeCurrency:t.nativeCurrency,isSupported:true})});return{networks:o}}async function B(e,t){const{networkMap:n}=e;return k(async()=>{try{const e=await t.getNetwork();if(Array.from(n.keys()).includes(Number(e.chainId))){const t=n.get(Number(e.chainId));return{name:t.chainName,chainId:parseInt(t.chainIdHex,16),nativeCurrency:t.nativeCurrency,isSupported:true}}return{chainId:Number(e.chainId),name:e.name,isSupported:false}}catch(e){const r=await R(t);const i=Array.from(n.keys()).includes(Number(r));return{chainId:Number(r),isSupported:i}}},{type:`GET_NETWORK_INFO_ERROR`})}const rt=e=>e.error?.data?.originalError?.code===et||e.error?.code===et;async function it(e,t,n){const{networkMap:r}=e;if(!(await z(e,{type:`all`})).networks.some(e=>e.chainId===n))throw new O(`Chain:${n} is not a supported chain`,`CHAIN_NOT_SUPPORTED_ERROR`);if(t.ethereumProvider?.isPassport)throw new O(`Switching networks with Passport provider is not supported`,`SWITCH_NETWORK_UNSUPPORTED`);try{await tt(r,t,n)}catch(e){console.error(e);if(rt(e))try{await nt(r,t,n)}catch(e){throw new O(`User cancelled add network request`,`USER_REJECTED_REQUEST_ERROR`,{error:e})}else throw new O(`User cancelled switch network request`,`USER_REJECTED_REQUEST_ERROR`)}const i=new L(t.ethereumProvider);const a=await i.getNetwork();if(Number(a.chainId)!==n)throw new O(`User cancelled switch network request`,`USER_REJECTED_REQUEST_ERROR`);return{network:await B(e,i),provider:i}}var at=class{httpClient;endpoint;configCache;version=`v1`;constructor(e,t){this.endpoint=t.remoteConfigEndpoint;this.httpClient=e}parseResponse(e){let t=e.data;if(e.data&&typeof e.data!==`object`)try{t=JSON.parse(e.data)}catch(e){throw new O(`Invalid configuration`,`API_ERROR`,{error:e})}return t}async loadConfig(){if(this.configCache)return this.configCache;let e;try{e=await this.httpClient.get(`${this.endpoint}/${this.version}/config`)}catch(e){throw new O(`Error: ${e.message}`,`API_ERROR`,{error:e})}this.configCache=this.parseResponse(e);return this.configCache}async getConfig(e){const t=await this.loadConfig();if(!t)return void 0;if(!e)return t;return t[e]}getHttpClient=()=>this.httpClient};const ot=`0x0000000000000000000000000000000000000eee`;var st=class{httpClient;remoteConfig;baseUrl;chainSlug;tokensCache;constructor(e,t,n){this.baseUrl=n.baseUrl;this.chainSlug=n.chainSlug;this.httpClient=e;this.remoteConfig=t}async loadTokens(){if(this.tokensCache)return this.tokensCache;let e;try{e=await this.httpClient.get(`${this.baseUrl}/v1/chains/${this.chainSlug}/tokens?verification_status=verified&is_canonical=true`)}catch(e){throw new O(`Error: ${e.message}`,`API_ERROR`,{error:e})}const t=this.parseResponse(e);this.tokensCache=await this.getMappingsForTokensResponse(t?.result||[]);return this.tokensCache}async getChainTokensConfig(){return await this.loadTokens()??{}}async getTokensConfig(e){const t=await this.loadTokens();if(!t||!t[e])return[];return t[e]??[]}async getMappingsForTokensResponse(e){const t={};const n=await this.fetchIMXTokenMappings();Object.keys(n).forEach(e=>{const r=parseInt(e,10);t[r]=[];t[r]?.push({address:n[e],decimals:18,name:`IMX`,symbol:`IMX`,bridge:`native`})});e.forEach(e=>{const n=parseInt(e.chain.id.split(`eip155:`).pop()||``,10);if(!e.symbol||!e.decimals)return;if(!t[n])t[n]=[];const r={address:e.contract_address.toLowerCase(),decimals:e.decimals,name:e.name,symbol:e.symbol,icon:e.image_url??void 0,bridge:e.bridge_used??null};t[n]?.push(r);const i=parseInt(e.root_chain_id?.split(`eip155:`).pop()||``,10);let a=e.root_contract_address?.toLowerCase();if(i&&a){if(!t[i])t[i]=[];if(a===ot)a=`native`;t[i]?.push({...r,address:a})}});return t}parseResponse(e){let t=e.data;if(e.data&&typeof e.data!==`object`)try{t=JSON.parse(e.data)}catch(e){throw new O(`Invalid token data`,`API_ERROR`,{error:e})}return t}async fetchIMXTokenMappings(){return await this.remoteConfig.getConfig(`imxAddressMapping`)}};var ct=class extends Error{message;constructor(e){super(e);this.message=e}};const lt=(e,t)=>{if(t)return Ne;if(e)return je;return Me};const ut=(t,n)=>{if(n)return M[A];if(t)return M[e.PRODUCTION];return M[e.SANDBOX]};const dt=(e,t)=>{if(t)return`imtbl-zkevm-devnet`;if(e)return`imtbl-zkevm-mainnet`;return`imtbl-zkevm-testnet`};const V=e=>{if(!e.isProduction)return 11155111;return 1};const H=e=>{if(e.isDevelopment)return 15003;if(e.isProduction)return 13371;return 13473};const ft=(t,n)=>{if(n)return ke[A];if(t)return ke[e.PRODUCTION];return ke[e.SANDBOX]};var pt=class{isDevelopment=false;isProduction;isOnRampEnabled;isSwapEnabled;isBridgeEnabled;remote;tokens;environment;networkMap;publishableKey;l1ChainId;l2ChainId;overrides;constructor(t,n){if(!Object.values(e).includes(t.baseConfig.environment))throw new ct(`Invalid checkout configuration of environment`);this.environment=t.baseConfig.environment;this.isProduction=!this.isDevelopment&&this.environment===e.PRODUCTION;this.isOnRampEnabled=t.onRamp?.enable??true;this.isSwapEnabled=t.swap?.enable??true;this.isBridgeEnabled=t.bridge?.enable??true;this.publishableKey=t.publishableKey??`<no-publishable-key>`;this.networkMap=t.overrides?.networkMap??lt(this.isProduction,this.isDevelopment);const r=t.overrides?.remoteConfigEndpoint??ft(this.isProduction,this.isDevelopment);this.remote=new at(n,{remoteConfigEndpoint:r});this.tokens=new st(n,this.remote,{baseUrl:t.overrides?.baseUrl??ut(this.isProduction,this.isDevelopment),chainSlug:t.overrides?.chainSlug??dt(this.isProduction,this.isDevelopment)});this.l1ChainId=V(this);this.l2ChainId=t.overrides?.l2ChainId??H(this);this.overrides=t.overrides??{}}get sdkVersion(){return I()}};const U=(e=``,t=``)=>e.toLowerCase()===t.toLowerCase();const mt=e=>e===15003||e===13473||e===13371;const ht=(e,t)=>{const n=e.indexOf(`.`);const r=e.substring(n+t+1);if(r&&parseFloat(r)>=1){const r=e.substring(0,n+t+1);const i=1/10**t;return(parseFloat(r)+i).toString()}return parseFloat(e.substring(0,n+t+1)).toString()};const W=(e,t=6)=>{if(e.indexOf(`.`)===-1)return e;return ht(e,t)};const gt=`native`;const G=async(e,{type:t=`all`,chainId:n,exclude:r})=>{let i=[];let a;let o;const s=n??V(e);const c=H(e);switch(t){case`swap`:i=await e.tokens.getTokensConfig(c);o=((await e.remote.getConfig(`dex`))?.blocklist||[]).map(e=>e.address.toLowerCase());i=i.filter(e=>e.address&&!o.includes(e.address));break;case`onramp`:a=await e.remote.getConfig(`onramp`);if(!a)i=[];i=a[`201811419111`]?.tokens||[];break;case`bridge`:i=(await e.tokens.getTokensConfig(s)).filter(e=>e.bridge===gt);break;case`all`:default:i=await e.tokens.getTokensConfig(s)}if(!r||r?.length===0)return{tokens:i};return{tokens:i.filter(e=>!r.map(e=>e.address).includes(e.address||``))}};const K=e=>!e||U(e,`native`);async function _t(e,t){return await k(async()=>{const n=new a(t,JSON.stringify(P),e);const[r,i,o]=await Promise.all([n.name(),n.symbol(),n.decimals()]);return{name:r,symbol:i,decimals:o,address:t}},{type:`GET_ERC20_INFO_ERROR`})}const vt=5;var yt=class{url;nativeToken;ttl;chainId;cacheMap;httpClient;setCache(e,t){this.cacheMap[e]={data:t,ttl:new Date().getTime()+this.ttl*1e3}}getCache(e){const t=this.cacheMap[e];if(!t||t.ttl<=new Date().getTime())return null;return t.data}constructor(e,t,n){this.httpClient=e;this.chainId=t;this.url=N[this.chainId].url;const r=N[this.chainId].nativeToken;this.nativeToken={address:r.address??``,decimals:r.decimals.toString(),name:r.name,symbol:r.symbol};this.cacheMap={};this.ttl=n!==void 0?n:vt}static isChainSupported=e=>Boolean(N[e]);static isBlockscoutError=e=>`code`in e;async getTokensByWalletAddress(e){try{let t=`${this.url}/api/v2/addresses/${e.walletAddress}/tokens?type=${e.tokenType}`;if(e.nextPage)t+=`&${new URLSearchParams(e.nextPage)}`;const n=this.getCache(t);if(n)return Promise.resolve(n);const r=await this.httpClient.get(t);const i={items:(r.data?.items?.map(e=>{const t={...e.token,address:e.token.address_hash,holders:e.token.holders_count};return{...e,token:t}})||[]).filter(e=>e.token.address&&e.token.address!==this.nativeToken.address),next_page_params:r.data?.next_page_params};this.setCache(t,i);return Promise.resolve(i)}catch(e){let t=r.InternalServerError;let i=`InternalServerError`;if(n.isAxiosError(e)){t=e.response?.status||t;i=e.message}return Promise.reject({code:t,message:i})}}async getNativeTokenByWalletAddress(e){try{const t=`${this.url}/api/v2/addresses/${e.walletAddress}`;const n=this.getCache(t);if(n)return Promise.resolve(n);const r=await this.httpClient.get(t);const i={token:this.nativeToken,value:r.data.coin_balance};this.setCache(t,i);return Promise.resolve(i)}catch(e){let t=r.InternalServerError;let i=`InternalServerError`;if(n.isAxiosError(e)){t=e.response?.status||t;i=e.message}return Promise.reject({code:t,message:i})}}};const bt=(e,t,n)=>{if(!e.isProduction)console.info(t,n)};const q=async(e,t,n)=>{const r=performance.now();const i=await n;const a=(performance.now()-r)/1e3;bt(e,t,a);return i};const xt=async(e,t,n)=>await k(async()=>{const r=await B(e,t);if(!r.isSupported)throw new O(`Chain:${r.chainId} is not a supported chain`,`CHAIN_NOT_SUPPORTED_ERROR`,{chainName:r.name});const i=await t.getBalance(n);return{balance:i,formattedBalance:s(i,r.nativeCurrency.decimals),token:r.nativeCurrency}},{type:`GET_BALANCE_ERROR`});async function St(e,t,n){return await k(async()=>{const r=new a(n,JSON.stringify(P),e);return Promise.all([_t(e,n),r.balanceOf(t)]).then(([e,t])=>{return{balance:t,formattedBalance:s(t,e.decimals),token:{name:e.name,symbol:e.symbol,decimals:e.decimals,address:n}}})},{type:`GET_ERC20_BALANCE_ERROR`})}const Ct=new Map;const wt=()=>Ct.clear();const Tt=async(e,t,n,i)=>{const a=i!==void 0;const o=Object.assign({},...(i??[]).map(e=>({[e.address?.toLowerCase()||`native`]:e})));let c=Ct.get(n);if(!c){c=new yt(e.remote.getHttpClient(),n);Ct.set(n,c)}const l=[];const u=`ERC-20`;const d=async e=>{let n;try{do{n=await e.getTokensByWalletAddress({walletAddress:t,tokenType:u,nextPage:n?.next_page_params});l.push(...n.items)}while(n.next_page_params)}catch(e){if(e?.code!==r.NotFound)throw new O(e.message||`InternalServerError | getTokensByWalletAddress`,`GET_INDEXER_BALANCE_ERROR`,{error:e})}};const f=async e=>{try{const n=await e.getNativeTokenByWalletAddress({walletAddress:t});n.token.address||=j;l.push(n)}catch(e){if(e?.code!==r.NotFound)throw new O(e.message||`InternalServerError | getNativeTokenByWalletAddress`,`GET_INDEXER_BALANCE_ERROR`,{error:e})}};await Promise.all([d(c),f(c)]);const p=[];l.forEach(e=>{const t=o[e.token.address.toLowerCase()];if(a&&!t)return;const n=e.token||{};if(e.value==null)return;const r=BigInt(e.value);let i=parseInt(n.decimals,10);if(Number.isNaN(i))i=18;const c=n.icon_url??t.icon;const l={...n,decimals:i,icon:c};const u=s(e.value,l.decimals);p.push({balance:r,formattedBalance:u,token:l})});return{balances:p}};const Et=async(e,t,n,r)=>{const i=[];r.forEach(r=>{if(!r.address||U(r.address,`native`))i.push(xt(e,t,n));else i.push(St(t,n,r.address))});return(await Promise.allSettled(i)).reduce((e,t)=>{if(t.status!==`fulfilled`||t.value.balance===0n)return e;const{value:n}=t;if(!n.token.address||U(n.token.address,`native`))n.token.address=j;e.balances.push(n);return e},{balances:new Array})};const Dt=async(e,t,n,r,i)=>{if(!t)throw new O(`indexer is disabled for this chain, you must provide a provider.`,`MISSING_PARAMS`);let a=n;if(!a)a=await(await t.getSigner()).getAddress();return await q(e,`Time to fetch balances using RPC for ${r}`,Et(e,t,a,i))};const J=async(e,t,n,i,a=false)=>{if(!n&&!t)throw new O(`both walletAddress and provider are missing. At least one must be provided.`,`MISSING_PARAMS`);if(!e.networkMap.get(i))throw new O(`chain ID ${i} not supported by the environment`,`CHAIN_NOT_SUPPORTED_ERROR`);const{tokens:o}=await G(e,{type:`all`,chainId:i});if(a)wt();if(yt.isChainSupported(i)){const a=n??await(await t?.getSigner())?.getAddress();try{return await q(e,`Time to fetch balances using blockscout for ${i}`,Tt(e,a,i,o))}catch(a){if(a.type===`GET_INDEXER_BALANCE_ERROR`&&a.data?.error?.code===r.TooManyRequests)return Dt(e,t,n,i,o);throw a}}return Dt(e,t,n,i,o)};async function Ot(e){if(!e?.send)throw new O(`Check wallet connection request failed`,`PROVIDER_REQUEST_FAILED_ERROR`,{rpcMethod:`eth_accounts`});let t=[];try{t=await e.send(`eth_accounts`,[])}catch(e){throw new O(`Check wallet connection request failed`,`PROVIDER_REQUEST_FAILED_ERROR`,{error:e,rpcMethod:`eth_accounts`})}return{isConnected:t&&t.length>0,walletAddress:t[0]??``}}async function kt(e){if(!e||!e.send)throw new O(`Incompatible provider`,`PROVIDER_REQUEST_MISSING_ERROR`,{details:`Attempting to connect with an incompatible provider`});await k(async()=>{if(!e.send)return;await e.send(`eth_requestAccounts`,[])},{type:`USER_REJECTED_REQUEST_ERROR`});return e}async function At(e){if(!e||!e.send)throw new O(`Incompatible provider`,`PROVIDER_REQUEST_MISSING_ERROR`,{details:`Attempting to connect with an incompatible provider`});await k(async()=>{if(!e.send)return;await e.send(`wallet_requestPermissions`,[{eth_accounts:{}}])},{type:`USER_REJECTED_REQUEST_ERROR`});return e}var jt=class{config;constructor(e){this.config=e}async feeEstimate(){return(await this.config.remote.getConfig(`onramp`))[`201811419111`]?.fees}async createWidgetUrl(e,t=new xe){return await this.getTransakWidgetUrl(e,t)}async getTransakWidgetUrl(e,t){const n=await this.config.remote.getConfig(`onramp`);const r=`${M[this.config.environment]}/checkout/v1/widget-url`;let i={api_key:n[`201811419111`].publishableApiKey,network:`immutablezkevm`,default_payment_method:`credit_debit_card`,disable_payment_methods:``,products_availed:`buy`,exchange_screen_title:e.customSubTitle===``?` `:e.customSubTitle??`Buy`,theme_color:`FFFFFF`,default_crypto_currency:e.tokenSymbol||`IMX`,hide_menu:!(e.showMenu??true),referrer_domain:window.location.origin};if(e.isPassport&&e.email)i={...i,email:e.email,is_auto_fill_user_data:true,disable_wallet_address_form:true};if(e.tokenAmount&&e.tokenSymbol)i={...i,default_crypto_amount:e.tokenAmount,crypto_currency_code:e.tokenSymbol};else i={...i,default_fiat_amount:50,default_fiat_currency:`usd`};if(e.walletAddress)i={...i,wallet_address:e.walletAddress};if(e.allowedTokens)i={...i,crypto_currency_list:e.allowedTokens?.join(`,`).toLowerCase()};return(await t.post(r,i,{method:`POST`})).data.url}};async function Mt(e,t,n,r){const i=t===V(r)?u.DEPOSIT:u.WITHDRAW;return await e.getFee({action:i,gasMultiplier:`auto`,sourceChainId:t.toString(),destinationChainId:n.toString(),token:j.toUpperCase(),amount:BigInt(0)})}function Nt(e,n,r,i){const a=r.get(e);const o=r.get(n);if(!a)throw new O(`Chain:${e} is not a supported chain`,`CHAIN_NOT_SUPPORTED_ERROR`);if(!o)throw new O(`Chain:${n} is not a supported chain`,`CHAIN_NOT_SUPPORTED_ERROR`);let s=p;if(i.isDevelopment)s=f;if(i.isProduction)s=d;return new m(new l({baseConfig:new t({environment:i.environment}),bridgeInstance:s,rootProvider:a,childProvider:o}))}async function Pt(e,n){const r=await n.remote.getConfig(`dex`);return new h({chainId:e,baseConfig:new t({environment:n.environment}),overrides:r?.overrides,secondaryFees:r?.secondaryFees})}function Ft(e){return new v({baseConfig:{environment:e.environment}})}function It(e){return new S({baseConfig:{environment:e.environment}})}function Lt(e,t,n){return new a(e,t,n)}const Rt=`0x0000000000000000000000000000000000000001`;const zt=18;async function Bt(e,t){const n=V(t);const r=H(t);if(!e.get(n))throw new Error(`Missing JsonRpcProvider for chain id: ${n}`);try{const i=await Mt(Nt(n,r,e,t),n,r,t);return{gasEstimateType:`BRIDGE_TO_L2`,fees:i,token:t.networkMap.get(n)?.nativeCurrency}}catch{return{gasEstimateType:`BRIDGE_TO_L2`,fees:{sourceChainGas:BigInt(0),approvalFee:BigInt(0),bridgeFee:BigInt(0),imtblFee:BigInt(0),totalFees:BigInt(0)},token:t.networkMap.get(n)?.nativeCurrency}}}async function Vt(e){const t=H(e);const{inAddress:n,outAddress:r}=(await e.remote.getConfig(`gasEstimateTokens`))[t].swapAddresses;try{const{swap:i}=await(await Pt(t,e)).getUnsignedSwapTxFromAmountIn(Rt,n,r,BigInt(c(`1`,zt)));if(!i.gasFeeEstimate)return{gasEstimateType:`SWAP`,fees:{}};return{gasEstimateType:`SWAP`,fees:{totalFees:i.gasFeeEstimate.value?BigInt(i.gasFeeEstimate.value):void 0,token:{address:i.gasFeeEstimate.token.address,symbol:i.gasFeeEstimate.token.symbol??``,name:i.gasFeeEstimate.token.name??``,decimals:i.gasFeeEstimate.token.decimals??zt}}}}catch{return{gasEstimateType:`SWAP`,fees:{}}}}async function Ht(e,t,n){switch(e.gasEstimateType){case`BRIDGE_TO_L2`:return await Bt(t,n);case`SWAP`:return await Vt(n);default:throw new O(`Invalid type provided for gasEstimateType`,`INVALID_GAS_ESTIMATE_TYPE`)}}const Ut=e=>!!e.maxFeePerGas&&!!e.maxPriorityFeePerGas;const Wt=e=>{if(Ut(e)){const{maxFeePerGas:t,maxPriorityFeePerGas:n}=e;if(t===null||n===null)return null;return n+(t-n)/BigInt(2)}if(e.gasPrice)return e.gasPrice;return null};function Gt(e){if(typeof window===`undefined`)return;const t=t=>e(t.detail);window.addEventListener(`eip6963:announceProvider`,t);window.dispatchEvent(new CustomEvent(`eip6963:requestProvider`));return()=>window.removeEventListener(`eip6963:announceProvider`,t)}function Kt(){const e=new Set;let t=[];const n=()=>Gt(n=>{if(t.some(({info:e})=>e.uuid===n.info.uuid))return;t=[...t,n];e.forEach(e=>e(t,{added:[n]}))});let r=n();return{_listeners(){return e},clear(){e.forEach(e=>e([],{removed:[...t]}));t=[]},destroy(){this.clear();e.clear();r?.()},findProvider({rdns:e}){return t.find(t=>t.info.rdns===e)},getProviders(){return t},reset(){this.clear();r?.();r=n()},subscribe(n,{emitImmediately:r}={}){e.add(n);if(r)n(t,{added:t});return()=>e.delete(n)}}}var Y=class e{static instance;store;resetTimeout;isInit=false;constructor(){this.store=Kt();this.store.reset()}static getInstance(){if(!e.instance)e.instance=new e;return e.instance}findProvider(e){return this.store.findProvider(e)}getProviders(){return this.store.getProviders()}subscribe(e){return this.store.subscribe(e)}clear(){this.store.clear()}reset(){clearTimeout(this.resetTimeout);this.resetTimeout=setTimeout(()=>{this.store.reset()},200)}initialise(){if(!this.isInit){this.isInit=true;this.reset()}}requestProviders(){window.dispatchEvent(new CustomEvent(`eip6963:requestProvider`))}destroy(){this.store.destroy()}};const qt={name:`MetaMask`,rdns:`io.metamask`,icon:`data:image/svg+xml;base64,PHN2ZyBmaWxsPSJub25lIiBoZWlnaHQ9IjMzIiB2aWV3Qm94PSIwIDAgMzUgMzMiIHdpZHRoPSIzNSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj48ZyBzdHJva2UtbGluZWNhcD0icm91bmQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiIHN0cm9rZS13aWR0aD0iLjI1Ij48cGF0aCBkPSJtMzIuOTU4MiAxLTEzLjEzNDEgOS43MTgzIDIuNDQyNC01LjcyNzMxeiIgZmlsbD0iI2UxNzcyNiIgc3Ryb2tlPSIjZTE3NzI2Ii8+PGcgZmlsbD0iI2UyNzYyNSIgc3Ryb2tlPSIjZTI3NjI1Ij48cGF0aCBkPSJtMi42NjI5NiAxIDEzLjAxNzE0IDkuODA5LTIuMzI1NC01LjgxODAyeiIvPjxwYXRoIGQ9Im0yOC4yMjk1IDIzLjUzMzUtMy40OTQ3IDUuMzM4NiA3LjQ4MjkgMi4wNjAzIDIuMTQzNi03LjI4MjN6Ii8+PHBhdGggZD0ibTEuMjcyODEgMjMuNjUwMSAyLjEzMDU1IDcuMjgyMyA3LjQ2OTk0LTIuMDYwMy0zLjQ4MTY2LTUuMzM4NnoiLz48cGF0aCBkPSJtMTAuNDcwNiAxNC41MTQ5LTIuMDc4NiAzLjEzNTggNy40MDUuMzM2OS0uMjQ2OS03Ljk2OXoiLz48cGF0aCBkPSJtMjUuMTUwNSAxNC41MTQ5LTUuMTU3NS00LjU4NzA0LS4xNjg4IDguMDU5NzQgNy40MDQ5LS4zMzY5eiIvPjxwYXRoIGQ9Im0xMC44NzMzIDI4Ljg3MjEgNC40ODE5LTIuMTYzOS0zLjg1ODMtMy4wMDYyeiIvPjxwYXRoIGQ9Im0yMC4yNjU5IDI2LjcwODIgNC40Njg5IDIuMTYzOS0uNjEwNS01LjE3MDF6Ii8+PC9nPjxwYXRoIGQ9Im0yNC43MzQ4IDI4Ljg3MjEtNC40NjktMi4xNjM5LjM2MzggMi45MDI1LS4wMzkgMS4yMzF6IiBmaWxsPSIjZDViZmIyIiBzdHJva2U9IiNkNWJmYjIiLz48cGF0aCBkPSJtMTAuODczMiAyOC44NzIxIDQuMTU3MiAxLjk2OTYtLjAyNi0xLjIzMS4zNTA4LTIuOTAyNXoiIGZpbGw9IiNkNWJmYjIiIHN0cm9rZT0iI2Q1YmZiMiIvPjxwYXRoIGQ9Im0xNS4xMDg0IDIxLjc4NDItMy43MTU1LTEuMDg4NCAyLjYyNDMtMS4yMDUxeiIgZmlsbD0iIzIzMzQ0NyIgc3Ryb2tlPSIjMjMzNDQ3Ii8+PHBhdGggZD0ibTIwLjUxMjYgMjEuNzg0MiAxLjA5MTMtMi4yOTM1IDIuNjM3MiAxLjIwNTF6IiBmaWxsPSIjMjMzNDQ3IiBzdHJva2U9IiMyMzM0NDciLz48cGF0aCBkPSJtMTAuODczMyAyOC44NzIxLjY0OTUtNS4zMzg2LTQuMTMxMTcuMTE2N3oiIGZpbGw9IiNjYzYyMjgiIHN0cm9rZT0iI2NjNjIyOCIvPjxwYXRoIGQ9Im0yNC4wOTgyIDIzLjUzMzUuNjM2NiA1LjMzODYgMy40OTQ2LTUuMjIxOXoiIGZpbGw9IiNjYzYyMjgiIHN0cm9rZT0iI2NjNjIyOCIvPjxwYXRoIGQ9Im0yNy4yMjkxIDE3LjY1MDctNy40MDUuMzM2OS42ODg1IDMuNzk2NiAxLjA5MTMtMi4yOTM1IDIuNjM3MiAxLjIwNTF6IiBmaWxsPSIjY2M2MjI4IiBzdHJva2U9IiNjYzYyMjgiLz48cGF0aCBkPSJtMTEuMzkyOSAyMC42OTU4IDIuNjI0Mi0xLjIwNTEgMS4wOTEzIDIuMjkzNS42ODg1LTMuNzk2Ni03LjQwNDk1LS4zMzY5eiIgZmlsbD0iI2NjNjIyOCIgc3Ryb2tlPSIjY2M2MjI4Ii8+PHBhdGggZD0ibTguMzkyIDE3LjY1MDcgMy4xMDQ5IDYuMDUxMy0uMTAzOS0zLjAwNjJ6IiBmaWxsPSIjZTI3NTI1IiBzdHJva2U9IiNlMjc1MjUiLz48cGF0aCBkPSJtMjQuMjQxMiAyMC42OTU4LS4xMTY5IDMuMDA2MiAzLjEwNDktNi4wNTEzeiIgZmlsbD0iI2UyNzUyNSIgc3Ryb2tlPSIjZTI3NTI1Ii8+PHBhdGggZD0ibTE1Ljc5NyAxNy45ODc2LS42ODg2IDMuNzk2Ny44NzA0IDQuNDgzMy4xOTQ5LTUuOTA4N3oiIGZpbGw9IiNlMjc1MjUiIHN0cm9rZT0iI2UyNzUyNSIvPjxwYXRoIGQ9Im0xOS44MjQyIDE3Ljk4NzYtLjM2MzggMi4zNTg0LjE4MTkgNS45MjE2Ljg3MDQtNC40ODMzeiIgZmlsbD0iI2UyNzUyNSIgc3Ryb2tlPSIjZTI3NTI1Ii8+PHBhdGggZD0ibTIwLjUxMjcgMjEuNzg0Mi0uODcwNCA0LjQ4MzQuNjIzNi40NDA2IDMuODU4NC0zLjAwNjIuMTE2OS0zLjAwNjJ6IiBmaWxsPSIjZjU4NDFmIiBzdHJva2U9IiNmNTg0MWYiLz48cGF0aCBkPSJtMTEuMzkyOSAyMC42OTU4LjEwNCAzLjAwNjIgMy44NTgzIDMuMDA2Mi42MjM2LS40NDA2LS44NzA0LTQuNDgzNHoiIGZpbGw9IiNmNTg0MWYiIHN0cm9rZT0iI2Y1ODQxZiIvPjxwYXRoIGQ9Im0yMC41OTA2IDMwLjg0MTcuMDM5LTEuMjMxLS4zMzc4LS4yODUxaC00Ljk2MjZsLS4zMjQ4LjI4NTEuMDI2IDEuMjMxLTQuMTU3Mi0xLjk2OTYgMS40NTUxIDEuMTkyMSAyLjk0ODkgMi4wMzQ0aDUuMDUzNmwyLjk2Mi0yLjAzNDQgMS40NDItMS4xOTIxeiIgZmlsbD0iI2MwYWM5ZCIgc3Ryb2tlPSIjYzBhYzlkIi8+PHBhdGggZD0ibTIwLjI2NTkgMjYuNzA4Mi0uNjIzNi0uNDQwNmgtMy42NjM1bC0uNjIzNi40NDA2LS4zNTA4IDIuOTAyNS4zMjQ4LS4yODUxaDQuOTYyNmwuMzM3OC4yODUxeiIgZmlsbD0iIzE2MTYxNiIgc3Ryb2tlPSIjMTYxNjE2Ii8+PHBhdGggZD0ibTMzLjUxNjggMTEuMzUzMiAxLjEwNDMtNS4zNjQ0Ny0xLjY2MjktNC45ODg3My0xMi42OTIzIDkuMzk0NCA0Ljg4NDYgNC4xMjA1IDYuODk4MyAyLjAwODUgMS41Mi0xLjc3NTItLjY2MjYtLjQ3OTUgMS4wNTIzLS45NTg4LS44MDU0LS42MjIgMS4wNTIzLS44MDM0eiIgZmlsbD0iIzc2M2UxYSIgc3Ryb2tlPSIjNzYzZTFhIi8+PHBhdGggZD0ibTEgNS45ODg3MyAxLjExNzI0IDUuMzY0NDctLjcxNDUxLjUzMTMgMS4wNjUyNy44MDM0LS44MDU0NS42MjIgMS4wNTIyOC45NTg4LS42NjI1NS40Nzk1IDEuNTE5OTcgMS43NzUyIDYuODk4MzUtMi4wMDg1IDQuODg0Ni00LjEyMDUtMTIuNjkyMzMtOS4zOTQ0eiIgZmlsbD0iIzc2M2UxYSIgc3Ryb2tlPSIjNzYzZTFhIi8+PHBhdGggZD0ibTMyLjA0ODkgMTYuNTIzNC02Ljg5ODMtMi4wMDg1IDIuMDc4NiAzLjEzNTgtMy4xMDQ5IDYuMDUxMyA0LjEwNTItLjA1MTloNi4xMzE4eiIgZmlsbD0iI2Y1ODQxZiIgc3Ryb2tlPSIjZjU4NDFmIi8+PHBhdGggZD0ibTEwLjQ3MDUgMTQuNTE0OS02Ljg5ODI4IDIuMDA4NS0yLjI5OTQ0IDcuMTI2N2g2LjExODgzbDQuMTA1MTkuMDUxOS0zLjEwNDg3LTYuMDUxM3oiIGZpbGw9IiNmNTg0MWYiIHN0cm9rZT0iI2Y1ODQxZiIvPjxwYXRoIGQ9Im0xOS44MjQxIDE3Ljk4NzYuNDQxNy03LjU5MzIgMi4wMDA3LTUuNDAzNGgtOC45MTE5bDIuMDAwNiA1LjQwMzQuNDQxNyA3LjU5MzIuMTY4OSAyLjM4NDIuMDEzIDUuODk1OGgzLjY2MzVsLjAxMy01Ljg5NTh6IiBmaWxsPSIjZjU4NDFmIiBzdHJva2U9IiNmNTg0MWYiLz48L2c+PC9zdmc+`,uuid:`fb8e904e-1a71-454a-af65-dc1ee86311c3`};const Jt={icon:`data:image/svg+xml,<svg viewBox="0 0 48 48" class="SvgIcon undefined Logo Logo--PassportSymbolOutlined css-1dn9atd" xmlns="http://www.w3.org/2000/svg"><g data-testid="undefined__g"><circle cx="24" cy="24" r="22.5" fill="url(%23paint0_radial_6324_83922)"></circle><circle cx="24" cy="24" r="22.5" fill="url(%23paint1_radial_6324_83922)"></circle><path d="M24 0C10.7452 0 0 10.7452 0 24C0 37.2548 10.7452 48 24 48C37.2548 48 48 37.2548 48 24C48 10.7452 37.2548 0 24 0ZM23.0718 9.16608C23.7383 8.83951 24.4406 8.86188 25.087 9.2287C27.3282 10.5059 29.5627 11.7942 31.786 13.096C32.5018 13.5165 32.8686 14.1897 32.8708 15.0173C32.8843 17.9184 32.8798 20.8171 32.8708 23.7182C32.8708 23.8255 32.8015 23.9821 32.7143 24.0335C31.8531 24.548 30.9808 25.0423 30.0347 25.5881V25.1318C30.0347 22.148 30.0257 19.1664 30.0414 16.1827C30.0436 15.6101 29.8468 15.241 29.339 14.9525C26.7377 13.474 24.1499 11.9687 21.5575 10.4723C21.4457 10.4075 21.3361 10.3381 21.1661 10.2352C21.8326 9.85722 22.4321 9.47698 23.0673 9.16608H23.0718ZM22.5953 38.8451C22.45 38.7713 22.3426 38.7198 22.2375 38.6595C18.8041 36.68 15.3752 34.687 11.9307 32.7232C10.9644 32.173 10.5238 31.3879 10.5349 30.2852C10.5551 27.9411 10.5484 25.597 10.5372 23.2507C10.5327 22.1927 10.9622 21.4255 11.8926 20.8977C14.3105 19.5221 16.715 18.1264 19.1195 16.7284C19.3275 16.6076 19.4796 16.5875 19.6965 16.7172C20.5264 17.216 21.3719 17.6924 22.2554 18.2024C22.0876 18.3031 21.9601 18.3791 21.8304 18.4552C19.2268 19.9582 16.6278 21.4658 14.0175 22.9599C13.5903 23.2037 13.3912 23.5213 13.3957 24.0179C13.4091 25.8654 13.4114 27.713 13.3957 29.5605C13.3912 30.0705 13.5948 30.3948 14.0332 30.6453C16.7866 32.2199 19.5288 33.8125 22.28 35.3916C22.5126 35.5258 22.611 35.6645 22.6065 35.9418C22.5864 36.888 22.5998 37.8363 22.5998 38.8473L22.5953 38.8451ZM22.5953 33.553C22.356 33.4166 22.1838 33.3204 22.0116 33.2198C19.8285 31.9605 17.6477 30.6967 15.4602 29.4464C15.2231 29.3122 15.1359 29.1668 15.1381 28.8917C15.1538 27.4714 15.1471 26.0511 15.1426 24.6308C15.1426 24.4384 15.1717 24.3064 15.3618 24.1991C16.167 23.7495 16.9633 23.2798 17.7618 22.8212C17.8199 22.7877 17.8826 22.7631 17.9877 22.7116V24.3064C17.9877 25.1698 18.0011 26.0354 17.9832 26.8988C17.972 27.3909 18.1622 27.7241 18.5916 27.9657C19.8285 28.6636 21.0498 29.3883 22.2867 30.0839C22.5305 30.2203 22.6043 30.3724 22.5998 30.6408C22.5842 31.5847 22.5931 32.5308 22.5931 33.5508L22.5953 33.553ZM20.0746 14.91C19.6116 14.6371 19.2157 14.6393 18.7527 14.91C16.1581 16.4265 13.5523 17.9228 10.9487 19.4259C10.8391 19.4908 10.7251 19.5489 10.5305 19.6541C10.5998 18.6654 10.3873 17.7327 10.7251 16.8291C10.9085 16.3348 11.2529 15.9635 11.7092 15.6995C13.8811 14.4447 16.0507 13.1877 18.227 11.9396C19.0211 11.4833 19.8308 11.4945 20.6248 11.953C23.0964 13.3756 25.5657 14.8026 28.0306 16.2341C28.1357 16.2945 28.2677 16.4309 28.2677 16.5338C28.2856 17.5493 28.2788 18.567 28.2788 19.6563C27.3819 19.1396 26.5543 18.6609 25.7267 18.1823C23.8412 17.093 21.9512 16.0149 20.0746 14.91ZM37.4427 30.8779C37.3778 31.6764 36.9103 32.2423 36.2192 32.6404C33.5732 34.1614 30.9294 35.6913 28.2856 37.2168C27.4557 37.6954 26.6259 38.1741 25.7938 38.6527C25.6932 38.7109 25.5903 38.7601 25.4539 38.8317C25.4449 38.693 25.4337 38.5924 25.4337 38.4917C25.4337 37.6149 25.4382 36.7404 25.4293 35.8636C25.4293 35.6645 25.4762 35.5437 25.6596 35.4386C29.5157 33.2198 33.3696 30.9942 37.2212 28.7709C37.2794 28.7374 37.3443 28.7105 37.4539 28.6591C37.4539 29.4375 37.4986 30.1622 37.4427 30.8779ZM37.4628 25.3577C37.4561 26.2658 36.9663 26.9033 36.1901 27.3506C33.175 29.0841 30.1622 30.8265 27.1493 32.5666C26.5991 32.8842 26.0466 33.1996 25.4561 33.5396C25.4472 33.3897 25.436 33.2913 25.436 33.1907C25.436 32.3273 25.4449 31.4617 25.4293 30.5983C25.4248 30.3523 25.5075 30.2226 25.72 30.0995C28.46 28.5271 31.1911 26.9368 33.9355 25.3733C34.4231 25.096 34.6378 24.7538 34.6334 24.1812C34.6132 21.1974 34.6244 18.2136 34.6244 15.2298V14.7087C35.3402 15.1404 36.0112 15.496 36.624 15.9299C37.1832 16.3258 37.465 16.9253 37.4673 17.6164C37.4762 20.1976 37.4829 22.7788 37.465 25.3599L37.4628 25.3577Z" fill="%230D0D0D"></path><path fill-rule="evenodd" d="M24 0C10.7452 0 0 10.7452 0 24C0 37.2548 10.7452 48 24 48C37.2548 48 48 37.2548 48 24C48 10.7452 37.2548 0 24 0ZM24 2C11.8497 2 2 11.8497 2 24C2 36.1503 11.8497 46 24 46C36.1503 46 46 36.1503 46 24C46 11.8497 36.1503 2 24 2Z" fill="url(%23paint2_radial_6324_83922)"></path><path fill-rule="evenodd" d="M24 0C10.7452 0 0 10.7452 0 24C0 37.2548 10.7452 48 24 48C37.2548 48 48 37.2548 48 24C48 10.7452 37.2548 0 24 0ZM24 2C11.8497 2 2 11.8497 2 24C2 36.1503 11.8497 46 24 46C36.1503 46 46 36.1503 46 24C46 11.8497 36.1503 2 24 2Z" fill="url(%23paint3_radial_6324_83922)"></path><defs><radialGradient id="paint0_radial_6324_83922" cx="0" cy="0" r="1" gradientUnits="userSpaceOnUse" gradientTransform="translate(13.4442 13.3899) rotate(44.9817) scale(46.7487 99.1435)"><stop stop-color="%23A3EEF8"></stop><stop offset="0.177083" stop-color="%23A4DCF5"></stop><stop offset="0.380208" stop-color="%23A6AEEC"></stop><stop offset="1" stop-color="%23ECBEE1"></stop></radialGradient><radialGradient id="paint1_radial_6324_83922" cx="0" cy="0" r="1" gradientUnits="userSpaceOnUse" gradientTransform="translate(25.9515 43.7068) rotate(84.265) scale(24.2138 46.3215)"><stop stop-color="%23FCF5EE"></stop><stop offset="0.715135" stop-color="%23ECBEE1" stop-opacity="0"></stop></radialGradient><radialGradient id="paint2_radial_6324_83922" cx="0" cy="0" r="1" gradientUnits="userSpaceOnUse" gradientTransform="translate(12.7405 12.6825) rotate(44.9817) scale(49.8653 105.753)"><stop stop-color="%23A3EEF8"></stop><stop offset="0.177083" stop-color="%23A4DCF5"></stop><stop offset="0.380208" stop-color="%23A6AEEC"></stop><stop offset="1" stop-color="%23ECBEE1"></stop></radialGradient><radialGradient id="paint3_radial_6324_83922" cx="0" cy="0" r="1" gradientUnits="userSpaceOnUse" gradientTransform="translate(26.0816 45.0206) rotate(84.265) scale(25.828 49.4096)"><stop stop-color="%23FCF5EE"></stop><stop offset="0.715135" stop-color="%23ECBEE1" stop-opacity="0"></stop></radialGradient></defs></g></svg>`,name:`Immutable Passport`,rdns:`com.immutable.passport`,uuid:`b90118be-7234-4c89-b89b-d5d267663eb5`};const Yt=e=>({info:Jt,provider:e});const Xt=e=>({info:qt,provider:e});async function Zt(){const e=await k(async()=>await C(),{type:`METAMASK_PROVIDER_ERROR`});if(!e||!e.request)throw new O(`No MetaMask provider installed.`,`METAMASK_PROVIDER_ERROR`);return new L(e)}async function Qt(e,t){let n=null;let r;switch(e){case`passport`:r=Y.getInstance().findProvider({rdns:Jt.rdns});if(!r)if(t)n=new L(await t.connectEvm({announceProvider:false}));else{console.error(`WalletProviderName was PASSPORT but the passport instance was not provided to the Checkout constructor`);throw new O(`Passport not provided`,`DEFAULT_PROVIDER_ERROR`)}break;case`metamask`:r=Y.getInstance().findProvider({rdns:qt.rdns});if(!r)n=await Zt();break;default:r=Y.getInstance().findProvider({rdns:e});if(!r){console.error(`The WalletProviderName that was provided is not supported`);throw new O(`Provider not supported`,`DEFAULT_PROVIDER_ERROR`)}}if(!n&&r)n=new L(r.provider);if(!n){console.error(`Failed to create provider`);throw new O(`Failed to create provider`,`DEFAULT_PROVIDER_ERROR`)}return{provider:n,walletProviderName:e}}function $t(e){return e&&`send`in e&&typeof e.send===`function`}async function X(e,t,n){return k(async()=>{if(`request`in t)return new L(t);if(t.ethereumProvider?.isPassport)return t;const r={...We,...n};const i=await R(t);let a=(await t.getNetwork()).chainId;try{if(!a)a=(await t.getNetwork()).chainId}catch(e){throw new O(`Unable to detect the browserProvider network`,`WEB3_PROVIDER_ERROR`,{error:e})}if(a!==BigInt(i)&&!r.allowMistmatchedChainId){console.error(`web3ChainId`,a,`underlyingChainId`,i,r);throw new O(`Your wallet has changed network, please switch to a supported network`,`WEB3_PROVIDER_ERROR`)}if(!(await z(e,{type:`all`})).networks.some(e=>e.chainId===Number(i))&&!r.allowUnsupportedProvider)throw new O(`Your wallet is connected to an unsupported network, please switch to a supported network`,`WEB3_PROVIDER_ERROR`);return t},{type:`WEB3_PROVIDER_ERROR`})}async function en(e,t){if(e.isProduction&&t?.has(1))return t;if(t?.has(11155111))return t;const n=new Map;(await z(e,{type:`all`})).networks.forEach(t=>{const r=e.networkMap.get(Number(t.chainId))?.rpcUrls[0];const i=new o(r);n.set(Number(t.chainId),i)});return n}const tn=(e,t,n)=>{const r=[];if(!e.sufficient){for(const t of e.allowances)if(!t.sufficient)r.push(t)}if(!t.sufficient){for(const e of t.allowances)if(!e.sufficient)r.push(e)}if(!n.sufficient){for(const e of n.allowances)if(!e.sufficient)r.push(e)}return r};const nn=e=>{const t=new Map;const n=[];e.forEach(e=>{const{type:r}=e;if(r!==`NATIVE`||e.isFee){n.push(e);return}const i={...e,isFee:`isFee`in e?e.isFee:false};const{amount:a}=i;const o=t.get(r);if(o&&o.type===`NATIVE`)o.amount+=a;else t.set(r,{...i})});return n.concat(Array.from(t.values()))};const rn=e=>{const t=new Map;const n=[];e.forEach(e=>{const{type:r}=e;if(r!==`ERC20`||e.isFee){n.push(e);return}const i={...e,isFee:`isFee`in e?e.isFee:false};const{tokenAddress:a,spenderAddress:o,amount:s}=i;const c=`${a}${o}`;const l=t.get(c);if(l&&l.type===`ERC20`)l.amount+=s;else t.set(c,{...i})});return n.concat(Array.from(t.values()))};const an=e=>{const t=new Map;const n=[];e.forEach(e=>{const{type:r}=e;if(r!==`ERC721`){n.push(e);return}const{contractAddress:i,spenderAddress:a,id:o}=e;const s=`${i}${a}${o}`;if(!t.get(s))t.set(s,{...e})});return n.concat(Array.from(t.values()))};const on=e=>{const t=new Map;const n=[];e.forEach(e=>{const{type:r}=e;if(r!==`ERC1155`){n.push(e);return}const{contractAddress:i,spenderAddress:a,id:o,amount:s}=e;const c=`${i}${a}${o}`;const l=t.get(c);if(l&&l.type===`ERC1155`)l.amount+=s;else t.set(c,{...e})});return n.concat(Array.from(t.values()))};const sn=e=>on(an(rn(nn(e))));const cn=async(e,t,n,r)=>{try{return await new a(n,JSON.stringify(P),e).allowance(t,r)}catch(e){throw new O(`Failed to get the allowance for ERC20`,`GET_ERC20_ALLOWANCE_ERROR`,{contractAddress:n,error:e})}};const ln=async(e,t,n,r,i)=>{try{const o=await new a(n,JSON.stringify(P),e).approve.populateTransaction(r,i);if(o)o.from=t;return o}catch(e){throw new O(`Failed to get the approval transaction for ERC20`,`GET_ERC20_ALLOWANCE_ERROR`,{contractAddress:n,error:e})}};const un=async(e,t,n)=>{let r=true;const i=[];const a=new Map;const o=new Map;const s=new Map;const c=new Map;for(const r of n){if(r.type!==`ERC20`)continue;const{tokenAddress:n,spenderAddress:i}=r;const s=`${n}${i}`;a.set(s,r);o.set(s,cn(e,t,n,i))}const l=await Promise.all(o.values());const u=Array.from(o.keys());for(let n=0;n<l.length;n++){const o=a.get(u[n]);if(!o||o.type!==`ERC20`)continue;if(l[n]>=o.amount){i.push({sufficient:true,itemRequirement:o});continue}r=false;const{tokenAddress:d,spenderAddress:f}=o;const p=`${d}${f}`;const m=o.amount-l[n];s.set(p,{type:`ERC20`,sufficient:false,delta:m,itemRequirement:o,approvalTransaction:void 0});c.set(p,ln(e,t,d,f,m))}const d=await Promise.all(c.values());const f=Array.from(c.keys());d.forEach((e,t)=>{const n=s.get(f[t]);if(!n)return;if(n.sufficient)return;n.approvalTransaction=e});return{sufficient:r,allowances:i.concat(Array.from(s.values()))}};const dn=async(e,t,n,r)=>{try{return await new a(n,JSON.stringify(F),e).isApprovedForAll(t,r)}catch(e){throw new O(`Failed to check approval for all ERC721s of collection`,`GET_ERC721_ALLOWANCE_ERROR`,{ownerAddress:t,contractAddress:n,spenderAddress:r,error:e})}};const fn=async(e,t,n,r,i)=>{try{const o=await new a(n,JSON.stringify(F),e).approve.populateTransaction(r,i);if(o)o.from=t;return o}catch(e){throw new O(`Failed to get the approval transaction for ERC721`,`GET_ERC721_ALLOWANCE_ERROR`,{id:i.toString(),contractAddress:n,spenderAddress:r,ownerAddress:t,error:e})}};const pn=async(e,t,n)=>{try{return await new a(t,JSON.stringify(F),e).getApproved(n)}catch(e){throw new O(`Failed to get approved address for ERC721`,`GET_ERC721_ALLOWANCE_ERROR`,{id:n.toString(),contractAddress:t,error:e})}};const mn=(e,t)=>{try{if(!e.trim())throw new O(`Invalid ERC721 ID`,`GET_ERC721_ALLOWANCE_ERROR`,{id:e,contractAddress:t});return BigInt(e)}catch(n){throw new O(`Invalid ERC721 ID`,`GET_ERC721_ALLOWANCE_ERROR`,{id:e,contractAddress:t})}};const hn=async(e,t,n)=>{const r=new Map;const i=new Map;for(const a of t){if(a.type!==`ERC721`)continue;const{contractAddress:t,spenderAddress:o}=a;const s=`${t}-${o}`;r.set(s,false);if(i.has(s))continue;i.set(s,dn(e,n,t,o))}const a=await Promise.all(i.values());const o=Array.from(i.keys());a.forEach((e,t)=>{r.set(o[t],e)});return r};const gn=async(e,t,n)=>{let r=true;const i=[];const a=new Map;const o=new Map;const s=new Map;const c=new Map;const l=await hn(e,n,t);for(const t of n){if(t.type!==`ERC721`)continue;const{contractAddress:n,id:r,spenderAddress:s}=t;const c=`${n}-${s}`;if(l.get(c)){i.push({sufficient:true,itemRequirement:t});continue}const u=`${n}-${r}`;const d=mn(r,n);a.set(u,t);o.set(u,pn(e,n,d))}const u=await Promise.all(o.values());const d=Array.from(o.keys());for(let n=0;n<u.length;n++){const o=a.get(d[n]);if(!o||o.type!==`ERC721`)continue;if(u[n]===o.spenderAddress){i.push({sufficient:true,itemRequirement:o});continue}r=false;const{contractAddress:l,id:f,spenderAddress:p}=o;const m=`${l}-${f}`;const h=mn(f,l);s.set(m,{type:`ERC721`,sufficient:false,itemRequirement:o,approvalTransaction:void 0});c.set(m,fn(e,t,l,p,h))}const f=await Promise.all(c.values());const p=Array.from(c.keys());f.forEach((e,t)=>{const n=s.get(p[t]);if(!n)return;if(n.sufficient)return;n.approvalTransaction=e});return{sufficient:r,allowances:i.concat(Array.from(s.values()))}};const _n=async(e,t,n,r)=>{try{return await new a(n,JSON.stringify(Pe),e).isApprovedForAll(t,r)}catch(e){throw new O(`Failed to check approval for all ERC1155s of collection`,`GET_ERC1155_ALLOWANCE_ERROR`,{ownerAddress:t,contractAddress:n,spenderAddress:r,error:e})}};const vn=async(e,t,n,r)=>{try{const i=await new a(n,JSON.stringify(Pe),e).setApprovalForAll.populateTransaction(r,true);if(i)i.from=t;return i}catch(e){throw new O(`Failed to get the approval transaction for ERC1155`,`GET_ERC1155_ALLOWANCE_ERROR`,{contractAddress:n,spenderAddress:r,ownerAddress:t,error:e})}};const yn=async(e,t,n)=>{const r=n.filter(e=>e.type===`ERC1155`);const i=await Promise.all(r.map(async n=>{if(await _n(e,t,n.contractAddress,n.spenderAddress))return{sufficient:true,itemRequirement:n};const r=await vn(e,t,n.contractAddress,n.spenderAddress);return{type:`ERC1155`,sufficient:false,itemRequirement:n,approvalTransaction:r}}));return{sufficient:i.some(e=>e.sufficient),allowances:i}};const bn=e=>{const t=new Map;const n=[];e.forEach(e=>{const{type:r}=e;if(r!==`NATIVE`||e.isFee){n.push(e);return}const{amount:i}=e;const a=t.get(r);if(a&&a.type===`NATIVE`)a.amount+=i;else t.set(r,{...e})});return n.concat(Array.from(t.values()))};const xn=e=>{const t=new Map;const n=[];e.forEach(e=>{const{type:r}=e;if(r!==`ERC20`||e.isFee){n.push(e);return}const{tokenAddress:i,amount:a}=e;const o=`${i}`;const s=t.get(o);if(s&&s.type===`ERC20`)s.amount+=a;else t.set(o,{...e})});return n.concat(Array.from(t.values()))};const Sn=e=>{const t=new Map;const n=[];e.forEach(e=>{const{type:r}=e;if(r!==`ERC721`){n.push(e);return}const{contractAddress:i,id:a}=e;const o=`${i}${a}`;if(!t.get(o))t.set(o,{...e})});return n.concat(Array.from(t.values()))};const Cn=e=>Sn(xn(bn(e)));const wn=e=>e.map(e=>{switch(e.type){case`ERC20`:return{address:e.tokenAddress};case`NATIVE`:return{address:j};case`ERC721`:default:return{address:e.contractAddress}}});const Tn=(e,t)=>{const n=BigInt(1);const r=t.find(t=>{const n=t;return U(n.contractAddress,e.contractAddress)&&n.id===e.id});const i=n<0||n===0n||r&&r.balance>=n;const a=n-(r?.balance??BigInt(0));let o=r;if(!o)o={type:`ERC721`,balance:BigInt(0),formattedBalance:`0`,contractAddress:e.contractAddress,id:e.id};return{sufficient:i??false,type:`ERC721`,delta:{balance:a,formattedBalance:a.toString()},current:o,required:{...o,balance:BigInt(1),formattedBalance:`1`},isFee:false}};const En=(e,t)=>{if(e.type===`ERC20`)return t.find(t=>{return U(t.token?.address,e.tokenAddress)});return t.find(e=>{return K(e.token?.address)})};const Dn=async(e,t,n)=>{const r={};for(const i of e){if(i.type===`NATIVE`){r[j]=De;continue}const e=En(i,t);let o=e?.token.address??``;let s=e?.token.name??``;let c=e?.token.symbol??``;let l=e?.token.decimals??18;if(!e&&i.type===`ERC20`){o=i.tokenAddress;if(o.toLowerCase()in r)continue;try{const e=new a(i.tokenAddress,JSON.stringify(P),n);const[t,r,u]=await Promise.all([e.name(),e.symbol(),e.decimals()]);o=i.tokenAddress;l=u;s=t;c=r}catch(e){console.error(`Failed to query contract information`,i.tokenAddress)}}r[o.toLowerCase()]={address:o,name:s,symbol:c,decimals:l}}return r};const On=(e,t,n)=>{let r=En(e,t);const i=e.amount;const a=i<0||i===0n||r&&r?.balance>=i;const o=i-(r?.balance??BigInt(0));if(e.type===`NATIVE`){if(!r)r={type:`NATIVE`,balance:BigInt(0),formattedBalance:`0`,token:n};return{sufficient:a??false,type:`NATIVE`,delta:{balance:o,formattedBalance:s(o,n.decimals)},current:{...r,type:`NATIVE`,token:n},required:{...r,type:`NATIVE`,balance:BigInt(e.amount),formattedBalance:s(e.amount,n.decimals),token:n},isFee:e.isFee}}if(!r)r={type:e.type,balance:BigInt(0),formattedBalance:`0`,token:n};return{sufficient:a??false,type:`ERC20`,delta:{balance:o,formattedBalance:s(o,n.decimals)},current:{...r,token:n},required:{...r,token:n,balance:BigInt(e.amount),formattedBalance:s(e.amount,n.decimals)},isFee:e.isFee}};const kn=async(e,t,n,r,i=false)=>{try{const a=new Map;wn(r).forEach(e=>{if(!e.address)return;a.set(e.address.toLocaleLowerCase(),e)});const{balances:o}=await J(e,t,n,H(e),i);return o.filter(e=>a.get((e.token.address||`native`).toLocaleLowerCase()))}catch(e){throw new O(`Failed to get balances`,`GET_BALANCE_ERROR`,{error:e})}};const An=async(e,t,n)=>{const r=[];const i=new Map;const o=new Map;n.forEach(t=>{if(t.type!==`ERC721`)return;const n=new a(t.contractAddress,JSON.stringify(F),e);i.set(t.contractAddress,t);o.set(t.contractAddress,n.ownerOf(t.id))});try{const e=await Promise.all(o.values());const n=Array.from(o.keys());e.forEach((e,a)=>{const o=i.get(n[a]);let s=0;if(o&&U(t,e))s=1;r.push({type:`ERC721`,balance:BigInt(s),formattedBalance:s.toString(),contractAddress:o.contractAddress,id:o.id})})}catch(e){throw new O(`Failed to get ERC721 balances`,`GET_ERC721_BALANCE_ERROR`,{error:e})}return r};const jn=async(e,t,n,r,i=false)=>{const a=Cn(r);const o=[];const c=[];a.forEach(e=>{switch(e.type){case`ERC20`:case`NATIVE`:o.push(e);break;case`ERC721`:c.push(e);break;default:}});o.sort(e=>`isFee`in e&&e.isFee?1:-1);if(c.length===0&&o.length===0)throw new O(`Unsupported item requirement balance check`,`UNSUPPORTED_BALANCE_REQUIREMENT_ERROR`);const l=[];if(o.length>0)l.push(kn(e,t,n,a,i));if(c.length>0)l.push(An(t,n,a));const u=await Promise.all(l);const d=[];if(o.length>0){const e=u.shift()??[];const n=new Map(e.map(e=>{return[e.type===`NATIVE`?j:e.token.address?.toLowerCase(),e]}));const r=await Dn(o,e,t);o.forEach(e=>{const t=(e.tokenAddress??`native`).toLowerCase();const i=r[t];const a=n.get(t);const o=On(e,[...n.values()],i);d.push(o);if(!a)return;const c=a.balance-o.required.balance;n.set(t,{...a,balance:c,formattedBalance:s(c,o.required.token.decimals)})})}if(c.length>0){const e=u.shift()??[];c.forEach(t=>{d.push(Tn(t,e))})}return{sufficient:d.find(e=>!e.sufficient)===void 0,balanceRequirements:d}};const Mn=async(e,t)=>{try{return await e.estimateGas(t)}catch(e){throw new O(`Failed to estimate gas for transaction`,`UNPREDICTABLE_GAS_LIMIT`,{error:e})}};const Nn=(e,t)=>{if(t.type===`TRANSACTION`||t.gasToken.type===`NATIVE`)return{type:`NATIVE`,amount:e,isFee:true};return{type:`ERC20`,amount:e,tokenAddress:t.gasToken.tokenAddress,spenderAddress:``,isFee:true}};const Pn=async(e,t,n)=>{const r=[];let i=BigInt(0);for(const n of t){if(n.approvalTransaction===void 0)continue;r.push(Mn(e,n.approvalTransaction))}if(n.type===`TRANSACTION`)r.push(Mn(e,n.transaction));else{const t=Wt(await e.getFeeData());if(t!==null){const e=t*n.gasToken.limit;if(e)i+=e}}(await Promise.all(r)).forEach(e=>{i+=e});if(i===0n)return null;return Nn(i,n)};const Fn=async()=>true;const In=async e=>{const t=Le(e.isDevelopment,e.isProduction);try{return await t.checkDexAvailability()}catch{return false}};function Ln(e){return e?.ethereumProvider?.isPassport===true}const Rn=async(e,t)=>{const n={onRamp:e.isOnRampEnabled,swap:e.isSwapEnabled,bridge:e.isBridgeEnabled};const r=[];if(n.onRamp)r.push({id:`onRamp`,promise:Fn()});if(n.swap)r.push({id:`swap`,promise:In(e)});if(r.length>0){const e=r.map(e=>e.promise);(await Promise.allSettled(e)).forEach((e,t)=>{const i=r[t].id;n[i]=n[i]&&e.status===`fulfilled`&&e.value})}n.bridge=n.bridge&&!Ln(t);return n};const zn=async(e,t,n,r)=>{const i=new Map;const a=new Map;if(t.size===0){const t={success:false,error:new O(`No L1 or L2 provider available`,`PROVIDER_ERROR`),balances:[]};i.set(V(e),t);i.set(H(e),t);return i}if(r.bridge){const r=V(e);if(t.has(r))a.set(r,J(e,t.get(r),n,r));else i.set(V(e),{success:false,error:new O(`No L1 provider available for ${r}`,`PROVIDER_ERROR`),balances:[]})}const o=H(e);if(t.has(o))a.set(o,J(e,t.get(o),n,o));else i.set(H(e),{success:false,error:new O(`No L2 provider available for ${o}`,`PROVIDER_ERROR`),balances:[]});if(a.size>0){const e=Array.from(a.keys());(await Promise.allSettled(a.values())).forEach((t,n)=>{const r=e[n];if(t.status===`fulfilled`)i.set(r,{success:true,balances:t.value.balances});else i.set(r,{success:false,error:new O(`Error getting ${o} balances`,`GET_BALANCE_ERROR`),balances:[]})})}return i};const Bn=async(e,t,n,r,i)=>{const a=new Map;const o=1;try{const s=await Pt(t,e);const c=[];const l=[];for(const e of i){if(e===r.address)continue;c.push(s.getUnsignedSwapTxFromAmountOut(n,e,r.address,r.amount,o));l.push(e)}(await q(e,`Time to resolve swap quotes from the dex`,Promise.allSettled(c))).forEach((e,t)=>{if(e.status===`rejected`)return;const n=l[t];a.set(n,{quote:e.value.quote,approval:e.value.approval?.gasFeeEstimate??null,swap:e.value.swap.gasFeeEstimate})});return a}catch{return a}};const Vn=(e,t,n)=>{let r=BigInt(0);let i=`0`;let a;if(e){r=e.value;i=s(e.value,e.token.decimals);a={name:e.token.name??``,symbol:e.token.symbol??``,address:e.token.address,decimals:e.token.decimals}}let o=BigInt(0);let c=`0`;let l;if(t){o=t.value;c=s(t.value,t.token.decimals);l={name:t.token.name??``,symbol:t.token.symbol??``,address:t.token.address,decimals:t.token.decimals}}const u=[];for(const e of n)u.push({type:`SWAP_FEE`,amount:e.amount.value,formattedAmount:s(e.amount.value,e.amount.token.decimals),basisPoints:e.basisPoints,token:{name:e.amount.token.name??``,symbol:e.amount.token.symbol??``,address:e.amount.token.address,decimals:e.amount.token.decimals}});return{approvalGasFee:{type:`GAS`,amount:r,formattedAmount:i,token:a},swapGasFee:{type:`GAS`,amount:o,formattedAmount:c,token:l},swapFees:u}};const Hn=(e,t,n,r)=>{const i=n.token.address;let a=`ERC20`;if(K(i))a=`NATIVE`;return{type:`SWAP`,chainId:e,fundingItem:{type:a,fundsRequired:{amount:t,formattedAmount:W(s(t,n.token.decimals))},userBalance:{balance:n.balance,formattedBalance:n.formattedBalance},token:n.token},fees:r}};const Un=e=>{if(e.type===`ERC20`)return!!e.required.token.address;if(e.type===`NATIVE`)return K(e.required.token.address);return false};const Wn=e=>{let t=``;let n=BigInt(0);switch(e.type){case`ERC20`:t=e.required.token.address;n=e.delta.balance;break;case`NATIVE`:n=e.delta.balance;break;default:break}return{address:t,amount:n}};const Gn=(e,t)=>{if(!t)return{sufficient:true,approvalGasFee:BigInt(0),approvalGasTokenAddress:``};const n=t.value;const r=t.token.address;if(e.length===0)return{sufficient:false,approvalGasFee:n,approvalGasTokenAddress:r};const i=e.find(e=>K(e.token.address)&&K(r)||U(e.token.address,r));if(!i)return{sufficient:false,approvalGasFee:n,approvalGasTokenAddress:r};if(i.balance<n)return{sufficient:false,approvalGasFee:n,approvalGasTokenAddress:r};return{sufficient:true,approvalGasFee:n,approvalGasTokenAddress:r}};const Kn=(e,t,n,r,i)=>{const a=new Map;if(t.approvalGasFee>BigInt(0))a.set(t.approvalGasTokenAddress,t.approvalGasFee);if(n){const e=a.get(n.token.address);if(e)a.set(n.token.address,e+n.value);else a.set(n.token.address,n.value)}if(i){const e=a.get(i.address);if(e)a.set(i.address,e+i.amount);else a.set(i.address,i.amount)}for(const e of r){const t=a.get(e.amount.token.address);if(t){a.set(e.amount.token.address,t+e.amount.value);continue}a.set(e.amount.token.address,e.amount.value)}for(const[t,n]of a.entries()){if(n===BigInt(0))continue;const r=e.find(e=>K(e.token.address)&&K(t)||U(e.token.address,t));if(!r)return false;if(r.balance<n)return false}return true};const qn=(e,t,n,r,i,a)=>{let o=BigInt(0);let s=``;let c=false;t.balanceRequirements.forEach(t=>{if(t.type===`NATIVE`||t.type===`ERC20`){if(t.required.token.address&&U(t.required.token.address,n)){s=t.required.token.address;c=true;o=e-t.required.balance}}});if(!c)return true;if(U(i.approvalGasTokenAddress,s))o-=i.approvalGasFee;for(const e of a)if(U(e.amount.token.address,s))o-=e.amount.value;return o>=r};const Jn=async(e,t,n,r,i,a,o)=>{const s=[];if(!t.swap)return s;if(a.length===0)return s;if(!Un(r))return s;const c=Wn(r);const l=H(e);const u=i.get(l);if(!u)return s;const d=u.balances;if(d.length===0)return s;const f=await Bn(e,H(e),n,c,a);const p=Array.from(f.keys());for(const e of p){const t=f.get(e);if(!t)continue;const n=d.find(t=>U(t.token.address,e));if(!n)continue;const r=t.quote.amountWithMaxSlippage;if(n.balance<r.value)continue;const i=Gn(d,t.approval);if(!i.sufficient)continue;if(!Kn(d,i,t.swap,t.quote.fees,{amount:r.value,address:e}))continue;if(!qn(n.balance,o,e,r.value,i,t.quote.fees))continue;const a=Vn(t.approval,t.swap,t.quote.fees);s.push(Hn(l,r.value,n,a))}return s};const Yn=(e,t)=>{if(t&&t.success)return e.filter(e=>{if(`address`in e)return t.balances.find(t=>U(t.token.address,e.address)&&t.balance>0);return t.balances.find(e=>!(`address`in e.token)&&e.balance>0)});return[]};const Xn=async(e,t)=>{if(t.onRamp)return(await G(e,{type:`onramp`})).tokens;return[]};const Zn=async(e,t,n)=>{if(n.bridge){const n=V(e);const r=(await G(e,{type:`bridge`,chainId:n})).tokens;const i=t.get(n);return Yn(r,i)}return[]};const Qn=async(e,t,n)=>{if(n.swap){const n=(await G(e,{type:`swap`})).tokens;const r=t.get(H(e));return Yn(n,r)}return[]};const $n=async(e,t,n)=>{const r={};r.swap=await Qn(e,t,n);r.bridge=await Zn(e,t,n);r.onRamp=await Xn(e,n);return r};const er=e=>{for(const t of e.balances)if(K(t.token.address))return t.balance;return BigInt(0)};const tr=async(e,t,n,r)=>{const i=Nt(n,r,t,e);try{return{...await i.getFee({action:u.DEPOSIT,gasMultiplier:`auto`,sourceChainId:n.toString(),destinationChainId:r.toString()}),approvalGas:BigInt(0)}}catch(e){throw new O(`Error estimating gas for bridge`,`BRIDGE_GAS_ESTIMATE_ERROR`,{error:e})}};const nr=`0x0000000000000000000000000000000000000eee`;const rr=e=>{if(e===13371)return`imtbl-zkevm-mainnet`;if(e===13473)return`imtbl-zkevm-testnet`;if(e===15003)return`imtbl-zkevm-devnet`;return``};const ir=async(e,t)=>{return(await t.remote.getConfig(`imxAddressMapping`))[e]??``};const ar=async(e,t)=>{if(K(t))return{l1address:await ir(V(e),e),l2address:j};const n=rr(H(e));const r=(await It(e).getToken({chainName:n,contractAddress:t})).result.root_contract_address;if(U(r??``,`0x0000000000000000000000000000000000000eee`))return{l1address:`native`,l2address:t};if(r===null)return void 0;return{l1address:r,l2address:t}};const or=(e,t)=>{return er(e)>=t};const sr=(e,t,n,r,i)=>{const a=i?.decimals??18;const o=[];if(t>0)o.push({type:`BRIDGE_FEE`,amount:t,formattedAmount:s(t,a),token:i});if(n>0)o.push({type:`IMMUTABLE_FEE`,amount:n,formattedAmount:s(n,a),token:i});return{approvalGasFee:{type:`GAS`,amount:r,formattedAmount:s(r,18),token:i},bridgeGasFee:{type:`GAS`,amount:e,formattedAmount:s(e,18),token:i},bridgeFees:o}};const cr=(e,t,n,r,i)=>({type:`BRIDGE`,chainId:e,fundingItem:{type:r,fundsRequired:{amount:n.amount,formattedAmount:W(n.formattedAmount)},userBalance:{balance:t.balance,formattedBalance:t.formattedBalance},token:{name:t.token.name,symbol:t.token.symbol,address:t.token.address,decimals:t.token.decimals}},fees:i});const lr=async(e,t,n,r,i)=>{if(!n.bridge)return void 0;const a=V(e);const o=H(e);const s=e.networkMap.get(a)?.nativeCurrency;const c=i.get(a);if(!t.get(a))throw new O(`No L1 provider available`,`PROVIDER_ERROR`,{chainId:a.toString()});if(c===void 0||c.success===false)return void 0;const l=await Zn(e,i,n);if(l.length===0)return void 0;const u=await ar(e,r.l2address);if(!u)return void 0;const{l1address:d}=u;if(K(d)){if(!l.find(e=>K(e.address)))return void 0}else if(!l.find(e=>U(e.address,d)))return;const{sourceChainGas:f,approvalGas:p,bridgeFee:m,imtblFee:h,totalFees:g}=await tr(e,t,a,o);if(!or(c,g))return void 0;if(K(d)){const e=c.balances.find(e=>K(e.token.address));if(e&&e.balance>=r.amount+g){const t=sr(f,m,h,p,s);return cr(a,e,r,`NATIVE`,t)}return}const _=c.balances.find(e=>U(e.token.address,d));if(_&&_.balance>=r.amount){const e=sr(f,m,h,p,s);return cr(a,_,r,`ERC20`,e)}};const ur=(e,t)=>{const n={l1balances:[],l2balances:[]};const r=t.get(V(e));const i=t.get(H(e));if(!r)return n;if(r.error!==void 0)return n;if(!r.success)return n;if(!i)return n;if(i.error!==void 0)return n;if(!i.success)return n;return{l1balances:r.balances,l2balances:i.balances}};const dr=(e,t)=>{let n=BigInt(0);e.quote.fees.forEach(e=>{if(U(e.amount.token.address,t))n+=e.amount.value});if(e.approval){if(U(e.approval.token.address,t))n+=e.approval.value}return n};const fr=(e,t)=>{for(const n of e.balanceRequirements)if(n.type===`NATIVE`||n.type===`ERC20`){if(U(n.required.token.address,t))return n.required.balance}return BigInt(0)};const pr=(e,t,n)=>{const r=n?.balance??BigInt(0);if(r>=e+t)return BigInt(0);if(r<=0)return e+t;const i=r-t;if(i>=0)return e-i;return e+t-r};const mr=(e,t,n,r,i)=>{const a=[];for(const[o,c]of e){const e=n.find(e=>U(e.token.address,o));const l=r.find(e=>U(e.l2address,o));if(!l)continue;const{l1address:u,l2address:d}=l;if(!u)continue;const f=t.find(e=>{if(e.token.address===void 0&&U(u,`0x0000000000000000000000000000000000000eee`))return true;return U(e.token.address,u)});if(!f)continue;const p=c.quote.amountWithMaxSlippage.value+dr(c,o);const m=fr(i,o);const h=pr(p,m,e);if(h<=0)continue;if(h>=f.balance)continue;a.push({amount:h,formattedAmount:W(s(h,f.token.decimals)),l2address:d})}return a};const hr=async(e,t)=>{const n=t.map(t=>ar(e,t.address??``));return(await Promise.all(n)).filter(e=>e!==void 0)};const gr=async(e,t,n,r,i)=>{const a=[];for(const e of i){if(!e.address)continue;a.push(e.address)}return await Bn(e,H(e),t,{address:n,amount:r.delta.balance},a)};const _r=(e,t,n,r,i,a)=>{if(e.length===0)return true;if(t.length===0)return true;if(n.length===0)return true;if(r.length===0)return true;if(!i.bridge)return true;if(!i.swap)return true;if(a===void 0)return true;if(a===``)return true;return false};const vr=(e,t,n,r)=>{const i=[];for(const a of r){if(!t.includes(a.l1address))continue;if(U(a.l2address,e))continue;const r=n.find(e=>U(e.address,a.l2address));if(!r)continue;i.push(r)}return i};const yr=(e,t,n,r,i)=>{const a=new Map;for(const[e,n]of t)a.set(e,{success:n.success,balances:n.balances});const o=new Map;for(const e of n){if(!e.token.address)continue;o.set(e.token.address,e)}for(const e of r){const{amount:t,l2address:n}=e;if(n===``)continue;let r=BigInt(0);const a=o.get(n);if(a)r=a.balance;const c=r+t;const l=i.find(e=>U(e.address,n));o.set(n,{balance:c,formattedBalance:s(c,l.decimals),token:l})}const c=Array.from(o.values());a.set(H(e),{success:true,balances:c});return a};const br=(e,t)=>{const n=[];for(const r of t){const{chainId:t,fundingItem:i}=r;const{userBalance:a}=r.fundingItem;const o=e.get(t);if(!o)continue;let s=BigInt(0);let c=`0`;const l=o.balances.find(e=>U(e.token.address,i.token.address));if(l){s=l.balance;c=l.formattedBalance}a.balance=s;a.formattedBalance=c;n.push(r)}return n};const xr=(e,t,n)=>{const r=[];for(const i of e){if(!i)continue;const e=n.find(e=>{if(i.fundingItem.token.address===void 0)return U(e.l1address,`0x0000000000000000000000000000000000000eee`)&&e.l2address;return U(e.l1address,i.fundingItem.token.address)&&e.l2address});if(!e)continue;const a=t.find(t=>U(t.fundingItem.token.address,e.l2address));if(!a)continue;r.push({bridgeFundingStep:i,swapFundingStep:a})}return r};const Sr=async(e,t,n,r,i,a,o,s,c)=>{const{l1balances:l,l2balances:u}=ur(e,a);const d=r.required.token.address;if(_r(o,s,l,u,n,d))return[];const f=await hr(e,s);const p=vr(d,o,s,f);if(p.length===0)return[];const m=mr(await gr(e,i,d,r,p),l,u,f,c);if(m.length===0)return[];const h=new Map;const g=new Map;const _=[];for(const r of m){if(!r.l2address)continue;h.set(r.l2address,lr(e,t,n,r,a));g.set(r.l2address,{amount:r.amount,formattedAmount:r.formattedAmount,l2address:r.l2address})}const v=await Promise.all(h.values());const y=Array.from(h.keys());const b=[];v.forEach((e,t)=>{const n=y[t];if(e===void 0)return;b.push(n);const r=g.get(n);if(!r)return;_.push({amount:r.amount,formattedAmount:r.formattedAmount,l2address:r.l2address})});if(b.length===0)return[];if(_.length===0)return[];const x=await Jn(e,n,i,r,yr(e,a,u,_,s),b,c);if(!x)return[];const S=br(a,x);return xr(v,S,f)};const Cr=async(e,t,n)=>{if(![`ERC20`,`NATIVE`].includes(n.type))return void 0;const{required:r,current:i,delta:a}=n;let o=false;(await Xn(e,t)).forEach(e=>{if(!e.address)return;if(!r.token)return;if(K(r.token.address)||U(e.address,r.token.address))o=true});if(!o)return void 0;return{type:`ONRAMP`,chainId:H(e),fundingItem:{type:K(r.token.address)?`NATIVE`:`ERC20`,fundsRequired:{amount:a.balance,formattedAmount:W(a.formattedBalance)},userBalance:{balance:i.balance,formattedBalance:i.formattedBalance},token:r.token}}};const wr=e=>e.bridge||e.swap||e.onRamp;const Tr=e=>{let t=0;let n;for(const r of e.balanceRequirements)if(!r.sufficient){t++;n=r}if(t===1)return n};const Er=async(e,t,n,r,i)=>{let a;if(r===void 0)return void 0;if(r.type!==`NATIVE`&&r.type!==`ERC20`)return;const o={amount:r.delta.balance,formattedAmount:r.delta.formattedBalance,l2address:r.required.token.address??``};if(n.bridge&&r)a=await lr(e,t,n,o,i);return a};const Dr=async(e,t,n,r,i,a,o)=>{const s=[];if(!t.swap)return s;if(n===void 0)return s;if(a===void 0)return s;const c=i.get(H(e));if(!c)return s;if(c.error!==void 0||!c.success)return s;if(a.length===0)return s;const l=a.filter(e=>e.address).map(e=>e.address);if(l.length===0)return s;return await Jn(e,t,r,n,i,l,o)};const Or=async(e,t,n,r,i,a,o,s)=>{if(!r)return[];const c=a.get(V(e));const l=a.get(H(e));if(!c)return[];if(c.error!==void 0||!c.success)return[];if(!l)return[];if(l.error!==void 0||!l.success)return[];const u=(o?.bridge??[]).map(e=>{if(e.address===void 0)return nr;return e.address});const d=o?.swap??[];if(r.type!==`NATIVE`&&r.type!==`ERC20`)return[];return await Sr(e,t,n,r,i,a,u,d,s)};const kr=async(e,t,n)=>{if(!t.onRamp)return void 0;if(n===void 0)return void 0;return await Cr(e,t,n)};const Z={swap:1,bridge:2,onRamp:3,bridgeAndSwap:4};const Q=(e,t,n,r)=>{if(!e)return;let i;if(`bridgeFundingStep`in e&&`swapFundingStep`in e)i=[e.bridgeFundingStep,e.swapFundingStep];else i=[e];const a={priority:t,steps:i};n.push(a);r?.(a)};const Ar=async(e,t,n,r,i)=>{if(!wr(r))return{type:`NO_ROUTE_OPTIONS`,message:`No routing options are available`};let a;try{a=await en(e)}catch(e){throw new O(`Error occurred while creating read only providers`,`PROVIDER_ERROR`,{error:e})}const o=await q(e,`Time to get token balances inside router`,zn(e,a,t,r));const s=await q(e,`Time to get routing allowlist`,$n(e,o,r));const c=Tr(n);const l=[];const u=[];if(r.swap)l.push(Dr(e,r,c,t,o,s.swap,n).then(e=>{e.forEach(e=>{Q(e,Z.swap,u,i)})}));if(r.bridge)l.push(Er(e,a,r,c,o).then(e=>{Q(e,Z.bridge,u,i)}));if(r.onRamp)l.push(kr(e,r,c).then(e=>{Q(e,Z.onRamp,u,i)}));if(r.swap&&r.bridge)l.push(Or(e,a,r,c,t,o,s,n).then(e=>{e.forEach(e=>{Q(e,Z.bridgeAndSwap,u,i)})}));await q(e,`Time to resolve all routes`,Promise.all(l));if(u.length===0)return{type:`NO_ROUTES_FOUND`,message:`Smart Checkout did not find any funding routes to fulfill the transaction`};return{type:`ROUTES_FOUND`,fundingRoutes:u}};const jr=e=>{return{sufficient:false,balanceRequirements:e.balanceRequirements.map(e=>{if(e.type===`ERC20`&&e.sufficient)return{...e,sufficient:false,delta:{balance:e.required.balance,formattedBalance:e.required.formattedBalance}};return e})}};const Mr=async(e,t,n,r,i,a,o,s,c)=>{const l=await q(e,`Total time to run the routing calculator`,Ar(e,t,!o||n&&s?jr(a):a,r,c));s?.({sufficient:n,transactionRequirements:i,router:{availableRoutingOptions:r,routingOutcome:l}});return l};const Nr=async(e,t,n,r,i,a,o,s=false)=>{const c=await(await t.getSigner()).getAddress();let l=sn(n);const u=un(t,c,l);const d=gn(t,c,l);const f=yn(t,c,l);const p=await q(e,`Time to calculate token allowances`,Promise.all([u,d,f]));const m=tn(p[0],p[1],p[2]);let h=null;if(r){h=await q(e,`Time to run gas calculator`,Pn(t,m,r));if(h!==null){l.push(h);l=sn(l)}}const g=await q(e,`Time to run balance checks`,jn(e,t,c,l,true));const{sufficient:_}=g;const v=g.balanceRequirements;const y=await q(e,`Time to fetch available routing options`,Rn(e,t));if(i?.onRamp===false)y.onRamp=false;if(i?.swap===false)y.swap=false;if(i?.bridge===false)y.bridge=false;if(a){Mr(e,c,_,y,v,g,s,a,o);return{sufficient:_,transactionRequirements:v}}if(_)return{sufficient:_,transactionRequirements:v};return{sufficient:_,transactionRequirements:v,router:{availableRoutingOptions:y,routingOutcome:await Mr(e,c,_,y,v,g,s,a,o)}}};function Pr(e){return e?.ethereumProvider?.isPassport===true}function Fr(e){return Pr(e)}const Ir=async(e,t)=>{const n=t;const{chainId:r}=await e.getNetwork();if(!mt(Number(r)))return n;if(typeof n.gasPrice!==`undefined`)return n;if(Fr(e))n.gasPrice=BigInt(0);else{n.maxFeePerGas=Fe.maxFeePerGas;n.maxPriorityFeePerGas=Fe.maxPriorityFeePerGas}return n};const Lr=e=>{if(e.code===`INSUFFICIENT_FUNDS`)return new O(e.message,`INSUFFICIENT_FUNDS`,{error:e});if(e.code===`ACTION_REJECTED`)return new O(e.message,`USER_REJECTED_REQUEST_ERROR`,{error:e});return new O(e.message,`TRANSACTION_FAILED`,{error:e})};const $=async(e,t)=>{try{const n=await e.getSigner();const r=await Ir(e,t);return{transactionResponse:await n.sendTransaction(r)}}catch(e){throw Lr(e)}};const Rr=async(e,t)=>{let n=[];try{const r=await Promise.all(t.map(t=>$(e,t)));n=await Promise.all(r.map(e=>e.transactionResponse.wait()))}catch(e){throw new O(`An error occurred while executing the approval transaction`,`EXECUTE_APPROVAL_TRANSACTION_ERROR`,{error:e})}for(const e of n)if(e?.status===0)return{type:`FAILED`,transactionHash:e.hash,reason:`Approval transaction failed and was reverted`};return{type:`SUCCESS`}};const zr=async(e,t)=>{let n=[];try{const r=await Promise.all(t.map(t=>$(e,t)));n=await Promise.all(r.map(e=>e.transactionResponse.wait()))}catch(e){throw new O(`An error occurred while executing the fulfillment transaction`,`EXECUTE_FULFILLMENT_TRANSACTION_ERROR`,{error:e})}for(const e of n)if(e?.status===0)return{type:`FAILED`,transactionHash:e.hash,reason:`Fulfillment transaction failed and was reverted`};return{type:`SUCCESS`}};const Br=async(e,t)=>{try{const n=await(await e.getSigner()).signTypedData(t.unsignedMessage.domain,t.unsignedMessage.types,t.unsignedMessage.value);return{orderComponents:t.orderComponents,orderHash:t.orderHash,signedMessage:n}}catch(e){throw new O(`An error occurred while signing the message`,`SIGN_MESSAGE_ERROR`,{error:e})}};const Vr=async e=>{let t=[];let n=[];const r=[];const i=[];for(const t of e){if(t.type!==g.TRANSACTION)continue;if(t.purpose===b.APPROVAL)r.push(t.buildTransaction());if(t.purpose===b.FULFILL_ORDER)i.push(t.buildTransaction())}t=await Promise.all(r);n=await Promise.all(i);return{approvalTransactions:t,fulfillmentTransactions:n}};const Hr=async e=>{let t=[];const n=[];for(const t of e){if(t.type!==g.TRANSACTION)continue;if(t.purpose===b.APPROVAL)n.push(t.buildTransaction())}t=await Promise.all(n);return t};const Ur=async e=>{let t=[];const n=[];for(const t of e){if(t.type!==g.TRANSACTION)continue;if(t.purpose===b.FULFILL_ORDER)n.push(t.buildTransaction())}t=await Promise.all(n);return t};const Wr=(e,t,n)=>{let r;for(const e of n){if(e.type!==g.SIGNABLE)continue;if(e.purpose===y.CREATE_LISTING)r={domain:e.message.domain,types:e.message.types,value:e.message.value}}if(!r)return void 0;return{orderHash:e,orderComponents:t,unsignedMessage:r}};const Gr=1;const Kr=6;const qr=(e,t,n=BigInt(1))=>{const r=e.amount;const i=Math.round(r.percentageDecimal*10**6);const a=t*BigInt(i)/BigInt(10**6);return a-a%n};const Jr=(e,t)=>{const n=e.amount;return c(n.token,t)};const Yr=(e,t,n=18,r=BigInt(1))=>{let i=BigInt(0);const a=BigInt(t);const o=a*BigInt(1*10**6)/BigInt(10**6);const s=[];for(const t of e){let e=BigInt(0);if(Object.hasOwn(t.amount,`percentageDecimal`)){e=qr(t,a,r);i+=e}else if(Object.hasOwn(t.amount,`token`)){e=Jr(t,n);i+=e}else throw new O(`Unknown fee type parsed, must be percentageDecimal or token`,`ORDER_FEE_ERROR`);if(i>o)throw new O(`The combined fees are above the allowed maximum of ${1*100}%`,`ORDER_FEE_ERROR`);if(e>0)s.push({amount:e.toString(),recipientAddress:t.recipient})}return s};const Xr=(e,t,n,r,i=false)=>{switch(e){case`ERC20`:return{type:e,amount:n,tokenAddress:t,spenderAddress:r,isFee:i};case`NATIVE`:default:return{type:`NATIVE`,amount:n,isFee:i}}};const Zr=(e,t)=>{if(t.length>0)return{type:`TRANSACTION`,transaction:t[0]};return{type:`GAS`,gasToken:{type:`NATIVE`,limit:BigInt(e)}}};const Qr=async(e,t,n,r={waitFulfillmentSettlements:true})=>{ee(`checkout_sdk`,`buy_initiated`);if(n.length===0)throw new O(`No orders were provided to the orders array. Please provide at least one order.`,`FULFILL_ORDER_LISTING_ERROR`);let i;let a=``;let o=18;const s=x.estimatedFulfillmentGasGwei;const c=Ft(e);const l=It(e);const u=await q(e,`Time to get the address from the provider`,(await t.getSigner()).getAddress());wt();J(e,t,u,V(e));J(e,t,u,H(e));const{id:d,takerFees:f,fillAmount:p}=n[0];let m;try{i=await q(e,`Time to fetch the listing from the orderbook`,c.getListing(d));const{seaportContractAddress:t,chainName:n}=c.config();m=n;a=t}catch(e){throw new O(`An error occurred while getting the order listing`,`GET_ORDER_LISTING_ERROR`,{error:e,orderId:d})}if(i.result.buy.length===0)throw new O(`An error occurred with the get order listing`,`GET_ORDER_LISTING_ERROR`,{orderId:d,message:`No buy side tokens found on order`});const h=i.result.buy[0];if(h.type===`ERC20`){const t=await q(e,`Time to get decimals of token contract for the buy token`,l.getToken({contractAddress:h.contractAddress,chainName:m}));if(t.result.decimals)o=t.result.decimals}let g=[];if(f&&f.length>0){const e=i.result.sell[0].type===`ERC721`?BigInt(1):BigInt(i.result.sell[0].amount);g=Yr(f,h.amount,o,e)}let v=[];let y=[];let b=[];const S=performance.now();try{const{actions:t}=await q(e,`Time to call fulfillOrder from the orderbook`,c.fulfillOrder(d,u,g,p));b=t;v=await q(e,`Time to construct the unsigned approval transactions`,Hr(t))}catch(t){bt(e,`Time to call fulfillOrder from the orderbook`,(performance.now()-S)/1e3);if(t.message.includes(_.EXPIRED))throw new O(`Order is expired`,`ORDER_EXPIRED_ERROR`,{orderId:d});if(!t.message.includes(`The fulfiller does not have the balances needed to fulfill`))throw new O(`Error occurred while trying to fulfill the order`,`FULFILL_ORDER_LISTING_ERROR`,{orderId:d,error:t})}try{y=await q(e,`Time to construct the unsigned fulfillment transactions`,Ur(b))}catch{}let C=BigInt(`0`);let w=`NATIVE`;let T=``;const E=i.result.buy;if(E.length>0)switch(E[0].type){case`NATIVE`:w=`NATIVE`;break;case`ERC20`:w=`ERC20`;T=E[0].contractAddress;break;default:throw new O(`Purchasing token type is unsupported`,`UNSUPPORTED_TOKEN_TYPE_ERROR`,{orderId:d})}E.forEach(e=>{if(e.type!==`ERC721`)C+=BigInt(e.amount)});i.result.fees.forEach(e=>{C+=BigInt(e.amount)});if(i.result.sell[0].type===`ERC1155`&&p)C=C*BigInt(p)/BigInt(i.result.sell[0].amount);const D=await q(e,`Total time running smart checkout`,Nr(e,t,[Xr(w,T,C,a)],Zr(s,y)));if(D.sufficient){const e=await Rr(t,v);if(e.type===`FAILED`)return{status:`FAILED`,transactionHash:e.transactionHash,reason:e.reason,smartCheckoutResult:D};try{if(y.length===0)y=await Ur(b)}catch(e){throw new O(`Error fetching fulfillment transaction`,`FULFILL_ORDER_LISTING_ERROR`,{error:e})}if(r.waitFulfillmentSettlements){const e=await zr(t,y);if(e.type===`FAILED`)return{status:`FAILED`,transactionHash:e.transactionHash,reason:e.reason,smartCheckoutResult:D};return{status:`SUCCESS`,smartCheckoutResult:D}}let n;try{n=(await Promise.all(y.map(e=>$(t,e)))).map(e=>e.transactionResponse)}catch(e){throw new O(`An error occurred while executing the fulfillment transaction`,`EXECUTE_FULFILLMENT_TRANSACTION_ERROR`,{message:e.message})}return{status:`FULFILLMENTS_UNSETTLED`,smartCheckoutResult:D,transactions:n}}return{status:`INSUFFICIENT_FUNDS`,smartCheckoutResult:D}};const $r=async(e,t,n,r,i)=>{let a;if(r.length===0)throw new O(`No orderIds were provided to the orderIds array. Please provide at least one orderId.`,`CANCEL_ORDER_LISTING_ERROR`);const o=r[0];try{const r=await q(e,`Time to get the address from the provider`,(await n.getSigner()).getAddress());a=await(await q(e,`Time to get the cancel order from the orderbook`,t.cancelOrdersOnChain([o],r))).cancellationAction.buildTransaction()}catch(e){throw new O(`An error occurred while cancelling the order listing`,`CANCEL_ORDER_LISTING_ERROR`,{orderId:o,error:e})}if(i){const e=await zr(n,[a]);if(e.type===`FAILED`)return{status:`FAILED`,transactionHash:e.transactionHash,reason:e.reason};return{status:`SUCCESS`}}let s;try{s=(await Promise.all([a].map(e=>$(n,e)))).map(e=>e.transactionResponse)}catch(e){throw new O(`An error occurred while executing the fulfillment transaction`,`EXECUTE_FULFILLMENT_TRANSACTION_ERROR`,{message:e.message})}return{status:`FULFILLMENTS_UNSETTLED`,transactions:s}};const ei=async(e,t,n)=>{try{const r=await t.getSigner();const i=await r.getAddress();const{signableAction:a}=await e.prepareOrderCancellations(n);const o=await r.signTypedData(a.message.domain,a.message.types,a.message.value);const{result:s}=await e.cancelOrders(n,i,o);const c=[];const l=[];const u=[];for(const e of s.successful_cancellations)c.push({orderId:e});for(const e of s.failed_cancellations)l.push({orderId:e.order,reason:e.reason_code});for(const e of s.pending_cancellations)u.push({orderId:e});return{successfulCancellations:c,failedCancellations:l,pendingCancellations:u}}catch(e){throw new O(`An error occurred while cancelling the order listing`,`CANCEL_ORDER_LISTING_ERROR`,{orderIds:n,error:e})}};const ti=async(e,t,n,r={waitFulfillmentSettlements:true,useGaslessCancel:false})=>{const i=Ft(e);if(r.useGaslessCancel)return await ei(i,t,n);return await $r(e,i,t,n,r.waitFulfillmentSettlements??true)};async function ni(e,t){const n=[];t.forEach(t=>{if(t.type===`ERC20`){const{tokenAddress:r}=t;n.push(Lt(r,P,e).decimals())}});const r=await Promise.all(n);return t.map((e,t)=>{if(e.type===`NATIVE`)return{...e,amount:c(e.amount,18)};if(e.type===`ERC20`)return{...e,amount:c(e.amount,r[t])};return e})}const ri=(e,t,n)=>({type:`ERC721`,id:e,contractAddress:t,spenderAddress:n});const ii=(e,t,n,r)=>({type:`ERC1155`,id:e,contractAddress:t,spenderAddress:n,amount:BigInt(r)});const ai=(e,t=18)=>{const n=c(e.amount,t);if(e.type===`NATIVE`)return{type:`NATIVE`,amount:n.toString()};return{type:`ERC20`,amount:n.toString(),contractAddress:e.tokenAddress}};const oi=async(e,t,n)=>{let r;let i;let o=``;ee(`checkout_sdk`,`sell_initiated`);if(n.length===0)throw new O(`No orders were provided to the orders array. Please provide at least one order.`,`PREPARE_ORDER_LISTING_ERROR`);const{buyToken:s,sellToken:c,makerFees:l,orderExpiry:u}=n[0];let d=18;if(s.type===`ERC20`)d=await q(e,`Time to get decimals of token contract for the buy token`,new a(s.tokenAddress,JSON.stringify(P),t).decimals());const f=ai(s,d);const p=`type`in c;try{const n=await q(e,`Time to get the address from the provider`,(await t.getSigner()).getAddress());r=Ft(e);const{seaportContractAddress:a}=r.config();o=a;const s=p&&c.type===`ERC1155`?{type:`ERC1155`,contractAddress:c.collectionAddress,tokenId:c.id,amount:c.amount}:{type:`ERC721`,contractAddress:c.collectionAddress,tokenId:c.id};i=await q(e,`Time to prepare the listing from the orderbook`,r.prepareListing({makerAddress:n,buy:f,sell:s,orderExpiry:u}))}catch(e){throw new O(`An error occurred while preparing the listing`,`PREPARE_ORDER_LISTING_ERROR`,{error:e,id:c.id,collectionAddress:c.collectionAddress})}const m=[];if(p&&c.type===`ERC1155`){const e=ii(c.id,c.collectionAddress,o,c.amount);m.push(e)}else{const e=ri(c.id,c.collectionAddress,o);m.push(e)}let h;if(!Ln(t))h=await q(e,`Total time running smart checkout`,Nr(e,t,m,{type:`GAS`,gasToken:{type:`NATIVE`,limit:BigInt(x.estimatedFulfillmentGasGwei)}}));else h={sufficient:true,transactionRequirements:[]};if(h.sufficient){const e=await Rr(t,(await Vr(i.actions)).approvalTransactions);if(e.type===`FAILED`)return{status:`FAILED`,transactionHash:e.transactionHash,reason:e.reason,smartCheckoutResult:h};const n=Wr(i.orderHash,i.orderComponents,i.actions);if(!n)throw new O(`The unsigned message is missing after preparing the listing`,`SIGN_MESSAGE_ERROR`,{id:c.id,collectionAddress:c.collectionAddress});const a=await Br(t,n);let o=``;const s={orderComponents:a.orderComponents,orderHash:a.orderHash,orderSignature:a.signedMessage,makerFees:[]};if(l!==void 0){let e=BigInt(1);if(p&&c.type===`ERC1155`)e=BigInt(c.amount);const t=Yr(l,f.amount,d,e);if(t.length!==l.length)throw new O(`One of the fees is too small, must be greater than 0.000001`,`CREATE_ORDER_LISTING_ERROR`);s.makerFees=t}try{o=(await r.createListing(s)).result.id}catch(e){throw new O(`An error occurred while creating the listing`,`CREATE_ORDER_LISTING_ERROR`,{error:e,collectionId:c.id,collectionAddress:c.collectionAddress})}return{status:`SUCCESS`,orderIds:[o],smartCheckoutResult:h}}return{status:`INSUFFICIENT_FUNDS`,smartCheckoutResult:h}};const si=async(e,t,n,r,i,a,o,s,l)=>{if(!n.address||n.decimals===0)throw new O(`fromToken address or decimals is missing.`,`MISSING_PARAMS`);if(!r.address||r.decimals===0)throw new O(`toToken address or decimals is missing.`,`MISSING_PARAMS`);if(i&&a)throw new O(`Only one of fromAmount or toAmount can be provided.`,`MISSING_PARAMS`);if(!i&&!a)throw new O(`fromAmount or toAmount must be provided.`,`MISSING_PARAMS`);const u=await Pt(H(e),e);const d=await(await t.getSigner()).getAddress();if(i)return u.getUnsignedSwapTxFromAmountIn(d,n.address,r.address,BigInt(c(i,n.decimals)),o,s,l);return u.getUnsignedSwapTxFromAmountOut(d,n.address,r.address,BigInt(c(a,r.decimals)),o,s,l)};const ci=async(e,t,n,r,i,a,o,s,c)=>{const l=await si(e,t,n,r,i,a,o,s,c);if(l.approval){if((await(await $(t,l.approval.transaction)).transactionResponse.wait())?.status===0)throw new O(`Approval transaction failed and was reverted`,`APPROVAL_TRANSACTION_FAILED`)}const u=await(await $(t,l.swap.transaction)).transactionResponse.wait();if(u?.status===0)throw new O(`Swap transaction failed and was reverted`,`TRANSACTION_FAILED`);return{swapReceipt:u,quote:l.quote,swap:l.swap}};async function li(e){const t=[];const n=e.exclude?.map(e=>e.walletProviderName)??[];let r=Object.values(He);if(n.length!==0)r=r.filter(e=>!n.includes(e));for(const e of r)t.push({walletProviderName:e});return{wallets:t}}const ui=async(e,t)=>Object.fromEntries(e.map(e=>[e.toLowerCase(),{sanctioned:false}]));const di=(e,t)=>false;const fi=(e,t)=>false;const pi=e=>false;const mi={baseConfig:{environment:e.SANDBOX},passport:void 0};var hi=class{readOnlyProviders;httpClient;config;fiatRampService;availability;passport;constructor(e=mi){this.httpClient=new xe(e);this.config=new pt(e,this.httpClient);this.fiatRampService=new jt(this.config);this.readOnlyProviders=new Map;this.availability=Le(this.config.isDevelopment,this.config.isProduction);this.passport=e.passport;Y.getInstance().initialise()}async widgets(e){const t=this;const n=I();try{const r=await import(`https://cdn.jsdelivr.net/npm/@imtbl/checkout-widgets@${I()}/dist/browser/index.js`);if(r&&r.WidgetsFactory)return new r.WidgetsFactory(t,e.config);throw new Error(`WidgetsFactory not found in loaded module for version: ${n}`)}catch(e){throw new O(`Failed to load widgets script`,`WIDGETS_SCRIPT_LOAD_ERROR`,{error:e})}}async createProvider(e){return await Qt(e.walletProviderName,this.passport)}getInjectedProviders(){return Y.getInstance().getProviders()}findInjectedProvider(e){return Y.getInstance().findProvider(e)}onInjectedProvidersChange(e){return Y.getInstance().subscribe(e)}clearInjectedProviders(){return Y.getInstance().clear()}async checkIsWalletConnected(e){const t=await X(this.config,e.provider,{allowMistmatchedChainId:true,allowUnsupportedProvider:true});return Ot(t)}async getRiskAssessment(e){return await ui(e,this.config)}checkIsAddressSanctioned(e,t){return di(e,t)}async connect(e){const t=await X(this.config,e.provider,{allowUnsupportedProvider:true,allowMistmatchedChainId:true});if(e.requestWalletPermissions&&!Pr(t))await At(t);else await kt(t);return t}async addNetwork(e){const t=await X(this.config,e.provider,{allowUnsupportedProvider:true,allowMistmatchedChainId:true});return await nt(this.config.networkMap,t,e.chainId)}async switchNetwork(e){const t=await X(this.config,e.provider,{allowUnsupportedProvider:true,allowMistmatchedChainId:true});return await it(this.config,t,e.chainId)}async getTokenInfo(e){return await _t(e.provider,e.tokenAddress)}async getBalance(e){const t=await X(this.config,e.provider);if(!e.tokenAddress||e.tokenAddress===``)return await xt(this.config,t,e.walletAddress);return await St(t,e.walletAddress,e.tokenAddress)}async getAllBalances(e){const t=!e.provider||`ethereumProvider`in e.provider?e.provider:new L(e.provider);return J(this.config,t,e.walletAddress,e.chainId)}async getNetworkAllowList(e){return await z(this.config,e)}async getTokenAllowList(e){return await G(this.config,e)}async getWalletAllowList(e){return await li(e)}async sendTransaction(e){const t=await X(this.config,e.provider,{allowUnsupportedProvider:true,allowMistmatchedChainId:true});return await $(t,e.transaction)}async providerCall(e,t){const n=await X(this.config,e,{allowUnsupportedProvider:true,allowMistmatchedChainId:true});try{return await t(n)}catch(e){throw Lr(e)}}async getNetworkInfo(e){const t=await X(this.config,e.provider,{allowUnsupportedProvider:true,allowMistmatchedChainId:true});return await B(this.config,t)}async buy(e){if(e.orders.length>1)console.warn(`This endpoint currently only processes the first order in the array.`);const t=await X(this.config,e.provider);return await Qr(this.config,t,e.orders,e.overrides)}async sell(e){if(e.orders.length>1)console.warn(`This endpoint currently only processes the first order in the array.`);const t=await X(this.config,e.provider);return await oi(this.config,t,e.orders)}async cancel(e){console.warn(`This endpoint currently only processes the first order in the array.`);const t=await X(this.config,e.provider);return await ti(this.config,t,e.orderIds,e.overrides)}async smartCheckout(e){const t=await X(this.config,e.provider);let n=[];try{n=await ni(t,e.itemRequirements)}catch(e){throw new O(`Failed to map item requirements`,`ITEM_REQUIREMENTS_ERROR`,{error:e})}return await Nr(this.config,t,n,e.transactionOrGasAmount,e.routingOptions,e.onComplete,e.onFundingRoute,e.fundingRouteFullAmount)}static isWrappedBrowserProvider(e){return $t(e)}async gasEstimate(e){this.readOnlyProviders=await en(this.config,this.readOnlyProviders);return await Ht(e,this.readOnlyProviders,this.config)}async createFiatRampUrl(e){let t;let n=`IMX`;let r;const i=`request`in e.browserProvider?new L(e.browserProvider):e.browserProvider;const a=await(await i.getSigner()).getAddress();const o=i.ethereumProvider?.isPassport||false;if(o&&e.passport)r=(await e.passport.getUserInfo())?.email;const s=await G(this.config,{type:`onramp`});const c=s.tokens?.find(t=>U(t.address,e.tokenAddress));if(c){t=e.tokenAmount;n=c.symbol}const l=s?.tokens?.filter(e=>e.symbol).map(e=>e.symbol);return await this.fiatRampService.createWidgetUrl({exchangeType:e.exchangeType,isPassport:o,walletAddress:a,tokenAmount:t,tokenSymbol:n,email:r,allowedTokens:l,showMenu:e.showMenu,customSubTitle:e.customSubTitle})}async getExchangeFeeEstimate(){return await this.fiatRampService.feeEstimate()}async isSwapAvailable(){return this.availability.checkDexAvailability()}async swap(e){const t=await X(this.config,e.provider);return ci(this.config,t,e.fromToken,e.toToken,e.fromAmount,e.toAmount,e.slippagePercent,e.maxHops,e.deadline)}async swapQuote(e){const t=await X(this.config,e.provider);return si(this.config,t,e.fromToken,e.toToken,e.fromAmount,e.toAmount,e.slippagePercent,e.maxHops,e.deadline)}};var gi=class{static getTransactionLink(e,t){const n=N?.[e]?.url;if(!n||!t)return void 0;return`${n}/tx/${t}`}};export{de as AddTokensEventType,gi as BlockExplorerService,ie as BridgeEventType,Ce as ChainId,we as ChainName,Te as ChainSlug,hi as Checkout,pt as CheckoutConfiguration,O as CheckoutError,Se as CheckoutErrorType,Ge as CheckoutStatus,se as CommerceEventType,le as CommerceFailureEventType,_e as CommerceFlowType,ce as CommerceSuccessEventType,ue as CommerceUserActionEventType,E as ConnectEventType,he as ConnectTargetLayer,Qe as ExchangeType,Xe as FeeType,Ze as FundingStepType,Re as GasEstimateType,Je as GasTokenType,M as IMMUTABLE_API_BASE_URL,w as IMTBLWidgetEvents,Ke as ItemType,ze as NetworkFilterTypes,oe as OnRampEventType,ae as OrchestrationEventType,T as ProviderEventType,fe as PurchaseEventType,Ye as RoutingOutcomeType,ne as SaleEventType,re as SalePaymentTypes,ge as SwapDirection,te as SwapEventType,Be as TokenFilterTypes,qe as TransactionOrGasType,pe as TransferEventType,D as WalletEventType,Ve as WalletFilterTypes,He as WalletProviderName,Ue as WalletProviderRdns,ve as WidgetTheme,me as WidgetType,L as WrappedBrowserProvider,ui as fetchRiskAssessment,Wt as getGasPriceInWei,Xt as getMetaMaskProviderDetail,Yt as getPassportProviderDetail,R as getUnderlyingChainId,di as isAddressSanctioned,fi as isSingleAddressSanctioned,qt as metaMaskProviderInfo,Jt as passportProviderInfo,pi as resultHasSanctionedWallets,X as validateProvider};