@mysten/deepbook-v3 2.5.1 → 2.6.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.
- package/CHANGELOG.md +29 -0
- package/PREDICT.md +160 -12
- package/dist/contracts/account/account.d.mts +23 -23
- package/dist/contracts/account/account_events.d.mts +20 -20
- package/dist/contracts/account/account_events.d.mts.map +1 -1
- package/dist/contracts/account/account_registry.d.mts +13 -13
- package/dist/contracts/deepbook/balances.d.mts +4 -4
- package/dist/contracts/deepbook/order.d.mts +12 -12
- package/dist/contracts/deepbook_predict/admin.d.mts +4 -4
- package/dist/contracts/deepbook_predict/builder_code.d.mts +11 -11
- package/dist/contracts/deepbook_predict/builder_code.d.mts.map +1 -1
- package/dist/contracts/deepbook_predict/builder_code_events.d.mts +10 -10
- package/dist/contracts/deepbook_predict/config_events.d.mts +67 -67
- package/dist/contracts/deepbook_predict/expiry_market.d.mts +176 -96
- package/dist/contracts/deepbook_predict/expiry_market.d.mts.map +1 -1
- package/dist/contracts/deepbook_predict/expiry_market.mjs +114 -1
- package/dist/contracts/deepbook_predict/expiry_market.mjs.map +1 -1
- package/dist/contracts/deepbook_predict/market_lifecycle_cap.d.mts +5 -5
- package/dist/contracts/deepbook_predict/market_manager.d.mts +27 -27
- package/dist/contracts/deepbook_predict/order_events.d.mts +50 -50
- package/dist/contracts/deepbook_predict/pause_cap.d.mts +5 -5
- package/dist/contracts/deepbook_predict/plp.d.mts +72 -72
- package/dist/contracts/deepbook_predict/pool_valuation_cap.d.mts +5 -5
- package/dist/contracts/deepbook_predict/predict_account.d.mts +14 -14
- package/dist/contracts/deepbook_predict/pricing.d.mts +53 -53
- package/dist/contracts/deepbook_predict/protocol_config.d.mts +64 -64
- package/dist/contracts/deepbook_predict/range_codec.d.mts +2 -2
- package/dist/contracts/deepbook_predict/registry.d.mts +28 -28
- package/dist/contracts/deepbook_predict/strike_exposure.mjs +12 -0
- package/dist/contracts/deepbook_predict/strike_exposure.mjs.map +1 -1
- package/dist/contracts/deepbook_predict/vault_events.d.mts +105 -105
- package/dist/contracts/deepbook_sessions/session_config.d.mts +4 -4
- package/dist/contracts/deepbook_sessions/sessions.d.mts +35 -10
- package/dist/contracts/deepbook_sessions/sessions.d.mts.map +1 -1
- package/dist/contracts/deepbook_sessions/sessions.mjs +44 -1
- package/dist/contracts/deepbook_sessions/sessions.mjs.map +1 -1
- package/dist/deployments/mainnet.d.mts.map +1 -1
- package/dist/deployments/mainnet.mjs +2 -0
- package/dist/deployments/mainnet.mjs.map +1 -1
- package/dist/deployments/testnet.d.mts.map +1 -1
- package/dist/deployments/testnet.mjs +4 -2
- package/dist/deployments/testnet.mjs.map +1 -1
- package/dist/deployments/types.d.mts +1 -1
- package/dist/predict/client.d.mts +12 -3
- package/dist/predict/client.d.mts.map +1 -1
- package/dist/predict/client.mjs +39 -18
- package/dist/predict/client.mjs.map +1 -1
- package/dist/predict/config/generated.d.mts +3 -2
- package/dist/predict/config/generated.d.mts.map +1 -1
- package/dist/predict/config/generated.mjs +1 -0
- package/dist/predict/config/generated.mjs.map +1 -1
- package/dist/predict/config/types.d.mts +3 -0
- package/dist/predict/config/types.d.mts.map +1 -1
- package/dist/predict/cost.d.mts +353 -0
- package/dist/predict/cost.d.mts.map +1 -0
- package/dist/predict/cost.mjs +555 -0
- package/dist/predict/cost.mjs.map +1 -0
- package/dist/predict/decode.mjs +6 -7
- package/dist/predict/decode.mjs.map +1 -1
- package/dist/predict/index.d.mts +3 -2
- package/dist/predict/index.mjs +2 -1
- package/dist/predict/pricing.mjs +1 -1
- package/dist/predict/reads/positions.mjs +1 -1
- package/dist/predict/reads/positions.mjs.map +1 -1
- package/dist/predict/tx/trade.d.mts.map +1 -1
- package/dist/predict/tx/trade.mjs +18 -2
- package/dist/predict/tx/trade.mjs.map +1 -1
- package/dist/sessions.d.mts +17 -1
- package/dist/sessions.d.mts.map +1 -1
- package/dist/sessions.mjs +22 -2
- package/dist/sessions.mjs.map +1 -1
- package/dist/transactions/balanceManager.d.mts +12 -12
- package/dist/transactions/deepbook.d.mts +20 -20
- package/dist/transactions/deepbookAdmin.d.mts +4 -4
- package/dist/transactions/deepbookAdmin.d.mts.map +1 -1
- package/dist/transactions/marginAdmin.d.mts +7 -7
- package/dist/transactions/marginAdmin.d.mts.map +1 -1
- package/dist/transactions/marginLiquidations.d.mts +3 -3
- package/dist/transactions/marginMaintainer.d.mts +5 -5
- package/dist/transactions/marginMaintainer.d.mts.map +1 -1
- package/dist/transactions/marginManager.d.mts +32 -32
- package/dist/transactions/marginPool.d.mts +18 -18
- package/dist/transactions/marginRegistry.d.mts +16 -16
- package/dist/transactions/marginTPSL.d.mts +10 -10
- package/dist/transactions/poolProxy.d.mts +8 -8
- package/package.json +2 -2
- package/src/contracts/deepbook_predict/expiry_market.ts +160 -0
- package/src/contracts/deepbook_predict/strike_exposure.ts +14 -0
- package/src/contracts/deepbook_sessions/sessions.ts +68 -0
- package/src/deployments/mainnet.ts +4 -1
- package/src/deployments/testnet.ts +6 -3
- package/src/deployments/types.ts +4 -2
- package/src/predict/client.ts +80 -27
- package/src/predict/config/generated.ts +4 -2
- package/src/predict/config/types.ts +3 -0
- package/src/predict/cost.ts +1022 -0
- package/src/predict/decode.ts +8 -8
- package/src/predict/index.ts +9 -0
- package/src/predict/reads/positions.ts +1 -1
- package/src/predict/tx/trade.ts +30 -1
- package/src/sessions.ts +37 -2
|
@@ -0,0 +1,353 @@
|
|
|
1
|
+
import { PricerInputs } from "./pricing.mjs";
|
|
2
|
+
import { POS_INF_TICK } from "./ticks.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/predict/cost.d.ts
|
|
5
|
+
declare namespace cost_d_exports {
|
|
6
|
+
export { BUILDER_FEE_MULTIPLIER, Boundaries, CloseBookTerms, CongestionPolicy, CongestionState, FEE_INCENTIVE_SUBSIDY_RATE, FLOAT_SCALING, FeePolicy, MAX_BUILDER_FEE_RATE, MAX_QUANTITY_LOTS, MIN_PREMIUM, MintBookTerms, MintBudgetCost, MintBudgetInputs, MintCost, MintCostInputs, OrderRange, POSITION_LOT_SIZE, POS_INF_TICK, ProbabilitySource, RedeemLiveInputs, RedeemLiveProceeds, SHIPPED_FEE_POLICY, bernoulliFeeRate, boundaryProbabilities, builderFee, closeInventoryImpact, congestionPenaltyRate, decodeOrderRange, expiryFeeMultiplier, feeIncentiveSubsidy, inventoryImpactPotential, mintCost, mintCostForBudget, mintInventoryImpact, orderStrikes, rangeProbability, redeemLiveProceeds, sqrtDown, tradingFee };
|
|
7
|
+
}
|
|
8
|
+
/** `math::float_scaling` — 1e9 is 1.0 for every rate and probability here. */
|
|
9
|
+
declare const FLOAT_SCALING = 1000000000n;
|
|
10
|
+
/** `constants::position_lot_size` — quantity is an integer number of these. */
|
|
11
|
+
declare const POSITION_LOT_SIZE = 10000n;
|
|
12
|
+
/** `constants::min_premium` — a mint below this premium aborts `EPremiumBelowMinimum`. */
|
|
13
|
+
declare const MIN_PREMIUM = 1000000n;
|
|
14
|
+
/** `constants::builder_fee_multiplier` — the builder's cut of the trading fee (10%). */
|
|
15
|
+
declare const BUILDER_FEE_MULTIPLIER = 100000000n;
|
|
16
|
+
/** `constants::max_builder_fee_rate` — cap on the builder fee as a share of quantity (0.5%). */
|
|
17
|
+
declare const MAX_BUILDER_FEE_RATE = 5000000n;
|
|
18
|
+
/** `constants::fee_incentive_subsidy_rate` — sponsor share of a trader's mint fee (20%). */
|
|
19
|
+
declare const FEE_INCENTIVE_SUBSIDY_RATE = 200000000n;
|
|
20
|
+
/** `order::max_quantity_lots` — the order ID's 32-bit lot field. */
|
|
21
|
+
declare const MAX_QUANTITY_LOTS: bigint;
|
|
22
|
+
/** `math::sqrt_down` — square root of a 1e9-scaled value, 1e9-scaled, rounded down. */
|
|
23
|
+
declare function sqrtDown(x: bigint): bigint;
|
|
24
|
+
/**
|
|
25
|
+
* One market's fee policy: the `StrikeExposureConfig` it snapshotted at creation, in raw 1e9
|
|
26
|
+
* rates. Snapshotted means later admin changes do NOT reprice a market already trading, so
|
|
27
|
+
* read it per market (the `MarketCreated` event carries every field) rather than assuming the
|
|
28
|
+
* template. The last three are the inventory-impact parameters, inert while
|
|
29
|
+
* `inventoryImpactMaxRate` is `0n` (the shipped value).
|
|
30
|
+
*/
|
|
31
|
+
interface FeePolicy {
|
|
32
|
+
/** `base_fee` — multiplies `sqrt(p·(1−p))`. */
|
|
33
|
+
baseFee: bigint;
|
|
34
|
+
/** `min_fee` — per-unit floor, applied per boundary leg before the ramp. */
|
|
35
|
+
minFee: bigint;
|
|
36
|
+
/** `expiry_fee_window_ms` — window before expiry over which the fee ramps. */
|
|
37
|
+
expiryFeeWindowMs: bigint;
|
|
38
|
+
/** `expiry_fee_max_multiplier` — multiplier reached at expiry; 1e9 disables the ramp. */
|
|
39
|
+
expiryFeeMaxMultiplier: bigint;
|
|
40
|
+
/** `min_entry_probability` — mint admission floor on the entry probability. */
|
|
41
|
+
minEntryProbability: bigint;
|
|
42
|
+
/** `max_entry_probability` — mint admission ceiling on the entry probability. */
|
|
43
|
+
maxEntryProbability: bigint;
|
|
44
|
+
/** `inventory_impact_max_rate` — maximum marginal impact rate; `0n` disables impact. */
|
|
45
|
+
inventoryImpactMaxRate: bigint;
|
|
46
|
+
/** `inventory_impact_scale` — the market's `max_expiry_allocation`, the curve's `B`. */
|
|
47
|
+
inventoryImpactScale: bigint;
|
|
48
|
+
/** `backing_buffer_lambda` — the buffer on non-peak payout in the liability formula. */
|
|
49
|
+
backingBufferLambda: bigint;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* The shipped template (`config_constants` defaults): 10% Bernoulli fee, a 2.2% per-leg floor,
|
|
53
|
+
* a one-day ramp window that is inert at a 1.0 multiplier, a 1%–99% entry band, and inventory
|
|
54
|
+
* impact disabled. A market that was created under these values charges exactly this; one
|
|
55
|
+
* created after an admin change does not, which is why the per-market snapshot is the real
|
|
56
|
+
* answer. Verify against the deployment's `MarketCreated` before pricing money on it.
|
|
57
|
+
*/
|
|
58
|
+
declare const SHIPPED_FEE_POLICY: FeePolicy;
|
|
59
|
+
/** A range's two boundary UP probabilities, raw 1e9. `null` is an infinite boundary — the
|
|
60
|
+
* −∞ lower of a DOWN order and the +∞ higher of an UP order — which is priced at the digital
|
|
61
|
+
* limit and pays no fee leg. */
|
|
62
|
+
interface Boundaries {
|
|
63
|
+
/** `P(settle > lower)`, or `null` for the −∞ lower bound. */
|
|
64
|
+
lowerUp: bigint | null;
|
|
65
|
+
/** `P(settle > higher)`, or `null` for the +∞ higher bound. */
|
|
66
|
+
higherUp: bigint | null;
|
|
67
|
+
}
|
|
68
|
+
/** Where a quote's probabilities come from: boundary probabilities you already hold (raw 1e9,
|
|
69
|
+
* e.g. `probabilityToRaw((await read.price(...)).up)`) or a local pricer snapshot plus
|
|
70
|
+
* the range's strikes in USD (`null` for an infinite side). */
|
|
71
|
+
type ProbabilitySource = Boundaries | {
|
|
72
|
+
pricer: PricerInputs;
|
|
73
|
+
lower: number | null;
|
|
74
|
+
upper: number | null;
|
|
75
|
+
};
|
|
76
|
+
/** The market's gas-price EWMA (`ewma::EwmaState`), both fields 1e9-scaled. */
|
|
77
|
+
interface CongestionState {
|
|
78
|
+
mean: bigint;
|
|
79
|
+
variance: bigint;
|
|
80
|
+
}
|
|
81
|
+
/** The protocol's congestion knobs (`EwmaConfig`). Shipped disabled. */
|
|
82
|
+
interface CongestionPolicy {
|
|
83
|
+
enabled: boolean;
|
|
84
|
+
/** `penalty_rate` — per-unit surcharge charged when the z-score fires. */
|
|
85
|
+
penaltyRate: bigint;
|
|
86
|
+
/** `z_score_threshold` — how many standard deviations above the mean gas must sit. */
|
|
87
|
+
zScoreThreshold: bigint;
|
|
88
|
+
}
|
|
89
|
+
/** Pre-trade payout-tree reads a mint's inventory-impact charge is evaluated against
|
|
90
|
+
* (`strike_exposure::quote_mint_range`). All in quote units. */
|
|
91
|
+
interface MintBookTerms {
|
|
92
|
+
/** `M` — largest summed net payout at any one settlement price. */
|
|
93
|
+
maxPayout: bigint;
|
|
94
|
+
/** `T` — sum of every live order's payout. */
|
|
95
|
+
totalPayout: bigint;
|
|
96
|
+
/** The payout peak inside the mint's own `(lower, higher]`. */
|
|
97
|
+
rangeMaxPayout: bigint;
|
|
98
|
+
}
|
|
99
|
+
/** The same reads for a live close, which also needs the peak OUTSIDE the order's range
|
|
100
|
+
* (`strike_exposure::live_close_inventory_impact`). */
|
|
101
|
+
interface CloseBookTerms extends MintBookTerms {
|
|
102
|
+
/** The payout peak in the complement of the order's range. */
|
|
103
|
+
complementMaxPayout: bigint;
|
|
104
|
+
}
|
|
105
|
+
/** `strike_exposure_config::raw_bernoulli_fee_rate` — `base_fee · sqrt(p·(1−p))`, the fee rate
|
|
106
|
+
* before the `min_fee` floor and the expiry ramp. Zero at the certain ends. */
|
|
107
|
+
declare function bernoulliFeeRate(baseFee: bigint, probability: bigint): bigint;
|
|
108
|
+
/** `strike_exposure_config::expiry_fee_multiplier` — 1.0 outside the window, rising linearly
|
|
109
|
+
* to `expiry_fee_max_multiplier` at expiry. */
|
|
110
|
+
declare function expiryFeeMultiplier(policy: FeePolicy, timeToExpiryMs: bigint): bigint;
|
|
111
|
+
/**
|
|
112
|
+
* `strike_exposure_config::trading_fee` — the fee for a whole range, charged PER FINITE
|
|
113
|
+
* BOUNDARY with each leg floored and ramped independently. A binary order has one finite
|
|
114
|
+
* boundary and pays one leg; a two-sided range pays two, so it is not the same fee as the
|
|
115
|
+
* range's own probability would suggest.
|
|
116
|
+
*/
|
|
117
|
+
declare function tradingFee(policy: FeePolicy, boundaries: Boundaries, quantity: bigint, timeToExpiryMs: bigint): bigint;
|
|
118
|
+
/** `expiry_market::builder_fee_amount` — an account carrying a builder code pays the builder a
|
|
119
|
+
* multiple of its trading fee, capped as a share of quantity. */
|
|
120
|
+
declare function builderFee(fee: bigint, quantity: bigint, hasBuilderCode: boolean): bigint;
|
|
121
|
+
/** `expiry_market::fee_incentive_subsidy_amount` — a sponsor pays part of the trader's MINT
|
|
122
|
+
* fee, bounded by the expiry's remaining sponsored balance. Mints only; redeems pay in full. */
|
|
123
|
+
declare function feeIncentiveSubsidy(fee: bigint, feeIncentiveBalance: bigint): bigint;
|
|
124
|
+
/**
|
|
125
|
+
* `ewma::penalty_fee`'s firing test, as a per-unit RATE: `penalty_rate` when the transaction's
|
|
126
|
+
* gas price is a high outlier against the market's pre-trade EWMA, else zero. It is a rate and
|
|
127
|
+
* not an amount because the surcharge is `rate · quantity`, and a budget search has to reprice
|
|
128
|
+
* it at every candidate quantity. `gasPrice` is the raw reference gas price (not 1e9-scaled),
|
|
129
|
+
* as `tx_context::gas_price` reports it.
|
|
130
|
+
*/
|
|
131
|
+
declare function congestionPenaltyRate(policy: CongestionPolicy, state: CongestionState, gasPrice: bigint): bigint;
|
|
132
|
+
/**
|
|
133
|
+
* `strike_exposure::inventory_impact_potential_for_liability` — the book-level potential
|
|
134
|
+
* `phi(L)`: marginal rate rising linearly to `inventory_impact_max_rate` over the scale `B`,
|
|
135
|
+
* flat at the cap above it. Trades are charged the DIFFERENCE of two evaluations, which is
|
|
136
|
+
* what makes inventory cycles telescope to zero.
|
|
137
|
+
*/
|
|
138
|
+
declare function inventoryImpactPotential(policy: FeePolicy, liability: bigint): bigint;
|
|
139
|
+
/** `strike_exposure::mint_range_inventory_impact` — the charge a mint of `quantity` over a
|
|
140
|
+
* range pays: the exact rise in the book potential. Zero at the shipped rate of `0n`. */
|
|
141
|
+
declare function mintInventoryImpact(policy: FeePolicy, book: MintBookTerms, quantity: bigint): bigint;
|
|
142
|
+
/** `strike_exposure::live_close_inventory_impact` — the rebate a live close of `payout`
|
|
143
|
+
* receives: the exact fall in the same potential. Zero at the shipped rate of `0n`. */
|
|
144
|
+
declare function closeInventoryImpact(policy: FeePolicy, book: CloseBookTerms, payout: bigint): bigint;
|
|
145
|
+
/** `pricing::probability` — the range's own probability, `up(lower) − up(higher)` with the
|
|
146
|
+
* chain's saturating subtraction and its infinite-boundary defaults. */
|
|
147
|
+
declare function rangeProbability(boundaries: Boundaries): bigint;
|
|
148
|
+
/** Price a range's two boundaries with the local float pricer. `lower`/`upper` are strikes in
|
|
149
|
+
* USD; pass `null` for an infinite side (`{ lower: strike, upper: null }` is an UP order,
|
|
150
|
+
* `{ lower: null, upper: strike }` a DOWN order). Carries the pricer's ~1e-4 approximation. */
|
|
151
|
+
declare function boundaryProbabilities(pricer: PricerInputs, lower: number | null, upper: number | null): Boundaries;
|
|
152
|
+
/** Inputs shared by the exact-quantity mint quote and the budget-sized one. */
|
|
153
|
+
interface MintInputsBase {
|
|
154
|
+
/** The market's snapshotted fee policy. */
|
|
155
|
+
fees: FeePolicy;
|
|
156
|
+
/** Market expiry, ms since epoch. */
|
|
157
|
+
expiryMs: number | bigint;
|
|
158
|
+
/** The clock the trade will price against, ms since epoch. Defaults to `Date.now()`. */
|
|
159
|
+
nowMs?: number | bigint;
|
|
160
|
+
/** Boundary probabilities, or a pricer snapshot plus the range's strikes. */
|
|
161
|
+
probabilities: ProbabilitySource;
|
|
162
|
+
/** Whether the minting account carries a builder code (it pays the builder fee). */
|
|
163
|
+
builderCode?: boolean;
|
|
164
|
+
/** The expiry's remaining sponsored fee balance (`fee_incentive_balance`). Default `0n`. */
|
|
165
|
+
feeIncentiveBalance?: number | bigint;
|
|
166
|
+
/** Per-unit congestion surcharge rate — see {@link congestionPenaltyRate}. Default `0n`. */
|
|
167
|
+
penaltyRate?: bigint;
|
|
168
|
+
/** Pre-trade payout-tree terms. Required when inventory impact is enabled. */
|
|
169
|
+
book?: MintBookTerms;
|
|
170
|
+
/** The deployment's `position_lot_size`. Defaults to the Move constant, `10_000n`. */
|
|
171
|
+
lotSize?: bigint;
|
|
172
|
+
}
|
|
173
|
+
/** Inputs for {@link mintCost}: an exact payout quantity. */
|
|
174
|
+
interface MintCostInputs extends MintInputsBase {
|
|
175
|
+
/** Maximum payout bought, in quote units — `number` is human USD, `bigint` is raw. */
|
|
176
|
+
quantity: number | bigint;
|
|
177
|
+
}
|
|
178
|
+
/** Inputs for {@link mintCostForBudget}: an all-in budget, the `mint_exact_cost` shape. */
|
|
179
|
+
interface MintBudgetInputs extends MintInputsBase {
|
|
180
|
+
/** The total to spend, fees included. */
|
|
181
|
+
budget: number | bigint;
|
|
182
|
+
/** Floor on the fill; a smaller result aborts, as `mint_exact_cost` does. Default one lot. */
|
|
183
|
+
minQuantity?: number | bigint;
|
|
184
|
+
/** The account's settled USDC. The chain caps the budget at it before sizing; pass it to
|
|
185
|
+
* reproduce that cap (and to let `U64_MAX` mean "my whole balance"). */
|
|
186
|
+
accountBalance?: number | bigint;
|
|
187
|
+
}
|
|
188
|
+
/** One mint's cost decomposition — the fields of the chain's `MintQuote`, in human units with
|
|
189
|
+
* the exact integers alongside. `cost` is the account debit. */
|
|
190
|
+
interface MintCost {
|
|
191
|
+
/** Maximum payout bought (human quote units). */
|
|
192
|
+
quantity: number;
|
|
193
|
+
/** Fill price, 0..1 per $1 of payout, before fees. */
|
|
194
|
+
entryProbability: number;
|
|
195
|
+
/** Premium into LP backing. */
|
|
196
|
+
premium: number;
|
|
197
|
+
/** `referral` is not here: it is a split of protocol proceeds, not a trader debit. */
|
|
198
|
+
fees: {
|
|
199
|
+
trading: number;
|
|
200
|
+
subsidy: number;
|
|
201
|
+
builder: number;
|
|
202
|
+
penalty: number;
|
|
203
|
+
impact: number;
|
|
204
|
+
};
|
|
205
|
+
/** All-in account debit: `premium + (trading − subsidy) + builder + penalty + impact`. */
|
|
206
|
+
cost: number;
|
|
207
|
+
/** All-in price per $1 of payout — `cost / quantity`, the number to compare across venues. */
|
|
208
|
+
costPerContract: number;
|
|
209
|
+
/** Maximum payout divided by the all-in debit, including fees. */
|
|
210
|
+
payoutMultiple: number;
|
|
211
|
+
raw: {
|
|
212
|
+
quantity: bigint;
|
|
213
|
+
entryProbability: bigint;
|
|
214
|
+
premium: bigint;
|
|
215
|
+
tradingFee: bigint;
|
|
216
|
+
subsidy: bigint;
|
|
217
|
+
builderFee: bigint;
|
|
218
|
+
penaltyFee: bigint;
|
|
219
|
+
impactCharge: bigint;
|
|
220
|
+
cost: bigint;
|
|
221
|
+
};
|
|
222
|
+
/** True when boundary probabilities were supplied as raw integers rather than priced
|
|
223
|
+
* locally in float. Does not verify their source, freshness or the other quote inputs. */
|
|
224
|
+
exactProbabilities: boolean;
|
|
225
|
+
}
|
|
226
|
+
/** Budget-sized mint plus the budget information needed to render an order preview. */
|
|
227
|
+
interface MintBudgetCost extends Omit<MintCost, 'raw'> {
|
|
228
|
+
/** Requested all-in budget, before the optional account-balance cap. */
|
|
229
|
+
budget: number;
|
|
230
|
+
/** Budget after the optional account-balance cap. */
|
|
231
|
+
effectiveBudget: number;
|
|
232
|
+
/** Requested budget minus actual cost, including any balance-cap shortfall. */
|
|
233
|
+
unspentBudget: number;
|
|
234
|
+
raw: MintCost['raw'] & {
|
|
235
|
+
budget: bigint;
|
|
236
|
+
effectiveBudget: bigint;
|
|
237
|
+
unspentBudget: bigint;
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* All-in cost of minting an exact payout quantity — the `mint_exact_quantity` shape, priced
|
|
242
|
+
* entirely client-side. Mirrors `compute_mint_quote`, including its admission checks: the
|
|
243
|
+
* entry-probability band on each finite leg and on the range, the `min_premium` floor, the lot
|
|
244
|
+
* grid, and the `all_in_cost <= quantity` bound (a contract may never cost more than it can
|
|
245
|
+
* pay out). Each violation throws the `PredictInputError` naming the abort the chain would
|
|
246
|
+
* have raised.
|
|
247
|
+
*/
|
|
248
|
+
declare function mintCost(inputs: MintCostInputs): MintCost;
|
|
249
|
+
/**
|
|
250
|
+
* A fill whose ALL-IN cost fits a budget — `expiry_market::mint_exact_cost` computed
|
|
251
|
+
* client-side, with the same lot search over the same cost function, so the answer is the
|
|
252
|
+
* quantity that entrypoint would size and the cost it would debit.
|
|
253
|
+
*
|
|
254
|
+
* Without it a "spend exactly $X" flow has to guess: every fee is charged ON TOP of the
|
|
255
|
+
* premium, so the caller subtracts an estimated fee load, pads it against an abort, and
|
|
256
|
+
* systematically underspends. Here the whole search runs locally; submit the all-in budget
|
|
257
|
+
* through `tx.mintCost` on deployments carrying `mint_exact_cost`.
|
|
258
|
+
*
|
|
259
|
+
* Sizing also respects the fill's maximum payout and the 32-bit lot cap; either can leave
|
|
260
|
+
* substantial budget unspent. When only the budget binds, one more lot would exceed it.
|
|
261
|
+
* If the budget fill exceeds its maximum payout, the contract's step-down is best effort:
|
|
262
|
+
* rounding can make it miss a larger admissible fill, including one meeting `minQuantity`.
|
|
263
|
+
* The chain caps the budget at the account balance first ({@link MintBudgetInputs.accountBalance}).
|
|
264
|
+
*/
|
|
265
|
+
declare function mintCostForBudget(inputs: MintBudgetInputs): MintBudgetCost;
|
|
266
|
+
/** Inputs for {@link redeemLiveProceeds}. The range is the ORDER's own range — the same two
|
|
267
|
+
* boundaries it was minted over, which is what `redeem_live` reprices. */
|
|
268
|
+
interface RedeemLiveInputs {
|
|
269
|
+
fees: FeePolicy;
|
|
270
|
+
expiryMs: number | bigint;
|
|
271
|
+
nowMs?: number | bigint;
|
|
272
|
+
/** The order's boundary probabilities now, or a pricer snapshot plus the order's strikes. */
|
|
273
|
+
probabilities: ProbabilitySource;
|
|
274
|
+
/** Payout being closed — the whole order, or part of it. */
|
|
275
|
+
closeQuantity: number | bigint;
|
|
276
|
+
/** Current position payout quantity, when known. Validates the close and returns the remainder. */
|
|
277
|
+
positionQuantity?: number | bigint;
|
|
278
|
+
builderCode?: boolean;
|
|
279
|
+
penaltyRate?: bigint;
|
|
280
|
+
/** Pre-trade payout-tree terms. Required when inventory impact is enabled. */
|
|
281
|
+
book?: CloseBookTerms;
|
|
282
|
+
lotSize?: bigint;
|
|
283
|
+
}
|
|
284
|
+
/** What a live close credits the account, decomposed. */
|
|
285
|
+
interface RedeemLiveProceeds {
|
|
286
|
+
/** NET credited to the account. */
|
|
287
|
+
proceeds: number;
|
|
288
|
+
/** Close value before fees: the range's current probability times the closed payout. */
|
|
289
|
+
gross: number;
|
|
290
|
+
fees: {
|
|
291
|
+
trading: number;
|
|
292
|
+
builder: number;
|
|
293
|
+
penalty: number;
|
|
294
|
+
impactRebate: number;
|
|
295
|
+
};
|
|
296
|
+
quantityClosed: number;
|
|
297
|
+
/** Unclosed payout quantity, or null when positionQuantity was not supplied. */
|
|
298
|
+
remainingQuantity: number | null;
|
|
299
|
+
/** Net credited per $1 of closed payout; includes fees and the inventory rebate. */
|
|
300
|
+
proceedsPerContract: number;
|
|
301
|
+
/** Current range probability, 0..1, before amount rounding and fees. */
|
|
302
|
+
probability: number;
|
|
303
|
+
raw: {
|
|
304
|
+
proceeds: bigint;
|
|
305
|
+
gross: bigint;
|
|
306
|
+
tradingFee: bigint;
|
|
307
|
+
builderFee: bigint;
|
|
308
|
+
penaltyFee: bigint;
|
|
309
|
+
impactRebate: bigint;
|
|
310
|
+
quantityClosed: bigint;
|
|
311
|
+
remainingQuantity: bigint | null; /** 1e9-scaled range probability; locally priced inputs remain approximate. */
|
|
312
|
+
probability: bigint;
|
|
313
|
+
};
|
|
314
|
+
/** Identifies raw probability inputs; does not verify their source or state freshness. */
|
|
315
|
+
exactProbabilities: boolean;
|
|
316
|
+
}
|
|
317
|
+
/**
|
|
318
|
+
* Net proceeds of closing a live position — `expiry_market::redeem_live`'s payment
|
|
319
|
+
* decomposition, client-side. The mirror of {@link mintCost}: the same per-boundary trading
|
|
320
|
+
* fee and builder fee, the same congestion surcharge, and the inventory-impact term as a
|
|
321
|
+
* REBATE rather than a charge. There is no sponsor subsidy on a close (incentives subsidise
|
|
322
|
+
* mints only), and each deduction is clamped at the payout remaining after the ones before it,
|
|
323
|
+
* exactly as the contract clamps them, so a close can never cost more than it releases.
|
|
324
|
+
*
|
|
325
|
+
* Use this for a local UI preview from a supplied snapshot. `read.quoteRedeem` simulates
|
|
326
|
+
* the actual close and remains the pre-trade check for ownership, remaining position size,
|
|
327
|
+
* live-market gates and current fees. `proceeds` is what `min_proceeds` is compared against
|
|
328
|
+
* on the real call; this preview does not guarantee execution at that amount.
|
|
329
|
+
*/
|
|
330
|
+
declare function redeemLiveProceeds(inputs: RedeemLiveInputs): RedeemLiveProceeds;
|
|
331
|
+
/** The contract terms packed into an order ID (`deepbook_predict::order`). Tick `0` as the
|
|
332
|
+
* lower bound is −∞ and {@link POS_INF_TICK} as the higher is +∞; multiply a finite tick by
|
|
333
|
+
* the market's `tickSize` for its raw strike. Use it to feed a position from `read.positions`
|
|
334
|
+
* into {@link redeemLiveProceeds}. */
|
|
335
|
+
interface OrderRange {
|
|
336
|
+
lowerTick: bigint;
|
|
337
|
+
higherTick: bigint;
|
|
338
|
+
/** Minted payout: `quantity_lots · position_lot_size`. */
|
|
339
|
+
quantity: bigint;
|
|
340
|
+
}
|
|
341
|
+
/** Decode an order ID's range and quantity — the TypeScript mirror of `order::lower_tick` /
|
|
342
|
+
* `higher_tick` / `quantity`. */
|
|
343
|
+
declare function decodeOrderRange(orderId: bigint, lotSize?: bigint): OrderRange;
|
|
344
|
+
/** The strikes an {@link OrderRange} prices against, in USD, with `null` for each infinite
|
|
345
|
+
* side — the shape {@link boundaryProbabilities} takes. `tickSize` is the market's raw tick
|
|
346
|
+
* size (`ActiveMarket.tickSize` in USD, or the raw value from the deployment). */
|
|
347
|
+
declare function orderStrikes(range: OrderRange, tickSizeRaw: bigint): {
|
|
348
|
+
lower: number | null;
|
|
349
|
+
upper: number | null;
|
|
350
|
+
};
|
|
351
|
+
//#endregion
|
|
352
|
+
export { cost_d_exports };
|
|
353
|
+
//# sourceMappingURL=cost.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cost.d.mts","names":[],"sources":["../../src/predict/cost.ts"],"mappings":";;;;;;;;cA8Ca,aAAA;;cAEA,iBAAA;;cAEA,WAAA;;cAEA,sBAAA;;cAEA,oBAAA;;cAEA,0BAAA;;cAEA,iBAAA;;iBAgEG,QAAA,CAAS,CAAA;;;;;;;;UAcR,SAAA;;EAEhB,OAAA;;EAEA,MAAA;;EAEA,iBAA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