Staking Contract Details

Staking contract details

Staking Contract

Table of Contents

Introduction

The staking contract empowers users to lock their BDCA tokens for a specified period to earn rewards. This guide delves into the contract's functionalities, explaining how users can participate in staking, the benefits they can accrue, and the underlying mechanisms governing reward distribution.

Contract Overview

The staking contract is designed to incentivize long-term token holding and foster a robust community around the project. It offers users a secure and transparent platform to stake their BDCA tokens in exchange for attractive rewards. Here's a breakdown of the key features:

  • Tiered Staking: The contract implements a tiered staking system. Users can choose from various staking tiers, each offering distinct lock durations and reward multipliers. Higher tiers typically come with longer lock durations but provide more significant rewards.

  • Lock Durations: Each staking tier is associated with a predefined lock duration. Users cannot withdraw their staked tokens before the lock period expires, ensuring commitment and contributing to project stability. Reward Distribution: The contract facilitates the distribution of rewards to users who participate in staking. Rewards can be in the form of BDCA tokens or other cryptocurrencies like USDT. The mechanism for calculating and distributing these rewards will be further elaborated upon in subsequent sections.

  • Security: The contract prioritizes security by implementing access control mechanisms. Only authorized roles can execute critical functions, safeguarding user funds and preventing unauthorized activities.

  • Transparency: The contract operates with transparency in mind. All relevant data, such as total staked amount, individual stake details, and reward distribution history, are readily accessible, fostering trust within the user community.

Staking Parameters

External Interfaces

  • bdcaToken: An interface to interact with the BDCA token contract.

  • usdtToken: An interface to interact with the USDT token contract.

  • presale: An interface to interact with the Presale contract.

  • stakingNft: An interface to interact with the Staking NFT contract.

Constants

  • UPGRADER_ROLE: The keccak256 hash representing the upgrader role.

  • DISTRIBUTOR_ROLE: The keccak256 hash representing the distributor role.

  • TIER_DENOMINATOR: The denominator used for tier calculations.

Numeric Constants

  • minStake: The minimum stake amount allowed.

  • maxStake: The maximum stake amount allowed.

  • totalStaked: The total amount currently staked.

NFT Information

  • nftTier: A mapping of NFT IDs to their corresponding tier levels.

  • nftLockedAmount: A mapping of NFT IDs to their locked staking amounts.

  • nftLockExpire: A mapping of NFT IDs to their lock expiration dates.

Tier Information

  • tierBonusPersentages: A mapping of tier levels to their bonus percentages.

  • tierAffiliateBonusPersentages: A mapping of tier levels to their affiliated bonus percentages.

  • tierLockDuration: A mapping of tier levels to their lock durations.

Modifiers

Not Paused Modifier

  • notPaused: Throws if the staking is paused.

    • Description: Ensures that the staking is not paused before executing the function.

    • Usage: Apply this modifier to functions that should only be called when the staking is not paused.

Is Paused Modifier

  • isPaused: Throws if the staking is not paused.

    • Description: Ensures that the staking is paused before executing the function.

    • Usage: Apply this modifier to functions that should only be called when the staking is paused.

Events

Staked

  • Staked: Emitted when a user stakes tokens.

    • Parameters:

      • user: The address of the user who staked tokens.

      • amount: The amount of tokens staked.

      • lockDuration: The duration for which the tokens are locked.

      • tokenId: The ID of the staking NFT token.

Unstaked

  • Unstaked: Emitted when a user unstakes tokens.

    • Parameters:

      • user: The address of the user who unstaked tokens.

      • amount: The amount of tokens unstaked.

      • tokenId: The ID of the staking NFT token.

RewardDistributed

  • RewardDistributed: Emitted when rewards are distributed to a user.

    • Parameters:

      • receiver: The address of the receiver of the rewards.

      • nftId: The ID of the staking NFT token.

      • bdcaBonus: The amount of BDCA tokens rewarded.

      • usdtBonus: The amount of USDT tokens rewarded.

Functions

Initialize

Initializes the Staking contract with the provided parameters.

Copy

function initialize(
    address _defaultAdmin,
    address _upgrader,
    address _distributor,
    IPresale _presale,
    IStakingNFT _stakingNft,
    IERC20Metadata _bdca,
    IERC20Metadata _usdt
) initializer public

Parameters

  • address _defaultAdmin: The address of the default admin.

  • address _upgrader: The address of the upgrader.

  • address _distributor: The address of the distributor.

  • IPresale _presale: The address of the Presale contract.

  • IStakingNFT _stakingNft: The address of the Staking NFT contract.

  • IERC20Metadata _bdca: The address of the BDCA token contract.

  • IERC20Metadata _usdt: The address of the USDT token contract.

Modifiers

  • initializer: Ensures that the initialization is only done once.

Returns

None


_authorizeUpgrade

Internal function for upgrading proxy contract to the newImplementation addrress.

Copy

function _authorizeUpgrade(address newImplementation) internal override onlyRole(UPGRADER_ROLE)

Parameters

  • address newImplementation: The address of the new implementation.

Modifiers

  • onlyRole(UPGRADER_ROLE): Restricts the function to be called only by the upgrader role.

Returns

None


pause

Pauses the presale contract.

Copy

function pause() external virtual notPaused onlyRole(DEFAULT_ADMIN_ROLE)

Modifiers

  • notPaused: Ensures that the staking is not paused before executing the function.

  • onlyRole(DEFAULT_ADMIN_ROLE): Restricts the function to be called only by the admin role.

Returns

None


unpause

Unpauses the presale contract.

Copy

function unpause() external onlyRole(DEFAULT_ADMIN_ROLE) isPaused

Modifiers

  • onlyRole(DEFAULT_ADMIN_ROLE): Restricts the function to be called only by the admin role.

  • isPaused: Ensures that the staking is paused before executing the function.

Returns

None


setMaxStake

Sets the maximum stake amount.

Copy

function setMaxStake(uint256 _maxStake) external virtual onlyRole(DEFAULT_ADMIN_ROLE)

Parameters

  • uint256 _maxStake: The maximum stake amount.

Modifiers

  • onlyRole(DEFAULT_ADMIN_ROLE): Restricts the function to be called only by the default admin role.

Returns

None


setMinStake

Sets the minimum stake amount.

Copy

function setMinStake(uint256 _minStake) external virtual onlyRole(DEFAULT_ADMIN_ROLE)

Parameters

  • uint256 _minStake: The minimum stake amount.

Modifiers

  • onlyRole(DEFAULT_ADMIN_ROLE): Restricts the function to be called only by the default admin role.

Returns

None


updatePresaleAddress

Updates the address of the Presale contract.

Copy

function updatePresaleAddress(IPresale _presale) external virtual onlyRole(DEFAULT_ADMIN_ROLE)

Parameters

  • IPresale _presale: The new address of the Presale contract.

Modifiers

  • onlyRole(DEFAULT_ADMIN_ROLE): Restricts the function to be called only by the default admin role.

Returns

None


updateStakingNftAddress

Updates the address of the Staking NFT contract.

Copy

function updateStakingNftAddress(IStakingNFT _nft) external virtual onlyRole(DEFAULT_ADMIN_ROLE)

Parameters

  • IStakingNFT _nft: The new address of the Staking NFT contract.

Modifiers

  • onlyRole(DEFAULT_ADMIN_ROLE): Restricts the function to be called only by the default admin role.

Returns

None


updateBDCATokenAddress

Updates the address of the BDCA token (ERC20) contract.

Copy

function updateBDCATokenAddress(IERC20Metadata _token) external virtual onlyRole(DEFAULT_ADMIN_ROLE)

Parameters

  • IERC20Metadata _token: The new address of the BDCA token contract.

Modifiers

  • onlyRole(DEFAULT_ADMIN_ROLE): Restricts the function to be called only by the default admin role.

Returns

None


updateUSDTTokenAddress

Updates the address of the USDT token (ERC20) contract.

Copy

function updateUSDTTokenAddress(IERC20Metadata _token) external virtual onlyRole(DEFAULT_ADMIN_ROLE)

Parameters

  • IERC20Metadata _token: The new address of the USDT token contract.

Modifiers

  • onlyRole(DEFAULT_ADMIN_ROLE): Restricts the function to be called only by the default admin role.

Returns

None


updateTier

Copy

function updateTier(uint8 _tier,uint256 _bonusPercentage, uint256 _bonusAffiliatePercentage, LockDuration calldata _lockDuration) external onlyRole(DEFAULT_ADMIN_ROLE)

Parameters

  • uint8 _tier: The tier to update.

  • uint256 _bonusPercentage: The bonus percentage for the tier.

  • uint256 _bonusAffiliatePercentage: The affiliate bonus percentage for the tier.

  • LockDuration _lockDuration: The lock duration for the tier.

Modifiers

  • onlyRole(DEFAULT_ADMIN_ROLE): Restricts the function to be called only by the default admin role.

Returns

None


updateRevenueLanchingStatus

Updates the status of revenue launching.

Copy

function updateRevenueLanchingStatus(bool _isRevenuesLaunched) external onlyRole(DEFAULT_ADMIN_ROLE)

Parameters

  • bool _isRevenuesLaunched: The new status of revenue launching.

Modifiers

  • onlyRole(DEFAULT_ADMIN_ROLE): Restricts the function to be called only by the default admin role.

Returns

None


stake

Stakes tokens into the Staking contract. Users can stake a specified amount of BDCA tokens for a defined staking tier. This function enforces minimum stake requirements, tier existence validation, and updates relevant variables to reflect the staking action.

Copy

function stake(uint256 _amount, uint8 _tier) external virtual notPaused nonReentrant

Parameters

  • uint256 _amount: The amount to stake.

  • uint8 _tier: The tier of the stake.

Modifiers

  • notPaused: Ensures that staking is not paused before executing the function.

  • nonReentrant: Ensures that the function cannot be called recursively.

Returns

None


unstake

Unstakes tokens from the Staking contract. Users can unstake tokens by providing the ID of the corresponding staking NFT. This function checks ownership, lock expiration, and calculates the amount to be unstaked.

Copy

function unstake(uint256 _tokenId) external virtual nonReentrant notPaused

Parameters

  • uint256 _tokenId: The ID of the NFT representing the stake.

Modifiers

  • notPaused: Ensures that staking is not paused before executing the function.

  • nonReentrant: Ensures that the function cannot be called recursively.

Returns

None


distributeRewards

Distributes rewards to StakingNFT owners within a specified range of NFT IDs. This function is accessible only by the distributor role and requires revenue launching to be active. It calculates BDCA and USDT bonuses for each eligible NFT owner within the given range and distributes the rewards accordingly.

Copy

function distributeRewards(uint256 _fromNftId, uint256 _tillNftId) external virtual onlyRole(DISTRIBUTOR_ROLE)

Parameters

  • uint256 _fromNftId: The starting ID of the NFT range to distribute rewards.

  • uint256 _tillNftId: The ending ID of the NFT range to distribute rewards.

Modifiers

  • onlyRole(DISTRIBUTOR_ROLE): Restricts the function to be called only by the distributor role.

Returns

None


rescueToken

Transfers all remaining tokens to the admin. This function is accessible only when staking is paused and allows the default admin to retrieve any remaining tokens from the Staking contract.

Copy

function rescueToken(address _token) external virtual isPaused onlyRole(DEFAULT_ADMIN_ROLE)

Parameters

  • address _token: The address of the token to be rescued.

Modifiers

  • isPaused: Ensures that staking is paused before executing the function.

  • onlyRole(DEFAULT_ADMIN_ROLE): Restricts the function to be called only by the default admin role.

Returns

None


calculateStakeBonus

Calculates the total stake amount including the bonus for a given staking tier. If revenue launching is not active, the bonus is added to the stake amount based on the specified tier bonus percentage.

Copy

function calculateStakeBonus(uint256 _amount, uint8 _tier) public view virtual returns(uint256)

Parameters

  • uint256 _amount: The amount to calculate the bonus for.

  • uint8 _tier: The tier to calculate the bonus for.

Returns

  • uint256: The calculated stake bonus.


calculateBonuses

Calculates the bonuses (BDCA and USDT) for a specific staking tier based on the total staked amount, the staked amount of the current NFT, and the USDT total share amount.

Copy

function calculateBonuses(uint256 _usdtTotalShareAmount, uint256 _totalStakedBalance, uint256 _stakedAmount, uint8 _tier) public view virtual returns(uint256 bdcaBonus, uint256 usdtBonus)

Parameters

  • uint256 _usdtTotalShareAmount: The total USDT share amount.

  • uint256 _totalStakedBalance: The total staked balance.

  • uint256 _stakedAmount: The staked amount.

  • uint8 _tier: The tier to calculate bonuses for.

Returns

  • (uint256 bdcaBonus, uint256 usdtBonus): The calculated BDCA and USDT bonuses.


calculateUnstakeAmount

Calculates the amount to be unstaked for a given staking NFT ID. This amount is equal to the initially staked amount plus any bonus accumulated.

Copy

function calculateUnstakeAmount(uint256 tokenId) public view virtual returns (uint256)

Parameters

  • uint256 tokenId: The ID of the NFT representing the stake.

Returns

  • uint256: The calculated unstake amount.


_mintNFT

Mints a new NFT and assigns it to the specified address.

Copy

function _mintNFT(address _to) internal virtual returns (uint256)

Parameters

  • address _to: The address to assign the minted NFT to.

Returns

  • uint256: The ID of the minted NFT.


_burnNFT

Burns an existing NFT.

Copy

function _burnNFT(uint256 _tokenId) internal virtual

Parameters

  • uint256 _tokenId: The ID of the NFT to burn.

Returns

None


_eligibleNftId

Checks if a given NFT ID is eligible for rewards distribution.

Copy

function _eligibleNftId(uint256 _nftId) internal view virtual returns(bool)

Parameters

  • uint256 _nftId: The ID of the NFT to check.

Returns

  • bool: True if the NFT is eligible, false otherwise.