Skip to content

Commit 2f50d49

Browse files
Jason-W123claude
andcommitted
chore(timeboost): drop dead code, dedupe tx helpers, simplify no-bid path
- Remove 7 setXxxLogger setters (never called) and switch `let log` → `const log`. - Drop dead exports: DOCS_DEFAULT_TIMING, currentRoundFor, roundStartTimestamp, waitForNextRound, bigintToRpcHex, partialObservationForExpressLane, TimeboostRuntime, ConditionalOptions. - Remove 3 `void X` suppressions and their unused imports. - Merge sendNativeEth + sendCall in timeboostDemoRunner into one signAndSend. - Export submitNormalTx + completeObservation; reuse them in the no-bid round path instead of hand-rolling nonce/gas/sign/receipt/timeboosted extraction. - Drop unused walletClient field from DeployContractsInput and its caller. Net -195 lines across 12 timeboost files; tsc + prettier clean. No behaviour change. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent b5015f3 commit 2f50d49

12 files changed

Lines changed: 52 additions & 247 deletions

src/playbooks/timeboost/auctionMonitor.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,16 @@
1212
* for the HTML report.
1313
*/
1414

15-
import { type Address, type Hash, type PublicClient, decodeEventLog, parseAbi } from 'viem';
15+
import { type Address, type Hash, type PublicClient, decodeEventLog } from 'viem';
1616
import { expressLaneAuctionArtifact } from './abis.js';
1717
import type { AuctionEvent } from './types.js';
1818

19-
let log = {
19+
const log = {
2020
info: (m: string) => console.log('ℹ', m),
2121
warn: (m: string) => console.log('⚠', m),
2222
event: (m: string) => console.log('•', m),
2323
};
2424

25-
export function setAuctionMonitorLogger(l: typeof log): void {
26-
log = l;
27-
}
28-
2925
export interface AuctionMonitorHandle {
3026
events: AuctionEvent[];
3127
stop: () => void;
@@ -142,6 +138,3 @@ function jsonReplacer(_key: string, v: unknown): unknown {
142138
if (typeof v === 'bigint') return v.toString();
143139
return v;
144140
}
145-
146-
// Suppress unused-import warning for parseAbi (kept available for future use).
147-
void parseAbi;

src/playbooks/timeboost/auctionRunner.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,13 @@ import { approveAndDeposit, submitBid, type SubmittedBid } from './bidder.js';
1717
import { snapshotRound, formatRoundLine, waitUntilRound, type RoundTiming } from './roundClock.js';
1818
import type { AuctionEvent } from './types.js';
1919

20-
let log = {
20+
const log = {
2121
info: (m: string) => console.log('ℹ', m),
2222
warn: (m: string) => console.log('⚠', m),
2323
success: (m: string) => console.log('✔', m),
2424
section: (m: string) => console.log('\n▸', m, '\n'),
2525
};
2626

27-
export function setAuctionRunnerLogger(l: typeof log): void {
28-
log = l;
29-
}
30-
3127
export interface RunOneAuctionInput {
3228
publicClient: PublicClient;
3329
auctionAddress: Address;

src/playbooks/timeboost/bidder.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,24 +24,19 @@ import {
2424
encodeAbiParameters,
2525
encodeFunctionData,
2626
keccak256,
27-
pad,
2827
toBytes,
2928
toHex,
3029
} from 'viem';
3130
import { sign as signRawHash, signatureToHex, privateKeyToAccount } from 'viem/accounts';
3231
import { ierc20Abi, expressLaneAuctionArtifact } from './abis.js';
3332
import { rawRpcCall, TimeboostRpcError } from './expressLaneRunner.js';
3433

35-
let log = {
34+
const log = {
3635
info: (m: string) => console.log('ℹ', m),
3736
warn: (m: string) => console.log('⚠', m),
3837
success: (m: string) => console.log('✔', m),
3938
};
4039

41-
export function setBidderLogger(l: typeof log): void {
42-
log = l;
43-
}
44-
4540
// ---------------------------------------------------------------------------
4641
// Types
4742
// ---------------------------------------------------------------------------
@@ -248,7 +243,3 @@ async function sendCall(
248243
if (receipt.status !== 'success') throw new Error(`Tx ${txHash} reverted`);
249244
return txHash;
250245
}
251-
252-
// Suppress unused-import warning for `pad` — exported as part of viem's API
253-
// surface that we may need in tests.
254-
void pad;

src/playbooks/timeboost/deployContracts.ts

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ import {
1818
type Hex,
1919
type LocalAccount,
2020
type PublicClient,
21-
type WalletClient,
22-
encodeAbiParameters,
2321
encodeDeployData,
2422
encodeFunctionData,
2523
} from 'viem';
@@ -43,19 +41,11 @@ export const DEFAULT_DEMO_TIMING: RoundTimingConfig = {
4341
reserveSubmissionSeconds: 3,
4442
};
4543

46-
/** Closer-to-production timing matching the docs example. */
47-
export const DOCS_DEFAULT_TIMING: RoundTimingConfig = {
48-
roundDurationSeconds: 60,
49-
auctionClosingSeconds: 15,
50-
reserveSubmissionSeconds: 15,
51-
};
52-
5344
export interface DeployContractsInput {
5445
/** Deployer (must hold child chain ETH for gas). */
5546
deployer: LocalAccount<string>;
56-
/** Both clients for the child chain. */
47+
/** Public client for the child chain (used to read nonce/gas + submit signed txs). */
5748
publicClient: PublicClient;
58-
walletClient: WalletClient;
5949
/** Address that will resolve auctions and hold AUCTIONEER_ROLE. */
6050
auctioneer: Address;
6151
/** Address that receives auction proceeds when `flushBeneficiaryBalance()` is called. */
@@ -287,26 +277,3 @@ function roundOffsetForRoundDuration(roundDurationSeconds: number): number {
287277
const nowSec = Math.floor(Date.now() / 1000);
288278
return Math.floor(nowSec / roundDurationSeconds) * roundDurationSeconds;
289279
}
290-
291-
// ---------------------------------------------------------------------------
292-
// Convenience: compute current round client-side from the deployed config.
293-
// Mirrors nitro/timeboost/roundtiminginfo.go.
294-
// ---------------------------------------------------------------------------
295-
296-
export function currentRoundFor(
297-
deployed: Pick<DeployedContracts, 'initialOffsetTimestamp' | 'timing'>,
298-
nowSec?: number,
299-
): number {
300-
const t = nowSec ?? Math.floor(Date.now() / 1000);
301-
return Math.floor((t - deployed.initialOffsetTimestamp) / deployed.timing.roundDurationSeconds);
302-
}
303-
304-
export function roundStartTimestamp(
305-
deployed: Pick<DeployedContracts, 'initialOffsetTimestamp' | 'timing'>,
306-
round: number,
307-
): number {
308-
return deployed.initialOffsetTimestamp + round * deployed.timing.roundDurationSeconds;
309-
}
310-
311-
/** Suppress unused-import warning (we may need encodeAbiParameters in tests later). */
312-
void encodeAbiParameters;

src/playbooks/timeboost/experimentRecorder.ts

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { type Address, type Hash, type Hex, type LocalAccount, type PublicClient
1414
import { submitExpressLaneTransaction, type ExpressLaneSubmitInput, type RunnerLogger } from './expressLaneRunner.js';
1515
import type { ExperimentRecord, TxObservation } from './types.js';
1616

17-
let recorderLogger: RunnerLogger & {
17+
const recorderLogger: RunnerLogger & {
1818
section: (m: string) => void;
1919
raw: (m: string) => void;
2020
success: (m: string) => void;
@@ -27,10 +27,6 @@ let recorderLogger: RunnerLogger & {
2727
success: (m) => console.log('✔', m),
2828
};
2929

30-
export function setRecorderLogger(l: typeof recorderLogger): void {
31-
recorderLogger = l;
32-
}
33-
3430
// ---------------------------------------------------------------------------
3531
// Public API
3632
// ---------------------------------------------------------------------------
@@ -118,19 +114,20 @@ export async function runExperimentPair(input: RunExperimentInput): Promise<Expe
118114
}
119115

120116
// ---------------------------------------------------------------------------
121-
// Internals — normal tx submission
117+
// Normal tx submission (exported so the no-bid round demo can reuse it
118+
// instead of hand-rolling the same nonce/gas/sign/send dance)
122119
// ---------------------------------------------------------------------------
123120

124-
interface SubmitNormalTxInput extends NormalTxInput {
121+
export interface SubmitNormalTxInput extends NormalTxInput {
125122
label: string;
126123
}
127124

128-
interface SubmitNormalTxResult {
125+
export interface SubmitNormalTxResult {
129126
txHash: Hash;
130127
sentAtMs: number;
131128
}
132129

133-
async function submitNormalTx(input: SubmitNormalTxInput): Promise<SubmitNormalTxResult> {
130+
export async function submitNormalTx(input: SubmitNormalTxInput): Promise<SubmitNormalTxResult> {
134131
const { senderAccount, childClient, chainId, to, valueEth = '0', label } = input;
135132

136133
const nonce = await childClient.getTransactionCount({
@@ -160,10 +157,10 @@ async function submitNormalTx(input: SubmitNormalTxInput): Promise<SubmitNormalT
160157
}
161158

162159
// ---------------------------------------------------------------------------
163-
// Internals — receipt polling + timeboosted extraction
160+
// Receipt polling + timeboosted extraction (exported for the no-bid round path)
164161
// ---------------------------------------------------------------------------
165162

166-
interface CompleteObservationInput {
163+
export interface CompleteObservationInput {
167164
lane: TxObservation['lane'];
168165
childClient: PublicClient;
169166
txHash: Hash;
@@ -173,7 +170,7 @@ interface CompleteObservationInput {
173170
timeoutMs: number;
174171
}
175172

176-
async function completeObservation(input: CompleteObservationInput): Promise<TxObservation> {
173+
export async function completeObservation(input: CompleteObservationInput): Promise<TxObservation> {
177174
const { childClient, txHash, sentAtMs, sender, lane, round, timeoutMs } = input;
178175

179176
// Use a tighter poll than the default — we want a wall-clock-accurate

src/playbooks/timeboost/expressLaneRunner.ts

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -17,33 +17,26 @@ import {
1717
parseEther,
1818
toHex,
1919
} from 'viem';
20-
import { DONT_CARE_SEQUENCE, type JsonExpressLaneSubmission, type TxObservation } from './types.js';
20+
import { DONT_CARE_SEQUENCE, type JsonExpressLaneSubmission } from './types.js';
2121
import { signExpressLaneSubmission } from './expressLaneSigner.js';
2222

2323
/**
2424
* Minimal logger surface so Phase 6 modules don't have to import the
2525
* playbook-wide logger.ts (which transitively pulls in `ora` →
2626
* `cli-spinners` and breaks on Node < 20.10 due to import attributes).
27-
*
28-
* Default is a `console.log`-backed no-op-ish sink. Production callers can
29-
* pass the real logger via `setRunnerLogger()`.
3027
*/
3128
export interface RunnerLogger {
3229
event: (msg: string) => void;
3330
info: (msg: string) => void;
3431
warn: (msg: string) => void;
3532
}
3633

37-
let activeLogger: RunnerLogger = {
34+
const activeLogger: RunnerLogger = {
3835
event: (m) => console.log('•', m),
3936
info: (m) => console.log('ℹ', m),
4037
warn: (m) => console.log('⚠', m),
4138
};
4239

43-
export function setRunnerLogger(l: RunnerLogger): void {
44-
activeLogger = l;
45-
}
46-
4740
export interface ExpressLaneSubmitInput {
4841
/** Controller account (must be a LocalAccount<string>; needs to deterministically sign tx + envelope). */
4942
controllerAccount: LocalAccount<string>;
@@ -145,24 +138,6 @@ export async function submitExpressLaneTransaction(input: ExpressLaneSubmitInput
145138
return { txHash, sentAtMs, rlpTx, submission };
146139
}
147140

148-
/**
149-
* Convenience: yield the partial TxObservation that the experiment recorder
150-
* will later complete with on-chain receipt fields.
151-
*/
152-
export function partialObservationForExpressLane(
153-
result: ExpressLaneSubmitResult,
154-
controllerAddress: Address,
155-
round: number,
156-
): Pick<TxObservation, 'lane' | 'sentAtMs' | 'txHash' | 'sender' | 'round'> {
157-
return {
158-
lane: 'express',
159-
sentAtMs: result.sentAtMs,
160-
txHash: result.txHash,
161-
sender: controllerAddress,
162-
round,
163-
};
164-
}
165-
166141
// ---------------------------------------------------------------------------
167142
// Minimal JSON-RPC client
168143
// ---------------------------------------------------------------------------

src/playbooks/timeboost/expressLaneSigner.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import {
2626
numberToBytes,
2727
pad,
2828
toBytes,
29-
toHex,
3029
} from 'viem';
3130

3231
const TIMEBOOST_DOMAIN_LABEL = 'TIMEBOOST_BID';
@@ -93,11 +92,3 @@ export async function signExpressLaneSubmission(account: Account, input: BuildSu
9392

9493
return local.signMessage({ message: { raw: messageBytes } });
9594
}
96-
97-
/**
98-
* Convenience: convert a bigint to its standard hex representation
99-
* compatible with the sequencer's `hexutil.Big` / `hexutil.Uint64` decoders.
100-
*/
101-
export function bigintToRpcHex(value: bigint): Hex {
102-
return toHex(value);
103-
}

src/playbooks/timeboost/roundClock.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,3 @@ export async function waitUntilRound(timing: RoundTiming, target: number, signal
7373
await new Promise((r) => setTimeout(r, sleepMs));
7474
}
7575
}
76-
77-
/**
78-
* Wait until the next round transitions and return the new round number.
79-
* Convenience for the demo runner's "watch round transitions" step.
80-
*/
81-
export async function waitForNextRound(timing: RoundTiming, signal?: AbortSignal): Promise<number> {
82-
const start = snapshotRound(timing).current;
83-
await waitUntilRound(timing, start + 1, signal);
84-
return start + 1;
85-
}

src/playbooks/timeboost/serviceManager.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,12 @@ const REDIS_HOST_PORT = 6379;
2929
export const BID_VALIDATOR_HOST_PORT = 9372;
3030
const AUCTIONEER_HTTP_HOST_PORT = 9373; // not strictly required; helpful for poking
3131

32-
let log = {
32+
const log = {
3333
info: (m: string) => console.log('ℹ', m),
3434
warn: (m: string) => console.log('⚠', m),
3535
success: (m: string) => console.log('✔', m),
3636
};
3737

38-
export function setServiceManagerLogger(l: typeof log): void {
39-
log = l;
40-
}
41-
4238
// ---------------------------------------------------------------------------
4339
// Public types
4440
// ---------------------------------------------------------------------------

0 commit comments

Comments
 (0)