Git Source
Inherits: ReentrancyGuard, Ownable
Author: Sperax Foundation
This contract allows users to swap supported stable-coins for yield earned by the USDs protocol. It sends USDs to the Dripper contract for rebase and to the Buyback Contract for buyback.
State Variables
vault
Copy address public vault;
oracle
Copy address public oracle;
buyback
Copy address public buyback;
dripper
Copy address public dripper;
buybackPercentage
Copy uint256 public buybackPercentage;
tokenData
Copy mapping ( address => TokenData) public tokenData;
Functions
constructor
Constructor of the YieldReserve contract.
Copy constructor ( address _buyback , address _vault , address _oracle , address _dripper );
Parameters
swap
Swap function to be called by frontend users.
Copy function swap ( address _srcToken , address _dstToken , uint256 _amountIn , uint256 _minAmountOut ) external ;
Parameters
toggleSrcTokenPermission
Allow or disallow a specific token
for use as a source/input token.
Copy function toggleSrcTokenPermission ( address _token , bool _isAllowed ) external onlyOwner ;
Parameters
toggleDstTokenPermission
Allow or disallow a specific token
for use as a destination/output token.
Reverts if caller is not owner.
Copy function toggleDstTokenPermission ( address _token , bool _isAllowed ) external onlyOwner ;
Parameters
withdraw
Emergency withdrawal function for unexpected situations.
Copy function withdraw ( address _token , address _receiver , uint256 _amount ) external onlyOwner ;
Parameters
updateBuybackPercentage
Set the percentage of newly minted USDs to be sent to the Buyback contract.
Reverts if caller is not owner.
The remaining USDs are sent to VaultCore for rebase.
Copy function updateBuybackPercentage ( uint256 _toBuyback ) public onlyOwner ;
Parameters
updateBuyback
Update the address of the Buyback contract.
Reverts if caller is not owner.
Copy function updateBuyback ( address _newBuyBack ) public onlyOwner ;
Parameters
updateOracle
Update the address of the Oracle contract.
Reverts if caller is not owner.
Copy function updateOracle ( address _newOracle ) public onlyOwner ;
Parameters
updateDripper
Update the address of the Dripper contract.
Reverts if caller is not owner.
Copy function updateDripper ( address _newDripper ) public onlyOwner ;
Parameters
updateVault
Update the address of the VaultCore contract.
Reverts if caller is not owner.
Copy function updateVault ( address _newVault ) public onlyOwner ;
Parameters
swap
Swap allowed source token for allowed destination token.
Copy function swap ( address _srcToken , address _dstToken , uint256 _amountIn , uint256 _minAmountOut , address _receiver )
public
nonReentrant ;
Parameters
mintUSDs
Mints USDs directly with the allowed collaterals for USDs.
Only collaterals configured in USDs vault are allowed to be used for minting.
Copy function mintUSDs ( address _token ) public nonReentrant ;
Parameters
getTokenBForTokenA
Get an estimate of the output token amount for a given input token amount.
Copy function getTokenBForTokenA ( address _srcToken , address _dstToken , uint256 _amountIn ) public view returns ( uint256 );
Parameters
Returns
_sendUSDs
Distributes USDs to the Buyback and Dripper contracts based on buybackPercentage.
Sends a portion of the USDs balance to the Buyback contract and the remaining to the Dripper contract for rebase.
Copy function _sendUSDs () private ;
Events
Swapped
Copy event Swapped (
address indexed srcToken, address indexed dstToken, address indexed dstReceiver, uint256 amountIn, uint256 amountOut
);
USDsMintedViaSwapper
Copy event USDsMintedViaSwapper ( address indexed collateralAddr, uint256 usdsMinted);
Withdrawn
Copy event Withdrawn ( address indexed token, address indexed receiver, uint256 amount);
BuybackPercentageUpdated
Copy event BuybackPercentageUpdated ( uint256 toBuyback);
BuybackUpdated
Copy event BuybackUpdated ( address newBuyback);
OracleUpdated
Copy event OracleUpdated ( address newOracle);
VaultUpdated
Copy event VaultUpdated ( address newVault);
DripperUpdated
Copy event DripperUpdated ( address newDripper);
USDsSent
Copy event USDsSent ( uint256 toBuyback, uint256 toDripper);
SrcTokenPermissionUpdated
Copy event SrcTokenPermissionUpdated ( address indexed token, bool isAllowed);
DstTokenPermissionUpdated
Copy event DstTokenPermissionUpdated ( address indexed token, bool isAllowed);
Errors
InvalidSourceToken
Copy error InvalidSourceToken ();
InvalidDestinationToken
Copy error InvalidDestinationToken ();
AlreadyInDesiredState
Copy error AlreadyInDesiredState ();
TokenPriceFeedMissing
Copy error TokenPriceFeedMissing ();
Structs
TokenData
Copy struct TokenData {
bool srcAllowed;
bool dstAllowed;
uint160 conversionFactor;
}