Creating, redeeming and swapping from code
Build, review, sign, submit and follow, through the versioned contract.
§1 The contract
Every person-signed instruction is built by the API, reviewed by the person, signed in the wallet, submitted back and followed until it lands. The browser never broadcasts on its own. The same zod contract validates the server and parses every response.
import { createClient } from '@surplus/contract'
const api = createClient('https://api.surplus.example')
// A twin swap: quote from the sleeve's curve, then build against the quote.
const quote = await api.quoteTwin({ sleeveId, inputMint, amountIn, slippageBps: 30, wallet })
const build = await api.buildTwinSwap({ wallet, quoteId: quote.id, minOut: quote.minOut })
// The wallet signs build.transactionBase64; the API relays and follows it.
const status = await api.submitTransaction({ mode: 'relay', buildId: build.id, signedTransactionBase64, idempotencyKey })
const settled = await api.transaction(status.id)§2 In kind
POST /v1/in-kind/create/build and POST /v1/in-kind/redeem/build return every transaction of a delivery at once, to sign under one approval. Pass the delivery’s id to resume from its next transaction.
§3 Instructions
- initialize_fund
- add_constituent
- add_issuer_mint
- queue_basket
- apply_basket
- place_buy
- place_redeem
- cancel_order
- open_strike
- deposit_slice
- release_slice
- settle_strike
- claim
- create_in_kind
- redeem_in_kind
- open_sleeve
- close_sleeve
- swap
- lend_deposit
- lend_withdraw
- harvest