@swapkit/api
Advanced tools
Comparing version 0.0.0-nightly-20240924091001 to 0.0.0-nightly-20241007084746
@@ -1,3 +0,3 @@ | ||
var be=Object.defineProperty;var D=(r,t)=>{for(var i in t)be(r,i,{get:t[i],enumerable:!0,configurable:!0,set:(n)=>t[i]=()=>n})};var y={};D(y,{getTNSChainAddress:()=>fe,getTHORNamesByOwner:()=>Ie,getTHORNamesByAddress:()=>Le,getTHORNameDetails:()=>K,getTHORChainPools:()=>He,getLiquidityPositionsRaw:()=>j,getLiquidityPositions:()=>he});import{AssetValue as f,BaseDecimal as h,RequestClient as T,SwapKitNumber as pe}from"@swapkit/helpers";function K(r){return T.get(`${G}/thorname/lookup/${r}`)}function Ie(r){return T.get(`${G}/thorname/owner/${r}`)}function Le(r){return T.get(`${G}/thorname/address/${r}`)}function He(r){return T.get(`${G}/pools`,{searchParams:{period:r}})}function j(r){return T.get(`${G}/fullmember?address=${r.join(",")}`)}async function fe({chain:r,tns:t}){return(await K(t))?.entries?.find((n)=>n.chain.toLowerCase()===r.toLowerCase())?.address}async function he(r){return(await j(r)).map((i)=>({assetRegisteredAddress:i.assetAddress,asset:f.from({asset:i.pool,value:i.assetAdded,fromBaseDecimal:h.THOR}),assetPending:f.from({asset:i.pool,value:i.assetPending,fromBaseDecimal:h.THOR}),assetWithdrawn:f.from({asset:i.pool,value:i.assetWithdrawn,fromBaseDecimal:h.THOR}),runeRegisteredAddress:i.runeAddress,rune:f.from({asset:"THOR.RUNE",value:i.runeAdded,fromBaseDecimal:h.THOR}),runePending:f.from({asset:"THOR.RUNE",value:i.runePending,fromBaseDecimal:h.THOR}),runeWithdrawn:f.from({asset:"THOR.RUNE",value:i.runeWithdrawn,fromBaseDecimal:h.THOR}),poolShare:new pe(i.sharedUnits).div(i.poolUnits),dateLastAdded:i.dateLastAdded,dateFirstAdded:i.dateFirstAdded}))}var G="https://mu.thorswap.net";import{AssetValue as A,BaseDecimal as u,Chain as N,RequestClient as B,SwapKitNumber as X}from"@swapkit/helpers";function w(r=!1){return r?`${F}/v2/mayaname`:`${$}/v2/thorname`}function Q(r,t=!1){return B.get(`${t?F:$}/v2/borrower/${r}`)}function J(r,t=!1){return B.get(`${t?F:$}/v2/saver/${r}`)}function Z(r,t){return B.get(`${t?F:$}/v2/member/${r}`)}function Be(r,t=!1){return B.get(`${w(t)}/lookup/${r}`)}function Pe(r,t=!1){return B.get(`${w(t)}/rlookup/${r}`)}function Ce(r,t=!1){return B.get(`${w(t)}/owner/${r}`)}async function Se(r,t=!1){return(await Q(r,t)).pools.map((n)=>({collateral_deposited:A.from({asset:n.collateral_asset,value:n.collateral_deposited,fromBaseDecimal:u.THOR}),collateral_withdrawn:A.from({asset:n.collateral_asset,value:n.collateral_withdrawn,fromBaseDecimal:u.THOR}),debt_issued_tor:X.fromBigInt(BigInt(n.debt_issued_tor),u.THOR),debt_repaid_tor:X.fromBigInt(BigInt(n.debt_repaid_tor),u.THOR),last_open_loan_timestamp:n.last_open_loan_timestamp,last_repay_loan_timestamp:n.last_repay_loan_timestamp,target_assets:n.target_assets.map((c)=>A.from({asset:c}))}))}async function ce(r,t=!1){return(await J(r,t)).pools.map((n)=>({assetRegisteredAddress:n.assetAddress,assetAdded:A.from({asset:n.pool,value:n.assetAdded,fromBaseDecimal:u.THOR}),assetDeposit:A.from({asset:n.pool,value:n.assetDeposit,fromBaseDecimal:u.THOR}),assetRedeem:A.from({asset:n.pool,value:n.assetRedeem,fromBaseDecimal:u.THOR}),assetWithdrawn:A.from({asset:n.pool,value:n.assetWithdrawn,fromBaseDecimal:u.THOR}),dateLastAdded:n.dateLastAdded,dateFirstAdded:n.dateFirstAdded}))}async function De(r,t=!1){return(await Z(r,t)).pools.map((n)=>({assetRegisteredAddress:n.assetAddress,asset:A.from({asset:n.pool,value:n.assetAdded,fromBaseDecimal:u.THOR}),assetPending:A.from({asset:n.pool,value:n.assetPending,fromBaseDecimal:u.THOR}),assetWithdrawn:A.from({asset:n.pool,value:n.assetWithdrawn,fromBaseDecimal:u.THOR}),[`${t?"cacao":"rune"}RegisteredAddress`]:n.runeAddress,[`${t?"cacao":"rune"}`]:A.from({asset:"THOR.RUNE",value:n.runeAdded,fromBaseDecimal:u.THOR}),[`${t?"cacao":"rune"}Pending`]:A.from({asset:"THOR.RUNE",value:n.runePending,fromBaseDecimal:u.THOR}),[`${t?"cacao":"rune"}Withdrawn`]:A.from({asset:"THOR.RUNE",value:n.runeWithdrawn,fromBaseDecimal:u.THOR}),poolShare:new X(n.liquidityUnits).div(n.pool),dateLastAdded:n.dateLastAdded,dateFirstAdded:n.dateFirstAdded}))}var $="https://midgard.ninerealms.com",F="https://midgard.mayachain.info",O=(r)=>({getBorrowerDetail:(t)=>Se(t,r===N.Maya),getBorrowerDetailRaw:(t)=>Q(t,r===N.Maya),getSaversDetail:(t)=>ce(t,r===N.Maya),getSaverDetailRaw:(t)=>J(t,r===N.Maya),getLiquidityPosition:(t)=>De(t,r===N.Maya),getLiquidityPositionRaw:(t)=>Z(t,r===N.Maya),getNameDetails:(t)=>Be(t,r===N.Maya),getNamesByAddress:(t)=>Pe(t,r===N.Maya),getNamesByOwner:(t)=>Ce(t,r===N.Maya)}),z=O(N.THORChain),_=O(N.Maya);var x={};D(x,{getThorchainQueue:()=>ve,getTNSPreferredAsset:()=>Me,getTHORNodeTNSDetails:()=>R,getRunePoolProviderInfo:()=>Xe,getRunePoolInfo:()=>ye,getNodes:()=>Ue,getMimirInfo:()=>$e,getLastBlock:()=>Ve,getInboundAddresses:()=>Fe});import{AssetValue as Te,RequestClient as p}from"@swapkit/helpers";function I({type:r="thorchain",stagenet:t=!1}={}){switch(r){case"mayachain":return t?"https://stagenet.mayanode.mayachain.info/mayachain":"https://mayanode.mayachain.info/mayachain";default:return t?"https://stagenet-thornode.ninerealms.com/thorchain":"https://thornode.thorswap.net/thorchain"}}function Ge({type:r="thorchain",stagenet:t=!1}={}){const i=r==="mayachain"?"mayaname":"thorname";return`${I({type:r,stagenet:t})}/${i}`}function Ve(r){return p.get(`${I(r)}/lastblock`)}function ve(r){return p.get(`${I(r)}/queue`)}function Ue(r){return p.get(`${I(r)}/nodes`)}function $e(r){return p.get(`${I(r)}/mimir`)}function Fe(r){return p.get(`${I(r)}/inbound_addresses`)}function R(r){return p.get(`${Ge(r)}/${r.name}`)}async function Me(r){const t=await R({name:r});if(!t.preferred_asset||t.preferred_asset===".")return;return Te.from({asyncTokenLookup:!0,asset:t.preferred_asset})}function ye(r){return p.get(`${I(r)}/runepool`)}function Xe(r){return p.get(`${I(r)}/rune_provider/${r.thorAddress}`)}var Y={};D(Y,{getTxnDetails:()=>Je,getTokenListProviders:()=>Ze,getSwapQuote:()=>Ee,getRepayQuote:()=>We,getLoans:()=>je,getLendingAssets:()=>Ke,getGasRates:()=>Qe,getCachedPrices:()=>ke,getBorrowQuote:()=>qe,APIV1RequestClient:()=>V});import{RequestClient as P}from"@swapkit/helpers";import{z as L}from"zod";var we;((o)=>{o.SWAP_TC_TO_TC="SWAP:TC-TC";o.SWAP_ETH_TO_TC="SWAP:ERC20-TC";o.SWAP_TC_TO_ETH="SWAP:TC-ERC20";o.SWAP_ETH_TO_ETH="SWAP:ERC20-ERC20";o.SWAP_AVAX_TO_TC="SWAP:AVAX-TC";o.SWAP_TC_TO_AVAX="SWAP:TC-AVAX";o.SWAP_AVAX_TO_AVAX="SWAP:AVAX-AVAX";o.SWAP_ETH_TO_AVAX="SWAP:ETH-AVAX";o.SWAP_AVAX_TO_ETH="SWAP:AVAX-ETH";o.SWAP_TC_TO_GAIA="SWAP:TC-GAIA";o.SWAP_GAIA_TO_TC="SWAP:GAIA-TC";o.SWAP_TC_TO_BTC="SWAP:TC-BTC";o.SWAP_BTC_TO_TC="SWAP:BTC-TC";o.SWAP_TC_TO_BCH="SWAP:TC-BCH";o.SWAP_BCH_TO_TC="SWAP:BCH-TC";o.SWAP_TC_TO_LTC="SWAP:TC-LTC";o.SWAP_LTC_TO_TC="SWAP:LTC-TC";o.SWAP_TC_TO_DOGE="SWAP:TC-DOGE";o.SWAP_DOGE_TO_TC="SWAP:DOGE-TC";o.TC_STATUS="TC:STATUS";o.TC_TRANSFER="TC:TRANSFER";o.TC_DEPOSIT="TC:DEPOSIT";o.TC_SEND="TC:SEND";o.TC_SWITCH="TC:SWITCH";o.TC_LP_ADD="TC:ADDLIQUIDITY";o.TC_LP_WITHDRAW="TC:WITHDRAW";o.TC_TNS_CREATE="TC:TNS-CREATE";o.TC_TNS_EXTEND="TC:TNS-EXTEND";o.TC_TNS_UPDATE="TC:TNS-UPDATE";o.TC_SAVINGS_ADD="TC:ADDSAVINGS";o.TC_SAVINGS_WITHDRAW="TC:WITHDRAWSAVINGS";o.TC_LENDING_OPEN="TC:LENDINGOPEN";o.TC_LENDING_CLOSE="TC:LENDINGCLOSE";o.ETH_APPROVAL="ETH:APPROVAL";o.ETH_STATUS="ETH:STATUS";o.ETH_TRANSFER_TO_TC="ETH:TRANSFER:IN";o.ETH_TRANSFER_FROM_TC="ETH:TRANSFER:OUT";o.AVAX_APPROVAL="AVAX:APPROVAL";o.AVAX_STATUS="AVAX:STATUS";o.AVAX_TRANSFER_TO_TC="AVAX:TRANSFER:IN";o.AVAX_TRANSFER_FROM_TC="AVAX:TRANSFER:OUT";o.BSC_APPROVAL="BSC:APPROVAL";o.BSC_STATUS="BSC:STATUS";o.BSC_TRANSFER_TO_TC="BSC:TRANSFER:IN";o.BSC_TRANSFER_FROM_TC="BSC:TRANSFER:OUT";o.APPROVAL="APPROVAL";o.STATUS="STATUS";o.TRANSFER_TO_TC="TRANSFER:IN";o.TRANSFER_FROM_TC="TRANSFER:OUT";o.UNSUPPORTED="UNSUPPORTED";o.TC_LENDING="TC:LENDING"})(we||={});var xe;((l)=>{l.PENDING="pending";l.SUCCESS="success";l.CANCELLED="cancelled";l.REFUNDED="refunded";l.REPLACED="replaced";l.ERROR="error";l.UNKNOWN="unknown";l.NOT_STARTED="not_started";l.NOT_FOUND="not_found";l.RETRIES_EXCEEDED="retries_exceeded";l.STREAMING="streaming"})(xe||={});var Ye;((n)=>{n[n.NOT_STARTED=0]="NOT_STARTED";n[n.SUCCESS=1]="SUCCESS";n[n.REFUNDED=2]="REFUNDED"})(Ye||={});var ee;((s)=>{s.INVALID_INPUT_PARAMETERS="1000";s.UNKNOWN_PROVIDERS="1001";s.CANNOT_FIND_INBOUND_ADDRESS="1002";s.NO_INBOUND_ADDRESSES="1003";s.CHAIN_HALTED_OR_UNSUPPORTED="1004";s.MISSING_INPUT_PARAMETER="1005";s.INVALID_TYPE_GENERIC="1100";s.INVALID_NUMBER_STRING="1101";s.INVALID_NUMBER="1102";s.INVALID_BOOLEAN="1103";s.INVALID_OBJECT="1104";s.INVALID_ARRAY="1105";s.SELL_AMOUNT_MUST_BE_POSITIVE_INTEGER="2000";s.SELL_BUY_ASSETS_ARE_THE_SAME="2001";s.MISSING_SOURCE_ADDRESS_FOR_SYNTH="2002";s.AFF_ADDRESS_AND_BPS_OR_NEITHER="2003";s.AFF_ADDRESS_TOO_LONG="2004";s.AFF_BPS_INTEGER_MAX_500="2005";s.SOURCE_ADDRESS_INVALID_FOR_SELL_CHAIN="2006";s.DESTINATION_ADDRESS_INVALID_FOR_BUY_CHAIN="2007";s.PREFERRED_PROVIDER_NOT_SUPPORTED="2008";s.DESTINATION_ADDRESS_SMART_CONTRACT="2009";s.BUY_AMOUNT_MUST_BE_POSITIVE_INTEGER="2010";s.SOURCE_ADDRESS_SMART_CONTRACT="2011";s.SWAP_AMOUNT_TOO_LOW="2012";s.INVALID_PROVIDER="2100";s.MISSING_CROSS_CHAIN_PROVIDER="2101";s.MISSING_AVAX_PROVIDER="2102";s.MISSING_BSC_PROVIDER="2103";s.MISSING_ETH_PROVIDER="2104";s.INVALID_PROVIDER_FOR_SWAP_OUT="2105";s.MISSING_ARB_PROVIDER="2106";s.INVALID_CHAIN="2200";s.INVALID_ASSET="2201";s.INVALID_ASSET_IDENTIFIER="2202";s.UNSUPPORTED_CHAIN="2204";s.UNSUPPORTED_ASSET="2203";s.UNSUPPORTED_ASSET_FOR_SWAPOUT="2205";s.INVALID_SOURCE_ADDRESS="2300";s.INVALID_DESTINATION_ADDRESS="2301";s.THORNODE_QUOTE_GENERIC_ERROR="3000";s.NOT_ENOUGH_SYNTH_BALANCE="3001";s.SYNTH_MINTING_CAP_REACHED="3002";s.INVALID_QUOTE_MODE="4000";s.NO_QUOTES="4001";s.SERVICE_UNAVAILABLE_GENERIC="5000";s.MISSING_GAS_DATA_GENERIC="5100";s.MISSING_TOKEN_INFO_GENERIC="5200";s.CANT_FIND_TOKEN_LIST="5201";s.NO_PRICE="5202";s.PRICE_IS_STALE="5203";s.ADDRESS_NOT_WHITELISTED="6000";s.ADDRESS_ALREADY_CLAIMED="6001";s.TEMPORARY_ERROR="9999"})(ee||={});var re;((d)=>{d.HEALTH_CONTROLLER="1000";d.LIQUIDITY_CONTROLLER="1001";d.PROVIDER_CONTROLLER="1002";d.QUOTE_CONTROLLER="1003";d.SWAP_CONTROLLER="1004";d.UTIL_CONTROLLER="1005";d.AIRDROP_CONTROLLER="1006";d.PROVIDER="2000";d.ASSET="2001";d.TOKEN_LIST="2002";d.QUOTE="2100";d.QUOTE_TXN_DETAILS="2101";d.THORCHAIN_PROVIDER="3000";d.UNISWAPV2_ETH_PROVIDER="3001";d.UNISWAPV3_ETH_PROVIDER="3002";d.SUSHISWAP_ETH_PROVIDER="3003";d.PANCAKESWAP_BSC_PROVIDER="3004";d.PANCAKESWAP_ETH_PROVIDER="3005";d.ONEINCH_ETH_PROVIDER="3006";d.ONEINCH_BSC_PROVIDER="3007";d.ONEINCH_AVAX_PROVIDER="3008";d.ZEROX_ETH_PROVIDER="3009";d.WOOFI_AVAX_PROVIDER="3010";d.PANGOLIN_AVAX_PROVIDER="3011";d.TRADERJOE_AVAX_PROVIDER="3012";d.KYBER_ETH_PROVIDER="3013";d.KYBER_AVAX_PROVIDER="3014";d.WOOFI_BSC_PROVIDER="3015";d.STARGATE_PROVIDER="3016";d.PROVIDER_UTIL="4000";d.TXN_DETAILS="5000";d.AIRDROP_UTIL="6000"})(re||={});var te;((g)=>{g.VALIDATION_ERROR="VALIDATION_ERROR";g.REQUEST_PARAMETER_ERROR="REQUEST_PARAMETER_ERROR";g.RESPONSE_PARSING_ERROR="RESPONSE_PARSING_ERROR";g.UNSUPPORTED="UNSUPPORTED";g.NOT_IMPLEMENTED="NOT_IMPLEMENTED";g.INCOMPATIBLE_ASSETS_OPERATIONS="INCOMPATIBLE_ASSETS_OPERATIONS";g.SERVICE_UNAVAILABLE="SERVICE_UNAVAILABLE";g.DOWN_FOR_MAINTENANCE="DOWN_FOR_MAINTENANCE";g.MISSING_INBOUND_INFO="MISSING_INBOUND_INFO";g.QUOTE_FETCHING_ERROR="QUOTE_FETCHING_ERROR";g.AIRDROP_ERROR="AIRDROP_ERROR";g.UNHANDLED_ERROR="UNHANDLED_ERROR"})(te||={});var ne=L.object({status:L.number(),type:L.nativeEnum(te),code:L.nativeEnum(ee),module:L.nativeEnum(re),complete:L.string(),identifier:L.string(),message:L.string()});function ke({tokens:r,...t}){const i=new URLSearchParams,n=r.filter((c,H,le)=>le.findIndex((Ne)=>Ne===c)===H);for(let c of n)i.append("tokens",JSON.stringify(c));if(t.metadata)i.append("metadata","true");if(t.lookup)i.append("lookup","true");if(t.sparkline)i.append("sparkline","true");return V.post(`${b}/tokenlist/cached-price`,{body:i.toString(),headers:{"Content-Type":"application/x-www-form-urlencoded"}})}function Ee(r){return V.get(`${b}/aggregator/tokens/quote`,{searchParams:r})}function qe(r){return V.get(`${b}/aggregator/lending/borrow`,{searchParams:r})}function We(r){return V.get(`${b}/aggregator/lending/repay`,{searchParams:r})}function Ke(){return P.get(`${b}/aggregator/lending/assets`)}function je(r){return P.get(`${b}/aggregator/lending/loans`,{searchParams:r})}function Qe(){return P.get(`${b}/resource-worker/gasPrice/getAll`)}function Je(r){return P.get(`${b}/apiusage/v2/txn`,{searchParams:{txHash:r}})}function Ze(){return P.get(`${b}/tokenlist/providers`)}var b="https://api.thorswap.finance",V=P.extend({responseHandler:(r)=>{try{return ne.parse(r)}catch(t){return r}}});var E={};D(E,{getTrackerDetails:()=>br,getTokenListV2:()=>Ir,getTokenListProvidersV2:()=>k,getSwapQuoteV2:()=>pr,getPrice:()=>Lr});import{RequestClient as v,SwapKitError as Ae}from"@swapkit/helpers";import{Chain as Oe,ChainId as ze,FeeTypeEnum as _e,ProviderName as S,WarningCodeEnum as Re}from"@swapkit/helpers";import{z as e}from"zod";var se;((a)=>{a.native_send="native_send";a.token_transfer="token_transfer";a.native_contract_call="native_contract_call";a.token_contract_call="token_contract_call";a.approve="approve";a.deposit="deposit";a.thorname_action="thorname_action";a.lp_action="lp_action";a.swap="swap";a.streaming_swap="streaming_swap";a.stake="stake";a.claim="claim";a.lending="lending";a.unknown="unknown"})(se||={});var oe;((H)=>{H.unknown="unknown";H.not_started="not_started";H.pending="pending";H.swappping="swapping";H.completed="completed"})(oe||={});var ie;((m)=>{m.not_started="not_started";m.starting="starting";m.broadcasted="broadcasted";m.mempool="mempool";m.inbound="inbound";m.outbound="outbound";m.swapping="swapping";m.completed="completed";m.refunded="refunded";m.partially_refunded="partially_refunded";m.dropped="dropped";m.reverted="reverted";m.replaced="replaced";m.retries_exceeded="retries_exceeded";m.parsing_error="parsing_error"})(ie||={});var Xr=e.object({error:e.string(),message:e.string()}),C=e.object({chain:e.nativeEnum(Oe),symbol:e.string(),ticker:e.string(),decimal:e.optional(e.number()),address:e.optional(e.string()),isGasAsset:e.boolean(),isSynthetic:e.boolean(),tax:e.optional(e.object({buy:e.number(),sell:e.number()}))}),er=e.object({name:e.string(),id:e.string(),market_cap:e.number(),total_volume:e.number(),price_change_24h_usd:e.number(),price_change_percentage_24h_usd:e.number(),timestamp:e.number()}),de=e.array(e.object({identifier:e.string(),provider:e.string(),cg:er.optional(),price_usd:e.number(),timestamp:e.number()}).partial()),wr=e.object({sellAsset:e.string({description:"Asset to sell"}),buyAsset:e.string({description:"Asset to buy"}),sellAmount:e.string({description:"Amount of asset to sell"}).refine((r)=>+r>0,{message:"sellAmount must be greater than 0",path:["sellAmount"]}),providers:e.optional(e.array(e.string({description:"List of providers to use"}).refine((r)=>{return S[r]!==void 0},{message:"Invalid provider",path:["providers"]}))),sourceAddress:e.optional(e.string({description:"Address to send asset from"})),destinationAddress:e.optional(e.string({description:"Address to send asset to"})),slippage:e.optional(e.number({description:"Slippage tolerance as a percentage. Default is 3%."})),affiliate:e.optional(e.string({description:"Affiliate thorname"})),affiliateFee:e.optional(e.number({description:"Affiliate fee in basis points"}).refine((r)=>{return r===Math.floor(r)&&r>=0},{message:"affiliateFee must be a positive integer",path:["affiliateFee"]})),allowSmartContractSender:e.optional(e.boolean({description:"Allow smart contract as sender"})),allowSmartContractReceiver:e.optional(e.boolean({description:"Allow smart contract as recipient"})),disableSecurityChecks:e.optional(e.boolean({description:"Disable security checks"})),includeTx:e.optional(e.boolean({description:"Set to true to include an transaction object (EVM only)"}))}).refine((r)=>r.sellAsset!==r.buyAsset,{message:"Must be different",path:["sellAsset","buyAsset"]}),xr=e.object({tokens:e.array(e.object({identifier:e.string()})),metadata:e.boolean()}),rr=e.object({evmCalldata:e.optional(e.string()),logs:e.optional(e.unknown()),memo:e.optional(e.string()),spender:e.optional(e.string())}),tr=e.object({estimatedfinalisedAt:e.number(),estimatedTimeToComplete:e.number(),updatedAt:e.number(),currentLegIndex:e.optional(e.number()),providerDetails:e.optional(e.unknown())}),nr=e.object({network:e.optional(C),affiliate:e.optional(C),liquidity:e.optional(C),protocol:e.optional(C),tax:e.optional(C)}),sr=e.object({broadcastedAt:e.optional(e.number()),wallet:e.optional(e.string()),quoteId:e.optional(e.string()),explorerUrl:e.optional(e.string()),affiliate:e.optional(e.string()),fees:e.optional(nr),provider:e.optional(e.nativeEnum(S)),images:e.optional(e.object({from:e.optional(e.string()),to:e.optional(e.string()),provider:e.optional(e.string()),chain:e.optional(e.string())}))}),M=e.object({chainId:e.nativeEnum(ze),hash:e.string(),block:e.number(),type:e.nativeEnum(se),status:e.nativeEnum(oe),trackingStatus:e.optional(e.nativeEnum(ie)),fromAsset:e.string(),fromAmount:e.string(),fromAddress:e.string(),toAsset:e.string(),toAmount:e.string(),toAddress:e.string(),finalAsset:e.optional(C),finalAddress:e.optional(e.string()),finalisedAt:e.number(),transient:e.optional(tr),meta:e.optional(sr),payload:e.optional(rr)}),Yr=M.extend({legs:e.array(M)}),kr=M.extend({legs:e.array(M)}),me=e.array(e.object({type:e.nativeEnum(_e),amount:e.string(),asset:e.string(),chain:e.string(),protocol:e.nativeEnum(S)})),ae=e.object({inbound:e.optional(e.number({description:"Time to receive inbound asset in seconds"})),swap:e.optional(e.number({description:"Time to swap assets in seconds"})),outbound:e.optional(e.number({description:"Time to receive outbound asset in seconds"})),total:e.number({description:"Total time in seconds"})}),or=e.object({to:e.string({description:"Address of the recipient"}),from:e.string({description:"Address of the sender"}),value:e.string({description:"Value to send"}),data:e.string({description:"Data to send"})}),ir=e.array(e.union([e.string(),e.number(),e.array(e.string()),e.object({from:e.string(),value:e.string()}).describe("Parameters to pass to the contract method")])),Er=e.object({contractAddress:e.string({description:"Address of the contract to interact with"}),contractMethod:e.string({description:"Name of the method to call"}),contractParams:ir,contractParamNames:e.array(e.string({description:"Names of the parameters to pass to the contract method"})),approvalToken:e.optional(e.string({description:"Address of the token to approve spending of"})),approvalSpender:e.optional(e.string({description:"Address of the spender to approve"}))}),dr=e.object({sellAsset:e.string({description:"Asset to sell"}),buyAsset:e.string({description:"Asset to buy"}),provider:e.nativeEnum(S),sourceAddress:e.string({description:"Source address"}),destinationAddress:e.string({description:"Destination address"}),estimatedTime:ae.optional(),affiliate:e.string({description:"Affiliate address"}).optional(),affiliateFee:e.number({description:"Affiliate fee"}).optional(),slipPercentage:e.number({description:"Slippage as a percentage"})}),qr=dr.omit({sourceAddress:!0,destinationAddress:!0,slipPercentage:!0}),mr=e.object({asset:e.string({description:"Asset name"}),price:e.number({description:"Price in USD"}),image:e.string({description:"Asset image"})}),ar=e.object({priceImpact:e.optional(e.number({description:"Price impact"})),assets:e.optional(e.array(mr)),approvalAddress:e.optional(e.string({description:"Approval address for swap"})),streamingInterval:e.number().optional(),maxStreamingQuantity:e.number().optional()}),ur=e.array(e.object({code:e.nativeEnum(Re),display:e.string(),tooltip:e.string().optional()})),Ar=e.object({provider:e.nativeEnum(S),sellAsset:e.string({description:"Asset to sell"}),sellAmount:e.string({description:"Sell amount"}),buyAsset:e.string({description:"Asset to buy"}),buyAmount:e.string({description:"Buy amount"}),buyAmountMaxSlippage:e.string({description:"Buy amount max slippage"}),fees:e.optional(me)}),gr=e.object({providers:e.array(e.nativeEnum(S)),sellAsset:e.string({description:"Asset to sell"}),sellAmount:e.string({description:"Sell amount"}),buyAsset:e.string({description:"Asset to buy"}),expectedBuyAmount:e.string({description:"Expected Buy amount"}),expectedBuyAmountMaxSlippage:e.string({description:"Expected Buy amount max slippage"}),sourceAddress:e.string({description:"Source address"}),destinationAddress:e.string({description:"Destination address"}),targetAddress:e.optional(e.string({description:"Target address"})),inboundAddress:e.optional(e.string({description:"Inbound address"})),expiration:e.optional(e.string({description:"Expiration"})),memo:e.optional(e.string({description:"Memo"})),fees:me,tx:e.optional(or),transaction:e.optional(e.unknown()),estimatedTime:e.optional(ae),totalSlippageBps:e.number({description:"Total slippage in bps"}),legs:e.array(Ar),warnings:ur,meta:ar}),ue=e.object({quoteId:e.string({description:"Quote ID"}),routes:e.array(gr),error:e.optional(e.string({description:"Error message"}))});function U(r){return r?Nr:lr}function br(r){return v.post(`${U()}/track`,{json:r})}async function pr(r,t){const i=await v.post(`${U(t)}/quote`,{json:r});if(i.error)throw new Ae("api_v2_server_error",{message:i.error});try{return ue.parse(i)}catch(n){return console.warn(n),i}}function k(r=!1){return v.get(`${U(r)}/providers`)}function Ir(r,t=!1){return v.get(`${U(t)}/tokens?provider=${r}`)}async function Lr(r,t=!1){const i=await v.post(`${U(t)}/price`,{json:r});try{return de.parse(i)}catch(n){throw new Ae("api_v2_invalid_response",n)}}var lr="https://api.swapkit.dev",Nr="https://dev-api.swapkit.dev";var W={};D(W,{getTokenList:()=>Br,getProviderLogo:()=>Sr,getLogoForAsset:()=>Pr,getChainLogoForAsset:()=>Cr});import{AssetValue as Hr,RequestClient as fr,getChainIdentifier as hr}from"@swapkit/helpers";function Br(r){return fr.get(`${q}/token-list/${r}.json`)}function Pr(r){return`${q}/token-list/images/${r.toLowerCase()}.png`}function Cr(r){const{chain:t}=Hr.from({asset:r}),i=hr(t).toLowerCase();return`${q}/token-list/images/${i}.png`}async function Sr(r){return ge||=await k(),ge.find((t)=>t.name===r)?.url}var q="https://static.thorswap.net",ge;var Or={...y,...x,...Y,...E,...W,thorchainMidgard:z,mayachainMidgard:_};export{se as TxnType,oe as TxnStatus,xe as TxStatus,we as TransactionType,Yr as TransactionSchema,kr as TransactionDTOSchema,ie as TrackingStatus,er as TokenDetailsMetadataSchema,Or as SwapKitApi,Ye as StreamingSwapProgressStatus,ur as RouteQuoteWarningSchema,ar as RouteQuoteMetadataSchema,mr as RouteQuoteMetadataAssetSchema,qr as RouteLegWithoutAddressesSchema,dr as RouteLegSchema,ue as QuoteResponseSchema,wr as QuoteRequestSchema,de as PriceResponseSchema,xr as PriceRequestSchema,me as FeesSchema,ae as EstimatedTimeSchema,or as EVMTransactionSchema,Er as EVMTransactionDetailsSchema,ir as EVMTransactionDetailsParamsSchema,te as ERROR_TYPE,re as ERROR_MODULE,ee as ERROR_CODE,C as AssetValueSchema,Xr as ApiV2ErrorSchema,ne as ApiV1ErrorSchema}; | ||
var fe=Object.defineProperty;var U=(r,t)=>{for(var i in t)fe(r,i,{get:t[i],enumerable:!0,configurable:!0,set:(n)=>t[i]=()=>n})};var k={};U(k,{getTNSChainAddress:()=>Se,getTHORNamesByOwner:()=>Be,getTHORNamesByAddress:()=>Ce,getTHORNameDetails:()=>_,getTHORChainPools:()=>Pe,getLiquidityPositionsRaw:()=>R,getLiquidityPositions:()=>ce});import{AssetValue as S,BaseDecimal as c,RequestClient as $,SwapKitNumber as he}from"@swapkit/helpers";function _(r){return $.get(`${F}/thorname/lookup/${r}`)}function Be(r){return $.get(`${F}/thorname/owner/${r}`)}function Ce(r){return $.get(`${F}/thorname/address/${r}`)}function Pe(r){return $.get(`${F}/pools`,{searchParams:{period:r}})}function R(r){return $.get(`${F}/fullmember?address=${r.join(",")}`)}async function Se({chain:r,tns:t}){return(await _(t))?.entries?.find((n)=>n.chain.toLowerCase()===r.toLowerCase())?.address}async function ce(r){return(await R(r)).map((i)=>({assetRegisteredAddress:i.assetAddress,asset:S.from({asset:i.pool,value:i.assetAdded,fromBaseDecimal:c.THOR}),assetPending:S.from({asset:i.pool,value:i.assetPending,fromBaseDecimal:c.THOR}),assetWithdrawn:S.from({asset:i.pool,value:i.assetWithdrawn,fromBaseDecimal:c.THOR}),runeRegisteredAddress:i.runeAddress,rune:S.from({asset:"THOR.RUNE",value:i.runeAdded,fromBaseDecimal:c.THOR}),runePending:S.from({asset:"THOR.RUNE",value:i.runePending,fromBaseDecimal:c.THOR}),runeWithdrawn:S.from({asset:"THOR.RUNE",value:i.runeWithdrawn,fromBaseDecimal:c.THOR}),poolShare:new he(i.sharedUnits).div(i.poolUnits),dateLastAdded:i.dateLastAdded,dateFirstAdded:i.dateFirstAdded}))}var F="https://mu.thorswap.net";import{AssetValue as l,BaseDecimal as g,Chain as I,RequestClient as D,SwapKitNumber as E}from"@swapkit/helpers";function K(r=!1){return r?`${x}/v2/mayaname`:`${v}/v2/thorname`}function ee(r,t=!1){return D.get(`${t?x:v}/v2/borrower/${r}`)}function re(r,t=!1){return D.get(`${t?x:v}/v2/saver/${r}`)}function te(r,t){return D.get(`${t?x:v}/v2/member/${r}`)}function De(r,t=!1){return D.get(`${K(t)}/lookup/${r}`)}function Ge(r,t=!1){return D.get(`${K(t)}/rlookup/${r}`)}function Te(r,t=!1){return D.get(`${K(t)}/owner/${r}`)}async function Ve(r,t=!1){return(await ee(r,t)).pools.map((n)=>({collateral_deposited:l.from({asset:n.collateral_asset,value:n.collateral_deposited,fromBaseDecimal:g.THOR}),collateral_withdrawn:l.from({asset:n.collateral_asset,value:n.collateral_withdrawn,fromBaseDecimal:g.THOR}),debt_issued_tor:E.fromBigInt(BigInt(n.debt_issued_tor),g.THOR),debt_repaid_tor:E.fromBigInt(BigInt(n.debt_repaid_tor),g.THOR),last_open_loan_timestamp:n.last_open_loan_timestamp,last_repay_loan_timestamp:n.last_repay_loan_timestamp,target_assets:n.target_assets.map((H)=>l.from({asset:H}))}))}async function Ue(r,t=!1){return(await re(r,t)).pools.map((n)=>({assetRegisteredAddress:n.assetAddress,assetAdded:l.from({asset:n.pool,value:n.assetAdded,fromBaseDecimal:g.THOR}),assetDeposit:l.from({asset:n.pool,value:n.assetDeposit,fromBaseDecimal:g.THOR}),assetRedeem:l.from({asset:n.pool,value:n.assetRedeem,fromBaseDecimal:g.THOR}),assetWithdrawn:l.from({asset:n.pool,value:n.assetWithdrawn,fromBaseDecimal:g.THOR}),dateLastAdded:n.dateLastAdded,dateFirstAdded:n.dateFirstAdded}))}async function $e(r,t=!1){return(await te(r,t)).pools.map((n)=>({assetRegisteredAddress:n.assetAddress,asset:l.from({asset:n.pool,value:n.assetAdded,fromBaseDecimal:g.THOR}),assetPending:l.from({asset:n.pool,value:n.assetPending,fromBaseDecimal:g.THOR}),assetWithdrawn:l.from({asset:n.pool,value:n.assetWithdrawn,fromBaseDecimal:g.THOR}),[`${t?"cacao":"rune"}RegisteredAddress`]:n.runeAddress,[`${t?"cacao":"rune"}`]:l.from({asset:"THOR.RUNE",value:n.runeAdded,fromBaseDecimal:g.THOR}),[`${t?"cacao":"rune"}Pending`]:l.from({asset:"THOR.RUNE",value:n.runePending,fromBaseDecimal:g.THOR}),[`${t?"cacao":"rune"}Withdrawn`]:l.from({asset:"THOR.RUNE",value:n.runeWithdrawn,fromBaseDecimal:g.THOR}),poolShare:new E(n.liquidityUnits).div(n.pool),dateLastAdded:n.dateLastAdded,dateFirstAdded:n.dateFirstAdded}))}var v="https://midgard.ninerealms.com",x="https://midgard.mayachain.info",ne=(r)=>({getBorrowerDetail:(t)=>Ve(t,r===I.Maya),getBorrowerDetailRaw:(t)=>ee(t,r===I.Maya),getSaversDetail:(t)=>Ue(t,r===I.Maya),getSaverDetailRaw:(t)=>re(t,r===I.Maya),getLiquidityPosition:(t)=>$e(t,r===I.Maya),getLiquidityPositionRaw:(t)=>te(t,r===I.Maya),getNameDetails:(t)=>De(t,r===I.Maya),getNamesByAddress:(t)=>Ge(t,r===I.Maya),getNamesByOwner:(t)=>Te(t,r===I.Maya)}),se=ne(I.THORChain),oe=ne(I.Maya);var j={};U(j,{getThorchainQueue:()=>Xe,getTNSPreferredAsset:()=>Ye,getTHORNodeTNSDetails:()=>ie,getRunePoolProviderInfo:()=>We,getRunePoolInfo:()=>qe,getNodes:()=>we,getMimirInfo:()=>ve,getLastBlock:()=>ye,getInboundAddresses:()=>xe});import{AssetValue as Fe,RequestClient as h}from"@swapkit/helpers";function B({type:r="thorchain",stagenet:t=!1}={}){switch(r){case"mayachain":return t?"https://stagenet.mayanode.mayachain.info/mayachain":"https://mayanode.mayachain.info/mayachain";default:return t?"https://stagenet-thornode.ninerealms.com/thorchain":"https://thornode.thorswap.net/thorchain"}}function Me({type:r="thorchain",stagenet:t=!1}={}){const i=r==="mayachain"?"mayaname":"thorname";return`${B({type:r,stagenet:t})}/${i}`}function ye(r){return h.get(`${B(r)}/lastblock`)}function Xe(r){return h.get(`${B(r)}/queue`)}function we(r){return h.get(`${B(r)}/nodes`)}function ve(r){return h.get(`${B(r)}/mimir`)}function xe(r){return h.get(`${B(r)}/inbound_addresses`)}function ie(r){return h.get(`${Me(r)}/${r.name}`)}async function Ye(r){const t=await ie({name:r});if(!t.preferred_asset||t.preferred_asset===".")return;return Fe.from({asyncTokenLookup:!0,asset:t.preferred_asset})}function qe(r){return h.get(`${B(r)}/runepool`)}function We(r){return h.get(`${B(r)}/rune_provider/${r.thorAddress}`)}var Q={};U(Q,{getTxnDetails:()=>Re,getTokenListProviders:()=>er,getSwapQuote:()=>Qe,getRepayQuote:()=>Ze,getLoans:()=>Oe,getLendingAssets:()=>ze,getGasRates:()=>_e,getCachedPrices:()=>je,getBorrowQuote:()=>Je,APIV1RequestClient:()=>M});import{RequestClient as G}from"@swapkit/helpers";import{z as C}from"zod";var ke;((o)=>{o.SWAP_TC_TO_TC="SWAP:TC-TC";o.SWAP_ETH_TO_TC="SWAP:ERC20-TC";o.SWAP_TC_TO_ETH="SWAP:TC-ERC20";o.SWAP_ETH_TO_ETH="SWAP:ERC20-ERC20";o.SWAP_AVAX_TO_TC="SWAP:AVAX-TC";o.SWAP_TC_TO_AVAX="SWAP:TC-AVAX";o.SWAP_AVAX_TO_AVAX="SWAP:AVAX-AVAX";o.SWAP_ETH_TO_AVAX="SWAP:ETH-AVAX";o.SWAP_AVAX_TO_ETH="SWAP:AVAX-ETH";o.SWAP_TC_TO_GAIA="SWAP:TC-GAIA";o.SWAP_GAIA_TO_TC="SWAP:GAIA-TC";o.SWAP_TC_TO_BTC="SWAP:TC-BTC";o.SWAP_BTC_TO_TC="SWAP:BTC-TC";o.SWAP_TC_TO_BCH="SWAP:TC-BCH";o.SWAP_BCH_TO_TC="SWAP:BCH-TC";o.SWAP_TC_TO_LTC="SWAP:TC-LTC";o.SWAP_LTC_TO_TC="SWAP:LTC-TC";o.SWAP_TC_TO_DOGE="SWAP:TC-DOGE";o.SWAP_DOGE_TO_TC="SWAP:DOGE-TC";o.TC_STATUS="TC:STATUS";o.TC_TRANSFER="TC:TRANSFER";o.TC_DEPOSIT="TC:DEPOSIT";o.TC_SEND="TC:SEND";o.TC_SWITCH="TC:SWITCH";o.TC_LP_ADD="TC:ADDLIQUIDITY";o.TC_LP_WITHDRAW="TC:WITHDRAW";o.TC_TNS_CREATE="TC:TNS-CREATE";o.TC_TNS_EXTEND="TC:TNS-EXTEND";o.TC_TNS_UPDATE="TC:TNS-UPDATE";o.TC_SAVINGS_ADD="TC:ADDSAVINGS";o.TC_SAVINGS_WITHDRAW="TC:WITHDRAWSAVINGS";o.TC_LENDING_OPEN="TC:LENDINGOPEN";o.TC_LENDING_CLOSE="TC:LENDINGCLOSE";o.ETH_APPROVAL="ETH:APPROVAL";o.ETH_STATUS="ETH:STATUS";o.ETH_TRANSFER_TO_TC="ETH:TRANSFER:IN";o.ETH_TRANSFER_FROM_TC="ETH:TRANSFER:OUT";o.AVAX_APPROVAL="AVAX:APPROVAL";o.AVAX_STATUS="AVAX:STATUS";o.AVAX_TRANSFER_TO_TC="AVAX:TRANSFER:IN";o.AVAX_TRANSFER_FROM_TC="AVAX:TRANSFER:OUT";o.BSC_APPROVAL="BSC:APPROVAL";o.BSC_STATUS="BSC:STATUS";o.BSC_TRANSFER_TO_TC="BSC:TRANSFER:IN";o.BSC_TRANSFER_FROM_TC="BSC:TRANSFER:OUT";o.APPROVAL="APPROVAL";o.STATUS="STATUS";o.TRANSFER_TO_TC="TRANSFER:IN";o.TRANSFER_FROM_TC="TRANSFER:OUT";o.UNSUPPORTED="UNSUPPORTED";o.TC_LENDING="TC:LENDING"})(ke||={});var Ee;((A)=>{A.PENDING="pending";A.SUCCESS="success";A.CANCELLED="cancelled";A.REFUNDED="refunded";A.REPLACED="replaced";A.ERROR="error";A.UNKNOWN="unknown";A.NOT_STARTED="not_started";A.NOT_FOUND="not_found";A.RETRIES_EXCEEDED="retries_exceeded";A.STREAMING="streaming"})(Ee||={});var Ke;((n)=>{n[n.NOT_STARTED=0]="NOT_STARTED";n[n.SUCCESS=1]="SUCCESS";n[n.REFUNDED=2]="REFUNDED"})(Ke||={});var me;((s)=>{s.INVALID_INPUT_PARAMETERS="1000";s.UNKNOWN_PROVIDERS="1001";s.CANNOT_FIND_INBOUND_ADDRESS="1002";s.NO_INBOUND_ADDRESSES="1003";s.CHAIN_HALTED_OR_UNSUPPORTED="1004";s.MISSING_INPUT_PARAMETER="1005";s.INVALID_TYPE_GENERIC="1100";s.INVALID_NUMBER_STRING="1101";s.INVALID_NUMBER="1102";s.INVALID_BOOLEAN="1103";s.INVALID_OBJECT="1104";s.INVALID_ARRAY="1105";s.SELL_AMOUNT_MUST_BE_POSITIVE_INTEGER="2000";s.SELL_BUY_ASSETS_ARE_THE_SAME="2001";s.MISSING_SOURCE_ADDRESS_FOR_SYNTH="2002";s.AFF_ADDRESS_AND_BPS_OR_NEITHER="2003";s.AFF_ADDRESS_TOO_LONG="2004";s.AFF_BPS_INTEGER_MAX_500="2005";s.SOURCE_ADDRESS_INVALID_FOR_SELL_CHAIN="2006";s.DESTINATION_ADDRESS_INVALID_FOR_BUY_CHAIN="2007";s.PREFERRED_PROVIDER_NOT_SUPPORTED="2008";s.DESTINATION_ADDRESS_SMART_CONTRACT="2009";s.BUY_AMOUNT_MUST_BE_POSITIVE_INTEGER="2010";s.SOURCE_ADDRESS_SMART_CONTRACT="2011";s.SWAP_AMOUNT_TOO_LOW="2012";s.INVALID_PROVIDER="2100";s.MISSING_CROSS_CHAIN_PROVIDER="2101";s.MISSING_AVAX_PROVIDER="2102";s.MISSING_BSC_PROVIDER="2103";s.MISSING_ETH_PROVIDER="2104";s.INVALID_PROVIDER_FOR_SWAP_OUT="2105";s.MISSING_ARB_PROVIDER="2106";s.INVALID_CHAIN="2200";s.INVALID_ASSET="2201";s.INVALID_ASSET_IDENTIFIER="2202";s.UNSUPPORTED_CHAIN="2204";s.UNSUPPORTED_ASSET="2203";s.UNSUPPORTED_ASSET_FOR_SWAPOUT="2205";s.INVALID_SOURCE_ADDRESS="2300";s.INVALID_DESTINATION_ADDRESS="2301";s.THORNODE_QUOTE_GENERIC_ERROR="3000";s.NOT_ENOUGH_SYNTH_BALANCE="3001";s.SYNTH_MINTING_CAP_REACHED="3002";s.INVALID_QUOTE_MODE="4000";s.NO_QUOTES="4001";s.SERVICE_UNAVAILABLE_GENERIC="5000";s.MISSING_GAS_DATA_GENERIC="5100";s.MISSING_TOKEN_INFO_GENERIC="5200";s.CANT_FIND_TOKEN_LIST="5201";s.NO_PRICE="5202";s.PRICE_IS_STALE="5203";s.ADDRESS_NOT_WHITELISTED="6000";s.ADDRESS_ALREADY_CLAIMED="6001";s.TEMPORARY_ERROR="9999"})(me||={});var ue;((m)=>{m.HEALTH_CONTROLLER="1000";m.LIQUIDITY_CONTROLLER="1001";m.PROVIDER_CONTROLLER="1002";m.QUOTE_CONTROLLER="1003";m.SWAP_CONTROLLER="1004";m.UTIL_CONTROLLER="1005";m.AIRDROP_CONTROLLER="1006";m.PROVIDER="2000";m.ASSET="2001";m.TOKEN_LIST="2002";m.QUOTE="2100";m.QUOTE_TXN_DETAILS="2101";m.THORCHAIN_PROVIDER="3000";m.UNISWAPV2_ETH_PROVIDER="3001";m.UNISWAPV3_ETH_PROVIDER="3002";m.SUSHISWAP_ETH_PROVIDER="3003";m.PANCAKESWAP_BSC_PROVIDER="3004";m.PANCAKESWAP_ETH_PROVIDER="3005";m.ONEINCH_ETH_PROVIDER="3006";m.ONEINCH_BSC_PROVIDER="3007";m.ONEINCH_AVAX_PROVIDER="3008";m.ZEROX_ETH_PROVIDER="3009";m.WOOFI_AVAX_PROVIDER="3010";m.PANGOLIN_AVAX_PROVIDER="3011";m.TRADERJOE_AVAX_PROVIDER="3012";m.KYBER_ETH_PROVIDER="3013";m.KYBER_AVAX_PROVIDER="3014";m.WOOFI_BSC_PROVIDER="3015";m.STARGATE_PROVIDER="3016";m.PROVIDER_UTIL="4000";m.TXN_DETAILS="5000";m.AIRDROP_UTIL="6000"})(ue||={});var de;((N)=>{N.VALIDATION_ERROR="VALIDATION_ERROR";N.REQUEST_PARAMETER_ERROR="REQUEST_PARAMETER_ERROR";N.RESPONSE_PARSING_ERROR="RESPONSE_PARSING_ERROR";N.UNSUPPORTED="UNSUPPORTED";N.NOT_IMPLEMENTED="NOT_IMPLEMENTED";N.INCOMPATIBLE_ASSETS_OPERATIONS="INCOMPATIBLE_ASSETS_OPERATIONS";N.SERVICE_UNAVAILABLE="SERVICE_UNAVAILABLE";N.DOWN_FOR_MAINTENANCE="DOWN_FOR_MAINTENANCE";N.MISSING_INBOUND_INFO="MISSING_INBOUND_INFO";N.QUOTE_FETCHING_ERROR="QUOTE_FETCHING_ERROR";N.AIRDROP_ERROR="AIRDROP_ERROR";N.UNHANDLED_ERROR="UNHANDLED_ERROR"})(de||={});var Ae=C.object({status:C.number(),type:C.nativeEnum(de),code:C.nativeEnum(me),module:C.nativeEnum(ue),complete:C.string(),identifier:C.string(),message:C.string()});function je({tokens:r,...t}){const i=new URLSearchParams,n=r.filter((H,p,W)=>W.findIndex((u)=>u===H)===p);for(let H of n)i.append("tokens",JSON.stringify(H));if(t.metadata)i.append("metadata","true");if(t.lookup)i.append("lookup","true");if(t.sparkline)i.append("sparkline","true");return M.post(`${L}/tokenlist/cached-price`,{body:i.toString(),headers:{"Content-Type":"application/x-www-form-urlencoded"}})}function Qe(r){return M.get(`${L}/aggregator/tokens/quote`,{searchParams:r})}function Je(r){return M.get(`${L}/aggregator/lending/borrow`,{searchParams:r})}function Ze(r){return M.get(`${L}/aggregator/lending/repay`,{searchParams:r})}function ze(){return G.get(`${L}/aggregator/lending/assets`)}function Oe(r){return G.get(`${L}/aggregator/lending/loans`,{searchParams:r})}function _e(){return G.get(`${L}/resource-worker/gasPrice/getAll`)}function Re(r){return G.get(`${L}/apiusage/v2/txn`,{searchParams:{txHash:r}})}function er(){return G.get(`${L}/tokenlist/providers`)}var L="https://api.thorswap.finance",M=G.extend({responseHandler:(r)=>{try{return Ae.parse(r)}catch(t){return r}}});var Z={};U(Z,{getTrackerDetails:()=>fr,getTokenTradingPairs:()=>Cr,getTokenListV2:()=>Le,getTokenListProvidersV2:()=>J,getSwapQuoteV2:()=>hr,getPrice:()=>Br});import{ProviderName as b,RequestClient as y,SwapKitError as q}from"@swapkit/helpers";import{Chain as rr,ChainId as tr,FeeTypeEnum as nr,ProviderName as V,WarningCodeEnum as sr}from"@swapkit/helpers";import{z as e}from"zod";var ae;((a)=>{a.native_send="native_send";a.token_transfer="token_transfer";a.native_contract_call="native_contract_call";a.token_contract_call="token_contract_call";a.approve="approve";a.deposit="deposit";a.thorname_action="thorname_action";a.lp_action="lp_action";a.swap="swap";a.streaming_swap="streaming_swap";a.stake="stake";a.claim="claim";a.lending="lending";a.unknown="unknown"})(ae||={});var ge;((p)=>{p.unknown="unknown";p.not_started="not_started";p.pending="pending";p.swappping="swapping";p.completed="completed"})(ge||={});var le;((d)=>{d.not_started="not_started";d.starting="starting";d.broadcasted="broadcasted";d.mempool="mempool";d.inbound="inbound";d.outbound="outbound";d.swapping="swapping";d.completed="completed";d.refunded="refunded";d.partially_refunded="partially_refunded";d.dropped="dropped";d.reverted="reverted";d.replaced="replaced";d.retries_exceeded="retries_exceeded";d.parsing_error="parsing_error"})(le||={});var Wr=e.object({error:e.string(),message:e.string()}),T=e.object({chain:e.nativeEnum(rr),symbol:e.string(),ticker:e.string(),decimal:e.optional(e.number()),address:e.optional(e.string()),isGasAsset:e.boolean(),isSynthetic:e.boolean(),tax:e.optional(e.object({buy:e.number(),sell:e.number()}))}),or=e.object({name:e.string(),id:e.string(),market_cap:e.number(),total_volume:e.number(),price_change_24h_usd:e.number(),price_change_percentage_24h_usd:e.number(),timestamp:e.string(),sparkline_in_7d:e.array(e.number())}),be=e.array(e.object({identifier:e.string(),provider:e.string(),cg:or.optional(),price_usd:e.number(),timestamp:e.number()}).partial()),kr=e.object({sellAsset:e.string({description:"Asset to sell"}),buyAsset:e.string({description:"Asset to buy"}),sellAmount:e.string({description:"Amount of asset to sell"}).refine((r)=>+r>0,{message:"sellAmount must be greater than 0",path:["sellAmount"]}),providers:e.optional(e.array(e.string({description:"List of providers to use"}).refine((r)=>{return V[r]!==void 0},{message:"Invalid provider",path:["providers"]}))),sourceAddress:e.optional(e.string({description:"Address to send asset from"})),destinationAddress:e.optional(e.string({description:"Address to send asset to"})),slippage:e.optional(e.number({description:"Slippage tolerance as a percentage. Default is 3%."})),affiliate:e.optional(e.string({description:"Affiliate thorname"})),affiliateFee:e.optional(e.number({description:"Affiliate fee in basis points"}).refine((r)=>{return r===Math.floor(r)&&r>=0},{message:"affiliateFee must be a positive integer",path:["affiliateFee"]})),allowSmartContractSender:e.optional(e.boolean({description:"Allow smart contract as sender"})),allowSmartContractReceiver:e.optional(e.boolean({description:"Allow smart contract as recipient"})),disableSecurityChecks:e.optional(e.boolean({description:"Disable security checks"})),includeTx:e.optional(e.boolean({description:"Set to true to include an transaction object (EVM only)"}))}).refine((r)=>r.sellAsset!==r.buyAsset,{message:"Must be different",path:["sellAsset","buyAsset"]}),Er=e.object({tokens:e.array(e.object({identifier:e.string()})),metadata:e.boolean()}),ir=e.object({evmCalldata:e.optional(e.string()),logs:e.optional(e.unknown()),memo:e.optional(e.string()),spender:e.optional(e.string())}),mr=e.object({estimatedfinalisedAt:e.number(),estimatedTimeToComplete:e.number(),updatedAt:e.number(),currentLegIndex:e.optional(e.number()),providerDetails:e.optional(e.unknown())}),ur=e.object({network:e.optional(T),affiliate:e.optional(T),liquidity:e.optional(T),protocol:e.optional(T),tax:e.optional(T)}),dr=e.object({broadcastedAt:e.optional(e.number()),wallet:e.optional(e.string()),quoteId:e.optional(e.string()),explorerUrl:e.optional(e.string()),affiliate:e.optional(e.string()),fees:e.optional(ur),provider:e.optional(e.nativeEnum(V)),images:e.optional(e.object({from:e.optional(e.string()),to:e.optional(e.string()),provider:e.optional(e.string()),chain:e.optional(e.string())}))}),Y=e.object({chainId:e.nativeEnum(tr),hash:e.string(),block:e.number(),type:e.nativeEnum(ae),status:e.nativeEnum(ge),trackingStatus:e.optional(e.nativeEnum(le)),fromAsset:e.string(),fromAmount:e.string(),fromAddress:e.string(),toAsset:e.string(),toAmount:e.string(),toAddress:e.string(),finalAsset:e.optional(T),finalAddress:e.optional(e.string()),finalisedAt:e.number(),transient:e.optional(mr),meta:e.optional(dr),payload:e.optional(ir)}),Kr=Y.extend({legs:e.array(Y)}),jr=Y.extend({legs:e.array(Y)}),Ne=e.array(e.object({type:e.nativeEnum(nr),amount:e.string(),asset:e.string(),chain:e.string(),protocol:e.nativeEnum(V)})),Ie=e.object({inbound:e.optional(e.number({description:"Time to receive inbound asset in seconds"})),swap:e.optional(e.number({description:"Time to swap assets in seconds"})),outbound:e.optional(e.number({description:"Time to receive outbound asset in seconds"})),total:e.number({description:"Total time in seconds"})}),Ar=e.object({to:e.string({description:"Address of the recipient"}),from:e.string({description:"Address of the sender"}),value:e.string({description:"Value to send"}),data:e.string({description:"Data to send"})}),ar=e.array(e.union([e.string(),e.number(),e.array(e.string()),e.object({from:e.string(),value:e.string()}).describe("Parameters to pass to the contract method")])),Qr=e.object({contractAddress:e.string({description:"Address of the contract to interact with"}),contractMethod:e.string({description:"Name of the method to call"}),contractParams:ar,contractParamNames:e.array(e.string({description:"Names of the parameters to pass to the contract method"})),approvalToken:e.optional(e.string({description:"Address of the token to approve spending of"})),approvalSpender:e.optional(e.string({description:"Address of the spender to approve"}))}),gr=e.object({sellAsset:e.string({description:"Asset to sell"}),buyAsset:e.string({description:"Asset to buy"}),provider:e.nativeEnum(V),sourceAddress:e.string({description:"Source address"}),destinationAddress:e.string({description:"Destination address"}),estimatedTime:Ie.optional(),affiliate:e.string({description:"Affiliate address"}).optional(),affiliateFee:e.number({description:"Affiliate fee"}).optional(),slipPercentage:e.number({description:"Slippage as a percentage"})}),Jr=gr.omit({sourceAddress:!0,destinationAddress:!0,slipPercentage:!0}),lr=e.object({asset:e.string({description:"Asset name"}),price:e.number({description:"Price in USD"}),image:e.string({description:"Asset image"})}),br=e.object({priceImpact:e.optional(e.number({description:"Price impact"})),assets:e.optional(e.array(lr)),approvalAddress:e.optional(e.string({description:"Approval address for swap"})),streamingInterval:e.number().optional(),maxStreamingQuantity:e.number().optional()}),Nr=e.array(e.object({code:e.nativeEnum(sr),display:e.string(),tooltip:e.string().optional()})),Ir=e.object({provider:e.nativeEnum(V),sellAsset:e.string({description:"Asset to sell"}),sellAmount:e.string({description:"Sell amount"}),buyAsset:e.string({description:"Asset to buy"}),buyAmount:e.string({description:"Buy amount"}),buyAmountMaxSlippage:e.string({description:"Buy amount max slippage"}),fees:e.optional(Ne)}),pr=e.object({providers:e.array(e.nativeEnum(V)),sellAsset:e.string({description:"Asset to sell"}),sellAmount:e.string({description:"Sell amount"}),buyAsset:e.string({description:"Asset to buy"}),expectedBuyAmount:e.string({description:"Expected Buy amount"}),expectedBuyAmountMaxSlippage:e.string({description:"Expected Buy amount max slippage"}),sourceAddress:e.string({description:"Source address"}),destinationAddress:e.string({description:"Destination address"}),targetAddress:e.optional(e.string({description:"Target address"})),inboundAddress:e.optional(e.string({description:"Inbound address"})),expiration:e.optional(e.string({description:"Expiration"})),memo:e.optional(e.string({description:"Memo"})),fees:Ne,tx:e.optional(Ar),transaction:e.optional(e.unknown()),estimatedTime:e.optional(Ie),totalSlippageBps:e.number({description:"Total slippage in bps"}),legs:e.array(Ir),warnings:Nr,meta:br}),pe=e.object({quoteId:e.string({description:"Quote ID"}),routes:e.array(pr),error:e.optional(e.string({description:"Error message"}))});function X(r){return r?Hr:Lr}function fr(r){return y.post(`${X()}/track`,{json:r})}async function hr(r,t){const i=await y.post(`${X(t)}/quote`,{json:r});if(i.error)throw new q("api_v2_server_error",{message:i.error});try{const n=pe.safeParse(i);if(!n.success)throw new q("api_v2_invalid_response",n.error);return n.data}catch(n){return console.warn(n),i}}function J(r=!1){return y.get(`${X(r)}/providers`)}function Le(r,t=!1){return y.get(`${X(t)}/tokens?provider=${r}`)}async function Br(r,t=!1){const i=await y.post(`${X(t)}/price`,{json:r});try{const n=be.safeParse(i);if(!n.success)throw new q("api_v2_invalid_response",n.error);return n.data}catch(n){throw new q("api_v2_invalid_response",n)}}async function Cr(r,t=!1){const i=new Map;if(!r.length)return i;const n=r.map(async(u)=>{return await Le(u,t)}),H=(await Promise.all(n)).filter((u)=>!!u).map(({tokens:u,...f})=>({data:{...f||{},tokens:u.map(({address:P,...w})=>({...w,...P&&["resource_rdx1tknxxxxxxxxxradxrdxxxxxxxxx009923554798xxxxxxxxxradxrd","0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee"].includes(P.toLowerCase())?{}:{address:P}}))},...f})),p=[b.CAVIAR_V1,b.CHAINFLIP,b.MAYACHAIN,b.MAYACHAIN_STREAMING],W=H.filter(({data:u})=>{return!p.includes(u?.provider||"")}).reduce((u,{data:f})=>f?.tokens?u.concat(f.tokens):u,[]);for(let{data:u}of H){if(!u?.tokens)return;const f=u.provider&&!p.includes(u.provider);for(let P of u.tokens){const w=i.get(P.identifier.toLowerCase())||{tokens:[],providers:[]},A=f?{tokens:W,providers:[b.THORCHAIN,b.THORCHAIN_STREAMING,b.PANCAKESWAP,b.ONEINCH,b.PANGOLIN_V1,b.SUSHISWAP_V2,b.TRADERJOE_V2,b.UNISWAP_V3,b.UNISWAP_V2]}:{tokens:u.tokens,providers:u.provider};i.set(P.identifier.toLowerCase(),{tokens:w.tokens.concat(A.tokens),providers:w.providers.concat(A.providers)})}}return i}var Lr="https://api.swapkit.dev",Hr="https://dev-api.swapkit.dev";var O={};U(O,{getTokenList:()=>Dr,getProviderLogo:()=>Vr,getLogoForAsset:()=>Gr,getChainLogoForAsset:()=>Tr});import{AssetValue as Pr,RequestClient as Sr,getChainIdentifier as cr}from"@swapkit/helpers";function Dr(r){return Sr.get(`${z}/token-list/${r}.json`)}function Gr(r){return`${z}/token-list/images/${r.toLowerCase()}.png`}function Tr(r){const{chain:t}=Pr.from({asset:r}),i=cr(t).toLowerCase();return`${z}/token-list/images/${i}.png`}async function Vr(r){return He||=await J(),He.find((t)=>t.name===r)?.url}var z="https://static.thorswap.net",He;var rt={...k,...j,...Q,...Z,...O,thorchainMidgard:se,mayachainMidgard:oe};export{ae as TxnType,ge as TxnStatus,Ee as TxStatus,ke as TransactionType,Kr as TransactionSchema,jr as TransactionDTOSchema,le as TrackingStatus,or as TokenDetailsMetadataSchema,rt as SwapKitApi,Ke as StreamingSwapProgressStatus,Nr as RouteQuoteWarningSchema,br as RouteQuoteMetadataSchema,lr as RouteQuoteMetadataAssetSchema,Jr as RouteLegWithoutAddressesSchema,gr as RouteLegSchema,pe as QuoteResponseSchema,kr as QuoteRequestSchema,be as PriceResponseSchema,Er as PriceRequestSchema,Ne as FeesSchema,Ie as EstimatedTimeSchema,Ar as EVMTransactionSchema,Qr as EVMTransactionDetailsSchema,ar as EVMTransactionDetailsParamsSchema,de as ERROR_TYPE,ue as ERROR_MODULE,me as ERROR_CODE,T as AssetValueSchema,Wr as ApiV2ErrorSchema,Ae as ApiV1ErrorSchema}; | ||
//# debugId=719437A95E366D5B64756E2164756E21 | ||
//# debugId=995E722858C1C9DB64756E2164756E21 |
{ | ||
"author": "swapkit-oss", | ||
"dependencies": { | ||
"@swapkit/helpers": "0.0.0-nightly-20240924091001", | ||
"@swapkit/helpers": "0.0.0-nightly-20241007084746", | ||
"zod": "3.23.8" | ||
@@ -31,3 +31,3 @@ }, | ||
"types": "./src/index.ts", | ||
"version": "0.0.0-nightly-20240924091001" | ||
"version": "0.0.0-nightly-20241007084746" | ||
} |
@@ -1,2 +0,2 @@ | ||
import { type ProviderName, RequestClient, SwapKitError } from "@swapkit/helpers"; | ||
import { ProviderName, RequestClient, SwapKitError } from "@swapkit/helpers"; | ||
import { | ||
@@ -36,3 +36,9 @@ type PriceRequest, | ||
try { | ||
return QuoteResponseSchema.parse(response); | ||
const parsedResponse = QuoteResponseSchema.safeParse(response); | ||
if (!parsedResponse.success) { | ||
throw new SwapKitError("api_v2_invalid_response", parsedResponse.error); | ||
} | ||
return parsedResponse.data; | ||
} catch (error) { | ||
@@ -59,3 +65,9 @@ // throw new SwapKitError("api_v2_invalid_response", error); | ||
try { | ||
return PriceResponseSchema.parse(response); | ||
const parsedResponse = PriceResponseSchema.safeParse(response); | ||
if (!parsedResponse.success) { | ||
throw new SwapKitError("api_v2_invalid_response", parsedResponse.error); | ||
} | ||
return parsedResponse.data; | ||
} catch (error) { | ||
@@ -65,1 +77,90 @@ throw new SwapKitError("api_v2_invalid_response", error); | ||
} | ||
// TODO update this once the trading pairs are supported by BE api | ||
export async function getTokenTradingPairs(providers: ProviderName[], isDev = false) { | ||
const tradingPairs = new Map< | ||
string, | ||
{ | ||
tokens: TokensResponseV2["tokens"]; | ||
providers: ProviderName[]; | ||
} | ||
>(); | ||
if (!providers.length) return tradingPairs; | ||
const providerRequests = providers.map(async (provider) => { | ||
const tokenList = await getTokenListV2(provider, isDev); | ||
return tokenList; | ||
}); | ||
const providersData = (await Promise.all(providerRequests)) | ||
.filter((provider) => !!provider) | ||
.map(({ tokens, ...rest }) => ({ | ||
data: { | ||
...(rest || {}), | ||
tokens: tokens.map(({ address, ...rest }) => ({ | ||
...rest, | ||
...(address && | ||
[ | ||
"resource_rdx1tknxxxxxxxxxradxrdxxxxxxxxx009923554798xxxxxxxxxradxrd", | ||
"0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee", | ||
].includes(address.toLowerCase()) | ||
? {} | ||
: { address }), | ||
})), | ||
}, | ||
...rest, | ||
})); | ||
const UNCHAINABLE_PROVIDERS = [ | ||
ProviderName.CAVIAR_V1, | ||
ProviderName.CHAINFLIP, | ||
ProviderName.MAYACHAIN, | ||
ProviderName.MAYACHAIN_STREAMING, | ||
]; | ||
const chainableTokens = providersData | ||
.filter(({ data }) => { | ||
return !UNCHAINABLE_PROVIDERS.includes((data?.provider || "") as ProviderName); | ||
}) | ||
.reduce( | ||
(acc, { data }) => (data?.tokens ? acc.concat(data.tokens) : acc), | ||
[] as TokensResponseV2["tokens"], | ||
); | ||
for (const { data } of providersData) { | ||
if (!data?.tokens) return; | ||
const isProviderChainable = | ||
data.provider && !UNCHAINABLE_PROVIDERS.includes(data.provider as ProviderName); | ||
for (const token of data.tokens) { | ||
const existingTradingPairs = tradingPairs.get(token.identifier.toLowerCase()) || { | ||
tokens: [], | ||
providers: [], | ||
}; | ||
const tradingPairsForToken = isProviderChainable | ||
? { | ||
tokens: chainableTokens, | ||
providers: [ | ||
ProviderName.THORCHAIN, | ||
ProviderName.THORCHAIN_STREAMING, | ||
ProviderName.PANCAKESWAP, | ||
ProviderName.ONEINCH, | ||
ProviderName.PANGOLIN_V1, | ||
ProviderName.SUSHISWAP_V2, | ||
ProviderName.TRADERJOE_V2, | ||
ProviderName.UNISWAP_V3, | ||
ProviderName.UNISWAP_V2, | ||
], | ||
} | ||
: { tokens: data.tokens, providers: data.provider }; | ||
tradingPairs.set(token.identifier.toLowerCase(), { | ||
tokens: existingTradingPairs.tokens.concat(tradingPairsForToken.tokens), | ||
providers: existingTradingPairs.providers.concat(tradingPairsForToken.providers), | ||
}); | ||
} | ||
} | ||
return tradingPairs; | ||
} |
@@ -151,3 +151,4 @@ import { | ||
price_change_percentage_24h_usd: z.number(), | ||
timestamp: z.number(), | ||
timestamp: z.string(), | ||
sparkline_in_7d: z.array(z.number()), | ||
}); | ||
@@ -154,0 +155,0 @@ |
Sorry, the diff of this file is not supported yet
169379
2226
+ Added@swapkit/helpers@0.0.0-nightly-20241007084746(transitive)
+ Added@swapkit/tokens@1.8.1(transitive)
- Removed@swapkit/helpers@0.0.0-nightly-20240924091001(transitive)
- Removed@swapkit/tokens@1.8.0(transitive)