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

refactor(QueryBase): Remove constructors in derived classes #808

Merged
merged 2 commits into from
Jan 2, 2025
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
28 changes: 1 addition & 27 deletions src/relayFeeCalculator/chain-queries/alephZero.ts
Original file line number Diff line number Diff line change
@@ -1,36 +1,10 @@
import assert from "assert";
import { getDeployedAddress } from "../../utils/DeploymentUtils";
import { DEFAULT_LOGGER, Logger } from "../relayFeeCalculator";
import { providers } from "ethers";
import { CHAIN_IDs, DEFAULT_SIMULATED_RELAYER_ADDRESS, TOKEN_SYMBOLS_MAP } from "../../constants";
import { CHAIN_IDs } from "../../constants";
import { Coingecko } from "../../coingecko/Coingecko";
import { isDefined } from "../../utils";
import { QueryBase } from "./baseQuery";

// @dev This class only exists because querying the native token price for this network is not the standard
// CoinGecko query because the native token symbol is not ETH.
export class AlephZeroQueries extends QueryBase {
constructor(
provider: providers.Provider,
symbolMapping = TOKEN_SYMBOLS_MAP,
spokePoolAddress = getDeployedAddress("SpokePool", CHAIN_IDs.ALEPH_ZERO),
simulatedRelayerAddress = DEFAULT_SIMULATED_RELAYER_ADDRESS,
coingeckoProApiKey?: string,
logger: Logger = DEFAULT_LOGGER
) {
assert(isDefined(spokePoolAddress));
super(
provider,
symbolMapping,
spokePoolAddress,
simulatedRelayerAddress,
logger,
coingeckoProApiKey,
undefined,
"usd"
);
}

override async getTokenPrice(tokenSymbol: string): Promise<number> {
if (!this.symbolMapping[tokenSymbol]) throw new Error(`${tokenSymbol} does not exist in mapping`);
const coingeckoInstance = Coingecko.get(this.logger, this.coingeckoProApiKey);
Expand Down
8 changes: 6 additions & 2 deletions src/relayFeeCalculator/chain-queries/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@ export class QueryBase__factory {
symbolMapping,
spokePoolAddress,
simulatedRelayerAddress,
logger,
coingeckoProApiKey,
logger
fixedGasPrice[chainId],
"usd"
Copy link
Member Author

@nicholaspai nicholaspai Jan 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm pretty sure we can just pass through and use the parent class's constructor here and therefore delete the derived construcotr in PolygonQueries and AlephZeroQueries. The only thing different in the child's constructor was changing the coingeckoBaseCurrency, which we can instead just explicitly state here when constructing the child class

);
}

Expand All @@ -48,8 +50,10 @@ export class QueryBase__factory {
symbolMapping,
spokePoolAddress,
simulatedRelayerAddress,
logger,
coingeckoProApiKey,
logger
fixedGasPrice[chainId],
"usd"
);
}

Expand Down
28 changes: 1 addition & 27 deletions src/relayFeeCalculator/chain-queries/polygon.ts
Original file line number Diff line number Diff line change
@@ -1,36 +1,10 @@
import assert from "assert";
import { getDeployedAddress } from "../../utils/DeploymentUtils";
import { DEFAULT_LOGGER, Logger } from "../relayFeeCalculator";
import { providers } from "ethers";
import { CHAIN_IDs, DEFAULT_SIMULATED_RELAYER_ADDRESS, TOKEN_SYMBOLS_MAP } from "../../constants";
import { CHAIN_IDs } from "../../constants";
import { Coingecko } from "../../coingecko/Coingecko";
import { isDefined } from "../../utils";
import { QueryBase } from "./baseQuery";

// @dev This class only exists because querying the native token price for this network is not the standard
// CoinGecko query because the native token symbol is not ETH.
export class PolygonQueries extends QueryBase {
constructor(
provider: providers.Provider,
symbolMapping = TOKEN_SYMBOLS_MAP,
spokePoolAddress = getDeployedAddress("SpokePool", CHAIN_IDs.POLYGON),
simulatedRelayerAddress = DEFAULT_SIMULATED_RELAYER_ADDRESS,
coingeckoProApiKey?: string,
logger: Logger = DEFAULT_LOGGER
) {
assert(isDefined(spokePoolAddress));
super(
provider,
symbolMapping,
spokePoolAddress,
simulatedRelayerAddress,
logger,
coingeckoProApiKey,
undefined,
"usd"
);
}

override async getTokenPrice(tokenSymbol: string): Promise<number> {
if (!this.symbolMapping[tokenSymbol]) throw new Error(`${tokenSymbol} does not exist in mapping`);
const coingeckoInstance = Coingecko.get(this.logger, this.coingeckoProApiKey);
Expand Down
Loading