@swapkit/core 1.0.0-rc.11 → 1.0.0-rc.111
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 +161 -26
- package/dist/index.es.js +6483 -1064
- 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 +870 -0
- package/src/{client → helpers}/explorerUrls.ts +11 -10
- package/src/helpers/mayanode.ts +31 -0
- package/src/{client → helpers}/thornode.ts +7 -7
- 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,41 +187,48 @@ 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 & {
|
|
146
229
|
assetValue: AssetValue;
|
|
147
230
|
}) => Promise<string>;
|
|
231
|
+
registerMayaname: ({ assetValue, ...param }: any) => Promise<string>;
|
|
148
232
|
extend: ({ wallets, config, apis, rpcUrls }: ExtendParams<T>) => void;
|
|
149
233
|
estimateMaxSendableAmount: ({ chain, params, }: {
|
|
150
234
|
chain: Chain;
|
|
@@ -160,6 +244,7 @@ export declare class SwapKitCore<T = ''> {
|
|
|
160
244
|
connectXDEFI: (_chains: Chain[]) => Promise<void>;
|
|
161
245
|
connectEVMWallet: (_chains: Chain[] | Chain, _wallet: EVMWalletOptions) => Promise<void>;
|
|
162
246
|
connectWalletconnect: (_chains: Chain[], _options?: any) => Promise<void>;
|
|
247
|
+
connectKeepkey: (_chains: Chain[], _derivationPath: number[][]) => Promise<string>;
|
|
163
248
|
connectKeystore: (_chains: Chain[], _phrase: string) => Promise<void>;
|
|
164
249
|
connectLedger: (_chains: Chain, _derivationPath: number[]) => Promise<void>;
|
|
165
250
|
connectTrezor: (_chains: Chain, _derivationPath: number[]) => Promise<void>;
|
|
@@ -168,14 +253,55 @@ export declare class SwapKitCore<T = ''> {
|
|
|
168
253
|
disconnectChain: (chain: Chain) => void;
|
|
169
254
|
}
|
|
170
255
|
|
|
171
|
-
export declare type
|
|
256
|
+
export declare type SwapKitProvider = ({ wallets, stagenet }: {
|
|
257
|
+
wallets: Wallets;
|
|
258
|
+
stagenet?: boolean;
|
|
259
|
+
}) => {
|
|
260
|
+
name: ProviderName;
|
|
261
|
+
methods: ProviderMethods;
|
|
262
|
+
};
|
|
263
|
+
|
|
264
|
+
declare type SwapKitProviders = {
|
|
265
|
+
[K in ProviderName]?: ProviderMethods;
|
|
266
|
+
};
|
|
267
|
+
|
|
268
|
+
export declare type SwapKitReturnType = SwapKitProviders & {
|
|
269
|
+
getAddress: (chain: Chain) => string;
|
|
270
|
+
getWallet: (chain: Chain) => ChainWallet<Chain> | undefined;
|
|
271
|
+
getWalletWithBalance: (chain: Chain, potentialScamFilter?: boolean) => Promise<ChainWallet<Chain>>;
|
|
272
|
+
getBalance: (chain: Chain, potentialScamFilter?: boolean) => AssetValue[];
|
|
273
|
+
getExplorerTxUrl: (chain: Chain, txHash: string) => string;
|
|
274
|
+
getExplorerAddressUrl: (chain: Chain, address: string) => string;
|
|
275
|
+
swap: (params: SwapParams) => Promise<string>;
|
|
276
|
+
validateAddress: (params: {
|
|
277
|
+
address: string;
|
|
278
|
+
chain: Chain;
|
|
279
|
+
}) => boolean | Promise<boolean> | undefined;
|
|
280
|
+
approveAssetValue: (assetValue: AssetValue, contractAddress: string) => boolean | Promise<string>;
|
|
281
|
+
isAssetValueApproved: (assetValue: AssetValue, contractAddress: string) => boolean | Promise<boolean>;
|
|
282
|
+
};
|
|
283
|
+
|
|
284
|
+
export declare type SwapKitWallet = {
|
|
285
|
+
connectMethodName: string;
|
|
286
|
+
connect: (params: ConnectWalletParamsLocal) => (connectParams: any) => void;
|
|
287
|
+
};
|
|
288
|
+
|
|
289
|
+
export declare type SwapParams = (SwapWithRouteParams | GenericSwapParams) & {
|
|
290
|
+
provider?: {
|
|
291
|
+
name: ProviderName;
|
|
292
|
+
config: Record<string, any>;
|
|
293
|
+
};
|
|
294
|
+
};
|
|
295
|
+
|
|
296
|
+
export declare type SwapWithRouteParams = {
|
|
172
297
|
recipient: string;
|
|
298
|
+
route: QuoteRoute | QuoteRouteV2;
|
|
299
|
+
feeOptionKey?: FeeOption;
|
|
300
|
+
quoteId?: string;
|
|
173
301
|
streamSwap?: boolean;
|
|
174
|
-
route: QuoteRoute;
|
|
175
|
-
feeOptionKey: FeeOption;
|
|
176
302
|
};
|
|
177
303
|
|
|
178
|
-
export declare type ThorchainWallet =
|
|
304
|
+
export declare type ThorchainWallet = ThorchainToolboxType & {
|
|
179
305
|
transfer: (params: CoreTxParams) => Promise<string>;
|
|
180
306
|
deposit: (params: DepositParam) => Promise<string>;
|
|
181
307
|
};
|
|
@@ -185,11 +311,13 @@ export declare type UpgradeParams = {
|
|
|
185
311
|
recipient: string;
|
|
186
312
|
};
|
|
187
313
|
|
|
188
|
-
export declare type UTXOWallet<T extends typeof BCHToolbox | typeof BTCToolbox | typeof DOGEToolbox | typeof LTCToolbox> =
|
|
314
|
+
export declare type UTXOWallet<T extends typeof BCHToolbox | typeof BTCToolbox | typeof DOGEToolbox | typeof LTCToolbox> = ReturnType<T> & {
|
|
189
315
|
transfer: (prams: CoreTxParams) => Promise<string>;
|
|
190
316
|
};
|
|
191
317
|
|
|
192
|
-
export declare type Wallet =
|
|
318
|
+
export declare type Wallet = {
|
|
319
|
+
[key in Chain]?: ChainWallet<key>;
|
|
320
|
+
};
|
|
193
321
|
|
|
194
322
|
export declare type WalletMethods = {
|
|
195
323
|
[Chain.Arbitrum]: EVMWallet<typeof ARBToolbox> | null;
|
|
@@ -198,17 +326,24 @@ export declare type WalletMethods = {
|
|
|
198
326
|
[Chain.Binance]: CosmosBasedWallet<typeof BinanceToolbox> | null;
|
|
199
327
|
[Chain.BitcoinCash]: UTXOWallet<typeof BCHToolbox> | null;
|
|
200
328
|
[Chain.Bitcoin]: UTXOWallet<typeof BTCToolbox> | null;
|
|
329
|
+
[Chain.Chainflip]: SubstrateBasedWallet<typeof ChainflipToolbox> | null;
|
|
201
330
|
[Chain.Cosmos]: CosmosBasedWallet<typeof GaiaToolbox> | null;
|
|
331
|
+
[Chain.Dash]: UTXOWallet<typeof DASHToolbox> | null;
|
|
202
332
|
[Chain.Dogecoin]: UTXOWallet<typeof DOGEToolbox> | null;
|
|
203
333
|
[Chain.Ethereum]: EVMWallet<typeof ETHToolbox> | null;
|
|
204
334
|
[Chain.Kujira]: CosmosBasedWallet<typeof KujiraToolbox> | null;
|
|
205
335
|
[Chain.Litecoin]: UTXOWallet<typeof LTCToolbox> | null;
|
|
206
336
|
[Chain.Maya]: ThorchainWallet | null;
|
|
207
337
|
[Chain.Optimism]: EVMWallet<typeof OPToolbox> | null;
|
|
338
|
+
[Chain.Polkadot]: SubstrateBasedWallet<typeof PolkadotToolbox> | null;
|
|
208
339
|
[Chain.Polygon]: EVMWallet<typeof MATICToolbox> | null;
|
|
209
340
|
[Chain.THORChain]: ThorchainWallet | null;
|
|
210
341
|
};
|
|
211
342
|
|
|
343
|
+
export declare type Wallets = {
|
|
344
|
+
[K in Chain]?: ChainWallet<K>;
|
|
345
|
+
};
|
|
346
|
+
|
|
212
347
|
|
|
213
348
|
export * from "@swapkit/helpers";
|
|
214
349
|
export * from "@swapkit/types";
|