@enkryptcom/swap 0.0.3 → 0.0.4
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 +6322 -0
- package/dist/index.d.cts +251 -0
- package/dist/index.d.ts +53 -16
- package/dist/index.js +4948 -854
- package/package.json +36 -32
- package/src/index.ts +270 -0
- package/dist/index.mjs +0 -1337
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
import EventEmitter from 'eventemitter3';
|
|
2
|
+
import { SignerType } from '@enkryptcom/types';
|
|
3
|
+
import { toBN } from 'web3-utils';
|
|
4
|
+
import Web3Eth from 'web3-eth';
|
|
5
|
+
import { Connection } from '@solana/web3.js';
|
|
6
|
+
|
|
7
|
+
declare enum SupportedNetworkName {
|
|
8
|
+
Ethereum = "ETH",
|
|
9
|
+
Binance = "BNB",
|
|
10
|
+
Litecoin = "LTC",
|
|
11
|
+
Dogecoin = "DOGE",
|
|
12
|
+
Matic = "MATIC",
|
|
13
|
+
Optimism = "OP",
|
|
14
|
+
Polkadot = "DOT",
|
|
15
|
+
Kusama = "KSM",
|
|
16
|
+
Bitcoin = "BTC",
|
|
17
|
+
EthereumClassic = "ETC",
|
|
18
|
+
Moonbeam = "GLMR",
|
|
19
|
+
Arbitrum = "ARB",
|
|
20
|
+
Gnosis = "GNO",
|
|
21
|
+
Avalanche = "AVAX",
|
|
22
|
+
Fantom = "FTM",
|
|
23
|
+
Kaia = "KAIA",
|
|
24
|
+
Aurora = "AURORA",
|
|
25
|
+
Zksync = "zkSync",
|
|
26
|
+
Base = "BASE",
|
|
27
|
+
MaticZK = "MATICZK",
|
|
28
|
+
Blast = "blast",
|
|
29
|
+
Telos = "TLOS",
|
|
30
|
+
Rootstock = "Rootstock",
|
|
31
|
+
Solana = "SOLANA"
|
|
32
|
+
}
|
|
33
|
+
declare enum NetworkType {
|
|
34
|
+
EVM = "evm",
|
|
35
|
+
Substrate = "substrate",
|
|
36
|
+
Bitcoin = "bitcoin",
|
|
37
|
+
Solana = "solana"
|
|
38
|
+
}
|
|
39
|
+
type BN = ReturnType<typeof toBN>;
|
|
40
|
+
interface TokenType {
|
|
41
|
+
address: string;
|
|
42
|
+
symbol: string;
|
|
43
|
+
decimals: number;
|
|
44
|
+
name: string;
|
|
45
|
+
logoURI: string;
|
|
46
|
+
type: NetworkType;
|
|
47
|
+
rank?: number;
|
|
48
|
+
cgId?: string;
|
|
49
|
+
balance?: BN;
|
|
50
|
+
price?: number;
|
|
51
|
+
}
|
|
52
|
+
interface NetworkInfo {
|
|
53
|
+
id: SupportedNetworkName;
|
|
54
|
+
symbol: string;
|
|
55
|
+
decimals: number;
|
|
56
|
+
name: string;
|
|
57
|
+
logoURI: string;
|
|
58
|
+
rank: number;
|
|
59
|
+
cgId: string;
|
|
60
|
+
type: NetworkType;
|
|
61
|
+
signerType: SignerType[];
|
|
62
|
+
}
|
|
63
|
+
interface TokenNetworkType {
|
|
64
|
+
name: SupportedNetworkName | string;
|
|
65
|
+
isAddress: (addr: string) => Promise<boolean>;
|
|
66
|
+
}
|
|
67
|
+
interface TokenTypeTo extends TokenType {
|
|
68
|
+
networkInfo: TokenNetworkType;
|
|
69
|
+
}
|
|
70
|
+
interface FromTokenType {
|
|
71
|
+
top: TokenType[];
|
|
72
|
+
trending: TokenType[];
|
|
73
|
+
all: TokenType[];
|
|
74
|
+
}
|
|
75
|
+
interface ToTokenType {
|
|
76
|
+
top: Record<SupportedNetworkName, TokenTypeTo[]> | Record<string, never>;
|
|
77
|
+
trending: Record<SupportedNetworkName, TokenTypeTo[]> | Record<string, never>;
|
|
78
|
+
all: Record<SupportedNetworkName, TokenTypeTo[]> | Record<string, never>;
|
|
79
|
+
}
|
|
80
|
+
interface EvmOptions {
|
|
81
|
+
infiniteApproval: boolean;
|
|
82
|
+
}
|
|
83
|
+
declare enum WalletIdentifier {
|
|
84
|
+
enkrypt = "enkrypt",
|
|
85
|
+
mew = "mew"
|
|
86
|
+
}
|
|
87
|
+
type APIType = Web3Eth | Connection;
|
|
88
|
+
interface QuoteMetaOptions {
|
|
89
|
+
infiniteApproval: boolean;
|
|
90
|
+
walletIdentifier: WalletIdentifier;
|
|
91
|
+
slippage?: string;
|
|
92
|
+
changellyQuoteId?: string;
|
|
93
|
+
changellynetworkFee?: BN;
|
|
94
|
+
priceRoute?: unknown;
|
|
95
|
+
}
|
|
96
|
+
interface SwapOptions {
|
|
97
|
+
network: SupportedNetworkName;
|
|
98
|
+
api: APIType;
|
|
99
|
+
evmOptions?: EvmOptions;
|
|
100
|
+
walletIdentifier: WalletIdentifier;
|
|
101
|
+
}
|
|
102
|
+
declare enum ProviderName {
|
|
103
|
+
oneInch = "oneInch",
|
|
104
|
+
paraswap = "paraswap",
|
|
105
|
+
zerox = "zerox",
|
|
106
|
+
changelly = "changelly",
|
|
107
|
+
rango = "rango",
|
|
108
|
+
jupiter = "jupiter"
|
|
109
|
+
}
|
|
110
|
+
declare enum TransactionStatus {
|
|
111
|
+
pending = "pending",
|
|
112
|
+
failed = "failed",
|
|
113
|
+
success = "success",
|
|
114
|
+
dropped = "dropped"
|
|
115
|
+
}
|
|
116
|
+
interface getQuoteOptions {
|
|
117
|
+
fromAddress: string;
|
|
118
|
+
toAddress: string;
|
|
119
|
+
amount: BN;
|
|
120
|
+
fromToken: TokenType;
|
|
121
|
+
toToken: TokenTypeTo;
|
|
122
|
+
}
|
|
123
|
+
declare enum TransactionType {
|
|
124
|
+
evm = "evm",
|
|
125
|
+
generic = "generic",
|
|
126
|
+
solana = "solana"
|
|
127
|
+
}
|
|
128
|
+
interface EVMTransaction {
|
|
129
|
+
from: string;
|
|
130
|
+
gasLimit: string;
|
|
131
|
+
to: string;
|
|
132
|
+
value: string;
|
|
133
|
+
data: string;
|
|
134
|
+
type: TransactionType.evm;
|
|
135
|
+
}
|
|
136
|
+
interface SolanaTransaction {
|
|
137
|
+
from: string;
|
|
138
|
+
to: string;
|
|
139
|
+
kind: "legacy" | "versioned";
|
|
140
|
+
serialized: string;
|
|
141
|
+
type: TransactionType.solana;
|
|
142
|
+
thirdPartySignatures: {
|
|
143
|
+
pubkey: string;
|
|
144
|
+
signature: number[];
|
|
145
|
+
}[];
|
|
146
|
+
}
|
|
147
|
+
interface GenericTransaction {
|
|
148
|
+
from: string;
|
|
149
|
+
to: string;
|
|
150
|
+
value: string;
|
|
151
|
+
type: TransactionType.generic;
|
|
152
|
+
}
|
|
153
|
+
type SwapTransaction = EVMTransaction | GenericTransaction | SolanaTransaction;
|
|
154
|
+
interface MinMaxResponse {
|
|
155
|
+
minimumFrom: BN;
|
|
156
|
+
maximumFrom: BN;
|
|
157
|
+
minimumTo: BN;
|
|
158
|
+
maximumTo: BN;
|
|
159
|
+
}
|
|
160
|
+
interface SwapQuote {
|
|
161
|
+
options: getQuoteOptions;
|
|
162
|
+
meta: QuoteMetaOptions;
|
|
163
|
+
provider: ProviderName;
|
|
164
|
+
}
|
|
165
|
+
interface ProviderQuoteResponse {
|
|
166
|
+
toTokenAmount: BN;
|
|
167
|
+
fromTokenAmount: BN;
|
|
168
|
+
totalGaslimit: number;
|
|
169
|
+
additionalNativeFees: BN;
|
|
170
|
+
provider: ProviderName;
|
|
171
|
+
quote: SwapQuote;
|
|
172
|
+
minMax: MinMaxResponse;
|
|
173
|
+
}
|
|
174
|
+
type StatusOptionTransaction = {
|
|
175
|
+
hash: string;
|
|
176
|
+
sentAt: number;
|
|
177
|
+
};
|
|
178
|
+
interface StatusOptions {
|
|
179
|
+
[key: string]: any;
|
|
180
|
+
transactions: StatusOptionTransaction[];
|
|
181
|
+
}
|
|
182
|
+
interface StatusOptionsResponse {
|
|
183
|
+
options: StatusOptions;
|
|
184
|
+
provider: ProviderName;
|
|
185
|
+
}
|
|
186
|
+
interface ProviderSwapResponse {
|
|
187
|
+
transactions: SwapTransaction[];
|
|
188
|
+
toTokenAmount: BN;
|
|
189
|
+
fromTokenAmount: BN;
|
|
190
|
+
additionalNativeFees: BN;
|
|
191
|
+
provider: ProviderName;
|
|
192
|
+
slippage: string;
|
|
193
|
+
fee: number;
|
|
194
|
+
getStatusObject: (options: StatusOptions) => Promise<StatusOptionsResponse>;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
declare const isSupportedNetwork: (networkName: SupportedNetworkName) => boolean;
|
|
198
|
+
declare const getSupportedNetworks: () => NetworkInfo[];
|
|
199
|
+
declare const getNetworkInfoByName: (networkName: SupportedNetworkName) => NetworkInfo;
|
|
200
|
+
|
|
201
|
+
declare const sortByRank: (x: {
|
|
202
|
+
rank?: number;
|
|
203
|
+
}, y: {
|
|
204
|
+
rank?: number;
|
|
205
|
+
}) => number;
|
|
206
|
+
declare const sortNativeToFront: (x: {
|
|
207
|
+
address: string;
|
|
208
|
+
}, y: {
|
|
209
|
+
address: string;
|
|
210
|
+
}) => 1 | -1 | 0;
|
|
211
|
+
|
|
212
|
+
declare class SwapToken {
|
|
213
|
+
token: TokenType;
|
|
214
|
+
constructor(token: TokenType);
|
|
215
|
+
setBalance(balance: BN): void;
|
|
216
|
+
getBalanceReadable(): string;
|
|
217
|
+
getBalanceRaw(): BN;
|
|
218
|
+
toReadable(amount: BN): string;
|
|
219
|
+
toRaw(amount: string): BN;
|
|
220
|
+
getFiatTotal(): number;
|
|
221
|
+
getFiatValue(): number;
|
|
222
|
+
getReadableToFiat(value: string): number;
|
|
223
|
+
getRawToFiat(value: BN): number;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
declare class Swap extends EventEmitter {
|
|
227
|
+
network: SupportedNetworkName;
|
|
228
|
+
evmOptions: EvmOptions;
|
|
229
|
+
private api;
|
|
230
|
+
initPromise: Promise<void>;
|
|
231
|
+
private providers;
|
|
232
|
+
private tokenList;
|
|
233
|
+
private topTokenInfo;
|
|
234
|
+
private fromTokens;
|
|
235
|
+
private toTokens;
|
|
236
|
+
private walletId;
|
|
237
|
+
constructor(options: SwapOptions);
|
|
238
|
+
private init;
|
|
239
|
+
getFromTokens(): FromTokenType;
|
|
240
|
+
getToTokens(): ToTokenType;
|
|
241
|
+
getQuotes(options: getQuoteOptions, context?: {
|
|
242
|
+
signal?: AbortSignal;
|
|
243
|
+
}): Promise<ProviderQuoteResponse[]>;
|
|
244
|
+
getSwap(quote: SwapQuote, context?: {
|
|
245
|
+
signal?: AbortSignal;
|
|
246
|
+
}): Promise<ProviderSwapResponse | null>;
|
|
247
|
+
getStatus(options: StatusOptionsResponse): Promise<TransactionStatus | null>;
|
|
248
|
+
static networkNameToInfo(networkName: SupportedNetworkName): NetworkInfo;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
export { type EVMTransaction, type GenericTransaction, type NetworkInfo, NetworkType, type ProviderQuoteResponse, type ProviderSwapResponse, type SolanaTransaction, type StatusOptions, type StatusOptionsResponse, SupportedNetworkName, SwapToken, type TokenType, type TokenTypeTo, TransactionStatus, TransactionType, WalletIdentifier, Swap as default, getNetworkInfoByName, getSupportedNetworks, isSupportedNetwork, sortByRank, sortNativeToFront };
|
package/dist/index.d.ts
CHANGED
|
@@ -2,10 +2,13 @@ import EventEmitter from 'eventemitter3';
|
|
|
2
2
|
import { SignerType } from '@enkryptcom/types';
|
|
3
3
|
import { toBN } from 'web3-utils';
|
|
4
4
|
import Web3Eth from 'web3-eth';
|
|
5
|
+
import { Connection } from '@solana/web3.js';
|
|
5
6
|
|
|
6
7
|
declare enum SupportedNetworkName {
|
|
7
8
|
Ethereum = "ETH",
|
|
8
9
|
Binance = "BNB",
|
|
10
|
+
Litecoin = "LTC",
|
|
11
|
+
Dogecoin = "DOGE",
|
|
9
12
|
Matic = "MATIC",
|
|
10
13
|
Optimism = "OP",
|
|
11
14
|
Polkadot = "DOT",
|
|
@@ -17,13 +20,21 @@ declare enum SupportedNetworkName {
|
|
|
17
20
|
Gnosis = "GNO",
|
|
18
21
|
Avalanche = "AVAX",
|
|
19
22
|
Fantom = "FTM",
|
|
20
|
-
|
|
21
|
-
Aurora = "AURORA"
|
|
23
|
+
Kaia = "KAIA",
|
|
24
|
+
Aurora = "AURORA",
|
|
25
|
+
Zksync = "zkSync",
|
|
26
|
+
Base = "BASE",
|
|
27
|
+
MaticZK = "MATICZK",
|
|
28
|
+
Blast = "blast",
|
|
29
|
+
Telos = "TLOS",
|
|
30
|
+
Rootstock = "Rootstock",
|
|
31
|
+
Solana = "SOLANA"
|
|
22
32
|
}
|
|
23
33
|
declare enum NetworkType {
|
|
24
34
|
EVM = "evm",
|
|
25
35
|
Substrate = "substrate",
|
|
26
|
-
Bitcoin = "bitcoin"
|
|
36
|
+
Bitcoin = "bitcoin",
|
|
37
|
+
Solana = "solana"
|
|
27
38
|
}
|
|
28
39
|
type BN = ReturnType<typeof toBN>;
|
|
29
40
|
interface TokenType {
|
|
@@ -62,9 +73,9 @@ interface FromTokenType {
|
|
|
62
73
|
all: TokenType[];
|
|
63
74
|
}
|
|
64
75
|
interface ToTokenType {
|
|
65
|
-
top: Record<SupportedNetworkName, TokenTypeTo[]>;
|
|
66
|
-
trending: Record<SupportedNetworkName, TokenTypeTo[]>;
|
|
67
|
-
all: Record<SupportedNetworkName, TokenTypeTo[]>;
|
|
76
|
+
top: Record<SupportedNetworkName, TokenTypeTo[]> | Record<string, never>;
|
|
77
|
+
trending: Record<SupportedNetworkName, TokenTypeTo[]> | Record<string, never>;
|
|
78
|
+
all: Record<SupportedNetworkName, TokenTypeTo[]> | Record<string, never>;
|
|
68
79
|
}
|
|
69
80
|
interface EvmOptions {
|
|
70
81
|
infiniteApproval: boolean;
|
|
@@ -73,12 +84,14 @@ declare enum WalletIdentifier {
|
|
|
73
84
|
enkrypt = "enkrypt",
|
|
74
85
|
mew = "mew"
|
|
75
86
|
}
|
|
76
|
-
type APIType = Web3Eth;
|
|
87
|
+
type APIType = Web3Eth | Connection;
|
|
77
88
|
interface QuoteMetaOptions {
|
|
78
89
|
infiniteApproval: boolean;
|
|
79
90
|
walletIdentifier: WalletIdentifier;
|
|
80
91
|
slippage?: string;
|
|
81
92
|
changellyQuoteId?: string;
|
|
93
|
+
changellynetworkFee?: BN;
|
|
94
|
+
priceRoute?: unknown;
|
|
82
95
|
}
|
|
83
96
|
interface SwapOptions {
|
|
84
97
|
network: SupportedNetworkName;
|
|
@@ -90,12 +103,15 @@ declare enum ProviderName {
|
|
|
90
103
|
oneInch = "oneInch",
|
|
91
104
|
paraswap = "paraswap",
|
|
92
105
|
zerox = "zerox",
|
|
93
|
-
changelly = "changelly"
|
|
106
|
+
changelly = "changelly",
|
|
107
|
+
rango = "rango",
|
|
108
|
+
jupiter = "jupiter"
|
|
94
109
|
}
|
|
95
110
|
declare enum TransactionStatus {
|
|
96
111
|
pending = "pending",
|
|
97
112
|
failed = "failed",
|
|
98
|
-
success = "success"
|
|
113
|
+
success = "success",
|
|
114
|
+
dropped = "dropped"
|
|
99
115
|
}
|
|
100
116
|
interface getQuoteOptions {
|
|
101
117
|
fromAddress: string;
|
|
@@ -106,7 +122,8 @@ interface getQuoteOptions {
|
|
|
106
122
|
}
|
|
107
123
|
declare enum TransactionType {
|
|
108
124
|
evm = "evm",
|
|
109
|
-
generic = "generic"
|
|
125
|
+
generic = "generic",
|
|
126
|
+
solana = "solana"
|
|
110
127
|
}
|
|
111
128
|
interface EVMTransaction {
|
|
112
129
|
from: string;
|
|
@@ -116,13 +133,24 @@ interface EVMTransaction {
|
|
|
116
133
|
data: string;
|
|
117
134
|
type: TransactionType.evm;
|
|
118
135
|
}
|
|
136
|
+
interface SolanaTransaction {
|
|
137
|
+
from: string;
|
|
138
|
+
to: string;
|
|
139
|
+
kind: "legacy" | "versioned";
|
|
140
|
+
serialized: string;
|
|
141
|
+
type: TransactionType.solana;
|
|
142
|
+
thirdPartySignatures: {
|
|
143
|
+
pubkey: string;
|
|
144
|
+
signature: number[];
|
|
145
|
+
}[];
|
|
146
|
+
}
|
|
119
147
|
interface GenericTransaction {
|
|
120
148
|
from: string;
|
|
121
149
|
to: string;
|
|
122
150
|
value: string;
|
|
123
151
|
type: TransactionType.generic;
|
|
124
152
|
}
|
|
125
|
-
type SwapTransaction = EVMTransaction | GenericTransaction;
|
|
153
|
+
type SwapTransaction = EVMTransaction | GenericTransaction | SolanaTransaction;
|
|
126
154
|
interface MinMaxResponse {
|
|
127
155
|
minimumFrom: BN;
|
|
128
156
|
maximumFrom: BN;
|
|
@@ -138,13 +166,18 @@ interface ProviderQuoteResponse {
|
|
|
138
166
|
toTokenAmount: BN;
|
|
139
167
|
fromTokenAmount: BN;
|
|
140
168
|
totalGaslimit: number;
|
|
169
|
+
additionalNativeFees: BN;
|
|
141
170
|
provider: ProviderName;
|
|
142
171
|
quote: SwapQuote;
|
|
143
172
|
minMax: MinMaxResponse;
|
|
144
173
|
}
|
|
174
|
+
type StatusOptionTransaction = {
|
|
175
|
+
hash: string;
|
|
176
|
+
sentAt: number;
|
|
177
|
+
};
|
|
145
178
|
interface StatusOptions {
|
|
146
179
|
[key: string]: any;
|
|
147
|
-
|
|
180
|
+
transactions: StatusOptionTransaction[];
|
|
148
181
|
}
|
|
149
182
|
interface StatusOptionsResponse {
|
|
150
183
|
options: StatusOptions;
|
|
@@ -154,6 +187,7 @@ interface ProviderSwapResponse {
|
|
|
154
187
|
transactions: SwapTransaction[];
|
|
155
188
|
toTokenAmount: BN;
|
|
156
189
|
fromTokenAmount: BN;
|
|
190
|
+
additionalNativeFees: BN;
|
|
157
191
|
provider: ProviderName;
|
|
158
192
|
slippage: string;
|
|
159
193
|
fee: number;
|
|
@@ -194,7 +228,6 @@ declare class Swap extends EventEmitter {
|
|
|
194
228
|
evmOptions: EvmOptions;
|
|
195
229
|
private api;
|
|
196
230
|
initPromise: Promise<void>;
|
|
197
|
-
private providerClasses;
|
|
198
231
|
private providers;
|
|
199
232
|
private tokenList;
|
|
200
233
|
private topTokenInfo;
|
|
@@ -205,10 +238,14 @@ declare class Swap extends EventEmitter {
|
|
|
205
238
|
private init;
|
|
206
239
|
getFromTokens(): FromTokenType;
|
|
207
240
|
getToTokens(): ToTokenType;
|
|
208
|
-
getQuotes(options: getQuoteOptions
|
|
209
|
-
|
|
241
|
+
getQuotes(options: getQuoteOptions, context?: {
|
|
242
|
+
signal?: AbortSignal;
|
|
243
|
+
}): Promise<ProviderQuoteResponse[]>;
|
|
244
|
+
getSwap(quote: SwapQuote, context?: {
|
|
245
|
+
signal?: AbortSignal;
|
|
246
|
+
}): Promise<ProviderSwapResponse | null>;
|
|
210
247
|
getStatus(options: StatusOptionsResponse): Promise<TransactionStatus | null>;
|
|
211
248
|
static networkNameToInfo(networkName: SupportedNetworkName): NetworkInfo;
|
|
212
249
|
}
|
|
213
250
|
|
|
214
|
-
export { EVMTransaction, GenericTransaction, NetworkInfo, NetworkType, ProviderQuoteResponse, ProviderSwapResponse, StatusOptions, StatusOptionsResponse, SupportedNetworkName, SwapToken, TokenType, TokenTypeTo, TransactionStatus, TransactionType, WalletIdentifier, Swap as default, getNetworkInfoByName, getSupportedNetworks, isSupportedNetwork, sortByRank, sortNativeToFront };
|
|
251
|
+
export { type EVMTransaction, type GenericTransaction, type NetworkInfo, NetworkType, type ProviderQuoteResponse, type ProviderSwapResponse, type SolanaTransaction, type StatusOptions, type StatusOptionsResponse, SupportedNetworkName, SwapToken, type TokenType, type TokenTypeTo, TransactionStatus, TransactionType, WalletIdentifier, Swap as default, getNetworkInfoByName, getSupportedNetworks, isSupportedNetwork, sortByRank, sortNativeToFront };
|