@swapkit/core 1.0.0-rc.17 → 1.0.0-rc.170

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.
Files changed (45) hide show
  1. package/dist/index.js +3 -0
  2. package/dist/index.js.map +37 -0
  3. package/package.json +26 -49
  4. package/src/__tests__/helpers.test.ts +65 -0
  5. package/src/aggregator/contracts/avaxGeneric.ts +50 -50
  6. package/src/aggregator/contracts/avaxWoofi.ts +80 -80
  7. package/src/aggregator/contracts/bscGeneric.ts +59 -59
  8. package/src/aggregator/contracts/ethGeneric.ts +50 -50
  9. package/src/aggregator/contracts/index.ts +30 -28
  10. package/src/aggregator/contracts/pancakeV2.ts +80 -80
  11. package/src/aggregator/contracts/pangolin.ts +65 -65
  12. package/src/aggregator/contracts/routers/index.ts +58 -0
  13. package/src/aggregator/contracts/routers/kyber.ts +402 -0
  14. package/src/aggregator/contracts/routers/oneinch.ts +2188 -0
  15. package/src/aggregator/contracts/routers/pancakeswap.ts +340 -0
  16. package/src/aggregator/contracts/routers/pangolin.ts +340 -0
  17. package/src/aggregator/contracts/routers/sushiswap.ts +340 -0
  18. package/src/aggregator/contracts/routers/traderJoe.ts +340 -0
  19. package/src/aggregator/contracts/routers/uniswapv2.ts +340 -0
  20. package/src/aggregator/contracts/routers/uniswapv3.ts +254 -0
  21. package/src/aggregator/contracts/routers/woofi.ts +171 -0
  22. package/src/aggregator/contracts/sushiswap.ts +65 -65
  23. package/src/aggregator/contracts/traderJoe.ts +65 -65
  24. package/src/aggregator/contracts/uniswapV2.ts +65 -65
  25. package/src/aggregator/contracts/uniswapV2Leg.ts +70 -70
  26. package/src/aggregator/contracts/uniswapV3_100.ts +70 -70
  27. package/src/aggregator/contracts/uniswapV3_10000.ts +70 -70
  28. package/src/aggregator/contracts/uniswapV3_3000.ts +70 -70
  29. package/src/aggregator/contracts/uniswapV3_500.ts +70 -70
  30. package/src/aggregator/getSwapParams.ts +12 -12
  31. package/src/client.ts +438 -0
  32. package/src/helpers/explorerUrls.ts +45 -0
  33. package/src/index.ts +6 -4
  34. package/src/types.ts +44 -0
  35. package/LICENSE +0 -201
  36. package/dist/index-9e36735e.cjs +0 -1
  37. package/dist/index-cf1865cd.js +0 -649
  38. package/dist/index.cjs +0 -2
  39. package/dist/index.d.ts +0 -216
  40. package/dist/index.es.js +0 -4181
  41. package/src/client/__tests__/helpers.test.ts +0 -69
  42. package/src/client/explorerUrls.ts +0 -62
  43. package/src/client/index.ts +0 -699
  44. package/src/client/thornode.ts +0 -31
  45. package/src/client/types.ts +0 -103
@@ -1,10 +1,10 @@
1
- import type { QuoteRoute } from '@swapkit/api';
1
+ import type { QuoteRoute } from "@swapkit/api";
2
2
 
3
- import type { AGG_CONTRACT_ADDRESS } from './contracts/index.ts';
4
- import { lowercasedGenericAbiMappings } from './contracts/index.ts';
3
+ import type { AGG_CONTRACT_ADDRESS } from "./contracts/index.ts";
4
+ import { lowercasedGenericAbiMappings } from "./contracts/index.ts";
5
5
 
6
6
  type SwapInParams = {
7
- calldata: QuoteRoute['calldata'];
7
+ calldata: QuoteRoute["calldata"];
8
8
  recipient: string;
9
9
  streamSwap?: boolean;
10
10
  contractAddress: AGG_CONTRACT_ADDRESS;
@@ -18,8 +18,8 @@ export const getSwapInParams = ({
18
18
  toChecksumAddress,
19
19
  calldata: {
20
20
  amount,
21
- amountOutMin = '',
22
- data = '',
21
+ amountOutMin = "",
22
+ data = "",
23
23
  deadline,
24
24
  memo,
25
25
  router,
@@ -34,7 +34,7 @@ export const getSwapInParams = ({
34
34
  const isGeneric = !!lowercasedGenericAbiMappings[contractAddress.toLowerCase()];
35
35
 
36
36
  if (isGeneric && !router) {
37
- throw new Error('Router is required on calldata for swapIn with GenericContract');
37
+ throw new Error("Router is required on calldata for swapIn with GenericContract");
38
38
  }
39
39
 
40
40
  /**
@@ -48,16 +48,16 @@ export const getSwapInParams = ({
48
48
  const baseMemo = tcMemo || memo;
49
49
  const transactionMemo = streamSwap ? memoStreamingSwap || baseMemo : baseMemo;
50
50
 
51
- if (!tcVault && !vault) throw new Error('TC Vault is required on calldata');
52
- if (!tcRouter && !router) throw new Error('TC Router is required on calldata');
53
- if (!transactionMemo) throw new Error('TC Memo is required on calldata');
54
- if (!token) throw new Error('Token is required on calldata');
51
+ if (!(tcVault || vault)) throw new Error("TC Vault is required on calldata");
52
+ if (!(tcRouter || router)) throw new Error("TC Router is required on calldata");
53
+ if (!transactionMemo) throw new Error("TC Memo is required on calldata");
54
+ if (!token) throw new Error("Token is required on calldata");
55
55
 
56
56
  const baseParams = [
57
57
  // v2 contracts don't have tcVault, tcRouter, tcMemo but vault, router, memo
58
58
  toChecksumAddress((tcRouter || router) as string),
59
59
  toChecksumAddress((tcVault || vault) as string),
60
- transactionMemo.replace('{recipientAddress}', recipient),
60
+ transactionMemo.replace("{recipientAddress}", recipient),
61
61
  toChecksumAddress(token),
62
62
  amount,
63
63
  ];
package/src/client.ts ADDED
@@ -0,0 +1,438 @@
1
+ import {
2
+ type AddChainWalletParams,
3
+ ApproveMode,
4
+ type ApproveReturnType,
5
+ AssetValue,
6
+ Chain,
7
+ type ConnectConfig,
8
+ type EVMChain,
9
+ EVMChains,
10
+ type FeeOption,
11
+ ProviderName as PluginNameEnum,
12
+ SwapKitError,
13
+ type SwapParams,
14
+ type UTXOChain,
15
+ type WalletChain,
16
+ isGasAsset,
17
+ } from "@swapkit/helpers";
18
+ import {
19
+ type BaseEVMWallet,
20
+ type TransferParams as EVMTransferParams,
21
+ evmValidateAddress,
22
+ } from "@swapkit/toolbox-evm";
23
+
24
+ import {
25
+ type TransferParams as CosmosTransferParams,
26
+ estimateTransactionFee as cosmosTransactionFee,
27
+ cosmosValidateAddress,
28
+ } from "@swapkit/toolbox-cosmos";
29
+ import { substrateValidateAddress } from "@swapkit/toolbox-substrate";
30
+ import { type UTXOTransferParams, utxoValidateAddress } from "@swapkit/toolbox-utxo";
31
+ import { lowercasedContractAbiMapping } from "./aggregator/contracts/index.ts";
32
+ import {
33
+ getExplorerAddressUrl as getAddressUrl,
34
+ getExplorerTxUrl as getTxUrl,
35
+ } from "./helpers/explorerUrls.ts";
36
+ import type { Apis, SwapKitPluginInterface, SwapKitWallet, Wallet } from "./types.ts";
37
+
38
+ export function SwapKit<
39
+ Plugins extends { [key in string]: SwapKitPluginInterface<{ [key in string]: Todo }> },
40
+ Wallets extends { [key in string]: SwapKitWallet<NotWorth[]> },
41
+ >({
42
+ apis = {},
43
+ config = {},
44
+ plugins,
45
+ rpcUrls = {},
46
+ stagenet = false,
47
+ wallets,
48
+ }: {
49
+ apis?: Apis;
50
+ config?: ConnectConfig;
51
+ plugins: Plugins;
52
+ rpcUrls?: { [key in Chain]?: string };
53
+ stagenet?: boolean;
54
+ wallets: Wallets;
55
+ }) {
56
+ type PluginName = keyof Plugins;
57
+
58
+ /**
59
+ * @REMOVE (V1)
60
+ * Compatibility layer for plugins and wallets for easier migration and backwards compatibility
61
+ */
62
+ const compatPlugins: Plugins = Array.isArray(plugins)
63
+ ? plugins.reduce((acc, pluginInterface) => {
64
+ // @ts-ignore Ignore until we remove the compatibility layer
65
+ const { name, plugin } = Object.values(pluginInterface)?.[0] || {};
66
+ acc[name] = plugin;
67
+ return acc;
68
+ }, {})
69
+ : plugins;
70
+ const compatWallets: Wallets = Array.isArray(wallets)
71
+ ? wallets.reduce((acc, wallet) => {
72
+ // @ts-ignore Ignore until we remove the compatibility layer
73
+ const [walletName, connectWallet] = Object.entries(wallet)?.[0] || {};
74
+ acc[walletName] = connectWallet;
75
+ return acc;
76
+ }, {})
77
+ : wallets;
78
+
79
+ const connectedWallets = {} as Wallet;
80
+ const availablePlugins = Object.entries(compatPlugins).reduce(
81
+ (acc, [pluginName, { plugin, config: pluginConfig }]) => {
82
+ const methods = plugin({
83
+ wallets: connectedWallets,
84
+ stagenet,
85
+ config: pluginConfig ?? config,
86
+ });
87
+
88
+ // @ts-expect-error
89
+ acc[pluginName] = methods;
90
+ return acc;
91
+ },
92
+ {} as { [key in PluginName]: ReturnType<Plugins[key]["plugin"]> },
93
+ );
94
+
95
+ const connectWalletMethods = Object.entries(compatWallets).reduce(
96
+ (acc, [walletName, wallet]) => {
97
+ const connectWallet = wallet({ addChain, config, apis, rpcUrls });
98
+
99
+ // @ts-expect-error
100
+ acc[walletName] = connectWallet;
101
+ return acc;
102
+ },
103
+ {} as { [key in keyof Wallets]: ReturnType<Wallets[key]> },
104
+ );
105
+
106
+ /**
107
+ * @Private
108
+ */
109
+ function getSwapKitPlugin<T extends PluginName>(pluginName: T) {
110
+ const plugin = availablePlugins[pluginName] || Object.values(availablePlugins)[0];
111
+
112
+ if (!plugin) {
113
+ throw new SwapKitError("core_plugin_not_found", "Could not find the requested plugin");
114
+ }
115
+
116
+ return plugin;
117
+ }
118
+
119
+ /**
120
+ * @Private
121
+ */
122
+ function getSwapKitPluginForSKProvider(pluginName: PluginNameEnum): Plugins[keyof Plugins] {
123
+ const plugin = Object.values(availablePlugins).find((plugin) =>
124
+ plugin.supportedSwapkitProviders?.includes(pluginName),
125
+ );
126
+
127
+ if (!plugin) {
128
+ throw new SwapKitError("core_plugin_not_found", "Could not find the requested plugin");
129
+ }
130
+
131
+ return plugin;
132
+ }
133
+
134
+ function addChain<T extends Chain>(connectWallet: AddChainWalletParams<T>) {
135
+ // @ts-expect-error: TODO
136
+ connectedWallets[connectWallet.chain] = connectWallet;
137
+ }
138
+
139
+ // biome-ignore lint/complexity/noExcessiveCognitiveComplexity: <explanation>
140
+ function approve<T extends ApproveMode>({
141
+ assetValue,
142
+ type = "checkOnly" as T,
143
+ contractAddress: spenderAddress,
144
+ }: {
145
+ type: T;
146
+ assetValue: AssetValue;
147
+ contractAddress: string | PluginName;
148
+ }) {
149
+ const plugin = availablePlugins[spenderAddress];
150
+
151
+ if (plugin) {
152
+ if (type === ApproveMode.CheckOnly && "isAssetValueApproved" in plugin) {
153
+ return plugin.isAssetValueApproved({ assetValue }) as ApproveReturnType<T>;
154
+ }
155
+ if (type === ApproveMode.Approve && "approveAssetValue" in plugin) {
156
+ return plugin.approveAssetValue({ assetValue }) as ApproveReturnType<T>;
157
+ }
158
+
159
+ throw new SwapKitError(
160
+ "core_approve_asset_target_invalid",
161
+ `Target ${String(spenderAddress)} cannot be used for approve operation`,
162
+ );
163
+ }
164
+
165
+ const { address, chain, isGasAsset, isSynthetic } = assetValue;
166
+ const isEVMChain = EVMChains.includes(chain as EVMChain);
167
+ const isNativeEVM = isEVMChain && isGasAsset;
168
+
169
+ if (isNativeEVM || !isEVMChain || isSynthetic) {
170
+ return Promise.resolve(type === "checkOnly" ? true : "approved") as ApproveReturnType<T>;
171
+ }
172
+
173
+ const walletMethods = connectedWallets[chain] as BaseEVMWallet;
174
+ const walletAction = type === "checkOnly" ? walletMethods?.isApproved : walletMethods?.approve;
175
+ if (!walletAction) throw new SwapKitError("core_wallet_connection_not_found");
176
+
177
+ const from = getAddress(chain);
178
+ if (!(address && from && typeof spenderAddress === "string")) {
179
+ throw new SwapKitError("core_approve_asset_address_or_from_not_found");
180
+ }
181
+
182
+ return walletAction({
183
+ amount: assetValue.getBaseValue("bigint"),
184
+ assetAddress: address,
185
+ from,
186
+ spenderAddress,
187
+ }) as ApproveReturnType<T>;
188
+ }
189
+
190
+ /**
191
+ * @Public
192
+ */
193
+ function getWallet<T extends Chain>(chain: T) {
194
+ return connectedWallets[chain];
195
+ }
196
+ function getAllWallets() {
197
+ return { ...connectedWallets };
198
+ }
199
+ function getAddress<T extends Chain>(chain: T) {
200
+ return getWallet(chain)?.address || "";
201
+ }
202
+
203
+ function validateAddress({ address, chain }: { address: string; chain: Chain }) {
204
+ switch (chain) {
205
+ case Chain.Arbitrum:
206
+ case Chain.Avalanche:
207
+ case Chain.Optimism:
208
+ case Chain.BinanceSmartChain:
209
+ case Chain.Polygon:
210
+ case Chain.Ethereum: {
211
+ return evmValidateAddress({ address });
212
+ }
213
+ case Chain.Polkadot: {
214
+ return substrateValidateAddress({ address, chain });
215
+ }
216
+ case Chain.Litecoin:
217
+ case Chain.Dash:
218
+ case Chain.Dogecoin:
219
+ case Chain.BitcoinCash:
220
+ case Chain.Bitcoin: {
221
+ return utxoValidateAddress({ address, chain });
222
+ }
223
+ case Chain.Cosmos:
224
+ case Chain.Kujira:
225
+ case Chain.Maya:
226
+ case Chain.THORChain: {
227
+ return cosmosValidateAddress({ address, chain });
228
+ }
229
+ }
230
+ return false;
231
+ }
232
+
233
+ function getBalance<T extends Chain>(chain: T, refresh?: boolean) {
234
+ if (refresh) {
235
+ return getWalletWithBalance(chain).then((wallet) => wallet.balance);
236
+ }
237
+
238
+ return getWallet(chain)?.balance || [];
239
+ }
240
+
241
+ async function getWalletWithBalance<T extends Chain>(chain: T, potentialScamFilter = true) {
242
+ const defaultBalance = [AssetValue.fromChainOrSignature(chain)];
243
+ const wallet = getWallet(chain);
244
+
245
+ if (!wallet) {
246
+ throw new SwapKitError("core_wallet_connection_not_found");
247
+ }
248
+
249
+ if ("getBalance" in wallet) {
250
+ // @ts-expect-error TODO add getBalance to radix
251
+ const balance = await wallet.getBalance(wallet.address, potentialScamFilter);
252
+ wallet.balance = balance?.length ? balance : defaultBalance;
253
+ }
254
+
255
+ return wallet;
256
+ }
257
+
258
+ function approveAssetValue(assetValue: AssetValue, contractAddress: string | PluginName) {
259
+ return approve({ assetValue, contractAddress, type: ApproveMode.Approve });
260
+ }
261
+
262
+ function isAssetValueApproved(assetValue: AssetValue, contractAddress: string | PluginName) {
263
+ return approve({ assetValue, contractAddress, type: ApproveMode.CheckOnly });
264
+ }
265
+
266
+ function swap<T extends PluginName>({ route, pluginName, ...rest }: SwapParams<T>) {
267
+ const plugin =
268
+ (pluginName && getSwapKitPlugin(pluginName)) ||
269
+ getSwapKitPluginForSKProvider(route.providers[0] as PluginNameEnum);
270
+ if (!plugin) throw new SwapKitError("core_swap_route_not_complete");
271
+
272
+ if ("swap" in plugin) {
273
+ return plugin.swap({ ...rest, route });
274
+ }
275
+
276
+ throw new SwapKitError("core_plugin_swap_not_found");
277
+ }
278
+
279
+ function transfer({
280
+ from,
281
+ recipient,
282
+ assetValue,
283
+ feeOptionKey,
284
+ }: UTXOTransferParams | EVMTransferParams | CosmosTransferParams) {
285
+ const chain = assetValue.chain as WalletChain;
286
+ const wallet = connectedWallets[chain];
287
+ if (!wallet) throw new SwapKitError("core_wallet_connection_not_found");
288
+
289
+ return wallet.transfer({ from, recipient, assetValue, feeOptionKey });
290
+ }
291
+
292
+ function disconnectAll() {
293
+ for (const chain of Object.keys(connectedWallets)) {
294
+ // @ts-expect-error: TODO
295
+ const wallet = connectedWallets[chain];
296
+ if ("disconnect" in wallet) {
297
+ wallet.disconnect();
298
+ }
299
+ // @ts-expect-error: TODO
300
+ delete connectedWallets[chain];
301
+ }
302
+ }
303
+
304
+ function disconnectChain(chain: Chain) {
305
+ const wallet = connectedWallets[chain];
306
+ const disconnect = wallet?.disconnect;
307
+ if (disconnect) {
308
+ disconnect();
309
+ }
310
+ delete connectedWallets[chain];
311
+ }
312
+
313
+ // biome-ignore lint/complexity/noExcessiveCognitiveComplexity: TODO clean this up
314
+ async function estimateTransactionFee<T extends PluginName>({
315
+ type,
316
+ feeOptionKey,
317
+ params,
318
+ }: (
319
+ | { type: "swap"; params: SwapParams<T> & { assetValue: AssetValue } }
320
+ | {
321
+ type: "transfer";
322
+ params: UTXOTransferParams | EVMTransferParams | CosmosTransferParams;
323
+ }
324
+ | {
325
+ type: "approve";
326
+ params: {
327
+ assetValue: AssetValue;
328
+ contractAddress: string | PluginName;
329
+ feeOptionKey?: FeeOption;
330
+ };
331
+ }
332
+ ) & {
333
+ feeOptionKey: FeeOption;
334
+ }): Promise<AssetValue | undefined> {
335
+ const { assetValue } = params;
336
+ const chain = params.assetValue.chain as WalletChain;
337
+ if (!connectedWallets[chain]) throw new SwapKitError("core_wallet_connection_not_found");
338
+ switch (chain) {
339
+ case Chain.Arbitrum:
340
+ case Chain.Avalanche:
341
+ case Chain.Ethereum:
342
+ case Chain.BinanceSmartChain:
343
+ case Chain.Polygon: {
344
+ const wallet = connectedWallets[chain as Exclude<EVMChain, Chain.Optimism>];
345
+ if (type === "transfer") {
346
+ const txObject = await wallet.createTransferTx(params);
347
+ return wallet.estimateTransactionFee(txObject, feeOptionKey);
348
+ }
349
+ if (type === "approve" && !isGasAsset(assetValue)) {
350
+ wallet.estimateTransactionFee(
351
+ await wallet.createApprovalTx({
352
+ assetAddress: assetValue.address as string,
353
+ spenderAddress: params.contractAddress as string,
354
+ amount: assetValue.getBaseValue("bigint"),
355
+ from: wallet.address,
356
+ }),
357
+ feeOptionKey,
358
+ );
359
+ }
360
+ if (type === "swap") {
361
+ const plugin = params.route.providers[0] as PluginNameEnum;
362
+ if (plugin === PluginNameEnum.CHAINFLIP) {
363
+ const txObject = await wallet.createTransferTx({
364
+ from: wallet.address,
365
+ recipient: wallet.address,
366
+ assetValue,
367
+ });
368
+ return wallet.estimateTransactionFee(txObject, feeOptionKey);
369
+ }
370
+ const {
371
+ route: { evmTransactionDetails },
372
+ } = params;
373
+ if (
374
+ !(
375
+ evmTransactionDetails &&
376
+ lowercasedContractAbiMapping[evmTransactionDetails.contractAddress]
377
+ )
378
+ )
379
+ return undefined;
380
+ wallet.estimateCall({
381
+ contractAddress: evmTransactionDetails.contractAddress,
382
+ // biome-ignore lint/style/noNonNullAssertion: TS cant infer the type
383
+ abi: lowercasedContractAbiMapping[evmTransactionDetails.contractAddress]!,
384
+ funcName: evmTransactionDetails.contractMethod,
385
+ funcParams: evmTransactionDetails.contractParams,
386
+ });
387
+ }
388
+ return AssetValue.fromChainOrSignature(chain, 0);
389
+ }
390
+ case Chain.Bitcoin:
391
+ case Chain.BitcoinCash:
392
+ case Chain.Dogecoin:
393
+ case Chain.Dash:
394
+ case Chain.Litecoin: {
395
+ const wallet = connectedWallets[chain as UTXOChain];
396
+ return wallet.estimateTransactionFee({
397
+ ...params,
398
+ feeOptionKey,
399
+ from: wallet.address,
400
+ recipient: wallet.address,
401
+ });
402
+ }
403
+ case Chain.THORChain:
404
+ case Chain.Maya:
405
+ case Chain.Kujira:
406
+ case Chain.Cosmos: {
407
+ return cosmosTransactionFee(params);
408
+ }
409
+ case Chain.Polkadot: {
410
+ const wallet = connectedWallets[chain as Chain.Polkadot];
411
+ return wallet.estimateTransactionFee({ ...params, recipient: wallet.address });
412
+ }
413
+ default:
414
+ return undefined;
415
+ }
416
+ }
417
+
418
+ return {
419
+ ...availablePlugins,
420
+ ...connectWalletMethods,
421
+
422
+ approveAssetValue,
423
+ getAddress,
424
+ getBalance,
425
+ getExplorerAddressUrl: getAddressUrl,
426
+ getExplorerTxUrl: getTxUrl,
427
+ getWallet,
428
+ getAllWallets,
429
+ getWalletWithBalance,
430
+ isAssetValueApproved,
431
+ estimateTransactionFee,
432
+ swap,
433
+ transfer,
434
+ validateAddress,
435
+ disconnectAll,
436
+ disconnectChain,
437
+ };
438
+ }
@@ -0,0 +1,45 @@
1
+ import { Chain, ChainToExplorerUrl } from "@swapkit/helpers";
2
+
3
+ export function getExplorerTxUrl({ chain, txHash }: { txHash: string; chain: Chain }) {
4
+ const baseUrl = ChainToExplorerUrl[chain];
5
+
6
+ switch (chain) {
7
+ case Chain.Binance:
8
+ case Chain.Maya:
9
+ case Chain.Kujira:
10
+ case Chain.Cosmos:
11
+ case Chain.THORChain:
12
+ case Chain.Solana:
13
+ return `${baseUrl}/tx/${txHash.startsWith("0x") ? txHash.slice(2) : txHash}`;
14
+
15
+ case Chain.Arbitrum:
16
+ case Chain.Avalanche:
17
+ case Chain.BinanceSmartChain:
18
+ case Chain.Ethereum:
19
+ case Chain.Optimism:
20
+ case Chain.Polkadot:
21
+ case Chain.Polygon:
22
+ return `${baseUrl}/tx/${txHash.startsWith("0x") ? txHash : `0x${txHash}`}`;
23
+
24
+ case Chain.Litecoin:
25
+ case Chain.Bitcoin:
26
+ case Chain.BitcoinCash:
27
+ case Chain.Dogecoin:
28
+ return `${baseUrl}/transaction/${txHash.toLowerCase()}`;
29
+
30
+ default:
31
+ throw new Error(`Unsupported chain: ${chain}`);
32
+ }
33
+ }
34
+
35
+ export function getExplorerAddressUrl({ chain, address }: { address: string; chain: Chain }) {
36
+ const baseUrl = ChainToExplorerUrl[chain];
37
+
38
+ switch (chain) {
39
+ case Chain.Solana:
40
+ return `${baseUrl}/account/${address}`;
41
+
42
+ default:
43
+ return `${baseUrl}/address/${address}`;
44
+ }
45
+ }
package/src/index.ts CHANGED
@@ -1,4 +1,6 @@
1
- export * from './client/index.ts';
2
- export * from './client/types.ts';
3
- export * from '@swapkit/helpers';
4
- export * from '@swapkit/types';
1
+ export * from "@swapkit/api";
2
+ export * from "@swapkit/helpers";
3
+ export { stripToCashAddress } from "@swapkit/toolbox-utxo";
4
+
5
+ export * from "./client.ts";
6
+ export * from "./types.ts";
package/src/types.ts ADDED
@@ -0,0 +1,44 @@
1
+ import type {
2
+ BaseWallet,
3
+ Chain,
4
+ ConnectWalletParams,
5
+ CosmosChain,
6
+ UTXOChain,
7
+ } from "@swapkit/helpers";
8
+ import type { CosmosWallets, ThorchainWallets } from "@swapkit/toolbox-cosmos";
9
+ import type { CovalentApiType, EthplorerApiType } from "@swapkit/toolbox-evm";
10
+ import type { EVMWallets } from "@swapkit/toolbox-evm";
11
+ import type { SolanaWallet } from "@swapkit/toolbox-solana";
12
+ import type { SubstrateWallets } from "@swapkit/toolbox-substrate";
13
+ import type { BlockchairApiType } from "@swapkit/toolbox-utxo";
14
+ import type { UTXOWallets } from "@swapkit/toolbox-utxo";
15
+
16
+ export type Wallet = BaseWallet<
17
+ EVMWallets & UTXOWallets & CosmosWallets & ThorchainWallets & SubstrateWallets & SolanaWallet
18
+ >;
19
+
20
+ export type SwapKitWallet<ConnectParams extends Todo[]> = (
21
+ params: ConnectWalletParams,
22
+ ) => (...connectParams: ConnectParams) => boolean | Promise<boolean>;
23
+
24
+ export type SwapKitPluginInterface<Methods = { [key in string]: Todo }> = {
25
+ plugin: ({
26
+ wallets,
27
+ stagenet,
28
+ config,
29
+ }: { wallets: Wallet; stagenet?: boolean; config: Todo }) => Methods;
30
+ config?: Todo;
31
+ };
32
+
33
+ type CovalentChains =
34
+ | Chain.BinanceSmartChain
35
+ | Chain.Polygon
36
+ | Chain.Avalanche
37
+ | Chain.Arbitrum
38
+ | Chain.Optimism;
39
+
40
+ export type Apis = { [key in CovalentChains]?: CovalentApiType } & {
41
+ [key in Chain.Ethereum]?: EthplorerApiType;
42
+ } & { [key in CosmosChain]?: Todo } & {
43
+ [key in UTXOChain]?: BlockchairApiType;
44
+ };