symbol selection work
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -1,5 +1,6 @@
|
|||||||
/.env
|
/.env
|
||||||
version.json
|
/public/version.json
|
||||||
|
/public/metadata.json
|
||||||
|
|
||||||
### JetBrains template
|
### JetBrains template
|
||||||
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
|
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
{"t":[{"a":"0x2653aB60a6fD19d3e1f4E729412C219257CA6e24","n":"USD Coin (Arb1)","s":"USDC","d":6},{"a":"0xEaD55ce1cC577C8020F5FcE39D4e5C643F591a0c","n":"USD Coin","s":"USDC","d":6},{"a":"0x87b60276434d5cB5CE46d2316B596c7Bc5f87cCA","n":"Wrapped Ether","s":"WETH","d":18}],"p":[{"a":"0x0CB9B6A3Bd11c5b7378712AC9a9D71419ADE06AA","b":"0x87b60276434d5cB5CE46d2316B596c7Bc5f87cCA","q":"0xEaD55ce1cC577C8020F5FcE39D4e5C643F591a0c","f":500,"e":1,"d":12,"x":{"data":{"uri":"https://alpha.dexorder.trade/42161/0xC6962004f452bE9203591991D15f6b388e09E8D0/","inverted":false}}},{"a":"0xDE0C15b466b9A3720c27221C7465737fa46C4e96","b":"0x2653aB60a6fD19d3e1f4E729412C219257CA6e24","q":"0x87b60276434d5cB5CE46d2316B596c7Bc5f87cCA","f":500,"e":1,"d":-12,"x":{"data":{"uri":"https://alpha.dexorder.trade/42161/0xC31E54c7a869B9FcBEcc14363CF510d1c41fa443/","inverted":true}}}]}
|
|
||||||
@@ -33,18 +33,60 @@ const configurationData = {
|
|||||||
|
|
||||||
const tokenMap = {}
|
const tokenMap = {}
|
||||||
const poolMap = {}
|
const poolMap = {}
|
||||||
let symbols = null
|
let _symbols = null
|
||||||
|
|
||||||
const indexer = new FlexSearch.Document({
|
const indexer = new FlexSearch.Document({
|
||||||
document: {id: 'id', index: ['id', 'as[]', 'b', 'q', 'bs', 'qs', 'e', 'd']},
|
document: {id: 'id', index: ['id', 'as[]', 'b', 'q', 'bs', 'qs', 'e', 'd']}, // this must match what is generated for the index object in addSymbol()
|
||||||
charset: {split: /\W+/},
|
charset: {split: /\W+/},
|
||||||
tokenize: 'forward',
|
tokenize: 'forward',
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const indexes = {}
|
||||||
|
const symbolsSeen = {} // keyed by (base,quote) so we only list one pool per pair even if there are many fee tiers
|
||||||
|
|
||||||
|
function addSymbol(p, base, quote, inverted) {
|
||||||
|
const symbol = base.s + '/' + quote.s
|
||||||
|
const exchange = ['UNIv2', 'UNIv3'][p.e]
|
||||||
|
const full_name = exchange + ':' + symbol // + '%' + formatFee(fee)
|
||||||
|
if (full_name in symbolsSeen) {
|
||||||
|
// add this pool's address to the index but don't create a new symbol
|
||||||
|
indexes[full_name].as.push(p.a)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
symbolsSeen[full_name] = true
|
||||||
|
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, inverted,}
|
||||||
|
indexes[full_name] = {
|
||||||
|
// 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,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// function formatFee(fee) {
|
||||||
|
// let str = (fee / 10000).toFixed(2);
|
||||||
|
// if (str.startsWith('0')) // start with the decimal point not a zero
|
||||||
|
// str = str.slice(1)
|
||||||
|
// return str
|
||||||
|
// }
|
||||||
|
|
||||||
async function getAllSymbols() {
|
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) {
|
if (_symbols===null) {
|
||||||
symbols = {}
|
_symbols = {}
|
||||||
for (const t of metadata.t)
|
for (const t of metadata.t)
|
||||||
tokenMap[t.a] = t
|
tokenMap[t.a] = t
|
||||||
metadata.p.forEach((p)=>{
|
metadata.p.forEach((p)=>{
|
||||||
@@ -60,39 +102,14 @@ async function getAllSymbols() {
|
|||||||
console.log(`No token ${p.q} found`)
|
console.log(`No token ${p.q} found`)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
const symbol = base.s + '/' + quote.s
|
addSymbol(p, base, quote, false);
|
||||||
const exchange = ['UNIv2','UNIv3'][p.e]
|
addSymbol(p, quote, base, true);
|
||||||
const full_name = exchange+':'+symbol
|
|
||||||
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 type = 'swap'
|
|
||||||
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)) {
|
console.log('indexes', indexes)
|
||||||
indexer.add(symbol.index)
|
Object.values(indexes).forEach(indexer.add.bind(indexer))
|
||||||
}
|
}
|
||||||
}
|
console.log('symbols', _symbols)
|
||||||
return Object.values(symbols)
|
return _symbols
|
||||||
}
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
@@ -132,7 +149,7 @@ export default {
|
|||||||
const result = []
|
const result = []
|
||||||
for (const f of found)
|
for (const f of found)
|
||||||
for (const key of f.result)
|
for (const key of f.result)
|
||||||
result.push(symbols[key])
|
result.push(_symbols[key])
|
||||||
onResultReadyCallback(result);
|
onResultReadyCallback(result);
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -145,6 +162,7 @@ export default {
|
|||||||
console.log('[resolveSymbol]: Method call', symbolName);
|
console.log('[resolveSymbol]: Method call', symbolName);
|
||||||
const symbols = await getAllSymbols();
|
const symbols = await getAllSymbols();
|
||||||
const symbolItem = symbols[symbolName]
|
const symbolItem = symbols[symbolName]
|
||||||
|
console.log('symbol resolved?', symbolItem)
|
||||||
if (!symbolItem) {
|
if (!symbolItem) {
|
||||||
console.log('[resolveSymbol]: Cannot resolve symbol', symbolName);
|
console.log('[resolveSymbol]: Cannot resolve symbol', symbolName);
|
||||||
onResolveErrorCallback('cannot resolve symbol');
|
onResolveErrorCallback('cannot resolve symbol');
|
||||||
|
|||||||
@@ -2,5 +2,6 @@ const versionPromise = fetch('/version.json').then(async (response)=>await respo
|
|||||||
const metadataPromise = fetch('/metadata.json').then(async (response)=>await response.json())
|
const metadataPromise = fetch('/metadata.json').then(async (response)=>await response.json())
|
||||||
|
|
||||||
export const version = await versionPromise
|
export const version = await versionPromise
|
||||||
export const metadata = await metadataPromise
|
|
||||||
console.log('version', version)
|
console.log('version', version)
|
||||||
|
export const metadata = await metadataPromise
|
||||||
|
console.log('metadata', metadata)
|
||||||
|
|||||||
Reference in New Issue
Block a user