@swapkit/helpers 1.0.0-rc.8 → 1.0.0-rc.80

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,5 +1,9 @@
1
+ import { BaseDecimal } from '@swapkit/types';
1
2
  import { Chain } from '@swapkit/types';
3
+ import type { ChainflipList } from '@swapkit/tokens';
4
+ import { ChainId } from '@swapkit/types';
2
5
  import type { CoinGeckoList } from '@swapkit/tokens';
6
+ import type { EVMChain } from '@swapkit/types';
3
7
  import { FeeOption } from '@swapkit/types';
4
8
  import type { MayaList } from '@swapkit/tokens';
5
9
  import { MemoType } from '@swapkit/types';
@@ -13,6 +17,8 @@ import type { TraderjoeList } from '@swapkit/tokens';
13
17
  import type { UniswapList } from '@swapkit/tokens';
14
18
  import type { WoofiList } from '@swapkit/tokens';
15
19
 
20
+ declare type AllowedNumberTypes = "bigint" | "number" | "string";
21
+
16
22
  export declare const assetFromString: (assetString: string) => {
17
23
  chain: Chain;
18
24
  symbol: string;
@@ -23,25 +29,40 @@ export declare const assetFromString: (assetString: string) => {
23
29
  export declare class AssetValue extends BigIntArithmetics {
24
30
  address?: string;
25
31
  chain: Chain;
26
- isSynthetic: boolean;
27
32
  isGasAsset: boolean;
33
+ isSynthetic: boolean;
28
34
  symbol: string;
35
+ tax?: TokenTax;
29
36
  ticker: string;
30
37
  type: ReturnType<typeof getAssetType>;
31
- constructor(params: AssetValueParams);
32
- get assetValue(): string;
33
- toString(short?: boolean): string;
38
+ constructor({ value, decimal, tax, chain, symbol, identifier, }: {
39
+ decimal: number;
40
+ value: SwapKitValueType;
41
+ tax?: TokenTax;
42
+ } & ({
43
+ chain: Chain;
44
+ symbol: string;
45
+ identifier?: never;
46
+ } | {
47
+ identifier: string;
48
+ chain?: never;
49
+ symbol?: never;
50
+ }));
51
+ toString(): string;
52
+ toUrl(): string;
34
53
  eq({ chain, symbol }: {
35
54
  chain: Chain;
36
55
  symbol: string;
37
56
  }): 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;
57
+ chainId(): ChainId;
58
+ static fromUrl(urlAsset: string, value?: NumberPrimitives): Promise<AssetValue>;
59
+ static fromString(assetString: string, value?: NumberPrimitives): Promise<AssetValue>;
60
+ static fromIdentifier(assetString: `${Chain}.${string}` | `${Chain}/${string}` | `${Chain}.${string}-${string}` | TokenNames, value?: NumberPrimitives): Promise<AssetValue>;
61
+ static fromStringSync(assetString: string, value?: NumberPrimitives): AssetValue;
62
+ static fromStringWithBase(assetString: string, value?: NumberPrimitives, baseDecimal?: number): Promise<AssetValue>;
63
+ static fromStringWithBaseSync(assetString: string, value?: NumberPrimitives, baseDecimal?: number): AssetValue;
64
+ static fromIdentifierSync(assetString: TokenNames, value?: NumberPrimitives): AssetValue;
65
+ static fromChainOrSignature(assetString: CommonAssetString, value?: NumberPrimitives): AssetValue;
45
66
  static loadStaticAssets(): Promise<{
46
67
  ok: true;
47
68
  } | {
@@ -51,16 +72,6 @@ export declare class AssetValue extends BigIntArithmetics {
51
72
  }>;
52
73
  }
53
74
 
54
- declare type AssetValueParams = {
55
- decimal: number;
56
- value: SwapKitValueType;
57
- } & ({
58
- chain: Chain;
59
- symbol: string;
60
- } | {
61
- identifier: string;
62
- });
63
-
64
75
  export declare class BigIntArithmetics {
65
76
 
66
77
  decimalMultiplier: bigint;
@@ -68,24 +79,12 @@ export declare class BigIntArithmetics {
68
79
  decimal?: number;
69
80
  static fromBigInt(value: bigint, decimal?: number): BigIntArithmetics;
70
81
  static shiftDecimals({ value, from, to, }: {
71
- value: InitialisationValueType;
82
+ value: InstanceType<typeof SwapKitNumber>;
72
83
  from: number;
73
84
  to: number;
74
85
  }): BigIntArithmetics;
75
86
  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;
87
+ set(value: SKBigIntParams): this;
89
88
  add(...args: InitialisationValueType[]): this;
90
89
  sub(...args: InitialisationValueType[]): this;
91
90
  mul(...args: InitialisationValueType[]): this;
@@ -95,16 +94,32 @@ export declare class BigIntArithmetics {
95
94
  lt(value: InitialisationValueType): boolean;
96
95
  lte(value: InitialisationValueType): boolean;
97
96
  eqValue(value: InitialisationValueType): boolean;
98
- getValue<T extends 'number' | 'string'>(type: T): NumberPrimitivesType[T];
99
- getBaseValue<T extends 'number' | 'string' | 'bigint'>(type: T): NumberPrimitivesType[T];
97
+ getValue<T extends AllowedNumberTypes>(type: T): NumberPrimitivesType[T];
98
+ getBaseValue<T extends AllowedNumberTypes>(type: T): NumberPrimitivesType[T];
100
99
  getBigIntValue(value: InitialisationValueType, decimal?: number): bigint;
101
- formatBigIntToSafeValue(value: bigint, decimal?: number): string;
102
100
  toSignificant(significantDigits?: number): string;
101
+ toFixed(fixedDigits?: number): string;
102
+ toAbbreviation(digits?: number): string;
103
+ toCurrency(currency?: string, { currencyPosition, decimal, decimalSeparator, thousandSeparator, }?: {
104
+ currencyPosition?: string | undefined;
105
+ decimal?: number | undefined;
106
+ decimalSeparator?: string | undefined;
107
+ thousandSeparator?: string | undefined;
108
+ }): string;
109
+ formatBigIntToSafeValue(value: bigint, decimal?: number): string;
103
110
  }
104
111
 
105
- export declare type CommonAssetString = 'MAYA.MAYA' | 'ETH.THOR' | 'ETH.vTHOR' | Chain;
112
+ export declare type CommonAssetString = `${Chain.Maya}.MAYA` | `${Chain.Ethereum}.THOR` | `${Chain.Ethereum}.vTHOR` | `${Chain.Kujira}.USK` | Chain;
113
+
114
+ export declare function derivationPathToString([network, chainId, account, change, index]: [
115
+ number,
116
+ number,
117
+ number,
118
+ number,
119
+ number | undefined
120
+ ]): string;
106
121
 
107
- export declare const derivationPathToString: ([network, chainId, account, change, index]: number[]) => string;
122
+ export declare type ErrorKeys = keyof typeof errorMessages;
108
123
 
109
124
  declare const errorMessages: {
110
125
  /**
@@ -115,6 +130,7 @@ declare const errorMessages: {
115
130
  readonly core_extend_error: 10003;
116
131
  readonly core_inbound_data_not_found: 10004;
117
132
  readonly core_approve_asset_address_or_from_not_found: 10005;
133
+ readonly core_plugin_not_found: 10006;
118
134
  readonly core_chain_halted: 10099;
119
135
  /**
120
136
  * Core - Wallet Connection
@@ -127,6 +143,7 @@ declare const errorMessages: {
127
143
  readonly core_wallet_trezor_not_installed: 10106;
128
144
  readonly core_wallet_keplr_not_installed: 10107;
129
145
  readonly core_wallet_okx_not_installed: 10108;
146
+ readonly core_wallet_keepkey_not_installed: 10109;
130
147
  /**
131
148
  * Core - Swap
132
149
  */
@@ -153,18 +170,49 @@ declare const errorMessages: {
153
170
  readonly core_transaction_deposit_to_pool_error: 10310;
154
171
  readonly core_transaction_deposit_insufficient_funds_error: 10311;
155
172
  readonly core_transaction_deposit_gas_error: 10312;
156
- readonly core_transaction_deposit_server_error: 10313;
173
+ readonly core_transaction_invalid_sender_address: 10313;
174
+ readonly core_transaction_deposit_server_error: 10314;
175
+ readonly core_transaction_user_rejected: 10315;
157
176
  /**
158
177
  * Wallets
159
178
  */
160
179
  readonly wallet_ledger_connection_error: 20001;
180
+ readonly wallet_ledger_connection_claimed: 20002;
181
+ readonly wallet_ledger_get_address_error: 20003;
182
+ readonly wallet_ledger_device_not_found: 20004;
183
+ readonly wallet_ledger_device_locked: 20005;
184
+ /**
185
+ * Chainflip
186
+ */
187
+ readonly chainflip_channel_error: 30001;
188
+ readonly chainflip_broker_recipient_error: 30002;
189
+ /**
190
+ * THORChain
191
+ */
161
192
  /**
162
193
  * Helpers
163
194
  */
164
195
  readonly helpers_number_different_decimals: 99101;
165
196
  };
166
197
 
167
- export declare const filterAssets: (assets: AssetValue[]) => AssetValue[];
198
+ export declare const filterAssets: (tokens: {
199
+ value: string;
200
+ decimal: number;
201
+ chain: Chain;
202
+ symbol: string;
203
+ }[]) => {
204
+ value: string;
205
+ decimal: number;
206
+ chain: Chain;
207
+ symbol: string;
208
+ }[];
209
+
210
+ export declare function findAssetBy(params: {
211
+ chain: EVMChain;
212
+ contract: string;
213
+ } | {
214
+ identifier: `${Chain}.${string}`;
215
+ }): Promise<TokenNames | undefined>;
168
216
 
169
217
  export declare function formatBigIntToSafeValue({ value, bigIntDecimal, decimal, }: {
170
218
  value: bigint;
@@ -179,14 +227,14 @@ export declare const getAssetType: ({ chain, symbol }: {
179
227
  symbol: string;
180
228
  }) => Chain.Avalanche | Chain.Cosmos | Chain.Kujira | "Synth" | "Native" | "BEP2" | "BEP20" | "ERC20" | "POLYGON" | "ARBITRUM" | "OPTIMISM";
181
229
 
182
- export declare const getAsymmetricAssetShare: ({ liquidityUnits, poolUnits, assetDepth, }: ShareParams<{
230
+ export declare function getAsymmetricAssetShare({ liquidityUnits, poolUnits, assetDepth, }: ShareParams<{
183
231
  assetDepth: string;
184
- }>) => SwapKitNumber;
232
+ }>): SwapKitNumber;
185
233
 
186
- export declare const getAsymmetricAssetWithdrawAmount: ({ percent, assetDepth, liquidityUnits, poolUnits, }: ShareParams<{
234
+ export declare function getAsymmetricAssetWithdrawAmount({ percent, assetDepth, liquidityUnits, poolUnits, }: ShareParams<{
187
235
  percent: number;
188
236
  assetDepth: string;
189
- }>) => SwapKitNumber;
237
+ }>): SwapKitNumber;
190
238
 
191
239
  /**
192
240
  * Ref: https://gitlab.com/thorchain/thornode/-/issues/657
@@ -199,14 +247,14 @@ export declare const getAsymmetricAssetWithdrawAmount: ({ percent, assetDepth, l
199
247
  * share = (s * A * (2 * T^2 - 2 * T * s + s^2))/T^3
200
248
  * (part1 * (part2 - part3 + part4)) / part5
201
249
  */
202
- export declare const getAsymmetricRuneShare: ({ liquidityUnits, poolUnits, runeDepth, }: ShareParams<{
250
+ export declare function getAsymmetricRuneShare({ liquidityUnits, poolUnits, runeDepth, }: ShareParams<{
203
251
  runeDepth: string;
204
- }>) => SwapKitNumber;
252
+ }>): SwapKitNumber;
205
253
 
206
- export declare const getAsymmetricRuneWithdrawAmount: ({ percent, runeDepth, liquidityUnits, poolUnits, }: ShareParams<{
254
+ export declare function getAsymmetricRuneWithdrawAmount({ percent, runeDepth, liquidityUnits, poolUnits, }: ShareParams<{
207
255
  percent: number;
208
256
  runeDepth: string;
209
- }>) => SwapKitNumber;
257
+ }>): SwapKitNumber;
210
258
 
211
259
  export declare const getCommonAssetInfo: (assetString: CommonAssetString) => {
212
260
  identifier: string;
@@ -216,42 +264,40 @@ export declare const getCommonAssetInfo: (assetString: CommonAssetString) => {
216
264
  export declare const getDecimal: ({ chain, symbol }: {
217
265
  chain: Chain;
218
266
  symbol: string;
219
- }) => Promise<number>;
267
+ }) => BaseDecimal | Promise<number>;
220
268
 
221
- export declare const getEstimatedPoolShare: ({ runeDepth, poolUnits, assetDepth, liquidityUnits, runeAmount, assetAmount, }: ShareParams<{
269
+ export declare function getEstimatedPoolShare({ runeDepth, poolUnits, assetDepth, liquidityUnits, runeAmount, assetAmount, }: ShareParams<{
222
270
  runeAmount: string;
223
271
  assetAmount: string;
224
272
  runeDepth: string;
225
273
  assetDepth: string;
226
- }>) => number;
274
+ }>): number;
227
275
 
228
- export declare const getLiquiditySlippage: ({ runeAmount, assetAmount, runeDepth, assetDepth, }: PoolParams) => number;
276
+ export declare function getLiquiditySlippage({ runeAmount, assetAmount, runeDepth, assetDepth, }: PoolParams): number;
229
277
 
230
- export declare const getMemoFor: <T extends MemoType>(memoType: T, options: MemoOptions<T>) => string;
278
+ export declare function getMAYANameCost(year: number): number;
231
279
 
232
- export declare const getMinAmountByChain: (chain: Chain) => AssetValue;
280
+ export declare const getMemoFor: <T extends MemoType>(memoType: T, options: MemoOptions<T>) => string;
233
281
 
234
- export declare const getRequest: <T>(url: string, params?: {
235
- [x: string]: any;
236
- } | undefined) => Promise<T>;
282
+ export declare function getMinAmountByChain(chain: Chain): AssetValue;
237
283
 
238
- export declare const getSymmetricPoolShare: ({ liquidityUnits, poolUnits, runeDepth, assetDepth, }: ShareParams<{
284
+ export declare function getSymmetricPoolShare({ liquidityUnits, poolUnits, runeDepth, assetDepth, }: ShareParams<{
239
285
  runeDepth: string;
240
286
  assetDepth: string;
241
- }>) => {
287
+ }>): {
242
288
  assetAmount: SwapKitNumber;
243
289
  runeAmount: SwapKitNumber;
244
290
  };
245
291
 
246
- export declare const getSymmetricWithdraw: ({ liquidityUnits, poolUnits, runeDepth, assetDepth, percent, }: ShareParams<{
292
+ export declare function getSymmetricWithdraw({ liquidityUnits, poolUnits, runeDepth, assetDepth, percent, }: ShareParams<{
247
293
  runeDepth: string;
248
294
  assetDepth: string;
249
295
  percent: number;
250
- }>) => {
296
+ }>): {
251
297
  [k: string]: SwapKitNumber;
252
298
  };
253
299
 
254
- export declare const getTHORNameCost: (year: number) => number;
300
+ export declare function getTHORNameCost(year: number): number;
255
301
 
256
302
  declare type InitialisationValueType = NumberPrimitives | BigIntArithmetics | SwapKitNumber;
257
303
 
@@ -260,22 +306,27 @@ export declare const isGasAsset: ({ chain, symbol }: {
260
306
  symbol: string;
261
307
  }) => boolean;
262
308
 
263
- export declare type Keys = keyof typeof errorMessages;
264
-
265
309
  export declare type MemoOptions<T extends MemoType> = {
266
- [MemoType.BOND]: WithAddress;
267
- [MemoType.LEAVE]: WithAddress;
268
- [MemoType.CLOSE_LOAN]: WithAddress<{
310
+ [MemoType.BOND]: {
311
+ address: string;
312
+ };
313
+ [MemoType.LEAVE]: {
314
+ address: string;
315
+ };
316
+ [MemoType.CLOSE_LOAN]: {
317
+ address: string;
269
318
  asset: string;
270
319
  minAmount?: string;
271
- }>;
272
- [MemoType.OPEN_LOAN]: WithAddress<{
320
+ };
321
+ [MemoType.OPEN_LOAN]: {
322
+ address: string;
273
323
  asset: string;
274
324
  minAmount?: string;
275
- }>;
276
- [MemoType.UNBOND]: WithAddress<{
325
+ };
326
+ [MemoType.UNBOND]: {
327
+ address: string;
277
328
  unbondAmount: number;
278
- }>;
329
+ };
279
330
  [MemoType.DEPOSIT]: WithChain<{
280
331
  symbol: string;
281
332
  address?: string;
@@ -288,10 +339,10 @@ export declare type MemoOptions<T extends MemoType> = {
288
339
  targetAssetString?: string;
289
340
  singleSide?: boolean;
290
341
  }>;
291
- [MemoType.THORNAME_REGISTER]: Omit<ThornameRegisterParam, 'preferredAsset' | 'expiryBlock'>;
342
+ [MemoType.THORNAME_REGISTER]: Omit<ThornameRegisterParam, "preferredAsset" | "expiryBlock">;
292
343
  }[T];
293
344
 
294
- declare type NumberPrimitives = bigint | number | string;
345
+ export declare type NumberPrimitives = bigint | number | string;
295
346
 
296
347
  declare type NumberPrimitivesType = {
297
348
  bigint: bigint;
@@ -299,16 +350,14 @@ declare type NumberPrimitivesType = {
299
350
  string: string;
300
351
  };
301
352
 
302
- declare type PoolParams<T = {}> = T & {
353
+ declare type PoolParams = {
303
354
  runeAmount: string;
304
355
  assetAmount: string;
305
356
  runeDepth: string;
306
357
  assetDepth: string;
307
358
  };
308
359
 
309
- export declare const postRequest: <T>(url: string, body: string, headers?: Record<string, string>, parseAsString?: boolean) => Promise<T>;
310
-
311
- declare type ShareParams<T = {}> = T & {
360
+ declare type ShareParams<T extends {}> = T & {
312
361
  liquidityUnits: string;
313
362
  poolUnits: string;
314
363
  };
@@ -319,17 +368,16 @@ declare type SKBigIntParams = InitialisationValueType | {
319
368
  };
320
369
 
321
370
  export declare class SwapKitError extends Error {
322
- constructor(errorKey: Keys, sourceError?: any);
371
+ constructor(errorKey: ErrorKeys, sourceError?: any);
323
372
  }
324
373
 
325
374
  export declare class SwapKitNumber extends BigIntArithmetics {
326
375
  eq(value: SwapKitValueType): boolean;
376
+ static fromBigInt(value: bigint, decimal?: number): SwapKitNumber;
327
377
  }
328
378
 
329
379
  export declare type SwapKitValueType = BigIntArithmetics | string | number;
330
380
 
331
- declare type TCTokenNames = (typeof ThorchainList)['tokens'][number]['identifier'];
332
-
333
381
  export declare type ThornameRegisterParam = {
334
382
  name: string;
335
383
  chain: string;
@@ -339,16 +387,22 @@ export declare type ThornameRegisterParam = {
339
387
  expiryBlock?: string;
340
388
  };
341
389
 
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'];
343
-
344
- export declare const validateTHORName: (name: string) => boolean;
390
+ 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"] | (typeof ChainflipList)["tokens"][number]["identifier"];
345
391
 
346
- declare type WithAddress<T = {}> = T & {
347
- address: string;
392
+ declare type TokenTax = {
393
+ buy: number;
394
+ sell: number;
348
395
  };
349
396
 
350
- declare type WithChain<T = {}> = T & {
397
+ export declare function validateMAYAName(name: string): boolean;
398
+
399
+ export declare function validateTHORName(name: string): boolean;
400
+
401
+ declare type WithChain<T extends {}> = T & {
351
402
  chain: Chain;
352
403
  };
353
404
 
405
+
406
+ export * from "@swapkit/api";
407
+
354
408
  export { }