Skip to content

Instantly share code, notes, and snippets.

View patcito's full-sized avatar

patcito patcito

View GitHub Profile
@patcito
patcito / README.md
Created May 26, 2026 14:34
FlyingTulip leverage engine — on-chain broadcastOrder (no HTTP). Solidity snippet for strategies + Python EOA helper.

FlyingTulip leverage engine — on-chain broadcastOrder (no HTTP)

If you'd rather your Solidity strategy submit orders fully on-chain instead of POSTing to our HTTP API, just call engine.broadcastOrder(order). Our executor watches the engine's OrderBroadcast event on Sonic mainnet and fills the order for you within seconds.

This is permissionless: the engine has no caller check — security is the user's EIP-712 signature (or, for broadcastOrder specifically,

@patcito
patcito / README.md
Created May 26, 2026 13:09
FlyingTulip leverage executor — PROD HTTP API (Python + TypeScript clients, EIP-712 LeveragedOrder)

FlyingTulip leverage executor — PROD HTTP API

The executor settles a signed LeveragedOrder on the prod LeverageRfqEngine (Sonic mainnet, chainId 146). You don't pass it calldata — you POST a signed order, the executor resolves the DEX route (incl. the ftUSD ↔ X composite via MintAndRedeem + Odos), signs the fill with its own KMS-managed relayer key, and broadcasts it. Engine does not gate by caller — security is the user's EIP-712 signature recovered inside _openLeverageFlash.

@patcito
patcito / admin-ui-v2-status.md
Last active May 19, 2026 12:52
Admin Dashboard v2 — status by route (what works / what's missing)

Admin Dashboard v2 — status by route

Live URL: https://admin-dashboard-v2-bay.vercel.app/

What works, what's mocked, what's missing — one row per route. Backend lives in asp-v2 at api-dev.0xbow.io.

Status legend:

  • ✅ Live and wired to the real backend
  • 🟡 Partial / mock data / cosmetic gaps
  • 🟠 Backend endpoint exists, frontend not yet using it
@patcito
patcito / totalRepayableMax-fe-note.md
Created May 5, 2026 15:04
ft-api v0.3.52: totalRepayableMax field — FE migration note

totalRepayableMax — new sibling field on /mm/lend (v0.3.52)

What changed

assets[].userMetrics now exposes three new fields alongside the existing totalRepayable*:

type LendAssetUserMetrics = {
  // existing — unchanged
 totalRepayable: number; // session-aware: min(wallet, debt) − relayer-fee headroom
@patcito
patcito / fe-round8-status.md
Last active April 23, 2026 15:45
FE rounds 7 + 8 status — what shipped + what's open

Shipped today

Lot of stuff landed. All of this is either live in dev or rolling right now.

1. That 0xea70c7ed revert

Decoded it — it's ftPositionManagerMinEquity(), the protocol's per-position equity floor. 5x on $0.10 gives you $0.10 of equity backing $0.40 of borrow, which is below what ftDNMM will let you open. That's why the order failed.

Added a stable code for it: ORDER_BELOW_MIN_EQUITY. Shows up on the POST response (code) and the poll response (errorCode). Friendly message: "position equity below PM minimum (bump up sellAmount or lower leverage)". Keep equity ≥ $1 on dev and you won't hit it.

@patcito
patcito / fe-latency-and-orders-guide.md
Last active April 23, 2026 15:22
why orders fail + session routing + WS latency UX

Reply for the FE dev — why orders fail + WS latency

Why orders fail (even when the params look fine)

The executor now emits stable errorCode on rejections. Branch your toast logic on it so the UX names the problem instead of "order failed" guessing. Most common on dev:

errorCode What it really means Fix on the FE side
ORDER_TOO_SMALL sellAmount is below the wrapper minimum on ftDNMM. 0.01 USDC or 0.0001 wS will trip this. Validate a min size per pair in the form. For dev use ≥ 0.1 USDC / ≥ 1 wS to be safe.
ORDER_REVERTED: Return amount is not enough The DEX quote came back under buyAmount. Happens on limit orders with a floor that's stricter than current market, or on market orders where you didn't relax buyAmount. For market orders set buyAmount = 1. For limit orders set buyAmount from the actual limit price minus slippage tolerance.
@patcito
patcito / fe-round4-shipped.md
Created April 22, 2026 16:12
FE gist round 4 — what shipped (items 1-15)

FE gist round 4 — what shipped

All 15 items are now done in dev (items marked 🟡 need you to verify end-to-end). Dev endpoints: REST https://api.opbalance.com/mm/spot/*, WS same host / /spot/ws.

1. Trade fee in wrong units

Fee was base units for all sides; now scaled by the sell-token's decimals so it matches the fee-currency you render. Also fee-currency tracks the side (sell → base, buy → quote). Verify: /spot/trades/:market_keyfee is human-scaled for both sides.

2. Funding rate reported as raw WAD

@patcito
patcito / fe-leverage-payloads.md
Created April 21, 2026 15:22
Leverage / Spot order payloads for wS-USDC 1 USDC margin 5x

Leverage / Spot order payloads — wS-USDC, 1 USDC margin

Live dev values (fetch at runtime, do not hardcode):

curl -sS https://api.opbalance.com/mm/leverage/config
{
@patcito
patcito / spot-api-full-changelog.md
Last active April 18, 2026 12:30
Spot API — structural overhaul + enrichment + risk fields (PRs #12-#18)

Spot API — changelog 2026-04-16 → 2026-04-17

Everything that landed on spot-trs-indexor in the last 24 h. Base URL on dev: https://api.opbalance.com/mm/spot. Paths below are as they appear through the ft-api proxy.


1. Structural overhaul (PR #12 — 9c85f96)

@patcito
patcito / spot-api-additions.md
Created April 16, 2026 18:38
Spot API additions — HF, partial/full liquidation prices, on-chain enrichment

Spot API additions — health factor, liquidation prices, on-chain enrichment

Addendum to the main spec. These are new/populated fields on existing endpoints.

Base URL (dev): https://api.opbalance.com/mm/spot


GET /account/positions?address=<>&chainId=<> — 3 new fields