Skip to content
Merged
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
target
target
.DS_Store
9 changes: 9 additions & 0 deletions starter-token/reference/contract/Nargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "starter_token_contract"
authors = [""]
compiler_version = ">=1.0.0"
type = "contract"

[dependencies]
aztec = { git = "https://github.com/AztecProtocol/aztec-packages/", tag = "v1.2.1", directory = "noir-projects/aztec-nr/aztec" }
easy_private_state = { git = "https://github.com/AztecProtocol/aztec-packages/", tag = "v1.2.1", directory = "noir-projects/aztec-nr/easy-easy_private-state" }
102 changes: 102 additions & 0 deletions starter-token/reference/contract/src/main.nr
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
use aztec::macros::aztec;

#[aztec]
pub contract StarterToken {
use aztec::{
state_vars::{private_set::PrivateSet, public_mutable::PublicMutable, map::Map},
messages::logs::note::encode_and_encrypt_note,
note::note_viewer_options::NoteViewerOptions,
macros::{
functions::{initializer, private, public, utility, internal},
storage::storage,
},
protocol_types::address::AztecAddress,
};

use easy_private_state::EasyPrivateUint;

#[storage]
struct Storage<Context> {
balances: Map<AztecAddress, PublicMutable<u128, Context>, Context>,
owner: PublicMutable<AztecAddress, Context>,
// ===============
private_balances: Map<AztecAddress, EasyPrivateUint<Context>, Context>,
}

#[initializer]
#[public]
fn setup() {
// The deployer (msg_sender) becomes the owner
storage.owner.write(context.msg_sender());
}

#[public]
fn mint(to: AztecAddress, amount: u128) {
assert_eq(maybe_owner, storage.owner.read());

let recipient_balance = storage.balances.at(to).read();

storage.balances.at(context.msg_sender()).write(recipient_balance + amount);
}

#[public]
fn transfer(to: AztecAddress, amount: u128) {
let sender = context.msg_sender();

let sender_balance = storage.balances.at(sender).read();

assert(sender_balance >= amount, "Cannot transfer more than the balance of the user");

storage.balances.at(sender).write(sender_balance - amount);

let recipient_balance = storage.balances.at(to).read();

storage.balances.at(to).write(recipient_balance + amount);
}

#[public]
fn transfer_ownership(new_owner: AztecAddress) {
let maybe_contract_owner = context.msg_sender();

assert_eq(maybe_owner, storage.owner.read());

storage.owner.write(new_owner);
}

// ===============

#[private]
fn mint_private(to: AztecAddress, amount: u128) {
GettingStarted::at(context.this_address())._assert_is_owner(context.msg_sender()).enqueue(&mut context);

storage.private_balances.at(to).add(value, to);
}

#[private]
fn transfer_private(to: AztecAddress, amount: u128) {
let sender = context.msg_sender();

storage.private_balances.at(sender).sub(amount, sender);

storage.private_balances.at(to).add(amount, to);
}

#[public]
#[internal]
fn _assert_is_owner(maybe_owner: AztecAddress) {
assert_eq(maybe_owner, storage.owner.read());
}

#[utility]
unconstrained fn balance_of(owner: AztecAddress) -> u128 {
let notes = storage.private_balances.at(owner).view_notes(NoteViewerOptions::new());

let mut amount = 0 as u128;
for i in 0..notes.len() {
let note = notes.get_unchecked(i);
amount = amount + note.get_value();
}

amount
}
}
9 changes: 9 additions & 0 deletions starter-token/reference/external-call-contract/Nargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "external_call_contract"
authors = [""]
compiler_version = ">=1.0.0"
type = "contract"

[dependencies]
aztec = { git = "https://github.com/AztecProtocol/aztec-packages/", tag = "v1.2.1", directory = "noir-projects/aztec-nr/aztec" }
starter_token = { path = "../nr" }
16 changes: 16 additions & 0 deletions starter-token/reference/external-call-contract/src/main.nr
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
use aztec::macros::aztec;

#[aztec]
pub contract ExternalCall {
use aztec::{
macros::functions::private,
protocol_types::address::AztecAddress,
};

use dep::starter_token::StarterToken;

#[private]
fn call_mint_on_other_contract(contract_address: AztecAddress, to: AztecAddress, amount: u128) {
StarterToken::at(contract_address).mint_private(to, amount).call(&mut context);
}
}
19 changes: 19 additions & 0 deletions starter-token/reference/ts/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "getting-started",
"version": "1.0.0",
"description": "",
"license": "ISC",
"author": "",
"type": "module",
"scripts": {
"build": "npx tsc",
"start": "npm run build && node dist/src/index.js"
},
"dependencies": {
"@aztec/accounts": "^1.2.1",
"@aztec/aztec.js": "^1.2.1"
},
"devDependencies": {
"typescript": "^5.8.3"
}
}
20 changes: 20 additions & 0 deletions starter-token/reference/ts/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { GettingStartedContract } from '../artifacts/GettingStarted.js';
import {
Fr,
createPXEClient,
waitForPXE,
} from '@aztec/aztec.js';
import { getInitialTestAccountsWallets } from '@aztec/accounts/testing';

const pxe = createPXEClient('http://localhost:8080');
await waitForPXE(pxe);

const wallets = await getInitialTestAccountsWallets(pxe);
const deployerWallet = wallets[0];

const contractDeploymentSalt = Fr.random();
const gettingStartedContract = await GettingStartedContract
.deploy(deployerWallet)
.send({ contractAddressSalt: contractDeploymentSalt }).wait();

console.log('Contract Address', gettingStartedContract.contract.address);
13 changes: 13 additions & 0 deletions starter-token/reference/ts/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"compilerOptions": {
"target": "esnext", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
"module": "nodenext", /* Specify what module code is generated. */
"moduleResolution": "nodenext", /* Specify how TypeScript looks up a file from a given module specifier. */
"resolveJsonModule": true, /* Enable importing .json files. */
"esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
"forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
"strict": true, /* Enable all strict type-checking options. */
"skipLibCheck": true, /* Skip type checking all .d.ts files. */
"outDir": "./dist"
}
}
8 changes: 8 additions & 0 deletions starter-token/start-here/contract/Nargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[package]
name = "starter_token_contract"
authors = [""]
compiler_version = ">=1.0.0"
type = "contract"

[dependencies]
aztec = { git = "https://github.com/AztecProtocol/aztec-packages/", tag = "v1.2.1", directory = "noir-projects/aztec-nr/aztec" }
6 changes: 6 additions & 0 deletions starter-token/start-here/contract/src/main.nr
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
use aztec::macros::aztec;

#[aztec]
pub contract StarterToken {
// Start here !
}
9 changes: 9 additions & 0 deletions starter-token/start-here/external-call-contract/Nargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "external_call_contract"
authors = [""]
compiler_version = ">=1.0.0"
type = "contract"

[dependencies]
aztec = { git = "https://github.com/AztecProtocol/aztec-packages/", tag = "v1.2.1", directory = "noir-projects/aztec-nr/aztec" }
starter_token = { path = "../nr" }
16 changes: 16 additions & 0 deletions starter-token/start-here/external-call-contract/src/main.nr
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
use aztec::macros::aztec;

#[aztec]
pub contract ExternalCall {
use aztec::{
macros::functions::private,
protocol_types::address::AztecAddress,
};

use dep::starter_token::StarterToken;

#[private]
fn call_mint_on_other_contract(contract_address: AztecAddress, to: AztecAddress, amount: u128) {
StarterToken::at(contract_address).mint_private(to, amount).call(&mut context);
}
}
19 changes: 19 additions & 0 deletions starter-token/start-here/ts/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "getting-started",
"version": "1.0.0",
"description": "",
"license": "ISC",
"author": "",
"type": "module",
"scripts": {
"build": "npx tsc",
"start": "npm run build && node dist/src/index.js"
},
"dependencies": {
"@aztec/accounts": "^1.2.1",
"@aztec/aztec.js": "^1.2.1"
},
"devDependencies": {
"typescript": "^5.8.3"
}
}
3 changes: 3 additions & 0 deletions starter-token/start-here/ts/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { StarterTokenContract } from '../artifacts/StarterToken.js';

// Start here !
13 changes: 13 additions & 0 deletions starter-token/start-here/ts/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"compilerOptions": {
"target": "esnext", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
"module": "nodenext", /* Specify what module code is generated. */
"moduleResolution": "nodenext", /* Specify how TypeScript looks up a file from a given module specifier. */
"resolveJsonModule": true, /* Enable importing .json files. */
"esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
"forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
"strict": true, /* Enable all strict type-checking options. */
"skipLibCheck": true, /* Skip type checking all .d.ts files. */
"outDir": "./dist"
}
}
Loading