🤖Dynamic Staking

Welcome to the Dynamic Staking smart contract documentation. This guide is designed to help you understand how the DynamicStaking contract works, its functionalities, and how users can interact with i

Overview

The Dynamic Staking contract is a sophisticated staking mechanism built on the Ethereum blockchain. It allows users to stake BET tokens in a dynamic environment where profits and losses are calculated over cycles. The contract supports creating new staking pools, staking tokens, withdrawing tokens, and distributing profits or losses.

Key Features

  • Dynamic Staking Pools: Supports the creation of new pools for staking tokens.

  • Profit and Loss Calculation: Calculates profits and losses at the end of each cycle and distributes them accordingly.

  • Invitee Staking: Tracks the total stakes made by invitees of a staker.

  • Non-Reentrant: Ensures that functions cannot be re-entered, mitigating potential security risks.

  • Access Control: Utilizes roles for managing permissions within the contract.

Key Components

ComponentDescription

ERC20 Token

The contract interacts with ERC20 tokens for staking and rewards.

DynamicStakingPool

Represents each staking pool within the contract.

Core

The core logic for token management and access control.

Calculation Window

A predefined time window for calculating profits/losses and distributing them.

Users can stake tokens by invoking the stake function. The amount to be staked must be greater than or equal to the minimum allowed amount.

function stake(address staker, uint256 amount) external onlyRole(CORE) nonReentrant

Requirements:

  • Not within the calculation window (DS04 error).

  • The amount is at least the minimum allowed amount (DS01 error).

  • The amount is divisible by 2 (DS09 error).

Withdraw Tokens

Tokens can be withdrawn from a pool by calling the withdraw function. This is only allowed during the calculation time and if the pool is fully distributed.

function withdraw(address pool) external

Requirements:

  • Must be calculation time (DS03 error).

  • Pool must be active and successfully distributed in the current cycle (DS08, DS10, DS11 errors).

Calculate Profit or Loss

This function calculates and distributes the profit or loss for each cycle. It must be called at least once per cycle based on the active pool count.

function calculateProfit(uint256 offset, uint256 count) external nonReentrant

Requirement:

  • Must be calculation time (DS03 error).

Reserve Funds

Allows game contracts to reserve funds from the staking contract.

function reserveFunds(uint256 amount) external onlyRole(GAME)

Requirements:

  • Not within the calculation window (DS04 error).

  • Sufficient balance to reserve (DS06 error).

Adjust Settings

The contract allows adjusting the minimum allowed staking amount and the calculation window through the following functions, controlled by the TIMELOCK role.

  • setMinAllowedAmount(uint256 _amount): Adjusts the minimum staking amount.

  • setCalculatingWindow(uint256 _window): Adjusts the calculation window.

Events

Various events are emitted for tracking activities within the contract, such as PoolOpened, PoolClosed, Staked, Withdraw, NewMinAllowedAmount, and NewCalculationWindow.

Conclusion

The Dynamic Staking smart contract introduces a flexible and dynamic approach to staking on the Ethereum blockchain. By leveraging calculation cycles, dynamic pools, and robust access control, it offers a comprehensive staking solution for users.

Last updated