@etcswapv2/sdk-legacy 1.0.2 → 1.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.js CHANGED
@@ -260,9 +260,15 @@ var TokenAmount = class _TokenAmount extends Fraction {
260
260
  return super.equalTo(other);
261
261
  }
262
262
  };
263
+ function getCurrencyDecimals(currency) {
264
+ if (currency && typeof currency === "object" && "decimals" in currency) {
265
+ return currency.decimals;
266
+ }
267
+ return 18;
268
+ }
263
269
  var CurrencyAmount = class _CurrencyAmount extends Fraction {
264
270
  constructor(currency, amount) {
265
- const decimals = currency instanceof Token ? currency.decimals : 18;
271
+ const decimals = getCurrencyDecimals(currency);
266
272
  const rawAmount = BigInt(amount);
267
273
  super(rawAmount, BigInt(10 ** decimals));
268
274
  this.currency = currency;
@@ -272,7 +278,7 @@ var CurrencyAmount = class _CurrencyAmount extends Fraction {
272
278
  return new _CurrencyAmount(ETHER, amount);
273
279
  }
274
280
  toExact() {
275
- const decimals = this.currency instanceof Token ? this.currency.decimals : 18;
281
+ const decimals = getCurrencyDecimals(this.currency);
276
282
  const divisor = BigInt(10 ** decimals);
277
283
  const quotient = this.raw / divisor;
278
284
  const remainder = this.raw % divisor;
@@ -307,8 +313,8 @@ var Price = class _Price extends Fraction {
307
313
  super(numerator, denominator);
308
314
  this.baseCurrency = baseCurrency;
309
315
  this.quoteCurrency = quoteCurrency;
310
- const baseDecimals = baseCurrency instanceof Token ? baseCurrency.decimals : 18;
311
- const quoteDecimals = quoteCurrency instanceof Token ? quoteCurrency.decimals : 18;
316
+ const baseDecimals = getCurrencyDecimals(baseCurrency);
317
+ const quoteDecimals = getCurrencyDecimals(quoteCurrency);
312
318
  this.scalar = new Fraction(
313
319
  BigInt(10 ** baseDecimals),
314
320
  BigInt(10 ** quoteDecimals)
@@ -334,7 +340,7 @@ var Price = class _Price extends Fraction {
334
340
  quote(currencyAmount) {
335
341
  return new CurrencyAmount(
336
342
  this.quoteCurrency,
337
- this.adjusted.numerator * currencyAmount.raw / this.adjusted.denominator
343
+ currencyAmount.raw * this.numerator / this.denominator
338
344
  );
339
345
  }
340
346
  toSignificant(significantDigits = 6) {
package/dist/index.mjs CHANGED
@@ -213,9 +213,15 @@ var TokenAmount = class _TokenAmount extends Fraction {
213
213
  return super.equalTo(other);
214
214
  }
215
215
  };
216
+ function getCurrencyDecimals(currency) {
217
+ if (currency && typeof currency === "object" && "decimals" in currency) {
218
+ return currency.decimals;
219
+ }
220
+ return 18;
221
+ }
216
222
  var CurrencyAmount = class _CurrencyAmount extends Fraction {
217
223
  constructor(currency, amount) {
218
- const decimals = currency instanceof Token ? currency.decimals : 18;
224
+ const decimals = getCurrencyDecimals(currency);
219
225
  const rawAmount = BigInt(amount);
220
226
  super(rawAmount, BigInt(10 ** decimals));
221
227
  this.currency = currency;
@@ -225,7 +231,7 @@ var CurrencyAmount = class _CurrencyAmount extends Fraction {
225
231
  return new _CurrencyAmount(ETHER, amount);
226
232
  }
227
233
  toExact() {
228
- const decimals = this.currency instanceof Token ? this.currency.decimals : 18;
234
+ const decimals = getCurrencyDecimals(this.currency);
229
235
  const divisor = BigInt(10 ** decimals);
230
236
  const quotient = this.raw / divisor;
231
237
  const remainder = this.raw % divisor;
@@ -260,8 +266,8 @@ var Price = class _Price extends Fraction {
260
266
  super(numerator, denominator);
261
267
  this.baseCurrency = baseCurrency;
262
268
  this.quoteCurrency = quoteCurrency;
263
- const baseDecimals = baseCurrency instanceof Token ? baseCurrency.decimals : 18;
264
- const quoteDecimals = quoteCurrency instanceof Token ? quoteCurrency.decimals : 18;
269
+ const baseDecimals = getCurrencyDecimals(baseCurrency);
270
+ const quoteDecimals = getCurrencyDecimals(quoteCurrency);
265
271
  this.scalar = new Fraction(
266
272
  BigInt(10 ** baseDecimals),
267
273
  BigInt(10 ** quoteDecimals)
@@ -287,7 +293,7 @@ var Price = class _Price extends Fraction {
287
293
  quote(currencyAmount) {
288
294
  return new CurrencyAmount(
289
295
  this.quoteCurrency,
290
- this.adjusted.numerator * currencyAmount.raw / this.adjusted.denominator
296
+ currencyAmount.raw * this.numerator / this.denominator
291
297
  );
292
298
  }
293
299
  toSignificant(significantDigits = 6) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etcswapv2/sdk-legacy",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "description": "Legacy V2 SDK for ETCswap - non-generic API compatible with Uniswap V2 interface",
5
5
  "repository": {
6
6
  "type": "git",
@@ -37,6 +37,14 @@
37
37
  "dependencies": {
38
38
  "viem": "^2.0.0"
39
39
  },
40
+ "scripts": {
41
+ "build": "tsup src/index.ts --format cjs,esm --dts --clean",
42
+ "clean": "rimraf dist",
43
+ "lint": "eslint src --ext .ts",
44
+ "test": "vitest run",
45
+ "typecheck": "tsc --noEmit",
46
+ "prepublishOnly": "pnpm run build"
47
+ },
40
48
  "devDependencies": {
41
49
  "@types/node": "^20.0.0",
42
50
  "rimraf": "^5.0.0",
@@ -46,12 +54,5 @@
46
54
  },
47
55
  "publishConfig": {
48
56
  "access": "public"
49
- },
50
- "scripts": {
51
- "build": "tsup src/index.ts --format cjs,esm --dts --clean",
52
- "clean": "rimraf dist",
53
- "lint": "eslint src --ext .ts",
54
- "test": "vitest run",
55
- "typecheck": "tsc --noEmit"
56
57
  }
57
- }
58
+ }