Skip to content

Commit

Permalink
Fix: pass block number retrieved from RPC-JSON getBlockNumber to Te…
Browse files Browse the repository at this point in the history
…nderly simulation (Uniswap#453)

* fix tenderly to pass block number

* make tenderly block look back the same as eip-1559

* don't look back block for tenderly simulation
  • Loading branch information
jsy1218 authored Nov 27, 2023
1 parent f536e18 commit 67f6b8c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 14 deletions.
6 changes: 4 additions & 2 deletions cli/commands/quote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export class Quote extends BaseCommand {
simulate: flags.boolean({ required: false, default: false }),
debugRouting: flags.boolean({ required: false, default: true }),
enableFeeOnTransferFeeFetching: flags.boolean({ required: false, default: false }),
requestBlockNumber: flags.integer({ required: false }),
};

async run() {
Expand Down Expand Up @@ -66,7 +67,8 @@ export class Quote extends BaseCommand {
forceMixedRoutes,
simulate,
debugRouting,
enableFeeOnTransferFeeFetching
enableFeeOnTransferFeeFetching,
requestBlockNumber
} = flags;

const topNSecondHopForTokenAddress = new MapWithLowerCaseKey();
Expand Down Expand Up @@ -137,7 +139,7 @@ export class Quote extends BaseCommand {
}
: undefined,
{
blockNumber: this.blockNumber,
blockNumber: requestBlockNumber ?? this.blockNumber,
v3PoolSelection: {
topN,
topNTokenInOut,
Expand Down
14 changes: 3 additions & 11 deletions src/providers/tenderly-simulation-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -301,11 +301,7 @@ export class TenderlySimulator extends Simulator {
to: UNIVERSAL_ROUTER_ADDRESS(this.chainId),
value: currencyIn.isNative ? swapRoute.methodParameters.value : '0',
from: fromAddress,
// TODO: This is a Temporary fix given by Tenderly team, remove once resolved on their end.
block_number:
chainId == ChainId.ARBITRUM_ONE && blockNumber
? blockNumber - 5
: undefined,
block_number: blockNumber,
simulation_type: TenderlySimulationType.QUICK,
save_if_fails: providerConfig?.saveTenderlySimulationIfFailed,
};
Expand Down Expand Up @@ -343,7 +339,7 @@ export class TenderlySimulator extends Simulator {

const latencies = Date.now() - before;
log.info(
`Tenderly simulation universal router request body: ${body}, having latencies ${latencies} in milliseconds.`
`Tenderly simulation universal router request body: ${JSON.stringify(body, null, 2)}, having latencies ${latencies} in milliseconds.`
);
metric.putMetric(
'TenderlySimulationUniversalRouterLatencies',
Expand Down Expand Up @@ -416,11 +412,7 @@ export class TenderlySimulator extends Simulator {
estimate_gas: true,
value: currencyIn.isNative ? swapRoute.methodParameters.value : '0',
from: fromAddress,
// TODO: This is a Temporary fix given by Tenderly team, remove once resolved on their end.
block_number:
chainId == ChainId.ARBITRUM_ONE && blockNumber
? blockNumber - 5
: undefined,
block_number: blockNumber,
simulation_type: TenderlySimulationType.QUICK,
};

Expand Down
3 changes: 2 additions & 1 deletion src/routers/alpha-router/alpha-router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1466,7 +1466,8 @@ export class AlphaRouter
if (!this.simulator) {
throw new Error('Simulator not initialized!');
}
log.info({ swapConfig, methodParameters }, 'Starting simulation');

log.info(JSON.stringify({ swapConfig, methodParameters, providerConfig }, null, 2), `Starting simulation`);
const fromAddress = swapConfig.simulate.fromAddress;
const beforeSimulate = Date.now();
const swapRouteWithSimulation = await this.simulator.simulate(
Expand Down

0 comments on commit 67f6b8c

Please sign in to comment.