About the Project Inspiration
In the realm of DeFi, staking is an essential element; however, it comes with one major negative aspect: friction in the unstaking process. Users experience a cooling-off period and therefore must manually send a later transaction to unstake their assets. I was excited about the possibilities of the new Ethereum set of standards that would help people think about this experience in its entirety. I wanted to create a system that was not only faster but truly instantaneous, relieving the user from having to take action at the moment of execution.
What It Does
Instant Unstake is a fully automated system that enables the user to unlock their staked assets at the exact moment their time lock expires.
Here’s the sequence:
The user locks their own ERC20 tokens into the InstantStaking7702 contract, which imposes a 3600-second (1-hour) lock.
This action immediately results in the creation of a pre-signed transaction. This one-of-a-kind transaction enables the EIP7702Executor contract to perform the unstake on the user’s behalf.
A Go-based automation bot watches the blockchain for newly mined blocks.
As soon as the block timestamp is greater than or equal to the stakeUnlockTimestamp, the pre-signed transaction is broadcast.
Tokens are transferred back to the user’s wallet instantly, creating a seamless, “fire-and-forget” unstaking experience.
How I Built It
The project consists of two main parts: on-chain smart contracts and an off-chain automation bot.
Smart Contracts: Written in Solidity and implemented using the Hardhat development environment.
InstantStaking7702.sol: The main staking contract that holds the user’s tokens and implements the unstake logic. The contract utilizes EIP-7702 principles by validating the code hash of the caller to ensure that only the authorized executor can perform the unstake.
TestToken.sol: A simple OpenZeppelin ERC20 contract used for demonstration.
EIP7702Executor.sol: A smart contract wallet authorized by the user to execute the unstake action.
Scripts & Automation:
Hardhat scripts were used to handle deployment, staking, and the generation of EIP-7702 pre-signed transactions.
The automation bot was developed in Go (Golang) using go-ethereum, go-fuzz, and package fuzzing tools. It subscribes to new blockchain headers via a WebSocket connection. This involves establishing a persistent connection and submitting the transaction at the correct time.
Challenges I Encountered
Working with cutting-edge technology came with its own set of challenges.
Library Compatibility: EIP-7702 is a new standard, and I encountered several versioning issues across JavaScript and Go libraries. I worked through breaking changes in ethers.js v6, Viem, and go-ethereum to ensure they worked together seamlessly.
Secure Authorization: Designing a secure authorization mechanism was a top priority. I implemented a code hash check within the staking contract to ensure that, even though the executor is authorized, only the exact verified code I deployed can perform the unstake. This prevents malicious contracts from mimicking the call.
Timing Is Everything: Creating a trusted bot that executes transactions at an exact timestamp is non-trivial. The bot had to handle potential RPC connection drops and re-verify on-chain state immediately before sending the transaction to prevent errors or replayed transactions.
What I Am Proud Of
I am extremely proud of building a fully functional, end-to-end system that addresses a specific DeFi UX problem. I successfully implemented EIP-7702 to delegate execution to a self-operating system, and watching the bot execute the transaction at the exact intended moment was a major achievement.
What I Learned
This project took me deep into several advanced blockchain topics, including how to implement EIP-7702 in practice, the importance of secure and stateless smart contract design, and the subtleties of building reliable off-chain computation systems that interact with on-chain logic.
The Future of Instant Unstake
The applications of this system are extensive. Future development phases could include:
Building a user-friendly UI that makes staking and pre-signed transaction generation a one-click process.
Generalizing the bot and executor contracts to support existing staking platforms.
Log in or sign up for Devpost to join the conversation.