@swapkit/helpers 4.4.5 → 4.5.2
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/api/index.cjs +2 -2
- package/dist/api/index.cjs.map +4 -4
- package/dist/api/index.js +2 -2
- package/dist/api/index.js.map +4 -4
- package/dist/index.cjs +3 -3
- package/dist/index.cjs.map +10 -10
- package/dist/index.js +3 -3
- package/dist/index.js.map +10 -10
- package/dist/types/api/index.d.ts +247 -0
- package/dist/types/api/index.d.ts.map +1 -1
- package/dist/types/api/swapkitApi/endpoints.d.ts +247 -0
- package/dist/types/api/swapkitApi/endpoints.d.ts.map +1 -1
- package/dist/types/api/swapkitApi/types.d.ts +3 -1
- package/dist/types/api/swapkitApi/types.d.ts.map +1 -1
- package/dist/types/modules/assetValue.d.ts +6 -0
- package/dist/types/modules/assetValue.d.ts.map +1 -1
- package/dist/types/modules/bigIntArithmetics.d.ts.map +1 -1
- package/dist/types/modules/swapKitConfig.d.ts +63 -36
- package/dist/types/modules/swapKitConfig.d.ts.map +1 -1
- package/dist/types/modules/swapKitError.d.ts +20 -24
- package/dist/types/modules/swapKitError.d.ts.map +1 -1
- package/dist/types/types/wallet.d.ts +5 -1
- package/dist/types/types/wallet.d.ts.map +1 -1
- package/dist/types/utils/asset.d.ts +1 -1
- package/dist/types/utils/asset.d.ts.map +1 -1
- package/package.json +24 -12
- package/src/api/index.ts +9 -0
- package/src/api/midgard/endpoints.ts +348 -0
- package/src/api/midgard/types.ts +515 -0
- package/src/api/swapkitApi/endpoints.ts +242 -0
- package/src/api/swapkitApi/types.ts +624 -0
- package/src/api/thornode/endpoints.ts +105 -0
- package/src/api/thornode/types.ts +247 -0
- package/src/contracts.ts +1 -0
- package/src/index.ts +28 -0
- package/src/modules/__tests__/assetValue.test.ts +1637 -0
- package/src/modules/__tests__/bigIntArithmetics.test.ts +383 -0
- package/src/modules/__tests__/swapKitConfig.test.ts +425 -0
- package/src/modules/__tests__/swapKitNumber.test.ts +535 -0
- package/src/modules/assetValue.ts +532 -0
- package/src/modules/bigIntArithmetics.ts +363 -0
- package/src/modules/feeMultiplier.ts +80 -0
- package/src/modules/requestClient.ts +110 -0
- package/src/modules/swapKitConfig.ts +174 -0
- package/src/modules/swapKitError.ts +470 -0
- package/src/modules/swapKitNumber.ts +13 -0
- package/src/tokens.ts +1 -0
- package/src/types/commonTypes.ts +10 -0
- package/src/types/derivationPath.ts +11 -0
- package/src/types/errors/apiV1.ts +0 -0
- package/src/types/index.ts +5 -0
- package/src/types/quotes.ts +174 -0
- package/src/types/sdk.ts +38 -0
- package/src/types/wallet.ts +124 -0
- package/src/utils/__tests__/asset.test.ts +185 -0
- package/src/utils/__tests__/derivationPath.test.ts +16 -0
- package/src/utils/__tests__/explorerUrls.test.ts +59 -0
- package/src/utils/__tests__/memo.test.ts +99 -0
- package/src/utils/__tests__/others.test.ts +83 -0
- package/src/utils/__tests__/validators.test.ts +24 -0
- package/src/utils/asset.ts +395 -0
- package/src/utils/chains.ts +100 -0
- package/src/utils/derivationPath.ts +101 -0
- package/src/utils/explorerUrls.ts +32 -0
- package/src/utils/liquidity.ts +150 -0
- package/src/utils/memo.ts +102 -0
- package/src/utils/others.ts +62 -0
- package/src/utils/validators.ts +32 -0
- package/src/utils/wallets.ts +237 -0
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
export enum ErrorCode {
|
|
2
|
+
unknownError = "unknownError",
|
|
3
|
+
test_error = "test_error",
|
|
4
|
+
providerDetailsError = "providerDetailsError",
|
|
5
|
+
blockHeaderNotFound = "blockHeaderNotFound",
|
|
6
|
+
blockHashNotFoundAtHeight = "blockHashNotFoundAtHeight",
|
|
7
|
+
blockHashNotFoundAtHash = "blockHashNotFoundAtHash",
|
|
8
|
+
txHashMissing = "txHashMissing",
|
|
9
|
+
assetValueMissingInfo = "assetValueMissingInfo",
|
|
10
|
+
invalidAsset = "invalidAsset",
|
|
11
|
+
blockIsRequired = "blockIsRequired",
|
|
12
|
+
currentBlockHeaderNotFound = "currentBlockHeaderNotFound",
|
|
13
|
+
failedToRetrieveBalance = "failedToRetrieveBalance",
|
|
14
|
+
failedToRetrieveBlock = "failedToRetrieveBlock",
|
|
15
|
+
failedToRetrieveFees = "failedToRetrieveFees",
|
|
16
|
+
notImplementedBCH = "notImplementedBCH",
|
|
17
|
+
notImplementedDoge = "notImplementedDoge",
|
|
18
|
+
noPoolsFound = "noPoolsFound",
|
|
19
|
+
noVaultsFound = "noVaultsFound",
|
|
20
|
+
noTxFound = "noTxFound",
|
|
21
|
+
noInputCoinFound = "noInputCoinFound",
|
|
22
|
+
noBlockDataFound = "noBlockDataFound",
|
|
23
|
+
multipleCosmosMessages = "multipleCosmosMessages",
|
|
24
|
+
heightOrHashNotProvided = "heightOrHashNotProvided",
|
|
25
|
+
unknownDenom = "unknownDenom",
|
|
26
|
+
invalidBlockHeight = "invalidBlockHeight",
|
|
27
|
+
timestampExtrinsicNoArgumentsForBlock = "timestampExtrinsicNoArgumentsForBlock",
|
|
28
|
+
timestampExtrinsicNoTimestampForBlock = "timestampExtrinsicNoTimestampForBlock",
|
|
29
|
+
noTimestampExtrinsicForHash = "noTimestampExtrinsicForHash",
|
|
30
|
+
timestampExtrinsicNoArgumentsForHash = "timestampExtrinsicNoArgumentsForHash",
|
|
31
|
+
txMemoUndefined = "txMemoUndefined",
|
|
32
|
+
txMemoIncorrect = "txMemoIncorrect",
|
|
33
|
+
txTypeNotFound = "txTypeNotFound",
|
|
34
|
+
txNoMessage = "txNoMessage",
|
|
35
|
+
txNotFound = "txNotFound",
|
|
36
|
+
txReceiptNotFound = "txReceiptNotFound",
|
|
37
|
+
txParsingError = "txParsingError",
|
|
38
|
+
txLogsParsingError = "txLogsParsingError",
|
|
39
|
+
blockNotFound = "blockNotFound",
|
|
40
|
+
balanceNotFound = "balanceNotFound",
|
|
41
|
+
configError = "configError",
|
|
42
|
+
synthSwapDisallowed = "synthSwapDisallowed",
|
|
43
|
+
providerQuoteTimeout = "providerQuoteTimeout",
|
|
44
|
+
noQuoteResponse = "noQuoteResponse",
|
|
45
|
+
noPoolAssetsFound = "noPoolAssetsFound",
|
|
46
|
+
noThorchainPools = "noThorchainPools",
|
|
47
|
+
noMayachainPools = "noMayachainPools",
|
|
48
|
+
noThorchainNetworkInfo = "noThorchainNetworkInfo",
|
|
49
|
+
invalidAffiliateFee = "invalidAffiliateFee",
|
|
50
|
+
invalidBuyAssetAddress = "invalidBuyAssetAddress",
|
|
51
|
+
invalidSellAssetAddress = "invalidSellAssetAddress",
|
|
52
|
+
invalidSourceAddress = "invalidSourceAddress",
|
|
53
|
+
invalidDestinationAddress = "invalidDestinationAddress",
|
|
54
|
+
sourceAddressIsSmartContract = "sourceAddressIsSmartContract",
|
|
55
|
+
destinationAddressIsSmartContract = "destinationAddressIsSmartContract",
|
|
56
|
+
invalidChainId = "invalidChainId",
|
|
57
|
+
unsupportedChainId = "unsupportedChainId",
|
|
58
|
+
unsupportedEVMChainId = "unsupportedEVMChainId",
|
|
59
|
+
unsupportedMethod = "unsupportedMethod",
|
|
60
|
+
unsupportedProvider = "unsupportedProvider",
|
|
61
|
+
invalidParamsForMethod = "invalidParamsForMethod",
|
|
62
|
+
unsupportedAdapter = "unsupportedAdapter",
|
|
63
|
+
noWhitelistTokens = "noWhitelistTokens",
|
|
64
|
+
failedFetchGasPrice = "failedFetchGasPrice",
|
|
65
|
+
failedToCreateDepositChannel = "failedToCreateDepositChannel",
|
|
66
|
+
noProviderDetailsFound = "noProviderDetailsFound",
|
|
67
|
+
noTokenListsFound = "noTokenListsFound",
|
|
68
|
+
tokenNotFound = "tokenNotFound",
|
|
69
|
+
tokenPriceNotFound = "tokenPriceNotFound",
|
|
70
|
+
tokenPriceFailedToUpdate = "tokenPriceFailedToUpdate",
|
|
71
|
+
swapAmountTooSmall = "swapAmountTooSmall",
|
|
72
|
+
legsArrayIsEmpty = "legsArrayIsEmpty",
|
|
73
|
+
failedToFetchQuoteForLeg = "failedToFetchQuoteForLeg",
|
|
74
|
+
noBlockHeaderFound = "noBlockHeaderFound",
|
|
75
|
+
failedToSimulateSwap = "failedToSimulateSwap",
|
|
76
|
+
addressScreeningFailed = "addressScreeningFailed",
|
|
77
|
+
noLiquidtyProvidersFound = "noLiquidtyProvidersFound",
|
|
78
|
+
insufficientLiquidity = "insufficientLiquidity",
|
|
79
|
+
noInboundDataFound = "noInbounDataFound",
|
|
80
|
+
noInboundAddressesFound = "noInboundAddressesFound",
|
|
81
|
+
noInboundAddressFoundForChain = "noInboundAddressFoundForChain",
|
|
82
|
+
noLastBlocksFound = "noLastBlocksFound",
|
|
83
|
+
noVersionFound = "noVersionFound",
|
|
84
|
+
noConstantsFound = "noConstantsFound",
|
|
85
|
+
noMimirsFound = "noMimirsFound",
|
|
86
|
+
noRoutesFound = "noRoutesFound",
|
|
87
|
+
quoteNotFound = "quoteNotFound",
|
|
88
|
+
ledgerSignFailed = "ledgerSignFailed",
|
|
89
|
+
ledgerWrongPayload = "ledgerWrongPayload",
|
|
90
|
+
ledgerFetchSwapFailed = "ledgerFetchSwapFailed",
|
|
91
|
+
failedToFetchTx = "failedToFetchTx",
|
|
92
|
+
failedBuildTransactionDetails = "failedBuildTransactionDetails",
|
|
93
|
+
noLegsForRoute = "noLegsForRoute",
|
|
94
|
+
noRouterAddressFound = "noRouterAddressFound",
|
|
95
|
+
noAggregatorAddressFound = "noAggregatorAddressFound",
|
|
96
|
+
noContractInstanceFound = "noContractInstanceFound",
|
|
97
|
+
noContractAddressFound = "noContractAddressFound",
|
|
98
|
+
invalidAffiliate = "invalidAffiliate",
|
|
99
|
+
thornameAffiliate = "thornameAffiliate",
|
|
100
|
+
providerNotfound = "No provider found",
|
|
101
|
+
noRecordFound = "No Record found",
|
|
102
|
+
slippageTooLow = "Slippage too low",
|
|
103
|
+
tradingHalted = "tradingHalted",
|
|
104
|
+
noWrappedGasAsset = "noWrappedGasAsset",
|
|
105
|
+
aggregatorAddressNotFound = "aggregatorAddressNotFound",
|
|
106
|
+
routerAddressNotFound = "routerAddressNotFound",
|
|
107
|
+
dummyAddressNotFound = "dummyAddressNotFound",
|
|
108
|
+
trackerError = "trackerError",
|
|
109
|
+
thorchainPoolUnavailable = "thorchainPoolUnavailable",
|
|
110
|
+
noOhlcvDataFound = "noOhlcvDataFound",
|
|
111
|
+
noTradingPairs = "noTradingPairs",
|
|
112
|
+
noLendingAvailability = "noLendingAvailability",
|
|
113
|
+
lendingRepayTooSmall = "lendingRepayTooSmall",
|
|
114
|
+
missingState = "missingState",
|
|
115
|
+
ledgerSwapNotFound = "ledgerSwapNotFound",
|
|
116
|
+
ledgerSwapNotReadyForTracking = "ledgerSwapNotReadyForTracking",
|
|
117
|
+
errorEstimatingGas = "errorEstimatingGas",
|
|
118
|
+
apiKeyInvalid = "apiKeyInvalid",
|
|
119
|
+
apiKeyFailedToUpdate = "apiKeyFailedToUpdate",
|
|
120
|
+
apiKeyExpired = "apiKeyExpired",
|
|
121
|
+
unauthorized = "unauthorized",
|
|
122
|
+
failedToCreateMemo = "failedToCreateMemo",
|
|
123
|
+
radixIncorrectInstructions = "radixIncorrectInstructions",
|
|
124
|
+
radixTxMissedParam = "radixTxMissedParam",
|
|
125
|
+
radixTxMissedAccount = "radixTxMissedAccount",
|
|
126
|
+
radixManifestParseError = "radixManifestParseError",
|
|
127
|
+
radixManifestBuildError = "radixManifestBuildError",
|
|
128
|
+
invalidAddressForChain = "invalidAddressForChain",
|
|
129
|
+
riskyAddress = "riskyAddress",
|
|
130
|
+
noRoutesToProcess = "noRoutesToProcess",
|
|
131
|
+
sellAssetAmountTooSmall = "sellAssetAmountTooSmall",
|
|
132
|
+
missingPrivateKey = "missingPrivateKey",
|
|
133
|
+
noMemoPriceProtection = "noMemoPriceProtection",
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
export enum WarningCodeEnum {
|
|
137
|
+
highSlippage = "highSlippage",
|
|
138
|
+
highPriceImpact = "highPriceImpact",
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
export enum ProviderName {
|
|
142
|
+
CAVIAR_V1 = "CAVIAR_V1",
|
|
143
|
+
CAMELOT_V3 = "CAMELOT_V3",
|
|
144
|
+
CHAINFLIP = "CHAINFLIP",
|
|
145
|
+
CHAINFLIP_STREAMING = "CHAINFLIP_STREAMING",
|
|
146
|
+
JUPITER = "JUPITER",
|
|
147
|
+
MAYACHAIN = "MAYACHAIN",
|
|
148
|
+
MAYACHAIN_STREAMING = "MAYACHAIN_STREAMING",
|
|
149
|
+
OCISWAP_V1 = "OCISWAP_V1",
|
|
150
|
+
ONEINCH = "ONEINCH",
|
|
151
|
+
OPENOCEAN_V2 = "OPENOCEAN_V2",
|
|
152
|
+
PANCAKESWAP = "PANCAKESWAP",
|
|
153
|
+
PANGOLIN_V1 = "PANGOLIN_V1",
|
|
154
|
+
SUSHISWAP_V2 = "SUSHISWAP_V2",
|
|
155
|
+
THORCHAIN = "THORCHAIN",
|
|
156
|
+
THORCHAIN_STREAMING = "THORCHAIN_STREAMING",
|
|
157
|
+
TRADERJOE_V2 = "TRADERJOE_V2",
|
|
158
|
+
UNISWAP_V2 = "UNISWAP_V2",
|
|
159
|
+
UNISWAP_V3 = "UNISWAP_V3",
|
|
160
|
+
NEAR = "NEAR",
|
|
161
|
+
GARDEN = "GARDEN",
|
|
162
|
+
OKX = "OKX",
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export enum FeeTypeEnum {
|
|
166
|
+
LIQUIDITY = "liquidity",
|
|
167
|
+
NETWORK = "network",
|
|
168
|
+
INBOUND = "inbound",
|
|
169
|
+
OUTBOUND = "outbound",
|
|
170
|
+
AFFILIATE = "affiliate",
|
|
171
|
+
TAX = "tax",
|
|
172
|
+
PRIORITY = "priority",
|
|
173
|
+
SERVICE = "service",
|
|
174
|
+
}
|
package/src/types/sdk.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { AssetValue } from "../modules/assetValue";
|
|
2
|
+
|
|
3
|
+
export type GenericSwapParams<T = unknown> = {
|
|
4
|
+
buyAsset?: AssetValue;
|
|
5
|
+
sellAsset?: AssetValue;
|
|
6
|
+
recipient?: string;
|
|
7
|
+
feeOptionKey?: FeeOption;
|
|
8
|
+
route: T;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export type SwapParams<PluginNames = string, R = unknown> = GenericSwapParams<R> & { pluginName?: PluginNames };
|
|
12
|
+
|
|
13
|
+
export enum FeeOption {
|
|
14
|
+
Average = "average",
|
|
15
|
+
Fast = "fast",
|
|
16
|
+
Fastest = "fastest",
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export enum ApproveMode {
|
|
20
|
+
Approve = "approve",
|
|
21
|
+
CheckOnly = "checkOnly",
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export type ApproveReturnType<T extends ApproveMode> = T extends "checkOnly" ? Promise<boolean> : Promise<string>;
|
|
25
|
+
|
|
26
|
+
export enum MemoType {
|
|
27
|
+
NAME_REGISTER = "~",
|
|
28
|
+
BOND = "BOND",
|
|
29
|
+
DEPOSIT = "+",
|
|
30
|
+
LEAVE = "LEAVE",
|
|
31
|
+
UNBOND = "UNBOND",
|
|
32
|
+
WITHDRAW = "-",
|
|
33
|
+
RUNEPOOL_DEPOSIT = "POOL+",
|
|
34
|
+
RUNEPOOL_WITHDRAW = "POOL-",
|
|
35
|
+
CLAIM_TCY = "tcy",
|
|
36
|
+
STAKE_TCY = "tcy+",
|
|
37
|
+
UNSTAKE_TCY = "tcy-",
|
|
38
|
+
}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import type { Chain, getChainConfig } from "@swapkit/types";
|
|
2
|
+
import type { BrowserProvider, Eip1193Provider } from "ethers";
|
|
3
|
+
|
|
4
|
+
import type { AssetValue } from "../modules/assetValue";
|
|
5
|
+
import type { FeeOption } from "./sdk";
|
|
6
|
+
|
|
7
|
+
declare global {
|
|
8
|
+
interface WindowEventMap {
|
|
9
|
+
"eip6963:announceProvider": CustomEvent;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export type EthereumWindowProvider = BrowserProvider & {
|
|
14
|
+
__XDEFI?: boolean;
|
|
15
|
+
isBraveWallet?: boolean;
|
|
16
|
+
isCoinbaseWallet?: boolean;
|
|
17
|
+
isMetaMask?: boolean;
|
|
18
|
+
isOkxWallet?: boolean;
|
|
19
|
+
isKeepKeyWallet?: boolean;
|
|
20
|
+
isTrust?: boolean;
|
|
21
|
+
isTalisman?: boolean;
|
|
22
|
+
on: (event: string, callback?: () => void) => void;
|
|
23
|
+
overrideIsMetaMask?: boolean;
|
|
24
|
+
request: <T = unknown>(args: { method: string; params?: unknown[] }) => Promise<T>;
|
|
25
|
+
selectedProvider?: EthereumWindowProvider;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export type NetworkParams = {
|
|
29
|
+
chainId: ReturnType<typeof getChainConfig>["chainId"];
|
|
30
|
+
chainName: string;
|
|
31
|
+
nativeCurrency: { name: string; symbol: string; decimals: number };
|
|
32
|
+
rpcUrls: string[];
|
|
33
|
+
blockExplorerUrls: string[];
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export enum WalletOption {
|
|
37
|
+
BITGET = "BITGET",
|
|
38
|
+
BRAVE = "BRAVE",
|
|
39
|
+
COINBASE_MOBILE = "COINBASE_MOBILE",
|
|
40
|
+
COINBASE_WEB = "COINBASE_WEB",
|
|
41
|
+
COSMOSTATION = "COSMOSTATION",
|
|
42
|
+
CTRL = "CTRL",
|
|
43
|
+
EIP6963 = "EIP6963",
|
|
44
|
+
/**
|
|
45
|
+
* @deprecated Use PASSKEYS instead
|
|
46
|
+
*/
|
|
47
|
+
EXODUS = "EXODUS",
|
|
48
|
+
KEEPKEY = "KEEPKEY",
|
|
49
|
+
KEEPKEY_BEX = "KEEPKEY_BEX",
|
|
50
|
+
KEPLR = "KEPLR",
|
|
51
|
+
KEYSTORE = "KEYSTORE",
|
|
52
|
+
LEAP = "LEAP",
|
|
53
|
+
LEDGER = "LEDGER",
|
|
54
|
+
LEDGER_LIVE = "LEDGER_LIVE",
|
|
55
|
+
METAMASK = "METAMASK",
|
|
56
|
+
OKX = "OKX",
|
|
57
|
+
OKX_MOBILE = "OKX_MOBILE",
|
|
58
|
+
ONEKEY = "ONEKEY",
|
|
59
|
+
PASSKEYS = "PASSKEYS",
|
|
60
|
+
PHANTOM = "PHANTOM",
|
|
61
|
+
POLKADOT_JS = "POLKADOT_JS",
|
|
62
|
+
RADIX_WALLET = "RADIX_WALLET",
|
|
63
|
+
TALISMAN = "TALISMAN",
|
|
64
|
+
TREZOR = "TREZOR",
|
|
65
|
+
TRONLINK = "TRONLINK",
|
|
66
|
+
TRUSTWALLET_WEB = "TRUSTWALLET_WEB",
|
|
67
|
+
VULTISIG = "VULTISIG",
|
|
68
|
+
WALLETCONNECT = "WALLETCONNECT",
|
|
69
|
+
WALLET_SELECTOR = "WALLET_SELECTOR",
|
|
70
|
+
XAMAN = "XAMAN",
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export enum LedgerErrorCode {
|
|
74
|
+
NoError = 0x9000,
|
|
75
|
+
LockedDevice = 0x5515,
|
|
76
|
+
TC_NotFound = 65535,
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* @deprecated CryptoChain has been deprecated - use Chain instead
|
|
81
|
+
*/
|
|
82
|
+
export type CryptoChain = Chain;
|
|
83
|
+
|
|
84
|
+
export type ChainWallet<T extends Chain> = {
|
|
85
|
+
chain: T;
|
|
86
|
+
address: string;
|
|
87
|
+
balance: AssetValue[];
|
|
88
|
+
walletType: WalletOption | string;
|
|
89
|
+
disconnect?: () => void;
|
|
90
|
+
signMessage?: (message: string) => Promise<string>;
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
export type EmptyWallet = { [key in Chain]?: unknown };
|
|
94
|
+
export type BaseWallet<T extends EmptyWallet | Record<string, unknown>> = {
|
|
95
|
+
[key in Chain]: ChainWallet<key> & (T extends EmptyWallet ? T[key] : never);
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
export type EIP6963ProviderInfo = { walletId: string; uuid: string; name: string; icon: string };
|
|
99
|
+
|
|
100
|
+
export type EIP6963ProviderDetail = { info: EIP6963ProviderInfo; provider: Eip1193Provider };
|
|
101
|
+
|
|
102
|
+
export type EIP6963Provider = { info: EIP6963ProviderInfo; provider: Eip1193Provider };
|
|
103
|
+
|
|
104
|
+
// This type represents the structure of an event dispatched by a wallet to announce its presence based on EIP-6963.
|
|
105
|
+
export type EIP6963AnnounceProviderEvent = Event & { detail: EIP6963Provider };
|
|
106
|
+
|
|
107
|
+
export type ChainSigner<T, S> = {
|
|
108
|
+
signTransaction: (params: T) => Promise<S> | S;
|
|
109
|
+
getAddress: () => Promise<string> | string;
|
|
110
|
+
sign?: (message: string) => Promise<string> | string;
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
export type GenericTransferParams = {
|
|
114
|
+
recipient: string;
|
|
115
|
+
assetValue: AssetValue;
|
|
116
|
+
memo?: string;
|
|
117
|
+
feeRate?: number;
|
|
118
|
+
feeOptionKey?: FeeOption;
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
export type GenericCreateTransactionParams = Omit<GenericTransferParams, "feeOptionKey" & "feeRate"> & {
|
|
122
|
+
sender: string;
|
|
123
|
+
feeRate: number;
|
|
124
|
+
};
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import { AllChains, Chain, getChainConfig } from "@swapkit/types";
|
|
3
|
+
|
|
4
|
+
import { assetFromString, fetchTokenInfo, getAssetType } from "../asset";
|
|
5
|
+
|
|
6
|
+
// TODO: this should be handled via AssetValue
|
|
7
|
+
const tickerMap: Record<string, string> = {
|
|
8
|
+
[Chain.Arbitrum]: "ETH",
|
|
9
|
+
[Chain.Aurora]: "ETH",
|
|
10
|
+
[Chain.Base]: "ETH",
|
|
11
|
+
[Chain.BinanceSmartChain]: "BNB",
|
|
12
|
+
[Chain.Cosmos]: "ATOM",
|
|
13
|
+
[Chain.Maya]: "CACAO",
|
|
14
|
+
[Chain.Optimism]: "ETH",
|
|
15
|
+
[Chain.THORChain]: "RUNE",
|
|
16
|
+
[Chain.Tron]: "TRX",
|
|
17
|
+
[Chain.XLayer]: "OKB",
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
describe("getAssetType", () => {
|
|
21
|
+
describe("when isSynth is true", () => {
|
|
22
|
+
test('should return "Synth"', () => {
|
|
23
|
+
const result = getAssetType({ chain: Chain.Bitcoin, symbol: "BTC/BTC" });
|
|
24
|
+
expect(result).toBe("Synth");
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
describe("when isSynth is false", () => {
|
|
29
|
+
describe("for gas assets on given chain", () => {
|
|
30
|
+
for (const chain of AllChains) {
|
|
31
|
+
test(`should return "Native" for chain ${chain} asset`, () => {
|
|
32
|
+
const ticker = tickerMap[chain] || chain;
|
|
33
|
+
const result = getAssetType({ chain: chain as Chain, symbol: ticker });
|
|
34
|
+
|
|
35
|
+
expect(result).toBe("Native");
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
describe("for non-gas assets on given chain", () => {
|
|
41
|
+
for (const chain of AllChains) {
|
|
42
|
+
test(`should return ${chain} for chain ${chain} asset`, () => {
|
|
43
|
+
const result = getAssetType({ chain: chain as Chain, symbol: "USDT" });
|
|
44
|
+
|
|
45
|
+
expect(result).toBe(chain);
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
describe("fetchTokenInfo", () => {
|
|
53
|
+
/**
|
|
54
|
+
* Test out native
|
|
55
|
+
*/
|
|
56
|
+
const filteredChains = AllChains.filter((c) => ![Chain.Ethereum, Chain.Avalanche].includes(c));
|
|
57
|
+
|
|
58
|
+
for (const chain of filteredChains) {
|
|
59
|
+
describe(chain, () => {
|
|
60
|
+
test(`returns proper decimal for native ${chain} asset`, async () => {
|
|
61
|
+
const { decimals } = await fetchTokenInfo({ address: "", chain });
|
|
62
|
+
const { baseDecimal } = getChainConfig(chain);
|
|
63
|
+
expect(decimals).toBe(baseDecimal);
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
describe("ETH", () => {
|
|
69
|
+
// TODO: if too many requests, this will fail due to timeout
|
|
70
|
+
test.todo("returns proper decimal for eth and it's assets", async () => {
|
|
71
|
+
const { decimals: ethDecimal } = await fetchTokenInfo({ address: "", chain: Chain.Ethereum });
|
|
72
|
+
expect(ethDecimal).toBe(getChainConfig(Chain.Ethereum).baseDecimal);
|
|
73
|
+
await Bun.sleep(500);
|
|
74
|
+
|
|
75
|
+
const { decimals: usdcDecimal } = await fetchTokenInfo({
|
|
76
|
+
address: "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
|
|
77
|
+
chain: Chain.Ethereum,
|
|
78
|
+
});
|
|
79
|
+
expect(usdcDecimal).toBe(6);
|
|
80
|
+
await Bun.sleep(500);
|
|
81
|
+
|
|
82
|
+
const { decimals: wbtcDecimal } = await fetchTokenInfo({
|
|
83
|
+
address: "0x2260fac5e5542a773aa44fbcfedf7c193bc2c599",
|
|
84
|
+
chain: Chain.Ethereum,
|
|
85
|
+
});
|
|
86
|
+
expect(wbtcDecimal).toBe(8);
|
|
87
|
+
await Bun.sleep(500);
|
|
88
|
+
|
|
89
|
+
const { decimals: kindDecimal } = await fetchTokenInfo({
|
|
90
|
+
address: "0x4618519de4c304f3444ffa7f812dddc2971cc688",
|
|
91
|
+
chain: Chain.Ethereum,
|
|
92
|
+
});
|
|
93
|
+
expect(kindDecimal).toBe(8);
|
|
94
|
+
await Bun.sleep(500);
|
|
95
|
+
|
|
96
|
+
const { decimals: shitcoinDecimal } = await fetchTokenInfo({
|
|
97
|
+
address: "0xCa208BfD69ae6D2667f1FCbE681BAe12767c0078",
|
|
98
|
+
chain: Chain.Ethereum,
|
|
99
|
+
});
|
|
100
|
+
expect(shitcoinDecimal).toBe(0);
|
|
101
|
+
await Bun.sleep(500);
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
describe("AVAX", () => {
|
|
106
|
+
// TODO: if too many requests, this will fail due to timeout
|
|
107
|
+
test.todo("returns proper decimal for avax and it's assets", async () => {
|
|
108
|
+
const { decimals: avaxDecimal } = await fetchTokenInfo({ address: "", chain: Chain.Avalanche });
|
|
109
|
+
expect(avaxDecimal).toBe(getChainConfig(Chain.Avalanche).baseDecimal);
|
|
110
|
+
|
|
111
|
+
const { decimals: wbtceDecimal } = await fetchTokenInfo({
|
|
112
|
+
address: "0x50b7545627a5162f82a992c33b87adc75187b218",
|
|
113
|
+
chain: Chain.Avalanche,
|
|
114
|
+
});
|
|
115
|
+
expect(wbtceDecimal).toBe(8);
|
|
116
|
+
|
|
117
|
+
const { decimals: btcbDecimal } = await fetchTokenInfo({
|
|
118
|
+
address: "0x152b9d0FdC40C096757F570A51E494bd4b943E50",
|
|
119
|
+
chain: Chain.Avalanche,
|
|
120
|
+
});
|
|
121
|
+
expect(btcbDecimal).toBe(8);
|
|
122
|
+
|
|
123
|
+
const { decimals: timeDecimal } = await fetchTokenInfo({
|
|
124
|
+
address: "0xb54f16fB19478766A268F172C9480f8da1a7c9C3",
|
|
125
|
+
chain: Chain.Avalanche,
|
|
126
|
+
});
|
|
127
|
+
expect(timeDecimal).toBe(9);
|
|
128
|
+
|
|
129
|
+
const { decimals: usdtDecimal } = await fetchTokenInfo({
|
|
130
|
+
address: "0x9702230A8Ea53601f5cD2dc00fDBc13d4dF4A8c7",
|
|
131
|
+
chain: Chain.Avalanche,
|
|
132
|
+
});
|
|
133
|
+
expect(usdtDecimal).toBe(6);
|
|
134
|
+
|
|
135
|
+
const { decimals: usdcDecimal } = await fetchTokenInfo({
|
|
136
|
+
address: "0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E",
|
|
137
|
+
chain: Chain.Avalanche,
|
|
138
|
+
});
|
|
139
|
+
expect(usdcDecimal).toBe(6);
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
describe("Radix", () => {
|
|
144
|
+
test.todo("returns proper decimal for radix and it's assets", async () => {
|
|
145
|
+
const { decimals: radixDecimal } = await fetchTokenInfo({ address: "", chain: Chain.Radix });
|
|
146
|
+
expect(radixDecimal).toBe(getChainConfig(Chain.Radix).baseDecimal);
|
|
147
|
+
await Bun.sleep(500);
|
|
148
|
+
|
|
149
|
+
const { decimals: xwBTCDecimal } = await fetchTokenInfo({
|
|
150
|
+
address: "xwBTC-resource_rdx1t580qxc7upat7lww4l2c4jckacafjeudxj5wpjrrct0p3e82sq4y75",
|
|
151
|
+
chain: Chain.Radix,
|
|
152
|
+
});
|
|
153
|
+
expect(xwBTCDecimal).toBe(8);
|
|
154
|
+
await Bun.sleep(500);
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
describe("assetFromString", () => {
|
|
160
|
+
test("should return the correct object", () => {
|
|
161
|
+
const assetString = "THOR.RUNE";
|
|
162
|
+
const result = assetFromString(assetString);
|
|
163
|
+
|
|
164
|
+
expect(result).toEqual({ chain: Chain.THORChain, symbol: "RUNE", synth: false, ticker: "RUNE" });
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
test("should return the correct object for multiple dashes", () => {
|
|
168
|
+
const assetString = "ETH.PENDLE-LPT-0x1234";
|
|
169
|
+
const result = assetFromString(assetString);
|
|
170
|
+
|
|
171
|
+
expect(result).toEqual({ chain: Chain.Ethereum, symbol: "PENDLE-LPT-0x1234", synth: false, ticker: "PENDLE-LPT" });
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
test.todo("should return the correct object for Radix resource", () => {
|
|
175
|
+
const assetString = "XRD.xwBTC-resource_rdx1t580qxc7upat7lww4l2c4jckacafjeudxj5wpjrrct0p3e82sq4y75";
|
|
176
|
+
const result = assetFromString(assetString);
|
|
177
|
+
|
|
178
|
+
expect(result).toEqual({
|
|
179
|
+
chain: Chain.Radix,
|
|
180
|
+
symbol: "xwBTC-resource_rdx1t580qxc7upat7lww4l2c4jckacafjeudxj5wpjrrct0p3e82sq4y75",
|
|
181
|
+
synth: false,
|
|
182
|
+
ticker: "xwBTC",
|
|
183
|
+
});
|
|
184
|
+
});
|
|
185
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
|
|
3
|
+
import type { DerivationPathArray } from "../../types";
|
|
4
|
+
import { derivationPathToString } from "../derivationPath";
|
|
5
|
+
|
|
6
|
+
describe("derivationPathToString", () => {
|
|
7
|
+
test("should return the correct string for a full path", () => {
|
|
8
|
+
const path = [1, 2, 3, 4, 5] as DerivationPathArray;
|
|
9
|
+
expect(derivationPathToString(path)).toEqual("m/1'/2'/3'/4/5");
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
test("should return the correct string for a short path", () => {
|
|
13
|
+
const path = [1, 2, 3, 4] as DerivationPathArray;
|
|
14
|
+
expect(derivationPathToString(path)).toEqual("m/1'/2'/3'/4");
|
|
15
|
+
});
|
|
16
|
+
});
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import { Chain, CosmosChains, EVMChains, getChainConfig, UTXOChains } from "@swapkit/helpers";
|
|
3
|
+
import { getExplorerAddressUrl, getExplorerTxUrl } from "../explorerUrls";
|
|
4
|
+
|
|
5
|
+
describe("Explorer URLs", () => {
|
|
6
|
+
describe("CosmosChains", () => {
|
|
7
|
+
for (const chain of CosmosChains) {
|
|
8
|
+
test(`getExplorerTxUrl returns correct URL for ${chain}`, () => {
|
|
9
|
+
expect(getExplorerTxUrl({ chain, txHash: "0x123456789" })).toBe(
|
|
10
|
+
`${getChainConfig(chain).explorerUrl}/tx/123456789`,
|
|
11
|
+
);
|
|
12
|
+
|
|
13
|
+
expect(getExplorerAddressUrl({ address: "asdfg", chain })).toBe(
|
|
14
|
+
`${getChainConfig(chain).explorerUrl}/address/asdfg`,
|
|
15
|
+
);
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
describe("EVMChains & SubstrateChains", () => {
|
|
21
|
+
for (const chain of [...EVMChains, Chain.Polkadot]) {
|
|
22
|
+
test(`getExplorerTxUrl returns correct URL for ${chain}`, () => {
|
|
23
|
+
expect(getExplorerTxUrl({ chain, txHash: "0x123456789" })).toBe(
|
|
24
|
+
`${getChainConfig(chain).explorerUrl}/tx/0x123456789`,
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
expect(getExplorerAddressUrl({ address: "asdfg", chain })).toBe(
|
|
28
|
+
`${getChainConfig(chain).explorerUrl}/address/asdfg`,
|
|
29
|
+
);
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
test("getExplorerTxUrl adds 0x for EVM like chains", () => {
|
|
34
|
+
expect(getExplorerTxUrl({ chain: Chain.Ethereum, txHash: "12345" })).toBe("https://etherscan.io/tx/0x12345");
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
describe("UTXOChains", () => {
|
|
39
|
+
for (const chain of UTXOChains.filter((c) => c !== Chain.Dash)) {
|
|
40
|
+
test(`getExplorerTxUrl returns correct URL for ${chain}`, () => {
|
|
41
|
+
expect(getExplorerTxUrl({ chain, txHash: "0x123456789" })).toBe(
|
|
42
|
+
`${getChainConfig(chain).explorerUrl}/transaction/0x123456789`,
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
expect(getExplorerAddressUrl({ address: "asdfg", chain })).toBe(
|
|
46
|
+
`${getChainConfig(chain).explorerUrl}/address/asdfg`,
|
|
47
|
+
);
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
describe("Solana", () => {
|
|
53
|
+
test("getExplorerTxUrl returns correct URL for Solana", () => {
|
|
54
|
+
expect(getExplorerTxUrl({ chain: Chain.Solana, txHash: "b123456789" })).toBe("https://solscan.io/tx/b123456789");
|
|
55
|
+
|
|
56
|
+
expect(getExplorerAddressUrl({ address: "asdfg", chain: Chain.Solana })).toBe("https://solscan.io/account/asdfg");
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
});
|