Zap

Git Source

Inherits: IZap, Ownable, ReentrancyGuard

A helper contract to simplify liquidity provision and removal in Tapio

Allows users to add/remove liquidity with automatic wrapping/unwrapping in 1 tx

SPA and wLP addresses are passed as parameters to each function

Functions

constructor

constructor() Ownable(msg.sender);

zapIn

Add liquidity to SPA and automatically wrap LP tokens

function zapIn(
    address spa,
    address wlp,
    address receiver,
    uint256 minMintAmount,
    uint256[] calldata amounts
)
    external
    nonReentrant
    returns (uint256 wlpAmount);

Parameters

NameTypeDescription
spaaddressAddress of the SPA contract
wlpaddressAddress of the wrapped LP token contract
receiveraddressAddress to receive the wrapped LP tokens
minMintAmountuint256Minimum amount of LP tokens to receive
amountsuint256[]Array of token amounts to add

Returns

NameTypeDescription
wlpAmountuint256Amount of wrapped LP tokens minted

zapOut

Remove liquidity from SPA by unwrapping LP tokens first

function zapOut(
    address spa,
    address wlp,
    address receiver,
    uint256 wlpAmount,
    uint256[] calldata minAmountsOut,
    bool proportional
)
    external
    nonReentrant
    returns (uint256[] memory amounts);

Parameters

NameTypeDescription
spaaddressAddress of the SPA contract
wlpaddressAddress of the wrapped LP token contract
receiveraddressAddress to receive the tokens
wlpAmountuint256Amount of wrapped LP tokens to redeem
minAmountsOutuint256[]Minimum amounts of tokens to receive
proportionalboolIf true, withdraws proportionally; if false, uses minAmountsOut

Returns

NameTypeDescription
amountsuint256[]Array of token amounts received

zapOutSingle

Unwrap wLP tokens and redeem a single asset

function zapOutSingle(
    address spa,
    address wlp,
    address receiver,
    uint256 wlpAmount,
    uint256 tokenIndex,
    uint256 minAmountOut
)
    external
    nonReentrant
    returns (uint256 amount);

Parameters

NameTypeDescription
spaaddressAddress of the SPA contract
wlpaddressAddress of the wrapped LP token contract
receiveraddressAddress to receive the tokens
wlpAmountuint256Amount of wrapped LP tokens to redeem
tokenIndexuint256Index of the token to receive
minAmountOutuint256Minimum amount of token to receive

Returns

NameTypeDescription
amountuint256Amount of token received

recoverERC20

Recover tokens accidentally sent to this contract

function recoverERC20(address token, uint256 amount, address to) external onlyOwner;

Parameters

NameTypeDescription
tokenaddressAddress of the token to recover
amountuint256Amount to recover
toaddressAddress to send the tokens to

_mint

Call SPA's mint function

function _mint(address spa, uint256[] calldata amounts, uint256 minMintAmount) internal returns (uint256);

_deposit

Call WLPToken's deposit function

function _deposit(address wlp, uint256 assets, address receiver) internal returns (uint256);

_redeem

Call WLPToken's redeem function

function _redeem(address wlp, uint256 shares, address receiver) internal returns (uint256);

_redeemProportion

Call SPA's redeemProportion function

function _redeemProportion(
    address spa,
    uint256 amount,
    uint256[] calldata minAmountsOut
)
    internal
    returns (uint256[] memory);

_redeemSingle

Call SPA's redeemSingle function

function _redeemSingle(
    address spa,
    uint256 amount,
    uint256 tokenIndex,
    uint256 minAmountOut
)
    internal
    returns (uint256);

_redeemMulti

Call SPA's redeemMulti function

function _redeemMulti(
    address spa,
    uint256[] calldata amounts,
    uint256 maxRedeemAmount
)
    internal
    returns (uint256[] memory);

_getTokens

Get the tokens from SPA

function _getTokens(address spa) internal view returns (address[] memory);

_getPoolToken

Get the LP token from SPA

function _getPoolToken(address spa) internal view returns (address);

_revertBytes

Helper function to revert with the same error message as the original call

function _revertBytes(bytes memory data) internal pure;

Errors

ZeroAmount

error ZeroAmount();

InvalidParameters

error InvalidParameters();

CallFailed

error CallFailed();