Skip to content

Commit

Permalink
Merge branch 'epic/relayer-config' into pxrl/sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
pxrl authored Dec 12, 2024
2 parents a7d4176 + 470e309 commit 16898eb
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 8 deletions.
30 changes: 22 additions & 8 deletions api/relayer-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@ import {
getWhiteListedRelayers,
isTimestampValid,
MAX_MESSAGE_AGE_SECONDS,
updateLimits,
} from "./_exclusivity/utils";
import { RelayerConfigUpdate, TypedRelayerConfigUpdateRequest } from "./_types";
import {
RelayerConfigUpdate,
RelayerFillLimitArraySchema,
TypedRelayerConfigUpdateRequest,
} from "./_types";

const handler = async (
request: TypedRelayerConfigUpdateRequest,
Expand All @@ -14,21 +19,30 @@ const handler = async (
if (request.method !== "POST") {
return response.status(405).end(`Method ${request.method} Not Allowed`);
}

const body = request.body as RelayerConfigUpdate;
const { authorization } = request.headers;
const { timestamp } = body;
const { relayerFillLimits, timestamp } = body;
if (!isTimestampValid(timestamp, MAX_MESSAGE_AGE_SECONDS)) {
return response.status(400).json({ message: "Message too old" });
}

if (
!authorization ||
!getWhiteListedRelayers().includes(
getRelayerFromSignature(authorization, JSON.stringify(body))
)
) {
if (!authorization) {
return response.status(401).json({ message: "Unauthorized" });
}
const relayer = getRelayerFromSignature(authorization, JSON.stringify(body));

if (!getWhiteListedRelayers().includes(relayer)) {
return response.status(401).json({ message: "Unauthorized" });
}

if (!RelayerFillLimitArraySchema.is(relayerFillLimits)) {
return response
.status(400)
.json({ message: "Invalid configuration payload" });
}

await updateLimits(relayer, relayerFillLimits);
return response.status(200).json({ message: "POST request received" });
};

Expand Down
13 changes: 13 additions & 0 deletions test/api/relayer-config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,19 @@ describe("Relayer Config API", () => {
test("POST request with valid timestamp", async () => {
const message = {
timestamp: Date.now() / 1000,
relayerFillLimits: [
{
originChainId: "1",
inputToken: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
destinationChainId: "42161",
outputToken: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
minOutputAmount: "1",
maxOutputAmount: "2",
balanceMultiplier: "1",
minProfitThreshold: "0.0001",
minExclusivityPeriod: "1",
},
],
};
const messageString = JSON.stringify(message);
const signature = await whitelistedRelayer.signMessage(messageString);
Expand Down

0 comments on commit 16898eb

Please sign in to comment.