@win-trader/bindings 0.1.0 → 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.
@@ -1,625 +0,0 @@
1
- import { Buffer } from "buffer";
2
- import { AssembledTransaction, Client as ContractClient, ClientOptions as ContractClientOptions, MethodOptions } from "@stellar/stellar-sdk/contract";
3
- import type { u32, u64, i128 } from "@stellar/stellar-sdk/contract";
4
- export * from "@stellar/stellar-sdk";
5
- export * as contract from "@stellar/stellar-sdk/contract";
6
- export * as rpc from "@stellar/stellar-sdk/rpc";
7
- export declare const OracleError: {
8
- 1: {
9
- message: string;
10
- };
11
- 2: {
12
- message: string;
13
- };
14
- 3: {
15
- message: string;
16
- };
17
- 4: {
18
- message: string;
19
- };
20
- /**
21
- * `upgrade` rejected — no `propose_upgrade` was made before commit.
22
- */
23
- 5: {
24
- message: string;
25
- };
26
- /**
27
- * `upgrade` rejected — timelock has not elapsed yet.
28
- */
29
- 6: {
30
- message: string;
31
- };
32
- /**
33
- * `upgrade` rejected — `new_wasm_hash` does not match the proposed hash.
34
- */
35
- 7: {
36
- message: string;
37
- };
38
- };
39
- export type StorageKey = {
40
- tag: "Initialized";
41
- values: void;
42
- } | {
43
- tag: "ConfigManager";
44
- values: void;
45
- } | {
46
- tag: "Publisher";
47
- values: void;
48
- } | {
49
- tag: "Price";
50
- values: readonly [string];
51
- } | {
52
- tag: "LastUpdate";
53
- values: readonly [string];
54
- } | {
55
- tag: "Version";
56
- values: void;
57
- };
58
- /**
59
- * Authoritative per-market state: the side aggregates, the funding indices,
60
- * the funding EMA, and the market configuration.
61
- *
62
- * Soroban limits UDT field names to 30 characters, so where a doc glossary
63
- * term is longer the field drops the redundant qualifier and its doc
64
- * comment carries the full term (e.g. `receiver_backed_index_long` is the
65
- * doc's `receiver_backed_payer_index` for the long side).
66
- */
67
- export interface Market {
68
- config: MarketConfig;
69
- /**
70
- * `INDEX_PRECISION`-scaled bps/day payer rate as of the last refresh.
71
- */
72
- current_payer_rate: i128;
73
- current_payer_side: PayerSide;
74
- last_funding_checkpoint: u64;
75
- long: MarketSide;
76
- /**
77
- * Cumulative payer fee per unit of dominant-side size that is LP
78
- * revenue on collection (§8.2).
79
- */
80
- lp_backed_index_long: i128;
81
- lp_backed_index_short: i128;
82
- lp_payer_remainder: i128;
83
- /**
84
- * Sub-stroop carry of the receiver-liability accrual (§8.3).
85
- */
86
- pending_remainder: i128;
87
- /**
88
- * Cumulative payer fee per unit of dominant-side size whose collection
89
- * restores cash backing an already-accrued receiver claim (§8.2).
90
- */
91
- receiver_backed_index_long: i128;
92
- receiver_backed_index_short: i128;
93
- /**
94
- * Cumulative funding credit per unit of light-side size (§8.2).
95
- */
96
- receiver_index_long: i128;
97
- receiver_index_remainder: i128;
98
- receiver_index_short: i128;
99
- receiver_payer_remainder: i128;
100
- short: MarketSide;
101
- /**
102
- * §8.1 signed EMA of the instantaneous skew: a fraction of one at
103
- * `INDEX_PRECISION` scale, positive when history says longs dominate.
104
- * Decays toward the current skew with the global half-life.
105
- */
106
- skew_ema: i128;
107
- }
108
- export interface LpConfig {
109
- lp_request_delay: u64;
110
- max_withdraw_utilization_bps: u32;
111
- min_deposit_nav_factor_bps: u32;
112
- }
113
- /**
114
- * Represents a single trader's open leveraged position.
115
- */
116
- export interface Position {
117
- /**
118
- * Asset units at `PRICE_PRECISION`.
119
- */
120
- base_exposure: i128;
121
- borrow_debt: i128;
122
- /**
123
- * Cash owned by an optional-order executor.
124
- */
125
- execution_budget: i128;
126
- funding_paid_to_lps_debt: i128;
127
- funding_paid_to_receivers_debt: i128;
128
- funding_received_debt: i128;
129
- id: u64;
130
- is_long: boolean;
131
- last_increased_time: u64;
132
- market: string;
133
- owner: string;
134
- /**
135
- * Fixed gross capacity assigned when risk opens.
136
- */
137
- risk_units: i128;
138
- /**
139
- * USD notional at `PRICE_PRECISION`.
140
- */
141
- size: i128;
142
- /**
143
- * Trigger price for the optional stop-loss order; `0` = none.
144
- */
145
- stop_loss: i128;
146
- /**
147
- * Trader-owned collateral recorded in contract state (the doc's
148
- * "stored collateral"). Effective collateral — stored collateral after
149
- * pending fees and funding credits — is always derived, never stored.
150
- */
151
- stored_collateral: i128;
152
- /**
153
- * Trigger price for the optional take-profit order; `0` = none.
154
- */
155
- take_profit: i128;
156
- }
157
- export interface LpRequest {
158
- amount: i128;
159
- execute_after: u64;
160
- id: u64;
161
- kind: LpRequestKind;
162
- owner: string;
163
- request_time: u64;
164
- status: LpRequestStatus;
165
- }
166
- /**
167
- * Which side currently pays funding (§8.1: the side the blended integral
168
- * skew points at — under the EMA this can be the *lighter* side for a
169
- * while after the book flips). `None` when the blend is exactly zero.
170
- */
171
- export type PayerSide = {
172
- tag: "None";
173
- values: void;
174
- } | {
175
- tag: "Long";
176
- values: void;
177
- } | {
178
- tag: "Short";
179
- values: void;
180
- };
181
- export type RiskState = {
182
- tag: "Normal";
183
- values: void;
184
- } | {
185
- tag: "Warning";
186
- values: void;
187
- } | {
188
- tag: "Adl";
189
- values: void;
190
- } | {
191
- tag: "HardCap";
192
- values: void;
193
- };
194
- /**
195
- * A pending limit/stop entry order: the frozen `open_position` arguments
196
- * plus a trigger condition and an expiry. Placing one only writes this
197
- * record — no funds move. A keeper's `execute_entry_order` pulls the
198
- * collateral via the owner's token allowance and opens the position
199
- * exactly as a market open would.
200
- */
201
- export interface EntryOrder {
202
- acceptable_price: i128;
203
- collateral: i128;
204
- execution_budget: i128;
205
- /**
206
- * Ledger timestamp after which the order is dead and swept on the next
207
- * touch (user-configurable max TTL).
208
- */
209
- expires_at: u64;
210
- id: u64;
211
- is_long: boolean;
212
- market: string;
213
- owner: string;
214
- size: i128;
215
- stop_loss: i128;
216
- take_profit: i128;
217
- /**
218
- * True → fill when price ≥ trigger (stop/breakout entry); false → fill
219
- * when price ≤ trigger (limit/dip entry). Inferred at placement from
220
- * the trigger vs. the current price.
221
- */
222
- trigger_above: boolean;
223
- /**
224
- * The oracle price at which the order becomes fillable.
225
- */
226
- trigger_price: i128;
227
- }
228
- export interface MarketSide {
229
- base_exposure: i128;
230
- risk_state: RiskState;
231
- risk_units: i128;
232
- size_open_interest: i128;
233
- stored_collateral_total: i128;
234
- }
235
- export interface RoundPrice {
236
- price: i128;
237
- symbol: string;
238
- }
239
- export interface OracleRound {
240
- id: u64;
241
- previous_id: u64;
242
- previous_timestamp: u64;
243
- prices: Array<RoundPrice>;
244
- timestamp: u64;
245
- }
246
- export interface GlobalConfig {
247
- base_borrow_rate_bps_day: i128;
248
- /**
249
- * §9.2 borrow-curve exponent, bps: 20_000 = u² (legacy quadratic),
250
- * 10_000 = linear. Bounded to ≤ 100_000 (e ≤ 10) by validation.
251
- */
252
- borrow_exponent_bps: u32;
253
- /**
254
- * §8.1 half-life of the funding skew EMA, seconds (global: one memory
255
- * horizon for every market).
256
- */
257
- funding_half_life_seconds: u64;
258
- hard_cap_factor_limit_bps: u32;
259
- lp_revenue_share_bps: u32;
260
- max_active_markets: u32;
261
- max_adl_reward: i128;
262
- max_insolvent_touch_reward: i128;
263
- max_variable_borrow_bps_day: i128;
264
- /**
265
- * §11.2 minimum borrow charge per capitalization: an index delta at
266
- * `INDEX_PRECISION` scale applied to the position's risk units
267
- * (2e11 = 2 bps of notional at a 10% market risk factor). Zero
268
- * disables the floor.
269
- */
270
- min_borrow_index_delta: i128;
271
- min_collateral: i128;
272
- min_position_lifetime: u64;
273
- /**
274
- * §11.1 share of a closing fee routed to the trader's referrer, carved
275
- * from the protocol slice (keeper and LP shares are untouched). `0`
276
- * disables referral accrual globally — a kill switch. Validated so
277
- * `lp + keeper + referral ≤ BPS`, keeping the protocol remainder ≥ 0.
278
- */
279
- referral_fee_share_bps: u32;
280
- risk_capacity_limit_bps: u32;
281
- risk_keeper_revenue_share_bps: u32;
282
- }
283
- export interface MarketConfig {
284
- adl_pnl_factor_bps: u32;
285
- adl_reward_bps: u32;
286
- /**
287
- * §11.1 closing-fee tier when the close worsens skew.
288
- */
289
- close_fee_high_bps: u32;
290
- /**
291
- * §11.1 closing-fee tier when the close improves or preserves skew.
292
- */
293
- close_fee_low_bps: u32;
294
- hard_cap_pnl_factor_bps: u32;
295
- /**
296
- * Margin required to open or add risk (§12.3). Divides max leverage:
297
- * a position may not be created closer to liquidation than this.
298
- */
299
- initial_margin_bps: u32;
300
- /**
301
- * §8.1 weight of the instantaneous skew in the funding blend, in bps;
302
- * the rest is the half-life EMA. `BPS` reproduces pure instant skew.
303
- */
304
- instant_weight_bps: u32;
305
- liquidation_reward_bps: u32;
306
- /**
307
- * Margin below which the position is liquidatable (§12.3). Must not
308
- * exceed `initial_margin_bps`; the gap is the entry buffer.
309
- */
310
- maintenance_margin_bps: u32;
311
- market_risk_factor_bps: u32;
312
- max_funding_rate_bps_day: i128;
313
- max_long_base_exposure: i128;
314
- max_long_size_open_interest: i128;
315
- max_short_base_exposure: i128;
316
- max_short_size_open_interest: i128;
317
- recovery_pnl_factor_bps: u32;
318
- warning_pnl_factor_bps: u32;
319
- }
320
- /**
321
- * Global safety thresholds for price validation.
322
- */
323
- export interface OracleConfig {
324
- /**
325
- * How long a cached aggregated price remains valid after the router
326
- * fetch (in seconds). A cache hit also requires every source timestamp
327
- * used for the cached median to remain within `staleness_threshold`.
328
- * Must be > 0 and <= `staleness_threshold`.
329
- */
330
- cache_duration: u64;
331
- /**
332
- * Maximum allowed spread between oracle sources in basis points
333
- * (e.g., 100 = 1%). Bounded at `crate::constants::MAX_DEVIATION_BPS_CEILING`.
334
- */
335
- max_deviation_bps: i128;
336
- /**
337
- * Minimum number of source responses that must agree within
338
- * `max_deviation_bps` for OracleRouter to return a price. Floored at
339
- * `crate::constants::MIN_REQUIRED_SOURCES_FLOOR`, ceilinged at
340
- * `crate::constants::MAX_ORACLE_SOURCES`.
341
- */
342
- min_required_sources: u32;
343
- /**
344
- * Maximum age of an external SEP-40 price feed before it is rejected
345
- * as stale (in seconds).
346
- */
347
- staleness_threshold: u64;
348
- }
349
- export type LpRequestKind = {
350
- tag: "Deposit";
351
- values: void;
352
- } | {
353
- tag: "Withdrawal";
354
- values: void;
355
- };
356
- /**
357
- * Data required during a WASM migration. Single definition for all contracts.
358
- */
359
- export interface MigrationData {
360
- version: u32;
361
- }
362
- /**
363
- * Pending WASM upgrade — set by `propose_upgrade`, consumed by `upgrade`
364
- * (cleared atomically on a successful install), or cleared by `cancel_upgrade`.
365
- * Single shape across every protocol contract. Contracts store it at
366
- * the shared `pending_upgrade` Symbol key in their own instance storage (see
367
- * `crate::upgrade::pending_upgrade_key`). `upgrade` refuses to install
368
- * unless `pending.wasm_hash` matches the supplied hash and `now >= eta`.
369
- */
370
- export interface PendingUpgrade {
371
- eta: u64;
372
- wasm_hash: Buffer;
373
- }
374
- export type LpRequestStatus = {
375
- tag: "Pending";
376
- values: void;
377
- } | {
378
- tag: "Settled";
379
- values: void;
380
- } | {
381
- tag: "Failed";
382
- values: void;
383
- } | {
384
- tag: "Expired";
385
- values: void;
386
- };
387
- /**
388
- * The caller-supplied fields of a `place_entry_order` request, bundled so
389
- * the entry point stays within Soroban's parameter limit. `owner` and
390
- * `market` are passed alongside; `id` and `trigger_above` are derived at
391
- * placement.
392
- */
393
- export interface EntryOrderParams {
394
- acceptable_price: i128;
395
- collateral: i128;
396
- execution_budget: i128;
397
- expires_at: u64;
398
- is_long: boolean;
399
- size: i128;
400
- stop_loss: i128;
401
- take_profit: i128;
402
- trigger_price: i128;
403
- }
404
- export interface SettlementResult {
405
- /**
406
- * Shares minted for a deposit or assets paid for a withdrawal.
407
- */
408
- amount: i128;
409
- status: SettlementStatus;
410
- }
411
- export type SettlementStatus = {
412
- tag: "Settled";
413
- values: void;
414
- } | {
415
- tag: "Failed";
416
- values: void;
417
- };
418
- export interface AccountingSnapshot {
419
- cash_lp_equity: i128;
420
- cash_shortfall: i128;
421
- free_lp_capital: i128;
422
- lp_blocked_side_count: u32;
423
- non_lp_claims: i128;
424
- open_position_count: u64;
425
- physical_cash: i128;
426
- required_risk_backing: i128;
427
- total_risk_units: i128;
428
- vault_nav: i128;
429
- }
430
- export declare const UpgradeableError: {
431
- /**
432
- * When migration is attempted but not allowed due to upgrade state.
433
- */
434
- 1100: {
435
- message: string;
436
- };
437
- };
438
- export declare const MerkleDistributorError: {
439
- /**
440
- * The merkle root is not set.
441
- */
442
- 1300: {
443
- message: string;
444
- };
445
- /**
446
- * The provided index was already claimed.
447
- */
448
- 1301: {
449
- message: string;
450
- };
451
- /**
452
- * The proof is invalid.
453
- */
454
- 1302: {
455
- message: string;
456
- };
457
- };
458
- /**
459
- * Storage keys for the data associated with `MerkleDistributor`
460
- */
461
- export type MerkleDistributorStorageKey = {
462
- tag: "Root";
463
- values: void;
464
- } | {
465
- tag: "Claimed";
466
- values: readonly [u32];
467
- };
468
- /**
469
- * Rounding direction for division operations
470
- */
471
- export type Rounding = {
472
- tag: "Floor";
473
- values: void;
474
- } | {
475
- tag: "Ceil";
476
- values: void;
477
- } | {
478
- tag: "Truncate";
479
- values: void;
480
- };
481
- export declare const SorobanFixedPointError: {
482
- /**
483
- * Arithmetic overflow occurred
484
- */
485
- 1500: {
486
- message: string;
487
- };
488
- /**
489
- * Division by zero
490
- */
491
- 1501: {
492
- message: string;
493
- };
494
- };
495
- export declare const CryptoError: {
496
- /**
497
- * The merkle proof length is out of bounds.
498
- */
499
- 1400: {
500
- message: string;
501
- };
502
- /**
503
- * The index of the leaf is out of bounds.
504
- */
505
- 1401: {
506
- message: string;
507
- };
508
- /**
509
- * No data in hasher state.
510
- */
511
- 1402: {
512
- message: string;
513
- };
514
- };
515
- export declare const PausableError: {
516
- /**
517
- * The operation failed because the contract is paused.
518
- */
519
- 1000: {
520
- message: string;
521
- };
522
- /**
523
- * The operation failed because the contract is not paused.
524
- */
525
- 1001: {
526
- message: string;
527
- };
528
- };
529
- /**
530
- * Storage key for the pausable state
531
- */
532
- export type PausableStorageKey = {
533
- tag: "Paused";
534
- values: void;
535
- };
536
- export interface Client {
537
- /**
538
- * Construct and simulate a migrate 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.
539
- */
540
- migrate: ({ migration_data, operator }: {
541
- migration_data: MigrationData;
542
- operator: string;
543
- }, options?: MethodOptions) => Promise<AssembledTransaction<null>>;
544
- /**
545
- * Construct and simulate a upgrade 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.
546
- */
547
- upgrade: ({ new_wasm_hash, operator }: {
548
- new_wasm_hash: Buffer;
549
- operator: string;
550
- }, options?: MethodOptions) => Promise<AssembledTransaction<null>>;
551
- /**
552
- * Construct and simulate a decimals 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.
553
- */
554
- decimals: (options?: MethodOptions) => Promise<AssembledTransaction<u32>>;
555
- /**
556
- * Construct and simulate a get_price 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.
557
- */
558
- get_price: ({ symbol }: {
559
- symbol: string;
560
- }, options?: MethodOptions) => Promise<AssembledTransaction<i128>>;
561
- /**
562
- * Construct and simulate a set_price 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.
563
- */
564
- set_price: ({ caller, symbol, price }: {
565
- caller: string;
566
- symbol: string;
567
- price: i128;
568
- }, options?: MethodOptions) => Promise<AssembledTransaction<null>>;
569
- /**
570
- * Construct and simulate a last_update 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.
571
- */
572
- last_update: ({ symbol }: {
573
- symbol: string;
574
- }, options?: MethodOptions) => Promise<AssembledTransaction<u64>>;
575
- /**
576
- * Construct and simulate a set_publisher 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.
577
- */
578
- set_publisher: ({ caller, new_publisher }: {
579
- caller: string;
580
- new_publisher: string;
581
- }, options?: MethodOptions) => Promise<AssembledTransaction<null>>;
582
- /**
583
- * Construct and simulate a cancel_upgrade 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.
584
- */
585
- cancel_upgrade: ({ caller }: {
586
- caller: string;
587
- }, options?: MethodOptions) => Promise<AssembledTransaction<null>>;
588
- /**
589
- * Construct and simulate a propose_upgrade 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.
590
- */
591
- propose_upgrade: ({ caller, wasm_hash }: {
592
- caller: string;
593
- wasm_hash: Buffer;
594
- }, options?: MethodOptions) => Promise<AssembledTransaction<null>>;
595
- }
596
- export declare class Client extends ContractClient {
597
- readonly options: ContractClientOptions;
598
- static deploy<T = Client>(
599
- /** Constructor/Initialization Args for the contract's `__constructor` method */
600
- { config_manager, publisher }: {
601
- config_manager: string;
602
- publisher: string;
603
- },
604
- /** Options for initializing a Client as well as for calling a method, with extras specific to deploying. */
605
- options: MethodOptions & Omit<ContractClientOptions, "contractId"> & {
606
- /** The hash of the Wasm blob, which must already be installed on-chain. */
607
- wasmHash: Buffer | string;
608
- /** Salt used to generate the contract's ID. Passed through to {@link Operation.createCustomContract}. Default: random. */
609
- salt?: Buffer | Uint8Array;
610
- /** The format used to decode `wasmHash`, if it's provided as a string. */
611
- format?: "hex" | "base64";
612
- }): Promise<AssembledTransaction<T>>;
613
- constructor(options: ContractClientOptions);
614
- readonly fromJSON: {
615
- migrate: (json: string) => AssembledTransaction<null>;
616
- upgrade: (json: string) => AssembledTransaction<null>;
617
- decimals: (json: string) => AssembledTransaction<number>;
618
- get_price: (json: string) => AssembledTransaction<bigint>;
619
- set_price: (json: string) => AssembledTransaction<null>;
620
- last_update: (json: string) => AssembledTransaction<bigint>;
621
- set_publisher: (json: string) => AssembledTransaction<null>;
622
- cancel_upgrade: (json: string) => AssembledTransaction<null>;
623
- propose_upgrade: (json: string) => AssembledTransaction<null>;
624
- };
625
- }