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

Update gas oracle values #2996

Merged
merged 4 commits into from
Nov 29, 2023
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
30 changes: 15 additions & 15 deletions typescript/infra/config/environments/mainnet3/gas-oracle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ import { supportedChainNames } from './chains';
// Last updated Mar 9, 2023.
const gasPrices: ChainMap<BigNumber> = {
// https://bscscan.com/chart/gasprice
bsc: ethers.utils.parseUnits('7', 'gwei'),
bsc: ethers.utils.parseUnits('3', 'gwei'),
// https://snowtrace.io/chart/gasprice
avalanche: ethers.utils.parseUnits('35', 'gwei'),
// https://polygonscan.com/chart/gasprice
polygon: ethers.utils.parseUnits('200', 'gwei'),
polygon: ethers.utils.parseUnits('300', 'gwei'),
// https://celoscan.io/chart/gasprice
// This one is interesting - the average is high (~20 gwei)
// but the median is low (< 10). This is likely because a popular wallet is
Expand All @@ -41,7 +41,7 @@ const gasPrices: ChainMap<BigNumber> = {
moonbeam: ethers.utils.parseUnits('150', 'gwei'),
// https://gnosisscan.io/chart/gasprice
// People also seem to be overpaying here
gnosis: ethers.utils.parseUnits('2', 'gwei'),
gnosis: ethers.utils.parseUnits('10', 'gwei'),
// Arbitrarily chosen as gas prices aren't really a thing
// in Solana.
solana: ethers.BigNumber.from('28'),
Expand All @@ -57,32 +57,32 @@ const gasPrices: ChainMap<BigNumber> = {
// tokens are what matters. These generally have high beta
const tokenUsdPrices: ChainMap<BigNumber> = {
// https://www.coingecko.com/en/coins/bnb
bsc: ethers.utils.parseUnits('211.55', TOKEN_EXCHANGE_RATE_DECIMALS),
bsc: ethers.utils.parseUnits('230.55', TOKEN_EXCHANGE_RATE_DECIMALS),
// https://www.coingecko.com/en/coins/avalanche
avalanche: ethers.utils.parseUnits('9.25', TOKEN_EXCHANGE_RATE_DECIMALS),
avalanche: ethers.utils.parseUnits('20.25', TOKEN_EXCHANGE_RATE_DECIMALS),
// https://www.coingecko.com/en/coins/polygon
polygon: ethers.utils.parseUnits('0.518', TOKEN_EXCHANGE_RATE_DECIMALS),
polygon: ethers.utils.parseUnits('0.75', TOKEN_EXCHANGE_RATE_DECIMALS),
// https://www.coingecko.com/en/coins/celo
celo: ethers.utils.parseUnits('0.42', TOKEN_EXCHANGE_RATE_DECIMALS),
celo: ethers.utils.parseUnits('0.52', TOKEN_EXCHANGE_RATE_DECIMALS),
// https://www.coingecko.com/en/coins/ethereum
arbitrum: ethers.utils.parseUnits('1619.00', TOKEN_EXCHANGE_RATE_DECIMALS),
arbitrum: ethers.utils.parseUnits('2000.00', TOKEN_EXCHANGE_RATE_DECIMALS),
// https://www.coingecko.com/en/coins/ethereum
optimism: ethers.utils.parseUnits('1619.00', TOKEN_EXCHANGE_RATE_DECIMALS),
optimism: ethers.utils.parseUnits('2000.00', TOKEN_EXCHANGE_RATE_DECIMALS),
// https://www.coingecko.com/en/coins/ethereum
ethereum: ethers.utils.parseUnits('1619.00', TOKEN_EXCHANGE_RATE_DECIMALS),
ethereum: ethers.utils.parseUnits('2000.00', TOKEN_EXCHANGE_RATE_DECIMALS),
// https://www.coingecko.com/en/coins/moonbeam
moonbeam: ethers.utils.parseUnits('0.166', TOKEN_EXCHANGE_RATE_DECIMALS),
moonbeam: ethers.utils.parseUnits('0.266', TOKEN_EXCHANGE_RATE_DECIMALS),
// xDAI
gnosis: ethers.utils.parseUnits('1.00', TOKEN_EXCHANGE_RATE_DECIMALS),
// https://www.coingecko.com/en/coins/solana
solana: ethers.utils.parseUnits('18.85', TOKEN_EXCHANGE_RATE_DECIMALS),
solana: ethers.utils.parseUnits('58.85', TOKEN_EXCHANGE_RATE_DECIMALS),
// https://www.coingecko.com/en/coins/ethereum
base: ethers.utils.parseUnits('1619.00', TOKEN_EXCHANGE_RATE_DECIMALS),
base: ethers.utils.parseUnits('2000.00', TOKEN_EXCHANGE_RATE_DECIMALS),
// https://www.coingecko.com/en/coins/ethereum
scroll: ethers.utils.parseUnits('1619.00', TOKEN_EXCHANGE_RATE_DECIMALS),
scroll: ethers.utils.parseUnits('2000.00', TOKEN_EXCHANGE_RATE_DECIMALS),
// https://www.coingecko.com/en/coins/ethereum
polygonzkevm: ethers.utils.parseUnits(
'1619.00',
'2000.00',
TOKEN_EXCHANGE_RATE_DECIMALS,
),
// https://www.coingecko.com/en/coins/neutron
Expand Down
3 changes: 3 additions & 0 deletions typescript/sdk/src/consts/chainMetadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ export const base: ChainMetadata = {
family: ExplorerFamily.Etherscan,
},
],
gasCurrencyCoinGeckoId: 'ethereum', // ETH is used for gas
blocks: {
confirmations: 1,
reorgPeriod: 1,
Expand Down Expand Up @@ -466,6 +467,7 @@ export const scroll: ChainMetadata = {
family: ExplorerFamily.Etherscan,
},
],
gasCurrencyCoinGeckoId: 'ethereum', // ETH is used for gas
blocks: {
confirmations: 1,
reorgPeriod: 1,
Expand Down Expand Up @@ -1001,6 +1003,7 @@ export const polygonzkevm: ChainMetadata = {
family: ExplorerFamily.Etherscan,
},
],
gasCurrencyCoinGeckoId: 'ethereum', // ETH is used for gas
blocks: {
confirmations: 1,
reorgPeriod: 1,
Expand Down
6 changes: 5 additions & 1 deletion typescript/sdk/src/gas/token-prices.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ describe('TokenPriceGetter', () => {
mockCoinGecko.setTokenPrice(chainA, priceA);
// Destination token
mockCoinGecko.setTokenPrice(chainB, priceB);
tokenPriceGetter = new CoinGeckoTokenPriceGetter(mockCoinGecko);
tokenPriceGetter = new CoinGeckoTokenPriceGetter(
mockCoinGecko,
undefined,
0,
);
});

describe('getTokenPrice', () => {
Expand Down
14 changes: 12 additions & 2 deletions typescript/sdk/src/gas/token-prices.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import CoinGecko from 'coingecko-api';

import { warn } from '@hyperlane-xyz/utils';
import { sleep, warn } from '@hyperlane-xyz/utils';

import { chainMetadata as defaultChainMetadata } from '../consts/chainMetadata';
import { CoreChainName, Mainnets } from '../consts/chains';
Expand Down Expand Up @@ -70,23 +70,31 @@ class TokenPriceCache {
export class CoinGeckoTokenPriceGetter implements TokenPriceGetter {
protected coinGecko: CoinGeckoInterface;
protected cache: TokenPriceCache;
protected sleepMsBetweenRequests: number;
protected metadata: ChainMap<ChainMetadata>;

constructor(
coinGecko: CoinGeckoInterface,
expirySeconds?: number,
sleepMsBetweenRequests = 5000,
chainMetadata = defaultChainMetadata,
) {
this.coinGecko = coinGecko;
this.cache = new TokenPriceCache(expirySeconds);
this.metadata = chainMetadata;
this.sleepMsBetweenRequests = sleepMsBetweenRequests;
}

static withDefaultCoinGecko(
expirySeconds?: number,
sleepMsBetweenRequests = 5000,
): CoinGeckoTokenPriceGetter {
const coinGecko = new CoinGecko();
return new CoinGeckoTokenPriceGetter(coinGecko, expirySeconds);
return new CoinGeckoTokenPriceGetter(
coinGecko,
expirySeconds,
sleepMsBetweenRequests,
);
}

async getTokenPrice(chain: ChainName): Promise<number> {
Expand Down Expand Up @@ -136,6 +144,8 @@ export class CoinGeckoTokenPriceGetter implements TokenPriceGetter {
const ids = chains.map(
(chain) => this.metadata[chain].gasCurrencyCoinGeckoId || chain,
);
// Coingecko rate limits, so we are adding this sleep
await sleep(this.sleepMsBetweenRequests);
const response = await this.coinGecko.simple.price({
ids,
vs_currencies: [currency],
Expand Down
Loading