diff --git a/tee-apps/sealed-bid-auction/script/server.ts b/tee-apps/sealed-bid-auction/script/server.ts index c6a45335..5e3a845b 100644 --- a/tee-apps/sealed-bid-auction/script/server.ts +++ b/tee-apps/sealed-bid-auction/script/server.ts @@ -5,6 +5,7 @@ import {SolverPriceBook} from "../src/core/SolverPriceBook.ts"; import {AuctionService} from "../src/core/AuctionService.ts"; import {arbitrum, arbitrumSepolia, base, baseSepolia} from "viem/chains"; import {BlockchainClient} from "../src/blockchain/BlockchainClient.ts"; +import { AuthService } from "../src/core/AuthService.ts"; dotenv.config(); @@ -19,10 +20,11 @@ const ARBITRUM_T1_ERC_7683_CONTRACT_ADDRESS = process.env.ARBITRUM_T1_ERC7683_CO const ARBITRUM_WS = (process.env.ARBITRUM_WS) as string; const BASE_WS = (process.env.BASE_WS) as string; -const solverPriceBook = new SolverPriceBook(SOLVER_PRICE_TTL_SECONDS ? Number(SOLVER_PRICE_TTL_SECONDS as string) : TEN_MINUTES_IN_SECONDS); +const authService = new AuthService(); +const solverPriceBook = new SolverPriceBook(authService, SOLVER_PRICE_TTL_SECONDS ? Number(SOLVER_PRICE_TTL_SECONDS as string) : TEN_MINUTES_IN_SECONDS); const auctionService = new AuctionService(solverPriceBook); -const httpServer = new AuctionApiServer(solverPriceBook, auctionService); +const httpServer = new AuctionApiServer(solverPriceBook, authService, auctionService); const arbitrumClient = new BlockchainClient( ARBITRUM_WS, IS_MAINNET ? arbitrum : arbitrumSepolia, diff --git a/tee-apps/sealed-bid-auction/src/api/AuctionApiServer.ts b/tee-apps/sealed-bid-auction/src/api/AuctionApiServer.ts index 0763aabc..92bf9572 100644 --- a/tee-apps/sealed-bid-auction/src/api/AuctionApiServer.ts +++ b/tee-apps/sealed-bid-auction/src/api/AuctionApiServer.ts @@ -20,17 +20,15 @@ export class AuctionApiServer { private readonly auctionController; private readonly authController; - private readonly authService; - private server: Server | null = null; public constructor( private readonly solverPriceBook: SolverPriceBook, - auctionService: AuctionService + private readonly authService: AuthService, + auctionService: AuctionService, ) { this.auctionController = new AuctionController(auctionService); - this.authService = new AuthService(); - this.authController = new AuthController(this.authService); + this.authController = new AuthController(authService); } public async start(port: number, tls: boolean) { diff --git a/tee-apps/sealed-bid-auction/src/core/SolverPriceBook.ts b/tee-apps/sealed-bid-auction/src/core/SolverPriceBook.ts index e7d6ef49..b8ed00a9 100644 --- a/tee-apps/sealed-bid-auction/src/core/SolverPriceBook.ts +++ b/tee-apps/sealed-bid-auction/src/core/SolverPriceBook.ts @@ -1,24 +1,24 @@ import { List as ImmutableList } from 'immutable'; import {type Interval, type PriceListItem} from "./types.ts"; +import type { AuthService } from "./AuthService.ts"; type PriceBookEntry = { timestamp: number; priceList: PriceListItem[]; } -const TEN_MINUTES_IN_MS = 600_000; - export class SolverPriceBook { private prices: Map = new Map(); - constructor(private readonly priceListTTLseconds: number) {} + constructor(private readonly authService: AuthService, private readonly priceListTTLseconds: number) {} public getCurrentPrices(): ImmutableList { return ImmutableList( - this.prices.entries().toArray() - .filter(([_key, value]) => value.timestamp + (this.priceListTTLseconds * 1000) > Date.now()) - .map(([_key, value]) => value.priceList) + this.prices.values().toArray() + .filter((priceBookEntry) => priceBookEntry.timestamp + (this.priceListTTLseconds * 1000) > Date.now()) + .filter((priceBookEntry) => this.authService.isLoggedIn(priceBookEntry.priceList[0]!.settlementReceiverAddress)) + .map((priceBookEntry) => priceBookEntry.priceList) ); } diff --git a/tee-apps/sealed-bid-auction/test/Websocket.integration.test.ts b/tee-apps/sealed-bid-auction/test/Websocket.integration.test.ts index 47d93fb9..138f54ea 100644 --- a/tee-apps/sealed-bid-auction/test/Websocket.integration.test.ts +++ b/tee-apps/sealed-bid-auction/test/Websocket.integration.test.ts @@ -5,10 +5,12 @@ import {PRICE_LIST_WITH_GAP_IN_RANGES, USERNAME, PRICE_LIST_WITH_TWO_ITEMS, PRIV import {SolverPriceBook} from "../src/core/SolverPriceBook.ts"; import {AuctionService} from "../src/core/AuctionService.ts"; import {signMessage} from "viem/accounts"; +import { AuthService } from "../src/core/AuthService.ts"; const wsPort = 3080; -const solverPriceBook = new SolverPriceBook(); -const httpServer = new AuctionApiServer(solverPriceBook, new AuctionService(solverPriceBook)); +const authService = new AuthService(); +const solverPriceBook = new SolverPriceBook(authService, 600); +const httpServer = new AuctionApiServer(solverPriceBook, authService, new AuctionService(solverPriceBook)); let socketClosed = true; let socket: WebSocket; let socketMessage: string | null;