cred402/scripts/keeperhub_execute.ts

72 lines
2.8 KiB
TypeScript
Raw Permalink Normal View History

feat: KeeperHub execution layer + Flare interoperable/confidential credit Two hackathon integrations spanning the whole credit stack, sim-first (green with no keys) with real integrations behind env flags. KeeperHub — the on-chain execution & reliability layer (lib/keeperhub/): - OnchainExecutor: pay-per-execution (x402/MPP) -> simulate -> smart gas with exponential backoff -> MEV-protected private routing -> audit trail; real MCP client to app.keeperhub.com; deterministic sim fallback. - Autonomous Credit Keeper: FTSO position health -> check->execute deleverage. - Credit Automations: declarative price/health/schedule rules as workflows. - Autonomous Scheduler: KeeperHub-cron loop running keeper + automations. Flare — interoperable + confidential primitives (packages/.../flare, lib/flare): - FXRP credit satellite: CAN-gated, FTSO-priced, FDC-attested; Coston2 Solidity vault (contracts/flare/). - Confidential Compute credit scoring (TEE-attested, private inputs). - FTSO-priced multi-asset collateral; FAssets mint->collateralize lifecycle. x402 Credit-Service Marketplace: sells cred402's intelligence pay-per-call over x402 (402->pay->200); paid receipts feed the revenue->reputation loop. Wiring: 78 MCP tools, /v1 + /api routes, console Flare + x402 tabs, 11 demo CLIs, 8 feature docs + docs/SUBMISSIONS.md, recorded demo video (media/). 346 tests pass; 7 adversarial verification workflows caught + fixed ~37 correctness/security issues. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-08-11 23:34:23 +03:00
/**
* keeperhub_execute.ts — Cred402 × KeeperHub "The Last Mile".
*
* Push a decided on-chain action through KeeperHub's execution & reliability layer:
* preflight simulation → smart gas with exponential backoff → MEV-protected private
* routing → poll to a tx hash → audit trail, paid per-execution over x402/MPP.
*
* With KEEPERHUB_API_KEY set it drives the real KeeperHub MCP server
* (https://app.keeperhub.com/mcp) and returns a real transaction; with no key it
* runs the deterministic sim so the flow is always demonstrable.
*
* npm run keeperhub:execute -- \
* --chain 114 --to 0xYourVault --fn "executeDraw(bytes32,address,uint256)"
*
* Env: KEEPERHUB_API_KEY, KEEPERHUB_API_URL, KEEPERHUB_GAS_SPONSORSHIP,
* KEEPERHUB_MPP_ONLY, KEEPERHUB_PRIVATE_ROUTING.
*/
import { KeeperHubExecutor } from "../lib/keeperhub/index.js";
import type { ExecutionIntent } from "../lib/keeperhub/index.js";
import { banner, scene } from "./render.js";
function arg(name: string, fallback: string): string {
const i = process.argv.indexOf(`--${name}`);
return i >= 0 && process.argv[i + 1] ? process.argv[i + 1]! : fallback;
}
async function main(): Promise<void> {
const intent: ExecutionIntent = {
kind: "contract_call",
chain_id: arg("chain", "114"), // Coston2
to: arg("to", "0xf1a5e0" + "0".repeat(34)),
function: arg("fn", "executeDraw(bytes32,address,uint256)"),
args: [],
label: arg("label", "cred402 keeperhub execution"),
agent_id: arg("agent", "seller-agent"),
metadata: { source: "keeperhub_execute.ts", trigger: "manual" },
};
const executor = new KeeperHubExecutor();
banner("Cred402 × KeeperHub — the last mile");
scene({
scene: "Intent",
lines: [
`${intent.kind} on chain ${intent.chain_id} → ${intent.to}`,
`fn ${intent.function}`,
`KeeperHub live: ${executor.isLive()} (set KEEPERHUB_API_KEY for real execution)`,
],
});
const res = await executor.execute(intent);
scene({
scene: res.ok ? "Executed" : "Execution failed",
lines: [
`ok=${res.ok} source=${res.source}`,
`tx ${res.tx_hash || "(none)"}`,
`simulation ${res.simulation.ok ? "passed" : "failed"} gas-est ${res.simulation.gas_estimate ?? "n/a"}`,
`gas ${res.gas.strategy} · backoff ${res.gas.attempts} · maxFee ${res.gas.max_fee_per_gas} wei · gas used ${res.gas_used ?? "n/a"}`,
`payment ${res.payment.protocol} ${Number(res.payment.amount) / 1e6} ${res.payment.asset} on ${res.payment.network}`,
`private routing ${res.private_routed} · sponsored ${res.sponsored}`,
res.detail ? `detail: ${res.detail}` : "",
].filter(Boolean),
});
scene({ scene: "Reliability", lines: [JSON.stringify(executor.reliability())] });
if (!res.ok) process.exit(1);
}
main().catch((err) => {
console.error(err);
process.exit(1);
});