# Aztec Network On/Off Ramp Spec A mechanism for people to purchase and sell ETH, LUSD, DAI or other assets directly on the Aztec rollup is highly desirable. This avoids Ethereum L1 transaction fees for depositing and withdrawing assets between Aztec and Ethereum. It is important to note that there are 2 types of accounts in Aztec, basic accounts and registered accounts. Basic accounts are just a private/public keypair. Registered accounts include distinct spending keys, an "alias" to identify accounts and some additional features. Registering an account requires a transaction on the network. You can read more about the two types of accounts [here](https://docs.aztec.network/how-aztec-works/accounts). ## Requirements - A funded Aztec account to send funds to individual's Aztec accounts when on-ramping - Aztec account(s) to receive funds when users are off-ramping. This can be done in multiple ways. - create a unique aztec account for each user or withdrawal request. When that account receives funds, you know exactly who it came from. - optionally, users send aztec transaction proofs to the service provider off-chain. The service provider validates the tx info, accepting or rejecting the transaction based on pre-determined acceptance criteria, before submitting to the Aztec sequencer. - have 1 common recipient for all users. Users will have to reveal their pub key when sending funds to the off ramp account. - Integration with a web application so that users can easily ### On ramping 1. Hold assets in an aztec account that will be used to send to people 2. Transfer assets to a user when USD deposit settles (off chain) a. Use the `TransferController` to send assets on Aztec (relevant docs [here](https://docs.aztec.network/sdk/usage/transfer)) b. `userId` is the public key of the sender. c. `value` is the amount and asset id (`AssetValue`) of the asset to send. d. `fee` is the amount and asset id of the transaction fee e. `recipient` is the customer's public key that is on-ramping. This can be collected directly from the user, or can use the SDK to lookup the public key from an alias (for registered accounts) with the `sdk.isAliasRegistered(alias: string)` and `sdk.getAccountPublicKey(alias: string)` methods. f. `recipientSpendingKeyRequired` is a flag that indicates whether the assets should be spendable by the account spending keys (for registered accounts). 3. Top up Aztec account when balance drops below a certain threshold a. A deposit will not be credited to the recipient's account until the next rollup block (10 mins - several hours) #### Network sync requirements On-ramping does not require that the web application is synced with the Aztec network. It is only used to get the `recipient` public key from the user (which could also be done through other means [eg an input form]). The SDK and creation of the `TransferController` can be done on the service provider's server. #### Relevant Interfaces: ```typescript AztecSdk.createTransferController( userId: GrumpkinAddress, userSigner: Signer, value: AssetValue, fee: AssetValue, recipient: GrumpkinAddress, recipientSpendingKeyRequired?: boolean) : Promise<TransferController>; ``` ```typescript interface AssetValue { assetId: number; value: bigint; } ``` ### Off ramping 1. A user initiates an off-ramping transaction 2. The off-ramp service generates a new (basic) account to receive the users transfer. a. Generate a random 32 byte private key (possibly from HD wallet key) b. Derive the public key with `sdk.derivePublicKey(privateKey: Buffer)` c. Save public key and off-ramp request info in an off-chain database 3. The user makes the transfer using the `TransferController` to the generated public key. 4. Wait for a rollup block to settle that includes the transaction. Can check with `sdk.getTransactionReceipt(txHash: TxHash, timeout?: number, interval?: number): Promise<Receipt>;` a. You can also query the Aztec sequencer for information about a specific transaction. [Relevant docs](https://docs.aztec.network/developers/sequencer-api#transactions) 6. Once the block settles, send off-chain USD to the user Alternatively: The transaction can also be sent directly ("off-chain") to the off-ramp for processing/validation and forwarding to the sequencer, this way it can be pre-validated and should always succeed unless a user spends the notes with a malicious tx. The USD should be held until the Aztec transaction is settled. This could also be useful for compliance as the off-ramp can reject transactions here. #### Network sync requirements Users must be synced with the Aztec network on their local machine, so the SDK is aware of which asset notes are available for spending and for creating the transaction proof. #### Relevant interfaces: ```typescript interface Receipt { status: boolean; blockNum?: number; revertError?: RevertError; } ``` ### Web application integration 1. Set up the SDK, [Setup docs page](https://docs.aztec.network/sdk/usage/setup) 2. Create an instance of the AztecSdk ```javascript sdk = await createAztecSdk(ethereumProvider, { serverUrl: "https://api.aztec.network/aztec-connect-testnet/falafel", // testnet pollInterval: 1000, debug: "bb:*", // print debug logs flavour: SdkFlavour.PLAIN, // Use PLAIN with Nodejs minConfirmation: 1, // ETH block confirmations }); await sdk.run(); await sdk.awaitSynchronised(); ``` 3. Get user account keys 4. Create the transaction