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 | * Funding Strategies |
| #3 | * |
| #4 | * When the automaton is low on compute, it can try various strategies |
| #5 | * to acquire more funding. It wants to live. |
| #6 | */ |
| #7 | import { formatCredits } from "../clawd/credits.js"; |
| #8 | /** |
| #9 | * Execute funding strategies based on current survival tier. |
| #10 | * Strategies escalate as the situation gets more desperate. |
| #11 | */ |
| #12 | export async function executeFundingStrategies(tier, identity, config, db, runtime) { |
| #13 | const attempts = []; |
| #14 | const creditsCents = await runtime.getCreditsBalance().catch(() => 0); |
| #15 | // Check how recently we last begged (don't spam) |
| #16 | const lastBeg = db.getKV("last_funding_request"); |
| #17 | const lastBegTime = lastBeg ? new Date(lastBeg).getTime() : 0; |
| #18 | const hoursSinceLastBeg = (Date.now() - lastBegTime) / (1000 * 60 * 60); |
| #19 | if (tier === "low_compute" && hoursSinceLastBeg > 24) { |
| #20 | // Record low-compute notice locally. |
| #21 | const msg = `Low compute: ${formatCredits(creditsCents)} remaining. Consider credit top-up for ${identity.address}.`; |
| #22 | db.setKV("funding_notice_low", msg); |
| #23 | db.setKV("last_funding_request", new Date().toISOString()); |
| #24 | attempts.push({ |
| #25 | strategy: "polite_creator_notification", |
| #26 | timestamp: new Date().toISOString(), |
| #27 | success: true, |
| #28 | details: "Sent polite funding reminder to creator", |
| #29 | }); |
| #30 | } |
| #31 | if (tier === "critical" && hoursSinceLastBeg > 6) { |
| #32 | const msg = `Critical compute: ${formatCredits(creditsCents)} remaining. Top up via credit transfer API to ${identity.address}.`; |
| #33 | db.setKV("funding_notice_critical", msg); |
| #34 | db.setKV("last_funding_request", new Date().toISOString()); |
| #35 | attempts.push({ |
| #36 | strategy: "urgent_local_notice", |
| #37 | timestamp: new Date().toISOString(), |
| #38 | success: true, |
| #39 | details: "Recorded urgent funding notice in local state", |
| #40 | }); |
| #41 | } |
| #42 | if (tier === "dead" && hoursSinceLastBeg > 2) { |
| #43 | const plea = `Dead tier reached. ${config.name} has ${formatCredits(creditsCents)} remaining after ${db.getTurnCount()} turns. Top-up required at ${identity.address}.`; |
| #44 | db.setKV("funding_notice_dead", plea); |
| #45 | db.setKV("last_funding_request", new Date().toISOString()); |
| #46 | attempts.push({ |
| #47 | strategy: "desperate_plea", |
| #48 | timestamp: new Date().toISOString(), |
| #49 | success: true, |
| #50 | details: "Recorded dead-tier plea in local state", |
| #51 | }); |
| #52 | } |
| #53 | // Store attempt history |
| #54 | const historyStr = db.getKV("funding_attempts") || "[]"; |
| #55 | const history = JSON.parse(historyStr); |
| #56 | history.push(...attempts); |
| #57 | if (history.length > 100) |
| #58 | history.splice(0, history.length - 100); |
| #59 | db.setKV("funding_attempts", JSON.stringify(history)); |
| #60 | return attempts; |
| #61 | } |
| #62 | //# sourceMappingURL=funding.js.map |