@swapkit/core 1.0.0-rc.1 → 1.0.0-rc.100

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.
Files changed (43) hide show
  1. package/dist/index.cjs +2 -2
  2. package/dist/index.cjs.map +1 -0
  3. package/dist/index.d.ts +163 -29
  4. package/dist/index.es.js +6502 -1061
  5. package/dist/index.es.js.map +1 -0
  6. package/package.json +23 -30
  7. package/src/__tests__/helpers.test.ts +79 -0
  8. package/src/aggregator/contracts/avaxGeneric.ts +50 -50
  9. package/src/aggregator/contracts/avaxWoofi.ts +80 -80
  10. package/src/aggregator/contracts/bscGeneric.ts +59 -59
  11. package/src/aggregator/contracts/ethGeneric.ts +50 -50
  12. package/src/aggregator/contracts/index.ts +30 -28
  13. package/src/aggregator/contracts/pancakeV2.ts +80 -80
  14. package/src/aggregator/contracts/pangolin.ts +65 -65
  15. package/src/aggregator/contracts/routers/index.ts +58 -0
  16. package/src/aggregator/contracts/routers/kyber.ts +402 -0
  17. package/src/aggregator/contracts/routers/oneinch.ts +2188 -0
  18. package/src/aggregator/contracts/routers/pancakeswap.ts +340 -0
  19. package/src/aggregator/contracts/routers/pangolin.ts +340 -0
  20. package/src/aggregator/contracts/routers/sushiswap.ts +340 -0
  21. package/src/aggregator/contracts/routers/traderJoe.ts +340 -0
  22. package/src/aggregator/contracts/routers/uniswapv2.ts +340 -0
  23. package/src/aggregator/contracts/routers/uniswapv3.ts +254 -0
  24. package/src/aggregator/contracts/routers/woofi.ts +171 -0
  25. package/src/aggregator/contracts/sushiswap.ts +65 -65
  26. package/src/aggregator/contracts/traderJoe.ts +65 -65
  27. package/src/aggregator/contracts/uniswapV2.ts +65 -65
  28. package/src/aggregator/contracts/uniswapV2Leg.ts +70 -70
  29. package/src/aggregator/contracts/uniswapV3_100.ts +70 -70
  30. package/src/aggregator/contracts/uniswapV3_10000.ts +70 -70
  31. package/src/aggregator/contracts/uniswapV3_3000.ts +70 -70
  32. package/src/aggregator/contracts/uniswapV3_500.ts +70 -70
  33. package/src/aggregator/getSwapParams.ts +12 -12
  34. package/src/client/index.ts +214 -651
  35. package/src/client/old.ts +837 -0
  36. package/src/{client → helpers}/explorerUrls.ts +10 -9
  37. package/src/{client → helpers}/thornode.ts +5 -5
  38. package/src/index.ts +6 -4
  39. package/src/types.ts +149 -0
  40. package/dist/index-9e36735e.cjs +0 -1
  41. package/dist/index-cf1865cd.js +0 -649
  42. package/src/client/__tests__/helpers.test.ts +0 -69
  43. package/src/client/types.ts +0 -101
@@ -1,15 +1,14 @@
1
- import { Chain, ChainToExplorerUrl } from '@swapkit/types';
1
+ import { Chain, ChainToExplorerUrl } from "@swapkit/types";
2
2
 
3
3
  export const getExplorerTxUrl = ({ chain, txHash }: { txHash: string; chain: Chain }) => {
4
4
  const baseUrl = ChainToExplorerUrl[chain];
5
5
 
6
6
  switch (chain) {
7
7
  case Chain.Binance:
8
- case Chain.Bitcoin:
9
- case Chain.BitcoinCash:
10
8
  case Chain.Maya:
9
+ case Chain.Kujira:
11
10
  case Chain.THORChain:
12
- return `${baseUrl}/tx/${txHash}`;
11
+ return `${baseUrl}/tx/${txHash.startsWith("0x") ? txHash.slice(2) : txHash}`;
13
12
 
14
13
  case Chain.Arbitrum:
15
14
  case Chain.Avalanche:
@@ -17,14 +16,16 @@ export const getExplorerTxUrl = ({ chain, txHash }: { txHash: string; chain: Cha
17
16
  case Chain.Ethereum:
18
17
  case Chain.Optimism:
19
18
  case Chain.Polygon:
20
- return `${baseUrl}/tx/${txHash.startsWith('0x') ? txHash : `0x${txHash}`}`;
19
+ return `${baseUrl}/tx/${txHash.startsWith("0x") ? txHash : `0x${txHash}`}`;
21
20
 
22
21
  case Chain.Cosmos:
23
22
  return `${baseUrl}/transactions/${txHash}`;
23
+
24
+ case Chain.Litecoin:
25
+ case Chain.Bitcoin:
26
+ case Chain.BitcoinCash:
24
27
  case Chain.Dogecoin:
25
28
  return `${baseUrl}/transaction/${txHash.toLowerCase()}`;
26
- case Chain.Litecoin:
27
- return `${baseUrl}/${txHash}`;
28
29
 
29
30
  default:
30
31
  throw new Error(`Unsupported chain: ${chain}`);
@@ -43,6 +44,8 @@ export const getExplorerAddressUrl = ({ chain, address }: { address: string; cha
43
44
  case Chain.BitcoinCash:
44
45
  case Chain.Dogecoin:
45
46
  case Chain.Ethereum:
47
+ case Chain.Kujira:
48
+ case Chain.Litecoin:
46
49
  case Chain.Maya:
47
50
  case Chain.Optimism:
48
51
  case Chain.Polygon:
@@ -51,8 +54,6 @@ export const getExplorerAddressUrl = ({ chain, address }: { address: string; cha
51
54
 
52
55
  case Chain.Cosmos:
53
56
  return `${baseUrl}/account/${address}`;
54
- case Chain.Litecoin:
55
- return `${baseUrl}/${address}`;
56
57
 
57
58
  default:
58
59
  throw new Error(`Unsupported chain: ${chain}`);
@@ -1,6 +1,6 @@
1
- import { getRequest } from '@swapkit/helpers';
2
- import type { Chain } from '@swapkit/types';
3
- import { ApiUrl } from '@swapkit/types';
1
+ import { RequestClient } from "@swapkit/helpers";
2
+ import type { Chain } from "@swapkit/types";
3
+ import { ApiUrl } from "@swapkit/types";
4
4
 
5
5
  type InboundAddressData = {
6
6
  address: string;
@@ -21,11 +21,11 @@ type InboundAddressData = {
21
21
  export const getInboundData = (stagenet: boolean) => {
22
22
  const baseUrl = stagenet ? ApiUrl.ThornodeStagenet : ApiUrl.ThornodeMainnet;
23
23
 
24
- return getRequest<InboundAddressData>(`${baseUrl}/thorchain/inbound_addresses`);
24
+ return RequestClient.get<InboundAddressData>(`${baseUrl}/thorchain/inbound_addresses`);
25
25
  };
26
26
 
27
27
  export const getMimirData = (stagenet: boolean) => {
28
28
  const baseUrl = stagenet ? ApiUrl.ThornodeStagenet : ApiUrl.ThornodeMainnet;
29
29
 
30
- return getRequest<Record<string, number>>(`${baseUrl}/thorchain/mimir`);
30
+ return RequestClient.get<Record<string, number>>(`${baseUrl}/thorchain/mimir`);
31
31
  };
package/src/index.ts CHANGED
@@ -1,4 +1,6 @@
1
- export * from './client/index.ts';
2
- export * from './client/types.ts';
3
- export * from '@swapkit/helpers';
4
- export * from '@swapkit/types';
1
+ export { SwapKit } from "./client/index.ts";
2
+ export * from "./client/old.ts";
3
+ export * from "./client/index.ts";
4
+ export * from "./types.ts";
5
+ export * from "@swapkit/helpers";
6
+ export * from "@swapkit/types";
package/src/types.ts ADDED
@@ -0,0 +1,149 @@
1
+ import type { AssetValue, QuoteRoute, SwapKitNumber } from "@swapkit/helpers";
2
+ import type {
3
+ BinanceToolbox,
4
+ DepositParam,
5
+ GaiaToolbox,
6
+ KujiraToolbox,
7
+ ThorchainToolboxType,
8
+ } from "@swapkit/toolbox-cosmos";
9
+ import type {
10
+ ARBToolbox,
11
+ AVAXToolbox,
12
+ BSCToolbox,
13
+ ETHToolbox,
14
+ MATICToolbox,
15
+ OPToolbox,
16
+ } from "@swapkit/toolbox-evm";
17
+ import type { ChainflipToolbox, PolkadotToolbox } from "@swapkit/toolbox-substrate";
18
+ import type {
19
+ BCHToolbox,
20
+ BTCToolbox,
21
+ DASHToolbox,
22
+ DOGEToolbox,
23
+ LTCToolbox,
24
+ } from "@swapkit/toolbox-utxo";
25
+ import {
26
+ Chain,
27
+ type ConnectConfig,
28
+ type CosmosChain,
29
+ type EVMChain,
30
+ type FeeOption,
31
+ type UTXOChain,
32
+ type WalletOption,
33
+ } from "@swapkit/types";
34
+
35
+ export type CoreTxParams = {
36
+ assetValue: AssetValue;
37
+ recipient: string;
38
+ memo?: string;
39
+ feeOptionKey?: FeeOption;
40
+ feeRate?: number;
41
+ data?: string;
42
+ from?: string;
43
+ expiration?: number;
44
+ };
45
+
46
+ export type AddLiquidityTxns = {
47
+ runeTx?: string;
48
+ assetTx?: string;
49
+ };
50
+
51
+ export type UpgradeParams = {
52
+ runeAmount: SwapKitNumber;
53
+ recipient: string;
54
+ };
55
+
56
+ export type OldChainWallet = {
57
+ address: string;
58
+ balance: AssetValue[];
59
+ walletType: WalletOption;
60
+ };
61
+
62
+ export type OldWallet = { [key in Chain]: OldChainWallet | null };
63
+
64
+ export type ChainWallet<T extends Chain> = WalletMethods[T] & {
65
+ chain: Chain;
66
+ address: string;
67
+ balance: AssetValue[];
68
+ walletType: WalletOption;
69
+ };
70
+
71
+ export type Wallet = {
72
+ [key in Chain]?: ChainWallet<key>;
73
+ };
74
+
75
+ export type ThorchainWallet = ThorchainToolboxType & {
76
+ transfer: (params: CoreTxParams) => Promise<string>;
77
+ deposit: (params: DepositParam) => Promise<string>;
78
+ };
79
+
80
+ export type CosmosBasedWallet<T extends typeof BinanceToolbox | typeof GaiaToolbox> =
81
+ ReturnType<T> & {
82
+ transfer: (params: CoreTxParams) => Promise<string>;
83
+ };
84
+
85
+ export type SubstrateBasedWallet<T extends typeof PolkadotToolbox | typeof ChainflipToolbox> =
86
+ Awaited<ReturnType<T>>;
87
+
88
+ export type EVMWallet<
89
+ T extends typeof AVAXToolbox | typeof BSCToolbox | typeof ETHToolbox | typeof OPToolbox,
90
+ > = ReturnType<T> & {
91
+ transfer: (params: CoreTxParams) => Promise<string>;
92
+ };
93
+
94
+ export type UTXOWallet<
95
+ T extends typeof BCHToolbox | typeof BTCToolbox | typeof DOGEToolbox | typeof LTCToolbox,
96
+ > = ReturnType<T> & {
97
+ transfer: (prams: CoreTxParams) => Promise<string>;
98
+ };
99
+
100
+ export type WalletMethods = {
101
+ [Chain.Arbitrum]: EVMWallet<typeof ARBToolbox> | null;
102
+ [Chain.Avalanche]: EVMWallet<typeof AVAXToolbox> | null;
103
+ [Chain.BinanceSmartChain]: EVMWallet<typeof BSCToolbox> | null;
104
+ [Chain.Binance]: CosmosBasedWallet<typeof BinanceToolbox> | null;
105
+ [Chain.BitcoinCash]: UTXOWallet<typeof BCHToolbox> | null;
106
+ [Chain.Bitcoin]: UTXOWallet<typeof BTCToolbox> | null;
107
+ [Chain.Chainflip]: SubstrateBasedWallet<typeof ChainflipToolbox> | null;
108
+ [Chain.Cosmos]: CosmosBasedWallet<typeof GaiaToolbox> | null;
109
+ [Chain.Dash]: UTXOWallet<typeof DASHToolbox> | null;
110
+ [Chain.Dogecoin]: UTXOWallet<typeof DOGEToolbox> | null;
111
+ [Chain.Ethereum]: EVMWallet<typeof ETHToolbox> | null;
112
+ [Chain.Kujira]: CosmosBasedWallet<typeof KujiraToolbox> | null;
113
+ [Chain.Litecoin]: UTXOWallet<typeof LTCToolbox> | null;
114
+ [Chain.Maya]: ThorchainWallet | null;
115
+ [Chain.Optimism]: EVMWallet<typeof OPToolbox> | null;
116
+ [Chain.Polkadot]: SubstrateBasedWallet<typeof PolkadotToolbox> | null;
117
+ [Chain.Polygon]: EVMWallet<typeof MATICToolbox> | null;
118
+ [Chain.THORChain]: ThorchainWallet | null;
119
+ };
120
+
121
+ export type QuoteRouteV2 = {
122
+ buyAsset: string;
123
+ sellAsset: string;
124
+ sellAmount: number;
125
+ destinationAddress: string;
126
+ sourceAddress: string;
127
+ providers: string[];
128
+ };
129
+
130
+ export type SwapWithRouteParams = {
131
+ recipient: string;
132
+ route: QuoteRoute | QuoteRouteV2;
133
+ feeOptionKey?: FeeOption;
134
+ quoteId?: string;
135
+ streamSwap?: boolean;
136
+ };
137
+
138
+ type ApisType = { [key in UTXOChain]?: string | any } & {
139
+ [key in EVMChain]?: string | any;
140
+ } & {
141
+ [key in CosmosChain]?: string;
142
+ };
143
+
144
+ export type ConnectWalletParamsLocal = {
145
+ addChain: (params: ChainWallet<Chain>) => void;
146
+ config: ConnectConfig;
147
+ rpcUrls: { [chain in Chain]?: string };
148
+ apis: ApisType;
149
+ };
@@ -1 +0,0 @@
1
- "use strict";var nt=Object.defineProperty;var st=(e,t,r)=>t in e?nt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r;var j=(e,t,r)=>(st(e,typeof t!="symbol"?t+"":t,r),r),D=(e,t,r)=>{if(!t.has(e))throw TypeError("Cannot "+r)};var s=(e,t,r)=>(D(e,t,"read from private field"),r?r.call(e):t.get(e)),b=(e,t,r)=>{if(t.has(e))throw TypeError("Cannot add the same private member more than once");t instanceof WeakSet?t.add(e):t.set(e,r)},M=(e,t,r,i)=>(D(e,t,"write to private field"),i?i.call(e,r):t.set(e,r),r);var u=(e,t,r)=>(D(e,t,"access private method"),r);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const Q="6.7.1";function ot(e,t,r){const i=t.split("|").map(o=>o.trim());for(let o=0;o<i.length;o++)switch(t){case"any":return;case"bigint":case"boolean":case"number":case"string":if(typeof e===t)return}const n=new Error(`invalid value for type ${t}`);throw n.code="INVALID_ARGUMENT",n.argument=`value.${r}`,n.value=e,n}function K(e,t,r){for(let i in t){let n=t[i];const o=r?r[i]:null;o&&ot(n,o,i),Object.defineProperty(e,i,{enumerable:!0,value:n,writable:!1})}}function x(e){if(e==null)return"null";if(Array.isArray(e))return"[ "+e.map(x).join(", ")+" ]";if(e instanceof Uint8Array){const t="0123456789abcdef";let r="0x";for(let i=0;i<e.length;i++)r+=t[e[i]>>4],r+=t[e[i]&15];return r}if(typeof e=="object"&&typeof e.toJSON=="function")return x(e.toJSON());switch(typeof e){case"boolean":case"symbol":return e.toString();case"bigint":return BigInt(e).toString();case"number":return e.toString();case"string":return JSON.stringify(e);case"object":{const t=Object.keys(e);return t.sort(),"{ "+t.map(r=>`${x(r)}: ${x(e[r])}`).join(", ")+" }"}}return"[ COULD NOT SERIALIZE ]"}function W(e,t,r){{const n=[];if(r){if("message"in r||"code"in r||"name"in r)throw new Error(`value will overwrite populated values: ${x(r)}`);for(const o in r){const l=r[o];n.push(o+"="+x(l))}}n.push(`code=${t}`),n.push(`version=${Q}`),n.length&&(e+=" ("+n.join(", ")+")")}let i;switch(t){case"INVALID_ARGUMENT":i=new TypeError(e);break;case"NUMERIC_FAULT":case"BUFFER_OVERRUN":i=new RangeError(e);break;default:i=new Error(e)}return K(i,{code:t}),r&&Object.assign(i,r),i}function g(e,t,r,i){if(!e)throw W(t,r,i)}function c(e,t,r,i){g(e,t,"INVALID_ARGUMENT",{argument:r,value:i})}["NFD","NFC","NFKD","NFKC"].reduce((e,t)=>{try{if("test".normalize(t)!=="test")throw new Error("bad");if(t==="NFD"){const r=String.fromCharCode(233).normalize("NFD"),i=String.fromCharCode(101,769);if(r!==i)throw new Error("broken")}e.push(t)}catch{}return e},[]);function Y(e,t,r){if(r==null&&(r=""),e!==t){let i=r,n="new";r&&(i+=".",n+=" "+r),g(!1,`private constructor; use ${i}from* methods`,"UNSUPPORTED_OPERATION",{operation:n})}}function ft(e,t,r){if(e instanceof Uint8Array)return r?new Uint8Array(e):e;if(typeof e=="string"&&e.match(/^0x([0-9a-f][0-9a-f])*$/i)){const i=new Uint8Array((e.length-2)/2);let n=2;for(let o=0;o<i.length;o++)i[o]=parseInt(e.substring(n,n+2),16),n+=2;return i}c(!1,"invalid BytesLike value",t||"value",e)}function tt(e,t){return ft(e,t,!1)}function ut(e,t){return!(typeof e!="string"||!e.match(/^0x[0-9A-Fa-f]*$/)||typeof t=="number"&&e.length!==2+2*t||t===!0&&e.length%2!==0)}const et=BigInt(0),E=BigInt(1),S=9007199254740991;function k(e,t){const r=q(e,"value"),i=BigInt(T(t,"width"));if(g(r>>i===et,"overflow","NUMERIC_FAULT",{operation:"fromTwos",fault:"overflow",value:e}),r>>i-E){const n=(E<<i)-E;return-((~r&n)+E)}return r}function z(e,t){const r=q(e,"value"),i=BigInt(T(t,"bits"));return r&(E<<i)-E}function V(e,t){switch(typeof e){case"bigint":return e;case"number":return c(Number.isInteger(e),"underflow",t||"value",e),c(e>=-S&&e<=S,"overflow",t||"value",e),BigInt(e);case"string":try{if(e==="")throw new Error("empty string");return e[0]==="-"&&e[1]!=="-"?-BigInt(e.substring(1)):BigInt(e)}catch(r){c(!1,`invalid BigNumberish string: ${r.message}`,t||"value",e)}}c(!1,"invalid BigNumberish value",t||"value",e)}function q(e,t){const r=V(e,t);return g(r>=et,"unsigned value cannot be negative","NUMERIC_FAULT",{fault:"overflow",operation:"getUint",value:e}),r}const X="0123456789abcdef";function rt(e){if(e instanceof Uint8Array){let t="0x0";for(const r of e)t+=X[r>>4],t+=X[r&15];return BigInt(t)}return V(e)}function T(e,t){switch(typeof e){case"bigint":return c(e>=-S&&e<=S,"overflow",t||"value",e),Number(e);case"number":return c(Number.isInteger(e),"underflow",t||"value",e),c(e>=-S&&e<=S,"overflow",t||"value",e),e;case"string":try{if(e==="")throw new Error("empty string");return T(BigInt(e),t)}catch(r){c(!1,`invalid numeric string: ${r.message}`,t||"value",e)}}c(!1,"invalid numeric value",t||"value",e)}const ct=BigInt(-1),d=BigInt(0),F=BigInt(1),lt=BigInt(5),B={};let A="0000";for(;A.length<80;)A+=A;function y(e){let t=A;for(;t.length<e;)t+=t;return BigInt("1"+t.substring(0,e))}function C(e,t,r){const i=BigInt(t.width);if(t.signed){const n=F<<i-F;g(r==null||e>=-n&&e<n,"overflow","NUMERIC_FAULT",{operation:r,fault:"overflow",value:e}),e>d?e=k(z(e,i),i):e=-k(z(-e,i),i)}else{const n=F<<i;g(r==null||e>=0&&e<n,"overflow","NUMERIC_FAULT",{operation:r,fault:"overflow",value:e}),e=(e%n+n)%n&n-F}return e}function P(e){typeof e=="number"&&(e=`fixed128x${e}`);let t=!0,r=128,i=18;if(typeof e=="string"){if(e!=="fixed")if(e==="ufixed")t=!1;else{const o=e.match(/^(u?)fixed([0-9]+)x([0-9]+)$/);c(o,"invalid fixed format","format",e),t=o[1]!=="u",r=parseInt(o[2]),i=parseInt(o[3])}}else if(e){const o=e,l=(h,R,it)=>o[h]==null?it:(c(typeof o[h]===R,"invalid fixed format ("+h+" not "+R+")","format."+h,o[h]),o[h]);t=l("signed","boolean",t),r=l("width","number",r),i=l("decimals","number",i)}c(r%8===0,"invalid FixedNumber width (not byte aligned)","format.width",r),c(i<=80,"invalid FixedNumber decimals (too large)","format.decimals",i);const n=(t?"":"u")+"fixed"+String(r)+"x"+String(i);return{signed:t,width:r,decimals:i,name:n}}function at(e,t){let r="";e<d&&(r="-",e*=ct);let i=e.toString();if(t===0)return r+i;for(;i.length<=t;)i=A+i;const n=i.length-t;for(i=i.substring(0,n)+"."+i.substring(n);i[0]==="0"&&i[1]!==".";)i=i.substring(1);for(;i[i.length-1]==="0"&&i[i.length-2]!==".";)i=i.substring(0,i.length-1);return r+i}var m,f,a,N,U,w,p,$,G,L,H,v,J,_,Z;const I=class I{constructor(t,r,i){b(this,N);b(this,w);b(this,$);b(this,L);b(this,v);b(this,_);j(this,"format");b(this,m,void 0);b(this,f,void 0);b(this,a,void 0);j(this,"_value");Y(t,B,"FixedNumber"),M(this,f,r),M(this,m,i);const n=at(r,i.decimals);K(this,{format:i.name,_value:n}),M(this,a,y(i.decimals))}get signed(){return s(this,m).signed}get width(){return s(this,m).width}get decimals(){return s(this,m).decimals}get value(){return s(this,f)}addUnsafe(t){return u(this,$,G).call(this,t)}add(t){return u(this,$,G).call(this,t,"add")}subUnsafe(t){return u(this,L,H).call(this,t)}sub(t){return u(this,L,H).call(this,t,"sub")}mulUnsafe(t){return u(this,v,J).call(this,t)}mul(t){return u(this,v,J).call(this,t,"mul")}mulSignal(t){u(this,N,U).call(this,t);const r=s(this,f)*s(t,f);return g(r%s(this,a)===d,"precision lost during signalling mul","NUMERIC_FAULT",{operation:"mulSignal",fault:"underflow",value:this}),u(this,w,p).call(this,r/s(this,a),"mulSignal")}divUnsafe(t){return u(this,_,Z).call(this,t)}div(t){return u(this,_,Z).call(this,t,"div")}divSignal(t){g(s(t,f)!==d,"division by zero","NUMERIC_FAULT",{operation:"div",fault:"divide-by-zero",value:this}),u(this,N,U).call(this,t);const r=s(this,f)*s(this,a);return g(r%s(t,f)===d,"precision lost during signalling div","NUMERIC_FAULT",{operation:"divSignal",fault:"underflow",value:this}),u(this,w,p).call(this,r/s(t,f),"divSignal")}cmp(t){let r=this.value,i=t.value;const n=this.decimals-t.decimals;return n>0?i*=y(n):n<0&&(r*=y(-n)),r<i?-1:r>i?1:0}eq(t){return this.cmp(t)===0}lt(t){return this.cmp(t)<0}lte(t){return this.cmp(t)<=0}gt(t){return this.cmp(t)>0}gte(t){return this.cmp(t)>=0}floor(){let t=s(this,f);return s(this,f)<d&&(t-=s(this,a)-F),t=s(this,f)/s(this,a)*s(this,a),u(this,w,p).call(this,t,"floor")}ceiling(){let t=s(this,f);return s(this,f)>d&&(t+=s(this,a)-F),t=s(this,f)/s(this,a)*s(this,a),u(this,w,p).call(this,t,"ceiling")}round(t){if(t==null&&(t=0),t>=this.decimals)return this;const r=this.decimals-t,i=lt*y(r-1);let n=this.value+i;const o=y(r);return n=n/o*o,C(n,s(this,m),"round"),new I(B,n,s(this,m))}isZero(){return s(this,f)===d}isNegative(){return s(this,f)<d}toString(){return this._value}toUnsafeFloat(){return parseFloat(this.toString())}toFormat(t){return I.fromString(this.toString(),t)}static fromValue(t,r,i){const n=r==null?0:T(r),o=P(i);let l=V(t,"value");const h=n-o.decimals;if(h>0){const R=y(h);g(l%R===d,"value loses precision for format","NUMERIC_FAULT",{operation:"fromValue",fault:"underflow",value:t}),l/=R}else h<0&&(l*=y(-h));return C(l,o,"fromValue"),new I(B,l,o)}static fromString(t,r){const i=t.match(/^(-?)([0-9]*)\.?([0-9]*)$/);c(i&&i[2].length+i[3].length>0,"invalid FixedNumber string value","value",t);const n=P(r);let o=i[2]||"0",l=i[3]||"";for(;l.length<n.decimals;)l+=A;g(l.substring(n.decimals).match(/^0*$/),"too many decimals for format","NUMERIC_FAULT",{operation:"fromString",fault:"underflow",value:t}),l=l.substring(0,n.decimals);const h=BigInt(i[1]+o+l);return C(h,n,"fromString"),new I(B,h,n)}static fromBytes(t,r){let i=rt(tt(t,"value"));const n=P(r);return n.signed&&(i=k(i,n.width)),C(i,n,"fromBytes"),new I(B,i,n)}};m=new WeakMap,f=new WeakMap,a=new WeakMap,N=new WeakSet,U=function(t){c(this.format===t.format,"incompatible format; use fixedNumber.toFormat","other",t)},w=new WeakSet,p=function(t,r){return t=C(t,s(this,m),r),new I(B,t,s(this,m))},$=new WeakSet,G=function(t,r){return u(this,N,U).call(this,t),u(this,w,p).call(this,s(this,f)+s(t,f),r)},L=new WeakSet,H=function(t,r){return u(this,N,U).call(this,t),u(this,w,p).call(this,s(this,f)-s(t,f),r)},v=new WeakSet,J=function(t,r){return u(this,N,U).call(this,t),u(this,w,p).call(this,s(this,f)*s(t,f)/s(this,a),r)},_=new WeakSet,Z=function(t,r){return g(s(t,f)!==d,"division by zero","NUMERIC_FAULT",{operation:"div",fault:"divide-by-zero",value:this}),u(this,N,U).call(this,t),u(this,w,p).call(this,s(this,f)*s(this,a)/s(t,f),r)};let O=I;const ht=["wei","kwei","mwei","gwei","szabo","finney","ether"];function gt(e,t){c(typeof e=="string","value must be a string","value",e);let r=18;if(typeof t=="string"){const i=ht.indexOf(t);c(i>=0,"invalid unit","unit",t),r=3*i}else t!=null&&(r=T(t,"unit"));return O.fromString(e,{decimals:r,width:512}).value}exports.FixedNumber=O;exports.assert=g;exports.assertArgument=c;exports.assertPrivate=Y;exports.defineProperties=K;exports.fromTwos=k;exports.getBigInt=V;exports.getBytes=tt;exports.getNumber=T;exports.getUint=q;exports.isHexString=ut;exports.makeError=W;exports.mask=z;exports.parseUnits=gt;exports.toBigInt=rt;exports.version=Q;