openttt 0.1.2 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +52 -30
- package/dist/adaptive_switch.d.ts +22 -7
- package/dist/adaptive_switch.js +52 -15
- package/dist/auto_mint.d.ts +22 -7
- package/dist/auto_mint.js +107 -30
- package/dist/ct_log.d.ts +47 -0
- package/dist/ct_log.js +107 -0
- package/dist/dynamic_fee.d.ts +13 -2
- package/dist/dynamic_fee.js +62 -11
- package/dist/errors.d.ts +44 -25
- package/dist/errors.js +58 -42
- package/dist/evm_connector.d.ts +28 -1
- package/dist/evm_connector.js +124 -32
- package/dist/grg_api_client.d.ts +41 -0
- package/dist/grg_api_client.js +116 -0
- package/dist/http_client.d.ts +98 -0
- package/dist/http_client.js +252 -0
- package/dist/index.d.ts +5 -5
- package/dist/index.js +5 -5
- package/dist/logger.d.ts +36 -4
- package/dist/logger.js +70 -11
- package/dist/networks.d.ts +21 -0
- package/dist/networks.js +30 -4
- package/dist/pool_registry.d.ts +9 -0
- package/dist/pool_registry.js +37 -0
- package/dist/pot_signer.d.ts +15 -0
- package/dist/pot_signer.js +28 -0
- package/dist/protocol_fee.d.ts +42 -26
- package/dist/protocol_fee.js +77 -54
- package/dist/revenue_tiers.d.ts +36 -0
- package/dist/revenue_tiers.js +83 -0
- package/dist/signer.d.ts +1 -2
- package/dist/signer.js +72 -14
- package/dist/time_synthesis.d.ts +38 -0
- package/dist/time_synthesis.js +131 -21
- package/dist/trust_store.d.ts +49 -0
- package/dist/trust_store.js +89 -0
- package/dist/ttt_builder.d.ts +1 -1
- package/dist/ttt_builder.js +2 -2
- package/dist/ttt_client.d.ts +42 -29
- package/dist/ttt_client.js +117 -28
- package/dist/types.d.ts +46 -3
- package/dist/v4_hook.d.ts +10 -2
- package/dist/v4_hook.js +10 -2
- package/dist/x402_enforcer.d.ts +17 -2
- package/dist/x402_enforcer.js +27 -2
- package/package.json +6 -2
- package/dist/golay.d.ts +0 -6
- package/dist/golay.js +0 -166
- package/dist/grg_forward.d.ts +0 -11
- package/dist/grg_forward.js +0 -74
- package/dist/grg_inverse.d.ts +0 -7
- package/dist/grg_inverse.js +0 -100
- package/dist/grg_pipeline.d.ts +0 -13
- package/dist/grg_pipeline.js +0 -64
- package/dist/reed_solomon.d.ts +0 -12
- package/dist/reed_solomon.js +0 -179
- package/vendor/helm-crypto/golay.d.ts +0 -6
- package/vendor/helm-crypto/golay.js +0 -167
- package/vendor/helm-crypto/golay.js.map +0 -1
- package/vendor/helm-crypto/grg_forward.d.ts +0 -22
- package/vendor/helm-crypto/grg_forward.js +0 -89
- package/vendor/helm-crypto/grg_forward.js.map +0 -1
- package/vendor/helm-crypto/grg_inverse.d.ts +0 -16
- package/vendor/helm-crypto/grg_inverse.js +0 -118
- package/vendor/helm-crypto/grg_inverse.js.map +0 -1
- package/vendor/helm-crypto/grg_pipeline.d.ts +0 -13
- package/vendor/helm-crypto/grg_pipeline.js +0 -66
- package/vendor/helm-crypto/grg_pipeline.js.map +0 -1
- package/vendor/helm-crypto/index.d.ts +0 -5
- package/vendor/helm-crypto/index.js +0 -17
- package/vendor/helm-crypto/index.js.map +0 -1
- package/vendor/helm-crypto/logger.d.ts +0 -6
- package/vendor/helm-crypto/logger.js +0 -11
- package/vendor/helm-crypto/logger.js.map +0 -1
- package/vendor/helm-crypto/reed_solomon.d.ts +0 -37
- package/vendor/helm-crypto/reed_solomon.js +0 -210
- package/vendor/helm-crypto/reed_solomon.js.map +0 -1
package/README.md
CHANGED
|
@@ -10,7 +10,9 @@ OpenTTT brings cryptographic time verification to blockchain transaction orderin
|
|
|
10
10
|
[](LICENSE)
|
|
11
11
|
[](https://github.com/Helm-Protocol/OpenTTT/actions/workflows/ci.yml)
|
|
12
12
|
[](https://codecov.io/gh/Helm-Protocol/OpenTTT)
|
|
13
|
-
[]()
|
|
14
|
+
|
|
15
|
+
> If this project is useful to you, please [star it on GitHub](https://github.com/Helm-Protocol/OpenTTT) — it helps others find it.
|
|
14
16
|
|
|
15
17
|
```
|
|
16
18
|
npm install openttt
|
|
@@ -27,7 +29,7 @@ Current MEV protection relies on **trust**: builders promise fair ordering, prot
|
|
|
27
29
|
| **Mechanism** | Social contract (request) | Physical verification (proof) |
|
|
28
30
|
| **Enforcement** | Reputation, exclusion | Economic natural selection |
|
|
29
31
|
| **Bad actors** | Must be identified and removed | Naturally unprofitable, self-selecting out |
|
|
30
|
-
| **Time source** | Block timestamp (miner-controlled) | Multi-source NTP synthesis (NIST,
|
|
32
|
+
| **Time source** | Block timestamp (miner-controlled) | Multi-source NTP synthesis (NIST, Google, Apple) |
|
|
31
33
|
|
|
32
34
|
**The core insight**: Rollups generate precise timestamps and deliver them to builders with a receipt. The Adaptive GRG pipeline then verifies whether the builder respected that ordering:
|
|
33
35
|
|
|
@@ -40,7 +42,22 @@ No governance vote. No slashing committee. Cheating is simply bad business.
|
|
|
40
42
|
|
|
41
43
|
## Quick Start
|
|
42
44
|
|
|
43
|
-
|
|
45
|
+
### Try it in 30 seconds — No ETH, No Wallet
|
|
46
|
+
|
|
47
|
+
```typescript
|
|
48
|
+
import { HttpOnlyClient } from "openttt";
|
|
49
|
+
|
|
50
|
+
const client = new HttpOnlyClient();
|
|
51
|
+
const pot = await client.generatePoT();
|
|
52
|
+
console.log(pot.timestamp, pot.confidence, pot.sources);
|
|
53
|
+
|
|
54
|
+
const valid = client.verifyPoT(pot);
|
|
55
|
+
console.log("Valid:", valid); // true
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
No blockchain. No wallet. No gas fees. Just verified time from 4 independent HTTPS sources (NIST, Apple, Google, Cloudflare). Start here, upgrade to on-chain when ready.
|
|
59
|
+
|
|
60
|
+
### On-Chain Mode (Full Power)
|
|
44
61
|
|
|
45
62
|
```typescript
|
|
46
63
|
import { TTTClient } from "openttt";
|
|
@@ -49,9 +66,7 @@ const ttt = await TTTClient.forBase({ privateKey: process.env.OPERATOR_PK! });
|
|
|
49
66
|
ttt.startAutoMint();
|
|
50
67
|
```
|
|
51
68
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
> **Shorthand**: Pass `privateKey` directly as a string instead of the full `signer` config object. The verbose form `{ signer: { type: "privateKey", key: "0x..." } }` still works for when you need other signer types (Turnkey, KMS, Privy).
|
|
69
|
+
Connects to Base, synthesizes time from atomic clock sources, and mints Proof-of-Time tokens on-chain.
|
|
55
70
|
|
|
56
71
|
---
|
|
57
72
|
|
|
@@ -95,7 +110,7 @@ const ttt = await TTTClient.create({
|
|
|
95
110
|
tier: "T1_block",
|
|
96
111
|
contractAddress: "0x...",
|
|
97
112
|
poolAddress: "0x...",
|
|
98
|
-
timeSources: ["nist", "
|
|
113
|
+
timeSources: ["nist", "google", "cloudflare", "apple"],
|
|
99
114
|
protocolFeeRate: 0.05,
|
|
100
115
|
enableGracefulShutdown: true,
|
|
101
116
|
});
|
|
@@ -246,8 +261,8 @@ const ttt = await TTTClient.create({
|
|
|
246
261
|
|
|
247
262
|
| Method | Description |
|
|
248
263
|
|---|---|
|
|
249
|
-
| `GrgPipeline.processForward(data)` | Encode
|
|
250
|
-
| `GrgPipeline.processInverse(shards, length)` | Decode
|
|
264
|
+
| `GrgPipeline.processForward(data)` | Encode data through the multi-layer integrity pipeline, producing verifiable shards |
|
|
265
|
+
| `GrgPipeline.processInverse(shards, length)` | Decode shards back to original data with integrity verification |
|
|
251
266
|
|
|
252
267
|
### AdaptiveSwitch
|
|
253
268
|
|
|
@@ -264,37 +279,23 @@ const ttt = await TTTClient.create({
|
|
|
264
279
|
```
|
|
265
280
|
TTTClient (entry point)
|
|
266
281
|
|-- AutoMintEngine Periodic minting loop
|
|
267
|
-
| |-- TimeSynthesis NTP multi-source median synthesis (NIST,
|
|
282
|
+
| |-- TimeSynthesis NTP multi-source median synthesis (NIST, Google, Apple)
|
|
268
283
|
| |-- DynamicFeeEngine Oracle-based pricing
|
|
269
284
|
| |-- EVMConnector On-chain mint/burn/events (ethers v6)
|
|
270
285
|
| '-- ProtocolFee EIP-712 signed fee collection
|
|
271
286
|
|-- AdaptiveSwitch TURBO/FULL mode state machine
|
|
272
|
-
|-- GRG Pipeline
|
|
287
|
+
|-- GRG Pipeline Multi-layer data integrity (proprietary)
|
|
273
288
|
|-- PoolRegistry Multi-pool statistics tracking
|
|
274
289
|
'-- Signer Abstraction PrivateKey | Turnkey | Privy | KMS
|
|
275
290
|
```
|
|
276
291
|
|
|
277
|
-
###
|
|
292
|
+
### Data Integrity: GRG Pipeline
|
|
278
293
|
|
|
279
|
-
GRG
|
|
294
|
+
GRG is a multi-layer data integrity pipeline that protects PoT payloads — analogous to how the TLS record protocol protects HTTP payloads. It provides compression, erasure coding, and error correction in a single pass.
|
|
280
295
|
|
|
281
|
-
|
|
282
|
-
FORWARD (Encode)
|
|
283
|
-
Raw Data --> Golomb-Rice Compression
|
|
284
|
-
--> Reed-Solomon Erasure Coding
|
|
285
|
-
--> Golay(24,12) Verification Codes
|
|
286
|
-
--> Shards
|
|
287
|
-
|
|
288
|
-
INVERSE (Decode)
|
|
289
|
-
Shards --> Golay(24,12) Error Detection
|
|
290
|
-
--> Reed-Solomon Reconstruction
|
|
291
|
-
--> Golomb-Rice Decompression
|
|
292
|
-
--> Raw Data
|
|
293
|
-
```
|
|
296
|
+
The pipeline produces verifiable shards that can be independently validated and reconstructed, ensuring PoT integrity even under partial data loss.
|
|
294
297
|
|
|
295
|
-
|
|
296
|
-
**Reed-Solomon** adds erasure coding so data survives shard loss.
|
|
297
|
-
**Golay(24,12)** detects and corrects up to 3-bit errors per 24-bit codeword.
|
|
298
|
+
> Implementation details are proprietary. See the [IETF Draft](https://datatracker.ietf.org/doc/draft-helmprotocol-tttps/) for the abstract specification.
|
|
298
299
|
|
|
299
300
|
### Adaptive Mode Switching
|
|
300
301
|
|
|
@@ -311,7 +312,7 @@ This asymmetry is deliberate: it is hard to earn trust and easy to lose it.
|
|
|
311
312
|
OpenTTT queries multiple atomic clock-synchronized NTP sources in parallel and produces a median-synthesized timestamp with confidence scoring:
|
|
312
313
|
|
|
313
314
|
- **NIST** (time.nist.gov) -- US national standard
|
|
314
|
-
- **
|
|
315
|
+
- **Apple** (time.apple.com) -- Apple global time service
|
|
315
316
|
- **Google** (time.google.com) -- Leap-smeared public NTP
|
|
316
317
|
|
|
317
318
|
All readings must fall within a stratum-dependent tolerance of the synthesized median (10ms for stratum 1, 25ms for stratum 2, 50ms for stratum 3+), or the Proof of Time is rejected. Single-source operation triggers a degraded-confidence warning.
|
|
@@ -390,4 +391,25 @@ Copyright 2026 Helm Protocol.
|
|
|
390
391
|
|
|
391
392
|
---
|
|
392
393
|
|
|
394
|
+
## Learn More
|
|
395
|
+
|
|
396
|
+
- [IETF Draft: draft-helmprotocol-tttps-00](https://datatracker.ietf.org/doc/draft-helmprotocol-tttps/) — TTTPS Protocol Specification
|
|
397
|
+
- [Yellow Paper](https://github.com/Helm-Protocol/OpenTTT/blob/main/YELLOW_PAPER.md) — Technical Deep Dive
|
|
398
|
+
- [MCP Server](https://github.com/Helm-Protocol/OpenTTT/tree/main/mcp) — AI Agent Integration (`@helm-protocol/ttt-mcp`)
|
|
399
|
+
- [Subgraph (The Graph)](https://api.studio.thegraph.com/query/1744392/openttt-base-sepolia/v0.2.0) — On-chain PoT Data
|
|
400
|
+
- [Base Sepolia Contracts](https://sepolia.basescan.org/address/0xde357135cA493e59680182CDE9E1c6A4dA400811) — TTT ERC-1155
|
|
401
|
+
- [Helm Protocol](https://github.com/Helm-Protocol) — GitHub Organization
|
|
402
|
+
|
|
393
403
|
[GitHub](https://github.com/Helm-Protocol/OpenTTT) | Built by [Helm Protocol](https://github.com/Helm-Protocol)
|
|
404
|
+
|
|
405
|
+
---
|
|
406
|
+
|
|
407
|
+
## Contributing
|
|
408
|
+
|
|
409
|
+
Contributions are welcome. If you find a bug, have a feature request, or want to improve the documentation, please open an issue or submit a pull request on [GitHub](https://github.com/Helm-Protocol/OpenTTT).
|
|
410
|
+
|
|
411
|
+
- **Bug reports**: Open an issue with a minimal reproduction case.
|
|
412
|
+
- **Feature requests**: Open an issue describing the use case and expected behavior.
|
|
413
|
+
- **Pull requests**: Fork the repo, make your changes, ensure all tests pass (`npm test`), and open a PR against `main`.
|
|
414
|
+
|
|
415
|
+
For significant changes, please open an issue first to discuss the approach.
|
|
@@ -12,6 +12,8 @@ export interface Block {
|
|
|
12
12
|
txs: string[];
|
|
13
13
|
data: Uint8Array;
|
|
14
14
|
}
|
|
15
|
+
/** Tier-based dynamic tolerance (ms) — auditor-requested upgrade */
|
|
16
|
+
export declare const TIER_TOLERANCE_MS: Record<string, number>;
|
|
15
17
|
export declare class AdaptiveSwitch {
|
|
16
18
|
private windowSize;
|
|
17
19
|
private threshold;
|
|
@@ -22,23 +24,36 @@ export declare class AdaptiveSwitch {
|
|
|
22
24
|
private consecutiveFailures;
|
|
23
25
|
private turboEntryThreshold;
|
|
24
26
|
private turboMaintainThreshold;
|
|
27
|
+
private tolerance;
|
|
28
|
+
constructor(options?: {
|
|
29
|
+
tolerance?: number;
|
|
30
|
+
});
|
|
25
31
|
/**
|
|
26
|
-
* TTT
|
|
32
|
+
* Core TTT mechanism: switches between Turbo/Full mode based on timestamp ordering match rate.
|
|
27
33
|
*/
|
|
28
|
-
verifyBlock(block: Block, tttRecord: TTTRecord): AdaptiveMode;
|
|
34
|
+
verifyBlock(block: Block, tttRecord: TTTRecord, chainId: number, poolAddress: string, tier?: string): AdaptiveMode;
|
|
29
35
|
/**
|
|
30
|
-
*
|
|
31
|
-
* TURBO: 20%
|
|
32
|
-
* FULL:
|
|
36
|
+
* Return fee discount rate based on current mode.
|
|
37
|
+
* TURBO: 20% discount (incentivizes profitability).
|
|
38
|
+
* FULL: No discount.
|
|
33
39
|
*/
|
|
34
40
|
getFeeDiscount(): number;
|
|
35
41
|
/**
|
|
36
|
-
*
|
|
42
|
+
* Get current adaptive mode.
|
|
37
43
|
*/
|
|
38
44
|
getCurrentMode(): AdaptiveMode;
|
|
39
45
|
/**
|
|
40
|
-
*
|
|
46
|
+
* Reset history (for testing).
|
|
41
47
|
*/
|
|
42
48
|
reset(): void;
|
|
49
|
+
/**
|
|
50
|
+
* Serialize internal state to JSON for persistence across restarts.
|
|
51
|
+
* Allows operators to avoid re-learning over 20 blocks after a restart.
|
|
52
|
+
*/
|
|
53
|
+
serialize(): string;
|
|
54
|
+
/**
|
|
55
|
+
* Reconstruct an AdaptiveSwitch from previously serialized JSON state.
|
|
56
|
+
*/
|
|
57
|
+
static deserialize(json: string): AdaptiveSwitch;
|
|
43
58
|
private compareTransactionOrder;
|
|
44
59
|
}
|
package/dist/adaptive_switch.js
CHANGED
|
@@ -2,15 +2,22 @@
|
|
|
2
2
|
// sdk/src/adaptive_switch.ts — Adaptive Mode Switcher
|
|
3
3
|
// Turbo (50ms) vs Full (127ms)
|
|
4
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
-
exports.AdaptiveSwitch = exports.AdaptiveMode = void 0;
|
|
6
|
-
const
|
|
5
|
+
exports.AdaptiveSwitch = exports.TIER_TOLERANCE_MS = exports.AdaptiveMode = void 0;
|
|
6
|
+
const helm_crypto_1 = require("../vendor/helm-crypto");
|
|
7
7
|
const logger_1 = require("./logger");
|
|
8
8
|
var AdaptiveMode;
|
|
9
9
|
(function (AdaptiveMode) {
|
|
10
10
|
AdaptiveMode["TURBO"] = "TURBO";
|
|
11
11
|
AdaptiveMode["FULL"] = "FULL";
|
|
12
12
|
})(AdaptiveMode || (exports.AdaptiveMode = AdaptiveMode = {}));
|
|
13
|
-
const TOLERANCE = 100; // 100ms tolerance for KTSat sync
|
|
13
|
+
// const TOLERANCE = 100; // 100ms tolerance for KTSat sync (now configurable via constructor)
|
|
14
|
+
/** Tier-based dynamic tolerance (ms) — auditor-requested upgrade */
|
|
15
|
+
exports.TIER_TOLERANCE_MS = {
|
|
16
|
+
T0_epoch: 2000, // 6.4min tick → 2s tolerance
|
|
17
|
+
T1_block: 200, // 2s tick → 200ms
|
|
18
|
+
T2_slot: 500, // 12s tick → 500ms
|
|
19
|
+
T3_micro: 10, // 100ms tick → 10ms (10%)
|
|
20
|
+
};
|
|
14
21
|
class AdaptiveSwitch {
|
|
15
22
|
windowSize = 20; // B1-9: Updated from 10 to 20
|
|
16
23
|
threshold = 0.9; // B1-9: Updated from 0.8 to 0.9
|
|
@@ -21,17 +28,22 @@ class AdaptiveSwitch {
|
|
|
21
28
|
consecutiveFailures = 0; // P2-1: Track consecutive failures for exponential backoff
|
|
22
29
|
turboEntryThreshold = 0.95; // P2-2: Hysteresis — stricter entry
|
|
23
30
|
turboMaintainThreshold = 0.85; // P2-2: Hysteresis — relaxed maintenance
|
|
31
|
+
tolerance;
|
|
32
|
+
constructor(options) {
|
|
33
|
+
this.tolerance = options?.tolerance ?? 100;
|
|
34
|
+
}
|
|
24
35
|
/**
|
|
25
|
-
* TTT
|
|
36
|
+
* Core TTT mechanism: switches between Turbo/Full mode based on timestamp ordering match rate.
|
|
26
37
|
*/
|
|
27
|
-
verifyBlock(block, tttRecord) {
|
|
28
|
-
// 1.
|
|
38
|
+
verifyBlock(block, tttRecord, chainId, poolAddress, tier) {
|
|
39
|
+
// 1. Check timestamp ordering and time match
|
|
29
40
|
const orderMatch = this.compareTransactionOrder(block.txs, tttRecord.txOrder);
|
|
30
|
-
const
|
|
41
|
+
const tolerance = tier ? (exports.TIER_TOLERANCE_MS[tier] ?? this.tolerance) : this.tolerance;
|
|
42
|
+
const timeMatch = Math.abs(block.timestamp - tttRecord.time) < tolerance;
|
|
31
43
|
let sequenceOk = orderMatch && timeMatch;
|
|
32
44
|
// B1-1: Do not skip GrgInverse.verify() in TURBO mode
|
|
33
45
|
// We check integrity regardless of mode
|
|
34
|
-
const integrityOk =
|
|
46
|
+
const integrityOk = helm_crypto_1.GrgInverse.verify(block.data, tttRecord.grgPayload, chainId, poolAddress);
|
|
35
47
|
if (!integrityOk) {
|
|
36
48
|
logger_1.logger.error(`[AdaptiveSwitch] GRG integrity check FAILED`);
|
|
37
49
|
sequenceOk = false; // Mark as false if integrity fails
|
|
@@ -42,7 +54,7 @@ class AdaptiveSwitch {
|
|
|
42
54
|
this.penaltyCooldown = 20 * Math.pow(2, this.consecutiveFailures - 1); // 20, 40, 80, 160, 320
|
|
43
55
|
}
|
|
44
56
|
}
|
|
45
|
-
// 2.
|
|
57
|
+
// 2. Update history (Sliding Window)
|
|
46
58
|
this.history.push(sequenceOk);
|
|
47
59
|
if (this.history.length > this.windowSize) {
|
|
48
60
|
this.history.shift();
|
|
@@ -50,7 +62,7 @@ class AdaptiveSwitch {
|
|
|
50
62
|
if (this.penaltyCooldown > 0) {
|
|
51
63
|
this.penaltyCooldown--;
|
|
52
64
|
}
|
|
53
|
-
// 3.
|
|
65
|
+
// 3. Calculate match rate and switch mode
|
|
54
66
|
const matchCount = this.history.filter(h => h).length;
|
|
55
67
|
const matchRate = this.history.length > 0 ? matchCount / this.history.length : 0;
|
|
56
68
|
// P2-2: Hysteresis — different thresholds for entering vs maintaining TURBO
|
|
@@ -73,21 +85,21 @@ class AdaptiveSwitch {
|
|
|
73
85
|
return this.currentMode;
|
|
74
86
|
}
|
|
75
87
|
/**
|
|
76
|
-
*
|
|
77
|
-
* TURBO: 20%
|
|
78
|
-
* FULL:
|
|
88
|
+
* Return fee discount rate based on current mode.
|
|
89
|
+
* TURBO: 20% discount (incentivizes profitability).
|
|
90
|
+
* FULL: No discount.
|
|
79
91
|
*/
|
|
80
92
|
getFeeDiscount() {
|
|
81
93
|
return this.currentMode === AdaptiveMode.TURBO ? 0.2 : 0.0;
|
|
82
94
|
}
|
|
83
95
|
/**
|
|
84
|
-
*
|
|
96
|
+
* Get current adaptive mode.
|
|
85
97
|
*/
|
|
86
98
|
getCurrentMode() {
|
|
87
99
|
return this.currentMode;
|
|
88
100
|
}
|
|
89
101
|
/**
|
|
90
|
-
*
|
|
102
|
+
* Reset history (for testing).
|
|
91
103
|
*/
|
|
92
104
|
reset() {
|
|
93
105
|
this.history = [];
|
|
@@ -95,6 +107,31 @@ class AdaptiveSwitch {
|
|
|
95
107
|
this.penaltyCooldown = 0;
|
|
96
108
|
this.consecutiveFailures = 0;
|
|
97
109
|
}
|
|
110
|
+
/**
|
|
111
|
+
* Serialize internal state to JSON for persistence across restarts.
|
|
112
|
+
* Allows operators to avoid re-learning over 20 blocks after a restart.
|
|
113
|
+
*/
|
|
114
|
+
serialize() {
|
|
115
|
+
return JSON.stringify({
|
|
116
|
+
history: this.history,
|
|
117
|
+
currentMode: this.currentMode,
|
|
118
|
+
consecutiveFailures: this.consecutiveFailures,
|
|
119
|
+
penaltyCooldown: this.penaltyCooldown,
|
|
120
|
+
tolerance: this.tolerance,
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Reconstruct an AdaptiveSwitch from previously serialized JSON state.
|
|
125
|
+
*/
|
|
126
|
+
static deserialize(json) {
|
|
127
|
+
const data = JSON.parse(json);
|
|
128
|
+
const instance = new AdaptiveSwitch({ tolerance: data.tolerance ?? 100 });
|
|
129
|
+
instance.history = data.history;
|
|
130
|
+
instance.currentMode = data.currentMode;
|
|
131
|
+
instance.consecutiveFailures = data.consecutiveFailures;
|
|
132
|
+
instance.penaltyCooldown = data.penaltyCooldown;
|
|
133
|
+
return instance;
|
|
134
|
+
}
|
|
98
135
|
compareTransactionOrder(blockTxs, expectedOrder) {
|
|
99
136
|
if (blockTxs.length !== expectedOrder.length)
|
|
100
137
|
return false;
|
package/dist/auto_mint.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import { TimeSynthesis } from "./time_synthesis";
|
|
1
2
|
import { EVMConnector } from "./evm_connector";
|
|
2
3
|
import { AutoMintConfig, MintResult } from "./types";
|
|
3
4
|
/**
|
|
4
|
-
* AutoMintEngine - TTT
|
|
5
|
-
*
|
|
5
|
+
* AutoMintEngine - Automatic TTT minting engine.
|
|
6
|
+
* Combines time synthesis, dynamic fee calculation, and EVM minting into a single loop.
|
|
6
7
|
*/
|
|
7
8
|
export declare class AutoMintEngine {
|
|
8
9
|
private config;
|
|
@@ -20,26 +21,40 @@ export declare class AutoMintEngine {
|
|
|
20
21
|
private consecutiveFailures;
|
|
21
22
|
private maxConsecutiveFailures;
|
|
22
23
|
private potSigner;
|
|
24
|
+
/** Monotonic counter appended to tokenId hash to prevent collision when two mints share the same nanosecond timestamp. */
|
|
25
|
+
private mintNonce;
|
|
26
|
+
/** Fire the GRG >50ms performance warning at most once per engine session. */
|
|
27
|
+
private warnedGrgSlow;
|
|
23
28
|
constructor(config: AutoMintConfig);
|
|
24
29
|
getEvmConnector(): EVMConnector;
|
|
30
|
+
getTimeSynthesis(): TimeSynthesis;
|
|
25
31
|
setOnMint(callback: (result: MintResult) => void): void;
|
|
26
32
|
setOnFailure(callback: (error: Error) => void): void;
|
|
27
33
|
setOnLatency(callback: (ms: number) => void): void;
|
|
28
34
|
/**
|
|
29
|
-
*
|
|
35
|
+
* Initialize the engine (RPC connection and contract setup).
|
|
30
36
|
*/
|
|
31
37
|
initialize(): Promise<void>;
|
|
32
38
|
/**
|
|
33
|
-
*
|
|
39
|
+
* Start the automatic minting loop.
|
|
34
40
|
*/
|
|
35
41
|
start(): void;
|
|
36
42
|
/**
|
|
37
|
-
*
|
|
43
|
+
* Stop the automatic minting loop.
|
|
38
44
|
*/
|
|
39
45
|
stop(): void;
|
|
40
46
|
/**
|
|
41
|
-
*
|
|
42
|
-
*
|
|
47
|
+
* Resume the minting loop after a circuit breaker trip.
|
|
48
|
+
* Resets the consecutive failure counter and restarts the loop.
|
|
49
|
+
*/
|
|
50
|
+
resume(): void;
|
|
51
|
+
/**
|
|
52
|
+
* Sleep helper for retry backoff.
|
|
53
|
+
*/
|
|
54
|
+
private sleep;
|
|
55
|
+
/**
|
|
56
|
+
* Execute a single mint tick.
|
|
57
|
+
* Time synthesis -> tokenId generation -> EVM mint call -> fee calculation/deduction.
|
|
43
58
|
*/
|
|
44
59
|
mintTick(): Promise<void>;
|
|
45
60
|
private signFeeMessage;
|