@swapkit/core 1.0.0-rc.111 → 1.0.0-rc.113

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/package.json CHANGED
@@ -1,26 +1,26 @@
1
1
  {
2
2
  "author": "swapkit-oss",
3
3
  "dependencies": {
4
- "@swapkit/helpers": "1.0.0-rc.75",
5
- "@swapkit/types": "1.0.0-rc.41"
4
+ "@swapkit/types": "1.0.0-rc.43",
5
+ "@swapkit/helpers": "1.0.0-rc.77"
6
6
  },
7
7
  "description": "SwapKit Lib core",
8
8
  "devDependencies": {
9
9
  "@vitest/coverage-istanbul": "1.3.1",
10
- "vite": "5.1.3",
10
+ "vite": "5.1.6",
11
11
  "vitest": "1.3.1",
12
- "@swapkit/tokens": "1.0.0-rc.37",
13
- "@swapkit/toolbox-cosmos": "1.0.0-rc.92",
14
- "@swapkit/toolbox-evm": "1.0.0-rc.81",
15
- "@swapkit/toolbox-substrate": "1.0.0-rc.10",
16
- "@swapkit/toolbox-utxo": "1.0.0-rc.83"
12
+ "@swapkit/tokens": "1.0.0-rc.39",
13
+ "@swapkit/toolbox-cosmos": "1.0.0-rc.94",
14
+ "@swapkit/toolbox-substrate": "1.0.0-rc.12",
15
+ "@swapkit/toolbox-utxo": "1.0.0-rc.85",
16
+ "@swapkit/toolbox-evm": "1.0.0-rc.83"
17
17
  },
18
18
  "peerDependencies": {
19
- "@swapkit/tokens": "1.0.0-rc.37",
20
- "@swapkit/toolbox-cosmos": "1.0.0-rc.92",
21
- "@swapkit/toolbox-evm": "1.0.0-rc.81",
22
- "@swapkit/toolbox-substrate": "1.0.0-rc.10",
23
- "@swapkit/toolbox-utxo": "1.0.0-rc.83"
19
+ "@swapkit/toolbox-cosmos": "1.0.0-rc.94",
20
+ "@swapkit/toolbox-substrate": "1.0.0-rc.12",
21
+ "@swapkit/toolbox-evm": "1.0.0-rc.83",
22
+ "@swapkit/tokens": "1.0.0-rc.39",
23
+ "@swapkit/toolbox-utxo": "1.0.0-rc.85"
24
24
  },
25
25
  "exports": {
26
26
  ".": {
@@ -45,7 +45,7 @@
45
45
  },
46
46
  "type": "module",
47
47
  "types": "./dist/index.d.ts",
48
- "version": "1.0.0-rc.111",
48
+ "version": "1.0.0-rc.113",
49
49
  "scripts": {
50
50
  "build": "NODE_OPTIONS=--max_old_space_size=16384 vite build",
51
51
  "clean": "rm -rf dist vite.config.ts.* node_modules",
@@ -10,7 +10,8 @@ import type {
10
10
  SwapWithRouteParams,
11
11
  } from "../types.ts";
12
12
 
13
- export type ProviderName = "thorchain" | "chainflip" | "mayachain";
13
+ export type PluginName = "thorchain" | "chainflip" | "mayachain";
14
+
14
15
  export enum ApproveMode {
15
16
  Approve = "approve",
16
17
  CheckOnly = "checkOnly",
@@ -20,8 +21,8 @@ export type ApproveReturnType<T extends ApproveMode> = T extends "checkOnly"
20
21
  ? Promise<boolean>
21
22
  : Promise<string>;
22
23
 
23
- type SwapKitProviders = {
24
- [K in ProviderName]?: ProviderMethods;
24
+ type SwapKitPlugins = {
25
+ [K in PluginName]?: ProviderMethods;
25
26
  };
26
27
 
27
28
  type GenericSwapParams = {
@@ -32,12 +33,12 @@ type GenericSwapParams = {
32
33
 
33
34
  export type SwapParams = (SwapWithRouteParams | GenericSwapParams) & {
34
35
  provider?: {
35
- name: ProviderName;
36
+ name: PluginName;
36
37
  config: Record<string, any>;
37
38
  };
38
39
  };
39
40
 
40
- export type SwapKitReturnType = SwapKitProviders & {
41
+ export type SwapKitReturnType = SwapKitPlugins & {
41
42
  getAddress: (chain: Chain) => string;
42
43
  getWallet: (chain: Chain) => ChainWallet<Chain> | undefined;
43
44
  getWalletWithBalance: (
@@ -60,14 +61,14 @@ export type SwapKitReturnType = SwapKitProviders & {
60
61
  };
61
62
 
62
63
  export type Wallets = { [K in Chain]?: ChainWallet<K> };
63
- export type AvailableProviders<T> = T | { [K in ProviderName]?: ProviderMethods };
64
+ export type AvailableProviders<T> = T | { [K in PluginName]?: ProviderMethods };
64
65
  export type ProviderMethods = {
65
66
  swap: (swapParams: SwapParams) => Promise<string>;
66
67
  [key: string]: any;
67
68
  };
68
69
 
69
- export type SwapKitProvider = ({ wallets, stagenet }: { wallets: Wallets; stagenet?: boolean }) => {
70
- name: ProviderName;
70
+ export type SwapKitPlugin = ({ wallets, stagenet }: { wallets: Wallets; stagenet?: boolean }) => {
71
+ name: PluginName;
71
72
  methods: ProviderMethods;
72
73
  };
73
74
 
@@ -82,12 +83,12 @@ export function SwapKit<
82
83
  >({
83
84
  stagenet,
84
85
  wallets,
85
- providers,
86
+ plugins,
86
87
  config = {},
87
88
  apis,
88
89
  rpcUrls,
89
90
  }: {
90
- providers: SwapKitProvider[];
91
+ plugins: SwapKitPlugin[];
91
92
  stagenet: boolean;
92
93
  wallets: SwapKitWallet[];
93
94
  config?: Record<string, any>;
@@ -95,12 +96,12 @@ export function SwapKit<
95
96
  rpcUrls: Record<string, any>;
96
97
  }): SwapKitReturnType & ConnectWalletMethods & AvailableProviders<ExtendedProviders> {
97
98
  const connectedWallets: Wallets = {};
98
- const availableProviders: AvailableProviders<ExtendedProviders> = {};
99
+ const availablePlugins: AvailableProviders<ExtendedProviders> = {};
99
100
 
100
- for (const provider of providers) {
101
- const { name, methods } = provider({ wallets: connectedWallets, stagenet });
101
+ for (const plugin of plugins) {
102
+ const { name, methods } = plugin({ wallets: connectedWallets, stagenet });
102
103
 
103
- availableProviders[name] = methods;
104
+ availablePlugins[name] = methods;
104
105
  }
105
106
 
106
107
  const connectWalletMethods = wallets.reduce((acc, wallet) => {
@@ -118,19 +119,16 @@ export function SwapKit<
118
119
  * @Private
119
120
  * Internal helpers
120
121
  */
121
- function getProvider(providerName?: ProviderName) {
122
- const provider =
123
- (availableProviders as SwapKitProviders)[providerName as ProviderName] ||
124
- Object.values(availableProviders)[0];
125
-
126
- if (!provider) {
127
- throw new SwapKitError(
128
- "core_swap_provider_not_found",
129
- "Could not find the requested provider",
130
- );
122
+ function getSwapKitPlugin(pluginName?: PluginName) {
123
+ const plugin =
124
+ (availablePlugins as SwapKitPlugins)[pluginName as PluginName] ||
125
+ Object.values(availablePlugins)[0];
126
+
127
+ if (!plugin) {
128
+ throw new SwapKitError("core_plugin_not_found", "Could not find the requested plugin");
131
129
  }
132
130
 
133
- return provider;
131
+ return plugin;
134
132
  }
135
133
 
136
134
  function addChain(connectWallet: ChainWallet<Chain>) {
@@ -233,14 +231,14 @@ export function SwapKit<
233
231
  return approve({ assetValue, contractAddress, type: ApproveMode.CheckOnly });
234
232
  }
235
233
 
236
- function swap({ provider: providerConfig, ...rest }: SwapParams) {
237
- const provider = getProvider(providerConfig?.name);
234
+ function swap({ provider, ...rest }: SwapParams) {
235
+ const plugin = getSwapKitPlugin(provider?.name);
238
236
 
239
- return provider.swap({ provider: providerConfig, ...rest });
237
+ return plugin.swap({ provider, ...rest });
240
238
  }
241
239
 
242
240
  return {
243
- ...availableProviders,
241
+ ...availablePlugins,
244
242
  ...connectWalletMethods,
245
243
  approveAssetValue,
246
244
  getAddress,
package/src/client/old.ts CHANGED
@@ -1,9 +1,4 @@
1
- import type {
2
- ErrorKeys,
3
- MayanameRegisterParam,
4
- QuoteRoute,
5
- ThornameRegisterParam,
6
- } from "@swapkit/helpers";
1
+ import type { ErrorKeys, QuoteRoute, ThornameRegisterParam } from "@swapkit/helpers";
7
2
  import {
8
3
  AssetValue,
9
4
  SwapKitError,
@@ -337,7 +332,8 @@ export class SwapKitCore<T = ""> {
337
332
  getChecksumAddressFromAsset({ chain, symbol, ticker }, chain),
338
333
  assetValue.getBaseValue("string"),
339
334
  params.memo,
340
- rest.expiration || parseInt(`${(new Date().getTime() + 15 * 60 * 1000) / 1000}`),
335
+ rest.expiration ||
336
+ Number.parseInt(`${(new Date().getTime() + 15 * 60 * 1000) / 1000}`),
341
337
  ],
342
338
  txOverrides: {
343
339
  from: params.from,
@@ -623,7 +619,7 @@ export class SwapKitCore<T = ""> {
623
619
  registerMayaname = ({
624
620
  assetValue,
625
621
  ...param
626
- }: MayanameRegisterParam & { assetValue: AssetValue }) =>
622
+ }: ThornameRegisterParam & { assetValue: AssetValue }) =>
627
623
  this.#mayachainTransfer({
628
624
  assetValue,
629
625
  memo: getMemoFor(MemoType.THORNAME_REGISTER, param),
@@ -692,39 +688,39 @@ export class SwapKitCore<T = ""> {
692
688
  /**
693
689
  * Wallet connection methods
694
690
  */
695
- // biome-ignore lint/nursery/useAwait: Extended methods
691
+ // biome-ignore lint/suspicious/useAwait: Extended methods
696
692
  connectXDEFI = async (_chains: Chain[]): Promise<void> => {
697
693
  throw new SwapKitError("core_wallet_xdefi_not_installed");
698
694
  };
699
- // biome-ignore lint/nursery/useAwait: Extended methods
695
+ // biome-ignore lint/suspicious/useAwait: Extended methods
700
696
  connectEVMWallet = async (_chains: Chain[] | Chain, _wallet: EVMWalletOptions): Promise<void> => {
701
697
  throw new SwapKitError("core_wallet_evmwallet_not_installed");
702
698
  };
703
- // biome-ignore lint/nursery/useAwait: Extended methods
699
+ // biome-ignore lint/suspicious/useAwait: Extended methods
704
700
  connectWalletconnect = async (_chains: Chain[], _options?: any): Promise<void> => {
705
701
  throw new SwapKitError("core_wallet_walletconnect_not_installed");
706
702
  };
707
- // biome-ignore lint/nursery/useAwait: Extended methods
703
+ // biome-ignore lint/suspicious/useAwait: Extended methods
708
704
  connectKeepkey = async (_chains: Chain[], _derivationPath: number[][]): Promise<string> => {
709
705
  throw new SwapKitError("core_wallet_keepkey_not_installed");
710
706
  };
711
- // biome-ignore lint/nursery/useAwait: Extended methods
707
+ // biome-ignore lint/suspicious/useAwait: Extended methods
712
708
  connectKeystore = async (_chains: Chain[], _phrase: string): Promise<void> => {
713
709
  throw new SwapKitError("core_wallet_keystore_not_installed");
714
710
  };
715
- // biome-ignore lint/nursery/useAwait: Extended methods
711
+ // biome-ignore lint/suspicious/useAwait: Extended methods
716
712
  connectLedger = async (_chains: Chain, _derivationPath: number[]): Promise<void> => {
717
713
  throw new SwapKitError("core_wallet_ledger_not_installed");
718
714
  };
719
- // biome-ignore lint/nursery/useAwait: Extended methods
715
+ // biome-ignore lint/suspicious/useAwait: Extended methods
720
716
  connectTrezor = async (_chains: Chain, _derivationPath: number[]): Promise<void> => {
721
717
  throw new SwapKitError("core_wallet_trezor_not_installed");
722
718
  };
723
- // biome-ignore lint/nursery/useAwait: Extended methods
719
+ // biome-ignore lint/suspicious/useAwait: Extended methods
724
720
  connectKeplr = async (_chain: Chain): Promise<void> => {
725
721
  throw new SwapKitError("core_wallet_keplr_not_installed");
726
722
  };
727
- // biome-ignore lint/nursery/useAwait: Extended methods
723
+ // biome-ignore lint/suspicious/useAwait: Extended methods
728
724
  connectOkx = async (_chains: Chain[]): Promise<void> => {
729
725
  throw new SwapKitError("core_wallet_okx_not_installed");
730
726
  };
@@ -816,7 +812,7 @@ export class SwapKitCore<T = ""> {
816
812
  router,
817
813
  address: poolAddress,
818
814
  } = await this.#getInboundDataByChain(assetValue.chain);
819
- const feeRate = (parseInt(gas_rate) || 0) * gasFeeMultiplier[feeOptionKey];
815
+ const feeRate = (Number.parseInt(gas_rate) || 0) * gasFeeMultiplier[feeOptionKey];
820
816
 
821
817
  return this.deposit({
822
818
  assetValue,