@win-trader/bindings 0.0.2 → 0.0.4

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