emj
shrx

Reference · Factory detection

Transaction output layout

Fixed output indices used by simplicity-lending and mirrored in lwk-dart PRs #13/#15. Indices are 0-based.

IssuanceFactory creation

OutputContent
0Auth NFT (1 unit, wallet address)
1Factory program UTXO (1 unit, covenant)
2OP_RETURN — 13-byte creation metadata (program id, issuing_utxos_count, reissuance_flags)

Lending offer creation (full tx)

Factory issuance outputs come first (auth NFT, factory, borrower NFT, lender NFT, protocol NFT…). Then attach_creation appends:

OutputContent
0–1Factory + auth (from issuance step)
2Borrower NFT (1 unit)
3Lender NFT (locked via ScriptAuth)
4Protocol fee keeper NFT (when present)
4 or 5OP_RETURN — 50-byte offer metadata (upstream: index 4)
5Pending offer — collateral locked in LendingOffer covenant (upstream: index 5)

50-byte offer metadata (OP_RETURN)

BytesField
0–3Program id (first 4 bytes of SHA256 of source)
4–35Principal asset id (32 bytes)
36–43Principal amount (u64 LE)
44–47Loan expiration block height (u32 LE)
48–49Interest rate basis points (u16 LE)

Collateral amount comes from the pending offer output value, not the metadata blob.

Indexer parsing

LendingOffer::try_from_tx reads outputs 2, 3, 5 and metadata at 4. Wrong indices → offers invisible to indexer even if tx confirms on-chain.