-
Notifications
You must be signed in to change notification settings - Fork 412
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add scripts for fetching prices and populating config (#3309)
### Description - Simple scripts for generating token and gas price constants ### Related issues - Fixes #3251 ### Backward compatibility Yes ### Testing Fork tests show diff onchain
- Loading branch information
Showing
6 changed files
with
126 additions
and
89 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
18 changes: 18 additions & 0 deletions
18
typescript/infra/config/environments/mainnet3/gasPrices.json
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,18 @@ | ||
{ | ||
"arbitrum": "0.1", | ||
"avalanche": "43.212830197", | ||
"bsc": "1.350070319", | ||
"celo": "10.0", | ||
"ethereum": "26.346912847", | ||
"mantapacific": "0.100000057", | ||
"moonbeam": "125.0", | ||
"optimism": "0.003225814", | ||
"polygon": "61.601287856", | ||
"gnosis": "1.852997796", | ||
"base": "0.0010003", | ||
"scroll": "0.46", | ||
"polygonzkevm": "3.95", | ||
"inevm": "0.1", | ||
"viction": "0.25", | ||
"injective": "0.1" | ||
} |
18 changes: 18 additions & 0 deletions
18
typescript/infra/config/environments/mainnet3/tokenPrices.json
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,18 @@ | ||
{ | ||
"arbitrum": "2914.61", | ||
"avalanche": "35.71", | ||
"bsc": "373.19", | ||
"celo": "0.772619", | ||
"ethereum": "2914.61", | ||
"mantapacific": "2914.61", | ||
"moonbeam": "0.419658", | ||
"optimism": "2914.61", | ||
"polygon": "0.982687", | ||
"gnosis": "1.012", | ||
"base": "2914.61", | ||
"scroll": "2914.61", | ||
"polygonzkevm": "2914.61", | ||
"inevm": "32.77", | ||
"viction": "0.750231", | ||
"injective": "32.77" | ||
} |
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,39 @@ | ||
import { ethers } from 'ethers'; | ||
|
||
import { MultiProtocolProvider, ProviderType } from '@hyperlane-xyz/sdk'; | ||
import { objMap, promiseObjAll } from '@hyperlane-xyz/utils'; | ||
|
||
import { mainnetConfigs } from '../config/environments/mainnet3/chains'; | ||
|
||
async function main() { | ||
const metadata = mainnetConfigs; | ||
|
||
const mpp = new MultiProtocolProvider(metadata); | ||
|
||
const prices = await promiseObjAll( | ||
objMap(metadata, async (chain, _) => { | ||
const provider = mpp.getProvider(chain); | ||
switch (provider.type) { | ||
case ProviderType.EthersV5: | ||
const gasPrice = await provider.provider.getGasPrice(); | ||
return ethers.utils.formatUnits(gasPrice, 'gwei'); | ||
case ProviderType.CosmJsWasm: | ||
// TODO: get default gas price | ||
return '0.1'; | ||
case ProviderType.SolanaWeb3: | ||
return '0.001'; | ||
default: | ||
throw new Error(`Unsupported provider type: ${provider.type}`); | ||
} | ||
}), | ||
); | ||
|
||
console.log(JSON.stringify(prices, null, 2)); | ||
} | ||
|
||
main() | ||
.then() | ||
.catch((err) => { | ||
console.error(err); | ||
process.exit(1); | ||
}); |
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,33 @@ | ||
import { objMap } from '@hyperlane-xyz/utils'; | ||
|
||
import { mainnetConfigs } from '../config/environments/mainnet3/chains'; | ||
|
||
const CURRENCY = 'usd'; | ||
|
||
async function main() { | ||
const metadata = mainnetConfigs; | ||
|
||
const ids = objMap( | ||
metadata, | ||
(_, metadata) => metadata.gasCurrencyCoinGeckoId ?? metadata.name, | ||
); | ||
|
||
const resp = await fetch( | ||
`https://api.coingecko.com/api/v3/simple/price?ids=${Object.entries( | ||
ids, | ||
).join(',')}&vs_currencies=${CURRENCY}`, | ||
); | ||
|
||
const idPrices = await resp.json(); | ||
|
||
const prices = objMap(ids, (_, id) => idPrices[id][CURRENCY].toString()); | ||
|
||
console.log(JSON.stringify(prices, null, 2)); | ||
} | ||
|
||
main() | ||
.then() | ||
.catch((err) => { | ||
console.error(err); | ||
process.exit(1); | ||
}); |
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