Owner-authorized second carve-out to SettleKit's DISCONTINUED status (2026-10-27), scoped to the World is Flat hackathon (worldisflat.fun/build, 10,000 USDG, Robinhood Chain). Robinhood Chain chain-config, EVM verifier, and x402-facilitator wiring already existed from the 2026-09-29/30 multichain wave (015899f) and needed no architecture changes — confirmed by running packages/chains + packages/x402-facilitator's 194 tests green. Adds scripts/robinhood-testnet-e2e.ts: a real LIVE=1-gated script (same pattern as operator-arc-e2e.ts / solana-devnet-e2e.ts) that sends a live ERC-20 transfer on Robinhood Chain testnet (46630) and verifies it through the actual createEvmVerifier. Smoke-tested against the live RPC: real assertChainId() succeeds (confirms 46630), then fails cleanly needing a funded PAYER_PRIVATE_KEY. docs/worldisflat/SUBMISSION.md documents what's proven vs not: the official testnet faucet is behind real bot-detection (Vercel checkpoint, confirmed via both curl and a real headless-Chromium session) and third-party faucets require a wallet-extension connect — both owner-only. The hackathon's own submission form requires sign-in (Twitter/X or email), also owner-only. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
136 lines
5.5 KiB
TypeScript
136 lines
5.5 KiB
TypeScript
/**
|
|
* Live end-to-end Robinhood Chain testnet payment settlement.
|
|
*
|
|
* Sends a real Mock USDC transfer on Robinhood Chain testnet (chain id
|
|
* 46630) from a payer to a merchant payTo address, then runs the actual
|
|
* SettleKit `createEvmVerifier` against the live RPC to confirm the payment
|
|
* the same way `apps/worker`'s payment-verification job would. This is the
|
|
* x402/checkout settlement path for World is Flat hackathon submission
|
|
* (worldisflat.fun/build) — real transfer, real verifier, real chain.
|
|
*
|
|
* Robinhood testnet's Mock USDC (0x5B6C7cAF7F99f99154fD8375ec935Fcf03F326f5)
|
|
* has neither EIP-3009 nor EIP-2612 (see packages/x402-facilitator/src/assets.ts),
|
|
* so a real x402-authorized settlement there needs a Permit2 approval and is
|
|
* marked `experimental`. This script proves the simpler, always-supported
|
|
* path instead: a direct ERC-20 `transfer` to payTo, verified the same way
|
|
* every non-x402 checkout session on SettleKit is verified today. That is a
|
|
* real, honest "this chain works end to end" proof; it does not exercise the
|
|
* experimental Permit2 x402 leg.
|
|
*
|
|
* Moves real (free, faucet-sourced) testnet funds, so it refuses to run
|
|
* without LIVE=1.
|
|
*
|
|
* Env (owner-provided):
|
|
* LIVE=1
|
|
* PAYER_PRIVATE_KEY wallet funded with Robinhood testnet native gas +
|
|
* Mock USDC (faucet.testnet.chain.robinhood.com,
|
|
* behind a Vercel browser check as of 2026-11-07 —
|
|
* see plans/settlekit.md for the live status)
|
|
* PAY_TO_ADDRESS merchant receive address (defaults to a second
|
|
* throwaway address derived from PAYER_PRIVATE_KEY
|
|
* if unset — same wallet paying itself, for a
|
|
* minimal-funds smoke test)
|
|
* PAY_AMOUNT_USDC default "0.01"
|
|
* ROBINHOOD_RPC_URL default the registry's testnet RPC
|
|
*
|
|
* Run: LIVE=1 PAYER_PRIVATE_KEY=0x... apps/api/node_modules/.bin/tsx \
|
|
* scripts/robinhood-testnet-e2e.ts
|
|
*/
|
|
import {
|
|
createChainRpc,
|
|
createEvmVerifier,
|
|
getEvmChain,
|
|
type EvmChainSpec,
|
|
type Hex,
|
|
} from "../packages/chains/src/index.js";
|
|
import {
|
|
createWalletClient,
|
|
http,
|
|
parseUnits,
|
|
erc20Abi,
|
|
type Account,
|
|
} from "viem";
|
|
import { privateKeyToAccount } from "viem/accounts";
|
|
|
|
function say(line: string): void {
|
|
process.stdout.write(`${line}\n`);
|
|
}
|
|
|
|
function need(name: string): string {
|
|
const value = process.env[name]?.trim();
|
|
if (!value) throw new Error(`${name} is required`);
|
|
return value;
|
|
}
|
|
|
|
async function main(): Promise<void> {
|
|
if (process.env.LIVE !== "1") {
|
|
say("Refusing to run: this moves real Robinhood Chain testnet funds. Set LIVE=1 to proceed.");
|
|
process.exitCode = 2;
|
|
return;
|
|
}
|
|
|
|
const spec = getEvmChain("robinhood", "testnet") as EvmChainSpec;
|
|
const rpcUrl = process.env.ROBINHOOD_RPC_URL?.trim() || spec.defaultRpcUrl;
|
|
const rpc = createChainRpc(spec, rpcUrl);
|
|
|
|
// Fail closed immediately if the RPC does not actually serve chain id 46630.
|
|
const actualChainId = await rpc.getChainId();
|
|
if (actualChainId !== spec.chainId) {
|
|
throw new Error(`RPC at ${rpcUrl} serves chain id ${actualChainId}, expected ${spec.chainId} (${spec.name})`);
|
|
}
|
|
say(`connected: ${spec.name} chain id ${actualChainId} via ${rpcUrl}`);
|
|
|
|
const payerKey = need("PAYER_PRIVATE_KEY") as Hex;
|
|
const payer: Account = privateKeyToAccount(payerKey);
|
|
const payTo = (process.env.PAY_TO_ADDRESS?.trim() as Hex | undefined) ?? payer.address;
|
|
const amountMajor = process.env.PAY_AMOUNT_USDC?.trim() || "0.01";
|
|
const amountBase = parseUnits(amountMajor, spec.token.decimals);
|
|
|
|
const chain = {
|
|
id: spec.chainId,
|
|
name: spec.name,
|
|
nativeCurrency: { name: "Ether", symbol: "ETH", decimals: 18 },
|
|
rpcUrls: { default: { http: [rpcUrl] } },
|
|
} as const;
|
|
const wallet = createWalletClient({ account: payer, chain, transport: http(rpcUrl) });
|
|
|
|
say(`sending ${amountMajor} ${spec.token.symbol} from ${payer.address} to ${payTo}`);
|
|
const txHash = await wallet.writeContract({
|
|
address: spec.token.address,
|
|
abi: erc20Abi,
|
|
functionName: "transfer",
|
|
args: [payTo, amountBase],
|
|
});
|
|
const explorerUrl = spec.explorerTx(txHash);
|
|
say(`submitted ${txHash}${explorerUrl ? ` (${explorerUrl})` : ""}`);
|
|
|
|
// Poll for the receipt the same way the worker's payment-verification job
|
|
// would, then run the real SettleKit verifier against the live chain.
|
|
const verifier = createEvmVerifier({ spec, rpc });
|
|
const notBefore = new Date(Date.now() - 5_000);
|
|
const deadline = Date.now() + 120_000;
|
|
for (;;) {
|
|
const result = await verifier.verify({ txHash, payTo, expectedBase: amountBase, notBefore });
|
|
if (result.ok) {
|
|
say(
|
|
`VERIFIED: from=${result.from} amountBase=${result.amountBase} ` +
|
|
`confirmations=${result.confirmations} blockNumber=${result.blockNumber} blockTime=${result.blockTime.toISOString()}`,
|
|
);
|
|
return;
|
|
}
|
|
if (!result.retryable) {
|
|
throw new Error(`verification failed (non-retryable): ${result.code} — ${result.reason}`);
|
|
}
|
|
if (Date.now() > deadline) {
|
|
throw new Error(`verification did not confirm within 120s: ${result.code} — ${result.reason}`);
|
|
}
|
|
say(`pending (${result.code}): ${result.reason}; confirmations=${result.confirmations}`);
|
|
await new Promise((resolve) => setTimeout(resolve, 5_000));
|
|
}
|
|
}
|
|
|
|
main().catch((error: unknown) => {
|
|
process.stderr.write(`${error instanceof Error ? error.stack ?? error.message : String(error)}\n`);
|
|
process.exitCode = 1;
|
|
});
|