@mysten/deepbook-v3 2.5.0 → 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 +31 -0
- package/PREDICT.md +160 -12
- 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 +19 -19
- package/dist/contracts/account/account_registry.d.mts.map +1 -1
- 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_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/config_events.d.mts.map +1 -1
- 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/market_manager.d.mts.map +1 -1
- 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/plp.d.mts.map +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 +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 +8 -8
- package/dist/contracts/deepbook_sessions/session_config.d.mts.map +1 -1
- package/dist/contracts/deepbook_sessions/sessions.d.mts +48 -23
- 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/balanceManager.d.mts.map +1 -1
- package/dist/transactions/deepbook.d.mts +20 -20
- package/dist/transactions/deepbookAdmin.d.mts +4 -4
- package/dist/transactions/marginAdmin.d.mts +7 -7
- package/dist/transactions/marginLiquidations.d.mts +3 -3
- package/dist/transactions/marginMaintainer.d.mts +5 -5
- package/dist/transactions/marginManager.d.mts +32 -32
- package/dist/transactions/marginPool.d.mts +18 -18
- package/dist/transactions/marginPool.d.mts.map +1 -1
- 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 +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
package/src/predict/decode.ts
CHANGED
|
@@ -50,8 +50,8 @@ function eventBytes(e: DecodableEvent): Uint8Array | null {
|
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
// Match by defining package + module + struct name. Events are typed by the
|
|
53
|
-
//
|
|
54
|
-
//
|
|
53
|
+
// package version that introduced their struct, not the latest Move-call target.
|
|
54
|
+
// All events decoded here were introduced in v1.
|
|
55
55
|
function matches(e: DecodableEvent, pkg: string, module: string, name: string): boolean {
|
|
56
56
|
const tag = e.eventType ?? e.type;
|
|
57
57
|
if (tag) {
|
|
@@ -246,7 +246,7 @@ export interface BuilderCodeReceipt {
|
|
|
246
246
|
export function decodeMints(cfg: PredictConfig, result: DecodableTransactionResult): MintReceipt[] {
|
|
247
247
|
return decodeAll(
|
|
248
248
|
result,
|
|
249
|
-
cfg.packages.predict,
|
|
249
|
+
cfg.packages.predictV1 ?? cfg.packages.predict,
|
|
250
250
|
'order_events',
|
|
251
251
|
'OrderMinted',
|
|
252
252
|
orderEvents.OrderMinted,
|
|
@@ -288,7 +288,7 @@ export function decodeRedeems(
|
|
|
288
288
|
cfg: PredictConfig,
|
|
289
289
|
result: DecodableTransactionResult,
|
|
290
290
|
): RedeemReceipt[] {
|
|
291
|
-
const pkg = cfg.packages.predict;
|
|
291
|
+
const pkg = cfg.packages.predictV1 ?? cfg.packages.predict;
|
|
292
292
|
const live = decodeAll(
|
|
293
293
|
result,
|
|
294
294
|
pkg,
|
|
@@ -341,7 +341,7 @@ export function decodeClaims(
|
|
|
341
341
|
): ClaimReceipt[] {
|
|
342
342
|
return decodeAll(
|
|
343
343
|
result,
|
|
344
|
-
cfg.packages.predict,
|
|
344
|
+
cfg.packages.predictV1 ?? cfg.packages.predict,
|
|
345
345
|
'order_events',
|
|
346
346
|
'SettledOrderRedeemed',
|
|
347
347
|
orderEvents.SettledOrderRedeemed,
|
|
@@ -403,7 +403,7 @@ export function decodePlpRequests(
|
|
|
403
403
|
cfg: PredictConfig,
|
|
404
404
|
result: DecodableTransactionResult,
|
|
405
405
|
): PlpRequestReceipt[] {
|
|
406
|
-
const pkg = cfg.packages.predict;
|
|
406
|
+
const pkg = cfg.packages.predictV1 ?? cfg.packages.predict;
|
|
407
407
|
// Supply/WithdrawRequested differ only in their min-out field (unused here);
|
|
408
408
|
// pick the fields both share so either generated struct's parse feeds `make`.
|
|
409
409
|
type RequestedCommon = Pick<
|
|
@@ -441,7 +441,7 @@ export function decodePlpCancels(
|
|
|
441
441
|
): PlpCancelReceipt[] {
|
|
442
442
|
return decodeAll(
|
|
443
443
|
result,
|
|
444
|
-
cfg.packages.predict,
|
|
444
|
+
cfg.packages.predictV1 ?? cfg.packages.predict,
|
|
445
445
|
'vault_events',
|
|
446
446
|
'RequestCancelled',
|
|
447
447
|
vaultEvents.RequestCancelled,
|
|
@@ -462,7 +462,7 @@ export function decodeBuilderCodeSets(
|
|
|
462
462
|
): BuilderCodeReceipt[] {
|
|
463
463
|
return decodeAll(
|
|
464
464
|
result,
|
|
465
|
-
cfg.packages.predict,
|
|
465
|
+
cfg.packages.predictV1 ?? cfg.packages.predict,
|
|
466
466
|
'builder_code_events',
|
|
467
467
|
'BuilderCodeSet',
|
|
468
468
|
builderCodeEvents.BuilderCodeSet,
|
package/src/predict/index.ts
CHANGED
|
@@ -14,6 +14,7 @@ export type {
|
|
|
14
14
|
MarketDescriptor,
|
|
15
15
|
MarketSummary,
|
|
16
16
|
MintAmountOptions,
|
|
17
|
+
MintCostOptions,
|
|
17
18
|
MintOptions,
|
|
18
19
|
MintQuote,
|
|
19
20
|
PlpSupplyOptions,
|
|
@@ -92,6 +93,14 @@ export type { Side } from './ticks.js';
|
|
|
92
93
|
export * as pricing from './pricing.js';
|
|
93
94
|
export type { PricerSnapshot } from './reads/pricing.js';
|
|
94
95
|
|
|
96
|
+
// === Client-side cost === the deployed FEE math as an exact integer port, so a quote needs no
|
|
97
|
+
// chain call: `cost.mintCost` (all-in debit for a quantity), `cost.mintCostForBudget` (the
|
|
98
|
+
// `mint_exact_cost` budget search), `cost.redeemLiveProceeds` (net credited by a live close),
|
|
99
|
+
// plus the components they are built from. Probabilities come from `pricing.*` or from the
|
|
100
|
+
// chain (`read.price`); the fee policy is the market's `MarketCreated` snapshot, with
|
|
101
|
+
// `cost.SHIPPED_FEE_POLICY` as the shipped template.
|
|
102
|
+
export * as cost from './cost.js';
|
|
103
|
+
|
|
95
104
|
// === Errors ===
|
|
96
105
|
export { PredictInputError, PredictMoveError, decodeMoveAbort } from './errors.js';
|
|
97
106
|
export type { MoveAbortError } from './errors.js';
|
|
@@ -83,7 +83,7 @@ export async function resolvePositionsTable(
|
|
|
83
83
|
// The PredictData field id is derivable — no listing needed for this hop.
|
|
84
84
|
const dataFieldId = deriveDynamicFieldID(
|
|
85
85
|
accountUid,
|
|
86
|
-
`${config.accountPackageId}::account::DataKey<${config.
|
|
86
|
+
`${config.accountPackageId}::account::DataKey<${config.predictPackageIdV1}::predict_account::PredictApp>`,
|
|
87
87
|
new Uint8Array([0]), // DataKey's hidden dummy_field: bool = false
|
|
88
88
|
);
|
|
89
89
|
const fieldContent = await contentOf(client, dataFieldId);
|
package/src/predict/tx/trade.ts
CHANGED
|
@@ -6,11 +6,12 @@ import { U64_MAX } from '../units.js';
|
|
|
6
6
|
import * as expiryMarket from '../../contracts/deepbook_predict/expiry_market.js';
|
|
7
7
|
import { withAuth } from './common.js';
|
|
8
8
|
|
|
9
|
-
// The
|
|
9
|
+
// The trade calls with their `auth` argument already supplied (see `withAuth`): each
|
|
10
10
|
// takes its generated options minus that slot and expands to auth → call.
|
|
11
11
|
const authed = {
|
|
12
12
|
mintExactQuantity: withAuth(expiryMarket.mintExactQuantity),
|
|
13
13
|
mintExactAmount: withAuth(expiryMarket.mintExactAmount),
|
|
14
|
+
mintExactCost: withAuth(expiryMarket.mintExactCost),
|
|
14
15
|
redeemLive: withAuth(expiryMarket.redeemLive),
|
|
15
16
|
redeemSettled: withAuth(expiryMarket.redeemSettled),
|
|
16
17
|
};
|
|
@@ -127,6 +128,34 @@ export function mintExactAmount(
|
|
|
127
128
|
);
|
|
128
129
|
}
|
|
129
130
|
|
|
131
|
+
/** Mint within an all-in budget, including fees, using the v2 entrypoint. */
|
|
132
|
+
export function mintExactCost(
|
|
133
|
+
config: GeneratedConfig,
|
|
134
|
+
args: {
|
|
135
|
+
expiryMarketId: string;
|
|
136
|
+
wrapperId: string;
|
|
137
|
+
lowerTick: bigint;
|
|
138
|
+
higherTick: bigint;
|
|
139
|
+
maxCostRaw: bigint;
|
|
140
|
+
minQuantityRaw: bigint;
|
|
141
|
+
} & MarketFeeds,
|
|
142
|
+
): (tx: Transaction) => TransactionResult {
|
|
143
|
+
return liveTrade(config, args, (pricer) =>
|
|
144
|
+
authed.mintExactCost({
|
|
145
|
+
config,
|
|
146
|
+
arguments: {
|
|
147
|
+
market: args.expiryMarketId,
|
|
148
|
+
wrapper: args.wrapperId,
|
|
149
|
+
pricer,
|
|
150
|
+
lowerTick: args.lowerTick,
|
|
151
|
+
higherTick: args.higherTick,
|
|
152
|
+
maxCost: args.maxCostRaw,
|
|
153
|
+
minQuantity: args.minQuantityRaw,
|
|
154
|
+
},
|
|
155
|
+
}),
|
|
156
|
+
);
|
|
157
|
+
}
|
|
158
|
+
|
|
130
159
|
// Owner-authorized redeem of a live (not-yet-settled) position: close `closeQuantityRaw`
|
|
131
160
|
// of `orderId` at the live pricer's mark, enforcing close-side slippage floors
|
|
132
161
|
// (`minProbabilityRaw`/`minProceedsRaw`, default 0 = uncapped). Returns `Option<u256>`:
|
package/src/sessions.ts
CHANGED
|
@@ -26,8 +26,10 @@ import { SessionsData } from './contracts/deepbook_sessions/sessions.js';
|
|
|
26
26
|
* registry. `sessionsPackageId` and `sessionsConfig` come from the sessions deployment.
|
|
27
27
|
*/
|
|
28
28
|
export interface SessionsConfig extends DeepbookSessionsConfig {
|
|
29
|
-
/** The `deepbook_sessions` Move package id. */
|
|
29
|
+
/** The latest `deepbook_sessions` Move-call package id. */
|
|
30
30
|
sessionsPackageId: string;
|
|
31
|
+
/** Original ID for v1 structs. Omit only for an unupgraded custom deployment. */
|
|
32
|
+
sessionsPackageIdV1?: string;
|
|
31
33
|
/** The shared `SessionsConfig` object id. */
|
|
32
34
|
sessionsConfig: string;
|
|
33
35
|
/** The shared `account` Move package id. */
|
|
@@ -196,7 +198,7 @@ export class SessionsContract {
|
|
|
196
198
|
// `0x2::derived_object::DerivedObjectKey<..>` and yield an id that points at nothing.
|
|
197
199
|
return deriveDynamicFieldID(
|
|
198
200
|
this.deriveAccountId(owner),
|
|
199
|
-
`${this.#config.accountPackageId}::account::DataKey<${this.#config.sessionsPackageId}::sessions::SessionsApp>`,
|
|
201
|
+
`${this.#config.accountPackageId}::account::DataKey<${this.#config.sessionsPackageIdV1 ?? this.#config.sessionsPackageId}::sessions::SessionsApp>`,
|
|
200
202
|
// DataKey is source-empty; Move's hidden `dummy_field: bool` is the key's one byte.
|
|
201
203
|
new Uint8Array([0]),
|
|
202
204
|
);
|
|
@@ -342,6 +344,39 @@ export class SessionsContract {
|
|
|
342
344
|
);
|
|
343
345
|
}
|
|
344
346
|
|
|
347
|
+
/**
|
|
348
|
+
* Mint within an all-in budget as a session. Amounts are raw Move units.
|
|
349
|
+
* Requires Sessions/Predict v2 (currently Testnet; Mainnet is still v1).
|
|
350
|
+
*/
|
|
351
|
+
mintExactCost(params: {
|
|
352
|
+
expiryMarketId: string;
|
|
353
|
+
wrapperId: string;
|
|
354
|
+
protocolConfig: string;
|
|
355
|
+
pricer: TransactionArgument;
|
|
356
|
+
lowerTick: number | bigint;
|
|
357
|
+
higherTick: number | bigint;
|
|
358
|
+
maxCost: number | bigint;
|
|
359
|
+
minQuantity: number | bigint;
|
|
360
|
+
}) {
|
|
361
|
+
return (tx: Transaction): TransactionResult =>
|
|
362
|
+
tx.add(
|
|
363
|
+
sessions.mintExactCost({
|
|
364
|
+
config: this.#generatedConfig,
|
|
365
|
+
arguments: {
|
|
366
|
+
market: params.expiryMarketId,
|
|
367
|
+
accountRegistry: this.#config.accountRegistry,
|
|
368
|
+
wrapper: params.wrapperId,
|
|
369
|
+
config: params.protocolConfig,
|
|
370
|
+
pricer: params.pricer,
|
|
371
|
+
lowerTick: params.lowerTick,
|
|
372
|
+
higherTick: params.higherTick,
|
|
373
|
+
maxCost: params.maxCost,
|
|
374
|
+
minQuantity: params.minQuantity,
|
|
375
|
+
},
|
|
376
|
+
}),
|
|
377
|
+
);
|
|
378
|
+
}
|
|
379
|
+
|
|
345
380
|
/**
|
|
346
381
|
* @description Close part or all of a live position at the pricer's mark, as `session`.
|
|
347
382
|
* `minProbability` / `minProceeds` are close-side slippage floors; `0` disables either,
|