Initial commit with 🏗️ create-eth @ 2.0.4

This commit is contained in:
han
2026-01-23 20:20:58 +07:00
commit b330aba2b4
185 changed files with 36981 additions and 0 deletions

View File

@@ -0,0 +1,56 @@
import { NextResponse } from "next/server";
import fs from "fs";
import path from "path";
const CONFIG_PATH = path.join(process.cwd(), "..", "hardhat", "scripts", "oracle-bot", "config.json");
export async function POST(request: Request) {
try {
const body = await request.json();
const { value, nodeAddress } = body;
if (typeof value !== "number" || value < 0) {
return NextResponse.json({ error: "Value must be a non-negative number" }, { status: 400 });
}
// Read current config
const configContent = await fs.promises.readFile(CONFIG_PATH, "utf-8");
const config = JSON.parse(configContent);
// Update node-specific config
if (!config.NODE_CONFIGS[nodeAddress]) {
config.NODE_CONFIGS[nodeAddress] = { ...config.NODE_CONFIGS.default };
}
config.NODE_CONFIGS[nodeAddress].PRICE_VARIANCE = value;
// Write back to file
await fs.promises.writeFile(CONFIG_PATH, JSON.stringify(config, null, 2));
return NextResponse.json({ success: true, value });
} catch (error) {
console.error("Error updating price variance:", error);
return NextResponse.json({ error: "Failed to update configuration" }, { status: 500 });
}
}
export async function GET(request: Request) {
try {
const { searchParams } = new URL(request.url);
const nodeAddress = searchParams.get("nodeAddress");
if (!nodeAddress) {
return NextResponse.json({ error: "nodeAddress parameter is required" }, { status: 400 });
}
const configContent = await fs.promises.readFile(CONFIG_PATH, "utf-8");
const config = JSON.parse(configContent);
const nodeConfig = config.NODE_CONFIGS[nodeAddress] || config.NODE_CONFIGS.default;
return NextResponse.json({
value: nodeConfig.PRICE_VARIANCE,
});
} catch (error) {
console.error("Error reading price variance:", error);
return NextResponse.json({ error: "Failed to read configuration" }, { status: 500 });
}
}

View File

@@ -0,0 +1,56 @@
import { NextResponse } from "next/server";
import fs from "fs";
import path from "path";
const CONFIG_PATH = path.join(process.cwd(), "..", "hardhat", "scripts", "oracle-bot", "config.json");
export async function POST(request: Request) {
try {
const body = await request.json();
const { value, nodeAddress } = body;
if (typeof value !== "number" || value < 0 || value > 1) {
return NextResponse.json({ error: "Value must be a number between 0 and 1" }, { status: 400 });
}
// Read current config
const configContent = await fs.promises.readFile(CONFIG_PATH, "utf-8");
const config = JSON.parse(configContent);
// Update node-specific config
if (!config.NODE_CONFIGS[nodeAddress]) {
config.NODE_CONFIGS[nodeAddress] = { ...config.NODE_CONFIGS.default };
}
config.NODE_CONFIGS[nodeAddress].PROBABILITY_OF_SKIPPING_REPORT = value;
// Write back to file
await fs.promises.writeFile(CONFIG_PATH, JSON.stringify(config, null, 2));
return NextResponse.json({ success: true, value });
} catch (error) {
console.error("Error updating skip probability:", error);
return NextResponse.json({ error: "Failed to update configuration" }, { status: 500 });
}
}
export async function GET(request: Request) {
try {
const { searchParams } = new URL(request.url);
const nodeAddress = searchParams.get("nodeAddress");
if (!nodeAddress) {
return NextResponse.json({ error: "nodeAddress parameter is required" }, { status: 400 });
}
const configContent = await fs.promises.readFile(CONFIG_PATH, "utf-8");
const config = JSON.parse(configContent);
const nodeConfig = config.NODE_CONFIGS[nodeAddress] || config.NODE_CONFIGS.default;
return NextResponse.json({
value: nodeConfig.PROBABILITY_OF_SKIPPING_REPORT,
});
} catch (error) {
console.error("Error reading skip probability:", error);
return NextResponse.json({ error: "Failed to read configuration" }, { status: 500 });
}
}

View File

@@ -0,0 +1,88 @@
import { NextResponse } from "next/server";
import { createPublicClient, createWalletClient, http, parseEther } from "viem";
import { privateKeyToAccount } from "viem/accounts";
import { hardhat } from "viem/chains";
import deployedContracts from "~~/contracts/deployedContracts";
const oraTokenAbi = [
{
type: "function",
name: "transfer",
stateMutability: "nonpayable",
inputs: [
{ name: "to", type: "address" },
{ name: "amount", type: "uint256" },
],
outputs: [{ name: "", type: "bool" }],
},
] as const;
const stakingOracleAbi = [
{
type: "function",
name: "oracleToken",
stateMutability: "view",
inputs: [],
outputs: [{ name: "", type: "address" }],
},
] as const;
const DEPLOYER_PRIVATE_KEY =
(process.env.__RUNTIME_DEPLOYER_PRIVATE_KEY as `0x${string}` | undefined) ??
// Hardhat default account #0 private key (localhost only).
("0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80" as const);
function isAddress(value: unknown): value is `0x${string}` {
return typeof value === "string" && /^0x[a-fA-F0-9]{40}$/.test(value);
}
export async function POST(request: Request) {
try {
const body = await request.json();
const to = body?.to;
const amount = body?.amount ?? "2000";
if (!isAddress(to)) {
return NextResponse.json({ error: "Invalid `to` address" }, { status: 400 });
}
if (typeof amount !== "string" || !/^\d+(\.\d+)?$/.test(amount)) {
return NextResponse.json({ error: "Invalid `amount`" }, { status: 400 });
}
// Safety: this faucet is intended for local Hardhat usage only.
if (process.env.NODE_ENV === "production") {
return NextResponse.json({ error: "ORA faucet disabled in production" }, { status: 403 });
}
const publicClient = createPublicClient({ chain: hardhat, transport: http() });
const account = privateKeyToAccount(DEPLOYER_PRIVATE_KEY);
const walletClient = createWalletClient({ chain: hardhat, transport: http(), account });
const stakingOracleAddress = (deployedContracts as any)?.[hardhat.id]?.StakingOracle?.address as
| `0x${string}`
| undefined;
if (!stakingOracleAddress) {
return NextResponse.json({ error: "StakingOracle not deployed on this network" }, { status: 500 });
}
const oraTokenAddress = (await publicClient.readContract({
address: stakingOracleAddress,
abi: stakingOracleAbi,
functionName: "oracleToken",
})) as `0x${string}`;
const hash = await walletClient.writeContract({
address: oraTokenAddress,
abi: oraTokenAbi,
functionName: "transfer",
args: [to, parseEther(amount)],
});
await publicClient.waitForTransactionReceipt({ hash });
return NextResponse.json({ success: true, hash });
} catch (error) {
console.error("Error funding ORA:", error);
return NextResponse.json({ error: "Failed to fund ORA" }, { status: 500 });
}
}