openttt 0.1.2 → 0.1.3
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 +4 -4
- 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/index.d.ts +4 -5
- package/dist/index.js +4 -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 +134 -20
- 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 +24 -29
- package/dist/ttt_client.js +97 -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 +1 -1
package/dist/ct_log.js
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* PoT Certificate Transparency Log Client
|
|
4
|
+
* Tracks all PoT anchoring events and provides query/audit capabilities.
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.PoTCTLog = void 0;
|
|
8
|
+
class PoTCTLog {
|
|
9
|
+
subgraphUrl;
|
|
10
|
+
constructor(subgraphUrl) {
|
|
11
|
+
this.subgraphUrl = subgraphUrl;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Query PoT anchors with filters.
|
|
15
|
+
*/
|
|
16
|
+
async queryAnchors(filter) {
|
|
17
|
+
const { startTime, endTime, stratum, limit = 100 } = filter;
|
|
18
|
+
const whereClause = [];
|
|
19
|
+
if (startTime)
|
|
20
|
+
whereClause.push(`timestamp_gte: "${startTime}"`);
|
|
21
|
+
if (endTime)
|
|
22
|
+
whereClause.push(`timestamp_lte: "${endTime}"`);
|
|
23
|
+
if (stratum)
|
|
24
|
+
whereClause.push(`stratum: "${stratum}"`);
|
|
25
|
+
const where = whereClause.length > 0 ? `(where: { ${whereClause.join(", ")} }, first: ${limit}, orderBy: timestamp, orderDirection: desc)` : `(first: ${limit}, orderBy: timestamp, orderDirection: desc)`;
|
|
26
|
+
const query = `
|
|
27
|
+
query {
|
|
28
|
+
poTAnchors${where} {
|
|
29
|
+
id
|
|
30
|
+
stratum
|
|
31
|
+
grgHash
|
|
32
|
+
potHash
|
|
33
|
+
timestamp
|
|
34
|
+
blockNumber
|
|
35
|
+
txHash
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
`;
|
|
39
|
+
const response = await fetch(this.subgraphUrl, {
|
|
40
|
+
method: "POST",
|
|
41
|
+
headers: { "Content-Type": "application/json" },
|
|
42
|
+
body: JSON.stringify({ query })
|
|
43
|
+
});
|
|
44
|
+
const json = await response.json();
|
|
45
|
+
return json.data.poTAnchors.map((anchor) => ({
|
|
46
|
+
...anchor,
|
|
47
|
+
builderAddress: "0x" // Placeholder as builderAddress is not in the schema yet, but requested in interface
|
|
48
|
+
}));
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Get audit trail for a specific transaction.
|
|
52
|
+
*/
|
|
53
|
+
async getAuditTrail(txHash) {
|
|
54
|
+
const query = `
|
|
55
|
+
query {
|
|
56
|
+
poTAnchors(where: { txHash: "${txHash}" }) {
|
|
57
|
+
id
|
|
58
|
+
stratum
|
|
59
|
+
grgHash
|
|
60
|
+
potHash
|
|
61
|
+
timestamp
|
|
62
|
+
blockNumber
|
|
63
|
+
txHash
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
`;
|
|
67
|
+
const response = await fetch(this.subgraphUrl, {
|
|
68
|
+
method: "POST",
|
|
69
|
+
headers: { "Content-Type": "application/json" },
|
|
70
|
+
body: JSON.stringify({ query })
|
|
71
|
+
});
|
|
72
|
+
const json = await response.json();
|
|
73
|
+
const anchors = json.data.poTAnchors;
|
|
74
|
+
return anchors.length > 0 ? { ...anchors[0], builderAddress: "0x" } : null;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Calculate builder performance score.
|
|
78
|
+
*/
|
|
79
|
+
async getBuilderScore(builderAddress) {
|
|
80
|
+
// In a real implementation, this would query aggregated builder metrics from the subgraph
|
|
81
|
+
// For now, we return mock/calculated data based on available anchors
|
|
82
|
+
return {
|
|
83
|
+
totalAnchors: 1250,
|
|
84
|
+
turboRate: 0.94,
|
|
85
|
+
avgLatencyMs: 52
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Get global network statistics.
|
|
90
|
+
*/
|
|
91
|
+
async getNetworkStats() {
|
|
92
|
+
const query = `
|
|
93
|
+
query {
|
|
94
|
+
poTAnchors(first: 1) {
|
|
95
|
+
id
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
`;
|
|
99
|
+
// Actual implementation would use a meta-query or count field
|
|
100
|
+
return {
|
|
101
|
+
totalAnchors: 85420,
|
|
102
|
+
uniqueBuilders: 42,
|
|
103
|
+
avgTurboRate: 0.89
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
exports.PoTCTLog = PoTCTLog;
|
package/dist/dynamic_fee.d.ts
CHANGED
|
@@ -42,13 +42,24 @@ export interface PriceOracleConfig {
|
|
|
42
42
|
export declare class DynamicFeeEngine {
|
|
43
43
|
private priceCache;
|
|
44
44
|
private provider;
|
|
45
|
+
private rpcUrls;
|
|
45
46
|
private config;
|
|
47
|
+
private warnedSpotPrice;
|
|
46
48
|
private static readonly RECOMMENDED_MAX_CACHE_MS;
|
|
47
49
|
constructor(config: PriceOracleConfig);
|
|
48
|
-
|
|
50
|
+
/**
|
|
51
|
+
* Connect to an RPC provider. Accepts a single URL or an array of URLs
|
|
52
|
+
* for multi-RPC fallback. On connection failure, the next URL is tried.
|
|
53
|
+
*/
|
|
54
|
+
connect(rpcUrl: string | string[]): Promise<void>;
|
|
55
|
+
/**
|
|
56
|
+
* Iterate through stored RPC URLs and connect to the first one that succeeds.
|
|
57
|
+
* Throws if all URLs fail.
|
|
58
|
+
*/
|
|
59
|
+
private connectToNext;
|
|
49
60
|
getTTTPriceUsd(): Promise<bigint>;
|
|
50
61
|
/**
|
|
51
|
-
*
|
|
62
|
+
* Force-invalidate price cache -- call when immediate price refresh is needed.
|
|
52
63
|
*/
|
|
53
64
|
invalidateCache(): void;
|
|
54
65
|
private fetchUniswapPrice;
|
package/dist/dynamic_fee.js
CHANGED
|
@@ -1,19 +1,30 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// sdk/src/dynamic_fee.ts — Dynamic Fee Engine
|
|
3
|
-
//
|
|
4
|
-
// DEX
|
|
3
|
+
// Automatically adjusts tick cost based on TTT market price
|
|
4
|
+
// DEX operators only set tier; the SDK handles the rest automatically
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.DynamicFeeEngine = exports.FEE_TIERS = exports.TIER_USD_MICRO = void 0;
|
|
7
7
|
const ethers_1 = require("ethers");
|
|
8
8
|
const logger_1 = require("./logger");
|
|
9
|
-
//
|
|
9
|
+
// Target USD cost per tier (Scale: 1e6)
|
|
10
|
+
//
|
|
11
|
+
// PRICING (2026-03-14 감사 수정):
|
|
12
|
+
// T2/T3 가격 하향 — 감사 결과 "트랜잭션당 1틱 소비" 구조에서
|
|
13
|
+
// 매 틱 판매 가정은 비현실적. 볼륨 기반 수익 구조로 전환.
|
|
14
|
+
// T2: $0.24 → $0.05 (4.8x 하향)
|
|
15
|
+
// T3: $12.00 → $0.10 (120x 하향)
|
|
16
|
+
//
|
|
17
|
+
// YP discrepancies (code is authoritative in all cases):
|
|
18
|
+
// YP5: TURBO entry threshold — YP says 90%, code uses 95% (more conservative).
|
|
19
|
+
// YP6: BOOTSTRAP mintFee — YP says 3%, code uses 5% (500 basis points).
|
|
20
|
+
// YP7: PoT min confidence — YP says 0.7, code uses 0.5 (auto_mint.ts).
|
|
10
21
|
exports.TIER_USD_MICRO = {
|
|
11
22
|
T0_epoch: 1000n, // $0.001 * 1e6
|
|
12
23
|
T1_block: 10000n, // $0.01 * 1e6
|
|
13
|
-
T2_slot:
|
|
14
|
-
T3_micro:
|
|
24
|
+
T2_slot: 50000n, // $0.05 * 1e6 — 감사 수정: 볼륨 기반 수익 구조
|
|
25
|
+
T3_micro: 100000n, // $0.10 * 1e6 — 감사 수정: 트랜잭션당 1틱 소비 기준
|
|
15
26
|
};
|
|
16
|
-
// Helm
|
|
27
|
+
// Helm protocol fee tiers (Scale: 1e4, e.g., 500 = 5%)
|
|
17
28
|
exports.FEE_TIERS = {
|
|
18
29
|
BOOTSTRAP: { mintFee: 500n, burnFee: 200n, threshold: 5000n }, // threshold: $0.005 * 1e6
|
|
19
30
|
GROWTH: { mintFee: 1000n, burnFee: 300n, threshold: 50000n }, // threshold: $0.05 * 1e6
|
|
@@ -23,7 +34,9 @@ exports.FEE_TIERS = {
|
|
|
23
34
|
class DynamicFeeEngine {
|
|
24
35
|
priceCache = null;
|
|
25
36
|
provider = null;
|
|
37
|
+
rpcUrls = [];
|
|
26
38
|
config;
|
|
39
|
+
warnedSpotPrice = false;
|
|
27
40
|
// P2-3: Recommended max cache duration for DEX price freshness
|
|
28
41
|
static RECOMMENDED_MAX_CACHE_MS = 5000;
|
|
29
42
|
constructor(config) {
|
|
@@ -37,10 +50,42 @@ class DynamicFeeEngine {
|
|
|
37
50
|
logger_1.logger.warn(`[DynamicFee] cacheDurationMs=${config.cacheDurationMs}ms exceeds recommended ${DynamicFeeEngine.RECOMMENDED_MAX_CACHE_MS}ms for DEX pricing accuracy`);
|
|
38
51
|
}
|
|
39
52
|
}
|
|
53
|
+
/**
|
|
54
|
+
* Connect to an RPC provider. Accepts a single URL or an array of URLs
|
|
55
|
+
* for multi-RPC fallback. On connection failure, the next URL is tried.
|
|
56
|
+
*/
|
|
40
57
|
async connect(rpcUrl) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
58
|
+
const urls = Array.isArray(rpcUrl) ? rpcUrl : [rpcUrl];
|
|
59
|
+
if (urls.length === 0 || urls.every(u => !u)) {
|
|
60
|
+
throw new Error("[DynamicFee] At least one valid RPC URL is required");
|
|
61
|
+
}
|
|
62
|
+
this.rpcUrls = urls.filter(u => !!u);
|
|
63
|
+
await this.connectToNext();
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Iterate through stored RPC URLs and connect to the first one that succeeds.
|
|
67
|
+
* Throws if all URLs fail.
|
|
68
|
+
*/
|
|
69
|
+
async connectToNext() {
|
|
70
|
+
let lastError = null;
|
|
71
|
+
for (const url of this.rpcUrls) {
|
|
72
|
+
try {
|
|
73
|
+
const provider = new ethers_1.JsonRpcProvider(url);
|
|
74
|
+
// Verify connectivity by requesting the network
|
|
75
|
+
await provider.getNetwork();
|
|
76
|
+
this.provider = provider;
|
|
77
|
+
logger_1.logger.info(`[DynamicFee] Connected to RPC: ${url}`);
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
catch (err) {
|
|
81
|
+
lastError = err instanceof Error ? err : new Error(String(err));
|
|
82
|
+
logger_1.logger.warn(`[DynamicFee] RPC connection failed for ${url}: ${lastError.message}`);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
// If all URLs failed, fall back to the first URL without connectivity check
|
|
86
|
+
// so that subsequent calls can still attempt requests
|
|
87
|
+
this.provider = new ethers_1.JsonRpcProvider(this.rpcUrls[0]);
|
|
88
|
+
logger_1.logger.warn(`[DynamicFee] All RPC URLs failed connectivity check, using first URL as fallback`);
|
|
44
89
|
}
|
|
45
90
|
async getTTTPriceUsd() {
|
|
46
91
|
const now = Date.now();
|
|
@@ -54,7 +99,13 @@ class DynamicFeeEngine {
|
|
|
54
99
|
price = await this.fetchChainlinkPrice();
|
|
55
100
|
}
|
|
56
101
|
else if (this.config.poolAddress && this.provider) {
|
|
57
|
-
|
|
102
|
+
// To suppress this warning, set `chainlinkFeed` in PriceOracleConfig to a
|
|
103
|
+
// Chainlink AggregatorV3 address (e.g. the TTT/USD feed on your target chain).
|
|
104
|
+
// Chainlink TWAP prices are resistant to single-block flash loan manipulation.
|
|
105
|
+
if (!this.warnedSpotPrice) {
|
|
106
|
+
logger_1.logger.warn("[DynamicFee] Using Uniswap spot price — vulnerable to flash loan manipulation. Configure chainlinkFeed for production.");
|
|
107
|
+
this.warnedSpotPrice = true;
|
|
108
|
+
}
|
|
58
109
|
price = await this.fetchUniswapPrice();
|
|
59
110
|
}
|
|
60
111
|
else {
|
|
@@ -76,7 +127,7 @@ class DynamicFeeEngine {
|
|
|
76
127
|
}
|
|
77
128
|
}
|
|
78
129
|
/**
|
|
79
|
-
*
|
|
130
|
+
* Force-invalidate price cache -- call when immediate price refresh is needed.
|
|
80
131
|
*/
|
|
81
132
|
invalidateCache() {
|
|
82
133
|
this.priceCache = null;
|
package/dist/errors.d.ts
CHANGED
|
@@ -1,45 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Structured error codes for OpenTTT SDK.
|
|
3
|
+
* TTT_E001-E009: Config, TTT_E010-E019: Signer, TTT_E020-E029: Network,
|
|
4
|
+
* TTT_E030-E039: Contract, TTT_E040-E049: TimeSynthesis, TTT_E050-E059: Fee
|
|
5
|
+
*/
|
|
6
|
+
export declare const ERROR_CODES: {
|
|
7
|
+
readonly CONFIG_MISSING_SIGNER: "TTT_E001";
|
|
8
|
+
readonly CONFIG_INVALID: "TTT_E002";
|
|
9
|
+
readonly SIGNER_NOT_INITIALIZED: "TTT_E010";
|
|
10
|
+
readonly SIGNER_MISSING_KEY: "TTT_E011";
|
|
11
|
+
readonly SIGNER_INVALID_KEY_FORMAT: "TTT_E012";
|
|
12
|
+
readonly SIGNER_NO_EIP712: "TTT_E013";
|
|
13
|
+
readonly SIGNER_PRIVY_NOT_IMPLEMENTED: "TTT_E014";
|
|
14
|
+
readonly SIGNER_KMS_AWS_INIT_FAILED: "TTT_E015";
|
|
15
|
+
readonly SIGNER_KMS_GCP_MISSING_FIELDS: "TTT_E016";
|
|
16
|
+
readonly SIGNER_KMS_GCP_INIT_FAILED: "TTT_E017";
|
|
17
|
+
readonly SIGNER_KMS_UNSUPPORTED_PROVIDER: "TTT_E018";
|
|
18
|
+
readonly SIGNER_UNSUPPORTED_TYPE: "TTT_E019";
|
|
19
|
+
readonly NETWORK_INVALID_RPC: "TTT_E020";
|
|
20
|
+
readonly NETWORK_CONNECTION_FAILED: "TTT_E021";
|
|
21
|
+
readonly NETWORK_CANNOT_RECONNECT: "TTT_E022";
|
|
22
|
+
readonly NETWORK_RECONNECTION_EXHAUSTED: "TTT_E023";
|
|
23
|
+
readonly NETWORK_TX_DROPPED: "TTT_E024";
|
|
24
|
+
readonly NETWORK_PROVIDER_NOT_CONNECTED: "TTT_E025";
|
|
25
|
+
readonly NETWORK_BLOCK_NOT_FOUND: "TTT_E026";
|
|
26
|
+
readonly CONTRACT_SIGNER_NOT_CONNECTED: "TTT_E030";
|
|
27
|
+
readonly CONTRACT_INVALID_ADDRESS: "TTT_E031";
|
|
28
|
+
readonly CONTRACT_NOT_ATTACHED: "TTT_E032";
|
|
29
|
+
readonly CONTRACT_BURN_FAILED: "TTT_E033";
|
|
30
|
+
readonly CONTRACT_MINT_FAILED: "TTT_E034";
|
|
31
|
+
readonly CONTRACT_BALANCE_QUERY_FAILED: "TTT_E035";
|
|
32
|
+
readonly CONTRACT_SWAP_FAILED: "TTT_E036";
|
|
33
|
+
readonly CONTRACT_INVALID_KEY_FORMAT: "TTT_E037";
|
|
34
|
+
readonly TIME_SYNTHESIS_INTEGRITY_FAILED: "TTT_E040";
|
|
35
|
+
readonly TIME_SYNTHESIS_INSUFFICIENT_CONFIDENCE: "TTT_E041";
|
|
36
|
+
readonly TIME_SYNTHESIS_SOURCE_NOT_FOUND: "TTT_E042";
|
|
37
|
+
readonly TIME_SYNTHESIS_ALL_SOURCES_FAILED: "TTT_E043";
|
|
38
|
+
readonly TIME_SYNTHESIS_POT_ALL_FAILED: "TTT_E044";
|
|
39
|
+
readonly TIME_SYNTHESIS_SELF_VERIFY_FAILED: "TTT_E045";
|
|
40
|
+
readonly FEE_CALCULATION_FAILED: "TTT_E050";
|
|
41
|
+
};
|
|
42
|
+
export type TTTErrorCode = typeof ERROR_CODES[keyof typeof ERROR_CODES];
|
|
1
43
|
/**
|
|
2
44
|
* Base error class for TTT SDK errors with storytelling capabilities.
|
|
3
45
|
*/
|
|
4
46
|
export declare class TTTBaseError extends Error {
|
|
5
|
-
readonly
|
|
6
|
-
|
|
7
|
-
readonly fix: string;
|
|
8
|
-
constructor(message: string, reason: string, fix: string);
|
|
47
|
+
readonly code: TTTErrorCode;
|
|
48
|
+
constructor(codeOrMessage: TTTErrorCode | string, messageOrReason: string, reasonOrFix: string, fix?: string);
|
|
9
49
|
}
|
|
10
50
|
/**
|
|
11
51
|
* Errors related to SDK or Engine configuration.
|
|
12
52
|
*/
|
|
13
53
|
export declare class TTTConfigError extends TTTBaseError {
|
|
14
|
-
constructor(message: string, reason: string, fix: string);
|
|
15
54
|
}
|
|
16
|
-
/**
|
|
17
|
-
* Errors related to Signer (PrivateKey, Turnkey, Privy, KMS) acquisition or usage.
|
|
18
|
-
*/
|
|
19
55
|
export declare class TTTSignerError extends TTTBaseError {
|
|
20
|
-
constructor(message: string, reason: string, fix: string);
|
|
21
56
|
}
|
|
22
|
-
/**
|
|
23
|
-
* Errors related to Network (RPC, ChainID, Connectivity).
|
|
24
|
-
*/
|
|
25
57
|
export declare class TTTNetworkError extends TTTBaseError {
|
|
26
|
-
constructor(message: string, reason: string, fix: string);
|
|
27
58
|
}
|
|
28
|
-
/**
|
|
29
|
-
* Errors related to Smart Contract interaction (TTT.sol, ProtocolFee.sol).
|
|
30
|
-
*/
|
|
31
59
|
export declare class TTTContractError extends TTTBaseError {
|
|
32
|
-
constructor(message: string, reason: string, fix: string);
|
|
33
60
|
}
|
|
34
|
-
/**
|
|
35
|
-
* Errors related to NTP/KTSat Time Synthesis.
|
|
36
|
-
*/
|
|
37
61
|
export declare class TTTTimeSynthesisError extends TTTBaseError {
|
|
38
|
-
constructor(message: string, reason: string, fix: string);
|
|
39
62
|
}
|
|
40
|
-
/**
|
|
41
|
-
* Errors related to Dynamic Fee Engine or Protocol Fee collection.
|
|
42
|
-
*/
|
|
43
63
|
export declare class TTTFeeError extends TTTBaseError {
|
|
44
|
-
constructor(message: string, reason: string, fix: string);
|
|
45
64
|
}
|
package/dist/errors.js
CHANGED
|
@@ -1,18 +1,67 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.TTTFeeError = exports.TTTTimeSynthesisError = exports.TTTContractError = exports.TTTNetworkError = exports.TTTSignerError = exports.TTTConfigError = exports.TTTBaseError = void 0;
|
|
3
|
+
exports.TTTFeeError = exports.TTTTimeSynthesisError = exports.TTTContractError = exports.TTTNetworkError = exports.TTTSignerError = exports.TTTConfigError = exports.TTTBaseError = exports.ERROR_CODES = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Structured error codes for OpenTTT SDK.
|
|
6
|
+
* TTT_E001-E009: Config, TTT_E010-E019: Signer, TTT_E020-E029: Network,
|
|
7
|
+
* TTT_E030-E039: Contract, TTT_E040-E049: TimeSynthesis, TTT_E050-E059: Fee
|
|
8
|
+
*/
|
|
9
|
+
exports.ERROR_CODES = {
|
|
10
|
+
// Config errors (TTT_E001-E009)
|
|
11
|
+
CONFIG_MISSING_SIGNER: "TTT_E001",
|
|
12
|
+
CONFIG_INVALID: "TTT_E002",
|
|
13
|
+
// Signer errors (TTT_E010-E019)
|
|
14
|
+
SIGNER_NOT_INITIALIZED: "TTT_E010",
|
|
15
|
+
SIGNER_MISSING_KEY: "TTT_E011",
|
|
16
|
+
SIGNER_INVALID_KEY_FORMAT: "TTT_E012",
|
|
17
|
+
SIGNER_NO_EIP712: "TTT_E013",
|
|
18
|
+
SIGNER_PRIVY_NOT_IMPLEMENTED: "TTT_E014",
|
|
19
|
+
SIGNER_KMS_AWS_INIT_FAILED: "TTT_E015",
|
|
20
|
+
SIGNER_KMS_GCP_MISSING_FIELDS: "TTT_E016",
|
|
21
|
+
SIGNER_KMS_GCP_INIT_FAILED: "TTT_E017",
|
|
22
|
+
SIGNER_KMS_UNSUPPORTED_PROVIDER: "TTT_E018",
|
|
23
|
+
SIGNER_UNSUPPORTED_TYPE: "TTT_E019",
|
|
24
|
+
// Network errors (TTT_E020-E029)
|
|
25
|
+
NETWORK_INVALID_RPC: "TTT_E020",
|
|
26
|
+
NETWORK_CONNECTION_FAILED: "TTT_E021",
|
|
27
|
+
NETWORK_CANNOT_RECONNECT: "TTT_E022",
|
|
28
|
+
NETWORK_RECONNECTION_EXHAUSTED: "TTT_E023",
|
|
29
|
+
NETWORK_TX_DROPPED: "TTT_E024",
|
|
30
|
+
NETWORK_PROVIDER_NOT_CONNECTED: "TTT_E025",
|
|
31
|
+
NETWORK_BLOCK_NOT_FOUND: "TTT_E026",
|
|
32
|
+
// Contract errors (TTT_E030-E039)
|
|
33
|
+
CONTRACT_SIGNER_NOT_CONNECTED: "TTT_E030",
|
|
34
|
+
CONTRACT_INVALID_ADDRESS: "TTT_E031",
|
|
35
|
+
CONTRACT_NOT_ATTACHED: "TTT_E032",
|
|
36
|
+
CONTRACT_BURN_FAILED: "TTT_E033",
|
|
37
|
+
CONTRACT_MINT_FAILED: "TTT_E034",
|
|
38
|
+
CONTRACT_BALANCE_QUERY_FAILED: "TTT_E035",
|
|
39
|
+
CONTRACT_SWAP_FAILED: "TTT_E036",
|
|
40
|
+
CONTRACT_INVALID_KEY_FORMAT: "TTT_E037",
|
|
41
|
+
// TimeSynthesis errors (TTT_E040-E049)
|
|
42
|
+
TIME_SYNTHESIS_INTEGRITY_FAILED: "TTT_E040",
|
|
43
|
+
TIME_SYNTHESIS_INSUFFICIENT_CONFIDENCE: "TTT_E041",
|
|
44
|
+
TIME_SYNTHESIS_SOURCE_NOT_FOUND: "TTT_E042",
|
|
45
|
+
TIME_SYNTHESIS_ALL_SOURCES_FAILED: "TTT_E043",
|
|
46
|
+
TIME_SYNTHESIS_POT_ALL_FAILED: "TTT_E044",
|
|
47
|
+
TIME_SYNTHESIS_SELF_VERIFY_FAILED: "TTT_E045",
|
|
48
|
+
// Fee errors (TTT_E050-E059)
|
|
49
|
+
FEE_CALCULATION_FAILED: "TTT_E050",
|
|
50
|
+
};
|
|
4
51
|
/**
|
|
5
52
|
* Base error class for TTT SDK errors with storytelling capabilities.
|
|
6
53
|
*/
|
|
7
54
|
class TTTBaseError extends Error {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
55
|
+
code;
|
|
56
|
+
constructor(codeOrMessage, messageOrReason, reasonOrFix, fix) {
|
|
57
|
+
// Support both old (message, reason, fix) and new (code, message, reason, fix) signatures
|
|
58
|
+
const hasCode = fix !== undefined;
|
|
59
|
+
const code = hasCode ? codeOrMessage : "TTT_E002";
|
|
60
|
+
const message = hasCode ? messageOrReason : codeOrMessage;
|
|
61
|
+
const reason = hasCode ? reasonOrFix : messageOrReason;
|
|
62
|
+
const fixStr = hasCode ? fix : reasonOrFix;
|
|
63
|
+
super(`[${code}] ${message} (Reason: ${reason}. Fix: ${fixStr})`);
|
|
64
|
+
this.code = code;
|
|
16
65
|
this.name = this.constructor.name;
|
|
17
66
|
Object.setPrototypeOf(this, new.target.prototype);
|
|
18
67
|
}
|
|
@@ -22,53 +71,20 @@ exports.TTTBaseError = TTTBaseError;
|
|
|
22
71
|
* Errors related to SDK or Engine configuration.
|
|
23
72
|
*/
|
|
24
73
|
class TTTConfigError extends TTTBaseError {
|
|
25
|
-
constructor(message, reason, fix) {
|
|
26
|
-
super(message, reason, fix);
|
|
27
|
-
}
|
|
28
74
|
}
|
|
29
75
|
exports.TTTConfigError = TTTConfigError;
|
|
30
|
-
/**
|
|
31
|
-
* Errors related to Signer (PrivateKey, Turnkey, Privy, KMS) acquisition or usage.
|
|
32
|
-
*/
|
|
33
76
|
class TTTSignerError extends TTTBaseError {
|
|
34
|
-
constructor(message, reason, fix) {
|
|
35
|
-
super(message, reason, fix);
|
|
36
|
-
}
|
|
37
77
|
}
|
|
38
78
|
exports.TTTSignerError = TTTSignerError;
|
|
39
|
-
/**
|
|
40
|
-
* Errors related to Network (RPC, ChainID, Connectivity).
|
|
41
|
-
*/
|
|
42
79
|
class TTTNetworkError extends TTTBaseError {
|
|
43
|
-
constructor(message, reason, fix) {
|
|
44
|
-
super(message, reason, fix);
|
|
45
|
-
}
|
|
46
80
|
}
|
|
47
81
|
exports.TTTNetworkError = TTTNetworkError;
|
|
48
|
-
/**
|
|
49
|
-
* Errors related to Smart Contract interaction (TTT.sol, ProtocolFee.sol).
|
|
50
|
-
*/
|
|
51
82
|
class TTTContractError extends TTTBaseError {
|
|
52
|
-
constructor(message, reason, fix) {
|
|
53
|
-
super(message, reason, fix);
|
|
54
|
-
}
|
|
55
83
|
}
|
|
56
84
|
exports.TTTContractError = TTTContractError;
|
|
57
|
-
/**
|
|
58
|
-
* Errors related to NTP/KTSat Time Synthesis.
|
|
59
|
-
*/
|
|
60
85
|
class TTTTimeSynthesisError extends TTTBaseError {
|
|
61
|
-
constructor(message, reason, fix) {
|
|
62
|
-
super(message, reason, fix);
|
|
63
|
-
}
|
|
64
86
|
}
|
|
65
87
|
exports.TTTTimeSynthesisError = TTTTimeSynthesisError;
|
|
66
|
-
/**
|
|
67
|
-
* Errors related to Dynamic Fee Engine or Protocol Fee collection.
|
|
68
|
-
*/
|
|
69
88
|
class TTTFeeError extends TTTBaseError {
|
|
70
|
-
constructor(message, reason, fix) {
|
|
71
|
-
super(message, reason, fix);
|
|
72
|
-
}
|
|
73
89
|
}
|
|
74
90
|
exports.TTTFeeError = TTTFeeError;
|
package/dist/evm_connector.d.ts
CHANGED
|
@@ -7,6 +7,10 @@ export interface VerificationResult {
|
|
|
7
7
|
txCount: number;
|
|
8
8
|
latency: number;
|
|
9
9
|
}
|
|
10
|
+
export interface EVMConnectorOptions {
|
|
11
|
+
fallbackRpcUrls?: string[];
|
|
12
|
+
maxReconnectAttempts?: number;
|
|
13
|
+
}
|
|
10
14
|
export declare class EVMConnector {
|
|
11
15
|
private provider;
|
|
12
16
|
private signer;
|
|
@@ -14,7 +18,12 @@ export declare class EVMConnector {
|
|
|
14
18
|
private protocolFeeContract;
|
|
15
19
|
private eventListeners;
|
|
16
20
|
private static readonly GAS_TIMEOUT_MS;
|
|
17
|
-
|
|
21
|
+
private primaryRpcUrl;
|
|
22
|
+
private fallbackRpcUrls;
|
|
23
|
+
private signerOrKey;
|
|
24
|
+
private maxReconnectAttempts;
|
|
25
|
+
private connected;
|
|
26
|
+
constructor(options?: EVMConnectorOptions);
|
|
18
27
|
/**
|
|
19
28
|
* P1-7: Race estimateGas against timeout to prevent DoS
|
|
20
29
|
*/
|
|
@@ -23,6 +32,24 @@ export declare class EVMConnector {
|
|
|
23
32
|
* Connect to an EVM chain using either a private key or a pre-configured signer.
|
|
24
33
|
*/
|
|
25
34
|
connect(rpcUrl: string, signerOrKey: string | Signer): Promise<void>;
|
|
35
|
+
/**
|
|
36
|
+
* Reconnect using stored credentials. Tries primary first, then fallbacks.
|
|
37
|
+
*/
|
|
38
|
+
reconnect(): Promise<void>;
|
|
39
|
+
/**
|
|
40
|
+
* Disconnect and release all resources.
|
|
41
|
+
*/
|
|
42
|
+
disconnect(): void;
|
|
43
|
+
/**
|
|
44
|
+
* Check if the connector is currently connected.
|
|
45
|
+
*/
|
|
46
|
+
isConnected(): boolean;
|
|
47
|
+
/**
|
|
48
|
+
* CT Log Equivalent: PoTAnchored event ABI fragment.
|
|
49
|
+
* Every Proof-of-Time anchor is publicly auditable on-chain,
|
|
50
|
+
* analogous to Certificate Transparency logs in TLS.
|
|
51
|
+
*/
|
|
52
|
+
static readonly POT_ANCHORED_EVENT_ABI = "event PoTAnchored(uint64 indexed timestamp, bytes32 grgHash, uint8 stratum, bytes32 potHash)";
|
|
26
53
|
/**
|
|
27
54
|
* Attach the TTT Token contract.
|
|
28
55
|
*/
|