feat: refund-deposit script for manual EVM deposit forwarding#3671
Open
TaprootFreak wants to merge 2 commits intodevelopfrom
Open
feat: refund-deposit script for manual EVM deposit forwarding#3671TaprootFreak wants to merge 2 commits intodevelopfrom
TaprootFreak wants to merge 2 commits intodevelopfrom
Conversation
Bootstraps the NestJS application context and uses the existing BlockchainRegistryService + EvmClient to derive the deposit wallet (EVM_DEPOSIT_SEED + accountIndex) and forward a chosen asset to a chosen recipient. Recipient can be derived from a deposit transaction (sender of that tx). Default behaviour is dry-run; --execute broadcasts. Supports all configured EVM chains. Sweep via --amount all subtracts the estimated fee for native, full balance for tokens.
Address review findings — full professional pass: * Extract pure logic (CLI parsing, validation, sweep math, chain config) into src/scripts/refund-deposit.util.ts for testability and consistency with the rest of the TypeScript codebase. * Add comprehensive unit tests (src/scripts/__tests__/refund-deposit.util.spec.ts, 20 cases) covering parseArgs, validateArgs, computeNativeSweepAmount and the chain/explorer mappings. Bug fixes: * Token-lookup case-sensitivity: normalise contract addresses to lowercase before getAssetByChainId — asset.chainId is stored lowercase in the DB while operators typically paste a checksum address from a block-explorer. * Native sweep estimateGas: probe with value=0 instead of value=balance, so providers that reject estimateGas with insufficient-funds-for-value don't fail the dry-run. * Native sweep safety buffer: reserve fee * SWEEP_FEE_SAFETY_FACTOR (1.05) instead of bare fee, so small gas-price drift between dry-run and execute does not cause an in-flight "insufficient funds" failure. * Token transfer gas check: estimate the actual transfer-call fee and reject the dry-run if it exceeds the native balance — previously a zero-balance native account would dry-run green and fail at execute. * parseArgs: reject unknown flags and positional arguments fail-loud instead of silently ignoring them (catches typos like '--chian'). * Drop pauschales /* eslint-disable */; scripts/*.js are already ignored by eslint config.
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
scripts/refund-deposit.jslets an operator manually forward funds from a DFX EVM deposit address to any recipient (e.g. back to the original sender of a stuck deposit)BlockchainRegistryService.getEvmClient(blockchain)for the right clientEvmClient.sendNativeCoinFromAccount/sendTokenFromAccountfor the actual sendEvmUtil.createWallet+GetConfig().blockchain.evm.walletAccountfor wallet derivationAssetService.getNativeAsset/getAssetByChainIdfor asset entitiesBehaviour
--executeis required to broadcast--amount allto sweep (native: balance − fee; token: full balance)--to <addr>or--to-sender-of <txHash>(looks uptx.from)--helpand input errors stay sub-100msUse case
Stuck deposits (unsupported asset, failed routing) sit on the deposit address with no automated path back. This gives operations a safe, auditable way to forward them without exporting the private key.
Usage
Run from inside the api container on prd (Azure App Service via
az webapp ssh) — the seed env var lives there.Test plan
node scripts/refund-deposit.js --helpprints usage instantly (no NestJS bootstrap)--to/--to-sender-of, invalid recipient addressdeposit.addressin DB), correct recipient (sender of referenced tx), correct balance and gas estimate--executebroadcasts and the tx confirms on-chain