@waterx/sdk 3.0.0 → 3.0.1

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.
@@ -1,13 +1,19 @@
1
+ import { OrderKind as OrderKindBcs } from "../generated/waterx_prediction/order.ts";
2
+ import { Outcome as OutcomeBcs } from "../generated/waterx_prediction/outcome.ts";
3
+ import { Selection as SelectionBcs, Status as StatusBcs } from "../generated/waterx_prediction/position.ts";
4
+ import { AccountDataView as AccountDataViewBcs, MarketView as MarketViewBcs, OrderView as OrderViewBcs, PositionView as PositionViewBcs, RegistryView as RegistryViewBcs } from "../generated/waterx_prediction/view.ts";
1
5
  import type { AccountDataView, CursorView, MarketExposure, MarketView, OrderKind, OrderView, Outcome, PositionStatus, PositionView, RegistryView, Selection } from "./types.ts";
2
- export declare const OrderKindBcs: any;
3
- export declare const SelectionBcs: any;
4
- export declare const StatusBcs: any;
5
- export declare const OutcomeBcs: any;
6
- export declare const RegistryViewBcs: any;
7
- export declare const OrderViewBcs: any;
8
- export declare const PositionViewBcs: any;
9
- export declare const MarketViewBcs: any;
10
- export declare const AccountDataViewBcs: any;
6
+ /**
7
+ * The prediction line decodes its `view::*` simulate reads with the codegen
8
+ * schemas in `../generated/waterx_prediction/*` — the single source of truth,
9
+ * regenerated by `pnpm codegen` from the deployed Move ABI. They are re-exported
10
+ * here under the legacy `*Bcs` names for back-compat (the public
11
+ * `@waterx/sdk/prediction/utils/bcs` subpath + tests). There is NO hand-written
12
+ * BCS mirror to keep in sync — a contract field add/remove/reorder flows in via
13
+ * `pnpm codegen`; the `map*` helpers below only translate the raw parse output
14
+ * to the public camelCase view types.
15
+ */
16
+ export { AccountDataViewBcs, MarketViewBcs, OrderKindBcs, OrderViewBcs, OutcomeBcs, PositionViewBcs, RegistryViewBcs, SelectionBcs, StatusBcs, };
11
17
  export declare function decodeEnumVariant(raw: unknown): string;
12
18
  export declare function mapSelection(raw: unknown): Selection;
13
19
  export declare function mapOutcome(raw: unknown): Outcome;
@@ -1,85 +1,19 @@
1
- import { bcs } from "@mysten/sui/bcs";
1
+ import { OrderKind as OrderKindBcs } from "../generated/waterx_prediction/order.js";
2
+ import { Outcome as OutcomeBcs } from "../generated/waterx_prediction/outcome.js";
3
+ import { Selection as SelectionBcs, Status as StatusBcs, } from "../generated/waterx_prediction/position.js";
4
+ import { AccountDataView as AccountDataViewBcs, MarketView as MarketViewBcs, OrderView as OrderViewBcs, PositionView as PositionViewBcs, RegistryView as RegistryViewBcs, } from "../generated/waterx_prediction/view.js";
2
5
  import { bytesToHex, marketIdBytesFromUnknown } from "./utils.js";
3
- export const OrderKindBcs = bcs.enum("OrderKind", {
4
- Open: null,
5
- Close: null,
6
- });
7
- export const SelectionBcs = bcs.enum("Selection", {
8
- No: null,
9
- Yes: null,
10
- });
11
- export const StatusBcs = bcs.enum("Status", {
12
- Open: null,
13
- PendingClose: null,
14
- });
15
- export const OutcomeBcs = bcs.enum("Outcome", {
16
- No: null,
17
- Yes: null,
18
- Invalid: null,
19
- });
20
- export const RegistryViewBcs = bcs.struct("RegistryView", {
21
- balance: bcs.u64(),
22
- min_reserve: bcs.u64(),
23
- order_cancel_cooldown_ms: bcs.u64(),
24
- next_order_id: bcs.u64(),
25
- order_count: bcs.u64(),
26
- position_count: bcs.u64(),
27
- unresolved_market_count: bcs.u64(),
28
- resolved_market_count: bcs.u64(),
29
- });
30
- export const OrderViewBcs = bcs.struct("OrderView", {
31
- order_id: bcs.u64(),
32
- kind: OrderKindBcs,
33
- account_id: bcs.Address,
34
- market_id: bcs.vector(bcs.u8()),
35
- selection: SelectionBcs,
36
- position_id: bcs.option(bcs.u64()),
37
- max_spend: bcs.u64(),
38
- min_shares: bcs.u64(),
39
- price_cap: bcs.u64(),
40
- min_proceeds: bcs.u64(),
41
- expiry_ts: bcs.u64(),
42
- self_cancel_after_ts: bcs.u64(),
43
- created_ts: bcs.u64(),
44
- by_admin: bcs.bool(),
45
- });
46
- export const PositionViewBcs = bcs.struct("PositionView", {
47
- position_id: bcs.u64(),
48
- account_id: bcs.Address,
49
- market_id: bcs.vector(bcs.u8()),
50
- selection: SelectionBcs,
51
- status: StatusBcs,
52
- filled_shares: bcs.u64(),
53
- filled_cost: bcs.u64(),
54
- opened_ts: bcs.u64(),
55
- payout: bcs.u64(),
56
- close_order_id: bcs.option(bcs.u64()),
57
- close_min_proceeds: bcs.u64(),
58
- close_expiry_ts: bcs.u64(),
59
- close_self_cancel_after_ts: bcs.u64(),
60
- });
61
- export const MarketViewBcs = bcs.struct("MarketView", {
62
- market_key: bcs.u64(),
63
- market_id: bcs.vector(bcs.u8()),
64
- resolved: bcs.bool(),
65
- paused: bcs.bool(),
66
- outcome: bcs.option(OutcomeBcs),
67
- unclaimed_count: bcs.u64(),
68
- yes_shares: bcs.u64(),
69
- yes_cost: bcs.u64(),
70
- no_shares: bcs.u64(),
71
- no_cost: bcs.u64(),
72
- });
73
- export const AccountDataViewBcs = bcs.struct("AccountDataView", {
74
- account_id: bcs.Address,
75
- has_data: bcs.bool(),
76
- order_count: bcs.u64(),
77
- position_count: bcs.u64(),
78
- order_front: bcs.option(bcs.u64()),
79
- order_back: bcs.option(bcs.u64()),
80
- position_front: bcs.option(bcs.u64()),
81
- position_back: bcs.option(bcs.u64()),
82
- });
6
+ /**
7
+ * The prediction line decodes its `view::*` simulate reads with the codegen
8
+ * schemas in `../generated/waterx_prediction/*` — the single source of truth,
9
+ * regenerated by `pnpm codegen` from the deployed Move ABI. They are re-exported
10
+ * here under the legacy `*Bcs` names for back-compat (the public
11
+ * `@waterx/sdk/prediction/utils/bcs` subpath + tests). There is NO hand-written
12
+ * BCS mirror to keep in sync — a contract field add/remove/reorder flows in via
13
+ * `pnpm codegen`; the `map*` helpers below only translate the raw parse output
14
+ * to the public camelCase view types.
15
+ */
16
+ export { AccountDataViewBcs, MarketViewBcs, OrderKindBcs, OrderViewBcs, OutcomeBcs, PositionViewBcs, RegistryViewBcs, SelectionBcs, StatusBcs, };
83
17
  export function decodeEnumVariant(raw) {
84
18
  if (typeof raw === "string")
85
19
  return raw;
@@ -150,6 +84,7 @@ export function mapRegistryView(raw) {
150
84
  minReserve: BigInt(raw.min_reserve),
151
85
  orderCancelCooldownMs: BigInt(raw.order_cancel_cooldown_ms),
152
86
  nextOrderId: BigInt(raw.next_order_id),
87
+ nextPositionId: BigInt(raw.next_position_id),
153
88
  orderCount: BigInt(raw.order_count),
154
89
  positionCount: BigInt(raw.position_count),
155
90
  unresolvedMarketCount: BigInt(raw.unresolved_market_count),
@@ -162,6 +97,7 @@ export function mapOrderView(raw) {
162
97
  orderId: BigInt(raw.order_id),
163
98
  kind: mapOrderKind(raw.kind),
164
99
  accountId: raw.account_id,
100
+ receiverAccountId: raw.receiver_account_id,
165
101
  marketId,
166
102
  marketIdHex: bytesToHex(marketId),
167
103
  selection: mapSelection(raw.selection),
@@ -23,7 +23,7 @@ import { Ed25519Keypair } from "@mysten/sui/keypairs/ed25519";
23
23
  import { Transaction } from "@mysten/sui/transactions";
24
24
  import { deriveObjectID, fromBase64, toBase64 } from "@mysten/sui/utils";
25
25
  import { sha256 } from "@noble/hashes/sha2.js";
26
- import { SelectionBcs } from "./bcs.js";
26
+ import { mapSelection, SelectionBcs } from "./bcs.js";
27
27
  import { GIFT_DOMAIN_CLAIM, GIFT_KDF_DOMAIN, GIFT_PUBKEY_LEN, GIFT_SIG_LEN, GIFT_URL_SEED_BYTES, } from "./constants.js";
28
28
  import { extractReturnBytes } from "./fetch.js";
29
29
  import { clockArg, createAccountRequest, idArg, resolveAccountRegistry, resolveGlobalConfig, resolveMarketRegistry, resolveSettlementCoinType, toBigInt, } from "./utils.js";
@@ -296,15 +296,7 @@ export async function getGift(client, params) {
296
296
  const id = () => bcs.Address.parse(extractReturnBytes(result, i++));
297
297
  const u64 = () => BigInt(bcs.u64().parse(extractReturnBytes(result, i++)));
298
298
  const bytes = () => new Uint8Array(bcs.vector(bcs.u8()).parse(extractReturnBytes(result, i++)));
299
- const sel = () => {
300
- const parsed = SelectionBcs.parse(extractReturnBytes(result, i++));
301
- const variant = parsed?.$kind ?? parsed; // bcs.enum returns { $kind } in v2
302
- if (variant === "Yes" || variant === "YES")
303
- return "YES";
304
- if (variant === "No" || variant === "NO")
305
- return "NO";
306
- throw new Error(`Unrecognized Selection variant: ${JSON.stringify(parsed)}`);
307
- };
299
+ const sel = () => mapSelection(SelectionBcs.parse(extractReturnBytes(result, i++)));
308
300
  const addrs = () => bcs.vector(bcs.Address).parse(extractReturnBytes(result, i++));
309
301
  const optString = () => bcs.option(bcs.string()).parse(extractReturnBytes(result, i++));
310
302
  const giftId = id();
@@ -14,6 +14,7 @@ export interface RegistryView {
14
14
  minReserve: bigint;
15
15
  orderCancelCooldownMs: bigint;
16
16
  nextOrderId: bigint;
17
+ nextPositionId: bigint;
17
18
  orderCount: bigint;
18
19
  positionCount: bigint;
19
20
  unresolvedMarketCount: bigint;
@@ -23,6 +24,7 @@ export interface OrderView {
23
24
  orderId: bigint;
24
25
  kind: OrderKind;
25
26
  accountId: string;
27
+ receiverAccountId: string;
26
28
  marketId: Uint8Array;
27
29
  marketIdHex: string;
28
30
  selection: Selection;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@waterx/sdk",
3
- "version": "3.0.0",
3
+ "version": "3.0.1",
4
4
  "description": "WaterX SDK — perpetuals and prediction markets on Sui",
5
5
  "license": "MIT",
6
6
  "author": "WaterX",