Skip to content

Shubhojit-17/Zero-G_Unstake

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

11 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸš€ Zero-G Unstake

The Gasless Emergency Exit

Unstake your tokens with zero BNB in your wallet. Powered by EIP-7702 Account Abstraction on BSC.


πŸ† BSC Hackathon 2025 β€” EIP-7702 Track

Zero-G Unstake is a novel rescue protocol that enables users to exit staking positions even when they have absolutely no native gas tokens (BNB) in their wallet. By leveraging EIP-7702's temporary EOA delegation, users can pay for gas using the very tokens they're unstaking.


πŸ“‹ Table of Contents


❌ The Problem

The "Out of Gas" Trap

Imagine this scenario:

  1. βœ… You staked 1,000 USDT into a yield vault 30 days ago
  2. βœ… The lock period has expired β€” your tokens are ready to withdraw
  3. ❌ Your wallet has 0 BNB β€” you cannot pay gas fees
  4. 😰 You're stuck. Your valuable assets are locked, visible but unreachable.

This is a critical UX failure in DeFi:

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                                                                 β”‚
β”‚   πŸ’° Your Wallet                                                β”‚
β”‚   β”œβ”€β”€ BNB Balance:    0.000 BNB                                 β”‚
β”‚   └── Staked USDT:    1,000 USDT (Ready to Unstake!)            β”‚
β”‚                                                                 β”‚
β”‚   β›½ Gas Required:     0.001 BNB (~$0.60)                        β”‚
β”‚                                                                 β”‚
β”‚   ❌ RESULT: Cannot unstake. Assets trapped.                    β”‚
β”‚                                                                 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Current workarounds are painful:

  • πŸ”„ Ask a friend to send you BNB (trust + coordination required)
  • πŸ’± Use a CEX to buy and withdraw BNB (KYC, fees, delays)
  • πŸŒ‰ Bridge from another chain (complex, risky, slow)

There has to be a better way.


βœ… The Solution

EIP-7702: Rescue-7702 Protocol

Zero-G Unstake introduces a paradigm shift using EIP-7702's account delegation:

"What if your EOA could temporarily become a smart account, unstake your tokens, and pay gas from the unstaked amount β€” all in one atomic transaction?"

The Magic of EIP-7702

EIP-7702 allows an Externally Owned Account (EOA) to temporarily delegate its execution logic to a smart contract. This means:

  • πŸ” Your keys, your control β€” Only you can authorize the delegation
  • ⚑ Temporary upgrade β€” Your EOA "borrows" smart contract capabilities
  • πŸ”„ Atomic execution β€” Unstake + gas payment happens in one transaction
  • πŸ’Έ Pay with what you have β€” Use your staked tokens to cover gas fees

πŸ”§ How It Works

Step-by-Step Rescue Flow

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                                                                          β”‚
β”‚  STEP 1: User Authorization (Off-Chain)                                  β”‚
β”‚  ═══════════════════════════════════════                                 β”‚
β”‚                                                                          β”‚
β”‚  User signs an EIP-7702 authorization payload:                           β”‚
β”‚  β€’ Delegates EOA logic β†’ UnstakeDelegate contract                        β”‚
β”‚  β€’ Specifies: vault address, token, expected amount                      β”‚
β”‚  β€’ NO gas required β€” this is just a signature!                           β”‚
β”‚                                                                          β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                                                                          β”‚
β”‚  STEP 2: Relayer Submission (On-Chain)                                   β”‚
β”‚  ═══════════════════════════════════════                                 β”‚
β”‚                                                                          β”‚
β”‚  A Relayer bot picks up the authorization:                               β”‚
β”‚  β€’ Bundles the EIP-7702 auth into a transaction                          β”‚
β”‚  β€’ Pays the BNB gas fee upfront                                          β”‚
β”‚  β€’ Submits to BSC Testnet                                                β”‚
β”‚                                                                          β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                                                                          β”‚
β”‚  STEP 3: Atomic Execution (On-Chain)                                     β”‚
β”‚  ════════════════════════════════════                                    β”‚
β”‚                                                                          β”‚
β”‚  The UnstakeDelegate logic executes FROM the user's EOA:                 β”‚
β”‚                                                                          β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”         β”‚
β”‚  β”‚ 1. Call vault.unstake() ──────────────► Tokens released     β”‚         β”‚
β”‚  β”‚ 2. Receive ERC20 tokens ──────────────► Into user's EOA     β”‚         β”‚
β”‚  β”‚ 3. Calculate gas cost + fee ──────────► e.g., 5 USDT        β”‚         β”‚
β”‚  β”‚ 4. Transfer fee to Relayer ───────────► Relayer reimbursed  β”‚         β”‚
β”‚  β”‚ 5. Keep remaining tokens ─────────────► User's wallet       β”‚         β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜         β”‚
β”‚                                                                          β”‚
β”‚  ALL STEPS ARE ATOMIC β€” If any step fails, everything reverts!           β”‚
β”‚                                                                          β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

The Result

Before After
0 BNB 0 BNB (unchanged)
1,000 USDT (staked) 995 USDT (in wallet)
❌ Trapped βœ… Free!

The user paid ~5 USDT (gas + fee) and rescued 995 USDT β€” without ever holding BNB.


πŸ—οΈ Architecture Flow

                                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                                    β”‚   BSC TESTNET   β”‚
                                    β”‚   BLOCKCHAIN    β”‚
                                    β””β”€β”€β”€β”€β”€β”€β”€β”€β–²β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                             β”‚
                                             β”‚ 3. Submit Tx
                                             β”‚    (Pays Gas)
                                             β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   1. Sign Auth    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚              β”‚ ────────────────► β”‚                   β”‚
β”‚     USER     β”‚   (Off-Chain)     β”‚     RELAYER       β”‚
β”‚   (0 BNB)    β”‚                   β”‚      (Bot)        β”‚
β”‚              β”‚ ◄──────────────── β”‚                   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   6. Success!     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
       β”‚                                     β”‚
       β”‚                                     β”‚
       β–Ό                                     β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                        ON-CHAIN EXECUTION                    β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
β”‚  β”‚                   User's EOA                           β”‚  β”‚
β”‚  β”‚            (Temporarily Upgraded via 7702)             β”‚  β”‚
β”‚  β”‚                         β”‚                              β”‚  β”‚
β”‚  β”‚    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”         β”‚  β”‚
β”‚  β”‚    β”‚         UnstakeDelegate Logic           β”‚         β”‚  β”‚
β”‚  β”‚    β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚         β”‚  β”‚
β”‚  β”‚    β”‚  β”‚  unstake() │───►│ Transfer Tokens β”‚  β”‚         β”‚  β”‚
β”‚  β”‚    β”‚  β”‚  from Vaultβ”‚    β”‚ (User + Relayer)β”‚  β”‚         β”‚  β”‚
β”‚  β”‚    β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚         β”‚  β”‚
β”‚  β”‚    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜         β”‚  β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
β”‚                              β”‚                               β”‚
β”‚              β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”               β”‚
β”‚              β–Ό                               β–Ό               β”‚
β”‚     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”             β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”      β”‚
β”‚     β”‚   Staking Vault β”‚             β”‚   ERC20 Token   β”‚      β”‚
β”‚     β”‚   (Releases $)  β”‚             β”‚   (USDT/etc)    β”‚      β”‚
β”‚     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜             β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜      β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

⭐ Key Features

πŸ”„ Atomic Execution

Every step β€” from unstaking to relayer reimbursement β€” happens in a single, atomic transaction. If any part fails, the entire operation reverts. Your funds are never at risk of being partially processed.

⏱️ No Cool-Down Required

Unlike traditional meta-transaction solutions that require pre-setup or session keys, Zero-G Unstake works instantly. Sign once, rescue immediately.

β›½ True Gas Abstraction

Users don't just "defer" gas payment β€” they pay with a different asset entirely. No BNB needed, ever. The gas cost is deducted from the unstaked tokens.

πŸ” Non-Custodial & Trustless

  • Private keys never leave the user's device
  • The Relayer cannot steal funds (atomic execution ensures fair reimbursement)
  • EIP-7702 delegation is temporary and scoped

πŸ’± Automatic Fee Calculation

The delegate contract calculates the real-time gas cost (in BNB) and converts it to the equivalent token amount plus a small service fee. Transparent and fair.

🌐 BSC Testnet Ready

Built and tested on BSC Testnet with full EIP-7702 support. Ready for mainnet deployment post-audit.


πŸ“œ Smart Contracts

Contract Description
MockERC20.sol Test token for simulating staked assets
StakingVault.sol Simple time-locked staking vault
UnstakeDelegate.sol Core EIP-7702 delegate logic for rescue operations
Relayer.sol (Optional) On-chain relayer registry and fee management

πŸš€ Getting Started

Prerequisites

  • Foundry installed
  • Node.js v18+ (for Viem scripts)
  • BSC Testnet BNB (for relayer operations)

Installation

# Clone the repository
git clone https://github.com/your-team/zero-g-unstake.git
cd zero-g-unstake

# Install Foundry dependencies
forge install

# Install Node.js dependencies
npm install

Build & Test

# Compile contracts
forge build

# Run tests
forge test -vvv

# Deploy to BSC Testnet
forge script script/Deploy.s.sol --rpc-url $BSC_TESTNET_RPC --broadcast

Run the Relayer

# Start the relayer bot
npx ts-node scripts/relayer.ts

πŸ›£οΈ Features & Roadmap

βœ… Core Features (Complete)

  • Core concept & architecture design
  • Smart contract implementation (ZeroGToken, StakingVault, UnstakeDelegate)
  • Comprehensive Foundry test suite (14 tests passing)
  • Viem-based relayer with EIP-7702 support
  • Sepolia Testnet deployment & demo

βœ… Bonus Features (Complete)

  • MEV-Safe Execution - Transactions routed through Flashbots/MEV Blocker
  • Auto-Unstake Bot - Monitors users and auto-rescues when lock expires
  • One-Click Frontend - React/Next.js UI with ConnectKit wallet integration

πŸš€ Quick Start

Prerequisites

  • Foundry installed
  • Node.js v18+ (for Viem scripts)
  • Sepolia Testnet ETH (for relayer operations)

Installation

# Clone the repository
git clone https://github.com/Shubhojit-17/Zero-G_Unstake.git
cd Zero-G_Unstake

# Install Foundry dependencies
forge install

# Install Node.js dependencies
npm install

Build & Test

# Compile contracts
forge build

# Run tests
forge test -vvv

Run Demo

# Copy and configure environment
cp .env.example .env
# Edit .env with your keys

# Run the full demo
npx tsx scripts/demo.ts

Start Frontend

cd frontend
npm install
npm run dev

Start Auto-Unstake Bot

# Register users for auto-rescue
npx tsx scripts/autoUnstakeBot.ts register <user-address>

# Start the bot
npx tsx scripts/autoUnstakeBot.ts start

πŸ“¦ Deployed Contracts (Sepolia)

Contract Address
ZeroGToken 0xACDca6c55F4CBA946763413854341b9E5556212A
StakingVault 0x5085d1DD5FbDA9166094C3a3dc41dea7Df8fD9e7
UnstakeDelegate 0x8ca2A267D31989FE05111cd46326AFA6971607AF

🀝 Team

Built with ❀️ for the BSC EIP-7702 Hackathon 2025


πŸ“„ License

MIT License β€” See LICENSE for details.


Zero-G Unstake β€” Because your tokens shouldn't be held hostage by gas fees.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors