IRISxiaowang / substrate-bank

MIT No Attribution
0 stars 0 forks source link

Create a Lottery pallet #20

Closed syan095 closed 9 months ago

syan095 commented 1 year ago

This pallet provides a "Lottery" system where people can buy a lottery, and periodically a winner will be chosen.

Config: // How long the lottery will be run for. Period: BlockNumber; // A portion of the winner's winning will be taken as tax and sent to the Treasury. TaxRate: Permill

Extrinsic: set_prize_split: Requires Governance (use root if Governance pallet is not yet done). Takes in a vec of Permills, defines how many winners and how the prize will be split. Total must add up to 1. Must be set to [Permill::One] as part of the Genesis Build.

update_ticket_price: Requires Manager/Auditor Updates the price of 1 ticket

buy_ticket: Requires Customer. Buys "n" number of tickets.

Hooks: After a certain time has passed, random winners are chosen from all tickets bought, and the prize for each winner is calculated from the "prize_split" set by governance. A share of the prize is paid to the treasury, the rest to the winner's account.

After the winner is decided, everything is reset, and the next round of lottery is automatically started.

Randomness: Blockchain must be deterministic, so pseudorandom is used. Use this guide: https://docs.substrate.io/reference/how-to-guides/pallet-design/incorporate-randomness/#create-a-nonce-and-use-it-in-your-randomness-implementation

You can use pallet_insecure_randomness_collective_flip to generate random number