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

Staking #10

Draft
wants to merge 62 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
5f20b77
Add grant disbursement program and configuration files to the reposit…
asharma13524 Oct 17, 2024
cbe68ed
remove pondo references
asharma13524 Oct 17, 2024
91b1742
add logic for facilitating bonds and unbonds
asharma13524 Oct 17, 2024
14563f3
add deps, fix compiler complaints
asharma13524 Oct 17, 2024
da7617d
fix future type issue
asharma13524 Oct 17, 2024
44f507e
update credits amount and grantee var names
asharma13524 Oct 17, 2024
050d5f4
replace time_oracle with block height
lukenewman Oct 18, 2024
46de4b8
add unbonding logic
asharma13524 Oct 18, 2024
d737a3a
simplify finalize_withdraw_principal
lukenewman Oct 18, 2024
a752aa6
fix build issue
lukenewman Oct 18, 2024
a761470
testnet deployment
asharma13524 Oct 18, 2024
d5ec131
update params for testnet deployment
asharma13524 Oct 18, 2024
8f2f0c4
testnet deployment
asharma13524 Oct 18, 2024
74a8c5b
Revert "replace time_oracle with block height"
asharma13524 Oct 18, 2024
22a74bd
testnet testing
asharma13524 Oct 18, 2024
8dda6f7
remove amount as param for process_grant
asharma13524 Oct 18, 2024
09b9547
update param names
asharma13524 Oct 18, 2024
34d7538
adjust with timestamps from mainnet
asharma13524 Oct 18, 2024
04eea8d
update static var amounts
asharma13524 Oct 18, 2024
f7acb2d
test withdraw_rewards setup (cliff is past time
asharma13524 Oct 18, 2024
607a743
update program.json for withdraw_rewards testing option
asharma13524 Oct 18, 2024
caa3aa9
remove self.caller assertion on claim withdrawal
asharma13524 Oct 18, 2024
37a36fc
update start and cliff timestamps
asharma13524 Oct 18, 2024
4aec685
update contract version to v9
asharma13524 Oct 18, 2024
843e781
remove extranneous vars, grant struct updates, fix credits assertion
asharma13524 Oct 18, 2024
c680aa9
a lil cleanup
lukenewman Oct 18, 2024
51723f5
assert caller in transition
lukenewman Oct 20, 2024
8018d77
more cleanup
lukenewman Oct 21, 2024
5a83907
remove unbond_state
asharma13524 Oct 21, 2024
cc1b4bf
combine grant addresses into one withdrawal_address, split out claim_…
lukenewman Oct 21, 2024
001078a
Merge branch 'grant-disbursement' of github.com:puzzlehq/serengeti in…
lukenewman Oct 21, 2024
95d776c
add todos
lukenewman Oct 21, 2024
85b5f38
add test oracle on testnet
asharma13524 Oct 21, 2024
d925d2b
update consts for mainnet deployment
lukenewman Oct 23, 2024
b42ba0a
clean up
lukenewman Oct 23, 2024
4386847
build
lukenewman Oct 23, 2024
24ef6ea
cleanup
lukenewman Oct 24, 2024
84b37f2
add logic to withdraw to handle forceful unbonding case
lukenewman Oct 24, 2024
dbb00c5
Add initial staking program with supporting files and configurations.
asharma13524 Oct 30, 2024
96750e3
Refactor staking logic by removing pending deposits handling and upda…
asharma13524 Oct 30, 2024
7d97488
update withdraw, claim commission, create withdraw
asharma13524 Oct 31, 2024
eb5abf4
remove pending withdrawals check
asharma13524 Nov 1, 2024
9648db4
working I think, more testing
asharma13524 Nov 5, 2024
0e34244
update commission and create withdraw claim logic
asharma13524 Nov 6, 2024
825a191
remove unnecessary i64 conversion
asharma13524 Nov 6, 2024
af274ab
add back bonding fns with simplified shares calcs
asharma13524 Nov 8, 2024
9e1ebba
add epoch based unbonding
asharma13524 Nov 8, 2024
a132f21
fix transfer public bug
asharma13524 Nov 8, 2024
10f7688
fix bonding bugs
asharma13524 Nov 8, 2024
7213e0a
fix i64 underflow
asharma13524 Nov 8, 2024
c5b5ae5
withdraw flow works (small bug where we are unabel to withdraw at tim…
asharma13524 Nov 8, 2024
31237ad
full flow working (ithink)
asharma13524 Nov 13, 2024
27af808
add admin withdraw case
asharma13524 Nov 14, 2024
ccc7d30
clean up
asharma13524 Nov 14, 2024
16943d6
staking program updates
asharma13524 Nov 21, 2024
5ac3e3a
remove unused fns
asharma13524 Dec 1, 2024
455f129
remove commented code
asharma13524 Dec 1, 2024
f5c352f
remove unnecessary files
asharma13524 Dec 1, 2024
4e2b8e3
rm total shares check
asharma13524 Dec 6, 2024
b277ad4
add forced unbond case
asharma13524 Dec 9, 2024
4f8700d
add a few comments
asharma13524 Dec 10, 2024
c292b90
add comments for bond all
asharma13524 Dec 10, 2024
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 grants/grant_disbursement/.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 grants/grant_disbursement/build/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# grant_disbursement_puzzle.aleo

## Build Guide

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

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

mapping committee:
key as address.public;
value as committee_state.public;

struct committee_state:
is_open as boolean;
commission as u8;

mapping delegated:
key as address.public;
value as u64.public;

mapping metadata:
key as address.public;
value as u32.public;

mapping bonded:
key as address.public;
value as bond_state.public;

struct bond_state:
validator as address;
microcredits as u64;

mapping unbonding:
key as address.public;
value as unbond_state.public;

struct unbond_state:
microcredits as u64;
height as u32;

mapping account:
key as address.public;
value as u64.public;

mapping withdraw:
key as address.public;
value as address.public;

record credits:
owner as address.private;
microcredits as u64.private;

function bond_validator:
input r0 as address.public;
input r1 as u64.public;
input r2 as u8.public;
assert.neq self.signer r0 ;
gte r1 1000000u64 into r3;
assert.eq r3 true ;
gt r2 100u8 into r4;
assert.neq r4 true ;
async bond_validator self.signer r0 r1 r2 into r5;
output r5 as credits.aleo/bond_validator.future;

finalize bond_validator:
input r0 as address.public;
input r1 as address.public;
input r2 as u64.public;
input r3 as u8.public;
get.or_use withdraw[r0] r1 into r4;
assert.eq r1 r4 ;
cast true r3 into r5 as committee_state;
get.or_use committee[r0] r5 into r6;
assert.eq r3 r6.commission ;
cast r0 0u64 into r7 as bond_state;
get.or_use bonded[r0] r7 into r8;
assert.eq r8.validator r0 ;
add r8.microcredits r2 into r9;
cast r0 r9 into r10 as bond_state;
get.or_use delegated[r0] 0u64 into r11;
add r2 r11 into r12;
gte r12 10000000000000u64 into r13;
assert.eq r13 true ;
get account[r0] into r14;
sub r14 r2 into r15;
contains committee[r0] into r16;
branch.eq r16 true to validator_in_committee;
set r4 into withdraw[r0];
gte r2 100000000u64 into r17;
assert.eq r17 true ;
get.or_use metadata[aleo1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq3ljyzc] 0u32 into r18;
add r18 1u32 into r19;
set r19 into metadata[aleo1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq3ljyzc];
contains unbonding[r0] into r20;
assert.eq r20 false ;
position validator_in_committee;
set r6 into committee[r0];
set r12 into delegated[r0];
set r10 into bonded[r0];
set r15 into account[r0];

function bond_public:
input r0 as address.public;
input r1 as address.public;
input r2 as u64.public;
gte r2 1000000u64 into r3;
assert.eq r3 true ;
assert.neq self.caller r0 ;
async bond_public self.caller r0 r1 r2 into r4;
output r4 as credits.aleo/bond_public.future;

finalize bond_public:
input r0 as address.public;
input r1 as address.public;
input r2 as address.public;
input r3 as u64.public;
get.or_use withdraw[r0] r2 into r4;
assert.eq r2 r4 ;
contains bonded[r0] into r5;
branch.eq r5 true to continue_bond_delegator;
set r2 into withdraw[r0];
cast true 0u8 into r6 as committee_state;
get.or_use committee[r1] r6 into r7;
assert.eq r7.is_open true ;
get.or_use metadata[aleo1qgqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqanmpl0] 0u32 into r8;
add r8 1u32 into r9;
lte r9 100000u32 into r10;
assert.eq r10 true ;
set r9 into metadata[aleo1qgqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqanmpl0];
position continue_bond_delegator;
cast r1 0u64 into r11 as bond_state;
get.or_use bonded[r0] r11 into r12;
assert.eq r12.validator r1 ;
add r12.microcredits r3 into r13;
gte r13 10000000000u64 into r14;
assert.eq r14 true ;
cast r1 r13 into r15 as bond_state;
get account[r0] into r16;
sub r16 r3 into r17;
get.or_use delegated[r1] 0u64 into r18;
add r3 r18 into r19;
contains unbonding[r1] into r20;
assert.eq r20 false ;
set r15 into bonded[r0];
set r17 into account[r0];
set r19 into delegated[r1];

function unbond_public:
input r0 as address.public;
input r1 as u64.public;
async unbond_public self.caller r0 r1 into r2;
output r2 as credits.aleo/unbond_public.future;

finalize unbond_public:
input r0 as address.public;
input r1 as address.public;
input r2 as u64.public;
add block.height 360u32 into r3;
cast 0u64 r3 into r4 as unbond_state;
get bonded[r1] into r5;
get withdraw[r1] into r6;
is.eq r0 r6 into r7;
contains withdraw[r5.validator] into r8;
get.or_use withdraw[r5.validator] aleo1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq3ljyzc into r9;
is.eq r0 r9 into r10;
and r8 r10 into r11;
or r7 r11 into r12;
assert.eq r12 true ;
is.eq r5.validator r1 into r13;
branch.eq r13 true to unbond_validator;
get.or_use unbonding[r1] r4 into r14;
get delegated[r5.validator] into r15;
sub r5.microcredits r2 into r16;
lt r16 10000000000u64 into r17;
or r11 r17 into r18;
ternary r18 r5.microcredits r2 into r19;
add r14.microcredits r19 into r20;
cast r20 r3 into r21 as unbond_state;
set r21 into unbonding[r1];
sub r15 r19 into r22;
set r22 into delegated[r5.validator];
branch.eq r18 true to remove_delegator;
cast r5.validator r16 into r23 as bond_state;
set r23 into bonded[r1];
branch.eq true true to end_unbond_delegator;
position remove_delegator;
remove bonded[r1];
get metadata[aleo1qgqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqanmpl0] into r24;
sub r24 1u32 into r25;
set r25 into metadata[aleo1qgqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqanmpl0];
position end_unbond_delegator;
gte r22 10000000000000u64 into r26;
branch.eq r26 true to end;
position unbond_validator;
contains committee[r5.validator] into r27;
nor r13 r27 into r28;
branch.eq r28 true to end;
get committee[r5.validator] into r29;
get bonded[r5.validator] into r30;
get delegated[r5.validator] into r31;
lt r31 10000000000000u64 into r32;
branch.eq r32 true to remove_validator;
sub r31 r2 into r33;
sub r30.microcredits r2 into r34;
gte r34 100000000u64 into r35;
gte r33 10000000000000u64 into r36;
and r35 r36 into r37;
branch.eq r37 false to remove_validator;
get.or_use unbonding[r5.validator] r4 into r38;
add r38.microcredits r2 into r39;
cast r39 r3 into r40 as unbond_state;
set r40 into unbonding[r5.validator];
set r33 into delegated[r5.validator];
cast r5.validator r34 into r41 as bond_state;
set r41 into bonded[r5.validator];
branch.eq true true to end;
position remove_validator;
remove committee[r5.validator];
get metadata[aleo1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq3ljyzc] into r42;
sub r42 1u32 into r43;
set r43 into metadata[aleo1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq3ljyzc];
sub r31 r30.microcredits into r44;
set r44 into delegated[r5.validator];
remove bonded[r5.validator];
get.or_use unbonding[r5.validator] r4 into r45;
add r30.microcredits r45.microcredits into r46;
cast r46 r3 into r47 as unbond_state;
set r47 into unbonding[r5.validator];
position end;

function claim_unbond_public:
input r0 as address.public;
async claim_unbond_public r0 into r1;
output r1 as credits.aleo/claim_unbond_public.future;

finalize claim_unbond_public:
input r0 as address.public;
get unbonding[r0] into r1;
gte block.height r1.height into r2;
assert.eq r2 true ;
get withdraw[r0] into r3;
get.or_use account[r3] 0u64 into r4;
add r1.microcredits r4 into r5;
set r5 into account[r3];
remove unbonding[r0];
contains bonded[r0] into r6;
branch.eq r6 true to end;
remove withdraw[r0];
position end;

function set_validator_state:
input r0 as boolean.public;
async set_validator_state self.caller r0 into r1;
output r1 as credits.aleo/set_validator_state.future;

finalize set_validator_state:
input r0 as address.public;
input r1 as boolean.public;
get committee[r0] into r2;
cast r1 r2.commission into r3 as committee_state;
set r3 into committee[r0];

function transfer_public:
input r0 as address.public;
input r1 as u64.public;
async transfer_public self.caller r0 r1 into r2;
output r2 as credits.aleo/transfer_public.future;

finalize transfer_public:
input r0 as address.public;
input r1 as address.public;
input r2 as u64.public;
get account[r0] into r3;
sub r3 r2 into r4;
set r4 into account[r0];
get.or_use account[r1] 0u64 into r5;
add r5 r2 into r6;
set r6 into account[r1];

function transfer_public_as_signer:
input r0 as address.public;
input r1 as u64.public;
async transfer_public_as_signer self.signer r0 r1 into r2;
output r2 as credits.aleo/transfer_public_as_signer.future;

finalize transfer_public_as_signer:
input r0 as address.public;
input r1 as address.public;
input r2 as u64.public;
get account[r0] into r3;
sub r3 r2 into r4;
set r4 into account[r0];
get.or_use account[r1] 0u64 into r5;
add r5 r2 into r6;
set r6 into account[r1];

function transfer_private:
input r0 as credits.record;
input r1 as address.private;
input r2 as u64.private;
sub r0.microcredits r2 into r3;
cast r1 r2 into r4 as credits.record;
cast r0.owner r3 into r5 as credits.record;
output r4 as credits.record;
output r5 as credits.record;

function transfer_private_to_public:
input r0 as credits.record;
input r1 as address.public;
input r2 as u64.public;
sub r0.microcredits r2 into r3;
cast r0.owner r3 into r4 as credits.record;
async transfer_private_to_public r1 r2 into r5;
output r4 as credits.record;
output r5 as credits.aleo/transfer_private_to_public.future;

finalize transfer_private_to_public:
input r0 as address.public;
input r1 as u64.public;
get.or_use account[r0] 0u64 into r2;
add r1 r2 into r3;
set r3 into account[r0];

function transfer_public_to_private:
input r0 as address.private;
input r1 as u64.public;
cast r0 r1 into r2 as credits.record;
async transfer_public_to_private self.caller r1 into r3;
output r2 as credits.record;
output r3 as credits.aleo/transfer_public_to_private.future;

finalize transfer_public_to_private:
input r0 as address.public;
input r1 as u64.public;
get account[r0] into r2;
sub r2 r1 into r3;
set r3 into account[r0];

function join:
input r0 as credits.record;
input r1 as credits.record;
add r0.microcredits r1.microcredits into r2;
cast r0.owner r2 into r3 as credits.record;
output r3 as credits.record;

function split:
input r0 as credits.record;
input r1 as u64.private;
sub r0.microcredits r1 into r2;
sub r2 10000u64 into r3;
cast r0.owner r1 into r4 as credits.record;
cast r0.owner r3 into r5 as credits.record;
output r4 as credits.record;
output r5 as credits.record;

function fee_private:
input r0 as credits.record;
input r1 as u64.public;
input r2 as u64.public;
input r3 as field.public;
assert.neq r1 0u64 ;
assert.neq r3 0field ;
add r1 r2 into r4;
sub r0.microcredits r4 into r5;
cast r0.owner r5 into r6 as credits.record;
output r6 as credits.record;

function fee_public:
input r0 as u64.public;
input r1 as u64.public;
input r2 as field.public;
assert.neq r0 0u64 ;
assert.neq r2 0field ;
add r0 r1 into r3;
async fee_public self.signer r3 into r4;
output r4 as credits.aleo/fee_public.future;

finalize fee_public:
input r0 as address.public;
input r1 as u64.public;
get account[r0] into r2;
sub r2 r1 into r3;
set r3 into account[r0];
Loading