-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/master' into pxrl/experimentalGas
- Loading branch information
Showing
21 changed files
with
632 additions
and
273 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,23 @@ | ||
import { any, literal, nullable, number, string, type, union } from "superstruct"; | ||
|
||
export type RPCProvider = "ALCHEMY" | "DRPC" | "INFURA" | "INFURA_DIN"; | ||
export type RPCTransport = "https" | "wss"; | ||
|
||
// JSON-RPC 2.0 Error object | ||
// See JSON-RPC 2.0 Specification section 5 Reponse object | ||
// https://www.jsonrpc.org/specification | ||
export const JsonRpcError = type({ | ||
jsonrpc: literal("2.0"), | ||
id: union([number(), string()]), | ||
error: type({ | ||
code: number(), | ||
message: string(), | ||
data: nullable(any()), | ||
}), | ||
}); | ||
|
||
// Generic/unknown RPC error (may embed a JsonRpcError). | ||
export const RpcError = type({ | ||
reason: string(), | ||
body: string(), | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
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 { 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, | ||
gasMarkup = 0 | ||
) { | ||
assert(isDefined(spokePoolAddress)); | ||
super( | ||
provider, | ||
symbolMapping, | ||
spokePoolAddress, | ||
simulatedRelayerAddress, | ||
gasMarkup, | ||
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); | ||
const [, tokenPrice] = await coingeckoInstance.getCurrentPriceByContract( | ||
this.symbolMapping[tokenSymbol].addresses[CHAIN_IDs.MAINNET], | ||
"usd" | ||
); | ||
|
||
const [, alephZeroPrice] = await coingeckoInstance.getCurrentPriceByContract( | ||
this.symbolMapping["AZERO"].addresses[CHAIN_IDs.MAINNET], | ||
"usd" | ||
); | ||
return Number((tokenPrice / alephZeroPrice).toFixed(this.symbolMapping["AZERO"].decimals)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.