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

initialize

Contract initializer

Parameters

Name
Type
Description

_veSpaRewarder

address

Rewarder's address

_rewardPercentage

uint256

Percentage of SPA to be rewarded

withdraw

Emergency withdrawal function for unexpected situations

Can only be called by the owner

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

updateRewardPercentage

Changes the reward percentage

Example value for _newRewardPercentage = 5000 for 50%

Parameters

Name
Type
Description

_newRewardPercentage

uint256

New Reward Percentage

updateVeSpaRewarder

Update veSpaRewarder address

Parameters

Name
Type
Description

_newVeSpaRewarder

address

is the address of desired veSpaRewarder

updateOracle

Update oracle address

Parameters

Name
Type
Description

_newOracle

address

is the address of desired oracle

buyUSDs

Function to buy USDs for SPA for frontend

Parameters

Name
Type
Description

_spaIn

uint256

Amount of SPA tokens

_minUSDsOut

uint256

Minimum amount out in USDs

getSPAReqdForUSDs

Calculates and returns SPA amount required for _usdsAmount

Parameters

Name
Type
Description

_usdsAmount

uint256

USDs amount the user wants

Returns

Name
Type
Description

uint256

Amount of SPA required

buyUSDs

Buy USDs for SPA if you want a different receiver

Parameters

Name
Type
Description

_receiver

address

Receiver of USDs

_spaIn

uint256

Amount of SPA tokens

_minUSDsOut

uint256

Minimum amount out in USDs

distributeAndBurnSPA

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

getUsdsOutForSpa

Returns the amount of USDS for SPA amount in

Parameters

Name
Type
Description

_spaIn

uint256

Amount of SPA tokens

Returns

Name
Type
Description

uint256

Amount of USDs user will get

_getUsdsOutForSpa

Returns the amount of USDS for SPA amount in

Parameters

Name
Type
Description

_spaIn

uint256

Amount of SPA tokens

Returns

Name
Type
Description

uint256

Amount of USDs user will get

uint256

_getOracleData

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

Returns

Name
Type
Description

uint256

The price of USDS in SPA, the price of SPA in USDS, and their respective precisions.

uint256

uint256

uint256

_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.

Parameters

Name
Type
Description

_rewardPercentage

uint256

The reward percentage to validate.

Events

BoughtBack

Withdrawn

SPARewarded

SPABurned

RewardPercentageUpdated

VeSpaRewarderUpdated

OracleUpdated

Errors

CannotWithdrawSPA

InsufficientUSDsBalance