Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Aleo Native Raffle #11

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
File renamed without changes.
File renamed without changes.
13 changes: 13 additions & 0 deletions arcade/giveaways/private/build/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# giveaway_private.aleo

## Build Guide

To compile this Aleo program, run:
```bash
snarkvm build
```

To execute this Aleo program, run:
```bash
snarkvm run hello
```
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
import puzzle_arcade_ticket_v001.aleo;
program giveaway.aleo;
program giveaway_private.aleo;

struct PrivateKey:
pk_pt1 as u128;
pk_pt2 as u128;
struct Code:
pt1 as u128;
pt2 as u128;
pt3 as u128;
pt4 as u128;
pt5 as u128;

record Prize:
owner as address.private;
private_key as PrivateKey.private;

record AuditPrize:
owner as address.private;
minter as address.private;
private_key as PrivateKey.private;
id as u8.private;
code as Code.private;

mapping entries:
key as u64.public;
Expand All @@ -39,23 +38,23 @@ mapping winner_count:
value as u64.public;

function mint_prize:
input r0 as u128.private;
input r0 as u8.private;
input r1 as u128.private;
assert.eq self.caller self.signer;
assert.eq self.caller aleo196a39wq9q8ea779cmlmff0c9pj2gl4f5e8fhjpvmufe5utuq7y8snz4h2l;
cast r0 r1 into r2 as PrivateKey;
cast aleo196a39wq9q8ea779cmlmff0c9pj2gl4f5e8fhjpvmufe5utuq7y8snz4h2l r2 into r3 as Prize.record;
cast r0 r1 into r4 as PrivateKey;
cast aleo196a39wq9q8ea779cmlmff0c9pj2gl4f5e8fhjpvmufe5utuq7y8snz4h2l aleo196a39wq9q8ea779cmlmff0c9pj2gl4f5e8fhjpvmufe5utuq7y8snz4h2l r4 into r5 as AuditPrize.record;
output r3 as Prize.record;
output r5 as AuditPrize.record;
input r2 as u128.private;
input r3 as u128.private;
input r4 as u128.private;
input r5 as u128.private;
assert.eq self.signer aleo196a39wq9q8ea779cmlmff0c9pj2gl4f5e8fhjpvmufe5utuq7y8snz4h2l;
cast r1 r2 r3 r4 r5 into r6 as Code;
cast aleo196a39wq9q8ea779cmlmff0c9pj2gl4f5e8fhjpvmufe5utuq7y8snz4h2l r0 r6 into r7 as Prize.record;
output r7 as Prize.record;

function buy_one_entry:
input r0 as puzzle_arcade_ticket_v001.aleo/PuzzleArcadeTicket.record;
call puzzle_arcade_ticket_v001.aleo/spend r0 1000000u64 into r1;
async buy_one_entry r0.owner into r2;
output r1 as puzzle_arcade_ticket_v001.aleo/PuzzleArcadeTicket.record;
output r2 as giveaway.aleo/buy_one_entry.future;
output r2 as giveaway_private.aleo/buy_one_entry.future;

finalize buy_one_entry:
input r0 as address.public;
Expand All @@ -75,7 +74,7 @@ function buy_two_entries:
call puzzle_arcade_ticket_v001.aleo/spend r0 2000000u64 into r1;
async buy_two_entries r0.owner into r2;
output r1 as puzzle_arcade_ticket_v001.aleo/PuzzleArcadeTicket.record;
output r2 as giveaway.aleo/buy_two_entries.future;
output r2 as giveaway_private.aleo/buy_two_entries.future;

finalize buy_two_entries:
input r0 as address.public;
Expand All @@ -98,7 +97,7 @@ function buy_three_entries:
call puzzle_arcade_ticket_v001.aleo/spend r0 3000000u64 into r1;
async buy_three_entries r0.owner into r2;
output r1 as puzzle_arcade_ticket_v001.aleo/PuzzleArcadeTicket.record;
output r2 as giveaway.aleo/buy_three_entries.future;
output r2 as giveaway_private.aleo/buy_three_entries.future;

finalize buy_three_entries:
input r0 as address.public;
Expand All @@ -123,7 +122,7 @@ function buy_four_entries:
call puzzle_arcade_ticket_v001.aleo/spend r0 4000000u64 into r1;
async buy_four_entries r0.owner into r2;
output r1 as puzzle_arcade_ticket_v001.aleo/PuzzleArcadeTicket.record;
output r2 as giveaway.aleo/buy_four_entries.future;
output r2 as giveaway_private.aleo/buy_four_entries.future;

finalize buy_four_entries:
input r0 as address.public;
Expand All @@ -150,7 +149,7 @@ function buy_five_entries:
call puzzle_arcade_ticket_v001.aleo/spend r0 5000000u64 into r1;
async buy_five_entries r0.owner into r2;
output r1 as puzzle_arcade_ticket_v001.aleo/PuzzleArcadeTicket.record;
output r2 as giveaway.aleo/buy_five_entries.future;
output r2 as giveaway_private.aleo/buy_five_entries.future;

finalize buy_five_entries:
input r0 as address.public;
Expand Down Expand Up @@ -179,7 +178,7 @@ function buy_six_entries:
call puzzle_arcade_ticket_v001.aleo/spend r0 6000000u64 into r1;
async buy_six_entries r0.owner into r2;
output r1 as puzzle_arcade_ticket_v001.aleo/PuzzleArcadeTicket.record;
output r2 as giveaway.aleo/buy_six_entries.future;
output r2 as giveaway_private.aleo/buy_six_entries.future;

finalize buy_six_entries:
input r0 as address.public;
Expand Down Expand Up @@ -210,7 +209,7 @@ function buy_seven_entries:
call puzzle_arcade_ticket_v001.aleo/spend r0 7000000u64 into r1;
async buy_seven_entries r0.owner into r2;
output r1 as puzzle_arcade_ticket_v001.aleo/PuzzleArcadeTicket.record;
output r2 as giveaway.aleo/buy_seven_entries.future;
output r2 as giveaway_private.aleo/buy_seven_entries.future;

finalize buy_seven_entries:
input r0 as address.public;
Expand Down Expand Up @@ -243,7 +242,7 @@ function buy_eight_entries:
call puzzle_arcade_ticket_v001.aleo/spend r0 8000000u64 into r1;
async buy_eight_entries r0.owner into r2;
output r1 as puzzle_arcade_ticket_v001.aleo/PuzzleArcadeTicket.record;
output r2 as giveaway.aleo/buy_eight_entries.future;
output r2 as giveaway_private.aleo/buy_eight_entries.future;

finalize buy_eight_entries:
input r0 as address.public;
Expand Down Expand Up @@ -278,7 +277,7 @@ function buy_nine_entries:
call puzzle_arcade_ticket_v001.aleo/spend r0 9000000u64 into r1;
async buy_nine_entries r0.owner into r2;
output r1 as puzzle_arcade_ticket_v001.aleo/PuzzleArcadeTicket.record;
output r2 as giveaway.aleo/buy_nine_entries.future;
output r2 as giveaway_private.aleo/buy_nine_entries.future;

finalize buy_nine_entries:
input r0 as address.public;
Expand Down Expand Up @@ -315,7 +314,7 @@ function buy_ten_entries:
call puzzle_arcade_ticket_v001.aleo/spend r0 10000000u64 into r1;
async buy_ten_entries r0.owner into r2;
output r1 as puzzle_arcade_ticket_v001.aleo/PuzzleArcadeTicket.record;
output r2 as giveaway.aleo/buy_ten_entries.future;
output r2 as giveaway_private.aleo/buy_ten_entries.future;

finalize buy_ten_entries:
input r0 as address.public;
Expand Down Expand Up @@ -353,7 +352,7 @@ function draw_winner:
assert.eq self.caller self.signer;
assert.eq self.caller aleo196a39wq9q8ea779cmlmff0c9pj2gl4f5e8fhjpvmufe5utuq7y8snz4h2l;
async draw_winner into r0;
output r0 as giveaway.aleo/draw_winner.future;
output r0 as giveaway_private.aleo/draw_winner.future;

finalize draw_winner:
get total_entries[0u64] into r0;
Expand All @@ -373,5 +372,5 @@ function send_prize_to_winner:
input r1 as Prize.record;
assert.eq self.caller self.signer;
assert.eq self.caller aleo196a39wq9q8ea779cmlmff0c9pj2gl4f5e8fhjpvmufe5utuq7y8snz4h2l;
cast r0 r1.private_key into r2 as Prize.record;
cast r0 r1.id r1.code into r2 as Prize.record;
output r2 as Prize.record;
6 changes: 6 additions & 0 deletions arcade/giveaways/private/build/program.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"program": "giveaway_private.aleo",
"version": "0.0.0",
"description": "",
"license": "MIT"
}
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
{
"program": "giveaway.aleo",
"program": "giveaway_private.aleo",
"version": "0.0.0",
"description": "",
"license": "MIT",
"dependencies": [
{
"name": "puzzle_arcade_ticket_v001.aleo",
"location": "network",
"network": "testnet"
"network": "testnet",
"path": null
}
]
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import puzzle_arcade_ticket_v001.aleo;

program giveaway.aleo {
program giveaway_private.aleo {
const OPERATOR: address = aleo196a39wq9q8ea779cmlmff0c9pj2gl4f5e8fhjpvmufe5utuq7y8snz4h2l;
const MAX_ENTRIES: u64 = 50u64;

Expand All @@ -20,44 +20,36 @@ program giveaway.aleo {
// total number of winners
mapping winner_count: u64 => u64;

struct PrivateKey {
pk_pt1: u128,
pk_pt2: u128
struct Code {
pt1: u128,
pt2: u128,
pt3: u128,
pt4: u128,
pt5: u128
}

record Prize {
owner: address,
private_key: PrivateKey,
id: u8,
code: Code
}

record AuditPrize {
owner: address,
minter: address,
private_key: PrivateKey,
}

transition mint_prize (pk_pt1: u128, pk_pt2: u128) -> (Prize, AuditPrize) {
assert_eq(self.caller, self.signer);
assert_eq(self.caller, OPERATOR);
transition mint_prize (id: u8, pt1: u128, pt2: u128, pt3: u128, pt4: u128, pt5: u128) -> Prize {
assert_eq(self.signer, OPERATOR);

let prize: Prize = Prize {
owner: OPERATOR,
private_key: PrivateKey {
pk_pt1: pk_pt1,
pk_pt2: pk_pt2
},
};

let audit_prize: AuditPrize = AuditPrize {
owner: OPERATOR,
minter: OPERATOR,
private_key: PrivateKey {
pk_pt1: pk_pt1,
pk_pt2: pk_pt2
id,
code: Code {
pt1,
pt2,
pt3,
pt4,
pt5
},
};

return (prize, audit_prize);
return (prize);
}

async transition buy_one_entry (ticket: puzzle_arcade_ticket_v001.aleo/PuzzleArcadeTicket) -> (
Expand Down Expand Up @@ -91,7 +83,7 @@ program giveaway.aleo {
async function add_two_entries (public participant: address) {
let current_raffle_count: u64 = Mapping::get_or_use(total_entries, 0u64, 0u64);
assert(current_raffle_count + 2u64 < MAX_ENTRIES);

for i: u64 in 0u64..2u64 {
Mapping::set(entries, current_raffle_count + i, participant);
}
Expand All @@ -112,7 +104,7 @@ program giveaway.aleo {
async function add_three_entries (public participant: address) {
let current_raffle_count: u64 = Mapping::get_or_use(total_entries, 0u64, 0u64);
assert(current_raffle_count + 3u64 < MAX_ENTRIES);

for i: u64 in 0u64..3u64 {
Mapping::set(entries, current_raffle_count + i, participant);
}
Expand All @@ -133,7 +125,7 @@ program giveaway.aleo {
async function add_four_entries(public participant: address) {
let current_raffle_count: u64 = Mapping::get_or_use(total_entries, 0u64, 0u64);
assert(current_raffle_count + 4u64 < MAX_ENTRIES);

for i: u64 in 0u64..4u64 {
Mapping::set(entries, current_raffle_count + i, participant);
}
Expand All @@ -154,7 +146,7 @@ program giveaway.aleo {
async function add_five_entries(public participant: address) {
let current_raffle_count: u64 = Mapping::get_or_use(total_entries, 0u64, 0u64);
assert(current_raffle_count + 5u64 < MAX_ENTRIES);

for i: u64 in 0u64..5u64 {
Mapping::set(entries, current_raffle_count + i, participant);
}
Expand All @@ -175,7 +167,7 @@ program giveaway.aleo {
async function add_six_entries(public participant: address) {
let current_raffle_count: u64 = Mapping::get_or_use(total_entries, 0u64, 0u64);
assert(current_raffle_count + 6u64 < MAX_ENTRIES);

for i: u64 in 0u64..6u64 {
Mapping::set(entries, current_raffle_count + i, participant);
}
Expand All @@ -196,7 +188,7 @@ program giveaway.aleo {
async function add_seven_entries(public participant: address) {
let current_raffle_count: u64 = Mapping::get_or_use(total_entries, 0u64, 0u64);
assert(current_raffle_count + 7u64 < MAX_ENTRIES);

for i: u64 in 0u64..7u64 {
Mapping::set(entries, current_raffle_count + i, participant);
}
Expand Down Expand Up @@ -259,7 +251,7 @@ program giveaway.aleo {
async function add_ten_entries(public participant: address) {
let current_raffle_count: u64 = Mapping::get_or_use(total_entries, 0u64, 0u64);
assert(current_raffle_count + 10u64 < MAX_ENTRIES);

for i: u64 in 0u64..10u64 {
Mapping::set(entries, current_raffle_count + i, participant);
}
Expand All @@ -270,7 +262,6 @@ program giveaway.aleo {
Mapping::set(user_entries, participant, current_user_entries + 10u16);
}

// todo: allow draw winner to only be called once
async transition draw_winner () -> (Future) {
assert_eq(self.caller, self.signer);
assert_eq(self.caller, OPERATOR);
Expand Down Expand Up @@ -301,30 +292,16 @@ program giveaway.aleo {
Mapping::set(winner, current_winner_count, winner_address);
}

transition send_prize_to_winner (public winner_addr: address, public prize: Prize) -> (Prize) {
transition send_prize_to_winner (public winner_addr: address, public prize: Prize) -> Prize {
assert_eq(self.caller, self.signer);
assert_eq(self.caller, OPERATOR);

let prize_to_winner: Prize = Prize {
owner: winner_addr,
private_key: prize.private_key,
id: prize.id,
code: prize.code
};

// let audit_prize_to_winner: AuditPrizeToWinner = AuditPrizeToWinner {
// owner: operator,
// winner: winner_addr,
// private_key: prize.private_key,
// };

return (prize_to_winner);
}

// finalize send_prize_to_winner (public winner_addr: address) {
// // get the current winner idx
// // let current_winner_count_idx: u64 = Mapping::get_or_use(winner_count, 0u64, 0u64);
// // get the current winner via the index (if draw_winner is called multiple times)
// // let winner_addr_from_mapping: address = Mapping::get(winner, current_winner_count_idx);
// // assert that this function is called with the winner_addr
// // assert_eq(winner_addr, winner_addr_from_mapping);
// }
}
File renamed without changes.
3 changes: 3 additions & 0 deletions arcade/giveaways/public/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
NETWORK=testnet
ENDPOINT=https://testnet.puzzle.online
PRIVATE_KEY=asdf
5 changes: 5 additions & 0 deletions arcade/giveaways/public/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.env
*.avm
*.prover
*.verifier
outputs/
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# giveaway.aleo
# giveaway_public.aleo

## Build Guide

Expand Down
Loading