{"id":30584495,"url":"https://github.com/ohmysol/erc20-rebase-token","last_synced_at":"2025-08-29T09:38:01.542Z","repository":{"id":311337611,"uuid":"1043422459","full_name":"ohMySol/erc20-rebase-token","owner":"ohMySol","description":"Rebase token that can be used in DeFi protocols to track users deposits + earned interest.","archived":false,"fork":false,"pushed_at":"2025-08-24T00:16:08.000Z","size":4,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-08-24T08:28:19.271Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Solidity","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ohMySol.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-08-23T20:22:33.000Z","updated_at":"2025-08-24T00:16:11.000Z","dependencies_parsed_at":"2025-08-24T09:02:24.622Z","dependency_job_id":"c18d1aee-8ef5-409f-a1fb-5ffe5ee0b470","html_url":"https://github.com/ohMySol/erc20-rebase-token","commit_stats":null,"previous_names":["ohmysol/erc20-rebase-token"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/ohMySol/erc20-rebase-token","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ohMySol%2Ferc20-rebase-token","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ohMySol%2Ferc20-rebase-token/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ohMySol%2Ferc20-rebase-token/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ohMySol%2Ferc20-rebase-token/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ohMySol","download_url":"https://codeload.github.com/ohMySol/erc20-rebase-token/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ohMySol%2Ferc20-rebase-token/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":272663963,"owners_count":24972507,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-29T02:00:10.610Z","response_time":87,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-08-29T09:37:58.103Z","updated_at":"2025-08-29T09:38:01.534Z","avatar_url":"https://github.com/ohMySol.png","language":"Solidity","funding_links":[],"categories":[],"sub_categories":[],"readme":"# RebaseERC20 - ETH Rebase Token Contract\n\nA rebase token implementation where user balances automatically increase as the underlying ETH pool grows, similar to AAVE's aTokens or Lido's stETH.\nWhile AAVE or Lido rebase tokens work with different tokens for deposit, my example showcase ETH usage as underlying token. But the code in **ERC20RebaseToken.sol** contract can be easily adjusted to use different tokens for depositing.\n\n## 🔑 Key Concept\n\nThis contract uses a **shares-based mechanism** where:\n- Users deposit ETH and receive **shares** representing their proportional ownership\n- User balances are calculated dynamically based on their share percentage of the total ETH pool\n- As the contract's ETH balance grows (through interest, staking rewards, etc.), all user balances automatically increase proportionally\n\n### The Magic Formula\n```solidity\nUser Balance = (User Shares × Total ETH Pool) ÷ Total Shares\n```\n\n## 🚀 How It Works\n\n### Example Scenario\n\n**Initial State:**\n- Alice deposits 10 ETH → receives 10 shares\n- Bob deposits 40 ETH → receives 40 shares  \n- Total: 50 ETH, 50 shares\n\n**Balances:**\n- Alice: `10 shares × 50 ETH ÷ 50 shares = 10 ETH`\n- Bob: `40 shares × 50 ETH ÷ 50 shares = 40 ETH`\n\n**After 10 ETH Interest Earned:**\n- Contract now has 60 ETH total\n- Shares remain unchanged (10 + 40 = 50)\n\n**New Balances automatically updated:**\n- Alice: `10 shares × 60 ETH ÷ 50 shares = 12 ETH` ✨ (+2 ETH interest)\n- Bob: `40 shares × 60 ETH ÷ 50 shares = 48 ETH` ✨ (+8 ETH interest)\n\n## 📋 Contract Methods\n\n### `balanceOf(address account) → uint256`\nReturns the current ETH balance (including earned interest) that the user can withdraw.\n\n### `mint(address to, uint256 slippageBp) payable`\nDeposits ETH and mints shares representing proportional ownership.\n\n**Parameters:**\n- `to`: Address to receive the shares\n- `slippageBp`: Maximum slippage in basis points (protection against deposit front-running)\n\n**Share Calculation:**\n- First deposit: `shares = msg.value`\n- Subsequent: `shares = totalShares × msg.value ÷ (currentBalance - msg.value)`\n\n### `burn(address from, uint256 amount)`\nBurns shares and withdraws the specified ETH amount (including interest).\n\n**Parameters:**\n- `from`: Address to burn shares from  \n- `amount`: **ETH amount** to withdraw (NOT shares)\n\n**Important:** The `amount` is in ETH, not shares. The contract calculates how many shares to burn automatically.\n\n### `transfer(address to, uint256 amount) → bool`\nTransfers ETH amount worth of shares to another address.\n\n### `transferFrom(address from, address to, uint256 amount) → bool`\nTransfers ETH amount worth of shares between addresses (requires allowance).\n\n### `approve(address spender, uint256 amount) → bool`\nApproves spender to spend shares amount on behalf of owner.\n\n**Note:** Allowances are in share amounts, not in underlying tokens.\n\n### `allowance(address owner, address spender) → uint256`\nReturns the shares amount the spender can spend on behalf of owner.\n\n### `totalSupply() → uint256`\nReturns the total ETH held by the contract.\n\n### `_amountToShares(uint256 amount) → (uint256)`\nConverts amount of tokens in shares representation.\nWhen user transfer or withdraw underlying tokens, we need to calculate how many shares to deduct, add from the balance.\n\n### `_spendAllowanceOrBlock()`\nVerify spender allowance and decrease it if validation pass.\n\n## 🔒 Security Features\n\n### Slippage Protection\nThe `mint` function includes slippage protection to prevent small deposit attack and front running:\n\n```solidity\n// Reverts if shares received deviate too much from expected\nif (sharesToMint * 10000 * totalBalance \u003c slippageBp * msg.value * _totalShares) {\n    revert SharesSlippage();\n}\n```\n\n### Withdrawal Protection\nUsers cannot withdraw more ETH than they own:\n- The `_amountToShares` conversion ensures proper share calculation\n- Underflow protection prevents burning more shares than owned\n- Zero-share burns are blocked to prevent ETH drainage\n\n### Allowance System\nStandard ERC20 allowance system for secure third-party interactions.\n\n## ⚠️ Important Considerations\n\n### Rounding\nDue to integer division, small amounts might round down to zero shares. The contract prevents zero-share burns to avoid ETH loss.\n\n### Interest Generation\nThis contract **does not generate interest automatically**. Interest must be added externally through:\n- Direct ETH transfers to the contract\n- Integration with yield protocols (staking, DeFi lending)\n- Rewards distribution mechanisms\n\n### Transfer Precision\nWhen transferring amounts, the receiving balance might be slightly less due to rounding in the shares conversion.\n\n## 🎯 Use Cases\n\n- **Liquid Staking Tokens**: Represent staked ETH that earns rewards\n- **Interest-Bearing Deposits**: DeFi savings accounts that accrue yield  \n- **Reward Distribution**: Automatically distribute protocol fees to token holders\n- **Yield Farming**: Tokens that appreciate from farming rewards\n\n---\n\n*This implementation provides the foundation for a rebase token system. Additional features like governance, yield strategies, or access controls can be added as needed.*","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fohmysol%2Ferc20-rebase-token","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fohmysol%2Ferc20-rebase-token","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fohmysol%2Ferc20-rebase-token/lists"}