@swapkit/core 1.0.0-rc.1 → 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.
Files changed (43) hide show
  1. package/dist/index.cjs +2 -2
  2. package/dist/index.cjs.map +1 -0
  3. package/dist/index.d.ts +163 -29
  4. package/dist/index.es.js +6502 -1061
  5. package/dist/index.es.js.map +1 -0
  6. package/package.json +23 -30
  7. package/src/__tests__/helpers.test.ts +79 -0
  8. package/src/aggregator/contracts/avaxGeneric.ts +50 -50
  9. package/src/aggregator/contracts/avaxWoofi.ts +80 -80
  10. package/src/aggregator/contracts/bscGeneric.ts +59 -59
  11. package/src/aggregator/contracts/ethGeneric.ts +50 -50
  12. package/src/aggregator/contracts/index.ts +30 -28
  13. package/src/aggregator/contracts/pancakeV2.ts +80 -80
  14. package/src/aggregator/contracts/pangolin.ts +65 -65
  15. package/src/aggregator/contracts/routers/index.ts +58 -0
  16. package/src/aggregator/contracts/routers/kyber.ts +402 -0
  17. package/src/aggregator/contracts/routers/oneinch.ts +2188 -0
  18. package/src/aggregator/contracts/routers/pancakeswap.ts +340 -0
  19. package/src/aggregator/contracts/routers/pangolin.ts +340 -0
  20. package/src/aggregator/contracts/routers/sushiswap.ts +340 -0
  21. package/src/aggregator/contracts/routers/traderJoe.ts +340 -0
  22. package/src/aggregator/contracts/routers/uniswapv2.ts +340 -0
  23. package/src/aggregator/contracts/routers/uniswapv3.ts +254 -0
  24. package/src/aggregator/contracts/routers/woofi.ts +171 -0
  25. package/src/aggregator/contracts/sushiswap.ts +65 -65
  26. package/src/aggregator/contracts/traderJoe.ts +65 -65
  27. package/src/aggregator/contracts/uniswapV2.ts +65 -65
  28. package/src/aggregator/contracts/uniswapV2Leg.ts +70 -70
  29. package/src/aggregator/contracts/uniswapV3_100.ts +70 -70
  30. package/src/aggregator/contracts/uniswapV3_10000.ts +70 -70
  31. package/src/aggregator/contracts/uniswapV3_3000.ts +70 -70
  32. package/src/aggregator/contracts/uniswapV3_500.ts +70 -70
  33. package/src/aggregator/getSwapParams.ts +12 -12
  34. package/src/client/index.ts +214 -651
  35. package/src/client/old.ts +837 -0
  36. package/src/{client → helpers}/explorerUrls.ts +10 -9
  37. package/src/{client → helpers}/thornode.ts +5 -5
  38. package/src/index.ts +6 -4
  39. package/src/types.ts +149 -0
  40. package/dist/index-9e36735e.cjs +0 -1
  41. package/dist/index-cf1865cd.js +0 -649
  42. package/src/client/__tests__/helpers.test.ts +0 -69
  43. package/src/client/types.ts +0 -101
package/dist/index.d.ts CHANGED
@@ -6,37 +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 type { FeeOption } from '@swapkit/types';
19
+ import { FeeOption } from '@swapkit/types';
15
20
  import type { GaiaToolbox } from '@swapkit/toolbox-cosmos';
21
+ import type { KujiraToolbox } from '@swapkit/toolbox-cosmos';
16
22
  import type { LTCToolbox } from '@swapkit/toolbox-utxo';
17
23
  import type { MATICToolbox } from '@swapkit/toolbox-evm';
18
24
  import type { OPToolbox } from '@swapkit/toolbox-evm';
19
- import type { QuoteRoute } from '@swapkit/api';
25
+ import type { PolkadotToolbox } from '@swapkit/toolbox-substrate';
26
+ import type { QuoteRoute } from '@swapkit/helpers';
20
27
  import type { SwapKitNumber } from '@swapkit/helpers';
21
28
  import type { ThorchainToolboxType } from '@swapkit/toolbox-cosmos';
22
29
  import type { ThornameRegisterParam } from '@swapkit/helpers';
23
- import type { WalletOption } from '@swapkit/types';
30
+ import { UTXOChain } from '@swapkit/types';
31
+ import { WalletOption } from '@swapkit/types';
24
32
 
25
33
  export declare type AddLiquidityTxns = {
26
34
  runeTx?: string;
27
35
  assetTx?: string;
28
36
  };
29
37
 
30
- declare type BaseWalletMethods = {
31
- getAddress: () => Promise<string> | string;
38
+ declare type ApisType = {
39
+ [key in UTXOChain]?: string | any;
40
+ } & {
41
+ [key in EVMChain]?: string | any;
42
+ } & {
43
+ [key in CosmosChain]?: string;
32
44
  };
33
45
 
34
- export declare type ChainWallet = {
46
+ declare type BaseSwapkitWalletConnectParams = {
47
+ chains: Chain[];
48
+ };
49
+
50
+ export declare type ChainWallet<T extends Chain> = WalletMethods[T] & {
51
+ chain: Chain;
35
52
  address: string;
36
53
  balance: AssetValue[];
37
54
  walletType: WalletOption;
38
55
  };
39
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
+
40
66
  export declare type CoreTxParams = {
41
67
  assetValue: AssetValue;
42
68
  recipient: string;
@@ -48,17 +74,68 @@ export declare type CoreTxParams = {
48
74
  expiration?: number;
49
75
  };
50
76
 
51
- export declare type CosmosBasedWallet<T extends typeof BinanceToolbox | typeof GaiaToolbox> = BaseWalletMethods & ReturnType<T> & {
77
+ export declare type CosmosBasedWallet<T extends typeof BinanceToolbox | typeof GaiaToolbox> = ReturnType<T> & {
52
78
  transfer: (params: CoreTxParams) => Promise<string>;
53
79
  };
54
80
 
55
- export declare type EVMWallet<T extends typeof AVAXToolbox | typeof BSCToolbox | typeof ETHToolbox | typeof OPToolbox> = BaseWalletMethods & ReturnType<T> & {
81
+ export declare type EVMWallet<T extends typeof AVAXToolbox | typeof BSCToolbox | typeof ETHToolbox | typeof OPToolbox> = ReturnType<T> & {
56
82
  transfer: (params: CoreTxParams) => Promise<string>;
57
83
  };
58
84
 
59
- export declare class SwapKitCore<T = ''> {
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 = ""> {
60
137
 
61
- connectedChains: Wallet;
138
+ connectedChains: OldWallet;
62
139
  connectedWallets: WalletMethods;
63
140
  readonly stagenet: boolean;
64
141
  constructor({ stagenet }?: {
@@ -68,9 +145,9 @@ export declare class SwapKitCore<T = ''> {
68
145
  getExplorerTxUrl: (chain: Chain, txHash: string) => string;
69
146
  getWallet: <T_1 extends Chain>(chain: Chain) => WalletMethods[T_1];
70
147
  getExplorerAddressUrl: (chain: Chain, address: string) => string;
71
- getBalance: (chain: Chain, refresh?: boolean) => Promise<AssetValue[]>;
72
- swap: ({ streamSwap, recipient, route, feeOptionKey }: SwapParams) => Promise<string>;
73
- 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<{
74
151
  address?: string | undefined;
75
152
  balance?: AssetValue[] | undefined;
76
153
  walletType?: WalletOption | undefined;
@@ -97,8 +174,7 @@ export declare class SwapKitCore<T = ''> {
97
174
  runeTx: string;
98
175
  assetTx: string;
99
176
  }>;
100
- addLiquidity: ({ poolIdentifier, runeAssetValue, assetValue, runeAddr, assetAddr, isPendingSymmAsset, mode, }: {
101
- poolIdentifier: string;
177
+ addLiquidity: ({ runeAssetValue, assetValue, runeAddr, assetAddr, isPendingSymmAsset, mode, }: {
102
178
  runeAssetValue: AssetValue;
103
179
  assetValue: AssetValue;
104
180
  isPendingSymmAsset?: boolean | undefined;
@@ -109,36 +185,42 @@ export declare class SwapKitCore<T = ''> {
109
185
  runeTx: string | undefined;
110
186
  assetTx: string | undefined;
111
187
  }>;
188
+ addLiquidityPart: ({ assetValue, poolAddress, address, symmetric, }: {
189
+ assetValue: AssetValue;
190
+ address?: string | undefined;
191
+ poolAddress: string;
192
+ symmetric: boolean;
193
+ }) => Promise<string>;
112
194
  withdraw: ({ memo, assetValue, percent, from, to, }: {
113
195
  memo?: string | undefined;
114
196
  assetValue: AssetValue;
115
197
  percent: number;
116
- from: 'sym' | 'rune' | 'asset';
117
- to: 'sym' | 'rune';
198
+ from: "sym" | "rune" | "asset";
199
+ to: "sym" | "rune" | "asset";
118
200
  }) => Promise<string>;
119
201
  savings: ({ assetValue, memo, percent, type, }: {
120
202
  assetValue: AssetValue;
121
203
  memo?: string | undefined;
122
204
  } & ({
123
- type: 'add';
205
+ type: "add";
124
206
  percent?: undefined;
125
207
  } | {
126
- type: 'withdraw';
208
+ type: "withdraw";
127
209
  percent: number;
128
210
  })) => Promise<string>;
129
211
  loan: ({ assetValue, memo, minAmount, type, }: {
130
212
  assetValue: AssetValue;
131
213
  memo?: string | undefined;
132
214
  minAmount: AssetValue;
133
- type: 'open' | 'close';
215
+ type: "open" | "close";
134
216
  }) => Promise<string>;
135
217
  nodeAction: ({ type, assetValue, address, }: {
136
218
  address: string;
137
219
  } & ({
138
- type: 'bond' | 'unbond';
220
+ type: "bond" | "unbond";
139
221
  assetValue: AssetValue;
140
222
  } | {
141
- type: 'leave';
223
+ type: "leave";
142
224
  assetValue?: undefined;
143
225
  })) => Promise<string>;
144
226
  registerThorname: ({ assetValue, ...param }: ThornameRegisterParam & {
@@ -159,22 +241,62 @@ export declare class SwapKitCore<T = ''> {
159
241
  connectXDEFI: (_chains: Chain[]) => Promise<void>;
160
242
  connectEVMWallet: (_chains: Chain[] | Chain, _wallet: EVMWalletOptions) => Promise<void>;
161
243
  connectWalletconnect: (_chains: Chain[], _options?: any) => Promise<void>;
244
+ connectKeepkey: (_chains: Chain[], _derivationPath: number[][]) => Promise<string>;
162
245
  connectKeystore: (_chains: Chain[], _phrase: string) => Promise<void>;
163
246
  connectLedger: (_chains: Chain, _derivationPath: number[]) => Promise<void>;
164
247
  connectTrezor: (_chains: Chain, _derivationPath: number[]) => Promise<void>;
165
- connectKeplr: () => Promise<void>;
248
+ connectKeplr: (_chain: Chain) => Promise<void>;
166
249
  connectOkx: (_chains: Chain[]) => Promise<void>;
167
250
  disconnectChain: (chain: Chain) => void;
168
251
  }
169
252
 
170
- export declare type SwapParams = {
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 = {
171
292
  recipient: string;
293
+ route: QuoteRoute | QuoteRouteV2;
294
+ feeOptionKey?: FeeOption;
295
+ quoteId?: string;
172
296
  streamSwap?: boolean;
173
- route: QuoteRoute;
174
- feeOptionKey: FeeOption;
175
297
  };
176
298
 
177
- export declare type ThorchainWallet = BaseWalletMethods & ThorchainToolboxType & {
299
+ export declare type ThorchainWallet = ThorchainToolboxType & {
178
300
  transfer: (params: CoreTxParams) => Promise<string>;
179
301
  deposit: (params: DepositParam) => Promise<string>;
180
302
  };
@@ -184,11 +306,15 @@ export declare type UpgradeParams = {
184
306
  recipient: string;
185
307
  };
186
308
 
187
- export declare type UTXOWallet<T extends typeof BCHToolbox | typeof BTCToolbox | typeof DOGEToolbox | typeof LTCToolbox> = BaseWalletMethods & ReturnType<T> & {
309
+ export declare type UTXOWallet<T extends typeof BCHToolbox | typeof BTCToolbox | typeof DOGEToolbox | typeof LTCToolbox> = ReturnType<T> & {
188
310
  transfer: (prams: CoreTxParams) => Promise<string>;
189
311
  };
190
312
 
191
- export declare type Wallet = Record<Chain, ChainWallet | null>;
313
+ export declare type Wallet = {
314
+ [key in Chain]?: ChainWallet<key>;
315
+ };
316
+
317
+ declare type WalletConnectParams = KeystoreWalletConnectParams;
192
318
 
193
319
  export declare type WalletMethods = {
194
320
  [Chain.Arbitrum]: EVMWallet<typeof ARBToolbox> | null;
@@ -197,16 +323,24 @@ export declare type WalletMethods = {
197
323
  [Chain.Binance]: CosmosBasedWallet<typeof BinanceToolbox> | null;
198
324
  [Chain.BitcoinCash]: UTXOWallet<typeof BCHToolbox> | null;
199
325
  [Chain.Bitcoin]: UTXOWallet<typeof BTCToolbox> | null;
326
+ [Chain.Chainflip]: SubstrateBasedWallet<typeof ChainflipToolbox> | null;
200
327
  [Chain.Cosmos]: CosmosBasedWallet<typeof GaiaToolbox> | null;
328
+ [Chain.Dash]: UTXOWallet<typeof DASHToolbox> | null;
201
329
  [Chain.Dogecoin]: UTXOWallet<typeof DOGEToolbox> | null;
202
330
  [Chain.Ethereum]: EVMWallet<typeof ETHToolbox> | null;
331
+ [Chain.Kujira]: CosmosBasedWallet<typeof KujiraToolbox> | null;
203
332
  [Chain.Litecoin]: UTXOWallet<typeof LTCToolbox> | null;
204
333
  [Chain.Maya]: ThorchainWallet | null;
205
334
  [Chain.Optimism]: EVMWallet<typeof OPToolbox> | null;
335
+ [Chain.Polkadot]: SubstrateBasedWallet<typeof PolkadotToolbox> | null;
206
336
  [Chain.Polygon]: EVMWallet<typeof MATICToolbox> | null;
207
337
  [Chain.THORChain]: ThorchainWallet | null;
208
338
  };
209
339
 
340
+ declare type Wallets = {
341
+ [K in Chain]?: ChainWallet<K>;
342
+ };
343
+
210
344
 
211
345
  export * from "@swapkit/helpers";
212
346
  export * from "@swapkit/types";