KAGE Network - Staking dapp
Decentralized Linear Staking Platform for KAGE Network
๐ Documentation ยท ๐ Live Platform ยท ๐ฌ Community
KagePool Contract Documentation¶
Overview¶
The KagePool contract is a robust staking pool system designed to allow users to stake ERC20 tokens and earn rewards over time. It supports multiple staking pools, each with customizable parameters such as cap, minimum stake, lock duration, and staking periods. Key features include:
- Multiple Pools: Manage various staking pools with distinct configurations.
- Early Withdrawals: Allow users to withdraw their staked tokens before the lock period ends, subject to penalties.
- Whitelisting: Control access to pools through whitelisting mechanisms.
- Emergency Withdrawals: Enable users to withdraw their stakes in case of emergencies.
- Gas Optimization: Structs are tightly packed, and storage operations are minimized for cost efficiency.
- Upgradeable: Utilizes OpenZeppelin's upgradeable contracts for future enhancements.
Contract Structure¶
contract KagePool is
Initializable,
OwnableUpgradeable,
ReentrancyGuardUpgradeable,
PausableUpgradeable
{
// Contract code...
}
Key Components¶
Structs¶
- KagePoolInfo: Stores configuration details of each staking pool.
- KageRevenueData: Tracks revenue data for users.
- KageStakingData: Maintains staking information for users in a pool.
- AdditionalPoolInfo: Contains supplementary pool information like penalties and delays.
- KagePendingEarlyWithdrawal: Manages data for users pending early withdrawals.
Events¶
KagePoolCreated,KageDeposit,KageWithdraw,KageClaimPendingWithdraw,KageEarlyWithdraw,KageUpdatePool,KageSetDelayDuration,KageAssignStakingData,KageAdminRecoverFund,KageChangeRewardDistributor,KageChangeTreasury
Functions¶
- Initialization & Management
__KagePool_init: Initializes the contract.kageAddPool: Adds a new staking pool.kageSetPool: Updates pool parameters.pauseContract/unpauseContract: Pauses or unpauses the contract.- Staking Operations
kageDeposit: Allows users to stake tokens.kageWithdraw: Enables users to withdraw staked tokens after the lock period.kageEarlyWithdrawAll: Initiates early withdrawal with penalties.kageEmergencyWithdraw: Allows emergency withdrawals when enabled.- Administrative Functions
setTreasury: Updates the treasury address.kageAdminRecoverFund: Recovers tokens mistakenly sent to the contract.kageSetRewardDistributor: Changes the reward distributor address.kageAssignStakedData: Reassigns staking data from one user to another.- View Functions
kagePoolLength,kageTotalStaked,kageBalanceOf,kageUserStakingData,getPoolEarlyWithdrawalPenalty,getPoolDelayDuration
Modifiers¶
kageValidatePoolById: Ensures the pool exists.onlyOwner: Restricts function access to the contract owner.nonReentrant: Prevents reentrancy attacks.whenNotPaused/whenPaused: Controls function execution based on contract pause state.
Mermaid Graph¶
```mermaid graph LR A[KagePool Contract] A → B[Initializable] A → C[OwnableUpgradeable] A → D[ReentrancyGuardUpgradeable] A → E[PausableUpgradeable] A → F[Pool Management] A → G[Staking Operations] A → H[Administrative Functions] A → I[View Functions]
F --> F1[kageAddPool]
F --> F2[kageSetPool]
G --> G1[kageDeposit]
G --> G2[kageWithdraw]
G --> G3[kageEarlyWithdrawAll]
G --> G4[kageEmergencyWithdraw]
H --> H1[setTreasury]
H --> H2[kageAdminRecoverFund]
H --> H3[kageSetRewardDistributor]
H --> H4[kageAssignStakedData]
I --> I1[kagePoolLength]
I --> I2[kageTotalStaked]
I --> I3[kageBalanceOf]
I --> I4[kageUserStakingData]
I --> I5[getPoolEarlyWithdrawalPenalty]
I --> I6[getPoolDelayDuration]
```
KAGENETWORK Contract Documentation¶
Overview¶
The KAGENETWORK contract is an ERC20-compliant token with advanced features designed for efficient token management and trading. It incorporates tax mechanisms, multi-send capabilities, integration with Uniswap for liquidity and trading, and supports EIP-2612 permits for gasless approvals. Key functionalities include:
- ERC20 Standard Compliance: Implements standard ERC20 functions like transfer, approve, and transferFrom.
- Tax Mechanisms: Applies buy and sell taxes, which are allocated to designated tax wallets.
- Uniswap Integration: Facilitates automatic liquidity addition and token swapping via Uniswap V2.
- Permit (EIP-2612): Allows approvals via signatures for gasless transactions.
- Multi-send Features: Enables batch transfers to multiple recipients for gas optimization.
- Access Control: Utilizes Ownable and custom modifiers for restricted function access.
- Upgradeability & Maintenance: Provides functions to manage tax wallets, ratios, trading status, and other parameters.
Contract Structure¶
Key Components¶
Structs¶
- mappingStructs: Manages address-specific settings like fee exclusions and block tracking.
- InitialData: Holds initial configuration data for taxes and ratios.
- TaxWallet: Represents wallets designated to receive tax allocations.
Events¶
Bought,Sold,Transfer,Approval
Functions¶
- ERC20 Standard Functions
name,symbol,decimals,totalSupply,balanceOf,transfer,allowance,approve,transferFrom- Permit (EIP-2612) Functions
permit,nonces,DOMAIN_SEPARATOR- Tax Management
setSellTax,setBuyTax,setSwapDivisor,setMaxTxRatio,setMaxWalletRatio,addTaxWallet,removeTaxWallet- Uniswap Integration
openTrading,_sell,doTaxes,sendETHToFee- Multi-send Functions
multisend,multisendFrom- Administrative Functions
changeERC20Controller,addNewLPPair,disableBlocklistAdd,setExcludedFromFee,setEthSendDivisor- View Functions
isExcludedFromFee,getLPPair,getTaxWallets,getERC20Controller,getSellTax,getBuyTax
Modifiers¶
onlyERC20Controller: Restricts access to the ERC20 controller.onlyDev: Limits function execution to the developer wallet.
Internal Functions¶
_approve: Handles token approvals._transfer: Manages token transfers with tax considerations._tokenTransfer: Processes actual token balance updates and tax application.calculateTaxesFee: Calculates the tax amount based on the transaction.
Mermaid Graph¶
```mermaid graph LR A[KAGENETWORK Contract] A → B[Context] A → C[IERC20] A → D[Ownable] A → E[IMultisend] A → F[IERC20Permit] A → G[ERC20 Functions] A → H[Tax Management] A → I[Uniswap Integration] A → J[Permit Functions] A → K[Multi-send Functions] A → L[Administrative Functions] A → M[View Functions]
G --> G1[name]
G --> G2[symbol]
G --> G3[decimals]
G --> G4[totalSupply]
G --> G5[balanceOf]
G --> G6[transfer]
G --> G7[allowance]
G --> G8[approve]
G --> G9[transferFrom]
H --> H1[setSellTax]
H --> H2[setBuyTax]
H --> H3[setSwapDivisor]
H --> H4[setMaxTxRatio]
H --> H5[setMaxWalletRatio]
H --> H6[addTaxWallet]
H --> H7[removeTaxWallet]
I --> I1[openTrading]
I --> I2[_sell]
I --> I3[doTaxes]
I --> I4[sendETHToFee]
J --> J1[permit]
J --> J2[nonces]
J --> J3[DOMAIN_SEPARATOR]
K --> K1[multisend]
K --> K2[multisendFrom]
L --> L1[changeERC20Controller]
L --> L2[addNewLPPair]
L --> L3[disableBlocklistAdd]
L --> L4[setExcludedFromFee]
L --> L5[setEthSendDivisor]
M --> M1[isExcludedFromFee]
M --> M2[getLPPair]
M --> M3[getTaxWallets]
M --> M4[getERC20Controller]
M --> M5[getSellTax]
M --> M6[getBuyTax]
```
Detailed Functionalities¶
ERC20 Standard Compliance¶
Implements all standard ERC20 functions, ensuring interoperability with wallets, exchanges, and other ERC20-compatible platforms.
Tax Mechanisms¶
- Buy Tax: Applied on token purchases, deducted from the transaction amount.
- Sell Tax: Applied on token sales, deducted before transferring tokens to the seller.
- Tax Allocation: Taxes are accumulated in the contract and periodically swapped for ETH using Uniswap, then distributed to designated tax wallets based on predefined ratios.
Uniswap Integration¶
Facilitates automatic liquidity addition and token swapping:
- openTrading: Initializes Uniswap pair, adds liquidity, and enables trading.
- doTaxes: Swaps accumulated tax tokens for ETH.
- sendETHToFee: Distributes swapped ETH to tax wallets.
Permit (EIP-2612)¶
Allows users to approve token allowances via off-chain signatures, enabling gasless approvals and enhancing user experience.
Multi-send Features¶
- multisend: Enables batch transfers to multiple recipients in a single transaction.
- multisendFrom: Allows batch transfers on behalf of another address, provided allowance is set.
Access Control¶
Utilizes Ownable for administrative functions and custom modifiers (onlyERC20Controller, onlyDev) to restrict sensitive operations to authorized roles.
Administrative Controls¶
- Tax Management: Adjust tax rates, add or remove tax wallets, and set tax ratios.
- Controller Management: Change the ERC20 controller responsible for proxy operations.
- Trading Controls: Open trading, manage liquidity pairs, and control blocklisting features.
Conclusion¶
Both KagePool and KAGENETWORK contracts offer comprehensive functionalities tailored for staking and token management within a decentralized ecosystem. KagePool focuses on providing flexible and secure staking options, while KAGENETWORK enhances token utility with tax mechanisms, trading integrations, and advanced ERC20 features. The accompanying Mermaid graphs illustrate the structural relationships and key components of each contract, aiding in better understanding and visualization.