Create a New Strategy for BOB Gateway
Introduction
BOB's Hybrid L2 vision is to unite the Bitcoin and Ethereum ecosystems. An important part of that goal is to improve the security and UX of native BTC holders looking to participate in DeFi.
BOB Gateway makes it possible for them to deposit into your smart contract with only one Bitcoin transaction.
Our open-source repositories contain all current strategies and their tests.
Brief Recap of BOB Gateway
Gateway is a trust-minimized P2P swap between BTC on Bitcoin mainnet and wrapped BTC on BOB. The process may include optional smart contract calls to execute the user's "intent". In the language of account abstraction, this is also referred to as "intent-based bridging" by executing "user operations".
In our language, BOB Gateway is the relayer that monitors orders, pairs users with liquidity providers, and trustlessly executes a "strategy" to accomplish the user's intent. Some intents are one step, such as staking or lending. Other intents combine several actions, like staking-and-lending or staking-and-restaking.
No matter how sophisticated the strategy, everything is handled on the user's behalf. Their UX is simply to fill out an order form and sign one Bitcoin transaction.
How to Write a Strategy
We’ll build up to a complex, multi-step strategy by starting with a simple one that we later extend.
One-Intent Example: Staking WBTC into xSolvBTC
At this point in the P2P swap process, the Gateway relayer has already verified that the user sent BTC to the LP. Having trustlessly verified this, the relayer sets about manipulating the LP's wrapped BTC to accomplish the user's intent.
In this example the relayer deposits WBTC to mint SolvBTC, which is then deposited to mint xSolvBTC, the LST that receives yield from Babylon.
// Mint SolvBTC with the LP's WBTC
uint256 shareValueBTC = solvBTCRouter.createSubscription(solvBTCPoolId, amountIn);
// Mint xSolvBTC with the SolvBTC created in the previous LP's WBTC
solvBTC.safeIncreaseAllowance(address(solvLSTRouter), shareValueBTC);
uint256 shareValueLST = solvLSTRouter.createSubscription(solvLSTPoolId, shareValueBTC);
require(shareValueLST >= args.amountOutMin, "Insufficient output amount");
// Transfer the xSolvBTC token to the user to complete the process
solvLST.safeTransfer(recipient, shareValueLST);
Multi-Intent Example: Stake-and-Lend
As we saw above, you are not limited to one smart contract call. You may wish to make several functions calls sequentially to accomplish a more sophisticated goal. This allows you to compose several DeFi protocols, such as staking, restaking, or lending.
A user with a higher risk tolerance may want to seek even more yield by depositing their BTC LST in a lending protocol. To extend the staking example above, let's look at a snippet from AvalonStrategy.sol that replaces the final safeTransfer function with an additional step to deposit the xSolvBTC into the Avalon lending protocol.
// tokenSent is solvLST, which identifies the correct Avalon lending pool
// amountIn is the balanceOf xSolvBTC from the previous step
// recipient is the user's EVM address, so their wallet controls the output tokens
pool.supply(address(tokenSent), amountIn, recipient, 0);