{"id":50496184,"url":"https://github.com/davidweb3-ctrl/staking-mining","last_synced_at":"2026-06-02T07:03:59.679Z","repository":{"id":325410299,"uuid":"1101000205","full_name":"davidweb3-ctrl/staking-mining","owner":"davidweb3-ctrl","description":"An ETH staking mining protocol developed using Foundry, where users stake ETH to earn KK Token rewards distributed fairly based on duration and staking amount, with optional integration with a lending market to earn additional interest.","archived":false,"fork":false,"pushed_at":"2025-11-21T06:36:30.000Z","size":17,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-11-21T08:31:30.290Z","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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/davidweb3-ctrl.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-11-21T03:48:10.000Z","updated_at":"2025-11-21T06:36:34.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/davidweb3-ctrl/staking-mining","commit_stats":null,"previous_names":["davidweb3-ctrl/staking-mining"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/davidweb3-ctrl/staking-mining","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davidweb3-ctrl%2Fstaking-mining","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davidweb3-ctrl%2Fstaking-mining/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davidweb3-ctrl%2Fstaking-mining/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davidweb3-ctrl%2Fstaking-mining/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/davidweb3-ctrl","download_url":"https://codeload.github.com/davidweb3-ctrl/staking-mining/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davidweb3-ctrl%2Fstaking-mining/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33810345,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-02T02:00:07.132Z","response_time":109,"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":"2026-06-02T07:03:58.395Z","updated_at":"2026-06-02T07:03:59.674Z","avatar_url":"https://github.com/davidweb3-ctrl.png","language":"Solidity","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ETH Staking Mining Contract\n\n一个基于 Solidity 的 ETH 质押挖矿合约，允许用户质押 ETH 来赚取 KK Token 奖励。奖励根据质押时长和质押数量进行公平分配。\n\n## 功能特性\n\n- ✅ **质押功能**: 用户可以质押 ETH 到合约\n- ✅ **赎回功能**: 用户可以赎回质押的 ETH\n- ✅ **奖励领取**: 用户可以领取赚取的 KK Token 奖励\n- ✅ **公平分配**: 奖励根据质押数量 × 质押时长进行分配\n- ✅ **每区块奖励**: 每个区块产出 10 个 KK Token\n- ✅ **借贷市场集成** (加分项): 质押的 ETH 可以存入借贷市场赚取利息\n\n## 项目结构\n\n```\nstaking-mining/\n├── contracts/\n│   ├── interfaces/\n│   │   ├── IToken.sol          # KK Token 接口\n│   │   ├── IStaking.sol        # 质押接口\n│   │   └── ILendingPool.sol   # 借贷市场接口\n│   ├── KKToken.sol             # KK Token 实现\n│   └── StakingPool.sol         # 质押池合约\n├── test/\n│   └── StakingPool.t.sol       # 测试文件\n├── script/\n│   └── Deploy.s.sol            # 部署脚本\n├── foundry.toml                # Foundry 配置\n└── README.md\n```\n\n## 技术实现\n\n### 公平分配机制\n\n合约使用权重系统来实现公平分配：\n- **权重计算**: `权重 = 质押数量 × 质押时长（区块数）`\n- **奖励分配**: 每个区块产出的 10 个 KK Token 按照用户权重占总权重的比例分配\n\n### 核心合约\n\n1. **KKToken**: ERC20 代币，支持授权合约铸造\n2. **StakingPool**: 质押池合约，实现所有质押和奖励逻辑\n\n## 安装和设置\n\n### 前置要求\n\n- [Foundry](https://book.getfoundry.sh/getting-started/installation)\n- Node.js (可选，用于其他工具)\n\n### 安装步骤\n\n1. **安装 Foundry** (如果还没有安装):\n```bash\ncurl -L https://foundry.paradigm.xyz | bash\nfoundryup\n```\n\n2. **安装依赖**:\n```bash\nforge install OpenZeppelin/openzeppelin-contracts --no-commit\n```\n\n3. **编译合约**:\n```bash\nforge build\n```\n\n4. **运行测试**:\n```bash\nforge test\n```\n\n5. **运行测试并显示详细输出**:\n```bash\nforge test -vvv\n```\n\n## 使用说明\n\n### 部署合约\n\n1. 创建 `.env` 文件并设置私钥:\n```\nPRIVATE_KEY=your_private_key_here\n```\n\n2. 运行部署脚本:\n```bash\nforge script script/Deploy.s.sol:DeployScript --rpc-url \u003cRPC_URL\u003e --broadcast --verify\n```\n\n### 合约交互\n\n#### 质押 ETH\n```solidity\nstakingPool.stake{value: 1 ether}();\n```\n\n#### 赎回 ETH\n```solidity\nstakingPool.unstake(0.5 ether);\n```\n\n#### 领取奖励\n```solidity\nstakingPool.claim();\n```\n\n#### 查询质押余额\n```solidity\nuint256 balance = stakingPool.balanceOf(userAddress);\n```\n\n#### 查询待领取奖励\n```solidity\nuint256 earned = stakingPool.earned(userAddress);\n```\n\n## 测试\n\n运行所有测试:\n```bash\nforge test\n```\n\n运行特定测试:\n```bash\nforge test --match-test testStake\n```\n\n显示 gas 报告:\n```bash\nforge test --gas-report\n```\n\n## 合约接口\n\n### IStaking 接口\n\n```solidity\ninterface IStaking {\n    function stake() payable external;\n    function unstake(uint256 amount) external;\n    function claim() external;\n    function balanceOf(address account) external view returns (uint256);\n    function earned(address account) external view returns (uint256);\n}\n```\n\n### IToken 接口\n\n```solidity\ninterface IToken is IERC20 {\n    function mint(address to, uint256 amount) external;\n}\n```\n\n## 安全特性\n\n- ✅ 重入攻击保护 (ReentrancyGuard)\n- ✅ 访问控制 (Ownable)\n- ✅ 安全的 ETH 转账\n- ✅ 防止除零错误\n\n## 借贷市场集成 (加分项)\n\n合约支持将质押的 ETH 存入借贷市场赚取额外利息。要启用此功能：\n\n1. 部署或使用现有的借贷市场合约（实现 `ILendingPool` 接口）\n2. 调用 `setLendingPool(address)` 设置借贷市场地址\n3. 之后所有质押的 ETH 会自动存入借贷市场\n\n## 开发步骤总结\n\n1. ✅ 创建 Foundry 项目结构\n2. ✅ 实现 KK Token 合约\n3. ✅ 实现 StakingPool 核心功能 (stake, unstake, claim)\n4. ✅ 实现公平分配机制（基于质押时长和数量）\n5. ✅ 集成借贷市场功能（可选）\n6. ✅ 编写测试文件\n7. ✅ 创建部署脚本\n\n## 许可证\n\nMIT\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdavidweb3-ctrl%2Fstaking-mining","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdavidweb3-ctrl%2Fstaking-mining","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdavidweb3-ctrl%2Fstaking-mining/lists"}