NFT Lotteries are an implementation of Lottery Fractionalization discussed in Dave White's paper on Martingale Shares. The protocol allows users to place an $X bet for a Y% chance at winning an NFT. NFT owners specify the required bet amount and probability a user has of winning their NFT, taking on the risk of losing it for the gains pocketed from each bet. Gamble your NFTs!
- An NFT owner deposits their NFT into the smart contract and specifies the required bet amount and percentage chance of winning it. For example, Alice deposits their Bored Ape and lists a 1 ETH bet amount for a 20% chance to win it (which implies it is worth 5 ETH).
- Bob wants to take Alice up on these Lottery terms for the Bored Ape and pays the 1 ETH bet amount. The 1 ETH is sent to Alice.
- The smart contract uses random number generation to simulate the Lottery giving Bob a 20% chance of winning. If Bob wins, they get the NFT (essentially having purchased it for 1 ETH). Otherwise, Alice keeps the NFT in addition to a 1 ETH gain from Bob's bet.
- Alice can come back and withdraw their Bored Ape at any time as long as nobody won the Lottery while it was listed and there's no pending bet.
├── lib
│ ├── chainlink
│ ├── forge-std
│ └── solmate
├── scripts
└── src
├── NFTLotteries.sol
└── test
└── NFTLotteries.t.sol
Frontend
- Design based on barebones impl and spec
Security
- Confirm VRF random bound
- Tune VRF gas callback
- Which license?
Set Up
$ git clone https://github.com/rohansanjay/nft-lotteries.git
$ cd nft-lotteries
$ forge install
Building
$ forge build
Testing
$ forge test
Updating Gas Snapshots
$ forge snapshot
Deploying
$ source .env
$ forge script script/Deploy.g.sol:Deploy --rpc-url $GOERLI_RPC_URL --broadcast --verify -vvvv
These smart contracts are being provided as is. No guarantee, representation or warranty is being made, express or implied, as to the safety or correctness of the user interface or the smart contracts. They have not been audited and as such there can be no assurance they will work as intended, and users may experience delays, failures, errors, omissions, loss of transmitted information or loss of funds. The creators are not liable for any of the foregoing. Users should proceed with caution and use at their own risk.