Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/lib/libraries/intent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ export class Intent {

private _nonce?: bigint;

private expiry = ONE_DAY;
private fillDeadline = 2 * ONE_HOUR;
private expiry = 2 * ONE_DAY;
private fillDeadline = 44 * ONE_HOUR;

constructor(opts: CreateIntentOptionsEscrow | CreateIntentOptionsCompact) {
this.lock = opts.lock;
Expand Down
81 changes: 81 additions & 0 deletions tests/unit/intent.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import { describe, expect, it } from "bun:test";
import { Intent } from "../../src/lib/libraries/intent";
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

function token(chain: chain): Token {
return {
address: "0x0000000000000000000000000000000000000001",
name: "MOCK",
chain,
decimals: 18
};
}

function makeIntent(inputChain: chain, outputChain: chain) {
return new Intent({
exclusiveFor: "",
inputTokens: [{ token: token(inputChain), amount: 1n }],
outputTokens: [{ token: token(outputChain), amount: 1n }],
verifier: "polymer",
account: () => "0x1111111111111111111111111111111111111111",
lock: { type: "escrow" }
});
}

function makeMultichainIntent(inputChains: chain[], outputChain: chain) {
return new Intent({
exclusiveFor: "",
inputTokens: inputChains.map((c) => ({ token: token(c), amount: 1n })),
outputTokens: [{ token: token(outputChain), amount: 1n }],
verifier: "polymer",
account: () => "0x1111111111111111111111111111111111111111",
lock: { type: "escrow" }
});
}

describe("Intent deadlines", () => {
it("cross-chain singlechain order uses 44h fillDeadline and 2d expires", () => {
const before = Math.floor(Date.now() / 1000);
const { order } = makeIntent("base", "arbitrum").singlechain();
const after = Math.floor(Date.now() / 1000);

expect(order.fillDeadline).toBeGreaterThanOrEqual(before + FORTY_FOUR_HOURS);
expect(order.fillDeadline).toBeLessThanOrEqual(after + FORTY_FOUR_HOURS);

expect(order.expires).toBeGreaterThanOrEqual(before + TWO_DAYS);
expect(order.expires).toBeLessThanOrEqual(after + TWO_DAYS);

expect(order.fillDeadline).toBeLessThanOrEqual(order.expires);
});

it("same-chain singlechain order uses 44h fillDeadline and 2d expires", () => {
const before = Math.floor(Date.now() / 1000);
const { order } = makeIntent("base", "base").singlechain();
const after = Math.floor(Date.now() / 1000);

expect(order.fillDeadline).toBeGreaterThanOrEqual(before + FORTY_FOUR_HOURS);
expect(order.fillDeadline).toBeLessThanOrEqual(after + FORTY_FOUR_HOURS);

expect(order.expires).toBeGreaterThanOrEqual(before + TWO_DAYS);
expect(order.expires).toBeLessThanOrEqual(after + TWO_DAYS);

expect(order.fillDeadline).toBeLessThanOrEqual(order.expires);
});

it("multichain order uses 44h fillDeadline and 2d expires", () => {
const before = Math.floor(Date.now() / 1000);
const { order } = makeMultichainIntent(["base", "arbitrum"], "ethereum").multichain();
const after = Math.floor(Date.now() / 1000);

expect(order.fillDeadline).toBeGreaterThanOrEqual(before + FORTY_FOUR_HOURS);
expect(order.fillDeadline).toBeLessThanOrEqual(after + FORTY_FOUR_HOURS);

expect(order.expires).toBeGreaterThanOrEqual(before + TWO_DAYS);
expect(order.expires).toBeLessThanOrEqual(after + TWO_DAYS);

expect(order.fillDeadline).toBeLessThanOrEqual(order.expires);
});
});
Loading