sponsor logo

First Flight #5

Completed

First Flight #5: Santa's List

He's making a smart contract and checking it twice ... Let's find out if this protocol has been naughty or nice!

Start Date Nov 30th, 2023 (12:00)
End Date Dec 7th, 2023 (12:00)
Time Left 0d/0h/0m
Rewards

SantasList

Contest Details

Prize Pool

  • High - 100xp

  • Medium - 20xp

  • Low - 2xp

  • Starts: November 30, 2023 Noon UTC

  • Ends: December 07, 2023 Noon UTC

Stats

About

Santa has adopted blockchain technology to keep track of the naughty and nice! Hooray! So Santa hired some south pole contract elves to help build him a blockchain-based list. He'd never worked with blockchain elves before but was excited to see what they could do! They got nearly 100% test coverage, so that's got to be good, right?

The codebase is broken up into 3 contracts:

  • SantasList.sol
  • SantaToken.sol
  • TokenUri.sol

SantasList

Santa's List is the main contract that stores the list of naughty and nice people. It doubles as an NFT contract that people can collect if they are NICE or EXTRA_NICE. In order for someone to be considered NICE or EXTRA_NICE they must be first "checked twice" by Santa.

Once they are checked twice, NICE users can collect their NFT, and EXTRA_NICE users can collect their NFT and they are given SantaTokens. The SantaToken is an ERC20 that can be used to buy the NFT for their NAUGHTY or UNKNOWN friends.

List Checking

In this contract Only Santa to take the following actions:

  • checkList: A function that changes an address to a new Status of NICE, EXTRA_NICE, NAUGHTY, or UNKNOWN on the original s_theListCheckedOnce list.
  • checkTwice: A function that changes an address to a new Status of NICE, EXTRA_NICE, NAUGHTY, or UNKNOWN on the new s_theListCheckedTwice list only if someone has already been marked on the s_theListCheckedOnce.

Collecting Presents

You can see what a Christmas NFT present looks like here!

The following functions are meant to be called by people, but only those marked NICE or EXTRA_NICE can benefit from them.

  • collectNFT: A function that allows a NICE or EXTRA_NICE user to collect their NFT. EXTRA_NICE users also receive SantaToken which is used to purchase an additional NFTs. An address is only allowed to collect 1 NFT per address, there is a check in the codebase to prevent someone from minting duplicate NFTs.
  • buyPresent: A function that trades 2e18 of SantaToken for an NFT. This function can be called by anyone.

SantaToken

This codebase is based off solmate a Modern, opinionated, and gas optimized building blocks for smart contract development. The ERC20 is a typical ERC20 with the following changes:

  • Only SantasList can mint tokens
  • Only SantasList can burn tokens (well, technically anyone can, but only SantasList can call the burn function)

TokenUri.sol

A minimal contract that exclusively has the tokenURI. It's a separate contract inherited by SantasList for readability purposes.

Getting Started

Requirements

  • git
    • You'll know you did it right if you can run git --version and you see a response like git version x.x.x
  • foundry
    • You'll know you did it right if you can run forge --version and you see a response like forge 0.2.0 (816e00b 2023-03-16T00:05:26.396218Z)

Quickstart

git clone https://github.com/Cyfrin/2023-11-Santas-List
cd 2023-11-Santas-List
make

Or optionally, you can run:

forge install
forge build

Usage

Testing

forge test

Test Coverage

forge coverage

and for coverage based testing:

forge coverage --report debug

Audit Scope Details

  • Commit Hash: 91c8f8c94a9ff2db91f0ab2b2742cf1739dd6374
  • In Scope:
./src/
#-- SantaToken.sol
#-- SantasList.sol
#-- TokenUri.sol

Compatibilities

  • Solc Version: 0.8.22
  • Chain(s) to deploy contract to:
    • Arbitrum
  • Tokens
    • SantaToken

Roles

  • Santa - Deployer of the protocol, should only be able to do 2 things:
    • checkList - Check the list once
    • checkTwice - Check the list twice
    • Additionally, it's OK if Santa mints themselves tokens.
  • User - Can buyPresents and mint NFTs depending on their status of NICE, NAUGHTY, EXTRA-NICE or UNKNOWN

Known Issues

  • We are aware that we are missing a number of zero address checks, please ignore.
  • The Christmas date is approximate, if it's more then 24 hours before or after Christmas, please report that. Otherwise, it's OK.