TicketConsumer

Git Source

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

NameTypeDescription
poolNamestringname of the pool
quantityuint256the amount of $TICKET to burn.
sigbytesthe 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

NameTypeDescription
quantityuint256the amount of $TICKET to burn.
depositAmountuint256
poolNamestring
sigbytesthe signature to authorize commitment.
depositSigbytessignature for MurePool deposit authorization.
permitSigbytessignature 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

NameTypeDescription
poolNamestringname 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

NameTypeDescription
poolNamestringname of the pool
committeraddressaddress 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

NameTypeDescription
poolNamestringname of the pool
minimumDepositAmountuint256minimum base deposit amount for pool per ticket
maximumDepositAmountuint256maximum deposit amount for pool per ticket
commitmentStartTimeuint256epoch timestamp for when commitments should start
commitmentEndTimeuint256epoch timestamp for when commitments should end

setContractConfiguration

Updates the pool configuration for deposits.

function setContractConfiguration(ContractConfiguration calldata contractConfig) external onlyRole(ADMIN_ROLE);

Parameters

NameTypeDescription
contractConfigContractConfigurationbase contract configuration

setCommitmentsPaused

Updates the pool configuration for deposits.

function setCommitmentsPaused(bool paused) external onlyRole(ADMIN_ROLE);

Parameters

NameTypeDescription
pausedboolboolean 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

NameTypeDescription
poolNamestringthe 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

NameTypeDescription
quantityuint256the quantity to commit
committeraddressaddress of the committer
poolNamestringname of the pool
depositAmountuint256amount 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

NameTypeDescription
quantityuint256the quantity to commit
committeraddressaddress of the committer
signeraddressaddress of the signer
depositAmountuint256amount being deposited with the commitment
poolNamestringname of the pool
sigbytessignature 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;
}