aztec-connect-bridges icon indicating copy to clipboard operation
aztec-connect-bridges copied to clipboard

feat: add mean bridge

Open nchamo opened this issue 2 years ago • 12 comments

Description

We are adding a new Aztec bridge that adds support for DCAing with Mean Finance. This bridge supports:

  • All pairs supported by Mean Finance
  • All swap intervals (weekly, daily, etc)
  • Any amount of swaps
  • Yield while DCAing

Subsidies

In our case, we will subsidize a combination of:

  • From token
  • To token
  • Amount of swaps
  • Swap interval

For example, we will subsidize (DAI => ETH, 7 swaps, daily) or (USDC => AAVE, 10 swaps, weekly)

Now, it's important to understand that (DAI => ETH, 7 swaps, daily) is different from (ETH => DAI, 7 swaps, daily) We are doing this because if we considered them the same, then they would share the same subsidy funds. If that happened, then depending on what positions were created, we could be subsidizing DAI => ETH twice before doing it for ETH => DAI

Another important detail is that since we are using the from/to token, we can subsidize "DAI with yield on Euler" without subsidizing "DAI" (and viceversa)

Note: the bridge has an owner that can set and modify subsidies

Checklist:

  • [X] I have reviewed my diff in github, line by line.
  • [X] Every change is related to the PR description.
  • [X] There are no unexpected formatting changes, or superfluous debug logs.
  • [X] The branch has been rebased against the head of its merge target.
  • [X] I'm happy for the PR to be merged at the reviewers next convenience.
  • [X] NatSpec documentation of all the non-test functions is present and is complete.
  • [ ] Continuous integration (CI) passes.
  • [X] Command forge coverage --match-contract MyContract returns 100% line coverage.
  • [X] All the possible reverts are tested.

Technical details

Wrappers Registry

This bridge supports the yield-while-DCAing feature. Since we can't pass the 4626 wrapper's address as part of the convert function, we introduced the concept of the Wrappers Registry. The idea is to have a registry that would allow us to map id => address. Since the id is smaller (uint16) than an address, we can pass it as part of the auxData

Anyone will be able to register tokens to the registry, since we can easily make sure that there is no wrong-doing

Flow

This is how we expect the data to be passed to the bridge:

  • inputAssetA will represent the token that the user will deposit (for example DAI)
  • outputAssetA will represent the token that the user will withdraw (for example ETH)
  • outputAssetB will be the same as output _inputAssetA (to support withdrawing unswapped funds)
  • auxData will encode:
    • The amount of swaps
    • The swap interval
    • The wrapper for the "from" token
    • The wrapper for the "to" token

AuxData

The auxData field is 64bits long:

  • First 24 bits: amount of swaps
  • Next 8 bits: swap interval code (we map the values between 0 and 7 to a swap interval)
  • Next 16 bits: wrapper id for the "from" token
  • Last 16 bits: wrapper id for the "to" token

nchamo avatar Feb 07 '23 13:02 nchamo