// SPDX-License-Identifier: MIT pragma solidity ^0.8.28; import {AsyncTypes, IAsyncReceiver, IAsyncRouter} from "./IAsync.sol"; /// @notice Base contract for an Asyncium consumer, in the shape of a VRF consumer: send an intent with /// `_request`, receive exactly one final receipt in `_onReceipt`. Only the router can call `onReceipt`. abstract contract AsyncClient is IAsyncReceiver { IAsyncRouter public immutable asyncRouter; address public asyncOwner; error OnlyRouter(); error OnlyAsyncOwner(); constructor(IAsyncRouter router_, address owner_) { asyncRouter = router_; asyncOwner = owner_; } modifier onlyAsyncOwner() { if (msg.sender != asyncOwner) revert OnlyAsyncOwner(); _; } function setAsyncOwner(address next) external onlyAsyncOwner { asyncOwner = next; } function onReceipt(uint256 intentId, AsyncTypes.Receipt calldata receipt) external { if (msg.sender != address(asyncRouter)) revert OnlyRouter(); _onReceipt(intentId, receipt); } function _request(AsyncTypes.Intent memory intent) internal returns (uint256) { return asyncRouter.request(intent); } function _onReceipt(uint256 intentId, AsyncTypes.Receipt calldata receipt) internal virtual; }