@proton/wrap-constants 0.0.58 → 0.0.59

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/utils.d.ts CHANGED
@@ -4,4 +4,5 @@ interface PartialCoin {
4
4
  xtokenContract: string;
5
5
  }
6
6
  export declare const isSameToken: (token1: PartialCoin, token2: PartialCoin) => boolean;
7
+ export declare const median: (numbers: number[]) => number;
7
8
  export {};
@@ -1262,6 +1262,18 @@ var wrapParser = /*#__PURE__*/z.object({
1262
1262
  var isSameToken = function isSameToken(token1, token2) {
1263
1263
  return token1.xtokenSymbol === token2.xtokenSymbol && token1.xtokenPrecision === token2.xtokenPrecision && token1.xtokenContract === token2.xtokenContract;
1264
1264
  };
1265
+ var median = function median(numbers) {
1266
+ var sorted = numbers.slice().sort(function (a, b) {
1267
+ return a - b;
1268
+ });
1269
+ var middle = Math.floor(sorted.length / 2);
1270
+
1271
+ if (sorted.length % 2 === 0) {
1272
+ return (sorted[middle - 1] + sorted[middle]) / 2;
1273
+ }
1274
+
1275
+ return sorted[middle];
1276
+ };
1265
1277
 
1266
1278
  var INode = function INode(key, data) {
1267
1279
  this.key = void 0;
@@ -1505,13 +1517,14 @@ var compute_transfer_curve = function compute_transfer_curve(reserve_in, reserve
1505
1517
 
1506
1518
  if (reserve_out <= x) {
1507
1519
  throw new Error("curve: insufficient reserve out");
1508
- } // TODO: Special -> to prevent stable unbalancing
1520
+ } // Amount out + Fee + 1
1521
+
1509
1522
 
1523
+ var amount_out_with_fee = new bignumber_js.BigNumber(reserve_out - x); // Fee + 1
1524
+ // +1 covers small precision issues
1510
1525
 
1511
- var amount_out_with_fee = new bignumber_js.BigNumber(reserve_out - x);
1512
- amount_out_with_fee = bignumber_js.BigNumber.minimum(amount_out_with_fee, amount_in); // Fee
1526
+ var fee = amount_out_with_fee.multipliedBy(exchange_fee).dividedBy(FEE_FACTOR).plus(1).toFixed(0, bignumber_js.BigNumber.ROUND_DOWN); // Amount out
1513
1527
 
1514
- var fee = amount_out_with_fee.multipliedBy(exchange_fee).dividedBy(FEE_FACTOR).toFixed(0, bignumber_js.BigNumber.ROUND_DOWN);
1515
1528
  var amount_out = amount_out_with_fee.minus(fee);
1516
1529
  return amount_out.integerValue(bignumber_js.BigNumber.ROUND_DOWN).shiftedBy(-precision);
1517
1530
  };
@@ -1572,6 +1585,7 @@ exports.initializeCoins = initializeCoins;
1572
1585
  exports.initializeConstants = initializeConstants;
1573
1586
  exports.isInputInvalid = isInputInvalid;
1574
1587
  exports.isSameToken = isSameToken;
1588
+ exports.median = median;
1575
1589
  exports.otcOrderResponseParser = otcOrderResponseParser;
1576
1590
  exports.otcQuoteBodyParser = otcQuoteBodyParser;
1577
1591
  exports.otcQuoteResponseParser = otcQuoteResponseParser;