Ticket
Inherits: AccessControl, ERC20, ERC20Permit
Title: Ticket
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")
TRANSFER_ROLE
Role allows user to transfer the token
bytes32 public constant TRANSFER_ROLE = keccak256("TRANSFER_ROLE")
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
| Name | Type | Description |
|---|---|---|
currencyAddress_ | address | the address of the ERC-20 currency token contract. |
exchangePrice_ | uint256 | the initial currency exchange price. |
discountConfig_ | DiscountRate[] | the initial discount rates. |
feeConfig_ | FeeConfig | the initial fee recipient configuration. |
operator_ | address | |
feeManager_ | address | |
name_ | string | name of the token contract. |
symbol_ | string | symbol 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
| Name | Type | Description |
|---|---|---|
quantity | uint256 | the 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
| Name | Type | Description |
|---|---|---|
quantity | uint256 | the amount of $TICKET to purchase. |
to | address | address to send the $TICKET to. |
sendTickets
send $TICKET to an address.
Mints $TICKET to the specified address.
function sendTickets(uint256 quantity, address to) external onlyRole(TICKET_OPERATOR);
Parameters
| Name | Type | Description |
|---|---|---|
quantity | uint256 | the amount of $TICKET to send. |
to | address | address to send the $TICKET to. |
sendTickets
send $TICKET to multiple address.
Mints $TICKET to the specified addresses.
function sendTickets(TicketRecipient[] calldata recipients) external onlyRole(TICKET_OPERATOR);
Parameters
| Name | Type | Description |
|---|---|---|
recipients | TicketRecipient[] | array of ticket recipients. |
updateExchangePrice
Allow a permitted caller to update the base exchange price.
function updateExchangePrice(uint256 exchangePrice_) external onlyRole(TICKET_OPERATOR);
Parameters
| Name | Type | Description |
|---|---|---|
exchangePrice_ | uint256 | updated base price. |
updateCurrencyAddress
Allow a permitted caller to update the exchange currency address.
function updateCurrencyAddress(address currencyAddress_) external onlyRole(TICKET_OPERATOR);
Parameters
| Name | Type | Description |
|---|---|---|
currencyAddress_ | address | updated currency address. |
getPrice
Returns the price in currency to charge for given $TICKET amount.
function getPrice(uint256 purchaseQuantity) external view returns (uint256);
Parameters
| Name | Type | Description |
|---|---|---|
purchaseQuantity | uint256 | the amount of $TICKET to purchase |
getDiscountRate
Returns the discount rate for given $TICKET amount.
function getDiscountRate(uint256 purchaseQuantity) external view returns (uint16);
Parameters
| Name | Type | Description |
|---|---|---|
purchaseQuantity | uint256 | the 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
| Name | Type | Description |
|---|---|---|
discountConfig_ | DiscountRate[] | discount config with percentages in basis points |
setFeeConfig
Sets the fee configuration.
function setFeeConfig(FeeConfig calldata feeConfig_) public onlyRole(FEE_MANAGER);
Parameters
| Name | Type | Description |
|---|---|---|
feeConfig_ | FeeConfig | fee configuration with percentages in basis points |
burn
Permit callers to burn their $TICKET.
function burn(uint256 quantity) public;
Parameters
| Name | Type | Description |
|---|---|---|
quantity | uint256 | The quantity of tickets to burn. |
withdrawCurrency
Withdraw any token from the contract. This should only be used in emergencies
function withdrawCurrency(address receiver, address currency) external onlyRole(FEE_MANAGER);
Parameters
| Name | Type | Description |
|---|---|---|
receiver | address | the address to which the token will be transferred |
currency | address | the address of the token contract |
_mintTicket
Mints $TICKET to specified address.
function _mintTicket(TicketRecipient memory ticketRecipient) private;
Parameters
| Name | Type | Description |
|---|---|---|
ticketRecipient | TicketRecipient | ticket quantity and recipient configuration |
_transferFee
Transfers the fee for $TICKET purchase.
function _transferFee(uint256 amount) private;
Parameters
| Name | Type | Description |
|---|---|---|
amount | uint256 | the 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
| Name | Type | Description |
|---|---|---|
from | address | the address from which the transfer is initiated |
to | address | the address to which the currency will be transferred |
amount | uint256 | the 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
| Name | Type | Description |
|---|---|---|
purchaseQuantity | uint256 | the amount of $TICKET to purchase |
_calculateDiscountRate
Determines the discount rate based on quantity being purchased.
function _calculateDiscountRate(uint256 purchaseQuantity) private view returns (uint16);
Parameters
| Name | Type | Description |
|---|---|---|
purchaseQuantity | uint256 | the amount of $TICKET to purchase |
_setFeeConfig
Sets the fee configuration.
function _setFeeConfig(FeeConfig memory feeConfig_) private;
Parameters
| Name | Type | Description |
|---|---|---|
feeConfig_ | FeeConfig | fee 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
| Name | Type | Description |
|---|---|---|
discountConfig_ | DiscountRate[] | discount config with percentages in basis points |
_update
Override ERC20._update to restrict transfers to whitelisted addresses
function _update(address from, address to, uint256 value) internal virtual override;
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();
UnauthorizedTransfer
This error is thrown when the transfer isn't made from or to a whitelisted address.
error UnauthorizedTransfer();
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;
}
TicketRecipient
Struct for ticket recipients
struct TicketRecipient {
address recipient;
uint256 quantity;
}
FeeConfig
Struct for fee configuration
struct FeeConfig {
FeeRecipient[] feeRecipients;
uint16 burnSplit;
}