USD marks

This commit is contained in:
tim
2025-03-29 15:27:13 -04:00
parent 1a3638a087
commit 0b29539e0a
3 changed files with 18 additions and 0 deletions

View File

@@ -37,6 +37,10 @@ export class CacheDict {
async contains(chain, key) {
return await redis.hExists(`${chain}|${this.series}`, key)
}
async items(chain) {
return Object.entries(await redis.hGetAll(`${chain}|${this.series}`)).map(([k, v]) => [k, v === null ? null : '' + v])
}
}
@@ -83,3 +87,4 @@ export const vaultOpenOrders = new CacheDict('voo')
export const vaultRecentlyClosedOrders = new CacheDict('vrco')
export const orderFilled = new CacheDict('of')
export const ohlcs = new CacheDict('ohlc')
export const marks = new CacheDict('mark.usd')

View File

@@ -1,4 +1,15 @@
import fs from "fs";
import {marks} from "./cache.js";
export const chainInfo = JSON.parse(fs.readFileSync('../contract/version.json')).chainInfo
console.log('chainInfo', chainInfo)
export async function joinChain( socket, chainId ) {
if (socket.chainId)
socket.leave(socket.chainId)
socket.join(chainId)
socket.chainId = chainId
const items = await marks.items(chainId);
for (let [token,mark] of items)
socket.emit('mark.usd', chainId, token, mark)
}

View File

@@ -4,6 +4,7 @@ import {requestVault, loginAddress} from "./vault.js";
import {subOHLCs, subPools, unsubOHLCs, unsubPools} from "./pool.js";
import {gib} from "./faucet.js";
import {approveRegion, approveTOS} from "./approval.js";
import {joinChain} from "./chain.js";
// Server route handling
@@ -21,6 +22,7 @@ export function initIO() {
socket.on('gib', async (chainId, owner, vault, tokenAmounts) => await gib(chainId, owner, vault, tokenAmounts))
socket.on('approveTOS', (time, version, callback) => approveTOS(socket, time, version, callback))
socket.on('approveRegion', (bypass) => approveRegion(socket, bypass))
socket.on('chain', async (chainId) => await joinChain(socket, chainId))
socket.join('public')
});
}