In the previous chapters, we learned about the SPA Pool for swapping and providing liquidity, the LPToken representing your share, and the WLPToken (Wrapped LP Token - ERC4626) which makes your LP position easier to use in other DeFi applications.
You might have noticed that getting those WLPTokens involves several steps:
mint
on the SPA Pool to deposit your tokens and get LPTokens back.deposit
on the WLPToken contract to wrap your LPTokens into WLPTokens.Whew! That’s quite a few clicks and transactions. Wouldn’t it be nice if you could just hand over your initial tokens and get the final WLPTokens in one go?
Adding or removing liquidity, especially when you want the wrapped WLPToken, requires multiple separate steps and transactions. Each transaction costs gas fees, and juggling approvals and different contract calls can be confusing for users.
The Zap contract acts like a friendly and efficient assistant. It takes your starting ingredients (your input tokens) and your goal (getting WLPTokens), and performs all the necessary intermediate steps for you within a single transaction. This saves you time, hassle, and gas fees! It also works in reverse for removing liquidity.
Zap is a utility smart contract. Think of it as a helper contract designed specifically to simplify common user interactions with the SPA Pool and their associated LPTokens and WLPTokens.
Its main job is to bundle a sequence of actions (like approvals, minting, depositing) into one function call.
Let’s say you have 100 USDC and 100 USDT, and you want to provide liquidity to a USDC/USDT SPA Pool and receive the corresponding WLPTokens. Instead of doing the four steps manually, you use Zap.
Your Goal: Provide 100 USDC and 100 USDT to get WLPTokens, accepting at least 199 LPTokens worth of value in the intermediate step.
Interaction:
You’d tell the Zap contract:
spa
): The address of the USDC/USDT pool.wlp
): The address of the wrapped token for that pool.receiver
): Your wallet address.minMintAmount
): 199 (protects you from unexpected price changes during the mint).amounts
): [100 * 1e6, 100 * 1e6]
(assuming 6 decimals for both).Simplified Code Interaction (Conceptual):
// --- File: periphery/Zap.sol (Conceptual Call) ---
// Assume 'zapContract' is the deployed Zap contract address
// Assume 'spa_address' and 'wlp_address' are known
// Assume 'usdc' and 'usdt' are the token contract instances
// Assume you have 100 USDC and 100 USDT
// 1. Approve the Zap contract to spend your USDC and USDT
usdc.approve(zapContract, 100 * 1e6);
usdt.approve(zapContract, 100 * 1e6);
// 2. Call zapIn on the Zap contract
uint256 receivedWLPTokens = zapContract.zapIn(
spa_address, // The specific SPA pool
wlp_address, // The specific WLPToken vault
your_address, // Who receives the final WLPTokens
199 * 1e18, // Minimum LPToken value expected (18 decimals)
[100 * 1e6, 100 * 1e6] // Amounts of USDC, USDT to deposit
);
// receivedWLPTokens now holds the amount of WLPToken you received.
// All steps (transfer USDC/USDT, mint LPToken, deposit LPToken, mint WLPToken)
// happened in this single zapIn transaction!
Explanation: