For the complete documentation index, see llms.txt. This page is also available as Markdown.

Swaps

Everything needed to place a swap.

Get a token's allocation factory context

get
/allocation-factory/{token}

Returns the registry's allocation-factory contract for a token and the choice context for exercising AllocationFactory_Allocate on it. Cached, refreshed every 24 hours. CC/Amulet is not served. Read it from the Splice Scan API per submission.

Path parameters
tokenstringRequired

The name/symbol of the token (URL encoded).

Example: USDCx
Responses
200

Allocation factory context

application/json

The registry's allocation-factory contract and the context for exercising it.

factoryIdstringRequired

Contract ID to exercise AllocationFactory_Allocate on

cachedAtstring · date-timeRequired

When this context was last fetched from the registry

Example: 2026-01-20T14:35:00Z
get/allocation-factory/{token}
GET /v1/allocation-factory/{token} HTTP/1.1
Host: api.tradecraft.fi
Accept: */*
{
  "factoryId": "text",
  "choiceContext": {
    "disclosedContracts": [
      {
        "templateId": "text",
        "contractId": "text",
        "createdEventBlob": "Ynl0ZXM=",
        "synchronizerId": "text"
      }
    ],
    "choiceContextData": {}
  },
  "cachedAt": "2026-01-20T14:35:00Z"
}

Get everything needed to place one swap

get
/swap-ticket

To swap by transfer:

  1. Send a token-standard transfer of amount_in of in.instrument_id to pool_party.

  2. Copy min_out into the transfer metadata under the key memo_key.

The ledger refunds the transfer instead of filling it below min_out. A transfer without the memo key swaps with no floor.

To swap directly, submit against amm_cid with the contracts in disclosures and min_out as the floor. memo_key does not apply.

amm_cid, the quote and disclosures come from one read, so they always agree. All three change when the pool settles a batch, so request a new ticket if the swap is delayed.

pool_party comes from the pool identity. The endpoint returns it even if no magic-address watcher runs for the pair.

disclosures carries the pool's contracts only. A CC transfer also needs AmuletRules and a current OpenMiningRound. Read those from the Splice Scan API per submission.

Where enabled, a ticket costs an x402 v2 payment, settled through FTP Tech's facilitator. The facilitator serves MainNet only, so DevNet and TestNet do not charge. A request without a payment gets a 402 whose PAYMENT-REQUIRED header lists the accepted prices, one entry per token in accepts (see X402PaymentRequired).

To pay:

  1. Pick one entry of accepts.

  2. As an external party, sign a token-standard TransferFactory_Transfer of exactly amount of extra.instrumentId to payTo. amount is an integer in units of 10^-10 of the token, so "100000000" is 0.01. The facilitator, extra.feePayer, submits the transfer and pays its traffic. The transfer must execute within extra.executeBeforeSeconds.

  3. Send the same request again with the x402 v2 payment payload, as Base64 JSON, in PAYMENT-SIGNATURE.

The payment settles only once the ticket is built, so an error costs nothing. One settled payment buys one ticket: a payment sent again gets a 402. If the facilitator gives no usable answer, the answer is a 502: retry with the same payment, never a new one.

Query parameters
instringRequired

Symbol of the token to sell.

Example: CC
outstringRequired

Symbol of the token to buy.

Example: USDCx
amountnumber · doubleRequired

Amount of the in token to sell. The endpoint cuts this to the ten decimal places a Daml Decimal carries, then quotes the cut amount as amount_in.

Example: 100
slippagenumber · double · max: 1Required

Slippage tolerance as a fraction, not a percentage. 0.005 is 0.5%. Required: a ticket with no floor can cost the caller money.

Example: 0.005
Header parameters
PAYMENT-SIGNATUREstringOptional

Base64 JSON of an x402 v2 payment payload: a signed TransferFactory_Transfer paying one entry of the 402's accepts. Its accepted field is that entry.

Responses
200

Swap ticket

application/json
get/swap-ticket
GET /v1/swap-ticket?in=CC&out=USDCx&amount=100&slippage=0.005 HTTP/1.1
Host: api.tradecraft.fi
Accept: */*
{
  "in": {
    "code": "CC",
    "instrument_id": {
      "admin": "party::admin123",
      "id": "Amulet"
    },
    "registry_url": "https://registry.example.com"
  },
  "out": {
    "code": "CC",
    "instrument_id": {
      "admin": "party::admin123",
      "id": "Amulet"
    },
    "registry_url": "https://registry.example.com"
  },
  "amount_in": 100,
  "amm_id": "TC CC/USDCx LP",
  "amm_cid": "00a1b2c3...",
  "pool_party": "tc-swp_CC-USDCx::1220abcd...",
  "expected_out": 12.93,
  "price_impact": 0.0002,
  "slippage": 0.005,
  "min_out": "12.86535",
  "memo_key": "splice.lfdecentralizedtrust.org/reason",
  "disclosures": {
    "amm": {
      "templateId": "text",
      "contractId": "text",
      "createdEventBlob": "Ynl0ZXM=",
      "synchronizerId": "text"
    },
    "amm_fees": {
      "templateId": "text",
      "contractId": "text",
      "createdEventBlob": "Ynl0ZXM=",
      "synchronizerId": "text"
    },
    "amm_rules": {
      "templateId": "text",
      "contractId": "text",
      "createdEventBlob": "Ynl0ZXM=",
      "synchronizerId": "text"
    },
    "instrument_config": {
      "templateId": "text",
      "contractId": "text",
      "createdEventBlob": "Ynl0ZXM=",
      "synchronizerId": "text"
    },
    "allocation_factory": {
      "templateId": "text",
      "contractId": "text",
      "createdEventBlob": "Ynl0ZXM=",
      "synchronizerId": "text"
    },
    "featured_app_right": {
      "templateId": "text",
      "contractId": "text",
      "createdEventBlob": "Ynl0ZXM=",
      "synchronizerId": "text"
    },
    "amm_data": {},
    "amm_fees_data": {},
    "amm_rules_data": {},
    "featured_app_right_id": "text"
  }
}

Last updated

Was this helpful?