@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
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
import type { AccountConfig } from '../../account.js';
|
|
4
4
|
import type { DeepbookPredictConfig } from '../../contracts/deepbook_predict/config-arguments.js';
|
|
5
|
+
import type { DeepbookPredictMathConfig } from '../../contracts/deepbook_predict_math/config-arguments.js';
|
|
6
|
+
import type { DeepbookPredictOrdersConfig } from '../../contracts/deepbook_predict_orders/config-arguments.js';
|
|
7
|
+
import { PredictInputError } from '../errors.js';
|
|
5
8
|
import type { PredictConfig } from './types.js';
|
|
6
9
|
|
|
7
10
|
/**
|
|
@@ -39,3 +42,50 @@ export function toGeneratedConfig(cfg: PredictConfig): GeneratedConfig {
|
|
|
39
42
|
accountRegistry: cfg.objects.accountRegistry,
|
|
40
43
|
};
|
|
41
44
|
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* {@link GeneratedConfig} plus the order-flow companion (`deepbook_predict_orders`) and the math
|
|
48
|
+
* library: the slice the queued-order thunks and reads take. A queued order calls the companion,
|
|
49
|
+
* which calls into Predict, so one object carries both packages' keys. `predictOrdersPackageIdV1`
|
|
50
|
+
* is the companion's original ID, which types `OrderFlow` and the queue events.
|
|
51
|
+
*/
|
|
52
|
+
export type OrdersGeneratedConfig = GeneratedConfig &
|
|
53
|
+
DeepbookPredictOrdersConfig &
|
|
54
|
+
DeepbookPredictMathConfig & {
|
|
55
|
+
predictOrdersPackageId: string;
|
|
56
|
+
predictOrdersPackageIdV1: string;
|
|
57
|
+
orderDesk: string;
|
|
58
|
+
queueRegistry: string;
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Project a config that records delayed execution onto {@link OrdersGeneratedConfig}. Throws
|
|
63
|
+
* `PredictInputError` while the config lacks the Predict upgrade, the companion package, its desk
|
|
64
|
+
* or its queue registry: building a queued order against a guessed package would abort on chain
|
|
65
|
+
* or, worse, address the wrong one.
|
|
66
|
+
*/
|
|
67
|
+
export function toOrdersConfig(cfg: PredictConfig): OrdersGeneratedConfig {
|
|
68
|
+
const { predictDelayedExecution, predictOrders, predictOrdersV1, predictMath } = cfg.packages;
|
|
69
|
+
const { orderDesk, queueRegistry } = cfg.objects;
|
|
70
|
+
if (!predictDelayedExecution || !predictOrders || !orderDesk || !queueRegistry) {
|
|
71
|
+
const missing = [
|
|
72
|
+
!predictDelayedExecution && '`packages.predictDelayedExecution`',
|
|
73
|
+
!predictOrders && '`packages.predictOrders`',
|
|
74
|
+
!orderDesk && '`objects.orderDesk`',
|
|
75
|
+
!queueRegistry && '`objects.queueRegistry`',
|
|
76
|
+
].filter(Boolean);
|
|
77
|
+
throw new PredictInputError(
|
|
78
|
+
`delayed execution isn't recorded for ${cfg.network} in this SDK version (missing ` +
|
|
79
|
+
`${missing.join(', ')}): pass a \`config\` that records the Predict upgrade, the ` +
|
|
80
|
+
'`deepbook_predict_orders` package, its order desk and its queue registry',
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
return {
|
|
84
|
+
...toGeneratedConfig(cfg),
|
|
85
|
+
predictOrdersPackageId: predictOrders,
|
|
86
|
+
predictOrdersPackageIdV1: predictOrdersV1 ?? predictOrders,
|
|
87
|
+
predictMathPackageId: predictMath,
|
|
88
|
+
orderDesk,
|
|
89
|
+
queueRegistry,
|
|
90
|
+
};
|
|
91
|
+
}
|
|
@@ -18,10 +18,24 @@ export const MAINNET_CONFIG: PredictConfig = Object.freeze({
|
|
|
18
18
|
// The record widens `network` to `string` so the published types don't pin a literal;
|
|
19
19
|
// this file is the mainnet config by construction.
|
|
20
20
|
network: 'mainnet',
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
// Delayed execution (DBU-885) is recorded on Mainnet. The generated record carries the package
|
|
22
|
+
// IDs that move with upgrades (Predict, `deepbook_predict_orders`, `deepbook_predict_math`) and
|
|
23
|
+
// the Lazer `State`. The three IDs pinned below are in no publication record and never move:
|
|
24
|
+
// the Predict version that introduced delayed execution (Mainnet v4), which defines its new
|
|
25
|
+
// types and events, and the `OrderDesk` and `QueueRegistry` that `deepbook_predict_orders`'s
|
|
26
|
+
// `init` shared at publish.
|
|
27
|
+
packages: Object.freeze({
|
|
28
|
+
...MAINNET_PREDICT.packages,
|
|
29
|
+
predictDelayedExecution: '0x98235c5842831c9b5f51dc637cf34c91db2aca5510802eb6ebfec63f5b71a7bb',
|
|
30
|
+
}),
|
|
31
|
+
objects: Object.freeze({
|
|
32
|
+
...MAINNET_PREDICT.objects,
|
|
33
|
+
orderDesk: '0x87b0a87262aacf58eaff567eed2fb7cb0f9cbc1f5ce33ef79216cd26d13a1b5b',
|
|
34
|
+
queueRegistry: '0x8d4f0c671862f065ac7f2c2cb24abc47cf75ed8fc8e5e52c1d4bdfa53eee164f',
|
|
35
|
+
}),
|
|
23
36
|
quoteCoinType: MAINNET_PREDICT.quoteCoinType,
|
|
24
37
|
coinTypes: MAINNET_PREDICT.coinTypes,
|
|
25
38
|
units: MAINNET_PREDICT.units,
|
|
26
39
|
underlyings: MAINNET_PREDICT.underlyings,
|
|
40
|
+
oracle: MAINNET_PREDICT.oracle,
|
|
27
41
|
});
|
|
@@ -18,10 +18,24 @@ export const TESTNET_CONFIG: PredictConfig = Object.freeze({
|
|
|
18
18
|
// The record widens `network` to `string` so the published types don't pin a literal;
|
|
19
19
|
// this file is the testnet config by construction.
|
|
20
20
|
network: 'testnet',
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
// Delayed execution (DBU-885) is recorded on Testnet. The generated record carries the package
|
|
22
|
+
// IDs that move with upgrades (Predict, `deepbook_predict_orders`, `deepbook_predict_math`) and
|
|
23
|
+
// the Lazer `State`. The three IDs pinned below are in no publication record and never move:
|
|
24
|
+
// the Predict version that introduced delayed execution (Testnet v5), which defines its new
|
|
25
|
+
// types and events, and the `OrderDesk` and `QueueRegistry` that `deepbook_predict_orders`'s
|
|
26
|
+
// `init` shared at publish.
|
|
27
|
+
packages: Object.freeze({
|
|
28
|
+
...TESTNET_PREDICT.packages,
|
|
29
|
+
predictDelayedExecution: '0x0654ecbed7c0f2645d9de7cb6cf08e65c2ee05cdbb39a415f17a6bd1cd92e267',
|
|
30
|
+
}),
|
|
31
|
+
objects: Object.freeze({
|
|
32
|
+
...TESTNET_PREDICT.objects,
|
|
33
|
+
orderDesk: '0x160fc026c4143f3dec36acfc6556379d54661d37fe28ad837b6a85e42aeddfea',
|
|
34
|
+
queueRegistry: '0xe9d75ed05b089d52a660a94b94963cdc89aeb7f3c75b57f76771454c81faae1f',
|
|
35
|
+
}),
|
|
23
36
|
quoteCoinType: TESTNET_PREDICT.quoteCoinType,
|
|
24
37
|
coinTypes: TESTNET_PREDICT.coinTypes,
|
|
25
38
|
units: TESTNET_PREDICT.units,
|
|
26
39
|
underlyings: TESTNET_PREDICT.underlyings,
|
|
40
|
+
oracle: TESTNET_PREDICT.oracle,
|
|
27
41
|
});
|
|
@@ -1,11 +1,42 @@
|
|
|
1
1
|
// Copyright (c) Mysten Labs, Inc.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
/**
|
|
3
|
+
/**
|
|
4
|
+
* The published Move packages a Predict deployment spans.
|
|
5
|
+
*
|
|
6
|
+
* Delayed execution (DBU-885) ships as three packages: the Predict upgrade, the order-flow
|
|
7
|
+
* companion `deepbook_predict_orders` (a fresh publish), and the math library
|
|
8
|
+
* `deepbook_predict_math` (a fresh publish). The queued-order builders, reads and decoders need
|
|
9
|
+
* `predictDelayedExecution`, `predictOrders`, `objects.orderDesk` and `objects.queueRegistry` all
|
|
10
|
+
* recorded, and throw
|
|
11
|
+
* `PredictInputError` otherwise rather than address the wrong package. Pass a custom `config`
|
|
12
|
+
* (a localnet publish) to use them before a network record exists.
|
|
13
|
+
*/
|
|
4
14
|
export interface PredictPackages {
|
|
5
15
|
/** Latest published package ID, used for Move calls. */
|
|
6
16
|
predict: string;
|
|
7
17
|
/** Original ID for v1 structs/events. Omit only for an unupgraded custom deployment. */
|
|
8
18
|
predictV1?: string;
|
|
19
|
+
/**
|
|
20
|
+
* The Predict version that introduced delayed execution (Mainnet v4, Testnet v5): the
|
|
21
|
+
* defining ID of the Predict types and events that version added (`ExpiryPnlRealized`,
|
|
22
|
+
* `FlushOperatorUpdated`, `OrderFlowUpdated`, `OrderReceipt`). A later upgrade does not move
|
|
23
|
+
* it, so it is pinned once per network rather than read from the latest publication.
|
|
24
|
+
*/
|
|
25
|
+
predictDelayedExecution?: string;
|
|
26
|
+
/**
|
|
27
|
+
* Latest published `deepbook_predict_orders` package ID: the call target of every queued-order
|
|
28
|
+
* entry point (`queue::enqueue_*`, `commit`, `resolve`, `refund`, `settle_step`, …), the queue
|
|
29
|
+
* reads and the desk setters.
|
|
30
|
+
*/
|
|
31
|
+
predictOrders?: string;
|
|
32
|
+
/**
|
|
33
|
+
* Original `deepbook_predict_orders` ID, which types `MarketQueue`, `OrderDesk`, the queue
|
|
34
|
+
* events and the `OrderFlow` witness. Omit until the package is first upgraded: it then
|
|
35
|
+
* defaults to `predictOrders`.
|
|
36
|
+
*/
|
|
37
|
+
predictOrdersV1?: string;
|
|
38
|
+
/** The `deepbook_predict_math` package ID, for its pure calls and layouts. */
|
|
39
|
+
predictMath?: string;
|
|
9
40
|
account: string;
|
|
10
41
|
propbook: string;
|
|
11
42
|
}
|
|
@@ -36,6 +67,17 @@ export interface PredictConfig {
|
|
|
36
67
|
poolVault: string;
|
|
37
68
|
oracleRegistry: string;
|
|
38
69
|
accountRegistry: string;
|
|
70
|
+
/**
|
|
71
|
+
* The order-flow companion's shared `OrderDesk`: the delayed-execution policy and the
|
|
72
|
+
* companion's version floor. Created once, by the package's `init` at publish.
|
|
73
|
+
*/
|
|
74
|
+
orderDesk?: string;
|
|
75
|
+
/**
|
|
76
|
+
* The order-flow companion's shared `QueueRegistry`, created next to the desk by the same
|
|
77
|
+
* `init`. Each market's `MarketQueue` sits at an ID derived from it and the market
|
|
78
|
+
* (`deriveQueueId`), and `queue::create_and_share` writes it.
|
|
79
|
+
*/
|
|
80
|
+
queueRegistry?: string;
|
|
39
81
|
};
|
|
40
82
|
/**
|
|
41
83
|
* The deployment's settlement coin type. Always read this rather than assuming a type:
|
|
@@ -58,4 +100,12 @@ export interface PredictConfig {
|
|
|
58
100
|
positionQuantityDecimals: number;
|
|
59
101
|
};
|
|
60
102
|
underlyings: Record<string, UnderlyingConfig>; // keyed by symbol, e.g. "BTC"
|
|
103
|
+
/**
|
|
104
|
+
* Oracle objects only the delayed-execution filler needs. Optional: traders never pass
|
|
105
|
+
* them, and a filler can name the Lazer `State` per call instead.
|
|
106
|
+
*/
|
|
107
|
+
oracle?: {
|
|
108
|
+
/** Pyth Lazer's shared `State`, which carries the current Lazer package ID. */
|
|
109
|
+
pythLazerState?: string;
|
|
110
|
+
};
|
|
61
111
|
}
|
package/src/predict/cost.ts
CHANGED
|
@@ -31,9 +31,9 @@
|
|
|
31
31
|
// against current account and market state, including the execution gates these previews
|
|
32
32
|
// do not check (ownership, pauses, trade window, oracle freshness and cash backing).
|
|
33
33
|
//
|
|
34
|
-
// The fee POLICY is a per-market snapshot taken at creation (`StrikeExposureConfig`)
|
|
35
|
-
// chain exposes no getter for `base_fee`/`min_fee`
|
|
36
|
-
//
|
|
34
|
+
// The fee POLICY is a per-market snapshot taken at creation (`StrikeExposureConfig`). The
|
|
35
|
+
// chain exposes no getter for `base_fee`/`min_fee`, so `read.feePolicy(market)` decodes it from
|
|
36
|
+
// the `ExpiryMarket` object. The market's `MarketCreated` event carries it too.
|
|
37
37
|
|
|
38
38
|
import { PredictInputError } from './errors.js';
|
|
39
39
|
import type { PricerInputs } from './pricing.js';
|
|
@@ -53,7 +53,14 @@ export const MIN_PREMIUM = 1_000_000n;
|
|
|
53
53
|
export const BUILDER_FEE_MULTIPLIER = 100_000_000n;
|
|
54
54
|
/** `constants::max_builder_fee_rate` — cap on the builder fee as a share of quantity (0.5%). */
|
|
55
55
|
export const MAX_BUILDER_FEE_RATE = 5_000_000n;
|
|
56
|
-
/**
|
|
56
|
+
/**
|
|
57
|
+
* The default sponsor share of a trader's mint fee (20%), and the rate the chain reads while the
|
|
58
|
+
* admin hasn't set one.
|
|
59
|
+
* @deprecated From delayed execution (DBU-885) the rate is admin-set: read it with
|
|
60
|
+
* `protocol_config::fee_incentive_subsidy_rate` (`read.queue(...).protocol.feeIncentiveSubsidyRate`)
|
|
61
|
+
* and pass it as `feeIncentiveSubsidyRate`. A hardcoded 20% underquotes every mint once the rate
|
|
62
|
+
* moves.
|
|
63
|
+
*/
|
|
57
64
|
export const FEE_INCENTIVE_SUBSIDY_RATE = 200_000_000n;
|
|
58
65
|
/** `order::max_quantity_lots` — the order ID's 32-bit lot field. */
|
|
59
66
|
export const MAX_QUANTITY_LOTS = (1n << 32n) - 1n;
|
|
@@ -130,8 +137,8 @@ export function sqrtDown(x: bigint): bigint {
|
|
|
130
137
|
/**
|
|
131
138
|
* One market's fee policy: the `StrikeExposureConfig` it snapshotted at creation, in raw 1e9
|
|
132
139
|
* rates. Snapshotted means later admin changes do NOT reprice a market already trading, so
|
|
133
|
-
* read it per market (the `MarketCreated` event carries every field
|
|
134
|
-
* template. The last three are the inventory-impact parameters, inert while
|
|
140
|
+
* read it per market with `read.feePolicy(market)` (the `MarketCreated` event carries every field
|
|
141
|
+
* too) rather than assuming the template. The last three are the inventory-impact parameters, inert while
|
|
135
142
|
* `inventoryImpactMaxRate` is `0n` (the shipped value).
|
|
136
143
|
*/
|
|
137
144
|
export interface FeePolicy {
|
|
@@ -158,9 +165,11 @@ export interface FeePolicy {
|
|
|
158
165
|
/**
|
|
159
166
|
* The shipped template (`config_constants` defaults): 10% Bernoulli fee, a 2.2% per-leg floor,
|
|
160
167
|
* a one-day ramp window that is inert at a 1.0 multiplier, a 1%–99% entry band, and inventory
|
|
161
|
-
* impact disabled.
|
|
162
|
-
*
|
|
163
|
-
*
|
|
168
|
+
* impact disabled. Neither recorded deployment's template matches it any more: both charge a
|
|
169
|
+
* 20.4% Bernoulli fee, ramp it to 3× over the last 60 s and admit entries in 25%–75% (checked
|
|
170
|
+
* 2026-10-09), so a live market's costs from this policy come out low. Pass
|
|
171
|
+
* `read.feePolicy(market)` instead. This stays for tests and for a deployment still on the
|
|
172
|
+
* defaults.
|
|
164
173
|
*/
|
|
165
174
|
export const SHIPPED_FEE_POLICY: FeePolicy = Object.freeze({
|
|
166
175
|
baseFee: 100_000_000n,
|
|
@@ -347,11 +356,17 @@ export function builderFee(fee: bigint, quantity: bigint, hasBuilderCode: boolea
|
|
|
347
356
|
}
|
|
348
357
|
|
|
349
358
|
/** `expiry_market::fee_incentive_subsidy_amount` — a sponsor pays part of the trader's MINT
|
|
350
|
-
* fee, bounded by the expiry's remaining sponsored balance. Mints only; redeems pay in full.
|
|
351
|
-
|
|
359
|
+
* fee, bounded by the expiry's remaining sponsored balance. Mints only; redeems pay in full.
|
|
360
|
+
* `rate` is the protocol's `fee_incentive_subsidy_rate` (1e9-scaled), 20% when omitted. */
|
|
361
|
+
export function feeIncentiveSubsidy(
|
|
362
|
+
fee: bigint,
|
|
363
|
+
feeIncentiveBalance: bigint,
|
|
364
|
+
rate: bigint = FEE_INCENTIVE_SUBSIDY_RATE,
|
|
365
|
+
): bigint {
|
|
352
366
|
assertUint(fee, 'fee');
|
|
353
367
|
assertUint(feeIncentiveBalance, 'feeIncentiveBalance');
|
|
354
|
-
|
|
368
|
+
assertUint(rate, 'feeIncentiveSubsidyRate', FLOAT_SCALING);
|
|
369
|
+
return min(mulDown(fee, rate), feeIncentiveBalance);
|
|
355
370
|
}
|
|
356
371
|
|
|
357
372
|
/**
|
|
@@ -534,7 +549,15 @@ interface MintInputsBase {
|
|
|
534
549
|
builderCode?: boolean;
|
|
535
550
|
/** The expiry's remaining sponsored fee balance (`fee_incentive_balance`). Default `0n`. */
|
|
536
551
|
feeIncentiveBalance?: number | bigint;
|
|
537
|
-
/**
|
|
552
|
+
/**
|
|
553
|
+
* The protocol's admin-set mint fee subsidy rate (`protocol_config::fee_incentive_subsidy_rate`),
|
|
554
|
+
* 1e9-scaled. Defaults to the 20% the chain reads while unset.
|
|
555
|
+
*/
|
|
556
|
+
feeIncentiveSubsidyRate?: bigint;
|
|
557
|
+
/**
|
|
558
|
+
* Per-unit congestion surcharge rate — see {@link congestionPenaltyRate}. Default `0n`. A
|
|
559
|
+
* queued (delayed-execution) fill pays no congestion penalty, so queued previews keep it 0.
|
|
560
|
+
*/
|
|
538
561
|
penaltyRate?: bigint;
|
|
539
562
|
/** Pre-trade payout-tree terms. Required when inventory impact is enabled. */
|
|
540
563
|
book?: MintBookTerms;
|
|
@@ -663,7 +686,11 @@ function mintQuoteAt(
|
|
|
663
686
|
} {
|
|
664
687
|
const premium = mulDown(rangeProbability(boundaries), quantity);
|
|
665
688
|
const fee = tradingFee(inputs.fees, boundaries, quantity, timeToExpiryMs);
|
|
666
|
-
const subsidy = feeIncentiveSubsidy(
|
|
689
|
+
const subsidy = feeIncentiveSubsidy(
|
|
690
|
+
fee,
|
|
691
|
+
rawAmount(inputs.feeIncentiveBalance ?? 0n),
|
|
692
|
+
inputs.feeIncentiveSubsidyRate,
|
|
693
|
+
);
|
|
667
694
|
const builder = builderFee(fee, quantity, inputs.builderCode ?? false);
|
|
668
695
|
const penalty = mulDown(inputs.penaltyRate ?? 0n, quantity);
|
|
669
696
|
const impact = inputs.book ? mintInventoryImpact(inputs.fees, inputs.book, quantity) : 0n;
|
|
@@ -1008,6 +1035,27 @@ export function decodeOrderRange(orderId: bigint, lotSize: bigint = POSITION_LOT
|
|
|
1008
1035
|
};
|
|
1009
1036
|
}
|
|
1010
1037
|
|
|
1038
|
+
/**
|
|
1039
|
+
* What an order pays at settlement, raw USDC: its full quantity when the settlement price lies
|
|
1040
|
+
* in `(lower, higher]`, else 0. The mirror of `strike_exposure::settled_order_payout`, which
|
|
1041
|
+
* rounds the settlement price up to the market's tick grid (`range_codec::limit_tick`) before
|
|
1042
|
+
* comparing it with the order's ticks, so a price inside a tick counts as that tick's upper edge.
|
|
1043
|
+
* Pass `read.settlement`'s `settlementPriceRaw` and `tickSizeRaw`, and the config's
|
|
1044
|
+
* `units.positionLotSize` when it isn't the default.
|
|
1045
|
+
*/
|
|
1046
|
+
export function settledPayout(
|
|
1047
|
+
orderId: bigint,
|
|
1048
|
+
settlementPriceRaw: bigint,
|
|
1049
|
+
tickSizeRaw: bigint,
|
|
1050
|
+
lotSize: bigint = POSITION_LOT_SIZE,
|
|
1051
|
+
): bigint {
|
|
1052
|
+
if (tickSizeRaw <= 0n) throw new PredictInputError('tickSizeRaw must be positive');
|
|
1053
|
+
const { lowerTick, higherTick, quantity } = decodeOrderRange(orderId, lotSize);
|
|
1054
|
+
const limit = (settlementPriceRaw + tickSizeRaw - 1n) / tickSizeRaw;
|
|
1055
|
+
const inRange = lowerTick < limit && (higherTick === POS_INF_TICK || limit <= higherTick);
|
|
1056
|
+
return inRange ? quantity : 0n;
|
|
1057
|
+
}
|
|
1058
|
+
|
|
1011
1059
|
/** The strikes an {@link OrderRange} prices against, in USD, with `null` for each infinite
|
|
1012
1060
|
* side — the shape {@link boundaryProbabilities} takes. `tickSize` is the market's raw tick
|
|
1013
1061
|
* size (`ActiveMarket.tickSize` in USD, or the raw value from the deployment). */
|