SELF Token Smart Contract Architecture
Overviewโ
The SELF token smart contract system is designed with modularity, security, and future migration in mind. Built on Ethereum as an ERC-20 token, it includes advanced features for staking, subscriptions, and governance while preparing for eventual migration to SELF Chain.
Contract Structureโ
Core Componentsโ
contracts/
โโโ SELFToken.sol # Main ERC-20 token contract
โโโ SELFOracle.sol # Price oracle for USD conversions
โโโ interfaces/
โ โโโ ISELFToken.sol # Interface for integrations
โโโ future/
โโโ SELFBridge.sol # Future bridge to SELF Chain
โโโ SELFGovernance.sol # Future governance module
Key Featuresโ
1. Non-Custodial Stakingโ
Unlike traditional staking, users retain full custody of their tokens:
// Tokens stay in user wallet
mapping(address => StakeInfo) public stakes;
struct StakeInfo {
uint256 amount; // Staked amount
uint256 timestamp; // Stake time
uint256 tier; // User tier level
uint256 rewards; // Accumulated rewards
}
Benefits:
- No smart contract risk for staked tokens
- Instant liquidity if needed
- Simplified tax implications
- Better user experience
2. Tier Systemโ
Three tiers provide increasing benefits:
Tier | Required SELF | APR Bonus | Benefits |
---|---|---|---|
Pioneer | 1,000 | +10% | Basic features, priority support |
Explorer | 10,000 | +25% | Advanced features, governance voting |
Multiverse | 100,000 | +50% | Full access, cross-chain privileges |
3. Dynamic Subscription Pricingโ
Oracle integration enables USD-based pricing:
// Price subscriptions in USD, pay in SELF
function purchaseSubscription(uint256 tierUSD, uint256 duration) {
uint256 selfAmount = oracle.usdToSelf(tierUSD);
// Process payment in SELF tokens
}
4. Deflationary Mechanicsโ
Multiple burn mechanisms create deflationary pressure:
- 50% of subscription payments burned
- Buyback program burns 40% of repurchased tokens
- Optional user burns for special features
5. Security Featuresโ
Access Control:
- Role-based permissions (DEFAULT_ADMIN, PAUSER, TREASURY)
- Multi-signature requirement for critical functions
- Time-locked admin actions
Safety Mechanisms:
- Pausable in emergencies
- Reentrancy guards
- Snapshot capability for migrations
- Prevention of staked token transfers
Integration Guideโ
For DEXsโ
Standard ERC-20 interface ensures compatibility:
// Uniswap V3 pool creation
const pool = await factory.createPool(
SELF_TOKEN_ADDRESS,
WETH_ADDRESS,
3000 // 0.3% fee tier
);
For Applicationsโ
Check user tier and subscription status:
const self = new ethers.Contract(SELF_ADDRESS, SELF_ABI, provider);
const userTier = await self.getUserTier(userAddress);
const isActive = await self.isSubscriptionActive(userAddress);
For Walletsโ
Display staking information:
const stakeInfo = await self.stakes(userAddress);
const rewards = await self.calculateRewards(userAddress);
Gas Optimizationโ
The contract employs several gas-saving techniques:
- Packed struct storage
- Minimal external calls
- Efficient reward calculations
- Batch operations where possible
Estimated Gas Costs:
- Token Transfer: ~65,000 gas
- Stake/Unstake: ~85,000 gas
- Claim Rewards: ~75,000 gas
- Purchase Subscription: ~120,000 gas
Development Setupโ
Prerequisitesโ
npm install --save-dev hardhat @openzeppelin/contracts
Compile Contractsโ
npx hardhat compile
Run Testsโ
npx hardhat test
Deploy to Mainnetโ
npx hardhat run scripts/deploy.js --network mainnet
Security Considerationsโ
Auditing Strategyโ
- Internal review and testing
- Community bug bounty program
- Professional audit before mainnet
- Continuous monitoring post-launch
Best Practicesโ
- Immutable core functions
- Upgradeable auxiliary features
- Clear documentation
- Comprehensive event logging
Contract Addressesโ
Testnet (Goerli)โ
- Token:
[To be deployed]
- Oracle:
[To be deployed]
Mainnetโ
- Token:
[To be deployed]
- Oracle:
[To be deployed]
Resourcesโ
The SELF token smart contract architecture provides robust features for staking, subscriptions, and ecosystem participation while maintaining security and efficiency.