Skip to content

Commit

Permalink
feat: tenderly simulation v4 native currency input no longer needs pe…
Browse files Browse the repository at this point in the history
…rmit2 or universal router approvals
  • Loading branch information
jsy1218 committed Sep 23, 2024
1 parent 2dfd1ea commit d6499bb
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/providers/tenderly-simulation-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import https from 'https';
import { MaxUint256 } from '@ethersproject/constants';
import { JsonRpcProvider } from '@ethersproject/providers';
import { permit2Address } from '@uniswap/permit2-sdk';
import { Protocol } from '@uniswap/router-sdk';
import { ChainId } from '@uniswap/sdk-core';
import { UNIVERSAL_ROUTER_ADDRESS } from '@uniswap/universal-router-sdk';
import { Pool as V4Pool } from '@uniswap/v4-sdk';
import axios, { AxiosRequestConfig } from 'axios';
import { BigNumber } from 'ethers/lib/ethers';

Expand Down Expand Up @@ -289,6 +291,8 @@ export class TenderlySimulator extends Simulator {
const currencyIn = swapRoute.trade.inputAmount.currency;
const tokenIn = currencyIn.wrapped;
const chainId = this.chainId;
const firstPoolIsV4 = swapRoute.route.some(route => route.protocol === Protocol.V4
|| (route.protocol === Protocol.MIXED && route.route.pools.length > 0 && route.route.pools[0] instanceof V4Pool));

if (TENDERLY_NOT_SUPPORTED_CHAINS.includes(chainId)) {
const msg = `${TENDERLY_NOT_SUPPORTED_CHAINS.toString()} not supported by Tenderly!`;
Expand Down Expand Up @@ -380,7 +384,7 @@ export class TenderlySimulator extends Simulator {
};

const body: TenderlySimulationBody = {
simulations: [approvePermit2, approveUniversalRouter, swap],
simulations: firstPoolIsV4 && currencyIn.isNative? [swap] : [approvePermit2, approveUniversalRouter, swap],
estimate_gas: true,
};
const opts: AxiosRequestConfig = {
Expand Down

0 comments on commit d6499bb

Please sign in to comment.