diff --git a/api/relayer-config.ts b/api/relayer-config.ts index 9759a343b..52fc8e837 100644 --- a/api/relayer-config.ts +++ b/api/relayer-config.ts @@ -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, @@ -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" }); }; diff --git a/test/api/relayer-config.test.ts b/test/api/relayer-config.test.ts index a8d6200da..b71b8d5be 100644 --- a/test/api/relayer-config.test.ts +++ b/test/api/relayer-config.test.ts @@ -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);