Skip to content

Commit

Permalink
Add basic sorting/parsing (#1328)
Browse files Browse the repository at this point in the history
  • Loading branch information
pxrl authored Dec 12, 2024
1 parent aa191bf commit 5dbddd3
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions api/_exclusivity/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ethers } from "ethers";
import { bnZero } from "../../src/utils/sdk";
import { RelayerFillLimit } from "../_types";

export const MAX_MESSAGE_AGE_SECONDS = 300;
Expand Down Expand Up @@ -26,7 +27,30 @@ export async function updateLimits(
relayer: string,
limits: RelayerFillLimit[]
): Promise<void> {
relayer; // todo
limits; // todo
const sortedLimits = limits
.map(({ minOutputAmount, maxOutputAmount, ...rest }) => ({
minOutputAmount: ethers.BigNumber.from(minOutputAmount),
maxOutputAmount: ethers.BigNumber.from(maxOutputAmount),
...rest,
}))
.sort(({ minOutputAmount: minA }, { minOutputAmount: minB }) =>
minA.sub(minB).gte(bnZero) ? 1 : -1
);

const sorted = sortedLimits
.slice(1)
.every(({ minOutputAmount, maxOutputAmount }, idx) => {
const { maxOutputAmount: prevMax } = sortedLimits[idx];
return maxOutputAmount.gt(minOutputAmount) && minOutputAmount.gt(prevMax);
});

if (!sorted) {
throw new Error("Relayer limits are overlapping");
}

// todo: Push each limit entry to the backend cache/db.
// The config types need to be reverted to strings as numbers.
relayer;

return;
}

0 comments on commit 5dbddd3

Please sign in to comment.