openttt 0.2.11 → 0.2.12
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 +99 -284
- package/package.json +9 -12
- package/dist/dynamic_fee.d.ts +0 -75
- package/dist/dynamic_fee.js +0 -254
- package/dist/http_client.d.ts +0 -98
- package/dist/http_client.js +0 -252
- package/dist/integrity_client.d.ts +0 -41
- package/dist/integrity_client.js +0 -122
- package/dist/osnma_source.d.ts +0 -82
- package/dist/osnma_source.js +0 -169
- package/dist/protocol_fee.d.ts +0 -72
- package/dist/protocol_fee.js +0 -199
- package/dist/revenue_tiers.d.ts +0 -36
- package/dist/revenue_tiers.js +0 -83
- package/dist/x402_enforcer.d.ts +0 -44
- package/dist/x402_enforcer.js +0 -92
package/dist/revenue_tiers.js
DELETED
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Revenue Tier Configuration
|
|
4
|
-
* Reflects the TTT Labs pricing strategy: Free/Sponsor-backed T0 up to Institutional T3.
|
|
5
|
-
*/
|
|
6
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.REVENUE_TIERS = exports.RevenueTier = void 0;
|
|
8
|
-
exports.calculateMonthlyCost = calculateMonthlyCost;
|
|
9
|
-
exports.getTierForUseCase = getTierForUseCase;
|
|
10
|
-
var RevenueTier;
|
|
11
|
-
(function (RevenueTier) {
|
|
12
|
-
RevenueTier["T0_EPOCH"] = "T0_EPOCH";
|
|
13
|
-
RevenueTier["T1_BLOCK"] = "T1_BLOCK";
|
|
14
|
-
RevenueTier["T2_SLOT"] = "T2_SLOT";
|
|
15
|
-
RevenueTier["T3_MICRO"] = "T3_MICRO";
|
|
16
|
-
})(RevenueTier || (exports.RevenueTier = RevenueTier = {}));
|
|
17
|
-
exports.REVENUE_TIERS = {
|
|
18
|
-
[RevenueTier.T0_EPOCH]: {
|
|
19
|
-
tier: RevenueTier.T0_EPOCH,
|
|
20
|
-
name: "Standard Epoch",
|
|
21
|
-
interval: "6.4 min",
|
|
22
|
-
pricePerTick: 0,
|
|
23
|
-
currency: "USDC",
|
|
24
|
-
model: "sponsor", // Let's Encrypt model: free to user, sponsor-backed
|
|
25
|
-
target: "Standard L1 Swaps / LP Integration",
|
|
26
|
-
sponsorEligible: true
|
|
27
|
-
},
|
|
28
|
-
[RevenueTier.T1_BLOCK]: {
|
|
29
|
-
tier: RevenueTier.T1_BLOCK,
|
|
30
|
-
name: "Fast Block",
|
|
31
|
-
interval: "2 sec",
|
|
32
|
-
pricePerTick: 0.01,
|
|
33
|
-
currency: "USDC",
|
|
34
|
-
model: "sdk_license",
|
|
35
|
-
target: "L2 Sequencer / Standard DeFi",
|
|
36
|
-
sponsorEligible: false
|
|
37
|
-
},
|
|
38
|
-
[RevenueTier.T2_SLOT]: {
|
|
39
|
-
tier: RevenueTier.T2_SLOT,
|
|
40
|
-
name: "High-Frequency Slot",
|
|
41
|
-
interval: "12 sec",
|
|
42
|
-
pricePerTick: 0.05,
|
|
43
|
-
currency: "USDC",
|
|
44
|
-
model: "sdk_license",
|
|
45
|
-
target: "Active Traders / Arbitrage",
|
|
46
|
-
sponsorEligible: false
|
|
47
|
-
},
|
|
48
|
-
[RevenueTier.T3_MICRO]: {
|
|
49
|
-
tier: RevenueTier.T3_MICRO,
|
|
50
|
-
name: "Institutional Micro-Tick",
|
|
51
|
-
interval: "100 ms",
|
|
52
|
-
pricePerTick: 0.10,
|
|
53
|
-
currency: "USDC",
|
|
54
|
-
model: "enterprise",
|
|
55
|
-
target: "Institutional / HFT Pipelines",
|
|
56
|
-
sponsorEligible: false
|
|
57
|
-
}
|
|
58
|
-
};
|
|
59
|
-
/**
|
|
60
|
-
* Calculate projected monthly cost based on tier and throughput.
|
|
61
|
-
*/
|
|
62
|
-
function calculateMonthlyCost(tier, ticksPerDay) {
|
|
63
|
-
const config = exports.REVENUE_TIERS[tier];
|
|
64
|
-
if (config.pricePerTick === 0)
|
|
65
|
-
return 0;
|
|
66
|
-
return config.pricePerTick * ticksPerDay * 30;
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* Determine the appropriate tier based on a usage description.
|
|
70
|
-
*/
|
|
71
|
-
function getTierForUseCase(useCase) {
|
|
72
|
-
const lowerCase = useCase.toLowerCase();
|
|
73
|
-
if (lowerCase.includes("institutional") || lowerCase.includes("hft") || lowerCase.includes("micro")) {
|
|
74
|
-
return RevenueTier.T3_MICRO;
|
|
75
|
-
}
|
|
76
|
-
if (lowerCase.includes("arbitrage") || lowerCase.includes("trader") || lowerCase.includes("slot")) {
|
|
77
|
-
return RevenueTier.T2_SLOT;
|
|
78
|
-
}
|
|
79
|
-
if (lowerCase.includes("l2") || lowerCase.includes("block") || lowerCase.includes("sequencer")) {
|
|
80
|
-
return RevenueTier.T1_BLOCK;
|
|
81
|
-
}
|
|
82
|
-
return RevenueTier.T0_EPOCH;
|
|
83
|
-
}
|
package/dist/x402_enforcer.d.ts
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { AdaptiveMode } from "./adaptive_switch";
|
|
2
|
-
import { EVMConnector } from "./evm_connector";
|
|
3
|
-
import { ProtocolFeeCollector } from "./protocol_fee";
|
|
4
|
-
import { DynamicFeeEngine, FeeCalculation } from "./dynamic_fee";
|
|
5
|
-
export interface SwapDetails {
|
|
6
|
-
user: string;
|
|
7
|
-
tokenIn: string;
|
|
8
|
-
tokenOut: string;
|
|
9
|
-
amount: bigint;
|
|
10
|
-
}
|
|
11
|
-
export declare class X402Enforcer {
|
|
12
|
-
private static getCost;
|
|
13
|
-
/**
|
|
14
|
-
* Deducts TTT ticks from the provided balance and determines Adaptive Mode.
|
|
15
|
-
*
|
|
16
|
-
* **Important:** By default, the `balance` parameter is an SDK-local value
|
|
17
|
-
* (tracked in-memory by the caller). It is NOT verified against the on-chain
|
|
18
|
-
* TTT token balance. This is sufficient for hot-path tick accounting where
|
|
19
|
-
* on-chain settlement happens separately via `deductOnChain()`.
|
|
20
|
-
*
|
|
21
|
-
* @param feeEngine - Dynamic fee engine for cost calculation
|
|
22
|
-
* @param swap - Swap details (user, tokens, amount)
|
|
23
|
-
* @param balance - SDK-local TTT balance (not on-chain unless verifyOnChain=true)
|
|
24
|
-
* @param tier - Stratum tier (0-3)
|
|
25
|
-
* @param mode - Current adaptive mode (Turbo/Full)
|
|
26
|
-
* @param verifyOnChain - If true, checks on-chain TTT balance via EVMConnector
|
|
27
|
-
* before deducting. Requires `connector` and `tokenId`. Default: false.
|
|
28
|
-
* @param connector - EVMConnector instance (required when verifyOnChain=true)
|
|
29
|
-
* @param tokenId - Token ID for on-chain balance lookup (required when verifyOnChain=true)
|
|
30
|
-
*/
|
|
31
|
-
static deductTick(feeEngine: DynamicFeeEngine, swap: SwapDetails, balance: bigint, tier: number, mode: AdaptiveMode, verifyOnChain?: boolean, connector?: EVMConnector, tokenId?: bigint): Promise<{
|
|
32
|
-
success: boolean;
|
|
33
|
-
remaining: bigint;
|
|
34
|
-
mode: AdaptiveMode;
|
|
35
|
-
}>;
|
|
36
|
-
/**
|
|
37
|
-
* Executes on-chain TTT burn via EVMConnector.
|
|
38
|
-
*/
|
|
39
|
-
static deductOnChain(connector: EVMConnector, feeEngine: DynamicFeeEngine, swap: SwapDetails, grgHash: string, tier: number, feeCollector?: ProtocolFeeCollector, burnFeeCalc?: FeeCalculation, signature?: string, nonce?: bigint, deadline?: number): Promise<string>;
|
|
40
|
-
/**
|
|
41
|
-
* Static validation rule.
|
|
42
|
-
*/
|
|
43
|
-
static enforcePool(feeEngine: DynamicFeeEngine, swap: SwapDetails, tttBalance: bigint, tier: number): Promise<boolean>;
|
|
44
|
-
}
|
package/dist/x402_enforcer.js
DELETED
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// sdk/src/x402_enforcer.ts — x402 Micropayment Enforcer (Expanded)
|
|
3
|
-
// Governs TTT tick consumption and on-chain settlement.
|
|
4
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
-
exports.X402Enforcer = void 0;
|
|
6
|
-
const logger_1 = require("./logger");
|
|
7
|
-
const TIER_MAP = {
|
|
8
|
-
0: "T0_epoch",
|
|
9
|
-
1: "T1_block",
|
|
10
|
-
2: "T2_slot",
|
|
11
|
-
3: "T3_micro"
|
|
12
|
-
};
|
|
13
|
-
class X402Enforcer {
|
|
14
|
-
static async getCost(feeEngine, tier) {
|
|
15
|
-
const tierKey = TIER_MAP[tier] || "T0_epoch";
|
|
16
|
-
const feeCalc = await feeEngine.calculateMintFee(tierKey);
|
|
17
|
-
return feeCalc.tttAmount;
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Deducts TTT ticks from the provided balance and determines Adaptive Mode.
|
|
21
|
-
*
|
|
22
|
-
* **Important:** By default, the `balance` parameter is an SDK-local value
|
|
23
|
-
* (tracked in-memory by the caller). It is NOT verified against the on-chain
|
|
24
|
-
* TTT token balance. This is sufficient for hot-path tick accounting where
|
|
25
|
-
* on-chain settlement happens separately via `deductOnChain()`.
|
|
26
|
-
*
|
|
27
|
-
* @param feeEngine - Dynamic fee engine for cost calculation
|
|
28
|
-
* @param swap - Swap details (user, tokens, amount)
|
|
29
|
-
* @param balance - SDK-local TTT balance (not on-chain unless verifyOnChain=true)
|
|
30
|
-
* @param tier - Stratum tier (0-3)
|
|
31
|
-
* @param mode - Current adaptive mode (Turbo/Full)
|
|
32
|
-
* @param verifyOnChain - If true, checks on-chain TTT balance via EVMConnector
|
|
33
|
-
* before deducting. Requires `connector` and `tokenId`. Default: false.
|
|
34
|
-
* @param connector - EVMConnector instance (required when verifyOnChain=true)
|
|
35
|
-
* @param tokenId - Token ID for on-chain balance lookup (required when verifyOnChain=true)
|
|
36
|
-
*/
|
|
37
|
-
static async deductTick(feeEngine, swap, balance, tier, mode, verifyOnChain = false, connector, tokenId) {
|
|
38
|
-
const cost = await this.getCost(feeEngine, tier);
|
|
39
|
-
// Optional on-chain balance verification before deducting
|
|
40
|
-
if (verifyOnChain) {
|
|
41
|
-
if (!connector || tokenId === undefined) {
|
|
42
|
-
throw new Error("[x402] verifyOnChain requires both connector and tokenId parameters");
|
|
43
|
-
}
|
|
44
|
-
const onChainBalance = await connector.getTTTBalance(swap.user, tokenId);
|
|
45
|
-
if (onChainBalance < cost) {
|
|
46
|
-
throw new Error(`[x402] On-chain balance insufficient for user ${swap.user}. Required: ${cost}, On-chain: ${onChainBalance}.`);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
if (balance < cost) {
|
|
50
|
-
throw new Error(`[x402] Insufficient TTT ticks for user ${swap.user}. Required: ${cost}, Have: ${balance}.`);
|
|
51
|
-
}
|
|
52
|
-
const newBalance = balance - cost;
|
|
53
|
-
logger_1.logger.info(`[x402] Deducted ${cost} ticks for swap. User: ${swap.user}, New Balance: ${newBalance}`);
|
|
54
|
-
return {
|
|
55
|
-
success: true,
|
|
56
|
-
remaining: newBalance,
|
|
57
|
-
mode
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* Executes on-chain TTT burn via EVMConnector.
|
|
62
|
-
*/
|
|
63
|
-
static async deductOnChain(connector, feeEngine, swap, grgHash, tier, feeCollector, burnFeeCalc, signature, nonce, deadline) {
|
|
64
|
-
logger_1.logger.info(`[x402] Enforcing on-chain settlement for user ${swap.user}...`);
|
|
65
|
-
const cost = await this.getCost(feeEngine, tier);
|
|
66
|
-
try {
|
|
67
|
-
const receipt = await connector.burnTTT(cost, grgHash, tier);
|
|
68
|
-
// Collect protocol burn fee if feeCollector and required params are provided
|
|
69
|
-
if (feeCollector && burnFeeCalc && signature && nonce !== undefined && deadline !== undefined) {
|
|
70
|
-
try {
|
|
71
|
-
await feeCollector.collectBurnFee(burnFeeCalc, signature, swap.user, nonce, deadline);
|
|
72
|
-
}
|
|
73
|
-
catch (feeError) {
|
|
74
|
-
logger_1.logger.error(`[x402] Burn fee collection failed but burn was successful: ${feeError instanceof Error ? feeError.message : feeError}`);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
return receipt.hash;
|
|
78
|
-
}
|
|
79
|
-
catch (error) {
|
|
80
|
-
logger_1.logger.error(`[x402] On-chain enforcement failed: ${error instanceof Error ? error.message : error}`);
|
|
81
|
-
throw error;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* Static validation rule.
|
|
86
|
-
*/
|
|
87
|
-
static async enforcePool(feeEngine, swap, tttBalance, tier) {
|
|
88
|
-
const cost = await this.getCost(feeEngine, tier);
|
|
89
|
-
return tttBalance >= cost;
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
exports.X402Enforcer = X402Enforcer;
|