@proton/wrap-constants 0.0.58 → 0.0.61

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/src/math.ts CHANGED
@@ -66,12 +66,14 @@ export const compute_transfer_curve = (
66
66
  throw new Error("curve: insufficient reserve out")
67
67
  }
68
68
 
69
- // TODO: Special -> to prevent stable unbalancing
70
- let amount_out_with_fee = new BN(reserve_out - x);
71
- amount_out_with_fee = BN.minimum(amount_out_with_fee, amount_in);
69
+ // Amount out + Fee + 1
70
+ const amount_out_with_fee = new BN(reserve_out - x);
72
71
 
73
- // Fee
74
- const fee = amount_out_with_fee.multipliedBy(exchange_fee).dividedBy(FEE_FACTOR).toFixed(0, BN.ROUND_DOWN);
72
+ // Fee + 1
73
+ // +1 covers small precision issues
74
+ const fee = amount_out_with_fee.multipliedBy(exchange_fee).dividedBy(FEE_FACTOR).plus(1).toFixed(0, BN.ROUND_DOWN);
75
+
76
+ // Amount out
75
77
  const amount_out = amount_out_with_fee.minus(fee)
76
78
 
77
79
  return amount_out.integerValue(BN.ROUND_DOWN).shiftedBy(-precision)
@@ -36,7 +36,8 @@ export interface Pool extends Omit<RawPool, 'pool1'|'pool2'> {
36
36
  add_liquidity_fee: number;
37
37
  remove_liquidity_fee: number;
38
38
  };
39
- liquidityUsd?: number;
39
+ liquidityUsd: number;
40
+ liquidityApr: number;
40
41
  }
41
42
 
42
43
  export type ExtendedToken = Coin & ExtendedAsset & { key: string; }
package/src/utils.ts CHANGED
@@ -8,4 +8,15 @@ export const isSameToken = (token1: PartialCoin, token2: PartialCoin) => {
8
8
  return token1.xtokenSymbol === token2.xtokenSymbol &&
9
9
  token1.xtokenPrecision === token2.xtokenPrecision &&
10
10
  token1.xtokenContract === token2.xtokenContract
11
- }
11
+ }
12
+
13
+ export const median = (numbers: number[]) => {
14
+ const sorted = numbers.slice().sort((a, b) => a - b);
15
+ const middle = Math.floor(sorted.length / 2);
16
+
17
+ if (sorted.length % 2 === 0) {
18
+ return (sorted[middle - 1] + sorted[middle]) / 2;
19
+ }
20
+
21
+ return sorted[middle];
22
+ }