function _json(name) {
    return async function(response) {
        try {
            return await response.json()
        }
        catch (e) {
            console.error(`could not read ${name}`)
            return null
        }
    }
}

const versionPromise = fetch('/version.json').then(_json('version.json'))
const metadataPromise = fetch('/metadata.json').then(_json('metadata.json'))

export const version = await versionPromise
console.log('version', version)
export const metadata = await metadataPromise
console.log('metadata', metadata)

export const metadataMap = {}
for (const [chain, info] of Object.entries(metadata)) {
    const map = {}
    for (const poolMeta of info.p)
        map[poolMeta.a] = poolMeta
    for (const tokenMeta of info.t)
        map[tokenMeta.a] = tokenMeta
    metadataMap[chain] = map
}
console.log('metadataMap', metadataMap)
