Skip to content

Commit

Permalink
feat: populate multiple chains in big query tokenInfo table (#284)
Browse files Browse the repository at this point in the history
### Description

Adds Ethereum tokens from to the `address_metadata.tokens_info` in Big
Query. The table should be edited to include the following nullable
fields: `tokenId` and `networkId`.

### Related Issues
ACT-953

---------

Co-authored-by: Charlie Andrews-Jubelt <cajubelt@users.noreply.github.com>
  • Loading branch information
MuckT and cajubelt authored Nov 7, 2023
1 parent 641417a commit 84e2538
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions scripts/update-bq.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,31 @@
/* eslint-disable no-console */

import { BigQuery } from '@google-cloud/bigquery'
import jsonData from '../src/data/mainnet/celo-tokens-info.json'
import { NetworkId } from '../src/types'
import { getTokensInfoByNetworkIds } from '../src/tokens-info'

const bigquery = new BigQuery()

const projectId = 'celo-mobile-mainnet' // we don't index testnet data
const datasetId = 'address_metadata'
const tableId = 'tokens_info'
const fieldsToKeep = ['address', 'decimals', 'name', 'symbol'] as const

const rows = jsonData.map((entry) => {
const row: Record<string, string | number> = {}
fieldsToKeep.forEach((field) => {
row[field] = entry[field]
})
const fieldsToKeep = [
'address',
'decimals',
'name',
'symbol',
'tokenId',
'networkId',
] as const

const tokensInfo = getTokensInfoByNetworkIds([
NetworkId['celo-mainnet'],
NetworkId['ethereum-mainnet'],
])

const rows = Object.entries(tokensInfo).map(([_, tokenInfo]) => {
const row: Record<string, string | number | boolean | null> = {}
fieldsToKeep.forEach((field) => (row[field] = tokenInfo[field] ?? null))
return row
})

Expand Down

0 comments on commit 84e2538

Please sign in to comment.