@hyperbridge/simplex 0.16.8 → 0.16.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -2,8 +2,8 @@ import { EventEmitter as EventEmitter$1 } from 'node:events';
2
2
  import { HexString, ERC7821Call, ChainConfig, Order, TokenInfo, IntentsCoprocessor, ExecutionResult, IntentGateway, FillOptions, FillerConfig as FillerConfig$1 } from '@hyperbridge/sdk';
3
3
  import { PublicClient, Hash, AbiEvent, BlockNumber, BlockTag, GetLogsParameters, GetLogsReturnType, WalletClient, Transport, Chain } from 'viem';
4
4
  import { LocalAccount, Account } from 'viem/accounts';
5
- import { L as LoggerContext, a as LogLevel, b as Logger, A as ActivityStore, c as ActivityInsert, d as ActivityEvent, O as OrderHistoryPage, W as WalletTx, e as LimitOrderStore, f as LimitOrder, g as LimitOrderFilter, B as BidStore, S as SimplexDataStore, h as LimitOrderFill, i as StoredBid, j as LogSink, k as BidStats, l as StateStore } from './types-C7rnnKWn.js';
6
- export { m as ActivityType, n as BidInsert, o as OperatorNotification, R as RuntimeState, p as WalletTxKind, q as addLogSink, r as configureLogger, s as getLogger } from './types-C7rnnKWn.js';
5
+ import { L as LoggerContext, a as LogLevel, b as Logger, A as ActivityStore, c as ActivityInsert, d as ActivityEvent, O as OrderHistoryPage, W as WalletTx, e as LimitOrderStore, f as LimitOrder, g as LimitOrderFilter, B as BidStore, S as SimplexDataStore, h as LimitOrderFill, i as StoredBid, j as LogSink, k as BidStats, l as StateStore } from './types-B5zkFhxR.js';
6
+ export { m as ActivityType, n as BidInsert, o as LimitOrderFillInsert, p as LimitOrderHold, q as LimitOrderInsert, r as LimitOrderPosting, s as LimitOrderSide, t as LimitOrderStatus, u as OperatorNotification, R as RuntimeState, v as WalletTxKind, w as addLogSink, x as configureLogger, y as getLogger } from './types-B5zkFhxR.js';
7
7
  import { ChannelCredentials } from '@grpc/grpc-js';
8
8
  import { EventEmitter } from 'events';
9
9
  import Decimal$1, { Decimal } from 'decimal.js';
@@ -546,7 +546,8 @@ interface MpcVaultSignerConfig {
546
546
  declare enum SignerType {
547
547
  PrivateKey = "privateKey",
548
548
  MpcVault = "mpcVault",
549
- Turnkey = "turnkey"
549
+ Turnkey = "turnkey",
550
+ SecretPhrase = "secretPhrase"
550
551
  }
551
552
  interface TurnkeySignerConfig {
552
553
  organizationId: string;
@@ -557,6 +558,15 @@ interface TurnkeySignerConfig {
557
558
  interface PrivateKeySignerConfig {
558
559
  key: HexString;
559
560
  }
561
+ interface SecretPhraseSignerConfig {
562
+ /** BIP-39 mnemonic from the English wordlist. */
563
+ phrase: string;
564
+ /**
565
+ * Which wallet under the phrase is the hot wallet: the last component of
566
+ * `m/44'/60'/0'/0/i`. Defaults to 0.
567
+ */
568
+ accountIndex?: number;
569
+ }
560
570
  /**
561
571
  * The `[simplex.signer]` block of the TOML file the binary reads — a tagged
562
572
  * union over the bundled backends. `createSigner` turns one into a {@link Signer};
@@ -568,7 +578,9 @@ type SignerConfig = ({
568
578
  type: SignerType.MpcVault;
569
579
  } & MpcVaultSignerConfig) | ({
570
580
  type: SignerType.Turnkey;
571
- } & TurnkeySignerConfig);
581
+ } & TurnkeySignerConfig) | ({
582
+ type: SignerType.SecretPhrase;
583
+ } & SecretPhraseSignerConfig);
572
584
  /**
573
585
  * A secp256k1 signature in split form, which is how EIP-7702 and raw digests
574
586
  * consume it: `r` and `s` as 32-byte 0x-hex, and `yParity` strictly 0 or 1.
@@ -682,6 +694,16 @@ interface Signer {
682
694
  */
683
695
  signTransaction(tx: SignerTransaction): Promise<HexString>;
684
696
  }
697
+ /**
698
+ * A {@link Signer} backed by a key tree rather than a single key, so it can hand
699
+ * out signers for sibling wallets.
700
+ */
701
+ interface DerivingSigner extends Signer {
702
+ /** Index of the wallet this signer itself signs with. */
703
+ readonly accountIndex: number;
704
+ /** The signer for the wallet at `index`, which may be this signer's own. */
705
+ derive(index: number): Signer;
706
+ }
685
707
  /** The tuple an EIP-7702 authorization signature covers. */
686
708
  interface AuthorizationRequest {
687
709
  chainId: number;
@@ -745,6 +767,19 @@ declare function viemSigner(account: LocalAccount): Signer;
745
767
  */
746
768
  declare function privateKeySigner(privateKey: HexString): Signer;
747
769
 
770
+ /**
771
+ * Throws unless the phrase is a BIP-39 mnemonic from the English wordlist with a
772
+ * matching checksum. The errors name what is wrong and never quote the phrase.
773
+ */
774
+ declare function validateSecretPhrase(phrase: string): void;
775
+ /**
776
+ * Signs with wallets derived from a BIP-39 phrase held in this process. The
777
+ * hot wallet is `m/44'/60'/0'/0/accountIndex`, and `derive` returns the signer
778
+ * for any sibling under the same parent.
779
+ */
780
+ declare function secretPhraseSigner(config: SecretPhraseSignerConfig): DerivingSigner;
781
+ declare function canDerive(signer: Signer): signer is DerivingSigner;
782
+
748
783
  /**
749
784
  * Signs through MPCVault's signing ceremony.
750
785
  *
@@ -1350,10 +1385,9 @@ interface BuiltinAssetResolver {
1350
1385
  getAssetBySymbol(chain: string, symbol: string): HexString | undefined;
1351
1386
  }
1352
1387
  /**
1353
- * Symbols pegged to 1 USD. They seed the USD anchor graph at $1 — the roots
1354
- * from which every pair's token0 must be reachable so confirmation depth can be
1355
- * sized in USD (see `unanchoredToken0Symbols` and `FXFiller.usdFactors`). Trade
1356
- * pricing never uses this as a price.
1388
+ * Symbols pegged to 1 USD. They are pinned at $1 when an order's USD value is
1389
+ * derived from the limit orders' rates (see `usdFactorsFrom`), which is what
1390
+ * sizes confirmation depth. Trade pricing never uses this as a price.
1357
1391
  */
1358
1392
  declare const USD_STABLE_SYMBOLS: ReadonlySet<string>;
1359
1393
  /** Normalises a symbol for lookups: trimmed, uppercased. "cNGN" ≡ "CNGN". */
@@ -1419,22 +1453,24 @@ declare class AssetRegistry {
1419
1453
  *
1420
1454
  * ```toml
1421
1455
  * [[pairs]]
1422
- * token0 = "USDC" # quote side — any symbol in the asset registry
1423
- * token1 = "CNGN" # base side — any symbol in the asset registry
1456
+ * token0 = "USDC" # the book's base — any symbol in the asset registry
1457
+ * token1 = "CNGN" # the book's quote — any symbol in the asset registry
1424
1458
  * ```
1425
1459
  *
1426
1460
  * A pair declares that a market exists and nothing more. What the filler will
1427
1461
  * pay on it comes from the operator's limit orders, which carry the rate and the
1428
1462
  * size they are good for.
1429
1463
  *
1430
- * One orientation only: declaring both `A/B` and `B/A` would make matching
1431
- * depend on declaration order. `token0 == token1` is the same-asset cross-chain
1432
- * market.
1464
+ * The orientation follows the orderbook's books, which the setup wizard copies:
1465
+ * `token0` is the book's base and `token1` its quote, so the `USDC-cNGN` book
1466
+ * (priced in cNGN per USDC) becomes `token0 = "USDC"`, `token1 = "CNGN"`. One
1467
+ * orientation only: `A/B` and `B/A` are the same market and declaring both is
1468
+ * refused. `token0 == token1` is the same-asset cross-chain market.
1433
1469
  */
1434
1470
  interface PairConfig {
1435
- /** Quote-side symbol (e.g. "USDC", "USDT", "ZARP"). */
1471
+ /** The book's base symbol (e.g. "USDC", "USDT"). Any symbol in the registry. */
1436
1472
  token0: string;
1437
- /** Base-side symbol (e.g. "CNGN"). Any symbol in the registry. */
1473
+ /** The book's quote symbol, which the book prices the base in (e.g. "CNGN"). Any symbol in the registry. */
1438
1474
  token1: string;
1439
1475
  }
1440
1476
  /**
@@ -1709,18 +1745,21 @@ interface FillerTomlConfig {
1709
1745
  */
1710
1746
  assets?: Record<string, AssetDefinition>;
1711
1747
  /**
1712
- * Trading pairs — the entire trading configuration. Each pair prices
1713
- * `token1` in units of `token0` via its own bid/ask curves and carries a
1714
- * per-order `maxOrderSize` cap; a same-token pair (token0 == token1) is the
1715
- * same-asset cross-chain market. Required unless running watch-only.
1748
+ * Markets the operator dashboard lists, as `token0`/`token1` symbol pairs.
1749
+ * They carry no prices and do not gate matching: the filler prices every
1750
+ * fill from the operator's limit orders. Optional; the browser setup wizard
1751
+ * writes one per book the orderbook lists. Keys left over from the curve
1752
+ * era (`bidPriceCurve`, `askPriceCurve`, `maxOrderSize`, `referenceOnly`)
1753
+ * are ignored.
1716
1754
  */
1717
1755
  pairs?: PairConfig[];
1718
1756
  /**
1719
1757
  * Per-chain confirmation policies for cross-chain orders, keyed by chain id.
1720
1758
  * Merged over built-in defaults (ETH, BSC, Polygon, Base, Arbitrum,
1721
1759
  * Unichain); every configured chain must be covered or startup fails. The
1722
- * curve amount axis is the order's USD value, derived from the pair curves
1723
- * via the USD anchors.
1760
+ * policy's amount axis is the order's USD value: USD stables count at $1 and
1761
+ * other tokens are valued through the open limit orders' rates. An order no
1762
+ * limit order connects to a dollar waits for the policy's maximum depth.
1724
1763
  */
1725
1764
  confirmationPolicies?: Record<string, ChainConfirmationPolicy>;
1726
1765
  simplex: {
@@ -1762,8 +1801,10 @@ interface FillerTomlConfig {
1762
1801
  };
1763
1802
  /**
1764
1803
  * Overfill protection knobs. Defaults: maxOverfillBps=500, maxConsecutiveClamps=3.
1765
- * `maxOverfillBps` clamps the per-leg output ceiling on every strategy.
1766
- * `maxConsecutiveClamps` only halts FXFiller. Curve clamps warn but never halt.
1804
+ * `maxOverfillBps` is warn-only: FXFiller logs a limit order whose offer exceeds
1805
+ * the swapper's ask by more than this, and clamps nothing. `maxConsecutiveClamps`
1806
+ * is accepted but dormant: the clamp that fed it was for Uniswap V4 venue pricing,
1807
+ * which is gone, so FXFiller never halts.
1767
1808
  */
1768
1809
  overfillProtection?: {
1769
1810
  maxOverfillBps?: number;
@@ -1926,12 +1967,6 @@ declare class ActivityRecorder extends EventEmitter$1 {
1926
1967
  walletTxs(limit?: number): Promise<WalletTx[]>;
1927
1968
  }
1928
1969
 
1929
- /**
1930
- * One curve-priced trading pair's editable price curves. The policies are the
1931
- * same instances the running engine prices with, so `replacePoints` takes
1932
- * effect on the next order evaluation. A side is absent when it cannot be
1933
- * edited: disabled (one-sided LP) or venue-priced (both sides absent).
1934
- */
1935
1970
  /** One market the engine serves, as the operator's market list shows it. */
1936
1971
  interface AdminStrategy {
1937
1972
  /** Stable identifier for the API. */
@@ -1952,6 +1987,15 @@ interface HaltControl {
1952
1987
  resetHalt(): void;
1953
1988
  }
1954
1989
 
1990
+ /** What a limit order may pay out over its whole life, as the fill chain enforces it. */
1991
+ interface LimitOrderBudget {
1992
+ budgetId: HexString;
1993
+ /** The order's whole size in the output token's own units. */
1994
+ cap: bigint;
1995
+ /** The token the order pays on its fill chain. */
1996
+ token: HexString;
1997
+ }
1998
+
1955
1999
  interface SwapCall {
1956
2000
  to: string;
1957
2001
  data: string;
@@ -1983,6 +2027,8 @@ interface BidPlan {
1983
2027
  fundingCalls: ERC7821Call[];
1984
2028
  partialFill: boolean;
1985
2029
  profit: number;
2030
+ /** That limit order's budget, which the bid settles against on the fill chain. */
2031
+ budget?: LimitOrderBudget;
1986
2032
  }
1987
2033
  declare class CacheService {
1988
2034
  private cacheData;
@@ -2017,13 +2063,21 @@ declare class CacheService {
2017
2063
  token: HexString;
2018
2064
  amount: bigint;
2019
2065
  }[] | null;
2066
+ /**
2067
+ * The budget of the limit order that priced the outputs cached for this order, or
2068
+ * null when no limit order did.
2069
+ *
2070
+ * Kept on the same entry as the outputs, so the two are replaced and expire
2071
+ * together: a bid can never sign one limit order's payout beside another's budget.
2072
+ */
2073
+ getBidBudget(orderId: string): LimitOrderBudget | null;
2020
2074
  setFillerOutputs(orderId: string, outputs: {
2021
2075
  token: HexString;
2022
2076
  amount: bigint;
2023
2077
  }[], inputs?: {
2024
2078
  token: HexString;
2025
2079
  amount: bigint;
2026
- }[]): void;
2080
+ }[], budget?: LimitOrderBudget): void;
2027
2081
  /**
2028
2082
  * The limit order this order was priced against, and the payout it allowed.
2029
2083
  *
@@ -2070,6 +2124,12 @@ declare class CacheService {
2070
2124
  setSolverSelection(chain: string, active: boolean): void;
2071
2125
  }
2072
2126
 
2127
+ /** What a bid's batch needs to settle its limit order's budget. */
2128
+ interface BudgetSettlement {
2129
+ budget: LimitOrderBudget;
2130
+ /** The solver's account, which is the only caller `debitOrder` accepts. */
2131
+ solverAccount: HexString;
2132
+ }
2073
2133
  declare class ContractInteractionService {
2074
2134
  private clientManager;
2075
2135
  private configService;
@@ -2113,13 +2173,14 @@ declare class ContractInteractionService {
2113
2173
  }>;
2114
2174
  /**
2115
2175
  * The call gas a bid needs: the shared estimate plus room for the funding calls
2116
- * this bid prepends.
2176
+ * this bid prepends and for settling its limit order's budget.
2117
2177
  *
2118
2178
  * Funding calls are not simulated (the V4 PositionManager's flash accounting does
2119
2179
  * not resolve in the bundler's estimation context), so each one adds a fixed
2120
2180
  * allowance for its modifyLiquidities + take. They differ between the bids on one
2121
2181
  * order, since each draws on its own limit order and so on its own funding, which
2122
2182
  * is why this is worked out per bid rather than baked into the cached estimate.
2183
+ * The estimate is of a lone fillOrder, so the budget call is not in it either.
2123
2184
  */
2124
2185
  private callGasLimitFor;
2125
2186
  /**
@@ -2163,6 +2224,15 @@ declare class ContractInteractionService {
2163
2224
  */
2164
2225
  /** What `holder` holds of an ERC-20 on `chain`, in the token's own units. */
2165
2226
  getTokenBalance(chain: string, token: HexString, holder: HexString): Promise<bigint>;
2227
+ /**
2228
+ * What the solver's account has tallied against a limit order's budget on `chain`, in
2229
+ * the paid token's own units, or null when it cannot be read.
2230
+ *
2231
+ * Null rather than a throw: an account whose implementation keeps no tally answers
2232
+ * with a revert or with no data, and the caller carries on without the figure either
2233
+ * way. Not retried, since that answer does not change on a second ask.
2234
+ */
2235
+ limitOrderSpent(chain: string, budgetId: HexString): Promise<bigint | null>;
2166
2236
  getSolverEntryPointBalance(chain: string): Promise<bigint>;
2167
2237
  /**
2168
2238
  * Deposits native tokens to the ERC-4337 EntryPoint on behalf of the solver account.
@@ -2275,8 +2345,13 @@ declare class ContractInteractionService {
2275
2345
  * Same-chain fills release escrow locally with no Hyperbridge dispatch, so the
2276
2346
  * gateway never pulls the fee token — its approval is skipped. Only cross-chain
2277
2347
  * fills, which dispatch a RedeemEscrow message paid in the fee token, need it.
2348
+ *
2349
+ * A bid priced by a limit order ends with `debitOrder`, which takes the budget's id
2350
+ * as its `orderId`, works out what the fill paid from what is left of the allowance
2351
+ * and reverts the whole batch if the order's payouts would pass its size. It has to
2352
+ * come last, after the gateway has drawn on the allowance.
2278
2353
  */
2279
- buildApprovalAndFillCalldata(order: Order, fillerOutputs: TokenInfo[], fillOptions: FillOptions, requiredFeeTokenAmount: bigint): Promise<HexString>;
2354
+ buildApprovalAndFillCalldata(order: Order, fillerOutputs: TokenInfo[], fillOptions: FillOptions, requiredFeeTokenAmount: bigint, settlement?: BudgetSettlement): Promise<HexString>;
2280
2355
  }
2281
2356
 
2282
2357
  /**
@@ -2775,12 +2850,18 @@ declare class OrderbookClient {
2775
2850
  private request;
2776
2851
  }
2777
2852
 
2853
+ /**
2854
+ * An operator error: the request itself is wrong, and retrying it unchanged will
2855
+ * fail the same way. The HTTP layer turns these into a 400.
2856
+ */
2857
+ declare class LimitOrderValidationError extends Error {
2858
+ }
2778
2859
  /**
2779
2860
  * One limit order as the operator states it: what simplex takes in, and what it
2780
2861
  * pays out for that.
2781
2862
  *
2782
- * "10000 USDC for 139000000 CNGN" is `tokenIn: "USDC", amountIn: 10000e18,
2783
- * tokenOut: "CNGN", amountOut: 139000000e18`. The rate and the side of the book
2863
+ * "10000 USDC for 15500000 CNGN" is `tokenIn: "USDC", amountIn: "10000",
2864
+ * tokenOut: "CNGN", amountOut: "15500000"`, in whole tokens. The rate and the side of the book
2784
2865
  * follow from those, so the order is directional by construction: it prices
2785
2866
  * USDC to CNGN swaps and never the reverse.
2786
2867
  */
@@ -3021,6 +3102,21 @@ declare class LimitOrderService {
3021
3102
  * down because the solver cannot cover what it quoted.
3022
3103
  */
3023
3104
  reconcile(now?: Date): Promise<ReconcileReport>;
3105
+ /**
3106
+ * Lowers every open order's `remaining` to what the solver's account will still
3107
+ * pay for it, and puts the order back on the book at that size.
3108
+ *
3109
+ * The account tallies each order's payouts on the fill chain and refuses a fill
3110
+ * that would take the tally past the order's size. A fill that never settled
3111
+ * here, or a store restored from an older copy, leaves `remaining` above that
3112
+ * room and the order posted at a size the account will refuse. A tally behind
3113
+ * the store changes nothing: `remaining` is never raised.
3114
+ *
3115
+ * Answers how many orders were lowered.
3116
+ */
3117
+ reconcileTallies(): Promise<number>;
3118
+ /** The order as the store now holds it when its tally lowered it, null when it was left alone. */
3119
+ private clampToTally;
3024
3120
  /**
3025
3121
  * Withdraws every order that has outlived the operator's own `expiresAt`.
3026
3122
  *
@@ -3131,6 +3227,13 @@ declare class IntentFiller {
3131
3227
  */
3132
3228
  /** Hands the filler the service that keeps the orderbook in step with a fill. */
3133
3229
  setLimitOrderService(service: LimitOrderService): void;
3230
+ /**
3231
+ * Brings the limit orders' `remaining` in line with their on-chain tallies.
3232
+ *
3233
+ * On the settlement queue, so the pass and a fill never resize the same order at
3234
+ * once. Resolves when the pass has run.
3235
+ */
3236
+ reconcileLimitOrderTallies(): Promise<void>;
3134
3237
  /** Whether the given chain id is configured for watch-only (monitor, never fill). */
3135
3238
  private isChainWatchOnly;
3136
3239
  /**
@@ -3275,8 +3378,8 @@ declare class IntentFiller {
3275
3378
  */
3276
3379
  private claimExecutedBid;
3277
3380
  /**
3278
- * What this fill delivered of the token the limit order pays, at 1e18, or null
3279
- * when the fill names none of it.
3381
+ * What this fill delivered of the token the limit order pays, or null when the
3382
+ * fill names none of it.
3280
3383
  */
3281
3384
  private deliveredAgainst;
3282
3385
  /**
@@ -3321,48 +3424,47 @@ interface TradingPair {
3321
3424
  token1: string;
3322
3425
  }
3323
3426
  /**
3324
- * Strategy for swaps across a configurable set of trading pairs, each priced
3325
- * and sized by its own bid/ask curves. Supports both same-chain and cross-chain
3326
- * orders.
3427
+ * Strategy for swaps priced by the operator's limit orders. Supports both
3428
+ * same-chain and cross-chain orders.
3327
3429
  *
3328
- * Pairs are declared as `token0`/`token1` registry symbols — e.g. USDC/CNGN,
3329
- * USDT/CNGN, ZARP/CNGN — and any number of pairs can run in one engine. Curves
3330
- * are quoted in **token1 per token0**; nothing assumes the quote side is a USD
3331
- * stablecoin and no external price feed is consulted. Trade sizing is
3332
- * pair-local in token0 units (the per-order `maxOrderSize` cap and the curve
3333
- * amount axis); only confirmation sizing converts to USD, using the curves
3334
- * themselves as the price feed (see `usdFactors`).
3430
+ * Every leg is matched against the open limit orders (`matchLimitOrders`): an
3431
+ * order serves a leg when it fills on the destination chain, takes the leg's
3432
+ * input, pays out its output, accepts its source chain and, at its own rate,
3433
+ * pays at least what the swapper asked for. Each matching order gets its own
3434
+ * bid, best offer first, sized `min(offer, remaining)`; there is no fallback
3435
+ * price, so a leg nothing matches is not bid on. No external price feed is
3436
+ * consulted. Confirmation sizing is the only place a dollar value is needed,
3437
+ * and it is derived from the limit orders' own rates (see `usdFactorsFrom`).
3335
3438
  *
3336
- * For each (input, output) leg the engine finds the configured pair matching
3337
- * the leg's direction:
3338
- * - input = token0, output = token1 → the filler *sells* token1 at the ask.
3339
- * - input = token1, output = token0 → the filler *buys* token1 at the bid.
3439
+ * Payouts are bounded by the filler's real balances plus funding-venue
3440
+ * withdrawals. Because the IntentGateway releases inputs proportionally to the
3441
+ * fraction of outputs provided, partial fills need no extra on-chain logic.
3340
3442
  *
3341
- * The filler holds inventory on both sides of its pairs. Profitability
3342
- * evaluation caps each pair's legs at the pair's `maxOrderSize`, prices each
3343
- * leg with its pair's curve (or venue), and bounds outputs by the filler's
3344
- * real balances plus funding-venue withdrawals. Because the IntentGateway
3345
- * releases inputs proportionally to the fraction of outputs provided, partial
3346
- * fills (and overfills) need no extra on-chain logic.
3443
+ * `[[pairs]]` markets do not gate matching; they name the markets the operator
3444
+ * dashboard lists.
3347
3445
  */
3348
3446
  declare class FXFiller implements FillerStrategy {
3349
3447
  name: string;
3350
3448
  private clientManager;
3351
3449
  private contractService;
3352
3450
  private configService;
3353
- /** Trading pairs served by this engine; each with its own bid/ask policies and cap. */
3451
+ /** Markets the dashboard lists. Informational only: matching reads the limit orders. */
3354
3452
  private pairs;
3355
3453
  /** Symbol → per-chain address resolution (built-ins + curated + user `[assets]`). */
3356
3454
  private registry;
3357
3455
  private signer;
3358
3456
  private logger;
3359
- /** Consecutive orders where overfill clamp activated. */
3457
+ /**
3458
+ * Consecutive orders where the overfill clamp activated. Dormant: the clamp
3459
+ * existed for venue-priced legs, which went with Uniswap V4 pricing, so every
3460
+ * outcome is now recorded unclamped and this never climbs. See `recordOrderOutcome`.
3461
+ */
3360
3462
  private consecutiveClamps;
3361
- /** Once set, the filler refuses all orders until restart — systemic pricing error suspected. */
3463
+ /** Once set, the filler refuses all orders until reset. Unreachable while the clamp is dormant. */
3362
3464
  private halted;
3363
- /** Ceiling bps above user-requested output. Sourced from filler config. */
3465
+ /** Bps above the swapper's ask past which a limit order's offer is logged as suspicious. Warn only. */
3364
3466
  private readonly maxOverfillBps;
3365
- /** Consecutive clamped evaluations before halting. Sourced from filler config. */
3467
+ /** Consecutive clamped evaluations before halting. Dormant, as `consecutiveClamps` is. */
3366
3468
  private readonly maxConsecutiveClamps;
3367
3469
  confirmationPolicy?: {
3368
3470
  getConfirmationBlocks: (chainId: number, amountUsd: number) => number;
@@ -3395,10 +3497,9 @@ declare class FXFiller implements FillerStrategy {
3395
3497
  */
3396
3498
  addPair(pair: TradingPair): void;
3397
3499
  /**
3398
- * Removes a market from the running engine. All-or-nothing: at least one
3399
- * market must remain and no other pair may lose its USD anchor (removing a
3400
- * reference feed that anchors a dependent market is rejected). In-flight
3401
- * rechecks of orders on the removed pair simply stop matching.
3500
+ * Removes a market from the running engine. At least one market must remain.
3501
+ * Matching reads the limit orders rather than the pairs, so removing a market
3502
+ * changes what the dashboard lists, not what the filler fills.
3402
3503
  */
3403
3504
  removePair(pair: TradingPair): void;
3404
3505
  /**
@@ -3408,22 +3509,20 @@ declare class FXFiller implements FillerStrategy {
3408
3509
  initialise(): Promise<void>;
3409
3510
  canFill(order: Order): Promise<boolean>;
3410
3511
  /**
3411
- * Evaluates whether an order is profitable to fill under the per-pair
3412
- * `maxOrderSize` caps (where set) and the filler's current token balances.
3512
+ * Evaluates whether an order is profitable to fill against the operator's
3513
+ * limit orders and the filler's current token balances.
3413
3514
  *
3414
3515
  * High-level flow:
3415
- * - Resolve each (input, output) leg to a configured pair and direction.
3416
- * - Estimate each pair's total token0 notional in the order and cap it at
3417
- * the pair's `maxOrderSize` when one is set; pair curves are evaluated at
3418
- * that (possibly uncapped) notional.
3419
- * - Walk the legs, allocating from each pair's capped token0 budget and
3420
- * pricing outputs at the pair's rate.
3421
- * - Further cap each leg by the filler's current token balance plus
3422
- * funding-venue withdrawals.
3423
- * - Cache the resulting outputs for later use in `executeOrder`.
3424
- *
3425
- * Note: we may intentionally overfill relative to the user's requested
3426
- * outputs if the pair pricing makes that attractive. This is how we stay competitive.
3516
+ * - Match each (input, output) leg against the open limit orders.
3517
+ * - Build one bid per matching order, best offer first, each paying the
3518
+ * order's whole offer for the input at its own rate, capped by what the
3519
+ * order has left. The gateway credits the swapper the ask and splits
3520
+ * anything above it between the swapper and the protocol.
3521
+ * - Treat a payout below the ask as a partial fill, which only orders
3522
+ * without output calldata and without an earlier partial fill allow.
3523
+ * - Cap each payout by the filler's balance plus funding-venue withdrawals,
3524
+ * then gate it on fees (full fills) and the same-asset spread.
3525
+ * - Cache the resulting bids for later use in `executeOrder`.
3427
3526
  */
3428
3527
  calculateProfitability(order: Order): Promise<number>;
3429
3528
  /**
@@ -3445,27 +3544,19 @@ declare class FXFiller implements FillerStrategy {
3445
3544
  private submitBid;
3446
3545
  /**
3447
3546
  * Update consecutive-clamp counter after a successful order evaluation.
3448
- * Only venue-priced legs feed this counter (see clamp site) — a streak of those
3449
- * is the signal that a live market source has gone off (stale pool, manipulated
3450
- * venue) and the filler should stop until an operator investigates. Offline
3451
- * price-curve clamps warn but never reach here.
3547
+ *
3548
+ * Dormant. Only venue-priced legs ever fed a clamped outcome here: a streak
3549
+ * of those meant a live market source had gone off (stale pool, manipulated
3550
+ * venue). Venue pricing went with Uniswap V4, and limit orders are prices the
3551
+ * operator set, so the only caller records `false` and the filler never
3552
+ * halts. `isHalted`, `resetHalt` and `[simplex.overfillProtection]
3553
+ * maxConsecutiveClamps` are kept so existing configs and the halt API still
3554
+ * load; they can go once nothing reads them.
3452
3555
  */
3453
3556
  private recordOrderOutcome;
3454
3557
  isHalted(): boolean;
3455
3558
  /** Operator acknowledgement after investigating a self-halt; resumes filling. */
3456
3559
  resetHalt(): void;
3457
- /**
3458
- * Given a single (input, output) leg and the remaining token0 budget of its
3459
- * pair, computes how much token0 notional to allocate to this leg and the
3460
- * corresponding maximum output amount at the pair's rate.
3461
- *
3462
- * `rate` is **token1 per 1 token0**:
3463
- * - token0 input → token1 output: token0 × rate → token1 amount.
3464
- * - token1 input → token0 output: token1 ÷ rate → token0 amount.
3465
- *
3466
- * Returns `null` when this leg cannot consume any of the pair's remaining
3467
- * budget (e.g. the cap has already been exhausted).
3468
- */
3469
3560
  /**
3470
3561
  * Whether any solver has already delivered output against this order.
3471
3562
  *
@@ -3659,7 +3750,8 @@ interface SimplexOptions {
3659
3750
  * transaction it sends. Required unless every chain is watch-only.
3660
3751
  *
3661
3752
  * {@link Signer} is an interface, not a menu: `privateKeySigner`,
3662
- * `turnkeySigner` and `mpcVaultSigner` are the implementations that ship here,
3753
+ * `secretPhraseSigner`, `turnkeySigner` and `mpcVaultSigner` are the
3754
+ * implementations that ship here,
3663
3755
  * `viemSigner` adapts any viem account (a `toAccount` wrapper around an HSM or
3664
3756
  * a remote signing service included), and anything else that satisfies the
3665
3757
  * interface works the same way.
@@ -3775,12 +3867,20 @@ interface SimplexEvents {
3775
3867
  "limit-order:cancelled": {
3776
3868
  order: LimitOrder;
3777
3869
  };
3778
- /** A fill worked the order down and it went back on the book at its new size. */
3870
+ /**
3871
+ * The order was worked down and went back on the book at its new size. A fill does
3872
+ * this, and so does a correction to the solver account's on-chain tally, for which
3873
+ * no fill is recorded. `delivered` is what the order went down by either way.
3874
+ */
3779
3875
  "limit-order:resized": {
3780
3876
  order: LimitOrder;
3781
3877
  delivered: string;
3782
3878
  };
3783
- /** A fill took the order under the orderbook's dust floor, so it is done. */
3879
+ /**
3880
+ * The order went under the orderbook's dust floor, so it is done. A fill takes it
3881
+ * there, and so does a correction to the solver account's on-chain tally, for which
3882
+ * no fill is recorded.
3883
+ */
3784
3884
  "limit-order:filled": {
3785
3885
  order: LimitOrder;
3786
3886
  };
@@ -4146,7 +4246,8 @@ declare class OrderScanner implements OrderScanner$1 {
4146
4246
  * back from its own endpoints, which also proves they answer for one chain
4147
4247
  * before a filler ever depends on them.
4148
4248
  *
4149
- * @throws if an endpoint set is invalid or unreachable, if two entries resolve
4249
+ * @throws if an endpoint set is invalid, if none of a chain's endpoints answer,
4250
+ * if its endpoints disagree on the chain, if two entries resolve
4150
4251
  * to the same chain, or if `scanIntervalSecs` is below the minimum.
4151
4252
  */
4152
4253
  static create(options: OrderScannerOptions): Promise<OrderScanner>;
@@ -4174,4 +4275,4 @@ declare class OrderScanner implements OrderScanner$1 {
4174
4275
  private closeNow;
4175
4276
  }
4176
4277
 
4177
- export { ActivityEvent, ActivityInsert, ActivityStore, type AllowlistConfig, type AssetBalanceRow, AssetController, type AssetDefinition, type AuthorizationRequest, type BalanceIssue, type BalanceSnapshot, BidStats, BidStore, type BinanceConfig, type ChainBalanceRow, type ChainConfirmationPolicy, ChainController, type ChainInput, type ChainView, type CurveConfig, type CurvePoint, type Eip7702Authorization$1 as Eip7702Authorization, type FillerConfigFile, type FillerTomlConfig, type HyperbridgeBalance, LogLevel, LogSink, Logger, LoggerContext, MemoryDataStore, type MpcVaultSignerConfig, OrderScanner, type OrderScanner$1 as OrderScannerContract, type OrderScannerHandlers, type OrderScannerOptions, type PairConfig, PairController, type PairView, type PrivateKeySignerConfig, type QueueConfig, RebalanceController, type RebalancingConfig, type ResolvedChainConfig, type ScannedFill, type ScannedOrder, type ScannerChainConfig, type Signature, type Signer, type SignerConfig, type SignerTransaction, SignerType, Simplex, type SimplexConfig, SimplexDataStore, type SimplexEvents, type SimplexOptions, type SimplexStatus, type SolverWork, StateStore, StoredBid, type Subscription, type TurnkeySignerConfig, type TypedDataPayload, USD_STABLE_SYMBOLS, type UserProvidedChainConfig, type VaultBalanceRow, VaultController, type VaultSweepDeposit, type VaultSweepResult, type VaultSweepSkip, type VaultSweepSkipReason, type VaultSweepSubmission, type VaultToml, type VaultTomlConfig, WalletController, WalletTx, assertConfirmationCoverage, createSigner, digestSigner, formatChainKey, isRegistrySymbol, mpcVaultSigner, normalizeSymbol, parseChainKey, pickAnchorStable, privateKeySigner, registrySymbols, turnkeySigner, validateAssetDefinitions, validateConfig, validatePairConfigs, validateSignerConfig, validateVaultToml, viemSigner };
4278
+ export { ActivityEvent, ActivityInsert, ActivityStore, type AllowlistConfig, type AssetBalanceRow, AssetController, type AssetDefinition, type AuthorizationRequest, type BalanceIssue, type BalanceSnapshot, BidStats, BidStore, type BinanceConfig, type CancelledLimitOrder, type ChainBalanceRow, type ChainConfirmationPolicy, ChainController, type ChainInput, type ChainView, type CreateLimitOrderRequest, type CurveConfig, type CurvePoint, type DerivingSigner, type Eip7702Authorization$1 as Eip7702Authorization, type FillerConfigFile, type FillerTomlConfig, type HyperbridgeBalance, LimitOrder, LimitOrderController, LimitOrderFill, LimitOrderFilter, LimitOrderStore, LimitOrderValidationError, LogLevel, LogSink, Logger, LoggerContext, MemoryDataStore, type MpcVaultSignerConfig, OrderScanner, type OrderScanner$1 as OrderScannerContract, type OrderScannerHandlers, type OrderScannerOptions, type PairConfig, PairController, type PairView, type PostedLimitOrder, type PostingOutcome, type PrivateKeySignerConfig, type QueueConfig, RebalanceController, type RebalancingConfig, type ResolvedChainConfig, type ScannedFill, type ScannedOrder, type ScannerChainConfig, type SecretPhraseSignerConfig, type Signature, type Signer, type SignerConfig, type SignerTransaction, SignerType, Simplex, type SimplexConfig, SimplexDataStore, type SimplexEvents, type SimplexOptions, type SimplexStatus, type SolverWork, StateStore, StoredBid, type Subscription, type TurnkeySignerConfig, type TypedDataPayload, USD_STABLE_SYMBOLS, type UserProvidedChainConfig, type VaultBalanceRow, VaultController, type VaultSweepDeposit, type VaultSweepResult, type VaultSweepSkip, type VaultSweepSkipReason, type VaultSweepSubmission, type VaultToml, type VaultTomlConfig, WalletController, WalletTx, assertConfirmationCoverage, canDerive, createSigner, digestSigner, formatChainKey, isRegistrySymbol, mpcVaultSigner, normalizeSymbol, parseChainKey, pickAnchorStable, privateKeySigner, registrySymbols, secretPhraseSigner, turnkeySigner, validateAssetDefinitions, validateConfig, validatePairConfigs, validateSecretPhrase, validateSignerConfig, validateVaultToml, viemSigner };