diff --git a/docs/docs/developers/tutorials/crowdfunding/donations.md b/docs/docs/developers/tutorials/crowdfunding/donations.md index 16dcfae5c58..ffbe02ed122 100644 --- a/docs/docs/developers/tutorials/crowdfunding/donations.md +++ b/docs/docs/developers/tutorials/crowdfunding/donations.md @@ -94,7 +94,7 @@ aztec = { git="https://github.com/AztecProtocol/aztec-packages/", tag="#include_ ``` A word about versions: -- Choose the aztec packages version to match your aztec tools as seen here - `aztec-cli -V` +- Choose the aztec packages version to match your aztec sandbox version - Check that your `compiler_version` in Nargo.toml is satisified by your aztec compiler - `aztec-nargo -V` More about versions [here](https://docs.aztec.network/developers/versions-updating). diff --git a/docs/docs/developers/tutorials/token_portal/depositing_to_aztec.md b/docs/docs/developers/tutorials/token_portal/depositing_to_aztec.md index 167d77e46b5..0b05d3e92a6 100644 --- a/docs/docs/developers/tutorials/token_portal/depositing_to_aztec.md +++ b/docs/docs/developers/tutorials/token_portal/depositing_to_aztec.md @@ -17,6 +17,7 @@ import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol // Messaging import {IRegistry} from "@aztec/l1-contracts/src/core/interfaces/messagebridge/IRegistry.sol"; import {IInbox} from "@aztec/l1-contracts/src/core/interfaces/messagebridge/IInbox.sol"; +import {IOutbox} from "@aztec/l1-contracts/src/core/interfaces/messagebridge/IOutbox.sol"; import {DataStructures} from "@aztec/l1-contracts/src/core/libraries/DataStructures.sol"; import {Hash} from "@aztec/l1-contracts/src/core/libraries/Hash.sol"; @@ -35,6 +36,12 @@ Create a file `PortalERC20.sol` in the same folder and add: #include_code contract /l1-contracts/test/portals/PortalERC20.sol solidity +Replace the openzeppelin import with this: + +```solidity +import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; +``` + ## Depositing tokens to Aztec publicly Next, we will write a function that is used to deposit funds on L1 that a user may have into an Aztec portal and send a message to the Aztec rollup to mint tokens _publicly_ on Aztec. diff --git a/docs/docs/developers/tutorials/token_portal/setup.md b/docs/docs/developers/tutorials/token_portal/setup.md index 8eb45c6d435..d4c44d37496 100644 --- a/docs/docs/developers/tutorials/token_portal/setup.md +++ b/docs/docs/developers/tutorials/token_portal/setup.md @@ -15,7 +15,7 @@ We recommend going through this setup to fully understand where things live. However if you’d rather skip this part, our dev-rels repo contains the starter code here. -# Prerequisites +## Prerequisites - [node v18+](https://github.com/tj/n) - [docker](https://docs.docker.com/) @@ -26,7 +26,7 @@ However if you’d rather skip this part, our dev-rels repo contains the starter /bin/sh -c "$(curl -fsSL 'https://sandbox.aztec.network')" ``` -# Create the root project and packages +## Create the root project and packages Our root project will house everything ✨ @@ -37,11 +37,21 @@ cd aztec-token-bridge && mkdir packages We will hold our projects inside of `packages` to follow the design of the project in the [repo](https://github.com/AztecProtocol/dev-rel/tree/main/tutorials/token-bridge-e2e). -# Create a noir project +## Create a noir project -Now inside `packages` create a new directory called `aztec-contracts` +Inside `packages` create a new directory `aztec-contracts`: -Inside `aztec-contracts`, create the following file structure: +```bash +cd packages && mkdir aztec-contracts +``` + +Inside `aztec-contracts` create a new contract project like this: + +```bash +aztec-nargo new --contract token_bridge +``` + +Your file structure should look something like this: ```tree aztec-contracts @@ -51,18 +61,13 @@ aztec-contracts ├── main.nr ``` -Inside `Nargo.toml` add the following content: +Inside `Nargo.toml` add the following dependencies: ```toml -[package] -name = "token_bridge" -authors = [""] -compiler_version = ">=0.18.0" -type = "contract" - [dependencies] aztec = { git="https://github.com/AztecProtocol/aztec-packages/", tag="#include_aztec_version", directory="noir-projects/aztec-nr/aztec" } token_portal_content_hash_lib = { git="https://github.com/AztecProtocol/aztec-packages/", tag="#include_aztec_version", directory="noir-projects/noir-contracts/contracts/token_portal_content_hash_lib" } +token = { git="https://github.com/AztecProtocol/aztec-packages/", tag="#include_aztec_version", directory="noir-projects/noir-contracts/contracts/token_contract" } ``` We will also be writing some helper functions that should exist elsewhere so we don't overcomplicated our contract. In `src` create one more file called `util.nr` - so your dir structure should now look like this: @@ -76,7 +81,7 @@ aztec-contracts ├── util.nr ``` -# Create a JS hardhat project +## Create a JS hardhat project In the `packages` dir, create a new directory called `l1-contracts` and run `yarn init -yp && npx hardhat init` inside of it. Keep hitting enter so you get the default setup (Javascript project) @@ -91,7 +96,7 @@ npx hardhat init Once you have a hardhat project set up, delete the existing contracts, tests, and scripts, and create a `TokenPortal.sol`: ```bash -rm -rf contracts test scripts +rm -rf contracts test scripts ignition mkdir contracts && cd contracts touch TokenPortal.sol ``` @@ -99,8 +104,7 @@ touch TokenPortal.sol Now add dependencies that are required. These include interfaces to Aztec Inbox, Outbox and Registry smart contracts, OpenZeppelin contracts, and NomicFoundation. ```bash -yarn add @aztec/foundation @aztec/l1-contracts @openzeppelin/contracts && yarn add --dev @nomicfoundation/hardhat-network-helpers @nomicfoundation/hardhat-chai-matchers @nomiclabs/hardhat-ethers @nomiclabs/hardhat-etherscan @types/chai @types/mocha @typechain/ethers-v5 @typechain/hardhat chai@4.0.0 hardhat-gas-reporter solidity-coverage ts-node typechain typescript - +yarn add @aztec/foundation @aztec/l1-contracts @openzeppelin/contracts ethers && yarn add --dev @nomicfoundation/hardhat-network-helpers @nomicfoundation/hardhat-chai-matchers @nomiclabs/hardhat-ethers @nomiclabs/hardhat-etherscan @types/chai @types/mocha @typechain/ethers-v5 @typechain/hardhat chai@4.0.0 hardhat-gas-reporter solidity-coverage ts-node typechain typescript @nomicfoundation/hardhat-ignition @nomicfoundation/hardhat-ignition-ethers @nomicfoundation/hardhat-verify ``` This is what your `l1-contracts` should look like: @@ -129,7 +133,7 @@ Inside the `packages` directory, run ```bash mkdir src && cd src && yarn init -yp -yarn add typescript @aztec/aztec.js @aztec/accounts @aztec/noir-contracts.js @aztec/types @aztec/foundation @aztec/l1-artifacts viem@1.21.4 "@types/node@^20.8.2" +yarn add typescript @aztec/aztec.js @aztec/accounts @aztec/noir-contracts.js @aztec/types @aztec/foundation @aztec/l1-artifacts viem@^2.7.15 "@types/node@^20.8.2" yarn add -D jest @jest/globals ts-jest ``` @@ -141,7 +145,7 @@ In `package.json`, add: "type": "module", "scripts": { "test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules $(yarn bin jest)" -} +}, ``` Your `package.json` should look something like this (do not copy and paste): diff --git a/docs/docs/developers/tutorials/token_portal/typescript_glue_code.md b/docs/docs/developers/tutorials/token_portal/typescript_glue_code.md index 592ca263f2f..7fd19a14a8e 100644 --- a/docs/docs/developers/tutorials/token_portal/typescript_glue_code.md +++ b/docs/docs/developers/tutorials/token_portal/typescript_glue_code.md @@ -36,10 +36,11 @@ Open `cross_chain_messaging.test.ts` and paste the initial description of the te ```typescript import { expect, jest} from '@jest/globals' -import { AccountWallet, AztecAddress, DebugLogger, EthAddress, Fr, computeAuthWitMessageHash, createDebugLogger, createPXEClient, waitForSandbox } from '@aztec/aztec.js'; -import { getSandboxAccountsWallets } from '@aztec/accounts/testing'; +import { AccountWallet, AztecAddress, DebugLogger, EthAddress, Fr, computeAuthWitMessageHash, createDebugLogger, createPXEClient, waitForPXE } from '@aztec/aztec.js'; +import { getInitialTestAccountsWallets } from '@aztec/accounts/testing'; import { TokenContract } from '@aztec/noir-contracts.js/Token'; -import { TokenBridgeContract } from '@aztec/noir-contracts.js/TokenBridge'; +import { TokenBridgeContract } from './fixtures/TokenBridge.js'; +import { createAztecNodeClient } from '@aztec/circuit-types'; import { CrossChainTestHarness } from './shared/cross_chain_test_harness.js'; import { mnemonicToAccount } from 'viem/accounts'; @@ -49,12 +50,12 @@ import { foundry } from 'viem/chains'; const { PXE_URL = 'http://localhost:8080', ETHEREUM_HOST = 'http://localhost:8545' } = process.env; const MNEMONIC = 'test test test test test test test test test test test junk'; const hdAccount = mnemonicToAccount(MNEMONIC); +const aztecNode = createAztecNodeClient(PXE_URL); describe('e2e_cross_chain_messaging', () => { jest.setTimeout(90_000); let logger: DebugLogger; - // include code: let user1Wallet: AccountWallet; let user2Wallet: AccountWallet; let ethAccount: EthAddress; @@ -68,8 +69,8 @@ describe('e2e_cross_chain_messaging', () => { beforeEach(async () => { logger = createDebugLogger('aztec:e2e_uniswap'); const pxe = createPXEClient(PXE_URL); - await waitForSandbox(pxe); - const wallets = await getSandboxAccountsWallets(pxe); + await waitForPXE(pxe); + const wallets = await getInitialTestAccountsWallets(pxe); const walletClient = createWalletClient({ account: hdAccount, @@ -82,6 +83,7 @@ describe('e2e_cross_chain_messaging', () => { }); crossChainTestHarness = await CrossChainTestHarness.new( + aztecNode, pxe, publicClient, walletClient, diff --git a/docs/docs/developers/tutorials/token_portal/withdrawing_to_l1.md b/docs/docs/developers/tutorials/token_portal/withdrawing_to_l1.md index 38a5458d786..82d8ca8cfbe 100644 --- a/docs/docs/developers/tutorials/token_portal/withdrawing_to_l1.md +++ b/docs/docs/developers/tutorials/token_portal/withdrawing_to_l1.md @@ -79,12 +79,14 @@ cd aztec-contracts/token_bridge aztec-nargo compile ``` -And generate the TypeScript interface for the contract and add it to the test dir: +You may get some unused variable warnings - you can ignore these. + +And generate the TypeScript interface for the contract and add it to the test dir. Run this inside `aztec-contracts/token_bridge`: ```bash aztec-builder target -o ../../src/test/fixtures ``` -This will create a TS interface in our `src/test` folder! +This will create a TS interface inside `fixtures` dir in our `src/test` folder! In the next step we will write the TypeScript code to deploy our contracts and call on both L1 and L2 so we can see how everything works together. diff --git a/docs/docs/developers/tutorials/uniswap/l1_portal.md b/docs/docs/developers/tutorials/uniswap/l1_portal.md index f22941f2514..d628755da83 100644 --- a/docs/docs/developers/tutorials/uniswap/l1_portal.md +++ b/docs/docs/developers/tutorials/uniswap/l1_portal.md @@ -13,12 +13,14 @@ cd l1-contracts/contracts && touch UniswapPortal.sol and paste this inside: ```solidity -pragma solidity ^0.8.20; +pragma solidity >=0.8.18; import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import {IRegistry} from "@aztec/l1-contracts/src/core/interfaces/messagebridge/IRegistry.sol"; +import {IOutbox} from "@aztec/l1-contracts/src/core/interfaces/messagebridge/IOutbox.sol"; import {DataStructures} from "@aztec/l1-contracts/src/core/libraries/DataStructures.sol"; +import {DataStructures as PortalDataStructures} from "./DataStructures.sol"; import {Hash} from "@aztec/l1-contracts/src/core/libraries/Hash.sol"; #include_code setup l1-contracts/test/portals/UniswapPortal.sol raw diff --git a/docs/docs/developers/tutorials/writing_private_voting_contract.md b/docs/docs/developers/tutorials/writing_private_voting_contract.md index 6af73511d58..f4c17808781 100644 --- a/docs/docs/developers/tutorials/writing_private_voting_contract.md +++ b/docs/docs/developers/tutorials/writing_private_voting_contract.md @@ -39,15 +39,9 @@ Your file structure should look something like this: The file `main.nr` will soon turn into our smart contract! -We will need the Aztec library to create this contract. Add the following content to `Nargo.toml`: +We will need the Aztec library to create this contract. In your `Nargo.toml` you should see `[dependencies]` - paste this bellow it. ```toml -[package] -name = "private_voting" -type = "contract" -authors = [""] -compiler_version = ">=0.18.0" - [dependencies] aztec = { git="https://github.com/AztecProtocol/aztec-packages", tag="#include_aztec_version", directory="noir-projects/aztec-nr/aztec" } ``` @@ -70,13 +64,11 @@ Inside this, paste these imports: We are using various utils within the Aztec library: -- `context` - exposes things such as the contract address, msg_sender, etc -- `context.request_nullifier_secret_key` - get your secret key to help us create a randomized nullifier -- `FunctionSelector::from_signature` - compute a function selector from signature so we can call functions from other functions -- `state_vars::{Map, PublicMutable}` - we will use a Map to store the votes (key = voteId, value = number of votes), and PublicMutable to hold our public values that we mentioned earlier -- `types::type_serialization::{..}` - various serialization methods for defining how to use these types -- `types::address::{AztecAddress},` - our admin will be held as an address -- `constants::EMPTY_NULLIFIED_COMMITMENT,` - this will come in useful when creating our nullifier +- `Context` and `PrivateContext` - exposes things such as the contract address, msg_sender, etc +- `AztecAddress` - A type for storing an address on Aztec +- `FunctionSelector` - Used for computing a selector to call a function +- `Map` - A data storage type for storing candidates with the number of votes they have +- `PublicMutable` - A type of storage, which holds a mutable public value. We'll store votes as PublicMutables ## Set up storage @@ -155,7 +147,9 @@ The easiest way to compile the contract is with `aztec-nargo`. Run the following aztec-nargo compile ``` -This will create a new directory called `target` and a JSON artifact inside it. To optionally create a typescript interface, run: +This will create a new directory called `target` and a JSON artifact inside it. + +Once it is compiled you can [deploy](../contracts/deploying_contracts/how_to_deploy_contract.md) it to the sandbox. Ensure your [sandbox is running](../sandbox/references/sandbox-reference.md). ```bash aztec-builder target -o src/artifacts diff --git a/docs/docs/developers/tutorials/writing_token_contract.md b/docs/docs/developers/tutorials/writing_token_contract.md index 5805cddfe55..cc555428c13 100644 --- a/docs/docs/developers/tutorials/writing_token_contract.md +++ b/docs/docs/developers/tutorials/writing_token_contract.md @@ -26,48 +26,41 @@ Check the [Dev Tools section](https://github.com/noir-lang/awesome-noir#dev-tool ## Project setup -Create a new directory called `token_contract_tutorial` +Create a new project with: ```bash -mkdir token_contract_tutorial +aztec-nargo new --contract token_contract ``` -inside that directory, create a `contracts` folder for the Aztec contracts. - -```bash -cd token_contract_tutorial && mkdir contracts && cd contracts -``` - -Create the following file structure +Your file structure should look something like this: ```tree . -└── contracts - ├── Nargo.toml - └── src - └── main.nr +|--private_voting +| |--src +| | |--main.nr +| |--Nargo.toml ``` -Add the following content to Nargo.toml file: +Inside `Nargo.toml` paste the following: ```toml -[package] -name = "token_contract" -authors = [""] -compiler_version = ">=0.18.0" -type = "contract" - [dependencies] aztec = { git="https://github.com/AztecProtocol/aztec-packages/", tag="#include_aztec_version", directory="noir-projects/aztec-nr/aztec" } authwit={ git="https://github.com/AztecProtocol/aztec-packages/", tag="#include_aztec_version", directory="noir-projects/aztec-nr/authwit"} compressed_string = {git="https://github.com/AztecProtocol/aztec-packages/", tag="#include_aztec_version", directory="noir-projects/aztec-nr/compressed-string"} ``` +We will be working within `main.nr` for the rest of the tutorial. + ## Contract Interface +Remove everything from `main.nr` and paste this: + ```rust contract Token { #[aztec(private)] + #[aztec(initializer)] fn constructor() {} #[aztec(public)] @@ -111,11 +104,13 @@ contract Token { #[aztec(public)] fn _initialize(new_admin: AztecAddress) {} + #[aztec(internal)] #[aztec(public)] - internal fn _increase_public_balance(to: AztecAddress, amount: Field) {} + fn _increase_public_balance(to: AztecAddress, amount: Field) {} + #[aztec(internal)] #[aztec(public)] - internal fn _reduce_total_supply(amount: Field) {} + fn _reduce_total_supply(amount: Field) {} // Unconstrained functions (read only) @@ -131,7 +126,7 @@ contract Token { } ``` -This specifies the interface of the `Token` contract. Go ahead and copy and paste this interface into your `main.nr` file. +This specifies the interface of the `Token` contract. Don't worry if you get some warnings - we haven't imported our types yet. Before we through the interface and implement each function, let's review the functions to get a sense of what the contract does. @@ -204,7 +199,12 @@ Just below the contract definition, add the following imports: #include_code imports /noir-projects/noir-contracts/contracts/token_contract/src/main.nr rust -We are importing the Option type, items from the `value_note` library to help manage private value storage, note utilities, context (for managing private and public execution contexts), `state_vars` for helping manage state, `types` for data manipulation and `oracle` for help passing data from the private to public execution context. We also import the `auth` [library](https://github.com/AztecProtocol/aztec-packages/blob/#include_aztec_version/noir-projects/aztec-nr/aztec/src/auth.nr) to handle token authorizations from [Account Contracts](../../learn/concepts/accounts/main). Check out the Account Contract with AuthWitness [here](https://github.com/AztecProtocol/aztec-packages/blob/#include_aztec_version/noir-projects/noir-contracts/contracts/schnorr_single_key_account_contract/src/main.nr). +We are importing: + +- `CompressedString` to hold the token symbol +- Types from `aztec::prelude` +- `compute_secret_hash` that will help with the shielding and unshielding, allowing someone to claim a token from private to public +- Types for storing note types For more detail on execution contexts, see [Contract Communication](../../learn/concepts/communication/main). diff --git a/docs/docs/developers/versions-updating.md b/docs/docs/developers/versions-updating.md index 7e2e46d8169..a4fee3a3640 100644 --- a/docs/docs/developers/versions-updating.md +++ b/docs/docs/developers/versions-updating.md @@ -74,14 +74,14 @@ VERSION=0.35.0 aztec-up 2. Update aztec-nr and individual @aztec dependencies: - +The sandbox must be running for the update command to work. Make sure it is [installed and running](../developers/sandbox/references/sandbox-reference.md). Follow [updating Aztec.nr packages](#updating-aztecnr-packages) and [updating JavaScript packages](#updating-aztecjs-packages) guides. @@ -96,19 +96,19 @@ There are four components whose versions need to be kept compatible: 3. `Aztec.nr`, the Noir framework for writing Aztec contracts First three are packaged together in docker and are kept compatible by running `aztec-up`. -But you need to update your Aztec.nr version manually or using `aztec-cli update`. +But you need to update your Aztec.nr version manually or using `aztec-builder update`. ## Updating Aztec.nr packages - +### Manual update To update the aztec.nr packages manually, update the tags of the `aztec.nr` dependencies in the `Nargo.toml` file. diff --git a/docs/sidebars.js b/docs/sidebars.js index 9c522947d5d..b2272172ad8 100644 --- a/docs/sidebars.js +++ b/docs/sidebars.js @@ -260,25 +260,25 @@ const sidebars = { "developers/tutorials/token_portal/typescript_glue_code", ], }, - { - label: "Swap on L1 Uniswap from L2 with Portals", - type: "category", - link: { - type: "doc", - id: "developers/tutorials/uniswap/main", - }, - items: [ - "developers/tutorials/uniswap/setup", - "developers/tutorials/uniswap/l1_portal", - "developers/tutorials/uniswap/l2_contract_setup", - "developers/tutorials/uniswap/swap_publicly", - "developers/tutorials/uniswap/execute_public_swap_on_l1", - "developers/tutorials/uniswap/swap_privately", - "developers/tutorials/uniswap/execute_private_swap_on_l1", - "developers/tutorials/uniswap/redeeming_swapped_assets_on_l2", - "developers/tutorials/uniswap/typescript_glue_code", - ], - }, + // { // temporarily removing as it is very very messy with monorepo references. we need to write new ts for this + // label: "Swap on L1 Uniswap from L2 with Portals", + // type: "category", + // link: { + // type: "doc", + // id: "developers/tutorials/uniswap/main", + // }, + // items: [ + // "developers/tutorials/uniswap/setup", + // "developers/tutorials/uniswap/l1_portal", + // "developers/tutorials/uniswap/l2_contract_setup", + // "developers/tutorials/uniswap/swap_publicly", + // "developers/tutorials/uniswap/execute_public_swap_on_l1", + // "developers/tutorials/uniswap/swap_privately", + // "developers/tutorials/uniswap/execute_private_swap_on_l1", + // "developers/tutorials/uniswap/redeeming_swapped_assets_on_l2", + // "developers/tutorials/uniswap/typescript_glue_code", + // ], + // }, "developers/tutorials/testing", ], }, diff --git a/l1-contracts/test/portals/DataStructures.sol b/l1-contracts/test/portals/DataStructures.sol index 7f6291a0f98..03245f859c1 100644 --- a/l1-contracts/test/portals/DataStructures.sol +++ b/l1-contracts/test/portals/DataStructures.sol @@ -1,3 +1,4 @@ +// docs:start:portals_data_structures // SPDX-License-Identifier: Apache-2.0 // Copyright 2024 Aztec Labs. pragma solidity >=0.8.18; @@ -9,3 +10,4 @@ library DataStructures { bytes32[] _path; } } +// docs:end:portals_data_structures diff --git a/noir-projects/noir-contracts/contracts/uniswap_contract/src/main.nr b/noir-projects/noir-contracts/contracts/uniswap_contract/src/main.nr index f8227136c67..7fe8812d566 100644 --- a/noir-projects/noir-contracts/contracts/uniswap_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/uniswap_contract/src/main.nr @@ -223,12 +223,13 @@ contract Uniswap { token.eq(TokenBridge::at(token_bridge).get_token().call(&mut context)), "input_asset address is not the same as seen in the bridge contract" ); } - // docs:end:assert_token_is_same - + // /// Unconstrained /// // this method exists solely for e2e tests to test that nonce gets incremented each time. unconstrained fn nonce_for_burn_approval() -> pub Field { storage.nonce_for_burn_approval.read() } + // docs:end:assert_token_is_same + }