Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions tee-apps/sealed-bid-auction/script/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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,
Expand Down
8 changes: 3 additions & 5 deletions tee-apps/sealed-bid-auction/src/api/AuctionApiServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
12 changes: 6 additions & 6 deletions tee-apps/sealed-bid-auction/src/core/SolverPriceBook.ts
Original file line number Diff line number Diff line change
@@ -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<string, PriceBookEntry> = new Map<string, PriceBookEntry>();

constructor(private readonly priceListTTLseconds: number) {}
constructor(private readonly authService: AuthService, private readonly priceListTTLseconds: number) {}

public getCurrentPrices(): ImmutableList<PriceListItem[]> {
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)
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down