Skip to content

Commit 5f8106b

Browse files
authored
Feat/sealed bid auction/only accept prices from connected solvers (#229)
1 parent 35b57c5 commit 5f8106b

4 files changed

Lines changed: 17 additions & 15 deletions

File tree

tee-apps/sealed-bid-auction/script/server.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {SolverPriceBook} from "../src/core/SolverPriceBook.ts";
55
import {AuctionService} from "../src/core/AuctionService.ts";
66
import {arbitrum, arbitrumSepolia, base, baseSepolia} from "viem/chains";
77
import {BlockchainClient} from "../src/blockchain/BlockchainClient.ts";
8+
import { AuthService } from "../src/core/AuthService.ts";
89

910
dotenv.config();
1011

@@ -19,10 +20,11 @@ const ARBITRUM_T1_ERC_7683_CONTRACT_ADDRESS = process.env.ARBITRUM_T1_ERC7683_CO
1920
const ARBITRUM_WS = (process.env.ARBITRUM_WS) as string;
2021
const BASE_WS = (process.env.BASE_WS) as string;
2122

22-
const solverPriceBook = new SolverPriceBook(SOLVER_PRICE_TTL_SECONDS ? Number(SOLVER_PRICE_TTL_SECONDS as string) : TEN_MINUTES_IN_SECONDS);
23+
const authService = new AuthService();
24+
const solverPriceBook = new SolverPriceBook(authService, SOLVER_PRICE_TTL_SECONDS ? Number(SOLVER_PRICE_TTL_SECONDS as string) : TEN_MINUTES_IN_SECONDS);
2325
const auctionService = new AuctionService(solverPriceBook);
2426

25-
const httpServer = new AuctionApiServer(solverPriceBook, auctionService);
27+
const httpServer = new AuctionApiServer(solverPriceBook, authService, auctionService);
2628
const arbitrumClient = new BlockchainClient(
2729
ARBITRUM_WS,
2830
IS_MAINNET ? arbitrum : arbitrumSepolia,

tee-apps/sealed-bid-auction/src/api/AuctionApiServer.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,15 @@ export class AuctionApiServer {
2020
private readonly auctionController;
2121
private readonly authController;
2222

23-
private readonly authService;
24-
2523
private server: Server | null = null;
2624

2725
public constructor(
2826
private readonly solverPriceBook: SolverPriceBook,
29-
auctionService: AuctionService
27+
private readonly authService: AuthService,
28+
auctionService: AuctionService,
3029
) {
3130
this.auctionController = new AuctionController(auctionService);
32-
this.authService = new AuthService();
33-
this.authController = new AuthController(this.authService);
31+
this.authController = new AuthController(authService);
3432
}
3533

3634
public async start(port: number, tls: boolean) {

tee-apps/sealed-bid-auction/src/core/SolverPriceBook.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
import { List as ImmutableList } from 'immutable';
22

33
import {type Interval, type PriceListItem} from "./types.ts";
4+
import type { AuthService } from "./AuthService.ts";
45

56
type PriceBookEntry = {
67
timestamp: number;
78
priceList: PriceListItem[];
89
}
910

10-
const TEN_MINUTES_IN_MS = 600_000;
11-
1211
export class SolverPriceBook {
1312
private prices: Map<string, PriceBookEntry> = new Map<string, PriceBookEntry>();
1413

15-
constructor(private readonly priceListTTLseconds: number) {}
14+
constructor(private readonly authService: AuthService, private readonly priceListTTLseconds: number) {}
1615

1716
public getCurrentPrices(): ImmutableList<PriceListItem[]> {
1817
return ImmutableList(
19-
this.prices.entries().toArray()
20-
.filter(([_key, value]) => value.timestamp + (this.priceListTTLseconds * 1000) > Date.now())
21-
.map(([_key, value]) => value.priceList)
18+
this.prices.values().toArray()
19+
.filter((priceBookEntry) => priceBookEntry.timestamp + (this.priceListTTLseconds * 1000) > Date.now())
20+
.filter((priceBookEntry) => this.authService.isLoggedIn(priceBookEntry.priceList[0]!.settlementReceiverAddress))
21+
.map((priceBookEntry) => priceBookEntry.priceList)
2222
);
2323
}
2424

tee-apps/sealed-bid-auction/test/Websocket.integration.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@ import {PRICE_LIST_WITH_GAP_IN_RANGES, USERNAME, PRICE_LIST_WITH_TWO_ITEMS, PRIV
55
import {SolverPriceBook} from "../src/core/SolverPriceBook.ts";
66
import {AuctionService} from "../src/core/AuctionService.ts";
77
import {signMessage} from "viem/accounts";
8+
import { AuthService } from "../src/core/AuthService.ts";
89

910
const wsPort = 3080;
10-
const solverPriceBook = new SolverPriceBook();
11-
const httpServer = new AuctionApiServer(solverPriceBook, new AuctionService(solverPriceBook));
11+
const authService = new AuthService();
12+
const solverPriceBook = new SolverPriceBook(authService, 600);
13+
const httpServer = new AuctionApiServer(solverPriceBook, authService, new AuctionService(solverPriceBook));
1214
let socketClosed = true;
1315
let socket: WebSocket;
1416
let socketMessage: string | null;

0 commit comments

Comments
 (0)