Yield Reserve

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

address public vault;

oracle

address public oracle;

buyback

address public buyback;

dripper

address public dripper;

buybackPercentage

uint256 public buybackPercentage;

tokenData

mapping(address => TokenData) public tokenData;

Functions

constructor

Constructor of the YieldReserve contract.

constructor(address _buyback, address _vault, address _oracle, address _dripper);

Parameters

swap

Swap function to be called by frontend users.

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.

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.

function toggleDstTokenPermission(address _token, bool _isAllowed) external onlyOwner;

Parameters

withdraw

Emergency withdrawal function for unexpected situations.

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.

function updateBuybackPercentage(uint256 _toBuyback) public onlyOwner;

Parameters

updateBuyback

Update the address of the Buyback contract.

Reverts if caller is not owner.

function updateBuyback(address _newBuyBack) public onlyOwner;

Parameters

updateOracle

Update the address of the Oracle contract.

Reverts if caller is not owner.

function updateOracle(address _newOracle) public onlyOwner;

Parameters

updateDripper

Update the address of the Dripper contract.

Reverts if caller is not owner.

function updateDripper(address _newDripper) public onlyOwner;

Parameters

updateVault

Update the address of the VaultCore contract.

Reverts if caller is not owner.

function updateVault(address _newVault) public onlyOwner;

Parameters

swap

Swap allowed source token for allowed destination token.

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.

function mintUSDs(address _token) public nonReentrant;

Parameters

getTokenBForTokenA

Get an estimate of the output token amount for a given input token amount.

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.

function _sendUSDs() private;

Events

Swapped

event Swapped(
    address indexed srcToken, address indexed dstToken, address indexed dstReceiver, uint256 amountIn, uint256 amountOut
);

USDsMintedViaSwapper

event USDsMintedViaSwapper(address indexed collateralAddr, uint256 usdsMinted);

Withdrawn

event Withdrawn(address indexed token, address indexed receiver, uint256 amount);

BuybackPercentageUpdated

event BuybackPercentageUpdated(uint256 toBuyback);

BuybackUpdated

event BuybackUpdated(address newBuyback);

OracleUpdated

event OracleUpdated(address newOracle);

VaultUpdated

event VaultUpdated(address newVault);

DripperUpdated

event DripperUpdated(address newDripper);

USDsSent

event USDsSent(uint256 toBuyback, uint256 toDripper);

SrcTokenPermissionUpdated

event SrcTokenPermissionUpdated(address indexed token, bool isAllowed);

DstTokenPermissionUpdated

event DstTokenPermissionUpdated(address indexed token, bool isAllowed);

Errors

InvalidSourceToken

error InvalidSourceToken();

InvalidDestinationToken

error InvalidDestinationToken();

AlreadyInDesiredState

error AlreadyInDesiredState();

TokenPriceFeedMissing

error TokenPriceFeedMissing();

Structs

TokenData

struct TokenData {
    bool srcAllowed;
    bool dstAllowed;
    uint160 conversionFactor;
}