@waterx/predict-sdk 0.1.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.
Files changed (105) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +67 -0
  3. package/dist/src/account.d.ts +64 -0
  4. package/dist/src/account.js +134 -0
  5. package/dist/src/admin.d.ts +47 -0
  6. package/dist/src/admin.js +104 -0
  7. package/dist/src/bcs.d.ts +20 -0
  8. package/dist/src/bcs.js +209 -0
  9. package/dist/src/client.d.ts +60 -0
  10. package/dist/src/client.js +59 -0
  11. package/dist/src/constants.d.ts +61 -0
  12. package/dist/src/constants.js +62 -0
  13. package/dist/src/fetch.d.ts +53 -0
  14. package/dist/src/fetch.js +187 -0
  15. package/dist/src/generated/bucket_v2_framework/account.d.ts +100 -0
  16. package/dist/src/generated/bucket_v2_framework/account.js +129 -0
  17. package/dist/src/generated/bucket_v2_framework/deps/std/type_name.d.ts +6 -0
  18. package/dist/src/generated/bucket_v2_framework/deps/std/type_name.js +19 -0
  19. package/dist/src/generated/bucket_v2_framework/deps/sui/balance.d.ts +10 -0
  20. package/dist/src/generated/bucket_v2_framework/deps/sui/balance.js +14 -0
  21. package/dist/src/generated/bucket_v2_framework/deps/sui/vec_map.d.ts +36 -0
  22. package/dist/src/generated/bucket_v2_framework/deps/sui/vec_map.js +27 -0
  23. package/dist/src/generated/bucket_v2_framework/deps/sui/vec_set.d.ts +16 -0
  24. package/dist/src/generated/bucket_v2_framework/deps/sui/vec_set.js +19 -0
  25. package/dist/src/generated/bucket_v2_framework/double.d.ts +382 -0
  26. package/dist/src/generated/bucket_v2_framework/double.js +466 -0
  27. package/dist/src/generated/bucket_v2_framework/float.d.ts +362 -0
  28. package/dist/src/generated/bucket_v2_framework/float.js +440 -0
  29. package/dist/src/generated/bucket_v2_framework/liability.d.ts +193 -0
  30. package/dist/src/generated/bucket_v2_framework/liability.js +205 -0
  31. package/dist/src/generated/bucket_v2_framework/linked_table.d.ts +384 -0
  32. package/dist/src/generated/bucket_v2_framework/linked_table.js +382 -0
  33. package/dist/src/generated/bucket_v2_framework/sheet.d.ts +344 -0
  34. package/dist/src/generated/bucket_v2_framework/sheet.js +344 -0
  35. package/dist/src/generated/utils/index.d.ts +30 -0
  36. package/dist/src/generated/utils/index.js +157 -0
  37. package/dist/src/generated/waterx_account/account.d.ts +1326 -0
  38. package/dist/src/generated/waterx_account/account.js +1487 -0
  39. package/dist/src/generated/waterx_account/deps/std/type_name.d.ts +6 -0
  40. package/dist/src/generated/waterx_account/deps/std/type_name.js +19 -0
  41. package/dist/src/generated/waterx_account/deps/sui/balance.d.ts +10 -0
  42. package/dist/src/generated/waterx_account/deps/sui/balance.js +14 -0
  43. package/dist/src/generated/waterx_account/deps/sui/table.d.ts +24 -0
  44. package/dist/src/generated/waterx_account/deps/sui/table.js +31 -0
  45. package/dist/src/generated/waterx_account/deps/sui/vec_map.d.ts +36 -0
  46. package/dist/src/generated/waterx_account/deps/sui/vec_map.js +27 -0
  47. package/dist/src/generated/waterx_account/deps/sui/vec_set.d.ts +16 -0
  48. package/dist/src/generated/waterx_account/deps/sui/vec_set.js +19 -0
  49. package/dist/src/generated/waterx_account/direct_rule.d.ts +72 -0
  50. package/dist/src/generated/waterx_account/direct_rule.js +75 -0
  51. package/dist/src/generated/waterx_account/events.d.ts +30 -0
  52. package/dist/src/generated/waterx_account/events.js +145 -0
  53. package/dist/src/generated/waterx_account/version.d.ts +10 -0
  54. package/dist/src/generated/waterx_account/version.js +8 -0
  55. package/dist/src/generated/waterx_prediction/account_data.d.ts +321 -0
  56. package/dist/src/generated/waterx_prediction/account_data.js +399 -0
  57. package/dist/src/generated/waterx_prediction/admin.d.ts +5 -0
  58. package/dist/src/generated/waterx_prediction/admin.js +9 -0
  59. package/dist/src/generated/waterx_prediction/deps/bucket_v2_framework/linked_table.d.ts +8 -0
  60. package/dist/src/generated/waterx_prediction/deps/bucket_v2_framework/linked_table.js +18 -0
  61. package/dist/src/generated/waterx_prediction/deps/sui/balance.d.ts +10 -0
  62. package/dist/src/generated/waterx_prediction/deps/sui/balance.js +14 -0
  63. package/dist/src/generated/waterx_prediction/deps/sui/table.d.ts +24 -0
  64. package/dist/src/generated/waterx_prediction/deps/sui/table.js +31 -0
  65. package/dist/src/generated/waterx_prediction/deps/sui/vec_set.d.ts +16 -0
  66. package/dist/src/generated/waterx_prediction/deps/sui/vec_set.js +19 -0
  67. package/dist/src/generated/waterx_prediction/events.d.ts +19 -0
  68. package/dist/src/generated/waterx_prediction/events.js +99 -0
  69. package/dist/src/generated/waterx_prediction/global_config.d.ts +68 -0
  70. package/dist/src/generated/waterx_prediction/global_config.js +83 -0
  71. package/dist/src/generated/waterx_prediction/order.d.ts +170 -0
  72. package/dist/src/generated/waterx_prediction/order.js +237 -0
  73. package/dist/src/generated/waterx_prediction/outcome.d.ts +58 -0
  74. package/dist/src/generated/waterx_prediction/outcome.js +73 -0
  75. package/dist/src/generated/waterx_prediction/position.d.ts +150 -0
  76. package/dist/src/generated/waterx_prediction/position.js +200 -0
  77. package/dist/src/generated/waterx_prediction/view.d.ts +353 -0
  78. package/dist/src/generated/waterx_prediction/view.js +426 -0
  79. package/dist/src/generated/waterx_prediction/waterx_prediction.d.ts +1520 -0
  80. package/dist/src/generated/waterx_prediction/waterx_prediction.js +1550 -0
  81. package/dist/src/index.d.ts +22 -0
  82. package/dist/src/index.js +17 -0
  83. package/dist/src/prediction.d.ts +81 -0
  84. package/dist/src/prediction.js +220 -0
  85. package/dist/src/types.d.ts +81 -0
  86. package/dist/src/types.js +1 -0
  87. package/dist/src/user/account.d.ts +2 -0
  88. package/dist/src/user/account.js +1 -0
  89. package/dist/src/user/admin.d.ts +4 -0
  90. package/dist/src/user/admin.js +2 -0
  91. package/dist/src/user/index.d.ts +4 -0
  92. package/dist/src/user/index.js +2 -0
  93. package/dist/src/user/keeper.d.ts +2 -0
  94. package/dist/src/user/keeper.js +1 -0
  95. package/dist/src/user/order.d.ts +2 -0
  96. package/dist/src/user/order.js +1 -0
  97. package/dist/src/user/position.d.ts +2 -0
  98. package/dist/src/user/position.js +1 -0
  99. package/dist/src/utils/bcs.d.ts +1 -0
  100. package/dist/src/utils/bcs.js +1 -0
  101. package/dist/src/utils/index.d.ts +1 -0
  102. package/dist/src/utils/index.js +1 -0
  103. package/dist/src/utils.d.ts +29 -0
  104. package/dist/src/utils.js +170 -0
  105. package/package.json +62 -0
package/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 WaterX
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
package/README.md ADDED
@@ -0,0 +1,67 @@
1
+ # @waterx/predict-sdk
2
+
3
+ TypeScript SDK for `waterx_prediction`, the WaterX prediction market broker on Sui.
4
+
5
+ The package exposes:
6
+
7
+ - `PredictClient` for Sui gRPC, simulation, and execution.
8
+ - User PTB builders for `placeOrder`, `requestClose`, `claim`, and self-cancel paths.
9
+ - Keeper PTB builders for fill/cancel/close/resolve/force-claim paths.
10
+ - Admin PTB builders for registry setup, settlement funding, pause controls, and keeper management.
11
+ - Generated Move wrappers in `src/generated` via `pnpm codegen`.
12
+ - User-facing grouped exports under `src/user`.
13
+ - Shared argument/BCS helpers under `src/utils`.
14
+ - View helpers that read `waterx_prediction::view` via `simulateTransaction` and BCS parsing.
15
+
16
+ ```ts
17
+ import { PredictClient, placeOrder } from "@waterx/predict-sdk";
18
+ import { Transaction } from "@mysten/sui/transactions";
19
+
20
+ const client = PredictClient.testnet();
21
+
22
+ const tx = new Transaction();
23
+ placeOrder(client, tx, {
24
+ accountId: "0x...",
25
+ maxSpend: 100_000_000n,
26
+ marketId: "0x...",
27
+ selection: "YES",
28
+ minShares: 50_000_000n,
29
+ priceCapBps: 7_000n,
30
+ expiryTs: 9_999_999_999_999n,
31
+ });
32
+ ```
33
+
34
+ Testnet package, shared object, registry, and settlement coin defaults are wired from the WaterX config snapshot:
35
+ [`WaterXProtocol/waterx-config`](https://github.com/WaterXProtocol/waterx-config).
36
+ You can still override any ID when testing a new deployment:
37
+
38
+ ```ts
39
+ const client = PredictClient.testnet({
40
+ packageId: "0x...",
41
+ globalConfig: "0x...",
42
+ marketRegistry: "0x...",
43
+ accountRegistry: "0x...",
44
+ settlementCoinType: "0x...::coin::COIN",
45
+ });
46
+ ```
47
+
48
+ ## Input validation
49
+
50
+ - PTB helpers use strict literals for `Selection` / `Outcome` (`"YES"`, `"NO"`, `"INVALID"`). On-chain view decoding accepts Move enum casing (for example `"Yes"`).
51
+ - `normalizeMarketId()` is for PTB `vector<u8>` arguments. Strings starting with `0x` are parsed as hex; other strings are UTF-8. View decoding expects `Uint8Array` or `number[]` for `market_id`, not strings.
52
+ - `toBigInt()` rejects empty strings, non-integers, negatives, and values above `u64::MAX`.
53
+
54
+ ## Development
55
+
56
+ ```bash
57
+ pnpm codegen
58
+ pnpm typecheck
59
+ pnpm build
60
+ pnpm test:unit
61
+ ```
62
+
63
+ `pnpm codegen` regenerates `src/generated` from:
64
+
65
+ - `../waterx-contract/waterx_prediction`
66
+ - `../waterx-contract/waterx_account`
67
+ - `../waterx-contract/bucket_framework`
@@ -0,0 +1,64 @@
1
+ import { Transaction, type TransactionArgument } from "@mysten/sui/transactions";
2
+ import type { PredictClient } from "./client.ts";
3
+ import type { AccountIdentityParams, CoinRef, IdArgument, ObjectArgument } from "./types.ts";
4
+ export interface AccountBaseParams {
5
+ accountPackageId?: string;
6
+ accountRegistry?: string;
7
+ }
8
+ export interface CreateAccountParams extends AccountBaseParams, AccountIdentityParams {
9
+ alias: string;
10
+ }
11
+ export declare function createAccount(client: PredictClient, tx: Transaction, params: CreateAccountParams): TransactionArgument;
12
+ export interface TransferCoinToAccountParams extends AccountBaseParams {
13
+ accountId: IdArgument;
14
+ coin: ObjectArgument;
15
+ coinType?: string;
16
+ }
17
+ export declare function transferCoinToAccount(client: PredictClient, tx: Transaction, params: TransferCoinToAccountParams): Transaction;
18
+ export interface RequestDepositParams extends AccountBaseParams {
19
+ accountId: IdArgument;
20
+ coin: ObjectArgument;
21
+ coinType?: string;
22
+ extraData?: Uint8Array | number[];
23
+ }
24
+ export declare function requestDeposit(client: PredictClient, tx: Transaction, params: RequestDepositParams): TransactionArgument;
25
+ export interface RequestDepositFromReceivingsParams extends AccountBaseParams {
26
+ accountId: IdArgument;
27
+ coins: CoinRef[];
28
+ coinType?: string;
29
+ extraData?: Uint8Array | number[];
30
+ }
31
+ export declare function requestDepositFromReceivings(client: PredictClient, tx: Transaction, params: RequestDepositFromReceivingsParams): TransactionArgument;
32
+ export interface RequestWithdrawParams extends AccountBaseParams, AccountIdentityParams {
33
+ accountId: IdArgument;
34
+ amount: bigint | number | string;
35
+ recipient: string;
36
+ coinType?: string;
37
+ extraData?: Uint8Array | number[];
38
+ }
39
+ export declare function requestWithdraw(client: PredictClient, tx: Transaction, params: RequestWithdrawParams): TransactionArgument;
40
+ export interface AddDelegateParams extends AccountBaseParams, AccountIdentityParams {
41
+ accountId: IdArgument;
42
+ delegate: string;
43
+ alias: string;
44
+ permissions: number;
45
+ expiresAtMs?: bigint | number | string | null;
46
+ }
47
+ export declare function addDelegate(client: PredictClient, tx: Transaction, params: AddDelegateParams): Transaction;
48
+ export interface RemoveDelegateParams extends AccountBaseParams, AccountIdentityParams {
49
+ accountId: IdArgument;
50
+ delegate: string;
51
+ }
52
+ export declare function removeDelegate(client: PredictClient, tx: Transaction, params: RemoveDelegateParams): Transaction;
53
+ export interface SetDelegatePredictionPermissionParams extends AccountBaseParams, AccountIdentityParams {
54
+ accountId: IdArgument;
55
+ delegate: string;
56
+ permissions: number;
57
+ predictionPackageId?: string;
58
+ }
59
+ export declare function setDelegatePredictionPermission(client: PredictClient, tx: Transaction, params: SetDelegatePredictionPermissionParams): Transaction;
60
+ export interface WhitelistPredictionProtocolParams extends AccountBaseParams {
61
+ adminCap: ObjectArgument;
62
+ predictionPackageId?: string;
63
+ }
64
+ export declare function whitelistPredictionProtocol(client: PredictClient, tx: Transaction, params: WhitelistPredictionProtocolParams): Transaction;
@@ -0,0 +1,134 @@
1
+ import { clockArg, createAccountRequest, idArg, objectArg, receivingCoinArg, resolveAccountRegistry, resolvePackageId, toBigInt, } from "./utils.js";
2
+ function accountPackage(client, packageId) {
3
+ return packageId ?? client.config.waterxAccountPackageId;
4
+ }
5
+ export function createAccount(client, tx, params) {
6
+ const senderRequest = createAccountRequest(client, tx, params);
7
+ const [accountId] = tx.moveCall({
8
+ target: `${accountPackage(client, params.accountPackageId)}::account::create_account`,
9
+ arguments: [
10
+ tx.object(resolveAccountRegistry(client, params.accountRegistry)),
11
+ senderRequest,
12
+ tx.pure.string(params.alias),
13
+ ],
14
+ });
15
+ return accountId;
16
+ }
17
+ export function transferCoinToAccount(client, tx, params) {
18
+ tx.moveCall({
19
+ target: `${accountPackage(client, params.accountPackageId)}::account::transfer_coin`,
20
+ typeArguments: [params.coinType ?? client.config.settlementCoinType],
21
+ arguments: [
22
+ tx.object(resolveAccountRegistry(client, params.accountRegistry)),
23
+ idArg(tx, params.accountId),
24
+ objectArg(tx, params.coin),
25
+ ],
26
+ });
27
+ return tx;
28
+ }
29
+ export function requestDeposit(client, tx, params) {
30
+ const [request] = tx.moveCall({
31
+ target: `${accountPackage(client, params.accountPackageId)}::account::request_deposit`,
32
+ typeArguments: [params.coinType ?? client.config.settlementCoinType],
33
+ arguments: [
34
+ tx.object(resolveAccountRegistry(client, params.accountRegistry)),
35
+ idArg(tx, params.accountId),
36
+ objectArg(tx, params.coin),
37
+ tx.pure.vector("u8", Array.from(params.extraData ?? [])),
38
+ ],
39
+ });
40
+ return request;
41
+ }
42
+ export function requestDepositFromReceivings(client, tx, params) {
43
+ const coinType = params.coinType ?? client.config.settlementCoinType;
44
+ const receivings = params.coins.map((coin) => receivingCoinArg(tx, coin));
45
+ const [request] = tx.moveCall({
46
+ target: `${accountPackage(client, params.accountPackageId)}::account::request_deposit_from_receivings`,
47
+ typeArguments: [coinType],
48
+ arguments: [
49
+ tx.object(resolveAccountRegistry(client, params.accountRegistry)),
50
+ idArg(tx, params.accountId),
51
+ tx.makeMoveVec({
52
+ type: `0x2::transfer::Receiving<0x2::coin::Coin<${coinType}>>`,
53
+ elements: receivings,
54
+ }),
55
+ tx.pure.vector("u8", Array.from(params.extraData ?? [])),
56
+ ],
57
+ });
58
+ return request;
59
+ }
60
+ export function requestWithdraw(client, tx, params) {
61
+ const senderRequest = createAccountRequest(client, tx, params);
62
+ const [request] = tx.moveCall({
63
+ target: `${accountPackage(client, params.accountPackageId)}::account::request_withdraw`,
64
+ typeArguments: [params.coinType ?? client.config.settlementCoinType],
65
+ arguments: [
66
+ tx.object(resolveAccountRegistry(client, params.accountRegistry)),
67
+ senderRequest,
68
+ idArg(tx, params.accountId),
69
+ tx.pure.u64(toBigInt(params.amount)),
70
+ tx.pure.address(params.recipient),
71
+ tx.pure.vector("u8", Array.from(params.extraData ?? [])),
72
+ clockArg(tx),
73
+ ],
74
+ });
75
+ return request;
76
+ }
77
+ export function addDelegate(client, tx, params) {
78
+ const senderRequest = createAccountRequest(client, tx, params);
79
+ tx.moveCall({
80
+ target: `${accountPackage(client, params.accountPackageId)}::account::add_delegate`,
81
+ arguments: [
82
+ tx.object(resolveAccountRegistry(client, params.accountRegistry)),
83
+ senderRequest,
84
+ idArg(tx, params.accountId),
85
+ tx.pure.address(params.delegate),
86
+ tx.pure.string(params.alias),
87
+ tx.pure.u32(params.permissions),
88
+ tx.pure.option("u64", params.expiresAtMs == null ? null : toBigInt(params.expiresAtMs)),
89
+ clockArg(tx),
90
+ ],
91
+ });
92
+ return tx;
93
+ }
94
+ export function removeDelegate(client, tx, params) {
95
+ const senderRequest = createAccountRequest(client, tx, params);
96
+ tx.moveCall({
97
+ target: `${accountPackage(client, params.accountPackageId)}::account::remove_delegate`,
98
+ arguments: [
99
+ tx.object(resolveAccountRegistry(client, params.accountRegistry)),
100
+ senderRequest,
101
+ idArg(tx, params.accountId),
102
+ tx.pure.address(params.delegate),
103
+ clockArg(tx),
104
+ ],
105
+ });
106
+ return tx;
107
+ }
108
+ export function setDelegatePredictionPermission(client, tx, params) {
109
+ const senderRequest = createAccountRequest(client, tx, params);
110
+ tx.moveCall({
111
+ target: `${accountPackage(client, params.accountPackageId)}::account::set_delegate_protocol_permission`,
112
+ typeArguments: [`${resolvePackageId(client, params.predictionPackageId)}::account_data::WaterXPrediction`],
113
+ arguments: [
114
+ tx.object(resolveAccountRegistry(client, params.accountRegistry)),
115
+ senderRequest,
116
+ idArg(tx, params.accountId),
117
+ tx.pure.address(params.delegate),
118
+ tx.pure.u32(params.permissions),
119
+ clockArg(tx),
120
+ ],
121
+ });
122
+ return tx;
123
+ }
124
+ export function whitelistPredictionProtocol(client, tx, params) {
125
+ tx.moveCall({
126
+ target: `${accountPackage(client, params.accountPackageId)}::account::whitelist_protocol`,
127
+ typeArguments: [`${resolvePackageId(client, params.predictionPackageId)}::account_data::WaterXPrediction`],
128
+ arguments: [
129
+ tx.object(resolveAccountRegistry(client, params.accountRegistry)),
130
+ objectArg(tx, params.adminCap),
131
+ ],
132
+ });
133
+ return tx;
134
+ }
@@ -0,0 +1,47 @@
1
+ import { Transaction } from "@mysten/sui/transactions";
2
+ import type { PredictClient } from "./client.ts";
3
+ import type { MarketIdInput, ObjectArgument } from "./types.ts";
4
+ export interface AdminBaseParams {
5
+ packageId?: string;
6
+ marketRegistry?: string;
7
+ settlementCoinType?: string;
8
+ }
9
+ export interface CreateMarketRegistryParams extends AdminBaseParams {
10
+ adminCap: ObjectArgument;
11
+ }
12
+ export declare function createMarketRegistry(client: PredictClient, tx: Transaction, params: CreateMarketRegistryParams): Transaction;
13
+ export interface DepositSettlementParams extends AdminBaseParams {
14
+ adminCap: ObjectArgument;
15
+ payment: ObjectArgument;
16
+ }
17
+ export declare function depositSettlement(client: PredictClient, tx: Transaction, params: DepositSettlementParams): Transaction;
18
+ export interface AdminWithdrawParams extends AdminBaseParams {
19
+ adminCap: ObjectArgument;
20
+ amount: bigint | number | string;
21
+ recipient: string;
22
+ }
23
+ export declare function adminWithdraw(client: PredictClient, tx: Transaction, params: AdminWithdrawParams): Transaction;
24
+ export interface SetMinReserveParams extends AdminBaseParams {
25
+ adminCap: ObjectArgument;
26
+ newReserve: bigint | number | string;
27
+ }
28
+ export declare function setMinReserve(client: PredictClient, tx: Transaction, params: SetMinReserveParams): Transaction;
29
+ export interface SetOrderCancelCooldownParams extends AdminBaseParams {
30
+ adminCap: ObjectArgument;
31
+ cooldownMs: bigint | number | string;
32
+ }
33
+ export declare function setOrderCancelCooldownMs(client: PredictClient, tx: Transaction, params: SetOrderCancelCooldownParams): Transaction;
34
+ export interface MarketPauseParams extends AdminBaseParams {
35
+ adminCap: ObjectArgument;
36
+ marketId: MarketIdInput;
37
+ }
38
+ export declare function pauseMarket(client: PredictClient, tx: Transaction, params: MarketPauseParams): Transaction;
39
+ export declare function unpauseMarket(client: PredictClient, tx: Transaction, params: MarketPauseParams): Transaction;
40
+ export interface KeeperAdminParams {
41
+ packageId?: string;
42
+ globalConfig?: string;
43
+ adminCap: ObjectArgument;
44
+ keeper: string;
45
+ }
46
+ export declare function addKeeper(client: PredictClient, tx: Transaction, params: KeeperAdminParams): Transaction;
47
+ export declare function removeKeeper(client: PredictClient, tx: Transaction, params: KeeperAdminParams): Transaction;
@@ -0,0 +1,104 @@
1
+ import { marketIdArg, objectArg, resolveGlobalConfig, resolveMarketRegistry, resolvePackageId, resolveSettlementCoinType, toBigInt, } from "./utils.js";
2
+ export function createMarketRegistry(client, tx, params) {
3
+ tx.moveCall({
4
+ target: `${resolvePackageId(client, params.packageId)}::waterx_prediction::create_market_registry`,
5
+ typeArguments: [resolveSettlementCoinType(client, params.settlementCoinType)],
6
+ arguments: [objectArg(tx, params.adminCap)],
7
+ });
8
+ return tx;
9
+ }
10
+ export function depositSettlement(client, tx, params) {
11
+ tx.moveCall({
12
+ target: `${resolvePackageId(client, params.packageId)}::waterx_prediction::deposit_settlement`,
13
+ typeArguments: [resolveSettlementCoinType(client, params.settlementCoinType)],
14
+ arguments: [
15
+ objectArg(tx, params.adminCap),
16
+ tx.object(resolveMarketRegistry(client, params.marketRegistry)),
17
+ objectArg(tx, params.payment),
18
+ ],
19
+ });
20
+ return tx;
21
+ }
22
+ export function adminWithdraw(client, tx, params) {
23
+ tx.moveCall({
24
+ target: `${resolvePackageId(client, params.packageId)}::waterx_prediction::admin_withdraw`,
25
+ typeArguments: [resolveSettlementCoinType(client, params.settlementCoinType)],
26
+ arguments: [
27
+ objectArg(tx, params.adminCap),
28
+ tx.object(resolveMarketRegistry(client, params.marketRegistry)),
29
+ tx.pure.u64(toBigInt(params.amount)),
30
+ tx.pure.address(params.recipient),
31
+ ],
32
+ });
33
+ return tx;
34
+ }
35
+ export function setMinReserve(client, tx, params) {
36
+ tx.moveCall({
37
+ target: `${resolvePackageId(client, params.packageId)}::waterx_prediction::set_min_reserve`,
38
+ typeArguments: [resolveSettlementCoinType(client, params.settlementCoinType)],
39
+ arguments: [
40
+ objectArg(tx, params.adminCap),
41
+ tx.object(resolveMarketRegistry(client, params.marketRegistry)),
42
+ tx.pure.u64(toBigInt(params.newReserve)),
43
+ ],
44
+ });
45
+ return tx;
46
+ }
47
+ export function setOrderCancelCooldownMs(client, tx, params) {
48
+ tx.moveCall({
49
+ target: `${resolvePackageId(client, params.packageId)}::waterx_prediction::set_order_cancel_cooldown_ms`,
50
+ typeArguments: [resolveSettlementCoinType(client, params.settlementCoinType)],
51
+ arguments: [
52
+ objectArg(tx, params.adminCap),
53
+ tx.object(resolveMarketRegistry(client, params.marketRegistry)),
54
+ tx.pure.u64(toBigInt(params.cooldownMs)),
55
+ ],
56
+ });
57
+ return tx;
58
+ }
59
+ export function pauseMarket(client, tx, params) {
60
+ tx.moveCall({
61
+ target: `${resolvePackageId(client, params.packageId)}::waterx_prediction::pause_market`,
62
+ typeArguments: [resolveSettlementCoinType(client, params.settlementCoinType)],
63
+ arguments: [
64
+ objectArg(tx, params.adminCap),
65
+ tx.object(resolveMarketRegistry(client, params.marketRegistry)),
66
+ marketIdArg(tx, params.marketId),
67
+ ],
68
+ });
69
+ return tx;
70
+ }
71
+ export function unpauseMarket(client, tx, params) {
72
+ tx.moveCall({
73
+ target: `${resolvePackageId(client, params.packageId)}::waterx_prediction::unpause_market`,
74
+ typeArguments: [resolveSettlementCoinType(client, params.settlementCoinType)],
75
+ arguments: [
76
+ objectArg(tx, params.adminCap),
77
+ tx.object(resolveMarketRegistry(client, params.marketRegistry)),
78
+ marketIdArg(tx, params.marketId),
79
+ ],
80
+ });
81
+ return tx;
82
+ }
83
+ export function addKeeper(client, tx, params) {
84
+ tx.moveCall({
85
+ target: `${resolvePackageId(client, params.packageId)}::global_config::add_keeper`,
86
+ arguments: [
87
+ tx.object(resolveGlobalConfig(client, params.globalConfig)),
88
+ objectArg(tx, params.adminCap),
89
+ tx.pure.address(params.keeper),
90
+ ],
91
+ });
92
+ return tx;
93
+ }
94
+ export function removeKeeper(client, tx, params) {
95
+ tx.moveCall({
96
+ target: `${resolvePackageId(client, params.packageId)}::global_config::remove_keeper`,
97
+ arguments: [
98
+ tx.object(resolveGlobalConfig(client, params.globalConfig)),
99
+ objectArg(tx, params.adminCap),
100
+ tx.pure.address(params.keeper),
101
+ ],
102
+ });
103
+ return tx;
104
+ }
@@ -0,0 +1,20 @@
1
+ import type { AccountDataView, CursorView, 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;
11
+ export declare function mapSelection(raw: unknown): Selection;
12
+ export declare function mapOutcome(raw: unknown): Outcome;
13
+ export declare function mapOrderKind(raw: unknown): OrderKind;
14
+ export declare function mapStatus(raw: unknown): PositionStatus;
15
+ export declare function mapRegistryView(raw: any): RegistryView;
16
+ export declare function mapOrderView(raw: any): OrderView;
17
+ export declare function mapPositionView(raw: any): PositionView;
18
+ export declare function mapMarketView(raw: any): MarketView;
19
+ export declare function mapAccountDataView(raw: any): AccountDataView;
20
+ export declare function mapCursorView(count: unknown, front: unknown, back: unknown): CursorView;
@@ -0,0 +1,209 @@
1
+ import { bcs } from "@mysten/sui/bcs";
2
+ 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
+ by_admin: bcs.bool(),
44
+ });
45
+ export const PositionViewBcs = bcs.struct("PositionView", {
46
+ position_id: bcs.u64(),
47
+ account_id: bcs.Address,
48
+ market_id: bcs.vector(bcs.u8()),
49
+ selection: SelectionBcs,
50
+ status: StatusBcs,
51
+ filled_shares: bcs.u64(),
52
+ filled_cost: bcs.u64(),
53
+ payout: bcs.u64(),
54
+ close_order_id: bcs.option(bcs.u64()),
55
+ close_min_proceeds: bcs.u64(),
56
+ close_expiry_ts: bcs.u64(),
57
+ close_self_cancel_after_ts: bcs.u64(),
58
+ });
59
+ export const MarketViewBcs = bcs.struct("MarketView", {
60
+ market_key: bcs.u64(),
61
+ market_id: bcs.vector(bcs.u8()),
62
+ resolved: bcs.bool(),
63
+ paused: bcs.bool(),
64
+ outcome: bcs.option(OutcomeBcs),
65
+ unclaimed_count: bcs.u64(),
66
+ });
67
+ export const AccountDataViewBcs = bcs.struct("AccountDataView", {
68
+ account_id: bcs.Address,
69
+ has_data: bcs.bool(),
70
+ order_count: bcs.u64(),
71
+ position_count: bcs.u64(),
72
+ order_front: bcs.option(bcs.u64()),
73
+ order_back: bcs.option(bcs.u64()),
74
+ position_front: bcs.option(bcs.u64()),
75
+ position_back: bcs.option(bcs.u64()),
76
+ });
77
+ function enumKind(raw) {
78
+ if (typeof raw === "string")
79
+ return raw;
80
+ if (raw && typeof raw === "object") {
81
+ const record = raw;
82
+ if (typeof record.$kind === "string")
83
+ return record.$kind;
84
+ const key = Object.keys(record).find((k) => k !== "$kind");
85
+ if (key)
86
+ return key;
87
+ }
88
+ throw new Error(`Unable to decode enum variant: ${JSON.stringify(raw)}`);
89
+ }
90
+ export function mapSelection(raw) {
91
+ const kind = enumKind(raw).toLowerCase();
92
+ if (kind === "yes")
93
+ return "YES";
94
+ if (kind === "no")
95
+ return "NO";
96
+ throw new Error(`Unknown Selection variant: ${kind}`);
97
+ }
98
+ export function mapOutcome(raw) {
99
+ const kind = enumKind(raw).toLowerCase();
100
+ if (kind === "yes")
101
+ return "YES";
102
+ if (kind === "no")
103
+ return "NO";
104
+ if (kind === "invalid")
105
+ return "INVALID";
106
+ throw new Error(`Unknown Outcome variant: ${kind}`);
107
+ }
108
+ export function mapOrderKind(raw) {
109
+ const kind = enumKind(raw).toLowerCase();
110
+ if (kind === "open")
111
+ return "OPEN";
112
+ if (kind === "close")
113
+ return "CLOSE";
114
+ throw new Error(`Unknown OrderKind variant: ${kind}`);
115
+ }
116
+ export function mapStatus(raw) {
117
+ const kind = enumKind(raw).toLowerCase();
118
+ if (kind === "open")
119
+ return "OPEN";
120
+ if (kind === "pendingclose" || kind === "pending_close")
121
+ return "PENDING_CLOSE";
122
+ throw new Error(`Unknown Status variant: ${kind}`);
123
+ }
124
+ function mapOptionalU64(raw) {
125
+ return raw == null ? null : BigInt(raw);
126
+ }
127
+ function asBytes(raw) {
128
+ return marketIdBytesFromUnknown(raw);
129
+ }
130
+ export function mapRegistryView(raw) {
131
+ return {
132
+ balance: BigInt(raw.balance),
133
+ minReserve: BigInt(raw.min_reserve),
134
+ orderCancelCooldownMs: BigInt(raw.order_cancel_cooldown_ms),
135
+ nextOrderId: BigInt(raw.next_order_id),
136
+ orderCount: BigInt(raw.order_count),
137
+ positionCount: BigInt(raw.position_count),
138
+ unresolvedMarketCount: BigInt(raw.unresolved_market_count),
139
+ resolvedMarketCount: BigInt(raw.resolved_market_count),
140
+ };
141
+ }
142
+ export function mapOrderView(raw) {
143
+ const marketId = asBytes(raw.market_id);
144
+ return {
145
+ orderId: BigInt(raw.order_id),
146
+ kind: mapOrderKind(raw.kind),
147
+ accountId: raw.account_id,
148
+ marketId,
149
+ marketIdHex: bytesToHex(marketId),
150
+ selection: mapSelection(raw.selection),
151
+ positionId: mapOptionalU64(raw.position_id),
152
+ maxSpend: BigInt(raw.max_spend),
153
+ minShares: BigInt(raw.min_shares),
154
+ priceCapBps: BigInt(raw.price_cap),
155
+ minProceeds: BigInt(raw.min_proceeds),
156
+ expiryTs: BigInt(raw.expiry_ts),
157
+ selfCancelAfterTs: BigInt(raw.self_cancel_after_ts),
158
+ byAdmin: raw.by_admin,
159
+ };
160
+ }
161
+ export function mapPositionView(raw) {
162
+ const marketId = asBytes(raw.market_id);
163
+ return {
164
+ positionId: BigInt(raw.position_id),
165
+ accountId: raw.account_id,
166
+ marketId,
167
+ marketIdHex: bytesToHex(marketId),
168
+ selection: mapSelection(raw.selection),
169
+ status: mapStatus(raw.status),
170
+ filledShares: BigInt(raw.filled_shares),
171
+ filledCost: BigInt(raw.filled_cost),
172
+ payout: BigInt(raw.payout),
173
+ closeOrderId: mapOptionalU64(raw.close_order_id),
174
+ closeMinProceeds: BigInt(raw.close_min_proceeds),
175
+ closeExpiryTs: BigInt(raw.close_expiry_ts),
176
+ closeSelfCancelAfterTs: BigInt(raw.close_self_cancel_after_ts),
177
+ };
178
+ }
179
+ export function mapMarketView(raw) {
180
+ const marketId = asBytes(raw.market_id);
181
+ return {
182
+ marketKey: BigInt(raw.market_key),
183
+ marketId,
184
+ marketIdHex: bytesToHex(marketId),
185
+ resolved: raw.resolved,
186
+ paused: raw.paused,
187
+ outcome: raw.outcome == null ? null : mapOutcome(raw.outcome),
188
+ unclaimedCount: BigInt(raw.unclaimed_count),
189
+ };
190
+ }
191
+ export function mapAccountDataView(raw) {
192
+ return {
193
+ accountId: raw.account_id,
194
+ hasData: raw.has_data,
195
+ orderCount: BigInt(raw.order_count),
196
+ positionCount: BigInt(raw.position_count),
197
+ orderFront: mapOptionalU64(raw.order_front),
198
+ orderBack: mapOptionalU64(raw.order_back),
199
+ positionFront: mapOptionalU64(raw.position_front),
200
+ positionBack: mapOptionalU64(raw.position_back),
201
+ };
202
+ }
203
+ export function mapCursorView(count, front, back) {
204
+ return {
205
+ count: BigInt(count),
206
+ front: mapOptionalU64(front),
207
+ back: mapOptionalU64(back),
208
+ };
209
+ }