Zap from Sonic
Deposit any token into any strategies in a single transaction on Sonic
Normally, if a user deposits a token that is different from the strategy's underlying token, they must first swap it and then deposit. With DogBone, we consolidate these steps into a single transaction. First, we prepare the swap data, execute the swap, and then deposit directly into the strategy. The swap data is obtained from some of the best DEX aggregators on the Sonic blockchain, such as KyberSwap and ODOS.
function zap(Swap memory swapData, Strategy memory T)
external
payable
returns (bytes memory)
{
_swap(swapData);
bytes memory result = doStrategy(T);
_validate(swapData, T, data);
return result;
}
// low-level function to swap user input token to strategy's underlying token.
function _swap(Swap memory swapData) internal;
// function to assure that user receive minimum liquidity required.
function _validate(Swap memory swapData, Strategy memory T, bytes memory result) internal;
/// API for all strategy zaps
/// @param T strategy Data
function doStrategy(Strategy memory T) public payable returns (bytes memory);
struct Strategy {
address strategy; // The vault to deposit into
address underlyingToken; // The token required for deposit
uint256 amountToDeposit; // The amount of underlying token to deposit
address lpReceiver; // The receiver of LP tokens
bytes4 funcSelector; // Determines which function to call based on the type of strategy
bytes loopingStrategy; // Empty if not a looping strategy; otherwise, it contains the encoded data for SiloLoopingStrategy/AaveLoopingStrategy
}
struct SiloLoopingStrategy {
bool isVaultProtected; // Indicates if the Silo’s vault is non-borrowable
uint256 leverage; // Leverage of the position
uint256 flashAmount; // Amount of the borrow token to flash loan from the Silo Borrow vault
bytes swapFlashloanData; // Swap data to convert the borrow token into the deposit token, encoded per the Swap struct
}
struct Swap {
address fromToken;
uint256 fromAmount;
address dexAggregatorRouter;
bytes data;
uint256 value;
}
Last updated