Skip to main content

Defi Bridge Contract Interface

Types

library AztecTypes {
enum AztecAssetType {
NOT_USED,
ETH,
ERC20,
VIRTUAL
}

struct AztecAsset {
uint256 id;
address erc20Address;
AztecAssetType assetType;
}
}

The AztecAsset struct is an attempt at a more developer-friendly description of an Aztec asset that does not rely on bit flags.

The type of the asset is described by an enum. For virtual or not used assets, the erc20Address will be 0.

For input virtual assets, the id field will contain the interaction nonce of the interaction that created the asset.

For output virtual assets, the id field will be the current interaction nonce.

External Methods

convert

Initiate a DeFi interaction and inform the rollup contract of the proceeds. If the DeFi interaction cannot proceed for any reason, it is expected that the convert method will throw.

    function convert(
AztecTypes.AztecAsset memory inputAssetA,
AztecTypes.AztecAsset memory inputAssetB,
AztecTypes.AztecAsset memory outputAssetA,
AztecTypes.AztecAsset memory outputAssetB,
uint256 totalInputValue,
uint256 interactionNonce,
uint64 auxData
)
external
payable
override
returns (
uint256 outputValueA,
uint256 outputValueB,
bool _isAsync
)
Input Values:
NameTypeDescription
inputAssetAAztecAssetfirst input asset
inputAssetBAztecAssetsecond input asset. Either VIRTUAL or NOT_USED
outputAssetAAztecAssetfirst output asset. Cannot be virtual
outputAssetBAztecAssetsecond output asset. Can be real or virtual (or NOT_USED)
totalInputValueuint256The amount of inputAsset this bridge contract is allowed to transfer from the rollup contract.
interactionNonceuint256The current defi interaction nonce
auxDatauint64Custom auxiliary metadata
Return Values:
NameTypeDescription
outputValueAuint256The amount of outputAssetA the rollup contract will be able to transfer from this bridge contract. Must be greater than 0 if numOutputAssets is 1.
outputValueBuint256The amount of outputAssetB the rollup contract will be able to transfer from this bridge contract. Must be 0 if numOutputAssets is 1.

In the unfortunate event when both output values are zeros, this function should throw so that the rollup contract could refund inputValue back to the users.

bit positionbit lengthdefinitiondescription
064auxDatacustom auxiliary data for bridge-specific logic
6432bitConfigflags that describe asset types
9632openingNonce(optional) reference to a previous defi interaction nonce (used for virtual assets)
12830outputAssetBasset id of 2nd output asset
15830outputAssetAasset id of 1st output asset
18830inputAssetasset id of 1st input asset
21832bridgeAddressIdid of bridge smart contract address

Bit Config Definition

bitmeaning
0firstInputVirtual
1secondInputVirtual
2firstOutputVirtual
3secondOutputVirtual
4secondInputReal
5secondOutputReal