Swaps
Everything needed to place a swap.
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.
The name/symbol of the token (URL encoded).
USDCxAllocation factory context
The registry's allocation-factory contract and the context for exercising it.
Contract ID to exercise AllocationFactory_Allocate on
When this context was last fetched from the registry
2026-01-20T14:35:00ZThe token is missing, malformed, unknown, or is CC/Amulet
No context is available for this token right now.
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"
}To swap by transfer:
Send a token-standard transfer of
amount_inofin.instrument_idtopool_party.Copy
min_outinto the transfer metadata under the keymemo_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:
Pick one entry of
accepts.As an external party, sign a token-standard
TransferFactory_Transferof exactlyamountofextra.instrumentIdtopayTo.amountis 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 withinextra.executeBeforeSeconds.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.
Symbol of the token to sell.
CCSymbol of the token to buy.
USDCxAmount 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.
100Slippage tolerance as a fraction, not a percentage. 0.005 is 0.5%. Required: a ticket with no floor can cost the caller money.
0.005Base64 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.
Swap ticket
A parameter is missing or malformed, no pool holds the pair, the
floor rounds to zero at Daml's precision, or PAYMENT-SIGNATURE
cannot be decoded.
Payment required. Either none was sent, it is not in an accepted
token, the facilitator refused it (for example a wrong amount or
payee), or it already bought a ticket (payment_already_redeemed).
error and the header both say which.
The payment facilitator gave no usable answer, so no ticket is
returned. This includes no reply, an error status such as its rate
limit, and a settlement without a transaction id. The payment may
have settled: retry with the same PAYMENT-SIGNATURE, not a new
payment, which could pay twice.
The pool exists, but the endpoint cannot build a ticket for it now, or no payment token in the price list is in the token registry.
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?
