Skip to content

Commit

Permalink
chore: Update price query (#247)
Browse files Browse the repository at this point in the history
* chore: Update price query

* chore: Cleanup
  • Loading branch information
garethfuller authored Nov 29, 2023
1 parent cf7a848 commit 20e6f45
Show file tree
Hide file tree
Showing 12 changed files with 23 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/config/arbitrum.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"networkId": 42161,
"network": "arbitrum",
"GqlChain": "ARBITRUM",
"rpc": "https://arbitrum-mainnet.infura.io/v3/{{INFURA_PROJECT_ID}}",
"subgraph": "https://api.thegraph.com/subgraphs/name/balancer-labs/balancer-arbitrum-v2-beta",
"addresses": {
Expand Down
1 change: 1 addition & 0 deletions src/config/avalanche.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"networkId": 43114,
"network": "avalanche",
"GqlChain": "AVALANCHE",
"rpc": "https://avalanche-mainnet.infura.io/v3/{{INFURA_PROJECT_ID}}",
"subgraph": "https://api.thegraph.com/subgraphs/name/balancer-labs/balancer-avalanche-v2",
"addresses": {
Expand Down
1 change: 1 addition & 0 deletions src/config/base.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"networkId": 8453,
"network": "base",
"GqlChain": "BASE",
"rpc": "https://developer-access-mainnet.base.org",
"subgraph": "https://api.studio.thegraph.com/query/24660/balancer-base-v2/version/latest",
"addresses": {
Expand Down
1 change: 1 addition & 0 deletions src/config/gnosis-chain.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"networkId": 100,
"network": "gnosis-chain",
"GqlChain": "GNOSIS",
"rpc": "https://poa-xdai.gateway.pokt.network/v1/lb/91bc0e12a76e7a84dd76189d",
"subgraph": "https://api.thegraph.com/subgraphs/name/balancer-labs/balancer-gnosis-chain-v2",
"addresses": {
Expand Down
1 change: 1 addition & 0 deletions src/config/goerli.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"networkId": 5,
"network": "goerli",
"GqlChain": "GOERLI",
"rpc": "https://goerli.infura.io/v3/{{INFURA_KEY}}",
"subgraph": "https://api.thegraph.com/subgraphs/name/balancer-labs/balancer-goerli-v2",
"addresses": {
Expand Down
1 change: 1 addition & 0 deletions src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export interface Config {
network: string;
rpc: string;
subgraph: string;
GqlChain: string;
addresses: {
nativeAsset: string;
wrappedNativeAsset: string;
Expand Down
1 change: 1 addition & 0 deletions src/config/mainnet.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"networkId": 1,
"network": "mainnet",
"GqlChain": "MAINNET",
"rpc": "https://mainnet.infura.io/v3/{{INFURA_PROJECT_ID}}",
"subgraph": "https://api.thegraph.com/subgraphs/name/balancer-labs/balancer-v2",
"addresses": {
Expand Down
1 change: 1 addition & 0 deletions src/config/optimism.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"networkId": 10,
"network": "optimism",
"GqlChain": "OPTIMISM",
"rpc": "https://optimism-mainnet.infura.io/v3/{{INFURA_PROJECT_ID}}",
"subgraph": "https://api.thegraph.com/subgraphs/name/balancer-labs/balancer-optimism-v2",
"addresses": {
Expand Down
1 change: 1 addition & 0 deletions src/config/polygon.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"networkId": 137,
"network": "polygon",
"GqlChain": "POLYGON",
"rpc": "https://polygon-mainnet.infura.io/v3/{{INFURA_PROJECT_ID}}",
"subgraph": "https://api.thegraph.com/subgraphs/name/balancer-labs/balancer-polygon-v2",
"addresses": {
Expand Down
1 change: 1 addition & 0 deletions src/config/sepolia.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"networkId": 11155111,
"network": "sepolia",
"GqlChain": "SEPOLIA",
"rpc": "https://sepolia.infura.io/v3/{{INFURA_KEY}}",
"subgraph": "https://api.studio.thegraph.com/query/24660/balancer-sepolia-v2/version/latest",
"addresses": {
Expand Down
1 change: 1 addition & 0 deletions src/config/zkevm.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"networkId": 1101,
"network": "zkevm",
"GqlChain": "ZKEVM",
"rpc": "https://polygonzkevm-mainnet.g.alchemy.com/v2/{{ALCHEMY_KEY}}",
"subgraph": "https://api.studio.thegraph.com/query/24660/balancer-polygon-zk-v2/version/latest",
"addresses": {
Expand Down
16 changes: 12 additions & 4 deletions src/modules/prices/beets-price-fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/

import { Token } from '@/modules/tokens';
import configs from '@/config';
import axios from 'axios';

const BEETS_API_URL =
Expand All @@ -22,18 +23,25 @@ class BeetsPriceFetcher {

const tokensWithPrices: Token[] = tokens.map(token => {
if (tokenPricesByChain[token.chainId][token.address]) {
token.price = token.price || {}
token.price.usd = tokenPricesByChain[token.chainId][token.address].toString()
token.price = token.price || {};
token.price.usd =
tokenPricesByChain[token.chainId][token.address].toString();
}
return token;
});


return tokensWithPrices;
}

async fetchFromBeetsAPI(chainId: number): Promise<Record<string, number>> {
const payload = JSON.stringify({query: 'query { tokenGetCurrentPrices { address price }}'});
const unspupportedChains = [5, 11155111];
if (unspupportedChains.includes(chainId)) {
return {};
}
const gqlChain = configs[chainId].GqlChain || 'MAINNET';
const payload = JSON.stringify({
query: `query { tokenGetCurrentPrices(chains: [${gqlChain}]) { address price }}`,
});
const result = await axios.post(BEETS_API_URL, payload, {
headers: {
'Content-Type': 'application/json',
Expand Down

0 comments on commit 20e6f45

Please sign in to comment.