From 314bac9168d96daf8a3e95f027d7a75e21fc4fe0 Mon Sep 17 00:00:00 2001 From: Brendan Asselstine Date: Thu, 21 Mar 2024 14:24:47 -0700 Subject: [PATCH 1/3] Added natspec to RngWitnet --- .history/src/RngWitnet_20240215162400.sol | 0 .history/src/RngWitnet_20240215162436.sol | 8 --- .history/src/RngWitnet_20240215162634.sol | 68 --------------------- .history/src/RngWitnet_20240215162637.sol | 68 --------------------- .history/src/RngWitnet_20240215162653.sol | 68 --------------------- .history/src/RngWitnet_20240215162654.sol | 68 --------------------- .history/src/RngWitnet_20240215162916.sol | 68 --------------------- .history/src/RngWitnet_20240215162924.sol | 68 --------------------- .history/src/RngWitnet_20240215162925.sol | 68 --------------------- .history/src/RngWitnet_20240215162934.sol | 72 ----------------------- .history/src/RngWitnet_20240215162944.sol | 72 ----------------------- .history/src/RngWitnet_20240215162945.sol | 72 ----------------------- src/RngWitnet.sol | 29 +++++++-- 13 files changed, 23 insertions(+), 706 deletions(-) delete mode 100644 .history/src/RngWitnet_20240215162400.sol delete mode 100644 .history/src/RngWitnet_20240215162436.sol delete mode 100644 .history/src/RngWitnet_20240215162634.sol delete mode 100644 .history/src/RngWitnet_20240215162637.sol delete mode 100644 .history/src/RngWitnet_20240215162653.sol delete mode 100644 .history/src/RngWitnet_20240215162654.sol delete mode 100644 .history/src/RngWitnet_20240215162916.sol delete mode 100644 .history/src/RngWitnet_20240215162924.sol delete mode 100644 .history/src/RngWitnet_20240215162925.sol delete mode 100644 .history/src/RngWitnet_20240215162934.sol delete mode 100644 .history/src/RngWitnet_20240215162944.sol delete mode 100644 .history/src/RngWitnet_20240215162945.sol diff --git a/.history/src/RngWitnet_20240215162400.sol b/.history/src/RngWitnet_20240215162400.sol deleted file mode 100644 index e69de29..0000000 diff --git a/.history/src/RngWitnet_20240215162436.sol b/.history/src/RngWitnet_20240215162436.sol deleted file mode 100644 index 189803f..0000000 --- a/.history/src/RngWitnet_20240215162436.sol +++ /dev/null @@ -1,8 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity ^0.8.19; - -import { RNGInterface } from "rng-contracts/RNGInterface.sol"; - -contract RngWitnet is RNGInterface { - -} \ No newline at end of file diff --git a/.history/src/RngWitnet_20240215162634.sol b/.history/src/RngWitnet_20240215162634.sol deleted file mode 100644 index 703168b..0000000 --- a/.history/src/RngWitnet_20240215162634.sol +++ /dev/null @@ -1,68 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity ^0.8.19; - -import { RNGInterface } from "rng-contracts/RNGInterface.sol"; - -contract RngWitnet is RNGInterface { -/** - * @notice Emitted when a new request for a random number has been submitted - * @param requestId The indexed ID of the request used to get the results of the RNG service - * @param sender The indexed address of the sender of the request - */ - event RandomNumberRequested(uint32 indexed requestId, address indexed sender); - - /** - * @notice Emitted when an existing request for a random number has been completed - * @param requestId The indexed ID of the request used to get the results of the RNG service - * @param randomNumber The random number produced by the 3rd-party service - */ - event RandomNumberCompleted(uint32 indexed requestId, uint256 randomNumber); - - /** - * @notice Gets the last request id used by the RNG service - * @return requestId The last request id used in the last request - */ - function getLastRequestId() external view returns (uint32 requestId) { - - } - - /** - * @notice Gets the Fee for making a Request against an RNG service - * @return feeToken The address of the token that is used to pay fees - * @return requestFee The fee required to be paid to make a request - */ - function getRequestFee() external view returns (address feeToken, uint256 requestFee) { - - } - - /** - * @notice Sends a request for a random number to the 3rd-party service - * @dev Some services will complete the request immediately, others may have a time-delay - * @dev Some services require payment in the form of a token, such as $LINK for Chainlink VRF - * @return requestId The ID of the request used to get the results of the RNG service - * @return lockBlock The block number at which the RNG service will start generating time-delayed randomness. - * The calling contract should "lock" all activity until the result is available via the `requestId` - */ - function requestRandomNumber() external returns (uint32 requestId, uint32 lockBlock) { - - } - - /** - * @notice Checks if the request for randomness from the 3rd-party service has completed - * @dev For time-delayed requests, this function is used to check/confirm completion - * @param requestId The ID of the request used to get the results of the RNG service - * @return isCompleted True if the request has completed and a random number is available, false otherwise - */ - function isRequestComplete(uint32 requestId) external view returns (bool isCompleted) { - - } - - /** - * @notice Gets the random number produced by the 3rd-party service - * @param requestId The ID of the request used to get the results of the RNG service - * @return randomNum The random number - */ - function randomNumber(uint32 requestId) external returns (uint256 randomNum) { - - } -} \ No newline at end of file diff --git a/.history/src/RngWitnet_20240215162637.sol b/.history/src/RngWitnet_20240215162637.sol deleted file mode 100644 index 54f9947..0000000 --- a/.history/src/RngWitnet_20240215162637.sol +++ /dev/null @@ -1,68 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity ^0.8.19; - -import { RNGInterface } from "rng-contracts/RNGInterface.sol"; - -contract RngWitnet is RNGInterface { -/** - * @notice Emitted when a new request for a random number has been submitted - * @param requestId The indexed ID of the request used to get the results of the RNG service - * @param sender The indexed address of the sender of the request - */ - event RandomNumberRequested(uint32 indexed requestId, address indexed sender); - - /** - * @notice Emitted when an existing request for a random number has been completed - * @param requestId The indexed ID of the request used to get the results of the RNG service - * @param randomNumber The random number produced by the 3rd-party service - */ - event RandomNumberCompleted(uint32 indexed requestId, uint256 randomNumber); - - /** - * @notice Gets the last request id used by the RNG service - * @return requestId The last request id used in the last request - */ - function getLastRequestId() external view returns (uint32 requestId) { - - } - - /** - * @notice Gets the Fee for making a Request against an RNG service - * @return feeToken The address of the token that is used to pay fees - * @return requestFee The fee required to be paid to make a request - */ - function getRequestFee() external view returns (address feeToken, uint256 requestFee) { - - } - - /** - * @notice Sends a request for a random number to the 3rd-party service - * @dev Some services will complete the request immediately, others may have a time-delay - * @dev Some services require payment in the form of a token, such as $LINK for Chainlink VRF - * @return requestId The ID of the request used to get the results of the RNG service - * @return lockBlock The block number at which the RNG service will start generating time-delayed randomness. - * The calling contract should "lock" all activity until the result is available via the `requestId` - */ - function requestRandomNumber() external returns (uint32 requestId, uint32 lockBlock) { - - } - - /** - * @notice Checks if the request for randomness from the 3rd-party service has completed - * @dev For time-delayed requests, this function is used to check/confirm completion - * @param requestId The ID of the request used to get the results of the RNG service - * @return isCompleted True if the request has completed and a random number is available, false otherwise - */ - function isRequestComplete(uint32 requestId) external view returns (bool isCompleted) { - - } - - /** - * @notice Gets the random number produced by the 3rd-party service - * @param requestId The ID of the request used to get the results of the RNG service - * @return randomNum The random number - */ - function randomNumber(uint32 requestId) external returns (uint256 randomNum) { - - } -} \ No newline at end of file diff --git a/.history/src/RngWitnet_20240215162653.sol b/.history/src/RngWitnet_20240215162653.sol deleted file mode 100644 index 54f9947..0000000 --- a/.history/src/RngWitnet_20240215162653.sol +++ /dev/null @@ -1,68 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity ^0.8.19; - -import { RNGInterface } from "rng-contracts/RNGInterface.sol"; - -contract RngWitnet is RNGInterface { -/** - * @notice Emitted when a new request for a random number has been submitted - * @param requestId The indexed ID of the request used to get the results of the RNG service - * @param sender The indexed address of the sender of the request - */ - event RandomNumberRequested(uint32 indexed requestId, address indexed sender); - - /** - * @notice Emitted when an existing request for a random number has been completed - * @param requestId The indexed ID of the request used to get the results of the RNG service - * @param randomNumber The random number produced by the 3rd-party service - */ - event RandomNumberCompleted(uint32 indexed requestId, uint256 randomNumber); - - /** - * @notice Gets the last request id used by the RNG service - * @return requestId The last request id used in the last request - */ - function getLastRequestId() external view returns (uint32 requestId) { - - } - - /** - * @notice Gets the Fee for making a Request against an RNG service - * @return feeToken The address of the token that is used to pay fees - * @return requestFee The fee required to be paid to make a request - */ - function getRequestFee() external view returns (address feeToken, uint256 requestFee) { - - } - - /** - * @notice Sends a request for a random number to the 3rd-party service - * @dev Some services will complete the request immediately, others may have a time-delay - * @dev Some services require payment in the form of a token, such as $LINK for Chainlink VRF - * @return requestId The ID of the request used to get the results of the RNG service - * @return lockBlock The block number at which the RNG service will start generating time-delayed randomness. - * The calling contract should "lock" all activity until the result is available via the `requestId` - */ - function requestRandomNumber() external returns (uint32 requestId, uint32 lockBlock) { - - } - - /** - * @notice Checks if the request for randomness from the 3rd-party service has completed - * @dev For time-delayed requests, this function is used to check/confirm completion - * @param requestId The ID of the request used to get the results of the RNG service - * @return isCompleted True if the request has completed and a random number is available, false otherwise - */ - function isRequestComplete(uint32 requestId) external view returns (bool isCompleted) { - - } - - /** - * @notice Gets the random number produced by the 3rd-party service - * @param requestId The ID of the request used to get the results of the RNG service - * @return randomNum The random number - */ - function randomNumber(uint32 requestId) external returns (uint256 randomNum) { - - } -} \ No newline at end of file diff --git a/.history/src/RngWitnet_20240215162654.sol b/.history/src/RngWitnet_20240215162654.sol deleted file mode 100644 index 54f9947..0000000 --- a/.history/src/RngWitnet_20240215162654.sol +++ /dev/null @@ -1,68 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity ^0.8.19; - -import { RNGInterface } from "rng-contracts/RNGInterface.sol"; - -contract RngWitnet is RNGInterface { -/** - * @notice Emitted when a new request for a random number has been submitted - * @param requestId The indexed ID of the request used to get the results of the RNG service - * @param sender The indexed address of the sender of the request - */ - event RandomNumberRequested(uint32 indexed requestId, address indexed sender); - - /** - * @notice Emitted when an existing request for a random number has been completed - * @param requestId The indexed ID of the request used to get the results of the RNG service - * @param randomNumber The random number produced by the 3rd-party service - */ - event RandomNumberCompleted(uint32 indexed requestId, uint256 randomNumber); - - /** - * @notice Gets the last request id used by the RNG service - * @return requestId The last request id used in the last request - */ - function getLastRequestId() external view returns (uint32 requestId) { - - } - - /** - * @notice Gets the Fee for making a Request against an RNG service - * @return feeToken The address of the token that is used to pay fees - * @return requestFee The fee required to be paid to make a request - */ - function getRequestFee() external view returns (address feeToken, uint256 requestFee) { - - } - - /** - * @notice Sends a request for a random number to the 3rd-party service - * @dev Some services will complete the request immediately, others may have a time-delay - * @dev Some services require payment in the form of a token, such as $LINK for Chainlink VRF - * @return requestId The ID of the request used to get the results of the RNG service - * @return lockBlock The block number at which the RNG service will start generating time-delayed randomness. - * The calling contract should "lock" all activity until the result is available via the `requestId` - */ - function requestRandomNumber() external returns (uint32 requestId, uint32 lockBlock) { - - } - - /** - * @notice Checks if the request for randomness from the 3rd-party service has completed - * @dev For time-delayed requests, this function is used to check/confirm completion - * @param requestId The ID of the request used to get the results of the RNG service - * @return isCompleted True if the request has completed and a random number is available, false otherwise - */ - function isRequestComplete(uint32 requestId) external view returns (bool isCompleted) { - - } - - /** - * @notice Gets the random number produced by the 3rd-party service - * @param requestId The ID of the request used to get the results of the RNG service - * @return randomNum The random number - */ - function randomNumber(uint32 requestId) external returns (uint256 randomNum) { - - } -} \ No newline at end of file diff --git a/.history/src/RngWitnet_20240215162916.sol b/.history/src/RngWitnet_20240215162916.sol deleted file mode 100644 index 13f0797..0000000 --- a/.history/src/RngWitnet_20240215162916.sol +++ /dev/null @@ -1,68 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity ^0.8.19; - -import { RNGInterface } from "rng-contracts/RNGInterface.sol"; - -contract RngWitnet is RNGInterface { -/** - * @notice Emitted when a new request for a random number has been submitted - * @param requestId The indexed ID of the request used to get the results of the RNG service - * @param sender The indexed address of the sender of the request - */ - event RandomNumberRequested(uint32 indexed requestId, address indexed sender); - - /** - * @notice Emitted when an existing request for a random number has been completed - * @param requestId The indexed ID of the request used to get the results of the RNG service - * @param randomNumber The random number produced by the 3rd-party service - */ - event RandomNumberCompleted(uint32 indexed requestId, uint256 randomNumber); - - /** - * @notice Gets the last request id used by the RNG service - * @return requestId The last request id used in the last request - */ - function getLastRequestId() external view returns (uint32 requestId) { - - } - - /** - * @notice Gets the Fee for making a Request against an RNG service - * @return feeToken The address of the token that is used to pay fees - * @return requestFee The fee required to be paid to make a request - */ - function getRequestFee() external view returns (address feeToken, uint256 requestFee) { - - } - - /** - * @notice Sends a request for a random number to the 3rd-party service - * @dev Some services will complete the request immediately, others may have a time-delay - * @dev Some services require payment in the form of a token, such as $LINK for Chainlink VRF - * @return requestId The ID of the request used to get the results of the RNG service - * @return lockBlock The block number at which the RNG service will start generating time-delayed randomness. - * The calling contract should "lock" all activity until the result is available via the `requestId` - */ - function requestRandomNumber() external returns (uint32 requestId, uint32 lockBlock) { - - } - - /** - * @notice Checks if the request for randomness from the 3rd-party service has completed - * @dev For time-delayed requests, this function is used to check/confirm completion - * @param requestId The ID of the request used to get the results of the RNG service - * @return isCompleted True if the request has completed and a random number is available, false otherwise - */ - function isRequestComplete(uint32 requestId) external view returns (bool isCompleted) { - - } - - /** - * @notice Gets the random number produced by the 3rd-party service - * @param requestId The ID of the request used to get the results of the RNG service - * @return randomNum The random number - */ - function randomNumber(uint32 requestId) external returns (uint256 randomNum) { - - } -} \ No newline at end of file diff --git a/.history/src/RngWitnet_20240215162924.sol b/.history/src/RngWitnet_20240215162924.sol deleted file mode 100644 index a2ff8c6..0000000 --- a/.history/src/RngWitnet_20240215162924.sol +++ /dev/null @@ -1,68 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity ^0.8.19; - -import { RNGInterface } from "rng-contracts/RNGInterface.sol"; - -contract RngWitnet is RNGInterface { - /** - * @notice Emitted when a new request for a random number has been submitted - * @param requestId The indexed ID of the request used to get the results of the RNG service - * @param sender The indexed address of the sender of the request - */ - event RandomNumberRequested(uint32 indexed requestId, address indexed sender); - - /** - * @notice Emitted when an existing request for a random number has been completed - * @param requestId The indexed ID of the request used to get the results of the RNG service - * @param randomNumber The random number produced by the 3rd-party service - */ - event RandomNumberCompleted(uint32 indexed requestId, uint256 randomNumber); - - /** - * @notice Gets the last request id used by the RNG service - * @return requestId The last request id used in the last request - */ - function getLastRequestId() external view returns (uint32 requestId) { - - } - - /** - * @notice Gets the Fee for making a Request against an RNG service - * @return feeToken The address of the token that is used to pay fees - * @return requestFee The fee required to be paid to make a request - */ - function getRequestFee() external view returns (address feeToken, uint256 requestFee) { - - } - - /** - * @notice Sends a request for a random number to the 3rd-party service - * @dev Some services will complete the request immediately, others may have a time-delay - * @dev Some services require payment in the form of a token, such as $LINK for Chainlink VRF - * @return requestId The ID of the request used to get the results of the RNG service - * @return lockBlock The block number at which the RNG service will start generating time-delayed randomness. - * The calling contract should "lock" all activity until the result is available via the `requestId` - */ - function requestRandomNumber() external returns (uint32 requestId, uint32 lockBlock) { - - } - - /** - * @notice Checks if the request for randomness from the 3rd-party service has completed - * @dev For time-delayed requests, this function is used to check/confirm completion - * @param requestId The ID of the request used to get the results of the RNG service - * @return isCompleted True if the request has completed and a random number is available, false otherwise - */ - function isRequestComplete(uint32 requestId) external view returns (bool isCompleted) { - - } - - /** - * @notice Gets the random number produced by the 3rd-party service - * @param requestId The ID of the request used to get the results of the RNG service - * @return randomNum The random number - */ - function randomNumber(uint32 requestId) external returns (uint256 randomNum) { - - } -} \ No newline at end of file diff --git a/.history/src/RngWitnet_20240215162925.sol b/.history/src/RngWitnet_20240215162925.sol deleted file mode 100644 index a2ff8c6..0000000 --- a/.history/src/RngWitnet_20240215162925.sol +++ /dev/null @@ -1,68 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity ^0.8.19; - -import { RNGInterface } from "rng-contracts/RNGInterface.sol"; - -contract RngWitnet is RNGInterface { - /** - * @notice Emitted when a new request for a random number has been submitted - * @param requestId The indexed ID of the request used to get the results of the RNG service - * @param sender The indexed address of the sender of the request - */ - event RandomNumberRequested(uint32 indexed requestId, address indexed sender); - - /** - * @notice Emitted when an existing request for a random number has been completed - * @param requestId The indexed ID of the request used to get the results of the RNG service - * @param randomNumber The random number produced by the 3rd-party service - */ - event RandomNumberCompleted(uint32 indexed requestId, uint256 randomNumber); - - /** - * @notice Gets the last request id used by the RNG service - * @return requestId The last request id used in the last request - */ - function getLastRequestId() external view returns (uint32 requestId) { - - } - - /** - * @notice Gets the Fee for making a Request against an RNG service - * @return feeToken The address of the token that is used to pay fees - * @return requestFee The fee required to be paid to make a request - */ - function getRequestFee() external view returns (address feeToken, uint256 requestFee) { - - } - - /** - * @notice Sends a request for a random number to the 3rd-party service - * @dev Some services will complete the request immediately, others may have a time-delay - * @dev Some services require payment in the form of a token, such as $LINK for Chainlink VRF - * @return requestId The ID of the request used to get the results of the RNG service - * @return lockBlock The block number at which the RNG service will start generating time-delayed randomness. - * The calling contract should "lock" all activity until the result is available via the `requestId` - */ - function requestRandomNumber() external returns (uint32 requestId, uint32 lockBlock) { - - } - - /** - * @notice Checks if the request for randomness from the 3rd-party service has completed - * @dev For time-delayed requests, this function is used to check/confirm completion - * @param requestId The ID of the request used to get the results of the RNG service - * @return isCompleted True if the request has completed and a random number is available, false otherwise - */ - function isRequestComplete(uint32 requestId) external view returns (bool isCompleted) { - - } - - /** - * @notice Gets the random number produced by the 3rd-party service - * @param requestId The ID of the request used to get the results of the RNG service - * @return randomNum The random number - */ - function randomNumber(uint32 requestId) external returns (uint256 randomNum) { - - } -} \ No newline at end of file diff --git a/.history/src/RngWitnet_20240215162934.sol b/.history/src/RngWitnet_20240215162934.sol deleted file mode 100644 index 4185dbd..0000000 --- a/.history/src/RngWitnet_20240215162934.sol +++ /dev/null @@ -1,72 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity ^0.8.19; - -import { RNGInterface } from "rng-contracts/RNGInterface.sol"; - -contract RngWitnet is RNGInterface { - /** - * @notice Emitted when a new request for a random number has been submitted - * @param requestId The indexed ID of the request used to get the results of the RNG service - * @param sender The indexed address of the sender of the request - */ - event RandomNumberRequested(uint32 indexed requestId, address indexed sender); - - /** - * @notice Emitted when an existing request for a random number has been completed - * @param requestId The indexed ID of the request used to get the results of the RNG service - * @param randomNumber The random number produced by the 3rd-party service - */ - event RandomNumberCompleted(uint32 indexed requestId, uint256 randomNumber); - - constructor() { - - } - - /** - * @notice Gets the last request id used by the RNG service - * @return requestId The last request id used in the last request - */ - function getLastRequestId() external view returns (uint32 requestId) { - - } - - /** - * @notice Gets the Fee for making a Request against an RNG service - * @return feeToken The address of the token that is used to pay fees - * @return requestFee The fee required to be paid to make a request - */ - function getRequestFee() external view returns (address feeToken, uint256 requestFee) { - - } - - /** - * @notice Sends a request for a random number to the 3rd-party service - * @dev Some services will complete the request immediately, others may have a time-delay - * @dev Some services require payment in the form of a token, such as $LINK for Chainlink VRF - * @return requestId The ID of the request used to get the results of the RNG service - * @return lockBlock The block number at which the RNG service will start generating time-delayed randomness. - * The calling contract should "lock" all activity until the result is available via the `requestId` - */ - function requestRandomNumber() external returns (uint32 requestId, uint32 lockBlock) { - - } - - /** - * @notice Checks if the request for randomness from the 3rd-party service has completed - * @dev For time-delayed requests, this function is used to check/confirm completion - * @param requestId The ID of the request used to get the results of the RNG service - * @return isCompleted True if the request has completed and a random number is available, false otherwise - */ - function isRequestComplete(uint32 requestId) external view returns (bool isCompleted) { - - } - - /** - * @notice Gets the random number produced by the 3rd-party service - * @param requestId The ID of the request used to get the results of the RNG service - * @return randomNum The random number - */ - function randomNumber(uint32 requestId) external returns (uint256 randomNum) { - - } -} \ No newline at end of file diff --git a/.history/src/RngWitnet_20240215162944.sol b/.history/src/RngWitnet_20240215162944.sol deleted file mode 100644 index 0a57eb8..0000000 --- a/.history/src/RngWitnet_20240215162944.sol +++ /dev/null @@ -1,72 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity ^0.8.19; - -import { RNGInterface } from "rng-contracts/RNGInterface.sol"; - -contract RngWitnet is RNGInterface { - /** - * @notice Emitted when a new request for a random number has been submitted - * @param requestId The indexed ID of the request used to get the results of the RNG service - * @param sender The indexed address of the sender of the request - */ - event RandomNumberRequested(uint32 indexed requestId, address indexed sender); - - /** - * @notice Emitted when an existing request for a random number has been completed - * @param requestId The indexed ID of the request used to get the results of the RNG service - * @param randomNumber The random number produced by the 3rd-party service - */ - event RandomNumberCompleted(uint32 indexed requestId, uint256 randomNumber); - - constructor() public { - - } - - /** - * @notice Gets the last request id used by the RNG service - * @return requestId The last request id used in the last request - */ - function getLastRequestId() external view returns (uint32 requestId) { - - } - - /** - * @notice Gets the Fee for making a Request against an RNG service - * @return feeToken The address of the token that is used to pay fees - * @return requestFee The fee required to be paid to make a request - */ - function getRequestFee() external view returns (address feeToken, uint256 requestFee) { - - } - - /** - * @notice Sends a request for a random number to the 3rd-party service - * @dev Some services will complete the request immediately, others may have a time-delay - * @dev Some services require payment in the form of a token, such as $LINK for Chainlink VRF - * @return requestId The ID of the request used to get the results of the RNG service - * @return lockBlock The block number at which the RNG service will start generating time-delayed randomness. - * The calling contract should "lock" all activity until the result is available via the `requestId` - */ - function requestRandomNumber() external returns (uint32 requestId, uint32 lockBlock) { - - } - - /** - * @notice Checks if the request for randomness from the 3rd-party service has completed - * @dev For time-delayed requests, this function is used to check/confirm completion - * @param requestId The ID of the request used to get the results of the RNG service - * @return isCompleted True if the request has completed and a random number is available, false otherwise - */ - function isRequestComplete(uint32 requestId) external view returns (bool isCompleted) { - - } - - /** - * @notice Gets the random number produced by the 3rd-party service - * @param requestId The ID of the request used to get the results of the RNG service - * @return randomNum The random number - */ - function randomNumber(uint32 requestId) external returns (uint256 randomNum) { - - } -} \ No newline at end of file diff --git a/.history/src/RngWitnet_20240215162945.sol b/.history/src/RngWitnet_20240215162945.sol deleted file mode 100644 index 0a57eb8..0000000 --- a/.history/src/RngWitnet_20240215162945.sol +++ /dev/null @@ -1,72 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity ^0.8.19; - -import { RNGInterface } from "rng-contracts/RNGInterface.sol"; - -contract RngWitnet is RNGInterface { - /** - * @notice Emitted when a new request for a random number has been submitted - * @param requestId The indexed ID of the request used to get the results of the RNG service - * @param sender The indexed address of the sender of the request - */ - event RandomNumberRequested(uint32 indexed requestId, address indexed sender); - - /** - * @notice Emitted when an existing request for a random number has been completed - * @param requestId The indexed ID of the request used to get the results of the RNG service - * @param randomNumber The random number produced by the 3rd-party service - */ - event RandomNumberCompleted(uint32 indexed requestId, uint256 randomNumber); - - constructor() public { - - } - - /** - * @notice Gets the last request id used by the RNG service - * @return requestId The last request id used in the last request - */ - function getLastRequestId() external view returns (uint32 requestId) { - - } - - /** - * @notice Gets the Fee for making a Request against an RNG service - * @return feeToken The address of the token that is used to pay fees - * @return requestFee The fee required to be paid to make a request - */ - function getRequestFee() external view returns (address feeToken, uint256 requestFee) { - - } - - /** - * @notice Sends a request for a random number to the 3rd-party service - * @dev Some services will complete the request immediately, others may have a time-delay - * @dev Some services require payment in the form of a token, such as $LINK for Chainlink VRF - * @return requestId The ID of the request used to get the results of the RNG service - * @return lockBlock The block number at which the RNG service will start generating time-delayed randomness. - * The calling contract should "lock" all activity until the result is available via the `requestId` - */ - function requestRandomNumber() external returns (uint32 requestId, uint32 lockBlock) { - - } - - /** - * @notice Checks if the request for randomness from the 3rd-party service has completed - * @dev For time-delayed requests, this function is used to check/confirm completion - * @param requestId The ID of the request used to get the results of the RNG service - * @return isCompleted True if the request has completed and a random number is available, false otherwise - */ - function isRequestComplete(uint32 requestId) external view returns (bool isCompleted) { - - } - - /** - * @notice Gets the random number produced by the 3rd-party service - * @param requestId The ID of the request used to get the results of the RNG service - * @return randomNum The random number - */ - function randomNumber(uint32 requestId) external returns (uint256 randomNum) { - - } -} \ No newline at end of file diff --git a/src/RngWitnet.sol b/src/RngWitnet.sol index c74900f..6b56443 100644 --- a/src/RngWitnet.sol +++ b/src/RngWitnet.sol @@ -7,26 +7,41 @@ import { DrawManager } from "pt-v5-draw-manager/DrawManager.sol"; import { Requestor } from "./Requestor.sol"; + +/// @title RngWitnet +/// @notice A contract that requests random numbers from the Witnet Randomness Oracle contract RngWitnet is IRng { - error NoPayment(); + /// @notice Emitted when a new random number is requested + /// @param requestId The id of the request + /// @param sender The address that requested the random number event RandomNumberRequested( uint32 indexed requestId, address indexed sender ); - + + /// @notice The Witnet Randomness contract IWitnetRandomness public immutable witnetRandomness; + /// @notice A mapping of addresses that requested RNG to their corresponding Requestor contract mapping(address user => Requestor) public requestors; + /// @notice The last request id used by the RNG service uint32 public lastRequestId; + /// @notice A mapping of request ids to the block number at which the request was made mapping(uint32 requestId => uint256 lockBlock) public requests; + /// @notice Creates a new instance of the RngWitnet contract + /// @param _witnetRandomness The address of the Witnet Randomness contract to use constructor(IWitnetRandomness _witnetRandomness) { witnetRandomness = _witnetRandomness; } + /// @notice Gets the Requestor contract for the given user. Creates a new one if it doesn't exist + /// @dev The Requestor contract holds the balance of Ether that a user has sent, so that they can withdraw + /// @param user The address of the user + /// @return The Requestor contract for the given user function getRequestor(address user) public returns (Requestor) { Requestor requestor = requestors[user]; if (address(requestor) == address(0)) { @@ -36,18 +51,20 @@ contract RngWitnet is IRng { return requestor; } + /// @notice Gets the block number at which the request was made + /// @param requestId The ID of the request used to get the results of the RNG service + /// @return The block number at which the request was made function requestedAtBlock(uint32 requestId) external override view returns (uint256) { return requests[requestId]; } - /** - * @notice Gets the last request id used by the RNG service - * @return requestId The last request id used in the last request - */ + /// @notice Gets the last request id used by the RNG service + /// @return requestId The last request id used in the last request function getLastRequestId() external view returns (uint32 requestId) { return lastRequestId; } + /// @notice Estimates the cost of the witnet randomness request function estimateRandomizeFee(uint256 _gasPrice) external view returns (uint256) { return witnetRandomness.estimateRandomizeFee(_gasPrice); } From cfb82955ecb11616cd93a027c228911249ec63e5 Mon Sep 17 00:00:00 2001 From: Brendan Asselstine Date: Thu, 21 Mar 2024 14:34:25 -0700 Subject: [PATCH 2/3] Added to Readme --- README.md | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index f49f75b..a05e622 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,6 @@ -# Foundry template +# PoolTogether RNG Witnet 0.7 integration -Template to kickstart a Foundry project. - -## Getting started - -The easiest way to get started is by clicking the [Use this template](https://github.com/GenerationSoftware/foundry-template/generate) button at the top right of this page. - -If you prefer to go the CLI way: - -``` -forge init my-project --template https://github.com/GenerationSoftware/foundry-template -``` +This is an RNG interface for Witnet 0.7 ## Development From a607aa6c160b9e2c7408af9b8234e726e0df2c9c Mon Sep 17 00:00:00 2001 From: Brendan Asselstine Date: Thu, 21 Mar 2024 15:03:05 -0700 Subject: [PATCH 3/3] Updated Draw Manager --- foundry.toml | 2 +- lib/pt-v5-draw-manager | 2 +- src/Requestor.sol | 25 ++++++++++++++++---- src/RngWitnet.sol | 44 +++++++++++++++++++++-------------- test/RngWitnet.t.sol | 4 ++-- test/fork/RngWitnetFork.t.sol | 4 ++-- 6 files changed, 53 insertions(+), 28 deletions(-) diff --git a/foundry.toml b/foundry.toml index e5a5796..f496c0e 100644 --- a/foundry.toml +++ b/foundry.toml @@ -3,7 +3,7 @@ src = 'src' out = 'out' test = 'test' libs = ['lib'] -solc = "0.8.21" +solc = "0.8.24" fs_permissions = [{ access = "read", path = "./broadcast" }] gas_reports = ["Foo"] diff --git a/lib/pt-v5-draw-manager b/lib/pt-v5-draw-manager index 1a28a8f..64cc3e4 160000 --- a/lib/pt-v5-draw-manager +++ b/lib/pt-v5-draw-manager @@ -1 +1 @@ -Subproject commit 1a28a8fcaff057c52f7599ea8294e01d965de686 +Subproject commit 64cc3e4608e4b3e13c5acf922ae2579469c2e95c diff --git a/src/Requestor.sol b/src/Requestor.sol index d29fa00..9f587db 100644 --- a/src/Requestor.sol +++ b/src/Requestor.sol @@ -1,31 +1,48 @@ // SPDX-License-Identifier: MIT -pragma solidity ^0.8.19; +pragma solidity ^0.8.24; import { IWitnetRandomness } from "witnet/interfaces/IWitnetRandomness.sol"; +/// @title Requestor +/// @notice A contract that requests random numbers from the Witnet Randomness Oracle. Holds the unused balance of Ether. contract Requestor { + /// @notice Thrown when a new random number is requested error NotCreator(); + /// @notice The address of the creator of the contract (RngWitnet) address public immutable creator; + /// @notice Creates a new instance of the Requestor contract and sets the creator as the sender constructor() { creator = msg.sender; } + /// @notice Requests a random number from the Witnet Randomness Oracle + /// @dev You can send Ether along with this call + /// @param value The amount of Ether to send to the Witnet Randomness Oracle + /// @param _witnetRandomness The Witnet Randomness Oracle contract function randomize(uint value, IWitnetRandomness _witnetRandomness) external payable onlyCreator { _witnetRandomness.randomize{ value: value }(); } - function withdraw(address payable _to) external onlyCreator { - _to.transfer(address(this).balance); + /// @notice Withdraws the balance of the contract to the specified address + /// @dev can only be called the creator of the contract (RngWitnet) + /// @param _to The address to which the balance will be sent + /// @return The balance of the contract that was transferred + function withdraw(address payable _to) external onlyCreator returns (uint256) { + uint balance = address(this).balance; + _to.transfer(balance); + return balance; } + /// @notice Allows receive of ether receive() payable external {} + /// @notice Modifier to only allow calls by the creator modifier onlyCreator() { if(msg.sender != address(creator)) { revert NotCreator(); } _; } -} \ No newline at end of file +} diff --git a/src/RngWitnet.sol b/src/RngWitnet.sol index 6b56443..6c00c8d 100644 --- a/src/RngWitnet.sol +++ b/src/RngWitnet.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity ^0.8.19; +pragma solidity ^0.8.24; import { IWitnetRandomness } from "witnet/interfaces/IWitnetRandomness.sol"; import { IRng } from "pt-v5-draw-manager/interfaces/IRng.sol"; @@ -7,7 +7,6 @@ import { DrawManager } from "pt-v5-draw-manager/DrawManager.sol"; import { Requestor } from "./Requestor.sol"; - /// @title RngWitnet /// @notice A contract that requests random numbers from the Witnet Randomness Oracle contract RngWitnet is IRng { @@ -65,10 +64,16 @@ contract RngWitnet is IRng { } /// @notice Estimates the cost of the witnet randomness request + /// @param _gasPrice The gas price that would be used for the randomize() request + /// @return The estimated gas cost of the randomize() request function estimateRandomizeFee(uint256 _gasPrice) external view returns (uint256) { return witnetRandomness.estimateRandomizeFee(_gasPrice); } + /// @notice Requests a random number from the Witnet Randomness Oracle + /// @param rngPaymentAmount The amount of Ether to send to the Witnet Randomness Oracle. This amount should be sent in this call, remaining from a previous call, or a combination thereof. The Requestor holds the current balance. + /// @return requestId The id of the request + /// @return lockBlock The block number at which the request was made function requestRandomNumber(uint256 rngPaymentAmount) public payable returns (uint32 requestId, uint256 lockBlock) { Requestor requestor = getRequestor(msg.sender); unchecked { @@ -81,32 +86,35 @@ contract RngWitnet is IRng { emit RandomNumberRequested(requestId, msg.sender); } - function withdraw() external { + /// @notice Withdraws the balance of the Requestor contract of the caller + /// @return The amount of Ether withdrawn + function withdraw() external returns (uint256) { Requestor requestor = requestors[msg.sender]; - requestor.withdraw(payable(msg.sender)); + return requestor.withdraw(payable(msg.sender)); } - /** - * @notice Checks if the request for randomness from the 3rd-party service has completed - * @dev For time-delayed requests, this function is used to check/confirm completion - * @param requestId The ID of the request used to get the results of the RNG service - * @return isCompleted True if the request has completed and a random number is available, false otherwise - */ + /// @notice Checks if the request for randomness from the 3rd-party service has completed + /// @dev For time-delayed requests, this function is used to check/confirm completion + /// @param requestId The ID of the request used to get the results of the RNG service + /// @return isCompleted True if the request has completed and a random number is available, false otherwise function isRequestComplete(uint32 requestId) external view returns (bool isCompleted) { return witnetRandomness.isRandomized(requests[requestId]); } - /** - * @notice Gets the random number produced by the 3rd-party service - * @param requestId The ID of the request used to get the results of the RNG service - * @return randomNum The random number - */ + /// @notice Gets the random number produced by the 3rd-party service + /// @param requestId The ID of the request used to get the results of the RNG service + /// @return randomNum The random number function randomNumber(uint32 requestId) external view returns (uint256 randomNum) { return uint256(witnetRandomness.getRandomnessAfter(requests[requestId])); } - function startDraw(uint256 rngPaymentAmount, DrawManager _drawManager, address _rewardRecipient) external payable { + /// @notice Starts a draw using the random number from the Witnet Randomness Oracle + /// @param rngPaymentAmount The amount of Ether to send to the Witnet Randomness Oracle + /// @param _drawManager The DrawManager contract to call + /// @param _rewardRecipient The address of the reward recipient + /// @return The id of the draw + function startDraw(uint256 rngPaymentAmount, DrawManager _drawManager, address _rewardRecipient) external payable returns (uint24) { (uint32 requestId,) = requestRandomNumber(rngPaymentAmount); - _drawManager.startDraw(_rewardRecipient, requestId); + return _drawManager.startDraw(_rewardRecipient, requestId); } -} +} \ No newline at end of file diff --git a/test/RngWitnet.t.sol b/test/RngWitnet.t.sol index 13446f7..d7a7d50 100644 --- a/test/RngWitnet.t.sol +++ b/test/RngWitnet.t.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: GPL-3.0 -pragma solidity ^0.8.21; +pragma solidity ^0.8.24; import "forge-std/Test.sol"; import "forge-std/console2.sol"; @@ -29,7 +29,7 @@ contract RngWitnetTest is Test { function testStartDraw() public { DrawManager drawManager = DrawManager(makeAddr("DrawManager")); - vm.mockCall(address(drawManager), abi.encodeWithSelector(drawManager.startDraw.selector, address(this), 1), abi.encode()); + vm.mockCall(address(drawManager), abi.encodeWithSelector(drawManager.startDraw.selector, address(this), 1), abi.encode(1)); vm.mockCall(address(witnetRandomness), 1e18, abi.encodeWithSelector(IWitnetRandomness.randomize.selector), abi.encode(0.5e18)); rngWitnet.startDraw{value: 1e18}(1e18, drawManager, address(this)); assertEq(address(rngWitnet.getRequestor(address(this))).balance, 1e18, "witnet balance should be 1e18"); diff --git a/test/fork/RngWitnetFork.t.sol b/test/fork/RngWitnetFork.t.sol index 420a3e3..369f080 100644 --- a/test/fork/RngWitnetFork.t.sol +++ b/test/fork/RngWitnetFork.t.sol @@ -15,9 +15,9 @@ contract RngWitnetForkTest is Test { uint256 fork; function setUp() public { - fork = vm.createFork("optimism-goerli"); + fork = vm.createFork("sepolia"); vm.selectFork(fork); - witnetRandomness = IWitnetRandomness(0x0123456fbBC59E181D76B6Fe8771953d1953B51a); + witnetRandomness = IWitnetRandomness(0xa579563E3ee6884e3b4cdE1BBb2fF6305686A83f); rngWitnet = new RngWitnet(witnetRandomness); vm.deal(address(this), 1000e18); }