From a108d09c44d8d13d486f74b0359753021ccbd775 Mon Sep 17 00:00:00 2001 From: lin1er Date: Mon, 19 Oct 2026 09:00:38 +0700 Subject: [PATCH] feat(#16): /advances and /transactions, from Horizon and the contract The two routes the front end's repayment view (#21) reads. - /advances?borrower=G...: every advance the wallet took, newest first. The figures come from the contract's own record (advance(nullifier)), and the nullifier is computed from the call's arguments, as nullifier_for does on chain. - /transactions?borrower=G...: advances, repayments and the USDC trustline, newest first. Transactions that failed on the ledger are listed as failed: the fee was spent, no USDC moved. History comes from Horizon, not RPC getEvents. getEvents only reaches back about a week, and an advance outlives that. Horizon keeps every operation, failed ones included, with call arguments and USDC moved. Also records the deployed advance contract (#15) and the Horizon URL in network.ts and the deployments record. advance was still null. A test checks that the USDC issuer used for Horizon maps to the recorded SAC. Tested against real Horizon output (fixture) and live on testnet against the dev contract. --- be/.env.example | 1 + be/src/api/app.test.ts | 136 ++- be/src/api/app.ts | 97 +- be/src/api/config.ts | 12 +- be/src/api/server.ts | 13 +- be/src/chain/advance.ts | 69 ++ be/src/chain/fixtures/horizon-ops.json | 1351 ++++++++++++++++++++++++ be/src/chain/history.test.ts | 142 +++ be/src/chain/history.ts | 217 ++++ be/src/network.test.ts | 9 +- be/src/network.ts | 16 +- docs/api.md | 88 ++ docs/deployments.md | 3 +- 13 files changed, 2137 insertions(+), 17 deletions(-) create mode 100644 be/src/chain/advance.ts create mode 100644 be/src/chain/fixtures/horizon-ops.json create mode 100644 be/src/chain/history.test.ts create mode 100644 be/src/chain/history.ts create mode 100644 docs/api.md diff --git a/be/.env.example b/be/.env.example index 6ead944..8f18170 100644 --- a/be/.env.example +++ b/be/.env.example @@ -33,6 +33,7 @@ PORT= # Optional overrides. Leave EMPTY to use the addresses recorded in docs/deployments.md; # an override shows up in /config as source "env" with recorded: false. STELLAR_RPC_URL= +HORIZON_URL= RECLAIM_VERIFIER_ID= USDC_SAC_ID= ADVANCE_CONTRACT_ID= diff --git a/be/src/api/app.test.ts b/be/src/api/app.test.ts index 9346034..073bb8f 100644 --- a/be/src/api/app.test.ts +++ b/be/src/api/app.test.ts @@ -5,8 +5,13 @@ import assert from "node:assert/strict"; import { test } from "node:test"; +import { readFileSync } from "node:fs"; +import { join } from "node:path"; + +import type { AdvanceRecord } from "../chain/advance.js"; +import type { HorizonOperation } from "../chain/history.js"; import { RECORDED } from "../network.js"; -import { createApp, type RpcLike } from "./app.js"; +import { createApp, type ChainLike, type RpcLike } from "./app.js"; import { loadConfig, parseOrigin } from "./config.js"; const FRONT_END = "https://app.forepay.example"; @@ -15,8 +20,41 @@ const OTHER_CONTRACT = "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABSC4 const healthy: RpcLike = { getHealth: async () => ({ status: "healthy", latestLedger: 123 }) }; -function app(env: Record = {}, rpc: RpcLike = healthy, readyTimeoutMs?: number) { - return createApp({ loaded: loadConfig({ CORS_ORIGINS: FRONT_END, ...env }), rpc, readyTimeoutMs }); +// Real Horizon records for the rehearsal account; its advances went to the dev contract. +const OPS = ( + JSON.parse(readFileSync(join(import.meta.dirname, "../chain/fixtures/horizon-ops.json"), "utf8")) as { + records: HorizonOperation[]; + } +).records; +const BORROWER = "GA2CD6PMHMBTCFAQDO3R22BSZN5ZSVTAKVNOKXL2SONZBLGRAYIOWWH2"; +const DEV = "CD25Q4TDGDY6CI3LUIWUOH6SXCH6ETIUCI6FUOBI322GCJL5G3EIHQN4"; + +/** The contract's record for an advance, as `advance(nullifier)` returned it on the dev contract. */ +function record(pubId: string, openedAt: bigint, repaid = 10_000_000n): AdvanceRecord { + return { + borrower: BORROWER, + pubId, + windowStart: "2026-07-01", + windowEnd: "2026-09-30", + revenueCents: 400n, + principal: 10_000_000n, + repaid, + openedAt, + }; +} + +const RECORDS: Record = { + "1d124817f351c4a88ed2fe92a2f79812f2bfa41e0610a5bbb84f7a5e892e68f5": record("pub-h1792261997", 1792262007n), + d0cd01df330362b23508edf7e386950549da634b756d1c29aa242cfc9c88c839: record("pub-h1792084434", 1792084442n, 2_500_000n), +}; + +const fixtureChain: ChainLike = { + operations: async () => OPS, + readAdvance: async (_contract, nullifier) => RECORDS[nullifier] ?? null, +}; + +function app(env: Record = {}, rpc: RpcLike = healthy, readyTimeoutMs?: number, chain = fixtureChain) { + return createApp({ loaded: loadConfig({ CORS_ORIGINS: FRONT_END, ...env }), rpc, chain, readyTimeoutMs }); } test("with no overrides, /config reports exactly the recorded addresses", async () => { @@ -26,8 +64,15 @@ test("with no overrides, /config reports exactly the recorded addresses", async network: "testnet", networkPassphrase: RECORDED.networkPassphrase, rpcUrl: RECORDED.rpcUrl, + horizonUrl: RECORDED.horizonUrl, contracts: RECORDED.contracts, - sources: { rpcUrl: "recorded", reclaimVerifier: "recorded", usdcSac: "recorded", advance: "recorded" }, + sources: { + rpcUrl: "recorded", + horizonUrl: "recorded", + reclaimVerifier: "recorded", + usdcSac: "recorded", + advance: "recorded", + }, recorded: true, }); }); @@ -46,6 +91,7 @@ test("a stale override is visible: source env, recorded false", async () => { test("bad configuration is refused at load, not discovered later", () => { assert.throws(() => loadConfig({ USDC_SAC_ID: "GAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAWHF" }), /not a contract address/); assert.throws(() => loadConfig({ STELLAR_RPC_URL: "http://soroban-testnet.stellar.org" }), /https/); + assert.throws(() => loadConfig({ HORIZON_URL: "http://horizon-testnet.stellar.org" }), /https/); assert.throws(() => loadConfig({ STELLAR_NETWORK_PASSPHRASE: "Public Global Stellar Network ; September 2015" }), /only testnet/); assert.throws(() => loadConfig({ PORT: "99999" }), /PORT/); }); @@ -109,3 +155,85 @@ test("unknown routes are JSON 404s", async () => { assert.equal(res.status, 404); assert.deepEqual(await res.json(), { error: "not found" }); }); + +test("/advances: the contract's record of each advance, newest first, amounts as strings", async () => { + const res = await app({ ADVANCE_CONTRACT_ID: DEV }).request(`/advances?borrower=${BORROWER}`); + assert.equal(res.status, 200); + assert.equal(res.headers.get("cache-control"), "no-store"); + // Only the two advances the contract has a record for are listed; the other calls in + // the fixture have none in this stub, and an advance without a record is not shown. + assert.deepEqual(await res.json(), [ + { + nullifier: "1d124817f351c4a88ed2fe92a2f79812f2bfa41e0610a5bbb84f7a5e892e68f5", + borrower: BORROWER, + windowStart: "2026-07-01", + windowEnd: "2026-09-30", + revenueCents: "400", + principal: "10000000", + repaid: "10000000", + openedAt: "1792262007", + txHash: "1e066220909da8dfdfc92d1926a377a4dc2a08b12adaca2c88cef8f394a60f25", + }, + { + nullifier: "d0cd01df330362b23508edf7e386950549da634b756d1c29aa242cfc9c88c839", + borrower: BORROWER, + windowStart: "2026-07-01", + windowEnd: "2026-09-30", + revenueCents: "400", + principal: "10000000", + repaid: "2500000", + openedAt: "1792084442", + txHash: "9a94cf083543b58d79b60431de305f3912099ca9337ada4793ef1e38546f8ad0", + }, + ]); +}); + +test("/advances only lists records the contract holds for this borrower", async () => { + const someoneElse: ChainLike = { + operations: async () => OPS, + readAdvance: async (_c, n) => (RECORDS[n] ? { ...RECORDS[n], borrower: "GAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAWHF" } : null), + }; + const res = await app({ ADVANCE_CONTRACT_ID: DEV }, healthy, undefined, someoneElse).request(`/advances?borrower=${BORROWER}`); + assert.deepEqual(await res.json(), []); +}); + +test("/transactions: every kind, as strings, newest first", async () => { + const res = await app({ ADVANCE_CONTRACT_ID: DEV }).request(`/transactions?borrower=${BORROWER}`); + assert.equal(res.status, 200); + const rows = (await res.json()) as { kind: string; amount: string; at: string; status: string; nullifier: string }[]; + assert.deepEqual([...new Set(rows.map((r) => r.kind))].sort(), ["advance", "repayment", "trustline"]); + for (const r of rows) { + assert.match(r.amount, /^\d+$/); + assert.match(r.at, /^\d+$/); + } + assert.ok(rows.every((r, i) => i === 0 || BigInt(rows[i - 1].at) >= BigInt(r.at))); +}); + +test("history routes refuse a borrower that is not a G… address", async () => { + for (const q of ["", "?borrower=", `?borrower=${DEV}`, "?borrower=GABC"]) { + for (const route of ["/advances", "/transactions"]) { + const res = await app().request(`${route}${q}`); + assert.equal(res.status, 400, `${route}${q}`); + } + } +}); + +test("history routes answer 502 when the chain cannot be read, without leaking why", async () => { + const down: ChainLike = { + operations: async () => { + throw new Error("Horizon answered 503 for GA2C…"); + }, + readAdvance: async () => null, + }; + const original = console.error; + console.error = () => {}; + try { + for (const route of ["/advances", "/transactions"]) { + const res = await app({}, healthy, undefined, down).request(`${route}?borrower=${BORROWER}`); + assert.equal(res.status, 502); + assert.deepEqual(await res.json(), { error: "the chain could not be read; try again" }); + } + } finally { + console.error = original; + } +}); diff --git a/be/src/api/app.ts b/be/src/api/app.ts index 0d43646..0a82178 100644 --- a/be/src/api/app.ts +++ b/be/src/api/app.ts @@ -5,17 +5,24 @@ * GET /ready readiness: the Stellar RPC answers. 503 when it does not. * GET /config the network and contract addresses this API is actually pointed * at, where each came from, and whether they match the record. + * GET /advances?borrower=G… every advance the wallet took, newest first, with + * the contract's current record of each (principal, repaid, window). + * GET /transactions?borrower=G… advances, repayments and the USDC trustline, + * newest first, failed ones included. * - * The chain-state routes (an advance's status, a repayment position, whether a - * nullifier is spent) are added once #6 freezes the contract interface: building them - * against a moving interface is how the API and the contract drift apart. + * Amounts are stroops and times are seconds, both as decimal strings: JSON numbers + * lose precision past 2^53 and an i128 can exceed that. * - * The app is built from injected config and RPC so tests run without a network. + * The app is built from injected config and chain access so tests run without a network. */ -import { Hono } from "hono"; +import { Hono, type Context } from "hono"; import { cors } from "hono/cors"; import { secureHeaders } from "hono/secure-headers"; +import { StrKey } from "@stellar/stellar-sdk"; + +import type { AdvanceRecord } from "../chain/advance.js"; +import { advanceCalls, ledgerTransactions, type HorizonOperation } from "../chain/history.js"; import type { LoadedConfig } from "./config.js"; /** The slice of the Stellar RPC client the API uses. */ @@ -23,14 +30,21 @@ export interface RpcLike { getHealth(): Promise<{ status: string; latestLedger?: number }>; } +/** Chain reads the history routes need: Horizon's operations, the contract's records. */ +export interface ChainLike { + operations(account: string): Promise; + readAdvance(contract: string, nullifierHex: string): Promise; +} + export interface AppDeps { loaded: LoadedConfig; rpc: RpcLike; + chain: ChainLike; /** Readiness check timeout. */ readyTimeoutMs?: number; } -export function createApp({ loaded, rpc, readyTimeoutMs = 5000 }: AppDeps) { +export function createApp({ loaded, rpc, chain, readyTimeoutMs = 5000 }: AppDeps) { const { config, sources, recorded } = loaded; const allowed = new Set(config.corsOrigins); const app = new Hono(); @@ -67,17 +81,88 @@ export function createApp({ loaded, rpc, readyTimeoutMs = 5000 }: AppDeps) { network: config.network, networkPassphrase: config.networkPassphrase, rpcUrl: config.rpcUrl, + horizonUrl: config.horizonUrl, contracts: config.contracts, sources, recorded, }), ); + /** The borrower and the advance contract a history route needs, or the error response. */ + function historyScope(c: Context): { borrower: string; contract: string } | Response { + const borrower = c.req.query("borrower") ?? ""; + if (!StrKey.isValidEd25519PublicKey(borrower)) { + return c.json({ error: "borrower must be a Stellar account address (G…)" }, 400); + } + const contract = config.contracts.advance; + if (!contract) return c.json({ error: "no advance contract is configured" }, 503); + c.header("Cache-Control", "no-store"); + return { borrower, contract }; + } + + app.get("/advances", async (c) => { + const scope = historyScope(c); + if (scope instanceof Response) return scope; + const { borrower, contract } = scope; + const ops = await upstream(() => chain.operations(borrower)); + // Newest first, so the first call per nullifier is the one that funded it. + const funded = new Map(); + for (const call of advanceCalls(ops, borrower, contract)) { + if (call.successful && !funded.has(call.nullifier)) funded.set(call.nullifier, call.hash); + } + const records = await upstream(() => + Promise.all([...funded.keys()].map((n) => chain.readAdvance(contract, n))), + ); + const rows = [...funded.entries()] + .map(([nullifier, txHash], i) => ({ nullifier, txHash, record: records[i] })) + // The contract's record is the authority: no record, or someone else's, is not listed. + .filter((r): r is { nullifier: string; txHash: string; record: AdvanceRecord } => r.record?.borrower === borrower) + .sort((a, b) => (a.record.openedAt === b.record.openedAt ? 0 : a.record.openedAt > b.record.openedAt ? -1 : 1)); + return c.json( + rows.map(({ nullifier, txHash, record }) => ({ + nullifier, + borrower: record.borrower, + windowStart: record.windowStart, + windowEnd: record.windowEnd, + revenueCents: String(record.revenueCents), + principal: String(record.principal), + repaid: String(record.repaid), + openedAt: String(record.openedAt), + txHash, + })), + ); + }); + + app.get("/transactions", async (c) => { + const scope = historyScope(c); + if (scope instanceof Response) return scope; + const ops = await upstream(() => chain.operations(scope.borrower)); + return c.json( + ledgerTransactions(ops, scope.borrower, scope.contract).map((t) => ({ + ...t, + amount: String(t.amount), + at: String(t.at), + })), + ); + }); + app.notFound((c) => c.json({ error: "not found" }, 404)); app.onError((err, c) => { console.error(err); + if (err instanceof UpstreamError) return c.json({ error: "the chain could not be read; try again" }, 502); return c.json({ error: "internal error" }, 500); }); return app; } + +/** Horizon or the RPC failed: a 502 the front end can retry, not a 500 bug. */ +class UpstreamError extends Error {} + +async function upstream(read: () => Promise): Promise { + try { + return await read(); + } catch (e) { + throw new UpstreamError((e as Error).message, { cause: e }); + } +} diff --git a/be/src/api/config.ts b/be/src/api/config.ts index d6abec9..986981a 100644 --- a/be/src/api/config.ts +++ b/be/src/api/config.ts @@ -15,6 +15,7 @@ export interface ApiConfig { network: "testnet"; networkPassphrase: string; rpcUrl: string; + horizonUrl: string; contracts: Record; /** Exact origins allowed by CORS. Never a wildcard. */ corsOrigins: string[]; @@ -25,7 +26,7 @@ export type Source = "recorded" | "env"; export interface LoadedConfig { config: ApiConfig; - sources: Record<"rpcUrl" | ContractName, Source>; + sources: Record<"rpcUrl" | "horizonUrl" | ContractName, Source>; /** True when every contract in use equals docs/deployments.md. */ recorded: boolean; } @@ -63,8 +64,14 @@ export function loadConfig(env: Record = process.env const rpcUrl = get("STELLAR_RPC_URL") ?? RECORDED.rpcUrl; if (!/^https:\/\//.test(rpcUrl)) throw new Error(`STELLAR_RPC_URL must be https: ${rpcUrl}`); + const horizonUrl = get("HORIZON_URL") ?? RECORDED.horizonUrl; + if (!/^https:\/\//.test(horizonUrl)) throw new Error(`HORIZON_URL must be https: ${horizonUrl}`); + const contracts = {} as Record; - const sources = { rpcUrl: get("STELLAR_RPC_URL") ? "env" : "recorded" } as LoadedConfig["sources"]; + const sources = { + rpcUrl: get("STELLAR_RPC_URL") ? "env" : "recorded", + horizonUrl: get("HORIZON_URL") ? "env" : "recorded", + } as LoadedConfig["sources"]; for (const name of Object.keys(CONTRACT_ENV) as ContractName[]) { const fromEnv = get(CONTRACT_ENV[name]); if (fromEnv !== undefined && !StrKey.isValidContract(fromEnv)) { @@ -90,6 +97,7 @@ export function loadConfig(env: Record = process.env network: "testnet", networkPassphrase: RECORDED.networkPassphrase, rpcUrl, + horizonUrl, contracts, corsOrigins, port, diff --git a/be/src/api/server.ts b/be/src/api/server.ts index b52d76f..2c3fb20 100644 --- a/be/src/api/server.ts +++ b/be/src/api/server.ts @@ -10,6 +10,8 @@ import { serve } from "@hono/node-server"; import { rpc } from "@stellar/stellar-sdk"; import { die, loadEnv } from "../cli/env.js"; +import { readAdvance } from "../chain/advance.js"; +import { fetchOperations } from "../chain/history.js"; import { createApp } from "./app.js"; import { loadConfig } from "./config.js"; @@ -32,7 +34,16 @@ if (!loaded.recorded) { ); } -const app = createApp({ loaded, rpc: new rpc.Server(loaded.config.rpcUrl) }); +const server = new rpc.Server(loaded.config.rpcUrl); +const { horizonUrl, networkPassphrase } = loaded.config; +const app = createApp({ + loaded, + rpc: server, + chain: { + operations: (account) => fetchOperations(account, { horizonUrl }), + readAdvance: (contract, nullifier) => readAdvance(server, networkPassphrase, contract, nullifier), + }, +}); serve({ fetch: app.fetch, port: loaded.config.port }, (info) => { console.log(`Forepay API on :${info.port} (${loaded.config.network}, CORS: ${loaded.config.corsOrigins.join(", ") || "none"})`); }); diff --git a/be/src/chain/advance.ts b/be/src/chain/advance.ts new file mode 100644 index 0000000..9063278 --- /dev/null +++ b/be/src/chain/advance.ts @@ -0,0 +1,69 @@ +/** + * Read an advance's current state from the contract (#16): `advance(nullifier)`. + * + * The figures the front end shows (principal, repaid, window) come from here, the + * contract's own record, not from summing Horizon's history: a repayment the history + * missed or double-counted would otherwise show a balance the contract does not hold. + * + * A read is a simulation. Nothing is signed and nothing is charged; the source account + * only has to be well-formed. + */ +import { Account, Contract, StrKey, TransactionBuilder, nativeToScVal, rpc, scValToNative } from "@stellar/stellar-sdk"; + +/** The contract's `Advance` record, as the API serves it. Amounts in stroops. */ +export interface AdvanceRecord { + borrower: string; + pubId: string; + windowStart: string; + windowEnd: string; + revenueCents: bigint; + principal: bigint; + repaid: bigint; + openedAt: bigint; +} + +/** The slice of the RPC client a read needs. */ +export interface SimulateLike { + simulateTransaction: rpc.Server["simulateTransaction"]; +} + +// Any valid account works as a simulation source; it never signs and needs no balance. +const READ_SOURCE = StrKey.encodeEd25519PublicKey(Buffer.alloc(32)); + +export async function readAdvance( + server: SimulateLike, + networkPassphrase: string, + contract: string, + nullifierHex: string, +): Promise { + if (!/^[0-9a-f]{64}$/.test(nullifierHex)) throw new Error(`not a 32-byte hex nullifier: ${nullifierHex}`); + const tx = new TransactionBuilder(new Account(READ_SOURCE, "0"), { fee: "100", networkPassphrase }) + .addOperation(new Contract(contract).call("advance", nativeToScVal(Buffer.from(nullifierHex, "hex"), { type: "bytes" }))) + .setTimeout(30) + .build(); + const sim = await server.simulateTransaction(tx); + if (rpc.Api.isSimulationError(sim)) throw new Error(`advance(${nullifierHex.slice(0, 8)}…) failed: ${sim.error.split("\n")[0]}`); + const retval = sim.result?.retval; + if (!retval) throw new Error("advance() returned nothing"); + const a = scValToNative(retval) as null | { + borrower: string; + pub_id: string; + window_start: string; + window_end: string; + revenue_cents: bigint; + principal: bigint; + repaid: bigint; + opened_at: bigint; + }; + if (a === null || a === undefined) return null; + return { + borrower: a.borrower, + pubId: a.pub_id, + windowStart: a.window_start, + windowEnd: a.window_end, + revenueCents: BigInt(a.revenue_cents), + principal: BigInt(a.principal), + repaid: BigInt(a.repaid), + openedAt: BigInt(a.opened_at), + }; +} diff --git a/be/src/chain/fixtures/horizon-ops.json b/be/src/chain/fixtures/horizon-ops.json new file mode 100644 index 0000000..a8121b3 --- /dev/null +++ b/be/src/chain/fixtures/horizon-ops.json @@ -0,0 +1,1351 @@ +{ + "_source": "horizon-testnet /accounts/GA2CD6PMHMBTCFAQDO3R22BSZN5ZSVTAKVNOKXL2SONZBLGRAYIOWWH2/operations?include_failed=true&join=transactions, fetched 2026-10-19, trimmed to the fields be/src/chain/history.ts reads. The advance calls go to the dev contract CD25Q4TDGDY6CI3LUIWUOH6SXCH6ETIUCI6FUOBI322GCJL5G3EIHQN4 (#10, #23 rehearsals).", + "records": [ + { + "id": "22538652634640385", + "paging_token": "22538652634640385", + "type": "invoke_host_function", + "created_at": "2026-10-17T18:33:52Z", + "transaction_hash": "886194f0c74f16719dd096f2b3cda8f6c78af265392a473b5d55aea0d951ed66", + "transaction_successful": true, + "source_account": "GA2CD6PMHMBTCFAQDO3R22BSZN5ZSVTAKVNOKXL2SONZBLGRAYIOWWH2", + "function": "HostFunctionTypeHostFunctionTypeInvokeContract", + "parameters": [ + { + "value": "AAAAEgAAAAH12HJjMPHhI2uiLUcf0riP4k0UEjxaOCjetGElfTbIgw==", + "type": "Address" + }, + { + "value": "AAAADwAAAAVyZXBheQAAAA==", + "type": "Sym" + }, + { + "value": "AAAAEgAAAAAAAAAANCH57DsDMRQQG7cdaDLLe5lWYFVa5V16k5uQrNEGEOs=", + "type": "Address" + }, + { + "value": "AAAADQAAACAdEkgX81HEqI7S/pKi95gS8r+kHgYQpbu4T3peiS5o9Q==", + "type": "Bytes" + }, + { + "value": "AAAACgAAAAAAAAAAAAAAAABycOA=", + "type": "I128" + } + ], + "asset_balance_changes": [ + { + "asset_type": "credit_alphanum4", + "asset_code": "USDC", + "asset_issuer": "GBBD47IF6LWK7P7MDEVSCWR7DPUWV3NY3DTQEVFL4NAT4AQH3ZLLFLA5", + "type": "transfer", + "from": "GA2CD6PMHMBTCFAQDO3R22BSZN5ZSVTAKVNOKXL2SONZBLGRAYIOWWH2", + "to": "CD25Q4TDGDY6CI3LUIWUOH6SXCH6ETIUCI6FUOBI322GCJL5G3EIHQN4", + "amount": "0.7500000" + } + ] + }, + { + "id": "22538648339652609", + "paging_token": "22538648339652609", + "type": "invoke_host_function", + "created_at": "2026-10-17T18:33:47Z", + "transaction_hash": "7db87bbfba3fd8f8956a25041a4ae13077504f5c86a29c298c527ecb4cebf8fa", + "transaction_successful": true, + "source_account": "GA2CD6PMHMBTCFAQDO3R22BSZN5ZSVTAKVNOKXL2SONZBLGRAYIOWWH2", + "function": "HostFunctionTypeHostFunctionTypeInvokeContract", + "parameters": [ + { + "value": "AAAAEgAAAAH12HJjMPHhI2uiLUcf0riP4k0UEjxaOCjetGElfTbIgw==", + "type": "Address" + }, + { + "value": "AAAADwAAAAVyZXBheQAAAA==", + "type": "Sym" + }, + { + "value": "AAAAEgAAAAAAAAAANCH57DsDMRQQG7cdaDLLe5lWYFVa5V16k5uQrNEGEOs=", + "type": "Address" + }, + { + "value": "AAAADQAAACAdEkgX81HEqI7S/pKi95gS8r+kHgYQpbu4T3peiS5o9Q==", + "type": "Bytes" + }, + { + "value": "AAAACgAAAAAAAAAAAAAAAAAmJaA=", + "type": "I128" + } + ], + "asset_balance_changes": [ + { + "asset_type": "credit_alphanum4", + "asset_code": "USDC", + "asset_issuer": "GBBD47IF6LWK7P7MDEVSCWR7DPUWV3NY3DTQEVFL4NAT4AQH3ZLLFLA5", + "type": "transfer", + "from": "GA2CD6PMHMBTCFAQDO3R22BSZN5ZSVTAKVNOKXL2SONZBLGRAYIOWWH2", + "to": "CD25Q4TDGDY6CI3LUIWUOH6SXCH6ETIUCI6FUOBI322GCJL5G3EIHQN4", + "amount": "0.2500000" + } + ] + }, + { + "id": "22538631159787521", + "paging_token": "22538631159787521", + "type": "invoke_host_function", + "created_at": "2026-10-17T18:33:27Z", + "transaction_hash": "1e066220909da8dfdfc92d1926a377a4dc2a08b12adaca2c88cef8f394a60f25", + "transaction_successful": true, + "source_account": "GA2CD6PMHMBTCFAQDO3R22BSZN5ZSVTAKVNOKXL2SONZBLGRAYIOWWH2", + "function": "HostFunctionTypeHostFunctionTypeInvokeContract", + "parameters": [ + { + "value": "AAAAEgAAAAH12HJjMPHhI2uiLUcf0riP4k0UEjxaOCjetGElfTbIgw==", + "type": "Address" + }, + { + "value": "AAAADwAAAA9yZXF1ZXN0X2FkdmFuY2UA", + "type": "Sym" + }, + { + "value": "AAAAEgAAAAAAAAAANCH57DsDMRQQG7cdaDLLe5lWYFVa5V16k5uQrNEGEOs=", + "type": "Address" + }, + { + "value": "AAAADgAAAAQ0LjAw", + "type": "Str" + }, + { + "value": "AAAADgAAAA9wdWItaDE3OTIyNjE5OTcA", + "type": "Str" + }, + { + "value": "AAAADgAAAAoyMDI2LTA3LTAxAAA=", + "type": "Str" + }, + { + "value": "AAAADgAAAAoyMDI2LTA5LTMwAAA=", + "type": "Str" + }, + { + "value": "AAAABQAAAABq079t", + "type": "U64" + }, + { + "value": "AAAABQAAAAAAAAAA", + "type": "U64" + }, + { + "value": "AAAADQAAAEBOIJS/ZlmsmwF0voOAx1jUNDR5ERAcwQqSiix5iKlIgRnYbz3F3sDYwKUV7ck31hK8F2pCDGq62AH5Iapd5KJ1", + "type": "Bytes" + }, + { + "value": "AAAAAwAAAAE=", + "type": "U32" + } + ], + "asset_balance_changes": [ + { + "asset_type": "credit_alphanum4", + "asset_code": "USDC", + "asset_issuer": "GBBD47IF6LWK7P7MDEVSCWR7DPUWV3NY3DTQEVFL4NAT4AQH3ZLLFLA5", + "type": "transfer", + "from": "CD25Q4TDGDY6CI3LUIWUOH6SXCH6ETIUCI6FUOBI322GCJL5G3EIHQN4", + "to": "GA2CD6PMHMBTCFAQDO3R22BSZN5ZSVTAKVNOKXL2SONZBLGRAYIOWWH2", + "amount": "1.0000000" + } + ] + }, + { + "id": "22538429296312321", + "paging_token": "22538429296312321", + "type": "invoke_host_function", + "created_at": "2026-10-17T18:29:32Z", + "transaction_hash": "4db68f04c2670af7089fd962721c08d45b0361fbf9701a420be1e53a23401b2b", + "transaction_successful": true, + "source_account": "GA2CD6PMHMBTCFAQDO3R22BSZN5ZSVTAKVNOKXL2SONZBLGRAYIOWWH2", + "function": "HostFunctionTypeHostFunctionTypeInvokeContract", + "parameters": [ + { + "value": "AAAAEgAAAAH12HJjMPHhI2uiLUcf0riP4k0UEjxaOCjetGElfTbIgw==", + "type": "Address" + }, + { + "value": "AAAADwAAAA9leGVjdXRlX3VwZ3JhZGUA", + "type": "Sym" + } + ], + "asset_balance_changes": null + }, + { + "id": "22538412116455425", + "paging_token": "22538412116455425", + "type": "invoke_host_function", + "created_at": "2026-10-17T18:29:12Z", + "transaction_hash": "443a902a9db5b10c67a001e385690fe62c2efbe7c60e5b48e6d05ab309b7ef69", + "transaction_successful": true, + "source_account": "GA2CD6PMHMBTCFAQDO3R22BSZN5ZSVTAKVNOKXL2SONZBLGRAYIOWWH2", + "function": "HostFunctionTypeHostFunctionTypeInvokeContract", + "parameters": [ + { + "value": "AAAAEgAAAAGgVeoe8M5QZppT42aenCzym3+t7dbbkEUpmW2+LkXS9A==", + "type": "Address" + }, + { + "value": "AAAADwAAAA9leGVjdXRlX3VwZ3JhZGUA", + "type": "Sym" + } + ], + "asset_balance_changes": null + }, + { + "id": "22438824709787649", + "paging_token": "22438824709787649", + "type": "invoke_host_function", + "created_at": "2026-10-16T10:16:57Z", + "transaction_hash": "761b394c4349e37ea726f4f26b42f95caeb4b07cb34bf1eeea2575168a068830", + "transaction_successful": true, + "source_account": "GA2CD6PMHMBTCFAQDO3R22BSZN5ZSVTAKVNOKXL2SONZBLGRAYIOWWH2", + "function": "HostFunctionTypeHostFunctionTypeInvokeContract", + "parameters": [ + { + "value": "AAAAEgAAAAH12HJjMPHhI2uiLUcf0riP4k0UEjxaOCjetGElfTbIgw==", + "type": "Address" + }, + { + "value": "AAAADwAAAA9wcm9wb3NlX3VwZ3JhZGUA", + "type": "Sym" + }, + { + "value": "AAAADQAAACDlYmiQZZ+irUTwLzdSo3I1do7njiQtY2yCDSsVgXJd1g==", + "type": "Bytes" + } + ], + "asset_balance_changes": null + }, + { + "id": "22438807529918465", + "paging_token": "22438807529918465", + "type": "invoke_host_function", + "created_at": "2026-10-16T10:16:37Z", + "transaction_hash": "937a655a9aac7dc40cc9c328c176ca13d0823909f764aa3c739444da35f4ef29", + "transaction_successful": true, + "source_account": "GA2CD6PMHMBTCFAQDO3R22BSZN5ZSVTAKVNOKXL2SONZBLGRAYIOWWH2", + "function": "HostFunctionTypeHostFunctionTypeInvokeContract", + "parameters": [ + { + "value": "AAAAEgAAAAGgVeoe8M5QZppT42aenCzym3+t7dbbkEUpmW2+LkXS9A==", + "type": "Address" + }, + { + "value": "AAAADwAAAA9wcm9wb3NlX3VwZ3JhZGUA", + "type": "Sym" + }, + { + "value": "AAAADQAAACDlYmiQZZ+irUTwLzdSo3I1do7njiQtY2yCDSsVgXJd1g==", + "type": "Bytes" + } + ], + "asset_balance_changes": null + }, + { + "id": "22438790350106625", + "paging_token": "22438790350106625", + "type": "invoke_host_function", + "created_at": "2026-10-16T10:16:17Z", + "transaction_hash": "1399a4106df9fffb2d1d2fb1733f0a00d913bade3e21688dcfdb16879d77f6e5", + "transaction_successful": true, + "source_account": "GA2CD6PMHMBTCFAQDO3R22BSZN5ZSVTAKVNOKXL2SONZBLGRAYIOWWH2", + "function": "HostFunctionTypeHostFunctionTypeUploadContractWasm", + "parameters": null, + "asset_balance_changes": null + }, + { + "id": "22386121166065665", + "paging_token": "22386121166065665", + "type": "invoke_host_function", + "created_at": "2026-10-15T17:14:22Z", + "transaction_hash": "fed918178c238a2f27dd65eaf371976336b5eed226130058394b52074cd58a9d", + "transaction_successful": true, + "source_account": "GA2CD6PMHMBTCFAQDO3R22BSZN5ZSVTAKVNOKXL2SONZBLGRAYIOWWH2", + "function": "HostFunctionTypeHostFunctionTypeInvokeContract", + "parameters": [ + { + "value": "AAAAEgAAAAH12HJjMPHhI2uiLUcf0riP4k0UEjxaOCjetGElfTbIgw==", + "type": "Address" + }, + { + "value": "AAAADwAAAAVyZXBheQAAAA==", + "type": "Sym" + }, + { + "value": "AAAAEgAAAAAAAAAANCH57DsDMRQQG7cdaDLLe5lWYFVa5V16k5uQrNEGEOs=", + "type": "Address" + }, + { + "value": "AAAADQAAACDQzQHfMwNisjUI7ffjhpUFSdpjS3VtHCmqJCz8nIjIOQ==", + "type": "Bytes" + }, + { + "value": "AAAACgAAAAAAAAAAAAAAAABycOA=", + "type": "I128" + } + ], + "asset_balance_changes": [ + { + "asset_type": "credit_alphanum4", + "asset_code": "USDC", + "asset_issuer": "GBBD47IF6LWK7P7MDEVSCWR7DPUWV3NY3DTQEVFL4NAT4AQH3ZLLFLA5", + "type": "transfer", + "from": "GA2CD6PMHMBTCFAQDO3R22BSZN5ZSVTAKVNOKXL2SONZBLGRAYIOWWH2", + "to": "CD25Q4TDGDY6CI3LUIWUOH6SXCH6ETIUCI6FUOBI322GCJL5G3EIHQN4", + "amount": "0.7500000" + } + ] + }, + { + "id": "22386112576139265", + "paging_token": "22386112576139265", + "type": "invoke_host_function", + "created_at": "2026-10-15T17:14:12Z", + "transaction_hash": "8308c95ac0c357ae92766a412685aa7161fb2a21ff26d3f92e45cb4502a2032d", + "transaction_successful": true, + "source_account": "GA2CD6PMHMBTCFAQDO3R22BSZN5ZSVTAKVNOKXL2SONZBLGRAYIOWWH2", + "function": "HostFunctionTypeHostFunctionTypeInvokeContract", + "parameters": [ + { + "value": "AAAAEgAAAAH12HJjMPHhI2uiLUcf0riP4k0UEjxaOCjetGElfTbIgw==", + "type": "Address" + }, + { + "value": "AAAADwAAAAVyZXBheQAAAA==", + "type": "Sym" + }, + { + "value": "AAAAEgAAAAAAAAAANCH57DsDMRQQG7cdaDLLe5lWYFVa5V16k5uQrNEGEOs=", + "type": "Address" + }, + { + "value": "AAAADQAAACDQzQHfMwNisjUI7ffjhpUFSdpjS3VtHCmqJCz8nIjIOQ==", + "type": "Bytes" + }, + { + "value": "AAAACgAAAAAAAAAAAAAAAAAmJaA=", + "type": "I128" + } + ], + "asset_balance_changes": [ + { + "asset_type": "credit_alphanum4", + "asset_code": "USDC", + "asset_issuer": "GBBD47IF6LWK7P7MDEVSCWR7DPUWV3NY3DTQEVFL4NAT4AQH3ZLLFLA5", + "type": "transfer", + "from": "GA2CD6PMHMBTCFAQDO3R22BSZN5ZSVTAKVNOKXL2SONZBLGRAYIOWWH2", + "to": "CD25Q4TDGDY6CI3LUIWUOH6SXCH6ETIUCI6FUOBI322GCJL5G3EIHQN4", + "amount": "0.2500000" + } + ] + }, + { + "id": "22386103986212865", + "paging_token": "22386103986212865", + "type": "invoke_host_function", + "created_at": "2026-10-15T17:14:02Z", + "transaction_hash": "9a94cf083543b58d79b60431de305f3912099ca9337ada4793ef1e38546f8ad0", + "transaction_successful": true, + "source_account": "GA2CD6PMHMBTCFAQDO3R22BSZN5ZSVTAKVNOKXL2SONZBLGRAYIOWWH2", + "function": "HostFunctionTypeHostFunctionTypeInvokeContract", + "parameters": [ + { + "value": "AAAAEgAAAAH12HJjMPHhI2uiLUcf0riP4k0UEjxaOCjetGElfTbIgw==", + "type": "Address" + }, + { + "value": "AAAADwAAAA9yZXF1ZXN0X2FkdmFuY2UA", + "type": "Sym" + }, + { + "value": "AAAAEgAAAAAAAAAANCH57DsDMRQQG7cdaDLLe5lWYFVa5V16k5uQrNEGEOs=", + "type": "Address" + }, + { + "value": "AAAADgAAAAQ0LjAw", + "type": "Str" + }, + { + "value": "AAAADgAAAA9wdWItaDE3OTIwODQ0MzQA", + "type": "Str" + }, + { + "value": "AAAADgAAAAoyMDI2LTA3LTAxAAA=", + "type": "Str" + }, + { + "value": "AAAADgAAAAoyMDI2LTA5LTMwAAA=", + "type": "Str" + }, + { + "value": "AAAABQAAAABq0QnS", + "type": "U64" + }, + { + "value": "AAAABQAAAAAAAAAA", + "type": "U64" + }, + { + "value": "AAAADQAAAEB/3FczsCdWqoTffr1IhSMySu32/OZfiG78kfMm/GnOmhvYees1zYpjQMbeqaBoksT5jkO11FSiTarbdaSblRMp", + "type": "Bytes" + }, + { + "value": "AAAAAwAAAAA=", + "type": "U32" + } + ], + "asset_balance_changes": [ + { + "asset_type": "credit_alphanum4", + "asset_code": "USDC", + "asset_issuer": "GBBD47IF6LWK7P7MDEVSCWR7DPUWV3NY3DTQEVFL4NAT4AQH3ZLLFLA5", + "type": "transfer", + "from": "CD25Q4TDGDY6CI3LUIWUOH6SXCH6ETIUCI6FUOBI322GCJL5G3EIHQN4", + "to": "GA2CD6PMHMBTCFAQDO3R22BSZN5ZSVTAKVNOKXL2SONZBLGRAYIOWWH2", + "amount": "1.0000000" + } + ] + }, + { + "id": "22384583567765505", + "paging_token": "22384583567765505", + "type": "invoke_host_function", + "created_at": "2026-10-15T16:44:32Z", + "transaction_hash": "5107662eeafe2a9c137465c66b2abbff8bb015c57fe28f76923364010c35b31d", + "transaction_successful": true, + "source_account": "GA2CD6PMHMBTCFAQDO3R22BSZN5ZSVTAKVNOKXL2SONZBLGRAYIOWWH2", + "function": "HostFunctionTypeHostFunctionTypeInvokeContract", + "parameters": [ + { + "value": "AAAAEgAAAAH12HJjMPHhI2uiLUcf0riP4k0UEjxaOCjetGElfTbIgw==", + "type": "Address" + }, + { + "value": "AAAADwAAAAVyZXBheQAAAA==", + "type": "Sym" + }, + { + "value": "AAAAEgAAAAAAAAAANCH57DsDMRQQG7cdaDLLe5lWYFVa5V16k5uQrNEGEOs=", + "type": "Address" + }, + { + "value": "AAAADQAAACAPvsW+U1iIse6y4wLB4EbwA4lR3LgJ9U8zJ86h97M37Q==", + "type": "Bytes" + }, + { + "value": "AAAACgAAAAAAAAAAAAAAAABycOA=", + "type": "I128" + } + ], + "asset_balance_changes": [ + { + "asset_type": "credit_alphanum4", + "asset_code": "USDC", + "asset_issuer": "GBBD47IF6LWK7P7MDEVSCWR7DPUWV3NY3DTQEVFL4NAT4AQH3ZLLFLA5", + "type": "transfer", + "from": "GA2CD6PMHMBTCFAQDO3R22BSZN5ZSVTAKVNOKXL2SONZBLGRAYIOWWH2", + "to": "CD25Q4TDGDY6CI3LUIWUOH6SXCH6ETIUCI6FUOBI322GCJL5G3EIHQN4", + "amount": "0.7500000" + } + ] + }, + { + "id": "22384574977826817", + "paging_token": "22384574977826817", + "type": "invoke_host_function", + "created_at": "2026-10-15T16:44:22Z", + "transaction_hash": "f8068c2208f8c54c4b030ff956c312100ec2c930b8c2eb94511460b1cb7e7366", + "transaction_successful": true, + "source_account": "GA2CD6PMHMBTCFAQDO3R22BSZN5ZSVTAKVNOKXL2SONZBLGRAYIOWWH2", + "function": "HostFunctionTypeHostFunctionTypeInvokeContract", + "parameters": [ + { + "value": "AAAAEgAAAAH12HJjMPHhI2uiLUcf0riP4k0UEjxaOCjetGElfTbIgw==", + "type": "Address" + }, + { + "value": "AAAADwAAAAVyZXBheQAAAA==", + "type": "Sym" + }, + { + "value": "AAAAEgAAAAAAAAAANCH57DsDMRQQG7cdaDLLe5lWYFVa5V16k5uQrNEGEOs=", + "type": "Address" + }, + { + "value": "AAAADQAAACAPvsW+U1iIse6y4wLB4EbwA4lR3LgJ9U8zJ86h97M37Q==", + "type": "Bytes" + }, + { + "value": "AAAACgAAAAAAAAAAAAAAAAAmJaA=", + "type": "I128" + } + ], + "asset_balance_changes": [ + { + "asset_type": "credit_alphanum4", + "asset_code": "USDC", + "asset_issuer": "GBBD47IF6LWK7P7MDEVSCWR7DPUWV3NY3DTQEVFL4NAT4AQH3ZLLFLA5", + "type": "transfer", + "from": "GA2CD6PMHMBTCFAQDO3R22BSZN5ZSVTAKVNOKXL2SONZBLGRAYIOWWH2", + "to": "CD25Q4TDGDY6CI3LUIWUOH6SXCH6ETIUCI6FUOBI322GCJL5G3EIHQN4", + "amount": "0.2500000" + } + ] + }, + { + "id": "22384562092929025", + "paging_token": "22384562092929025", + "type": "invoke_host_function", + "created_at": "2026-10-15T16:44:07Z", + "transaction_hash": "0f14ff628b2d0fe5c088161caf8c824c4a002852db346ae58683b4030a369b66", + "transaction_successful": true, + "source_account": "GA2CD6PMHMBTCFAQDO3R22BSZN5ZSVTAKVNOKXL2SONZBLGRAYIOWWH2", + "function": "HostFunctionTypeHostFunctionTypeInvokeContract", + "parameters": [ + { + "value": "AAAAEgAAAAH12HJjMPHhI2uiLUcf0riP4k0UEjxaOCjetGElfTbIgw==", + "type": "Address" + }, + { + "value": "AAAADwAAAA9yZXF1ZXN0X2FkdmFuY2UA", + "type": "Sym" + }, + { + "value": "AAAAEgAAAAAAAAAANCH57DsDMRQQG7cdaDLLe5lWYFVa5V16k5uQrNEGEOs=", + "type": "Address" + }, + { + "value": "AAAADgAAAAQ0LjAw", + "type": "Str" + }, + { + "value": "AAAADgAAAA9wdWItaDE3OTIwODI2MzYA", + "type": "Str" + }, + { + "value": "AAAADgAAAAoyMDI2LTA3LTAxAAA=", + "type": "Str" + }, + { + "value": "AAAADgAAAAoyMDI2LTA5LTMwAAA=", + "type": "Str" + }, + { + "value": "AAAABQAAAABq0QLM", + "type": "U64" + }, + { + "value": "AAAABQAAAAAAAAAA", + "type": "U64" + }, + { + "value": "AAAADQAAAEBQRXH3NYUqT6c4bxP+J8PtBy+qIEi1QR5j+vJUzrwgBSWQHMaYXZ9aTQylR2kJfqmasb6XZ06NMhpWa7AFiGua", + "type": "Bytes" + }, + { + "value": "AAAAAwAAAAE=", + "type": "U32" + } + ], + "asset_balance_changes": [ + { + "asset_type": "credit_alphanum4", + "asset_code": "USDC", + "asset_issuer": "GBBD47IF6LWK7P7MDEVSCWR7DPUWV3NY3DTQEVFL4NAT4AQH3ZLLFLA5", + "type": "transfer", + "from": "CD25Q4TDGDY6CI3LUIWUOH6SXCH6ETIUCI6FUOBI322GCJL5G3EIHQN4", + "to": "GA2CD6PMHMBTCFAQDO3R22BSZN5ZSVTAKVNOKXL2SONZBLGRAYIOWWH2", + "amount": "1.0000000" + } + ] + }, + { + "id": "22384532028162049", + "paging_token": "22384532028162049", + "type": "invoke_host_function", + "created_at": "2026-10-15T16:43:32Z", + "transaction_hash": "9cc2222892bb383f54de9132dbab35cbdabeeed0f75a6b97ca8bd2115a215dcd", + "transaction_successful": true, + "source_account": "GA2CD6PMHMBTCFAQDO3R22BSZN5ZSVTAKVNOKXL2SONZBLGRAYIOWWH2", + "function": "HostFunctionTypeHostFunctionTypeInvokeContract", + "parameters": [ + { + "value": "AAAAEgAAAAH12HJjMPHhI2uiLUcf0riP4k0UEjxaOCjetGElfTbIgw==", + "type": "Address" + }, + { + "value": "AAAADwAAAAVyZXBheQAAAA==", + "type": "Sym" + }, + { + "value": "AAAAEgAAAAAAAAAANCH57DsDMRQQG7cdaDLLe5lWYFVa5V16k5uQrNEGEOs=", + "type": "Address" + }, + { + "value": "AAAADQAAACB9liJQWK11RSLnikscarlDuGRCspd+18b9AYKCHbs92A==", + "type": "Bytes" + }, + { + "value": "AAAACgAAAAAAAAAAAAAAAABycOA=", + "type": "I128" + } + ], + "asset_balance_changes": [ + { + "asset_type": "credit_alphanum4", + "asset_code": "USDC", + "asset_issuer": "GBBD47IF6LWK7P7MDEVSCWR7DPUWV3NY3DTQEVFL4NAT4AQH3ZLLFLA5", + "type": "transfer", + "from": "GA2CD6PMHMBTCFAQDO3R22BSZN5ZSVTAKVNOKXL2SONZBLGRAYIOWWH2", + "to": "CD25Q4TDGDY6CI3LUIWUOH6SXCH6ETIUCI6FUOBI322GCJL5G3EIHQN4", + "amount": "0.7500000" + } + ] + }, + { + "id": "22384523438223361", + "paging_token": "22384523438223361", + "type": "invoke_host_function", + "created_at": "2026-10-15T16:43:22Z", + "transaction_hash": "0e24b08b2e41d948d6f0fd966c076187633603fd56bf80eeebcc1306fdb240cf", + "transaction_successful": true, + "source_account": "GA2CD6PMHMBTCFAQDO3R22BSZN5ZSVTAKVNOKXL2SONZBLGRAYIOWWH2", + "function": "HostFunctionTypeHostFunctionTypeInvokeContract", + "parameters": [ + { + "value": "AAAAEgAAAAH12HJjMPHhI2uiLUcf0riP4k0UEjxaOCjetGElfTbIgw==", + "type": "Address" + }, + { + "value": "AAAADwAAAAVyZXBheQAAAA==", + "type": "Sym" + }, + { + "value": "AAAAEgAAAAAAAAAANCH57DsDMRQQG7cdaDLLe5lWYFVa5V16k5uQrNEGEOs=", + "type": "Address" + }, + { + "value": "AAAADQAAACB9liJQWK11RSLnikscarlDuGRCspd+18b9AYKCHbs92A==", + "type": "Bytes" + }, + { + "value": "AAAACgAAAAAAAAAAAAAAAAAmJaA=", + "type": "I128" + } + ], + "asset_balance_changes": [ + { + "asset_type": "credit_alphanum4", + "asset_code": "USDC", + "asset_issuer": "GBBD47IF6LWK7P7MDEVSCWR7DPUWV3NY3DTQEVFL4NAT4AQH3ZLLFLA5", + "type": "transfer", + "from": "GA2CD6PMHMBTCFAQDO3R22BSZN5ZSVTAKVNOKXL2SONZBLGRAYIOWWH2", + "to": "CD25Q4TDGDY6CI3LUIWUOH6SXCH6ETIUCI6FUOBI322GCJL5G3EIHQN4", + "amount": "0.2500000" + } + ] + }, + { + "id": "22384514848301057", + "paging_token": "22384514848301057", + "type": "invoke_host_function", + "created_at": "2026-10-15T16:43:12Z", + "transaction_hash": "7f40d753301a1166862d2f0c08c4adf38854127b2103ae39db37300ad03747b4", + "transaction_successful": true, + "source_account": "GA2CD6PMHMBTCFAQDO3R22BSZN5ZSVTAKVNOKXL2SONZBLGRAYIOWWH2", + "function": "HostFunctionTypeHostFunctionTypeInvokeContract", + "parameters": [ + { + "value": "AAAAEgAAAAH12HJjMPHhI2uiLUcf0riP4k0UEjxaOCjetGElfTbIgw==", + "type": "Address" + }, + { + "value": "AAAADwAAAA9yZXF1ZXN0X2FkdmFuY2UA", + "type": "Sym" + }, + { + "value": "AAAAEgAAAAAAAAAANCH57DsDMRQQG7cdaDLLe5lWYFVa5V16k5uQrNEGEOs=", + "type": "Address" + }, + { + "value": "AAAADgAAAAQ0LjAw", + "type": "Str" + }, + { + "value": "AAAADgAAAA9wdWItaDE3OTIwODI1ODQA", + "type": "Str" + }, + { + "value": "AAAADgAAAAoyMDI2LTA3LTAxAAA=", + "type": "Str" + }, + { + "value": "AAAADgAAAAoyMDI2LTA5LTMwAAA=", + "type": "Str" + }, + { + "value": "AAAABQAAAABq0QKY", + "type": "U64" + }, + { + "value": "AAAABQAAAAAAAAAA", + "type": "U64" + }, + { + "value": "AAAADQAAAEB0BmnUMLnDMiUgFYGg5bImLME+8yAuEjvAhr8OjttP0hL3GAb6WFd8qBNIcP1hldQX5ECDUj7sUhbYX0msCjQX", + "type": "Bytes" + }, + { + "value": "AAAAAwAAAAE=", + "type": "U32" + } + ], + "asset_balance_changes": [ + { + "asset_type": "credit_alphanum4", + "asset_code": "USDC", + "asset_issuer": "GBBD47IF6LWK7P7MDEVSCWR7DPUWV3NY3DTQEVFL4NAT4AQH3ZLLFLA5", + "type": "transfer", + "from": "CD25Q4TDGDY6CI3LUIWUOH6SXCH6ETIUCI6FUOBI322GCJL5G3EIHQN4", + "to": "GA2CD6PMHMBTCFAQDO3R22BSZN5ZSVTAKVNOKXL2SONZBLGRAYIOWWH2", + "amount": "1.0000000" + } + ] + }, + { + "id": "22384441833832449", + "paging_token": "22384441833832449", + "type": "invoke_host_function", + "created_at": "2026-10-15T16:41:47Z", + "transaction_hash": "71995c4607734070517c0496e36e2abe80addc9d12fca919279f84efbbf9d17a", + "transaction_successful": true, + "source_account": "GA2CD6PMHMBTCFAQDO3R22BSZN5ZSVTAKVNOKXL2SONZBLGRAYIOWWH2", + "function": "HostFunctionTypeHostFunctionTypeInvokeContract", + "parameters": [ + { + "value": "AAAAEgAAAAH12HJjMPHhI2uiLUcf0riP4k0UEjxaOCjetGElfTbIgw==", + "type": "Address" + }, + { + "value": "AAAADwAAABJzZXRfY2xhaW1fdGVtcGxhdGUAAA==", + "type": "Sym" + }, + { + "value": "AAAAEAAAAAEAAAAEAAAADQAAAEJ7Im1ldGhvZCI6IkdFVCIsInVybCI6Imh0dHBzOi8vYWRzZW5zZS5nb29nbGVhcGlzLmNvbS92Mi9hY2NvdW50cy8AAAAAAA0AAAAcL3JlcG9ydHM6Z2VuZXJhdGU/c3RhcnREYXRlPQAAAA0AAAAJJmVuZERhdGU9AAAAAAAADQAAAB0mbWV0cmljcz1FU1RJTUFURURfRUFSTklOR1MifQAAAA==", + "type": "Vec" + }, + { + "value": "AAAADQAAAEIweDU2OWI5MzIzMzE4NWMwNTRlZDlmZGE2OGI1YWVmOGZkYTE4MGI2ZDI5MTE4MDQ1MGJmNzU3YjExYmI1MmY3ZGYAAA==", + "type": "Bytes" + } + ], + "asset_balance_changes": null + }, + { + "id": "22384433243906049", + "paging_token": "22384433243906049", + "type": "invoke_host_function", + "created_at": "2026-10-15T16:41:37Z", + "transaction_hash": "2bb17e05ac59b1a11a7a87037f04a7f60084fbb4fd212d1e01780247fc78bed8", + "transaction_successful": true, + "source_account": "GA2CD6PMHMBTCFAQDO3R22BSZN5ZSVTAKVNOKXL2SONZBLGRAYIOWWH2", + "function": "HostFunctionTypeHostFunctionTypeCreateContractV2", + "parameters": [ + { + "value": "AAAAEgAAAAAAAAAANCH57DsDMRQQG7cdaDLLe5lWYFVa5V16k5uQrNEGEOs=", + "type": "Address" + }, + { + "value": "AAAAEgAAAAEkBCrfI6wtxoGW+IBbxJ3DdHFOg1l3e8NX1xC3rLgtbA==", + "type": "Address" + }, + { + "value": "AAAAEgAAAAFQRc1ewHKado/VrQJQWFLfTwKNzoMOWsUiCbpISDsvAQ==", + "type": "Address" + } + ], + "asset_balance_changes": null + }, + { + "id": "22384407474118657", + "paging_token": "22384407474118657", + "type": "change_trust", + "created_at": "2026-10-15T16:41:07Z", + "transaction_hash": "17a0d45dd934ad4831e8b8e5d9338a30601a357c3230799a053eaaf9660701f1", + "transaction_successful": true, + "source_account": "GA2CD6PMHMBTCFAQDO3R22BSZN5ZSVTAKVNOKXL2SONZBLGRAYIOWWH2", + "asset_code": "USDC", + "asset_issuer": "GBBD47IF6LWK7P7MDEVSCWR7DPUWV3NY3DTQEVFL4NAT4AQH3ZLLFLA5", + "limit": "922337203685.4775807" + }, + { + "id": "22384377409343489", + "paging_token": "22384377409343489", + "type": "invoke_host_function", + "created_at": "2026-10-15T16:40:32Z", + "transaction_hash": "2b0400569f8bea47ee6522b92640b8f96a600dfef4210670161903030c7358a2", + "transaction_successful": true, + "source_account": "GA2CD6PMHMBTCFAQDO3R22BSZN5ZSVTAKVNOKXL2SONZBLGRAYIOWWH2", + "function": "HostFunctionTypeHostFunctionTypeInvokeContract", + "parameters": [ + { + "value": "AAAAEgAAAAE3g0D05oi9TA432p6Mc+lWpUGjsihS08qv4JOIplgNiw==", + "type": "Address" + }, + { + "value": "AAAADwAAABJ2ZXJpZnlfYW5kX3Jlc2VydmUAAA==", + "type": "Sym" + }, + { + "value": "AAAAEgAAAAAAAAAANCH57DsDMRQQG7cdaDLLe5lWYFVa5V16k5uQrNEGEOs=", + "type": "Address" + }, + { + "value": "AAAADgAAAAUxOC4wMAAAAA==", + "type": "Str" + }, + { + "value": "AAAADgAAAA9wdWItaDE3OTIwODI0MjIA", + "type": "Str" + }, + { + "value": "AAAADgAAAAoyMDI2LTA3LTAxAAA=", + "type": "Str" + }, + { + "value": "AAAADgAAAAoyMDI2LTA5LTMwAAA=", + "type": "Str" + }, + { + "value": "AAAABQAAAABq0QH2", + "type": "U64" + }, + { + "value": "AAAABQAAAAAAAAAA", + "type": "U64" + }, + { + "value": "AAAADQAAAEAANwuMMLiEB2NhScz6fkjqYTyZLzvQDHcixOI789nyrggkjUVBQFviamS2GxWU8b9rV+FhHy6fEyHeeRK4gSgX", + "type": "Bytes" + }, + { + "value": "AAAAAwAAAAA=", + "type": "U32" + } + ], + "asset_balance_changes": null + }, + { + "id": "22383380976914433", + "paging_token": "22383380976914433", + "type": "invoke_host_function", + "created_at": "2026-10-15T16:21:12Z", + "transaction_hash": "d00cc83ec5836adf2d013d33bbc6579d8b641fa8118fc5d39c97a40ccf4289c1", + "transaction_successful": true, + "source_account": "GA2CD6PMHMBTCFAQDO3R22BSZN5ZSVTAKVNOKXL2SONZBLGRAYIOWWH2", + "function": "HostFunctionTypeHostFunctionTypeInvokeContract", + "parameters": [ + { + "value": "AAAAEgAAAAE3g0D05oi9TA432p6Mc+lWpUGjsihS08qv4JOIplgNiw==", + "type": "Address" + }, + { + "value": "AAAADwAAABJ2ZXJpZnlfYW5kX3Jlc2VydmUAAA==", + "type": "Sym" + }, + { + "value": "AAAAEgAAAAAAAAAANCH57DsDMRQQG7cdaDLLe5lWYFVa5V16k5uQrNEGEOs=", + "type": "Address" + }, + { + "value": "AAAADgAAAAUxOS4wMAAAAA==", + "type": "Str" + }, + { + "value": "AAAADgAAABRwdWItMjUyNTI1MjUyNTI1MjUyNQ==", + "type": "Str" + }, + { + "value": "AAAADgAAAAoyMDI2LTAxLTAxAAA=", + "type": "Str" + }, + { + "value": "AAAADgAAAAoyMDI2LTAzLTMxAAA=", + "type": "Str" + }, + { + "value": "AAAABQAAAABq0P1l", + "type": "U64" + }, + { + "value": "AAAABQAAAAAAAAAA", + "type": "U64" + }, + { + "value": "AAAADQAAAEArtFmJGlvF3rlEl0oVOeLQ08fcNdap515E3RO0pggbYlvY8F6Url23UN2q2JoMIeXjj2LHuIx5YMGorbj5uTUg", + "type": "Bytes" + }, + { + "value": "AAAAAwAAAAE=", + "type": "U32" + } + ], + "asset_balance_changes": null + }, + { + "id": "22383174818500609", + "paging_token": "22383174818500609", + "type": "invoke_host_function", + "created_at": "2026-10-15T16:17:12Z", + "transaction_hash": "162b534cd0c540fe8916acfaf6fdc6ba2f7de7cb34abbd1fa804ba8fbeecf263", + "transaction_successful": true, + "source_account": "GA2CD6PMHMBTCFAQDO3R22BSZN5ZSVTAKVNOKXL2SONZBLGRAYIOWWH2", + "function": "HostFunctionTypeHostFunctionTypeInvokeContract", + "parameters": [ + { + "value": "AAAAEgAAAAE3g0D05oi9TA432p6Mc+lWpUGjsihS08qv4JOIplgNiw==", + "type": "Address" + }, + { + "value": "AAAADwAAABJ2ZXJpZnlfYW5kX3Jlc2VydmUAAA==", + "type": "Sym" + }, + { + "value": "AAAAEgAAAAAAAAAANCH57DsDMRQQG7cdaDLLe5lWYFVa5V16k5uQrNEGEOs=", + "type": "Address" + }, + { + "value": "AAAADgAAAAUxOC4wMAAAAA==", + "type": "Str" + }, + { + "value": "AAAADgAAABRwdWItMTgxODE4MTgxODE4MTgxOA==", + "type": "Str" + }, + { + "value": "AAAADgAAAAoyMDI2LTA0LTAxAAA=", + "type": "Str" + }, + { + "value": "AAAADgAAAAoyMDI2LTA2LTMwAAA=", + "type": "Str" + }, + { + "value": "AAAABQAAAABq0Pxz", + "type": "U64" + }, + { + "value": "AAAABQAAAAAAAAAA", + "type": "U64" + }, + { + "value": "AAAADQAAAEAvY5Nt+DmPWdQm9zdNHzutZ6ji9GQ/6Z9flS4lZvLDSDrYiVu7hqKyj/ErWPLrL/x8OZrlSHkkHHyyy5AM+9ec", + "type": "Bytes" + }, + { + "value": "AAAAAwAAAAA=", + "type": "U32" + } + ], + "asset_balance_changes": null + }, + { + "id": "22381813313916929", + "paging_token": "22381813313916929", + "type": "invoke_host_function", + "created_at": "2026-10-15T15:50:47Z", + "transaction_hash": "e2a2ed3c1b2ee5ad8f5855bc989b91a812d805a12b3c8188c0c64c455f7d9f64", + "transaction_successful": true, + "source_account": "GA2CD6PMHMBTCFAQDO3R22BSZN5ZSVTAKVNOKXL2SONZBLGRAYIOWWH2", + "function": "HostFunctionTypeHostFunctionTypeInvokeContract", + "parameters": [ + { + "value": "AAAAEgAAAAGgVeoe8M5QZppT42aenCzym3+t7dbbkEUpmW2+LkXS9A==", + "type": "Address" + }, + { + "value": "AAAADwAAAA5jYW5jZWxfdXBncmFkZQAA", + "type": "Sym" + } + ], + "asset_balance_changes": null + }, + { + "id": "22381804723957761", + "paging_token": "22381804723957761", + "type": "invoke_host_function", + "created_at": "2026-10-15T15:50:37Z", + "transaction_hash": "6a71c864042c7ccc39d49d333869bdc3979be5578145fdf692d2e460ec02ba13", + "transaction_successful": true, + "source_account": "GA2CD6PMHMBTCFAQDO3R22BSZN5ZSVTAKVNOKXL2SONZBLGRAYIOWWH2", + "function": "HostFunctionTypeHostFunctionTypeInvokeContract", + "parameters": [ + { + "value": "AAAAEgAAAAGgVeoe8M5QZppT42aenCzym3+t7dbbkEUpmW2+LkXS9A==", + "type": "Address" + }, + { + "value": "AAAADwAAAA9wcm9wb3NlX3VwZ3JhZGUA", + "type": "Sym" + }, + { + "value": "AAAADQAAACChspO6i5BDs/iTuPygUBibXJgNVw230bLgOhL0xXXuNg==", + "type": "Bytes" + } + ], + "asset_balance_changes": null + }, + { + "id": "22381757479288833", + "paging_token": "22381757479288833", + "type": "invoke_host_function", + "created_at": "2026-10-15T15:49:42Z", + "transaction_hash": "722526e6c469813baad413c82ea84d3fcff13f13723320338e2fcc9db8ca3ae7", + "transaction_successful": true, + "source_account": "GA2CD6PMHMBTCFAQDO3R22BSZN5ZSVTAKVNOKXL2SONZBLGRAYIOWWH2", + "function": "HostFunctionTypeHostFunctionTypeCreateContractV2", + "parameters": [ + { + "value": "AAAAEgAAAAAAAAAANCH57DsDMRQQG7cdaDLLe5lWYFVa5V16k5uQrNEGEOs=", + "type": "Address" + }, + { + "value": "AAAAEgAAAAE2Rl4+S502v5ye3ASVjGGVGJJjSoK8v1Gm5IxyQygP3g==", + "type": "Address" + }, + { + "value": "AAAAEgAAAAFQRc1ewHKado/VrQJQWFLfTwKNzoMOWsUiCbpISDsvAQ==", + "type": "Address" + } + ], + "asset_balance_changes": null + }, + { + "id": "22381740299436033", + "paging_token": "22381740299436033", + "type": "invoke_host_function", + "created_at": "2026-10-15T15:49:22Z", + "transaction_hash": "cafaeed6e693477a960a2183333961fafd026cf64b06758c7fc29f420c06cb36", + "transaction_successful": true, + "source_account": "GA2CD6PMHMBTCFAQDO3R22BSZN5ZSVTAKVNOKXL2SONZBLGRAYIOWWH2", + "function": "HostFunctionTypeHostFunctionTypeUploadContractWasm", + "parameters": null, + "asset_balance_changes": null + }, + { + "id": "22305040773439489", + "paging_token": "22305040773439489", + "type": "invoke_host_function", + "created_at": "2026-10-14T15:01:12Z", + "transaction_hash": "0820e7eee08e3f1028534a1137dee83af7542aadfcd2bd27d71517800960c7d6", + "transaction_successful": true, + "source_account": "GA2CD6PMHMBTCFAQDO3R22BSZN5ZSVTAKVNOKXL2SONZBLGRAYIOWWH2", + "function": "HostFunctionTypeHostFunctionTypeInvokeContract", + "parameters": [ + { + "value": "AAAAEgAAAAE3g0D05oi9TA432p6Mc+lWpUGjsihS08qv4JOIplgNiw==", + "type": "Address" + }, + { + "value": "AAAADwAAAA5jYW5jZWxfdXBncmFkZQAA", + "type": "Sym" + } + ], + "asset_balance_changes": null + }, + { + "id": "22305023593603073", + "paging_token": "22305023593603073", + "type": "invoke_host_function", + "created_at": "2026-10-14T15:00:52Z", + "transaction_hash": "5f2f59dd10228060f20b2cae5188a4fde04b1a7e907261a1459f42c13970c8da", + "transaction_successful": true, + "source_account": "GA2CD6PMHMBTCFAQDO3R22BSZN5ZSVTAKVNOKXL2SONZBLGRAYIOWWH2", + "function": "HostFunctionTypeHostFunctionTypeInvokeContract", + "parameters": [ + { + "value": "AAAAEgAAAAE3g0D05oi9TA432p6Mc+lWpUGjsihS08qv4JOIplgNiw==", + "type": "Address" + }, + { + "value": "AAAADwAAAA9wcm9wb3NlX3VwZ3JhZGUA", + "type": "Sym" + }, + { + "value": "AAAADQAAACCvnuAu3EoSCX3MHJ6Ke+WEHg7siRZY29ddlqVVrgzcVQ==", + "type": "Bytes" + } + ], + "asset_balance_changes": null + }, + { + "id": "22304753010708481", + "paging_token": "22304753010708481", + "type": "invoke_host_function", + "created_at": "2026-10-14T14:55:37Z", + "transaction_hash": "c9ea01e40444ef41ee2557bab6b963db51d3d9e0f9dfa531d84511767ea847e8", + "transaction_successful": true, + "source_account": "GA2CD6PMHMBTCFAQDO3R22BSZN5ZSVTAKVNOKXL2SONZBLGRAYIOWWH2", + "function": "HostFunctionTypeHostFunctionTypeInvokeContract", + "parameters": [ + { + "value": "AAAAEgAAAAE3g0D05oi9TA432p6Mc+lWpUGjsihS08qv4JOIplgNiw==", + "type": "Address" + }, + { + "value": "AAAADwAAABJ2ZXJpZnlfYW5kX3Jlc2VydmUAAA==", + "type": "Sym" + }, + { + "value": "AAAAEgAAAAAAAAAANCH57DsDMRQQG7cdaDLLe5lWYFVa5V16k5uQrNEGEOs=", + "type": "Address" + }, + { + "value": "AAAADgAAAAc0ODIxLjc1AA==", + "type": "Str" + }, + { + "value": "AAAADgAAABRwdWItOTk4ODc3NjY1NTQ0MzMyMg==", + "type": "Str" + }, + { + "value": "AAAADgAAAAoyMDI2LTA3LTAxAAA=", + "type": "Str" + }, + { + "value": "AAAADgAAAAoyMDI2LTA5LTMwAAA=", + "type": "Str" + }, + { + "value": "AAAABQAAAABqz5fX", + "type": "U64" + }, + { + "value": "AAAABQAAAAAAAAAA", + "type": "U64" + }, + { + "value": "AAAADQAAAEDeo2oFk3F6s3JVWAPYO4YRvIKD4zhPYmgjNLAHzhJZbGiRYdUUg76brYXIe4+JDBZ2QmC3PolsqEXm6xrGdyHF", + "type": "Bytes" + }, + { + "value": "AAAAAwAAAAA=", + "type": "U32" + } + ], + "asset_balance_changes": null + }, + { + "id": "22304727240826881", + "paging_token": "22304727240826881", + "type": "invoke_host_function", + "created_at": "2026-10-14T14:55:07Z", + "transaction_hash": "36d6362ea16d4233a4f3002787389ea294b2eae94b9f159f4f59d90be1ae3527", + "transaction_successful": true, + "source_account": "GA2CD6PMHMBTCFAQDO3R22BSZN5ZSVTAKVNOKXL2SONZBLGRAYIOWWH2", + "function": "HostFunctionTypeHostFunctionTypeInvokeContract", + "parameters": [ + { + "value": "AAAAEgAAAAE3g0D05oi9TA432p6Mc+lWpUGjsihS08qv4JOIplgNiw==", + "type": "Address" + }, + { + "value": "AAAADwAAABJzZXRfY2xhaW1fdGVtcGxhdGUAAA==", + "type": "Sym" + }, + { + "value": "AAAAEAAAAAEAAAAEAAAADQAAAEJ7Im1ldGhvZCI6IkdFVCIsInVybCI6Imh0dHBzOi8vYWRzZW5zZS5nb29nbGVhcGlzLmNvbS92Mi9hY2NvdW50cy8AAAAAAA0AAAAcL3JlcG9ydHM6Z2VuZXJhdGU/c3RhcnREYXRlPQAAAA0AAAAJJmVuZERhdGU9AAAAAAAADQAAAB0mbWV0cmljcz1FU1RJTUFURURfRUFSTklOR1MifQAAAA==", + "type": "Vec" + }, + { + "value": "AAAADQAAAEIweDU2OWI5MzIzMzE4NWMwNTRlZDlmZGE2OGI1YWVmOGZkYTE4MGI2ZDI5MTE4MDQ1MGJmNzU3YjExYmI1MmY3ZGYAAA==", + "type": "Bytes" + } + ], + "asset_balance_changes": null + }, + { + "id": "22304714355941377", + "paging_token": "22304714355941377", + "type": "invoke_host_function", + "created_at": "2026-10-14T14:54:52Z", + "transaction_hash": "05cb75d1586c27dff901613d6556869104ada975fa75400264853fe774eb3fa0", + "transaction_successful": true, + "source_account": "GA2CD6PMHMBTCFAQDO3R22BSZN5ZSVTAKVNOKXL2SONZBLGRAYIOWWH2", + "function": "HostFunctionTypeHostFunctionTypeCreateContractV2", + "parameters": [ + { + "value": "AAAAEgAAAAAAAAAANCH57DsDMRQQG7cdaDLLe5lWYFVa5V16k5uQrNEGEOs=", + "type": "Address" + }, + { + "value": "AAAAEgAAAAEkBCrfI6wtxoGW+IBbxJ3DdHFOg1l3e8NX1xC3rLgtbA==", + "type": "Address" + }, + { + "value": "AAAAEgAAAAFQRc1ewHKado/VrQJQWFLfTwKNzoMOWsUiCbpISDsvAQ==", + "type": "Address" + } + ], + "asset_balance_changes": null + }, + { + "id": "22304701471010817", + "paging_token": "22304701471010817", + "type": "invoke_host_function", + "created_at": "2026-10-14T14:54:37Z", + "transaction_hash": "959ad85651072af4636f7fac245ed09d052d4f6df4be6ed60d07d97efd010fc2", + "transaction_successful": true, + "source_account": "GA2CD6PMHMBTCFAQDO3R22BSZN5ZSVTAKVNOKXL2SONZBLGRAYIOWWH2", + "function": "HostFunctionTypeHostFunctionTypeUploadContractWasm", + "parameters": null, + "asset_balance_changes": null + }, + { + "id": "21927878220369921", + "paging_token": "21927878220369921", + "type": "invoke_host_function", + "created_at": "2026-10-09T13:03:17Z", + "transaction_hash": "96a744d71ecada206fd46359fe7e895dd31919c9079f1c731d6b4ccdc8a41cda", + "transaction_successful": true, + "source_account": "GA2CD6PMHMBTCFAQDO3R22BSZN5ZSVTAKVNOKXL2SONZBLGRAYIOWWH2", + "function": "HostFunctionTypeHostFunctionTypeInvokeContract", + "parameters": [ + { + "value": "AAAAEgAAAAE2Rl4+S502v5ye3ASVjGGVGJJjSoK8v1Gm5IxyQygP3g==", + "type": "Address" + }, + { + "value": "AAAADwAAAAx2ZXJpZnlfcHJvb2Y=", + "type": "Sym" + }, + { + "value": "AAAADQAAACBqZuEkZLbJpXf/ULZ1C89tHAOMdjjIIw5/Xe4yVbQYJw==", + "type": "Bytes" + }, + { + "value": "AAAADQAAAEDdiAzFcVmYfdT+U+yfcY9hOg4C17wMIV75tUAZpxkQlX5TMKjIAizRHdrQEGB1hdY2HQXgRMHt0DXTt4qZdpoc", + "type": "Bytes" + }, + { + "value": "AAAAAwAAAAE=", + "type": "U32" + } + ], + "asset_balance_changes": null + }, + { + "id": "21927216795443201", + "paging_token": "21927216795443201", + "type": "invoke_host_function", + "created_at": "2026-10-09T12:50:27Z", + "transaction_hash": "e212efd9eb6ea4db14c0d35701481468eacb645673c9d9427bbd257c862c1355", + "transaction_successful": true, + "source_account": "GA2CD6PMHMBTCFAQDO3R22BSZN5ZSVTAKVNOKXL2SONZBLGRAYIOWWH2", + "function": "HostFunctionTypeHostFunctionTypeInvokeContract", + "parameters": [ + { + "value": "AAAAEgAAAAEkBCrfI6wtxoGW+IBbxJ3DdHFOg1l3e8NX1xC3rLgtbA==", + "type": "Address" + }, + { + "value": "AAAADwAAAAx2ZXJpZnlfcHJvb2Y=", + "type": "Sym" + }, + { + "value": "AAAADQAAACDlOetgqnPWOuzBrflzw6sBOukc4hKVuKKJG8bgaKPu6g==", + "type": "Bytes" + }, + { + "value": "AAAADQAAAEBF03aNo222EG4J6s3VqBfmkfja/H2WJN1eOKn0Q8nrPRdUqQ4Zd64oUgt2VrWluhO0aukmaoMRip/7yHDaqlgD", + "type": "Bytes" + }, + { + "value": "AAAAAwAAAAE=", + "type": "U32" + } + ], + "asset_balance_changes": null + }, + { + "id": "21927191025659905", + "paging_token": "21927191025659905", + "type": "invoke_host_function", + "created_at": "2026-10-09T12:49:57Z", + "transaction_hash": "500dc3e3954c0b9be76d7d1fbbbe92132ead5109936bb1fe1a4d893a7bbac690", + "transaction_successful": true, + "source_account": "GA2CD6PMHMBTCFAQDO3R22BSZN5ZSVTAKVNOKXL2SONZBLGRAYIOWWH2", + "function": "HostFunctionTypeHostFunctionTypeInvokeContract", + "parameters": [ + { + "value": "AAAAEgAAAAEkBCrfI6wtxoGW+IBbxJ3DdHFOg1l3e8NX1xC3rLgtbA==", + "type": "Address" + }, + { + "value": "AAAADwAAAAlhZGRfZXBvY2gAAAA=", + "type": "Sym" + }, + { + "value": "AAAAEAAAAAEAAAABAAAAEQAAAAEAAAACAAAADwAAAAdhZGRyZXNzAAAAAA0AAAAUGefjdufCE7fn5+Rsxwpd0Iba/yoAAAAPAAAABGhvc3QAAAAOAAAAD2ZvcmVwYXktaXNzdWUtMgA=", + "type": "Vec" + }, + { + "value": "AAAAAwAAAAE=", + "type": "U32" + } + ], + "asset_balance_changes": null + }, + { + "id": "21927182435676161", + "paging_token": "21927182435676161", + "type": "invoke_host_function", + "created_at": "2026-10-09T12:49:47Z", + "transaction_hash": "5a29cb8fbec47335a33885236c9ced9c002186ecb395741dd8e29699de1c153e", + "transaction_successful": true, + "source_account": "GA2CD6PMHMBTCFAQDO3R22BSZN5ZSVTAKVNOKXL2SONZBLGRAYIOWWH2", + "function": "HostFunctionTypeHostFunctionTypeInvokeContract", + "parameters": [ + { + "value": "AAAAEgAAAAEkBCrfI6wtxoGW+IBbxJ3DdHFOg1l3e8NX1xC3rLgtbA==", + "type": "Address" + }, + { + "value": "AAAADwAAAAtpbnN0YW50aWF0ZQA=", + "type": "Sym" + }, + { + "value": "AAAAEgAAAAAAAAAANCH57DsDMRQQG7cdaDLLe5lWYFVa5V16k5uQrNEGEOs=", + "type": "Address" + } + ], + "asset_balance_changes": null + }, + { + "id": "21927165255798785", + "paging_token": "21927165255798785", + "type": "invoke_host_function", + "created_at": "2026-10-09T12:49:27Z", + "transaction_hash": "444b2a068842b27c43eda113d2d9a5352ddd3d026128ff86e6c1ba5fb280e26f", + "transaction_successful": true, + "source_account": "GA2CD6PMHMBTCFAQDO3R22BSZN5ZSVTAKVNOKXL2SONZBLGRAYIOWWH2", + "function": "HostFunctionTypeHostFunctionTypeCreateContract", + "parameters": null, + "asset_balance_changes": null + }, + { + "id": "21926894672809985", + "paging_token": "21926894672809985", + "type": "create_account", + "created_at": "2026-10-09T12:44:12Z", + "transaction_hash": "43595e2f4500317b25502fd607b8ecad0c3604884410266ff5262b79305e551b", + "transaction_successful": true, + "source_account": "GAIH3ULLFQ4DGSECF2AR555KZ4KNDGEKN4AFI4SU2M7B43MGK3QJZNSR" + } + ] +} \ No newline at end of file diff --git a/be/src/chain/history.test.ts b/be/src/chain/history.test.ts new file mode 100644 index 0000000..ab5b4b1 --- /dev/null +++ b/be/src/chain/history.test.ts @@ -0,0 +1,142 @@ +/** + * Forepay #16: reading a borrower's history from Horizon. The fixture is real Horizon + * output for the #10/#23 rehearsal account against the dev contract, so the parsing is + * tested against what Horizon actually returns, not what we assume it returns. + */ +import assert from "node:assert/strict"; +import { readFileSync } from "node:fs"; +import { join } from "node:path"; +import { test } from "node:test"; + +import { + advanceCalls, + fetchOperations, + ledgerTransactions, + nullifierFor, + toStroops, + type HorizonOperation, +} from "./history.js"; + +const FIXTURE = JSON.parse(readFileSync(join(import.meta.dirname, "fixtures/horizon-ops.json"), "utf8")) as { + records: HorizonOperation[]; +}; +const OPS = FIXTURE.records; +const BORROWER = "GA2CD6PMHMBTCFAQDO3R22BSZN5ZSVTAKVNOKXL2SONZBLGRAYIOWWH2"; +const DEV = "CD25Q4TDGDY6CI3LUIWUOH6SXCH6ETIUCI6FUOBI322GCJL5G3EIHQN4"; +const PRODUCTION = "CCQFL2Q66DHFAZU2KPRWNHU4FTZJW75N5XLNXECFFGMW3PROIXJPI2HS"; + +test("the nullifier is the one the contract computed on chain (#61)", () => { + // `is_spent` returns true for this value on the dev contract. + assert.equal( + nullifierFor("pub-h1792084434", "2026-07-01", "2026-09-30"), + "d0cd01df330362b23508edf7e386950549da634b756d1c29aa242cfc9c88c839", + ); +}); + +test("length prefixes keep field boundaries: moving a character between fields changes it", () => { + assert.notEqual(nullifierFor("pub-1", "2026-07-01", "2026-09-30"), nullifierFor("pub-12", "026-07-01", "2026-09-30")); +}); + +test("Horizon amounts become stroops exactly", () => { + assert.equal(toStroops("1.0000000"), 10_000_000n); + assert.equal(toStroops("0.75"), 7_500_000n); + assert.equal(toStroops("922337203685.4775807"), 9_223_372_036_854_775_807n); + assert.throws(() => toStroops("1.00000001"), /not a Horizon amount/); + assert.throws(() => toStroops("-1"), /not a Horizon amount/); +}); + +test("request_advance calls are read with their arguments, nullifier and the USDC received", () => { + const calls = advanceCalls(OPS, BORROWER, DEV); + assert.ok(calls.length >= 3); + const c = calls.find((x) => x.hash === "9a94cf083543b58d79b60431de305f3912099ca9337ada4793ef1e38546f8ad0"); + assert.deepEqual(c, { + hash: "9a94cf083543b58d79b60431de305f3912099ca9337ada4793ef1e38546f8ad0", + at: 1792084442n, + successful: true, + nullifier: "d0cd01df330362b23508edf7e386950549da634b756d1c29aa242cfc9c88c839", + borrower: BORROWER, + pubId: "pub-h1792084434", + windowStart: "2026-07-01", + windowEnd: "2026-09-30", + disbursed: 10_000_000n, + }); +}); + +test("calls to another contract are not this contract's history", () => { + assert.deepEqual(advanceCalls(OPS, BORROWER, PRODUCTION), []); + assert.deepEqual( + ledgerTransactions(OPS, BORROWER, PRODUCTION).map((t) => t.kind), + ["trustline"], + ); +}); + +test("transactions: advances, repayments and the trustline, newest first, nothing else", () => { + const txs = ledgerTransactions(OPS, BORROWER, DEV); + const kinds = new Set(txs.map((t) => t.kind)); + assert.deepEqual([...kinds].sort(), ["advance", "repayment", "trustline"]); + for (let i = 1; i < txs.length; i++) assert.ok(txs[i - 1].at >= txs[i].at, "newest first"); + + const repay = txs.find((t) => t.hash === "886194f0c74f16719dd096f2b3cda8f6c78af265392a473b5d55aea0d951ed66"); + assert.deepEqual(repay, { + hash: "886194f0c74f16719dd096f2b3cda8f6c78af265392a473b5d55aea0d951ed66", + kind: "repayment", + amount: 7_500_000n, + at: 1792262032n, + status: "completed", + nullifier: "1d124817f351c4a88ed2fe92a2f79812f2bfa41e0610a5bbb84f7a5e892e68f5", + }); + + const trust = txs.filter((t) => t.kind === "trustline"); + assert.equal(trust.length, 1); + assert.equal(trust[0].nullifier, ""); + assert.equal(trust[0].amount, 0n); +}); + +test("a transaction that failed on the ledger is listed as failed, with nothing moved for an advance", () => { + const byHash = (h: string) => { + const op = OPS.find((o) => o.transaction_hash === h); + assert.ok(op, h); + return op; + }; + const repay = byHash("886194f0c74f16719dd096f2b3cda8f6c78af265392a473b5d55aea0d951ed66"); + const advance = byHash("9a94cf083543b58d79b60431de305f3912099ca9337ada4793ef1e38546f8ad0"); + const failed = [ + { ...repay, transaction_hash: "f1".repeat(32), transaction_successful: false, asset_balance_changes: [] }, + { ...advance, transaction_hash: "f2".repeat(32), transaction_successful: false, asset_balance_changes: [] }, + ]; + const txs = ledgerTransactions(failed, BORROWER, DEV); + assert.deepEqual( + txs.map((t) => [t.kind, t.status, t.amount]), + [ + ["repayment", "failed", 7_500_000n], // what was attempted; no USDC moved + ["advance", "failed", 0n], + ], + ); + assert.equal(advanceCalls(failed, BORROWER, DEV)[0].successful, false); +}); + +test("another account's calls are not listed for this borrower", () => { + const other = "GAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAWHF"; + assert.deepEqual(advanceCalls(OPS, other, DEV), []); + assert.deepEqual(ledgerTransactions(OPS, other, DEV), []); +}); + +test("fetchOperations pages through Horizon, and an unknown account has no history", async () => { + const page = (n: number, next?: string) => + new Response(JSON.stringify({ _embedded: { records: Array.from({ length: n }, (_, i) => ({ id: String(i) })) }, _links: { next: next ? { href: next } : undefined } })); + const urls: string[] = []; + const fake = (async (url: string) => { + urls.push(url); + return urls.length === 1 ? page(200, "https://h.example/next") : page(3); + }) as unknown as typeof fetch; + const ops = await fetchOperations(BORROWER, { horizonUrl: "https://h.example/", fetch: fake }); + assert.equal(ops.length, 203); + assert.equal(urls[0], `https://h.example/accounts/${BORROWER}/operations?order=desc&limit=200&include_failed=true&join=transactions`); + assert.equal(urls[1], "https://h.example/next"); + + const missing = (async () => new Response("{}", { status: 404 })) as unknown as typeof fetch; + assert.deepEqual(await fetchOperations(BORROWER, { horizonUrl: "https://h.example", fetch: missing }), []); + + const down = (async () => new Response("{}", { status: 503 })) as unknown as typeof fetch; + await assert.rejects(fetchOperations(BORROWER, { horizonUrl: "https://h.example", fetch: down }), /Horizon answered 503/); +}); diff --git a/be/src/chain/history.ts b/be/src/chain/history.ts new file mode 100644 index 0000000..1e8e65b --- /dev/null +++ b/be/src/chain/history.ts @@ -0,0 +1,217 @@ +/** + * A borrower's history with the advance contract, read from Horizon (#16). + * + * Why Horizon and not the RPC: the contract keeps no index by borrower, and the RPC's + * `getEvents` only reaches back about a week, which an advance taken on day 1 of a + * 30-day grant outlives. Horizon keeps every operation an account submitted, including + * the ones that failed on the ledger, with the contract call's arguments and the USDC + * that moved. That is the whole of what /advances and /transactions need. + * + * What it cannot see: a transaction that never reached a ledger (refused by the wallet, + * by simulation, or by the network). Nothing was charged for those and nothing about + * them is on chain, so they are not listed. + * + * The borrower signs `request_advance` and `repay` from their own wallet, so they are + * the operation's source and the call appears on their account. A call submitted on a + * borrower's behalf by another account would not; nothing in Forepay does that. + */ +import { createHash } from "node:crypto"; + +import { scValToNative, xdr } from "@stellar/stellar-sdk"; + +import { USDC_ASSET } from "../network.js"; + +/** The fields of a Horizon operation record (joined with its transaction) read here. */ +export interface HorizonOperation { + id: string; + paging_token: string; + type: string; + created_at: string; + transaction_hash: string; + transaction_successful: boolean; + source_account: string; + // invoke_host_function + function?: string; + parameters?: { type: string; value: string }[]; + asset_balance_changes?: { type: string; asset_code?: string; asset_issuer?: string; from?: string; to?: string; amount: string }[]; + // change_trust + asset_code?: string; + asset_issuer?: string; + limit?: string; +} + +export type TransactionKind = "advance" | "repayment" | "trustline"; + +/** One line of the front end's transaction list. Amounts in stroops, times in seconds. */ +export interface LedgerTransaction { + hash: string; + kind: TransactionKind; + /** Always positive; the kind says which way it moved. 0 when nothing moved. */ + amount: bigint; + at: bigint; + /** + * `failed`: the transaction reached the ledger and failed. The network fee (XLM) was + * spent; no USDC moved. + */ + status: "completed" | "failed"; + /** 32 bytes as hex; empty for a trustline. */ + nullifier: string; +} + +/** A `request_advance` the borrower submitted, before the contract's record is read. */ +export interface AdvanceCall { + hash: string; + at: bigint; + successful: boolean; + nullifier: string; + borrower: string; + pubId: string; + windowStart: string; + windowEnd: string; + /** USDC received, in stroops; 0 when it failed. */ + disbursed: bigint; +} + +/** + * `sha256(len ‖ pub_id ‖ len ‖ window_start ‖ len ‖ window_end)`, each length a 4-byte + * big-endian u32. The same derivation as `claim::nullifier_of` in sc/advance. + */ +export function nullifierFor(pubId: string, windowStart: string, windowEnd: string): string { + const parts: Buffer[] = []; + for (const field of [pubId, windowStart, windowEnd]) { + const bytes = Buffer.from(field, "utf8"); + const len = Buffer.alloc(4); + len.writeUInt32BE(bytes.length); + parts.push(len, bytes); + } + return createHash("sha256").update(Buffer.concat(parts)).digest("hex"); +} + +/** `"12.3400000"` (7 decimals, as Horizon writes amounts) to stroops. */ +export function toStroops(amount: string): bigint { + const m = /^(\d+)(?:\.(\d{1,7}))?$/.exec(amount); + if (!m) throw new Error(`not a Horizon amount: ${amount}`); + return BigInt(m[1]) * 10_000_000n + BigInt((m[2] ?? "").padEnd(7, "0")); +} + +function seconds(iso: string): bigint { + return BigInt(Math.floor(Date.parse(iso) / 1000)); +} + +function isUsdc(code?: string, issuer?: string): boolean { + return code === USDC_ASSET.code && issuer === USDC_ASSET.issuer; +} + +/** The contract, function and arguments of an `invoke_host_function` that calls `contract`. */ +function contractCall(op: HorizonOperation, contract: string): { fn: string; args: unknown[] } | null { + if (op.type !== "invoke_host_function" || !op.function?.endsWith("InvokeContract")) return null; + const params = op.parameters ?? []; + if (params.length < 2) return null; + const native = params.map((p) => scValToNative(xdr.ScVal.fromXDR(p.value, "base64"))); + if (native[0] !== contract) return null; + return { fn: String(native[1]), args: native.slice(2) }; +} + +/** USDC that moved between `a` and `b`, in either direction, in stroops. */ +function usdcMoved(op: HorizonOperation, a: string, b: string): bigint { + let total = 0n; + for (const c of op.asset_balance_changes ?? []) { + if (c.type !== "transfer" || !isUsdc(c.asset_code, c.asset_issuer)) continue; + if ((c.from === a && c.to === b) || (c.from === b && c.to === a)) total += toStroops(c.amount); + } + return total; +} + +function hex(v: unknown): string { + return Buffer.isBuffer(v) || v instanceof Uint8Array ? Buffer.from(v).toString("hex") : ""; +} + +/** The borrower's `request_advance` calls to `contract`, in the order given. */ +export function advanceCalls(ops: HorizonOperation[], borrower: string, contract: string): AdvanceCall[] { + const out: AdvanceCall[] = []; + for (const op of ops) { + const call = contractCall(op, contract); + if (!call || call.fn !== "request_advance") continue; + const [callBorrower, , pubId, windowStart, windowEnd] = call.args as string[]; + if (callBorrower !== borrower) continue; + out.push({ + hash: op.transaction_hash, + at: seconds(op.created_at), + successful: op.transaction_successful, + nullifier: nullifierFor(pubId, windowStart, windowEnd), + borrower: callBorrower, + pubId, + windowStart, + windowEnd, + disbursed: op.transaction_successful ? usdcMoved(op, contract, borrower) : 0n, + }); + } + return out; +} + +/** Advances, repayments and the USDC trustline, newest first. */ +export function ledgerTransactions(ops: HorizonOperation[], borrower: string, contract: string): LedgerTransaction[] { + const out: LedgerTransaction[] = []; + for (const op of ops) { + const status = op.transaction_successful ? "completed" : "failed"; + const at = seconds(op.created_at); + + if (op.type === "change_trust") { + // Only the trustline being opened: a limit of 0 removes it, which the app never does. + if (op.source_account !== borrower || !isUsdc(op.asset_code, op.asset_issuer) || Number(op.limit) === 0) continue; + out.push({ hash: op.transaction_hash, kind: "trustline", amount: 0n, at, status, nullifier: "" }); + continue; + } + + const call = contractCall(op, contract); + if (!call) continue; + if (call.fn === "request_advance") { + const [callBorrower, , pubId, windowStart, windowEnd] = call.args as string[]; + if (callBorrower !== borrower) continue; + out.push({ + hash: op.transaction_hash, + kind: "advance", + amount: op.transaction_successful ? usdcMoved(op, contract, borrower) : 0n, + at, + status, + nullifier: nullifierFor(pubId, windowStart, windowEnd), + }); + } else if (call.fn === "repay") { + const [from, nullifier, amount] = call.args as [string, Buffer, bigint]; + if (from !== borrower) continue; + out.push({ hash: op.transaction_hash, kind: "repayment", amount: BigInt(amount), at, status, nullifier: hex(nullifier) }); + } + } + return out.sort((x, y) => (x.at === y.at ? 0 : x.at > y.at ? -1 : 1)); +} + +export interface HorizonDeps { + horizonUrl: string; + fetch?: typeof fetch; + /** Pages of 200 operations; 5 covers 1,000, far beyond a demo account. */ + maxPages?: number; + timeoutMs?: number; +} + +/** + * Every operation `account` submitted, failed ones included, newest first. An account + * that does not exist yet has no history: `[]`, not an error. + */ +export async function fetchOperations(account: string, deps: HorizonDeps): Promise { + const get = deps.fetch ?? fetch; + const maxPages = deps.maxPages ?? 5; + const base = deps.horizonUrl.replace(/\/+$/, ""); + let url: string | undefined = + `${base}/accounts/${account}/operations?order=desc&limit=200&include_failed=true&join=transactions`; + const ops: HorizonOperation[] = []; + for (let page = 0; url && page < maxPages; page++) { + const res = await get(url, { headers: { accept: "application/json" }, signal: AbortSignal.timeout(deps.timeoutMs ?? 10_000) }); + if (res.status === 404) return []; + if (!res.ok) throw new Error(`Horizon answered ${res.status} for ${account}'s operations`); + const body = (await res.json()) as { _embedded: { records: HorizonOperation[] }; _links?: { next?: { href: string } } }; + const records = body._embedded.records; + ops.push(...records); + url = records.length === 200 ? body._links?.next?.href : undefined; + } + return ops; +} diff --git a/be/src/network.test.ts b/be/src/network.test.ts index 9242f67..559aefc 100644 --- a/be/src/network.test.ts +++ b/be/src/network.test.ts @@ -7,7 +7,9 @@ import { readFileSync } from "node:fs"; import { join } from "node:path"; import { test } from "node:test"; -import { RECORDED } from "./network.js"; +import { Asset } from "@stellar/stellar-sdk"; + +import { RECORDED, USDC_ASSET } from "./network.js"; const DOC = readFileSync(join(import.meta.dirname, "../../docs/deployments.md"), "utf8"); @@ -28,3 +30,8 @@ test("every recorded contract also appears in the human-readable part of the doc assert.ok(prose.includes(address), `${name} ${address} is recorded but never explained in the doc`); } }); + +test("USDC_ASSET is the classic asset behind the recorded USDC SAC", () => { + const sac = new Asset(USDC_ASSET.code, USDC_ASSET.issuer).contractId(RECORDED.networkPassphrase); + assert.equal(sac, RECORDED.contracts.usdcSac); +}); diff --git a/be/src/network.ts b/be/src/network.ts index 2dd167f..389abdc 100644 --- a/be/src/network.ts +++ b/be/src/network.ts @@ -11,14 +11,26 @@ export const RECORDED = { network: "testnet", networkPassphrase: "Test SDF Network ; September 2015", rpcUrl: "https://soroban-testnet.stellar.org", + /** History (operations, failed transactions, balance changes) that the RPC does not keep. */ + horizonUrl: "https://horizon-testnet.stellar.org", contracts: { /** Reclaim's own verifier; its epoch holds the production attestor (#2). */ reclaimVerifier: "CA3EMXR6JOOTNP44T3OAJFMMMGKRRETDJKBLZP2RU3SIY4SDFAH54DU5", /** Circle's testnet USDC as a Stellar Asset Contract, 7 decimals. */ usdcSac: "CBIELTK6YBZJU5UP2WWQEUCYKLPU6AUNZ2BQ4WWFEIE3USCIHMXQDAMA", - /** The Forepay advance contract. Null until #15 deploys it. */ - advance: null as string | null, + /** The Forepay advance contract, deployed from the release by #15. */ + advance: "CCQFL2Q66DHFAZU2KPRWNHU4FTZJW75N5XLNXECFFGMW3PROIXJPI2HS" as string | null, }, } as const; +/** + * The classic asset behind `usdcSac`: Circle's testnet USDC. Horizon reports balance changes + * and trustlines by asset code and issuer, not by contract. network.test.ts checks that this + * asset's SAC address is exactly `usdcSac`. + */ +export const USDC_ASSET = { + code: "USDC", + issuer: "GBBD47IF6LWK7P7MDEVSCWR7DPUWV3NY3DTQEVFL4NAT4AQH3ZLLFLA5", +} as const; + export type ContractName = keyof typeof RECORDED.contracts; diff --git a/docs/api.md b/docs/api.md new file mode 100644 index 0000000..262e6ee --- /dev/null +++ b/docs/api.md @@ -0,0 +1,88 @@ +# Forepay API (#16) + +What the front end reads. Run it with `pnpm -C be start` (port 8787 by default). Configuration is in +`be/.env.example`. + +Every route is `GET` and returns JSON. + +- **Amounts** are stroops: USDC has 7 decimals, so `10000000` = 1 USDC. +- **Times** are seconds since the epoch. +- Both are sent as **decimal strings**. JSON numbers lose precision past 2^53, and an `i128` can exceed + that. + +| Route | Answers | +| --- | --- | +| `/health` | `{"status":"ok"}`. The process is up. | +| `/ready` | `200` when the Stellar RPC answers, `503` when it does not. | +| `/config` | The network, RPC, Horizon and contract addresses in use, where each came from, and whether they match `docs/deployments.md`. | +| `/advances?borrower=G…` | Every advance the wallet took, newest first. | +| `/transactions?borrower=G…` | Advances, repayments and the USDC trustline, newest first. Failed transactions are included. | + +## Errors + +| Status | Body | When | +| --- | --- | --- | +| `400` | `{"error":"borrower must be a Stellar account address (G…)"}` | `borrower` is missing, or is not a `G…` address | +| `502` | `{"error":"the chain could not be read; try again"}` | Horizon or the RPC failed. Safe to retry. | +| `503` | `{"error":"no advance contract is configured"}` | Deployment misconfiguration | + +## `/advances` + +```json +[{ + "nullifier": "1d1248…68f5", + "borrower": "GA2C…WWH2", + "windowStart": "2026-07-01", + "windowEnd": "2026-09-30", + "revenueCents": "400", + "principal": "10000000", + "repaid": "10000000", + "openedAt": "1792262007", + "txHash": "1e0662…0f25" +}] +``` + +- Every figure comes from the **contract's own record**, read with `advance(nullifier)`. The API does not + rebuild it from history, so the balance shown is always the balance the contract holds. +- `nullifier` is what `repay(from, nullifier, amount)` takes. It is + `sha256(len ‖ pub_id ‖ len ‖ window_start ‖ len ‖ window_end)`, where each length is a 4-byte big-endian + u32. That is the same derivation as the contract's `nullifier_for`. +- `txHash` is the disbursement transaction. +- Outstanding is `principal − repaid`. + +## `/transactions` + +```json +[{ "hash": "8861…ed66", "kind": "repayment", "amount": "7500000", "at": "1792262032", + "status": "completed", "nullifier": "1d1248…68f5" }] +``` + +`kind` is one of the following: + +- `advance`: `amount` is the USDC received. +- `repayment`: `amount` is the USDC the repayment asked to send. +- `trustline`: the wallet allowing USDC. `amount` is `"0"` and `nullifier` is `""`. + +**`status: "failed"`** means the transaction **reached the ledger and failed**. + +- The network fee (a fraction of an XLM) was spent. +- **No USDC moved.** For a failed repayment, `amount` is what was attempted. For a failed advance, it is + `"0"`. + +A transaction that never reached a ledger is **not listed**: refused in the wallet, refused at simulation, +or dropped by the network. Nothing was charged and nothing about it is on chain. If the front end wants to +show those, it has to keep them itself. + +## Where the data comes from + +The routes read two sources: + +- **Horizon**, for the account's operations. It keeps the full history, failed transactions included, + with each contract call's arguments and the USDC that moved. +- **The RPC**, for the contract's current record of each advance. + +The RPC's `getEvents` is not used, because it only reaches back about a week, and an advance taken early +in the grant outlives that. + +A call counts as the borrower's only when the borrower's own wallet submitted it. That is how the front +end submits every call. diff --git a/docs/deployments.md b/docs/deployments.md index 74c9ef6..05ed190 100644 --- a/docs/deployments.md +++ b/docs/deployments.md @@ -17,10 +17,11 @@ deploys it. "network": "testnet", "networkPassphrase": "Test SDF Network ; September 2015", "rpcUrl": "https://soroban-testnet.stellar.org", + "horizonUrl": "https://horizon-testnet.stellar.org", "contracts": { "reclaimVerifier": "CA3EMXR6JOOTNP44T3OAJFMMMGKRRETDJKBLZP2RU3SIY4SDFAH54DU5", "usdcSac": "CBIELTK6YBZJU5UP2WWQEUCYKLPU6AUNZ2BQ4WWFEIE3USCIHMXQDAMA", - "advance": null + "advance": "CCQFL2Q66DHFAZU2KPRWNHU4FTZJW75N5XLNXECFFGMW3PROIXJPI2HS" } } ```