@enkryptcom/swap 0.0.3

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2022 kvhnuke <10602065+kvhnuke@users.noreply.github.com>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # @enkryptcom/swap
2
+
3
+ ## Swap library for Enkrypt
@@ -0,0 +1,214 @@
1
+ import EventEmitter from 'eventemitter3';
2
+ import { SignerType } from '@enkryptcom/types';
3
+ import { toBN } from 'web3-utils';
4
+ import Web3Eth from 'web3-eth';
5
+
6
+ declare enum SupportedNetworkName {
7
+ Ethereum = "ETH",
8
+ Binance = "BNB",
9
+ Matic = "MATIC",
10
+ Optimism = "OP",
11
+ Polkadot = "DOT",
12
+ Kusama = "KSM",
13
+ Bitcoin = "BTC",
14
+ EthereumClassic = "ETC",
15
+ Moonbeam = "GLMR",
16
+ Arbitrum = "ARB",
17
+ Gnosis = "GNO",
18
+ Avalanche = "AVAX",
19
+ Fantom = "FTM",
20
+ Klaytn = "KLAY",
21
+ Aurora = "AURORA"
22
+ }
23
+ declare enum NetworkType {
24
+ EVM = "evm",
25
+ Substrate = "substrate",
26
+ Bitcoin = "bitcoin"
27
+ }
28
+ type BN = ReturnType<typeof toBN>;
29
+ interface TokenType {
30
+ address: string;
31
+ symbol: string;
32
+ decimals: number;
33
+ name: string;
34
+ logoURI: string;
35
+ type: NetworkType;
36
+ rank?: number;
37
+ cgId?: string;
38
+ balance?: BN;
39
+ price?: number;
40
+ }
41
+ interface NetworkInfo {
42
+ id: SupportedNetworkName;
43
+ symbol: string;
44
+ decimals: number;
45
+ name: string;
46
+ logoURI: string;
47
+ rank: number;
48
+ cgId: string;
49
+ type: NetworkType;
50
+ signerType: SignerType[];
51
+ }
52
+ interface TokenNetworkType {
53
+ name: SupportedNetworkName | string;
54
+ isAddress: (addr: string) => Promise<boolean>;
55
+ }
56
+ interface TokenTypeTo extends TokenType {
57
+ networkInfo: TokenNetworkType;
58
+ }
59
+ interface FromTokenType {
60
+ top: TokenType[];
61
+ trending: TokenType[];
62
+ all: TokenType[];
63
+ }
64
+ interface ToTokenType {
65
+ top: Record<SupportedNetworkName, TokenTypeTo[]>;
66
+ trending: Record<SupportedNetworkName, TokenTypeTo[]>;
67
+ all: Record<SupportedNetworkName, TokenTypeTo[]>;
68
+ }
69
+ interface EvmOptions {
70
+ infiniteApproval: boolean;
71
+ }
72
+ declare enum WalletIdentifier {
73
+ enkrypt = "enkrypt",
74
+ mew = "mew"
75
+ }
76
+ type APIType = Web3Eth;
77
+ interface QuoteMetaOptions {
78
+ infiniteApproval: boolean;
79
+ walletIdentifier: WalletIdentifier;
80
+ slippage?: string;
81
+ changellyQuoteId?: string;
82
+ }
83
+ interface SwapOptions {
84
+ network: SupportedNetworkName;
85
+ api: APIType;
86
+ evmOptions?: EvmOptions;
87
+ walletIdentifier: WalletIdentifier;
88
+ }
89
+ declare enum ProviderName {
90
+ oneInch = "oneInch",
91
+ paraswap = "paraswap",
92
+ zerox = "zerox",
93
+ changelly = "changelly"
94
+ }
95
+ declare enum TransactionStatus {
96
+ pending = "pending",
97
+ failed = "failed",
98
+ success = "success"
99
+ }
100
+ interface getQuoteOptions {
101
+ fromAddress: string;
102
+ toAddress: string;
103
+ amount: BN;
104
+ fromToken: TokenType;
105
+ toToken: TokenTypeTo;
106
+ }
107
+ declare enum TransactionType {
108
+ evm = "evm",
109
+ generic = "generic"
110
+ }
111
+ interface EVMTransaction {
112
+ from: string;
113
+ gasLimit: string;
114
+ to: string;
115
+ value: string;
116
+ data: string;
117
+ type: TransactionType.evm;
118
+ }
119
+ interface GenericTransaction {
120
+ from: string;
121
+ to: string;
122
+ value: string;
123
+ type: TransactionType.generic;
124
+ }
125
+ type SwapTransaction = EVMTransaction | GenericTransaction;
126
+ interface MinMaxResponse {
127
+ minimumFrom: BN;
128
+ maximumFrom: BN;
129
+ minimumTo: BN;
130
+ maximumTo: BN;
131
+ }
132
+ interface SwapQuote {
133
+ options: getQuoteOptions;
134
+ meta: QuoteMetaOptions;
135
+ provider: ProviderName;
136
+ }
137
+ interface ProviderQuoteResponse {
138
+ toTokenAmount: BN;
139
+ fromTokenAmount: BN;
140
+ totalGaslimit: number;
141
+ provider: ProviderName;
142
+ quote: SwapQuote;
143
+ minMax: MinMaxResponse;
144
+ }
145
+ interface StatusOptions {
146
+ [key: string]: any;
147
+ transactionHashes: string[];
148
+ }
149
+ interface StatusOptionsResponse {
150
+ options: StatusOptions;
151
+ provider: ProviderName;
152
+ }
153
+ interface ProviderSwapResponse {
154
+ transactions: SwapTransaction[];
155
+ toTokenAmount: BN;
156
+ fromTokenAmount: BN;
157
+ provider: ProviderName;
158
+ slippage: string;
159
+ fee: number;
160
+ getStatusObject: (options: StatusOptions) => Promise<StatusOptionsResponse>;
161
+ }
162
+
163
+ declare const isSupportedNetwork: (networkName: SupportedNetworkName) => boolean;
164
+ declare const getSupportedNetworks: () => NetworkInfo[];
165
+ declare const getNetworkInfoByName: (networkName: SupportedNetworkName) => NetworkInfo;
166
+
167
+ declare const sortByRank: (x: {
168
+ rank?: number;
169
+ }, y: {
170
+ rank?: number;
171
+ }) => number;
172
+ declare const sortNativeToFront: (x: {
173
+ address: string;
174
+ }, y: {
175
+ address: string;
176
+ }) => 1 | -1 | 0;
177
+
178
+ declare class SwapToken {
179
+ token: TokenType;
180
+ constructor(token: TokenType);
181
+ setBalance(balance: BN): void;
182
+ getBalanceReadable(): string;
183
+ getBalanceRaw(): BN;
184
+ toReadable(amount: BN): string;
185
+ toRaw(amount: string): BN;
186
+ getFiatTotal(): number;
187
+ getFiatValue(): number;
188
+ getReadableToFiat(value: string): number;
189
+ getRawToFiat(value: BN): number;
190
+ }
191
+
192
+ declare class Swap extends EventEmitter {
193
+ network: SupportedNetworkName;
194
+ evmOptions: EvmOptions;
195
+ private api;
196
+ initPromise: Promise<void>;
197
+ private providerClasses;
198
+ private providers;
199
+ private tokenList;
200
+ private topTokenInfo;
201
+ private fromTokens;
202
+ private toTokens;
203
+ private walletId;
204
+ constructor(options: SwapOptions);
205
+ private init;
206
+ getFromTokens(): FromTokenType;
207
+ getToTokens(): ToTokenType;
208
+ getQuotes(options: getQuoteOptions): Promise<ProviderQuoteResponse[]>;
209
+ getSwap(quote: SwapQuote): Promise<ProviderSwapResponse | null>;
210
+ getStatus(options: StatusOptionsResponse): Promise<TransactionStatus | null>;
211
+ static networkNameToInfo(networkName: SupportedNetworkName): NetworkInfo;
212
+ }
213
+
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 };