TREZ Token Project: Referral Reward System

TREZ Token Project: Referral Reward System

Last updated: October 2025

The TREZ Token Project, built on Solana, includes a referral mechanism inside the mining contract (EUBkEwKJJnuenTnocaUHDZUaSegeWWZAFwBTqTRcQ1sJ) that pays 3 TREZ to the miner and 3 TREZ to the referrer whenever the miner submits a valid proof-of-work solution. This page explains how it works on-chain and how it integrates with the mining app (trez_miner.py) to provide transparency for both investors and miners.

Table of Contents

Overview of the Referral Reward System

The referral system incentivizes adoption by paying a fixed bonus to both parties when a miner’s claim_reward succeeds. It is fully on-chain, immutable once set, and enforced by the program logic to ensure fairness.

Key Components

  • MinerData PDA ([b"miner_data", user_pubkey]): stores the miner’s referrer public key set via set_referrer (one-time).
  • Distributor PDA ([b"distributor"]): authority that holds TREZ in its ATA for payouts.
  • claim_reward Instruction: validates PoW and pays the block reward + referral bonus.

Reward Distribution

  • When a miner finds a valid PoW:
    • The miner receives the current block reward.
    • If a referrer is set: the referrer receives 3 TREZ.
    • If no referrer is set: the miner receives an additional 3 TREZ.
  • Example: Alice (miner) sets Bob as referrer → Alice’s valid claim pays Alice the block reward and Bob 3 TREZ.

Implementation in the Mining Contract

The logic resides in programs/trez-mining/src/lib.rs (Anchor):

1) set_referrer

  • Purpose: lock a referrer on-chain (one-time).
  • Behavior: writes the referrer key to MinerData; subsequent attempts fail with ReferrerAlreadySet (e.g., code 6004).
  • Security: prevents self-referral; PDA derivation must match the miner; signer is required.

2) claim_reward

  • Purpose: verify PoW and distribute rewards including the referral bonus.
  • Behavior: pays block reward to miner_token, then:
    • If miner_data.referrer is set → transfer 3 TREZ to referrer_token.
    • Else → transfer 3 TREZ to miner_token.
  • Pseudocode:
// Inside claim_reward (Anchor, Rust)
if miner_data.referrer.is_some() {
    token::transfer(
        CpiContext::new(
            ctx.accounts.token_program.to_account_info(),
            token::Transfer {
                from: ctx.accounts.distributor_token.to_account_info(),
                to:   ctx.accounts.referrer_token.to_account_info(),
                authority: ctx.accounts.distributor_authority.to_account_info(),
            },
        ),
        3_000_000_000, // 3 TREZ (6 decimals)
    )?;
} else {
    token::transfer(
        CpiContext::new(
            ctx.accounts.token_program.to_account_info(),
            token::Transfer {
                from: ctx.accounts.distributor_token.to_account_info(),
                to:   ctx.accounts.miner_token.to_account_info(),
                authority: ctx.accounts.distributor_authority.to_account_info(),
            },
        ),
        3_000_000_000,
    )?;
}

Integration with the Mining Application

  • Set Referrer (_lock_referrer_onchain): calls set_referrer, validates input and SOL balance, then disables the field (🔒).
  • Claim Rewards (_mine_loop): mines nonces, submits claim_reward, and logs bonus routing (to referrer or miner).
  • Referral Count (_update_my_referral_count): counts MinerData with your key set as referrer for live stats.
  • UX: clear logs (e.g., “🎉 Nonce found!”, “🟢 Confirmed”), priority fees for reliable confirmation, and safety checks for ATAs/SOL.

Security & Transparency Features

  • Immutable Referrer: one-time lock prevents tampering; UI mirrors this by disabling edits.
  • On-Chain Verification: bonuses only pay on valid PoW; all transfers are visible on explorers.
  • Fair Distribution: 3 TREZ to referrer when set; otherwise, miner receives the bonus—no funds lost.
  • Program-Owned Funds: bonuses come from the distributor’s PDA-controlled ATA, transferable only via program instructions.
  • Auditable Code: referral logic in lib.rs and app flows in trez_miner.py are open for review.

Example Workflow

  1. Miner Setup: create/fund wallet, enter referrer, click “Lock Referrer” → UI shows 🔒 locked.
  2. Mining: start mining; when a nonce meets difficulty, the app submits claim_reward.
  3. Payout: miner receives block reward; referrer gets 3 TREZ (or miner gets the +3 TREZ if no referrer).
  4. Tracking: referrer count and balances update in the app; transactions visible on explorers.

Assurance for Investors and Miners

  • Fixed Bonus: 3 TREZ is hard-coded in the program.
  • Locked Mechanism: referrer is immutable; payouts require valid claims.
  • Transparent: events and token transfers are on-chain and queryable.
  • Reliable App: wallet protections, clear errors, and verifiable logs.

Verification Steps

  • Check Referrer: open the miner’s MinerData PDA ([b"miner_data", miner_pubkey]) on a Solana explorer.
  • Verify Bonus: inspect claim_reward transactions for a 3 TREZ transfer to the referrer’s ATA (or miner’s ATA if none set).
  • Test the App: run trez_miner.py, set a referrer, mine, and confirm UI + on-chain results.
  • Audit Logic: review set_referrer/claim_reward in lib.rs and flows in trez_miner.py.

Informational only; not financial advice. Always confirm program IDs and account addresses before interacting on-chain.