35 major breaking releases

38.0.0 Sep 26, 2024
37.0.0 Jul 18, 2024
36.0.0 Jul 12, 2024
35.0.0 Jun 24, 2024
3.0.0 Feb 10, 2021

#1 in #lottery

Download history 3/week @ 2024-07-25 29/week @ 2024-09-12 38/week @ 2024-09-19 191/week @ 2024-09-26 35/week @ 2024-10-03 98/week @ 2024-10-10 145/week @ 2024-10-17 180/week @ 2024-10-24 281/week @ 2024-10-31 10055/week @ 2024-11-07

10,697 downloads per month
Used in 8 crates (via polkadot-sdk)

Apache-2.0

2MB
36K SLoC

Release

Polkadot SDK stable2409


lib.rs:

A lottery pallet that uses participation in the network to purchase tickets.

With this pallet, you can configure a lottery, which is a pot of money that users contribute to, and that is reallocated to a single user at the end of the lottery period. Just like a normal lottery system, to participate, you need to "buy a ticket", which is used to fund the pot.

The unique feature of this lottery system is that tickets can only be purchased by making a "valid call" dispatched through this pallet. By configuring certain calls to be valid for the lottery, you can encourage users to make those calls on your network. An example of how this could be used is to set validator nominations as a valid lottery call. If the lottery is set to repeat every month, then users would be encouraged to re-nominate validators every month. A user can only purchase one ticket per valid call per lottery.

This pallet can be configured to use dynamically set calls or statically set calls. Call validation happens through the ValidateCall implementation. This pallet provides one implementation of this using the CallIndices storage item. You can also make your own implementation at the runtime level which can contain much more complex logic, such as validation of the parameters, which this pallet alone cannot do.

This pallet uses the modulus operator to pick a random winner. It is known that this might introduce a bias if the random number chosen in a range that is not perfectly divisible by the total number of participants. The MaxGenerateRandom configuration can help mitigate this by generating new numbers until we hit the limit or we find a "fair" number. This is best effort only.

Dependencies

~18–34MB
~554K SLoC