diff --git a/.gitignore b/.gitignore index f721f7f..82f5efc 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,3 @@ -.env *.avm *.prover *.verifier diff --git a/README.md b/README.md index 10dafc0..1c023f1 100644 --- a/README.md +++ b/README.md @@ -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` \ No newline at end of file diff --git a/build/imports/workshop_ofac.aleo b/build/imports/workshop_ofac.aleo new file mode 100644 index 0000000..1970e5b --- /dev/null +++ b/build/imports/workshop_ofac.aleo @@ -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; diff --git a/build/main.aleo b/build/main.aleo new file mode 100644 index 0000000..44d9fde --- /dev/null +++ b/build/main.aleo @@ -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; diff --git a/build/program.json b/build/program.json new file mode 100644 index 0000000..7d29927 --- /dev/null +++ b/build/program.json @@ -0,0 +1,9 @@ +{ + "program": "aisha_token.aleo", + "version": "0.1.0", + "description": "", + "license": "", + "leo": "3.2.0", + "dependencies": null, + "dev_dependencies": null +} diff --git a/program.json b/program.json index 6f437e0..749f290 100644 --- a/program.json +++ b/program.json @@ -1,5 +1,5 @@ { - "program": "token.aleo", + "program": "aisha_token.aleo", "version": "0.1.0", "description": "", "license": "MIT", diff --git a/src/main.leo b/src/main.leo index b80a248..e732b26 100644 --- a/src/main.leo +++ b/src/main.leo @@ -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 { @@ -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( @@ -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); } @@ -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(); } @@ -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, @@ -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); } @@ -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(); } @@ -203,4 +238,4 @@ program token.aleo { ==================================================================================================================== */ -} +} \ No newline at end of file