@swapkit/core 1.0.0-rc.111 → 1.0.0-rc.112
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 +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +14 -12
- package/dist/index.es.js +75 -77
- package/dist/index.es.js.map +1 -1
- package/package.json +14 -14
- package/src/client/index.ts +27 -29
- package/src/client/old.ts +14 -18
package/package.json
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
1
|
{
|
|
2
2
|
"author": "swapkit-oss",
|
|
3
3
|
"dependencies": {
|
|
4
|
-
"@swapkit/
|
|
5
|
-
"@swapkit/
|
|
4
|
+
"@swapkit/types": "1.0.0-rc.42",
|
|
5
|
+
"@swapkit/helpers": "1.0.0-rc.76"
|
|
6
6
|
},
|
|
7
7
|
"description": "SwapKit Lib core",
|
|
8
8
|
"devDependencies": {
|
|
9
9
|
"@vitest/coverage-istanbul": "1.3.1",
|
|
10
|
-
"vite": "5.1.
|
|
10
|
+
"vite": "5.1.6",
|
|
11
11
|
"vitest": "1.3.1",
|
|
12
|
-
"@swapkit/tokens": "1.0.0-rc.
|
|
13
|
-
"@swapkit/toolbox-cosmos": "1.0.0-rc.
|
|
14
|
-
"@swapkit/toolbox-evm": "1.0.0-rc.
|
|
15
|
-
"@swapkit/toolbox-substrate": "1.0.0-rc.
|
|
16
|
-
"@swapkit/toolbox-utxo": "1.0.0-rc.
|
|
12
|
+
"@swapkit/tokens": "1.0.0-rc.38",
|
|
13
|
+
"@swapkit/toolbox-cosmos": "1.0.0-rc.93",
|
|
14
|
+
"@swapkit/toolbox-evm": "1.0.0-rc.82",
|
|
15
|
+
"@swapkit/toolbox-substrate": "1.0.0-rc.11",
|
|
16
|
+
"@swapkit/toolbox-utxo": "1.0.0-rc.84"
|
|
17
17
|
},
|
|
18
18
|
"peerDependencies": {
|
|
19
|
-
"@swapkit/tokens": "1.0.0-rc.
|
|
20
|
-
"@swapkit/toolbox-
|
|
21
|
-
"@swapkit/toolbox-
|
|
22
|
-
"@swapkit/toolbox-
|
|
23
|
-
"@swapkit/toolbox-
|
|
19
|
+
"@swapkit/tokens": "1.0.0-rc.38",
|
|
20
|
+
"@swapkit/toolbox-evm": "1.0.0-rc.82",
|
|
21
|
+
"@swapkit/toolbox-cosmos": "1.0.0-rc.93",
|
|
22
|
+
"@swapkit/toolbox-utxo": "1.0.0-rc.84",
|
|
23
|
+
"@swapkit/toolbox-substrate": "1.0.0-rc.11"
|
|
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.
|
|
48
|
+
"version": "1.0.0-rc.112",
|
|
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",
|
package/src/client/index.ts
CHANGED
|
@@ -10,7 +10,8 @@ import type {
|
|
|
10
10
|
SwapWithRouteParams,
|
|
11
11
|
} from "../types.ts";
|
|
12
12
|
|
|
13
|
-
export type
|
|
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
|
|
24
|
-
[K in
|
|
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:
|
|
36
|
+
name: PluginName;
|
|
36
37
|
config: Record<string, any>;
|
|
37
38
|
};
|
|
38
39
|
};
|
|
39
40
|
|
|
40
|
-
export type SwapKitReturnType =
|
|
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
|
|
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
|
|
70
|
-
name:
|
|
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
|
-
|
|
86
|
+
plugins,
|
|
86
87
|
config = {},
|
|
87
88
|
apis,
|
|
88
89
|
rpcUrls,
|
|
89
90
|
}: {
|
|
90
|
-
|
|
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
|
|
99
|
+
const availablePlugins: AvailableProviders<ExtendedProviders> = {};
|
|
99
100
|
|
|
100
|
-
for (const
|
|
101
|
-
const { name, methods } =
|
|
101
|
+
for (const plugin of plugins) {
|
|
102
|
+
const { name, methods } = plugin({ wallets: connectedWallets, stagenet });
|
|
102
103
|
|
|
103
|
-
|
|
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
|
|
122
|
-
const
|
|
123
|
-
(
|
|
124
|
-
Object.values(
|
|
125
|
-
|
|
126
|
-
if (!
|
|
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
|
|
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
|
|
237
|
-
const
|
|
234
|
+
function swap({ provider, ...rest }: SwapParams) {
|
|
235
|
+
const plugin = getSwapKitPlugin(provider?.name);
|
|
238
236
|
|
|
239
|
-
return
|
|
237
|
+
return plugin.swap({ provider, ...rest });
|
|
240
238
|
}
|
|
241
239
|
|
|
242
240
|
return {
|
|
243
|
-
...
|
|
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 ||
|
|
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
|
-
}:
|
|
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/
|
|
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/
|
|
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/
|
|
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/
|
|
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/
|
|
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/
|
|
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/
|
|
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/
|
|
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/
|
|
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,
|