Skip to content

Commit 84c9fdb

Browse files
authored
chore(docs): Fix token bridge tutorial (AztecProtocol#3935)
Had a few missing links, wrong filepaths, and missing snippets
1 parent 6572bd6 commit 84c9fdb

5 files changed

Lines changed: 43 additions & 41 deletions

File tree

docs/docs/dev_docs/tutorials/token_portal/depositing_to_aztec.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,20 @@ In this step, we will write our token portal contract on L1.
88

99
In `l1-contracts/contracts` in your file called `TokenPortal.sol` paste this:
1010

11-
#include_code init /l1-contracts/test/portals/TokenPortal.sol solidity
11+
```solidity
12+
pragma solidity >=0.8.18;
13+
14+
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
15+
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
16+
17+
// Messaging
18+
import {IRegistry} from "@aztec/l1-contracts/src/core/interfaces/messagebridge/IRegistry.sol";
19+
import {IInbox} from "@aztec/l1-contracts/src/core/interfaces/messagebridge/IInbox.sol";
20+
import {DataStructures} from "@aztec/l1-contracts/src/core/libraries/DataStructures.sol";
21+
import {Hash} from "@aztec/l1-contracts/src/core/libraries/Hash.sol";
22+
23+
#include_code init /l1-contracts/test/portals/TokenPortal.sol raw
24+
```
1225

1326
This imports relevant files including the interfaces used by the Aztec rollup. And initializes the contract with the following parameters:
1427

docs/docs/dev_docs/tutorials/token_portal/setup.md

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ type = "contract"
6262

6363
[dependencies]
6464
aztec = { git="https://github.com/AztecProtocol/aztec-packages/", tag="#include_aztec_version", directory="yarn-project/aztec-nr/aztec" }
65-
token_portal_content_hash_lib = { git="https://github.com/AztecProtocol/aztec-packages/", tag="aztec-packages-v0.16.9", directory="yarn-project/noir-contracts/contracts/token_portal_content_hash_lib" }
65+
token_portal_content_hash_lib = { git="https://github.com/AztecProtocol/aztec-packages/", tag="#include_aztec_version", directory="yarn-project/noir-contracts/contracts/token_portal_content_hash_lib" }
66+
protocol_types = { git="https://github.com/AztecProtocol/aztec-packages/", tag="#include_aztec_version", directory="yarn-project/noir-protocol-circuits/src/crates/types"}
6667
```
6768

6869
We will also be writing some helper functions that should exist elsewhere so we don't overcomplicated our contract. In `src` create two more files - one called `util.nr` and one called `token_interface` - so your dir structure should now look like this:
@@ -74,6 +75,7 @@ aztec-contracts
7475
├── src
7576
├── main.nr
7677
├── token_interface.nr
78+
├── util.nr
7779
```
7880

7981
# Create a JS hardhat project
@@ -99,7 +101,7 @@ touch TokenPortal.sol
99101
Now add dependencies that are required. These include interfaces to Aztec Inbox, Outbox and Registry smart contracts, OpenZeppelin contracts, and NomicFoundation.
100102

101103
```bash
102-
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
104+
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
103105

104106
```
105107

@@ -129,7 +131,7 @@ Inside the `packages` directory, run
129131

130132
```bash
131133
mkdir src && cd src && yarn init -yp
132-
yarn add @aztec/aztec.js @aztec/accounts @aztec/noir-contracts @aztec/circuit-types @aztec/foundation @aztec/l1-artifacts viem "@types/node@^20.8.2"
134+
yarn add typescript @aztec/aztec.js @aztec/accounts @aztec/noir-contracts @aztec/types @aztec/foundation @aztec/l1-artifacts viem@1.21.4 "@types/node@^20.8.2"
133135
yarn add -D jest @jest/globals ts-jest
134136
```
135137

@@ -144,7 +146,7 @@ In `package.json`, add:
144146
}
145147
```
146148

147-
Your `package.json` should look something like this:
149+
Your `package.json` should look something like this (do not copy and paste):
148150

149151
```json
150152
{
@@ -154,18 +156,11 @@ Your `package.json` should look something like this:
154156
"license": "MIT",
155157
"private": true,
156158
"type": "module",
157-
"dependencies": {
158-
"@aztec/aztec.js": "^0.8.7",
159-
"@aztec/foundation": "^0.8.7",
160-
"@aztec/noir-contracts": "^0.8.7",
161-
"@aztec/circuit-types": "^0.8.7",
162-
"@types/node": "^20.8.2",
163-
"ethers": "^5.7"
159+
"dependencies": {
160+
"dep": "version",
164161
},
165162
"devDependencies": {
166-
"@jest/globals": "^29.7.0",
167-
"jest": "^29.7.0",
168-
"ts-jest": "^29.1.1"
163+
"dep": "version",
169164
},
170165
"scripts": {
171166
"test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules $(yarn bin jest)"
@@ -227,12 +222,6 @@ Then create a jest config file: `jest.config.json`
227222
}
228223
```
229224

230-
You will also need to install some dependencies:
231-
232-
```bash
233-
yarn add --dev typescript @types/jest ts-jest
234-
```
235-
236225
Finally, we will create a test file. Run this in the `src` directory.:
237226

238227
```bash
@@ -249,6 +238,7 @@ src
249238
└── cross_chain_messaging.test.ts
250239
├── jest.config.json
251240
├── package.json
241+
├── tsconfig.json
252242
```
253243

254244
In the next step, we’ll start writing our L1 smart contract with some logic to deposit tokens to Aztec from L1.

docs/docs/dev_docs/tutorials/token_portal/typescript_glue_code.md

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,12 @@ title: Deploy & Call Contracts with Typescript
44

55
In this step we will write a Typescript test to interact with the sandbox and call our contracts!
66

7-
Go to the `src/test` directory in your `packages` dir and create a new file called `cross_chain_messaging.test.ts`:
8-
9-
```bash
10-
cd src/test
11-
touch cross_chain_messaging.test.ts
12-
```
13-
147
## Test imports and setup
158

169
We need some helper files that can keep our code clean. Inside your `src/test` directory:
1710

1811
```bash
19-
mkdir fixtures && cd fixtures
12+
cd fixtures
2013
touch utils.ts
2114
cd .. && mkdir shared && cd shared
2215
touch cross_chain_test_harness.ts
@@ -47,8 +40,8 @@ Open `cross_chain_messaging.test.ts` and paste the initial description of the te
4740

4841
```typescript
4942
import { expect, jest} from '@jest/globals'
50-
import { AccountWallet, AztecAddress, DebugLogger, EthAddress, Fr, computeAuthWitMessageHash, createDebugLogger, createPXEClient, waitForPXE } from '@aztec/aztec.js';
51-
import { getInitialTestAccountsWallets } from '@aztec/accounts/testing';
43+
import { AccountWallet, AztecAddress, DebugLogger, EthAddress, Fr, computeAuthWitMessageHash, createDebugLogger, createPXEClient, waitForSandbox } from '@aztec/aztec.js';
44+
import { getSandboxAccountsWallets } from '@aztec/accounts/testing';
5245
import { TokenContract } from '@aztec/noir-contracts/Token';
5346
import { TokenBridgeContract } from '@aztec/noir-contracts/TokenBridge';
5447

@@ -80,8 +73,8 @@ describe('e2e_cross_chain_messaging', () => {
8073
beforeEach(async () => {
8174
logger = createDebugLogger('aztec:e2e_uniswap');
8275
const pxe = createPXEClient(PXE_URL);
83-
await waitForPXE(pxe);
84-
const wallets = await getInitialTestAccountsWallets(pxe);
76+
await waitForSandbox(pxe);
77+
const wallets = await getSandboxAccountsWallets(pxe);
8578

8679
const walletClient = createWalletClient({
8780
account: hdAccount,

docs/docs/dev_docs/tutorials/token_portal/withdrawing_to_l1.md

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,10 @@ For both the public and private flow, we use the same mechanism to determine the
4242
After the transaction is completed on L2, the portal must call the outbox to successfully transfer funds to the user on L1. Like with deposits, things can be complex here. For example, what happens if the transaction was done on L2 to burn tokens but can’t be withdrawn to L1? Then the funds are lost forever! How do we prevent this?
4343

4444
Paste this in your `TokenPortal.sol`:
45-
46-
#include_code token_portal_withdraw /l1-contracts/test/portals/TokenPortal.sol solidity
45+
```solidity
46+
#include_code token_portal_withdraw /l1-contracts/test/portals/TokenPortal.sol raw
47+
}
48+
```
4749

4850
Here we reconstruct the L2 to L1 message and check that this message exists on the outbox. If so, we consume it and transfer the funds to the recipient. As part of the reconstruction, the content hash looks similar to what we did in our bridge contract on aztec where we pass the amount and recipient to the the hash. This way a malicious actor can’t change the recipient parameter to the address and withdraw funds to themselves.
4951

@@ -53,13 +55,17 @@ We call this pattern _designed caller_ which enables a new paradigm **where we c
5355

5456
Before we can compile and use the contract, we need to add two additional functions.
5557

56-
We need a function that let's us read the token value.
58+
We need a function that lets us read the token value. Paste this into `main.nr`:
5759

5860
#include_code read_token /yarn-project/noir-contracts/contracts/token_bridge_contract/src/main.nr rust
5961

60-
And the `compute_note_hash_and_nullifier` required on every contract.
62+
And the `compute_note_hash_and_nullifier` required on every contract:
63+
64+
```rust
65+
#include_code compute_note_hash_and_nullifier_placeholder /yarn-project/noir-contracts/contracts/token_bridge_contract/src/main.nr raw
66+
}
67+
```
6168

62-
#include_code compute_note_hash_and_nullifier_placeholder /yarn-project/noir-contracts/contracts/token_bridge_contract/src/main.nr rust
6369

6470
## Compile code
6571

@@ -75,14 +81,14 @@ npx hardhat compile
7581
And compile your Aztec.nr contracts like this:
7682

7783
```bash
78-
cd aztec-contracts/token-bridge
84+
cd aztec-contracts/token_bridge
7985
aztec-nargo compile
8086
```
8187

8288
And generate the TypeScript interface for the contract and add it to the test dir:
8389

8490
```bash
85-
aztec-cli codegen target -o ../../../src/test/fixtures --ts
91+
aztec-cli codegen target -o ../../src/test/fixtures --ts
8692
```
8793

8894
This will create a TS interface in our `src/test` folder!

l1-contracts/test/portals/TokenPortal.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// docs:start:init
21
pragma solidity >=0.8.18;
32

43
import {IERC20} from "@oz/token/ERC20/IERC20.sol";
@@ -12,6 +11,7 @@ import {DataStructures} from "../../src/core/libraries/DataStructures.sol";
1211
import {Hash} from "../../src/core/libraries/Hash.sol";
1312
// docs:end:content_hash_sol_import
1413

14+
// docs:start:init
1515
contract TokenPortal {
1616
using SafeERC20 for IERC20;
1717

0 commit comments

Comments
 (0)