@enkryptcom/swap 0.0.4 → 0.0.6

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.
Binary file
Binary file
Binary file
Binary file
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@enkryptcom/swap",
3
- "version": "0.0.4",
3
+ "version": "0.0.6",
4
4
  "description": "Swap library for enkrypt",
5
5
  "type": "module",
6
- "main": "src/index.ts",
7
- "module": "src/index.ts",
6
+ "main": "dist/index.cjs",
7
+ "module": "dist/index.js",
8
8
  "publishConfig": {
9
9
  "main": "dist/index.cjs",
10
10
  "module": "dist/index.js",
@@ -22,39 +22,41 @@
22
22
  "node": ">=14.15.0"
23
23
  },
24
24
  "dependencies": {
25
- "@enkryptcom/types": "workspace:^",
26
- "@enkryptcom/utils": "workspace:^",
27
- "@solana/spl-token": "^0.4.13",
28
- "@solana/web3.js": "^1.98.2",
29
- "bignumber.js": "^9.3.0",
30
- "eventemitter3": "^5.0.1",
25
+ "@1inch/fusion-sdk": "^2.4.5",
26
+ "@1inch/limit-order-sdk": "^5.2.3",
27
+ "@enkryptcom/types": "^0.0.5",
28
+ "@enkryptcom/utils": "^0.0.5",
29
+ "@solana/spl-token": "^0.4.14",
30
+ "@solana/web3.js": "^1.98.4",
31
+ "bignumber.js": "^9.3.1",
32
+ "eventemitter3": "^5.0.4",
31
33
  "isomorphic-ws": "^5.0.0",
32
- "json-rpc-2.0": "^1.7.0",
33
- "lodash": "^4.17.21",
34
- "rango-sdk-basic": "^0.1.67",
34
+ "json-rpc-2.0": "^1.7.1",
35
+ "lodash": "^4.17.23",
36
+ "rango-sdk-basic": "^0.1.72",
35
37
  "reconnecting-websocket": "^4.4.0",
36
- "uuid": "^11.1.0",
38
+ "uuid": "^13.0.0",
37
39
  "web3-eth": "^1.10.4",
38
40
  "web3-utils": "^1.10.4",
39
- "ws": "^8.18.2"
41
+ "ws": "^8.19.0"
40
42
  },
41
43
  "devDependencies": {
42
- "@types/node": "^22.15.24",
43
- "@typescript-eslint/eslint-plugin": "^8.33.0",
44
- "@typescript-eslint/parser": "^8.33.0",
45
- "eslint": "^9.27.0",
44
+ "@types/node": "^22.19.7",
45
+ "@typescript-eslint/eslint-plugin": "^8.54.0",
46
+ "@typescript-eslint/parser": "^8.54.0",
47
+ "eslint": "^9.39.2",
46
48
  "eslint-config-airbnb-base": "^15.0.0",
47
- "eslint-config-prettier": "^10.1.5",
49
+ "eslint-config-prettier": "^10.1.8",
48
50
  "eslint-import-resolver-alias": "^1.1.2",
49
- "eslint-plugin-import": "^2.31.0",
51
+ "eslint-plugin-import": "^2.32.0",
50
52
  "eslint-plugin-module-resolver": "^1.5.0",
51
- "prettier": "^3.5.3",
53
+ "prettier": "^3.8.1",
52
54
  "ts-node": "^10.9.2",
53
55
  "tsconfig-paths": "^4.2.0",
54
- "tsup": "^8.5.0",
55
- "typescript": "^5.8.3",
56
- "typescript-eslint": "8.33.0",
57
- "vitest": "^3.1.4"
56
+ "tsup": "^8.5.1",
57
+ "typescript": "^5.9.3",
58
+ "typescript-eslint": "8.54.0",
59
+ "vitest": "^4.0.18"
58
60
  },
59
61
  "repository": {
60
62
  "type": "git",
@@ -62,5 +64,6 @@
62
64
  },
63
65
  "keywords": [],
64
66
  "author": "kvhnuke",
65
- "license": "MIT"
66
- }
67
+ "license": "MIT",
68
+ "types": "dist/index.d.ts"
69
+ }
package/src/index.ts DELETED
@@ -1,270 +0,0 @@
1
- import { merge } from "lodash";
2
- import EventEmitter from "eventemitter3";
3
- import type Web3Eth from "web3-eth";
4
- import type { Connection as Web3Solana } from "@solana/web3.js";
5
- import { TOKEN_LISTS, TOP_TOKEN_INFO_LIST } from "./configs";
6
- import OneInch from "./providers/oneInch";
7
- import Paraswap from "./providers/paraswap";
8
- import Changelly from "./providers/changelly";
9
- import ZeroX from "./providers/zerox";
10
- import Rango from "./providers/rango";
11
- import NetworkDetails, {
12
- isSupportedNetwork,
13
- getSupportedNetworks,
14
- getNetworkInfoByName,
15
- } from "./common/supportedNetworks";
16
- import type {
17
- APIType,
18
- EvmOptions,
19
- FromTokenType,
20
- getQuoteOptions,
21
- NetworkInfo,
22
- ProviderFromTokenResponse,
23
- ProviderQuoteResponse,
24
- ProviderSwapResponse,
25
- ProviderToTokenResponse,
26
- SwapOptions,
27
- SwapQuote,
28
- TokenType,
29
- TokenTypeTo,
30
- TopTokenInfo,
31
- ToTokenType,
32
- GenericTransaction,
33
- SolanaTransaction,
34
- EVMTransaction,
35
- StatusOptionsResponse,
36
- StatusOptions,
37
- ProviderClass,
38
- } from "./types";
39
- import {
40
- SupportedNetworkName,
41
- Events,
42
- WalletIdentifier,
43
- NetworkType,
44
- TransactionType,
45
- TransactionStatus,
46
- } from "./types";
47
- import { sortByRank, sortNativeToFront } from "./utils/common";
48
- import SwapToken from "./swapToken";
49
- import { Jupiter } from "./providers/jupiter";
50
-
51
- class Swap extends EventEmitter {
52
- network: SupportedNetworkName;
53
-
54
- evmOptions: EvmOptions;
55
-
56
- private api: APIType;
57
-
58
- initPromise: Promise<void>;
59
-
60
- private providers: ProviderClass[];
61
-
62
- private tokenList: FromTokenType;
63
-
64
- private topTokenInfo: TopTokenInfo;
65
-
66
- private fromTokens: FromTokenType;
67
-
68
- private toTokens: ToTokenType;
69
-
70
- private walletId: WalletIdentifier;
71
-
72
- constructor(options: SwapOptions) {
73
- super();
74
- this.network = options.network;
75
- this.evmOptions = options.evmOptions
76
- ? options.evmOptions
77
- : { infiniteApproval: true };
78
- this.api = options.api;
79
- this.walletId = options.walletIdentifier;
80
- this.topTokenInfo = {
81
- contractsToId: {},
82
- topTokens: {},
83
- trendingTokens: {},
84
- };
85
- this.tokenList = {
86
- all: [],
87
- top: [],
88
- trending: [],
89
- };
90
- this.toTokens = {
91
- all: {},
92
- top: {},
93
- trending: {},
94
- };
95
- this.fromTokens = {
96
- all: [],
97
- top: [],
98
- trending: [],
99
- };
100
- this.initPromise = this.init();
101
- }
102
-
103
- private async init() {
104
- if (TOKEN_LISTS[this.network]) {
105
- this.tokenList = await fetch(TOKEN_LISTS[this.network]).then((res) =>
106
- res.json(),
107
- );
108
- }
109
-
110
- this.topTokenInfo = await fetch(TOP_TOKEN_INFO_LIST).then((res) =>
111
- res.json(),
112
- );
113
-
114
- // TODO: use network type instead?
115
- switch (this.network) {
116
- case SupportedNetworkName.Solana:
117
- // Solana
118
- this.providers = [
119
- new Jupiter(this.api as Web3Solana, this.network),
120
- new Rango(this.api as Web3Solana, this.network),
121
- new Changelly(this.api, this.network),
122
- ];
123
- break;
124
- default:
125
- // EVM
126
- this.providers = [
127
- new OneInch(this.api as Web3Eth, this.network),
128
- new Paraswap(this.api as Web3Eth, this.network),
129
- new Changelly(this.api, this.network),
130
- new ZeroX(this.api as Web3Eth, this.network),
131
- new Rango(this.api as Web3Eth, this.network),
132
- ];
133
- break;
134
- }
135
-
136
- await Promise.all(
137
- this.providers.map((Provider) => Provider.init(this.tokenList.all)),
138
- );
139
- const allFromTokens: ProviderFromTokenResponse = {};
140
- [...this.providers].reverse().forEach((p) => {
141
- Object.assign(allFromTokens, p.getFromTokens());
142
- });
143
- this.fromTokens = {
144
- all: Object.values(allFromTokens).sort(sortNativeToFront),
145
- top: this.tokenList.top.filter((topt) => !!allFromTokens[topt.address]),
146
- trending: this.tokenList.trending.filter(
147
- (trendt) => !!allFromTokens[trendt.address],
148
- ),
149
- };
150
- const native = this.fromTokens.all.shift();
151
- this.fromTokens.all.sort(sortByRank);
152
- if (native) this.fromTokens.all.unshift(native);
153
- const allToTokens: ProviderToTokenResponse = {};
154
- [...this.providers].reverse().forEach((p) => {
155
- merge(allToTokens, p.getToTokens());
156
- });
157
- Object.keys(allToTokens).forEach((nName) => {
158
- const values = Object.values(allToTokens[nName]);
159
- values.sort(sortNativeToFront);
160
- const nativeTo = values.shift();
161
- values.sort(sortByRank);
162
- if (nativeTo) values.unshift(nativeTo);
163
- values.forEach((val: TokenTypeTo) => {
164
- if (val.cgId && this.topTokenInfo.topTokens[val.cgId]) {
165
- if (!this.toTokens.top[nName]) this.toTokens.top[nName] = [];
166
- this.toTokens.top[nName].push({
167
- ...val,
168
- rank: this.topTokenInfo.topTokens[val.cgId].rank,
169
- });
170
- }
171
- if (val.cgId && this.topTokenInfo.trendingTokens[val.cgId]) {
172
- if (!this.toTokens.trending[nName])
173
- this.toTokens.trending[nName] = [];
174
- this.toTokens.trending[nName].push({
175
- ...val,
176
- rank: this.topTokenInfo.trendingTokens[val.cgId],
177
- });
178
- }
179
- });
180
- if (this.toTokens.top[nName]) this.toTokens.top[nName].sort(sortByRank);
181
- if (this.toTokens.trending[nName])
182
- this.toTokens.trending[nName].sort(sortByRank);
183
- this.toTokens.all[nName] = values;
184
- });
185
- }
186
-
187
- getFromTokens() {
188
- return this.fromTokens;
189
- }
190
-
191
- getToTokens() {
192
- return this.toTokens;
193
- }
194
-
195
- /**
196
- * Request a quote from each provider
197
- *
198
- * Only providers that support the network will respond
199
- */
200
- async getQuotes(
201
- options: getQuoteOptions,
202
- context?: { signal?: AbortSignal },
203
- ): Promise<ProviderQuoteResponse[]> {
204
- const response = await Promise.all(
205
- this.providers.map((provider) =>
206
- provider
207
- .getQuote(
208
- options,
209
- {
210
- infiniteApproval: this.evmOptions.infiniteApproval,
211
- walletIdentifier: this.walletId,
212
- },
213
- context,
214
- )
215
- .then((res) => {
216
- if (!res) return res;
217
- this.emit(Events.QuoteUpdate, res.toTokenAmount);
218
- return res;
219
- }),
220
- ),
221
- );
222
- // Sort by the dest token amount i.e. best offer first
223
- return response
224
- .filter((res) => res !== null)
225
- .sort((a, b) => (b.toTokenAmount.gt(a.toTokenAmount) ? 1 : -1));
226
- }
227
-
228
- getSwap(
229
- quote: SwapQuote,
230
- context?: { signal?: AbortSignal },
231
- ): Promise<ProviderSwapResponse | null> {
232
- const provider = this.providers.find((p) => p.name === quote.provider);
233
- return provider.getSwap(quote, context);
234
- }
235
-
236
- getStatus(options: StatusOptionsResponse): Promise<TransactionStatus | null> {
237
- const provider = this.providers.find((p) => p.name === options.provider);
238
- return provider.getStatus(options.options);
239
- }
240
-
241
- static networkNameToInfo(networkName: SupportedNetworkName): NetworkInfo {
242
- return NetworkDetails[networkName];
243
- }
244
- }
245
-
246
- export {
247
- SwapToken,
248
- isSupportedNetwork,
249
- getSupportedNetworks,
250
- TokenType,
251
- TokenTypeTo,
252
- WalletIdentifier,
253
- SupportedNetworkName,
254
- getNetworkInfoByName,
255
- sortByRank,
256
- sortNativeToFront,
257
- NetworkInfo,
258
- ProviderQuoteResponse,
259
- ProviderSwapResponse,
260
- NetworkType,
261
- GenericTransaction,
262
- SolanaTransaction,
263
- EVMTransaction,
264
- TransactionType,
265
- TransactionStatus,
266
- StatusOptionsResponse,
267
- StatusOptions,
268
- };
269
-
270
- export default Swap;