Author: Apolo San
License: MIT
Version: 1.0.0
Reference System for DeFi (RSD) is an innovative DeFi protocol that implements a dynamic supply adjustment mechanism for an ERC20 token. The system automatically adjusts token supply based on trading volume and market activity, combined with a unique reward system and gambling mechanism.
- Elastic Supply: Token supply automatically adjusts based on trading volume and market metrics
- Optimal Policy Algorithm: Uses machine learning-inspired algorithms to determine supply changes
- Random Policy Fallback: Implements random adjustments for increased unpredictability
- Crowdsale Functionality: Built-in token sale mechanism with configurable duration and rates
- Miner Rewards: Automatic rewards for block miners (10% of reward pool)
- Owner Rewards: Configurable rewards for contract owner
- Proof of Bet (PoBet): Gambling mechanism where users can win pooled tokens
- OpenZeppelin Integration: Built on battle-tested OpenZeppelin contracts
- Access Control: Owner-only functions for critical parameters
- SafeMath: Protection against integer overflow/underflow
- Comprehensive Testing: Extensive test suite covering all functionality
The RSD token implements a sophisticated supply adjustment mechanism:
1. Volume Tracking: Monitor trading volume over transaction intervals
2. Metric Calculation: Calculate distance between target and current supply
3. Policy Decision: Choose between optimal or random adjustment policy
4. Supply Adjustment: Mint or burn tokens based on policy decision
5. Reward Distribution: Distribute rewards to miners and pools
Parameter | Default Value | Description |
---|---|---|
ALPHA |
120 | Learning rate for optimal policy |
EPSILON |
120 | Threshold for policy selection |
EXPANSION_RATE |
1000 | Rate of market cap expansion (0.1%) |
SALE_RATE |
2000 | Crowdsale conversion rate |
CROWDSALE_DURATION |
7889229 | Crowdsale duration (3 months) |
- Node.js >= 12.0.0
- npm or yarn
- Truffle Framework
- Ganache CLI (for local development)
# Clone the repository
git clone https://github.com/apolosan/rsd.git
cd rsd
# Install dependencies
npm install
# Install Truffle globally (if not already installed)
npm install -g truffle
# Install Ganache CLI for local blockchain
npm install -g ganache-cli
- Create a
.secret
file with your mnemonic phrase:
echo "your twelve word mnemonic phrase here" > .secret
- Configure network settings in
truffle-config.js
as needed.
- Start Ganache:
ganache-cli
- Compile Contracts:
truffle compile
- Deploy Contracts:
truffle migrate --network development
- Run Tests:
truffle test
The project includes a comprehensive JavaScript simulation:
node simulation/rsd_simulation.js
This simulation demonstrates:
- Multi-account trading scenarios
- Supply adjustment mechanisms
- Reward distribution
- Price estimation algorithms
Deploy to BSC Testnet:
truffle migrate --network bsc_testnet
function transfer(address recipient, uint256 amount) external returns (bool)
function approve(address spender, uint256 amount) external returns (bool)
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool)
function crowdsale(address beneficiary) public payable
- Allows users to purchase RSD tokens by sending ETH
- Rate: 1 ETH =
SALE_RATE * 1.5
RSD tokens - Maximum purchase: 50,000 RSD per transaction
function updateSaleRate(uint16 rate) external onlyOwner
function updateCrowdsaleDuration(uint128 timestampDuration) external onlyOwner
function updateExpansionRate(uint16 expansionRate) external onlyOwner
function withdrawSales(address payable account) external onlyOwner
function burn(uint256 amount) external
function generateRandomMoreThanOnce() external
function obtainRandomNumber(uint256 modulus) external
event SupplyAdjustment(bool reduction, uint256 amount)
event PolicyAdjustment(bool reduction, uint16 percentageFactor)
event PoBet(address winner, uint256 amount)
event Reward(address miner, uint256 amount)
event Pool(uint256 amount)
The project includes comprehensive tests covering:
- Contract Deployment: Verify proper initialization
- ERC20 Functionality: Standard token operations
- Crowdsale Mechanism: Token purchase and limits
- Supply Adjustment: Dynamic supply changes
- Reward System: Miner and owner rewards
- Random Number Generation: Cryptographic randomness
- Access Control: Owner-only functions
Run specific test categories:
# Run all tests
truffle test
# Run with gas reporting
truffle test --reporter eth-gas-reporter
ReferenceSystemDeFi.sol
βββ ERC20 Implementation
βββ Ownable Access Control
βββ Crowdsale Functionality
βββ Supply Adjustment Engine
βββ Reward Distribution System
βββ Random Number Generator
βββ Betting Mechanism (PoBet)
- Factory Pattern: Used for account and transaction management
- Observer Pattern: Events for external monitoring
- Strategy Pattern: Multiple policy adjustment strategies
- Singleton Pattern: Contract state management
@openzeppelin/contracts
: Security and standard implementations@truffle/hdwallet-provider
: Wallet management for deploymentbignumber.js
: Precise decimal arithmetic@metamask/detect-provider
: Web3 provider detection
- Integer Overflow Protection: SafeMath library usage
- Access Control: Owner-only critical functions
- Reentrancy Protection: Proper state updates before external calls
- Input Validation: Parameter bounds checking
- Randomness: Cryptographically secure random number generation
- Oracle Dependency: Price feeds rely on transaction volume
- Centralization: Owner has significant control over parameters
- Complexity: Advanced economic mechanisms may have edge cases
The included simulation demonstrates:
- Supply Elasticity: Token supply adjusts Β±15% based on trading volume
- Reward Distribution: ~1-2% of transaction volume goes to rewards
- Price Stability: Mechanism helps stabilize token value
- Network Effects: Increased usage leads to more rewards
Example simulation output:
INITIAL SUPPLY: 4950.00 RSD
FINAL SUPPLY: 5247.83 RSD
GROW RATE: 5.6742 %
- Fork the repository
- Create a feature branch:
git checkout -b feature/amazing-feature
- Make your changes and add tests
- Ensure all tests pass:
truffle test
- Commit your changes:
git commit -m 'Add amazing feature'
- Push to the branch:
git push origin feature/amazing-feature
- Open a Pull Request
- Follow Solidity style guide
- Add comprehensive tests for new features
- Document all public functions
- Use meaningful variable names
- Include gas optimization considerations
This project is licensed under the MIT License - see the LICENSE file for details.
- Repository: https://github.com/apolosan/rsd
- Documentation: This README
- Issues: https://github.com/apolosan/rsd/issues
Author: Apolo San
Email: [Contact via GitHub]
GitHub: @apolosan
- β Core ERC20 functionality
- β Dynamic supply adjustment
- β Crowdsale mechanism
- β Reward system
- β Comprehensive testing
- π Oracle integration for external price feeds
- π Governance token mechanics
- π Liquidity mining programs
- π Cross-chain compatibility
- π Advanced staking mechanisms
Built with β€οΈ for the DeFi community