// SPDX-License-Identifier: MIT pragma solidity ^0.8.28; import {AsyncTypes, IAsyncReceiver, IAsyncRouter} from "./IAsync.sol"; /// @title MockAsyncRouter /// @notice For Foundry tests of a consumer: `request` records the intent, `answer` delivers a scripted /// Filled, Partial, Dropped or Unanswered receipt into the consumer, exactly like the real router. contract MockAsyncRouter is IAsyncRouter { struct Rec { address consumer; AsyncTypes.Intent intent; bool answered; } uint256 public nextIntentId = 1; mapping(uint256 => Rec) public recs; event IntentRequested(uint256 indexed intentId, address indexed consumer, AsyncTypes.Intent intent); function request(AsyncTypes.Intent calldata it) external returns (uint256 id) { id = nextIntentId++; recs[id] = Rec(msg.sender, it, false); emit IntentRequested(id, msg.sender, it); } function cloidOf(uint256 id) external view returns (bytes16) { return bytes16(keccak256(abi.encode(block.chainid, address(this), id))); } function intentOf(uint256 id) external view returns (address, address, uint64, uint8, bool, bool, uint128, uint128, AsyncTypes.Intent memory) { Rec storage r = recs[id]; return (r.consumer, address(0), 0, r.answered ? 3 : 1, false, false, 0, 0, r.intent); } function answer(uint256 id, AsyncTypes.Status status, uint64 filledSz, uint64 avgPx) public { Rec storage r = recs[id]; require(!r.answered && r.consumer != address(0), "mock: not open"); r.answered = true; AsyncTypes.Receipt memory rc; rc.status = status; rc.filledSz = filledSz; rc.avgPx = avgPx; rc.oid = uint64(id + 1_000_000); rc.coreTime = uint64(block.timestamp * 1000); IAsyncReceiver(r.consumer).onReceipt{gas: r.intent.callbackGas}(id, rc); } function fill(uint256 id) external { answer(id, AsyncTypes.Status.Filled, recs[id].intent.sz, recs[id].intent.limitPx); } function drop(uint256 id) external { answer(id, AsyncTypes.Status.Dropped, 0, 0); } }