feat: full TSS recovery flow for the Tempo chain (TIP-20 / EIP-7702#8741
Open
bhavesh-prasad wants to merge 3 commits into
Open
feat: full TSS recovery flow for the Tempo chain (TIP-20 / EIP-7702#8741bhavesh-prasad wants to merge 3 commits into
bhavesh-prasad wants to merge 3 commits into
Conversation
cfd5179 to
f1ccfe6
Compare
Signed-off-by: B.Prasad <bhaveshprasad584@bitgo.com> TICKET: CECHO-917 Signed-off-by: B.Prasad <bhaveshprasad584@bitgo.com>
nvrakesh06
reviewed
May 14, 2026
nvrakesh06
requested changes
May 14, 2026
nvrakesh06
reviewed
May 14, 2026
Contributor
nvrakesh06
left a comment
There was a problem hiding this comment.
Fee estimation — two cases
Case A — swept token == fee token ✅ handled
When sweeping pathUSD (the fee token), the gas cost is correctly reserved before sweeping:
const sweepAmount = isPathUsd ? balance - gasMarginUnits : balance;
if (sweepAmount <= 0n) { throw ... }The function throws early if the balance doesn't cover the fee, so the wallet is never left unable to pay.
Case B — swept token != fee token ❌ not handled
When sweeping a different TIP-20 (e.g. tempo:usdc), the full token balance is swept but the fee token balance is never checked. If the wallet has no pathUSD, the transaction will be submitted and fail on-chain silently.
The same guard from Case A needs to be applied to the fee token balance here:
if (feeTokenAddress.toLowerCase() !== tokenAddress.toLowerCase()) {
const feeTokenRaw = await this.queryAddressTokenBalance(feeTokenAddress, walletAddress, params.apiKey);
if (BigInt(feeTokenRaw.toString()) < gasMarginUnits) {
throw new Error(
`Insufficient fee token balance in ${feeTokenAddress}: ` +
`have ${feeTokenRaw} units, need at least ${gasMarginUnits} units for gas`
);
}
}…% gas buffer TEST_BACKUP_KEY updated to a full 130-char commonKeyChain (pubkey + chaincode) since buildUnsignedSweepTxnTSS now calls MPC.deriveUnhardened which requires both components. Test 2 balance raised from 15_000 to 50_000 to account for the 75% gas margin buffer raising the minimum required balance to 17_500. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> TICKET: CECHO-917 Signed-off-by: B.Prasad <bhaveshprasad584@bitgo.com>
nvrakesh06
approved these changes
May 14, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements the full TSS recovery flow for the Tempo chain (TIP-20 / EIP-7702).
What was there before
buildUnsignedSweepTxnTSSandrecoveryBlockchainExplorerQuerywere stubs returning empty/dummy objectsWhat this PR adds
Recovery infrastructure (
tempo.ts)recoveryBlockchainExplorerQuery— routes Etherscan-style queries to Tempo's Alchemy JSON-RPC endpoint (configured viaenvironments.ts)queryTempoRpc— translatesaccount/balance,account/tokenbalance, andaccount/txlistqueries intoeth_call/eth_getTransactionCountJSON-RPC callsbuildTempoSweepTx— shared helper that queries token balance, computes sweep amount, and builds an unsigned TIP-20 transfer transaction; used by both recovery pathsrecoverTSS— overrides base-class recovery with two paths:buildUnsignedSweepTxnTSSbuildUnsignedSweepTxnTSS— builds an unsigned TIP-20 sweep and returns theUnsignedSweepTxMPCv2structure for offline vault signingDynamic gas margin
GAS_MARGIN_UNITS = 20_000nconstantgasMarginUnits = gasLimit × maxFeePerGas / 10^12gasLimit × gasPricepattern used across all ETH-like coin recovery flows inabstract-eth; the/10^12factor converts from wei scale (18 decimals) to pathUSD's TIP-20 units (6 decimals)Environment config (
environments.ts)evmconfig entry sorecoveryBlockchainExplorerQuerycan resolve the RPC URL and API token