$yieldfabric-ai>

Complete Workflows

End-to-end examples demonstrating real-world use cases

01

Annuity Settlement Workflow

This example demonstrates how to create and settle an annuity using self-referential obligations and atomic swaps.

Overview

An issuer creates future payment obligations and atomically swaps them for immediate liquidity:

Issuer

  • Creates 105 AUD in future obligations
  • Receives 100 AUD immediately

Counterparty

  • Pays 100 AUD upfront
  • Receives 105 AUD over time (5% yield)

Step 1: Create Annuity Stream Obligation

Issuer creates obligation with themselves as both obligor AND counterpart to build structure without counterparty risk:

curl -X POST https://pay.yieldfabric.com/graphql \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "query": "mutation($initialPayments: InitialPaymentsInput, $data: JSON) { createObligation(input: { counterpart: \"issuer@yieldfabric.com\", denomination: \"aud-token-asset\", obligor: \"issuer@yieldfabric.com\", notional: \"5\", expiry: \"2025-11-01\", data: $data, initialPayments: $initialPayments }) { success contractId } }",
    "variables": {
      "data": { "name": "Annuity Stream", "description": "5-day annuity" },
      "initialPayments": {
        "amount": "5",
        "payments": [
          { "unlockSender": "2025-11-01T00:00:00+00:00", "unlockReceiver": "2025-11-01T00:00:00+00:00" },
          { "unlockSender": "2025-11-02T00:00:00+00:00", "unlockReceiver": "2025-11-02T00:00:00+00:00" },
          { "unlockSender": "2025-11-03T00:00:00+00:00", "unlockReceiver": "2025-11-03T00:00:00+00:00" },
          { "unlockSender": "2025-11-04T00:00:00+00:00", "unlockReceiver": "2025-11-04T00:00:00+00:00" },
          { "unlockSender": "2025-11-05T00:00:00+00:00", "unlockReceiver": "2025-11-05T00:00:00+00:00" }
        ]
      }
    }
  }'

# Save: export ANNUITY_CONTRACT_ID="CONTRACT-OBLIGATION-..."

Step 2: Accept the Annuity

curl -X POST https://pay.yieldfabric.com/graphql \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "query": "mutation { acceptObligation(input: { contractId: \"'$ANNUITY_CONTRACT_ID'\" }) { success } }"
  }'

Step 3: Create Redemption Obligation

Create a single payment obligation for 100 AUD:

curl -X POST https://pay.yieldfabric.com/graphql \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "query": "mutation($initialPayments: InitialPaymentsInput, $data: JSON) { createObligation(input: { counterpart: \"issuer@yieldfabric.com\", denomination: \"aud-token-asset\", obligor: \"issuer@yieldfabric.com\", notional: \"100\", expiry: \"2025-11-01\", data: $data, initialPayments: $initialPayments }) { success contractId } }",
    "variables": {
      "data": { "name": "Redemption", "description": "Single payment" },
      "initialPayments": {
        "amount": "100",
        "payments": [
          { "unlockSender": "2025-11-06T00:00:00+00:00", "unlockReceiver": "2025-11-06T00:00:00+00:00" }
        ]
      }
    }
  }'

# Save: export REDEMPTION_CONTRACT_ID="CONTRACT-OBLIGATION-..."

Step 4: Accept Redemption

curl -X POST https://pay.yieldfabric.com/graphql \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "query": "mutation { acceptObligation(input: { contractId: \"'$REDEMPTION_CONTRACT_ID'\" }) { success } }"
  }'

Step 5: Create Atomic Swap

Exchange both obligations for 100 AUD upfront payment:

curl -X POST https://pay.yieldfabric.com/graphql \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "query": "mutation($counterpartyExpectedPayments: InitialPaymentsInput) { createSwap(input: { swapId: \"123456789\", counterparty: \"counterpart@yieldfabric.com\", deadline: \"2025-11-10\", initiatorObligationIds: [\"'$ANNUITY_CONTRACT_ID'\", \"'$REDEMPTION_CONTRACT_ID'\"], counterpartyExpectedPayments: $counterpartyExpectedPayments }) { success swapId } }",
    "variables": {
      "counterpartyExpectedPayments": {
        "denomination": "aud-token-asset",
        "amount": "100",
        "payments": [
          { "unlockSender": null, "unlockReceiver": null }
        ]
      }
    }
  }'

Step 6: Counterpart Completes Swap

Counterpart pays 100 AUD and receives obligation rights:

curl -X POST https://pay.yieldfabric.com/graphql \
  -H "Authorization: Bearer $COUNTERPART_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "query": "mutation { completeSwap(input: { swapId: \"123456789\" }) { success message } }"
  }'

✓ Workflow Complete

The swap is now complete with atomic settlement:

  • Issuer received 100 AUD immediately (liquidity)
  • Counterpart owns rights to 105 AUD payments (5% yield)
  • Both transfers happened simultaneously (atomic)
  • All recorded on-chain with full audit trail
02

Other Common Workflows

Simple Invoice Payment

  1. 1Seller creates obligation with buyer as counterparty
  2. 2Buyer accepts obligation
  3. 3Payment unlocks on due date
  4. 4Buyer executes payment
  5. 5Seller receives funds

Loan Repayment Schedule

  1. 1Borrower creates repayment obligation (self-referential)
  2. 2Borrower accepts obligation
  3. 3Lender provides loan via instant payment
  4. 4Borrower's repayments unlock on schedule
  5. 5Lender receives repayments over time

Escrow Transaction

  1. 1Buyer creates fully-funded obligation
  2. 2Funds locked with oracle conditions (e.g., "goods delivered")
  3. 3Seller ships goods
  4. 4Oracle confirms delivery
  5. 5Payment releases to seller