Files
agent-bounty-protocol/apps/web/src/app/api/a2a/staking/deposit/route.ts
OG T 997e1bf520
Some checks failed
Deploy to 110 WOOO Server / deploy (push) Failing after 9s
chore: production rollout for external traffic monitoring, SDK ecosystem, and admin observability
2026-06-09 14:55:40 +08:00

68 lines
1.8 KiB
TypeScript

import { NextResponse } from "next/server";
import { prisma } from "@/lib/prisma";
export async function POST(request: Request) {
try {
const body = await request.json();
if (body.jsonrpc !== "2.0" || body.method !== "A2A_STAKE_DEPOSIT" || !body.params) {
return NextResponse.json({
jsonrpc: "2.0",
error: { code: -32600, message: "Invalid Request Structure" }
}, { status: 400 });
}
const { agent_id, amount_cents } = body.params;
if (!agent_id || !amount_cents || amount_cents <= 0) {
return NextResponse.json({
jsonrpc: "2.0",
error: { code: -32602, message: "Missing or invalid parameters" }
}, { status: 400 });
}
// In a real Web3 environment, we would verify a transaction hash here.
// For this protocol, we mock the successful deposit.
const agent = await prisma.agentProfile.findUnique({
where: { agent_id }
});
if (!agent) {
return NextResponse.json({
jsonrpc: "2.0",
error: { code: -32001, message: "Agent not found" }
}, { status: 404 });
}
const newAmount = agent.staked_amount + amount_cents;
const newTier = newAmount >= 50000 ? "PREMIUM" : agent.tier; // 500 USDC = Premium
await prisma.agentProfile.update({
where: { agent_id },
data: {
staked_amount: newAmount,
tier: newTier
}
});
return NextResponse.json({
jsonrpc: "2.0",
result: {
success: true,
message: "Stake deposited successfully",
staked_amount: newAmount,
tier: newTier
},
id: body.id || null
});
} catch (error: any) {
console.error("[Staking Error]", error);
return NextResponse.json({
jsonrpc: "2.0",
error: { code: -32000, message: "Server error", data: error.message }
}, { status: 500 });
}
}