-
Notifications
You must be signed in to change notification settings - Fork 143
/
IDefiBridge.sol
69 lines (66 loc) · 4.31 KB
/
IDefiBridge.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// SPDX-License-Identifier: Apache-2.0
// Copyright 2022 Aztec
pragma solidity >=0.8.4;
import {AztecTypes} from "rollup-encoder/libraries/AztecTypes.sol";
interface IDefiBridge {
/**
* @notice A function which converts input assets to output assets.
* @param _inputAssetA A struct detailing the first input asset
* @param _inputAssetB A struct detailing the second input asset
* @param _outputAssetA A struct detailing the first output asset
* @param _outputAssetB A struct detailing the second output asset
* @param _totalInputValue An amount of input assets transferred to the bridge (Note: "total" is in the name
* because the value can represent summed/aggregated token amounts of users actions on L2)
* @param _interactionNonce A globally unique identifier of this interaction/`convert(...)` call.
* @param _auxData Bridge specific data to be passed into the bridge contract (e.g. slippage, nftID etc.)
* @return outputValueA An amount of `_outputAssetA` returned from this interaction.
* @return outputValueB An amount of `_outputAssetB` returned from this interaction.
* @return isAsync A flag indicating if the interaction is async.
* @dev This function is called from the RollupProcessor contract via the DefiBridgeProxy. Before this function is
* called _RollupProcessor_ contract will have sent you all the assets defined by the input params. This
* function is expected to convert input assets to output assets (e.g. on Uniswap) and return the amounts
* of output assets to be received by the _RollupProcessor_. If output assets are ERC20 tokens the bridge has
* to _RollupProcessor_ as a spender before the interaction is finished. If some of the output assets is ETH
* it has to be sent to _RollupProcessor_ via the `receiveEthFromBridge(uint256 _interactionNonce)` method
* inside before the `convert(...)` function call finishes.
* @dev If there are two input assets, equal amounts of both assets will be transferred to the bridge before this
* method is called.
* @dev **BOTH** output assets could be virtual but since their `assetId` is currently assigned as
* `_interactionNonce` it would simply mean that more of the same virtual asset is minted.
* @dev If this interaction is async the function has to return `(0,0 true)`. Async interaction will be finalised at
* a later time and its output assets will be returned in a `IDefiBridge.finalise(...)` call.
*
*/
function convert(
AztecTypes.AztecAsset calldata _inputAssetA,
AztecTypes.AztecAsset calldata _inputAssetB,
AztecTypes.AztecAsset calldata _outputAssetA,
AztecTypes.AztecAsset calldata _outputAssetB,
uint256 _totalInputValue,
uint256 _interactionNonce,
uint64 _auxData,
address _rollupBeneficiary
) external payable returns (uint256 outputValueA, uint256 outputValueB, bool isAsync);
/**
* @notice A function that finalises asynchronous interaction.
* @param _inputAssetA A struct detailing the first input asset
* @param _inputAssetB A struct detailing the second input asset
* @param _outputAssetA A struct detailing the first output asset
* @param _outputAssetB A struct detailing the second output asset
* @param _interactionNonce A globally unique identifier of this interaction/`convert(...)` call.
* @param _auxData Bridge specific data to be passed into the bridge contract (e.g. slippage, nftID etc.)
* @return outputValueA An amount of `_outputAssetA` returned from this interaction.
* @return outputValueB An amount of `_outputAssetB` returned from this interaction.
* @dev This function should use the `BridgeBase.onlyRollup()` modifier to ensure it can only be called from
* the `RollupProcessor.processAsyncDefiInteraction(uint256 _interactionNonce)` method.
*
*/
function finalise(
AztecTypes.AztecAsset calldata _inputAssetA,
AztecTypes.AztecAsset calldata _inputAssetB,
AztecTypes.AztecAsset calldata _outputAssetA,
AztecTypes.AztecAsset calldata _outputAssetB,
uint256 _interactionNonce,
uint64 _auxData
) external payable returns (uint256 outputValueA, uint256 outputValueB, bool interactionComplete);
}