SPA Buyback

Git Source

Inherits: Initializable, OwnableUpgradeable, ReentrancyGuardUpgradeable

Author: Sperax Foundation

This contract allows users to exchange SPA tokens for USDs tokens.

Users can provide SPA tokens and receive USDs tokens in return based on the current exchange rate.

A percentage of the provided SPA tokens are distributed as rewards, and the rest are burned.

State Variables

veSpaRewarder

address public veSpaRewarder;

rewardPercentage

uint256 public rewardPercentage;

oracle

address public oracle;

Functions

constructor

constructor();

initialize

Contract initializer

function initialize(address _veSpaRewarder, uint256 _rewardPercentage) external initializer;

Parameters

withdraw

Emergency withdrawal function for unexpected situations

Can only be called by the owner

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

Parameters

updateRewardPercentage

Changes the reward percentage

Example value for _newRewardPercentage = 5000 for 50%

function updateRewardPercentage(uint256 _newRewardPercentage) external onlyOwner;

Parameters

updateVeSpaRewarder

Update veSpaRewarder address

function updateVeSpaRewarder(address _newVeSpaRewarder) external onlyOwner;

Parameters

updateOracle

Update oracle address

function updateOracle(address _newOracle) external onlyOwner;

Parameters

buyUSDs

Function to buy USDs for SPA for frontend

function buyUSDs(uint256 _spaIn, uint256 _minUSDsOut) external;

Parameters

getSPAReqdForUSDs

Calculates and returns SPA amount required for _usdsAmount

function getSPAReqdForUSDs(uint256 _usdsAmount) external view returns (uint256);

Parameters

Returns

buyUSDs

Buy USDs for SPA if you want a different receiver

function buyUSDs(address _receiver, uint256 _spaIn, uint256 _minUSDsOut) public nonReentrant;

Parameters

distributeAndBurnSPA

Sends available SPA in this contract to rewarder based on rewardPercentage and burns the rest

function distributeAndBurnSPA() public;

getUsdsOutForSpa

Returns the amount of USDS for SPA amount in

function getUsdsOutForSpa(uint256 _spaIn) public view returns (uint256);

Parameters

Returns

_getUsdsOutForSpa

Returns the amount of USDS for SPA amount in

function _getUsdsOutForSpa(uint256 _spaIn) private view returns (uint256, uint256);

Parameters

Returns

_getOracleData

Retrieves price data from the oracle contract for SPA and USDS tokens.

function _getOracleData() private view returns (uint256, uint256, uint256, uint256);

Returns

_isValidRewardPercentage

Checks if the provided reward percentage is valid.

The reward percentage must be a non-zero value and should not exceed the maximum percentage value.

function _isValidRewardPercentage(uint256 _rewardPercentage) private pure;

Parameters

Events

BoughtBack

event BoughtBack(
    address indexed receiverOfUSDs, address indexed senderOfSPA, uint256 spaPrice, uint256 spaAmount, uint256 usdsAmount
);

Withdrawn

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

SPARewarded

event SPARewarded(uint256 spaAmount);

SPABurned

event SPABurned(uint256 spaAmount);

RewardPercentageUpdated

event RewardPercentageUpdated(uint256 newRewardPercentage);

VeSpaRewarderUpdated

event VeSpaRewarderUpdated(address newVeSpaRewarder);

OracleUpdated

event OracleUpdated(address newOracle);

Errors

CannotWithdrawSPA

error CannotWithdrawSPA();

InsufficientUSDsBalance

error InsufficientUSDsBalance(uint256 toSend, uint256 bal);