Ticket

Git Source

Inherits: AccessControl, ERC20, ERC20Permit

Author: Mure

ERC-20 token contract for a ticketing system. This token contract is meant to facilitate ticket system. A user can deposit a configurable currency in exchange for this token. A burn mechanism is provided to be used to indicate ticket consumption.

State Variables

FEE_MANAGER

Role allows user to update fee configuration

bytes32 public constant FEE_MANAGER = keccak256("FEE_MANAGER");

TICKET_OPERATOR

Role allows user to operate the ticket contract

bytes32 public constant TICKET_OPERATOR = keccak256("TICKET_OPERATOR");

CURRENCY

The address of the exchange currency token contract.

address public CURRENCY;

TREASURY

The address of the treasury which will receive the deposited currency.

address public TREASURY;

FEE_RECIPIENT

The address of the treasury which will receive the deposited currency.

address public FEE_RECIPIENT;

exchangePrice

Exchange rate of a ticket with the configured currency.

uint256 public exchangePrice;

feeConfig

Fee configuration for the received funds. Fee splits are in basis points.

FeeConfig private feeConfig;

discountConfig

Discount rates based on purchase quantity sorted based on quantity. Percentages are in basis points.

DiscountRate[] private discountConfig;

Functions

constructor

Construct a new instance of this TICKET contract configured with the given immutable contract addresses.

constructor(
    address currencyAddress_,
    uint256 exchangePrice_,
    DiscountRate[] memory discountConfig_,
    FeeConfig memory feeConfig_,
    address operator_,
    address feeManager_,
    string memory name_,
    string memory symbol_
) ERC20(name_, symbol_) ERC20Permit(name_);

Parameters

NameTypeDescription
currencyAddress_addressthe address of the ERC-20 currency token contract.
exchangePrice_uint256the initial currency exchange price.
discountConfig_DiscountRate[]the initial discount rates.
feeConfig_FeeConfigthe initial fee recipient configuration.
operator_address
feeManager_address
name_stringname of the token contract.
symbol_stringsymbol of the token contract.

purchaseTicket

Exchange currency for $TICKET.

Transfers deposited currency to TREASURY and mints $TICKET based on price.

function purchaseTicket(uint256 quantity) external;

Parameters

NameTypeDescription
quantityuint256the amount of $TICKET to purchase.

purchaseTicket

Exchange currency for $TICKET.

Transfers deposited currency to TREASURY and mints $TICKET based on price.

function purchaseTicket(uint256 quantity, address to) external;

Parameters

NameTypeDescription
quantityuint256the amount of $TICKET to purchase.
toaddressaddress to send the $TICKET to.

updateExchangePrice

Allow a permitted caller to update the base exchange price.

function updateExchangePrice(uint256 exchangePrice_) external onlyRole(TICKET_OPERATOR);

Parameters

NameTypeDescription
exchangePrice_uint256updated base price.

updateCurrencyAddress

Allow a permitted caller to update the exchange currency address.

function updateCurrencyAddress(address currencyAddress_) external onlyRole(TICKET_OPERATOR);

Parameters

NameTypeDescription
currencyAddress_addressupdated currency address.

getPrice

Returns the price in currency to charge for given $TICKET amount.

function getPrice(uint256 purchaseQuantity) external view returns (uint256);

Parameters

NameTypeDescription
purchaseQuantityuint256the amount of $TICKET to purchase

getDiscountRate

Returns the discount rate for given $TICKET amount.

function getDiscountRate(uint256 purchaseQuantity) external view returns (uint16);

Parameters

NameTypeDescription
purchaseQuantityuint256the amount of $TICKET to purchase

getDiscountConfig

function getDiscountConfig() external view returns (DiscountRate[] memory);

getFeeConfig

function getFeeConfig() external view returns (FeeRecipient[] memory, uint16);

decimals

function decimals() public view virtual override returns (uint8);

setDiscountConfig

Sets discount rates for purchase quantities.

makes sure that the array is sorted based on quantity and the percentages being set are valid.

function setDiscountConfig(DiscountRate[] calldata discountConfig_) public onlyRole(TICKET_OPERATOR);

Parameters

NameTypeDescription
discountConfig_DiscountRate[]discount config with percentages in basis points

setFeeConfig

Sets the fee configuration.

function setFeeConfig(FeeConfig calldata feeConfig_) public onlyRole(FEE_MANAGER);

Parameters

NameTypeDescription
feeConfig_FeeConfigfee configuration with percentages in basis points

burn

Permit callers to burn their $TICKET.

function burn(uint256 quantity) public;

Parameters

NameTypeDescription
quantityuint256The quantity of tickets to burn.

_transferFee

Transfers the fee for $TICKET purchase.

function _transferFee(uint256 amount) private;

Parameters

NameTypeDescription
amountuint256the amount of price being charged

_transferCurrency

Transfers currency from the given address to the given address.

function _transferCurrency(address from, address to, uint256 amount) private;

Parameters

NameTypeDescription
fromaddressthe address from which the transfer is initiated
toaddressthe address to which the currency will be transferred
amountuint256the amount of currency to be transferred

_calculatePrice

Determines the price in currency to charge for given $TICKET amount.

Deducts the discount from base price.

function _calculatePrice(uint256 purchaseQuantity) private view returns (uint256);

Parameters

NameTypeDescription
purchaseQuantityuint256the amount of $TICKET to purchase

_calculateDiscountRate

Determines the discount rate based on quantity being purchased.

function _calculateDiscountRate(uint256 purchaseQuantity) private view returns (uint16);

Parameters

NameTypeDescription
purchaseQuantityuint256the amount of $TICKET to purchase

_setFeeConfig

Sets the fee configuration.

function _setFeeConfig(FeeConfig memory feeConfig_) private;

Parameters

NameTypeDescription
feeConfig_FeeConfigfee configuration with percentages in basis points

_setDiscountConfig

Sets discount rates for purchase quantities.

makes sure that the array is sorted based on quantity and the percentages being set are valid.

function _setDiscountConfig(DiscountRate[] memory discountConfig_) private;

Parameters

NameTypeDescription
discountConfig_DiscountRate[]discount config with percentages in basis points

Events

DiscountUpdated

event DiscountUpdated(DiscountRate[] indexed discountConfig);

TicketsMinted

event TicketsMinted(address indexed to, uint256 indexed quantity);

TicketsBurned

event TicketsBurned(address indexed from, uint256 indexed quantity);

CurrencyUpdated

event CurrencyUpdated(address indexed currencyAddress);

FeeConfigUpdated

event FeeConfigUpdated(FeeConfig indexed feeConfig);

ExchangePriceUpdated

event ExchangePriceUpdated(uint256 indexed exchangePrice);

Errors

TransferFailure

This error is thrown when transfer of currency fails.

error TransferFailure();

InvalidDiscountRate

This error is thrown when the discount rate being set is invalid.

error InvalidDiscountRate();

InvalidFeeConfig

This error is thrown when the fee configuration being set is invalid.

error InvalidFeeConfig();

Structs

DiscountRate

Struct for discount rate configuration

struct DiscountRate {
    uint256 quantity;
    uint16 discount;
}

FeeRecipient

Struct for fee recipient configuration

struct FeeRecipient {
    address recipient;
    uint16 split;
}

FeeConfig

Struct for fee configuration

struct FeeConfig {
    FeeRecipient[] feeRecepients;
    uint16 burnSplit;
}