@swapkit/helpers 1.0.0-rc.6 → 1.0.0-rc.60

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.d.ts CHANGED
@@ -1,8 +1,10 @@
1
1
  import { Chain } from '@swapkit/types';
2
+ import { ChainId } from '@swapkit/types';
2
3
  import type { CoinGeckoList } from '@swapkit/tokens';
3
4
  import { FeeOption } from '@swapkit/types';
4
5
  import type { MayaList } from '@swapkit/tokens';
5
6
  import { MemoType } from '@swapkit/types';
7
+ import type { Options } from 'ky';
6
8
  import type { PancakeswapETHList } from '@swapkit/tokens';
7
9
  import type { PancakeswapList } from '@swapkit/tokens';
8
10
  import type { PangolinList } from '@swapkit/tokens';
@@ -13,6 +15,8 @@ import type { TraderjoeList } from '@swapkit/tokens';
13
15
  import type { UniswapList } from '@swapkit/tokens';
14
16
  import type { WoofiList } from '@swapkit/tokens';
15
17
 
18
+ declare type AllowedNumberTypes = 'bigint' | 'number' | 'string';
19
+
16
20
  export declare const assetFromString: (assetString: string) => {
17
21
  chain: Chain;
18
22
  symbol: string;
@@ -23,25 +27,38 @@ export declare const assetFromString: (assetString: string) => {
23
27
  export declare class AssetValue extends BigIntArithmetics {
24
28
  address?: string;
25
29
  chain: Chain;
26
- isSynthetic: boolean;
27
30
  isGasAsset: boolean;
31
+ isSynthetic: boolean;
28
32
  symbol: string;
33
+ tax?: TokenTax;
29
34
  ticker: string;
30
35
  type: ReturnType<typeof getAssetType>;
31
- constructor(params: AssetValueParams);
32
- get assetValue(): string;
33
- toString(short?: boolean): string;
36
+ constructor({ value, decimal, tax, chain, symbol, identifier, }: {
37
+ decimal: number;
38
+ value: SwapKitValueType;
39
+ tax?: TokenTax;
40
+ } & ({
41
+ chain: Chain;
42
+ symbol: string;
43
+ identifier?: never;
44
+ } | {
45
+ identifier: string;
46
+ chain?: never;
47
+ symbol?: never;
48
+ }));
49
+ toString(): string;
50
+ toUrl(): string;
34
51
  eq({ chain, symbol }: {
35
52
  chain: Chain;
36
53
  symbol: string;
37
54
  }): 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;
55
+ chainId(): ChainId;
56
+ static fromUrl(urlAsset: string, value?: NumberPrimitives): Promise<AssetValue>;
57
+ static fromString(assetString: string, value?: NumberPrimitives): Promise<AssetValue>;
58
+ static fromIdentifier(assetString: `${Chain}.${string}` | `${Chain}/${string}` | `${Chain}.${string}-${string}` | TokenNames, value?: NumberPrimitives): Promise<AssetValue>;
59
+ static fromStringSync(assetString: string, value?: NumberPrimitives): AssetValue;
60
+ static fromIdentifierSync(assetString: TokenNames, value?: NumberPrimitives): AssetValue;
61
+ static fromChainOrSignature(assetString: CommonAssetString, value?: NumberPrimitives): AssetValue;
45
62
  static loadStaticAssets(): Promise<{
46
63
  ok: true;
47
64
  } | {
@@ -51,16 +68,6 @@ export declare class AssetValue extends BigIntArithmetics {
51
68
  }>;
52
69
  }
53
70
 
54
- declare type AssetValueParams = {
55
- decimal: number;
56
- value: SwapKitValueType;
57
- } & ({
58
- chain: Chain;
59
- symbol: string;
60
- } | {
61
- identifier: string;
62
- });
63
-
64
71
  export declare class BigIntArithmetics {
65
72
 
66
73
  decimalMultiplier: bigint;
@@ -68,24 +75,12 @@ export declare class BigIntArithmetics {
68
75
  decimal?: number;
69
76
  static fromBigInt(value: bigint, decimal?: number): BigIntArithmetics;
70
77
  static shiftDecimals({ value, from, to, }: {
71
- value: InitialisationValueType;
78
+ value: InstanceType<typeof SwapKitNumber>;
72
79
  from: number;
73
80
  to: number;
74
81
  }): BigIntArithmetics;
75
82
  constructor(params: SKBigIntParams);
76
- /**
77
- * @deprecated Use `getBaseValue('string')` instead
78
- */
79
- get baseValue(): string;
80
- /**
81
- * @deprecated Use `getBaseValue('number')` instead
82
- */
83
- get baseValueNumber(): number;
84
- /**
85
- * @deprecated Use `getBaseValue('bigint')` instead
86
- */
87
- get baseValueBigInt(): bigint;
88
- set(value: SKBigIntParams): any;
83
+ set(value: SKBigIntParams): this;
89
84
  add(...args: InitialisationValueType[]): this;
90
85
  sub(...args: InitialisationValueType[]): this;
91
86
  mul(...args: InitialisationValueType[]): this;
@@ -95,16 +90,24 @@ export declare class BigIntArithmetics {
95
90
  lt(value: InitialisationValueType): boolean;
96
91
  lte(value: InitialisationValueType): boolean;
97
92
  eqValue(value: InitialisationValueType): boolean;
98
- getValue<T extends 'number' | 'string' | 'bigint'>(type: T): NumberPrimitivesType[T];
99
- getBaseValue<T extends 'number' | 'string' | 'bigint'>(type: T): NumberPrimitivesType[T];
93
+ getValue<T extends AllowedNumberTypes>(type: T): NumberPrimitivesType[T];
94
+ getBaseValue<T extends AllowedNumberTypes>(type: T): NumberPrimitivesType[T];
100
95
  getBigIntValue(value: InitialisationValueType, decimal?: number): bigint;
101
- formatBigIntToSafeValue(value: bigint, decimal?: number): string;
102
96
  toSignificant(significantDigits?: number): string;
97
+ toFixed(fixedDigits?: number): string;
98
+ toAbbreviation(digits?: number): string;
99
+ toCurrency(currency?: string, { currencyPosition, decimal, decimalSeparator, thousandSeparator, }?: {
100
+ currencyPosition?: string | undefined;
101
+ decimal?: number | undefined;
102
+ decimalSeparator?: string | undefined;
103
+ thousandSeparator?: string | undefined;
104
+ }): string;
105
+ formatBigIntToSafeValue(value: bigint, decimal?: number): string;
103
106
  }
104
107
 
105
108
  export declare type CommonAssetString = 'MAYA.MAYA' | 'ETH.THOR' | 'ETH.vTHOR' | Chain;
106
109
 
107
- export declare const derivationPathToString: ([network, chainId, account, change, index]: number[]) => string;
110
+ export declare function derivationPathToString([network, chainId, account, change, index]: number[]): string;
108
111
 
109
112
  declare const errorMessages: {
110
113
  /**
@@ -153,6 +156,7 @@ declare const errorMessages: {
153
156
  readonly core_transaction_deposit_to_pool_error: 10310;
154
157
  readonly core_transaction_deposit_insufficient_funds_error: 10311;
155
158
  readonly core_transaction_deposit_gas_error: 10312;
159
+ readonly core_transaction_invalid_sender_address: 10313;
156
160
  readonly core_transaction_deposit_server_error: 10313;
157
161
  /**
158
162
  * Wallets
@@ -164,7 +168,17 @@ declare const errorMessages: {
164
168
  readonly helpers_number_different_decimals: 99101;
165
169
  };
166
170
 
167
- export declare const filterAssets: (assets: AssetValue[]) => AssetValue[];
171
+ export declare const filterAssets: (tokens: {
172
+ value: string;
173
+ decimal: number;
174
+ chain: Chain;
175
+ symbol: string;
176
+ }[]) => {
177
+ value: string;
178
+ decimal: number;
179
+ chain: Chain;
180
+ symbol: string;
181
+ }[];
168
182
 
169
183
  export declare function formatBigIntToSafeValue({ value, bigIntDecimal, decimal, }: {
170
184
  value: bigint;
@@ -177,16 +191,16 @@ export declare const gasFeeMultiplier: Record<FeeOption, number>;
177
191
  export declare const getAssetType: ({ chain, symbol }: {
178
192
  chain: Chain;
179
193
  symbol: string;
180
- }) => "KUJI" | "Synth" | "Native" | "GAIA" | "BEP2" | "BEP20" | "ERC20" | "AVAX" | "POLYGON" | "ARBITRUM" | "OPTIMISM";
194
+ }) => Chain.Avalanche | Chain.Cosmos | Chain.Kujira | "Synth" | "Native" | "BEP2" | "BEP20" | "ERC20" | "POLYGON" | "ARBITRUM" | "OPTIMISM";
181
195
 
182
- export declare const getAsymmetricAssetShare: ({ liquidityUnits, poolUnits, assetDepth, }: ShareParams<{
196
+ export declare function getAsymmetricAssetShare({ liquidityUnits, poolUnits, assetDepth, }: ShareParams<{
183
197
  assetDepth: string;
184
- }>) => SwapKitNumber;
198
+ }>): SwapKitNumber;
185
199
 
186
- export declare const getAsymmetricAssetWithdrawAmount: ({ percent, assetDepth, liquidityUnits, poolUnits, }: ShareParams<{
200
+ export declare function getAsymmetricAssetWithdrawAmount({ percent, assetDepth, liquidityUnits, poolUnits, }: ShareParams<{
187
201
  percent: number;
188
202
  assetDepth: string;
189
- }>) => SwapKitNumber;
203
+ }>): SwapKitNumber;
190
204
 
191
205
  /**
192
206
  * Ref: https://gitlab.com/thorchain/thornode/-/issues/657
@@ -199,14 +213,14 @@ export declare const getAsymmetricAssetWithdrawAmount: ({ percent, assetDepth, l
199
213
  * share = (s * A * (2 * T^2 - 2 * T * s + s^2))/T^3
200
214
  * (part1 * (part2 - part3 + part4)) / part5
201
215
  */
202
- export declare const getAsymmetricRuneShare: ({ liquidityUnits, poolUnits, runeDepth, }: ShareParams<{
216
+ export declare function getAsymmetricRuneShare({ liquidityUnits, poolUnits, runeDepth, }: ShareParams<{
203
217
  runeDepth: string;
204
- }>) => SwapKitNumber;
218
+ }>): SwapKitNumber;
205
219
 
206
- export declare const getAsymmetricRuneWithdrawAmount: ({ percent, runeDepth, liquidityUnits, poolUnits, }: ShareParams<{
220
+ export declare function getAsymmetricRuneWithdrawAmount({ percent, runeDepth, liquidityUnits, poolUnits, }: ShareParams<{
207
221
  percent: number;
208
222
  runeDepth: string;
209
- }>) => SwapKitNumber;
223
+ }>): SwapKitNumber;
210
224
 
211
225
  export declare const getCommonAssetInfo: (assetString: CommonAssetString) => {
212
226
  identifier: string;
@@ -218,40 +232,36 @@ export declare const getDecimal: ({ chain, symbol }: {
218
232
  symbol: string;
219
233
  }) => Promise<number>;
220
234
 
221
- export declare const getEstimatedPoolShare: ({ runeDepth, poolUnits, assetDepth, liquidityUnits, runeAmount, assetAmount, }: ShareParams<{
235
+ export declare function getEstimatedPoolShare({ runeDepth, poolUnits, assetDepth, liquidityUnits, runeAmount, assetAmount, }: ShareParams<{
222
236
  runeAmount: string;
223
237
  assetAmount: string;
224
238
  runeDepth: string;
225
239
  assetDepth: string;
226
- }>) => number;
240
+ }>): number;
227
241
 
228
- export declare const getLiquiditySlippage: ({ runeAmount, assetAmount, runeDepth, assetDepth, }: PoolParams) => number;
242
+ export declare function getLiquiditySlippage({ runeAmount, assetAmount, runeDepth, assetDepth, }: PoolParams): number;
229
243
 
230
244
  export declare const getMemoFor: <T extends MemoType>(memoType: T, options: MemoOptions<T>) => string;
231
245
 
232
- export declare const getMinAmountByChain: (chain: Chain) => AssetValue;
246
+ export declare function getMinAmountByChain(chain: Chain): AssetValue;
233
247
 
234
- export declare const getRequest: <T>(url: string, params?: {
235
- [x: string]: any;
236
- } | undefined) => Promise<T>;
237
-
238
- export declare const getSymmetricPoolShare: ({ liquidityUnits, poolUnits, runeDepth, assetDepth, }: ShareParams<{
248
+ export declare function getSymmetricPoolShare({ liquidityUnits, poolUnits, runeDepth, assetDepth, }: ShareParams<{
239
249
  runeDepth: string;
240
250
  assetDepth: string;
241
- }>) => {
251
+ }>): {
242
252
  assetAmount: SwapKitNumber;
243
253
  runeAmount: SwapKitNumber;
244
254
  };
245
255
 
246
- export declare const getSymmetricWithdraw: ({ liquidityUnits, poolUnits, runeDepth, assetDepth, percent, }: ShareParams<{
256
+ export declare function getSymmetricWithdraw({ liquidityUnits, poolUnits, runeDepth, assetDepth, percent, }: ShareParams<{
247
257
  runeDepth: string;
248
258
  assetDepth: string;
249
259
  percent: number;
250
- }>) => {
260
+ }>): {
251
261
  [k: string]: SwapKitNumber;
252
262
  };
253
263
 
254
- export declare const getTHORNameCost: (year: number) => number;
264
+ export declare function getTHORNameCost(year: number): number;
255
265
 
256
266
  declare type InitialisationValueType = NumberPrimitives | BigIntArithmetics | SwapKitNumber;
257
267
 
@@ -291,7 +301,7 @@ export declare type MemoOptions<T extends MemoType> = {
291
301
  [MemoType.THORNAME_REGISTER]: Omit<ThornameRegisterParam, 'preferredAsset' | 'expiryBlock'>;
292
302
  }[T];
293
303
 
294
- declare type NumberPrimitives = bigint | number | string;
304
+ export declare type NumberPrimitives = bigint | number | string;
295
305
 
296
306
  declare type NumberPrimitivesType = {
297
307
  bigint: bigint;
@@ -306,7 +316,10 @@ declare type PoolParams<T = {}> = T & {
306
316
  assetDepth: string;
307
317
  };
308
318
 
309
- export declare const postRequest: <T>(url: string, body: string, headers?: Record<string, string>, parseAsString?: boolean) => Promise<T>;
319
+ export declare const RequestClient: {
320
+ get: <T>(url: string | URL | Request, options?: Options) => Promise<T>;
321
+ post: <T_1>(url: string | URL | Request, options?: Options) => Promise<T_1>;
322
+ };
310
323
 
311
324
  declare type ShareParams<T = {}> = T & {
312
325
  liquidityUnits: string;
@@ -324,12 +337,11 @@ export declare class SwapKitError extends Error {
324
337
 
325
338
  export declare class SwapKitNumber extends BigIntArithmetics {
326
339
  eq(value: SwapKitValueType): boolean;
340
+ static fromBigInt(value: bigint, decimal?: number): SwapKitNumber;
327
341
  }
328
342
 
329
343
  export declare type SwapKitValueType = BigIntArithmetics | string | number;
330
344
 
331
- declare type TCTokenNames = (typeof ThorchainList)['tokens'][number]['identifier'];
332
-
333
345
  export declare type ThornameRegisterParam = {
334
346
  name: string;
335
347
  chain: string;
@@ -339,9 +351,14 @@ export declare type ThornameRegisterParam = {
339
351
  expiryBlock?: string;
340
352
  };
341
353
 
342
- declare type TokenNames = TCTokenNames | (typeof CoinGeckoList)['tokens'][number]['identifier'] | (typeof MayaList)['tokens'][number]['identifier'] | (typeof PancakeswapETHList)['tokens'][number]['identifier'] | (typeof PancakeswapList)['tokens'][number]['identifier'] | (typeof PangolinList)['tokens'][number]['identifier'] | (typeof StargateARBList)['tokens'][number]['identifier'] | (typeof SushiswapList)['tokens'][number]['identifier'] | (typeof TraderjoeList)['tokens'][number]['identifier'] | (typeof WoofiList)['tokens'][number]['identifier'] | (typeof UniswapList)['tokens'][number]['identifier'];
354
+ declare type TokenNames = (typeof ThorchainList)['tokens'][number]['identifier'] | (typeof CoinGeckoList)['tokens'][number]['identifier'] | (typeof MayaList)['tokens'][number]['identifier'] | (typeof PancakeswapETHList)['tokens'][number]['identifier'] | (typeof PancakeswapList)['tokens'][number]['identifier'] | (typeof PangolinList)['tokens'][number]['identifier'] | (typeof StargateARBList)['tokens'][number]['identifier'] | (typeof SushiswapList)['tokens'][number]['identifier'] | (typeof TraderjoeList)['tokens'][number]['identifier'] | (typeof WoofiList)['tokens'][number]['identifier'] | (typeof UniswapList)['tokens'][number]['identifier'];
355
+
356
+ declare type TokenTax = {
357
+ buy: number;
358
+ sell: number;
359
+ };
343
360
 
344
- export declare const validateTHORName: (name: string) => boolean;
361
+ export declare function validateTHORName(name: string): boolean;
345
362
 
346
363
  declare type WithAddress<T = {}> = T & {
347
364
  address: string;