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
12 changes: 4 additions & 8 deletions tee-apps/sealed-bid-auction/.env.template
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,18 @@
LOG_LEVEL=info
SERVER_PORT=
WS_URL=
USE_TLS=true
SOLVER_PRICE_TTL_SECONDS=
USE_TLS=false
SOLVER_PRICE_TTL_SECONDS=600
NEXT_NONCE_URL=
IS_MAINNET=false

#Arbitrum
ARBITRUM_RPC=https://arb1.arbitrum.io/rpc
ARBITRUM_SEPOLIA_RPC=https://arbitrum-sepolia-rpc.publicnode.com
ARBITRUM_SEPOLIA_POLLING_INTERVAL_MS=500
ARBITRUM_WS=
ARBITRUM_T1_ERC7683_CONTRACT_ADDRESS=
ARBITRUM_SIGNER_PRIVATE_KEY=

#Base
BASE_RPC=https://base-rpc.publicnode.com
BASE_SEPOLIA_RPC=https://base-sepolia-rpc.publicnode.com
BASE_SEPOLIA_POLLING_INTERVAL_MS=2000
BASE_WS=
BASE_T1_ERC7683_CONTRACT_ADDRESS=
BASE_SIGNER_PRIVATE_KEY=

Expand Down
15 changes: 6 additions & 9 deletions tee-apps/sealed-bid-auction/script/server.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import * as dotenv from "dotenv";

dotenv.config();

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();

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
Expand All @@ -17,23 +16,21 @@ 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 ARBITRUM_RPC = (IS_MAINNET ? process.env.ARBITRUM_MAINNET_RPC : process.env.ARBITRUM_SEPOLIA_RPC) as string;
const BASE_RPC = (IS_MAINNET ? process.env.BASE_MAINNET_RPC : process.env.BASE_SEPOLIA_RPC) 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 httpServer = new AuctionApiServer(solverPriceBook, auctionService);
const arbitrumClient = new BlockchainClient(
ARBITRUM_RPC,
ARBITRUM_WS,
IS_MAINNET ? arbitrum : arbitrumSepolia,
Number(process.env.ARBITRUM_SEPOLIA_POLLING_INTERVAL_MS as string),
process.env.ARBITRUM_SIGNER_PRIVATE_KEY as `0x${string}`
);
const baseClient = new BlockchainClient(
BASE_RPC,
BASE_WS,
IS_MAINNET ? base : baseSepolia,
Number(process.env.BASE_SEPOLIA_POLLING_INTERVAL_MS as string),
process.env.BASE_SIGNER_PRIVATE_KEY as `0x${string}`
);
const arbitrumSepoliaIntentObserver = new ViemIntentObserver(
Expand Down
115 changes: 49 additions & 66 deletions tee-apps/sealed-bid-auction/src/blockchain/BlockchainClient.ts
Original file line number Diff line number Diff line change
@@ -1,78 +1,61 @@
import { type Chain, createPublicClient, createWalletClient, http } from "viem";
import { privateKeyToAccount } from "viem/accounts";
import {type Chain, createPublicClient, webSocket} from "viem";
import {privateKeyToAccount} from "viem/accounts";

export class BlockchainClient {
private _publicClient;
private _walletClient;

public constructor(
rpcUrl: string,
chain: Chain,
pollingInterval: number,
private readonly signerKey?: `0x${string}`
) {
this._publicClient = createPublicClient({
chain,
transport: http(rpcUrl),
pollingInterval,
});

if (signerKey) {
const account = privateKeyToAccount(signerKey);

this._walletClient = createWalletClient({
account,
chain: chain,
transport: http(rpcUrl),
});
private _publicClient;

public constructor(
wsUrl: string,
chain: Chain,
private readonly signerKey?: `0x${string}`,
) {
this._publicClient = createPublicClient({
chain: chain,
transport: webSocket(wsUrl, {
reconnect: true,
keepAlive: true,
retryDelay: 1000,
}),
});
}
}

public get publicClient() {
return this._publicClient;
}

public get walletClient() {
if (!this._walletClient) {
throw new Error("Wallet client not initialised!");
public get publicClient() {
return this._publicClient;
}

return this._walletClient;
}
public async signMessage(message: string): Promise<`0x${string}`> {
if (!this.signerKey) {
throw new Error("Signer key not initialised!");
}

public async signMessage(message: string): Promise<`0x${string}`> {
if (!this.signerKey) {
throw new Error("Signer key not initialised!");
}
const account = privateKeyToAccount(this.signerKey);

const account = privateKeyToAccount(this.signerKey);

return await account.signMessage({
message,
});
}

public async signTypedData(
domain: Record<string, any>,
types: Record<string, any>,
message: Record<string, any>
): Promise<`0x${string}`> {
if (!this.signerKey) {
throw new Error("Signer key not initialised!");
return await account.signMessage({
message,
});
}

const account = privateKeyToAccount(this.signerKey);

const primaryType = Object.keys(types)[0];
if (!primaryType) {
throw new Error("No types provided for EIP-712 signing");
public async signTypedData(
domain: Record<string, any>,
types: Record<string, any>,
message: Record<string, any>
): Promise<`0x${string}`> {
if (!this.signerKey) {
throw new Error("Signer key not initialised!");
}

const account = privateKeyToAccount(this.signerKey);

const primaryType = Object.keys(types)[0];
if (!primaryType) {
throw new Error("No types provided for EIP-712 signing");
}

return await account.signTypedData({
domain,
types,
primaryType,
message,
});
}

return await account.signTypedData({
domain,
types,
primaryType,
message,
});
}
}