/** * SynFutures V3 — Perpetual futures on Base * * Direct ethers v6 integration — no SDK dependency. * * Flow: Approve USDC → Gate.deposit → Instrument.trade → (close: trade opposite) → Gate.withdraw * * Architecture: * Gate manages margin deposits/withdrawals across all instruments * Instrument contracts handle trading (one per market type) * Observer provides read-only queries (positions, prices, quotes) * All values inside Instrument use WAD (18 decimals) * Gate deposit/withdraw use the token's native decimals (USDC = 6) * * Contracts (Base mainnet): * Gate: 0x208B443983D8BcC8578e9D86Db23FbA547071270 * Observer: 0xDb166a6E454d2a273Cd50CCD6420703564B2a830 * Config: 0xB63902d38738e353f3f52AdD203C418A0bFEa172 * * Encoding: * Gate.deposit(bytes32) — packs (quantity << 160) | tokenAddress * Instrument.trade(bytes32[2]) — page0: deadline|tick|expiry, page1: size|amount */ import { ethers } from 'ethers'; export declare const SYNFUTURES_CONTRACTS: { readonly GATE: "0x208B443983D8BcC8578e9D86Db23FbA547071270"; readonly OBSERVER: "0xDb166a6E454d2a273Cd50CCD6420703564B2a830"; readonly CONFIG: "0xB63902d38738e353f3f52AdD203C418A0bFEa172"; readonly USDC: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913"; }; export declare const SYNFUTURES_INSTRUMENTS: Record; export type SynFuturesSide = 'long' | 'short'; export interface SynFuturesOrder { /** Instrument key (e.g. 'LINK', 'PYTH') or instrument address */ instrument: string; /** Long or short */ side: SynFuturesSide; /** Trade size in USDC notional (e.g. '20' = $20 notional) */ notional: string; /** USDC margin to deposit (e.g. '10' for 2x leverage on $20 notional) */ margin: string; /** Max acceptable slippage in basis points (default: 300 = 3%) */ slippageBps?: number; } export interface SynFuturesPosition { instrument: string; instrumentAddress: string; side: string; size: string; balance: string; entryNotional: string; } /** * Build calls to deposit USDC margin into the SynFutures Gate. * * Steps: * 1. Approve USDC → Gate * 2. Gate.deposit(packed(USDC, amount)) */ export declare function buildDepositCalls(usdcAmount: bigint): Array<{ to: string; data: string; value: string; }>; /** * Build the trade call for opening/modifying a perp position. * * @param instrumentAddress - The instrument contract address * @param size - Trade size in WAD (positive = long, negative = short) * @param amount - Margin amount in WAD (how much margin to allocate from Gate reserve) * @param limitTick - Slippage limit tick (MAX_TICK for longs, MIN_TICK for shorts) * @param deadline - Unix timestamp deadline */ export declare function buildTradeCall(instrumentAddress: string, size: bigint, amount: bigint, limitTick: number, deadline: number): { to: string; data: string; value: string; }; /** * Build calls to open a new perp position. * * Full flow: approve USDC → deposit to Gate → trade on Instrument * * @param order - Order parameters * @param quote - Quote from inquireByNotional (provides size and minAmount) */ export declare function buildOpenPositionCalls(order: SynFuturesOrder, quote: { size: bigint; minAmount: bigint; tick: number; }): Array<{ to: string; data: string; value: string; }>; /** * Build calls to close an existing position. * * Trade with opposite size, amount = 0 (withdraw all margin after close). */ export declare function buildClosePositionCalls(instrumentAddress: string, currentSize: bigint): Array<{ to: string; data: string; value: string; }>; /** * Build call to withdraw USDC from Gate back to wallet. */ export declare function buildWithdrawCalls(usdcAmount: bigint): Array<{ to: string; data: string; value: string; }>; /** * Get a trade quote by notional amount. * Returns the size you'd get for a given USD notional, plus fees. */ export declare function getQuote(instrument: string, notional: string, side: SynFuturesSide, provider: ethers.JsonRpcProvider): Promise<{ size: bigint; benchmark: bigint; mark: bigint; fee: bigint; minAmount: bigint; tick: number; }>; /** * Get the current AMM state for an instrument (price, liquidity, OI). */ export declare function getAmmState(instrument: string, provider: ethers.JsonRpcProvider): Promise<{ priceWad: bigint; priceUsd: string; tick: number; liquidity: bigint; totalLong: bigint; totalShort: bigint; openInterest: bigint; status: number; }>; /** * Get user's position on a specific instrument. */ export declare function getPosition(instrument: string, wallet: string, provider: ethers.JsonRpcProvider): Promise; /** * Get user's Gate reserve (deposited margin not yet allocated). */ export declare function getGateReserve(wallet: string, provider: ethers.JsonRpcProvider): Promise; /** * Get all available instruments from Gate. */ export declare function getInstrumentCount(provider: ethers.JsonRpcProvider): Promise;