@latens/sdk 0.0.0-stage → 1.3.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/LICENSE +21 -0
- package/README.md +108 -2
- package/dist/calculator.d.ts +2 -0
- package/dist/calculator.js +30 -0
- package/dist/client.d.ts +78 -0
- package/dist/client.js +151 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +6 -0
- package/dist/normalizer.d.ts +2 -0
- package/dist/normalizer.js +40 -0
- package/dist/sizing.d.ts +13 -0
- package/dist/sizing.js +248 -0
- package/dist/standing.d.ts +20 -0
- package/dist/standing.js +99 -0
- package/dist/types.d.ts +230 -0
- package/dist/types.js +1 -0
- package/openapi/openapi.v3.1.json +410 -0
- package/package.json +49 -4
- package/src/calculator.ts +43 -0
- package/src/client.ts +272 -0
- package/src/index.ts +6 -0
- package/src/normalizer.ts +43 -0
- package/src/sizing.ts +335 -0
- package/src/standing.ts +126 -0
- package/src/types.ts +278 -0
package/dist/sizing.js
ADDED
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
import { calculateDeterministicComputeCost } from "./calculator.js";
|
|
2
|
+
import { roundUsd } from "./normalizer.js";
|
|
3
|
+
import { calculateEffectiveDeskFeeBps } from "./standing.js";
|
|
4
|
+
const BYTES_PER_PARAM = {
|
|
5
|
+
fp32: 4.0,
|
|
6
|
+
fp16: 2.0,
|
|
7
|
+
bf16: 2.0,
|
|
8
|
+
fp8: 1.0,
|
|
9
|
+
int8: 1.0,
|
|
10
|
+
q8_0: 1.06,
|
|
11
|
+
q4_k_m: 0.6,
|
|
12
|
+
int4: 0.55,
|
|
13
|
+
};
|
|
14
|
+
const KV_BYTES_PER_ELEMENT = {
|
|
15
|
+
fp16: 2.0,
|
|
16
|
+
fp8: 1.0,
|
|
17
|
+
int8: 1.0,
|
|
18
|
+
};
|
|
19
|
+
const HARDWARE_TEMPLATES = [
|
|
20
|
+
{
|
|
21
|
+
gpuModel: "RTX 3090",
|
|
22
|
+
vramPerGpuGb: 24,
|
|
23
|
+
validCounts: [1, 2, 4],
|
|
24
|
+
notes: "Cost-efficient 24 GB consumer tier for quantized inference.",
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
gpuModel: "RTX 4090",
|
|
28
|
+
vramPerGpuGb: 24,
|
|
29
|
+
validCounts: [1, 2, 4, 8],
|
|
30
|
+
notes: "High throughput 24 GB PCIe nodes for inference and LoRA fine-tuning.",
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
gpuModel: "L40S",
|
|
34
|
+
vramPerGpuGb: 48,
|
|
35
|
+
validCounts: [1, 2, 4, 8],
|
|
36
|
+
notes: "48 GB datacenter FP8 accelerator suited for mid-size LLMs.",
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
gpuModel: "A100 SXM",
|
|
40
|
+
vramPerGpuGb: 80,
|
|
41
|
+
validCounts: [1, 2, 4, 8],
|
|
42
|
+
notes: "80 GB HBM2e with NVLink for production inference and training.",
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
gpuModel: "H100 SXM",
|
|
46
|
+
vramPerGpuGb: 80,
|
|
47
|
+
validCounts: [1, 2, 4, 8],
|
|
48
|
+
notes: "80 GB HBM3 with Transformer Engine FP8 and high-bandwidth NVLink.",
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
gpuModel: "H200",
|
|
52
|
+
vramPerGpuGb: 141,
|
|
53
|
+
validCounts: [1, 2, 4, 8],
|
|
54
|
+
notes: "141 GB HBM3e for long-context 70B+ and 405B models with fewer nodes.",
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
gpuModel: "B200",
|
|
58
|
+
vramPerGpuGb: 192,
|
|
59
|
+
validCounts: [1, 2, 4, 8],
|
|
60
|
+
notes: "192 GB HBM3e flagship cluster nodes for frontier training and MoE.",
|
|
61
|
+
},
|
|
62
|
+
];
|
|
63
|
+
function estimateKvCacheGb(params) {
|
|
64
|
+
const { parameterCountBillions, contextLength, batchSize, kvQuantization } = params;
|
|
65
|
+
/*
|
|
66
|
+
* Deterministic GQA-aware heuristic matching modern Llama/Qwen/DeepSeek
|
|
67
|
+
* transformer architectures:
|
|
68
|
+
* - ~32 layers @ 7B, ~80 layers @ 70B, ~126 layers @ 405B
|
|
69
|
+
* - Effective KV heads/dim scales sublinearly with parameter count due to GQA
|
|
70
|
+
*/
|
|
71
|
+
const estimatedLayers = Math.max(24, Math.round(14 * Math.pow(parameterCountBillions, 0.42)));
|
|
72
|
+
const kvHiddenDim = Math.max(512, Math.round(320 * Math.pow(parameterCountBillions, 0.34)));
|
|
73
|
+
const bytesPerEl = KV_BYTES_PER_ELEMENT[kvQuantization];
|
|
74
|
+
const bytes = 2 * estimatedLayers * kvHiddenDim * contextLength * batchSize * bytesPerEl;
|
|
75
|
+
return bytes / 1024 ** 3;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Deterministically estimate GPU VRAM requirements for LLM inference,
|
|
79
|
+
* LoRA/QLoRA fine-tuning, or full-parameter fine-tuning, and return
|
|
80
|
+
* compatible multi-GPU hardware layouts.
|
|
81
|
+
*/
|
|
82
|
+
export function estimateLlmVramRequirements(input) {
|
|
83
|
+
if (!Number.isFinite(input.parameterCountBillions) ||
|
|
84
|
+
input.parameterCountBillions <= 0) {
|
|
85
|
+
throw new RangeError("parameterCountBillions must be greater than zero.");
|
|
86
|
+
}
|
|
87
|
+
const quantization = input.quantization ?? "bf16";
|
|
88
|
+
const mode = input.mode ?? "inference";
|
|
89
|
+
const contextLength = Math.max(512, Math.floor(input.contextLength ?? 8192));
|
|
90
|
+
const batchSize = Math.max(1, Math.floor(input.batchSize ?? 1));
|
|
91
|
+
const kvQuantization = input.kvCacheQuantization ?? "fp16";
|
|
92
|
+
const headroomPct = Math.min(50, Math.max(5, input.headroomPct ?? 15));
|
|
93
|
+
const bytesPerParam = BYTES_PER_PARAM[quantization];
|
|
94
|
+
if (!bytesPerParam) {
|
|
95
|
+
throw new TypeError(`Unsupported quantization: ${String(quantization)}`);
|
|
96
|
+
}
|
|
97
|
+
const weightsGb = (input.parameterCountBillions * 1e9 * bytesPerParam) / 1024 ** 3;
|
|
98
|
+
const kvCacheGb = estimateKvCacheGb({
|
|
99
|
+
parameterCountBillions: input.parameterCountBillions,
|
|
100
|
+
contextLength,
|
|
101
|
+
batchSize,
|
|
102
|
+
kvQuantization,
|
|
103
|
+
});
|
|
104
|
+
let trainingOverheadGb = 0;
|
|
105
|
+
if (mode === "lora_finetune") {
|
|
106
|
+
/* Adapter weights + AdamW states on trainable LoRA ranks + activation checkpoints */
|
|
107
|
+
const trainableParamRatio = 0.025;
|
|
108
|
+
const adapterStatesGb = (input.parameterCountBillions * 1e9 * trainableParamRatio * 16) / 1024 ** 3;
|
|
109
|
+
const activationsGb = (input.parameterCountBillions * 0.14 * Math.sqrt(contextLength / 4096)) *
|
|
110
|
+
Math.sqrt(batchSize);
|
|
111
|
+
trainingOverheadGb = adapterStatesGb + activationsGb;
|
|
112
|
+
}
|
|
113
|
+
else if (mode === "full_finetune") {
|
|
114
|
+
/*
|
|
115
|
+
* Mixed-precision AdamW (FP32 master weights + momentum + variance = 12 bytes/param)
|
|
116
|
+
* plus BF16 gradients (2 bytes/param) and gradient-checkpointed activations.
|
|
117
|
+
*/
|
|
118
|
+
const optimizerAndGradsGb = (input.parameterCountBillions * 1e9 * 14) / 1024 ** 3;
|
|
119
|
+
const activationsGb = (input.parameterCountBillions * 0.25 * Math.sqrt(contextLength / 4096)) *
|
|
120
|
+
Math.sqrt(batchSize);
|
|
121
|
+
trainingOverheadGb = optimizerAndGradsGb + activationsGb;
|
|
122
|
+
}
|
|
123
|
+
const cudaContextGb = 1.5;
|
|
124
|
+
const rawTotalGb = weightsGb + kvCacheGb + trainingOverheadGb + cudaContextGb;
|
|
125
|
+
const runtimeOverheadGb = cudaContextGb + rawTotalGb * (headroomPct / 100);
|
|
126
|
+
const minimumVramGb = roundUsd(rawTotalGb, 2);
|
|
127
|
+
const recommendedVramGb = roundUsd(weightsGb + kvCacheGb + trainingOverheadGb + runtimeOverheadGb, 2);
|
|
128
|
+
const recommendedConfigs = [];
|
|
129
|
+
for (const tpl of HARDWARE_TEMPLATES) {
|
|
130
|
+
const count = tpl.validCounts.find((c) => c * tpl.vramPerGpuGb >= recommendedVramGb);
|
|
131
|
+
if (!count)
|
|
132
|
+
continue;
|
|
133
|
+
const totalVramGb = count * tpl.vramPerGpuGb;
|
|
134
|
+
const utilizationPct = roundUsd((recommendedVramGb / totalVramGb) * 100, 1);
|
|
135
|
+
recommendedConfigs.push({
|
|
136
|
+
gpuModel: tpl.gpuModel,
|
|
137
|
+
gpuCount: count,
|
|
138
|
+
vramPerGpuGb: tpl.vramPerGpuGb,
|
|
139
|
+
totalVramGb,
|
|
140
|
+
estimatedUtilizationPct: utilizationPct,
|
|
141
|
+
notes: tpl.notes,
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
recommendedConfigs.sort((a, b) => {
|
|
145
|
+
if (a.gpuCount !== b.gpuCount)
|
|
146
|
+
return a.gpuCount - b.gpuCount;
|
|
147
|
+
return a.totalVramGb - b.totalVramGb;
|
|
148
|
+
});
|
|
149
|
+
return {
|
|
150
|
+
parameterCountBillions: input.parameterCountBillions,
|
|
151
|
+
quantization,
|
|
152
|
+
mode,
|
|
153
|
+
contextLength,
|
|
154
|
+
batchSize,
|
|
155
|
+
kvCacheQuantization: kvQuantization,
|
|
156
|
+
weightsGb: roundUsd(weightsGb, 2),
|
|
157
|
+
kvCacheGb: roundUsd(kvCacheGb, 2),
|
|
158
|
+
trainingOverheadGb: roundUsd(trainingOverheadGb, 2),
|
|
159
|
+
runtimeOverheadGb: roundUsd(runtimeOverheadGb, 2),
|
|
160
|
+
minimumVramGb,
|
|
161
|
+
recommendedVramGb,
|
|
162
|
+
recommendedConfigs,
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Deterministically rank normalized GPU offers by total cost of ownership
|
|
167
|
+
* (compute + persistent storage + outbound egress), with optional $LTNS
|
|
168
|
+
* Private Compute Desk fee estimation.
|
|
169
|
+
*/
|
|
170
|
+
export function rankOffersByTco(offers, options) {
|
|
171
|
+
if (!Number.isFinite(options.durationHours) || options.durationHours <= 0) {
|
|
172
|
+
throw new RangeError("durationHours must be greater than zero.");
|
|
173
|
+
}
|
|
174
|
+
const availableOnly = options.availableOnly ?? true;
|
|
175
|
+
const confirmedOnly = options.confirmedOnly ?? false;
|
|
176
|
+
const minTotalVramGb = Math.max(0, options.minTotalVramGb ?? 0);
|
|
177
|
+
const storageGb = Math.max(0, options.storageGb ?? 0);
|
|
178
|
+
const egressGb = Math.max(0, options.egressGb ?? 0);
|
|
179
|
+
const fallbackStorageRate = Math.max(0, options.defaultStorageCostPerGbMonthUsd ?? 0.1);
|
|
180
|
+
const fallbackEgressRate = Math.max(0, options.defaultEgressCostPerGbUsd ?? 0);
|
|
181
|
+
const holderTier = options.holderTier ?? "open";
|
|
182
|
+
const settlementAsset = options.settlementAsset ?? "USDG";
|
|
183
|
+
const feeSpec = calculateEffectiveDeskFeeBps(holderTier, settlementAsset);
|
|
184
|
+
const eligible = offers.filter((offer) => {
|
|
185
|
+
if (availableOnly && offer.availability_status === "unavailable") {
|
|
186
|
+
return false;
|
|
187
|
+
}
|
|
188
|
+
if (confirmedOnly && offer.price_precision !== "confirmed_offer") {
|
|
189
|
+
return false;
|
|
190
|
+
}
|
|
191
|
+
if (offer.total_vram_gb < minTotalVramGb) {
|
|
192
|
+
return false;
|
|
193
|
+
}
|
|
194
|
+
return offer.hourly_price_usd > 0;
|
|
195
|
+
});
|
|
196
|
+
const rankedRaw = eligible.map((offer) => {
|
|
197
|
+
const breakdown = calculateDeterministicComputeCost({
|
|
198
|
+
hourlyRatePerInstanceUsd: offer.hourly_price_usd,
|
|
199
|
+
instanceCount: 1,
|
|
200
|
+
durationHours: options.durationHours,
|
|
201
|
+
storageGb,
|
|
202
|
+
storageCostPerGbMonthUsd: offer.storage_cost_per_gb_month_usd ?? fallbackStorageRate,
|
|
203
|
+
egressGb,
|
|
204
|
+
egressCostPerGbUsd: offer.egress_cost_per_gb_usd ?? fallbackEgressRate,
|
|
205
|
+
});
|
|
206
|
+
const estimatedDeskFeeUsd = roundUsd(breakdown.totalEstimatedUsd * (feeSpec.effectiveFeeBps / 10_000), 4);
|
|
207
|
+
return {
|
|
208
|
+
offerId: offer.id,
|
|
209
|
+
provider: offer.provider,
|
|
210
|
+
gpuModel: offer.gpu_model,
|
|
211
|
+
gpuCount: offer.gpu_count,
|
|
212
|
+
totalVramGb: offer.total_vram_gb,
|
|
213
|
+
region: offer.region,
|
|
214
|
+
pricePrecision: offer.price_precision,
|
|
215
|
+
productCategory: offer.product_category,
|
|
216
|
+
hourlyPriceUsd: roundUsd(offer.hourly_price_usd, 4),
|
|
217
|
+
pricePerGpuUsd: roundUsd(offer.price_per_gpu_usd, 4),
|
|
218
|
+
breakdown,
|
|
219
|
+
deskFeeBps: feeSpec.effectiveFeeBps,
|
|
220
|
+
estimatedDeskFeeUsd,
|
|
221
|
+
totalWithDeskFeeUsd: roundUsd(breakdown.totalEstimatedUsd + estimatedDeskFeeUsd, 4),
|
|
222
|
+
savingsVsMostExpensiveUsd: 0,
|
|
223
|
+
sourceUrl: offer.source_url,
|
|
224
|
+
};
|
|
225
|
+
});
|
|
226
|
+
rankedRaw.sort((a, b) => a.breakdown.totalEstimatedUsd - b.breakdown.totalEstimatedUsd);
|
|
227
|
+
const cheapest = rankedRaw[0]?.breakdown.totalEstimatedUsd ?? 0;
|
|
228
|
+
const mostExpensive = rankedRaw[rankedRaw.length - 1]?.breakdown.totalEstimatedUsd ?? 0;
|
|
229
|
+
const ranked = rankedRaw.map((entry) => ({
|
|
230
|
+
...entry,
|
|
231
|
+
savingsVsMostExpensiveUsd: roundUsd(Math.max(0, mostExpensive - entry.breakdown.totalEstimatedUsd), 4),
|
|
232
|
+
}));
|
|
233
|
+
const spreadMultiplier = cheapest > 0 && mostExpensive > 0
|
|
234
|
+
? roundUsd(mostExpensive / cheapest, 2)
|
|
235
|
+
: 1;
|
|
236
|
+
return {
|
|
237
|
+
durationHours: options.durationHours,
|
|
238
|
+
evaluatedCount: offers.length,
|
|
239
|
+
eligibleCount: ranked.length,
|
|
240
|
+
holderTier,
|
|
241
|
+
settlementAsset,
|
|
242
|
+
effectiveDeskFeeBps: feeSpec.effectiveFeeBps,
|
|
243
|
+
cheapestTotalUsd: cheapest,
|
|
244
|
+
mostExpensiveTotalUsd: mostExpensive,
|
|
245
|
+
spreadMultiplier,
|
|
246
|
+
ranked,
|
|
247
|
+
};
|
|
248
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { HolderTierId, LtnsTierSpec, SettlementAsset } from "./types.js";
|
|
2
|
+
export declare const LTNS_CHAIN_ID = 4663;
|
|
3
|
+
export declare const LTNS_CHAIN_NAME = "Robinhood Chain";
|
|
4
|
+
export declare const LTNS_CONTRACT_ADDRESS = "0x6c29b040f7d139c93d22f8d6e29b1528e3ca4bf9";
|
|
5
|
+
export declare const LTNS_DECIMALS = 18;
|
|
6
|
+
export declare const LTNS_TOTAL_SUPPLY = 1000000000;
|
|
7
|
+
export declare const LTNS_SETTLEMENT_REBATE_BPS = 15;
|
|
8
|
+
export declare const LTNS_TIERS: readonly LtnsTierSpec[];
|
|
9
|
+
export declare function isValidEvmAddress(address: string): boolean;
|
|
10
|
+
export declare function resolveHolderTier(balanceTokens: number): {
|
|
11
|
+
tier: LtnsTierSpec;
|
|
12
|
+
nextTier: LtnsTierSpec | null;
|
|
13
|
+
tokensToNextTier: number;
|
|
14
|
+
};
|
|
15
|
+
export declare function calculateEffectiveDeskFeeBps(tierId: HolderTierId, settlementAsset?: SettlementAsset): {
|
|
16
|
+
baseTierFeeBps: number;
|
|
17
|
+
settlementExtraRebateBps: number;
|
|
18
|
+
effectiveFeeBps: number;
|
|
19
|
+
effectiveFeePct: number;
|
|
20
|
+
};
|
package/dist/standing.js
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
export const LTNS_CHAIN_ID = 4663;
|
|
2
|
+
export const LTNS_CHAIN_NAME = "Robinhood Chain";
|
|
3
|
+
export const LTNS_CONTRACT_ADDRESS = "0x6c29b040f7d139c93d22f8d6e29b1528e3ca4bf9";
|
|
4
|
+
export const LTNS_DECIMALS = 18;
|
|
5
|
+
export const LTNS_TOTAL_SUPPLY = 1_000_000_000;
|
|
6
|
+
export const LTNS_SETTLEMENT_REBATE_BPS = 15;
|
|
7
|
+
export const LTNS_TIERS = [
|
|
8
|
+
{
|
|
9
|
+
id: "open",
|
|
10
|
+
code: "TIER 00",
|
|
11
|
+
label: "Open Access",
|
|
12
|
+
shortLabel: "OPEN",
|
|
13
|
+
minTokens: 0,
|
|
14
|
+
supplySharePct: "0.00%",
|
|
15
|
+
deskQueueLabel: "Standard Queue",
|
|
16
|
+
deskPriorityRank: 0,
|
|
17
|
+
deskFeeBps: 100,
|
|
18
|
+
feeRebatePct: 0,
|
|
19
|
+
brokerLimit15m: 30,
|
|
20
|
+
agentReadRpm: 60,
|
|
21
|
+
agentCalculateRpm: 90,
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
id: "verified",
|
|
25
|
+
code: "TIER 01",
|
|
26
|
+
label: "Verified Holder",
|
|
27
|
+
shortLabel: "VERIFIED",
|
|
28
|
+
minTokens: 100_000,
|
|
29
|
+
supplySharePct: "0.01%",
|
|
30
|
+
deskQueueLabel: "Priority Batch",
|
|
31
|
+
deskPriorityRank: 1,
|
|
32
|
+
deskFeeBps: 75,
|
|
33
|
+
feeRebatePct: 25,
|
|
34
|
+
brokerLimit15m: 75,
|
|
35
|
+
agentReadRpm: 150,
|
|
36
|
+
agentCalculateRpm: 225,
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
id: "priority",
|
|
40
|
+
code: "TIER 02",
|
|
41
|
+
label: "Priority Desk",
|
|
42
|
+
shortLabel: "PRIORITY",
|
|
43
|
+
minTokens: 1_000_000,
|
|
44
|
+
supplySharePct: "0.10%",
|
|
45
|
+
deskQueueLabel: "Dedicated Sourcing",
|
|
46
|
+
deskPriorityRank: 2,
|
|
47
|
+
deskFeeBps: 50,
|
|
48
|
+
feeRebatePct: 50,
|
|
49
|
+
brokerLimit15m: 150,
|
|
50
|
+
agentReadRpm: 300,
|
|
51
|
+
agentCalculateRpm: 450,
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
id: "institutional",
|
|
55
|
+
code: "TIER 03",
|
|
56
|
+
label: "Institutional Clearing",
|
|
57
|
+
shortLabel: "INSTITUTIONAL",
|
|
58
|
+
minTokens: 5_000_000,
|
|
59
|
+
supplySharePct: "0.50%",
|
|
60
|
+
deskQueueLabel: "Direct Allocation",
|
|
61
|
+
deskPriorityRank: 3,
|
|
62
|
+
deskFeeBps: 0,
|
|
63
|
+
feeRebatePct: 100,
|
|
64
|
+
brokerLimit15m: 300,
|
|
65
|
+
agentReadRpm: 600,
|
|
66
|
+
agentCalculateRpm: 900,
|
|
67
|
+
},
|
|
68
|
+
];
|
|
69
|
+
export function isValidEvmAddress(address) {
|
|
70
|
+
return /^0x[a-fA-F0-9]{40}$/.test(address.trim());
|
|
71
|
+
}
|
|
72
|
+
export function resolveHolderTier(balanceTokens) {
|
|
73
|
+
const safe = Number.isFinite(balanceTokens) ? Math.max(0, balanceTokens) : 0;
|
|
74
|
+
let activeIndex = 0;
|
|
75
|
+
for (let i = LTNS_TIERS.length - 1; i >= 0; i--) {
|
|
76
|
+
const candidate = LTNS_TIERS[i];
|
|
77
|
+
if (candidate && safe >= candidate.minTokens) {
|
|
78
|
+
activeIndex = i;
|
|
79
|
+
break;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
const tier = LTNS_TIERS[activeIndex] ?? LTNS_TIERS[0];
|
|
83
|
+
const nextTier = LTNS_TIERS[activeIndex + 1] ?? null;
|
|
84
|
+
const tokensToNextTier = nextTier
|
|
85
|
+
? Math.max(0, Math.ceil(nextTier.minTokens - safe))
|
|
86
|
+
: 0;
|
|
87
|
+
return { tier, nextTier, tokensToNextTier };
|
|
88
|
+
}
|
|
89
|
+
export function calculateEffectiveDeskFeeBps(tierId, settlementAsset = "USDG") {
|
|
90
|
+
const tier = LTNS_TIERS.find((item) => item.id === tierId) ?? LTNS_TIERS[0];
|
|
91
|
+
const extraRebate = settlementAsset === "LTNS" ? LTNS_SETTLEMENT_REBATE_BPS : 0;
|
|
92
|
+
const effectiveFeeBps = Math.max(0, tier.deskFeeBps - extraRebate);
|
|
93
|
+
return {
|
|
94
|
+
baseTierFeeBps: tier.deskFeeBps,
|
|
95
|
+
settlementExtraRebateBps: extraRebate,
|
|
96
|
+
effectiveFeeBps,
|
|
97
|
+
effectiveFeePct: Number((effectiveFeeBps / 100).toFixed(2)),
|
|
98
|
+
};
|
|
99
|
+
}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
export type ProviderId = "vast" | "runpod" | "cudo" | "vultr" | "akash" | "lambda" | "crusoe" | "scaleway";
|
|
2
|
+
export type PricePrecision = "confirmed_offer" | "catalog_starting";
|
|
3
|
+
export type ProductCategory = "dedicated_instance" | "secure_pod" | "community_pod" | "cloud_vm" | "bare_metal" | "decentralized_lease" | "interruptible_spot";
|
|
4
|
+
export type HolderTierId = "open" | "verified" | "priority" | "institutional";
|
|
5
|
+
export type SettlementAsset = "USDG" | "LTNS" | "ETH" | "USD";
|
|
6
|
+
export interface LtnsTierSpec {
|
|
7
|
+
id: HolderTierId;
|
|
8
|
+
code: string;
|
|
9
|
+
label: string;
|
|
10
|
+
shortLabel: string;
|
|
11
|
+
minTokens: number;
|
|
12
|
+
supplySharePct: string;
|
|
13
|
+
deskQueueLabel: string;
|
|
14
|
+
deskPriorityRank: number;
|
|
15
|
+
deskFeeBps: number;
|
|
16
|
+
feeRebatePct: number;
|
|
17
|
+
brokerLimit15m: number;
|
|
18
|
+
agentReadRpm: number;
|
|
19
|
+
agentCalculateRpm: number;
|
|
20
|
+
}
|
|
21
|
+
export interface WalletTokenStanding {
|
|
22
|
+
walletAddress: string;
|
|
23
|
+
tokenAddress: string;
|
|
24
|
+
ticker: string;
|
|
25
|
+
chainId: number;
|
|
26
|
+
balanceWei: string;
|
|
27
|
+
balanceTokens: number;
|
|
28
|
+
balanceFormatted: string;
|
|
29
|
+
tier: LtnsTierSpec;
|
|
30
|
+
nextTier: LtnsTierSpec | null;
|
|
31
|
+
tokensToNextTier: number;
|
|
32
|
+
progressToNextPct: number;
|
|
33
|
+
source: "onchain_rpc" | "cache" | "fallback";
|
|
34
|
+
checkedAt: string;
|
|
35
|
+
buyUrl: string;
|
|
36
|
+
explorerUrl: string;
|
|
37
|
+
}
|
|
38
|
+
export interface TokenStandingResponse {
|
|
39
|
+
token: {
|
|
40
|
+
ticker: string;
|
|
41
|
+
contractAddress: string;
|
|
42
|
+
chainId: number;
|
|
43
|
+
chainName: string;
|
|
44
|
+
decimals: number;
|
|
45
|
+
totalSupply: number;
|
|
46
|
+
settlementExtraRebateBps: number;
|
|
47
|
+
buyUrl: string;
|
|
48
|
+
explorerUrl: string;
|
|
49
|
+
};
|
|
50
|
+
tiers: LtnsTierSpec[];
|
|
51
|
+
standing: WalletTokenStanding | null;
|
|
52
|
+
}
|
|
53
|
+
export interface NormalizedGpuOffer {
|
|
54
|
+
id: string;
|
|
55
|
+
provider: ProviderId;
|
|
56
|
+
provider_offer_id: string;
|
|
57
|
+
gpu_model: string;
|
|
58
|
+
gpu_raw_name: string;
|
|
59
|
+
manufacturer: "NVIDIA" | "AMD" | "Intel" | "Other";
|
|
60
|
+
gpu_count: number;
|
|
61
|
+
vram_per_gpu_gb: number;
|
|
62
|
+
total_vram_gb: number;
|
|
63
|
+
hourly_price_usd: number;
|
|
64
|
+
price_per_gpu_usd: number;
|
|
65
|
+
currency: "USD";
|
|
66
|
+
price_precision: PricePrecision;
|
|
67
|
+
product_category: ProductCategory;
|
|
68
|
+
region: string;
|
|
69
|
+
country_code: string | null;
|
|
70
|
+
availability_status: "available" | "limited" | "unavailable";
|
|
71
|
+
reliability_score: number | null;
|
|
72
|
+
storage_cost_per_gb_month_usd: number | null;
|
|
73
|
+
egress_cost_per_gb_usd: number | null;
|
|
74
|
+
cpu_cores: number | null;
|
|
75
|
+
system_ram_gb: number | null;
|
|
76
|
+
disk_space_gb: number | null;
|
|
77
|
+
cuda_version: string | null;
|
|
78
|
+
source_url: string;
|
|
79
|
+
fetched_at: string;
|
|
80
|
+
is_stale: boolean;
|
|
81
|
+
}
|
|
82
|
+
export type AgentOffersSort = "price_asc" | "price_desc" | "vram_desc";
|
|
83
|
+
export type PriceHistoryWindow = "24h" | "7d" | "30d";
|
|
84
|
+
export type PriceHistoryInterval = "15m" | "1h" | "1d";
|
|
85
|
+
export interface GpuPriceHistoryQuery {
|
|
86
|
+
model: string;
|
|
87
|
+
window?: PriceHistoryWindow;
|
|
88
|
+
interval?: PriceHistoryInterval;
|
|
89
|
+
category?: ProductCategory | "all";
|
|
90
|
+
}
|
|
91
|
+
export interface PriceHistoryPoint {
|
|
92
|
+
t: string;
|
|
93
|
+
min: number;
|
|
94
|
+
median: number;
|
|
95
|
+
max: number;
|
|
96
|
+
offers: number;
|
|
97
|
+
providers: number;
|
|
98
|
+
}
|
|
99
|
+
export interface GpuPriceHistoryResponse {
|
|
100
|
+
object: "gpu_price_history";
|
|
101
|
+
read_only: boolean;
|
|
102
|
+
model: string;
|
|
103
|
+
matched_models?: string[];
|
|
104
|
+
window: PriceHistoryWindow;
|
|
105
|
+
interval: PriceHistoryInterval;
|
|
106
|
+
category: string;
|
|
107
|
+
first_recorded_at: string | null;
|
|
108
|
+
coverage_hours: number;
|
|
109
|
+
points: PriceHistoryPoint[];
|
|
110
|
+
}
|
|
111
|
+
export interface AgentOffersQuery {
|
|
112
|
+
model?: string;
|
|
113
|
+
gpu_model?: string;
|
|
114
|
+
provider?: ProviderId | "all";
|
|
115
|
+
category?: ProductCategory | "all" | "all_dedicated";
|
|
116
|
+
min_vram_gb?: number;
|
|
117
|
+
max_price_per_gpu_usd?: number;
|
|
118
|
+
max_hourly_usd?: number;
|
|
119
|
+
gpu_count?: number;
|
|
120
|
+
region?: string;
|
|
121
|
+
available_only?: boolean;
|
|
122
|
+
sort?: AgentOffersSort;
|
|
123
|
+
offset?: number;
|
|
124
|
+
limit?: number;
|
|
125
|
+
}
|
|
126
|
+
export interface AgentCalculateInput {
|
|
127
|
+
offer_id?: string;
|
|
128
|
+
gpu_model?: string;
|
|
129
|
+
gpu_count?: number;
|
|
130
|
+
duration_hours: number;
|
|
131
|
+
hourly_price_per_gpu_usd?: number;
|
|
132
|
+
storage_gb?: number;
|
|
133
|
+
storage_cost_per_gb_month_usd?: number;
|
|
134
|
+
egress_gb?: number;
|
|
135
|
+
egress_cost_per_gb_usd?: number;
|
|
136
|
+
additional_flat_fees_usd?: number;
|
|
137
|
+
}
|
|
138
|
+
export interface ComputeCostInput {
|
|
139
|
+
hourlyRatePerInstanceUsd: number;
|
|
140
|
+
instanceCount?: number;
|
|
141
|
+
durationHours: number;
|
|
142
|
+
storageGb?: number;
|
|
143
|
+
storageCostPerGbMonthUsd?: number;
|
|
144
|
+
egressGb?: number;
|
|
145
|
+
egressCostPerGbUsd?: number;
|
|
146
|
+
}
|
|
147
|
+
export interface ComputeCostBreakdown {
|
|
148
|
+
computeSubtotalUsd: number;
|
|
149
|
+
storageSubtotalUsd: number;
|
|
150
|
+
egressSubtotalUsd: number;
|
|
151
|
+
totalEstimatedUsd: number;
|
|
152
|
+
effectiveHourlyUsd: number;
|
|
153
|
+
currency: "USD";
|
|
154
|
+
}
|
|
155
|
+
export type LlmQuantization = "fp32" | "fp16" | "bf16" | "fp8" | "int8" | "q8_0" | "q4_k_m" | "int4";
|
|
156
|
+
export type LlmWorkloadMode = "inference" | "lora_finetune" | "full_finetune";
|
|
157
|
+
export interface LlmSizingInput {
|
|
158
|
+
parameterCountBillions: number;
|
|
159
|
+
quantization?: LlmQuantization;
|
|
160
|
+
mode?: LlmWorkloadMode;
|
|
161
|
+
contextLength?: number;
|
|
162
|
+
batchSize?: number;
|
|
163
|
+
kvCacheQuantization?: "fp16" | "fp8" | "int8";
|
|
164
|
+
headroomPct?: number;
|
|
165
|
+
}
|
|
166
|
+
export interface LlmSizingRecommendation {
|
|
167
|
+
gpuModel: string;
|
|
168
|
+
gpuCount: number;
|
|
169
|
+
vramPerGpuGb: number;
|
|
170
|
+
totalVramGb: number;
|
|
171
|
+
estimatedUtilizationPct: number;
|
|
172
|
+
notes: string;
|
|
173
|
+
}
|
|
174
|
+
export interface LlmSizingResult {
|
|
175
|
+
parameterCountBillions: number;
|
|
176
|
+
quantization: LlmQuantization;
|
|
177
|
+
mode: LlmWorkloadMode;
|
|
178
|
+
contextLength: number;
|
|
179
|
+
batchSize: number;
|
|
180
|
+
kvCacheQuantization: "fp16" | "fp8" | "int8";
|
|
181
|
+
weightsGb: number;
|
|
182
|
+
kvCacheGb: number;
|
|
183
|
+
trainingOverheadGb: number;
|
|
184
|
+
runtimeOverheadGb: number;
|
|
185
|
+
minimumVramGb: number;
|
|
186
|
+
recommendedVramGb: number;
|
|
187
|
+
recommendedConfigs: LlmSizingRecommendation[];
|
|
188
|
+
}
|
|
189
|
+
export interface OfferTcoComparisonOptions {
|
|
190
|
+
durationHours: number;
|
|
191
|
+
minTotalVramGb?: number;
|
|
192
|
+
storageGb?: number;
|
|
193
|
+
egressGb?: number;
|
|
194
|
+
defaultStorageCostPerGbMonthUsd?: number;
|
|
195
|
+
defaultEgressCostPerGbUsd?: number;
|
|
196
|
+
availableOnly?: boolean;
|
|
197
|
+
confirmedOnly?: boolean;
|
|
198
|
+
holderTier?: HolderTierId;
|
|
199
|
+
settlementAsset?: SettlementAsset;
|
|
200
|
+
}
|
|
201
|
+
export interface RankedGpuOfferTco {
|
|
202
|
+
offerId: string;
|
|
203
|
+
provider: ProviderId;
|
|
204
|
+
gpuModel: string;
|
|
205
|
+
gpuCount: number;
|
|
206
|
+
totalVramGb: number;
|
|
207
|
+
region: string;
|
|
208
|
+
pricePrecision: PricePrecision;
|
|
209
|
+
productCategory: ProductCategory;
|
|
210
|
+
hourlyPriceUsd: number;
|
|
211
|
+
pricePerGpuUsd: number;
|
|
212
|
+
breakdown: ComputeCostBreakdown;
|
|
213
|
+
deskFeeBps: number;
|
|
214
|
+
estimatedDeskFeeUsd: number;
|
|
215
|
+
totalWithDeskFeeUsd: number;
|
|
216
|
+
savingsVsMostExpensiveUsd: number;
|
|
217
|
+
sourceUrl: string;
|
|
218
|
+
}
|
|
219
|
+
export interface OfferTcoComparisonResult {
|
|
220
|
+
durationHours: number;
|
|
221
|
+
evaluatedCount: number;
|
|
222
|
+
eligibleCount: number;
|
|
223
|
+
holderTier: HolderTierId;
|
|
224
|
+
settlementAsset: SettlementAsset;
|
|
225
|
+
effectiveDeskFeeBps: number;
|
|
226
|
+
cheapestTotalUsd: number;
|
|
227
|
+
mostExpensiveTotalUsd: number;
|
|
228
|
+
spreadMultiplier: number;
|
|
229
|
+
ranked: RankedGpuOfferTco[];
|
|
230
|
+
}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|