Unlocking liquidity
Last updated
Last updated
n the previous , the offer we posted had to receive a transfer liquidity for it to succeed when taken. Now, we want instead to post the offer without transferring tokens from the admin to Mangrove or the OfferMakerTutorial
(we call this unlocked or ). This way, the tokens are pulled just-in-time when the offer is taken and can thus be made available for other purposes (e.g., for generating extra yield in another DeFi protocol).
Note :
Since you are not committing your liquidity to your smart offer, you can post multiple offers with unlocked liquidity. We call that .
For this to work, we use a so-called - a smart contract that can be used to route tokens from the admin to the OfferMakerTutorial
contract when the offer is taken.
First add the following import at the top of the file:
Then, replace the noRouter()
with a SimpleRouter()
(specified as part of Direct.RouterParams
) in the constructor definition:
and insert the following to the constructor body:
Thus, the beginning of the tutorial should look like this:
You can now redeploy the contract, activate it, and post an offer as before - remember to update the $OFFER_MAKER
environment variable.
We will also need:
To let the OfferMakerTutorial
pull funds from the admin's reserve of WBTC.
To make sure that the admin and/or taker have enough funds on their wallet (we can [mint](#Getting tokens) tokens if needed).
If the admin (acting as a maker) does not have required WBTC tokens then the smart offer will fail when taken.
Note: the offer could still be posted - a smart offer can source liquidity elsewhere on-chain.
The router needs to be able to pull funds from the admin. First, we need to get the address of the router. We can do this like so (you did remember to update the $OFFER_MAKER
variable, right?):
Let's put the address in an environment variable:
Finally, let's run the approval:
Let's put the address in an environment variable:
Finally, let's run the approval:
The OfferMakerTutorial
now uses the approval of the SimpleRouter
to transfer funds from the admin. If you wonder where the approval of the transfers from OfferMakerTutorial
happens, then its the activate
call. See approvals for more details on that topic.
Note: you can follow those steps in the .
Getting tokens
If you don't have any WBTC, you can get some by using the following commands (taken from ), or the corresponding faucet. Just look for a token holder with large amounts of WBTC - you can check the list on Polygonscan. Also, remember to add the chosen address under $LUCKY_USER
in your .env
file.
Approving the contract to pull the funds
The OfferMakerTutorial
now uses the approval of the SimpleRouter
to transfer funds from the admin. If you wonder where the approval of the transfers from OfferMakerTutorial
happens, then its the activate
call. See for more details on that topic.