@swapkit/core 1.0.0-rc.11 → 1.0.0-rc.110
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/index.cjs +2 -2
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +160 -26
- package/dist/index.es.js +6480 -1095
- package/dist/index.es.js.map +1 -0
- package/package.json +23 -30
- package/src/__tests__/helpers.test.ts +77 -0
- package/src/aggregator/contracts/avaxGeneric.ts +50 -50
- package/src/aggregator/contracts/avaxWoofi.ts +80 -80
- package/src/aggregator/contracts/bscGeneric.ts +59 -59
- package/src/aggregator/contracts/ethGeneric.ts +50 -50
- package/src/aggregator/contracts/index.ts +30 -28
- package/src/aggregator/contracts/pancakeV2.ts +80 -80
- package/src/aggregator/contracts/pangolin.ts +65 -65
- package/src/aggregator/contracts/routers/index.ts +58 -0
- package/src/aggregator/contracts/routers/kyber.ts +402 -0
- package/src/aggregator/contracts/routers/oneinch.ts +2188 -0
- package/src/aggregator/contracts/routers/pancakeswap.ts +340 -0
- package/src/aggregator/contracts/routers/pangolin.ts +340 -0
- package/src/aggregator/contracts/routers/sushiswap.ts +340 -0
- package/src/aggregator/contracts/routers/traderJoe.ts +340 -0
- package/src/aggregator/contracts/routers/uniswapv2.ts +340 -0
- package/src/aggregator/contracts/routers/uniswapv3.ts +254 -0
- package/src/aggregator/contracts/routers/woofi.ts +171 -0
- package/src/aggregator/contracts/sushiswap.ts +65 -65
- package/src/aggregator/contracts/traderJoe.ts +65 -65
- package/src/aggregator/contracts/uniswapV2.ts +65 -65
- package/src/aggregator/contracts/uniswapV2Leg.ts +70 -70
- package/src/aggregator/contracts/uniswapV3_100.ts +70 -70
- package/src/aggregator/contracts/uniswapV3_10000.ts +70 -70
- package/src/aggregator/contracts/uniswapV3_3000.ts +70 -70
- package/src/aggregator/contracts/uniswapV3_500.ts +70 -70
- package/src/aggregator/getSwapParams.ts +12 -12
- package/src/client/index.ts +212 -645
- package/src/client/old.ts +837 -0
- package/src/{client → helpers}/explorerUrls.ts +11 -10
- package/src/{client → helpers}/thornode.ts +5 -5
- package/src/index.ts +6 -4
- package/src/types.ts +149 -0
- package/dist/index-9e36735e.cjs +0 -1
- package/dist/index-cf1865cd.js +0 -649
- package/src/client/__tests__/helpers.test.ts +0 -69
- package/src/client/types.ts +0 -103
package/dist/index.d.ts
CHANGED
|
@@ -6,38 +6,70 @@ import type { BinanceToolbox } from '@swapkit/toolbox-cosmos';
|
|
|
6
6
|
import type { BSCToolbox } from '@swapkit/toolbox-evm';
|
|
7
7
|
import type { BTCToolbox } from '@swapkit/toolbox-utxo';
|
|
8
8
|
import { Chain } from '@swapkit/types';
|
|
9
|
+
import type { ChainflipToolbox } from '@swapkit/toolbox-substrate';
|
|
10
|
+
import { ConnectConfig } from '@swapkit/types';
|
|
11
|
+
import { CosmosChain } from '@swapkit/types';
|
|
12
|
+
import type { DASHToolbox } from '@swapkit/toolbox-utxo';
|
|
9
13
|
import type { DepositParam } from '@swapkit/toolbox-cosmos';
|
|
10
14
|
import type { DOGEToolbox } from '@swapkit/toolbox-utxo';
|
|
11
15
|
import type { ETHToolbox } from '@swapkit/toolbox-evm';
|
|
16
|
+
import { EVMChain } from '@swapkit/types';
|
|
12
17
|
import type { EVMWalletOptions } from '@swapkit/types';
|
|
13
18
|
import type { ExtendParams } from '@swapkit/types';
|
|
14
|
-
import
|
|
19
|
+
import { FeeOption } from '@swapkit/types';
|
|
15
20
|
import type { GaiaToolbox } from '@swapkit/toolbox-cosmos';
|
|
16
21
|
import type { KujiraToolbox } from '@swapkit/toolbox-cosmos';
|
|
17
22
|
import type { LTCToolbox } from '@swapkit/toolbox-utxo';
|
|
18
23
|
import type { MATICToolbox } from '@swapkit/toolbox-evm';
|
|
19
24
|
import type { OPToolbox } from '@swapkit/toolbox-evm';
|
|
20
|
-
import type {
|
|
25
|
+
import type { PolkadotToolbox } from '@swapkit/toolbox-substrate';
|
|
26
|
+
import type { QuoteRoute } from '@swapkit/helpers';
|
|
21
27
|
import type { SwapKitNumber } from '@swapkit/helpers';
|
|
22
28
|
import type { ThorchainToolboxType } from '@swapkit/toolbox-cosmos';
|
|
23
29
|
import type { ThornameRegisterParam } from '@swapkit/helpers';
|
|
24
|
-
import
|
|
30
|
+
import { UTXOChain } from '@swapkit/types';
|
|
31
|
+
import { WalletOption } from '@swapkit/types';
|
|
25
32
|
|
|
26
33
|
export declare type AddLiquidityTxns = {
|
|
27
34
|
runeTx?: string;
|
|
28
35
|
assetTx?: string;
|
|
29
36
|
};
|
|
30
37
|
|
|
31
|
-
declare type
|
|
32
|
-
|
|
38
|
+
declare type ApisType = {
|
|
39
|
+
[key in UTXOChain]?: string | any;
|
|
40
|
+
} & {
|
|
41
|
+
[key in EVMChain]?: string | any;
|
|
42
|
+
} & {
|
|
43
|
+
[key in CosmosChain]?: string;
|
|
33
44
|
};
|
|
34
45
|
|
|
35
|
-
export declare
|
|
46
|
+
export declare enum ApproveMode {
|
|
47
|
+
Approve = "approve",
|
|
48
|
+
CheckOnly = "checkOnly"
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export declare type ApproveReturnType<T extends ApproveMode> = T extends "checkOnly" ? Promise<boolean> : Promise<string>;
|
|
52
|
+
|
|
53
|
+
export declare type AvailableProviders<T> = T | {
|
|
54
|
+
[K in ProviderName]?: ProviderMethods;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
export declare type ChainWallet<T extends Chain> = WalletMethods[T] & {
|
|
58
|
+
chain: Chain;
|
|
36
59
|
address: string;
|
|
37
60
|
balance: AssetValue[];
|
|
38
61
|
walletType: WalletOption;
|
|
39
62
|
};
|
|
40
63
|
|
|
64
|
+
export declare type ConnectWalletParamsLocal = {
|
|
65
|
+
addChain: (params: ChainWallet<Chain>) => void;
|
|
66
|
+
config: ConnectConfig;
|
|
67
|
+
rpcUrls: {
|
|
68
|
+
[chain in Chain]?: string;
|
|
69
|
+
};
|
|
70
|
+
apis: ApisType;
|
|
71
|
+
};
|
|
72
|
+
|
|
41
73
|
export declare type CoreTxParams = {
|
|
42
74
|
assetValue: AssetValue;
|
|
43
75
|
recipient: string;
|
|
@@ -49,17 +81,63 @@ export declare type CoreTxParams = {
|
|
|
49
81
|
expiration?: number;
|
|
50
82
|
};
|
|
51
83
|
|
|
52
|
-
export declare type CosmosBasedWallet<T extends typeof BinanceToolbox | typeof GaiaToolbox> =
|
|
84
|
+
export declare type CosmosBasedWallet<T extends typeof BinanceToolbox | typeof GaiaToolbox> = ReturnType<T> & {
|
|
53
85
|
transfer: (params: CoreTxParams) => Promise<string>;
|
|
54
86
|
};
|
|
55
87
|
|
|
56
|
-
export declare type EVMWallet<T extends typeof AVAXToolbox | typeof BSCToolbox | typeof ETHToolbox | typeof OPToolbox> =
|
|
88
|
+
export declare type EVMWallet<T extends typeof AVAXToolbox | typeof BSCToolbox | typeof ETHToolbox | typeof OPToolbox> = ReturnType<T> & {
|
|
57
89
|
transfer: (params: CoreTxParams) => Promise<string>;
|
|
58
90
|
};
|
|
59
91
|
|
|
60
|
-
|
|
92
|
+
declare type GenericSwapParams = {
|
|
93
|
+
buyAsset: AssetValue;
|
|
94
|
+
sellAsset: AssetValue;
|
|
95
|
+
recipient: string;
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
export declare type OldChainWallet = {
|
|
99
|
+
address: string;
|
|
100
|
+
balance: AssetValue[];
|
|
101
|
+
walletType: WalletOption;
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
export declare type OldWallet = {
|
|
105
|
+
[key in Chain]: OldChainWallet | null;
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
export declare type ProviderMethods = {
|
|
109
|
+
swap: (swapParams: SwapParams) => Promise<string>;
|
|
110
|
+
[key: string]: any;
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
export declare type ProviderName = "thorchain" | "chainflip" | "mayachain";
|
|
114
|
+
|
|
115
|
+
export declare type QuoteRouteV2 = {
|
|
116
|
+
buyAsset: string;
|
|
117
|
+
sellAsset: string;
|
|
118
|
+
sellAmount: number;
|
|
119
|
+
destinationAddress: string;
|
|
120
|
+
sourceAddress: string;
|
|
121
|
+
providers: string[];
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
export declare type SubstrateBasedWallet<T extends typeof PolkadotToolbox | typeof ChainflipToolbox> = Awaited<ReturnType<T>>;
|
|
125
|
+
|
|
126
|
+
export declare function SwapKit<ExtendedProviders extends {}, ConnectWalletMethods extends Record<string, ReturnType<SwapKitWallet["connect"]>>>({ stagenet, wallets, providers, config, apis, rpcUrls, }: {
|
|
127
|
+
providers: SwapKitProvider[];
|
|
128
|
+
stagenet: boolean;
|
|
129
|
+
wallets: SwapKitWallet[];
|
|
130
|
+
config?: Record<string, any>;
|
|
131
|
+
apis: Record<string, any>;
|
|
132
|
+
rpcUrls: Record<string, any>;
|
|
133
|
+
}): SwapKitReturnType & ConnectWalletMethods & AvailableProviders<ExtendedProviders>;
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* @deprecated Use SwapKit instead (import { SwapKit } from "@swapkit/core")
|
|
137
|
+
*/
|
|
138
|
+
export declare class SwapKitCore<T = ""> {
|
|
61
139
|
|
|
62
|
-
connectedChains:
|
|
140
|
+
connectedChains: OldWallet;
|
|
63
141
|
connectedWallets: WalletMethods;
|
|
64
142
|
readonly stagenet: boolean;
|
|
65
143
|
constructor({ stagenet }?: {
|
|
@@ -70,7 +148,7 @@ export declare class SwapKitCore<T = ''> {
|
|
|
70
148
|
getWallet: <T_1 extends Chain>(chain: Chain) => WalletMethods[T_1];
|
|
71
149
|
getExplorerAddressUrl: (chain: Chain, address: string) => string;
|
|
72
150
|
getBalance: (chain: Chain, potentialScamFilter?: boolean) => Promise<AssetValue[]>;
|
|
73
|
-
swap: ({ streamSwap, recipient, route, feeOptionKey }:
|
|
151
|
+
swap: ({ streamSwap, recipient, route, feeOptionKey, }: SwapWithRouteParams) => Promise<string>;
|
|
74
152
|
getWalletByChain: (chain: Chain, potentialScamFilter?: boolean) => Promise<{
|
|
75
153
|
address?: string | undefined;
|
|
76
154
|
balance?: AssetValue[] | undefined;
|
|
@@ -98,8 +176,7 @@ export declare class SwapKitCore<T = ''> {
|
|
|
98
176
|
runeTx: string;
|
|
99
177
|
assetTx: string;
|
|
100
178
|
}>;
|
|
101
|
-
addLiquidity: ({
|
|
102
|
-
poolIdentifier: string;
|
|
179
|
+
addLiquidity: ({ runeAssetValue, assetValue, runeAddr, assetAddr, isPendingSymmAsset, mode, }: {
|
|
103
180
|
runeAssetValue: AssetValue;
|
|
104
181
|
assetValue: AssetValue;
|
|
105
182
|
isPendingSymmAsset?: boolean | undefined;
|
|
@@ -110,36 +187,42 @@ export declare class SwapKitCore<T = ''> {
|
|
|
110
187
|
runeTx: string | undefined;
|
|
111
188
|
assetTx: string | undefined;
|
|
112
189
|
}>;
|
|
190
|
+
addLiquidityPart: ({ assetValue, poolAddress, address, symmetric, }: {
|
|
191
|
+
assetValue: AssetValue;
|
|
192
|
+
address?: string | undefined;
|
|
193
|
+
poolAddress: string;
|
|
194
|
+
symmetric: boolean;
|
|
195
|
+
}) => Promise<string>;
|
|
113
196
|
withdraw: ({ memo, assetValue, percent, from, to, }: {
|
|
114
197
|
memo?: string | undefined;
|
|
115
198
|
assetValue: AssetValue;
|
|
116
199
|
percent: number;
|
|
117
|
-
from:
|
|
118
|
-
to:
|
|
200
|
+
from: "sym" | "rune" | "asset";
|
|
201
|
+
to: "sym" | "rune" | "asset";
|
|
119
202
|
}) => Promise<string>;
|
|
120
203
|
savings: ({ assetValue, memo, percent, type, }: {
|
|
121
204
|
assetValue: AssetValue;
|
|
122
205
|
memo?: string | undefined;
|
|
123
206
|
} & ({
|
|
124
|
-
type:
|
|
207
|
+
type: "add";
|
|
125
208
|
percent?: undefined;
|
|
126
209
|
} | {
|
|
127
|
-
type:
|
|
210
|
+
type: "withdraw";
|
|
128
211
|
percent: number;
|
|
129
212
|
})) => Promise<string>;
|
|
130
213
|
loan: ({ assetValue, memo, minAmount, type, }: {
|
|
131
214
|
assetValue: AssetValue;
|
|
132
215
|
memo?: string | undefined;
|
|
133
216
|
minAmount: AssetValue;
|
|
134
|
-
type:
|
|
217
|
+
type: "open" | "close";
|
|
135
218
|
}) => Promise<string>;
|
|
136
219
|
nodeAction: ({ type, assetValue, address, }: {
|
|
137
220
|
address: string;
|
|
138
221
|
} & ({
|
|
139
|
-
type:
|
|
222
|
+
type: "bond" | "unbond";
|
|
140
223
|
assetValue: AssetValue;
|
|
141
224
|
} | {
|
|
142
|
-
type:
|
|
225
|
+
type: "leave";
|
|
143
226
|
assetValue?: undefined;
|
|
144
227
|
})) => Promise<string>;
|
|
145
228
|
registerThorname: ({ assetValue, ...param }: ThornameRegisterParam & {
|
|
@@ -160,6 +243,7 @@ export declare class SwapKitCore<T = ''> {
|
|
|
160
243
|
connectXDEFI: (_chains: Chain[]) => Promise<void>;
|
|
161
244
|
connectEVMWallet: (_chains: Chain[] | Chain, _wallet: EVMWalletOptions) => Promise<void>;
|
|
162
245
|
connectWalletconnect: (_chains: Chain[], _options?: any) => Promise<void>;
|
|
246
|
+
connectKeepkey: (_chains: Chain[], _derivationPath: number[][]) => Promise<string>;
|
|
163
247
|
connectKeystore: (_chains: Chain[], _phrase: string) => Promise<void>;
|
|
164
248
|
connectLedger: (_chains: Chain, _derivationPath: number[]) => Promise<void>;
|
|
165
249
|
connectTrezor: (_chains: Chain, _derivationPath: number[]) => Promise<void>;
|
|
@@ -168,14 +252,55 @@ export declare class SwapKitCore<T = ''> {
|
|
|
168
252
|
disconnectChain: (chain: Chain) => void;
|
|
169
253
|
}
|
|
170
254
|
|
|
171
|
-
export declare type
|
|
255
|
+
export declare type SwapKitProvider = ({ wallets, stagenet }: {
|
|
256
|
+
wallets: Wallets;
|
|
257
|
+
stagenet?: boolean;
|
|
258
|
+
}) => {
|
|
259
|
+
name: ProviderName;
|
|
260
|
+
methods: ProviderMethods;
|
|
261
|
+
};
|
|
262
|
+
|
|
263
|
+
declare type SwapKitProviders = {
|
|
264
|
+
[K in ProviderName]?: ProviderMethods;
|
|
265
|
+
};
|
|
266
|
+
|
|
267
|
+
export declare type SwapKitReturnType = SwapKitProviders & {
|
|
268
|
+
getAddress: (chain: Chain) => string;
|
|
269
|
+
getWallet: (chain: Chain) => ChainWallet<Chain> | undefined;
|
|
270
|
+
getWalletWithBalance: (chain: Chain, potentialScamFilter?: boolean) => Promise<ChainWallet<Chain>>;
|
|
271
|
+
getBalance: (chain: Chain, potentialScamFilter?: boolean) => AssetValue[];
|
|
272
|
+
getExplorerTxUrl: (chain: Chain, txHash: string) => string;
|
|
273
|
+
getExplorerAddressUrl: (chain: Chain, address: string) => string;
|
|
274
|
+
swap: (params: SwapParams) => Promise<string>;
|
|
275
|
+
validateAddress: (params: {
|
|
276
|
+
address: string;
|
|
277
|
+
chain: Chain;
|
|
278
|
+
}) => boolean | Promise<boolean> | undefined;
|
|
279
|
+
approveAssetValue: (assetValue: AssetValue, contractAddress: string) => boolean | Promise<string>;
|
|
280
|
+
isAssetValueApproved: (assetValue: AssetValue, contractAddress: string) => boolean | Promise<boolean>;
|
|
281
|
+
};
|
|
282
|
+
|
|
283
|
+
export declare type SwapKitWallet = {
|
|
284
|
+
connectMethodName: string;
|
|
285
|
+
connect: (params: ConnectWalletParamsLocal) => (connectParams: any) => void;
|
|
286
|
+
};
|
|
287
|
+
|
|
288
|
+
export declare type SwapParams = (SwapWithRouteParams | GenericSwapParams) & {
|
|
289
|
+
provider?: {
|
|
290
|
+
name: ProviderName;
|
|
291
|
+
config: Record<string, any>;
|
|
292
|
+
};
|
|
293
|
+
};
|
|
294
|
+
|
|
295
|
+
export declare type SwapWithRouteParams = {
|
|
172
296
|
recipient: string;
|
|
297
|
+
route: QuoteRoute | QuoteRouteV2;
|
|
298
|
+
feeOptionKey?: FeeOption;
|
|
299
|
+
quoteId?: string;
|
|
173
300
|
streamSwap?: boolean;
|
|
174
|
-
route: QuoteRoute;
|
|
175
|
-
feeOptionKey: FeeOption;
|
|
176
301
|
};
|
|
177
302
|
|
|
178
|
-
export declare type ThorchainWallet =
|
|
303
|
+
export declare type ThorchainWallet = ThorchainToolboxType & {
|
|
179
304
|
transfer: (params: CoreTxParams) => Promise<string>;
|
|
180
305
|
deposit: (params: DepositParam) => Promise<string>;
|
|
181
306
|
};
|
|
@@ -185,11 +310,13 @@ export declare type UpgradeParams = {
|
|
|
185
310
|
recipient: string;
|
|
186
311
|
};
|
|
187
312
|
|
|
188
|
-
export declare type UTXOWallet<T extends typeof BCHToolbox | typeof BTCToolbox | typeof DOGEToolbox | typeof LTCToolbox> =
|
|
313
|
+
export declare type UTXOWallet<T extends typeof BCHToolbox | typeof BTCToolbox | typeof DOGEToolbox | typeof LTCToolbox> = ReturnType<T> & {
|
|
189
314
|
transfer: (prams: CoreTxParams) => Promise<string>;
|
|
190
315
|
};
|
|
191
316
|
|
|
192
|
-
export declare type Wallet =
|
|
317
|
+
export declare type Wallet = {
|
|
318
|
+
[key in Chain]?: ChainWallet<key>;
|
|
319
|
+
};
|
|
193
320
|
|
|
194
321
|
export declare type WalletMethods = {
|
|
195
322
|
[Chain.Arbitrum]: EVMWallet<typeof ARBToolbox> | null;
|
|
@@ -198,17 +325,24 @@ export declare type WalletMethods = {
|
|
|
198
325
|
[Chain.Binance]: CosmosBasedWallet<typeof BinanceToolbox> | null;
|
|
199
326
|
[Chain.BitcoinCash]: UTXOWallet<typeof BCHToolbox> | null;
|
|
200
327
|
[Chain.Bitcoin]: UTXOWallet<typeof BTCToolbox> | null;
|
|
328
|
+
[Chain.Chainflip]: SubstrateBasedWallet<typeof ChainflipToolbox> | null;
|
|
201
329
|
[Chain.Cosmos]: CosmosBasedWallet<typeof GaiaToolbox> | null;
|
|
330
|
+
[Chain.Dash]: UTXOWallet<typeof DASHToolbox> | null;
|
|
202
331
|
[Chain.Dogecoin]: UTXOWallet<typeof DOGEToolbox> | null;
|
|
203
332
|
[Chain.Ethereum]: EVMWallet<typeof ETHToolbox> | null;
|
|
204
333
|
[Chain.Kujira]: CosmosBasedWallet<typeof KujiraToolbox> | null;
|
|
205
334
|
[Chain.Litecoin]: UTXOWallet<typeof LTCToolbox> | null;
|
|
206
335
|
[Chain.Maya]: ThorchainWallet | null;
|
|
207
336
|
[Chain.Optimism]: EVMWallet<typeof OPToolbox> | null;
|
|
337
|
+
[Chain.Polkadot]: SubstrateBasedWallet<typeof PolkadotToolbox> | null;
|
|
208
338
|
[Chain.Polygon]: EVMWallet<typeof MATICToolbox> | null;
|
|
209
339
|
[Chain.THORChain]: ThorchainWallet | null;
|
|
210
340
|
};
|
|
211
341
|
|
|
342
|
+
export declare type Wallets = {
|
|
343
|
+
[K in Chain]?: ChainWallet<K>;
|
|
344
|
+
};
|
|
345
|
+
|
|
212
346
|
|
|
213
347
|
export * from "@swapkit/helpers";
|
|
214
348
|
export * from "@swapkit/types";
|