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

Name
Type
Description

_buyback

address

Address of the Buyback contract.

_vault

address

Address of the Vault.

_oracle

address

Address of the Oracle.

_dripper

address

Address of the Dripper contract.

swap

Swap function to be called by frontend users.

function swap(address _srcToken, address _dstToken, uint256 _amountIn, uint256 _minAmountOut) external;

Parameters

Name
Type
Description

_srcToken

address

Source/Input token.

_dstToken

address

Destination/Output token.

_amountIn

uint256

Input token amount.

_minAmountOut

uint256

Minimum output tokens expected.

toggleSrcTokenPermission

Allow or disallow a specific token for use as a source/input token.

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

Parameters

Name
Type
Description

_token

address

Address of the token to be allowed or disallowed.

_isAllowed

bool

If set to true, the token will be allowed as a source/input token; otherwise, it will be disallowed.

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

Name
Type
Description

_token

address

Address of the token to be allowed or disallowed.

_isAllowed

bool

If set to true, the token will be allowed as a destination/output token; otherwise, it will be disallowed.

withdraw

Emergency withdrawal function for unexpected situations.

function withdraw(address _token, address _receiver, uint256 _amount) external onlyOwner;

Parameters

Name
Type
Description

_token

address

Address of the asset to be withdrawn.

_receiver

address

Address of the receiver of tokens.

_amount

uint256

Amount of tokens to be withdrawn.

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

Name
Type
Description

_toBuyback

uint256

The percentage of USDs sent to Buyback (e.g., 3000 for 30%).

updateBuyback

Update the address of the Buyback contract.

Reverts if caller is not owner.

function updateBuyback(address _newBuyBack) public onlyOwner;

Parameters

Name
Type
Description

_newBuyBack

address

New address of the Buyback contract.

updateOracle

Update the address of the Oracle contract.

Reverts if caller is not owner.

function updateOracle(address _newOracle) public onlyOwner;

Parameters

Name
Type
Description

_newOracle

address

New address of the Oracle contract.

updateDripper

Update the address of the Dripper contract.

Reverts if caller is not owner.

function updateDripper(address _newDripper) public onlyOwner;

Parameters

Name
Type
Description

_newDripper

address

New address of the Dripper contract.

updateVault

Update the address of the VaultCore contract.

Reverts if caller is not owner.

function updateVault(address _newVault) public onlyOwner;

Parameters

Name
Type
Description

_newVault

address

New address of the VaultCore contract.

swap

Swap allowed source token for allowed destination token.

function swap(address _srcToken, address _dstToken, uint256 _amountIn, uint256 _minAmountOut, address _receiver)
    public
    nonReentrant;

Parameters

Name
Type
Description

_srcToken

address

Source/Input token.

_dstToken

address

Destination/Output token.

_amountIn

uint256

Input token amount.

_minAmountOut

uint256

Minimum output tokens expected.

_receiver

address

Receiver of the tokens.

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

Name
Type
Description

_token

address

Address of token to mint USDs with

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

Name
Type
Description

_srcToken

address

Input token address.

_dstToken

address

Output token address.

_amountIn

uint256

Input amount of _srcToken.

Returns

Name
Type
Description

uint256

Estimated output token amount.

_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;
}