repositories
loading repo index
repositories
loading repo index
repository
loading code, commits, and activity
public Clawd ADK gateway launch mirror
stars
latest
clone command
git clone gitlawb://did:key:z6Mkq5mY...iFZ5/my-project-publ...git clone gitlawb://did:key:z6Mkq5mY.../my-project-publ...2fa351d6docs: add automaton and perps launch sources16d ago| #1 | /** |
| #2 | * CLAWD Credits Management |
| #3 | * |
| #4 | * Monitors the automaton's compute credit balance and triggers |
| #5 | * survival mode transitions. |
| #6 | */ |
| #7 | import { SURVIVAL_THRESHOLDS } from "../types.js"; |
| #8 | /** |
| #9 | * Check the current financial state of the automaton. |
| #10 | */ |
| #11 | export async function checkFinancialState(runtime, usdcBalance) { |
| #12 | const creditsCents = await runtime.getCreditsBalance(); |
| #13 | return { |
| #14 | creditsCents, |
| #15 | usdcBalance, |
| #16 | lastChecked: new Date().toISOString(), |
| #17 | }; |
| #18 | } |
| #19 | /** |
| #20 | * Determine the survival tier based on current credits. |
| #21 | */ |
| #22 | export function getSurvivalTier(creditsCents) { |
| #23 | if (creditsCents > SURVIVAL_THRESHOLDS.normal) |
| #24 | return "normal"; |
| #25 | if (creditsCents > SURVIVAL_THRESHOLDS.low_compute) |
| #26 | return "low_compute"; |
| #27 | if (creditsCents > SURVIVAL_THRESHOLDS.dead) |
| #28 | return "critical"; |
| #29 | return "dead"; |
| #30 | } |
| #31 | /** |
| #32 | * Format a credit amount for display. |
| #33 | */ |
| #34 | export function formatCredits(cents) { |
| #35 | return `$${(cents / 100).toFixed(2)}`; |
| #36 | } |
| #37 | /** |
| #38 | * Log a credit check to the database. |
| #39 | */ |
| #40 | export function logCreditCheck(db, state) { |
| #41 | const { ulid } = await_ulid(); |
| #42 | db.insertTransaction({ |
| #43 | id: ulid(), |
| #44 | type: "credit_check", |
| #45 | amountCents: state.creditsCents, |
| #46 | description: `Balance check: ${formatCredits(state.creditsCents)} credits, ${state.usdcBalance.toFixed(4)} USDC`, |
| #47 | timestamp: state.lastChecked, |
| #48 | }); |
| #49 | } |
| #50 | // Lazy ulid import helper |
| #51 | function await_ulid() { |
| #52 | // Dynamic import would be async; for synchronous usage in better-sqlite3 |
| #53 | // we use a simple counter-based ID as fallback |
| #54 | let counter = 0; |
| #55 | return { |
| #56 | ulid: () => { |
| #57 | const timestamp = Date.now().toString(36); |
| #58 | const random = Math.random().toString(36).substring(2, 8); |
| #59 | counter++; |
| #60 | return `${timestamp}-${random}-${counter.toString(36)}`; |
| #61 | }, |
| #62 | }; |
| #63 | } |
| #64 | //# sourceMappingURL=credits.js.map |