This project implements an upgradeable (UUPS Proxy pattern) Event Factory smart contract, which is responsible for creating Event smart contracts for ERC1155 ticket sales.
The development tool used is the Foundry where the contracts and the tests are written, and then there's hardhat integrated which is used for writing the deployment and upgrade scripts.
-
createEvent - Users can create the Event smart contract by calling this function and passing in the data about the tickets. This data should include the different types of tickets that there will be with their id, cost, and the maximum supply. The ownership of this smart contract is then transferred to the caller of the transaction and the EventCreated event is fired.
-
version - Returns the version of the Factory contract as it's upgradeable.
-
buyTickets - By calling this function, users can buy ticket(s) for that specific event. The exact ether value should be sent with this transaction for it to succeed, if it is sent more, the transaction will revert. If the maximum amount of ticket amount has been reached, users won't be able to call this function. The owner of the event contract can also pause the ticket sales which will make it impossible for users to call this function.
-
buyTicketsBatch - If users want to buy different types of tickets, they should call this function, if even one of the ticket number limits is reached, the whole transaction will revert. It's also important that the user should be sent the exact amount of ether for all the tickets combined for this transaction to succeed.
-
remainingTickets - Returns the remaining amount of a specific ticket.
-
soldTickets - Returns the sold amount of a specific ticket.
-
endSales - Owners function to stop ticket sales. IMPORTANT: If the sales are stopped, users are still able to transfer tickets to other addresses.
-
continueSales - Owners function to continue ticket sales.
-
version - Returns the version of the contract.
-
withdrawFunds - Transfers all the contract funds to the owner.
Tests are written to cover as many scenarios as possible, but still, it's not enough for production. This should never happen in production-ready code!
To run the tests, you will have to do the following
IMPORTANT: Make sure you run tests on a Mainnet fork because some test cases include Mainnet token addresses!
- Clone this repository to your local machine.
- Run
forge install
. - Run
forge build
. - Run
forge test --fork-url {MAINNET_RPC_URL]
.
OR, you can just run forge test --fork-url {MAINNET_RPC_URL]
, which will automatically install dependencies and compile the contracts.
To deploy the contract, you will have to do the following
- Clone this repository to your local machine.
- Run
forge install && npm install
. - Create the
.env
file based on the.env.example
. - Modify network options in
hardhat.config.ts
. - Deploy the smart contract with
npx hardhat run script/deploy.ts --network {network name}
If you would like to deploy it locally, make sure to run npx hardhat node
before the 3rd step, and deploy the smart contract with localhost
as the "network name"