openttt 0.2.9 → 0.2.11
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/dist/index.d.ts +1 -0
- package/dist/index.js +3 -2
- package/package.json +2 -7
- package/dist/ttt_builder.d.ts +0 -32
- package/dist/ttt_builder.js +0 -84
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -17,11 +17,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
// sdk/src/index.ts
|
|
18
18
|
// 서버 내부 전용 (npm pack에서 제외):
|
|
19
19
|
// grg_forward, grg_inverse, grg_pipeline, golay, reed_solomon
|
|
20
|
-
//
|
|
20
|
+
// auto_mint (GRG 의존)
|
|
21
21
|
// 위 모듈은 서버 코드에서 직접 경로로 import할 것.
|
|
22
22
|
__exportStar(require("./evm_connector"), exports);
|
|
23
23
|
__exportStar(require("./x402_enforcer"), exports);
|
|
24
|
-
|
|
24
|
+
__exportStar(require("./adaptive_switch"), exports);
|
|
25
|
+
// ttt_builder omitted — server-internal only
|
|
25
26
|
__exportStar(require("./protocol_fee"), exports);
|
|
26
27
|
__exportStar(require("./pool_registry"), exports);
|
|
27
28
|
__exportStar(require("./v4_hook"), exports);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "openttt",
|
|
3
|
-
"version": "0.2.
|
|
4
|
-
"description": "OpenTTT
|
|
3
|
+
"version": "0.2.11",
|
|
4
|
+
"description": "OpenTTT \u2014 TLS-grade transaction ordering for DeFi. Time + Logic + Sync.",
|
|
5
5
|
"license": "BSL-1.1",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -13,7 +13,6 @@
|
|
|
13
13
|
"ttt",
|
|
14
14
|
"proof-of-time",
|
|
15
15
|
"transaction-ordering",
|
|
16
|
-
"grg",
|
|
17
16
|
"base",
|
|
18
17
|
"ethereum"
|
|
19
18
|
],
|
|
@@ -64,10 +63,6 @@
|
|
|
64
63
|
"dist/time_synthesis.d.ts",
|
|
65
64
|
"dist/trust_store.js",
|
|
66
65
|
"dist/trust_store.d.ts",
|
|
67
|
-
"dist/ttt_builder.js",
|
|
68
|
-
"dist/ttt_builder.d.ts",
|
|
69
|
-
"dist/ttt_client.js",
|
|
70
|
-
"dist/ttt_client.d.ts",
|
|
71
66
|
"dist/types.js",
|
|
72
67
|
"dist/types.d.ts",
|
|
73
68
|
"dist/v4_hook.js",
|
package/dist/ttt_builder.d.ts
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { AdaptiveMode, Block, TTTRecord } from "./adaptive_switch";
|
|
2
|
-
import { EVMConnector } from "./evm_connector";
|
|
3
|
-
export declare class TTTBuilder {
|
|
4
|
-
private mode;
|
|
5
|
-
private connector;
|
|
6
|
-
private tttBalance;
|
|
7
|
-
private adaptiveSwitch;
|
|
8
|
-
constructor(connector?: EVMConnector);
|
|
9
|
-
/**
|
|
10
|
-
* Purchase TTT from the market using EVMConnector.
|
|
11
|
-
* P1-5: Router/token addresses configurable. P1-6: 5% slippage protection.
|
|
12
|
-
*/
|
|
13
|
-
purchaseTTT(poolAddress: string, amount: bigint, tokenInAddress?: string, routerAddress?: string, slippageBps?: bigint): Promise<void>;
|
|
14
|
-
/**
|
|
15
|
-
* Apply TTT to a block by burning it.
|
|
16
|
-
* This signals the intention to use TTT for prioritized processing.
|
|
17
|
-
*/
|
|
18
|
-
consumeTick(tokenId: string, tier?: string): Promise<void>;
|
|
19
|
-
/**
|
|
20
|
-
* Verify block data using the AdaptiveSwitch pipeline.
|
|
21
|
-
* Updates the current mode based on verification results.
|
|
22
|
-
*/
|
|
23
|
-
verifyBlock(blockData: Block, tttRecord: TTTRecord, chainId: number, poolAddress: string, tier?: string): Promise<AdaptiveMode>;
|
|
24
|
-
/**
|
|
25
|
-
* Return the current TURBO/FULL mode.
|
|
26
|
-
*/
|
|
27
|
-
getMode(): AdaptiveMode;
|
|
28
|
-
/**
|
|
29
|
-
* Helper to get current balance (for testing).
|
|
30
|
-
*/
|
|
31
|
-
getBalance(): bigint;
|
|
32
|
-
}
|
package/dist/ttt_builder.js
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// sdk/src/ttt_builder.ts — TTT Builder Implementation
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.TTTBuilder = void 0;
|
|
5
|
-
const ethers_1 = require("ethers");
|
|
6
|
-
const adaptive_switch_1 = require("./adaptive_switch");
|
|
7
|
-
const evm_connector_1 = require("./evm_connector");
|
|
8
|
-
const dynamic_fee_1 = require("./dynamic_fee");
|
|
9
|
-
const logger_1 = require("./logger");
|
|
10
|
-
class TTTBuilder {
|
|
11
|
-
mode = adaptive_switch_1.AdaptiveMode.FULL;
|
|
12
|
-
connector;
|
|
13
|
-
tttBalance = 0n;
|
|
14
|
-
adaptiveSwitch;
|
|
15
|
-
constructor(connector) {
|
|
16
|
-
this.connector = connector || new evm_connector_1.EVMConnector();
|
|
17
|
-
this.adaptiveSwitch = new adaptive_switch_1.AdaptiveSwitch();
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Purchase TTT from the market using EVMConnector.
|
|
21
|
-
* P1-5: Router/token addresses configurable. P1-6: 5% slippage protection.
|
|
22
|
-
*/
|
|
23
|
-
async purchaseTTT(poolAddress, amount, tokenInAddress = "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913", routerAddress = "0x11C9e42994625A0F52906852A9b91e1B69B79B22", slippageBps = 500n // 5% default slippage protection
|
|
24
|
-
) {
|
|
25
|
-
logger_1.logger.info(`[TTTBuilder] Purchasing ${amount} TTT from pool: ${poolAddress}`);
|
|
26
|
-
// P1-6: Calculate minimum output with slippage protection
|
|
27
|
-
const minAmountOut = (amount * (10000n - slippageBps)) / 10000n;
|
|
28
|
-
const receipt = await this.connector.swap(routerAddress, tokenInAddress, poolAddress, amount, minAmountOut);
|
|
29
|
-
this.tttBalance += amount;
|
|
30
|
-
logger_1.logger.info(`[TTTBuilder] Purchase successful. TX: ${receipt.hash}. Current balance: ${this.tttBalance}`);
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Apply TTT to a block by burning it.
|
|
34
|
-
* This signals the intention to use TTT for prioritized processing.
|
|
35
|
-
*/
|
|
36
|
-
async consumeTick(tokenId, tier = "T1_block") {
|
|
37
|
-
logger_1.logger.info(`[TTTBuilder] Consuming TTT tick for token: ${tokenId} (Tier: ${tier})`);
|
|
38
|
-
// Look up tier-based costs from TIER_USD_MICRO
|
|
39
|
-
// Use BigInt to avoid floating point precision issues (Scale: 1e18)
|
|
40
|
-
const usdCostFactor = dynamic_fee_1.TIER_USD_MICRO[tier] || 10000n; // default 0.01 USD
|
|
41
|
-
let costTTT = (usdCostFactor * (10n ** 12n)); // Convert to 18 decimals (1e6 * 1e12 = 1e18)
|
|
42
|
-
// Apply discount if in TURBO mode (Economic incentive for honest builders)
|
|
43
|
-
// R2-P2-3: Use integer-only discount map to avoid float→BigInt precision loss
|
|
44
|
-
const DISCOUNT_PERMILLE = { "TURBO": 200n, "FULL": 0n };
|
|
45
|
-
const discountPermille = DISCOUNT_PERMILLE[this.adaptiveSwitch.getCurrentMode()] ?? 0n;
|
|
46
|
-
if (discountPermille > 0n) {
|
|
47
|
-
costTTT = (costTTT * (1000n - discountPermille)) / 1000n;
|
|
48
|
-
logger_1.logger.info(`[TTTBuilder] TURBO discount applied: ${Number(discountPermille) / 10}%. Final cost: ${costTTT}`);
|
|
49
|
-
}
|
|
50
|
-
if (this.tttBalance < costTTT) {
|
|
51
|
-
throw new Error(`[TTTBuilder] Insufficient TTT balance to consume tick. Needed: ${costTTT}, Balance: ${this.tttBalance}`);
|
|
52
|
-
}
|
|
53
|
-
// Call the actual burn function on the TTT contract via the connector.
|
|
54
|
-
const grgHash = ethers_1.ethers.keccak256(ethers_1.ethers.toUtf8Bytes(tokenId));
|
|
55
|
-
const tierLevel = parseInt(tier.substring(1, 2)) || 1;
|
|
56
|
-
await this.connector.burnTTT(costTTT, grgHash, tierLevel);
|
|
57
|
-
this.tttBalance -= costTTT;
|
|
58
|
-
logger_1.logger.info(`[TTTBuilder] Tick consumed. Cost: ${costTTT}. Remaining balance: ${this.tttBalance}`);
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* Verify block data using the AdaptiveSwitch pipeline.
|
|
62
|
-
* Updates the current mode based on verification results.
|
|
63
|
-
*/
|
|
64
|
-
async verifyBlock(blockData, tttRecord, chainId, poolAddress, tier) {
|
|
65
|
-
logger_1.logger.info(`[TTTBuilder] Verifying block at timestamp: ${blockData.timestamp}`);
|
|
66
|
-
const result = this.adaptiveSwitch.verifyBlock(blockData, tttRecord, chainId, poolAddress, tier);
|
|
67
|
-
this.mode = result;
|
|
68
|
-
logger_1.logger.info(`[TTTBuilder] Verification complete. Mode: ${this.mode}`);
|
|
69
|
-
return this.mode;
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* Return the current TURBO/FULL mode.
|
|
73
|
-
*/
|
|
74
|
-
getMode() {
|
|
75
|
-
return this.mode;
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Helper to get current balance (for testing).
|
|
79
|
-
*/
|
|
80
|
-
getBalance() {
|
|
81
|
-
return this.tttBalance;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
exports.TTTBuilder = TTTBuilder;
|