A Helper Contract to Facilitate Undelegating ZRX
December 1st, 2024

ZRX stakers are encountering problems when preparing their staked ZRX for withdrawal. This issue primarily affects users connecting to the 0x portal via MetaMask with a hardware wallet. A common problem arises from the need to correctly encode two sets of tuple parameters for the moveStake function, which is necessary to undelegate stake and prepare it for withdrawal at the next epoch. Many users, including those using Etherscan or certain hardware wallets, have found this encoding process challenging, leading to errors and failed transactions. The root of the problem is not entirely clear, but it seems related to an upgraded Web3 library used by wallet providers and MetaMask.

Our Solution: The TupleFixer Contract

To address this, we have engineered the TupleFixer Contract, designed to simplify the process of undelegating ZRX stakes:

  • Non-Upgradable and Open Source: The contract is immutable and its source code is publicly verified, ensuring transparency and trust.

  • ZRX Staking Proxy Integration: The address of the ZRX Staking Proxy is hardcoded in the bytecode as a constant, ensuring that the contract always interacts with the correct staking contract.

How It Works:

Encoding Calldata:

  1. Browse toEtherscan for TupleFixer.

  2. Connect Your Wallet: Use the "Connect to Web3" button.

  3. Select Method: Choose 4. encodeUndelegateAll.

  4. Query the Contract: Click "Query" to retrieve the encoded calldata necessary for undelegating. This will also return the total amount that will be undelegated.

  5. use the returned encodedCalls and totalUndelegatedAmount for the next phases.

Executing the Calls:

  1. Browse toEtherscan ZRX Staking Proxy Contract.

  2. Connect Wallet: Connect via "Connect to Web3"

  3. Use batchExecute: Select method 3. batchExecute.

  4. Input Calldata: Paste the encodedCalls from TupleFixer into the data field, ensuring to wrap in brackets [] your comma-separated calls. Example [<calldata1>, <calldata2>, <anyOtherCalldata>] for multiple calls, [<calldata>] if the previous call’s output is a single bytes array.

  5. Click the Write Button: this will prompt a transaction confirmation in your wallet. Ensure you are interacting with the intended address: the ZRX Staking Proxy linked here.

Important Notes:

  • Post-Undelegation: After undelegating, a staker must wait for the next epoch (every 7 days) to withdraw their stake via Etherscan.

  • Selective Undelegation: The contract only provides calldata for pools where stake is still delegated and not yet undelegated this epoch.

Contract Details:

The TupleFixer contract exposes (among others) the following functionality:

function encodeUndelegateAll() external view returns (uint256 totalUndelegatedAmount, bytes[] memory encodedCalls)

This function loops through all possible pool IDs (up to the hardcoded _LAST_POOL_ID, designed to prevent DDOS via number of created pools inflation) to find where the user has staked ZRX, calculating the total amount to undelegate and encoding the necessary calls.

Conclusion:

The TupleFixer contract by Rigoblock offers a straightforward solution for ZRX stakers facing encoding issues. By automating the creation of the required transaction data, it reduces user error and enhances the unstaking experience.

IMPORTANT NOTICE: after undelegating stake, you will have to wait until the next epoch (maximum 7 days at current parameters) to withdraw your stake. Once the new epoch starts, if you are not able to withdraw your stake through the 0x portal, you will need to follow these steps to successfully withdraw your stake:

  1. Browse toEtherscan for Staking Proxy Contract. Note: unlike previous interactions with the ZRX staking proxy, we will use the Write as Proxy tab, which this link directs to.

  2. Connect Your Wallet: Use the "Connect to Web3" button.

  3. Select Method: Choose 17. unstake.

  4. Add the Amount: Use the previously retrieved totalUndelegatedAmount. Alternatively, add your staked ZRX units and use the + button to append the necessary 18 zeroes.

  5. Click the Write Button: this will prompt a transaction confirmation in your wallet. Ensure you are interacting with the intended address: the ZRX Staking Proxy linked here. This transaction will withdraw your ZRX to your wallet, thus completing the unstake process.

References:

[TupleFixer publicly verified code]

Subscribe to Rigoblock
Receive the latest updates directly to your inbox.
Nft graphic
Mint this entry as an NFT to add it to your collection.
Verification
This entry has been permanently stored onchain and signed by its creator.
More from Rigoblock

Skeleton

Skeleton

Skeleton