TicketConsumer
Inherits: EIP712Upgradeable, ReentrancyGuardUpgradeable, PausableUpgradeable, AccessControlUpgradeable
Author: Mure
Contract to record commitments and consume Tickets associated with the Ticket and Pool contract
Utilizes the beacon proxy pattern to deploy multiple proxies, each representing a distinct application within the protocol. Implements the EIP-712 standard for signature validation, preventing unauthorized access. Security measures include the OpenZeppelin PausableUpgradeable pattern for emergency pausing, ReentrancyGuardUpgradeable to prevent reentrancy attacks, and role based access control through AccessControlUpgradeable.
State Variables
ADMIN_ROLE
Role allows user to update contract configurations
bytes32 public constant ADMIN_ROLE = keccak256("TICKET_CONSUMER_ADMIN");
TicketConsumerStorageLocation
Hash for storage location
keccak256(abi.encode(uint256(keccak256("mure.TicketConsumer")) - 1)) & ~bytes32(uint256(0xff))
bytes32 private constant TicketConsumerStorageLocation =
0xa517efc6fde9e1a3d05cb7ac467254548b2bee1ce4290b0a81a21700967a6300;
COMMIT_TICKET_HASH
Struct hash for validating ticket commitment
keccak256("CommitTickets(uint256 quantity,address committer,string pool,uint256 amount)")
bytes32 private constant COMMIT_TICKET_HASH = 0x94ff97a6bb66dc5d656631dfe6b320f3b5cd4350fb456819848e7526cd060f8a;
Functions
constructor
constructor();
initialize
function initialize(
ContractConfiguration calldata contractConfig,
address admin_,
string calldata name_,
string calldata version_
) external initializer;
commitTicket
Deposit a ticket to commit to a round.
Burns the deposited ticket and registers commitment.
function commitTicket(string calldata poolName, uint256 quantity, bytes calldata sig) external;
Parameters
Name | Type | Description |
---|---|---|
poolName | string | name of the pool |
quantity | uint256 | the amount of $TICKET to burn. |
sig | bytes | the signature to authorize commitment. |
commitTicketAndDeposit
Deposit a ticket to commit to a round and deposits the committed amount to the pool.
Burns the deposited ticket and registers commitment. Deposits amount to the configured pool.
function commitTicketAndDeposit(
uint256 quantity,
uint256 depositAmount,
string calldata poolName,
bytes calldata sig,
bytes calldata depositSig,
bytes calldata permitSig
) external;
Parameters
Name | Type | Description |
---|---|---|
quantity | uint256 | the amount of $TICKET to burn. |
depositAmount | uint256 | |
poolName | string | |
sig | bytes | the signature to authorize commitment. |
depositSig | bytes | signature for MurePool deposit authorization. |
permitSig | bytes | signature for MurePool depositFor permit. |
getPoolConfig
Returns the pool deposit range and total allotment.
function getPoolConfig(string calldata poolName) external view returns (uint256, uint256, uint256, uint256);
Parameters
Name | Type | Description |
---|---|---|
poolName | string | name of the pool |
getContractConfig
Returns the ticket address set on the contract.
function getContractConfig() external view returns (ContractConfiguration memory);
getTicketAddress
Returns the ticket address set on the contract.
function getTicketAddress() external view returns (address);
getCommittedTickets
Returns the signer address set on the contract.
function getCommittedTickets(string calldata poolName, address committer) external view returns (uint256);
Parameters
Name | Type | Description |
---|---|---|
poolName | string | name of the pool |
committer | address | address of the committer |
setPoolConfiguration
Updates the pool configuration for deposits.
function setPoolConfiguration(
string calldata poolName,
uint256 minimumDepositAmount,
uint256 maximumDepositAmount,
uint256 commitmentStartTime,
uint256 commitmentEndTime
) external onlyRole(ADMIN_ROLE);
Parameters
Name | Type | Description |
---|---|---|
poolName | string | name of the pool |
minimumDepositAmount | uint256 | minimum base deposit amount for pool per ticket |
maximumDepositAmount | uint256 | maximum deposit amount for pool per ticket |
commitmentStartTime | uint256 | epoch timestamp for when commitments should start |
commitmentEndTime | uint256 | epoch timestamp for when commitments should end |
setContractConfiguration
Updates the pool configuration for deposits.
function setContractConfiguration(ContractConfiguration calldata contractConfig) external onlyRole(ADMIN_ROLE);
Parameters
Name | Type | Description |
---|---|---|
contractConfig | ContractConfiguration | base contract configuration |
setCommitmentsPaused
Updates the pool configuration for deposits.
function setCommitmentsPaused(bool paused) external onlyRole(ADMIN_ROLE);
Parameters
Name | Type | Description |
---|---|---|
paused | bool | boolean to define if commitments are paused |
_depositFunds
Deposits committed amount into the pool.
function _depositFunds(
address from,
uint256 amount,
string calldata poolName,
bytes calldata depositSig,
bytes calldata permitSig
) private nonReentrant;
_consumeTicket
Consumes tickets.
Burns the deposited tickets and registers commitment.
function _consumeTicket(address from, uint256 quantity, string calldata poolName, uint256 depositedAmount) private;
isPoolCommitmentActive
Checks if commitments for the specified pool are active.
function isPoolCommitmentActive(string calldata poolName) private view returns (bool);
Parameters
Name | Type | Description |
---|---|---|
poolName | string | the name of the pool to check if it is active |
_getStorage
Retrieves the storage for the TicketConsumer contract.
function _getStorage() private pure returns (TicketConsumerStorage storage $);
_hashCommit
Generates a hashed representation of the specified quantity and committer address.
function _hashCommit(uint256 quantity, address committer, string calldata poolName, uint256 depositAmount)
private
view
returns (bytes32);
Parameters
Name | Type | Description |
---|---|---|
quantity | uint256 | the quantity to commit |
committer | address | address of the committer |
poolName | string | name of the pool |
depositAmount | uint256 | amount being deposited with the commitment |
_verifySignature
Verifies the signature for commitment authorization.
function _verifySignature(
uint256 quantity,
address committer,
address signer,
uint256 depositAmount,
string calldata poolName,
bytes calldata sig
) private view;
Parameters
Name | Type | Description |
---|---|---|
quantity | uint256 | the quantity to commit |
committer | address | address of the committer |
signer | address | address of the signer |
depositAmount | uint256 | amount being deposited with the commitment |
poolName | string | name of the pool |
sig | bytes | signature to verify |
Events
TicketsConsumed
event TicketsConsumed(address indexed from, string poolName, uint256 ticketQuantity, uint256 indexed depositedAmount);
Errors
Unauthorized
error Unauthorized();
InvalidDepositAmount
error InvalidDepositAmount();
CommitmentsInactive
error CommitmentsInactive();
Structs
ContractConfiguration
Struct for pool configuration
struct ContractConfiguration {
address ticketContract;
address poolContract;
address signer;
bool paused;
}
PoolConfiguration
Struct for pool configuration
struct PoolConfiguration {
uint256 maximumDepositAmount;
uint256 minimumDepositAmount;
uint32 commitmentStartTime;
uint32 commitmentEndTime;
mapping(address committer => uint256 ticketCount) committedTickets;
}
TicketConsumerStorage
Note: storage-location: erc7201:mure.TicketConsumer
struct TicketConsumerStorage {
address TICKET;
address SIGNER;
address POOL_CONTRACT;
bool paused;
mapping(string poolName => PoolConfiguration) poolConfig;
}