@win-trader/bindings 0.0.4 → 0.3.0

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.
@@ -5,47 +5,44 @@ export * from "@stellar/stellar-sdk";
5
5
  export * as contract from "@stellar/stellar-sdk/contract";
6
6
  export * as rpc from "@stellar/stellar-sdk/rpc";
7
7
  export declare const ConfigManagerError: {
8
- 1: {
8
+ 300: {
9
9
  message: string;
10
10
  };
11
- 2: {
11
+ 301: {
12
12
  message: string;
13
13
  };
14
- 3: {
14
+ 310: {
15
15
  message: string;
16
16
  };
17
- 6: {
17
+ 311: {
18
18
  message: string;
19
19
  };
20
- 7: {
20
+ 320: {
21
21
  message: string;
22
22
  };
23
- 8: {
23
+ 321: {
24
24
  message: string;
25
25
  };
26
- 9: {
26
+ 322: {
27
27
  message: string;
28
28
  };
29
- 10: {
29
+ 323: {
30
30
  message: string;
31
31
  };
32
- 11: {
32
+ 330: {
33
33
  message: string;
34
34
  };
35
- 12: {
35
+ 331: {
36
36
  message: string;
37
37
  };
38
- 13: {
38
+ 332: {
39
39
  message: string;
40
40
  };
41
- 14: {
41
+ 333: {
42
42
  message: string;
43
43
  };
44
44
  };
45
45
  export type StorageKey = {
46
- tag: "Initialized";
47
- values: void;
48
- } | {
49
46
  tag: "UpgradeTimelock";
50
47
  values: void;
51
48
  } | {
@@ -105,6 +102,17 @@ export declare const AccessControlError: {
105
102
  message: string;
106
103
  };
107
104
  };
105
+ export declare const OwnableError: {
106
+ 2100: {
107
+ message: string;
108
+ };
109
+ 2101: {
110
+ message: string;
111
+ };
112
+ 2102: {
113
+ message: string;
114
+ };
115
+ };
108
116
  /**
109
117
  * Storage key for enumeration of accounts per role.
110
118
  */
@@ -137,17 +145,6 @@ export type AccessControlStorageKey = {
137
145
  tag: "PendingAdmin";
138
146
  values: void;
139
147
  };
140
- export declare const OwnableError: {
141
- 2100: {
142
- message: string;
143
- };
144
- 2101: {
145
- message: string;
146
- };
147
- 2102: {
148
- message: string;
149
- };
150
- };
151
148
  /**
152
149
  * Storage keys for `Ownable` utility.
153
150
  */
@@ -159,103 +156,71 @@ export type OwnableStorageKey = {
159
156
  values: void;
160
157
  };
161
158
  /**
162
- * Authoritative per-market state: the side aggregates, the funding indices,
163
- * the funding EMA, and the market configuration.
164
- *
165
- * Soroban limits UDT field names to 30 characters, so where a doc glossary
166
- * term is longer the field drops the redundant qualifier and its doc
167
- * comment carries the full term (e.g. `receiver_backed_index_long` is the
168
- * doc's `receiver_backed_payer_index` for the long side).
159
+ * SEP-40 asset identifier. Markets are quoted as `Other(market symbol)`.
169
160
  */
161
+ export type Asset = {
162
+ tag: "Stellar";
163
+ values: readonly [string];
164
+ } | {
165
+ tag: "Other";
166
+ values: readonly [string];
167
+ };
168
+ export interface PriceData {
169
+ price: i128;
170
+ timestamp: u64;
171
+ }
172
+ export interface StampedPrice {
173
+ observed_at: u64;
174
+ price: i128;
175
+ }
170
176
  export interface Market {
171
177
  config: MarketConfig;
172
- /**
173
- * `INDEX_PRECISION`-scaled bps/day payer rate as of the last refresh.
174
- */
175
178
  current_payer_rate: i128;
176
179
  current_payer_side: PayerSide;
177
180
  last_funding_checkpoint: u64;
178
181
  long: MarketSide;
179
- /**
180
- * Cumulative payer fee per unit of dominant-side size that is LP
181
- * revenue on collection (§8.2).
182
- */
182
+ long_payer_remainders: RemainderGroup;
183
183
  lp_backed_index_long: i128;
184
184
  lp_backed_index_short: i128;
185
- lp_payer_remainder: i128;
186
- /**
187
- * Sub-stroop carry of the receiver-liability accrual (§8.3).
188
- */
189
- pending_remainder: i128;
190
- /**
191
- * Cumulative payer fee per unit of dominant-side size whose collection
192
- * restores cash backing an already-accrued receiver claim (§8.2).
193
- */
185
+ pending_receiver_funding: i128;
194
186
  receiver_backed_index_long: i128;
195
187
  receiver_backed_index_short: i128;
196
- /**
197
- * Cumulative funding credit per unit of light-side size (§8.2).
198
- */
199
188
  receiver_index_long: i128;
200
- receiver_index_remainder: i128;
201
189
  receiver_index_short: i128;
202
- receiver_payer_remainder: i128;
203
190
  short: MarketSide;
204
- /**
205
- * §8.1 signed EMA of the instantaneous skew: a fraction of one at
206
- * `INDEX_PRECISION` scale, positive when history says longs dominate.
207
- * Decays toward the current skew with the global half-life.
208
- */
191
+ short_payer_remainders: RemainderGroup;
209
192
  skew_ema: i128;
210
193
  }
194
+ export type Trigger = {
195
+ tag: "None";
196
+ values: void;
197
+ } | {
198
+ tag: "Attached";
199
+ values: readonly [TriggerInstruction];
200
+ };
211
201
  export interface LpConfig {
212
- lp_request_delay: u64;
202
+ lp_request_delay_seconds: u64;
213
203
  max_withdraw_utilization_bps: u32;
214
204
  min_deposit_nav_factor_bps: u32;
215
205
  }
216
- /**
217
- * Represents a single trader's open leveraged position.
218
- */
219
206
  export interface Position {
220
- /**
221
- * Asset units at `PRICE_PRECISION`.
222
- */
223
207
  base_exposure: i128;
224
- borrow_debt: i128;
225
- /**
226
- * Cash owned by an optional-order executor.
227
- */
228
- execution_budget: i128;
229
- funding_paid_to_lps_debt: i128;
230
- funding_paid_to_receivers_debt: i128;
231
- funding_received_debt: i128;
208
+ borrow_index_snapshot: i128;
232
209
  id: u64;
233
210
  is_long: boolean;
234
- last_increased_time: u64;
211
+ lp_payer_index_snapshot: i128;
235
212
  market: string;
213
+ opened_at: u64;
236
214
  owner: string;
237
- /**
238
- * Fixed gross capacity assigned when risk opens.
239
- */
215
+ pending_mutation_action_id: Option<u64>;
216
+ receiver_index_snapshot: i128;
217
+ receiver_payer_index_snapshot: i128;
240
218
  risk_units: i128;
241
- /**
242
- * USD notional at `PRICE_PRECISION`.
243
- */
244
219
  size: i128;
245
- /**
246
- * Trigger price for the optional stop-loss order; `0` = none.
247
- */
248
- stop_loss: i128;
249
- /**
250
- * Trader-owned collateral recorded in contract state (the doc's
251
- * "stored collateral"). Effective collateral — stored collateral after
252
- * pending fees and funding credits — is always derived, never stored.
253
- */
220
+ stop_loss: Trigger;
254
221
  stored_collateral: i128;
255
- /**
256
- * Trigger price for the optional take-profit order; `0` = none.
257
- */
258
- take_profit: i128;
222
+ stored_minimum_borrow_fee: i128;
223
+ take_profit: Trigger;
259
224
  }
260
225
  export interface LpRequest {
261
226
  amount: i128;
@@ -264,13 +229,12 @@ export interface LpRequest {
264
229
  kind: LpRequestKind;
265
230
  owner: string;
266
231
  request_time: u64;
232
+ /**
233
+ * The resolve reward fixed when the request was made.
234
+ */
235
+ reward: i128;
267
236
  status: LpRequestStatus;
268
237
  }
269
- /**
270
- * Which side currently pays funding (§8.1: the side the blended integral
271
- * skew points at — under the EMA this can be the *lighter* side for a
272
- * while after the book flips). `None` when the blend is exactly zero.
273
- */
274
238
  export type PayerSide = {
275
239
  tag: "None";
276
240
  values: void;
@@ -294,69 +258,67 @@ export type RiskState = {
294
258
  tag: "HardCap";
295
259
  values: void;
296
260
  };
261
+ export type ActionKind = {
262
+ tag: "MarketOpen";
263
+ values: void;
264
+ } | {
265
+ tag: "LimitOpen";
266
+ values: void;
267
+ } | {
268
+ tag: "Decrease";
269
+ values: void;
270
+ } | {
271
+ tag: "Close";
272
+ values: void;
273
+ };
297
274
  export interface MarketSide {
298
275
  base_exposure: i128;
276
+ hard_cap_payout_factor: i128;
277
+ hard_cap_reference_pnl: i128;
299
278
  risk_state: RiskState;
300
279
  risk_units: i128;
301
280
  size_open_interest: i128;
302
281
  stored_collateral_total: i128;
303
282
  }
304
- export interface RoundPrice {
305
- price: i128;
306
- symbol: string;
283
+ export interface OpenPayload {
284
+ acceptable_price: i128;
285
+ expires_at: u64;
286
+ is_long: boolean;
287
+ size: i128;
288
+ stop_loss: i128;
289
+ submitted_collateral: i128;
290
+ take_profit: i128;
307
291
  }
308
- export interface OracleRound {
309
- id: u64;
310
- previous_id: u64;
311
- previous_timestamp: u64;
312
- prices: Array<RoundPrice>;
313
- timestamp: u64;
292
+ export interface ClosePayload {
293
+ acceptable_price: i128;
294
+ position_id: u64;
314
295
  }
315
296
  export interface GlobalConfig {
316
297
  base_borrow_rate_bps_day: i128;
317
- /**
318
- * §8.1 half-life of the funding skew EMA, seconds (global: one memory
319
- * horizon for every market).
320
- */
298
+ borrow_lp_revenue_share_bps: u32;
299
+ config_timelock_seconds: u64;
300
+ fee_lp_revenue_share_bps: u32;
321
301
  funding_half_life_seconds: u64;
322
- hard_cap_factor_limit_bps: u32;
323
- lp_revenue_share_bps: u32;
302
+ global_hard_cap_limit_bps: u32;
303
+ hard_cap_relatch_band_bps: u32;
304
+ keeper_rewards: KeeperRewards;
324
305
  max_active_markets: u32;
325
- max_adl_reward: i128;
326
- max_insolvent_touch_reward: i128;
306
+ max_market_order_lifetime: u64;
307
+ max_order_lifetime_seconds: u64;
308
+ max_price_age_seconds: u64;
327
309
  max_variable_borrow_bps_day: i128;
310
+ min_borrow_fee_seconds: u64;
328
311
  min_collateral: i128;
329
312
  min_position_lifetime: u64;
330
313
  risk_capacity_limit_bps: u32;
331
- risk_keeper_revenue_share_bps: u32;
332
314
  }
333
315
  export interface MarketConfig {
334
316
  adl_pnl_factor_bps: u32;
335
- adl_reward_bps: u32;
336
- /**
337
- * §11.1 closing-fee tier when the close worsens skew.
338
- */
339
- close_fee_high_bps: u32;
340
- /**
341
- * §11.1 closing-fee tier when the close improves or preserves skew.
342
- */
343
- close_fee_low_bps: u32;
317
+ close_pnl_fee_bps: u32;
318
+ close_size_fee_bps: u32;
344
319
  hard_cap_pnl_factor_bps: u32;
345
- /**
346
- * Margin required to open or add risk (§12.3). Divides max leverage:
347
- * a position may not be created closer to liquidation than this.
348
- */
349
320
  initial_margin_bps: u32;
350
- /**
351
- * §8.1 weight of the instantaneous skew in the funding blend, in bps;
352
- * the rest is the half-life EMA. `BPS` reproduces pure instant skew.
353
- */
354
321
  instant_weight_bps: u32;
355
- liquidation_reward_bps: u32;
356
- /**
357
- * Margin below which the position is liquidatable (§12.3). Must not
358
- * exceed `initial_margin_bps`; the gap is the entry buffer.
359
- */
360
322
  maintenance_margin_bps: u32;
361
323
  market_risk_factor_bps: u32;
362
324
  max_funding_rate_bps_day: i128;
@@ -364,37 +326,88 @@ export interface MarketConfig {
364
326
  max_long_size_open_interest: i128;
365
327
  max_short_base_exposure: i128;
366
328
  max_short_size_open_interest: i128;
329
+ open_fee_bps: u32;
330
+ order_execution_delay_seconds: u64;
367
331
  recovery_pnl_factor_bps: u32;
368
332
  warning_pnl_factor_bps: u32;
369
333
  }
370
- /**
371
- * Global safety thresholds for price validation.
372
- */
373
- export interface OracleConfig {
374
- /**
375
- * How long a cached aggregated price remains valid after the router
376
- * fetch (in seconds). A cache hit also requires every source timestamp
377
- * used for the cached median to remain within `staleness_threshold`.
378
- * Must be > 0 and <= `staleness_threshold`.
379
- */
380
- cache_duration: u64;
381
- /**
382
- * Maximum allowed spread between oracle sources in basis points
383
- * (e.g., 100 = 1%). Bounded at `crate::constants::MAX_DEVIATION_BPS_CEILING`.
384
- */
385
- max_deviation_bps: i128;
386
- /**
387
- * Minimum number of source responses that must agree within
388
- * `max_deviation_bps` for OracleRouter to return a price. Floored at
389
- * `crate::constants::MIN_REQUIRED_SOURCES_FLOOR`, ceilinged at
390
- * `crate::constants::MAX_ORACLE_SOURCES`.
391
- */
392
- min_required_sources: u32;
393
- /**
394
- * Maximum age of an external SEP-40 price feed before it is rejected
395
- * as stale (in seconds).
396
- */
397
- staleness_threshold: u64;
334
+ export type ActionOutcome = {
335
+ tag: "Executed";
336
+ values: void;
337
+ } | {
338
+ tag: "Failed";
339
+ values: void;
340
+ } | {
341
+ tag: "Cancelled";
342
+ values: void;
343
+ } | {
344
+ tag: "Expired";
345
+ values: void;
346
+ } | {
347
+ tag: "Superseded";
348
+ values: void;
349
+ } | {
350
+ tag: "NotReady";
351
+ values: void;
352
+ } | {
353
+ tag: "Pending";
354
+ values: void;
355
+ } | {
356
+ tag: "RequiresLiquidation";
357
+ values: void;
358
+ };
359
+ export type ActionPayload = {
360
+ tag: "MarketOpen";
361
+ values: readonly [OpenPayload];
362
+ } | {
363
+ tag: "LimitOpen";
364
+ values: readonly [OpenPayload, TriggerCondition];
365
+ } | {
366
+ tag: "Decrease";
367
+ values: readonly [DecreasePayload];
368
+ } | {
369
+ tag: "Close";
370
+ values: readonly [ClosePayload];
371
+ };
372
+ export type FailureReason = {
373
+ tag: "PriceBoundExceeded";
374
+ values: void;
375
+ } | {
376
+ tag: "CapacityExceeded";
377
+ values: void;
378
+ } | {
379
+ tag: "ExposureCapExceeded";
380
+ values: void;
381
+ } | {
382
+ tag: "SideRestricted";
383
+ values: void;
384
+ } | {
385
+ tag: "InsufficientCollateral";
386
+ values: void;
387
+ } | {
388
+ tag: "UnpayableProfit";
389
+ values: void;
390
+ } | {
391
+ tag: "PositionGone";
392
+ values: void;
393
+ } | {
394
+ tag: "MarketPaused";
395
+ values: void;
396
+ } | {
397
+ tag: "SizeTooSmall";
398
+ values: void;
399
+ };
400
+ export interface KeeperRewards {
401
+ adl: i128;
402
+ close: i128;
403
+ decrease: i128;
404
+ expiry: i128;
405
+ limit_order: i128;
406
+ liquidation: i128;
407
+ lp_resolve: i128;
408
+ open: i128;
409
+ sl: i128;
410
+ tp: i128;
398
411
  }
399
412
  export type LpRequestKind = {
400
413
  tag: "Deposit";
@@ -403,24 +416,35 @@ export type LpRequestKind = {
403
416
  tag: "Withdrawal";
404
417
  values: void;
405
418
  };
406
- /**
407
- * Data required during a WASM migration. Single definition for all contracts.
408
- */
409
419
  export interface MigrationData {
410
420
  version: u32;
411
421
  }
412
- /**
413
- * Pending WASM upgrade — set by `propose_upgrade`, consumed by `upgrade`
414
- * (cleared atomically on a successful install), or cleared by `cancel_upgrade`.
415
- * Single shape across every protocol contract. Contracts store it at
416
- * the shared `pending_upgrade` Symbol key in their own instance storage (see
417
- * `crate::upgrade::pending_upgrade_key`). `upgrade` refuses to install
418
- * unless `pending.wasm_hash` matches the supplied hash and `now >= eta`.
419
- */
422
+ export interface PendingAction {
423
+ action_id: u64;
424
+ commit_observed_at: u64;
425
+ created_at: u64;
426
+ escrowed_collateral: i128;
427
+ execute_after: u64;
428
+ kind: ActionKind;
429
+ market_id: string;
430
+ owner: string;
431
+ payload: ActionPayload;
432
+ }
420
433
  export interface PendingUpgrade {
421
434
  eta: u64;
422
435
  wasm_hash: Buffer;
423
436
  }
437
+ export interface RemainderGroup {
438
+ distribution_remainder: i128;
439
+ lp_payer_remainder: i128;
440
+ receiver_liability_remainder: i128;
441
+ receiver_payer_remainder: i128;
442
+ }
443
+ export interface DecreasePayload {
444
+ acceptable_price: i128;
445
+ position_id: u64;
446
+ size_removed: i128;
447
+ }
424
448
  export type LpRequestStatus = {
425
449
  tag: "Pending";
426
450
  values: void;
@@ -430,15 +454,20 @@ export type LpRequestStatus = {
430
454
  } | {
431
455
  tag: "Failed";
432
456
  values: void;
433
- } | {
434
- tag: "Expired";
435
- values: void;
436
457
  };
458
+ export interface PendingFeesView {
459
+ borrow: i128;
460
+ funding_paid_to_lps: i128;
461
+ funding_paid_to_receivers: i128;
462
+ funding_received: i128;
463
+ }
464
+ export interface PendingPriceFeed {
465
+ effective_at: u64;
466
+ price_feed: string;
467
+ }
437
468
  export interface SettlementResult {
438
- /**
439
- * Shares minted for a deposit or assets paid for a withdrawal.
440
- */
441
469
  amount: i128;
470
+ reward: i128;
442
471
  status: SettlementStatus;
443
472
  }
444
473
  export type SettlementStatus = {
@@ -447,19 +476,49 @@ export type SettlementStatus = {
447
476
  } | {
448
477
  tag: "Failed";
449
478
  values: void;
479
+ } | {
480
+ tag: "NotReady";
481
+ values: void;
450
482
  };
483
+ export interface TriggerCondition {
484
+ trigger_above: boolean;
485
+ trigger_price: i128;
486
+ }
451
487
  export interface AccountingSnapshot {
452
488
  cash_lp_equity: i128;
453
489
  cash_shortfall: i128;
490
+ deleveraging_side_count: u32;
454
491
  free_lp_capital: i128;
455
- lp_blocked_side_count: u32;
492
+ min_equity_clear_of_adl: i128;
456
493
  non_lp_claims: i128;
457
494
  open_position_count: u64;
458
495
  physical_cash: i128;
459
496
  required_risk_backing: i128;
497
+ restricted_side_count: u32;
460
498
  total_risk_units: i128;
461
499
  vault_nav: i128;
462
500
  }
501
+ export interface TriggerInstruction {
502
+ acceptable_price: i128;
503
+ commit_observed_at: u64;
504
+ committed_at: u64;
505
+ execute_after: u64;
506
+ trigger_price: i128;
507
+ }
508
+ export interface PendingGlobalConfig {
509
+ config: GlobalConfig;
510
+ effective_at: u64;
511
+ }
512
+ export interface PendingMarketConfig {
513
+ config: MarketConfig;
514
+ effective_at: u64;
515
+ }
516
+ export interface EventHeader {
517
+ actor: string;
518
+ event_version: u32;
519
+ ledger_timestamp: u64;
520
+ market: string;
521
+ }
463
522
  export declare const UpgradeableError: {
464
523
  /**
465
524
  * When migration is attempted but not allowed due to upgrade state.
@@ -488,16 +547,6 @@ export declare const MerkleDistributorError: {
488
547
  message: string;
489
548
  };
490
549
  };
491
- /**
492
- * Storage keys for the data associated with `MerkleDistributor`
493
- */
494
- export type MerkleDistributorStorageKey = {
495
- tag: "Root";
496
- values: void;
497
- } | {
498
- tag: "Claimed";
499
- values: readonly [u32];
500
- };
501
550
  /**
502
551
  * Rounding direction for division operations
503
552
  */
@@ -525,37 +574,47 @@ export declare const SorobanFixedPointError: {
525
574
  message: string;
526
575
  };
527
576
  };
528
- export declare const CryptoError: {
577
+ export declare const PausableError: {
529
578
  /**
530
- * The merkle proof length is out of bounds.
579
+ * The operation failed because the contract is paused.
531
580
  */
532
- 1400: {
581
+ 1000: {
533
582
  message: string;
534
583
  };
535
584
  /**
536
- * The index of the leaf is out of bounds.
585
+ * The operation failed because the contract is not paused.
537
586
  */
538
- 1401: {
587
+ 1001: {
539
588
  message: string;
540
589
  };
590
+ };
591
+ /**
592
+ * Storage keys for the data associated with `MerkleDistributor`
593
+ */
594
+ export type MerkleDistributorStorageKey = {
595
+ tag: "Root";
596
+ values: void;
597
+ } | {
598
+ tag: "Claimed";
599
+ values: readonly [u32];
600
+ };
601
+ export declare const CryptoError: {
541
602
  /**
542
- * No data in hasher state.
603
+ * The merkle proof length is out of bounds.
543
604
  */
544
- 1402: {
605
+ 1400: {
545
606
  message: string;
546
607
  };
547
- };
548
- export declare const PausableError: {
549
608
  /**
550
- * The operation failed because the contract is paused.
609
+ * The index of the leaf is out of bounds.
551
610
  */
552
- 1000: {
611
+ 1401: {
553
612
  message: string;
554
613
  };
555
614
  /**
556
- * The operation failed because the contract is not paused.
615
+ * No data in hasher state.
557
616
  */
558
- 1001: {
617
+ 1402: {
559
618
  message: string;
560
619
  };
561
620
  };
@@ -630,10 +689,6 @@ export interface Client {
630
689
  caller: string;
631
690
  wasm_hash: Buffer;
632
691
  }, options?: MethodOptions) => Promise<AssembledTransaction<null>>;
633
- /**
634
- * Construct and simulate a bump_config_state transaction. Returns an `AssembledTransaction` object which will have a `result` field containing the result of the simulation. If this transaction changes contract state, you will need to call `signAndSend()` on the returned object.
635
- */
636
- bump_config_state: (options?: MethodOptions) => Promise<AssembledTransaction<null>>;
637
692
  /**
638
693
  * Construct and simulate a get_pending_admin transaction. Returns an `AssembledTransaction` object which will have a `result` field containing the result of the simulation. If this transaction changes contract state, you will need to call `signAndSend()` on the returned object.
639
694
  */
@@ -683,7 +738,6 @@ export declare class Client extends ContractClient {
683
738
  propose_admin: (json: string) => AssembledTransaction<null>;
684
739
  cancel_upgrade: (json: string) => AssembledTransaction<null>;
685
740
  propose_upgrade: (json: string) => AssembledTransaction<null>;
686
- bump_config_state: (json: string) => AssembledTransaction<null>;
687
741
  get_pending_admin: (json: string) => AssembledTransaction<Option<string>>;
688
742
  get_upgrade_timelock: (json: string) => AssembledTransaction<bigint>;
689
743
  set_upgrade_timelock: (json: string) => AssembledTransaction<null>;