Skip to content

Commit

Permalink
Merge pull request #12 from AztecProtocol/jc-devs-getting-started
Browse files Browse the repository at this point in the history
Add Developers - Getting Started page
  • Loading branch information
critesjosh authored Sep 23, 2022
2 parents de8736b + fd66de2 commit 78da00d
Show file tree
Hide file tree
Showing 8 changed files with 1,777 additions and 831 deletions.
58 changes: 58 additions & 0 deletions docs/docs/developers/getting-started.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
---
title: Getting Started
---

## Building on Aztec

There are two common ways that developers can start building on Aztec.

1. Build a user facing application that connects to the Aztec network via the Typescript SDK.
2. Build an Aztec Connect bridge that connects the Aztec network to Ethereum smart contracts.

We are also working on Noir, a domain specific language for creating and verifying proofs. There are some resources to learn more about this project at the bottom of the page.

## Building with the SDK

The fastest way to get started developing on Aztec is using the public mainnet fork testnet.

1. Connect Metamask (or other Ethereum wallet) to the testnet
1. Chain ID: `677868`
2. RPC URL: `https://mainnet-fork.aztec.network`
2. Get testnet funds
1. Ping [@critesjosh_](https://twitter.com/critesjosh_) for testnet ETH. We will have a public faucet published soon.
3. Install the SDK in your project.
1. `npm install @aztec/sdk`
4. Interact with Aztec (optional, useful for cross-referencing)
1. Use the testnet version of zk.money (https://aztec-connect-testnet.zk.money/)
2. Use the `azteccli` command line tool. https://github.com/critesjosh/azteccli

Once you have testnet ETH and setup the SDK, you can start interacting with the Aztec network. You can start registering accounts, making deposits, doing transfers and withdrawals and other things supported by the [SDK](../sdk/overview.md).

You can see how to set up the SDK on the [setup page](../sdk/usage/setup.mdx) or in the command line repo (https://github.com/critesjosh/azteccli/blob/main/src/base.ts).

The [overview page](../sdk/overview.md) of the SDK section has more information about using the SDK.

### Aztec SDK Resources

- [Aztec SDK on npm](https://www.npmjs.com/package/@aztec/sdk)
- [Aztec SDK on GitHub](https://github.com/AztecProtocol/aztec-connect/tree/master/sdk)
- [Getting Started with Aztec CLI / SDK](https://hackmd.io/NOtgWFSxS-Ko5mLlqt5GRw)
- [Aztec CLI](https://github.com/critesjosh/azteccli)
- [Testnet zk.money](https://aztec-connect-testnet.zk.money/)
- [Testnet block explorer](https://aztec-connect-testnet-explorer.aztec.network/)

## Building an Aztec Connect Bridge Contract

The [Aztec Connect bridges GitHub repository](https://github.com/AztecProtocol/aztec-connect-bridges) has the most up to date information about creating a bridge contract.

## Noir

Noir is a Domain Specific Language for SNARK proving systems. It can be used outside of Aztec or blockchain contexts. Noir will be used to create future versions of Aztec and as an integral part of the developer stack for building applications on Aztec.

It has been designed to use any ACIR compatible proving system. It's design choices are influenced heavily by Rust.

### Noir Resources

- [Official GitHub repo](https://github.com/noir-lang/noir)
- [The Noir Programming Language Book](https://noir-lang.github.io/book/index.html)
- [Getting Started with Noir Guide](https://hackmd.io/8jmyfuuTRWKr2w6rxr8HBw)
4 changes: 2 additions & 2 deletions docs/docs/sdk/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
title: SDK Overview
---

The Aztec SDK is the gateway for developers to access the Aztec network and benefit from low gas fees and privacy on Ethereum. The SDK connects to Ethereum and our zk-rollup service and can be integrated with a few lines of code.
The Aztec SDK is the gateway for developers to access the Aztec network and benefit from low gas fees and privacy on Ethereum. The SDK connects to Ethereum and an Aztec client and can be integrated with a few lines of code.

The SDK is designed to abstract away the complexities of zero-knowledge proofs from the developer and end users. It provides a simple API for creating accounts, depositing and withdrawing tokens and interacting with Ethereum smart contracts anonymously. Core transfers inside the SDK are private by default.
The SDK is designed to abstract away the complexities of zero-knowledge proofs from the developer and end users. It provides a simple API for creating accounts, depositing and withdrawing tokens and interacting with Ethereum smart contracts anonymously. Aztec native transfers with the SDK are private by default.

Under the hood the SDK keeps track of a users private balances across multiples assets and provides easy to use helper methods to the developer to create seamless private UI's.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
```ts
import { BitConfig } from './bit_config';
export declare class BridgeId {
readonly addressId: number;
export declare class BridgeCallData {
readonly bridgeAddressId: number;
readonly inputAssetIdA: number;
readonly outputAssetIdA: number;
readonly inputAssetIdB?: number | undefined;
readonly outputAssetIdB?: number | undefined;
readonly auxData: number;
static ZERO: BridgeId;
static ZERO: BridgeCallData;
static ENCODED_LENGTH_IN_BYTES: number;
readonly bitConfig: BitConfig;
constructor(addressId: number, inputAssetIdA: number, outputAssetIdA: number, inputAssetIdB?: number | undefined, outputAssetIdB?: number | undefined, auxData?: number);
static random(): BridgeId;
static fromBigInt(val: bigint): BridgeId;
static fromBuffer(buf: Buffer): BridgeId;
static fromString(str: string): BridgeId;
constructor(bridgeAddressId: number, inputAssetIdA: number, outputAssetIdA: number, inputAssetIdB?: number | undefined, outputAssetIdB?: number | undefined, auxData?: number);
static random(): BridgeCallData;
static fromBigInt(val: bigint): BridgeCallData;
static fromBuffer(buf: Buffer): BridgeCallData;
static fromString(str: string): BridgeCallData;
get firstInputVirtual(): boolean;
get secondInputVirtual(): boolean;
get firstOutputVirtual(): boolean;
Expand All @@ -26,6 +26,6 @@ export declare class BridgeId {
toBigInt(): bigint;
toBuffer(): Buffer;
toString(): string;
equals(id: BridgeId): boolean;
equals(id: BridgeCallData): boolean;
}
```
28 changes: 14 additions & 14 deletions docs/docs/sdk/usage/ethereum-interaction.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ The [DefiController](../types/sdk/DefiController) makes it easy to interact dire
AztecSdk.createDefiController(
userId: GrumpkinAddress,
userSigner: Signer,
bridgeId: BridgeId,
bridgeCallData: BridgeCallData,
value: AssetValue,
fee: AssetValue)
: Promise<DefiController>
Expand All @@ -24,7 +24,7 @@ AztecSdk.createDefiController(
| --------- | ---- | ----------- |
| userId | [GrumpkinAddress](../types/barretenberg/GrumpkinAddress) | Owner of the value note to be sent. |
| userSigner | [Signer](../types/sdk/Signer) | A signer associated with the `userId`. |
| bridgeId | [BridgeId](../types/barretenberg/BridgeId) | A unique id corresponding to the bridge that the `value` is sent to. |
| bridgeCallData | [BridgeCallData](../types/barretenberg/BridgeCallData) | A unique id corresponding to the bridge that the `value` is sent to. |
| value | [AssetValue](../types/barretenberg/AssetValue) | Asset type and amount to send. |
| fee | [AssetValue](../types/barretenberg/AssetValue) | Asset type and amount to pay for the Aztec transaction fee. |

Expand All @@ -34,19 +34,19 @@ AztecSdk.createDefiController(
| --------- | ----------- |
| [DefiController](../types/sdk/DefiController) | A user instance with apis bound to the user's account id. |

## BridgeId Setup
## BridgeCallData Setup

A bridge `addressId` is required to setup a [BridgeId](../types/barretenberg/BridgeId). The `addressId` is a number associated with the bridge. It increments by 1 as new bridges are deployed to Ethereum and added to the rollup processor contract.
A bridge `addressId` is required to setup [BridgeCallData](../types/barretenberg/BridgeCallData). The `addressId` is a number associated with the bridge. It increments by 1 as new bridges are deployed to Ethereum and added to the rollup processor contract.

You can get the bridge `addressId`s from the published [Deployed Bridge Info table](https://github.com/AztecProtocol/aztec-connect-bridges#deployed-bridge-info).

You can also query the bridge ids on the rollup processor contracts directly. [Here is the link](https://etherscan.io/address/0xff1f2b4adb9df6fc8eafecdcbf96a2b351680455#readProxyContract
) to read the contract Etherscan. You can get the bridge contract addresses from the `getSupportedBridge` or `getSupportedBridges` functions. The bridge `addressId` corresponds to it's index in the supported bridges array returned by `getSupportedBridges`.

Once you have the bridge `addressId`, you can initialize a new bridge instance. The `BridgeId` contstructor looks like this:
Once you have the bridge `addressId`, you can initialize a new bridge instance. The `BridgeCallData` contstructor looks like this:

```ts
const bridge = new BridgeId(
const bridge = new BridgeCallData(
addressId: number,
inputAssetIdA: number,
outputAssetIdA: number,
Expand All @@ -64,12 +64,12 @@ const bridge = new BridgeId(
| outputAssetIdB | number | Optional. The [asset id](../../glossary#asset-ids) of the second output asset. |
| auxData | number | Custom auxiliary data for bridge-specific logic. |

The `BridgeId` is passed to the `DefiController` to specify how to construct the interaction.
The `BridgeCallData` is passed to the `DefiController` to specify how to construct the interaction.

For example, you can create the `BridgeId` for the ETH to wstETH Lido bridge like this:
For example, you can create the `BridgeCallData` for the ETH to wstETH Lido bridge like this:

```ts
const ethToWstEthBridge = new BridgeId(2, 0, 2); // IN: ETH (0), OUT: wstETH (2)
const ethToWstEthBridge = new BridgeCallData(2, 0, 2); // IN: ETH (0), OUT: wstETH (2)
```

The Lido bridge contract is `addressId` 2, takes 1 input asset (ETH, `assetId` = 0) and returns 1 output asset (wstETH, `assetId` = 2). This bridge doesn't take any `auxData` since it is just a simple exchange of ETH to wstETH.
Expand All @@ -91,8 +91,8 @@ For example:
```ts
const elementAdaptor = createElementAdaptor(
ethereumProvider,
"0xFF1F2B4ADb9dF6FC8eAFecDcbF96A2B351680455", // rollup address
"0xaeD181779A8AAbD8Ce996949853FEA442C2CDB47", // bridge address
"0xFF1F2B4ADb9dF6FC8eAFecDcbF96A2B351680455", // rollup contract
"0xaeD181779A8AAbD8Ce996949853FEA442C2CDB47", // bridge contract
false // mainnet flag
);
```
Expand All @@ -107,12 +107,12 @@ await elementAdaptor.getAuxData?(
outputAssetB: AztecAsset): Promise<bigint[]>;
```

This function returns an index of numbers corresponding to various tranche expiry times that correspond to the inputAsset. This will determine which tranche the user interacts with. So you could set up a `BridgeId` for a user to interact with the latest tranche by passing the last index of the array of returned expiry times.
This function returns an index of numbers corresponding to various tranche expiry times that correspond to the inputAsset. This will determine which tranche the user interacts with. So you could set up `BridgeCallData` for a user to interact with the latest tranche by passing the last index of the array of returned expiry times.

Looking at the [Deployed Bridge Info table](https://github.com/AztecProtocol/aztec-connect-bridges#deployed-bridge-info), the Element bridge is id 1, it takes DAI (asset id 1) and returns DAI and you can pass an element from the `auxData` array from the connector and pass this to the `DefiController`.

```ts
const elementBridge = new BridgeId(1, 1, 1, undefined, undefined, Number(elementAuxData[0])); // IN: DAI (1), OUT: DAI (1)
const elementBridge = new BridgeCallData(1, 1, 1, undefined, undefined, Number(elementAuxData[0])); // IN: DAI (1), OUT: DAI (1)
```

#### Async `finalise`
Expand All @@ -125,7 +125,7 @@ If you want to finalise a defi interaction without having to rely on interaction

## Fees

Similarly to other controllers, the SDK comes with a helper method to calculate fees. It requires the `BridgeId` since different bridges cost different amounts of gas. `settlementTime` is type [DefiSettlementTime](../types/barretenberg/DefiSettlementTime).
Similarly to other controllers, the SDK comes with a helper method to calculate fees. It requires the `BridgeCallData` since different bridges cost different amounts of gas. `settlementTime` is type [DefiSettlementTime](../types/barretenberg/DefiSettlementTime).

`DefiSettlementTime` is an enum with members `DEADLINE`, `NEXT_ROLLUP` and `INSTANT`. `DEADLINE` is the slowest and cheapest. It provides a longer opportunity for your transaction to be batched with other similar interactions. `NEXT_ROLLUP` is the next most expensive and will process in the next regardless of the number of similar interactions. `INSTANT` is the most expensive and will pay the cost to settle the rollup and process the interaction immediately.

Expand Down
4 changes: 2 additions & 2 deletions docs/docs/sdk/usage/setup.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const setupSdk = async () => {
sdk = await createAztecSdk(walletProvider, {
serverUrl: process.env.ROLLUP_HOST,
pollInterval: 1000,
memoryDb: true,
memoryDb: true, // set to false to save chain data
debug: "bb:*", // print debug logs
flavour: SdkFlavour.PLAIN, // Use PLAIN with Nodejs
minConfirmation: 1, // ETH block confirmations
Expand Down Expand Up @@ -83,7 +83,7 @@ You can enable debugging when you create the SDK instance.
const sdk = await createAztecSdk(ethereumProvider, {
serverUrl: "https://aztec-connect-testnet-sdk.aztec.network", // mainnet fork testnet
pollInterval: 1000,
memoryDb: true,
memoryDb: true, // set to false to save DB in a project file rather than memory
debug: "bb:*",
minConfirmation: 1, // ETH block confirmations
});
Expand Down
8 changes: 4 additions & 4 deletions docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@
"write-heading-ids": "docusaurus write-heading-ids"
},
"dependencies": {
"@docusaurus/core": "2.0.0-beta.20",
"@docusaurus/plugin-ideal-image": "^2.0.0-beta.20",
"@docusaurus/preset-classic": "2.0.0-beta.20",
"@docusaurus/core": "^2.1.0",
"@docusaurus/plugin-ideal-image": "^2.1.0",
"@docusaurus/preset-classic": "^2.1.0",
"@mdx-js/react": "^1.6.22",
"clsx": "^1.1.1",
"prism-react-renderer": "^1.3.1",
"react": "^17.0.2",
"react-dom": "^17.0.2"
},
"devDependencies": {
"@docusaurus/module-type-aliases": "^2.0.0-beta.20",
"@docusaurus/module-type-aliases": "^2.1.0",
"@tsconfig/docusaurus": "^1.0.5",
"typescript": "^4.7.2"
},
Expand Down
7 changes: 7 additions & 0 deletions docs/sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ const sidebars = {
"how-aztec-works/faq",
],
},
{
type: 'category',
label: 'Developers',
items: [
'developers/getting-started'
]
},
// {
// type: 'category',
// label: 'Guides',
Expand Down
Loading

0 comments on commit 78da00d

Please sign in to comment.