@etcswapv2/sdk-legacy 1.0.0

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.mjs ADDED
@@ -0,0 +1,570 @@
1
+ // src/index.ts
2
+ var ChainId = /* @__PURE__ */ ((ChainId2) => {
3
+ ChainId2[ChainId2["MAINNET"] = 1] = "MAINNET";
4
+ ChainId2[ChainId2["ROPSTEN"] = 3] = "ROPSTEN";
5
+ ChainId2[ChainId2["RINKEBY"] = 4] = "RINKEBY";
6
+ ChainId2[ChainId2["G\xD6RLI"] = 5] = "G\xD6RLI";
7
+ ChainId2[ChainId2["KOVAN"] = 42] = "KOVAN";
8
+ ChainId2[ChainId2["CLASSIC"] = 61] = "CLASSIC";
9
+ ChainId2[ChainId2["MORDOR"] = 63] = "MORDOR";
10
+ return ChainId2;
11
+ })(ChainId || {});
12
+ var SUPPORTED_CHAINS = [61 /* CLASSIC */, 63 /* MORDOR */];
13
+ var Ether = class _Ether {
14
+ constructor() {
15
+ this.decimals = 18;
16
+ this.symbol = "ETC";
17
+ this.name = "Ether";
18
+ }
19
+ static get Instance() {
20
+ return this._instance || (this._instance = new _Ether());
21
+ }
22
+ };
23
+ var ETHER = Ether.Instance;
24
+ var Token = class {
25
+ constructor(chainId, address, decimals, symbol, name) {
26
+ this.chainId = chainId;
27
+ this.address = address.toLowerCase();
28
+ this.decimals = decimals;
29
+ this.symbol = symbol;
30
+ this.name = name;
31
+ }
32
+ equals(other) {
33
+ return this.chainId === other.chainId && this.address === other.address;
34
+ }
35
+ sortsBefore(other) {
36
+ return this.address.toLowerCase() < other.address.toLowerCase();
37
+ }
38
+ };
39
+ var WETC = {
40
+ [61 /* CLASSIC */]: new Token(
41
+ 61 /* CLASSIC */,
42
+ "0x1953cab0E5bFa6D4a9BaD6E05fD46C1CC6527a5a",
43
+ 18,
44
+ "WETC",
45
+ "Wrapped Ether"
46
+ ),
47
+ [63 /* MORDOR */]: new Token(
48
+ 63 /* MORDOR */,
49
+ "0x1953cab0E5bFa6D4a9BaD6E05fD46C1CC6527a5a",
50
+ 18,
51
+ "WETC",
52
+ "Wrapped Ether"
53
+ )
54
+ };
55
+ var WETH = WETC;
56
+ var Fraction = class _Fraction {
57
+ constructor(numerator, denominator = 1n) {
58
+ this.numerator = BigInt(numerator);
59
+ this.denominator = BigInt(denominator);
60
+ }
61
+ get quotient() {
62
+ return this.numerator / this.denominator;
63
+ }
64
+ invert() {
65
+ return new _Fraction(this.denominator, this.numerator);
66
+ }
67
+ add(other) {
68
+ const otherFraction = other instanceof _Fraction ? other : new _Fraction(other);
69
+ if (this.denominator === otherFraction.denominator) {
70
+ return new _Fraction(this.numerator + otherFraction.numerator, this.denominator);
71
+ }
72
+ return new _Fraction(
73
+ this.numerator * otherFraction.denominator + otherFraction.numerator * this.denominator,
74
+ this.denominator * otherFraction.denominator
75
+ );
76
+ }
77
+ subtract(other) {
78
+ const otherFraction = other instanceof _Fraction ? other : new _Fraction(other);
79
+ if (this.denominator === otherFraction.denominator) {
80
+ return new _Fraction(this.numerator - otherFraction.numerator, this.denominator);
81
+ }
82
+ return new _Fraction(
83
+ this.numerator * otherFraction.denominator - otherFraction.numerator * this.denominator,
84
+ this.denominator * otherFraction.denominator
85
+ );
86
+ }
87
+ multiply(other) {
88
+ const otherFraction = other instanceof _Fraction ? other : new _Fraction(other);
89
+ return new _Fraction(
90
+ this.numerator * otherFraction.numerator,
91
+ this.denominator * otherFraction.denominator
92
+ );
93
+ }
94
+ divide(other) {
95
+ const otherFraction = other instanceof _Fraction ? other : new _Fraction(other);
96
+ return new _Fraction(
97
+ this.numerator * otherFraction.denominator,
98
+ this.denominator * otherFraction.numerator
99
+ );
100
+ }
101
+ lessThan(other) {
102
+ const otherFraction = other instanceof _Fraction ? other : new _Fraction(other);
103
+ return this.numerator * otherFraction.denominator < otherFraction.numerator * this.denominator;
104
+ }
105
+ greaterThan(other) {
106
+ const otherFraction = other instanceof _Fraction ? other : new _Fraction(other);
107
+ return this.numerator * otherFraction.denominator > otherFraction.numerator * this.denominator;
108
+ }
109
+ equalTo(other) {
110
+ const otherFraction = other instanceof _Fraction ? other : new _Fraction(other);
111
+ return this.numerator * otherFraction.denominator === otherFraction.numerator * this.denominator;
112
+ }
113
+ toSignificant(significantDigits = 6) {
114
+ const value = Number(this.numerator) / Number(this.denominator);
115
+ return value.toPrecision(significantDigits);
116
+ }
117
+ toFixed(decimalPlaces = 4) {
118
+ const value = Number(this.numerator) / Number(this.denominator);
119
+ return value.toFixed(decimalPlaces);
120
+ }
121
+ };
122
+ var Percent = class _Percent extends Fraction {
123
+ constructor(numerator, denominator = 100n) {
124
+ super(numerator, denominator);
125
+ }
126
+ toFixed(decimalPlaces = 2) {
127
+ return (Number(this.numerator) / Number(this.denominator) * 100).toFixed(decimalPlaces);
128
+ }
129
+ toSignificant(significantDigits = 3) {
130
+ return (Number(this.numerator) / Number(this.denominator) * 100).toPrecision(significantDigits);
131
+ }
132
+ add(other) {
133
+ const result = super.add(other);
134
+ return new _Percent(result.numerator, result.denominator);
135
+ }
136
+ subtract(other) {
137
+ const result = super.subtract(other);
138
+ return new _Percent(result.numerator, result.denominator);
139
+ }
140
+ multiply(other) {
141
+ const result = super.multiply(other);
142
+ return new _Percent(result.numerator, result.denominator);
143
+ }
144
+ };
145
+ var TokenAmount = class _TokenAmount extends Fraction {
146
+ constructor(token, amount) {
147
+ const rawAmount = BigInt(amount);
148
+ super(rawAmount, BigInt(10 ** token.decimals));
149
+ this.token = token;
150
+ this.raw = rawAmount;
151
+ }
152
+ get currency() {
153
+ return this.token;
154
+ }
155
+ toExact() {
156
+ const divisor = BigInt(10 ** this.token.decimals);
157
+ const quotient = this.raw / divisor;
158
+ const remainder = this.raw % divisor;
159
+ if (remainder === 0n) {
160
+ return quotient.toString();
161
+ }
162
+ const remainderStr = remainder.toString().padStart(this.token.decimals, "0");
163
+ return `${quotient}.${remainderStr}`.replace(/\.?0+$/, "");
164
+ }
165
+ toSignificant(significantDigits = 6) {
166
+ return parseFloat(this.toExact()).toPrecision(significantDigits);
167
+ }
168
+ add(other) {
169
+ if (!this.token.equals(other.token)) throw new Error("TOKEN");
170
+ return new _TokenAmount(this.token, this.raw + other.raw);
171
+ }
172
+ subtract(other) {
173
+ if (other instanceof _TokenAmount) {
174
+ if (!this.token.equals(other.token)) throw new Error("TOKEN");
175
+ return new _TokenAmount(this.token, this.raw - other.raw);
176
+ }
177
+ const otherFraction = other instanceof Fraction ? other : new Fraction(other);
178
+ return new _TokenAmount(this.token, this.raw - otherFraction.numerator);
179
+ }
180
+ greaterThan(other) {
181
+ if (other instanceof _TokenAmount) {
182
+ return this.raw > other.raw;
183
+ }
184
+ return super.greaterThan(other);
185
+ }
186
+ lessThan(other) {
187
+ if (other instanceof _TokenAmount) {
188
+ return this.raw < other.raw;
189
+ }
190
+ return super.lessThan(other);
191
+ }
192
+ equalTo(other) {
193
+ if (other instanceof _TokenAmount) {
194
+ return this.raw === other.raw;
195
+ }
196
+ return super.equalTo(other);
197
+ }
198
+ };
199
+ var CurrencyAmount = class _CurrencyAmount extends Fraction {
200
+ constructor(currency, amount) {
201
+ const decimals = currency instanceof Token ? currency.decimals : 18;
202
+ const rawAmount = BigInt(amount);
203
+ super(rawAmount, BigInt(10 ** decimals));
204
+ this.currency = currency;
205
+ this.raw = rawAmount;
206
+ }
207
+ static ether(amount) {
208
+ return new _CurrencyAmount(ETHER, amount);
209
+ }
210
+ toExact() {
211
+ const decimals = this.currency instanceof Token ? this.currency.decimals : 18;
212
+ const divisor = BigInt(10 ** decimals);
213
+ const quotient = this.raw / divisor;
214
+ const remainder = this.raw % divisor;
215
+ if (remainder === 0n) {
216
+ return quotient.toString();
217
+ }
218
+ const remainderStr = remainder.toString().padStart(decimals, "0");
219
+ return `${quotient}.${remainderStr}`.replace(/\.?0+$/, "");
220
+ }
221
+ toSignificant(significantDigits = 6) {
222
+ return parseFloat(this.toExact()).toPrecision(significantDigits);
223
+ }
224
+ add(other) {
225
+ return new _CurrencyAmount(this.currency, this.raw + other.raw);
226
+ }
227
+ subtract(other) {
228
+ if (other instanceof _CurrencyAmount) {
229
+ return new _CurrencyAmount(this.currency, this.raw - other.raw);
230
+ }
231
+ const otherFraction = other instanceof Fraction ? other : new Fraction(other);
232
+ return new _CurrencyAmount(this.currency, this.raw - otherFraction.numerator);
233
+ }
234
+ greaterThan(other) {
235
+ if (other instanceof _CurrencyAmount) {
236
+ return this.raw > other.raw;
237
+ }
238
+ return super.greaterThan(other);
239
+ }
240
+ };
241
+ var Price = class _Price extends Fraction {
242
+ constructor(baseCurrency, quoteCurrency, denominator, numerator) {
243
+ super(numerator, denominator);
244
+ this.baseCurrency = baseCurrency;
245
+ this.quoteCurrency = quoteCurrency;
246
+ const baseDecimals = baseCurrency instanceof Token ? baseCurrency.decimals : 18;
247
+ const quoteDecimals = quoteCurrency instanceof Token ? quoteCurrency.decimals : 18;
248
+ this.scalar = new Fraction(
249
+ BigInt(10 ** baseDecimals),
250
+ BigInt(10 ** quoteDecimals)
251
+ );
252
+ }
253
+ get raw() {
254
+ return new Fraction(this.numerator, this.denominator);
255
+ }
256
+ get adjusted() {
257
+ return this.raw.multiply(this.scalar);
258
+ }
259
+ invert() {
260
+ return new _Price(this.quoteCurrency, this.baseCurrency, this.numerator, this.denominator);
261
+ }
262
+ multiply(other) {
263
+ return new _Price(
264
+ this.baseCurrency,
265
+ other.quoteCurrency,
266
+ this.denominator * other.denominator,
267
+ this.numerator * other.numerator
268
+ );
269
+ }
270
+ quote(currencyAmount) {
271
+ return new CurrencyAmount(
272
+ this.quoteCurrency,
273
+ this.adjusted.numerator * currencyAmount.raw / this.adjusted.denominator
274
+ );
275
+ }
276
+ toSignificant(significantDigits = 6) {
277
+ return this.adjusted.toSignificant(significantDigits);
278
+ }
279
+ toFixed(decimalPlaces = 4) {
280
+ return this.adjusted.toFixed(decimalPlaces);
281
+ }
282
+ };
283
+ var Pair = class _Pair {
284
+ constructor(tokenAmountA, tokenAmountB) {
285
+ const [token0Amount, token1Amount] = tokenAmountA.token.sortsBefore(tokenAmountB.token) ? [tokenAmountA, tokenAmountB] : [tokenAmountB, tokenAmountA];
286
+ this.token0 = token0Amount.token;
287
+ this.token1 = token1Amount.token;
288
+ this.reserve0 = token0Amount;
289
+ this.reserve1 = token1Amount;
290
+ const pairAddress = _Pair.getAddress(this.token0, this.token1);
291
+ this.liquidityToken = new Token(
292
+ this.token0.chainId,
293
+ pairAddress,
294
+ 18,
295
+ "ETC-V2",
296
+ "ETCswap V2"
297
+ );
298
+ }
299
+ static getAddress(tokenA, tokenB) {
300
+ const [token0, token1] = tokenA.sortsBefore(tokenB) ? [tokenA, tokenB] : [tokenB, tokenA];
301
+ const factoryAddress = FACTORY_ADDRESS[token0.chainId] ?? "0x0000000000000000000000000000000000000000";
302
+ return `0x${factoryAddress.slice(2, 42)}${token0.address.slice(2, 6)}${token1.address.slice(2, 6)}`.toLowerCase();
303
+ }
304
+ get token0Price() {
305
+ return new Price(this.token0, this.token1, this.reserve0.raw, this.reserve1.raw);
306
+ }
307
+ get token1Price() {
308
+ return new Price(this.token1, this.token0, this.reserve1.raw, this.reserve0.raw);
309
+ }
310
+ priceOf(token) {
311
+ return token.equals(this.token0) ? this.token0Price : this.token1Price;
312
+ }
313
+ reserveOf(token) {
314
+ return token.equals(this.token0) ? this.reserve0 : this.reserve1;
315
+ }
316
+ involvesToken(token) {
317
+ return token.equals(this.token0) || token.equals(this.token1);
318
+ }
319
+ getLiquidityValue(token, totalSupply, liquidity, _feeOn) {
320
+ if (!totalSupply.token.equals(this.liquidityToken)) throw new Error("TOTAL_SUPPLY");
321
+ if (!liquidity.token.equals(this.liquidityToken)) throw new Error("LIQUIDITY");
322
+ if (liquidity.raw > totalSupply.raw) throw new Error("LIQUIDITY");
323
+ const reserve = this.reserveOf(token);
324
+ return new TokenAmount(token, liquidity.raw * reserve.raw / totalSupply.raw);
325
+ }
326
+ /**
327
+ * Returns the amount of liquidity tokens that would be minted given the deposited amounts
328
+ */
329
+ getLiquidityMinted(totalSupply, tokenAmountA, tokenAmountB) {
330
+ if (!totalSupply.token.equals(this.liquidityToken)) throw new Error("LIQUIDITY");
331
+ const tokenAmounts = tokenAmountA.token.sortsBefore(tokenAmountB.token) ? [tokenAmountA, tokenAmountB] : [tokenAmountB, tokenAmountA];
332
+ const amount0 = tokenAmounts[0].raw;
333
+ const amount1 = tokenAmounts[1].raw;
334
+ if (totalSupply.raw === 0n) {
335
+ const sqrt = (n) => {
336
+ if (n < 0n) throw new Error("NEGATIVE");
337
+ if (n < 2n) return n;
338
+ let x = n;
339
+ let y = (x + 1n) / 2n;
340
+ while (y < x) {
341
+ x = y;
342
+ y = (x + n / x) / 2n;
343
+ }
344
+ return x;
345
+ };
346
+ const liquidity = sqrt(amount0 * amount1) - MINIMUM_LIQUIDITY;
347
+ return new TokenAmount(this.liquidityToken, liquidity);
348
+ } else {
349
+ const liquidity0 = amount0 * totalSupply.raw / this.reserve0.raw;
350
+ const liquidity1 = amount1 * totalSupply.raw / this.reserve1.raw;
351
+ const liquidity = liquidity0 < liquidity1 ? liquidity0 : liquidity1;
352
+ return new TokenAmount(this.liquidityToken, liquidity);
353
+ }
354
+ }
355
+ };
356
+ var TradeType = /* @__PURE__ */ ((TradeType2) => {
357
+ TradeType2[TradeType2["EXACT_INPUT"] = 0] = "EXACT_INPUT";
358
+ TradeType2[TradeType2["EXACT_OUTPUT"] = 1] = "EXACT_OUTPUT";
359
+ return TradeType2;
360
+ })(TradeType || {});
361
+ var Route = class {
362
+ constructor(pairs, input, output) {
363
+ this.pairs = pairs;
364
+ this.path = pairs.reduce((path, pair) => {
365
+ const inputToken = path[path.length - 1];
366
+ const outputToken = pair.token0.equals(inputToken) ? pair.token1 : pair.token0;
367
+ return [...path, outputToken];
368
+ }, [input instanceof Token ? input : WETC[pairs[0].token0.chainId]]);
369
+ this.input = input;
370
+ this.output = output ?? this.path[this.path.length - 1];
371
+ }
372
+ get midPrice() {
373
+ const prices = this.pairs.map((pair, i) => pair.priceOf(this.path[i]));
374
+ return prices.reduce((acc, price) => {
375
+ return new Price(
376
+ acc.baseCurrency,
377
+ price.quoteCurrency,
378
+ acc.denominator * price.denominator,
379
+ acc.numerator * price.numerator
380
+ );
381
+ });
382
+ }
383
+ };
384
+ var Trade = class _Trade {
385
+ constructor(route, amount, tradeType) {
386
+ this.route = route;
387
+ this.tradeType = tradeType;
388
+ if (tradeType === 0 /* EXACT_INPUT */) {
389
+ this.inputAmount = amount;
390
+ this.outputAmount = new CurrencyAmount(route.output, 0n);
391
+ } else {
392
+ this.outputAmount = amount;
393
+ this.inputAmount = new CurrencyAmount(route.input, 0n);
394
+ }
395
+ this.priceImpact = new Percent(0n, 10000n);
396
+ }
397
+ get executionPrice() {
398
+ return new Price(
399
+ this.inputAmount.currency,
400
+ this.outputAmount.currency,
401
+ this.inputAmount.raw,
402
+ this.outputAmount.raw
403
+ );
404
+ }
405
+ minimumAmountOut(slippageTolerance) {
406
+ if (this.tradeType === 1 /* EXACT_OUTPUT */) {
407
+ return this.outputAmount;
408
+ }
409
+ const slippageAdjustedAmountOut = new Fraction(1n).add(slippageTolerance).invert().multiply(new Fraction(this.outputAmount.raw)).quotient;
410
+ return new CurrencyAmount(this.outputAmount.currency, slippageAdjustedAmountOut);
411
+ }
412
+ maximumAmountIn(slippageTolerance) {
413
+ if (this.tradeType === 0 /* EXACT_INPUT */) {
414
+ return this.inputAmount;
415
+ }
416
+ const slippageAdjustedAmountIn = new Fraction(1n).add(slippageTolerance).multiply(new Fraction(this.inputAmount.raw)).quotient;
417
+ return new CurrencyAmount(this.inputAmount.currency, slippageAdjustedAmountIn);
418
+ }
419
+ static exactIn(route, amountIn) {
420
+ return new _Trade(route, amountIn, 0 /* EXACT_INPUT */);
421
+ }
422
+ static exactOut(route, amountOut) {
423
+ return new _Trade(route, amountOut, 1 /* EXACT_OUTPUT */);
424
+ }
425
+ static bestTradeExactIn(pairs, currencyAmountIn, currencyOut, _options = {}) {
426
+ const inputToken = currencyAmountIn.currency instanceof Token ? currencyAmountIn.currency : WETC[pairs[0]?.token0.chainId];
427
+ if (!inputToken) return [];
428
+ for (const pair of pairs) {
429
+ if (pair.involvesToken(inputToken)) {
430
+ const outputToken = pair.token0.equals(inputToken) ? pair.token1 : pair.token0;
431
+ const outputCurrency = currencyOut instanceof Token ? currencyOut : WETC[outputToken.chainId];
432
+ if (outputCurrency && outputToken.equals(outputCurrency)) {
433
+ const route = new Route([pair], currencyAmountIn.currency, currencyOut);
434
+ return [new _Trade(route, currencyAmountIn, 0 /* EXACT_INPUT */)];
435
+ }
436
+ }
437
+ }
438
+ return [];
439
+ }
440
+ static bestTradeExactOut(pairs, currencyIn, currencyAmountOut, _options = {}) {
441
+ const outputToken = currencyAmountOut.currency instanceof Token ? currencyAmountOut.currency : WETC[pairs[0]?.token0.chainId];
442
+ if (!outputToken) return [];
443
+ for (const pair of pairs) {
444
+ if (pair.involvesToken(outputToken)) {
445
+ const inputToken = pair.token0.equals(outputToken) ? pair.token1 : pair.token0;
446
+ const inputCurrency = currencyIn instanceof Token ? currencyIn : WETC[inputToken.chainId];
447
+ if (inputCurrency && inputToken.equals(inputCurrency)) {
448
+ const route = new Route([pair], currencyIn, currencyAmountOut.currency);
449
+ return [new _Trade(route, currencyAmountOut, 1 /* EXACT_OUTPUT */)];
450
+ }
451
+ }
452
+ }
453
+ return [];
454
+ }
455
+ };
456
+ var JSBI = {
457
+ BigInt: (value) => BigInt(value),
458
+ add: (a, b) => a + b,
459
+ subtract: (a, b) => a - b,
460
+ multiply: (a, b) => a * b,
461
+ divide: (a, b) => a / b,
462
+ remainder: (a, b) => a % b,
463
+ exponentiate: (a, b) => a ** b,
464
+ greaterThan: (a, b) => a > b,
465
+ greaterThanOrEqual: (a, b) => a >= b,
466
+ lessThan: (a, b) => a < b,
467
+ lessThanOrEqual: (a, b) => a <= b,
468
+ equal: (a, b) => a === b,
469
+ notEqual: (a, b) => a !== b
470
+ };
471
+ var Rounding = /* @__PURE__ */ ((Rounding2) => {
472
+ Rounding2[Rounding2["ROUND_DOWN"] = 0] = "ROUND_DOWN";
473
+ Rounding2[Rounding2["ROUND_HALF_UP"] = 1] = "ROUND_HALF_UP";
474
+ Rounding2[Rounding2["ROUND_UP"] = 2] = "ROUND_UP";
475
+ return Rounding2;
476
+ })(Rounding || {});
477
+ function currencyEquals(a, b) {
478
+ if (a === ETHER && b === ETHER) return true;
479
+ if (a instanceof Token && b instanceof Token) return a.equals(b);
480
+ return false;
481
+ }
482
+ var FACTORY_ADDRESS = {
483
+ [61 /* CLASSIC */]: "0x0307cd3D7DA98A29e6Ed0D2137be386Ec1e4Bc9C",
484
+ [63 /* MORDOR */]: "0x212eE1B5c8C26ff5B2c4c14CD1C54486Fe23ce70"
485
+ };
486
+ var ROUTER_ADDRESS = {
487
+ [61 /* CLASSIC */]: "0x79Bf07555C34e68C4Ae93642d1007D7f908d60F5",
488
+ [63 /* MORDOR */]: "0x6d194227a9A1C11f144B35F96E6289c5602Da493"
489
+ };
490
+ var INIT_CODE_HASH = {
491
+ [61 /* CLASSIC */]: "0xb5e58237f3a44220ffc3dfb989e53735df8fcd9df82c94b13105be8380344e52",
492
+ [63 /* MORDOR */]: "0x4d8a51f257ed377a6ac3f829cd4226c892edbbbcb87622bcc232807b885b1303"
493
+ };
494
+ var MINIMUM_LIQUIDITY = 1000n;
495
+ var Router = class {
496
+ static swapCallParameters(trade, options) {
497
+ const etherIn = !(trade.inputAmount.currency instanceof Token);
498
+ const etherOut = !(trade.outputAmount.currency instanceof Token);
499
+ let methodName;
500
+ if (trade.tradeType === 0 /* EXACT_INPUT */) {
501
+ if (etherIn) {
502
+ methodName = options.feeOnTransfer ? "swapExactETCForTokensSupportingFeeOnTransferTokens" : "swapExactETCForTokens";
503
+ } else if (etherOut) {
504
+ methodName = options.feeOnTransfer ? "swapExactTokensForETCSupportingFeeOnTransferTokens" : "swapExactTokensForETC";
505
+ } else {
506
+ methodName = options.feeOnTransfer ? "swapExactTokensForTokensSupportingFeeOnTransferTokens" : "swapExactTokensForTokens";
507
+ }
508
+ } else {
509
+ if (etherIn) {
510
+ methodName = "swapETCForExactTokens";
511
+ } else if (etherOut) {
512
+ methodName = "swapTokensForExactETC";
513
+ } else {
514
+ methodName = "swapTokensForExactTokens";
515
+ }
516
+ }
517
+ const path = trade.route.path.map((token) => token.address);
518
+ const amountIn = trade.maximumAmountIn(options.allowedSlippage).raw.toString();
519
+ const amountOut = trade.minimumAmountOut(options.allowedSlippage).raw.toString();
520
+ const deadline = options.deadline.toString();
521
+ let args;
522
+ let value = "0";
523
+ if (trade.tradeType === 0 /* EXACT_INPUT */) {
524
+ if (etherIn) {
525
+ args = [amountOut, path, options.recipient, deadline];
526
+ value = amountIn;
527
+ } else if (etherOut) {
528
+ args = [amountIn, amountOut, path, options.recipient, deadline];
529
+ } else {
530
+ args = [amountIn, amountOut, path, options.recipient, deadline];
531
+ }
532
+ } else {
533
+ if (etherIn) {
534
+ args = [amountOut, path, options.recipient, deadline];
535
+ value = amountIn;
536
+ } else if (etherOut) {
537
+ args = [amountOut, amountIn, path, options.recipient, deadline];
538
+ } else {
539
+ args = [amountOut, amountIn, path, options.recipient, deadline];
540
+ }
541
+ }
542
+ return { methodName, args, value };
543
+ }
544
+ };
545
+ export {
546
+ ChainId,
547
+ CurrencyAmount,
548
+ ETHER,
549
+ Ether,
550
+ FACTORY_ADDRESS,
551
+ Fraction,
552
+ INIT_CODE_HASH,
553
+ JSBI,
554
+ MINIMUM_LIQUIDITY,
555
+ Pair,
556
+ Percent,
557
+ Price,
558
+ ROUTER_ADDRESS,
559
+ Rounding,
560
+ Route,
561
+ Router,
562
+ SUPPORTED_CHAINS,
563
+ Token,
564
+ TokenAmount,
565
+ Trade,
566
+ TradeType,
567
+ WETC,
568
+ WETH,
569
+ currencyEquals
570
+ };
package/package.json ADDED
@@ -0,0 +1,55 @@
1
+ {
2
+ "name": "@etcswapv2/sdk-legacy",
3
+ "version": "1.0.0",
4
+ "description": "Legacy V2 SDK for ETCswap - non-generic API compatible with Uniswap V2 interface",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/etcswap/sdks.git",
8
+ "directory": "sdks/v2-sdk-legacy"
9
+ },
10
+ "keywords": [
11
+ "etcswap",
12
+ "ethereum-classic",
13
+ "etc",
14
+ "dex",
15
+ "amm",
16
+ "v2",
17
+ "legacy",
18
+ "uniswap-v2-compatible"
19
+ ],
20
+ "license": "MIT",
21
+ "main": "dist/index.js",
22
+ "module": "dist/index.mjs",
23
+ "types": "dist/index.d.ts",
24
+ "exports": {
25
+ ".": {
26
+ "types": "./dist/index.d.ts",
27
+ "import": "./dist/index.mjs",
28
+ "require": "./dist/index.js"
29
+ }
30
+ },
31
+ "files": [
32
+ "dist"
33
+ ],
34
+ "engines": {
35
+ "node": ">=18"
36
+ },
37
+ "scripts": {
38
+ "build": "tsup src/index.ts --format cjs,esm --dts --clean",
39
+ "clean": "rimraf dist",
40
+ "lint": "eslint src --ext .ts",
41
+ "test": "vitest run",
42
+ "typecheck": "tsc --noEmit",
43
+ "prepublishOnly": "pnpm run build"
44
+ },
45
+ "devDependencies": {
46
+ "@types/node": "^20.0.0",
47
+ "rimraf": "^5.0.0",
48
+ "tsup": "^8.0.0",
49
+ "typescript": "^5.3.0",
50
+ "vitest": "^3.0.0"
51
+ },
52
+ "publishConfig": {
53
+ "access": "public"
54
+ }
55
+ }