Skip to content

Commit

Permalink
fix arb integ-test
Browse files Browse the repository at this point in the history
  • Loading branch information
jsy1218 committed Feb 7, 2024
1 parent 643ed6a commit 55e1e82
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 15 deletions.
2 changes: 2 additions & 0 deletions src/providers/v3/gas-data-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,9 @@ export class ArbitrumGasDataProvider
const gasData = await gasDataContract.getPricesInWei({
blockTag: providerConfig?.blockNumber,
});
console.log(`arb gas data ${JSON.stringify(gasData)}`)
const perL1CalldataByte = gasData[1];
console.log(`perL2TxFee ${JSON.stringify(gasData[0])}`)
return {
perL2TxFee: gasData[0],
perL1CalldataFee: perL1CalldataByte.div(16),
Expand Down
4 changes: 3 additions & 1 deletion src/routers/alpha-router/alpha-router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -803,7 +803,8 @@ export class AlphaRouter
this.tokenProvider,
this.chainId,
this.blockedTokenListProvider,
this.tokenValidatorProvider
this.tokenValidatorProvider,
this.l2GasDataProvider
);

this.v3Quoter = new V3Quoter(
Expand Down Expand Up @@ -2079,6 +2080,7 @@ export class AlphaRouter
gasPriceWei,
poolProvider: this.v2PoolProvider,
token: quoteToken,
l2GasDataProvider: this.l2GasDataProvider,
providerConfig: providerConfig,
});

Expand Down
18 changes: 6 additions & 12 deletions src/routers/alpha-router/functions/best-swap-route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import FixedReverseHeap from 'mnemonist/fixed-reverse-heap';
import Queue from 'mnemonist/queue';

import { IPortionProvider } from '../../../providers/portion-provider';
import { HAS_L1_FEE } from '../../../util';
import { HAS_L1_FEE, V2_SUPPORTED } from '../../../util';
import { CurrencyAmount } from '../../../util/amounts';
import { log } from '../../../util/log';
import { metric, MetricLoggerUnit } from '../../../util/metric';
Expand Down Expand Up @@ -361,7 +361,7 @@ export async function getBestSwapRouteBy(
throw new Error("Can't compute L1 gas fees.");
} else {
const v2Routes = curRoutesNew.filter((routes) => routes.protocol === Protocol.V2);
if (v2Routes.length > 0) {
if (v2Routes.length > 0 && V2_SUPPORTED.includes(chainId)) {
const v2GasCostL1 = await v2GasModel.calculateL1GasFees!(v2Routes as V2RouteWithValidQuote[]);
gasCostL1QuoteToken = gasCostL1QuoteToken.add(v2GasCostL1.gasCostL1QuoteToken);
}
Expand Down Expand Up @@ -446,7 +446,7 @@ export async function getBestSwapRouteBy(
const usdTokenDecimals = usdToken.decimals;

// if on L2, calculate the L1 security fee
const gasCostsL1ToL2: L1ToL2GasCosts = {
let gasCostsL1ToL2: L1ToL2GasCosts = {
gasUsedL1: BigNumber.from(0),
gasUsedL1OnL2: BigNumber.from(0),
gasCostL1USD: CurrencyAmount.fromRawAmount(usdToken, 0),
Expand All @@ -462,22 +462,16 @@ export async function getBestSwapRouteBy(
throw new Error("Can't compute L1 gas fees.");
} else {
const v2Routes = bestSwap.filter((routes) => routes.protocol === Protocol.V2);
if (v2Routes.length > 0) {
if (v2Routes.length > 0 && V2_SUPPORTED.includes(chainId)) {
const v2GasCostL1 = await v2GasModel.calculateL1GasFees!(v2Routes as V2RouteWithValidQuote[]);
gasCostsL1ToL2.gasUsedL1 = gasCostsL1ToL2.gasUsedL1.add(v2GasCostL1.gasUsedL1);
gasCostsL1ToL2.gasUsedL1OnL2 = gasCostsL1ToL2.gasUsedL1OnL2.add(v2GasCostL1.gasUsedL1OnL2);
gasCostsL1ToL2.gasCostL1USD = gasCostsL1ToL2.gasCostL1USD.add(v2GasCostL1.gasCostL1USD);
gasCostsL1ToL2.gasCostL1QuoteToken = gasCostsL1ToL2.gasCostL1QuoteToken.add(v2GasCostL1.gasCostL1QuoteToken);
gasCostsL1ToL2 = v2GasCostL1;
}
const v3Routes = bestSwap.filter((routes) => routes.protocol === Protocol.V3);
if (v3Routes.length > 0) {
const v3GasCostL1 = await v3GasModel.calculateL1GasFees!(
v3Routes as V3RouteWithValidQuote[]
);
gasCostsL1ToL2.gasUsedL1 = gasCostsL1ToL2.gasUsedL1.add(v3GasCostL1.gasUsedL1);
gasCostsL1ToL2.gasUsedL1OnL2 = gasCostsL1ToL2.gasUsedL1OnL2.add(v3GasCostL1.gasUsedL1OnL2);
gasCostsL1ToL2.gasCostL1USD = gasCostsL1ToL2.gasCostL1USD.add(v3GasCostL1.gasCostL1USD);
gasCostsL1ToL2.gasCostL1QuoteToken = gasCostsL1ToL2.gasCostL1QuoteToken.add(v3GasCostL1.gasCostL1QuoteToken);
gasCostsL1ToL2 = v3GasCostL1;
}
}
}
Expand Down
13 changes: 12 additions & 1 deletion src/routers/alpha-router/quoters/v2-quoter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,19 @@ import { NATIVE_OVERHEAD } from '../gas-models/v3/gas-costs';
import { BaseQuoter } from './base-quoter';
import { GetQuotesResult } from './model/results/get-quotes-result';
import { GetRoutesResult } from './model/results/get-routes-result';
import {
ArbitrumGasData,
IL2GasDataProvider,
OptimismGasData
} from '../../../providers/v3/gas-data-provider';

export class V2Quoter extends BaseQuoter<V2CandidatePools, V2Route> {
protected v2SubgraphProvider: IV2SubgraphProvider;
protected v2PoolProvider: IV2PoolProvider;
protected v2QuoteProvider: IV2QuoteProvider;
protected v2GasModelFactory: IV2GasModelFactory;
protected l2GasDataProvider?: IL2GasDataProvider<OptimismGasData>
| IL2GasDataProvider<ArbitrumGasData>;

constructor(
v2SubgraphProvider: IV2SubgraphProvider,
Expand All @@ -48,7 +55,9 @@ export class V2Quoter extends BaseQuoter<V2CandidatePools, V2Route> {
tokenProvider: ITokenProvider,
chainId: ChainId,
blockedTokenListProvider?: ITokenListProvider,
tokenValidatorProvider?: ITokenValidatorProvider
tokenValidatorProvider?: ITokenValidatorProvider,
l2GasDataProvider?: IL2GasDataProvider<OptimismGasData>
| IL2GasDataProvider<ArbitrumGasData>
) {
super(
tokenProvider,
Expand All @@ -61,6 +70,7 @@ export class V2Quoter extends BaseQuoter<V2CandidatePools, V2Route> {
this.v2PoolProvider = v2PoolProvider;
this.v2QuoteProvider = v2QuoteProvider;
this.v2GasModelFactory = v2GasModelFactory;
this.l2GasDataProvider = l2GasDataProvider;
}

protected async getRoutes(
Expand Down Expand Up @@ -180,6 +190,7 @@ export class V2Quoter extends BaseQuoter<V2CandidatePools, V2Route> {
gasPriceWei,
poolProvider: this.v2PoolProvider,
token: quoteToken,
l2GasDataProvider: this.l2GasDataProvider,
providerConfig: {
..._routingConfig,
additionalGasOverhead: NATIVE_OVERHEAD(
Expand Down
2 changes: 2 additions & 0 deletions src/util/gas-factory-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,8 @@ export const calculateL1GasFeesHelper = async (
gasCostL1USD: CurrencyAmount;
gasCostL1QuoteToken: CurrencyAmount;
}> => {
console.log(`l2GasData ${JSON.stringify(l2GasData)}`)

const swapOptions: SwapOptionsUniversalRouter = {
type: SwapType.UNIVERSAL_ROUTER,
recipient: '0x0000000000000000000000000000000000000001',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3419,7 +3419,7 @@ describe('quote for other networks', () => {
// Scope limited for non mainnet network tests to validating the swap
});

it(`${wrappedNative.symbol} -> erc20 v2 only`, async () => {
it(`${wrappedNative.symbol} -> ${erc1.symbol} v2 only`, async () => {
const tokenIn = wrappedNative;
const tokenOut = erc1;

Expand Down

0 comments on commit 55e1e82

Please sign in to comment.