From e5f544b7c66519fb34016dd15975887219816cc6 Mon Sep 17 00:00:00 2001 From: Cat McGee Date: Thu, 19 Oct 2023 11:45:03 +0100 Subject: [PATCH 1/4] fix formatting issues --- .../token_portal/minting_on_aztec.md | 5 ++- .../dev_docs/tutorials/token_portal/setup.md | 20 ++++----- .../token_portal/typescript_glue_code.md | 8 ++-- .../dev_docs/tutorials/uniswap/l1_portal.md | 4 +- .../tutorials/uniswap/typescript_glue_code.md | 16 +++---- docs/sidebars.js | 44 +++++++++---------- 6 files changed, 49 insertions(+), 48 deletions(-) diff --git a/docs/docs/dev_docs/tutorials/token_portal/minting_on_aztec.md b/docs/docs/dev_docs/tutorials/token_portal/minting_on_aztec.md index e09a68929c87..b1ba0d07bae7 100644 --- a/docs/docs/dev_docs/tutorials/token_portal/minting_on_aztec.md +++ b/docs/docs/dev_docs/tutorials/token_portal/minting_on_aztec.md @@ -10,11 +10,12 @@ In our `token-bridge` nargo project in `aztec-contracts`, under `src` there is a ```rust mod util; -#include_code token_bridge_imports /yarn-project/noir-contracts/src/contracts/token_bridge_contract/src/main.nr rust raw +#include_code token_bridge_imports /yarn-project/noir-contracts/src/contracts/token_bridge_contract/src/main.nr raw use crate::token_interface::Token; use crate::util::{get_mint_public_content_hash, get_mint_private_content_hash, get_withdraw_content_hash}; -#include_code token_bridge_storage_and_constructor /yarn-project/noir-contracts/src/contracts/token_bridge_contract/src/main.nr rust raw +#include_code token_bridge_storage_and_constructor /yarn-project/noir-contracts/src/contracts/token_bridge_contract/src/main.nr raw ``` + This imports Aztec-related dependencies and our two helper files `token_interface.nr` and `util.nr`. (The code above will give errors right now - this is because we haven't implemented util and token_interface yet.) diff --git a/docs/docs/dev_docs/tutorials/token_portal/setup.md b/docs/docs/dev_docs/tutorials/token_portal/setup.md index 4c72b1e6545d..63c096fdb6c1 100644 --- a/docs/docs/dev_docs/tutorials/token_portal/setup.md +++ b/docs/docs/dev_docs/tutorials/token_portal/setup.md @@ -21,13 +21,13 @@ However if you’d rather skip this part, our dev-rels repo contains the starter - [docker](https://docs.docker.com/) - [Aztec sandbox](https://docs.aztec.network/dev_docs/getting_started/sandbox) - you should have this running before starting the tutorial -```sh +```bash /bin/sh -c "$(curl -fsSL 'https://sandbox.aztec.network')" ``` - Nargo -```sh +```bash curl -L https://raw.githubusercontent.com/noir-lang/noirup/main/install | sh noirup -v #include_noir_version ``` @@ -36,7 +36,7 @@ noirup -v #include_noir_version Our root project will house everything ✨ -```sh +```bash mkdir aztec-token-bridge ``` @@ -46,7 +46,7 @@ Now inside `aztec-token-bridge` create a new directory called `aztec-contracts` Inside `aztec-contracts`, create a nargo contract project by running -```sh +```bash mkdir aztec-contracts cd aztec-contracts nargo new --contract token_bridge @@ -89,7 +89,7 @@ aztec-contracts In the root dir `aztec-token-bridge`, create a new directory called `l1-contracts` and run `npx hardhat init` inside of it. Keep hitting enter so you get the default setup (Javascript project) -```sh +```bash mkdir l1-contracts cd l1-contracts npx hardhat init @@ -97,7 +97,7 @@ npx hardhat init Once you have a hardhat project set up, delete the existing contracts and create a `TokenPortal.sol`: -```sh +```bash cd contracts rm *.sol touch TokenPortal.sol @@ -105,7 +105,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. -```sh +```bash yarn add @aztec/l1-contracts @nomicfoundation/hardhat-network-helpers @nomicfoundation/hardhat-chai-matchers @nomiclabs/hardhat-ethers @nomiclabs/hardhat-etherscan @types/chai @types/mocha @typechain/ethers-v5 @typechain/hardhat chai hardhat-gas-reporter solidity-coverage ts-node typechain typescript @openzeppelin/contracts ``` @@ -136,7 +136,7 @@ We will use `viem` in this tutorial and `jest` for testing. Inside the root directory, run -```sh +```bash mkdir src && cd src && yarn init -yp yarn add @aztec/aztec.js @aztec/noir-contracts @aztec/types @aztec/foundation @aztec/l1-artifacts viem "@types/node@^20.8.2" yarn add -D jest @jest/globals ts-jest @@ -236,13 +236,13 @@ Then create a jest config file: `jest.config.json` You will also need to install some dependencies: -```sh +```bash yarn add --dev typescript @types/jest ts-jest ``` Finally, we will create a test file. Run this in the `src` directory.: -```sh +```bash mkdir test && cd test touch cross_chain_messaging.test.ts ``` diff --git a/docs/docs/dev_docs/tutorials/token_portal/typescript_glue_code.md b/docs/docs/dev_docs/tutorials/token_portal/typescript_glue_code.md index 8ed8d53a4a99..4cbf7c59ff84 100644 --- a/docs/docs/dev_docs/tutorials/token_portal/typescript_glue_code.md +++ b/docs/docs/dev_docs/tutorials/token_portal/typescript_glue_code.md @@ -6,7 +6,7 @@ In this step we will write a Typescript test to interact with the sandbox and ca Go to the `src/test` directory in your root dir and create a new file called `cross_chain_messaging.test.ts`: -```sh +```bash cd src/test touch cross_chain_messaging.test.ts ``` @@ -60,11 +60,11 @@ const [PortalERC20Abi, PortalERC20Bytecode] = const [TokenPortalAbi, TokenPortalBytecode] = getL1ContractABIAndBytecode("TokenPortal"); -#include_code deployL1Contract /yarn-project/ethereum/src/deploy_l1_contracts.ts typescript raw +#include_code deployL1Contract /yarn-project/ethereum/src/deploy_l1_contracts.ts raw -#include_code deployAndInitializeTokenAndBridgeContracts /yarn-project/end-to-end/src/shared/cross_chain_test_harness.ts typescript raw +#include_code deployAndInitializeTokenAndBridgeContracts /yarn-project/end-to-end/src/shared/cross_chain_test_harness.ts raw -#include_code delay /yarn-project/end-to-end/src/fixtures/utils.ts typescript raw +#include_code delay /yarn-project/end-to-end/src/fixtures/utils.ts raw ``` This code diff --git a/docs/docs/dev_docs/tutorials/uniswap/l1_portal.md b/docs/docs/dev_docs/tutorials/uniswap/l1_portal.md index 48623f896ed6..f22941f2514b 100644 --- a/docs/docs/dev_docs/tutorials/uniswap/l1_portal.md +++ b/docs/docs/dev_docs/tutorials/uniswap/l1_portal.md @@ -20,9 +20,9 @@ import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import {IRegistry} from "@aztec/l1-contracts/src/core/interfaces/messagebridge/IRegistry.sol"; import {DataStructures} from "@aztec/l1-contracts/src/core/libraries/DataStructures.sol"; import {Hash} from "@aztec/l1-contracts/src/core/libraries/Hash.sol"; -``` -#include_code setup l1-contracts/test/portals/UniswapPortal.sol solidity raw +#include_code setup l1-contracts/test/portals/UniswapPortal.sol raw +``` In this set up we defined the `initialize()` function and a struct (`LocalSwapVars`) to manage assets being swapped. diff --git a/docs/docs/dev_docs/tutorials/uniswap/typescript_glue_code.md b/docs/docs/dev_docs/tutorials/uniswap/typescript_glue_code.md index f4e793e2a4d0..525a11f2945a 100644 --- a/docs/docs/dev_docs/tutorials/uniswap/typescript_glue_code.md +++ b/docs/docs/dev_docs/tutorials/uniswap/typescript_glue_code.md @@ -6,7 +6,7 @@ In this step, we We will now write a Typescript to interact with the sandbox and In the root folder, go to `src` dir we created in [the token bridge tutorial](../token_portal/setup.md). -```sh +```bash cd src/test touch uniswap.test.ts ``` @@ -22,14 +22,14 @@ We will write two tests: To compile the Solidity contracts, run this: -```sh +```bash cd l1-contracts npx hardhat compile ``` and the Aztec.nr contracts: -```sh +```bash cd aztec-contracts aztec-cli compile --typescript ../../src/test/fixtures uniswap ``` @@ -59,7 +59,7 @@ export FORK_URL= Now rerun the sandbox: -```sh +```bash /bin/sh -c "$(curl -fsSL 'https://sandbox.aztec.network')" ``` @@ -114,9 +114,9 @@ const MNEMONIC = "test test test test test test test test test test test junk"; const hdAccount = mnemonicToAccount(MNEMONIC); const expectedForkBlockNumber = 17514288; -#include_code uniswap_l1_l2_test_setup_const yarn-project/end-to-end/src/shared/uniswap_l1_l2.ts typescript raw -#include_code uniswap_setup yarn-project/canary/src/uniswap_trade_on_l1_from_l2.test.ts typescript raw -#include_code uniswap_l1_l2_test_beforeAll yarn-project/end-to-end/src/shared/uniswap_l1_l2.ts typescript raw +#include_code uniswap_l1_l2_test_setup_const yarn-project/end-to-end/src/shared/uniswap_l1_l2.ts raw +#include_code uniswap_setup yarn-project/canary/src/uniswap_trade_on_l1_from_l2.test.ts raw +#include_code uniswap_l1_l2_test_beforeAll yarn-project/end-to-end/src/shared/uniswap_l1_l2.ts raw ``` ## Private flow test @@ -131,7 +131,7 @@ const expectedForkBlockNumber = 17514288; Make sure your sandbox is running. -```sh +```bash cd ~/.aztec && docker-compose up ``` diff --git a/docs/sidebars.js b/docs/sidebars.js index f8934b0138cb..5bf47ed851d9 100644 --- a/docs/sidebars.js +++ b/docs/sidebars.js @@ -55,7 +55,7 @@ const sidebars = { { type: "html", - value: '', + value: '', }, // SPECIFICATION @@ -245,7 +245,7 @@ const sidebars = { ], }, { - label: "Build Uniswap with Portals", + label: "Build a Uniswap Integration with Portals", type: "category", link: { type: "doc", @@ -312,27 +312,27 @@ const sidebars = { }, "dev_docs/contracts/common_errors", { - label: "Resources", - type: "category", - items: [ - //"dev_docs/contracts/resources/style_guide", - { - label: "Common Patterns", - type: "category", - // link: { - // type: "doc", - // id: "dev_docs/contracts/resources/common_patterns/main", - // }, - items: [ + label: "Resources", + type: "category", + items: [ + //"dev_docs/contracts/resources/style_guide", + { + label: "Common Patterns", + type: "category", + // link: { + // type: "doc", + // id: "dev_docs/contracts/resources/common_patterns/main", + // }, + items: [ "dev_docs/contracts/resources/common_patterns/authwit", - // "dev_docs/contracts/resources/common_patterns/sending_tokens_to_user", - // "dev_docs/contracts/resources/common_patterns/sending_tokens_to_contract", - // "dev_docs/contracts/resources/common_patterns/access_control", - // "dev_docs/contracts/resources/common_patterns/interacting_with_l1", - ], - }, - ], - }, + // "dev_docs/contracts/resources/common_patterns/sending_tokens_to_user", + // "dev_docs/contracts/resources/common_patterns/sending_tokens_to_contract", + // "dev_docs/contracts/resources/common_patterns/access_control", + // "dev_docs/contracts/resources/common_patterns/interacting_with_l1", + ], + }, + ], + }, // { // label: "Security Considerations", // type: "category", From fdfbb17f290d42a0686ba5d8a6540aecc0563b1c Mon Sep 17 00:00:00 2001 From: Cat McGee Date: Thu, 19 Oct 2023 11:52:18 +0100 Subject: [PATCH 2/4] set up instructions --- docs/docs/dev_docs/tutorials/token_portal/setup.md | 12 +++++++----- .../tutorials/token_portal/typescript_glue_code.md | 2 +- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/docs/docs/dev_docs/tutorials/token_portal/setup.md b/docs/docs/dev_docs/tutorials/token_portal/setup.md index 63c096fdb6c1..b2ebf35ff75f 100644 --- a/docs/docs/dev_docs/tutorials/token_portal/setup.md +++ b/docs/docs/dev_docs/tutorials/token_portal/setup.md @@ -87,26 +87,28 @@ aztec-contracts # Create a JS hardhat project -In the root dir `aztec-token-bridge`, create a new directory called `l1-contracts` and run `npx hardhat init` inside of it. Keep hitting enter so you get the default setup (Javascript project) +In the root dir `aztec-token-bridge`, 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) ```bash mkdir l1-contracts cd l1-contracts +yarn init -yp npx hardhat init ``` -Once you have a hardhat project set up, delete the existing contracts and create a `TokenPortal.sol`: +Once you have a hardhat project set up, delete the existing contracts, tests, and scripts, and create a `TokenPortal.sol`: ```bash -cd contracts -rm *.sol +rm -rf contracts test scripts +mkdir contracts && cd contracts 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/l1-contracts @nomicfoundation/hardhat-network-helpers @nomicfoundation/hardhat-chai-matchers @nomiclabs/hardhat-ethers @nomiclabs/hardhat-etherscan @types/chai @types/mocha @typechain/ethers-v5 @typechain/hardhat chai hardhat-gas-reporter solidity-coverage ts-node typechain typescript @openzeppelin/contracts +yarn add @aztec/foundation @aztec/l1-contracts @openzeppelin/contracts && yarn add @nomicfoundation/hardhat-network-helpers @nomicfoundation/hardhat-chai-matchers @nomiclabs/hardhat-ethers @nomiclabs/hardhat-etherscan @types/chai @types/mocha @typechain/ethers-v5 @typechain/hardhat chai hardhat-gas-reporter solidity-coverage ts-node typechain typescript --dev ``` diff --git a/docs/docs/dev_docs/tutorials/token_portal/typescript_glue_code.md b/docs/docs/dev_docs/tutorials/token_portal/typescript_glue_code.md index 4cbf7c59ff84..0b18a8cd9247 100644 --- a/docs/docs/dev_docs/tutorials/token_portal/typescript_glue_code.md +++ b/docs/docs/dev_docs/tutorials/token_portal/typescript_glue_code.md @@ -165,7 +165,7 @@ This fetches the wallets from the sandbox and deploys our cross chain harness on ```bash cd packages/src -yarn test +DEBUG='aztec:canary_uniswap' yarn test ``` ### Error handling From 36148c47da43c616a85f0da48453feea026f398f Mon Sep 17 00:00:00 2001 From: Cat McGee Date: Thu, 19 Oct 2023 20:47:59 +0100 Subject: [PATCH 3/4] packages pattern to match repo --- docs/docs/dev_docs/tutorials/token_portal/setup.md | 11 +++++++---- .../tutorials/token_portal/typescript_glue_code.md | 2 +- .../tutorials/token_portal/withdrawing_to_l1.md | 2 +- docs/docs/dev_docs/tutorials/uniswap/setup.md | 2 +- .../tutorials/uniswap/typescript_glue_code.md | 4 ++-- 5 files changed, 12 insertions(+), 9 deletions(-) diff --git a/docs/docs/dev_docs/tutorials/token_portal/setup.md b/docs/docs/dev_docs/tutorials/token_portal/setup.md index b2ebf35ff75f..7aecd0d32059 100644 --- a/docs/docs/dev_docs/tutorials/token_portal/setup.md +++ b/docs/docs/dev_docs/tutorials/token_portal/setup.md @@ -32,17 +32,20 @@ curl -L https://raw.githubusercontent.com/noir-lang/noirup/main/install | sh noirup -v #include_noir_version ``` -# Create the root project +# Create the root project and packages Our root project will house everything ✨ ```bash mkdir aztec-token-bridge +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 nargo project -Now inside `aztec-token-bridge` create a new directory called `aztec-contracts` +Now inside `packages` create a new directory called `aztec-contracts` Inside `aztec-contracts`, create a nargo contract project by running @@ -87,7 +90,7 @@ aztec-contracts # Create a JS hardhat project -In the root dir `aztec-token-bridge`, create a new directory called `l1-contracts` and run `yarn init -yp && +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) ```bash @@ -136,7 +139,7 @@ In this directory, we will write TS code that will interact with our L1 and L2 c We will use `viem` in this tutorial and `jest` for testing. -Inside the root directory, run +Inside the `packages` directory, run ```bash mkdir src && cd src && yarn init -yp diff --git a/docs/docs/dev_docs/tutorials/token_portal/typescript_glue_code.md b/docs/docs/dev_docs/tutorials/token_portal/typescript_glue_code.md index 0b18a8cd9247..8775c14955ac 100644 --- a/docs/docs/dev_docs/tutorials/token_portal/typescript_glue_code.md +++ b/docs/docs/dev_docs/tutorials/token_portal/typescript_glue_code.md @@ -4,7 +4,7 @@ title: Deploy & Call Contracts with Typescript In this step we will write a Typescript test to interact with the sandbox and call our contracts! -Go to the `src/test` directory in your root dir and create a new file called `cross_chain_messaging.test.ts`: +Go to the `src/test` directory in your `packages` dir and create a new file called `cross_chain_messaging.test.ts`: ```bash cd src/test diff --git a/docs/docs/dev_docs/tutorials/token_portal/withdrawing_to_l1.md b/docs/docs/dev_docs/tutorials/token_portal/withdrawing_to_l1.md index 9e0a4aad9e5c..9f66177bce92 100644 --- a/docs/docs/dev_docs/tutorials/token_portal/withdrawing_to_l1.md +++ b/docs/docs/dev_docs/tutorials/token_portal/withdrawing_to_l1.md @@ -57,7 +57,7 @@ We call this pattern _designed caller_ which enables a new paradigm **where we c Congratulations, you have written all the contracts we need for this tutorial! Now let's compile them. -Compile your Solidity contracts using hardhat. Run this in the root of your project: +Compile your Solidity contracts using hardhat. Run this in the `packages` directory: ```bash cd l1-contracts diff --git a/docs/docs/dev_docs/tutorials/uniswap/setup.md b/docs/docs/dev_docs/tutorials/uniswap/setup.md index 5fce5ff89bd0..7eb1051f139c 100644 --- a/docs/docs/dev_docs/tutorials/uniswap/setup.md +++ b/docs/docs/dev_docs/tutorials/uniswap/setup.md @@ -11,7 +11,7 @@ If you don’t have this, you can find the code for it [in our dev-rels repo](ht To interact with Uniswap we need to add its interface. In the root repo we created in the [token bridge tutorial](../token_portal/main.md), run this: ```bash -cd l1-contracts +cd packages/l1-contracts mkdir external && cd external touch ISwapRouter.sol ``` diff --git a/docs/docs/dev_docs/tutorials/uniswap/typescript_glue_code.md b/docs/docs/dev_docs/tutorials/uniswap/typescript_glue_code.md index 525a11f2945a..ff965fa77d7d 100644 --- a/docs/docs/dev_docs/tutorials/uniswap/typescript_glue_code.md +++ b/docs/docs/dev_docs/tutorials/uniswap/typescript_glue_code.md @@ -4,7 +4,7 @@ title: Deploy & Call Contracts with Typescript In this step, we We will now write a Typescript to interact with the sandbox and see our Solidity and Aztec.nr contracts in action. -In the root folder, go to `src` dir we created in [the token bridge tutorial](../token_portal/setup.md). +In the `packages` directory, go to `src` dir we created in [the token bridge tutorial](../token_portal/setup.md). ```bash cd src/test @@ -138,6 +138,6 @@ cd ~/.aztec && docker-compose up Then run this in the root directory. ```bash -cd src +cd packages/src yarn test uniswap ``` From b961d39082eb0d65a64084225d285d0abf21f41d Mon Sep 17 00:00:00 2001 From: Cat McGee Date: Thu, 19 Oct 2023 20:49:57 +0100 Subject: [PATCH 4/4] addressed rahul's comments --- docs/docs/dev_docs/tutorials/token_portal/setup.md | 2 +- docs/sidebars.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/docs/dev_docs/tutorials/token_portal/setup.md b/docs/docs/dev_docs/tutorials/token_portal/setup.md index 7aecd0d32059..170dc06164b2 100644 --- a/docs/docs/dev_docs/tutorials/token_portal/setup.md +++ b/docs/docs/dev_docs/tutorials/token_portal/setup.md @@ -111,7 +111,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 @nomicfoundation/hardhat-network-helpers @nomicfoundation/hardhat-chai-matchers @nomiclabs/hardhat-ethers @nomiclabs/hardhat-etherscan @types/chai @types/mocha @typechain/ethers-v5 @typechain/hardhat chai hardhat-gas-reporter solidity-coverage ts-node typechain typescript --dev +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 hardhat-gas-reporter solidity-coverage ts-node typechain typescript ``` diff --git a/docs/sidebars.js b/docs/sidebars.js index 5bf47ed851d9..3ecb982658f6 100644 --- a/docs/sidebars.js +++ b/docs/sidebars.js @@ -245,7 +245,7 @@ const sidebars = { ], }, { - label: "Build a Uniswap Integration with Portals", + label: "Swap on L1 Uniswap from L2 with Portals", type: "category", link: { type: "doc",