OZLFacet

Main L2 implementation.

This is the contract that gets initially called in L2 during the bridging flow, and it's in charge of managing the exchange from the user's ETH to their Account's stablecoin.

It also deposits the protocol's fees in DeFi and is in charge of the redemption of each user's OZL balance for the protocol's profits, once this feature is enabled.

Github repo here.

Open methods

Parameters:

withdrawUserShare

function withdrawUserShare(
        bytes memory accData_,
        address receiver_,
        uint shares_
) external onlyWhenEnabled filterDetails(acc_);

Allows an OZL holder to redeem their OZL balance for the protocol's revenue.

Parameters:

Name
Type
Description

accData_

bytes

Account details (except for the name)

receiver_

address

Receiver of the protocol's revenue after redemption

shares_

uint256

OZL balance to redeem

Owner methods

addTokenToDatabase

function addTokenToDatabase(struct TradeOps calldata newSwap_) external;

Adds a new token to the group of tokens that an user can choose from for an Account as the coin to receive as the final destination on L2.

Due to the nature of the interaction of each token, other details are added (in the form of a struct) besides the address of the token, details such the Curve pool where it can be traded, its base token, etc.

Parameters:

Struct:

struct TradeOps {
    int128 tokenIn;
    int128 tokenOut;
    address baseToken;
    address token;  
    address pool;
}
Name
Type
Description

tokenIn

int128

Index at Curve pool of the base token (USDT or WBTC) of the new token to add

tokenOut

int128

Index at Curve pool of the new token to add

baseToken

address

Base token

token

address

New token to add

pool

address

Curve pool where the new token to add is found

Function:

Name
Type
Description

newSwap_

struct TradeOps

Configuration of the new token to add

removeTokenFromDatabase

function removeTokenFromDatabase(struct TradeOps calldata swapToRemove_) external;

The contrary of addTokenToDatabase()

Parameters:

Struct:

struct TradeOps {
    int128 tokenIn;
    int128 tokenOut;
    address baseToken;
    address token;  
    address pool;
}
Name
Type
Description

tokenIn

int128

Index at Curve pool of the base token (USDT or WBTC) of the token to remove

tokenOut

int128

Index at Curve pool of the new token to add

baseToken

address

Base token

token

address

Token to remove

pool

address

Curve pool where the token to remove is found

Function:

Name
Type
Description

swapToRemove_

struct TradeOps

Configuration of the token to remove

System methods

exchangeToAccountToken

function exchangeToAccountToken(
        bytes memory accData_,
        uint amountToSend_,
        address account_
) external payable noReentrancy(0) onlyAuthorized;

This function gets called by Arbitrum directly (with ozMiddleware 's L1 alias as the sender) in L2 when bridging the user's ETH, alongside the configuration of the Account (L1 --> L2).

It's the one that starts the flow in L2 which ends with the user receiving the stablecoin of the Account.

Parameters:

Name
Type
Description

accData_

bytes

Details of the Account (except for the name)

amountToSend_

uint256

Gross amount (without Gelato's fee) sent to the Account

account_

address

The Account

_depositFeesInDefi

function _depositFeesInDeFi(uint fee_, bool isRetry_) private;

Deposit the protocol's fee in different DeFi protocols (Curve and Yearn at the moment) for generating yield.

This would be Ozel's revenue that users can later redeem with their OZL balance.

If by any external variable, like not enough slippage, it's not possible to deposit the fees, the amount will remain within the contract's balance and will be re-attempted to be deposited in the next bridging call on L2.

Parameters:

Name
Type
Description

fee_

uint256

Protocol's fee

isRetry_

boolean

If the call is a re-attempt to deposit fees that previously failed.

_swapsForBaseToken

function _swapsForBaseToken(
        uint amountIn_, 
        uint baseTokenOut_, 
        struct AccountConfig calldata acc_
) private;

There are two base tokens that allows branching into the other stablecoins, depending on the Account's selected token. These two base tokens are USDT and WBTC.

So if for example an Account has USDT as its selected token, this function would be the final swap. But if the Account's token is USDC, this function would exchange the user's ETH for USDT, and then delegate the final execution to executeFinalTrade() on ozExecutorFacet for the final swap from USDT to USDC.

This is necessary due to Curve's pools and the tokens they hold.

Parameters:

Name
Type
Description

amountIn_

uint256

Amount to swap for base token

baseTokenOut_

uint256

Number of the base token coming out, based on their index at its Curve pool.

_tradeWithExecutor

function _tradeWithExecutor(struct AccountConfig calldata acc_) private;

If the Account's token is not USDT nor WBTC, the final swap to its stablecoin would be forwarded to ozExecutorFacet by this function.

If the Account's token is in fact USDT or WBTC, this function is never called throughout the entire flow.

Parameters:

Struct:

struct AccountConfig { 
    address user;
    address token;
    uint slippage; 
    string name;
}
Name
Type
Description

user

address

Owner of the Account

token

address

Account stablecoin

slippage

uint256

Account slippage

name

string

Name of the Account

Function:

Name
Type
Description

acc_

struct AccountConfig

Account configuration

Last updated