Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Zap

Git Source

Inherits: IZap, 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 wSPA addresses are passed as parameters to each function

Functions

zapIn

Add liquidity to SPA and automatically wrap SPA tokens

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

Parameters

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

Returns

NameTypeDescription
wspaAmountuint256Amount of wrapped SPA tokens minted

zapOut

Remove liquidity from SPA by unwrapping SPA tokens first

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

Parameters

NameTypeDescription
spaaddressAddress of the SPA contract
wspaaddressAddress of the wrapped SPA token contract
receiveraddressAddress to receive the tokens
wspaAmountuint256Amount of wrapped SPA 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 wSPA tokens and redeem a single asset

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

Parameters

NameTypeDescription
spaaddressAddress of the SPA contract
wspaaddressAddress of the wrapped SPA token contract
receiveraddressAddress to receive the tokens
wspaAmountuint256Amount of wrapped SPA tokens to redeem
tokenIndexuint256Index of the token to receive
minAmountOutuint256Minimum amount of token to receive

Returns

NameTypeDescription
amountuint256Amount of token received

_mint

Call SPA's mint function

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

_deposit

Call WSPAToken's deposit function

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

_redeem

Call WSPAToken's redeem function

function _redeem(address wspa, 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 pool 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();