{"id":20975109,"url":"https://github.com/0xheartcode/mzero-stacking-contract","last_synced_at":"2026-05-25T18:02:42.427Z","repository":{"id":233338998,"uuid":"772301791","full_name":"0xheartcode/Mzero-Stacking-Contract","owner":"0xheartcode","description":"Audited Stacking Contract for Metazero","archived":false,"fork":false,"pushed_at":"2025-05-19T11:08:33.000Z","size":9815,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-02-27T16:13:19.725Z","etag":null,"topics":["foundry","solidity","staking-contract"],"latest_commit_sha":null,"homepage":"","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/0xheartcode.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":"audits/ASSURE_DEFI_METAZERO_ADVANCED_04_11_24.pdf","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":"2024-03-14T23:24:11.000Z","updated_at":"2025-05-19T11:08:36.000Z","dependencies_parsed_at":"2024-11-19T04:55:56.123Z","dependency_job_id":null,"html_url":"https://github.com/0xheartcode/Mzero-Stacking-Contract","commit_stats":null,"previous_names":["0xheartcode/mzero-stacking-contract"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/0xheartcode/Mzero-Stacking-Contract","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/0xheartcode%2FMzero-Stacking-Contract","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/0xheartcode%2FMzero-Stacking-Contract/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/0xheartcode%2FMzero-Stacking-Contract/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/0xheartcode%2FMzero-Stacking-Contract/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/0xheartcode","download_url":"https://codeload.github.com/0xheartcode/Mzero-Stacking-Contract/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/0xheartcode%2FMzero-Stacking-Contract/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33486787,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-25T14:31:05.219Z","status":"ssl_error","status_checked_at":"2026-05-25T14:31:02.878Z","response_time":57,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["foundry","solidity","staking-contract"],"created_at":"2024-11-19T04:39:28.058Z","updated_at":"2026-05-25T18:02:42.410Z","avatar_url":"https://github.com/0xheartcode.png","language":"Solidity","funding_links":[],"categories":[],"sub_categories":[],"readme":"# MetaZero Staking Contract\n\nA highly optimized ERC20 token staking platform with time-locked unstaking, configurable fee mechanisms, and precise reward distribution. Built with Solidity using the Foundry development framework.\n\n![Staking Dashboard](./screenshots/stakedashboard.png)\n\n## Project Overview\n\nThis project implements a robust staking contract that allows users to:\n\n- Stake ERC20 tokens and earn rewards based on stake amount and duration\n- Earn proportional rewards calculated with mathematical precision\n- Initiate and complete unstaking with a configurable time-lock period\n- Pay an optional unstaking fee (configurable up to 2%)\n\nThe implementation features a sophisticated reward distribution system that efficiently handles multiple stakers while maintaining high precision and gas efficiency.\n\n## Technical Implementation\n\nThe project consists of two main contracts:\n\n- **BasicToken.sol**: A standard ERC20 token implementation that serves as both the staking and reward token\n- **StakingContract.sol**: The core staking mechanism with the following features:\n  - Two-step unstaking process (initiate + complete) with time-lock\n  - Linear reward emission over a configurable duration\n  - Precise reward calculation using accumulated \"reward per token\" approach\n  - Fee mechanism with admin configuration options\n  - Protection against precision loss and fund locking\n\n### Key Technical Features\n\n- **Reward Calculation**: Implements a mathematically sound reward distribution algorithm that guarantees fair allocation regardless of when users join or leave the staking pool\n- **Security Measures**: Uses OpenZeppelin's ReentrancyGuard to prevent reentrancy attacks\n- **Access Control**: Implements Ownable pattern for privileged functions\n- **Gas Optimization**: Carefully designed to minimize gas costs during staking and unstaking operations\n\n## Security and Audits\n\nThe contract has undergone rigorous security audits by two reputable firms:\n\n- **Assure DeFi Audit**: [View Report](https://github.com/Assure-DeFi/Audits/blob/main/METAZERO_ADVANCED_04_11_24.pdf)\n- **ThreeSigma Audit**: [View Report](https://github.com/threesigmaxyz/publications/blob/main/audits/metazero-2/MetazeroStakingAudit.pdf)\n\nThese audits verified the contract's security, mathematical correctness, and resistance to common attack vectors. One minor precision loss issue (approximately 1 wei per staker) was identified and deemed acceptable.\n\n## Testing\n\nThe contract includes comprehensive test coverage, addressing:\n\n- Basic staking functionality\n- Reward calculation accuracy\n- Unstaking mechanics and timelock enforcement\n- Multi-user interaction scenarios\n- Edge cases and potential attack vectors\n\n![Test Results](./screenshots/tests.png)\n\n### Running Tests\n\n```shell\n$ forge test\n```\n\n## Installation and Usage\n\n### Prerequisites\n\n- [Foundry](https://book.getfoundry.sh/getting-started/installation)\n- Ethereum wallet with testnet ETH (for deployment)\n\n### Build\n\n```shell\n$ forge build\n```\n\n### Deployment\n\n1. Add your wallet with the `cast` tool\n2. Create an `.env` file in the root directory:\n```\nSEPOLIA_RPC_URL=\nETH_RPC_URL=\nETHERSCAN_API_KEY=\n```\n3. Deploy the token:\n```shell\n$ forge create ./src/BasicToken.sol:BasicToken --account $USER\n```\n4. Deploy the staking contract:\n```shell\n$ forge create src/StakingContract.sol:StakingContract --constructor-args $TOKENADDRESS 1000000000000000000 1711202960 259200 --account $USER\n```\n5. Verify the contract:\n```shell\n$ forge verify-contract --chain-id 11155111 --watch $TOKENADDRESS ./src/StakingContract.sol:StakingContract --constructor-args $(cast abi-encode \"constructor(token,uint256,uint256,uint256)\" $DEPLOYEDADDRESS 1000000000000000000 1711202960 259200)\n```\n\n## Development Insights\n\nThe staking contract was initially designed as a simple staking pool but evolved to meet additional requirements. The complexity introduced by these new features was carefully managed to maintain security and efficiency. The contract demonstrates advanced Solidity patterns and precise mathematical implementation for reward distribution.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F0xheartcode%2Fmzero-stacking-contract","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F0xheartcode%2Fmzero-stacking-contract","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F0xheartcode%2Fmzero-stacking-contract/lists"}