@mysten/deepbook-v3 2.1.4 → 2.4.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 +70 -0
- package/PREDICT.md +154 -48
- package/README.md +18 -13
- 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.d.mts +23 -23
- package/dist/contracts/account/account.d.mts.map +1 -1
- package/dist/contracts/account/account_events.d.mts +20 -20
- package/dist/contracts/account/account_registry.d.mts +19 -19
- package/dist/contracts/deepbook/account.d.mts +18 -18
- package/dist/contracts/deepbook/account.d.mts.map +1 -1
- package/dist/contracts/deepbook/balances.d.mts +4 -4
- package/dist/contracts/deepbook/balances.d.mts.map +1 -1
- package/dist/contracts/deepbook/deep_price.d.mts +3 -3
- package/dist/contracts/deepbook/deep_price.d.mts.map +1 -1
- package/dist/contracts/deepbook/order.d.mts +12 -12
- package/dist/contracts/deepbook_predict/admin.d.mts +27 -0
- package/dist/contracts/deepbook_predict/admin.d.mts.map +1 -0
- package/dist/contracts/deepbook_predict/admin.mjs +38 -0
- package/dist/contracts/deepbook_predict/admin.mjs.map +1 -0
- package/dist/contracts/deepbook_predict/builder_code.d.mts +81 -0
- package/dist/contracts/deepbook_predict/builder_code.d.mts.map +1 -0
- package/dist/contracts/deepbook_predict/builder_code.mjs +103 -0
- package/dist/contracts/deepbook_predict/builder_code.mjs.map +1 -0
- package/dist/contracts/deepbook_predict/builder_code_events.d.mts +25 -0
- package/dist/contracts/deepbook_predict/builder_code_events.d.mts.map +1 -0
- package/dist/contracts/deepbook_predict/builder_code_events.mjs +7 -1
- package/dist/contracts/deepbook_predict/builder_code_events.mjs.map +1 -1
- package/dist/contracts/deepbook_predict/config_events.d.mts +104 -0
- package/dist/contracts/deepbook_predict/config_events.d.mts.map +1 -0
- package/dist/contracts/deepbook_predict/config_events.mjs +155 -0
- package/dist/contracts/deepbook_predict/config_events.mjs.map +1 -0
- 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/ewma_config.mjs +28 -0
- package/dist/contracts/deepbook_predict/ewma_config.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.d.mts +859 -0
- package/dist/contracts/deepbook_predict/expiry_market.d.mts.map +1 -0
- package/dist/contracts/deepbook_predict/expiry_market.mjs +662 -7
- package/dist/contracts/deepbook_predict/expiry_market.mjs.map +1 -1
- package/dist/contracts/deepbook_predict/market_lifecycle_cap.d.mts +39 -0
- package/dist/contracts/deepbook_predict/market_lifecycle_cap.d.mts.map +1 -0
- package/dist/contracts/deepbook_predict/market_lifecycle_cap.mjs +51 -0
- package/dist/contracts/deepbook_predict/market_lifecycle_cap.mjs.map +1 -0
- package/dist/contracts/deepbook_predict/market_manager.d.mts +159 -0
- package/dist/contracts/deepbook_predict/market_manager.d.mts.map +1 -0
- package/dist/contracts/deepbook_predict/market_manager.mjs +88 -2
- package/dist/contracts/deepbook_predict/market_manager.mjs.map +1 -1
- package/dist/contracts/deepbook_predict/order_events.d.mts +101 -0
- package/dist/contracts/deepbook_predict/order_events.d.mts.map +1 -0
- package/dist/contracts/deepbook_predict/order_events.mjs +7 -1
- package/dist/contracts/deepbook_predict/order_events.mjs.map +1 -1
- package/dist/contracts/deepbook_predict/pause_cap.d.mts +39 -0
- package/dist/contracts/deepbook_predict/pause_cap.d.mts.map +1 -0
- package/dist/contracts/deepbook_predict/pause_cap.mjs +51 -0
- package/dist/contracts/deepbook_predict/pause_cap.mjs.map +1 -0
- package/dist/contracts/deepbook_predict/plp.d.mts +801 -0
- package/dist/contracts/deepbook_predict/plp.d.mts.map +1 -0
- package/dist/contracts/deepbook_predict/plp.mjs +511 -32
- 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/pool_valuation_cap.d.mts +39 -0
- package/dist/contracts/deepbook_predict/pool_valuation_cap.d.mts.map +1 -0
- package/dist/contracts/deepbook_predict/pool_valuation_cap.mjs +52 -0
- package/dist/contracts/deepbook_predict/pool_valuation_cap.mjs.map +1 -0
- package/dist/contracts/deepbook_predict/predict_account.d.mts +90 -0
- package/dist/contracts/deepbook_predict/predict_account.d.mts.map +1 -0
- package/dist/contracts/deepbook_predict/predict_account.mjs +25 -2
- package/dist/contracts/deepbook_predict/predict_account.mjs.map +1 -1
- package/dist/contracts/deepbook_predict/pricing.d.mts +127 -0
- package/dist/contracts/deepbook_predict/pricing.d.mts.map +1 -0
- package/dist/contracts/deepbook_predict/pricing.mjs +37 -1
- package/dist/contracts/deepbook_predict/pricing.mjs.map +1 -1
- package/dist/contracts/deepbook_predict/pricing_config.mjs +28 -0
- package/dist/contracts/deepbook_predict/pricing_config.mjs.map +1 -0
- package/dist/contracts/deepbook_predict/protocol_config.d.mts +665 -0
- package/dist/contracts/deepbook_predict/protocol_config.d.mts.map +1 -0
- package/dist/contracts/deepbook_predict/protocol_config.mjs +841 -0
- package/dist/contracts/deepbook_predict/protocol_config.mjs.map +1 -0
- package/dist/contracts/deepbook_predict/range_codec.d.mts +30 -0
- package/dist/contracts/deepbook_predict/range_codec.d.mts.map +1 -0
- package/dist/contracts/deepbook_predict/range_codec.mjs +6 -1
- package/dist/contracts/deepbook_predict/range_codec.mjs.map +1 -1
- package/dist/contracts/deepbook_predict/registry.d.mts +382 -0
- package/dist/contracts/deepbook_predict/registry.d.mts.map +1 -0
- package/dist/contracts/deepbook_predict/registry.mjs +458 -2
- 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.d.mts +199 -0
- package/dist/contracts/deepbook_predict/vault_events.d.mts.map +1 -0
- package/dist/contracts/deepbook_predict/vault_events.mjs +38 -8
- 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 +28 -6
- package/dist/predict/client.d.mts.map +1 -1
- package/dist/predict/client.mjs +7 -6
- 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 +21 -2
- package/dist/predict/index.mjs +20 -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 +48 -17
- 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 +31 -2
- 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
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,75 @@
|
|
|
1
1
|
# @mysten/deepbook-v3
|
|
2
2
|
|
|
3
|
+
## 2.4.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- b07659a: Predict: export the generated move-call bindings from `@mysten/deepbook-v3/predict`, the
|
|
8
|
+
way `/account` already exports `accountMoveCalls`. Each `client.predict.tx.*` builder returns a
|
|
9
|
+
finished `Transaction`, so a Predict call could not join a PTB the caller was building — creating
|
|
10
|
+
an account, funding it and queueing a PLP supply in one transaction meant hand-writing
|
|
11
|
+
`plp::request_supply` as a raw `moveCall`. Every Predict module with a callable function is now
|
|
12
|
+
reachable as a namespace of transaction thunks (`plpMoveCalls`, `expiryMarketMoveCalls`,
|
|
13
|
+
`predictAccountMoveCalls`, `protocolConfigMoveCalls`, `registryMoveCalls`, `builderCodeMoveCalls`,
|
|
14
|
+
`marketManagerMoveCalls`, `pricingMoveCalls`, `rangeCodecMoveCalls`, and the cap modules),
|
|
15
|
+
alongside the event layouts (`vaultEvents`, `orderEvents`, `configEvents`, `builderCodeEvents`).
|
|
16
|
+
Pass `config: toGeneratedConfig(cfg)` and the shared objects fill themselves in; owner-authorized
|
|
17
|
+
calls take an `Auth` from `generateAuth(cfg)`. Additive only: no existing export changes.
|
|
18
|
+
|
|
19
|
+
### Patch Changes
|
|
20
|
+
|
|
21
|
+
- ee8df5d: Predict docs: document both recorded deployments. `PREDICT.md` and the README now
|
|
22
|
+
describe the `deepbook-predict-mainnet` and `deepbook-predict-testnet` records that `getConfig`,
|
|
23
|
+
`getDeployment`, `getUnits`, `getAccountConfig`, and `getSessionsConfig` resolve, the quote coin
|
|
24
|
+
per network (Circle native USDC on mainnet, a mintable test coin that displays as DUSDC on
|
|
25
|
+
testnet, read from `quoteCoinType`), the `side: 'range'` descriptor arm, which decoders have
|
|
26
|
+
plural forms, what is exported for PTB composition, that `read.markets()` returns
|
|
27
|
+
live-and-not-yet-settled markets, and the `supplyPlp` / `withdrawPlp` floor options as shipped.
|
|
28
|
+
Documentation only; no runtime change.
|
|
29
|
+
|
|
30
|
+
## 2.3.0
|
|
31
|
+
|
|
32
|
+
### Minor Changes
|
|
33
|
+
|
|
34
|
+
- 7b47a9a: Predict: let `supplyPlp` and `withdrawPlp` set a price floor. Both hard-pinned the
|
|
35
|
+
request's floor to 0, so the SDK could only ever queue an LP request that accepts whatever mark
|
|
36
|
+
the next pool flush quotes. They now take an optional third argument — `{ minPlpOut }` (raw
|
|
37
|
+
`bigint` shares) and `{ minUsdcOut }` (USD decimals) — defaulting to the previous no-floor
|
|
38
|
+
behaviour.
|
|
39
|
+
- 1e2f728: Add Mainnet deployment ids for Predict, sessions and the account primitive. `getConfig`,
|
|
40
|
+
`getAccountConfig`, `getSessionsConfig`, `getUnits` and `getDeployment` now resolve `'mainnet'`
|
|
41
|
+
instead of throwing, and `MAINNET_CONFIG` / `MAINNET_DEPLOYMENT` / `MAINNET_UNITS` are exported
|
|
42
|
+
alongside their testnet counterparts. `DeployedNetwork` widens to `'testnet' | 'mainnet'`.
|
|
43
|
+
|
|
44
|
+
Mainnet settles in Circle's native USDC
|
|
45
|
+
(`0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC`). The in-repo
|
|
46
|
+
test currency is never published to Mainnet, so the collateral type resolves to Circle's package
|
|
47
|
+
there and to the DeepBook test coin on Testnet — read `quoteCoinType` from the config rather than
|
|
48
|
+
assuming either.
|
|
49
|
+
|
|
50
|
+
The ids are generated from the deploy tooling's own Mainnet manifest, like Testnet's, so both
|
|
51
|
+
networks move together on a redeploy and cannot drift apart across subpaths.
|
|
52
|
+
|
|
53
|
+
## 2.2.0
|
|
54
|
+
|
|
55
|
+
### Minor Changes
|
|
56
|
+
|
|
57
|
+
- e7c8014: Target the `deepbook-predict-testnet` deployment. Every testnet id the SDK ships changes
|
|
58
|
+
— the Predict, account and sessions packages and their shared objects — so `getConfig('testnet')`,
|
|
59
|
+
`getAccountConfig('testnet')`, `getSessionsConfig('testnet')` and `TESTNET_CONFIG` all resolve
|
|
60
|
+
against the new deployment, and `getDeployment('testnet')` reports it by name and source commit.
|
|
61
|
+
Anything pinned to the previous testnet deployment's ids will not find its accounts, positions or
|
|
62
|
+
markets there; they are separate deployments, not an upgrade.
|
|
63
|
+
|
|
64
|
+
The settlement collateral is renamed upstream from `dusdc::dusdc::DUSDC` to `usdc::usdc::USDC`, so
|
|
65
|
+
one Move module path resolves on both testnet and mainnet and mainnet can link native USDC by
|
|
66
|
+
address alone. `quoteCoinType` carries the new type. The testnet coin keeps the `DUSDC` display
|
|
67
|
+
symbol, which is what distinguishes the mintable test coin from native USDC in wallets and
|
|
68
|
+
explorers — read `quoteCoinType` rather than assuming a symbol or a type.
|
|
69
|
+
|
|
70
|
+
The exported surface is otherwise unchanged: no symbol is added, removed or re-typed, and the
|
|
71
|
+
renamed Move argument (`min_usdc_out`) is internal to the transaction builders.
|
|
72
|
+
|
|
3
73
|
## 2.1.4
|
|
4
74
|
|
|
5
75
|
## 2.1.3
|
package/PREDICT.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# DeepBook Predict (`@mysten/deepbook-v3/predict`)
|
|
2
2
|
|
|
3
|
-
TypeScript SDK for DeepBook Predict — binary markets on Sui. Builds ready-to-sign
|
|
4
|
-
reads on-chain state through your Sui client. The SDK never signs and never touches
|
|
5
|
-
`tx.*` method returns a `Transaction` for your wallet (dapp-kit) or signer to execute.
|
|
3
|
+
TypeScript SDK for DeepBook Predict — binary and range markets on Sui. Builds ready-to-sign
|
|
4
|
+
transactions and reads on-chain state through your Sui client. The SDK never signs and never touches
|
|
5
|
+
keys: every `tx.*` method returns a `Transaction` for your wallet (dapp-kit) or signer to execute.
|
|
6
6
|
|
|
7
7
|
## Install
|
|
8
8
|
|
|
@@ -12,8 +12,10 @@ npm i @mysten/deepbook-v3 @mysten/sui
|
|
|
12
12
|
|
|
13
13
|
`@mysten/sui` is a peer dependency.
|
|
14
14
|
|
|
15
|
-
>
|
|
16
|
-
>
|
|
15
|
+
> Two deployments are recorded, **testnet** and **mainnet**: `predict({ network })` and
|
|
16
|
+
> `getConfig(network)` resolve either, and any other network throws. They settle in different coins
|
|
17
|
+
> that share one Move module path — read `quoteCoinType` from the config rather than assuming a
|
|
18
|
+
> symbol or a type. See [Networks & deployments](#networks--deployments).
|
|
17
19
|
|
|
18
20
|
## Quickstart
|
|
19
21
|
|
|
@@ -32,16 +34,22 @@ const client = new SuiGrpcClient({
|
|
|
32
34
|
// One-time: create your Predict account (a shared AccountWrapper).
|
|
33
35
|
const createTx = client.predict.tx.createManager();
|
|
34
36
|
|
|
35
|
-
// Fund it: pulls
|
|
37
|
+
// Fund it: pulls the deployment's quote coin (`client.predict.cfg.quoteCoinType`) from your
|
|
38
|
+
// address (coin objects and/or address balance).
|
|
36
39
|
const depositTx = client.predict.tx.deposit(myAddress, 250); // $250
|
|
37
40
|
|
|
38
|
-
// Cash out: lands in your
|
|
41
|
+
// Cash out: lands in your quote-coin address balance by default (no coin-object churn).
|
|
39
42
|
// Pass { toCoinObject: true } if you need a discrete Coin<T> instead.
|
|
40
43
|
const withdrawTx = client.predict.tx.withdraw(myAddress, 100); // $100
|
|
41
44
|
|
|
42
|
-
// Pick a
|
|
45
|
+
// Pick a market. `read.markets()` lists ACTIVE markets — live and not yet settled — which
|
|
46
|
+
// includes a market past its expiry that nobody has settled yet; quoting against one aborts.
|
|
47
|
+
// Expiries are absolute timestamps, so never hardcode one: filter on `expiryMs`, leaving
|
|
48
|
+
// room to quote, sign and land (and clear the pre-expiry no-trade window).
|
|
43
49
|
const markets = await client.predict.read.markets();
|
|
44
|
-
|
|
50
|
+
// -> [{ id, expiryMs, tickSize, admissionTickSize, mintPaused, referencePrice }, ...]
|
|
51
|
+
const tradeable = markets.filter((m) => Number(m.expiryMs) > Date.now() + 30_000 && !m.mintPaused);
|
|
52
|
+
const expiryMs = tradeable[0].expiryMs;
|
|
45
53
|
|
|
46
54
|
// Describe the position once and reuse it — quoting and minting take the same descriptor.
|
|
47
55
|
const desc = { underlying: 'BTC', expiryMs, strike: 'reference', side: 'up' } as const;
|
|
@@ -73,14 +81,10 @@ receipt.entryProbability; // your fill price (0..1 per $1 payout)
|
|
|
73
81
|
receipt.premium; // exact cost breakdown
|
|
74
82
|
receipt.fees;
|
|
75
83
|
|
|
76
|
-
// Read:
|
|
77
|
-
const
|
|
78
|
-
// -> [{ id, expiryMs, tickSize, admissionTickSize, mintPaused, referencePrice }, ...]
|
|
79
|
-
const market = await client.predict.read.market({
|
|
80
|
-
underlying: 'BTC',
|
|
81
|
-
expiryMs: markets[0].expiryMs,
|
|
82
|
-
});
|
|
84
|
+
// Read: one market's live state (+ NAV) and the pool.
|
|
85
|
+
const market = await client.predict.read.market({ underlying: 'BTC', expiryMs });
|
|
83
86
|
console.log(market?.nav, market?.tickSize, market?.mintPaused);
|
|
87
|
+
const pool = await client.predict.read.pool();
|
|
84
88
|
```
|
|
85
89
|
|
|
86
90
|
## ⚠ Slippage defaults are UNCAPPED
|
|
@@ -89,25 +93,41 @@ console.log(market?.nav, market?.tickSize, market?.mintPaused);
|
|
|
89
93
|
**uncapped** — if the price moves between your quote and execution, the position can cost up to your
|
|
90
94
|
full account balance. **Call `read.quoteMint` and pass its `cost` (plus your buffer) as `maxCost`.**
|
|
91
95
|
The same applies to `redeem`: the deployed `redeem_live` DOES take `min_probability` /
|
|
92
|
-
`min_proceeds` floors, but the facade does not surface them
|
|
93
|
-
`read.quoteRedeem` first, close fast
|
|
96
|
+
`min_proceeds` floors, but the facade's `tx.redeem` does not surface them and always sends `0`
|
|
97
|
+
(uncapped). `read.quoteRedeem` first, close fast. The floors are reachable through `/sessions`:
|
|
98
|
+
`SessionsContract.redeemLive` takes `minProbability` / `minProceeds` (raw units —
|
|
99
|
+
`probabilityToRaw`, `usdcToRaw`) plus a `pricer` from `loadLivePricer`, and is signed by a session
|
|
100
|
+
key the owner has authorized (see the README's `/sessions` section).
|
|
94
101
|
|
|
95
102
|
## Units
|
|
96
103
|
|
|
97
104
|
Everything human-facing is decimal; everything on-chain is scaled integers. The facade converts
|
|
98
105
|
**inputs** exactly (string/bigint math — no floats on the money path in). Read outputs typed
|
|
99
|
-
`number` are display values: above 2^53 raw they lose low-digit precision —
|
|
100
|
-
|
|
106
|
+
`number` are display values: above 2^53 raw they lose low-digit precision — quotes and receipts
|
|
107
|
+
carry a `raw` block of `bigint`s alongside, and `plpBalance` / `pool().plpTotalSupply` are raw
|
|
108
|
+
`bigint` already.
|
|
109
|
+
|
|
110
|
+
Amounts are in the deployment's quote coin — `getConfig(network).quoteCoinType`: Circle native USDC
|
|
111
|
+
on mainnet, a mintable 6-decimal test coin on testnet. Both are `…::usdc::USDC`, so only the package
|
|
112
|
+
address tells them apart; read the type, never assume a symbol.
|
|
101
113
|
|
|
102
114
|
| Concept | You pass / receive | On-chain raw |
|
|
103
115
|
| ------------------------------------------- | -------------------------------------------------------------- | ------------------------------------- |
|
|
104
|
-
| Amounts (deposit, spend, maxCost, balances) | USD decimal number or string (`12.5`, `"12.5"`) | ×1e6 (
|
|
116
|
+
| Amounts (deposit, spend, maxCost, balances) | USD decimal number or string (`12.5`, `"12.5"`) | ×1e6 (quote coin) |
|
|
105
117
|
| `quantity` | **max payout** in USD; positions pay $1 per contract at expiry | ×1e6, in $0.01 lots |
|
|
106
118
|
| `strike` | USD (`105_000`) | ×1e9, must land on the admission grid |
|
|
107
119
|
| `maxProbability` | 0..1 (`0.35` = 35¢ per $1 contract) | ×1e9 |
|
|
108
120
|
| PLP shares (`withdrawPlp`, `plpBalance`) | raw `bigint` shares | 6-decimal coin |
|
|
109
121
|
|
|
110
|
-
`side: "up"` wins if the settlement price is above the strike; `"down"` below
|
|
122
|
+
`side: "up"` wins if the settlement price is above the strike; `"down"` below; `"range"` (see
|
|
123
|
+
[Range positions](#range-positions)) if it lands inside `(lower, upper]`.
|
|
124
|
+
|
|
125
|
+
Trading closes slightly before expiry: the protocol enforces a short pre-expiry no-trade window
|
|
126
|
+
(`no_trade_window_ms` on the live `ProtocolConfig`, 2 s on both recorded deployments), so a mint or
|
|
127
|
+
redeem submitted inside it aborts `ETradeWindowClosed` rather than filling. Treat the last seconds
|
|
128
|
+
of a window as untradeable rather than retrying, and when choosing a market from `read.markets()`
|
|
129
|
+
leave enough of the window to quote, sign and land — a quote taken seconds before expiry executes
|
|
130
|
+
inside the window.
|
|
111
131
|
|
|
112
132
|
## Reference-price markets (Polymarket-style windows)
|
|
113
133
|
|
|
@@ -134,11 +154,11 @@ strikes away from the reference remain fully supported.
|
|
|
134
154
|
### Numeric strikes must sit on the admission grid
|
|
135
155
|
|
|
136
156
|
New mint strikes must be a whole multiple of the market's **`admissionTickSize`** — a step
|
|
137
|
-
deliberately coarser than `tickSize`, and it
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
157
|
+
deliberately coarser than `tickSize`, and it is configured per cadence (both recorded deployments
|
|
158
|
+
run `$1` against a `$0.01` tick on their enabled cadences, 1m and 5m). Always read it off the market
|
|
159
|
+
rather than assuming a value. The market's `referencePrice` is the one finite strike the chain
|
|
160
|
+
admits off-grid. `read.markets()` and `read.market()` both report `admissionTickSize`, so a board
|
|
161
|
+
can be built from it directly:
|
|
142
162
|
|
|
143
163
|
```ts
|
|
144
164
|
const m = (await client.predict.read.markets())[0];
|
|
@@ -148,6 +168,23 @@ const strike = Math.round(target / m.admissionTickSize) * m.admissionTickSize;
|
|
|
148
168
|
An off-grid numeric strike throws `PredictInputError` at build time rather than aborting on chain
|
|
149
169
|
with `EInvalidAdmissionTick`.
|
|
150
170
|
|
|
171
|
+
### Range positions
|
|
172
|
+
|
|
173
|
+
`MarketDescriptor` has a third arm: `{ underlying, expiryMs, side: 'range', lower, upper }`. It pays
|
|
174
|
+
$1 per contract when the settlement price lands inside `(lower, upper]` — left-open, right-closed,
|
|
175
|
+
the same convention as the on-chain range key. Both bounds are USD strikes that must be finite, on
|
|
176
|
+
the tick grid, with `lower < upper`, and **each is admission-grid checked** exactly like a binary
|
|
177
|
+
numeric strike. `strike: 'reference'` is binary-only — a range has no single reference strike — and
|
|
178
|
+
`read.price` is binary-only too; price a range locally with `pricer.range(lower, upper)`.
|
|
179
|
+
|
|
180
|
+
```ts
|
|
181
|
+
const tx = await client.predict.tx.mint(
|
|
182
|
+
myAddress,
|
|
183
|
+
{ underlying: 'BTC', expiryMs, side: 'range', lower: 104_000, upper: 106_000 },
|
|
184
|
+
{ quantity: 25, maxCost: 10 },
|
|
185
|
+
);
|
|
186
|
+
```
|
|
187
|
+
|
|
151
188
|
## What's in the box
|
|
152
189
|
|
|
153
190
|
- **`client.predict.tx`** — `createManager`, `deposit`, `withdraw`, `mint`, `mintAmount`, `redeem`,
|
|
@@ -155,23 +192,59 @@ with `EInvalidAdmissionTick`.
|
|
|
155
192
|
`setBuilderCode`, `unsetBuilderCode`. Market-resolving builders
|
|
156
193
|
(`mint`/`mintAmount`/`redeem`/`claimSettled`) are async: they resolve the market object from
|
|
157
194
|
`{ underlying, expiryMs, strike, side }` via the on-chain registry (cached per client).
|
|
158
|
-
- **`client.predict.read`** — `markets()` (
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
195
|
+
- **`client.predict.read`** — `markets()` (summaries of the pool's **active** markets — live and not
|
|
196
|
+
yet settled, so a market past expiry that nobody has settled is still listed and quoting against
|
|
197
|
+
it aborts; filter on `expiryMs` and `mintPaused` before trading: id, expiry, tick size, admission
|
|
198
|
+
tick size, mint-paused, reference price), `market(desc)` (state + live NAV), `price(m)` (anonymous
|
|
199
|
+
both-sides pricing for any strike, one chain call per strike), `pricer(m)` (a **client-side board
|
|
200
|
+
pricer** — one chain read of the resolved pricer, then price every strike locally; see below),
|
|
162
201
|
`quoteMint(owner, m, opts)` / `quoteRedeem(owner, m, opts)` (exact dry-run quotes: real fees from
|
|
163
202
|
the real code path — and they throw the same typed errors the real trade would, so a quote doubles
|
|
164
203
|
as preflight), `balance(owner)`, `plpBalance(owner)`, `pool()`, `positions(owner)` (chain-only
|
|
165
204
|
enumeration of open positions), `hasPosition(owner, marketId, orderId)`. All reads run over the
|
|
166
205
|
client's `simulateTransaction`; no indexer required.
|
|
167
206
|
- **`client.predict.decode`** — pure execution-result decoders (no network): `mint`, `redeem`,
|
|
168
|
-
`claim`, `createManager`, `deposit`, `withdraw`, `plpRequest`, `plpCancel`, `builderCode
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
207
|
+
`claim`, `createManager`, `deposit`, `withdraw`, `plpRequest`, `plpCancel`, `builderCode`. Each
|
|
208
|
+
singular form throws unless exactly one matching event is present; `mints`, `redeems` and `claims`
|
|
209
|
+
are the plural forms for batched PTBs and return every receipt (the other decoders have no
|
|
210
|
+
plural). Execute transactions with events included and pass the result; receipts come back in SDK
|
|
211
|
+
units with raw bigints alongside. Decoding uses the events' canonical BCS bytes, so it is
|
|
212
|
+
transport-independent.
|
|
213
|
+
- **PTB composition** — each `client.predict.tx.*` builder returns a finished `Transaction`, so to
|
|
214
|
+
put a Predict call into a PTB you are building, use the generated move-call bindings `/predict`
|
|
215
|
+
exports: one namespace of transaction thunks per Predict module (`plpMoveCalls`,
|
|
216
|
+
`expiryMarketMoveCalls`, `predictAccountMoveCalls`, `protocolConfigMoveCalls`,
|
|
217
|
+
`registryMoveCalls`, `builderCodeMoveCalls`, `marketManagerMoveCalls`, `pricingMoveCalls`,
|
|
218
|
+
`rangeCodecMoveCalls`, `adminMoveCalls` and the cap modules) plus the event layouts
|
|
219
|
+
(`vaultEvents`, `orderEvents`, `configEvents`, `builderCodeEvents`). Pass
|
|
220
|
+
`config: toGeneratedConfig(cfg)` — the flat config slice the bindings resolve the shared objects
|
|
221
|
+
against — and give owner-authorized calls `auth: tx.add(generateAuth(cfg))`, the hot-potato `Auth`
|
|
222
|
+
the account calls consume. The account itself (create, deposit, share) is
|
|
223
|
+
`@mysten/deepbook-v3/account`'s `accountRegistryMoveCalls` / `accountMoveCalls`. Also exported:
|
|
224
|
+
`loadLivePricer(toGeneratedConfig(cfg), { expiryMarketId, ...cfg.underlyings[sym] })` — the
|
|
225
|
+
`pricer` every live trade call borrows, which the `/sessions` Predict wrappers take as a PTB
|
|
226
|
+
result — and `deriveAccountWrapperId(cfg, owner)`.
|
|
227
|
+
|
|
228
|
+
```ts
|
|
229
|
+
// Create an account, fund it, and queue a PLP supply — one PTB, one signature.
|
|
230
|
+
const config = toGeneratedConfig(cfg);
|
|
231
|
+
const wrapper = tx.add(accountRegistryMoveCalls._new({ config }));
|
|
232
|
+
tx.add(
|
|
233
|
+
accountMoveCalls.depositFunds({
|
|
234
|
+
config,
|
|
235
|
+
arguments: { wrapper, auth: tx.add(generateAuth(cfg)), coin },
|
|
236
|
+
typeArguments: [cfg.quoteCoinType],
|
|
237
|
+
}),
|
|
238
|
+
);
|
|
239
|
+
tx.add(
|
|
240
|
+
plpMoveCalls.requestSupply({
|
|
241
|
+
config,
|
|
242
|
+
arguments: { wrapper, auth: tx.add(generateAuth(cfg)), amount, minPlpOut },
|
|
243
|
+
}),
|
|
244
|
+
);
|
|
245
|
+
tx.add(accountMoveCalls.share({ config, arguments: { self: wrapper } }));
|
|
246
|
+
```
|
|
247
|
+
|
|
175
248
|
- **Typed errors** — invalid inputs throw `PredictInputError` before the chain sees them; failed
|
|
176
249
|
simulations throw `PredictMoveError` with the decoded Move abort (`module`, `code`, `abortName`).
|
|
177
250
|
|
|
@@ -198,9 +271,9 @@ on-chain; the client only evaluates the digital. It throws the same typed stale-
|
|
|
198
271
|
The math is a faithful float port of the deployed `pricing::compute_nd2` (SVI with the skew
|
|
199
272
|
correction, signed params, and the remaining-time roll-down). It agrees with the chain closely —
|
|
200
273
|
within ~1e-4 in probability, up to ~1e-4 near ATM where the chain's fixed-point truncation dominates
|
|
201
|
-
(`
|
|
202
|
-
namespace for callers who already hold their own oracle inputs (e.g. a live feed) and want
|
|
203
|
-
chain calls:
|
|
274
|
+
(`test/predict/testnet/pricing.test.ts` bounds it live). The pure functions are exported under a
|
|
275
|
+
`pricing` namespace for callers who already hold their own oracle inputs (e.g. a live feed) and want
|
|
276
|
+
zero chain calls:
|
|
204
277
|
|
|
205
278
|
```ts
|
|
206
279
|
import { pricing } from '@mysten/deepbook-v3/predict';
|
|
@@ -218,11 +291,29 @@ const rolled = pricing.rollDown(rawSvi, remainingMs, anchorTteMs); // decay a, b
|
|
|
218
291
|
|
|
219
292
|
## Networks & deployments
|
|
220
293
|
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
294
|
+
Two deployments are recorded. `getDeployment(network)` names each one and the deepbookv3 commit its
|
|
295
|
+
ids were generated at:
|
|
296
|
+
|
|
297
|
+
| Network | Deployment | Chain id | Source commit | `quoteCoinType` |
|
|
298
|
+
| --------- | -------------------------- | ---------- | ------------- | -------------------------------------------------------------------------------------------------------------------------- |
|
|
299
|
+
| `mainnet` | `deepbook-predict-mainnet` | `35834a8a` | `14a7e8f8` | Circle native USDC — `0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC` |
|
|
300
|
+
| `testnet` | `deepbook-predict-testnet` | `4c78adac` | `a928bd2d` | mintable test coin, displays as `DUSDC` — `0xc028557a1ed49e42ed091e115aedefd70a442b184c18fbec5c48d5b6c0b8c184::usdc::USDC` |
|
|
301
|
+
|
|
302
|
+
Object ids for both are baked into the SDK — `MAINNET_CONFIG` / `TESTNET_CONFIG`, with
|
|
303
|
+
`MAINNET_DEPLOYMENT` / `TESTNET_DEPLOYMENT` and `MAINNET_UNITS` / `TESTNET_UNITS` alongside — and
|
|
304
|
+
are regenerated, with a release, whenever a deployment moves. `getConfig`, `getDeployment` and
|
|
305
|
+
`getUnits` resolve both networks and throw on any other; `getAccountConfig` (`/account`) and
|
|
306
|
+
`getSessionsConfig` (`/sessions`) read slices of the same generated record, so the three subpaths
|
|
307
|
+
cannot address different deployments. Units are identical on both (`$0.01` lots, 6 quote decimals,
|
|
308
|
+
1e9 fixed-point scale).
|
|
309
|
+
|
|
310
|
+
Move-call targets resolve from the config's package ids, so a deployment of your own is addressed by
|
|
311
|
+
passing `config` — `predict({ network, config })` or
|
|
312
|
+
`new PredictClient({ client, network, config })` — and `network` is then not consulted.
|
|
313
|
+
|
|
314
|
+
An expired market stays in `read.markets()` until someone settles it — the list is the pool's
|
|
315
|
+
live-and-not-yet-settled set, not a tradeable set. On either network, check `expiryMs` against the
|
|
316
|
+
clock (and `mintPaused`) before quoting rather than assuming the list is tradeable.
|
|
226
317
|
|
|
227
318
|
## Notes
|
|
228
319
|
|
|
@@ -233,11 +324,26 @@ stop requiring an SDK release for target resolution.
|
|
|
233
324
|
as the cheap validator.
|
|
234
325
|
- PLP supply/withdraw are queued and fill at the next pool flush; cancels take the queue `index` —
|
|
235
326
|
get it from `decode.plpRequest(result).index`.
|
|
327
|
+
- **Both take an optional price floor**, and default to none:
|
|
328
|
+
`supplyPlp(owner, amountUsdc, { minPlpOut })` (`PlpSupplyOptions`, raw `bigint` shares; omitted →
|
|
329
|
+
`0n`) and `withdrawPlp(owner, shares, { minUsdcOut })` (`PlpWithdrawOptions`, USD decimals as
|
|
330
|
+
`number | string`, measured after the protocol's withdraw fee; omitted → no floor). Each floors
|
|
331
|
+
the flush's MARK for the whole request rather than naming a quantity — a flush quoting less
|
|
332
|
+
declines instead of filling smaller. What a miss costs is the deployment's
|
|
333
|
+
`lp_request_limit_flush_attempts`: the deployed value is one on both recorded deployments, so the
|
|
334
|
+
first flush below the floor cancels the request and refunds it, and re-queueing is a fresh
|
|
335
|
+
transaction (three is the configurable maximum, not the default). Leave the floor off and the
|
|
336
|
+
request takes whatever mark the flush quotes.
|
|
337
|
+
- **First-time funding in one PTB**: `deposit(owner, amount, { create: true })` creates the wrapper,
|
|
338
|
+
deposits through the fresh handle and shares it last. `owner` must be the transaction signer (the
|
|
339
|
+
wrapper is derived from the sender), and it aborts if the account already exists — the builder
|
|
340
|
+
does no chain read, so gate on `wrapperIdFor(owner)` + a `getObject`, or fall back to `deposit`
|
|
341
|
+
without the flag on that abort.
|
|
236
342
|
- `claimSettled` closes the order in full — the deployed entrypoint takes no quantity.
|
|
237
343
|
- **`withdraw` lands in your address balance by default** (`0x2::coin::send_funds`), not a coin
|
|
238
344
|
object — it merges into the versionless accumulator `deposit` already draws from, so the round
|
|
239
|
-
trip never accretes stray `Coin<
|
|
240
|
-
internal custody balance; use the client's `getBalance(owner)` for the wallet-side
|
|
345
|
+
trip never accretes stray `Coin<USDC>` objects. `read.balance(owner)` reflects the account's
|
|
346
|
+
internal custody balance; use the client's `getBalance(owner)` for the wallet-side USDC total
|
|
241
347
|
(coin objects + address balance). Pass `withdraw(owner, amt, { toCoinObject: true })` for a
|
|
242
348
|
discrete coin (wallets/explorers that only render coin objects, or same-PTB composition).
|
|
243
349
|
|
package/README.md
CHANGED
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
## Entry points
|
|
4
4
|
|
|
5
|
-
| Import | Contents
|
|
6
|
-
| ------------------------------ |
|
|
7
|
-
| `@mysten/deepbook-v3` | DeepBook spot and margin — pools, orders, balance managers, flash loans, governance, margin managers/pools, TPSL.
|
|
8
|
-
| `@mysten/deepbook-v3/account` | The shared on-chain **account primitive** (`AccountContract`): the canonical `AccountWrapper`, `Auth`, and custody balances that DeepBook's core account wrapper and DeepBook Predict both build on.
|
|
9
|
-
| `@mysten/deepbook-v3/sessions` | **Time-limited trading sessions** over a canonical Account (`SessionsContract`): grant an ephemeral address bounded authority until a fixed expiry. Covers the session lifecycle and the DeepBook Predict wrappers.
|
|
10
|
-
| `@mysten/deepbook-v3/predict` | **DeepBook Predict** — binary markets: market discovery, quotes, mint/redeem/claim, PLP, typed receipts and a client-side board pricer. See [PREDICT.md](./PREDICT.md).
|
|
5
|
+
| Import | Contents |
|
|
6
|
+
| ------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
7
|
+
| `@mysten/deepbook-v3` | DeepBook spot and margin — pools, orders, balance managers, flash loans, governance, margin managers/pools, TPSL. |
|
|
8
|
+
| `@mysten/deepbook-v3/account` | The shared on-chain **account primitive** (`AccountContract`): the canonical `AccountWrapper`, `Auth`, and custody balances that DeepBook's core account wrapper and DeepBook Predict both build on. |
|
|
9
|
+
| `@mysten/deepbook-v3/sessions` | **Time-limited trading sessions** over a canonical Account (`SessionsContract`): grant an ephemeral address bounded authority until a fixed expiry. Covers the session lifecycle and the DeepBook Predict wrappers. |
|
|
10
|
+
| `@mysten/deepbook-v3/predict` | **DeepBook Predict** — binary and range markets: market discovery, quotes, mint/redeem/claim, PLP, typed receipts and a client-side board pricer, with deployed ids for testnet and mainnet. See [PREDICT.md](./PREDICT.md). |
|
|
11
11
|
|
|
12
12
|
Subpaths are separate module graphs — importing `@mysten/deepbook-v3/account` does not load any spot
|
|
13
13
|
or margin code.
|
|
@@ -15,10 +15,13 @@ or margin code.
|
|
|
15
15
|
Each subpath also exports the **deployed ids** for its own surface, so a caller never transcribes
|
|
16
16
|
them: `getAccountConfig(network)` on `/account`, `getSessionsConfig(network)` on `/sessions`,
|
|
17
17
|
`getConfig(network)` on `/predict`. All three read one generated record (`src/deployments/`), so a
|
|
18
|
-
redeploy updates every subpath at once and they cannot end up addressing different deployments.
|
|
19
|
-
`
|
|
20
|
-
|
|
21
|
-
rather than returning placeholder ids.
|
|
18
|
+
redeploy updates every subpath at once and they cannot end up addressing different deployments. Two
|
|
19
|
+
networks are recorded, `testnet` (`deepbook-predict-testnet`) and `mainnet`
|
|
20
|
+
(`deepbook-predict-mainnet`); `getDeployment(network)` names the deployment and the deepbookv3
|
|
21
|
+
commit those ids came from, and an unrecorded network throws rather than returning placeholder ids.
|
|
22
|
+
The two deployments settle in different coins that share one Move module path — Circle native USDC
|
|
23
|
+
on mainnet, a mintable test coin (displayed as `DUSDC`) on testnet — so take the coin type from
|
|
24
|
+
`getConfig(network).quoteCoinType` on `/predict` rather than assuming either.
|
|
22
25
|
|
|
23
26
|
### `@mysten/deepbook-v3/account`
|
|
24
27
|
|
|
@@ -30,7 +33,7 @@ is computable off-chain with no chain read. `AccountContract` takes only the dep
|
|
|
30
33
|
import { Transaction } from '@mysten/sui/transactions';
|
|
31
34
|
import { AccountContract, getAccountConfig } from '@mysten/deepbook-v3/account';
|
|
32
35
|
|
|
33
|
-
// Deployed ids ship with the package — no transcription.
|
|
36
|
+
// Deployed ids ship with the package — no transcription. 'testnet' | 'mainnet'.
|
|
34
37
|
const account = new AccountContract(getAccountConfig('testnet'));
|
|
35
38
|
|
|
36
39
|
// …or drive a deployment of your own:
|
|
@@ -38,8 +41,10 @@ const custom = new AccountContract({ accountPackageId: '0x…', accountRegistry:
|
|
|
38
41
|
|
|
39
42
|
const wrapperId = account.deriveAccountWrapperId(owner);
|
|
40
43
|
|
|
44
|
+
// `quoteCoinType` is the deployment's settlement coin — `getConfig(network).quoteCoinType`
|
|
45
|
+
// from `/predict` — not a symbol you assume.
|
|
41
46
|
const tx = new Transaction();
|
|
42
|
-
tx.add(account.depositFunds({ wrapperId, coin, coinType:
|
|
47
|
+
tx.add(account.depositFunds({ wrapperId, coin, coinType: quoteCoinType }));
|
|
43
48
|
```
|
|
44
49
|
|
|
45
50
|
> `Account` exported from the package root is `@deepbook/core::account::Account` (the per-pool
|
|
@@ -61,7 +66,7 @@ withdrawal or arbitrary-mutation entrypoint.
|
|
|
61
66
|
```ts
|
|
62
67
|
import { SessionsContract, getSessionsConfig } from '@mysten/deepbook-v3/sessions';
|
|
63
68
|
|
|
64
|
-
// Deployed ids ship with the package — no transcription.
|
|
69
|
+
// Deployed ids ship with the package — no transcription. 'testnet' | 'mainnet'.
|
|
65
70
|
const sessions = new SessionsContract(getSessionsConfig('testnet'));
|
|
66
71
|
|
|
67
72
|
const wrapperId = sessions.deriveAccountWrapperId(owner);
|
package/dist/account.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"account.d.mts","names":[],"sources":["../src/account.ts"],"mappings":";;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"account.d.mts","names":[],"sources":["../src/account.ts"],"mappings":";;;;;;;;;;;;AAqCA;;;;;;;;;AAiBA;;UAjBiB,aAAA,SAAsB,eAAA;EAiB6B;EAfnE,gBAAA;EAegC;EAbhC,eAAA;AAAA;;AAsCD;;;;;;;;;iBAzBgB,gBAAA,CAAiB,OAAA,EAAS,UAAA,GAAa,aAAA;;;;;;;;;;cAyB1C,eAAA;EAAA;EAMQ;;;cAAR,MAAA,EAAQ,aAAA;EA0BpB;;;;;;;EAfA,sBAAA,CAAuB,KAAA;EA0CW;;;;;;EA3BlC,YAAA,CAAA,IACS,EAAA,EAAI,WAAA,KAAc,iBAAA;EAgDJ;;;;;;EAtCvB,aAAA,CAAA,IACS,EAAA,EAAI,WAAA;EA0Db;;;;;;;;;EA3CA,uBAAA,CAAwB,MAAA;IAAU,IAAA,EAAM,yBAAA;IAA2B,QAAA;EAAA,KAC1D,EAAA,EAAI,WAAA;EA8Dc;;;;;;;EAzC3B,YAAA,CAAa,MAAA;IAAU,SAAA;IAAmB,IAAA,EAAM,yBAAA;IAA2B,QAAA;EAAA,KAClE,EAAA,EAAI,WAAA;;;;;;;;;EAoBb,aAAA,CAAc,MAAA;IAAU,SAAA;IAAmB,MAAA;IAAgB,QAAA;EAAA,KAClD,EAAA,EAAI,WAAA,KAAc,iBAAA;;;;;;;EAkB3B,WAAA,CAAY,MAAA;IAAU,SAAA;EAAA,KACb,EAAA,EAAI,WAAA,KAAc,iBAAA;;;;;;;;EAW3B,OAAA,CAAQ,MAAA;IAAU,KAAA;IAAe,QAAA;EAAA,KACxB,EAAA,EAAI,WAAA,KAAc,iBAAA;AAAA"}
|
package/dist/account.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Account, AccountWrapper, account_exports, balance, depositFunds, generateAuth, loadAccount, share, withdrawFunds } from "./contracts/account/account.mjs";
|
|
2
2
|
import { _new, account_registry_exports } from "./contracts/account/account_registry.mjs";
|
|
3
|
+
import { MAINNET_ACCOUNT } from "./deployments/mainnet.mjs";
|
|
3
4
|
import { TESTNET_ACCOUNT, TESTNET_DEPLOYMENT, TESTNET_UNITS } from "./deployments/testnet.mjs";
|
|
4
5
|
import { getDeployment, getUnits } from "./deployments/index.mjs";
|
|
5
6
|
import { account_events_exports } from "./contracts/account/account_events.mjs";
|
|
@@ -19,7 +20,8 @@ import { deriveObjectID } from "@mysten/sui/utils";
|
|
|
19
20
|
*/
|
|
20
21
|
function getAccountConfig(network) {
|
|
21
22
|
if (network === "testnet") return TESTNET_ACCOUNT;
|
|
22
|
-
|
|
23
|
+
if (network === "mainnet") return MAINNET_ACCOUNT;
|
|
24
|
+
throw new Error(`@mysten/deepbook-v3/account: no account deployment recorded for network '${network}'. The account primitive is recorded for testnet and mainnet; for your own deployment pass \`{ accountPackageId, accountRegistry }\` to AccountContract directly.`);
|
|
23
25
|
}
|
|
24
26
|
const AccountWrapperKey = bcs.struct("AccountWrapperKey", { pos0: bcs.Address });
|
|
25
27
|
/**
|
package/dist/account.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"account.mjs","names":["#config","account.generateAuth","accountRegistry._new","account.share","account.depositFunds","account.withdrawFunds","account.loadAccount","account.balance"],"sources":["../src/account.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\nimport { bcs } from '@mysten/sui/bcs';\nimport type {\n\tTransaction,\n\tTransactionObjectArgument,\n\tTransactionResult,\n} from '@mysten/sui/transactions';\nimport { deriveObjectID } from '@mysten/sui/utils';\n\nimport * as account from './contracts/account/account.js';\nimport * as accountRegistry from './contracts/account/account_registry.js';\nimport type { AccountConfig as GeneratedAccountConfig } from './contracts/account/config-arguments.js';\nimport { TESTNET_ACCOUNT } from './deployments/testnet.js';\nimport type { NetworkArg } from './deployments/index.js';\n\n// Provenance: which on-chain deployment the ids above came from. Re-exported so a consumer\n// can answer \"which deploy is this build pinned to?\" without reaching for another subpath.\nexport { getDeployment, getUnits, TESTNET_DEPLOYMENT, TESTNET_UNITS } from './deployments/index.js';\nexport type { NetworkArg } from './deployments/index.js';\nexport type { DeployedNetwork } from './deployments/index.js';\n\n/**\n * The deployed ids of the shared `account` package this contract builds against.\n *\n * Kept deliberately minimal — ids only — so any consumer of the shared account primitive\n * (DeepBook core's account wrapper, Predict, …) can drive these builders with its OWN\n * deployment's ids without constructing a full product-SDK config.\n *\n * Extends the codegen-generated config interface so there is exactly one config shape and\n * casing: the generated bindings resolve `options.config` against these same keys, and if\n * codegen adds, drops, or renames a key this file stops compiling instead of silently\n * building a PTB against the wrong object. The ids are narrowed to `string` — codegen types\n * the package id as optional and the registry as the wider `ConfigValue`, but the\n * wrapper-address derivation needs plain ids.\n */\nexport interface AccountConfig extends GeneratedAccountConfig {\n\t/** The `account` Move package id. */\n\taccountPackageId: string;\n\t/** The shared `AccountRegistry` object id. */\n\taccountRegistry: string;\n}\n\n/**\n * @description The deployed `account` ids for `network`, so a caller does not transcribe\n * them. Generated from the deploy manifest — see `src/deployments/`.\n * @throws if the network has no recorded deployment, rather than returning placeholder ids\n * that would fail as a confusing on-chain abort.\n *\n * ```ts\n * const account = new AccountContract(getAccountConfig('testnet'));\n * ```\n */\nexport function getAccountConfig(network: NetworkArg): AccountConfig {\n\tif (network === 'testnet') return TESTNET_ACCOUNT;\n\tthrow new Error(\n\t\t`@mysten/deepbook-v3/account: no account deployment recorded for network '${network}'. ` +\n\t\t\t'The account primitive is testnet-only today; for your own deployment pass ' +\n\t\t\t'`{ accountPackageId, accountRegistry }` to AccountContract directly.',\n\t);\n}\n\n// `AccountWrapperKey(address)` is a one-field positional struct, so its BCS is just the\n// owner's 32-byte address. See `packages/account/sources/account_registry.move`.\nconst AccountWrapperKey = bcs.struct('AccountWrapperKey', {\n\tpos0: bcs.Address,\n});\n\n/**\n * AccountContract — the reusable on-chain account primitive (`packages/account`).\n *\n * An owner has one canonical `AccountWrapper`, a *derived* object of the account registry,\n * so its id is computable off-chain (no read). The wrapper holds an `Account` whose custody\n * balances apps deposit into and withdraw from; app-specific data hangs off it under an\n * app-keyed slot. Authority is a hot-potato `Auth` minted from the tx sender and consumed\n * by the very next account-loading call.\n */\nexport class AccountContract {\n\t#config: AccountConfig;\n\n\t/**\n\t * @param {AccountConfig} config Deployed ids of the shared `account` package\n\t */\n\tconstructor(config: AccountConfig) {\n\t\tthis.#config = config;\n\t}\n\n\t/**\n\t * @description The deterministic id of an owner's canonical account wrapper — no chain\n\t * read needed. The wrapper is a derived object of the account registry, so its id is\n\t * `derive_address(registry, AccountWrapperKey(owner))`.\n\t * @param {string} owner Owner address\n\t * @returns The wrapper object id\n\t */\n\tderiveAccountWrapperId(owner: string): string {\n\t\tconst key = AccountWrapperKey.serialize({ pos0: owner }).toBytes();\n\t\treturn deriveObjectID(\n\t\t\tthis.#config.accountRegistry,\n\t\t\t`${this.#config.accountPackageId}::account_registry::AccountWrapperKey`,\n\t\t\tkey,\n\t\t);\n\t}\n\n\t/**\n\t * @description Mint owner authority for the transaction sender. A hot-potato `Auth`\n\t * consumed by the very next account-loading call (`load_account_mut` inside\n\t * `deposit_funds` / `withdraw_funds` / an app's own entrypoints).\n\t * @returns A function that takes a Transaction object\n\t */\n\tgenerateAuth() {\n\t\treturn (tx: Transaction): TransactionResult =>\n\t\t\ttx.add(account.generateAuth({ config: this.#config }));\n\t}\n\n\t/**\n\t * @description Create the sender's canonical account wrapper and share it. `new` derives\n\t * the wrapper at its deterministic address (see `deriveAccountWrapperId`) and aborts if\n\t * it already exists; `share` publishes the shared object apps borrow against.\n\t * @returns A function that takes a Transaction object\n\t */\n\tcreateAccount() {\n\t\treturn (tx: Transaction): void => {\n\t\t\tconst wrapper = tx.add(accountRegistry._new({ config: this.#config }));\n\t\t\ttx.add(account.share({ config: this.#config, arguments: { self: wrapper } }));\n\t\t};\n\t}\n\n\t/**\n\t * @description First-time funding in ONE PTB: create the sender's wrapper, deposit\n\t * `coin` through the fresh handle, then `share` LAST (once shared, by-value use of the\n\t * handle is over). This cannot be split into `createAccount` + `depositFunds`: an object\n\t * input can only address an object that pre-exists the PTB, so a wrapper created inside\n\t * it is reachable only through `new`'s result handle.\n\t * @param {object} params Coin to deposit and its coin type\n\t * @returns A function that takes a Transaction object\n\t */\n\tcreateAccountAndDeposit(params: { coin: TransactionObjectArgument; coinType: string }) {\n\t\treturn (tx: Transaction): void => {\n\t\t\tconst wrapper = tx.add(accountRegistry._new({ config: this.#config }));\n\t\t\tconst auth = tx.add(this.generateAuth());\n\t\t\ttx.add(\n\t\t\t\taccount.depositFunds({\n\t\t\t\t\tconfig: this.#config,\n\t\t\t\t\targuments: { wrapper, auth, coin: params.coin },\n\t\t\t\t\ttypeArguments: [params.coinType],\n\t\t\t\t}),\n\t\t\t);\n\t\t\ttx.add(account.share({ config: this.#config, arguments: { self: wrapper } }));\n\t\t};\n\t}\n\n\t/**\n\t * @description Deposit a caller-provided `coin` into the account's stored balance via the\n\t * PTB-callable `deposit_funds` (folds settle → authorize → load → deposit; clock and\n\t * accumulator root auto-injected). The caller owns coin sourcing.\n\t * @param {object} params Wrapper id, coin to deposit, and its coin type\n\t * @returns A function that takes a Transaction object\n\t */\n\tdepositFunds(params: { wrapperId: string; coin: TransactionObjectArgument; coinType: string }) {\n\t\treturn (tx: Transaction): void => {\n\t\t\tconst auth = tx.add(this.generateAuth());\n\t\t\ttx.add(\n\t\t\t\taccount.depositFunds({\n\t\t\t\t\tconfig: this.#config,\n\t\t\t\t\targuments: { wrapper: params.wrapperId, auth, coin: params.coin },\n\t\t\t\t\ttypeArguments: [params.coinType],\n\t\t\t\t}),\n\t\t\t);\n\t\t};\n\t}\n\n\t/**\n\t * @description Withdraw `amount` (raw u64 units) from the account's stored balance via\n\t * the PTB-callable `withdraw_funds` (folds settle → authorize → load → withdraw; clock\n\t * and accumulator root auto-injected), returning the minted `Coin<T>` for the caller to\n\t * transfer or compose.\n\t * @param {object} params Wrapper id, raw amount, and coin type\n\t * @returns A function that takes a Transaction object and returns the `Coin<T>`\n\t */\n\twithdrawFunds(params: { wrapperId: string; amount: bigint; coinType: string }) {\n\t\treturn (tx: Transaction): TransactionResult => {\n\t\t\tconst auth = tx.add(this.generateAuth());\n\t\t\treturn tx.add(\n\t\t\t\taccount.withdrawFunds({\n\t\t\t\t\tconfig: this.#config,\n\t\t\t\t\targuments: { wrapper: params.wrapperId, auth, amount: params.amount },\n\t\t\t\t\ttypeArguments: [params.coinType],\n\t\t\t\t}),\n\t\t\t);\n\t\t};\n\t}\n\n\t/**\n\t * @description Borrow the `Account` out of its wrapper — the read-side entry point apps\n\t * chain their own getters onto (`account::balance<T>`, an app's own data accessors).\n\t * @param {object} params Wrapper id\n\t * @returns A function that takes a Transaction object and returns the `Account`\n\t */\n\tloadAccount(params: { wrapperId: string }) {\n\t\treturn (tx: Transaction): TransactionResult =>\n\t\t\ttx.add(account.loadAccount({ config: this.#config, arguments: { self: params.wrapperId } }));\n\t}\n\n\t/**\n\t * @description Read an owner's stored custody balance for a coin type: chains\n\t * `load_account(wrapper)` → `balance<T>(account, root, clock)`. Compose in a\n\t * dev-inspect/simulate PTB and read the u64 return of the LAST command.\n\t * @param {object} params Owner address and coin type\n\t * @returns A function that takes a Transaction object\n\t */\n\tbalance(params: { owner: string; coinType: string }) {\n\t\treturn (tx: Transaction): TransactionResult => {\n\t\t\tconst acct = tx.add(\n\t\t\t\tthis.loadAccount({ wrapperId: this.deriveAccountWrapperId(params.owner) }),\n\t\t\t);\n\t\t\treturn tx.add(\n\t\t\t\taccount.balance({\n\t\t\t\t\tconfig: this.#config,\n\t\t\t\t\ttypeArguments: [params.coinType],\n\t\t\t\t\targuments: { self: acct },\n\t\t\t\t}),\n\t\t\t);\n\t\t};\n\t}\n}\n\n// === Generated bindings ===\n// The move-call thunks and BCS structs, for consumers composing their own PTBs or\n// parsing account objects/events (e.g. `AccountWrapper.parse`, the event layouts).\n//\n// NOTE: `Account` here is the shared account primitive's custody account\n// (`account::account::Account`). It is deliberately NOT re-exported from this\n// package's root — the root already exports a different `Account`\n// (`@deepbook/core::account::Account`, the per-pool trading account) and the two\n// have unrelated layouts. Keep them separated by subpath.\nexport * as accountMoveCalls from './contracts/account/account.js';\nexport * as accountRegistryMoveCalls from './contracts/account/account_registry.js';\nexport * as accountEvents from './contracts/account/account_events.js';\nexport { Account, AccountWrapper } from './contracts/account/account.js';\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAqDA,SAAgB,iBAAiB,SAAoC;AACpE,KAAI,YAAY,UAAW,QAAO;AAClC,OAAM,IAAI,MACT,4EAA4E,QAAQ,qJAGpF;;AAKF,MAAM,oBAAoB,IAAI,OAAO,qBAAqB,EACzD,MAAM,IAAI,SACV,CAAC;;;;;;;;;;AAWF,IAAa,kBAAb,MAA6B;CAC5B;;;;CAKA,YAAY,QAAuB;AAClC,QAAKA,SAAU;;;;;;;;;CAUhB,uBAAuB,OAAuB;EAC7C,MAAM,MAAM,kBAAkB,UAAU,EAAE,MAAM,OAAO,CAAC,CAAC,SAAS;AAClE,SAAO,eACN,MAAKA,OAAQ,iBACb,GAAG,MAAKA,OAAQ,iBAAiB,wCACjC,IACA;;;;;;;;CASF,eAAe;AACd,UAAQ,OACP,GAAG,IAAIC,aAAqB,EAAE,QAAQ,MAAKD,QAAS,CAAC,CAAC;;;;;;;;CASxD,gBAAgB;AACf,UAAQ,OAA0B;GACjC,MAAM,UAAU,GAAG,IAAIE,KAAqB,EAAE,QAAQ,MAAKF,QAAS,CAAC,CAAC;AACtE,MAAG,IAAIG,MAAc;IAAE,QAAQ,MAAKH;IAAS,WAAW,EAAE,MAAM,SAAS;IAAE,CAAC,CAAC;;;;;;;;;;;;CAa/E,wBAAwB,QAA+D;AACtF,UAAQ,OAA0B;GACjC,MAAM,UAAU,GAAG,IAAIE,KAAqB,EAAE,QAAQ,MAAKF,QAAS,CAAC,CAAC;GACtE,MAAM,OAAO,GAAG,IAAI,KAAK,cAAc,CAAC;AACxC,MAAG,IACFI,aAAqB;IACpB,QAAQ,MAAKJ;IACb,WAAW;KAAE;KAAS;KAAM,MAAM,OAAO;KAAM;IAC/C,eAAe,CAAC,OAAO,SAAS;IAChC,CAAC,CACF;AACD,MAAG,IAAIG,MAAc;IAAE,QAAQ,MAAKH;IAAS,WAAW,EAAE,MAAM,SAAS;IAAE,CAAC,CAAC;;;;;;;;;;CAW/E,aAAa,QAAkF;AAC9F,UAAQ,OAA0B;GACjC,MAAM,OAAO,GAAG,IAAI,KAAK,cAAc,CAAC;AACxC,MAAG,IACFI,aAAqB;IACpB,QAAQ,MAAKJ;IACb,WAAW;KAAE,SAAS,OAAO;KAAW;KAAM,MAAM,OAAO;KAAM;IACjE,eAAe,CAAC,OAAO,SAAS;IAChC,CAAC,CACF;;;;;;;;;;;CAYH,cAAc,QAAiE;AAC9E,UAAQ,OAAuC;GAC9C,MAAM,OAAO,GAAG,IAAI,KAAK,cAAc,CAAC;AACxC,UAAO,GAAG,IACTK,cAAsB;IACrB,QAAQ,MAAKL;IACb,WAAW;KAAE,SAAS,OAAO;KAAW;KAAM,QAAQ,OAAO;KAAQ;IACrE,eAAe,CAAC,OAAO,SAAS;IAChC,CAAC,CACF;;;;;;;;;CAUH,YAAY,QAA+B;AAC1C,UAAQ,OACP,GAAG,IAAIM,YAAoB;GAAE,QAAQ,MAAKN;GAAS,WAAW,EAAE,MAAM,OAAO,WAAW;GAAE,CAAC,CAAC;;;;;;;;;CAU9F,QAAQ,QAA6C;AACpD,UAAQ,OAAuC;GAC9C,MAAM,OAAO,GAAG,IACf,KAAK,YAAY,EAAE,WAAW,KAAK,uBAAuB,OAAO,MAAM,EAAE,CAAC,CAC1E;AACD,UAAO,GAAG,IACTO,QAAgB;IACf,QAAQ,MAAKP;IACb,eAAe,CAAC,OAAO,SAAS;IAChC,WAAW,EAAE,MAAM,MAAM;IACzB,CAAC,CACF"}
|
|
1
|
+
{"version":3,"file":"account.mjs","names":["#config","account.generateAuth","accountRegistry._new","account.share","account.depositFunds","account.withdrawFunds","account.loadAccount","account.balance"],"sources":["../src/account.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\nimport { bcs } from '@mysten/sui/bcs';\nimport type {\n\tTransaction,\n\tTransactionObjectArgument,\n\tTransactionResult,\n} from '@mysten/sui/transactions';\nimport { deriveObjectID } from '@mysten/sui/utils';\n\nimport * as account from './contracts/account/account.js';\nimport * as accountRegistry from './contracts/account/account_registry.js';\nimport type { AccountConfig as GeneratedAccountConfig } from './contracts/account/config-arguments.js';\nimport { MAINNET_ACCOUNT } from './deployments/mainnet.js';\nimport { TESTNET_ACCOUNT } from './deployments/testnet.js';\nimport type { NetworkArg } from './deployments/index.js';\n\n// Provenance: which on-chain deployment the ids above came from. Re-exported so a consumer\n// can answer \"which deploy is this build pinned to?\" without reaching for another subpath.\nexport { getDeployment, getUnits, TESTNET_DEPLOYMENT, TESTNET_UNITS } from './deployments/index.js';\nexport type { NetworkArg } from './deployments/index.js';\nexport type { DeployedNetwork } from './deployments/index.js';\n\n/**\n * The deployed ids of the shared `account` package this contract builds against.\n *\n * Kept deliberately minimal — ids only — so any consumer of the shared account primitive\n * (DeepBook core's account wrapper, Predict, …) can drive these builders with its OWN\n * deployment's ids without constructing a full product-SDK config.\n *\n * Extends the codegen-generated config interface so there is exactly one config shape and\n * casing: the generated bindings resolve `options.config` against these same keys, and if\n * codegen adds, drops, or renames a key this file stops compiling instead of silently\n * building a PTB against the wrong object. The ids are narrowed to `string` — codegen types\n * the package id as optional and the registry as the wider `ConfigValue`, but the\n * wrapper-address derivation needs plain ids.\n */\nexport interface AccountConfig extends GeneratedAccountConfig {\n\t/** The `account` Move package id. */\n\taccountPackageId: string;\n\t/** The shared `AccountRegistry` object id. */\n\taccountRegistry: string;\n}\n\n/**\n * @description The deployed `account` ids for `network`, so a caller does not transcribe\n * them. Generated from the deploy manifest — see `src/deployments/`.\n * @throws if the network has no recorded deployment, rather than returning placeholder ids\n * that would fail as a confusing on-chain abort.\n *\n * ```ts\n * const account = new AccountContract(getAccountConfig('testnet'));\n * ```\n */\nexport function getAccountConfig(network: NetworkArg): AccountConfig {\n\tif (network === 'testnet') return TESTNET_ACCOUNT;\n\tif (network === 'mainnet') return MAINNET_ACCOUNT;\n\tthrow new Error(\n\t\t`@mysten/deepbook-v3/account: no account deployment recorded for network '${network}'. ` +\n\t\t\t'The account primitive is recorded for testnet and mainnet; for your own deployment pass ' +\n\t\t\t'`{ accountPackageId, accountRegistry }` to AccountContract directly.',\n\t);\n}\n\n// `AccountWrapperKey(address)` is a one-field positional struct, so its BCS is just the\n// owner's 32-byte address. See `packages/account/sources/account_registry.move`.\nconst AccountWrapperKey = bcs.struct('AccountWrapperKey', {\n\tpos0: bcs.Address,\n});\n\n/**\n * AccountContract — the reusable on-chain account primitive (`packages/account`).\n *\n * An owner has one canonical `AccountWrapper`, a *derived* object of the account registry,\n * so its id is computable off-chain (no read). The wrapper holds an `Account` whose custody\n * balances apps deposit into and withdraw from; app-specific data hangs off it under an\n * app-keyed slot. Authority is a hot-potato `Auth` minted from the tx sender and consumed\n * by the very next account-loading call.\n */\nexport class AccountContract {\n\t#config: AccountConfig;\n\n\t/**\n\t * @param {AccountConfig} config Deployed ids of the shared `account` package\n\t */\n\tconstructor(config: AccountConfig) {\n\t\tthis.#config = config;\n\t}\n\n\t/**\n\t * @description The deterministic id of an owner's canonical account wrapper — no chain\n\t * read needed. The wrapper is a derived object of the account registry, so its id is\n\t * `derive_address(registry, AccountWrapperKey(owner))`.\n\t * @param {string} owner Owner address\n\t * @returns The wrapper object id\n\t */\n\tderiveAccountWrapperId(owner: string): string {\n\t\tconst key = AccountWrapperKey.serialize({ pos0: owner }).toBytes();\n\t\treturn deriveObjectID(\n\t\t\tthis.#config.accountRegistry,\n\t\t\t`${this.#config.accountPackageId}::account_registry::AccountWrapperKey`,\n\t\t\tkey,\n\t\t);\n\t}\n\n\t/**\n\t * @description Mint owner authority for the transaction sender. A hot-potato `Auth`\n\t * consumed by the very next account-loading call (`load_account_mut` inside\n\t * `deposit_funds` / `withdraw_funds` / an app's own entrypoints).\n\t * @returns A function that takes a Transaction object\n\t */\n\tgenerateAuth() {\n\t\treturn (tx: Transaction): TransactionResult =>\n\t\t\ttx.add(account.generateAuth({ config: this.#config }));\n\t}\n\n\t/**\n\t * @description Create the sender's canonical account wrapper and share it. `new` derives\n\t * the wrapper at its deterministic address (see `deriveAccountWrapperId`) and aborts if\n\t * it already exists; `share` publishes the shared object apps borrow against.\n\t * @returns A function that takes a Transaction object\n\t */\n\tcreateAccount() {\n\t\treturn (tx: Transaction): void => {\n\t\t\tconst wrapper = tx.add(accountRegistry._new({ config: this.#config }));\n\t\t\ttx.add(account.share({ config: this.#config, arguments: { self: wrapper } }));\n\t\t};\n\t}\n\n\t/**\n\t * @description First-time funding in ONE PTB: create the sender's wrapper, deposit\n\t * `coin` through the fresh handle, then `share` LAST (once shared, by-value use of the\n\t * handle is over). This cannot be split into `createAccount` + `depositFunds`: an object\n\t * input can only address an object that pre-exists the PTB, so a wrapper created inside\n\t * it is reachable only through `new`'s result handle.\n\t * @param {object} params Coin to deposit and its coin type\n\t * @returns A function that takes a Transaction object\n\t */\n\tcreateAccountAndDeposit(params: { coin: TransactionObjectArgument; coinType: string }) {\n\t\treturn (tx: Transaction): void => {\n\t\t\tconst wrapper = tx.add(accountRegistry._new({ config: this.#config }));\n\t\t\tconst auth = tx.add(this.generateAuth());\n\t\t\ttx.add(\n\t\t\t\taccount.depositFunds({\n\t\t\t\t\tconfig: this.#config,\n\t\t\t\t\targuments: { wrapper, auth, coin: params.coin },\n\t\t\t\t\ttypeArguments: [params.coinType],\n\t\t\t\t}),\n\t\t\t);\n\t\t\ttx.add(account.share({ config: this.#config, arguments: { self: wrapper } }));\n\t\t};\n\t}\n\n\t/**\n\t * @description Deposit a caller-provided `coin` into the account's stored balance via the\n\t * PTB-callable `deposit_funds` (folds settle → authorize → load → deposit; clock and\n\t * accumulator root auto-injected). The caller owns coin sourcing.\n\t * @param {object} params Wrapper id, coin to deposit, and its coin type\n\t * @returns A function that takes a Transaction object\n\t */\n\tdepositFunds(params: { wrapperId: string; coin: TransactionObjectArgument; coinType: string }) {\n\t\treturn (tx: Transaction): void => {\n\t\t\tconst auth = tx.add(this.generateAuth());\n\t\t\ttx.add(\n\t\t\t\taccount.depositFunds({\n\t\t\t\t\tconfig: this.#config,\n\t\t\t\t\targuments: { wrapper: params.wrapperId, auth, coin: params.coin },\n\t\t\t\t\ttypeArguments: [params.coinType],\n\t\t\t\t}),\n\t\t\t);\n\t\t};\n\t}\n\n\t/**\n\t * @description Withdraw `amount` (raw u64 units) from the account's stored balance via\n\t * the PTB-callable `withdraw_funds` (folds settle → authorize → load → withdraw; clock\n\t * and accumulator root auto-injected), returning the minted `Coin<T>` for the caller to\n\t * transfer or compose.\n\t * @param {object} params Wrapper id, raw amount, and coin type\n\t * @returns A function that takes a Transaction object and returns the `Coin<T>`\n\t */\n\twithdrawFunds(params: { wrapperId: string; amount: bigint; coinType: string }) {\n\t\treturn (tx: Transaction): TransactionResult => {\n\t\t\tconst auth = tx.add(this.generateAuth());\n\t\t\treturn tx.add(\n\t\t\t\taccount.withdrawFunds({\n\t\t\t\t\tconfig: this.#config,\n\t\t\t\t\targuments: { wrapper: params.wrapperId, auth, amount: params.amount },\n\t\t\t\t\ttypeArguments: [params.coinType],\n\t\t\t\t}),\n\t\t\t);\n\t\t};\n\t}\n\n\t/**\n\t * @description Borrow the `Account` out of its wrapper — the read-side entry point apps\n\t * chain their own getters onto (`account::balance<T>`, an app's own data accessors).\n\t * @param {object} params Wrapper id\n\t * @returns A function that takes a Transaction object and returns the `Account`\n\t */\n\tloadAccount(params: { wrapperId: string }) {\n\t\treturn (tx: Transaction): TransactionResult =>\n\t\t\ttx.add(account.loadAccount({ config: this.#config, arguments: { self: params.wrapperId } }));\n\t}\n\n\t/**\n\t * @description Read an owner's stored custody balance for a coin type: chains\n\t * `load_account(wrapper)` → `balance<T>(account, root, clock)`. Compose in a\n\t * dev-inspect/simulate PTB and read the u64 return of the LAST command.\n\t * @param {object} params Owner address and coin type\n\t * @returns A function that takes a Transaction object\n\t */\n\tbalance(params: { owner: string; coinType: string }) {\n\t\treturn (tx: Transaction): TransactionResult => {\n\t\t\tconst acct = tx.add(\n\t\t\t\tthis.loadAccount({ wrapperId: this.deriveAccountWrapperId(params.owner) }),\n\t\t\t);\n\t\t\treturn tx.add(\n\t\t\t\taccount.balance({\n\t\t\t\t\tconfig: this.#config,\n\t\t\t\t\ttypeArguments: [params.coinType],\n\t\t\t\t\targuments: { self: acct },\n\t\t\t\t}),\n\t\t\t);\n\t\t};\n\t}\n}\n\n// === Generated bindings ===\n// The move-call thunks and BCS structs, for consumers composing their own PTBs or\n// parsing account objects/events (e.g. `AccountWrapper.parse`, the event layouts).\n//\n// NOTE: `Account` here is the shared account primitive's custody account\n// (`account::account::Account`). It is deliberately NOT re-exported from this\n// package's root — the root already exports a different `Account`\n// (`@deepbook/core::account::Account`, the per-pool trading account) and the two\n// have unrelated layouts. Keep them separated by subpath.\nexport * as accountMoveCalls from './contracts/account/account.js';\nexport * as accountRegistryMoveCalls from './contracts/account/account_registry.js';\nexport * as accountEvents from './contracts/account/account_events.js';\nexport { Account, AccountWrapper } from './contracts/account/account.js';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAsDA,SAAgB,iBAAiB,SAAoC;AACpE,KAAI,YAAY,UAAW,QAAO;AAClC,KAAI,YAAY,UAAW,QAAO;AAClC,OAAM,IAAI,MACT,4EAA4E,QAAQ,mKAGpF;;AAKF,MAAM,oBAAoB,IAAI,OAAO,qBAAqB,EACzD,MAAM,IAAI,SACV,CAAC;;;;;;;;;;AAWF,IAAa,kBAAb,MAA6B;CAC5B;;;;CAKA,YAAY,QAAuB;AAClC,QAAKA,SAAU;;;;;;;;;CAUhB,uBAAuB,OAAuB;EAC7C,MAAM,MAAM,kBAAkB,UAAU,EAAE,MAAM,OAAO,CAAC,CAAC,SAAS;AAClE,SAAO,eACN,MAAKA,OAAQ,iBACb,GAAG,MAAKA,OAAQ,iBAAiB,wCACjC,IACA;;;;;;;;CASF,eAAe;AACd,UAAQ,OACP,GAAG,IAAIC,aAAqB,EAAE,QAAQ,MAAKD,QAAS,CAAC,CAAC;;;;;;;;CASxD,gBAAgB;AACf,UAAQ,OAA0B;GACjC,MAAM,UAAU,GAAG,IAAIE,KAAqB,EAAE,QAAQ,MAAKF,QAAS,CAAC,CAAC;AACtE,MAAG,IAAIG,MAAc;IAAE,QAAQ,MAAKH;IAAS,WAAW,EAAE,MAAM,SAAS;IAAE,CAAC,CAAC;;;;;;;;;;;;CAa/E,wBAAwB,QAA+D;AACtF,UAAQ,OAA0B;GACjC,MAAM,UAAU,GAAG,IAAIE,KAAqB,EAAE,QAAQ,MAAKF,QAAS,CAAC,CAAC;GACtE,MAAM,OAAO,GAAG,IAAI,KAAK,cAAc,CAAC;AACxC,MAAG,IACFI,aAAqB;IACpB,QAAQ,MAAKJ;IACb,WAAW;KAAE;KAAS;KAAM,MAAM,OAAO;KAAM;IAC/C,eAAe,CAAC,OAAO,SAAS;IAChC,CAAC,CACF;AACD,MAAG,IAAIG,MAAc;IAAE,QAAQ,MAAKH;IAAS,WAAW,EAAE,MAAM,SAAS;IAAE,CAAC,CAAC;;;;;;;;;;CAW/E,aAAa,QAAkF;AAC9F,UAAQ,OAA0B;GACjC,MAAM,OAAO,GAAG,IAAI,KAAK,cAAc,CAAC;AACxC,MAAG,IACFI,aAAqB;IACpB,QAAQ,MAAKJ;IACb,WAAW;KAAE,SAAS,OAAO;KAAW;KAAM,MAAM,OAAO;KAAM;IACjE,eAAe,CAAC,OAAO,SAAS;IAChC,CAAC,CACF;;;;;;;;;;;CAYH,cAAc,QAAiE;AAC9E,UAAQ,OAAuC;GAC9C,MAAM,OAAO,GAAG,IAAI,KAAK,cAAc,CAAC;AACxC,UAAO,GAAG,IACTK,cAAsB;IACrB,QAAQ,MAAKL;IACb,WAAW;KAAE,SAAS,OAAO;KAAW;KAAM,QAAQ,OAAO;KAAQ;IACrE,eAAe,CAAC,OAAO,SAAS;IAChC,CAAC,CACF;;;;;;;;;CAUH,YAAY,QAA+B;AAC1C,UAAQ,OACP,GAAG,IAAIM,YAAoB;GAAE,QAAQ,MAAKN;GAAS,WAAW,EAAE,MAAM,OAAO,WAAW;GAAE,CAAC,CAAC;;;;;;;;;CAU9F,QAAQ,QAA6C;AACpD,UAAQ,OAAuC;GAC9C,MAAM,OAAO,GAAG,IACf,KAAK,YAAY,EAAE,WAAW,KAAK,uBAAuB,OAAO,MAAM,EAAE,CAAC,CAC1E;AACD,UAAO,GAAG,IACTO,QAAgB;IACf,QAAQ,MAAKP;IACb,eAAe,CAAC,OAAO,SAAS;IAChC,WAAW,EAAE,MAAM,MAAM;IACzB,CAAC,CACF"}
|
package/dist/client.d.mts
CHANGED
|
@@ -163,7 +163,7 @@ declare class DeepBookClient {
|
|
|
163
163
|
}[] | null>;
|
|
164
164
|
getLevel2Range(poolKey: string, priceLow: number | bigint, priceHigh: number | bigint, isBid: boolean): Promise<Level2Range>;
|
|
165
165
|
getLevel2TicksFromMid(poolKey: string, ticks: number): Promise<Level2TicksFromMid>;
|
|
166
|
-
getAccountOrderDetails(poolKey: string, managerKey: string): Promise<
|
|
166
|
+
getAccountOrderDetails(poolKey: string, managerKey: string): Promise<{
|
|
167
167
|
balance_manager_id: string;
|
|
168
168
|
order_id: string;
|
|
169
169
|
client_order_id: string;
|
|
@@ -177,7 +177,7 @@ declare class DeepBookClient {
|
|
|
177
177
|
epoch: string;
|
|
178
178
|
status: number;
|
|
179
179
|
expire_timestamp: string;
|
|
180
|
-
}[]>;
|
|
180
|
+
}[] | []>;
|
|
181
181
|
account(poolKey: string, managerKey: string): Promise<AccountInfo>;
|
|
182
182
|
lockedBalance(poolKey: string, balanceManagerKey: string): Promise<LockedBalances>;
|
|
183
183
|
getPoolDeepPrice(poolKey: string): Promise<PoolDeepPrice>;
|