Skip to content

Commit

Permalink
refactor(QueryBase): Remove constructors in derived classes (#808)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicholaspai authored Jan 2, 2025
1 parent 515ec15 commit 765ef85
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,34 +1,8 @@
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";

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,34 +1,8 @@
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";

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 765ef85

Please sign in to comment.