Skip to content
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
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
.env
*.avm
*.prover
*.verifier
Expand Down
17 changes: 15 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,17 @@
# Work by [aisha]

# Compliant Private Tokens Workshop - Token Template
- **Github Repo:** https://github.com/ayan-aisha/private-token-workshop-token-template

This is the Leo project scaffolding for the Aleo compliant private tokens workshop. For more information, head over to the [main repository](https://github.com/alex-aleo/private-token-workshop).
- **Deployment address:** `aleo18kg2c5wm6fygl5yka9n8yyllfxls2x535haklls44mu9t96crqqsdm5kk6`

- **Deployment Id:** `at1696ps5aua9l9x7n7dd2cydc7y3chtu9zusqgqpckuvmshjlwau8smvev3r`

- **mint_public:** `at1qgqsx4698pm0h55nl0k3pz89ku8shkv526mt9qwm5mlrshqvrsyqz5nn24`

- **mint_private:** `at1j4x05wahz8kyrzgyalzyr26u5qvspqrk3n9g2vxrzwj8lrjvdvxsqjprhh`

- **transfer_public:** `at1dl0kfzm7526j5vnyhgurxrww9ny8qhnqx6l5yarwalajts4kcgxqgl8r59`

- **transfer_private:** `at1hqypek7jpzpvgfsp56ttewx3aj9m5dpjeuyer38hgs4ha27fx5fqpqjgr3`

- **program name:** `aisha_token.aleo`
44 changes: 44 additions & 0 deletions build/imports/workshop_ofac.aleo
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
program workshop_ofac.aleo;

mapping sanctioned:
key as field.public;
value as boolean.public;

function address_check:
input r0 as address.private;
hash.psd2 r0 into r1 as field;
async address_check r1 into r2;
output r2 as workshop_ofac.aleo/address_check.future;

finalize address_check:
input r0 as field.public;
get.or_use sanctioned[r0] false into r1;
is.eq r1 false into r2;
assert.eq r2 true;

function add_sanctioned_addresses:
input r0 as address.private;
is.eq self.signer aleo16ee2zncu2t6ftcpnnnmyd3c6pf8eu2xfyksh23amwqgvapp6mg8q8hy7e0 into r1;
assert.eq r1 true;
hash.psd2 r0 into r2 as field;
async add_sanctioned_addresses r2 into r3;
output r3 as workshop_ofac.aleo/add_sanctioned_addresses.future;

finalize add_sanctioned_addresses:
input r0 as field.public;
set true into sanctioned[r0];

function remove_sanctioned_addresses:
input r0 as address.private;
is.eq self.signer aleo16ee2zncu2t6ftcpnnnmyd3c6pf8eu2xfyksh23amwqgvapp6mg8q8hy7e0 into r1;
assert.eq r1 true;
hash.psd2 r0 into r2 as field;
async remove_sanctioned_addresses r2 into r3;
output r3 as workshop_ofac.aleo/remove_sanctioned_addresses.future;

finalize remove_sanctioned_addresses:
input r0 as field.public;
set false into sanctioned[r0];

constructor:
assert.eq program_owner aleo16ee2zncu2t6ftcpnnnmyd3c6pf8eu2xfyksh23amwqgvapp6mg8q8hy7e0;
79 changes: 79 additions & 0 deletions build/main.aleo
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import workshop_ofac.aleo;
program aisha_token.aleo;

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

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

function mint_public:
input r0 as address.public;
input r1 as u64.public;
call workshop_ofac.aleo/address_check r0 into r2;
async mint_public r0 r1 r2 into r3;
output r3 as aisha_token.aleo/mint_public.future;

finalize mint_public:
input r0 as address.public;
input r1 as u64.public;
input r2 as workshop_ofac.aleo/address_check.future;
await r2;
get.or_use balances[r0] 0u64 into r3;
add r3 r1 into r4;
set r4 into balances[r0];

function mint_private:
input r0 as address.private;
input r1 as u64.private;
call workshop_ofac.aleo/address_check r0 into r2;
cast r0 r1 into r3 as Token.record;
async mint_private r2 into r4;
output r3 as Token.record;
output r4 as aisha_token.aleo/mint_private.future;

finalize mint_private:
input r0 as workshop_ofac.aleo/address_check.future;
await r0;

function transfer_public:
input r0 as address.public;
input r1 as u64.public;
call workshop_ofac.aleo/address_check r0 into r2;
async transfer_public self.signer r0 r1 r2 into r3;
output r3 as aisha_token.aleo/transfer_public.future;

finalize transfer_public:
input r0 as address.public;
input r1 as address.public;
input r2 as u64.public;
input r3 as workshop_ofac.aleo/address_check.future;
await r3;
get.or_use balances[r0] 0u64 into r4;
sub r4 r2 into r5;
set r5 into balances[r0];
get.or_use balances[r1] 0u64 into r6;
add r6 r2 into r7;
set r7 into balances[r1];

function transfer_private:
input r0 as Token.record;
input r1 as address.private;
input r2 as u64.private;
call workshop_ofac.aleo/address_check r1 into r3;
sub r0.amount r2 into r4;
cast r0.owner r4 into r5 as Token.record;
cast r1 r2 into r6 as Token.record;
async transfer_private r3 into r7;
output r5 as Token.record;
output r6 as Token.record;
output r7 as aisha_token.aleo/transfer_private.future;

finalize transfer_private:
input r0 as workshop_ofac.aleo/address_check.future;
await r0;

constructor:
assert.eq edition 0u16;
9 changes: 9 additions & 0 deletions build/program.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"program": "aisha_token.aleo",
"version": "0.1.0",
"description": "",
"license": "",
"leo": "3.2.0",
"dependencies": null,
"dev_dependencies": null
}
2 changes: 1 addition & 1 deletion program.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"program": "token.aleo",
"program": "aisha_token.aleo",
"version": "0.1.0",
"description": "",
"license": "MIT",
Expand Down
39 changes: 37 additions & 2 deletions src/main.leo
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ TODO:

====================================================================================================================
*/
program token.aleo {
program aisha_token.aleo {
mapping balances: address => u64; // On-chain mapping between user addresses and public token balances

record Token {
Expand Down Expand Up @@ -54,6 +54,8 @@ program token.aleo {
let address_check : Future = workshop_ofac.aleo/address_check(recipient);

// TODO: Fill in here
return mint_public_onchain(recipient, amount, address_check);

}

async function mint_public_onchain(
Expand All @@ -64,6 +66,8 @@ program token.aleo {
address_check.await();

// TODO: Fill in here
let current_amount: u64 = Mapping::get_or_use(balances, recipient, 0u64 );
Mapping::set(balances, recipient, current_amount + amount);
}


Expand Down Expand Up @@ -92,12 +96,19 @@ program token.aleo {
private amount: u64
) -> (Token,Future) {
// TODO: Fill in here
let address_check:Future = workshop_ofac.aleo/address_check(recipient);
let token: Token = Token{
owner:recipient,
amount:amount,
};
return (token, mint_private_onchain(address_check));

}
async function mint_private_onchain(
address_check : Future
){
// TODO: Fill in here
address_check.await();
}


Expand Down Expand Up @@ -129,6 +140,9 @@ program token.aleo {
public amount: u64
) -> Future {
// TODO: Fill in here
let address_check:Future = workshop_ofac.aleo/address_check(recipient);

return transfer_public_onchain(self.signer, recipient, amount, address_check);
}
async function transfer_public_onchain(
public sender: address,
Expand All @@ -137,6 +151,11 @@ program token.aleo {
public address_check : Future
) {
// TODO: Fill in here
address_check.await();
let sender_amount: u64 = Mapping::get_or_use(balances, sender, 0u64);
Mapping::set(balances, sender, sender_amount - amount);
let reciever_amount:u64 = Mapping::get_or_use(balances, recipient, 0u64);
Mapping::set(balances, recipient, reciever_amount + amount);
}


Expand Down Expand Up @@ -170,12 +189,28 @@ program token.aleo {
private amount: u64
) -> (Token, Token, Future) {
// TODO: Fill in here
let address_check: Future = workshop_ofac.aleo/address_check(recipient);

let difference: u64 = sender.amount - amount;

let remaining: Token = Token {
owner: sender.owner,
amount: difference
};

let transferred: Token = Token {
owner: recipient,
amount: amount,
};

return (remaining, transferred, transfer_private_onchain(address_check));
}

async function transfer_private_onchain(
public address_check : Future
){
// TODO: Fill in here
address_check.await();
}


Expand Down Expand Up @@ -203,4 +238,4 @@ program token.aleo {

====================================================================================================================
*/
}
}