@mysten/deepbook-v3 2.1.4 → 2.3.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 +43 -0
- package/PREDICT.md +17 -5
- package/dist/account.d.mts.map +1 -1
- package/dist/account.mjs +3 -1
- package/dist/account.mjs.map +1 -1
- package/dist/client.d.mts +2 -2
- package/dist/contracts/account/account_events.d.mts +20 -20
- package/dist/contracts/deepbook/account.d.mts +18 -18
- package/dist/contracts/deepbook/balances.d.mts +4 -4
- package/dist/contracts/deepbook/order.d.mts +12 -12
- package/dist/contracts/deepbook_predict/deps/sui/vec_map.mjs +37 -0
- package/dist/contracts/deepbook_predict/deps/sui/vec_map.mjs.map +1 -0
- package/dist/contracts/deepbook_predict/expiry_cash.mjs +1 -1
- package/dist/contracts/deepbook_predict/expiry_cash.mjs.map +1 -1
- package/dist/contracts/deepbook_predict/expiry_market.mjs +15 -6
- package/dist/contracts/deepbook_predict/expiry_market.mjs.map +1 -1
- package/dist/contracts/deepbook_predict/market_manager.mjs.map +1 -1
- package/dist/contracts/deepbook_predict/order_events.mjs.map +1 -1
- package/dist/contracts/deepbook_predict/plp.mjs +53 -31
- package/dist/contracts/deepbook_predict/plp.mjs.map +1 -1
- package/dist/contracts/deepbook_predict/pool_accounting.mjs +7 -7
- package/dist/contracts/deepbook_predict/pool_accounting.mjs.map +1 -1
- package/dist/contracts/deepbook_predict/predict_account.mjs +1 -1
- package/dist/contracts/deepbook_predict/predict_account.mjs.map +1 -1
- package/dist/contracts/deepbook_predict/pricing.mjs +13 -1
- package/dist/contracts/deepbook_predict/pricing.mjs.map +1 -1
- package/dist/contracts/deepbook_predict/registry.mjs +2 -1
- package/dist/contracts/deepbook_predict/registry.mjs.map +1 -1
- package/dist/contracts/deepbook_predict/strike_exposure.mjs.map +1 -1
- package/dist/contracts/deepbook_predict/strike_payout_tree.mjs +13 -1
- package/dist/contracts/deepbook_predict/strike_payout_tree.mjs.map +1 -1
- package/dist/contracts/deepbook_predict/vault_events.mjs +19 -7
- package/dist/contracts/deepbook_predict/vault_events.mjs.map +1 -1
- 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 +22 -22
- package/dist/contracts/deepbook_sessions/sessions.d.mts.map +1 -1
- package/dist/deployments/index.d.mts +3 -2
- package/dist/deployments/index.d.mts.map +1 -1
- package/dist/deployments/index.mjs +4 -1
- package/dist/deployments/index.mjs.map +1 -1
- package/dist/deployments/mainnet.d.mts +14 -0
- package/dist/deployments/mainnet.d.mts.map +1 -0
- package/dist/deployments/mainnet.mjs +73 -0
- package/dist/deployments/mainnet.mjs.map +1 -0
- package/dist/deployments/testnet.mjs +23 -23
- package/dist/deployments/testnet.mjs.map +1 -1
- package/dist/deployments/types.d.mts +1 -1
- package/dist/predict/client.d.mts +25 -4
- package/dist/predict/client.d.mts.map +1 -1
- package/dist/predict/client.mjs +4 -4
- package/dist/predict/client.mjs.map +1 -1
- package/dist/predict/config/index.d.mts +2 -0
- package/dist/predict/config/index.d.mts.map +1 -1
- package/dist/predict/config/index.mjs +4 -1
- package/dist/predict/config/index.mjs.map +1 -1
- package/dist/predict/config/mainnet.d.mts +17 -0
- package/dist/predict/config/mainnet.d.mts.map +1 -0
- package/dist/predict/config/mainnet.mjs +26 -0
- package/dist/predict/config/mainnet.mjs.map +1 -0
- package/dist/predict/config/types.d.mts +6 -0
- package/dist/predict/config/types.d.mts.map +1 -1
- package/dist/predict/index.d.mts +4 -2
- package/dist/predict/index.mjs +3 -1
- package/dist/predict/pricing.d.mts +6 -6
- package/dist/predict/pricing.d.mts.map +1 -1
- package/dist/predict/pricing.mjs +6 -6
- package/dist/predict/pricing.mjs.map +1 -1
- package/dist/predict/reads/balances.mjs.map +1 -1
- package/dist/predict/reads/markets.mjs +1 -1
- package/dist/predict/reads/markets.mjs.map +1 -1
- package/dist/predict/reads/pricing.d.mts +2 -1
- package/dist/predict/reads/pricing.d.mts.map +1 -1
- package/dist/predict/reads/pricing.mjs.map +1 -1
- package/dist/sessions.d.mts.map +1 -1
- package/dist/sessions.mjs +3 -1
- 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/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/poolProxy.d.mts +8 -8
- package/package.json +3 -3
- package/src/account.ts +3 -1
- package/src/contracts/deepbook_predict/builder_code.ts +3 -3
- package/src/contracts/deepbook_predict/config_events.ts +9 -2
- package/src/contracts/deepbook_predict/deps/sui/vec_map.ts +33 -0
- package/src/contracts/deepbook_predict/expiry_cash.ts +1 -1
- package/src/contracts/deepbook_predict/expiry_market.ts +70 -11
- package/src/contracts/deepbook_predict/market_lifecycle_cap.ts +3 -10
- package/src/contracts/deepbook_predict/market_manager.ts +2 -2
- package/src/contracts/deepbook_predict/order_events.ts +6 -6
- package/src/contracts/deepbook_predict/plp.ts +263 -81
- package/src/contracts/deepbook_predict/pool_accounting.ts +14 -14
- package/src/contracts/deepbook_predict/pool_valuation_cap.ts +69 -0
- package/src/contracts/deepbook_predict/predict_account.ts +1 -1
- package/src/contracts/deepbook_predict/pricing.ts +16 -4
- package/src/contracts/deepbook_predict/protocol_config.ts +202 -7
- package/src/contracts/deepbook_predict/registry.ts +91 -17
- package/src/contracts/deepbook_predict/strike_exposure.ts +1 -1
- package/src/contracts/deepbook_predict/strike_payout_tree.ts +27 -0
- package/src/contracts/deepbook_predict/vault_events.ts +45 -14
- package/src/contracts/propbook/block_scholes_store.ts +8 -42
- package/src/deployments/index.ts +13 -3
- package/src/deployments/mainnet.ts +107 -0
- package/src/deployments/testnet.ts +25 -25
- package/src/deployments/types.ts +1 -1
- package/src/predict/client.ts +45 -15
- package/src/predict/config/index.ts +7 -2
- package/src/predict/config/mainnet.ts +27 -0
- package/src/predict/config/types.ts +7 -1
- package/src/predict/index.ts +5 -0
- package/src/predict/pricing.ts +11 -9
- package/src/predict/reads/balances.ts +1 -1
- package/src/predict/reads/markets.ts +1 -1
- package/src/predict/reads/pricing.ts +2 -1
- package/src/sessions.ts +4 -1
|
@@ -23,29 +23,16 @@ import { type Transaction, type TransactionArgument } from '@mysten/sui/transact
|
|
|
23
23
|
import * as table from './deps/sui/table.js';
|
|
24
24
|
const $moduleName = '@local-pkg/propbook::block_scholes_store';
|
|
25
25
|
/**
|
|
26
|
-
* One accepted observation
|
|
27
|
-
*
|
|
28
|
-
* not changed republishes under its original model time, so only
|
|
29
|
-
* `source_timestamp_ms` distinguishes a quiet feed from a stopped one.
|
|
26
|
+
* One accepted observation paired with its signed source time and on-chain
|
|
27
|
+
* recording time.
|
|
30
28
|
*/
|
|
31
29
|
export function BsRead<Value extends BcsType<any>>(...typeParameters: [Value]) {
|
|
32
30
|
return new MoveStruct({
|
|
33
31
|
name: `${$moduleName}::BsRead<${typeParameters[0].name as Value['name']}>`,
|
|
34
32
|
fields: {
|
|
35
33
|
/**
|
|
36
|
-
* Provider
|
|
37
|
-
*
|
|
38
|
-
* ordering keys on this first. The published VALUES are as-of the envelope time:
|
|
39
|
-
* per the provider contract, an SVI publish whose model time is unchanged carries
|
|
40
|
-
* the same calibration already rolled down to its new publish time, never
|
|
41
|
-
* duplicate data.
|
|
42
|
-
*/
|
|
43
|
-
model_timestamp_ms: U64,
|
|
44
|
-
/**
|
|
45
|
-
* Envelope time of the batch this observation arrived in, advancing on every
|
|
46
|
-
* provider flush and never regressing once stored (see `apply`). The economic
|
|
47
|
-
* clock: consumers gate freshness on it and the SVI roll-down anchors on it, so a
|
|
48
|
-
* republished unchanged value is re-asserted as current at its new envelope time.
|
|
34
|
+
* Provider value/SVI time in Unix milliseconds. Latest ordering, exact history,
|
|
35
|
+
* freshness, and SVI roll-down all key on this clock.
|
|
49
36
|
*/
|
|
50
37
|
source_timestamp_ms: U64,
|
|
51
38
|
/** Sui clock time when the accepting transaction executed. */
|
|
@@ -135,7 +122,7 @@ export const BlockScholesBatchIngested = new MoveStruct({
|
|
|
135
122
|
propbook_oracle_id: bcs.Address,
|
|
136
123
|
/** `0` = spot, `1` = forward, and `2` = SVI. */
|
|
137
124
|
series_kind: bcs.u8(),
|
|
138
|
-
|
|
125
|
+
batch_timestamp_ms: U64,
|
|
139
126
|
/** Sui clock time when the batch ingestion transaction executed. */
|
|
140
127
|
onchain_timestamp_ms: U64,
|
|
141
128
|
/** Verified observations carried by the batch. */
|
|
@@ -366,8 +353,8 @@ export interface SpotAtOptions {
|
|
|
366
353
|
];
|
|
367
354
|
}
|
|
368
355
|
/**
|
|
369
|
-
* Returns the canonical spot observation
|
|
370
|
-
* `source_timestamp_ms`.
|
|
356
|
+
* Returns the canonical spot observation whose provider source timestamp is
|
|
357
|
+
* exactly `source_timestamp_ms`.
|
|
371
358
|
*/
|
|
372
359
|
export function spotAt(options: SpotAtOptions) {
|
|
373
360
|
const packageAddress = options.package ?? '@local-pkg/propbook';
|
|
@@ -427,27 +414,6 @@ export function svi(options: SviOptions) {
|
|
|
427
414
|
arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
|
|
428
415
|
});
|
|
429
416
|
}
|
|
430
|
-
export interface ReadModelTimestampMsArguments {
|
|
431
|
-
read: TransactionArgument;
|
|
432
|
-
}
|
|
433
|
-
export interface ReadModelTimestampMsOptions {
|
|
434
|
-
package?: string;
|
|
435
|
-
arguments: ReadModelTimestampMsArguments | [read: TransactionArgument];
|
|
436
|
-
typeArguments: [string];
|
|
437
|
-
}
|
|
438
|
-
export function readModelTimestampMs(options: ReadModelTimestampMsOptions) {
|
|
439
|
-
const packageAddress = options.package ?? '@local-pkg/propbook';
|
|
440
|
-
const argumentsTypes = [null] satisfies (string | null)[];
|
|
441
|
-
const parameterNames = ['read'];
|
|
442
|
-
return (tx: Transaction) =>
|
|
443
|
-
tx.moveCall({
|
|
444
|
-
package: packageAddress,
|
|
445
|
-
module: 'block_scholes_store',
|
|
446
|
-
function: 'read_model_timestamp_ms',
|
|
447
|
-
arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
|
|
448
|
-
typeArguments: options.typeArguments,
|
|
449
|
-
});
|
|
450
|
-
}
|
|
451
417
|
export interface ReadSourceTimestampMsArguments {
|
|
452
418
|
read: TransactionArgument;
|
|
453
419
|
}
|
|
@@ -717,7 +683,7 @@ export interface InsertAtOptions {
|
|
|
717
683
|
}
|
|
718
684
|
/**
|
|
719
685
|
* Insert the canonical spot batch into exact minute-boundary history without
|
|
720
|
-
* changing `latest`. A valid batch whose
|
|
686
|
+
* changing `latest`. A valid batch whose spot update source timestamp is not a
|
|
721
687
|
* minute boundary, or whose spot is zero or wider than `u64`, is ignored without
|
|
722
688
|
* aborting. The first admissible observation at a boundary owns the key and cannot
|
|
723
689
|
* be replaced.
|
package/src/deployments/index.ts
CHANGED
|
@@ -12,6 +12,13 @@
|
|
|
12
12
|
|
|
13
13
|
import type { SuiClientTypes } from '@mysten/sui/client';
|
|
14
14
|
|
|
15
|
+
import {
|
|
16
|
+
MAINNET_ACCOUNT,
|
|
17
|
+
MAINNET_DEPLOYMENT,
|
|
18
|
+
MAINNET_PREDICT,
|
|
19
|
+
MAINNET_SESSIONS,
|
|
20
|
+
MAINNET_UNITS,
|
|
21
|
+
} from './mainnet.js';
|
|
15
22
|
import {
|
|
16
23
|
TESTNET_ACCOUNT,
|
|
17
24
|
TESTNET_DEPLOYMENT,
|
|
@@ -30,9 +37,10 @@ export type {
|
|
|
30
37
|
} from './types.js';
|
|
31
38
|
|
|
32
39
|
export { TESTNET_ACCOUNT, TESTNET_DEPLOYMENT, TESTNET_PREDICT, TESTNET_SESSIONS, TESTNET_UNITS };
|
|
40
|
+
export { MAINNET_ACCOUNT, MAINNET_DEPLOYMENT, MAINNET_PREDICT, MAINNET_SESSIONS, MAINNET_UNITS };
|
|
33
41
|
|
|
34
|
-
/** Networks this package carries ids for.
|
|
35
|
-
export type DeployedNetwork = 'testnet';
|
|
42
|
+
/** Networks this package carries ids for. */
|
|
43
|
+
export type DeployedNetwork = 'testnet' | 'mainnet';
|
|
36
44
|
|
|
37
45
|
/**
|
|
38
46
|
* Accepts the same wide network type the Sui client exposes, so `getUnits(client.network)`
|
|
@@ -45,7 +53,7 @@ export type NetworkArg = SuiClientTypes.Network;
|
|
|
45
53
|
function unrecorded(network: string, override: string): Error {
|
|
46
54
|
return new Error(
|
|
47
55
|
`@mysten/deepbook-v3: no deployment recorded for network '${network}'. ` +
|
|
48
|
-
'Predict, sessions and the account primitive are testnet
|
|
56
|
+
'Predict, sessions and the account primitive are recorded for testnet and mainnet. ' +
|
|
49
57
|
`For your own deployment, ${override}`,
|
|
50
58
|
);
|
|
51
59
|
}
|
|
@@ -58,6 +66,7 @@ function unrecorded(network: string, override: string): Error {
|
|
|
58
66
|
*/
|
|
59
67
|
export function getDeployment(network: NetworkArg): DeploymentInfo {
|
|
60
68
|
if (network === 'testnet') return TESTNET_DEPLOYMENT;
|
|
69
|
+
if (network === 'mainnet') return MAINNET_DEPLOYMENT;
|
|
61
70
|
throw unrecorded(network, 'read the deployment name and commit from your own deploy manifest.');
|
|
62
71
|
}
|
|
63
72
|
|
|
@@ -69,5 +78,6 @@ export function getDeployment(network: NetworkArg): DeploymentInfo {
|
|
|
69
78
|
*/
|
|
70
79
|
export function getUnits(network: NetworkArg): DeploymentUnits {
|
|
71
80
|
if (network === 'testnet') return TESTNET_UNITS;
|
|
81
|
+
if (network === 'mainnet') return MAINNET_UNITS;
|
|
72
82
|
throw unrecorded(network, 'read these scale constants from your own deploy manifest.');
|
|
73
83
|
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
// Copyright (c) Mysten Labs, Inc.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
// GENERATED by `pnpm sync-deployment` from the deploy tooling's own manifest
|
|
5
|
+
// (`packages/predict/deployment/deployment.mainnet.json`). Do not hand-edit:
|
|
6
|
+
// the next regeneration overwrites it, and a hand-patched id is exactly the drift this
|
|
7
|
+
// file exists to prevent. To move to a new deployment, check the sibling deepbookv3
|
|
8
|
+
// checkout out to the new anchor and re-run the script.
|
|
9
|
+
//
|
|
10
|
+
// Deployment: deepbook-predict-mainnet
|
|
11
|
+
// sourceCommit: 14a7e8f822e0397df2d61fbfbce3ef21086891c2
|
|
12
|
+
//
|
|
13
|
+
// Runtime-dependency-free — every subpath reads a slice of this, so a value import here
|
|
14
|
+
// would pull that module into all of their graphs. The type import below is erased.
|
|
15
|
+
//
|
|
16
|
+
// Frozen: these are shared module singletons, so an accessor handing one to a caller who
|
|
17
|
+
// mutates it would change what every other caller sees.
|
|
18
|
+
|
|
19
|
+
import type {
|
|
20
|
+
AccountIds,
|
|
21
|
+
DeploymentInfo,
|
|
22
|
+
DeploymentUnits,
|
|
23
|
+
PredictIds,
|
|
24
|
+
SessionsIds,
|
|
25
|
+
} from './types.js';
|
|
26
|
+
|
|
27
|
+
/** Which on-chain deployment the ids below came from. */
|
|
28
|
+
export const MAINNET_DEPLOYMENT: DeploymentInfo = Object.freeze({
|
|
29
|
+
deployment: 'deepbook-predict-mainnet',
|
|
30
|
+
network: 'mainnet',
|
|
31
|
+
chainId: '35834a8a',
|
|
32
|
+
sourceCommit: '14a7e8f822e0397df2d61fbfbce3ef21086891c2',
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
/** Ids for the shared `account` primitive — the `/account` subpath's slice. */
|
|
36
|
+
export const MAINNET_ACCOUNT: AccountIds = Object.freeze({
|
|
37
|
+
accountPackageId: '0xa6f1b22aaeb429f6fd8f01c13f605256e00876457fd122da8a0e2c1045c75929',
|
|
38
|
+
accountRegistry: '0x210ba485d973b5356e9078318837137efabdd5ffb9eeb3705ba7eef3340324fc',
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Ids for time-limited sessions — the `/sessions` subpath's slice.
|
|
43
|
+
*
|
|
44
|
+
* `deepbookRegistry` is only needed by the DeepBook **spot** session wrappers; the Predict
|
|
45
|
+
* wrappers never take it. It is carried here so a spot caller does not have to reach into
|
|
46
|
+
* the package root for one id.
|
|
47
|
+
*/
|
|
48
|
+
export const MAINNET_SESSIONS: SessionsIds = Object.freeze({
|
|
49
|
+
sessionsPackageId: '0xebfa125baee571c1f8c903c1dd54a5bc57949db82469b836c32eca251756c82a',
|
|
50
|
+
sessionsConfig: '0x0c5f64365b3bf1f67827d6975893190079cc048247f9ff0b08390aa9ee697c5c',
|
|
51
|
+
accountPackageId: '0xa6f1b22aaeb429f6fd8f01c13f605256e00876457fd122da8a0e2c1045c75929',
|
|
52
|
+
accountRegistry: '0x210ba485d973b5356e9078318837137efabdd5ffb9eeb3705ba7eef3340324fc',
|
|
53
|
+
deepbookRegistry: '0xaf16199a2dff736e9f07a845f23c5da6df6f756eddb631aed9d24a93efc4549d',
|
|
54
|
+
deepbookCoreAccountPackageId:
|
|
55
|
+
'0xebcd5b403ee78021e3f78d1c77e2117a676caa8a9754dedb99e7b102b0d81872',
|
|
56
|
+
/** Required by every Predict session wrapper — they all take `config: &ProtocolConfig`. */
|
|
57
|
+
protocolConfig: '0x55e8800bcb31b792683ca4385bd533716e2a9721364236a69ee2c3bee61dd8f2',
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Scale constants the deployment owns rather than the SDK. Deployment-wide:
|
|
62
|
+
* `quoteCoinDecimals` and `fixedPointScale` apply to any subpath formatting a custody
|
|
63
|
+
* balance, not just Predict.
|
|
64
|
+
*/
|
|
65
|
+
export const MAINNET_UNITS: DeploymentUnits = Object.freeze({
|
|
66
|
+
positionLotSize: 10000,
|
|
67
|
+
fixedPointScale: 1000000000,
|
|
68
|
+
quoteCoinDecimals: 6,
|
|
69
|
+
positionQuantityDecimals: 6,
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
/** Ids for DeepBook Predict — the `/predict` subpath's slice. */
|
|
73
|
+
export const MAINNET_PREDICT: PredictIds = Object.freeze({
|
|
74
|
+
network: 'mainnet',
|
|
75
|
+
packages: Object.freeze({
|
|
76
|
+
predict: '0x774f9555865a7b96e31ec982f62d5bdf9d74bf57a6468b5ed41340c231afd7df',
|
|
77
|
+
account: '0xa6f1b22aaeb429f6fd8f01c13f605256e00876457fd122da8a0e2c1045c75929',
|
|
78
|
+
propbook: '0x2a63e378ab0138cdcb12651a093f3799f8b8e4f6c927ce6de0e8bc7ded0ec49d',
|
|
79
|
+
}),
|
|
80
|
+
objects: Object.freeze({
|
|
81
|
+
registry: '0xc98e430d82bed9f777288061faa1988da705a97db7f0da9f215ab372c53a2362',
|
|
82
|
+
protocolConfig: '0x55e8800bcb31b792683ca4385bd533716e2a9721364236a69ee2c3bee61dd8f2',
|
|
83
|
+
poolVault: '0x3f80653bf9324162254d89724276aae7b36ba7c83d4650214afbf266da98f492',
|
|
84
|
+
oracleRegistry: '0x1ff67a8499b0af7c0fbb26ba82c319be25413af93d9a961ee60f8d1229e7de7c',
|
|
85
|
+
accountRegistry: '0x210ba485d973b5356e9078318837137efabdd5ffb9eeb3705ba7eef3340324fc',
|
|
86
|
+
}),
|
|
87
|
+
quoteCoinType: '0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC',
|
|
88
|
+
/**
|
|
89
|
+
* `plp` is the LP share coin type. It is NOT derivable from `packages.predict`: a Move
|
|
90
|
+
* type tag keeps the ORIGINAL package id across an upgrade, while `packages.predict`
|
|
91
|
+
* moves to the latest. They agree only while predict is at v1.
|
|
92
|
+
*/
|
|
93
|
+
coinTypes: Object.freeze({
|
|
94
|
+
plp: '0x774f9555865a7b96e31ec982f62d5bdf9d74bf57a6468b5ed41340c231afd7df::plp::PLP',
|
|
95
|
+
deep: '0xdeeb7a4662eec9f2f3def03fb937a663dddaa2e215b8078a284d026b7946c270::deep::DEEP',
|
|
96
|
+
}),
|
|
97
|
+
units: MAINNET_UNITS,
|
|
98
|
+
underlyings: Object.freeze({
|
|
99
|
+
BTC: Object.freeze({
|
|
100
|
+
symbol: 'BTC',
|
|
101
|
+
propbookUnderlyingId: 1,
|
|
102
|
+
pythFeed: '0x44bd2e00549973bb6a58785836e97ed80b4979e67dc3bf312c997e56053e5376',
|
|
103
|
+
blockScholesValueStore: '0xe7c83ee4ac0c300d68d8d4c3d265d78287b4767dcbc5f279cd6f210b6248d493',
|
|
104
|
+
blockScholesSviStore: '0x8e5568aebf490c2adfd4e010a9b4ddcf7c774183f58c98fcd438bae1fc68f561',
|
|
105
|
+
}),
|
|
106
|
+
}),
|
|
107
|
+
});
|
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
// file exists to prevent. To move to a new deployment, check the sibling deepbookv3
|
|
8
8
|
// checkout out to the new anchor and re-run the script.
|
|
9
9
|
//
|
|
10
|
-
// Deployment: predict-testnet
|
|
11
|
-
// sourceCommit:
|
|
10
|
+
// Deployment: deepbook-predict-testnet
|
|
11
|
+
// sourceCommit: a928bd2da4b71abf7c4ea6f66abec2763308331e
|
|
12
12
|
//
|
|
13
13
|
// Runtime-dependency-free — every subpath reads a slice of this, so a value import here
|
|
14
14
|
// would pull that module into all of their graphs. The type import below is erased.
|
|
@@ -26,16 +26,16 @@ import type {
|
|
|
26
26
|
|
|
27
27
|
/** Which on-chain deployment the ids below came from. */
|
|
28
28
|
export const TESTNET_DEPLOYMENT: DeploymentInfo = Object.freeze({
|
|
29
|
-
deployment: 'predict-testnet
|
|
29
|
+
deployment: 'deepbook-predict-testnet',
|
|
30
30
|
network: 'testnet',
|
|
31
31
|
chainId: '4c78adac',
|
|
32
|
-
sourceCommit: '
|
|
32
|
+
sourceCommit: 'a928bd2da4b71abf7c4ea6f66abec2763308331e',
|
|
33
33
|
});
|
|
34
34
|
|
|
35
35
|
/** Ids for the shared `account` primitive — the `/account` subpath's slice. */
|
|
36
36
|
export const TESTNET_ACCOUNT: AccountIds = Object.freeze({
|
|
37
|
-
accountPackageId: '
|
|
38
|
-
accountRegistry: '
|
|
37
|
+
accountPackageId: '0x543139156cb90d1a73df33b5dca37d7c8bdce62506c7874ebc854afd319b98f1',
|
|
38
|
+
accountRegistry: '0xb889caefe327cbdea58e529e3b9e10dc93f1e661ddef32824d28527edf8d6385',
|
|
39
39
|
});
|
|
40
40
|
|
|
41
41
|
/**
|
|
@@ -46,15 +46,15 @@ export const TESTNET_ACCOUNT: AccountIds = Object.freeze({
|
|
|
46
46
|
* the package root for one id.
|
|
47
47
|
*/
|
|
48
48
|
export const TESTNET_SESSIONS: SessionsIds = Object.freeze({
|
|
49
|
-
sessionsPackageId: '
|
|
50
|
-
sessionsConfig: '
|
|
51
|
-
accountPackageId: '
|
|
52
|
-
accountRegistry: '
|
|
49
|
+
sessionsPackageId: '0x10c91d168dc4a04357f9d23795a204092ca46e5b97f8b9ef26fea95664d5bb38',
|
|
50
|
+
sessionsConfig: '0x63cde7c7d846f15c51802ec3d44ba44918658e3155b0d2e0cb26d6fc1b4dadd8',
|
|
51
|
+
accountPackageId: '0x543139156cb90d1a73df33b5dca37d7c8bdce62506c7874ebc854afd319b98f1',
|
|
52
|
+
accountRegistry: '0xb889caefe327cbdea58e529e3b9e10dc93f1e661ddef32824d28527edf8d6385',
|
|
53
53
|
deepbookRegistry: '0x7c256edbda983a2cd6f946655f4bf3f00a41043993781f8674a7046e8c0e11d1',
|
|
54
54
|
deepbookCoreAccountPackageId:
|
|
55
|
-
'
|
|
55
|
+
'0x2dbb8e6a5b9a8ac6201c7aeff6de0c7e7bca5dcd8d6c16538cb1a7447a298071',
|
|
56
56
|
/** Required by every Predict session wrapper — they all take `config: &ProtocolConfig`. */
|
|
57
|
-
protocolConfig: '
|
|
57
|
+
protocolConfig: '0xfeda745dfdef2cd9721c2ff1e1de538d103bc6012469d0eec10ea5de67f636d0',
|
|
58
58
|
});
|
|
59
59
|
|
|
60
60
|
/**
|
|
@@ -73,25 +73,25 @@ export const TESTNET_UNITS: DeploymentUnits = Object.freeze({
|
|
|
73
73
|
export const TESTNET_PREDICT: PredictIds = Object.freeze({
|
|
74
74
|
network: 'testnet',
|
|
75
75
|
packages: Object.freeze({
|
|
76
|
-
predict: '
|
|
77
|
-
account: '
|
|
78
|
-
propbook: '
|
|
76
|
+
predict: '0x25d075d2de915feda7ab9b8f855afe59cbcd4b2ce96f75324940c810f84da018',
|
|
77
|
+
account: '0x543139156cb90d1a73df33b5dca37d7c8bdce62506c7874ebc854afd319b98f1',
|
|
78
|
+
propbook: '0xa04a43dbbfb123feec96691a22809d8a87e9ac37ae9356079c439750145aa92b',
|
|
79
79
|
}),
|
|
80
80
|
objects: Object.freeze({
|
|
81
|
-
registry: '
|
|
82
|
-
protocolConfig: '
|
|
83
|
-
poolVault: '
|
|
84
|
-
oracleRegistry: '
|
|
85
|
-
accountRegistry: '
|
|
81
|
+
registry: '0xd21fab5444128eb65c5f6299564f583db72ad84d17581a4febe68878127100d5',
|
|
82
|
+
protocolConfig: '0xfeda745dfdef2cd9721c2ff1e1de538d103bc6012469d0eec10ea5de67f636d0',
|
|
83
|
+
poolVault: '0xd6b96a77d5acfd4f4a660cbd1098ed62abf2317e85a01274d1a4eeef19603767',
|
|
84
|
+
oracleRegistry: '0xda71af88a8b9d01b6913937a84c5a63bb4e1015a7a2142185ec9ef73f675615f',
|
|
85
|
+
accountRegistry: '0xb889caefe327cbdea58e529e3b9e10dc93f1e661ddef32824d28527edf8d6385',
|
|
86
86
|
}),
|
|
87
|
-
quoteCoinType: '
|
|
87
|
+
quoteCoinType: '0xc028557a1ed49e42ed091e115aedefd70a442b184c18fbec5c48d5b6c0b8c184::usdc::USDC',
|
|
88
88
|
/**
|
|
89
89
|
* `plp` is the LP share coin type. It is NOT derivable from `packages.predict`: a Move
|
|
90
90
|
* type tag keeps the ORIGINAL package id across an upgrade, while `packages.predict`
|
|
91
91
|
* moves to the latest. They agree only while predict is at v1.
|
|
92
92
|
*/
|
|
93
93
|
coinTypes: Object.freeze({
|
|
94
|
-
plp: '
|
|
94
|
+
plp: '0x25d075d2de915feda7ab9b8f855afe59cbcd4b2ce96f75324940c810f84da018::plp::PLP',
|
|
95
95
|
deep: '0x36dbef866a1d62bf7328989a10fb2f07d769f4ee587c0de4a0a256e57e0a58a8::deep::DEEP',
|
|
96
96
|
}),
|
|
97
97
|
units: TESTNET_UNITS,
|
|
@@ -99,9 +99,9 @@ export const TESTNET_PREDICT: PredictIds = Object.freeze({
|
|
|
99
99
|
BTC: Object.freeze({
|
|
100
100
|
symbol: 'BTC',
|
|
101
101
|
propbookUnderlyingId: 1,
|
|
102
|
-
pythFeed: '
|
|
103
|
-
blockScholesValueStore: '
|
|
104
|
-
blockScholesSviStore: '
|
|
102
|
+
pythFeed: '0x7179188b3a27758c53668a4ec09a81be114dea5ffabcf367f4e720a26db8ee59',
|
|
103
|
+
blockScholesValueStore: '0x77dee47fb870753c740439f436e0c30c00c60f13f171c901125b3d60f89518e5',
|
|
104
|
+
blockScholesSviStore: '0xe8aa80965d201e2cb18359c3aa315e3abc5bbf807a10a59d6e011ef41be5db7a',
|
|
105
105
|
}),
|
|
106
106
|
}),
|
|
107
107
|
});
|
package/src/deployments/types.ts
CHANGED
|
@@ -25,7 +25,7 @@ export interface DeploymentInfo {
|
|
|
25
25
|
*
|
|
26
26
|
* Only `positionLotSize` is currently read by the SDK (`PredictClient#assertLot`); the other
|
|
27
27
|
* three are shipped as the deployment's own record of its scales. `units.ts` still hardcodes
|
|
28
|
-
* the
|
|
28
|
+
* the USDC and fixed-point decimals, so do not read this as "the SDK derives its scaling
|
|
29
29
|
* from here" — wiring that up is separate work.
|
|
30
30
|
*/
|
|
31
31
|
export interface DeploymentUnits {
|
package/src/predict/client.ts
CHANGED
|
@@ -135,6 +135,29 @@ export interface CloseOptions {
|
|
|
135
135
|
quantity: number;
|
|
136
136
|
}
|
|
137
137
|
|
|
138
|
+
/** Options for `supplyPlp`. */
|
|
139
|
+
export interface PlpSupplyOptions {
|
|
140
|
+
/**
|
|
141
|
+
* Floor on the PLP minted for the whole request, as raw `bigint` shares — PLP is raw
|
|
142
|
+
* everywhere in this SDK. It is a floor on the MARK, not a share count: a flush quoting
|
|
143
|
+
* less does not fill smaller, it declines. Omitted → `0n`, no floor.
|
|
144
|
+
*
|
|
145
|
+
* How a miss is handled is the deployment's `lp_request_limit_flush_attempts`: at the
|
|
146
|
+
* shipped count of one the first flush below the floor cancels and refunds the request.
|
|
147
|
+
*/
|
|
148
|
+
minPlpOut?: bigint;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/** Options for `withdrawPlp`. */
|
|
152
|
+
export interface PlpWithdrawOptions {
|
|
153
|
+
/**
|
|
154
|
+
* Floor on the USDC paid for the whole request, in USD decimals like every other amount
|
|
155
|
+
* here. A floor on the MARK, not an amount: a flush quoting less declines rather than
|
|
156
|
+
* paying out smaller. Omitted → no floor. Measured after the protocol's withdraw fee.
|
|
157
|
+
*/
|
|
158
|
+
minUsdcOut?: number | string;
|
|
159
|
+
}
|
|
160
|
+
|
|
138
161
|
/** One tradeable market as returned by read.markets(). */
|
|
139
162
|
export interface ActiveMarket {
|
|
140
163
|
id: string;
|
|
@@ -171,7 +194,7 @@ export interface MarketSummary {
|
|
|
171
194
|
|
|
172
195
|
/** Aggregate pool figures. Balances in human units (shares raw); the pending fields
|
|
173
196
|
* are request COUNTS, not amounts — the on-chain getters expose queue lengths, and
|
|
174
|
-
* the escrowed
|
|
197
|
+
* the escrowed USDC/PLP behind them is tracked separately. */
|
|
175
198
|
export interface PoolSummary {
|
|
176
199
|
plpTotalSupply: bigint;
|
|
177
200
|
idleUsdc: number;
|
|
@@ -566,7 +589,7 @@ export class PredictClient {
|
|
|
566
589
|
},
|
|
567
590
|
|
|
568
591
|
// Withdraw `amountUsdc` from the account back to `owner`. By default the funds land
|
|
569
|
-
// in the owner's
|
|
592
|
+
// in the owner's USDC *address balance* (the versionless accumulator) via
|
|
570
593
|
// `0x2::coin::send_funds` — no coin-object churn, and they merge into the same
|
|
571
594
|
// balance `deposit` draws from, closing the loop. Pass `{ toCoinObject: true }` to
|
|
572
595
|
// instead receive a discrete `Coin<T>` object (for wallets/explorers that only
|
|
@@ -652,45 +675,52 @@ export class PredictClient {
|
|
|
652
675
|
},
|
|
653
676
|
|
|
654
677
|
// Queue a supply request pulling `amountUsdc` from the account's existing custody
|
|
655
|
-
// balance. `request_supply` auto-settles
|
|
678
|
+
// balance. `request_supply` auto-settles USDC then `account.withdraw`s the payment
|
|
656
679
|
// into queue escrow; the PLP fill is delivered at the next flush, not returned here.
|
|
657
680
|
// Command order is auth → request (auth is a hot potato consumed by this call). The
|
|
658
|
-
// `minPlpOut` slot is the per-request floor on PLP minted at flush —
|
|
659
|
-
// (no floor)
|
|
660
|
-
//
|
|
661
|
-
|
|
681
|
+
// `minPlpOut` slot is the per-request floor on PLP minted at flush — `options.minPlpOut`
|
|
682
|
+
// when given, otherwise 0 (no floor). At the shipped attempt count of one, the first
|
|
683
|
+
// flush whose mark quotes less cancels and refunds the request; three is the
|
|
684
|
+
// configurable maximum, not the default.
|
|
685
|
+
supplyPlp: (
|
|
686
|
+
owner: string,
|
|
687
|
+
amountUsdc: number | string,
|
|
688
|
+
options: PlpSupplyOptions = {},
|
|
689
|
+
): Transaction =>
|
|
662
690
|
txOf(
|
|
663
691
|
requestSupply({
|
|
664
692
|
config: this.#config,
|
|
665
693
|
arguments: {
|
|
666
694
|
wrapper: this.wrapperIdFor(owner),
|
|
667
695
|
amount: usdcToRaw(amountUsdc),
|
|
668
|
-
minPlpOut: 0n,
|
|
696
|
+
minPlpOut: options.minPlpOut ?? 0n,
|
|
669
697
|
},
|
|
670
698
|
}),
|
|
671
699
|
),
|
|
672
700
|
|
|
673
701
|
// Queue a withdraw request pulling `shares` (raw PLP u64) from account custody into
|
|
674
702
|
// queue escrow — the Move parameter is named `amount`, but on `request_withdraw` it
|
|
675
|
-
// counts PLP SHARES, not
|
|
703
|
+
// counts PLP SHARES, not USDC. Auto-settles flush-delivered PLP first; the USDC
|
|
676
704
|
// fill lands on the account at the next flush (no `withdraw_settled` entrypoint).
|
|
677
|
-
// Command order is auth → request. The `
|
|
678
|
-
// on
|
|
679
|
-
//
|
|
680
|
-
|
|
705
|
+
// Command order is auth → request. The `minUsdcOut` slot is the per-request floor
|
|
706
|
+
// on USDC paid at flush — `options.minUsdcOut` when given, otherwise 0 (no floor).
|
|
707
|
+
// At the shipped attempt count of one, the first flush whose mark quotes less
|
|
708
|
+
// cancels and refunds the request; three is the configurable maximum, not the
|
|
709
|
+
// default.
|
|
710
|
+
withdrawPlp: (owner: string, shares: bigint, options: PlpWithdrawOptions = {}): Transaction =>
|
|
681
711
|
txOf(
|
|
682
712
|
requestWithdraw({
|
|
683
713
|
config: this.#config,
|
|
684
714
|
arguments: {
|
|
685
715
|
wrapper: this.wrapperIdFor(owner),
|
|
686
716
|
amount: shares,
|
|
687
|
-
|
|
717
|
+
minUsdcOut: options.minUsdcOut === undefined ? 0n : usdcToRaw(options.minUsdcOut),
|
|
688
718
|
},
|
|
689
719
|
}),
|
|
690
720
|
),
|
|
691
721
|
|
|
692
722
|
// Cancel a still-pending supply request by queue `index`, refunding its escrowed
|
|
693
|
-
//
|
|
723
|
+
// USDC straight back into the requesting account. Command order is auth → cancel.
|
|
694
724
|
cancelSupplyPlp: (owner: string, index: bigint): Transaction =>
|
|
695
725
|
txOf(
|
|
696
726
|
cancelSupplyRequest({
|
|
@@ -1,17 +1,20 @@
|
|
|
1
1
|
// Copyright (c) Mysten Labs, Inc.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
import { MAINNET_CONFIG } from './mainnet.js';
|
|
3
4
|
import { TESTNET_CONFIG } from './testnet.js';
|
|
4
5
|
import type { PredictConfig } from './types.js';
|
|
5
6
|
import type { NetworkArg } from '../../deployments/index.js';
|
|
6
7
|
|
|
7
|
-
export { TESTNET_CONFIG };
|
|
8
|
+
export { TESTNET_CONFIG, MAINNET_CONFIG };
|
|
8
9
|
export type { PredictConfig, PredictPackages, UnderlyingConfig } from './types.js';
|
|
9
10
|
|
|
10
11
|
export function getConfig(network: NetworkArg): PredictConfig {
|
|
11
12
|
if (network === 'testnet') return TESTNET_CONFIG;
|
|
13
|
+
if (network === 'mainnet') return MAINNET_CONFIG;
|
|
12
14
|
throw new Error(
|
|
13
15
|
`@mysten/deepbook-v3/predict: no Predict deployment recorded for network '${network}'. ` +
|
|
14
|
-
'Predict is testnet
|
|
16
|
+
'Predict is recorded for testnet and mainnet; for your own deployment pass `config` to ' +
|
|
17
|
+
'PredictClient ' +
|
|
15
18
|
'or `predict({ config })`.',
|
|
16
19
|
);
|
|
17
20
|
}
|
|
@@ -20,6 +23,8 @@ export function getConfig(network: NetworkArg): PredictConfig {
|
|
|
20
23
|
export {
|
|
21
24
|
getDeployment,
|
|
22
25
|
getUnits,
|
|
26
|
+
MAINNET_DEPLOYMENT,
|
|
27
|
+
MAINNET_UNITS,
|
|
23
28
|
TESTNET_DEPLOYMENT,
|
|
24
29
|
TESTNET_UNITS,
|
|
25
30
|
} from '../../deployments/index.js';
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// Copyright (c) Mysten Labs, Inc.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { MAINNET_PREDICT } from '../../deployments/mainnet.js';
|
|
5
|
+
import type { PredictConfig } from './types.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Mainnet deployment constants, read from the shared generated record in
|
|
9
|
+
* `src/deployments/` rather than transcribed here. `/account` and `/sessions` read slices of
|
|
10
|
+
* that same record, so a redeploy (`pnpm sync-deployment`) moves every subpath together and
|
|
11
|
+
* they cannot end up addressing different deployments.
|
|
12
|
+
*
|
|
13
|
+
* The record is generated from the deploy tooling's `deployment.mainnet.json`; see
|
|
14
|
+
* `scripts/sync-deployment.ts`. `getDeployment('mainnet')` names the deployment and the
|
|
15
|
+
* deepbookv3 commit these ids came from.
|
|
16
|
+
*/
|
|
17
|
+
export const MAINNET_CONFIG: PredictConfig = Object.freeze({
|
|
18
|
+
// The record widens `network` to `string` so the published types don't pin a literal;
|
|
19
|
+
// this file is the mainnet config by construction.
|
|
20
|
+
network: 'mainnet',
|
|
21
|
+
packages: MAINNET_PREDICT.packages,
|
|
22
|
+
objects: MAINNET_PREDICT.objects,
|
|
23
|
+
quoteCoinType: MAINNET_PREDICT.quoteCoinType,
|
|
24
|
+
coinTypes: MAINNET_PREDICT.coinTypes,
|
|
25
|
+
units: MAINNET_PREDICT.units,
|
|
26
|
+
underlyings: MAINNET_PREDICT.underlyings,
|
|
27
|
+
});
|
|
@@ -34,7 +34,13 @@ export interface PredictConfig {
|
|
|
34
34
|
oracleRegistry: string;
|
|
35
35
|
accountRegistry: string;
|
|
36
36
|
};
|
|
37
|
-
|
|
37
|
+
/**
|
|
38
|
+
* The deployment's settlement coin type. Always read this rather than assuming a type:
|
|
39
|
+
* the contracts renamed the collateral to `usdc::usdc::USDC`, but a deployment published
|
|
40
|
+
* before that rename still serves its original coin type, and this field is what the
|
|
41
|
+
* deployment record actually carries.
|
|
42
|
+
*/
|
|
43
|
+
quoteCoinType: string;
|
|
38
44
|
/**
|
|
39
45
|
* Coin types the deployment owns. `plp` is NOT derivable from `packages.predict`: a Move
|
|
40
46
|
* type tag keeps the ORIGINAL package id across an upgrade, while `packages.predict`
|
package/src/predict/index.ts
CHANGED
|
@@ -16,6 +16,8 @@ export type {
|
|
|
16
16
|
MintAmountOptions,
|
|
17
17
|
MintOptions,
|
|
18
18
|
MintQuote,
|
|
19
|
+
PlpSupplyOptions,
|
|
20
|
+
PlpWithdrawOptions,
|
|
19
21
|
PoolSummary,
|
|
20
22
|
RedeemQuote,
|
|
21
23
|
} from './client.js';
|
|
@@ -30,10 +32,13 @@ export { deriveAccountWrapperId, generateAuth } from './tx/common.js';
|
|
|
30
32
|
|
|
31
33
|
// === Config ===
|
|
32
34
|
export {
|
|
35
|
+
MAINNET_CONFIG,
|
|
33
36
|
TESTNET_CONFIG,
|
|
34
37
|
getConfig,
|
|
35
38
|
getDeployment,
|
|
36
39
|
getUnits,
|
|
40
|
+
MAINNET_DEPLOYMENT,
|
|
41
|
+
MAINNET_UNITS,
|
|
37
42
|
TESTNET_DEPLOYMENT,
|
|
38
43
|
TESTNET_UNITS,
|
|
39
44
|
} from './config/index.js';
|
package/src/predict/pricing.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
// Copyright (c) Mysten Labs, Inc.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
// Faithful float port of
|
|
4
|
-
//
|
|
3
|
+
// Faithful float port of `deepbook_predict::pricing::compute_nd2` as of the anchor the
|
|
4
|
+
// generated bindings are pinned to (`sui-codegen.config.ts`: the `deepbook-predict-testnet`
|
|
5
|
+
// deployment). `pricing.move` is untouched across the anchors this SDK has used, so the
|
|
6
|
+
// formula is unchanged from earlier deployments — the SVI-adjusted digital
|
|
5
7
|
// probability, WITH the skew-correction term. It operates on the pricer's
|
|
6
8
|
// ALREADY-RESOLVED forward and ALREADY-ROLLED-DOWN SVI, exactly as `load_live_pricer`
|
|
7
9
|
// returns them (decoded by `reads/pricing.ts`). So the two on-chain steps that pick the
|
|
@@ -16,7 +18,7 @@
|
|
|
16
18
|
// sits at its floor (float64 here is the more precise side, not the less); negligible for
|
|
17
19
|
// display. `tests/testnet/pricing.test.ts` bounds it live against the deployment.
|
|
18
20
|
//
|
|
19
|
-
// The on-chain formula (pricing.move `compute_nd2
|
|
21
|
+
// The on-chain formula (pricing/pricing.move `compute_nd2`):
|
|
20
22
|
// k = ln(strike / forward)
|
|
21
23
|
// x = k - m
|
|
22
24
|
// w = a + b·(ρ·x + √(x² + σ²)) // a, b already rolled down
|
|
@@ -146,12 +148,12 @@ export function strikeAtProbability(inputs: PricerInputs, p: number): number | n
|
|
|
146
148
|
|
|
147
149
|
/** Roll `a` and `b` down by the fraction of anchored time remaining, matching the chain's
|
|
148
150
|
* `roll_down_svi` (variance decays toward expiry). `remainingMs` = expiry − now;
|
|
149
|
-
* `anchorTteMs` = expiry − the SVI observation's **
|
|
150
|
-
* freshness gate
|
|
151
|
-
* (
|
|
152
|
-
* fraction. `read.pricer` avoids the question entirely (the chain
|
|
153
|
-
* `rho`, `m`, `sigma` are unchanged. Feed an UNrolled provider surface;
|
|
154
|
-
* expects. */
|
|
151
|
+
* `anchorTteMs` = expiry − the SVI observation's **provider `svi_timestamp`** (its per-update
|
|
152
|
+
* source timestamp) — the same clock the freshness gate accepts, and what the chain anchors on
|
|
153
|
+
* (`pricing.move`: "One clock serves every job"). Anchoring on the batch's ingestion time
|
|
154
|
+
* instead rolls by the wrong fraction. `read.pricer` avoids the question entirely (the chain
|
|
155
|
+
* has already rolled). `rho`, `m`, `sigma` are unchanged. Feed an UNrolled provider surface;
|
|
156
|
+
* the result is what {@link upProbability} expects. */
|
|
155
157
|
export function rollDown(svi: Svi, remainingMs: number, anchorTteMs: number): Svi {
|
|
156
158
|
const frac = anchorTteMs > 0 ? remainingMs / anchorTteMs : 0;
|
|
157
159
|
return { ...svi, a: svi.a * frac, b: svi.b * frac };
|
|
@@ -9,7 +9,7 @@ import { inspectReturns, type ReadClient } from './inspect.js';
|
|
|
9
9
|
import { parseU64LE } from './parse.js';
|
|
10
10
|
|
|
11
11
|
// An owner's stored account balance for `coinType` (the deployment's quote coin,
|
|
12
|
-
//
|
|
12
|
+
// USDC on testnet, unless the caller asks for another). Chains `account::load_account(wrapper)` →
|
|
13
13
|
// `account::balance<T>(account, root, clock)`; the u64 is command 1's return —
|
|
14
14
|
// see packages/account/sources/account.move:{80,86}. The clock is auto-injected by
|
|
15
15
|
// the generated `balance` wrapper; the wrapper id is derived off-chain (no read).
|
|
@@ -28,7 +28,7 @@ export async function activeMarketIds(
|
|
|
28
28
|
|
|
29
29
|
// The expiry market id for one underlying at one expiry, or null if none exists.
|
|
30
30
|
// `registry::expiry_market_id(registry, propbook_underlying_id: u32, expiry: u64):
|
|
31
|
-
// Option<ID>` — see packages/predict/sources/registry/registry.move:
|
|
31
|
+
// Option<ID>` — see packages/predict/sources/registry/registry.move:58.
|
|
32
32
|
export async function expiryMarketId(
|
|
33
33
|
client: ReadClient,
|
|
34
34
|
config: GeneratedConfig,
|
|
@@ -23,7 +23,8 @@ const i64 = (v: { magnitude: string | number | bigint; is_negative: boolean }):
|
|
|
23
23
|
/** A resolved pricer snapshot read from the chain: the decimal forward + rolled SVI the
|
|
24
24
|
* client-side math consumes, plus the oracle source timestamps behind it (ms; for
|
|
25
25
|
* staleness display — Pyth is 0 when no usable spot existed). The Block-Scholes entries are
|
|
26
|
-
*
|
|
26
|
+
* the provider's PER-UPDATE source timestamps (`value_timestamp` for spot/forward,
|
|
27
|
+
* `svi_timestamp` for SVI) — the clocks freshness and the SVI roll-down anchor on. */
|
|
27
28
|
export interface PricerSnapshot extends PricerInputs {
|
|
28
29
|
sources: {
|
|
29
30
|
pythSpotMs: number;
|