Skip to content

Commit 51b7c25

Browse files
committed
remove clamp
1 parent 2faf3c8 commit 51b7c25

File tree

3 files changed

+2
-30
lines changed

3 files changed

+2
-30
lines changed

src/tests/math.test.ts

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { describe, expect, it } from "vitest";
2-
import { clamp, getPercentile } from "../utils/math";
2+
import { getPercentile } from "../utils/math";
33

44
describe("getPercentile", () => {
55
it("should correctly calculate the p50 (median) of a sorted array", () => {
@@ -27,25 +27,3 @@ describe("getPercentile", () => {
2727
expect(getPercentile(numbers, 50)).toBe(0);
2828
});
2929
});
30-
31-
describe("clamp", () => {
32-
it("clamps the value correctly below the minimum", () => {
33-
expect(clamp(0, { min: 2, max: 10 })).toBe(2);
34-
});
35-
36-
it("clamps the value correctly at the minimum", () => {
37-
expect(clamp(2, { min: 2, max: 10 })).toBe(2);
38-
});
39-
40-
it("returns the value when within bounds", () => {
41-
expect(clamp(3, { min: 2, max: 10 })).toBe(3);
42-
});
43-
44-
it("clamps the value correctly at the maximum", () => {
45-
expect(clamp(10, { min: 2, max: 10 })).toBe(10);
46-
});
47-
48-
it("clamps the value correctly above the maximum", () => {
49-
expect(clamp(12, { min: 2, max: 10 })).toBe(10);
50-
});
51-
});

src/utils/math.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,3 @@ export const getPercentile = (arr: number[], percentile: number): number => {
77
const index = Math.floor((percentile / 100) * (arr.length - 1));
88
return arr[index];
99
};
10-
11-
export const clamp = (
12-
val: number,
13-
{ min, max }: { min: number; max: number },
14-
) => Math.max(min, Math.min(val, max));

src/worker/tasks/sendTransactionWorker.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ import {
3939
isReplacementGasFeeTooLow,
4040
wrapError,
4141
} from "../../utils/error";
42-
import { clamp } from "../../utils/math";
4342
import { getChecksumAddress } from "../../utils/primitiveTypes";
4443
import { recordMetrics } from "../../utils/prometheus";
4544
import { redis } from "../../utils/redis/redis";
@@ -595,7 +594,7 @@ export const _updateGasFees = (
595594
return populatedTransaction;
596595
}
597596

598-
const multiplier = BigInt(clamp(resendCount * 2, { min: 2, max: 10 }));
597+
const multiplier = BigInt(Math.min(10, resendCount * 2));
599598

600599
const updated = { ...populatedTransaction };
601600
if (updated.gasPrice) {

0 commit comments

Comments
 (0)