Skip to content

Commit

Permalink
fix: linting
Browse files Browse the repository at this point in the history
  • Loading branch information
o-az committed Jan 7, 2024
1 parent 5a749e7 commit 8553acd
Show file tree
Hide file tree
Showing 12 changed files with 114 additions and 112 deletions.
5 changes: 1 addition & 4 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
{
"recommendations": [
"biomejs.biome",
"github.vscode-github-actions"
]
"recommendations": ["biomejs.biome", "github.vscode-github-actions"]
}
12 changes: 6 additions & 6 deletions scripts/sanitize-db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default {
const results = []
const errors = []
for (const chunk of chunks) {
const addresses = chunk.map((row) => row.address)
const addresses = chunk.map(row => row.address)
try {
const hasBalanceOfs = await hasBalanceOfBatch(pathParam as Chain, addresses, env)

Expand All @@ -39,7 +39,7 @@ export default {
})
} catch (error) {
console.error(error)
errors.push(...chunk.map((_) => _.address))
errors.push(...chunk.map(_ => _.address))
} finally {
sleep(5)
}
Expand All @@ -53,7 +53,7 @@ export default {
const deleteRows = await removeRows({
database: env.DB,
chain: pathParam,
addresses: chunk,
addresses: chunk
})
console.log(JSON.stringify(deleteRows, undefined, 2))
} catch (error) {
Expand All @@ -64,11 +64,11 @@ export default {
return new Response(
JSON.stringify({
errors,
results,
results
}),
{
headers: { 'content-type': 'application/json' },
headers: { 'content-type': 'application/json' }
}
)
},
}
}
62 changes: 31 additions & 31 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,173 +8,173 @@ export const chains = {
name: 'Ethereum Mainnet',
id: 1,
currency: 'ETH',
explorer: 'https://etherscan.io',
explorer: 'https://etherscan.io'
},
optimism: {
name: 'Optimism Mainnet',
id: 10,
currency: 'ETH',
explorer: 'https://optimistic.etherscan.io',
explorer: 'https://optimistic.etherscan.io'
},
gnosis: {
name: 'Gnosis Chain',
id: 100,
currency: 'xDai',
explorer: 'https://gnosischain.com',
explorer: 'https://gnosischain.com'
},
arbitrum: {
name: 'Arbitrum One',
id: 42_161,
currency: 'ETH',
explorer: 'https://arbiscan.io',
explorer: 'https://arbiscan.io'
},
polygon: {
name: 'Polygon (Matic) Mainnet',
id: 137,
currency: 'MATIC',
explorer: 'https://explorer-mainnet.maticvigil.com',
explorer: 'https://explorer-mainnet.maticvigil.com'
},
celo: {
name: 'Celo Mainnet',
id: 42_220,
currency: 'CELO',
explorer: 'https://explorer.celo.org',
explorer: 'https://explorer.celo.org'
},
moonbeam: {
name: 'Moonbeam',
id: 1284,
currency: 'GLMR',
explorer: 'https://blockscout.moonbeam.network',
explorer: 'https://blockscout.moonbeam.network'
},
avalanche: {
name: 'Avalanche Mainnet',
id: 43_114,
currency: 'AVAX',
explorer: 'https://explorer.avax.network',
explorer: 'https://explorer.avax.network'
},
fantom: {
name: 'Fantom Opera',
id: 250,
currency: 'FTM',
explorer: 'https://ftmscan.com',
explorer: 'https://ftmscan.com'
},
bsc: {
name: 'Binance Smart Chain',
id: 56,
currency: 'BNB',
explorer: 'https://bscscan.com',
explorer: 'https://bscscan.com'
},
harmony: {
name: 'Harmony One',
id: 1_666_600_000,
currency: 'ONE',
explorer: 'https://explorer.harmony.one',
},
explorer: 'https://explorer.harmony.one'
}
} as const satisfies Chains

export const unsupportedChains = {
aurora: {
name: 'Aurora',
id: 1_313_161_554,
currency: 'NEAR',
explorer: 'https://explorer.aurora.dev',
explorer: 'https://explorer.aurora.dev'
},
goerli: {
name: 'Görli Testnet',
id: 5,
currency: 'ETH',
explorer: 'https://goerli.etherscan.io',
explorer: 'https://goerli.etherscan.io'
},
optimismGoerli: {
name: 'Optimism Görli Testnet',
id: 420,
currency: 'ETH',
explorer: 'https://goerli.optimism.io',
explorer: 'https://goerli.optimism.io'
},
baseGoerli: {
name: 'Base Görli Testnet',
id: 84_531,
currency: 'ETH',
explorer: 'https://goerli.etherscan.io',
explorer: 'https://goerli.etherscan.io'
},

arbitrumNova: {
name: 'Arbitrum Nova',
id: 42_170,
currency: 'ARB',
explorer: 'https://explorer.arbitrum.io',
explorer: 'https://explorer.arbitrum.io'
},
bitorrnet: {
name: 'BitTorrent',
id: 199,
currency: 'BTT',
explorer: 'https://bttcscan.com',
explorer: 'https://bttcscan.com'
},
moonriver: {
name: 'Moonriver',
id: 1285,
currency: 'MOVR',
explorer: 'https://blockscout.moonriver.moonbeam.network',
explorer: 'https://blockscout.moonriver.moonbeam.network'
},
evmos: {
name: 'Evmos',
id: 9001,
currency: 'EVM',
explorer: 'https://explorer.evmos.org',
explorer: 'https://explorer.evmos.org'
},
cento: {
name: 'Cento',
id: 7700,
currency: 'CENTO',
explorer: 'https://explorer.cento.org',
explorer: 'https://explorer.cento.org'
},
sepolia: {
name: 'Sepolia Testnet',
id: 11_155_111,
currency: 'ETH',
explorer: 'https://sepolia.etherscan.io',
explorer: 'https://sepolia.etherscan.io'
},
polygonMumbai: {
name: 'Polygon (Matic) Mumbai Testnet',
id: 80_001,
currency: 'MATIC',
explorer: 'https://explorer-mumbai.maticvigil.com',
explorer: 'https://explorer-mumbai.maticvigil.com'
},
centoTestnet: {
name: 'Cento Testnet',
id: 740,
currency: 'CENTO',
explorer: 'https://testnet.explorer.cento.org',
explorer: 'https://testnet.explorer.cento.org'
},
avalancheFuji: {
name: 'Avalanche Fuji Testnet',
id: 43_113,
currency: 'AVAX',
explorer: 'https://explorer.fuji.avax.network',
explorer: 'https://explorer.fuji.avax.network'
},
fantomTestnet: {
name: 'Fantom Testnet',
id: 4002,
currency: 'FTM',
explorer: 'https://testnet.ftmscan.com',
explorer: 'https://testnet.ftmscan.com'
},
arbitrumGoerli: {
name: 'Arbitrum Görli Testnet',
id: 421_613,
currency: 'ETH',
explorer: 'https://goerli.arbiscan.io',
},
explorer: 'https://goerli.arbiscan.io'
}
} satisfies UnsupportedChains

export const chainNames = Object.keys(chains) as Array<Chain>

export const invalidResponse = {
chain: {
success: false,
data: `Invalid chain. Available chains: ${Object.keys(chains).join(', ')}`,
data: `Invalid chain. Available chains: ${Object.keys(chains).join(', ')}`
},
token: {
success: false,
data: 'Invalid token.',
},
data: 'Invalid token.'
}
}
12 changes: 10 additions & 2 deletions src/database/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,19 @@ import type { Chain, Pretty, Token } from '#/types'
import { Kysely } from 'kysely'
import { D1Dialect } from 'kysely-d1'

interface KvTable {
key: string
value: string
}

export type Database = {
[K in Chain]: Pretty<Token>
}

type GetDatabase = (database: Env['DB']) => Promise<Kysely<Database>>

export const getDatabase: GetDatabase = async (database) =>
new Kysely<Database>({ dialect: new D1Dialect({ database }) })
export const getDatabase: GetDatabase = async database =>
new Kysely<Database>({
// @ts-expect-error
dialect: new D1Dialect({ database })
})
33 changes: 16 additions & 17 deletions src/database/seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ export default {
await insertNewTokens({
chain: chain as Chain,
tokens: seedResult[chain as Chain],
database: env.DB,
database: env.DB
})
}
return new Response('ok', { status: 200 })
},
}
}

type SeedDataShape = {
Expand Down Expand Up @@ -65,7 +65,7 @@ export async function seed({ DB: database, TOKEN_LIST_URLS }: Env) {
symbol,
name,
decimals,
logoURI,
logoURI
})
}
const payloadsByChain = {} as Record<Chain, Array<Token>>
Expand All @@ -83,7 +83,7 @@ export async function seed({ DB: database, TOKEN_LIST_URLS }: Env) {
async function fetchTokenList(url: string) {
const response = await fetch(url)
if (!response.ok) throw new Error(`Failed to fetch tokenlist.json from ${url}`)
const json = await response.json<SeedDataShape>()
const json = (await response.json()) as SeedDataShape
console.log(`DONE -- fetched ${json.tokens.length} tokens from ${url}`)
return json.tokens
}
Expand All @@ -100,14 +100,14 @@ const folioChains = [
'moonbeam',
'optimism',
// 'polygon',
'harmony',
'harmony'
] as const
type FolioChain = typeof folioChains[number]
type FolioChain = (typeof folioChains)[number]

async function getTokensList(urls: Array<string>) {
const tokenLists = await Promise.all([...urls].map((url) => fetchTokenList(url)))
const tokenLists = await Promise.all([...urls].map(url => fetchTokenList(url)))
const reshapedTokenLists = await Promise.all(
folioChains.map((chain) => reshapeTokenList(chain as FolioChain))
folioChains.map(chain => reshapeTokenList(chain as FolioChain))
)
tokenLists.push(...reshapedTokenLists)
return tokenLists
Expand All @@ -119,21 +119,20 @@ async function reshapeTokenList(chain: FolioChain) {
`https://raw.githubusercontent.com/llamafolio/llamafolio-tokens/master/${chain}/tokenlist.json`
)
if (!response.ok) throw new Error('Failed to fetch token list')
const json = await response.json<
Array<{
address: string
name: string
symbol: string
decimals: number
}>
>()
const json = (await response.json()) as Array<{
address: string
name: string
symbol: string
decimals: number
}>

const tokens = json.map(({ address, ...token }) => ({
chainId: chains[chain].id,
address: address.toLowerCase(),
name: token.name,
symbol: token.symbol,
decimals: token.decimals,
logoURI: `https://raw.githubusercontent.com/llamafolio/llamafolio-tokens/master/${chain}/logos/${address.toLowerCase()}.png`,
logoURI: `https://raw.githubusercontent.com/llamafolio/llamafolio-tokens/master/${chain}/logos/${address.toLowerCase()}.png`
}))
console.log(`DONE -- fetched ${tokens.length} tokens from ${chain}`)
return tokens
Expand Down
Loading

0 comments on commit 8553acd

Please sign in to comment.