A blockchain-based retirement savings system that allows individuals to build long-term pension wealth — without governments, banks, or pension funds. Smart contracts automate savings, investments, and payouts in a fully transparent and trustless way.
Instead of centralized fund managers, smart contracts handle everything — automatically, transparently, and without any middlemen.
Open source • Auditable • Deployable on BSC
// SPDX-License-Identifier: MIT pragma solidity ^0.8.24; /* DeFi Pension Prototype Educational only — NOT audited */ interface IERC20 { function transfer(address to, uint256 amount) external returns (bool); function transferFrom(address from, address to, uint256 amount) external returns (bool); function balanceOf(address user) external view returns (uint256); function approve(address spender, uint256 amount) external returns (bool); } // Strategy — connects to Aave, Compound, Yearn, etc. interface IPensionStrategy { function deposit(uint256 amount) external; function withdraw(uint256 amount) external; function totalAssets() external view returns (uint256); } contract DeFiPension { IERC20 public immutable asset; address public dao; IPensionStrategy public strategy; uint256 public constant BASIS_POINTS = 10_000; uint256 public constant EARLY_EXIT_PENALTY_BP = 1_000; // 10% struct PensionPlan { uint256 totalContributed; uint256 shares; uint256 retirementTime; uint256 lastPayout; bool retired; } mapping(address => PensionPlan) public plans; uint256 public totalShares; event PlanCreated (address indexed user, uint256 retirementTime); event Contribution (address indexed user, uint256 amount); event EarlyWithdraw(address indexed user, uint256 amount, uint256 penalty); event Retired (address indexed user); event PensionPaid (address indexed user, uint256 amount); event StrategyUpdated(address newStrategy); modifier onlyDAO() { require(msg.sender == dao, "Not DAO"); _; } constructor(address _asset, address _strategy, address _dao) { asset = IERC20(_asset); strategy = IPensionStrategy(_strategy); dao = _dao; asset.approve(_strategy, type(uint256).max); } // ── CREATE PLAN ─────────────────────────────── function createPlan(uint256 retirementTime) external { require(plans[msg.sender].retirementTime == 0, "Plan exists"); require(retirementTime > block.timestamp + 365 days, "Too soon"); plans[msg.sender] = PensionPlan(0, 0, retirementTime, 0, false); emit PlanCreated(msg.sender, retirementTime); } // ── CONTRIBUTE ──────────────────────────────── function contribute(uint256 amount) external { PensionPlan storage p = plans[msg.sender]; require(p.retirementTime > 0, "No plan"); require(!p.retired, "Retired"); asset.transferFrom(msg.sender, address(this), amount); uint256 pb = strategy.totalAssets(); strategy.deposit(amount); uint256 minted = totalShares == 0 ? amount : (amount * totalShares) / pb; p.shares += minted; p.totalContributed += amount; totalShares += minted; emit Contribution(msg.sender, amount); } // ── ENTER RETIREMENT ────────────────────────── function enterRetirement() external { PensionPlan storage p = plans[msg.sender]; require(!p.retired, "Already retired"); require(block.timestamp >= p.retirementTime, "Too early"); p.retired = true; p.lastPayout = block.timestamp; emit Retired(msg.sender); } // ── CLAIM PENSION (2% monthly annuity) ──────── function claimPension() external { PensionPlan storage p = plans[msg.sender]; require(p.retired, "Not retired"); require(block.timestamp - p.lastPayout >= 30 days, "Too soon"); uint256 entitled = (strategy.totalAssets() * p.shares) / totalShares; uint256 payout = (entitled * 200) / BASIS_POINTS; p.lastPayout = block.timestamp; strategy.withdraw(payout); asset.transfer(msg.sender, payout); emit PensionPaid(msg.sender, payout); } // ── EMERGENCY WITHDRAW (10% penalty) ────────── function emergencyWithdraw() external { PensionPlan storage p = plans[msg.sender]; require(!p.retired, "Already retired"); uint256 entitled = (strategy.totalAssets() * p.shares) / totalShares; uint256 penalty = (entitled * EARLY_EXIT_PENALTY_BP) / BASIS_POINTS; totalShares -= p.shares; delete plans[msg.sender]; strategy.withdraw(entitled); asset.transfer(msg.sender, entitled - penalty); asset.transfer(dao, penalty); emit EarlyWithdraw(msg.sender, entitled - penalty, penalty); } // ── ADMIN ────────────────────────────────────── function updateStrategy(address newStrategy) external onlyDAO { strategy = IPensionStrategy(newStrategy); asset.approve(newStrategy, type(uint256).max); emit StrategyUpdated(newStrategy); } }
Multi-layer protection ensuring safety of all pension funds on-chain.
Estimate your retirement wealth with DeFi Pension Protocol.
* Estimates only. Past yields do not guarantee future returns. DeFi carries risk.
Our path to building the world's first fully decentralized pension protocol.