Skip to content

Commit

Permalink
refactor(QueryBase): Remove constructors in derived classes
Browse files Browse the repository at this point in the history
The constructor calls in AlephZeroQueries and PolygonQueries are not useful since the `getTokenPrice()` class function is the main changed logic from the parent `QueryBase` class. We can reduce LOC in the repo by removing these constructors.

This was partially motivated by work on #801 where I had to modify these constructors because the `QueryBase` constructor changed
  • Loading branch information
nicholaspai committed Dec 27, 2024
1 parent 281f9f7 commit fd77ce8
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 56 deletions.
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"
);
}

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

0 comments on commit fd77ce8

Please sign in to comment.