Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(refactor): relayFeeCalculator queries #647

Merged
merged 5 commits into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 0 additions & 55 deletions src/relayFeeCalculator/chain-queries/arbitrum.ts

This file was deleted.

83 changes: 0 additions & 83 deletions src/relayFeeCalculator/chain-queries/base.ts

This file was deleted.

11 changes: 5 additions & 6 deletions src/relayFeeCalculator/chain-queries/baseQuery.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { SpokePool, SpokePool__factory } from "../../typechain";
import { L2Provider } from "@eth-optimism/sdk/dist/interfaces/l2-provider";
import { providers } from "ethers";
import { Coingecko } from "../../coingecko";
import { CHAIN_IDs, DEFAULT_SIMULATED_RELAYER_ADDRESS } from "../../constants";
import { Deposit } from "../../interfaces";
import { SpokePool, SpokePool__factory } from "../../typechain";
import {
BigNumberish,
TransactionCostEstimate,
estimateTotalGasRequiredByUnsignedTransaction,
populateV3Relay,
TransactionCostEstimate,
} from "../../utils";
import { Logger, QueryInterface } from "../relayFeeCalculator";
import { Deposit } from "../../interfaces";

type Provider = providers.Provider;
type OptimismProvider = L2Provider<Provider>;
Expand All @@ -26,22 +26,21 @@ type SymbolMappingType = Record<
* A unified QueryBase for querying gas costs, token prices, and decimals of various tokens
* on a blockchain.
*/
export default abstract class QueryBase implements QueryInterface {
export class QueryBase implements QueryInterface {
readonly spokePool: SpokePool;
/**
* Instantiates a QueryBase instance
* @param provider A valid Ethers.js provider
* @param symbolMapping A mapping to valid ERC20 tokens and their respective characteristics
* @param spokePoolAddress The valid address of the Spoke Pool deployment
* @param usdcAddress The valid token address of the USDC ERC-20 token
* @param simulatedRelayerAddress The address that these queries will reference as the sender. Note: This address must be approved for USDC
* @param gasMarkup A multiplier that is applied to the total gas estimate
* @param logger A logging utility to report logs
* @param coingeckoProApiKey An optional CoinGecko API key that links to a PRO account
* @param fixedGasPrice Overrides the gas price with a fixed value. Note: primarily used for the Boba blockchain
* @param coingeckoBaseCurrency The basis currency that CoinGecko will use to resolve pricing
*/
protected constructor(
constructor(
readonly provider: Provider | OptimismProvider,
readonly symbolMapping: SymbolMappingType,
readonly spokePoolAddress: string,
Expand Down
28 changes: 0 additions & 28 deletions src/relayFeeCalculator/chain-queries/boba.ts

This file was deleted.

59 changes: 0 additions & 59 deletions src/relayFeeCalculator/chain-queries/ethereum.ts

This file was deleted.

58 changes: 58 additions & 0 deletions src/relayFeeCalculator/chain-queries/factory.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { CHAIN_IDs, TOKEN_SYMBOLS_MAP } from "@across-protocol/constants-v2";
import { getDeployedAddress } from "@across-protocol/contracts-v2";
import { asL2Provider } from "@eth-optimism/sdk";
import { providers } from "ethers";
import { DEFAULT_SIMULATED_RELAYER_ADDRESS } from "../../constants";
import { chainIsMatic, chainIsOPStack } from "../../utils";
import { QueryBase } from "./baseQuery";
import { PolygonQueries } from "./polygon";
import { DEFAULT_LOGGER, Logger } from "../relayFeeCalculator";

/**
* Some chains have a fixed gas price that is applied to the gas estimates. We should override
* the gas markup for these chains.
*/
const fixedGasPrice = {
[CHAIN_IDs.BOBA]: 1e9,
};

export class QueryBase__factory {
static create(
chainId: number,
provider: providers.Provider,
symbolMapping = TOKEN_SYMBOLS_MAP,
spokePoolAddress = getDeployedAddress("SpokePool", chainId),
simulatedRelayerAddress = DEFAULT_SIMULATED_RELAYER_ADDRESS,
coingeckoProApiKey?: string,
logger: Logger = DEFAULT_LOGGER,
gasMarkup = 0,
coingeckoBaseCurrency = "eth"
): QueryBase {
// Currently the only chain that has a custom query class is Polygon
if (chainIsMatic(chainId)) {
return new PolygonQueries(
provider,
symbolMapping,
spokePoolAddress,
simulatedRelayerAddress,
coingeckoProApiKey,
logger,
gasMarkup
);
}
// For OPStack chains, we need to wrap the provider in an L2Provider
provider = chainIsOPStack(chainId) ? asL2Provider(provider) : provider;

return new QueryBase(
provider,
symbolMapping,
spokePoolAddress,
simulatedRelayerAddress,
gasMarkup,
logger,
coingeckoProApiKey,
fixedGasPrice[chainId],
coingeckoBaseCurrency
);
}
}
9 changes: 1 addition & 8 deletions src/relayFeeCalculator/chain-queries/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
export * from "./arbitrum";
export * from "./base";
export * from "./baseQuery";
export * from "./boba";
export * from "./ethereum";
export * from "./linea";
export * from "./optimism";
export * from "./polygon";
export * from "./zksync";
export * from "./mode";
export * from "./factory";
33 changes: 0 additions & 33 deletions src/relayFeeCalculator/chain-queries/linea.ts

This file was deleted.

Loading
Loading