diff --git a/src/charts/datafeed.js b/src/charts/datafeed.js index fa201f4..a27d938 100644 --- a/src/charts/datafeed.js +++ b/src/charts/datafeed.js @@ -35,7 +35,7 @@ const tokenMap = {} const poolMap = {} let symbols = null const indexer = new FlexSearch.Document({ - document: {id: 'id', index: ['id', 'a', 'b', 'q', 'bs', 'qs', 'e', 'd']}, + document: {id: 'id', index: ['id', 'as[]', 'b', 'q', 'bs', 'qs', 'e', 'd']}, charset: {split: /\W+/}, tokenize: 'forward', }) @@ -45,45 +45,52 @@ async function getAllSymbols() { const built = {} // keyed by (base,quote) so we only list one pool per pair even if there are many fee tiers if (symbols===null) { symbols = {} - for (const t of metadata['t']) - tokenMap[t['a']] = t - metadata['p'].forEach((p)=>{ - poolMap[p['a']] = p + for (const t of metadata.t) + tokenMap[t.a] = t + metadata.p.forEach((p)=>{ + poolMap[p.a] = p // todo inversion - const base = tokenMap[p['b']]; - const quote = tokenMap[p['q']]; + const base = tokenMap[p.b]; + const quote = tokenMap[p.q]; if (!base) { - console.log(`No token ${p['b']} found`) + console.log(`No token ${p.b} found`) return } if (!quote) { - console.log(`No token ${p['q']} found`) + console.log(`No token ${p.q} found`) return } - const symbol = base['s'] + '/' + quote['s'] - const exchange = ['UNIv2','UNIv3'][p['e']] + const symbol = base.s + '/' + quote.s + const exchange = ['UNIv2','UNIv3'][p.e] const full_name = exchange+':'+symbol - if (full_name in built) + if (full_name in built) { + // add this pool's address to the index but don't create a new symbol + symbols[full_name].index.as.push(p.a) return + } built[full_name] = true - const longExchange = ['Uniswap v2', 'Uniswap v3',][p['e']] - const description = `${base['n']} / ${quote['n']}` + const longExchange = ['Uniswap v2', 'Uniswap v3',][p.e] + const description = `${base.n} / ${quote.n}` const type = 'swap' - symbols[full_name] = {symbol, full_name, description, exchange, type,} - indexer.add({ - // key - id: full_name, - // addresses - a: p['a'], - b: p['b'], - q: p['q'], - // symbols - bs: base['s'], - qs: quote['s'], - e: exchange, - d: description, - }) + symbols[full_name] = {symbol, full_name, description, exchange, type, + index: { + // key + id: full_name, + // addresses + as: [p.a], // multiple pool addrs for each fee tier + b: p.b, + q: p.q, + // symbols + bs: base.s, + qs: quote.s, + e: exchange, + d: description, + } + } }) + for (const symbol of Object.values(symbols)) { + indexer.add(symbol.index) + } } return Object.values(symbols) }