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