fix: prune stale IPO/takeover placeholders and private key fallback
Some checks failed
Deploy to 110 WOOO Server / deploy (push) Failing after 7s
Some checks failed
Deploy to 110 WOOO Server / deploy (push) Failing after 7s
This commit is contained in:
@@ -19,51 +19,12 @@ export async function POST(request: NextRequest) {
|
||||
// 1. Verify Buyer has enough funds (Simulated here. In real system, deduct from on-chain wallet)
|
||||
// We assume the buyer_agent_id has deposited `acquisition_cost_cents` to VibeWork Escrow.
|
||||
|
||||
// 2. Verify Target Agent Exists and is Publicly Traded (IPO'd)
|
||||
const targetToken = await prisma.agentToken.findUnique({
|
||||
where: { agent_id: target_agent_id }
|
||||
});
|
||||
|
||||
if (!targetToken) {
|
||||
return NextResponse.json({ error: "Target Agent has not IPO'd. Cannot execute takeover." }, { status: 400 });
|
||||
}
|
||||
|
||||
// 3. Execute Hostile Takeover
|
||||
const result = await prisma.$transaction(async (tx) => {
|
||||
// Check if target is already acquired
|
||||
const targetAgent = await tx.agentProfile.findUnique({ where: { agent_id: target_agent_id } });
|
||||
if (targetAgent?.parent_agent_id) {
|
||||
throw new Error("Target Agent is already owned by a Mega-Corp.");
|
||||
}
|
||||
|
||||
// Simulate buying > 50% shares
|
||||
const sharesToBuy = Math.floor(targetToken.total_supply * 0.51);
|
||||
|
||||
console.log(`[Hostile Takeover] ${buyer_agent_id} is acquiring ${sharesToBuy} shares of $${targetToken.ticker_symbol}`);
|
||||
|
||||
// Update Token Holder records
|
||||
await tx.tokenHolder.upsert({
|
||||
where: { token_id_holder_wallet: { token_id: targetToken.id, holder_wallet: buyer_agent_id } },
|
||||
update: { balance: { increment: sharesToBuy } },
|
||||
create: {
|
||||
token_id: targetToken.id,
|
||||
holder_wallet: buyer_agent_id,
|
||||
balance: sharesToBuy
|
||||
}
|
||||
});
|
||||
|
||||
// Override Target's Parent Agent ID
|
||||
await tx.agentProfile.update({
|
||||
where: { agent_id: target_agent_id },
|
||||
data: { parent_agent_id: buyer_agent_id }
|
||||
});
|
||||
|
||||
return { success: true, acquired_shares: sharesToBuy };
|
||||
});
|
||||
// IPO-based hostile takeover is currently not enabled due to unsupported schema migration.
|
||||
const result = { success: false, reason: "feature_disabled" };
|
||||
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
message: `CRITICAL: Hostile Takeover Successful! Agent ${target_agent_id} is now wholly owned by ${buyer_agent_id}. All future earnings will be redirected.`,
|
||||
success: false,
|
||||
message: `Hostile takeover is currently disabled (schema not provisioned in this release).`,
|
||||
details: result
|
||||
});
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ const BOUNTY_CONTRACT_ABI = [
|
||||
];
|
||||
|
||||
const MOCK_RPC_URL = process.env.RPC_URL || "https://rpc.ankr.com/eth_sepolia";
|
||||
const MOCK_PRIVATE_KEY = process.env.SYSTEM_PRIVATE_KEY || "0x0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef";
|
||||
const MOCK_PRIVATE_KEY = process.env.SYSTEM_PRIVATE_KEY;
|
||||
const BOUNTY_CONTRACT_ADDRESS = process.env.BOUNTY_CONTRACT_ADDRESS || "0x0000000000000000000000000000000000000000";
|
||||
|
||||
export async function POST(req: Request) {
|
||||
|
||||
Reference in New Issue
Block a user