diff --git a/src/lib/libraries/intent.ts b/src/lib/libraries/intent.ts index f080e1e..c32301f 100644 --- a/src/lib/libraries/intent.ts +++ b/src/lib/libraries/intent.ts @@ -98,6 +98,7 @@ function encodeOutputs(outputs: MandateOutput[]) { const ONE_MINUTE = 60; const ONE_HOUR = 60 * ONE_MINUTE; const ONE_DAY = 24 * ONE_HOUR; +const EXCLUSIVITY_WINDOW = 5 * ONE_MINUTE; // gives solvers time to fill before exclusivity ends /** * @notice Class representing a Li.Fi Intent. Contains intent abstractions and helpers. @@ -179,16 +180,12 @@ export class Intent { } encodeOutputs(currentTime: number) { - // Get the current epoch timestamp: - currentTime; - const ONE_MINUTE = 60; - let context: `0x${string}` = "0x"; if (this.exclusiveFor) { const paddedExclusiveFor: `0x${string}` = `0x${this.exclusiveFor.replace("0x", "").padStart(64, "0")}`; context = encodePacked( ["bytes1", "bytes32", "uint32"], - ["0xe0", paddedExclusiveFor, currentTime + ONE_MINUTE] + ["0xe0", paddedExclusiveFor, currentTime + EXCLUSIVITY_WINDOW] ); } diff --git a/tests/unit/intent.test.ts b/tests/unit/intent.test.ts index e65c2f8..b65588c 100644 --- a/tests/unit/intent.test.ts +++ b/tests/unit/intent.test.ts @@ -4,6 +4,7 @@ import type { chain, Token } from "../../src/lib/config"; const FORTY_FOUR_HOURS = 44 * 60 * 60; // 158_400 const TWO_DAYS = 2 * 24 * 60 * 60; // 172_800 +const FIVE_MINUTES = 5 * 60; // 300 function token(chain: chain): Token { return { @@ -14,9 +15,9 @@ function token(chain: chain): Token { }; } -function makeIntent(inputChain: chain, outputChain: chain) { +function makeIntent(inputChain: chain, outputChain: chain, exclusiveFor = "") { return new Intent({ - exclusiveFor: "", + exclusiveFor, inputTokens: [{ token: token(inputChain), amount: 1n }], outputTokens: [{ token: token(outputChain), amount: 1n }], verifier: "polymer", @@ -78,4 +79,22 @@ describe("Intent deadlines", () => { expect(order.fillDeadline).toBeLessThanOrEqual(order.expires); }); + + it("encodes exclusiveFor deadline as now + 5 minutes in output context", () => { + const exclusiveFor = "0x2222222222222222222222222222222222222222"; + const before = Math.floor(Date.now() / 1000); + const { order } = makeIntent("base", "arbitrum", exclusiveFor).singlechain(); + const after = Math.floor(Date.now() / 1000); + + const context = order.outputs[0].context; + expect(context.length).toBeGreaterThan(2); // not just "0x" + + // Layout: bytes1 0xe0 || bytes32 exclusiveFor || uint32 deadline + // = 37 bytes = 74 hex chars after the "0x" prefix. + expect(context.length).toBe(2 + 74); + + const deadline = parseInt(context.slice(-8), 16); + expect(deadline).toBeGreaterThanOrEqual(before + FIVE_MINUTES); + expect(deadline).toBeLessThanOrEqual(after + FIVE_MINUTES); + }); });