Burn WUSD

Burn WUSD

The action of burning WUSD allows you to get back the corresponding amount of collateralized stablecoins (or, if preferred, the corresponding amount of LP tokens).

To burn WUSD tokens, use the safeTransferFrom or safeBatchTransferFrom method directly from the WUSD token collection itself to the WUSDExtensionController, with the following inputs:

  • from -> sender address

  • objectId/s -> WUSD object Id

  • amount/s -> WUSD amount to burn, or an array containing the amounts in case of safeBatchTransferFrom

  • data

Regarding the data input:

The payload must contain a value other than "1" to burn the WUSD token amount. If the value passed is 1, a Rebalance is called.

In addition, the payload must contain a series of parameters useful for recovering tokens from the burn action. In particular, the payload must contain:

  • ammPosition -> position of the AMM you want to use (see here for more information)

  • liquidityPoolPosition -> position of the LP you want to use (see here for more information)

  • liquidityPoolAmount -> amount of tokens corresponding to the WUSD amount to be burned for that chosen pool. If byLiquidityPool is true, this parameter represents an amount of LP tokens; if false, this parameter represents an amount of pair tokens

  • keepLiquidityPool -> a boolean value representing whether to get back LP tokens (true) or the corresponding amount of pair tokens inside the LP token (false)

The onERC1155Received/onERC1155BatchReceived function takes care of burning the WUSD amount that arrives in the WUSDExtensionController contract. It calls the _onSingleReceived function, and then, taking the payload sent via safeTransferFrom/safeBatchTransferFrom, distinguishes between two cases: If the payload is equal to 1, it will perform a rebalance; if different from 1, it will perform a burn:

if(action == 1) {
    _rebalanceByDebt(from, value, payload);
} else {
    _burn(from, value, payload);
}

At this point, to burn the desired amount of WUSD, the _burn function is called. The function performs a decode of the payload to obtain the information needed to perform the burn.

function _burn(address from, uint256 value, bytes memory payload) private { 
    (uint256 ammPosition, uint256 liquidityPoolPosition, uint256 liquidityPoolAmount, bool keepLiquidityPool) = abi.decode(payload, (uint256, uint256, uint256, bool));

A _safeApprove is called on the extension and then the burn method of the extension itself, which burns the WUSD and returns the amount of LP tokens:

_safeApprove(_wusdInteroperableInterfaceAddress, _extension, INativeV1(_collection).toInteroperableInterfaceAmount(_wusdObjectId, value));
WUSDExtension(_extension).burnFor(from, value, _allowedAMMs[ammPosition].ammAddress, _allowedAMMs[ammPosition].liquidityPools[liquidityPoolPosition], liquidityPoolAmount, keepLiquidityPool ? from : address(this));

The payload must contain keepLiquidityPool == true in case the burner wants to receive the pair tokens inside the LP token back. In this case the _removeLiquidity function is called via the AMM aggregator to remove the liquidity from the AMM, and returns the corresponding amount to the user:

if(!keepLiquidityPool) {
    _checkAllowance(liquidityPoolAddress, liquidityPoolAmount, address(amm));
    amm.removeLiquidity(LiquidityPoolData(
        liquidityPoolAddress,
        liquidityPoolAmount,
        address(0),
        true,
        false,
        from
    ));
}

Please refer to the WUSD Frontend Integration section for more details.

Last updated