Sperax
  • USDs (Sperax USD)
    • Minting and Redeeming
    • Auto Yield
      • Smart Contracts can opt in for the rebase feature (Auto-yield).
    • Stability Mechanism
    • Key parameters and functions
    • Technical documents
      • Sequence diagrams
      • Smart contracts
        • Vault
        • USDs
        • CollateralManager
        • SPA Buyback
        • MasterPriceOracle
        • Yield Reserve
        • Fee Calculator
        • RebaseManager
        • Dripper
        • BaseStrategy
      • Deployed contracts
  • Buyback Contract
  • Staking Protocol
    • Locking SPA
    • Withdrawing SPA
    • Staking Rewards
  • Demeter Protocol
    • How does Demeter Work?
    • Technical documents
      • Smart contracts
        • E721 Farms
          • E721Farm
          • Camelot V3
            • CamelotV3FarmDeployer
            • CamelotV3Farm
        • Base contracts
          • Farm
          • FarmStorage
          • FarmRegistry
          • FarmDeployer
        • Features
          • ClaimableFee
          • ExpirableFarm
          • OperableDeposit
        • Rewarder
          • Rewarder
          • RewarderFactory
      • Deployed contracts
  • Getting Started on Our DApp
    • Minting & Redeeming USDs
    • Stake SPA
  • Governance
  • Bug Bounty Program
  • FAQ
    • SPA Tokenomics
    • xSPA token
    • Smart Contract Addresses
    • How to Transfer SPA from Ethereum to Arbitrum
  • Quick Links
    • Audit Reports
    • Sperax Dapp
    • Demeter Dapp
    • Discord
    • Forum
    • Snapshot
Powered by GitBook
On this page
  • State Variables
  • veSpaRewarder
  • rewardPercentage
  • oracle
  • Functions
  • constructor
  • initialize
  • withdraw
  • updateRewardPercentage
  • updateVeSpaRewarder
  • updateOracle
  • buyUSDs
  • getSPAReqdForUSDs
  • buyUSDs
  • distributeAndBurnSPA
  • getUsdsOutForSpa
  • _getUsdsOutForSpa
  • _getOracleData
  • _isValidRewardPercentage
  • Events
  • BoughtBack
  • Withdrawn
  • SPARewarded
  • SPABurned
  • RewardPercentageUpdated
  • VeSpaRewarderUpdated
  • OracleUpdated
  • Errors
  • CannotWithdrawSPA
  • InsufficientUSDsBalance

Was this helpful?

Export as PDF
  1. USDs (Sperax USD)
  2. Technical documents
  3. Smart contracts

SPA Buyback

PreviousCollateralManagerNextMasterPriceOracle

Was this helpful?

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

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

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

updateRewardPercentage

Changes the reward percentage

Example value for _newRewardPercentage = 5000 for 50%

function updateRewardPercentage(uint256 _newRewardPercentage) external onlyOwner;

Parameters

Name
Type
Description

_newRewardPercentage

uint256

New Reward Percentage

updateVeSpaRewarder

Update veSpaRewarder address

function updateVeSpaRewarder(address _newVeSpaRewarder) external onlyOwner;

Parameters

Name
Type
Description

_newVeSpaRewarder

address

is the address of desired veSpaRewarder

updateOracle

Update oracle address

function updateOracle(address _newOracle) external onlyOwner;

Parameters

Name
Type
Description

_newOracle

address

is the address of desired oracle

buyUSDs

Function to buy USDs for SPA for frontend

function buyUSDs(uint256 _spaIn, uint256 _minUSDsOut) external;

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

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

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

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

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

function distributeAndBurnSPA() public;

getUsdsOutForSpa

Returns the amount of USDS for SPA amount in

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

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

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

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.

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

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.

function _isValidRewardPercentage(uint256 _rewardPercentage) private pure;

Parameters

Name
Type
Description

_rewardPercentage

uint256

The reward percentage to validate.

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);
Git Source