@swapkit/helpers 0.0.0-nightly-20240208140027
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/LICENSE +201 -0
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +490 -0
- package/dist/index.es.js +1241 -0
- package/dist/index.es.js.map +1 -0
- package/package.json +53 -0
- package/src/helpers/__tests__/asset.test.ts +157 -0
- package/src/helpers/__tests__/memo.test.ts +79 -0
- package/src/helpers/__tests__/others.test.ts +59 -0
- package/src/helpers/asset.ts +227 -0
- package/src/helpers/liquidity.ts +180 -0
- package/src/helpers/memo.ts +93 -0
- package/src/helpers/others.ts +20 -0
- package/src/helpers/validators.ts +18 -0
- package/src/index.ts +17 -0
- package/src/modules/__tests__/assetValue.test.ts +409 -0
- package/src/modules/__tests__/bigIntArithmetics.test.ts +30 -0
- package/src/modules/__tests__/swapKitNumber.test.ts +533 -0
- package/src/modules/assetValue.ts +266 -0
- package/src/modules/bigIntArithmetics.ts +419 -0
- package/src/modules/swapKitError.ts +79 -0
- package/src/modules/swapKitNumber.ts +16 -0
- package/src/types.ts +30 -0
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
const errorMessages = {
|
|
2
|
+
/**
|
|
3
|
+
* Core
|
|
4
|
+
*/
|
|
5
|
+
core_wallet_connection_not_found: 10001,
|
|
6
|
+
core_estimated_max_spendable_chain_not_supported: 10002,
|
|
7
|
+
core_extend_error: 10003,
|
|
8
|
+
core_inbound_data_not_found: 10004,
|
|
9
|
+
core_approve_asset_address_or_from_not_found: 10005,
|
|
10
|
+
core_chain_halted: 10099,
|
|
11
|
+
/**
|
|
12
|
+
* Core - Wallet Connection
|
|
13
|
+
*/
|
|
14
|
+
core_wallet_xdefi_not_installed: 10101,
|
|
15
|
+
core_wallet_evmwallet_not_installed: 10102,
|
|
16
|
+
core_wallet_walletconnect_not_installed: 10103,
|
|
17
|
+
core_wallet_keystore_not_installed: 10104,
|
|
18
|
+
core_wallet_ledger_not_installed: 10105,
|
|
19
|
+
core_wallet_trezor_not_installed: 10106,
|
|
20
|
+
core_wallet_keplr_not_installed: 10107,
|
|
21
|
+
core_wallet_okx_not_installed: 10108,
|
|
22
|
+
core_wallet_keepkey_not_installed: 10109,
|
|
23
|
+
/**
|
|
24
|
+
* Core - Swap
|
|
25
|
+
*/
|
|
26
|
+
core_swap_invalid_params: 10200,
|
|
27
|
+
core_swap_route_not_complete: 10201,
|
|
28
|
+
core_swap_asset_not_recognized: 10202,
|
|
29
|
+
core_swap_contract_not_found: 10203,
|
|
30
|
+
core_swap_route_transaction_not_found: 10204,
|
|
31
|
+
core_swap_contract_not_supported: 10205,
|
|
32
|
+
core_swap_transaction_error: 10206,
|
|
33
|
+
core_swap_quote_mode_not_supported: 10207,
|
|
34
|
+
/**
|
|
35
|
+
* Core - Transaction
|
|
36
|
+
*/
|
|
37
|
+
core_transaction_deposit_error: 10301,
|
|
38
|
+
core_transaction_create_liquidity_rune_error: 10302,
|
|
39
|
+
core_transaction_create_liquidity_asset_error: 10303,
|
|
40
|
+
core_transaction_create_liquidity_invalid_params: 10304,
|
|
41
|
+
core_transaction_add_liquidity_invalid_params: 10305,
|
|
42
|
+
core_transaction_add_liquidity_no_rune_address: 10306,
|
|
43
|
+
core_transaction_add_liquidity_rune_error: 10307,
|
|
44
|
+
core_transaction_add_liquidity_asset_error: 10308,
|
|
45
|
+
core_transaction_withdraw_error: 10309,
|
|
46
|
+
core_transaction_deposit_to_pool_error: 10310,
|
|
47
|
+
core_transaction_deposit_insufficient_funds_error: 10311,
|
|
48
|
+
core_transaction_deposit_gas_error: 10312,
|
|
49
|
+
core_transaction_invalid_sender_address: 10313,
|
|
50
|
+
core_transaction_deposit_server_error: 10314,
|
|
51
|
+
core_transaction_user_rejected: 10315,
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Wallets
|
|
55
|
+
*/
|
|
56
|
+
wallet_ledger_connection_error: 20001,
|
|
57
|
+
wallet_ledger_connection_claimed: 20002,
|
|
58
|
+
wallet_ledger_get_address_error: 20003,
|
|
59
|
+
wallet_ledger_device_not_found: 20004,
|
|
60
|
+
wallet_ledger_device_locked: 20005,
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Helpers
|
|
64
|
+
*/
|
|
65
|
+
helpers_number_different_decimals: 99101,
|
|
66
|
+
} as const;
|
|
67
|
+
|
|
68
|
+
export type ErrorKeys = keyof typeof errorMessages;
|
|
69
|
+
|
|
70
|
+
export class SwapKitError extends Error {
|
|
71
|
+
constructor(errorKey: ErrorKeys, sourceError?: any) {
|
|
72
|
+
if (sourceError) {
|
|
73
|
+
console.error(sourceError, { stack: sourceError?.stack, message: sourceError?.message });
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
super(errorKey, { cause: { code: errorMessages[errorKey], message: errorKey } });
|
|
77
|
+
Object.setPrototypeOf(this, SwapKitError.prototype);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { BigIntArithmetics, formatBigIntToSafeValue } from './bigIntArithmetics.ts';
|
|
2
|
+
|
|
3
|
+
export type SwapKitValueType = BigIntArithmetics | string | number;
|
|
4
|
+
|
|
5
|
+
export class SwapKitNumber extends BigIntArithmetics {
|
|
6
|
+
eq(value: SwapKitValueType) {
|
|
7
|
+
return this.eqValue(value);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
static fromBigInt(value: bigint, decimal?: number) {
|
|
11
|
+
return new SwapKitNumber({
|
|
12
|
+
decimal,
|
|
13
|
+
value: formatBigIntToSafeValue({ value, bigIntDecimal: decimal, decimal }),
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
}
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
ChainflipList,
|
|
3
|
+
CoinGeckoList,
|
|
4
|
+
MayaList,
|
|
5
|
+
PancakeswapETHList,
|
|
6
|
+
PancakeswapList,
|
|
7
|
+
PangolinList,
|
|
8
|
+
StargateARBList,
|
|
9
|
+
SushiswapList,
|
|
10
|
+
ThorchainList,
|
|
11
|
+
TraderjoeList,
|
|
12
|
+
UniswapList,
|
|
13
|
+
WoofiList,
|
|
14
|
+
} from '@swapkit/tokens';
|
|
15
|
+
|
|
16
|
+
export type TokenTax = { buy: number; sell: number };
|
|
17
|
+
|
|
18
|
+
export type TokenNames =
|
|
19
|
+
| (typeof ThorchainList)['tokens'][number]['identifier']
|
|
20
|
+
| (typeof CoinGeckoList)['tokens'][number]['identifier']
|
|
21
|
+
| (typeof MayaList)['tokens'][number]['identifier']
|
|
22
|
+
| (typeof PancakeswapETHList)['tokens'][number]['identifier']
|
|
23
|
+
| (typeof PancakeswapList)['tokens'][number]['identifier']
|
|
24
|
+
| (typeof PangolinList)['tokens'][number]['identifier']
|
|
25
|
+
| (typeof StargateARBList)['tokens'][number]['identifier']
|
|
26
|
+
| (typeof SushiswapList)['tokens'][number]['identifier']
|
|
27
|
+
| (typeof TraderjoeList)['tokens'][number]['identifier']
|
|
28
|
+
| (typeof WoofiList)['tokens'][number]['identifier']
|
|
29
|
+
| (typeof UniswapList)['tokens'][number]['identifier']
|
|
30
|
+
| (typeof ChainflipList)['tokens'][number]['identifier'];
|