Mint WUSD
Mint WUSD
To mint new WUSD, use the addLiquidity
function of the WUSDExtensionController contract.
The inputs of this function are as follows:
ammPosition
-> the position of the AMM you're going to use inside theallowedAMM
arrayliquidityPoolPosition
-> the position of the liquidity pool you're going to use inside theallowedAMM
arrayliquidityPoolAmount
-> the amount of tokens of which you want to mint the corresponding amount of WUSD. IfbyLiquidityPool
istrue
, this parameter represents an LP token amount, ifbyLiquidityPool
isfalse
, this parameter represents the pair token amounts.byLiquidityPool
-> a boolean value that represents if the amount passed is of an LP token (true
) or of the pair tokens (false
)
Starting with the AMM and passed LP positions
, the LP address
is retrieved:
The AMM address is then retrieved from the AMM position passed as the following input:
The corresponding amount in LP tokens is then calculated calling the byLiquidityPoolAmount
of that specific AMM (see the AMM Aggregator section for more):
This function previews two cases regarding the value of the parameter byLiquidityPool
:
if
byLiquidityPool
istrue
, you are passing LP tokens:
The corresponding amount in LP tokens is sent using _safeTransferFrom
from the msg.sender
to the WUSDExtensionController contract itself; these will be used to mint the corresponding amount of WUSD.
if
byLiquidityPool
is false, you are passing pair tokens:
The corresponding amounts of each pair tokens, recovered from the previous byLiquidityPoolAmount
call, are sent using _safeTransferFrom
from msg.sender
to the WUSDExtensionController contract itself, and the _safeApprove
method is called to approve the AMM to add liquidity to the pool using tokens sent by the user :
At this point, the amount of LP tokens / pair tokens needed to mint WUSD is calculated by adding liquidity using the addLiquidity
function on the chosen AMM:
The addLiquidity
function takes as input the following:
liquidityPoolAddress
liquidityPoolAmount
address(0)
-> tokenAddress passed as0x0000000000000000000000000000000000000000
because the operation is managed using LP tokenstrue
->amountIsLiquidityPool
false
->involvingETH
address
-> receiveraddress
Now in both cases (byLiquidityPool
true/false) _safeApprove
is called on the LP tokens / pair tokens and the corresponding WUSD amount is finally minted using the mintFor
function on the WUSDExtension contract, and then sent to the msg.sender
.
If there is a positive difference between what was sent by the user (in pair tokens or LP tokens) and what was actually spent by the function to mint new WUSD, this difference is automatically returned to the user by internally calling the _safeTransfer
function:
Last updated