From 149697e2e113c8e3a9387e18e882a42635eb97b2 Mon Sep 17 00:00:00 2001 From: evchip Date: Tue, 16 Dec 2025 09:37:25 -0800 Subject: [PATCH 01/13] chore(v0.9.1): release metadata for v0.9.1 contract upgrades --- contracts/deployments/7683/v0.9.1.json | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 contracts/deployments/7683/v0.9.1.json diff --git a/contracts/deployments/7683/v0.9.1.json b/contracts/deployments/7683/v0.9.1.json new file mode 100644 index 00000000..924c3906 --- /dev/null +++ b/contracts/deployments/7683/v0.9.1.json @@ -0,0 +1,25 @@ +{ + "metadata": { + "version": "v0.9.1", + "date": "2025-12-16", + "by": "Evan", + "from_machine": "localhost", + "from_branch": "canary", + "from_commit": "0854f70f22cebab5ce34cb3a3c5a2b9ab8dadba9" + }, + "addresses": { + "arbitrum": { + "t1ProxyAdmin": "0xb45A6e9e6920A3bfa7Ac5D6783A060bc157DEC5b", + "t1ERC7683": { + "implementation": "0x8c5CD39DbFB5f265a8370f1D5943611F427217d8" + } + }, + "base": { + "t1ProxyAdmin": "0x1a209EA791e41Bd93a8f2f772CfA04949ECD1962", + "t1ERC7683": { + "implementation": "0x8c5CD39DbFB5f265a8370f1D5943611F427217d8" + } + }, + "deployerAddress": "0xfA004a3f114641FAeE326800f0266d719e9Fc9c3" + } +} From b16761122a1bda1661d0cbb8017d1d5c850557c4 Mon Sep 17 00:00:00 2001 From: evchip Date: Tue, 16 Dec 2025 09:51:45 -0800 Subject: [PATCH 02/13] chore(v0.9.1.json): update address for second upgrade on arbitrum --- contracts/deployments/7683/v0.9.1.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/deployments/7683/v0.9.1.json b/contracts/deployments/7683/v0.9.1.json index 924c3906..9ce05098 100644 --- a/contracts/deployments/7683/v0.9.1.json +++ b/contracts/deployments/7683/v0.9.1.json @@ -11,7 +11,7 @@ "arbitrum": { "t1ProxyAdmin": "0xb45A6e9e6920A3bfa7Ac5D6783A060bc157DEC5b", "t1ERC7683": { - "implementation": "0x8c5CD39DbFB5f265a8370f1D5943611F427217d8" + "implementation": "0x50645311C65Ee364aD37b54219d69FCBf7FF0759" } }, "base": { From c46640ee07b491f0fbd76977c0ebe142d3d5906c Mon Sep 17 00:00:00 2001 From: evchip Date: Wed, 17 Dec 2025 11:02:02 -0800 Subject: [PATCH 03/13] feat(sealed-bid-auction): add logic to capture historical event logs --- tee-apps/sealed-bid-auction/script/server.ts | 131 ++++++++++-------- .../src/blockchain/ViemIntentObserver.ts | 53 ++++++- 2 files changed, 124 insertions(+), 60 deletions(-) diff --git a/tee-apps/sealed-bid-auction/script/server.ts b/tee-apps/sealed-bid-auction/script/server.ts index 33c63d66..be51cb85 100644 --- a/tee-apps/sealed-bid-auction/script/server.ts +++ b/tee-apps/sealed-bid-auction/script/server.ts @@ -1,80 +1,97 @@ -import * as dotenv from "dotenv"; -import {AuctionApiServer} from "../src/api/AuctionApiServer.ts"; -import {ViemIntentObserver} from "../src/blockchain/ViemIntentObserver.ts"; -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 * as dotenv from "dotenv" +import { AuctionApiServer } from "../src/api/AuctionApiServer.ts" +import { ViemIntentObserver } from "../src/blockchain/ViemIntentObserver.ts" +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" -dotenv.config(); +dotenv.config() -const USE_TLS = process.env.USE_TLS as string === "true"; -const IS_MAINNET = process.env.IS_MAINNET as string === "true"; +const USE_TLS = (process.env.USE_TLS as string) === "true" +const IS_MAINNET = (process.env.IS_MAINNET as string) === "true" const SOLVER_PRICE_TTL_SECONDS = process.env.SOLVER_PRICE_TTL_SECONDS -const TEN_MINUTES_IN_SECONDS = 600; +const TEN_MINUTES_IN_SECONDS = 600 -const BASE_T1_ERC_7683_CONTRACT_ADDRESS = process.env.BASE_T1_ERC7683_CONTRACT_ADDRESS as `0x${string}`; -const ARBITRUM_T1_ERC_7683_CONTRACT_ADDRESS = process.env.ARBITRUM_T1_ERC7683_CONTRACT_ADDRESS as `0x${string}`; +const BASE_T1_ERC_7683_CONTRACT_ADDRESS = process.env + .BASE_T1_ERC7683_CONTRACT_ADDRESS as `0x${string}` +const ARBITRUM_T1_ERC_7683_CONTRACT_ADDRESS = process.env + .ARBITRUM_T1_ERC7683_CONTRACT_ADDRESS as `0x${string}` -const ARBITRUM_WS = (process.env.ARBITRUM_WS) as string; -const BASE_WS = (process.env.BASE_WS) as string; +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 auctionService = new AuctionService(solverPriceBook); +const solverPriceBook = new SolverPriceBook( + 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, auctionService) const arbitrumClient = new BlockchainClient( - ARBITRUM_WS, - IS_MAINNET ? arbitrum : arbitrumSepolia, - process.env.ARBITRUM_SIGNER_PRIVATE_KEY as `0x${string}` -); + ARBITRUM_WS, + IS_MAINNET ? arbitrum : arbitrumSepolia, + process.env.ARBITRUM_SIGNER_PRIVATE_KEY as `0x${string}` +) const baseClient = new BlockchainClient( - BASE_WS, - IS_MAINNET ? base : baseSepolia, - process.env.BASE_SIGNER_PRIVATE_KEY as `0x${string}` -); + BASE_WS, + IS_MAINNET ? base : baseSepolia, + process.env.BASE_SIGNER_PRIVATE_KEY as `0x${string}` +) + +const fromBlockEnv = process.env.INTENT_OBSERVER_FROM_BLOCK +const fromBlock = fromBlockEnv ? BigInt(fromBlockEnv) : null +const auctionPollingInterval = 500; + const arbitrumSepoliaIntentObserver = new ViemIntentObserver( - arbitrumClient, - ARBITRUM_T1_ERC_7683_CONTRACT_ADDRESS, - auctionService, - httpServer, - baseClient.publicClient.chain.id, - BASE_T1_ERC_7683_CONTRACT_ADDRESS -); + arbitrumClient, + ARBITRUM_T1_ERC_7683_CONTRACT_ADDRESS, + auctionService, + httpServer, + baseClient.publicClient.chain.id, + BASE_T1_ERC_7683_CONTRACT_ADDRESS, + auctionPollingInterval, + fromBlock +) const baseSepoliaIntentObserver = new ViemIntentObserver( - baseClient, - BASE_T1_ERC_7683_CONTRACT_ADDRESS, - auctionService, - httpServer, - arbitrumClient.publicClient.chain.id, - ARBITRUM_T1_ERC_7683_CONTRACT_ADDRESS -); + baseClient, + BASE_T1_ERC_7683_CONTRACT_ADDRESS, + auctionService, + httpServer, + arbitrumClient.publicClient.chain.id, + ARBITRUM_T1_ERC_7683_CONTRACT_ADDRESS, + auctionPollingInterval, + null +) async function main() { - console.log(`Starting ${IS_MAINNET ? 'mainnet' : 'testnet'} Sealed Bid API server...`); - await httpServer.start(Number(process.env.SERVER_PORT as string), USE_TLS); - arbitrumSepoliaIntentObserver.start(); - baseSepoliaIntentObserver.start(); + console.log( + `Starting ${IS_MAINNET ? "mainnet" : "testnet"} Sealed Bid API server...` + ) + await httpServer.start(Number(process.env.SERVER_PORT as string), USE_TLS) + arbitrumSepoliaIntentObserver.start() + baseSepoliaIntentObserver.start() } async function stopAll() { - await httpServer.stop(); + await httpServer.stop() } main() - .then() - .catch(async (error) => { - await stopAll(); - console.error("", error); - process.exit(1); - }); + .then() + .catch(async (error) => { + await stopAll() + console.error("", error) + process.exit(1) + }) process.on("SIGINT", async () => { - await stopAll(); - process.exit(0); -}); + await stopAll() + process.exit(0) +}) process.on("SIGTERM", async () => { - await stopAll(); - process.exit(0); -}); + await stopAll() + process.exit(0) +}) diff --git a/tee-apps/sealed-bid-auction/src/blockchain/ViemIntentObserver.ts b/tee-apps/sealed-bid-auction/src/blockchain/ViemIntentObserver.ts index 658208b2..b28ffd14 100644 --- a/tee-apps/sealed-bid-auction/src/blockchain/ViemIntentObserver.ts +++ b/tee-apps/sealed-bid-auction/src/blockchain/ViemIntentObserver.ts @@ -2,6 +2,7 @@ import { decodeAbiParameters, parseEventLogs, trim, + type Log, type WatchEventOnLogsParameter, } from "viem"; @@ -16,9 +17,11 @@ import { serialize, WinstonLogger } from "../utils/WinstonLogger.ts"; import type { BlockchainClient } from "./BlockchainClient.ts"; import type { AuctionResult } from "../api/types.ts"; +const HISTORICAL_BLOCK_CHUNK_SIZE = 100n; + export class ViemIntentObserver { private logger: WinstonLogger; - + constructor( private readonly sourceChainClient: BlockchainClient, private readonly sourceChainT1Erc7683ContractAddress: `0x${string}`, @@ -26,14 +29,23 @@ export class ViemIntentObserver { private readonly apiServer: AuctionApiServer, private readonly destinationChainId: number, private readonly destinationChainT1Erc7683ContractAddress: `0x${string}`, - private readonly auctionPollingInterval: number = 500 + private readonly auctionPollingInterval: number = 500, + private readonly fromBlock: bigint | null ) { this.logger = new WinstonLogger( `${ViemIntentObserver.name}[${this.sourceChainClient.publicClient.chain.name}]` ); } - public start() { + public async start() { + if (this.fromBlock !== null) { + await this.fetchHistoricalLogs(); + } + + this.startWatching(); + } + + private startWatching() { this.sourceChainClient.publicClient.watchEvent({ address: this.sourceChainT1Erc7683ContractAddress, event: OPEN_INTENT_ABI_EVENT, @@ -46,6 +58,41 @@ export class ViemIntentObserver { ); } + private async fetchHistoricalLogs() { + if (this.fromBlock === null) return; + + const currentBlock = await this.sourceChainClient.publicClient.getBlockNumber(); + this.logger.info( + `Fetching historical logs from block ${this.fromBlock} to ${currentBlock}` + ); + + let fromBlock = this.fromBlock; + + while (fromBlock <= currentBlock) { + const toBlock = fromBlock + HISTORICAL_BLOCK_CHUNK_SIZE - 1n > currentBlock + ? currentBlock + : fromBlock + HISTORICAL_BLOCK_CHUNK_SIZE - 1n; + + this.logger.info(`Fetching logs from block ${fromBlock} to ${toBlock}`); + + const logs = await this.sourceChainClient.publicClient.getLogs({ + address: this.sourceChainT1Erc7683ContractAddress, + event: OPEN_INTENT_ABI_EVENT, + fromBlock, + toBlock, + }); + + if (logs.length > 0) { + this.logger.info(`Found ${logs.length} historical logs in blocks ${fromBlock}-${toBlock}`); + await this.processIntentLogs(logs as unknown as WatchEventOnLogsParameter); + } + + fromBlock = toBlock + 1n; + } + + this.logger.info(`Finished fetching historical logs, caught up to block ${currentBlock}`); + } + private async processIntentLogs(logs: WatchEventOnLogsParameter) { this.logger.info("Intent was Open-ed!"); From 9c191092634fc8ee1d799f4a64bcb1ae65efd799 Mon Sep 17 00:00:00 2001 From: evchip Date: Wed, 17 Dec 2025 20:18:45 -0800 Subject: [PATCH 04/13] chore(v091): add proxy addresses of 7683 --- contracts/deployments/7683/v0.9.1.json | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/contracts/deployments/7683/v0.9.1.json b/contracts/deployments/7683/v0.9.1.json index 9ce05098..39341333 100644 --- a/contracts/deployments/7683/v0.9.1.json +++ b/contracts/deployments/7683/v0.9.1.json @@ -11,13 +11,15 @@ "arbitrum": { "t1ProxyAdmin": "0xb45A6e9e6920A3bfa7Ac5D6783A060bc157DEC5b", "t1ERC7683": { - "implementation": "0x50645311C65Ee364aD37b54219d69FCBf7FF0759" + "implementation": "0x50645311C65Ee364aD37b54219d69FCBf7FF0759", + "proxy": "0x996f3583BD967bbA19694733AA7A7623E6D780eb" } }, "base": { "t1ProxyAdmin": "0x1a209EA791e41Bd93a8f2f772CfA04949ECD1962", "t1ERC7683": { - "implementation": "0x8c5CD39DbFB5f265a8370f1D5943611F427217d8" + "implementation": "0x8c5CD39DbFB5f265a8370f1D5943611F427217d8", + "proxy": "0xdbA711a6c1b187479e9a5b33020E5217D0BD5A1f" } }, "deployerAddress": "0xfA004a3f114641FAeE326800f0266d719e9Fc9c3" From cfc13e0b844ca6cfa37e49161ac0268abd77db34 Mon Sep 17 00:00:00 2001 From: evchip Date: Thu, 18 Dec 2025 09:43:03 -0800 Subject: [PATCH 05/13] refactor(sealed-bid-auction): rewrite component to pass open event to solver --- tee-apps/sealed-bid-auction/src/api/types.ts | 13 +++++++++ .../src/blockchain/ViemIntentObserver.ts | 27 ++++++++++++++++--- 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/tee-apps/sealed-bid-auction/src/api/types.ts b/tee-apps/sealed-bid-auction/src/api/types.ts index b352444a..9b3c06d2 100644 --- a/tee-apps/sealed-bid-auction/src/api/types.ts +++ b/tee-apps/sealed-bid-auction/src/api/types.ts @@ -31,12 +31,25 @@ export interface AuctionQuote { timestamp: number; } +export interface OpenEventLog { + address: string; + topics: string[]; + data: string; + blockNumber: string; + transactionHash: string; + transactionIndex: string; + blockHash: string; + logIndex: string; + removed: boolean; +} + export interface AuctionResult { type: string; orderId: string; settlementReceiverAddress: string; amountOut: bigint; signature: string; + openEvent: OpenEventLog; } export interface AuthAttempt { diff --git a/tee-apps/sealed-bid-auction/src/blockchain/ViemIntentObserver.ts b/tee-apps/sealed-bid-auction/src/blockchain/ViemIntentObserver.ts index 658208b2..c6d055c0 100644 --- a/tee-apps/sealed-bid-auction/src/blockchain/ViemIntentObserver.ts +++ b/tee-apps/sealed-bid-auction/src/blockchain/ViemIntentObserver.ts @@ -14,7 +14,7 @@ import { import type { AuctionApiServer } from "../api/AuctionApiServer.ts"; import { serialize, WinstonLogger } from "../utils/WinstonLogger.ts"; import type { BlockchainClient } from "./BlockchainClient.ts"; -import type { AuctionResult } from "../api/types.ts"; +import type { AuctionResult, OpenEventLog } from "../api/types.ts"; export class ViemIntentObserver { private logger: WinstonLogger; @@ -54,7 +54,23 @@ export class ViemIntentObserver { logs, }); - for (const order of parsedLogs) { + for (let i = 0; i < parsedLogs.length; i++) { + const order = parsedLogs[i]; + const rawLog = logs[i]; + + // Convert raw log to eth_getLogs hex format for tokka-filler + const openEvent: OpenEventLog = { + address: rawLog.address, + topics: rawLog.topics as string[], + data: rawLog.data, + blockNumber: `0x${rawLog.blockNumber.toString(16)}`, + transactionHash: rawLog.transactionHash, + transactionIndex: `0x${rawLog.transactionIndex.toString(16)}`, + blockHash: rawLog.blockHash, + logIndex: `0x${rawLog.logIndex.toString(16)}`, + removed: rawLog.removed, + }; + for (const fillInstruction of order.args.resolvedOrder.fillInstructions) { const [decodedOrder] = decodeAbiParameters( ORDER_DATA_ABI_PARAMETERS_WRAPPED_IN_TUPLE, @@ -79,7 +95,8 @@ export class ViemIntentObserver { closedAuction: orderData.closedAuction, data: orderData.data, }, - order.args.orderId + order.args.orderId, + openEvent ); } } @@ -87,7 +104,8 @@ export class ViemIntentObserver { private async runAuctionAndNotifySolver( orderData: OrderData, - orderId: `0x${string}` + orderId: `0x${string}`, + openEvent: OpenEventLog ) { this.logger.info(`Running auction for order ${orderId}`); @@ -116,6 +134,7 @@ export class ViemIntentObserver { winningPrice.settlementReceiverAddress as `0x${string}`, winningPrice.amountOut ), + openEvent, }; await this.apiServer.notifySolvers( From ae2fa942d5235533108cbefef01cc2cb058a2762 Mon Sep 17 00:00:00 2001 From: evchip Date: Thu, 18 Dec 2025 11:16:49 -0800 Subject: [PATCH 06/13] refactor(sealed bid auction): add try catch block to auction call --- .../src/blockchain/ViemIntentObserver.ts | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/tee-apps/sealed-bid-auction/src/blockchain/ViemIntentObserver.ts b/tee-apps/sealed-bid-auction/src/blockchain/ViemIntentObserver.ts index 866f0a07..cd535d00 100644 --- a/tee-apps/sealed-bid-auction/src/blockchain/ViemIntentObserver.ts +++ b/tee-apps/sealed-bid-auction/src/blockchain/ViemIntentObserver.ts @@ -159,11 +159,17 @@ export class ViemIntentObserver { this.logger.debug(`Running auction for orderData ${serialize(orderData)}`); while (Date.now() / 1000 < orderData.fillDeadline) { - const winningPrice = this.auctionService.auction( - orderData.inputToken, - orderData.outputToken, - orderData.amountIn - ); + let winningPrice; + try { + winningPrice = this.auctionService.auction( + orderData.inputToken, + orderData.outputToken, + orderData.amountIn + ); + } catch (e) { + this.logger.error(`Auction error: ${e}`); + break; + } this.logger.debug(`Auction winner: ${serialize(winningPrice)}`); From 4869d69dcb84e4613b8ad6a1e083c5d73d244252 Mon Sep 17 00:00:00 2001 From: evchip Date: Thu, 18 Dec 2025 11:20:38 -0800 Subject: [PATCH 07/13] refactor(sealed bid auction): temp always trigger while loop --- .../sealed-bid-auction/src/blockchain/ViemIntentObserver.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tee-apps/sealed-bid-auction/src/blockchain/ViemIntentObserver.ts b/tee-apps/sealed-bid-auction/src/blockchain/ViemIntentObserver.ts index cd535d00..e59b3f7d 100644 --- a/tee-apps/sealed-bid-auction/src/blockchain/ViemIntentObserver.ts +++ b/tee-apps/sealed-bid-auction/src/blockchain/ViemIntentObserver.ts @@ -158,7 +158,7 @@ export class ViemIntentObserver { this.logger.debug(`Running auction for orderData ${serialize(orderData)}`); - while (Date.now() / 1000 < orderData.fillDeadline) { + while (0 < orderData.fillDeadline) { let winningPrice; try { winningPrice = this.auctionService.auction( From 099453feed279f9b50203ab9d87e9f5662dcb410 Mon Sep 17 00:00:00 2001 From: evchip Date: Thu, 18 Dec 2025 11:21:04 -0800 Subject: [PATCH 08/13] feat(sealed bid auction): add log for timeout --- tee-apps/sealed-bid-auction/src/blockchain/ViemIntentObserver.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/tee-apps/sealed-bid-auction/src/blockchain/ViemIntentObserver.ts b/tee-apps/sealed-bid-auction/src/blockchain/ViemIntentObserver.ts index e59b3f7d..ab53d2b1 100644 --- a/tee-apps/sealed-bid-auction/src/blockchain/ViemIntentObserver.ts +++ b/tee-apps/sealed-bid-auction/src/blockchain/ViemIntentObserver.ts @@ -205,6 +205,7 @@ export class ViemIntentObserver { setTimeout(resolve, this.auctionPollingInterval) ); } + this.logger.info(`Auction for order ${orderId} timed out`); } private async signAuctionResult( From da024410663577b69ba71d9bceb39596f69d1668 Mon Sep 17 00:00:00 2001 From: evchip Date: Thu, 18 Dec 2025 11:37:36 -0800 Subject: [PATCH 09/13] refactor(sealed bid app): rm temp debugging measures --- .../sealed-bid-auction/src/blockchain/ViemIntentObserver.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tee-apps/sealed-bid-auction/src/blockchain/ViemIntentObserver.ts b/tee-apps/sealed-bid-auction/src/blockchain/ViemIntentObserver.ts index ab53d2b1..cd535d00 100644 --- a/tee-apps/sealed-bid-auction/src/blockchain/ViemIntentObserver.ts +++ b/tee-apps/sealed-bid-auction/src/blockchain/ViemIntentObserver.ts @@ -158,7 +158,7 @@ export class ViemIntentObserver { this.logger.debug(`Running auction for orderData ${serialize(orderData)}`); - while (0 < orderData.fillDeadline) { + while (Date.now() / 1000 < orderData.fillDeadline) { let winningPrice; try { winningPrice = this.auctionService.auction( @@ -205,7 +205,6 @@ export class ViemIntentObserver { setTimeout(resolve, this.auctionPollingInterval) ); } - this.logger.info(`Auction for order ${orderId} timed out`); } private async signAuctionResult( From 6428afb2164d4e8eac0368fa959f7cf52b026e5d Mon Sep 17 00:00:00 2001 From: evchip Date: Thu, 18 Dec 2025 12:34:10 -0800 Subject: [PATCH 10/13] fix(sealed bid server.ts): unformat \& add arb / base specific from blocks --- tee-apps/sealed-bid-auction/script/server.ts | 136 +++++++++---------- 1 file changed, 65 insertions(+), 71 deletions(-) diff --git a/tee-apps/sealed-bid-auction/script/server.ts b/tee-apps/sealed-bid-auction/script/server.ts index be51cb85..d6093612 100644 --- a/tee-apps/sealed-bid-auction/script/server.ts +++ b/tee-apps/sealed-bid-auction/script/server.ts @@ -1,97 +1,91 @@ -import * as dotenv from "dotenv" -import { AuctionApiServer } from "../src/api/AuctionApiServer.ts" -import { ViemIntentObserver } from "../src/blockchain/ViemIntentObserver.ts" -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 * as dotenv from "dotenv"; +import {AuctionApiServer} from "../src/api/AuctionApiServer.ts"; +import {ViemIntentObserver} from "../src/blockchain/ViemIntentObserver.ts"; +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"; -dotenv.config() +dotenv.config(); -const USE_TLS = (process.env.USE_TLS as string) === "true" -const IS_MAINNET = (process.env.IS_MAINNET as string) === "true" +const USE_TLS = process.env.USE_TLS as string === "true"; +const IS_MAINNET = process.env.IS_MAINNET as string === "true"; const SOLVER_PRICE_TTL_SECONDS = process.env.SOLVER_PRICE_TTL_SECONDS -const TEN_MINUTES_IN_SECONDS = 600 +const TEN_MINUTES_IN_SECONDS = 600; -const BASE_T1_ERC_7683_CONTRACT_ADDRESS = process.env - .BASE_T1_ERC7683_CONTRACT_ADDRESS as `0x${string}` -const ARBITRUM_T1_ERC_7683_CONTRACT_ADDRESS = process.env - .ARBITRUM_T1_ERC7683_CONTRACT_ADDRESS as `0x${string}` +const BASE_T1_ERC_7683_CONTRACT_ADDRESS = process.env.BASE_T1_ERC7683_CONTRACT_ADDRESS as `0x${string}`; +const ARBITRUM_T1_ERC_7683_CONTRACT_ADDRESS = process.env.ARBITRUM_T1_ERC7683_CONTRACT_ADDRESS as `0x${string}`; -const ARBITRUM_WS = process.env.ARBITRUM_WS as string -const BASE_WS = process.env.BASE_WS as string +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 auctionService = new AuctionService(solverPriceBook) +const solverPriceBook = new SolverPriceBook(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, auctionService); const arbitrumClient = new BlockchainClient( - ARBITRUM_WS, - IS_MAINNET ? arbitrum : arbitrumSepolia, - process.env.ARBITRUM_SIGNER_PRIVATE_KEY as `0x${string}` -) + ARBITRUM_WS, + IS_MAINNET ? arbitrum : arbitrumSepolia, + process.env.ARBITRUM_SIGNER_PRIVATE_KEY as `0x${string}` +); const baseClient = new BlockchainClient( - BASE_WS, - IS_MAINNET ? base : baseSepolia, - process.env.BASE_SIGNER_PRIVATE_KEY as `0x${string}` -) + BASE_WS, + IS_MAINNET ? base : baseSepolia, + process.env.BASE_SIGNER_PRIVATE_KEY as `0x${string}` +); -const fromBlockEnv = process.env.INTENT_OBSERVER_FROM_BLOCK -const fromBlock = fromBlockEnv ? BigInt(fromBlockEnv) : null +const fromBlockEnvArbitrum = process.env.INTENT_OBSERVER_FROM_BLOCK_ARBITRUM; +const fromBlockArbitrum = fromBlockEnvArbitrum ? BigInt(fromBlockEnvArbitrum) : null; +const fromBlockEnvBase = process.env.INTENT_OBSERVER_FROM_BLOCK_BASE; +const fromBlockBase = fromBlockEnvBase ? BigInt(fromBlockEnvBase) : null; const auctionPollingInterval = 500; const arbitrumSepoliaIntentObserver = new ViemIntentObserver( - arbitrumClient, - ARBITRUM_T1_ERC_7683_CONTRACT_ADDRESS, - auctionService, - httpServer, - baseClient.publicClient.chain.id, - BASE_T1_ERC_7683_CONTRACT_ADDRESS, - auctionPollingInterval, - fromBlock -) + arbitrumClient, + ARBITRUM_T1_ERC_7683_CONTRACT_ADDRESS, + auctionService, + httpServer, + baseClient.publicClient.chain.id, + BASE_T1_ERC_7683_CONTRACT_ADDRESS, + auctionPollingInterval, + fromBlockArbitrum +); const baseSepoliaIntentObserver = new ViemIntentObserver( - baseClient, - BASE_T1_ERC_7683_CONTRACT_ADDRESS, - auctionService, - httpServer, - arbitrumClient.publicClient.chain.id, - ARBITRUM_T1_ERC_7683_CONTRACT_ADDRESS, - auctionPollingInterval, - null -) + baseClient, + BASE_T1_ERC_7683_CONTRACT_ADDRESS, + auctionService, + httpServer, + arbitrumClient.publicClient.chain.id, + ARBITRUM_T1_ERC_7683_CONTRACT_ADDRESS, + auctionPollingInterval, + fromBlockBase +); async function main() { - console.log( - `Starting ${IS_MAINNET ? "mainnet" : "testnet"} Sealed Bid API server...` - ) - await httpServer.start(Number(process.env.SERVER_PORT as string), USE_TLS) - arbitrumSepoliaIntentObserver.start() - baseSepoliaIntentObserver.start() + console.log(`Starting ${IS_MAINNET ? 'mainnet' : 'testnet'} Sealed Bid API server...`); + await httpServer.start(Number(process.env.SERVER_PORT as string), USE_TLS); + arbitrumSepoliaIntentObserver.start(); + baseSepoliaIntentObserver.start(); } async function stopAll() { - await httpServer.stop() + await httpServer.stop(); } main() - .then() - .catch(async (error) => { - await stopAll() - console.error("", error) - process.exit(1) - }) + .then() + .catch(async (error) => { + await stopAll(); + console.error("", error); + process.exit(1); + }); process.on("SIGINT", async () => { - await stopAll() - process.exit(0) -}) + await stopAll(); + process.exit(0); +}); process.on("SIGTERM", async () => { - await stopAll() - process.exit(0) -}) + await stopAll(); + process.exit(0); +}); \ No newline at end of file From ecfecd86aeee20240efa7940933ee19aa0606fdd Mon Sep 17 00:00:00 2001 From: evchip Date: Thu, 18 Dec 2025 12:36:39 -0800 Subject: [PATCH 11/13] docs(tee-apps): update docs according to setup --- tee-apps/intent-pauser/README.md | 3 ++- tee-apps/sealed-bid-auction/.env.template | 3 +++ tee-apps/sealed-bid-auction/README.md | 7 +++++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/tee-apps/intent-pauser/README.md b/tee-apps/intent-pauser/README.md index 631493c4..2c3c490b 100644 --- a/tee-apps/intent-pauser/README.md +++ b/tee-apps/intent-pauser/README.md @@ -11,8 +11,9 @@ bun install To configure: ```bash -cp .env.example .env +cp .env.template .env ``` + ... and fill in the values in `.env`. To run: diff --git a/tee-apps/sealed-bid-auction/.env.template b/tee-apps/sealed-bid-auction/.env.template index 959232f9..56cf86ac 100644 --- a/tee-apps/sealed-bid-auction/.env.template +++ b/tee-apps/sealed-bid-auction/.env.template @@ -7,6 +7,9 @@ SOLVER_PRICE_TTL_SECONDS=600 NEXT_NONCE_URL= IS_MAINNET=false +INTENT_OBSERVER_FROM_BLOCK_BASE= +INTENT_OBSERVER_FROM_BLOCK_ARBITRUM= + #Arbitrum ARBITRUM_WS= ARBITRUM_T1_ERC7683_CONTRACT_ADDRESS= diff --git a/tee-apps/sealed-bid-auction/README.md b/tee-apps/sealed-bid-auction/README.md index 68b89535..406d31ce 100644 --- a/tee-apps/sealed-bid-auction/README.md +++ b/tee-apps/sealed-bid-auction/README.md @@ -8,6 +8,13 @@ bun install ``` Save TLS key in `key.pem` and certificate in `cert.pem` . Consider using CloudFlare Origin Server Certificate (of course if you use CloudFlare) +To configure: + +```bash +cp .env.template .env +``` +... and fill in the values in `.env`. + ### To run: Start server: From 4870d64b29aabe0680dbbc907c30be92ecb7324c Mon Sep 17 00:00:00 2001 From: evchip Date: Thu, 18 Dec 2025 12:37:39 -0800 Subject: [PATCH 12/13] refactor(tee app): add empty line at bottom of server.ts --- tee-apps/sealed-bid-auction/script/server.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tee-apps/sealed-bid-auction/script/server.ts b/tee-apps/sealed-bid-auction/script/server.ts index d6093612..c6a45335 100644 --- a/tee-apps/sealed-bid-auction/script/server.ts +++ b/tee-apps/sealed-bid-auction/script/server.ts @@ -88,4 +88,4 @@ process.on("SIGINT", async () => { process.on("SIGTERM", async () => { await stopAll(); process.exit(0); -}); \ No newline at end of file +}); From dad7f81dd7a4b0dd3ed2ec1e451939ab3f1d13a4 Mon Sep 17 00:00:00 2001 From: evchip Date: Thu, 18 Dec 2025 12:42:17 -0800 Subject: [PATCH 13/13] docs(sealed bid app env): add description of from block env vars --- tee-apps/sealed-bid-auction/.env.template | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tee-apps/sealed-bid-auction/.env.template b/tee-apps/sealed-bid-auction/.env.template index 56cf86ac..50103748 100644 --- a/tee-apps/sealed-bid-auction/.env.template +++ b/tee-apps/sealed-bid-auction/.env.template @@ -7,6 +7,8 @@ SOLVER_PRICE_TTL_SECONDS=600 NEXT_NONCE_URL= IS_MAINNET=false +# optional from blocks for historical event logging +# these are useful if we miss events and want to rewind INTENT_OBSERVER_FROM_BLOCK_BASE= INTENT_OBSERVER_FROM_BLOCK_ARBITRUM=