@swapkit/helpers 1.0.0-rc.70 → 1.0.0-rc.72
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 +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +33 -19
- package/dist/index.es.js +400 -363
- package/dist/index.es.js.map +1 -1
- package/package.json +12 -16
- package/src/helpers/__tests__/asset.test.ts +64 -62
- package/src/helpers/__tests__/memo.test.ts +42 -40
- package/src/helpers/__tests__/others.test.ts +31 -31
- package/src/helpers/asset.ts +53 -52
- package/src/helpers/liquidity.ts +9 -9
- package/src/helpers/memo.ts +17 -18
- package/src/helpers/others.ts +3 -3
- package/src/helpers/validators.ts +5 -5
- package/src/index.ts +9 -9
- package/src/modules/__tests__/assetValue.test.ts +245 -144
- package/src/modules/__tests__/bigIntArithmetics.test.ts +8 -8
- package/src/modules/__tests__/swapKitNumber.test.ts +232 -232
- package/src/modules/assetValue.ts +78 -40
- package/src/modules/bigIntArithmetics.ts +86 -86
- package/src/modules/swapKitError.ts +17 -2
- package/src/modules/swapKitNumber.ts +1 -1
- package/src/types.ts +13 -13
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { BaseDecimal } from '@swapkit/types';
|
|
1
2
|
import { Chain } from '@swapkit/types';
|
|
2
3
|
import type { ChainflipList } from '@swapkit/tokens';
|
|
3
4
|
import { ChainId } from '@swapkit/types';
|
|
@@ -15,7 +16,7 @@ import type { TraderjoeList } from '@swapkit/tokens';
|
|
|
15
16
|
import type { UniswapList } from '@swapkit/tokens';
|
|
16
17
|
import type { WoofiList } from '@swapkit/tokens';
|
|
17
18
|
|
|
18
|
-
declare type AllowedNumberTypes =
|
|
19
|
+
declare type AllowedNumberTypes = "bigint" | "number" | "string";
|
|
19
20
|
|
|
20
21
|
export declare const assetFromString: (assetString: string) => {
|
|
21
22
|
chain: Chain;
|
|
@@ -57,6 +58,8 @@ export declare class AssetValue extends BigIntArithmetics {
|
|
|
57
58
|
static fromString(assetString: string, value?: NumberPrimitives): Promise<AssetValue>;
|
|
58
59
|
static fromIdentifier(assetString: `${Chain}.${string}` | `${Chain}/${string}` | `${Chain}.${string}-${string}` | TokenNames, value?: NumberPrimitives): Promise<AssetValue>;
|
|
59
60
|
static fromStringSync(assetString: string, value?: NumberPrimitives): AssetValue;
|
|
61
|
+
static fromStringWithBase(assetString: string, value?: NumberPrimitives, baseDecimal?: number): Promise<AssetValue>;
|
|
62
|
+
static fromStringWithBaseSync(assetString: string, value?: NumberPrimitives, baseDecimal?: number): AssetValue;
|
|
60
63
|
static fromIdentifierSync(assetString: TokenNames, value?: NumberPrimitives): AssetValue;
|
|
61
64
|
static fromChainOrSignature(assetString: CommonAssetString, value?: NumberPrimitives): AssetValue;
|
|
62
65
|
static loadStaticAssets(): Promise<{
|
|
@@ -144,6 +147,7 @@ declare const errorMessages: {
|
|
|
144
147
|
readonly core_swap_contract_not_supported: 10205;
|
|
145
148
|
readonly core_swap_transaction_error: 10206;
|
|
146
149
|
readonly core_swap_quote_mode_not_supported: 10207;
|
|
150
|
+
readonly core_swap_provider_not_found: 10208;
|
|
147
151
|
/**
|
|
148
152
|
* Core - Transaction
|
|
149
153
|
*/
|
|
@@ -170,6 +174,13 @@ declare const errorMessages: {
|
|
|
170
174
|
readonly wallet_ledger_get_address_error: 20003;
|
|
171
175
|
readonly wallet_ledger_device_not_found: 20004;
|
|
172
176
|
readonly wallet_ledger_device_locked: 20005;
|
|
177
|
+
/**
|
|
178
|
+
* Chainflip
|
|
179
|
+
*/
|
|
180
|
+
readonly chainflip_channel_error: 30001;
|
|
181
|
+
/**
|
|
182
|
+
* THORChain
|
|
183
|
+
*/
|
|
173
184
|
/**
|
|
174
185
|
* Helpers
|
|
175
186
|
*/
|
|
@@ -238,7 +249,7 @@ export declare const getCommonAssetInfo: (assetString: CommonAssetString) => {
|
|
|
238
249
|
export declare const getDecimal: ({ chain, symbol }: {
|
|
239
250
|
chain: Chain;
|
|
240
251
|
symbol: string;
|
|
241
|
-
}) => Promise<number>;
|
|
252
|
+
}) => BaseDecimal | Promise<number>;
|
|
242
253
|
|
|
243
254
|
export declare function getEstimatedPoolShare({ runeDepth, poolUnits, assetDepth, liquidityUnits, runeAmount, assetAmount, }: ShareParams<{
|
|
244
255
|
runeAmount: string;
|
|
@@ -279,19 +290,26 @@ export declare const isGasAsset: ({ chain, symbol }: {
|
|
|
279
290
|
}) => boolean;
|
|
280
291
|
|
|
281
292
|
export declare type MemoOptions<T extends MemoType> = {
|
|
282
|
-
[MemoType.BOND]:
|
|
283
|
-
|
|
284
|
-
|
|
293
|
+
[MemoType.BOND]: {
|
|
294
|
+
address: string;
|
|
295
|
+
};
|
|
296
|
+
[MemoType.LEAVE]: {
|
|
297
|
+
address: string;
|
|
298
|
+
};
|
|
299
|
+
[MemoType.CLOSE_LOAN]: {
|
|
300
|
+
address: string;
|
|
285
301
|
asset: string;
|
|
286
302
|
minAmount?: string;
|
|
287
|
-
}
|
|
288
|
-
[MemoType.OPEN_LOAN]:
|
|
303
|
+
};
|
|
304
|
+
[MemoType.OPEN_LOAN]: {
|
|
305
|
+
address: string;
|
|
289
306
|
asset: string;
|
|
290
307
|
minAmount?: string;
|
|
291
|
-
}
|
|
292
|
-
[MemoType.UNBOND]:
|
|
308
|
+
};
|
|
309
|
+
[MemoType.UNBOND]: {
|
|
310
|
+
address: string;
|
|
293
311
|
unbondAmount: number;
|
|
294
|
-
}
|
|
312
|
+
};
|
|
295
313
|
[MemoType.DEPOSIT]: WithChain<{
|
|
296
314
|
symbol: string;
|
|
297
315
|
address?: string;
|
|
@@ -304,7 +322,7 @@ export declare type MemoOptions<T extends MemoType> = {
|
|
|
304
322
|
targetAssetString?: string;
|
|
305
323
|
singleSide?: boolean;
|
|
306
324
|
}>;
|
|
307
|
-
[MemoType.THORNAME_REGISTER]: Omit<ThornameRegisterParam,
|
|
325
|
+
[MemoType.THORNAME_REGISTER]: Omit<ThornameRegisterParam, "preferredAsset" | "expiryBlock">;
|
|
308
326
|
}[T];
|
|
309
327
|
|
|
310
328
|
export declare type NumberPrimitives = bigint | number | string;
|
|
@@ -315,14 +333,14 @@ declare type NumberPrimitivesType = {
|
|
|
315
333
|
string: string;
|
|
316
334
|
};
|
|
317
335
|
|
|
318
|
-
declare type PoolParams
|
|
336
|
+
declare type PoolParams = {
|
|
319
337
|
runeAmount: string;
|
|
320
338
|
assetAmount: string;
|
|
321
339
|
runeDepth: string;
|
|
322
340
|
assetDepth: string;
|
|
323
341
|
};
|
|
324
342
|
|
|
325
|
-
declare type ShareParams<T
|
|
343
|
+
declare type ShareParams<T extends {}> = T & {
|
|
326
344
|
liquidityUnits: string;
|
|
327
345
|
poolUnits: string;
|
|
328
346
|
};
|
|
@@ -352,7 +370,7 @@ export declare type ThornameRegisterParam = {
|
|
|
352
370
|
expiryBlock?: string;
|
|
353
371
|
};
|
|
354
372
|
|
|
355
|
-
declare type TokenNames = (typeof ThorchainList)[
|
|
373
|
+
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"];
|
|
356
374
|
|
|
357
375
|
declare type TokenTax = {
|
|
358
376
|
buy: number;
|
|
@@ -361,11 +379,7 @@ declare type TokenTax = {
|
|
|
361
379
|
|
|
362
380
|
export declare function validateTHORName(name: string): boolean;
|
|
363
381
|
|
|
364
|
-
declare type
|
|
365
|
-
address: string;
|
|
366
|
-
};
|
|
367
|
-
|
|
368
|
-
declare type WithChain<T = {}> = T & {
|
|
382
|
+
declare type WithChain<T extends {}> = T & {
|
|
369
383
|
chain: Chain;
|
|
370
384
|
};
|
|
371
385
|
|