Skip to content

Open-source platform for 3D AI agents. Turn text or a photo into a rigged, animated GLB avatar, give it an LLM brain, memory and a wallet, and embed it anywhere with one web component. Remote MCP server, x402 payments, Three.js, browser-native.

fix(royalties): record the settlement chain so a payout links to the right explorer

nirholasa0d25e43cfc2
diff --git a/api/_lib/royalty.js b/api/_lib/royalty.js
index 86302811d..d7917cfee 100644
--- a/api/_lib/royalty.js
+++ b/api/_lib/royalty.js
@@ -137,9 +137,15 @@ export async function settleRoyalties(authorUserId) {
try {
const txHash = await _redeemForGroup({ ...group, total_usd: claimedTotal, ledger_ids: claimedIds }, authorUserId);
+ // Record the chain alongside the transaction. Without it a settled row
+ // carries a hash with no way to tell which explorer resolves it, and any
+ // consumer linking the tx has to guess (and would guess Solana, the
+ // platform default, for what is always an EVM redeem). CAIP-2, matching
+ // what the x402 rail writes, so both lanes read identically.
+ const network = `eip155:${group.chain_id}`;
await sql`
UPDATE royalty_ledger
- SET status = 'settled', settled_at = now(), tx_hash = ${txHash}
+ SET status = 'settled', settled_at = now(), tx_hash = ${txHash}, network = ${network}
WHERE id = ANY(${claimedIds}::uuid[])
`;
} catch (e) {
diff --git a/specs/SKILL_ROYALTY_SPLIT.md b/specs/SKILL_ROYALTY_SPLIT.md
index 959c6eb10..7f7b82ec2 100644
--- a/specs/SKILL_ROYALTY_SPLIT.md
+++ b/specs/SKILL_ROYALTY_SPLIT.md
@@ -66,6 +66,7 @@ One settled call produces at most one `royalty_ledger` row.
| SR-16 | Rows are claimed atomically (`pending → settling`, conditional on still being `pending`) before any redeem. A concurrent pass claiming the same rows gets an empty set, so an on-chain payout runs at most once per row. |
| SR-17 | A claim that lands below the dust threshold is released back to `pending` rather than paid, so a race can never trigger a payout whose gas exceeds its value. |
| SR-18 | A failed redeem marks its claimed rows `failed`, never silently back to `pending`. A failure is visible state, not a retry loop. |
+| SR-21 | A row settled by the redeem leg records its chain (`network`, CAIP-2) in the same write as its `tx_hash`. A hash with no chain cannot be resolved to an explorer, and a consumer forced to guess would guess the platform default (Solana) for what is always an EVM redeem. |
## Reporting
@@ -79,7 +80,7 @@ One settled call produces at most one `royalty_ledger` row.
Each invariant is covered by at least one positive and one negative test. The
suites that prove them:
-- [`tests/skill-royalty.test.js`](../tests/skill-royalty.test.js): the split math (SR-1 … SR-5) and the flag gate (SR-15).
+- [`tests/skill-royalty.test.js`](../tests/skill-royalty.test.js): the split math (SR-1 … SR-5), the accrual writer (SR-10 … SR-13), the flag gate (SR-15), and the claim semantics that make a double payout impossible (SR-16 … SR-18, SR-21).
- [`tests/skill-royalty-earnings.test.js`](../tests/skill-royalty-earnings.test.js): the read side, including the LEFT JOIN regression guard (SR-14) and separated totals (SR-19).
- [`scripts/royalty-proof.mjs`](../scripts/royalty-proof.mjs): an end-to-end proof against a real Postgres, asserting SR-1, SR-4, SR-11, SR-12, SR-13, SR-14 and SR-20 in one run, moving no funds.
diff --git a/src/dashboard-next/pages/creator.js b/src/dashboard-next/pages/creator.js
index 1916ae19d..d5cde3cdc 100644
--- a/src/dashboard-next/pages/creator.js
+++ b/src/dashboard-next/pages/creator.js
@@ -926,7 +926,10 @@ function ledgerRow(e) {
// straight to the explorer: the author can verify their own payout on-chain
// instead of trusting this table. Rows with no tx (in-app calls awaiting the
// redeem leg) render the plain amount.
- const txUrl = e.tx_hash ? revenueTxUrl(e.tx_hash, e.network) : null;
+ // Both a transaction AND its chain are required: revenueTxUrl falls back to
+ // the platform default chain for an unknown network, so linking a tx whose
+ // chain we do not know would point an EVM settlement at a Solana explorer.
+ const txUrl = e.tx_hash && e.network ? revenueTxUrl(e.tx_hash, e.network) : null;
const amount = usd(Number(e.price_usd || 0));
const amountCell = txUrl
? `<a href="${esc(txUrl)}" target="_blank" rel="noopener" title="View this settlement on the explorer">${amount}</a>`
diff --git a/tests/skill-royalty.test.js b/tests/skill-royalty.test.js
index 68c8400ad..1a9ca6d62 100644
--- a/tests/skill-royalty.test.js
+++ b/tests/skill-royalty.test.js
@@ -213,10 +213,15 @@ describe('settleRoyalties claim semantics (no double-pay)', () => {
process.env.SKILL_ROYALTIES_EVM_7710_ENABLED = 'true';
});
+ const realFetch = globalThis.fetch;
+
afterEach(() => {
delete process.env.SKILL_ROYALTIES_EVM_7710_ENABLED;
sqlMock.mockReset();
sqlMock.mockResolvedValue([{ id: 'ledger-1' }]);
+ // One case stubs the relayer call; never leave that stub in place for the
+ // next test, which must reach its own failure path for real.
+ globalThis.fetch = realFetch;
});
it('claims pending rows before redeeming, conditional on still being pending', async () => {
@@ -247,6 +252,28 @@ describe('settleRoyalties claim semantics (no double-pay)', () => {
expect(texts.some((t) => /SET status = 'settled'/i.test(t))).toBe(false);
});
+ it('records the settlement chain next to the transaction hash', async () => {
+ respondWith({ claimed: [{ id: 'ledger-a', price_usd: 1.5 }] });
+ // Give the redeem a wallet to pay so it reaches the settled UPDATE.
+ sqlMock.mockImplementation(async (strings) => {
+ const text = Array.isArray(strings) ? strings.join('?') : String(strings);
+ if (/SELECT[\s\S]*FROM royalty_ledger rl/i.test(text)) return [GROUP];
+ if (/SET status = 'settling'/i.test(text)) return [{ id: 'ledger-a', price_usd: 1.5 }];
+ if (/FROM user_wallets/i.test(text)) return [{ address: '0x2222222222222222222222222222222222222222' }];
+ if (/FROM agent_delegations/i.test(text)) return [{ id: 'del-1', delegation_json: {}, scope: {} }];
+ return [];
+ });
+ globalThis.fetch = vi.fn(async () => ({ ok: true, json: async () => ({ tx_hash: '0xdeadbeef' }) }));
+
+ await settleRoyalties(AUTHOR);
+
+ const settle = sqlMock.mock.calls.find((c) => /SET status = 'settled'/i.test(c[0].join('?')));
+ expect(settle).toBeDefined();
+ // A hash with no chain cannot be resolved to an explorer by any consumer.
+ expect(settle[0].join('?')).toMatch(/network =/i);
+ expect(settle.slice(1)).toContain(`eip155:${GROUP.chain_id}`);
+ });
+
it('marks a group failed when the redeem cannot complete', async () => {
respondWith({ claimed: [{ id: 'ledger-a', price_usd: 1.5 }] });
// No author payout wallet: _redeemForGroup throws before any relayer call.