DYFIRedeemer
Inherits: IDYFIRedeemer, AccessControlEnumerable, ReentrancyGuard, Pausable
This contract can be used to redeem dYFI for YFI for multiple dYFI holders in a single transaction.
Any address that holds dYFI can approve this contract to spend their dYFI. Then the caller of massRedeem
will provide a list of dYFI holders and their dYFI amounts. By utilizing low-fee flash loans from Balancer,
this contract can redeem all dYFI for YFI, and sell the excess YFI for ETH to pay back the flash loan and
to reward the caller.
The users who approve this contract to spend their dYFI must acknowledge that they will not receive more than
the minimum amount of YFI that should be redeemed for their dYFI. The minimum amount of YFI at a given time can be
calculated using the minYfiRedeem(uint256 dYfiAmount)
function.
State Variables
_REDEMPTION
Address of the redemption contract for dYFI tokens.
address private constant _REDEMPTION = 0x7dC3A74F0684fc026f9163C6D5c3C99fda2cf60a;
_YFI_ETH_PRICE_FEED
Address of the Chainlink YFI/ETH price feed contract.
address private constant _YFI_ETH_PRICE_FEED = 0x3EbEACa272Ce4f60E800f6C5EE678f50D2882fd4;
_FLASH_LOAN_PROVIDER
Address of the Balancer flash loan provider contract.
address private constant _FLASH_LOAN_PROVIDER = 0xBA12222222228d8Ba445958a75a0704d566BF2C8;
_DYFI
Address of the dYFI token contract.
address private constant _DYFI = 0x41252E8691e964f7DE35156B68493bAb6797a275;
_YFI
Address of the YFI token contract.
address private constant _YFI = 0x0bc529c00C6401aEF6D220BE8C6Ea1667F6Ad93e;
_WETH
Address of the WETH token contract.
address private constant _WETH = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2;
_ETH_YFI_CURVE_POOL
Address of the Curve ETH/YFI liquidity pool contract.
address private constant _ETH_YFI_CURVE_POOL = 0xC26b89A667578ec7b3f11b2F98d6Fd15C07C54ba;
_MAX_SLIPPAGE
Maximum slippage allowed during redemption, represented as a fraction of 1e18.
uint256 private constant _MAX_SLIPPAGE = 0.05e18;
_DEFAULT_SLIPPAGE
Default slippage used during redemption if no specific slippage is set, represented as a fraction of 1e18.
uint256 private constant _DEFAULT_SLIPPAGE = 0.01e18;
_slippage
The slippage that should be applied to the redemption process
uint256 private _slippage;
Functions
constructor
constructor(address admin) payable;
receive
Allows this contract to receive ETH
receive() external payable;
massRedeem
Redeems dYFI for YFI for multiple dYFI holders in a single transaction. Any extra ETH will be sent to the caller.
This function utilizes flash loans from Balancer to acquire ETH needed to redeem dYFI for YFI. The amount of YFI to distribute is calculated as follows: YFI to distribute = dYFI amount - ETH required for redemption * YFI/ETH price * (1 + slippage) The extra YFI is swapped for ETH and sent to the caller as an extra reward.
function massRedeem(
address[] calldata dYfiHolders,
uint256[] calldata dYfiAmounts
)
external
nonReentrant
whenNotPaused;
Parameters
Name | Type | Description |
---|---|---|
dYfiHolders | address[] | list of addresses that hold dYFI and have approved this contract to spend their dYFI |
dYfiAmounts | uint256[] | list of dYFI amounts that should be redeemed for YFI from the corresponding dYFI holder |
receiveFlashLoan
Called by the flash loan provider to execute a flash loan of WETH.
The unchecked block is used here because overflow is not possible as the loop index i
is simply incremented in each iteration. The loop is bounded by dYfiHolders.length
, ensuring
that i
will not exceed the length of the array and overflow. Underflow is not a concern as i
is initialized to 0 and only incremented.
The unchecked block is used here because overflow is not possible as the loop index i
is simply incremented in each iteration. The loop is bounded by dYfiHolders.length
, ensuring
that i
will not exceed the length of the array and overflow. Underflow is not a concern as i
is initialized to 0 and only incremented.
function receiveFlashLoan(
IERC20[] calldata tokens,
uint256[] calldata amounts,
uint256[] calldata feeAmounts,
bytes calldata userData
)
external;
Parameters
Name | Type | Description |
---|---|---|
tokens | IERC20[] | list of token addresses flash loaned. |
amounts | uint256[] | list of amounts flash loaned. |
feeAmounts | uint256[] | list of fee amounts that must be paid back. |
userData | bytes | additional data with no specified format. |
setSlippage
Sets the slippage that should be applied to DYFI -> YFI redeems.
The slippage is applied to the YFI/ETH price. For example, if the slippage is 0.01e18, then the YFI/ETH price will be multiplied by 1.01.
function setSlippage(uint256 slippage_) external onlyRole(DEFAULT_ADMIN_ROLE);
Parameters
Name | Type | Description |
---|---|---|
slippage_ | uint256 | The new slippage to use for YFI swaps. |
kill
Kills the contract. Only the admin can call this function.
function kill() external onlyRole(DEFAULT_ADMIN_ROLE);
minYfiRedeem
Returns the minimum amount of YFI that should be redeemed for a given amount of dYFI
function minYfiRedeem(uint256 dYfiAmount) external view returns (uint256);
Parameters
Name | Type | Description |
---|---|---|
dYfiAmount | uint256 | The amount of dYFI to redeem |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | The minimum amount of YFI that should be redeemed for a given amount of dYFI |
currentYfiRedeem
Returns the expected amount of YFI that should be redeemed for a given amount of dYFI
function currentYfiRedeem(uint256 dYfiAmount) external view returns (uint256);
Parameters
Name | Type | Description |
---|---|---|
dYfiAmount | uint256 | The amount of dYFI to redeem |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | The expected amount of YFI that should be redeemed for a given amount of dYFI |
expectedMassRedeemReward
Calculates the expected amount of ETH the caller will receive for redeeming dYFI for YFI for the given users and amounts.
This assumes flash loan fee of 0.
function expectedMassRedeemReward(uint256 dYfiAmount) external view returns (uint256);
Parameters
Name | Type | Description |
---|---|---|
dYfiAmount | uint256 | total dYFI amount that should be redeemed for YFI. |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | The expected amount of ETH the caller will receive for redeeming dYFI for YFI. |
getLatestPrice
Returns the latest YFI/ETH from the Chainlink price feed.
function getLatestPrice() external view returns (uint256);
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | The latest ETH per 1 YFI from the Chainlink price feed. |
slippage
Get the slippage that should be applied to DYFI -> YFI redeems.
function slippage() external view returns (uint256);
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | The slippage in 1e18 precision. |
_setSlippage
Internal function to set the slippage that should be applied to DYFI -> YFI redeems.
function _setSlippage(uint256 slippage_) internal;
Parameters
Name | Type | Description |
---|---|---|
slippage_ | uint256 | The new slippage to use for YFI swaps. |
_getLatestPrice
Returns ETH per 1 YFI in 1e18 precision
function _getLatestPrice() internal view returns (uint256);
_getEthRequired
Returns the minimum ETH required for redemption in 1e18 precision
function _getEthRequired(uint256 dYfiAmount) internal view returns (uint256);
Events
SlippageSet
Emitted when the slippage is set.
event SlippageSet(uint256 slippage);
Parameters
Name | Type | Description |
---|---|---|
slippage | uint256 | The new slippage value set for the redemption process. |
DYfiRedeemed
Emitted when dYFI is redeemed for YFI.
event DYfiRedeemed(address indexed dYfiHolder, uint256 dYfiAmount, uint256 yfiAmount);
Parameters
Name | Type | Description |
---|---|---|
dYfiHolder | address | The address of the dYFI holder whose tokens were redeemed. |
dYfiAmount | uint256 | The amount of dYFI that was redeemed. |
yfiAmount | uint256 | The amount of YFI received from redeeming the dYFI. |
CallerReward
Emitted when a reward is given to the caller of the massRedeem function.
event CallerReward(address indexed caller, uint256 amount);
Parameters
Name | Type | Description |
---|---|---|
caller | address | The address of the caller who received the reward. |
amount | uint256 | The amount of the reward received. |