@swapkit/helpers 1.0.0-rc.1 → 1.0.0-rc.2

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.
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var le=Object.create;var H=Object.defineProperty;var ue=Object.getOwnPropertyDescriptor;var he=Object.getOwnPropertyNames;var de=Object.getPrototypeOf,me=Object.prototype.hasOwnProperty;var ge=(n,e,t)=>e in n?H(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var _e=(n,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of he(e))!me.call(n,s)&&s!==t&&H(n,s,{get:()=>e[s],enumerable:!(i=ue(e,s))||i.enumerable});return n};var pe=(n,e,t)=>(t=n!=null?le(de(n)):{},_e(e||!n||!n.__esModule?H(t,"default",{value:n,enumerable:!0}):t,n));var m=(n,e,t)=>(ge(n,typeof e!="symbol"?e+"":e,t),t),Ce=(n,e,t)=>{if(!e.has(n))throw TypeError("Cannot "+t)};var p=(n,e,t)=>{if(e.has(n))throw TypeError("Cannot add the same private member more than once");e instanceof WeakSet?e.add(n):e.set(n,t)};var h=(n,e,t)=>(Ce(n,e,"access private method"),t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("@swapkit/types"),fe=n=>{if(n<0)throw new Error("Invalid number of year");return 10+n},Ae=n=>{if(n.length>30)return!1;const e=/^[a-zA-Z0-9+_-]+$/g;return!!n.match(e)},we=([n,e,t,i,s])=>`${n}'/${e}'/${t}'/${i}${typeof s!="number"?"":`/${s}`}`,Se=async(n,e)=>{const t=Object.entries(e||{}).reduce((s,[r,c])=>(c&&(s[r]=c),s),{});return(await fetch(`${n}${e?`?${new URLSearchParams(t).toString()}`:""}`,{method:"GET",mode:"cors",credentials:"omit",referrer:"https://sk.thorswap.net"})).json()},z=async(n,e,t,i=!1)=>{const s=await fetch(`${n}`,{body:e,headers:t,method:"POST",referrer:"https://sk.thorswap.net"});return i?s.text():s.json()},$e="0x313ce567",X=async({chain:n,to:e})=>{try{const t=await z(a.ChainToRPC[n],JSON.stringify({method:"eth_call",params:[{to:e.toLowerCase(),data:$e},"latest"],id:44,jsonrpc:"2.0"}),{accept:"*/*","cache-control":"no-cache","content-type":"application/json"},!0),{result:i}=JSON.parse(t);return parseInt(BigInt(i).toString())}catch(t){return console.error(t),a.BaseDecimal[n]}},be=async n=>{if(n===a.Chain.Ethereum)return a.BaseDecimal.ETH;const[,e]=n.split("-");return e!=null&&e.startsWith("0x")?X({chain:a.Chain.Ethereum,to:e}):a.BaseDecimal.ETH},ye=async n=>{const[,e]=n.split("-");return e!=null&&e.startsWith("0x")?X({chain:a.Chain.Avalanche,to:e.toLowerCase()}):a.BaseDecimal.AVAX},Be=async n=>(n===a.Chain.BinanceSmartChain,a.BaseDecimal.BSC),j=async({chain:n,symbol:e})=>{switch(n){case a.Chain.Ethereum:return be(e);case a.Chain.Avalanche:return ye(e);case a.Chain.BinanceSmartChain:return Be(e);default:return a.BaseDecimal[n]}},Te={[a.FeeOption.Average]:1.2,[a.FeeOption.Fast]:1.5,[a.FeeOption.Fastest]:2},J=({chain:n,symbol:e})=>{switch(n){case a.Chain.Bitcoin:case a.Chain.BitcoinCash:case a.Chain.Litecoin:case a.Chain.Dogecoin:case a.Chain.Binance:case a.Chain.Ethereum:case a.Chain.Avalanche:return e===n;case a.Chain.Arbitrum:case a.Chain.Optimism:return e==="ETH";case a.Chain.Maya:return e==="CACAO";case a.Chain.Cosmos:return e==="ATOM";case a.Chain.Polygon:return e==="MATIC";case a.Chain.BinanceSmartChain:return e==="BNB";case a.Chain.THORChain:return e==="RUNE"}},K=n=>{switch(n){case"ETH.THOR":return{identifier:"ETH.THOR-0xa5f2211b9b8170f694421f2046281775e8468044",decimal:18};case"ETH.vTHOR":return{identifier:"ETH.vTHOR-0x815c23eca83261b6ec689b60cc4a58b54bc24d8d",decimal:18};case a.Chain.Cosmos:return{identifier:"GAIA.ATOM",decimal:a.BaseDecimal[n]};case a.Chain.THORChain:return{identifier:"THOR.RUNE",decimal:a.BaseDecimal[n]};case a.Chain.BinanceSmartChain:return{identifier:"BSC.BNB",decimal:a.BaseDecimal[n]};case a.Chain.Maya:return{identifier:"MAYA.CACAO",decimal:a.BaseDecimal.MAYA};case"MAYA.MAYA":return{identifier:"MAYA.MAYA",decimal:4};case a.Chain.Arbitrum:case a.Chain.Optimism:case a.Chain.BitcoinCash:case a.Chain.Litecoin:case a.Chain.Dogecoin:case a.Chain.Binance:case a.Chain.Avalanche:case a.Chain.Polygon:case a.Chain.Bitcoin:case a.Chain.Ethereum:return{identifier:`${n}.${n}`,decimal:a.BaseDecimal[n]}}},Q=({chain:n,symbol:e})=>{if(e.includes("/"))return"Synth";switch(n){case a.Chain.Bitcoin:case a.Chain.BitcoinCash:case a.Chain.Dogecoin:case a.Chain.Litecoin:case a.Chain.Maya:case a.Chain.THORChain:return"Native";case a.Chain.Cosmos:return e==="ATOM"?"Native":"GAIA";case a.Chain.Binance:return e===a.Chain.Binance?"Native":"BEP2";case a.Chain.BinanceSmartChain:return e===a.Chain.Binance?"Native":"BEP20";case a.Chain.Ethereum:return e===a.Chain.Ethereum?"Native":"ERC20";case a.Chain.Avalanche:return e===a.Chain.Avalanche?"Native":"AVAX";case a.Chain.Polygon:return e===a.Chain.Polygon?"Native":"POLYGON";case a.Chain.Arbitrum:return[a.Chain.Ethereum,a.Chain.Arbitrum].includes(e)?"Native":"ARBITRUM";case a.Chain.Optimism:return[a.Chain.Ethereum,a.Chain.Optimism].includes(e)?"Native":"OPTIMISM"}},Ie=n=>{var c;const[e,...t]=n.split("."),i=n.includes("/"),s=t.join("."),r=(c=s==null?void 0:s.split("-"))==null?void 0:c[0];return{chain:e,symbol:s,ticker:r,synth:i}},Z=({liquidityUnits:n,poolUnits:e,runeDepth:t})=>{const i=d(n),s=d(e),r=d(t),c=i.mul(r),o=s.mul(s).mul(2),u=s.mul(i).mul(2),l=i.mul(i),g=s.mul(s).mul(s);return c.mul(o.sub(u).add(l)).div(g)},ee=({liquidityUnits:n,poolUnits:e,assetDepth:t})=>{const i=d(n),s=d(e),r=d(t),c=i.mul(r),o=s.mul(s).mul(2),u=s.mul(i).mul(2),l=i.mul(i),g=c.mul(o.sub(u).add(l)),C=s.mul(s).mul(s);return g.div(C)},ve=({percent:n,runeDepth:e,liquidityUnits:t,poolUnits:i})=>Z({runeDepth:e,liquidityUnits:t,poolUnits:i}).mul(n),Me=({percent:n,assetDepth:e,liquidityUnits:t,poolUnits:i})=>ee({assetDepth:e,liquidityUnits:t,poolUnits:i}).mul(n),d=n=>new ae({value:n,decimal:a.BaseDecimal.THOR}),te=({liquidityUnits:n,poolUnits:e,runeDepth:t,assetDepth:i})=>({assetAmount:d(i).mul(n).div(e),runeAmount:d(t).mul(n).div(e)}),Ee=({liquidityUnits:n,poolUnits:e,runeDepth:t,assetDepth:i,percent:s})=>Object.fromEntries(Object.entries(te({liquidityUnits:n,poolUnits:e,runeDepth:t,assetDepth:i})).map(([r,c])=>[r,c.mul(s)])),Oe=({runeDepth:n,poolUnits:e,assetDepth:t,liquidityUnits:i,runeAmount:s,assetAmount:r})=>{const c=d(n),o=d(t),u=d(e),l=d(s),g=d(r),C=l.mul(o),b=g.mul(c),R=l.mul(g),se=c.mul(o),re=u.mul(C.add(b.add(R.mul(2)))),ce=C.add(b.add(se.mul(2))),U=re.div(ce),N=d(i).add(U);if(U.baseValueNumber===0)return N.div(u).baseValueNumber;const oe=u.add(N);return N.div(oe).baseValueNumber},De=({runeAmount:n,assetAmount:e,runeDepth:t,assetDepth:i})=>{const s=d(t),r=d(i),c=d(e),o=d(n),u=c.mul(s).sub(r.mul(o)),l=r.mul(o).add(s.mul(r));return Math.abs(u.div(l).baseValueNumber)},Ve=({symbol:n,ticker:e,chain:t})=>t==="ETH"&&e!=="ETH"?`${e}-${n.slice(-3)}`:n,Re=(n,e)=>{switch(n){case a.MemoType.LEAVE:case a.MemoType.BOND:{const{address:t}=e;return`${n}:${t}`}case a.MemoType.UNBOND:{const{address:t,unbondAmount:i}=e;return`${n}:${t}:${i*10**8}`}case a.MemoType.THORNAME_REGISTER:{const{name:t,chain:i,address:s,owner:r}=e;return`${n}:${t}:${i}:${s}${r?`:${r}`:""}`}case a.MemoType.DEPOSIT:{const{chain:t,symbol:i,address:s,singleSide:r}=e;return r?`${n}:${t}/${i}::t:0`:`${n}:${t}.${i}:${s||""}:t:0`}case a.MemoType.WITHDRAW:{const{chain:t,ticker:i,symbol:s,basisPoints:r,targetAssetString:c,singleSide:o}=e,u=!o&&c?`:${c}`:"",l=Ve({chain:t,symbol:s,ticker:i});return`${n}:${t}${o?"/":"."}${l}:${r}${u}`}case a.MemoType.OPEN_LOAN:case a.MemoType.CLOSE_LOAN:{const{asset:t,address:i}=e;return`${n}:${t}:${i}`}default:return""}},S=8,P=({value:n,bigIntDecimal:e=S,decimal:t=S})=>{const i=n<0n;let s=n.toString().substring(i?1:0);const r=t-(s.length-1);r>0&&(s="0".repeat(r)+s);const c=s.length-t;let o=s.slice(-t);return parseInt(o[e])>=5?o=`${o.substring(0,e-1)}${(parseInt(o[e-1])+1).toString()}`:o=o.substring(0,e),`${i?"-":""}${s.slice(0,c)}.${o}`.replace(/\.?0*$/,"")},W=Object.values(a.Chain),Ne=(n="")=>{const e=n.toUpperCase(),[t]=e.split(".");if(W.includes(t))return!0;const[i]=e.split("/");if(W.includes(i))return!0;throw new Error(`Invalid identifier: ${n}. Expected format: <Chain>.<Ticker> or <Chain>.<Ticker>-<ContractAddress>`)},w=n=>10n**BigInt(n),y=n=>Math.log10(parseFloat(n.toString()));var f,B,D,ne,V,ie,M,L,A,T,E,x,$,O;const I=class I{constructor(e){p(this,f);p(this,D);p(this,V);p(this,M);p(this,A);p(this,E);p(this,$);m(this,"decimalMultiplier",10n**8n);m(this,"bigIntValue",0n);m(this,"decimal");const t=typeof e=="object",i=t?e.value:e;this.decimal=t?e.decimal:void 0,this.decimalMultiplier=w(Math.max(h(this,E,x).call(this,h(this,A,T).call(this,i)),this.decimal||0)),h(this,D,ne).call(this,i)}static fromBigInt(e,t){return new I({decimal:t,value:P({value:e,bigIntDecimal:t,decimal:t})})}static shiftDecimals({value:e,from:t,to:i}){return I.fromBigInt(new I(e).bigIntValue*w(i)/w(t),i)}get unsafeNumber(){return parseFloat((this.bigIntValue/this.decimalMultiplier).toString())}get baseValue(){return h(this,$,O).call(this,"string")}get baseValueNumber(){return h(this,$,O).call(this,"number")}get baseValueBigInt(){return h(this,$,O).call(this,"number")}get value(){return this.formatBigIntToSafeValue(this.bigIntValue,this.decimal||y(this.decimalMultiplier))}add(...e){return h(this,f,B).call(this,"add",...e)}sub(...e){return h(this,f,B).call(this,"sub",...e)}mul(...e){return h(this,f,B).call(this,"mul",...e)}div(...e){return h(this,f,B).call(this,"div",...e)}gt(e){return this.bigIntValue>this.getBigIntValue(e)}gte(e){return this.bigIntValue>=this.getBigIntValue(e)}lt(e){return this.bigIntValue<this.getBigIntValue(e)}lte(e){return this.bigIntValue<=this.getBigIntValue(e)}eqValue(e){return this.bigIntValue===this.getBigIntValue(e)}getBigIntValue(e,t){return!t&&typeof e=="object"?e.bigIntValue:(e=typeof e=="object"?e.value:e,h(this,M,L).call(this,h(this,A,T).call(this,e),t))}formatBigIntToSafeValue(e,t){const i=t||this.decimal||S,s=Math.max(i,y(this.decimalMultiplier)),r=e<0n;let c=e.toString().substring(r?1:0);const o=s-(c.length-1);o>0&&(c="0".repeat(o)+c);const u=c.length-s;let l=c.slice(-s);return parseInt(l[i])>=5?l=`${l.substring(0,i-1)}${(parseInt(l[i-1])+1).toString()}`:l=l.substring(0,i),`${r?"-":""}${c.slice(0,u)}.${l}`.replace(/\.?0*$/,"")}toSignificant(e){const t=this.value.split("."),i=t[0],s=t[1];return s?`${i}.${s.slice(0,e||this.decimal)}`.replace(/\.?0*$/,""):i}};f=new WeakSet,B=function(e,...t){const i=h(this,V,ie).call(this,this,...t),s=w(i),r=t.reduce((o,u)=>{const l=this.getBigIntValue(u,i);if(e==="div"&&l===0n)throw new RangeError("Division by zero");return e==="add"?o+l:e==="sub"?o-l:e==="mul"?o*l/s:o*s/l},this.bigIntValue*s/this.decimalMultiplier),c=P({bigIntDecimal:i,decimal:Math.max(i,y(this.decimalMultiplier)),value:r});return new this.constructor({decimal:this.decimal,value:c,identifier:this.toString()})},D=new WeakSet,ne=function(e,t){const i=h(this,A,T).call(this,e)||"0";this.bigIntValue=t||h(this,M,L).call(this,i)},V=new WeakSet,ie=function(...e){const t=e.map(i=>typeof i=="object"?i.decimal||y(i.decimalMultiplier):h(this,E,x).call(this,h(this,A,T).call(this,i))).filter(Boolean);return Math.max(...t,S)},M=new WeakSet,L=function(e,t){const i=t?w(t):this.decimalMultiplier,s=y(i),[r,c=""]=e.split(".");return BigInt(`${r}${c.padEnd(s,"0")}`)},A=new WeakSet,T=function(e){const i=`${typeof e=="number"?Number(e).toLocaleString("fullwide",{useGrouping:!1,maximumFractionDigits:20}):e}`.replaceAll(",",".").split(".");return i.length>1?`${i.slice(0,-1).join("")}.${i.at(-1)}`:i[0]},E=new WeakSet,x=function(e){var i;const t=((i=e.split(".")[1])==null?void 0:i.length)||0;return Math.max(t,S)},$=new WeakSet,O=function(e){const t=this.decimalMultiplier/w(this.decimal||0),i=this.bigIntValue/t;switch(e){case"number":return Number(i);case"string":return i.toString();default:return i}};let v=I,q;const k=n=>{if(!q)throw new Error("Static assets not loaded, call await AssetValue.loadStaticAssets() first");return q.get(n.toUpperCase())||{decimal:a.BaseDecimal.THOR,identifier:""}},Y=async(n,e=0)=>{Ne(n);const t=await j(F(n));return new _({decimal:t,value:e,identifier:n})};class _ extends v{constructor(t){super(t.value instanceof v?t.value:{decimal:t.decimal,value:t.value});m(this,"address");m(this,"chain");m(this,"isSynthetic",!1);m(this,"isGasAsset",!1);m(this,"symbol");m(this,"ticker");m(this,"type");const i="identifier"in t?t.identifier:`${t.chain}.${t.symbol}`,s=F(i);this.type=Q(s),this.chain=s.chain,this.ticker=s.ticker,this.symbol=s.symbol,this.address=s.address,this.isSynthetic=s.isSynthetic,this.isGasAsset=s.isGasAsset}static async fromString(t,i=0){return Y(t,i)}static fromStringSync(t,i=0){const{decimal:s,identifier:r}=k(t);return r?new _({decimal:s,identifier:r,value:i}):void 0}static async fromIdentifier(t,i=0){return Y(t,i)}static fromIdentifierSync(t,i=0){const{decimal:s,identifier:r}=k(t);return new _({decimal:s,identifier:r,value:i})}static fromChainOrSignature(t,i=0){const{decimal:s,identifier:r}=K(t);return new _({value:i,decimal:s,identifier:r})}static async fromTCQuote(t,i=0){const s=await j(F(t)),r=this.shiftDecimals({value:i,from:a.BaseDecimal.THOR,to:s});return new _({value:r,identifier:t,decimal:s})}static fromTCQuoteStatic(t,i=0){const s=k(t),r=this.shiftDecimals({value:i,from:a.BaseDecimal.THOR,to:s.decimal});return new _({...s,value:r})}static async loadStaticAssets(){return new Promise(async(t,i)=>{try{const{ThorchainList:s,NativeList:r,...c}=await import("@swapkit/tokens");q=[r,...Object.values(c)].reduce((u,{tokens:l})=>(l.forEach(({identifier:g,chain:C,...b})=>{const R="decimals"in b?b.decimals:a.BaseDecimal[C];u.set(g,{identifier:g,decimal:R})}),u),new Map),t({ok:!0})}catch(s){console.error(s),i({ok:!1,error:s,message:"Couldn't load static assets. Ensure you have installed @swapkit/tokens package"})}})}get assetValue(){return`${this.value} ${this.ticker}`}toString(){return`${this.chain}.${this.symbol}`}eq({chain:t,symbol:i}){return this.chain===t&&this.symbol===i}}const He=n=>{const e=_.fromChainOrSignature(n);switch(n){case a.Chain.Bitcoin:case a.Chain.Litecoin:case a.Chain.BitcoinCash:return e.add(10001);case a.Chain.Dogecoin:return e.add(100000001);case a.Chain.Avalanche:case a.Chain.Ethereum:return e.add(10*10**9);case a.Chain.THORChain:case a.Chain.Maya:return e.add(0);default:return e.add(1)}},F=n=>{const e=n.slice(0,14).includes("/"),t=n.includes(".")?n:`${a.Chain.THORChain}.${n}`,[i,s]=t.split("."),[r,c]=s.split("-");return{address:c==null?void 0:c.toLowerCase(),chain:i,isGasAsset:J({chain:i,symbol:s}),isSynthetic:e,symbol:c?`${r}-${(c==null?void 0:c.toLowerCase())??""}`:s,ticker:e?s:r}},ke={core_wallet_connection_not_found:10001,core_estimated_max_spendable_chain_not_supported:10002,core_extend_error:10003,core_inbound_data_not_found:10004,core_approve_asset_address_or_from_not_found:10005,core_chain_halted:10099,core_wallet_xdefi_not_installed:10101,core_wallet_evmwallet_not_installed:10102,core_wallet_walletconnect_not_installed:10103,core_wallet_keystore_not_installed:10104,core_wallet_ledger_not_installed:10105,core_wallet_trezor_not_installed:10106,core_wallet_keplr_not_installed:10107,core_wallet_okx_not_installed:10108,core_swap_invalid_params:10200,core_swap_route_not_complete:10201,core_swap_asset_not_recognized:10202,core_swap_contract_not_found:10203,core_swap_route_transaction_not_found:10204,core_swap_contract_not_supported:10205,core_swap_transaction_error:10206,core_swap_quote_mode_not_supported:10207,core_transaction_deposit_error:10301,core_transaction_create_liquidity_rune_error:10302,core_transaction_create_liquidity_asset_error:10303,core_transaction_create_liquidity_invalid_params:10304,core_transaction_add_liquidity_invalid_params:10305,core_transaction_add_liquidity_no_rune_address:10306,core_transaction_add_liquidity_rune_error:10307,core_transaction_add_liquidity_asset_error:10308,core_transaction_withdraw_error:10309,core_transaction_deposit_to_pool_error:10310,core_transaction_deposit_insufficient_funds_error:10311,core_transaction_deposit_gas_error:10312,core_transaction_deposit_server_error:10313,wallet_ledger_connection_error:20001,helpers_number_different_decimals:99101};class G extends Error{constructor(e,t){console.error(t),super(e,{cause:{code:ke[e],message:e}}),Object.setPrototypeOf(this,G.prototype)}}class ae extends v{eq(e){return this.eqValue(e)}toString(){return this.value}}exports.AssetValue=_;exports.DEFAULT_DECIMAL=S;exports.SwapKitError=G;exports.SwapKitNumber=ae;exports.assetFromString=Ie;exports.derivationPathToString=we;exports.formatBigIntToSafeValue=P;exports.gasFeeMultiplier=Te;exports.getAssetType=Q;exports.getAsymmetricAssetShare=ee;exports.getAsymmetricAssetWithdrawAmount=Me;exports.getAsymmetricRuneShare=Z;exports.getAsymmetricRuneWithdrawAmount=ve;exports.getCommonAssetInfo=K;exports.getDecimal=j;exports.getEstimatedPoolShare=Oe;exports.getLiquiditySlippage=De;exports.getMemoFor=Re;exports.getMinAmountByChain=He;exports.getRequest=Se;exports.getSymmetricPoolShare=te;exports.getSymmetricWithdraw=Ee;exports.getTHORNameCost=fe;exports.isGasAsset=J;exports.postRequest=z;exports.validateTHORName=Ae;
1
+ "use strict";var le=Object.create;var H=Object.defineProperty;var ue=Object.getOwnPropertyDescriptor;var he=Object.getOwnPropertyNames;var de=Object.getPrototypeOf,me=Object.prototype.hasOwnProperty;var ge=(n,e,t)=>e in n?H(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var _e=(n,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of he(e))!me.call(n,s)&&s!==t&&H(n,s,{get:()=>e[s],enumerable:!(i=ue(e,s))||i.enumerable});return n};var pe=(n,e,t)=>(t=n!=null?le(de(n)):{},_e(e||!n||!n.__esModule?H(t,"default",{value:n,enumerable:!0}):t,n));var m=(n,e,t)=>(ge(n,typeof e!="symbol"?e+"":e,t),t),Ce=(n,e,t)=>{if(!e.has(n))throw TypeError("Cannot "+t)};var p=(n,e,t)=>{if(e.has(n))throw TypeError("Cannot add the same private member more than once");e instanceof WeakSet?e.add(n):e.set(n,t)};var h=(n,e,t)=>(Ce(n,e,"access private method"),t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("@swapkit/types"),fe=n=>{if(n<0)throw new Error("Invalid number of year");return 10+n},Ae=n=>{if(n.length>30)return!1;const e=/^[a-zA-Z0-9+_-]+$/g;return!!n.match(e)},we=([n,e,t,i,s])=>`${n}'/${e}'/${t}'/${i}${typeof s!="number"?"":`/${s}`}`,Se=async(n,e)=>{const t=Object.entries(e||{}).reduce((s,[r,c])=>(c&&(s[r]=c),s),{});return(await fetch(`${n}${e?`?${new URLSearchParams(t).toString()}`:""}`,{method:"GET",mode:"cors",credentials:"omit",referrer:"https://sk.thorswap.net"})).json()},Y=async(n,e,t,i=!1)=>{const s=await fetch(`${n}`,{body:e,headers:t,method:"POST",referrer:"https://sk.thorswap.net"});return i?s.text():s.json()},$e="0x313ce567",J=async({chain:n,to:e})=>{try{const t=await Y(a.ChainToRPC[n],JSON.stringify({method:"eth_call",params:[{to:e.toLowerCase(),data:$e},"latest"],id:44,jsonrpc:"2.0"}),{accept:"*/*","cache-control":"no-cache","content-type":"application/json"},!0),{result:i}=JSON.parse(t);return parseInt(BigInt(i).toString())}catch(t){return console.error(t),a.BaseDecimal[n]}},be=async n=>{if(n===a.Chain.Ethereum)return a.BaseDecimal.ETH;const[,e]=n.split("-");return e!=null&&e.startsWith("0x")?J({chain:a.Chain.Ethereum,to:e}):a.BaseDecimal.ETH},ye=async n=>{const[,e]=n.split("-");return e!=null&&e.startsWith("0x")?J({chain:a.Chain.Avalanche,to:e.toLowerCase()}):a.BaseDecimal.AVAX},Be=async n=>(n===a.Chain.BinanceSmartChain,a.BaseDecimal.BSC),F=async({chain:n,symbol:e})=>{switch(n){case a.Chain.Ethereum:return be(e);case a.Chain.Avalanche:return ye(e);case a.Chain.BinanceSmartChain:return Be(e);default:return a.BaseDecimal[n]}},Ie={[a.FeeOption.Average]:1.2,[a.FeeOption.Fast]:1.5,[a.FeeOption.Fastest]:2},z=({chain:n,symbol:e})=>{switch(n){case a.Chain.Bitcoin:case a.Chain.BitcoinCash:case a.Chain.Litecoin:case a.Chain.Dogecoin:case a.Chain.Binance:case a.Chain.Ethereum:case a.Chain.Avalanche:return e===n;case a.Chain.Arbitrum:case a.Chain.Optimism:return e==="ETH";case a.Chain.Maya:return e==="CACAO";case a.Chain.Kujira:return e==="KUJI";case a.Chain.Cosmos:return e==="ATOM";case a.Chain.Polygon:return e==="MATIC";case a.Chain.BinanceSmartChain:return e==="BNB";case a.Chain.THORChain:return e==="RUNE"}},X=n=>{switch(n){case"ETH.THOR":return{identifier:"ETH.THOR-0xa5f2211b9b8170f694421f2046281775e8468044",decimal:18};case"ETH.vTHOR":return{identifier:"ETH.vTHOR-0x815c23eca83261b6ec689b60cc4a58b54bc24d8d",decimal:18};case a.Chain.Cosmos:return{identifier:"GAIA.ATOM",decimal:a.BaseDecimal[n]};case a.Chain.THORChain:return{identifier:"THOR.RUNE",decimal:a.BaseDecimal[n]};case a.Chain.BinanceSmartChain:return{identifier:"BSC.BNB",decimal:a.BaseDecimal[n]};case a.Chain.Maya:return{identifier:"MAYA.CACAO",decimal:a.BaseDecimal.MAYA};case"MAYA.MAYA":return{identifier:"MAYA.MAYA",decimal:4};case a.Chain.Kujira:case a.Chain.Arbitrum:case a.Chain.Optimism:case a.Chain.BitcoinCash:case a.Chain.Litecoin:case a.Chain.Dogecoin:case a.Chain.Binance:case a.Chain.Avalanche:case a.Chain.Polygon:case a.Chain.Bitcoin:case a.Chain.Ethereum:return{identifier:`${n}.${n}`,decimal:a.BaseDecimal[n]}}},Q=({chain:n,symbol:e})=>{if(e.includes("/"))return"Synth";switch(n){case a.Chain.Bitcoin:case a.Chain.BitcoinCash:case a.Chain.Dogecoin:case a.Chain.Litecoin:case a.Chain.Maya:case a.Chain.THORChain:return"Native";case a.Chain.Cosmos:return e==="ATOM"?"Native":"GAIA";case a.Chain.Kujira:return e==="KUJI"?"Native":"KUJI";case a.Chain.Binance:return e===a.Chain.Binance?"Native":"BEP2";case a.Chain.BinanceSmartChain:return e===a.Chain.Binance?"Native":"BEP20";case a.Chain.Ethereum:return e===a.Chain.Ethereum?"Native":"ERC20";case a.Chain.Avalanche:return e===a.Chain.Avalanche?"Native":"AVAX";case a.Chain.Polygon:return e===a.Chain.Polygon?"Native":"POLYGON";case a.Chain.Arbitrum:return[a.Chain.Ethereum,a.Chain.Arbitrum].includes(e)?"Native":"ARBITRUM";case a.Chain.Optimism:return[a.Chain.Ethereum,a.Chain.Optimism].includes(e)?"Native":"OPTIMISM"}},Te=n=>{var c;const[e,...t]=n.split("."),i=n.includes("/"),s=t.join("."),r=(c=s==null?void 0:s.split("-"))==null?void 0:c[0];return{chain:e,symbol:s,ticker:r,synth:i}},Z=({liquidityUnits:n,poolUnits:e,runeDepth:t})=>{const i=d(n),s=d(e),r=d(t),c=i.mul(r),o=s.mul(s).mul(2),u=s.mul(i).mul(2),l=i.mul(i),g=s.mul(s).mul(s);return c.mul(o.sub(u).add(l)).div(g)},ee=({liquidityUnits:n,poolUnits:e,assetDepth:t})=>{const i=d(n),s=d(e),r=d(t),c=i.mul(r),o=s.mul(s).mul(2),u=s.mul(i).mul(2),l=i.mul(i),g=c.mul(o.sub(u).add(l)),C=s.mul(s).mul(s);return g.div(C)},ve=({percent:n,runeDepth:e,liquidityUnits:t,poolUnits:i})=>Z({runeDepth:e,liquidityUnits:t,poolUnits:i}).mul(n),Me=({percent:n,assetDepth:e,liquidityUnits:t,poolUnits:i})=>ee({assetDepth:e,liquidityUnits:t,poolUnits:i}).mul(n),d=n=>new ae({value:n,decimal:a.BaseDecimal.THOR}),te=({liquidityUnits:n,poolUnits:e,runeDepth:t,assetDepth:i})=>({assetAmount:d(i).mul(n).div(e),runeAmount:d(t).mul(n).div(e)}),Ee=({liquidityUnits:n,poolUnits:e,runeDepth:t,assetDepth:i,percent:s})=>Object.fromEntries(Object.entries(te({liquidityUnits:n,poolUnits:e,runeDepth:t,assetDepth:i})).map(([r,c])=>[r,c.mul(s)])),Oe=({runeDepth:n,poolUnits:e,assetDepth:t,liquidityUnits:i,runeAmount:s,assetAmount:r})=>{const c=d(n),o=d(t),u=d(e),l=d(s),g=d(r),C=l.mul(o),b=g.mul(c),N=l.mul(g),se=c.mul(o),re=u.mul(C.add(b.add(N.mul(2)))),ce=C.add(b.add(se.mul(2))),G=re.div(ce),R=d(i).add(G);if(G.baseValueNumber===0)return R.div(u).baseValueNumber;const oe=u.add(R);return R.div(oe).baseValueNumber},De=({runeAmount:n,assetAmount:e,runeDepth:t,assetDepth:i})=>{const s=d(t),r=d(i),c=d(e),o=d(n),u=c.mul(s).sub(r.mul(o)),l=r.mul(o).add(s.mul(r));return Math.abs(u.div(l).baseValueNumber)},Ve=({symbol:n,ticker:e,chain:t})=>t==="ETH"&&e!=="ETH"?`${e}-${n.slice(-3)}`:n,Ne=(n,e)=>{switch(n){case a.MemoType.LEAVE:case a.MemoType.BOND:{const{address:t}=e;return`${n}:${t}`}case a.MemoType.UNBOND:{const{address:t,unbondAmount:i}=e;return`${n}:${t}:${i*10**8}`}case a.MemoType.THORNAME_REGISTER:{const{name:t,chain:i,address:s,owner:r}=e;return`${n}:${t}:${i}:${s}${r?`:${r}`:""}`}case a.MemoType.DEPOSIT:{const{chain:t,symbol:i,address:s,singleSide:r}=e;return r?`${n}:${t}/${i}::t:0`:`${n}:${t}.${i}:${s||""}:t:0`}case a.MemoType.WITHDRAW:{const{chain:t,ticker:i,symbol:s,basisPoints:r,targetAssetString:c,singleSide:o}=e,u=!o&&c?`:${c}`:"",l=Ve({chain:t,symbol:s,ticker:i});return`${n}:${t}${o?"/":"."}${l}:${r}${u}`}case a.MemoType.OPEN_LOAN:case a.MemoType.CLOSE_LOAN:{const{asset:t,address:i}=e;return`${n}:${t}:${i}`}default:return""}},S=8,P=({value:n,bigIntDecimal:e=S,decimal:t=S})=>{const i=n<0n;let s=n.toString().substring(i?1:0);const r=t-(s.length-1);r>0&&(s="0".repeat(r)+s);const c=s.length-t;let o=s.slice(-t);return parseInt(o[e])>=5?o=`${o.substring(0,e-1)}${(parseInt(o[e-1])+1).toString()}`:o=o.substring(0,e),`${i?"-":""}${s.slice(0,c)}.${o}`.replace(/\.?0*$/,"")},W=Object.values(a.Chain),Re=(n="")=>{const e=n.toUpperCase(),[t]=e.split(".");if(W.includes(t))return!0;const[i]=e.split("/");if(W.includes(i))return!0;throw new Error(`Invalid identifier: ${n}. Expected format: <Chain>.<Ticker> or <Chain>.<Ticker>-<ContractAddress>`)},w=n=>10n**BigInt(n),y=n=>Math.log10(parseFloat(n.toString()));var f,B,D,ne,V,ie,M,L,A,I,E,x,$,O;const T=class T{constructor(e){p(this,f);p(this,D);p(this,V);p(this,M);p(this,A);p(this,E);p(this,$);m(this,"decimalMultiplier",10n**8n);m(this,"bigIntValue",0n);m(this,"decimal");const t=typeof e=="object",i=t?e.value:e;this.decimal=t?e.decimal:void 0,this.decimalMultiplier=w(Math.max(h(this,E,x).call(this,h(this,A,I).call(this,i)),this.decimal||0)),h(this,D,ne).call(this,i)}static fromBigInt(e,t){return new T({decimal:t,value:P({value:e,bigIntDecimal:t,decimal:t})})}static shiftDecimals({value:e,from:t,to:i}){return T.fromBigInt(new T(e).bigIntValue*w(i)/w(t),i)}get unsafeNumber(){return parseFloat((this.bigIntValue/this.decimalMultiplier).toString())}get baseValue(){return h(this,$,O).call(this,"string")}get baseValueNumber(){return h(this,$,O).call(this,"number")}get baseValueBigInt(){return h(this,$,O).call(this,"number")}get value(){return this.formatBigIntToSafeValue(this.bigIntValue,this.decimal||y(this.decimalMultiplier))}add(...e){return h(this,f,B).call(this,"add",...e)}sub(...e){return h(this,f,B).call(this,"sub",...e)}mul(...e){return h(this,f,B).call(this,"mul",...e)}div(...e){return h(this,f,B).call(this,"div",...e)}gt(e){return this.bigIntValue>this.getBigIntValue(e)}gte(e){return this.bigIntValue>=this.getBigIntValue(e)}lt(e){return this.bigIntValue<this.getBigIntValue(e)}lte(e){return this.bigIntValue<=this.getBigIntValue(e)}eqValue(e){return this.bigIntValue===this.getBigIntValue(e)}getBigIntValue(e,t){return!t&&typeof e=="object"?e.bigIntValue:(e=typeof e=="object"?e.value:e,h(this,M,L).call(this,h(this,A,I).call(this,e),t))}formatBigIntToSafeValue(e,t){const i=t||this.decimal||S,s=Math.max(i,y(this.decimalMultiplier)),r=e<0n;let c=e.toString().substring(r?1:0);const o=s-(c.length-1);o>0&&(c="0".repeat(o)+c);const u=c.length-s;let l=c.slice(-s);return parseInt(l[i])>=5?l=`${l.substring(0,i-1)}${(parseInt(l[i-1])+1).toString()}`:l=l.substring(0,i),`${r?"-":""}${c.slice(0,u)}.${l}`.replace(/\.?0*$/,"")}toSignificant(e){const t=this.value.split("."),i=t[0],s=t[1];return s?`${i}.${s.slice(0,e||this.decimal)}`.replace(/\.?0*$/,""):i}};f=new WeakSet,B=function(e,...t){const i=h(this,V,ie).call(this,this,...t),s=w(i),r=t.reduce((o,u)=>{const l=this.getBigIntValue(u,i);if(e==="div"&&l===0n)throw new RangeError("Division by zero");return e==="add"?o+l:e==="sub"?o-l:e==="mul"?o*l/s:o*s/l},this.bigIntValue*s/this.decimalMultiplier),c=P({bigIntDecimal:i,decimal:Math.max(i,y(this.decimalMultiplier)),value:r});return new this.constructor({decimal:this.decimal,value:c,identifier:this.toString()})},D=new WeakSet,ne=function(e,t){const i=h(this,A,I).call(this,e)||"0";this.bigIntValue=t||h(this,M,L).call(this,i)},V=new WeakSet,ie=function(...e){const t=e.map(i=>typeof i=="object"?i.decimal||y(i.decimalMultiplier):h(this,E,x).call(this,h(this,A,I).call(this,i))).filter(Boolean);return Math.max(...t,S)},M=new WeakSet,L=function(e,t){const i=t?w(t):this.decimalMultiplier,s=y(i),[r,c=""]=e.split(".");return BigInt(`${r}${c.padEnd(s,"0")}`)},A=new WeakSet,I=function(e){const i=`${typeof e=="number"?Number(e).toLocaleString("fullwide",{useGrouping:!1,maximumFractionDigits:20}):e}`.replaceAll(",",".").split(".");return i.length>1?`${i.slice(0,-1).join("")}.${i.at(-1)}`:i[0]},E=new WeakSet,x=function(e){var i;const t=((i=e.split(".")[1])==null?void 0:i.length)||0;return Math.max(t,S)},$=new WeakSet,O=function(e){const t=this.decimalMultiplier/w(this.decimal||0),i=this.bigIntValue/t;switch(e){case"number":return Number(i);case"string":return i.toString();default:return i}};let v=T,j;const k=n=>{if(!j)throw new Error("Static assets not loaded, call await AssetValue.loadStaticAssets() first");return j.get(n.toUpperCase())||{decimal:a.BaseDecimal.THOR,identifier:""}},K=async(n,e=0)=>{Re(n);const t=await F(q(n));return new _({decimal:t,value:e,identifier:n})};class _ extends v{constructor(t){super(t.value instanceof v?t.value:{decimal:t.decimal,value:t.value});m(this,"address");m(this,"chain");m(this,"isSynthetic",!1);m(this,"isGasAsset",!1);m(this,"symbol");m(this,"ticker");m(this,"type");const i="identifier"in t?t.identifier:`${t.chain}.${t.symbol}`,s=q(i);this.type=Q(s),this.chain=s.chain,this.ticker=s.ticker,this.symbol=s.symbol,this.address=s.address,this.isSynthetic=s.isSynthetic,this.isGasAsset=s.isGasAsset}static async fromString(t,i=0){return K(t,i)}static fromStringSync(t,i=0){const{decimal:s,identifier:r}=k(t);return r?new _({decimal:s,identifier:r,value:i}):void 0}static async fromIdentifier(t,i=0){return K(t,i)}static fromIdentifierSync(t,i=0){const{decimal:s,identifier:r}=k(t);return new _({decimal:s,identifier:r,value:i})}static fromChainOrSignature(t,i=0){const{decimal:s,identifier:r}=X(t);return new _({value:i,decimal:s,identifier:r})}static async fromTCQuote(t,i=0){const s=await F(q(t)),r=this.shiftDecimals({value:i,from:a.BaseDecimal.THOR,to:s});return new _({value:r,identifier:t,decimal:s})}static fromTCQuoteStatic(t,i=0){const s=k(t),r=this.shiftDecimals({value:i,from:a.BaseDecimal.THOR,to:s.decimal});return new _({...s,value:r})}static async loadStaticAssets(){return new Promise(async(t,i)=>{try{const{ThorchainList:s,NativeList:r,...c}=await import("@swapkit/tokens");j=[r,...Object.values(c)].reduce((u,{tokens:l})=>(l.forEach(({identifier:g,chain:C,...b})=>{const N="decimals"in b?b.decimals:a.BaseDecimal[C];u.set(g,{identifier:g,decimal:N})}),u),new Map),t({ok:!0})}catch(s){console.error(s),i({ok:!1,error:s,message:"Couldn't load static assets. Ensure you have installed @swapkit/tokens package"})}})}get assetValue(){return`${this.value} ${this.ticker}`}toString(){return`${this.chain}.${this.symbol}`}eq({chain:t,symbol:i}){return this.chain===t&&this.symbol===i}}const He=n=>{const e=_.fromChainOrSignature(n);switch(n){case a.Chain.Bitcoin:case a.Chain.Litecoin:case a.Chain.BitcoinCash:return e.add(10001);case a.Chain.Dogecoin:return e.add(100000001);case a.Chain.Avalanche:case a.Chain.Ethereum:return e.add(10*10**9);case a.Chain.THORChain:case a.Chain.Maya:return e.add(0);default:return e.add(1)}},q=n=>{const e=n.slice(0,14).includes("/"),t=n.includes(".")?n:`${a.Chain.THORChain}.${n}`,[i,s]=t.split("."),[r,c]=s.split("-");return{address:c==null?void 0:c.toLowerCase(),chain:i,isGasAsset:z({chain:i,symbol:s}),isSynthetic:e,symbol:c?`${r}-${(c==null?void 0:c.toLowerCase())??""}`:s,ticker:e?s:r}},ke={core_wallet_connection_not_found:10001,core_estimated_max_spendable_chain_not_supported:10002,core_extend_error:10003,core_inbound_data_not_found:10004,core_approve_asset_address_or_from_not_found:10005,core_chain_halted:10099,core_wallet_xdefi_not_installed:10101,core_wallet_evmwallet_not_installed:10102,core_wallet_walletconnect_not_installed:10103,core_wallet_keystore_not_installed:10104,core_wallet_ledger_not_installed:10105,core_wallet_trezor_not_installed:10106,core_wallet_keplr_not_installed:10107,core_wallet_okx_not_installed:10108,core_swap_invalid_params:10200,core_swap_route_not_complete:10201,core_swap_asset_not_recognized:10202,core_swap_contract_not_found:10203,core_swap_route_transaction_not_found:10204,core_swap_contract_not_supported:10205,core_swap_transaction_error:10206,core_swap_quote_mode_not_supported:10207,core_transaction_deposit_error:10301,core_transaction_create_liquidity_rune_error:10302,core_transaction_create_liquidity_asset_error:10303,core_transaction_create_liquidity_invalid_params:10304,core_transaction_add_liquidity_invalid_params:10305,core_transaction_add_liquidity_no_rune_address:10306,core_transaction_add_liquidity_rune_error:10307,core_transaction_add_liquidity_asset_error:10308,core_transaction_withdraw_error:10309,core_transaction_deposit_to_pool_error:10310,core_transaction_deposit_insufficient_funds_error:10311,core_transaction_deposit_gas_error:10312,core_transaction_deposit_server_error:10313,wallet_ledger_connection_error:20001,helpers_number_different_decimals:99101};class U extends Error{constructor(e,t){console.error(t),super(e,{cause:{code:ke[e],message:e}}),Object.setPrototypeOf(this,U.prototype)}}class ae extends v{eq(e){return this.eqValue(e)}toString(){return this.value}}exports.AssetValue=_;exports.DEFAULT_DECIMAL=S;exports.SwapKitError=U;exports.SwapKitNumber=ae;exports.assetFromString=Te;exports.derivationPathToString=we;exports.formatBigIntToSafeValue=P;exports.gasFeeMultiplier=Ie;exports.getAssetType=Q;exports.getAsymmetricAssetShare=ee;exports.getAsymmetricAssetWithdrawAmount=Me;exports.getAsymmetricRuneShare=Z;exports.getAsymmetricRuneWithdrawAmount=ve;exports.getCommonAssetInfo=X;exports.getDecimal=F;exports.getEstimatedPoolShare=Oe;exports.getLiquiditySlippage=De;exports.getMemoFor=Ne;exports.getMinAmountByChain=He;exports.getRequest=Se;exports.getSymmetricPoolShare=te;exports.getSymmetricWithdraw=Ee;exports.getTHORNameCost=fe;exports.isGasAsset=z;exports.postRequest=Y;exports.validateTHORName=Ae;
package/dist/index.d.ts CHANGED
@@ -170,7 +170,7 @@ export declare const gasFeeMultiplier: Record<FeeOption, number>;
170
170
  export declare const getAssetType: ({ chain, symbol }: {
171
171
  chain: Chain;
172
172
  symbol: string;
173
- }) => "Synth" | "Native" | "GAIA" | "BEP2" | "BEP20" | "ERC20" | "AVAX" | "POLYGON" | "ARBITRUM" | "OPTIMISM";
173
+ }) => "KUJI" | "Synth" | "Native" | "GAIA" | "BEP2" | "BEP20" | "ERC20" | "AVAX" | "POLYGON" | "ARBITRUM" | "OPTIMISM";
174
174
 
175
175
  export declare const getAsymmetricAssetShare: ({ liquidityUnits, poolUnits, assetDepth, }: ShareParams<{
176
176
  assetDepth: string;
package/dist/index.es.js CHANGED
@@ -20,7 +20,7 @@ const vt = (n) => {
20
20
  return !1;
21
21
  const t = /^[a-zA-Z0-9+_-]+$/g;
22
22
  return !!n.match(t);
23
- }, yt = ([n, t, e, r, s]) => `${n}'/${t}'/${e}'/${r}${typeof s != "number" ? "" : `/${s}`}`, Tt = async (n, t) => {
23
+ }, Tt = ([n, t, e, r, s]) => `${n}'/${t}'/${e}'/${r}${typeof s != "number" ? "" : `/${s}`}`, Bt = async (n, t) => {
24
24
  const e = Object.entries(t || {}).reduce(
25
25
  (s, [a, c]) => (c && (s[a] = c), s),
26
26
  {}
@@ -37,7 +37,7 @@ const vt = (n) => {
37
37
  referrer: "https://sk.thorswap.net"
38
38
  });
39
39
  return r ? s.text() : s.json();
40
- }, ot = "0x313ce567", z = async ({ chain: n, to: t }) => {
40
+ }, ot = "0x313ce567", K = async ({ chain: n, to: t }) => {
41
41
  try {
42
42
  const e = await ct(
43
43
  at[n],
@@ -58,11 +58,11 @@ const vt = (n) => {
58
58
  if (n === i.Ethereum)
59
59
  return h.ETH;
60
60
  const [, t] = n.split("-");
61
- return t != null && t.startsWith("0x") ? z({ chain: i.Ethereum, to: t }) : h.ETH;
61
+ return t != null && t.startsWith("0x") ? K({ chain: i.Ethereum, to: t }) : h.ETH;
62
62
  }, lt = async (n) => {
63
63
  const [, t] = n.split("-");
64
- return t != null && t.startsWith("0x") ? z({ chain: i.Avalanche, to: t.toLowerCase() }) : h.AVAX;
65
- }, dt = async (n) => n === i.BinanceSmartChain ? h.BSC : h.BSC, X = async ({ chain: n, symbol: t }) => {
64
+ return t != null && t.startsWith("0x") ? K({ chain: i.Avalanche, to: t.toLowerCase() }) : h.AVAX;
65
+ }, dt = async (n) => n === i.BinanceSmartChain ? h.BSC : h.BSC, J = async ({ chain: n, symbol: t }) => {
66
66
  switch (n) {
67
67
  case i.Ethereum:
68
68
  return ut(t);
@@ -73,7 +73,7 @@ const vt = (n) => {
73
73
  default:
74
74
  return h[n];
75
75
  }
76
- }, Bt = {
76
+ }, yt = {
77
77
  [x.Average]: 1.2,
78
78
  [x.Fast]: 1.5,
79
79
  [x.Fastest]: 2
@@ -92,6 +92,8 @@ const vt = (n) => {
92
92
  return t === "ETH";
93
93
  case i.Maya:
94
94
  return t === "CACAO";
95
+ case i.Kujira:
96
+ return t === "KUJI";
95
97
  case i.Cosmos:
96
98
  return t === "ATOM";
97
99
  case i.Polygon:
@@ -117,6 +119,7 @@ const vt = (n) => {
117
119
  return { identifier: "MAYA.CACAO", decimal: h.MAYA };
118
120
  case "MAYA.MAYA":
119
121
  return { identifier: "MAYA.MAYA", decimal: 4 };
122
+ case i.Kujira:
120
123
  case i.Arbitrum:
121
124
  case i.Optimism:
122
125
  case i.BitcoinCash:
@@ -142,6 +145,8 @@ const vt = (n) => {
142
145
  return "Native";
143
146
  case i.Cosmos:
144
147
  return t === "ATOM" ? "Native" : "GAIA";
148
+ case i.Kujira:
149
+ return t === "KUJI" ? "Native" : "KUJI";
145
150
  case i.Binance:
146
151
  return t === i.Binance ? "Native" : "BEP2";
147
152
  case i.BinanceSmartChain:
@@ -211,8 +216,8 @@ const vt = (n) => {
211
216
  runeAmount: s,
212
217
  assetAmount: a
213
218
  }) => {
214
- const c = m(n), o = m(e), l = m(t), u = m(s), g = m(a), $ = u.mul(o), v = g.mul(c), D = u.mul(g), K = c.mul(o), tt = l.mul($.add(v.add(D.mul(2)))), et = $.add(v.add(K.mul(2))), G = tt.div(et), H = m(r).add(G);
215
- if (G.baseValueNumber === 0)
219
+ const c = m(n), o = m(e), l = m(t), u = m(s), g = m(a), $ = u.mul(o), v = g.mul(c), D = u.mul(g), Z = c.mul(o), tt = l.mul($.add(v.add(D.mul(2)))), et = $.add(v.add(Z.mul(2))), U = tt.div(et), H = m(r).add(U);
220
+ if (U.baseValueNumber === 0)
216
221
  return H.div(l).baseValueNumber;
217
222
  const nt = l.add(H);
218
223
  return H.div(nt).baseValueNumber;
@@ -259,10 +264,10 @@ const vt = (n) => {
259
264
  default:
260
265
  return "";
261
266
  }
262
- }, B = 8, U = ({
267
+ }, y = 8, G = ({
263
268
  value: n,
264
- bigIntDecimal: t = B,
265
- decimal: e = B
269
+ bigIntDecimal: t = y,
270
+ decimal: e = y
266
271
  }) => {
267
272
  const r = n < 0n;
268
273
  let s = n.toString().substring(r ? 1 : 0);
@@ -284,8 +289,8 @@ const vt = (n) => {
284
289
  throw new Error(
285
290
  `Invalid identifier: ${n}. Expected format: <Chain>.<Ticker> or <Chain>.<Ticker>-<ContractAddress>`
286
291
  );
287
- }, S = (n) => 10n ** BigInt(n), C = (n) => Math.log10(parseFloat(n.toString()));
288
- var w, y, R, J, k, Q, O, L, b, T, V, j, I, N;
292
+ }, I = (n) => 10n ** BigInt(n), C = (n) => Math.log10(parseFloat(n.toString()));
293
+ var w, T, R, z, k, X, O, L, b, B, V, j, S, N;
289
294
  const M = class M {
290
295
  constructor(t) {
291
296
  p(this, w);
@@ -294,19 +299,19 @@ const M = class M {
294
299
  p(this, O);
295
300
  p(this, b);
296
301
  p(this, V);
297
- p(this, I);
302
+ p(this, S);
298
303
  _(this, "decimalMultiplier", 10n ** 8n);
299
304
  _(this, "bigIntValue", 0n);
300
305
  _(this, "decimal");
301
306
  const e = typeof t == "object", r = e ? t.value : t;
302
- this.decimal = e ? t.decimal : void 0, this.decimalMultiplier = S(
303
- Math.max(d(this, V, j).call(this, d(this, b, T).call(this, r)), this.decimal || 0)
304
- ), d(this, R, J).call(this, r);
307
+ this.decimal = e ? t.decimal : void 0, this.decimalMultiplier = I(
308
+ Math.max(d(this, V, j).call(this, d(this, b, B).call(this, r)), this.decimal || 0)
309
+ ), d(this, R, z).call(this, r);
305
310
  }
306
311
  static fromBigInt(t, e) {
307
312
  return new M({
308
313
  decimal: e,
309
- value: U({ value: t, bigIntDecimal: e, decimal: e })
314
+ value: G({ value: t, bigIntDecimal: e, decimal: e })
310
315
  });
311
316
  }
312
317
  static shiftDecimals({
@@ -315,7 +320,7 @@ const M = class M {
315
320
  to: r
316
321
  }) {
317
322
  return M.fromBigInt(
318
- new M(t).bigIntValue * S(r) / S(e),
323
+ new M(t).bigIntValue * I(r) / I(e),
319
324
  r
320
325
  );
321
326
  }
@@ -323,13 +328,13 @@ const M = class M {
323
328
  return parseFloat((this.bigIntValue / this.decimalMultiplier).toString());
324
329
  }
325
330
  get baseValue() {
326
- return d(this, I, N).call(this, "string");
331
+ return d(this, S, N).call(this, "string");
327
332
  }
328
333
  get baseValueNumber() {
329
- return d(this, I, N).call(this, "number");
334
+ return d(this, S, N).call(this, "number");
330
335
  }
331
336
  get baseValueBigInt() {
332
- return d(this, I, N).call(this, "number");
337
+ return d(this, S, N).call(this, "number");
333
338
  }
334
339
  get value() {
335
340
  return this.formatBigIntToSafeValue(
@@ -338,16 +343,16 @@ const M = class M {
338
343
  );
339
344
  }
340
345
  add(...t) {
341
- return d(this, w, y).call(this, "add", ...t);
346
+ return d(this, w, T).call(this, "add", ...t);
342
347
  }
343
348
  sub(...t) {
344
- return d(this, w, y).call(this, "sub", ...t);
349
+ return d(this, w, T).call(this, "sub", ...t);
345
350
  }
346
351
  mul(...t) {
347
- return d(this, w, y).call(this, "mul", ...t);
352
+ return d(this, w, T).call(this, "mul", ...t);
348
353
  }
349
354
  div(...t) {
350
- return d(this, w, y).call(this, "div", ...t);
355
+ return d(this, w, T).call(this, "div", ...t);
351
356
  }
352
357
  gt(t) {
353
358
  return this.bigIntValue > this.getBigIntValue(t);
@@ -365,10 +370,10 @@ const M = class M {
365
370
  return this.bigIntValue === this.getBigIntValue(t);
366
371
  }
367
372
  getBigIntValue(t, e) {
368
- return !e && typeof t == "object" ? t.bigIntValue : (t = typeof t == "object" ? t.value : t, d(this, O, L).call(this, d(this, b, T).call(this, t), e));
373
+ return !e && typeof t == "object" ? t.bigIntValue : (t = typeof t == "object" ? t.value : t, d(this, O, L).call(this, d(this, b, B).call(this, t), e));
369
374
  }
370
375
  formatBigIntToSafeValue(t, e) {
371
- const r = e || this.decimal || B, s = Math.max(
376
+ const r = e || this.decimal || y, s = Math.max(
372
377
  r,
373
378
  C(this.decimalMultiplier)
374
379
  ), a = t < 0n;
@@ -390,8 +395,8 @@ const M = class M {
390
395
  ) : r;
391
396
  }
392
397
  };
393
- w = new WeakSet(), y = function(t, ...e) {
394
- const r = d(this, k, Q).call(this, this, ...e), s = S(r), a = e.reduce(
398
+ w = new WeakSet(), T = function(t, ...e) {
399
+ const r = d(this, k, X).call(this, this, ...e), s = I(r), a = e.reduce(
395
400
  (o, l) => {
396
401
  const u = this.getBigIntValue(l, r);
397
402
  if (t === "div" && u === 0n)
@@ -400,24 +405,24 @@ w = new WeakSet(), y = function(t, ...e) {
400
405
  },
401
406
  //normalize is to precision multiplier base
402
407
  this.bigIntValue * s / this.decimalMultiplier
403
- ), c = U({
408
+ ), c = G({
404
409
  bigIntDecimal: r,
405
410
  decimal: Math.max(r, C(this.decimalMultiplier)),
406
411
  value: a
407
412
  });
408
413
  return new this.constructor({ decimal: this.decimal, value: c, identifier: this.toString() });
409
- }, R = new WeakSet(), J = function(t, e) {
410
- const r = d(this, b, T).call(this, t) || "0";
414
+ }, R = new WeakSet(), z = function(t, e) {
415
+ const r = d(this, b, B).call(this, t) || "0";
411
416
  this.bigIntValue = e || d(this, O, L).call(this, r);
412
- }, k = new WeakSet(), Q = function(...t) {
417
+ }, k = new WeakSet(), X = function(...t) {
413
418
  const e = t.map(
414
- (r) => typeof r == "object" ? r.decimal || C(r.decimalMultiplier) : d(this, V, j).call(this, d(this, b, T).call(this, r))
419
+ (r) => typeof r == "object" ? r.decimal || C(r.decimalMultiplier) : d(this, V, j).call(this, d(this, b, B).call(this, r))
415
420
  ).filter(Boolean);
416
- return Math.max(...e, B);
421
+ return Math.max(...e, y);
417
422
  }, O = new WeakSet(), L = function(t, e) {
418
- const r = e ? S(e) : this.decimalMultiplier, s = C(r), [a, c = ""] = t.split(".");
423
+ const r = e ? I(e) : this.decimalMultiplier, s = C(r), [a, c = ""] = t.split(".");
419
424
  return BigInt(`${a}${c.padEnd(s, "0")}`);
420
- }, b = new WeakSet(), T = function(t) {
425
+ }, b = new WeakSet(), B = function(t) {
421
426
  const r = `${typeof t == "number" ? Number(t).toLocaleString("fullwide", {
422
427
  useGrouping: !1,
423
428
  maximumFractionDigits: 20
@@ -426,9 +431,9 @@ w = new WeakSet(), y = function(t, ...e) {
426
431
  }, V = new WeakSet(), j = function(t) {
427
432
  var r;
428
433
  const e = ((r = t.split(".")[1]) == null ? void 0 : r.length) || 0;
429
- return Math.max(e, B);
430
- }, I = new WeakSet(), N = function(t) {
431
- const e = this.decimalMultiplier / S(this.decimal || 0), r = this.bigIntValue / e;
434
+ return Math.max(e, y);
435
+ }, S = new WeakSet(), N = function(t) {
436
+ const e = this.decimalMultiplier / I(this.decimal || 0), r = this.bigIntValue / e;
432
437
  switch (t) {
433
438
  case "number":
434
439
  return Number(r);
@@ -445,7 +450,7 @@ const P = (n) => {
445
450
  return q.get(n.toUpperCase()) || { decimal: h.THOR, identifier: "" };
446
451
  }, Y = async (n, t = 0) => {
447
452
  $t(n);
448
- const e = await X(F(n));
453
+ const e = await J(F(n));
449
454
  return new A({ decimal: e, value: t, identifier: n });
450
455
  };
451
456
  class A extends E {
@@ -484,7 +489,7 @@ class A extends E {
484
489
  return new A({ value: r, decimal: s, identifier: a });
485
490
  }
486
491
  static async fromTCQuote(e, r = 0) {
487
- const s = await X(F(e)), a = this.shiftDecimals({ value: r, from: h.THOR, to: s });
492
+ const s = await J(F(e)), a = this.shiftDecimals({ value: r, from: h.THOR, to: s });
488
493
  return new A({ value: a, identifier: e, decimal: s });
489
494
  }
490
495
  static fromTCQuoteStatic(e, r = 0) {
@@ -618,9 +623,9 @@ const Dt = (n) => {
618
623
  */
619
624
  helpers_number_different_decimals: 99101
620
625
  };
621
- class Z extends Error {
626
+ class Q extends Error {
622
627
  constructor(t, e) {
623
- console.error(e), super(t, { cause: { code: wt[t], message: t } }), Object.setPrototypeOf(this, Z.prototype);
628
+ console.error(e), super(t, { cause: { code: wt[t], message: t } }), Object.setPrototypeOf(this, Q.prototype);
624
629
  }
625
630
  }
626
631
  class bt extends E {
@@ -633,25 +638,25 @@ class bt extends E {
633
638
  }
634
639
  export {
635
640
  A as AssetValue,
636
- B as DEFAULT_DECIMAL,
637
- Z as SwapKitError,
641
+ y as DEFAULT_DECIMAL,
642
+ Q as SwapKitError,
638
643
  bt as SwapKitNumber,
639
644
  Mt as assetFromString,
640
- yt as derivationPathToString,
641
- U as formatBigIntToSafeValue,
642
- Bt as gasFeeMultiplier,
645
+ Tt as derivationPathToString,
646
+ G as formatBigIntToSafeValue,
647
+ yt as gasFeeMultiplier,
643
648
  _t as getAssetType,
644
649
  pt as getAsymmetricAssetShare,
645
650
  Ot as getAsymmetricAssetWithdrawAmount,
646
651
  gt as getAsymmetricRuneShare,
647
652
  Et as getAsymmetricRuneWithdrawAmount,
648
653
  ht as getCommonAssetInfo,
649
- X as getDecimal,
654
+ J as getDecimal,
650
655
  Nt as getEstimatedPoolShare,
651
656
  Rt as getLiquiditySlippage,
652
657
  kt as getMemoFor,
653
658
  Dt as getMinAmountByChain,
654
- Tt as getRequest,
659
+ Bt as getRequest,
655
660
  ft as getSymmetricPoolShare,
656
661
  Vt as getSymmetricWithdraw,
657
662
  vt as getTHORNameCost,
package/package.json CHANGED
@@ -6,15 +6,15 @@
6
6
  "vite": "4.4.9",
7
7
  "vitest": "0.34.4",
8
8
  "@internal/config": "0.0.0-internal.0",
9
- "@swapkit/tokens": "1.0.0-rc.0",
10
- "@swapkit/types": "1.0.0-rc.0"
9
+ "@swapkit/tokens": "1.0.0-rc.1",
10
+ "@swapkit/types": "1.0.0-rc.1"
11
11
  },
12
12
  "eslintConfig": {
13
13
  "extends": "../../../internal/eslint-config"
14
14
  },
15
15
  "peerDependencies": {
16
- "@swapkit/tokens": "1.0.0-rc.0",
17
- "@swapkit/types": "1.0.0-rc.0"
16
+ "@swapkit/tokens": "1.0.0-rc.1",
17
+ "@swapkit/types": "1.0.0-rc.1"
18
18
  },
19
19
  "exports": {
20
20
  ".": {
@@ -39,7 +39,7 @@
39
39
  "repository": "https://github.com/thorswap/SwapKit.git",
40
40
  "type": "module",
41
41
  "types": "./dist/index.d.ts",
42
- "version": "1.0.0-rc.1",
42
+ "version": "1.0.0-rc.2",
43
43
  "scripts": {
44
44
  "build": "vite build",
45
45
  "clean": "rm -rf dist vite.config.ts.* .turbo node_modules",
@@ -90,6 +90,9 @@ export const isGasAsset = ({ chain, symbol }: { chain: Chain; symbol: string })
90
90
  case Chain.Maya:
91
91
  return symbol === 'CACAO';
92
92
 
93
+ case Chain.Kujira:
94
+ return symbol === 'KUJI';
95
+
93
96
  case Chain.Cosmos:
94
97
  return symbol === 'ATOM';
95
98
  case Chain.Polygon:
@@ -121,6 +124,7 @@ export const getCommonAssetInfo = (
121
124
  case 'MAYA.MAYA':
122
125
  return { identifier: 'MAYA.MAYA', decimal: 4 };
123
126
 
127
+ case Chain.Kujira:
124
128
  case Chain.Arbitrum:
125
129
  case Chain.Optimism:
126
130
  case Chain.BitcoinCash:
@@ -149,6 +153,8 @@ export const getAssetType = ({ chain, symbol }: { chain: Chain; symbol: string }
149
153
 
150
154
  case Chain.Cosmos:
151
155
  return symbol === 'ATOM' ? 'Native' : 'GAIA';
156
+ case Chain.Kujira:
157
+ return symbol === 'KUJI' ? 'Native' : 'KUJI';
152
158
  case Chain.Binance:
153
159
  return symbol === Chain.Binance ? 'Native' : 'BEP2';
154
160
  case Chain.BinanceSmartChain: