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

add wip arcade store contracts #14

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
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
5 changes: 5 additions & 0 deletions arcade/store/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.env
*.avm
*.prover
*.verifier
outputs/
13 changes: 13 additions & 0 deletions arcade/store/build/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# puzzle_arcade_store.aleo

## Build Guide

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

To execute this Aleo program, run:
```bash
snarkvm run hello
```
110 changes: 110 additions & 0 deletions arcade/store/build/imports/puzzle_arcade_ticket_v002.aleo
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
program puzzle_arcade_ticket_v002.aleo;

record PuzzleArcadeTicket:
owner as address.private;
amount as u64.private;

mapping registry:
key as address.public;
value as boolean.public;

function add_program_to_registry:
input r0 as address.private;
assert.eq self.caller self.signer ;
assert.eq self.caller aleo196a39wq9q8ea779cmlmff0c9pj2gl4f5e8fhjpvmufe5utuq7y8snz4h2l ;
async add_program_to_registry r0 into r1;
output r1 as puzzle_arcade_ticket_v002.aleo/add_program_to_registry.future;

finalize add_program_to_registry:
input r0 as address.public;
set true into registry[r0];

function mint:
input r0 as address.public;
input r1 as u64.public;
cast r0 r1 into r2 as PuzzleArcadeTicket.record;
async mint self.caller into r3;
output r2 as PuzzleArcadeTicket.record;
output r3 as puzzle_arcade_ticket_v002.aleo/mint.future;

finalize mint:
input r0 as address.public;
get.or_use registry[r0] false into r1;
assert.eq r1 true ;

function spend:
input r0 as PuzzleArcadeTicket.record;
input r1 as u64.public;
gte r0.amount r1 into r2;
assert.eq r2 true ;
sub r0.amount r1 into r3;
cast r0.owner r3 into r4 as PuzzleArcadeTicket.record;
output r4 as PuzzleArcadeTicket.record;

function join:
input r0 as PuzzleArcadeTicket.record;
input r1 as PuzzleArcadeTicket.record;
gt r0.amount 0u64 into r2;
assert.eq r2 true ;
gt r1.amount 0u64 into r3;
assert.eq r3 true ;
add r0.amount r1.amount into r4;
cast self.signer r4 into r5 as PuzzleArcadeTicket.record;
output r5 as PuzzleArcadeTicket.record;

function join3:
input r0 as PuzzleArcadeTicket.record;
input r1 as PuzzleArcadeTicket.record;
input r2 as PuzzleArcadeTicket.record;
gt r0.amount 0u64 into r3;
assert.eq r3 true ;
gt r1.amount 0u64 into r4;
assert.eq r4 true ;
gt r2.amount 0u64 into r5;
assert.eq r5 true ;
add r0.amount r1.amount into r6;
add r6 r2.amount into r7;
cast self.signer r7 into r8 as PuzzleArcadeTicket.record;
output r8 as PuzzleArcadeTicket.record;

function join4:
input r0 as PuzzleArcadeTicket.record;
input r1 as PuzzleArcadeTicket.record;
input r2 as PuzzleArcadeTicket.record;
input r3 as PuzzleArcadeTicket.record;
gt r0.amount 0u64 into r4;
assert.eq r4 true ;
gt r1.amount 0u64 into r5;
assert.eq r5 true ;
gt r2.amount 0u64 into r6;
assert.eq r6 true ;
gt r3.amount 0u64 into r7;
assert.eq r7 true ;
add r0.amount r1.amount into r8;
add r8 r2.amount into r9;
add r9 r3.amount into r10;
cast self.signer r10 into r11 as PuzzleArcadeTicket.record;
output r11 as PuzzleArcadeTicket.record;

function join5:
input r0 as PuzzleArcadeTicket.record;
input r1 as PuzzleArcadeTicket.record;
input r2 as PuzzleArcadeTicket.record;
input r3 as PuzzleArcadeTicket.record;
input r4 as PuzzleArcadeTicket.record;
gt r0.amount 0u64 into r5;
assert.eq r5 true ;
gt r1.amount 0u64 into r6;
assert.eq r6 true ;
gt r2.amount 0u64 into r7;
assert.eq r7 true ;
gt r3.amount 0u64 into r8;
assert.eq r8 true ;
gt r4.amount 0u64 into r9;
assert.eq r9 true ;
add r0.amount r1.amount into r10;
add r10 r2.amount into r11;
add r11 r3.amount into r12;
add r12 r4.amount into r13;
cast self.signer r13 into r14 as PuzzleArcadeTicket.record;
output r14 as PuzzleArcadeTicket.record;
34 changes: 34 additions & 0 deletions arcade/store/build/main.aleo
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import puzzle_arcade_ticket_v002.aleo;
program puzzle_arcade_store.aleo;

struct Code:
pt1 as u128;
pt2 as u128;
pt3 as u128;
pt4 as u128;
pt5 as u128;

record Product:
owner as address.private;
id as u64.private;
code as Code.private;

function mint:
input r0 as u64.private;
input r1 as Code.private;
cast aleo14y7ahmrzka0wphss6p5wtvs0s08u4e00azr8ua6wxr3h60vlgyyqw7mxtd r0 r1 into r2 as Product.record;
output r2 as Product.record;

function purchase:
input r0 as u64.private;
input r1 as puzzle_arcade_ticket_v002.aleo/PuzzleArcadeTicket.record;
input r2 as u64.private;
call puzzle_arcade_ticket_v002.aleo/spend r1 r2 into r3;
output r3 as puzzle_arcade_ticket_v002.aleo/PuzzleArcadeTicket.record;

function fulfill:
input r0 as address.private;
input r1 as Product.record;
assert.eq r1.owner aleo14y7ahmrzka0wphss6p5wtvs0s08u4e00azr8ua6wxr3h60vlgyyqw7mxtd;
cast r0 r1.id r1.code into r2 as Product.record;
output r2 as Product.record;
6 changes: 6 additions & 0 deletions arcade/store/build/program.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"program": "puzzle_arcade_store.aleo",
"version": "0.0.0",
"description": "",
"license": "MIT"
}
6 changes: 6 additions & 0 deletions arcade/store/leo.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[[package]]
name = "puzzle_arcade_ticket_v002.aleo"
network = "testnet"
location = "network"
checksum = "57a6dd0337f1036933fb846720ac51bf3987e0293ced5d7ffd53e083d54aa005"
dependencies = []
14 changes: 14 additions & 0 deletions arcade/store/program.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"program": "puzzle_arcade_store.aleo",
"version": "0.1.0",
"description": "",
"license": "MIT",
"dependencies": [
{
"name": "puzzle_arcade_ticket_v002.aleo",
"location": "network",
"network": "testnet",
"path": null
}
]
}
44 changes: 44 additions & 0 deletions arcade/store/src/main.leo
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import puzzle_arcade_ticket_v002.aleo;

program puzzle_arcade_store.aleo {
const STORE_OPERATOR: address = aleo14y7ahmrzka0wphss6p5wtvs0s08u4e00azr8ua6wxr3h60vlgyyqw7mxtd;
struct Code {
pt1: u128,
pt2: u128,
pt3: u128,
pt4: u128,
pt5: u128
}

record Product {
owner: address,
id: u64,
code: Code
}

transition mint(id: u64, code: Code) -> Product {
return Product { owner: STORE_OPERATOR, id, code };
}

transition purchase(
id: u64,
ticket: puzzle_arcade_ticket_v002.aleo/PuzzleArcadeTicket,
amt: u64, // amount of PART to burn
) -> (puzzle_arcade_ticket_v002.aleo/PuzzleArcadeTicket)
{
// burn purchaser's part
let spent_ticket: puzzle_arcade_ticket_v002.aleo/PuzzleArcadeTicket = puzzle_arcade_ticket_v002.aleo/spend (ticket, amt);
return (spent_ticket);
}

transition fulfill(buyer: address, product: Product) -> Product {
// assert the product is owned by the store operator to prevent a secondary market
assert_eq(product.owner, STORE_OPERATOR);
// transfer the product to the purchaser
return Product {
owner: buyer,
id: product.id,
code: product.code
};
}
}