feat(cli): add simulate command for testing RBTC and ERC20 transfers …#288
Conversation
…with gas estimation, balance validation, cost analysis, and formatted result output
…nsaction-simulation
scguaquetam
left a comment
There was a problem hiding this comment.
Please follow accordingly to current standard.
src/commands/simulate.ts
Outdated
| error?: string; | ||
| } | ||
|
|
||
| function logInfo(message: string) { |
There was a problem hiding this comment.
This is wrong implemented, in order for this feature of CLI to be used in the MCP Server, we need normalize the usage of console chalk and spinner, in a external/nonexternal basis, for that please refer to other existing commands and check how they use this, for example THIS where we use logMessage and startSpinner, succeedSpinner, etc.
There was a problem hiding this comment.
Thanks for the feedback. I've refactored simulate.ts to follow the standard pattern used in other commands
src/commands/simulate.ts
Outdated
| const balanceAfterTransfer = currentTokenBalance - transferAmount; | ||
| const networkName = isTestnet ? "Rootstock Testnet" : "Rootstock Mainnet"; | ||
|
|
||
| console.log("\n" + chalk.cyan("📊 SIMULATION RESULTS") + "\n"); |
src/commands/simulate.ts
Outdated
| ] | ||
| }); | ||
| console.log(simulationTable); | ||
|
|
…rnal, switching to logMessage/logInfo/logError, simplifying function signatures, removing unused helpers, standardizing CLI vs external context handling, and cleaning up duplicate code
bin/index.ts
Outdated
| }); | ||
|
|
||
| program.parse(process.argv); | ||
| program.parse(process.argv); |
There was a problem hiding this comment.
you have this repeated here
src/commands/simulate.ts
Outdated
| error?: string; | ||
| } | ||
|
|
||
| function logMessage( |
There was a problem hiding this comment.
In other PR you have implemented an improvement here with this management, is it okay if you do it here also?
|
Heyy.. I’ve made the necessary changes. Is there a chance this could be
approved and included in the December 15th disbursement batch?
…On Fri, Dec 12, 2025, 11:17 AM Sebas ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In src/commands/simulate.ts
<#288 (comment)>:
> + balances: {
+ currentBalance: string;
+ balanceAfterTransfer: string;
+ balanceAfterGas: string;
+ tokenSymbol: string;
+ };
+ validation: {
+ sufficientBalance: boolean;
+ sufficientGas: boolean;
+ validTransaction: boolean;
+ };
+ };
+ error?: string;
+}
+
+function logMessage(
In other PR you have implemented an improvement here with this management,
is it okay if you do it here also?
—
Reply to this email directly, view it on GitHub
<#288 (review)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/A7QZ75ITV4GUBYSPH747CTT4BKI2XAVCNFSM6AAAAACLTBPJFWVHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMZTKNZRGIYTMNZQGU>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
scguaquetam
left a comment
There was a problem hiding this comment.
Please take in account these comments for better implementation.
src/commands/simulate.ts
Outdated
| const { balance: tokenBalance, decimals, name: tokenName, symbol: tokenSymbol } = | ||
| await getTokenInfo(publicClient, tokenAddress, walletAddress); | ||
|
|
||
| const currentTokenBalance = Number(tokenBalance) / (10 ** decimals); |
There was a problem hiding this comment.
Should we here use BigInt instead of Number? in case of managing too big values?
can we keep all in bigint?
src/commands/simulate.ts
Outdated
| async function simulateERC20Transfer( | ||
| params: TransactionSimulationOptions, | ||
| publicClient: any, | ||
| walletClient: any, |
There was a problem hiding this comment.
here you can use the PublicClient and WalletClient types from Viem instead of using any.
src/utils/simulationUtils.ts
Outdated
| @@ -0,0 +1,162 @@ | |||
| import { PublicClient, Account, Address, parseEther, formatEther } from "viem"; | |||
There was a problem hiding this comment.
parseEther ist not used here
| amount: bigint, | ||
| gasPrice?: bigint | ||
| ): Promise<GasEstimationResult> { | ||
| let gasEstimate = BigInt(100000); |
There was a problem hiding this comment.
in this case, if the estimation fails, it is hardcoded, we should somehow , tell the user in this case this is a fallback or fixed value due to an error on estimation.
src/utils/logger.ts
Outdated
| logMessage(isExternal, message, chalk.yellow); | ||
| } | ||
|
|
||
| export function capitalize(str: string): string { |
There was a problem hiding this comment.
I think this function is not being used on the project
There was a problem hiding this comment.
had an idea for dynamic string formatting in the logger utilities and thought capitalize would be useful, but the idea didn't hold up after implementation, turns out hardcoded messages work better for this use case
src/commands/simulate.ts
Outdated
| logMessage(params.isExternal || false, summaryMessage, isSuccessful ? chalk.green : chalk.red); | ||
|
|
||
| return { | ||
| success: true, |
There was a problem hiding this comment.
here, even if the transaction simulation fails, you are returning a success true, and other fields.
- Replace any types with PublicClient/WalletClient from Viem - Use BigInt for token balance calculations - Add fallback gas warning for users - Fix simulation result to return actual status instead of always true - Remove unused capitalize function and parseEther import - Add proper error logging and type guards
Add comprehensive documentation for the new simulate command that allows users to test RBTC and ERC20 token transfers before execution. Documentation includes usage examples, output samples, available options, and explanations of simulation results for both mainnet and testnet networks.
|
hey @Ad-Capital, |
…with gas estimation, balance validation, cost analysis, and formatted result output