# On-chain Giveaway
Below is a proposed technical design for a sybil-resistant onchain giveaway for a DEX. This can be repurposed for a lot of giveaway designs.
note: this is solely a mechanism spec for educational/research purposes. any interest should consider the risks of running , [especially one that acts more like a lottery](https://www.uspis.gov/wp-content/uploads/2019/12/pub-546_consumers-guide-to-sweepstakes-lotteries_508.pdf)
sponsor:
---
a sponsor can be anyone with a token 'stake' in the smart contract program who wishes to offer it as a giveaway
this ensures "alignment of interests" between the participants in the giveaway, the sponsor, and the rest of the smart contract program
can be any kind token staked really (stable, L1, etc), not just a governance one
example: if theres a staked insurance fund, either protocol-owned or any external staker can offer a sweepstakes
entry process:
---
Giveaways on-chain are hard and making them too open increase chances of a sybil attacks defeat the purpose.
Making use of blockchain infra:
- free claim of 1 raffle ticket (important to ensure that this transaction includes no other instructions) allowed for each user every unix_ts
- X (e.g. $.01) of taker volume (at default fee tier) => 1 raffle ticket
max raffle tickets per account = Y (e.g. 500 million)
blockchain reward/costs for:
free claim = one transaction => 1 ticket
for trading $1 = one transaction + .001 fee => 100 tickets
if the prize is $1000, and the price of SOL is $25, then:
`one transaction = .000005 * $25 = $0.000125`
(perhaps there are ways the solana network can lower these costs further?)
`EV = 1000/(total_tickets)`
`breakeven total tickets = 1000/0.000125 = 8000000`
Thus, only if at contest end the belief is that `total_tickets <= 8000000` it makes sense to do the free claims as a sybil attacker.
Otherwise, it it simply a bonus giveaway on top of existing actions that would otherwise be taken.
selection process
---
- chance based: use [Switchboard's VRF](https://switchboardxyz.medium.com/verifiable-randomness-on-solana-46f72a46d9cf)*
- skill based: create a game where the raffle tickets represent attempts allowed. the highest score for the game gets the prize pool
*see appendix for onchain process
prize pool process
---
- as a extra element of chance, the prize pool can be a draw between a basket of sizes
- this draw can be designed in a way s.t. the expected value is always `= sum(prizes) / sum(tickets)` *
*see appendix for onchain process
Appendix
---
### calculating each participant's odds
1. loop through all and calculate total raffle tickets
2. loop again and assign numeric range for each user (on their account)
3. draw random number from (0, total_tickets) for contest account
4. settle winning user with contest account
### calculating prize odds
lets consider the following:
`prizes = [$100, $500, $26600]`
```
total_prize = sum(prizes)
> $27500
ratio[i] = total_prize / prizes[i]
> [275, 55, 1] // int math
```
select random value from (0, sum(ratio)] to decide prize
the chance of high prize decreases the large the large prize is! allowing for a growing "jackpot"