This commit is contained in:
Tim
2024-01-23 01:32:44 -04:00
parent 0e5a4bac6d
commit ee021c9590
6 changed files with 63 additions and 3 deletions

48
src/blockchain/ohlcs.js Normal file
View File

@@ -0,0 +1,48 @@
import {socket} from "@/socket.js";
import {useStore} from "@/store/store.js";
import {Exchange} from "@/blockchain/orderlib.js";
import {uniswapV3PoolAddress} from "@/blockchain/uniswap.js";
import {ethers, FixedNumber} from "ethers";
import {uniswapV3PoolAbi} from "@/blockchain/abi.js";
const ohlcSubCounts = {} // key is route and value is a subscription counter
export const WIDE_PRICE_FORMAT = {decimals:38, width:512, signed:false}; // 38 decimals is 127 bits
export function subOHLCs( chainId, poolPeriods ) {
if( !poolPeriods.length )
return
const toSub = []
for( const [pool,period] of poolPeriods ) {
const key = `${pool}|${period}`
if (!(key in ohlcSubCounts) || ohlcSubCounts[key] === 0) {
ohlcSubCounts[key] = 1
toSub.push(key)
} else {
ohlcSubCounts[key]++
}
}
if( toSub.length )
socket.emit('subOHLCs', chainId, toSub)
}
export function unsubPrices( chainId, poolPeriods ) {
const toUnsub = []
for( const [pool,period] of poolPeriods ) {
const key = `${pool}|${period}`
if (!(key in ohlcSubCounts) || ohlcSubCounts[key] === 0) {
console.error('overdecremented',pool,period)
ohlcSubCounts[key] = 1
toSub.push(key)
} else {
ohlcSubCounts[key]--
if( ohlcSubCounts[key] == 0 )
toUnsub.push(key)
}
}
if( toUnsub.length )
socket.emit('unsubOHLCs', chainId, toUnsub )
}
// todo get history