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

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()},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;
1
+ "use strict";var oe=Object.create;var N=Object.defineProperty;var le=Object.getOwnPropertyDescriptor;var ue=Object.getOwnPropertyNames;var he=Object.getPrototypeOf,de=Object.prototype.hasOwnProperty;var me=(n,e,t)=>e in n?N(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var ge=(n,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let a of ue(e))!de.call(n,a)&&a!==t&&N(n,a,{get:()=>e[a],enumerable:!(i=le(e,a))||i.enumerable});return n};var _e=(n,e,t)=>(t=n!=null?oe(he(n)):{},ge(e||!n||!n.__esModule?N(t,"default",{value:n,enumerable:!0}):t,n));var g=(n,e,t)=>(me(n,typeof e!="symbol"?e+"":e,t),t),pe=(n,e,t)=>{if(!e.has(n))throw TypeError("Cannot "+t)};var C=(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 m=(n,e,t)=>(pe(n,e,"access private method"),t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("@swapkit/types"),Ce=n=>{if(n<0)throw new Error("Invalid number of year");return 10+n},fe=n=>{if(n.length>30)return!1;const e=/^[a-zA-Z0-9+_-]+$/g;return!!n.match(e)},Ae=([n,e,t,i,a])=>`${n}'/${e}'/${t}'/${i}${typeof a!="number"?"":`/${a}`}`,we=async(n,e)=>{try{const t=Object.entries(e||{}).reduce((a,[s,c])=>(c&&(a[s]=c),a),{});return(await fetch(`${n}${e?`?${new URLSearchParams(t).toString()}`:""}`,{method:"GET",mode:"cors",credentials:"omit",referrer:"https://sk.thorswap.net"})).json()}catch(t){return console.error(t),{}}},K=async(n,e,t,i=!1)=>{try{const a=await fetch(`${n}`,{body:e,headers:t,method:"POST",referrer:"https://sk.thorswap.net"});return i?a.text():a.json()}catch{return{}}},Se="0x313ce567",Y=async({chain:n,to:e})=>{try{const t=await K(r.ChainToRPC[n],JSON.stringify({method:"eth_call",params:[{to:e.toLowerCase(),data:Se},"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),r.BaseDecimal[n]}},$e=async n=>{if(n===r.Chain.Ethereum)return r.BaseDecimal.ETH;const[,e]=n.split("-");return e!=null&&e.startsWith("0x")?Y({chain:r.Chain.Ethereum,to:e}):r.BaseDecimal.ETH},be=async n=>{const[,e]=n.split("-");return e!=null&&e.startsWith("0x")?Y({chain:r.Chain.Avalanche,to:e.toLowerCase()}):r.BaseDecimal.AVAX},Be=async n=>(n===r.Chain.BinanceSmartChain,r.BaseDecimal.BSC),q=async({chain:n,symbol:e})=>{switch(n){case r.Chain.Ethereum:return $e(e);case r.Chain.Avalanche:return be(e);case r.Chain.BinanceSmartChain:return Be(e);default:return r.BaseDecimal[n]}},ye={[r.FeeOption.Average]:1.2,[r.FeeOption.Fast]:1.5,[r.FeeOption.Fastest]:2},J=({chain:n,symbol:e})=>{switch(n){case r.Chain.Bitcoin:case r.Chain.BitcoinCash:case r.Chain.Litecoin:case r.Chain.Dogecoin:case r.Chain.Binance:case r.Chain.Ethereum:case r.Chain.Avalanche:return e===n;case r.Chain.Arbitrum:case r.Chain.Optimism:return e==="ETH";case r.Chain.Maya:return e==="CACAO";case r.Chain.Kujira:return e==="KUJI";case r.Chain.Cosmos:return e==="ATOM";case r.Chain.Polygon:return e==="MATIC";case r.Chain.BinanceSmartChain:return e==="BNB";case r.Chain.THORChain:return e==="RUNE"}},z=n=>{switch(n){case"ETH.THOR":return{identifier:"ETH.THOR-0xa5f2211b9b8170f694421f2046281775e8468044",decimal:18};case"ETH.vTHOR":return{identifier:"ETH.vTHOR-0x815c23eca83261b6ec689b60cc4a58b54bc24d8d",decimal:18};case r.Chain.Cosmos:return{identifier:"GAIA.ATOM",decimal:r.BaseDecimal[n]};case r.Chain.THORChain:return{identifier:"THOR.RUNE",decimal:r.BaseDecimal[n]};case r.Chain.BinanceSmartChain:return{identifier:"BSC.BNB",decimal:r.BaseDecimal[n]};case r.Chain.Maya:return{identifier:"MAYA.CACAO",decimal:r.BaseDecimal.MAYA};case"MAYA.MAYA":return{identifier:"MAYA.MAYA",decimal:4};case r.Chain.Kujira:case r.Chain.Arbitrum:case r.Chain.Optimism:case r.Chain.BitcoinCash:case r.Chain.Litecoin:case r.Chain.Dogecoin:case r.Chain.Binance:case r.Chain.Avalanche:case r.Chain.Polygon:case r.Chain.Bitcoin:case r.Chain.Ethereum:return{identifier:`${n}.${n}`,decimal:r.BaseDecimal[n]}}},X=({chain:n,symbol:e})=>{if(e.includes("/"))return"Synth";switch(n){case r.Chain.Bitcoin:case r.Chain.BitcoinCash:case r.Chain.Dogecoin:case r.Chain.Litecoin:case r.Chain.Maya:case r.Chain.THORChain:return"Native";case r.Chain.Cosmos:return e==="ATOM"?"Native":"GAIA";case r.Chain.Kujira:return e==="KUJI"?"Native":"KUJI";case r.Chain.Binance:return e===r.Chain.Binance?"Native":"BEP2";case r.Chain.BinanceSmartChain:return e===r.Chain.Binance?"Native":"BEP20";case r.Chain.Ethereum:return e===r.Chain.Ethereum?"Native":"ERC20";case r.Chain.Avalanche:return e===r.Chain.Avalanche?"Native":"AVAX";case r.Chain.Polygon:return e===r.Chain.Polygon?"Native":"POLYGON";case r.Chain.Arbitrum:return[r.Chain.Ethereum,r.Chain.Arbitrum].includes(e)?"Native":"ARBITRUM";case r.Chain.Optimism:return[r.Chain.Ethereum,r.Chain.Optimism].includes(e)?"Native":"OPTIMISM"}},Ie=n=>{var c;const[e,...t]=n.split("."),i=n.includes("/"),a=t.join("."),s=(c=a==null?void 0:a.split("-"))==null?void 0:c[0];return{chain:e,symbol:a,ticker:s,synth:i}},Q=({liquidityUnits:n,poolUnits:e,runeDepth:t})=>{const i=d(n),a=d(e),s=d(t),c=i.mul(s),o=a.mul(a).mul(2),l=a.mul(i).mul(2),u=i.mul(i),h=a.mul(a).mul(a);return c.mul(o.sub(l).add(u)).div(h)},Z=({liquidityUnits:n,poolUnits:e,assetDepth:t})=>{const i=d(n),a=d(e),s=d(t),c=i.mul(s),o=a.mul(a).mul(2),l=a.mul(i).mul(2),u=i.mul(i),h=c.mul(o.sub(l).add(u)),p=a.mul(a).mul(a);return h.div(p)},Te=({percent:n,runeDepth:e,liquidityUnits:t,poolUnits:i})=>Q({runeDepth:e,liquidityUnits:t,poolUnits:i}).mul(n),ve=({percent:n,assetDepth:e,liquidityUnits:t,poolUnits:i})=>Z({assetDepth:e,liquidityUnits:t,poolUnits:i}).mul(n),d=n=>new ie({value:n,decimal:r.BaseDecimal.THOR}),ee=({liquidityUnits:n,poolUnits:e,runeDepth:t,assetDepth:i})=>({assetAmount:d(i).mul(n).div(e),runeAmount:d(t).mul(n).div(e)}),Me=({liquidityUnits:n,poolUnits:e,runeDepth:t,assetDepth:i,percent:a})=>Object.fromEntries(Object.entries(ee({liquidityUnits:n,poolUnits:e,runeDepth:t,assetDepth:i})).map(([s,c])=>[s,c.mul(a)])),Ve=({runeDepth:n,poolUnits:e,assetDepth:t,liquidityUnits:i,runeAmount:a,assetAmount:s})=>{const c=d(n),o=d(t),l=d(e),u=d(a),h=d(s),p=u.mul(o),$=h.mul(c),E=u.mul(h),ae=c.mul(o),re=l.mul(p.add($.add(E.mul(2)))),se=p.add($.add(ae.mul(2))),U=re.div(se),D=d(i).add(U);if(U.baseValueNumber===0)return D.div(l).baseValueNumber;const ce=l.add(D);return D.div(ce).baseValueNumber},Oe=({runeAmount:n,assetAmount:e,runeDepth:t,assetDepth:i})=>{const a=d(t),s=d(i),c=d(e),o=d(n),l=c.mul(a).sub(s.mul(o)),u=s.mul(o).add(a.mul(s));return Math.abs(l.div(u).baseValueNumber)},Ee=({symbol:n,ticker:e,chain:t})=>t==="ETH"&&e!=="ETH"?`${e}-${n.slice(-3)}`:n,De=(n,e)=>{switch(n){case r.MemoType.LEAVE:case r.MemoType.BOND:{const{address:t}=e;return`${n}:${t}`}case r.MemoType.UNBOND:{const{address:t,unbondAmount:i}=e;return`${n}:${t}:${i*10**8}`}case r.MemoType.THORNAME_REGISTER:{const{name:t,chain:i,address:a,owner:s}=e;return`${n}:${t}:${i}:${a}${s?`:${s}`:""}`}case r.MemoType.DEPOSIT:{const{chain:t,symbol:i,address:a,singleSide:s}=e;return s?`${n}:${t}/${i}::t:0`:`${n}:${t}.${i}:${a||""}:t:0`}case r.MemoType.WITHDRAW:{const{chain:t,ticker:i,symbol:a,basisPoints:s,targetAssetString:c,singleSide:o}=e,l=!o&&c?`:${c}`:"",u=Ee({chain:t,symbol:a,ticker:i});return`${n}:${t}${o?"/":"."}${u}:${s}${l}`}case r.MemoType.OPEN_LOAN:case r.MemoType.CLOSE_LOAN:{const{asset:t,address:i}=e;return`${n}:${t}:${i}`}default:return""}},G=Object.values(r.Chain),Ne=(n="")=>{const e=n.toUpperCase(),[t]=e.split(".");if(G.includes(t))return!0;const[i]=e.split("/");if(G.includes(i))return!0;throw new Error(`Invalid identifier: ${n}. Expected format: <Chain>.<Ticker> or <Chain>.<Ticker>-<ContractAddress>`)},I=8,w=n=>10n**BigInt(n),b=n=>Math.log10(parseFloat(n.toString()));function H({value:n,bigIntDecimal:e=I,decimal:t=I}){const i=n<0n;let a=n.toString().substring(i?1:0);const s=t-(a.length-1);s>0&&(a="0".repeat(s)+a);const c=a.length-t;let o=a.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?"-":""}${a.slice(0,c)}.${o}`.replace(/\.?0*$/,"")}var f,B,V,te,O,ne,v,k,A,y,M,L;const T=class T{constructor(e){C(this,f);C(this,V);C(this,O);C(this,v);C(this,A);C(this,M);g(this,"decimalMultiplier",10n**8n);g(this,"bigIntValue",0n);g(this,"decimal");const t=R(e);this.decimal=typeof e=="object"?e.decimal:void 0,this.decimalMultiplier=w(Math.max(m(this,M,L).call(this,m(this,A,y).call(this,t)),this.decimal||0)),m(this,V,te).call(this,t)}static fromBigInt(e,t){return new T({decimal:t,value:H({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 baseValue(){return this.getBaseValue("string")}get baseValueNumber(){return this.getBaseValue("number")}get baseValueBigInt(){return this.getBaseValue("bigint")}set(e){return new this.constructor({decimal:this.decimal,value:e,identifier:this.toString()})}add(...e){return m(this,f,B).call(this,"add",...e)}sub(...e){return m(this,f,B).call(this,"sub",...e)}mul(...e){return m(this,f,B).call(this,"mul",...e)}div(...e){return m(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)}getValue(e){const t=this.formatBigIntToSafeValue(this.bigIntValue,this.decimal||b(this.decimalMultiplier));switch(e){case"number":return Number(t);case"string":return t;default:return this.bigIntValue}}getBaseValue(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 this.bigIntValue}}getBigIntValue(e,t){return!t&&typeof e=="object"?e.bigIntValue:m(this,v,k).call(this,m(this,A,y).call(this,R(e)),t)}formatBigIntToSafeValue(e,t){const i=t||this.decimal||I,a=Math.max(i,b(this.decimalMultiplier)),s=e<0n,c=e.toString().substring(s?1:0),o=a-(c.length-1),l=o>0?"0".repeat(o)+c:c,u=l.length-a;let h=l.slice(-a);return parseInt(h[i])>=5?h=`${h.substring(0,i-1)}${(parseInt(h[i-1])+1).toString()}`:h=h.substring(0,i),`${s?"-":""}${l.slice(0,u)}.${h}`.replace(/\.?0*$/,"")}toSignificant(e=6){const[t,i]=this.getValue("string").split("."),a=t||"",s=i||"",c=parseInt(a)?a.length+s.length:s.length;if(c<=e)return this.getValue("string");if(a.length>=e)return a.slice(0,e).padEnd(a.length,"0");if(parseInt(a))return`${a}.${s.slice(0,e-a.length)}`.padEnd(c-e,"0");const o=parseInt(s),l=`${o}`.slice(0,e);return`0.${l.padStart(s.length-`${o}`.length+l.length,"0")}`}};f=new WeakSet,B=function(e,...t){const i=m(this,O,ne).call(this,this,...t),a=w(i),s=t.reduce((o,l)=>{const u=this.getBigIntValue(l,i);switch(e){case"add":return o+u;case"sub":return o-u;case"mul":return o*u/a;case"div":{if(u===0n)throw new RangeError("Division by zero");return o*a/u}default:return o}},this.bigIntValue*a/this.decimalMultiplier),c=H({bigIntDecimal:i,decimal:Math.max(i,b(this.decimalMultiplier)),value:s});return new this.constructor({decimal:this.decimal,value:c,identifier:this.toString()})},V=new WeakSet,te=function(e){const t=m(this,A,y).call(this,e)||"0";this.bigIntValue=m(this,v,k).call(this,t)},O=new WeakSet,ne=function(...e){const t=e.map(i=>typeof i=="object"?i.decimal||b(i.decimalMultiplier):m(this,M,L).call(this,m(this,A,y).call(this,i))).filter(Boolean);return Math.max(...t,I)},v=new WeakSet,k=function(e,t){const i=t?w(t):this.decimalMultiplier,a=b(i),[s,c=""]=e.split(".");return BigInt(`${s}${c.padEnd(a,"0")}`)},A=new WeakSet,y=function(e){const i=`${typeof e=="number"?Number(e).toLocaleString("fullwide",{useGrouping:!1,maximumFractionDigits:20}):R(e)}`.replaceAll(",",".").split(".");return i.length>1?`${i.slice(0,-1).join("")}.${i.at(-1)}`:i[0]},M=new WeakSet,L=function(e){var i;const t=((i=e.split(".")[1])==null?void 0:i.length)||0;return Math.max(t,I)};let S=T;function R(n){return typeof n=="object"?"getValue"in n?n.getValue("string"):n.value:n}let x;const P=n=>{if(!x)throw new Error("Static assets not loaded, call await AssetValue.loadStaticAssets() first");return x.get(n.toUpperCase())||{decimal:r.BaseDecimal.THOR,identifier:""}},W=async(n,e=0)=>{Ne(n);const t=await q(j(n));return new _({decimal:t,value:e,identifier:n})};class _ extends S{constructor(t){super(t.value instanceof S?t.value:{decimal:t.decimal,value:t.value});g(this,"address");g(this,"chain");g(this,"isSynthetic",!1);g(this,"isGasAsset",!1);g(this,"symbol");g(this,"ticker");g(this,"type");const i="identifier"in t?t.identifier:`${t.chain}.${t.symbol}`,a=j(i);this.type=X(a),this.chain=a.chain,this.ticker=a.ticker,this.symbol=a.symbol,this.address=a.address,this.isSynthetic=a.isSynthetic,this.isGasAsset=a.isGasAsset}get assetValue(){return`${this.getValue("string")} ${this.ticker}`}toString(){return`${this.chain}.${this.symbol}`}eq({chain:t,symbol:i}){return this.chain===t&&this.symbol===i}static async fromString(t,i=0){return W(t,i)}static fromStringSync(t,i=0){const{decimal:a,identifier:s}=P(t);return s?new _({decimal:a,identifier:s,value:i}):void 0}static async fromIdentifier(t,i=0){return W(t,i)}static fromIdentifierSync(t,i=0){const{decimal:a,identifier:s}=P(t);return new _({decimal:a,identifier:s,value:i})}static fromChainOrSignature(t,i=0){const{decimal:a,identifier:s}=z(t);return new _({value:i,decimal:a,identifier:s})}static async fromTCQuote(t,i=0){const a=await q(j(t)),s=this.shiftDecimals({value:i,from:r.BaseDecimal.THOR,to:a});return new _({value:s,identifier:t,decimal:a})}static fromTCQuoteStatic(t,i=0){const a=P(t),s=this.shiftDecimals({value:i,from:r.BaseDecimal.THOR,to:a.decimal});return new _({...a,value:s})}static async loadStaticAssets(){return new Promise(async(t,i)=>{try{const{ThorchainList:a,NativeList:s,...c}=await import("@swapkit/tokens");x=[s,...Object.values(c)].reduce((l,{tokens:u})=>(u.forEach(({identifier:h,chain:p,...$})=>{const E="decimals"in $?$.decimals:r.BaseDecimal[p];l.set(h,{identifier:h,decimal:E})}),l),new Map),t({ok:!0})}catch(a){console.error(a),i({ok:!1,error:a,message:"Couldn't load static assets. Ensure you have installed @swapkit/tokens package"})}})}}const Re=n=>{const e=_.fromChainOrSignature(n);switch(n){case r.Chain.Bitcoin:case r.Chain.Litecoin:case r.Chain.BitcoinCash:return e.add(10001);case r.Chain.Dogecoin:return e.add(100000001);case r.Chain.Avalanche:case r.Chain.Ethereum:return e.add(10*10**9);case r.Chain.THORChain:case r.Chain.Maya:return e.add(0);default:return e.add(1)}},j=n=>{const e=n.slice(0,14).includes("/"),t=n.includes(".")?n:`${r.Chain.THORChain}.${n}`,[i,a]=t.split("."),[s,c]=a.split("-");return{address:c==null?void 0:c.toLowerCase(),chain:i,isGasAsset:J({chain:i,symbol:a}),isSynthetic:e,symbol:c?`${s}-${(c==null?void 0:c.toLowerCase())??""}`:a,ticker:e?a:s}},Pe={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 F extends Error{constructor(e,t){console.error(t),super(e,{cause:{code:Pe[e],message:e}}),Object.setPrototypeOf(this,F.prototype)}}class ie extends S{eq(e){return this.eqValue(e)}}exports.AssetValue=_;exports.BigIntArithmetics=S;exports.SwapKitError=F;exports.SwapKitNumber=ie;exports.assetFromString=Ie;exports.derivationPathToString=Ae;exports.formatBigIntToSafeValue=H;exports.gasFeeMultiplier=ye;exports.getAssetType=X;exports.getAsymmetricAssetShare=Z;exports.getAsymmetricAssetWithdrawAmount=ve;exports.getAsymmetricRuneShare=Q;exports.getAsymmetricRuneWithdrawAmount=Te;exports.getCommonAssetInfo=z;exports.getDecimal=q;exports.getEstimatedPoolShare=Ve;exports.getLiquiditySlippage=Oe;exports.getMemoFor=De;exports.getMinAmountByChain=Re;exports.getRequest=we;exports.getSymmetricPoolShare=ee;exports.getSymmetricWithdraw=Me;exports.getTHORNameCost=Ce;exports.isGasAsset=J;exports.postRequest=K;exports.validateTHORName=fe;
package/dist/index.d.ts CHANGED
@@ -21,20 +21,6 @@ export declare const assetFromString: (assetString: string) => {
21
21
  };
22
22
 
23
23
  export declare class AssetValue extends BigIntArithmetics {
24
- static fromString(assetString: string, value?: number | string): Promise<AssetValue>;
25
- static fromStringSync(assetString: string, value?: number | string): AssetValue | undefined;
26
- static fromIdentifier(assetString: `${Chain}.${string}` | `${Chain}/${string}` | `${Chain}.${string}-${string}`, value?: number | string): Promise<AssetValue>;
27
- static fromIdentifierSync(identifier: TokenNames, value?: number | string): AssetValue;
28
- static fromChainOrSignature(assetString: CommonAssetString, value?: number | string): AssetValue;
29
- static fromTCQuote(identifier: TCTokenNames, value?: number | string): Promise<AssetValue>;
30
- static fromTCQuoteStatic(identifier: TCTokenNames, value?: number | string): AssetValue;
31
- static loadStaticAssets(): Promise<{
32
- ok: true;
33
- } | {
34
- ok: false;
35
- message: string;
36
- error: any;
37
- }>;
38
24
  address?: string;
39
25
  chain: Chain;
40
26
  isSynthetic: boolean;
@@ -49,6 +35,20 @@ export declare class AssetValue extends BigIntArithmetics {
49
35
  chain: Chain;
50
36
  symbol: string;
51
37
  }): boolean;
38
+ static fromString(assetString: string, value?: number | string): Promise<AssetValue>;
39
+ static fromStringSync(assetString: string, value?: number | string): AssetValue | undefined;
40
+ static fromIdentifier(assetString: `${Chain}.${string}` | `${Chain}/${string}` | `${Chain}.${string}-${string}`, value?: number | string): Promise<AssetValue>;
41
+ static fromIdentifierSync(identifier: TokenNames, value?: number | string): AssetValue;
42
+ static fromChainOrSignature(assetString: CommonAssetString, value?: number | string): AssetValue;
43
+ static fromTCQuote(identifier: TCTokenNames, value?: number | string): Promise<AssetValue>;
44
+ static fromTCQuoteStatic(identifier: TCTokenNames, value?: number | string): AssetValue;
45
+ static loadStaticAssets(): Promise<{
46
+ ok: true;
47
+ } | {
48
+ ok: false;
49
+ message: string;
50
+ error: any;
51
+ }>;
52
52
  }
53
53
 
54
54
  declare type AssetValueParams = {
@@ -61,44 +61,40 @@ declare type AssetValueParams = {
61
61
  identifier: string;
62
62
  });
63
63
 
64
- declare class BigIntArithmetics {
64
+ export declare class BigIntArithmetics {
65
65
 
66
66
  decimalMultiplier: bigint;
67
67
  bigIntValue: bigint;
68
68
  decimal?: number;
69
69
  static fromBigInt(value: bigint, decimal?: number): BigIntArithmetics;
70
70
  static shiftDecimals({ value, from, to, }: {
71
- value: BigIntArithmetics | string | number;
71
+ value: InitialisationValueType;
72
72
  from: number;
73
73
  to: number;
74
74
  }): BigIntArithmetics;
75
- constructor(valueOrParams: BigIntArithmetics | string | number | {
76
- decimal?: number;
77
- value: number | string;
78
- });
79
- get unsafeNumber(): number;
75
+ constructor(params: SKBigIntParams);
80
76
  get baseValue(): string;
81
77
  get baseValueNumber(): number;
82
78
  get baseValueBigInt(): bigint;
83
- get value(): string;
84
- add(...args: (BigIntArithmetics | string | number)[]): this;
85
- sub(...args: (BigIntArithmetics | string | number)[]): this;
86
- mul(...args: (BigIntArithmetics | string | number)[]): this;
87
- div(...args: (BigIntArithmetics | string | number)[]): this;
88
- gt(value: BigIntArithmetics | string | number): boolean;
89
- gte(value: BigIntArithmetics | string | number): boolean;
90
- lt(value: BigIntArithmetics | string | number): boolean;
91
- lte(value: BigIntArithmetics | string | number): boolean;
92
- eqValue(value: BigIntArithmetics | string | number): boolean;
93
- getBigIntValue(value: BigIntArithmetics | string | number, decimal?: number): bigint;
79
+ set(value: SKBigIntParams): any;
80
+ add(...args: InitialisationValueType[]): this;
81
+ sub(...args: InitialisationValueType[]): this;
82
+ mul(...args: InitialisationValueType[]): this;
83
+ div(...args: InitialisationValueType[]): this;
84
+ gt(value: InitialisationValueType): boolean;
85
+ gte(value: InitialisationValueType): boolean;
86
+ lt(value: InitialisationValueType): boolean;
87
+ lte(value: InitialisationValueType): boolean;
88
+ eqValue(value: InitialisationValueType): boolean;
89
+ getValue<T extends 'number' | 'string' | 'bigint'>(type: T): NumberPrimitivesType[T];
90
+ getBaseValue<T extends 'number' | 'string' | 'bigint'>(type: T): NumberPrimitivesType[T];
91
+ getBigIntValue(value: InitialisationValueType, decimal?: number): bigint;
94
92
  formatBigIntToSafeValue(value: bigint, decimal?: number): string;
95
93
  toSignificant(significantDigits?: number): string;
96
94
  }
97
95
 
98
96
  export declare type CommonAssetString = 'MAYA.MAYA' | 'ETH.THOR' | 'ETH.vTHOR' | Chain;
99
97
 
100
- export declare const DEFAULT_DECIMAL = 8;
101
-
102
98
  export declare const derivationPathToString: ([network, chainId, account, change, index]: number[]) => string;
103
99
 
104
100
  declare const errorMessages: {
@@ -159,11 +155,11 @@ declare const errorMessages: {
159
155
  readonly helpers_number_different_decimals: 99101;
160
156
  };
161
157
 
162
- export declare const formatBigIntToSafeValue: ({ value, bigIntDecimal, decimal, }: {
158
+ export declare function formatBigIntToSafeValue({ value, bigIntDecimal, decimal, }: {
163
159
  value: bigint;
164
- bigIntDecimal?: number | undefined;
165
- decimal?: number | undefined;
166
- }) => string;
160
+ bigIntDecimal?: number;
161
+ decimal?: number;
162
+ }): string;
167
163
 
168
164
  export declare const gasFeeMultiplier: Record<FeeOption, number>;
169
165
 
@@ -246,6 +242,8 @@ export declare const getSymmetricWithdraw: ({ liquidityUnits, poolUnits, runeDep
246
242
 
247
243
  export declare const getTHORNameCost: (year: number) => number;
248
244
 
245
+ declare type InitialisationValueType = NumberPrimitives | BigIntArithmetics | SwapKitNumber;
246
+
249
247
  export declare const isGasAsset: ({ chain, symbol }: {
250
248
  chain: Chain;
251
249
  symbol: string;
@@ -282,6 +280,14 @@ export declare type MemoOptions<T extends MemoType> = {
282
280
  [MemoType.THORNAME_REGISTER]: Omit<ThornameRegisterParam, 'preferredAsset' | 'expiryBlock'>;
283
281
  }[T];
284
282
 
283
+ declare type NumberPrimitives = bigint | number | string;
284
+
285
+ declare type NumberPrimitivesType = {
286
+ bigint: bigint;
287
+ number: number;
288
+ string: string;
289
+ };
290
+
285
291
  declare type PoolParams<T = {}> = T & {
286
292
  runeAmount: string;
287
293
  assetAmount: string;
@@ -296,16 +302,20 @@ declare type ShareParams<T = {}> = T & {
296
302
  poolUnits: string;
297
303
  };
298
304
 
305
+ declare type SKBigIntParams = InitialisationValueType | {
306
+ decimal?: number;
307
+ value: number | string;
308
+ };
309
+
299
310
  export declare class SwapKitError extends Error {
300
311
  constructor(errorKey: Keys, sourceError?: any);
301
312
  }
302
313
 
303
314
  export declare class SwapKitNumber extends BigIntArithmetics {
304
315
  eq(value: SwapKitValueType): boolean;
305
- toString(): string;
306
316
  }
307
317
 
308
- declare type SwapKitValueType = BigIntArithmetics | string | number;
318
+ export declare type SwapKitValueType = BigIntArithmetics | string | number;
309
319
 
310
320
  declare type TCTokenNames = (typeof ThorchainList)['tokens'][number]['identifier'];
311
321