@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 +1 -0
- package/dist/wrap-constants.cjs.development.js +18 -4
- package/dist/wrap-constants.cjs.development.js.map +1 -1
- package/dist/wrap-constants.cjs.production.min.js +1 -1
- package/dist/wrap-constants.cjs.production.min.js.map +1 -1
- package/dist/wrap-constants.esm.js +18 -5
- package/dist/wrap-constants.esm.js.map +1 -1
- package/package.json +2 -2
- package/src/math.ts +7 -5
- package/src/utils.ts +12 -1
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
|
-
//
|
|
70
|
-
|
|
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
|
-
|
|
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)
|
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
|
+
}
|