Skip to content

Add TransparentStaking: audited-pattern rewrite of the reviewed staking contract - #2

Draft
Rezamoradifar wants to merge 2 commits into
mainfrom
claude/new-project-1gpy93
Draft

Add TransparentStaking: audited-pattern rewrite of the reviewed staking contract#2
Rezamoradifar wants to merge 2 commits into
mainfrom
claude/new-project-1gpy93

Conversation

@Rezamoradifar

Copy link
Copy Markdown
Owner

Summary

Adds contracts/TransparentStaking.sol, a from-scratch rewrite of the previously reviewed "ArbiSmart" staking contract, designed to be transparent, auditable, and free of the issues found in the original:

  • No hidden withdrawal path. The original's polymarketArbitrageTrade let the owner pull 20% of the contract's balance directly, disguised with "arbitrage" event names but with no actual trading logic. Removed entirely.
  • No Ponzi economics. Every stake's promised reward is checked against a pre-funded rewardReserve at stake time (pendingRewardObligation invariant: rewardReserve >= pendingRewardObligation). If the reserve can't cover the promise, the stake reverts. Rewards can never be paid out of new depositors' principal.
  • No partner-only emergency sweep. The original's emergencyMode/executeEmergency split all remaining funds among 4 "partner" addresses, leaving depositors with nothing. Removed; replaced with a pause() that only blocks new stakes and never blocks claim()/withdraw().
  • No blacklist, no tx.origin EOA gate. Both were centralization/compatibility footguns; removed.
  • No multi-level MLM referral tree. Replaced with an optional, capped (max 5%, immutable), single-level referral bonus paid from a dedicated, permissionlessly-fundable referralReserve.
  • Bounded owner powers, enforced on-chain, not just by convention:
    • withdrawExcessRewardReserve / withdrawExcessReferralReserve can only move funds not currently backing a live promise — the ceiling is computed on-chain (rewardReserve - pendingRewardObligation), so the owner cannot touch principal or promised rewards.
    • Plan terms (duration, total rate, min/max stake) are immutable once created; the owner can only disable a plan for future stakes.
    • Fees (claimFeeBps, maxEarlyExitFeeBps, referralBps) are immutable and hard-capped in the constructor (10% / 15% / 5% respectively), so they can never be raised post-launch.
  • Fair, transparent early exit. Early-exit fee applies only to principal and decays linearly to 0 at maturity (max 15%); reward already accrued up to the moment of exit is still paid — only the unearned future portion is forfeited. No 50% cliff-edge penalties like the original.
  • Uses OpenZeppelin's SafeERC20, ReentrancyGuard, Pausable, and Ownable2Step instead of hand-rolled equivalents.

This file is a reference implementation for compilation/audit with a standard toolchain (Hardhat/Foundry) and the @openzeppelin/contracts package — this repo currently has no Solidity build pipeline (the existing contracts/ directory only holds ABI TypeScript files consumed by the frontend), so no build config was added.

Test plan

  • Compile with @openzeppelin/contracts v5.x under Hardhat or Foundry
  • Unit tests: stake/claim/withdraw happy path, insufficient-reserve revert, early-exit fee decay, referral payout, withdrawExcessRewardReserve ceiling enforcement, pause blocking only new stakes
  • Independent security audit before any mainnet deployment

Generated by Claude Code

Replaces the Ponzi-style economics and hidden owner-withdrawal path from
the reviewed ArbiSmart contract with a fully collateralized model:

- Every stake's promised reward must be backed by a pre-funded
  rewardReserve before the stake is accepted (pendingRewardObligation
  invariant), so rewards can never be paid from new depositors' funds.
- Removed the fake "polymarketArbitrageTrade" owner withdrawal path,
  the partner-only emergency fund sweep, the blacklist, the tx.origin
  EOA gate, and the multi-level MLM referral structure.
- Owner powers are now bounded on-chain: pause() only blocks new
  stakes (never claims/withdrawals), and reserve withdrawals are
  capped to the mathematically unencumbered excess.
- Plan terms are immutable once created; fees are immutable and
  hard-capped at deploy time.
- Uses OpenZeppelin SafeERC20/ReentrancyGuard/Pausable/Ownable2Step.
@Rezamoradifar

Rezamoradifar commented Jul 20, 2026

Copy link
Copy Markdown
Owner Author

Deploy Preview for playful-starship-836a94 failed.

Name Link
🔨 Latest commit b06e9ca
🔍 Latest deploy log https://app.netlify.com/projects/playful-starship-836a94/deploys/6a5e26714377ba0008e8324d

@netlify

netlify Bot commented Jul 20, 2026

Copy link
Copy Markdown

Deploy Preview for euphonious-biscotti-e90450 ready!

Name Link
🔨 Latest commit b06e9ca
🔍 Latest deploy log https://app.netlify.com/projects/euphonious-biscotti-e90450/deploys/6a5e2672c951310008a429aa
😎 Deploy Preview https://deploy-preview-2--euphonious-biscotti-e90450.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Adds a disaster-recovery mechanism that mirrors the original contract's
partner-vote idea but removes its fatal flaw: the emergency destination
is a single address fixed at deploy time (emergencyRecipient), never the
council members themselves, so a colluding majority cannot vote the funds
to themselves. The 10 council seats are set once in the constructor with
no add/remove function, so membership can never be repacked later either.

Flow: 6-of-10 council votes -> contract pauses new stakes (claim/withdraw
stay open) -> 72h timelock -> anyone can execute the sweep to
emergencyRecipient. Cancelling a pending vote also requires 6-of-10, so
neither the owner nor a single member can unilaterally start or stop it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants