@mysten/deepbook-v3 2.6.4 → 2.8.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 +153 -0
- package/PREDICT.md +389 -61
- package/dist/contracts/account/account.d.mts +23 -23
- package/dist/contracts/account/account.d.mts.map +1 -1
- package/dist/contracts/account/account_registry.d.mts +13 -13
- package/dist/contracts/deepbook/account.d.mts +18 -18
- package/dist/contracts/deepbook/balances.d.mts +4 -4
- package/dist/contracts/deepbook/deep_price.d.mts +3 -3
- 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_events.d.mts +10 -10
- package/dist/contracts/deepbook_predict/config_events.d.mts +93 -68
- package/dist/contracts/deepbook_predict/config_events.d.mts.map +1 -1
- package/dist/contracts/deepbook_predict/config_events.mjs +45 -1
- package/dist/contracts/deepbook_predict/config_events.mjs.map +1 -1
- package/dist/contracts/deepbook_predict/deps/std/type_name.mjs +17 -0
- package/dist/contracts/deepbook_predict/deps/std/type_name.mjs.map +1 -0
- package/dist/contracts/deepbook_predict/expiry_market.d.mts +652 -235
- package/dist/contracts/deepbook_predict/expiry_market.d.mts.map +1 -1
- package/dist/contracts/deepbook_predict/expiry_market.mjs +652 -186
- package/dist/contracts/deepbook_predict/expiry_market.mjs.map +1 -1
- package/dist/contracts/deepbook_predict/lp_book.mjs +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/order_events.d.mts.map +1 -1
- package/dist/contracts/deepbook_predict/order_events.mjs +3 -1
- package/dist/contracts/deepbook_predict/order_events.mjs.map +1 -1
- package/dist/contracts/deepbook_predict/pause_cap.d.mts +5 -5
- package/dist/contracts/deepbook_predict/plp.d.mts +184 -82
- package/dist/contracts/deepbook_predict/plp.d.mts.map +1 -1
- package/dist/contracts/deepbook_predict/plp.mjs +126 -7
- package/dist/contracts/deepbook_predict/plp.mjs.map +1 -1
- package/dist/contracts/deepbook_predict/pool_accounting.mjs +1 -1
- 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 +91 -58
- package/dist/contracts/deepbook_predict/pricing.d.mts.map +1 -1
- package/dist/contracts/deepbook_predict/pricing.mjs +30 -3
- package/dist/contracts/deepbook_predict/pricing.mjs.map +1 -1
- package/dist/contracts/deepbook_predict/pricing_config.mjs.map +1 -1
- package/dist/contracts/deepbook_predict/protocol_config.d.mts +400 -92
- package/dist/contracts/deepbook_predict/protocol_config.d.mts.map +1 -1
- package/dist/contracts/deepbook_predict/protocol_config.mjs +451 -61
- package/dist/contracts/deepbook_predict/protocol_config.mjs.map +1 -1
- 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 +1 -1
- package/dist/contracts/deepbook_predict/strike_payout_tree.mjs +17 -12
- package/dist/contracts/deepbook_predict/strike_payout_tree.mjs.map +1 -1
- package/dist/contracts/deepbook_predict/vault_events.d.mts +154 -106
- package/dist/contracts/deepbook_predict/vault_events.d.mts.map +1 -1
- package/dist/contracts/deepbook_predict/vault_events.mjs +57 -1
- package/dist/contracts/deepbook_predict/vault_events.mjs.map +1 -1
- package/dist/contracts/deepbook_predict_math/config-arguments.d.mts +10 -0
- package/dist/contracts/deepbook_predict_math/config-arguments.d.mts.map +1 -0
- package/dist/contracts/deepbook_predict_math/lazer_price.d.mts +106 -0
- package/dist/contracts/deepbook_predict_math/lazer_price.d.mts.map +1 -0
- package/dist/contracts/deepbook_predict_math/lazer_price.mjs +125 -0
- package/dist/contracts/deepbook_predict_math/lazer_price.mjs.map +1 -0
- package/dist/contracts/deepbook_predict_math/math.d.mts +284 -0
- package/dist/contracts/deepbook_predict_math/math.d.mts.map +1 -0
- package/dist/contracts/deepbook_predict_math/math.mjs +364 -0
- package/dist/contracts/deepbook_predict_math/math.mjs.map +1 -0
- package/dist/contracts/deepbook_predict_orders/config-arguments.d.mts +13 -0
- package/dist/contracts/deepbook_predict_orders/config-arguments.d.mts.map +1 -0
- package/dist/contracts/deepbook_predict_orders/delayed_execution_config.d.mts +215 -0
- package/dist/contracts/deepbook_predict_orders/delayed_execution_config.d.mts.map +1 -0
- package/dist/contracts/deepbook_predict_orders/delayed_execution_config.mjs +215 -0
- package/dist/contracts/deepbook_predict_orders/delayed_execution_config.mjs.map +1 -0
- package/dist/contracts/deepbook_predict_orders/deps/deepbook_predict/expiry_market.mjs +87 -0
- package/dist/contracts/deepbook_predict_orders/deps/deepbook_predict/expiry_market.mjs.map +1 -0
- package/dist/contracts/deepbook_predict_orders/deps/deepbook_predict/pricing.mjs +52 -0
- package/dist/contracts/deepbook_predict_orders/deps/deepbook_predict/pricing.mjs.map +1 -0
- package/dist/contracts/deepbook_predict_orders/deps/fixed_math/i64.mjs +25 -0
- package/dist/contracts/deepbook_predict_orders/deps/fixed_math/i64.mjs.map +1 -0
- package/dist/contracts/deepbook_predict_orders/deps/sui/balance.mjs +21 -0
- package/dist/contracts/deepbook_predict_orders/deps/sui/balance.mjs.map +1 -0
- package/dist/contracts/deepbook_predict_orders/deps/sui/table.mjs +39 -0
- package/dist/contracts/deepbook_predict_orders/deps/sui/table.mjs.map +1 -0
- package/dist/contracts/deepbook_predict_orders/desk.d.mts +187 -0
- package/dist/contracts/deepbook_predict_orders/desk.d.mts.map +1 -0
- package/dist/contracts/deepbook_predict_orders/desk.mjs +261 -0
- package/dist/contracts/deepbook_predict_orders/desk.mjs.map +1 -0
- package/dist/contracts/deepbook_predict_orders/order_queue.d.mts +1042 -0
- package/dist/contracts/deepbook_predict_orders/order_queue.d.mts.map +1 -0
- package/dist/contracts/deepbook_predict_orders/order_queue.mjs +849 -0
- package/dist/contracts/deepbook_predict_orders/order_queue.mjs.map +1 -0
- package/dist/contracts/deepbook_predict_orders/queue.d.mts +683 -0
- package/dist/contracts/deepbook_predict_orders/queue.d.mts.map +1 -0
- package/dist/contracts/deepbook_predict_orders/queue.mjs +912 -0
- package/dist/contracts/deepbook_predict_orders/queue.mjs.map +1 -0
- package/dist/contracts/deepbook_predict_orders/queue_events.d.mts +195 -0
- package/dist/contracts/deepbook_predict_orders/queue_events.d.mts.map +1 -0
- package/dist/contracts/deepbook_predict_orders/queue_events.mjs +187 -0
- package/dist/contracts/deepbook_predict_orders/queue_events.mjs.map +1 -0
- package/dist/contracts/deepbook_sessions/session_config.d.mts +8 -8
- package/dist/contracts/deepbook_sessions/sessions.d.mts +163 -28
- package/dist/contracts/deepbook_sessions/sessions.d.mts.map +1 -1
- package/dist/contracts/deepbook_sessions/sessions.mjs +234 -5
- package/dist/contracts/deepbook_sessions/sessions.mjs.map +1 -1
- package/dist/deployments/mainnet.mjs +7 -4
- package/dist/deployments/mainnet.mjs.map +1 -1
- package/dist/deployments/testnet.mjs +7 -4
- package/dist/deployments/testnet.mjs.map +1 -1
- package/dist/predict/bindings/expiry-market.d.mts +77 -0
- package/dist/predict/bindings/expiry-market.d.mts.map +1 -0
- package/dist/predict/bindings/expiry-market.mjs +139 -0
- package/dist/predict/bindings/expiry-market.mjs.map +1 -0
- package/dist/predict/bindings/protocol-config.d.mts +39 -0
- package/dist/predict/bindings/protocol-config.d.mts.map +1 -0
- package/dist/predict/bindings/protocol-config.mjs +90 -0
- package/dist/predict/bindings/protocol-config.mjs.map +1 -0
- package/dist/predict/bindings/rename.mjs +9 -0
- package/dist/predict/bindings/rename.mjs.map +1 -0
- package/dist/predict/client.d.mts +595 -16
- package/dist/predict/client.d.mts.map +1 -1
- package/dist/predict/client.mjs +986 -10
- package/dist/predict/client.mjs.map +1 -1
- package/dist/predict/config/generated.d.mts +22 -1
- package/dist/predict/config/generated.d.mts.map +1 -1
- package/dist/predict/config/generated.mjs +30 -1
- package/dist/predict/config/generated.mjs.map +1 -1
- package/dist/predict/config/mainnet.mjs +11 -3
- package/dist/predict/config/mainnet.mjs.map +1 -1
- package/dist/predict/config/testnet.mjs +11 -3
- package/dist/predict/config/testnet.mjs.map +1 -1
- package/dist/predict/config/types.d.mts +50 -1
- package/dist/predict/config/types.d.mts.map +1 -1
- package/dist/predict/cost.d.mts +38 -11
- package/dist/predict/cost.d.mts.map +1 -1
- package/dist/predict/cost.mjs +37 -11
- package/dist/predict/cost.mjs.map +1 -1
- package/dist/predict/decode.d.mts +251 -1
- package/dist/predict/decode.d.mts.map +1 -1
- package/dist/predict/decode.mjs +342 -4
- package/dist/predict/decode.mjs.map +1 -1
- package/dist/predict/errors.d.mts +69 -6
- package/dist/predict/errors.d.mts.map +1 -1
- package/dist/predict/errors.mjs +277 -4
- package/dist/predict/errors.mjs.map +1 -1
- package/dist/predict/index.d.mts +21 -10
- package/dist/predict/index.mjs +24 -12
- package/dist/predict/queue-id.d.mts +13 -0
- package/dist/predict/queue-id.d.mts.map +1 -0
- package/dist/predict/queue-id.mjs +19 -0
- package/dist/predict/queue-id.mjs.map +1 -0
- package/dist/predict/queue.d.mts +505 -0
- package/dist/predict/queue.d.mts.map +1 -0
- package/dist/predict/queue.mjs +774 -0
- package/dist/predict/queue.mjs.map +1 -0
- package/dist/predict/reads/balances.mjs +1 -1
- package/dist/predict/reads/markets.mjs +46 -5
- package/dist/predict/reads/markets.mjs.map +1 -1
- package/dist/predict/reads/pool.mjs +1 -1
- package/dist/predict/reads/pricing.d.mts +1 -1
- package/dist/predict/reads/queue.d.mts +105 -0
- package/dist/predict/reads/queue.d.mts.map +1 -0
- package/dist/predict/reads/queue.mjs +445 -0
- package/dist/predict/reads/queue.mjs.map +1 -0
- package/dist/predict/ticks.d.mts +9 -1
- package/dist/predict/ticks.d.mts.map +1 -1
- package/dist/predict/ticks.mjs +18 -1
- package/dist/predict/ticks.mjs.map +1 -1
- package/dist/predict/tx/authed.mjs +1 -1
- package/dist/predict/tx/common.d.mts.map +1 -1
- package/dist/predict/tx/common.mjs +12 -1
- package/dist/predict/tx/common.mjs.map +1 -1
- package/dist/predict/tx/queue.d.mts +220 -0
- package/dist/predict/tx/queue.d.mts.map +1 -0
- package/dist/predict/tx/queue.mjs +399 -0
- package/dist/predict/tx/queue.mjs.map +1 -0
- package/dist/predict/tx/trade.d.mts.map +1 -1
- package/dist/predict/tx/trade.mjs +61 -43
- package/dist/predict/tx/trade.mjs.map +1 -1
- package/dist/sessions.d.mts +90 -2
- package/dist/sessions.d.mts.map +1 -1
- package/dist/sessions.mjs +107 -2
- package/dist/sessions.mjs.map +1 -1
- package/dist/transactions/balanceManager.d.mts +12 -12
- package/dist/transactions/balanceManager.d.mts.map +1 -1
- package/dist/transactions/deepbook.d.mts +20 -20
- package/dist/transactions/deepbook.d.mts.map +1 -1
- 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/marginManager.d.mts.map +1 -1
- 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/marginTPSL.d.mts.map +1 -1
- package/dist/transactions/poolProxy.d.mts +8 -8
- package/dist/transactions/poolProxy.d.mts.map +1 -1
- package/package.json +4 -4
- package/src/contracts/deepbook_predict/config_events.ts +39 -0
- package/src/contracts/deepbook_predict/deps/std/type_name.ts +24 -0
- package/src/contracts/deepbook_predict/expiry_market.ts +960 -169
- package/src/contracts/deepbook_predict/order_events.ts +3 -1
- package/src/contracts/deepbook_predict/plp.ts +150 -9
- package/src/contracts/deepbook_predict/pricing.ts +46 -7
- package/src/contracts/deepbook_predict/pricing_config.ts +3 -1
- package/src/contracts/deepbook_predict/protocol_config.ts +648 -33
- package/src/contracts/deepbook_predict/strike_payout_tree.ts +25 -21
- package/src/contracts/deepbook_predict/vault_events.ts +65 -0
- package/src/contracts/deepbook_predict_math/config-arguments.ts +6 -0
- package/src/contracts/deepbook_predict_math/lazer_price.ts +196 -0
- package/src/contracts/deepbook_predict_math/math.ts +553 -0
- package/src/contracts/deepbook_predict_orders/config-arguments.ts +11 -0
- package/src/contracts/deepbook_predict_orders/delayed_execution_config.ts +430 -0
- package/src/contracts/deepbook_predict_orders/deps/deepbook_predict/expiry_market.ts +108 -0
- package/src/contracts/deepbook_predict_orders/deps/deepbook_predict/pricing.ts +58 -0
- package/src/contracts/deepbook_predict_orders/deps/fixed_math/i64.ts +21 -0
- package/src/contracts/deepbook_predict_orders/deps/sui/balance.ts +19 -0
- package/src/contracts/deepbook_predict_orders/deps/sui/table.ts +37 -0
- package/src/contracts/deepbook_predict_orders/desk.ts +419 -0
- package/src/contracts/deepbook_predict_orders/order_flow.ts +19 -0
- package/src/contracts/deepbook_predict_orders/order_queue.ts +1670 -0
- package/src/contracts/deepbook_predict_orders/queue.ts +1394 -0
- package/src/contracts/deepbook_predict_orders/queue_events.ts +189 -0
- package/src/contracts/deepbook_sessions/sessions.ts +355 -4
- package/src/deployments/mainnet.ts +7 -2
- package/src/deployments/testnet.ts +7 -2
- package/src/deployments/types.ts +14 -1
- package/src/predict/bindings/expiry-market.ts +127 -0
- package/src/predict/bindings/protocol-config.ts +59 -0
- package/src/predict/bindings/rename.ts +14 -0
- package/src/predict/client.ts +2076 -13
- package/src/predict/config/generated.ts +50 -0
- package/src/predict/config/mainnet.ts +16 -2
- package/src/predict/config/testnet.ts +16 -2
- package/src/predict/config/types.ts +51 -1
- package/src/predict/cost.ts +62 -14
- package/src/predict/decode.ts +691 -2
- package/src/predict/errors.ts +391 -14
- package/src/predict/index.ts +87 -6
- package/src/predict/queue-id.ts +22 -0
- package/src/predict/queue.ts +1231 -0
- package/src/predict/reads/markets.ts +30 -0
- package/src/predict/reads/queue.ts +606 -0
- package/src/predict/ticks.ts +35 -0
- package/src/predict/tx/common.ts +25 -1
- package/src/predict/tx/queue.ts +525 -0
- package/src/predict/tx/trade.ts +80 -49
- package/src/sessions.ts +206 -1
|
@@ -7,7 +7,9 @@
|
|
|
7
7
|
*
|
|
8
8
|
* Events carry transition identities and deltas rather than account or market
|
|
9
9
|
* balances. Partial closes link an old order ID to its replacement; the position
|
|
10
|
-
* root remains constant across that chain.
|
|
10
|
+
* root remains constant across that chain. Queued fills emit `OrderMinted` and
|
|
11
|
+
* `LiveOrderRedeemed` from inside Predict's order-flow fills; the queue's own
|
|
12
|
+
* events belong to the order-flow companion package.
|
|
11
13
|
*/
|
|
12
14
|
|
|
13
15
|
import { MoveStruct } from '../utils/index.js';
|
|
@@ -77,10 +77,8 @@ export const PoolValuation = new MoveStruct({
|
|
|
77
77
|
started_at_ms: U64,
|
|
78
78
|
/**
|
|
79
79
|
* Drain budgets committed at start (the cap owner's choice), bounding how many
|
|
80
|
-
* requests each queue processes at finish.
|
|
81
|
-
*
|
|
82
|
-
* but only ever drains at these budgets, so completion can help LPs, never starve
|
|
83
|
-
* them by finishing with a zero budget.
|
|
80
|
+
* requests each queue processes at finish. `finish_flush` takes no budget, so the
|
|
81
|
+
* flush operator who completes it drains at exactly these.
|
|
84
82
|
*/
|
|
85
83
|
supply_budget: bcs.option(U64),
|
|
86
84
|
withdraw_budget: bcs.option(U64),
|
|
@@ -114,7 +112,10 @@ export const PoolVault = new MoveStruct({
|
|
|
114
112
|
* withdraws this balance.
|
|
115
113
|
*/
|
|
116
114
|
protocol_reserve_balance: balance.Balance,
|
|
117
|
-
/**
|
|
115
|
+
/**
|
|
116
|
+
* Sponsor-funded USDC reserved for taker fee sponsorship, excluded from PLP NAV.
|
|
117
|
+
* Admin may reclaim it through `withdraw_fee_incentives`.
|
|
118
|
+
*/
|
|
118
119
|
fee_incentive_reserve: balance.Balance,
|
|
119
120
|
/** PLP share issuance plus queued supply/withdraw escrow. */
|
|
120
121
|
lp: lp_book.LpBook,
|
|
@@ -595,8 +596,8 @@ export interface SnapshotExpiryPricerOptions {
|
|
|
595
596
|
* a payout tree — so all markets fit one PTB regardless of book size.
|
|
596
597
|
*
|
|
597
598
|
* The oracle feeding this stage must have been written in an EARLIER transaction:
|
|
598
|
-
* `pricing::
|
|
599
|
-
*
|
|
599
|
+
* `pricing::resolve_live` refuses a read stamped with the current transaction
|
|
600
|
+
* digest (RP-24), so a keeper cannot refresh and snapshot in one PTB.
|
|
600
601
|
*
|
|
601
602
|
* A market already settled at snapshot time is recorded with no pricer, gets no
|
|
602
603
|
* stamp (settled flows never touch live NAV), and contributes 0. An
|
|
@@ -786,6 +787,11 @@ export interface FinishFlushOptions {
|
|
|
786
787
|
* Because queueing is permissionless and a refunded request returns its escrow in
|
|
787
788
|
* the same transaction, an operator should bound both budgets in production rather
|
|
788
789
|
* than rely on queue length staying small — see RP-12.
|
|
790
|
+
*
|
|
791
|
+
* Only an allowlisted flush operator may call it
|
|
792
|
+
* (`protocol_config::ENotFlushOperator`). Fills move idle cash, so restricting who
|
|
793
|
+
* completes a flush keeps idle predictable for the keeper that funds markets for
|
|
794
|
+
* queued orders.
|
|
789
795
|
*/
|
|
790
796
|
export function finishFlush(options: FinishFlushOptions) {
|
|
791
797
|
const packageAddress =
|
|
@@ -828,7 +834,10 @@ export interface RebalanceExpiryCashOptions {
|
|
|
828
834
|
* Permissionless and standalone: anyone may call it at any cadence. Handles all
|
|
829
835
|
* three per-market cases — initial funding of a freshly registered (unfunded)
|
|
830
836
|
* market, ongoing live rebalance/surplus-sweep toward target, and the
|
|
831
|
-
* settled-market sweep (deactivate, return all free cash, materialize profit).
|
|
837
|
+
* settled-market sweep (deactivate, return all free cash, materialize profit). The
|
|
838
|
+
* live target covers the market's queued orders' cash need (the waiting cash need
|
|
839
|
+
* in `expiry_market::order_flow_state`), so the keeper calls this after each
|
|
840
|
+
* enqueue to fund those orders' fills, and a sweep never takes that cash back.
|
|
832
841
|
* Call `expiry_market::try_settle` first in the same PTB when settlement may be
|
|
833
842
|
* due. An expired unsettled market is a no-op until that transition succeeds. Mint
|
|
834
843
|
* asserts backing but never pulls pool cash, so this is what makes a market
|
|
@@ -878,7 +887,9 @@ export interface SponsorFeeIncentivesOptions {
|
|
|
878
887
|
/**
|
|
879
888
|
* Sponsor taker fee incentives with USDC. Anyone may contribute; the payment joins
|
|
880
889
|
* a pool-level reserve that is excluded from PLP NAV and later allocated to expiry
|
|
881
|
-
* markets by the normal rebalance flow.
|
|
890
|
+
* markets by the normal rebalance flow. A contribution is not earmarked to its
|
|
891
|
+
* sponsor: admin can withdraw any of the reserve through
|
|
892
|
+
* `withdraw_fee_incentives`.
|
|
882
893
|
*/
|
|
883
894
|
export function sponsorFeeIncentives(options: SponsorFeeIncentivesOptions) {
|
|
884
895
|
const packageAddress =
|
|
@@ -901,6 +912,136 @@ export function sponsorFeeIncentives(options: SponsorFeeIncentivesOptions) {
|
|
|
901
912
|
),
|
|
902
913
|
});
|
|
903
914
|
}
|
|
915
|
+
export interface WithdrawFeeIncentivesArguments {
|
|
916
|
+
vault?: RawTransactionArgument<string>;
|
|
917
|
+
AdminCap: RawTransactionArgument<string>;
|
|
918
|
+
config?: RawTransactionArgument<string>;
|
|
919
|
+
amount: RawTransactionArgument<number | bigint>;
|
|
920
|
+
}
|
|
921
|
+
export interface WithdrawFeeIncentivesOptions {
|
|
922
|
+
package?: string;
|
|
923
|
+
arguments: WithdrawFeeIncentivesArguments;
|
|
924
|
+
config?: {
|
|
925
|
+
poolVault: ConfigValue;
|
|
926
|
+
protocolConfig: ConfigValue;
|
|
927
|
+
predictPackageId?: string;
|
|
928
|
+
};
|
|
929
|
+
}
|
|
930
|
+
/**
|
|
931
|
+
* Withdraw `amount` USDC of sponsor-funded fee incentives from the pool-level
|
|
932
|
+
* reserve, for sponsorship the protocol no longer wants to spend. Admin-only.
|
|
933
|
+
*
|
|
934
|
+
* Reaches the reserve only. Incentives already allocated to a live market stay in
|
|
935
|
+
* that market's `fee_incentive_balance` and return to the reserve when its
|
|
936
|
+
* settled-market sweep runs, after which they can be withdrawn here; setting
|
|
937
|
+
* `protocol_config::set_fee_incentive_subsidy_rate` to zero stops them being spent
|
|
938
|
+
* in the meantime. The per-expiry lifetime allocation counters are not credited
|
|
939
|
+
* back: they bound what a market may ever receive, and a withdrawal does not
|
|
940
|
+
* change what a market already received.
|
|
941
|
+
*
|
|
942
|
+
* Not gated on the valuation flag, in either stage of a flush: the reserve is
|
|
943
|
+
* excluded from PLP NAV and no flush figure, frozen or live, reads it, so a
|
|
944
|
+
* withdrawal cannot reach the mark.
|
|
945
|
+
*/
|
|
946
|
+
export function withdrawFeeIncentives(options: WithdrawFeeIncentivesOptions) {
|
|
947
|
+
const packageAddress =
|
|
948
|
+
options.package ?? options.config?.predictPackageId ?? '@local-pkg/deepbook_predict';
|
|
949
|
+
const argumentsTypes = [null, null, null, 'u64'] satisfies (string | null)[];
|
|
950
|
+
const parameterNames = ['vault', 'AdminCap', 'config', 'amount'];
|
|
951
|
+
return (tx: Transaction) =>
|
|
952
|
+
tx.moveCall({
|
|
953
|
+
package: packageAddress,
|
|
954
|
+
module: 'plp',
|
|
955
|
+
function: 'withdraw_fee_incentives',
|
|
956
|
+
arguments: normalizeMoveArguments(
|
|
957
|
+
{
|
|
958
|
+
...options.arguments,
|
|
959
|
+
vault: options.arguments?.vault ?? options.config?.poolVault,
|
|
960
|
+
config: options.arguments?.config ?? options.config?.protocolConfig,
|
|
961
|
+
},
|
|
962
|
+
argumentsTypes,
|
|
963
|
+
parameterNames,
|
|
964
|
+
),
|
|
965
|
+
});
|
|
966
|
+
}
|
|
967
|
+
export interface AddUsdcToPlpArguments {
|
|
968
|
+
vault?: RawTransactionArgument<string>;
|
|
969
|
+
config?: RawTransactionArgument<string>;
|
|
970
|
+
payment: RawTransactionArgument<string>;
|
|
971
|
+
}
|
|
972
|
+
export interface AddUsdcToPlpOptions {
|
|
973
|
+
package?: string;
|
|
974
|
+
arguments: AddUsdcToPlpArguments;
|
|
975
|
+
config?: {
|
|
976
|
+
poolVault: ConfigValue;
|
|
977
|
+
protocolConfig: ConfigValue;
|
|
978
|
+
predictPackageId?: string;
|
|
979
|
+
};
|
|
980
|
+
}
|
|
981
|
+
/**
|
|
982
|
+
* Add USDC straight to pool idle liquidity without minting any PLP. Anyone may
|
|
983
|
+
* call it; the payment is an outright gift to the existing share base, so the
|
|
984
|
+
* caller receives nothing back and no share of it is recoverable.
|
|
985
|
+
*
|
|
986
|
+
* This is the incentive/top-up path: because no shares are issued, the whole
|
|
987
|
+
* `payment` lands inside the value the next flush's mark divides by an unchanged
|
|
988
|
+
* `total_supply`, which raises NAV per PLP for every current holder. It
|
|
989
|
+
* deliberately does not touch the profit basis — the basis tracks cash sent to and
|
|
990
|
+
* returned from expiries, so an outside contribution is neither a debit nor a
|
|
991
|
+
* credit, and the protocol reserve therefore takes no cut of it (`pool_value`
|
|
992
|
+
* leaves `exclusion` unchanged while `gross_pool_value` grows). Sending the same
|
|
993
|
+
* USDC through `request_supply` instead mints shares against it, so only the
|
|
994
|
+
* supply fee would reach existing holders — zero as shipped.
|
|
995
|
+
*
|
|
996
|
+
* Three gates, each closing a state this entrypoint would otherwise manufacture:
|
|
997
|
+
*
|
|
998
|
+
* - **Bootstrapped pool.** At `total_supply == 0` there is no share base to
|
|
999
|
+
* credit; the USDC would only inflate the genesis lock's non-withdrawable stake.
|
|
1000
|
+
* - **Contribution price ceiling.** Pool cash after the contribution — idle plus
|
|
1001
|
+
* the net cash deployed into active expiries — may price at most
|
|
1002
|
+
* `contribution_price_ceiling_factor` USDC per PLP, a tenth of the band a flush
|
|
1003
|
+
* mark needs to be fillable. Above the band every supply and withdraw head is
|
|
1004
|
+
* refunded (RP-2) and `total_supply` grows only through a supply fill, so
|
|
1005
|
+
* nothing brings the price back down — a terminal state that an unbounded
|
|
1006
|
+
* contribution against a small share base would otherwise reach for the price of
|
|
1007
|
+
* the contribution. The ceiling sits well inside the band because later fills
|
|
1008
|
+
* only push the price up (rounding and retained fees stay in the pool), so a
|
|
1009
|
+
* pool left exactly at the band would leave it on the next uneven or fee-charged
|
|
1010
|
+
* fill. The test is one-sided because a contribution can only move the price up.
|
|
1011
|
+
* It reads pool cash rather than pool NAV — NAV needs a flush — and counts
|
|
1012
|
+
* deployed cash because the mark does: `rebalance_expiry_cash` is
|
|
1013
|
+
* permissionless, so an idle-only test could be emptied into a market and passed
|
|
1014
|
+
* again. Cash is exactly the protocol-controlled share: the guard forbids this
|
|
1015
|
+
* entrypoint from _manufacturing_ the degenerate ratio and leaves market-driven
|
|
1016
|
+
* NAV moves (trader premiums and P&L) to RP-1/RP-2, which own them.
|
|
1017
|
+
* - **No flush in flight.** The seal freezes idle mid-flush, so an ungated
|
|
1018
|
+
* contribution would land on one side or the other of that capture depending
|
|
1019
|
+
* only on when the contributor's transaction executed — either paying that
|
|
1020
|
+
* flush's queued withdrawals or not. `sponsor_fee_incentives` takes the same
|
|
1021
|
+
* gate. `rebalance_expiry_cash` may run mid-window because it only moves cash
|
|
1022
|
+
* between two figures the seal already froze; new value is different.
|
|
1023
|
+
*/
|
|
1024
|
+
export function addUsdcToPlp(options: AddUsdcToPlpOptions) {
|
|
1025
|
+
const packageAddress =
|
|
1026
|
+
options.package ?? options.config?.predictPackageId ?? '@local-pkg/deepbook_predict';
|
|
1027
|
+
const argumentsTypes = [null, null, null] satisfies (string | null)[];
|
|
1028
|
+
const parameterNames = ['vault', 'config', 'payment'];
|
|
1029
|
+
return (tx: Transaction) =>
|
|
1030
|
+
tx.moveCall({
|
|
1031
|
+
package: packageAddress,
|
|
1032
|
+
module: 'plp',
|
|
1033
|
+
function: 'add_usdc_to_plp',
|
|
1034
|
+
arguments: normalizeMoveArguments(
|
|
1035
|
+
{
|
|
1036
|
+
...options.arguments,
|
|
1037
|
+
vault: options.arguments?.vault ?? options.config?.poolVault,
|
|
1038
|
+
config: options.arguments?.config ?? options.config?.protocolConfig,
|
|
1039
|
+
},
|
|
1040
|
+
argumentsTypes,
|
|
1041
|
+
parameterNames,
|
|
1042
|
+
),
|
|
1043
|
+
});
|
|
1044
|
+
}
|
|
904
1045
|
export interface LockCapitalArguments {
|
|
905
1046
|
vault?: RawTransactionArgument<string>;
|
|
906
1047
|
config?: RawTransactionArgument<string>;
|
|
@@ -11,16 +11,52 @@
|
|
|
11
11
|
* an exact source-timestamp spot from Propbook's bounded recent history. The live
|
|
12
12
|
* forward comes from one of two admin-selected sources
|
|
13
13
|
* (`PricingConfig.use_pyth_spot_for_forward`): a fresh positive Pyth spot carrying
|
|
14
|
-
* the Block Scholes basis, or the Block Scholes forward directly.
|
|
15
|
-
*
|
|
14
|
+
* the Block Scholes basis, or the Block Scholes forward directly. A load falls
|
|
15
|
+
* back to the Block Scholes forward when the selected Pyth spot is stale or
|
|
16
|
+
* unavailable; valuation prices on that fallback, while every live trade (mints,
|
|
17
|
+
* mint quotes, and live redeems) refuses it through `assert_pyth_spot_fresh`.
|
|
18
|
+
* Exact-history reads do not apply live freshness policy.
|
|
19
|
+
*
|
|
20
|
+
* Delayed execution splits that read in two. `load_vol` validates the same live
|
|
21
|
+
* inputs when an order is admitted and returns the raw Block Scholes basis and SVI
|
|
22
|
+
* its receipt stores; `pricer_at` later rebuilds a `Pricer` from them at the
|
|
23
|
+
* order's committed Pyth tick. The `try_*` reads price exactly as `up_price` and
|
|
24
|
+
* `range_price` do, and return `none` where those abort, so an order-flow fill
|
|
25
|
+
* never aborts on a surface.
|
|
16
26
|
*/
|
|
17
27
|
|
|
18
28
|
import { MoveStruct, normalizeMoveArguments } from '../utils/index.js';
|
|
19
|
-
import { U128, U64 } from '../../bcs/integers.js';
|
|
20
29
|
import { bcs } from '@mysten/sui/bcs';
|
|
30
|
+
import { U64, U128 } from '../../bcs/integers.js';
|
|
21
31
|
import { type Transaction, type TransactionArgument } from '@mysten/sui/transactions';
|
|
22
32
|
import * as i64 from './deps/fixed_math/i64.js';
|
|
23
33
|
const $moduleName = '@local-pkg/deepbook_predict::pricing';
|
|
34
|
+
export const VolSnapshot = new MoveStruct({
|
|
35
|
+
name: `${$moduleName}::VolSnapshot`,
|
|
36
|
+
fields: {
|
|
37
|
+
/**
|
|
38
|
+
* Canonical Propbook Pyth source for the market's underlying; commit finds this
|
|
39
|
+
* feed in each Lazer update.
|
|
40
|
+
*/
|
|
41
|
+
pyth_source_id: bcs.u32(),
|
|
42
|
+
/** The matched Block Scholes spot and forward, narrowed to Predict's width. */
|
|
43
|
+
bs_spot: U64,
|
|
44
|
+
bs_forward: U64,
|
|
45
|
+
/** Raw SVI parameters before roll-down, at 1e9. */
|
|
46
|
+
svi_a: i64.I64,
|
|
47
|
+
svi_b: U64,
|
|
48
|
+
svi_rho: i64.I64,
|
|
49
|
+
svi_m: i64.I64,
|
|
50
|
+
svi_sigma: U64,
|
|
51
|
+
/**
|
|
52
|
+
* Provider source timestamps of the three reads. The SVI one is also the roll-down
|
|
53
|
+
* anchor.
|
|
54
|
+
*/
|
|
55
|
+
bs_spot_source_timestamp_ms: U64,
|
|
56
|
+
bs_forward_source_timestamp_ms: U64,
|
|
57
|
+
svi_source_timestamp_ms: U64,
|
|
58
|
+
},
|
|
59
|
+
});
|
|
24
60
|
export const PricingSVI = new MoveStruct({
|
|
25
61
|
name: `${$moduleName}::PricingSVI`,
|
|
26
62
|
fields: {
|
|
@@ -56,10 +92,13 @@ export const Pricer = new MoveStruct({
|
|
|
56
92
|
/**
|
|
57
93
|
* Timestamps of the oracle observations this snapshot validated, as trade events
|
|
58
94
|
* report them — each observation's own economic clock. Pyth carries its source
|
|
59
|
-
* timestamp (`0` only when no usable normalized observation exists
|
|
60
|
-
*
|
|
61
|
-
* provider `
|
|
62
|
-
*
|
|
95
|
+
* timestamp (`0` only when no usable normalized observation exists; a `pricer_at`
|
|
96
|
+
* Pricer carries the committed update's generation time); Block Scholes spot and
|
|
97
|
+
* forward carry the provider `value_timestamp`, and SVI carries the provider
|
|
98
|
+
* `svi_timestamp`. Those timestamps are the clocks freshness gates and SVI
|
|
99
|
+
* roll-down use. The Pyth timestamp, including its `0` sentinel, is also what
|
|
100
|
+
* `assert_pyth_spot_fresh` gates live trades on, so it must stay the value the
|
|
101
|
+
* load's forward selection read.
|
|
63
102
|
*/
|
|
64
103
|
pyth_spot_source_timestamp_ms: U64,
|
|
65
104
|
block_scholes_spot_source_timestamp_ms: U64,
|
|
@@ -24,7 +24,9 @@ export const PricingConfig = new MoveStruct({
|
|
|
24
24
|
use_pyth_spot_for_forward: bcs.bool(),
|
|
25
25
|
/**
|
|
26
26
|
* Fixed wall-clock maximum age for Pyth spot; it does not vary with time to
|
|
27
|
-
* expiry.
|
|
27
|
+
* expiry. Past it, while `use_pyth_spot_for_forward` is set, a live load falls
|
|
28
|
+
* back to the Block Scholes forward, which valuation prices on and every live
|
|
29
|
+
* trade (mint, mint quote, live redeem) refuses.
|
|
28
30
|
*/
|
|
29
31
|
pyth_spot_freshness_ms: U64,
|
|
30
32
|
/**
|