// SPDX-License-Identifier: MIT pragma solidity 0.8.30; interface IQuiverCoordinator { function getFee(address provider) external view returns(uint128); function requestWithCallback(address provider,bytes32 userRandomNumber) external payable returns(uint64); } interface IWinRandomConsumer {function receiveRandomness(uint256 requestId,uint256 word) external;} /** Candidate adapter. Quiver provider withholding/liveness must be reviewed before activation. */ contract WinQuiverAdapter { IQuiverCoordinator public immutable coordinator; address public immutable provider; address public immutable consumer; bytes32 public immutable coordinatorHash; uint256 public nonce; mapping(uint64=>bool) public requested; mapping(uint64=>bool) public delivered; error Unauthorized();error InvalidConfiguration(); constructor(address coordinator_,address provider_,address consumer_,bytes32 expectedHash){ if(coordinator_.code.length==0||consumer_.code.length==0||provider_==address(0)||coordinator_.codehash!=expectedHash)revert InvalidConfiguration(); coordinator=IQuiverCoordinator(coordinator_);provider=provider_;consumer=consumer_;coordinatorHash=expectedHash; } function fee() external view returns(uint256){return coordinator.getFee(provider);} function request(bytes32 commitment) external payable returns(uint256){ if(msg.sender!=consumer)revert Unauthorized(); if(address(coordinator).codehash!=coordinatorHash||msg.value!=coordinator.getFee(provider))revert InvalidConfiguration(); bytes32 contribution=keccak256(abi.encode(block.chainid,address(this),consumer,++nonce,commitment)); uint64 seq=coordinator.requestWithCallback{value:msg.value}(provider,contribution); if(seq==0||requested[seq])revert InvalidConfiguration();requested[seq]=true;return seq; } function quiverCallback(uint64 seq,address provider_,bytes32 word) external { if(msg.sender!=address(coordinator)||provider_!=provider)revert Unauthorized(); if(!requested[seq]||delivered[seq])return; delivered[seq]=true;IWinRandomConsumer(consumer).receiveRandomness(seq,uint256(word)); } }