@obelyzk/sdk 0.5.0 → 1.0.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.
@@ -29,14 +29,20 @@ __export(obelysk_exports, {
29
29
  GENERATOR_H: () => GENERATOR_H,
30
30
  MAINNET_PRIVACY_POOLS: () => MAINNET_PRIVACY_POOLS,
31
31
  MAINNET_TOKENS: () => MAINNET_TOKENS,
32
+ OTCOrderbookClient: () => OTCOrderbookClient,
32
33
  ObelyskClient: () => ObelyskClient,
33
34
  ObelyskPrivacy: () => ObelyskPrivacy,
35
+ OrderSide: () => OrderSide,
36
+ OrderStatus: () => OrderStatus,
37
+ OrderType: () => OrderType,
34
38
  PrivacyPoolClient: () => PrivacyPoolClient,
35
39
  PrivacyRouterClient: () => PrivacyRouterClient,
36
40
  ProverStakingClient: () => ProverStakingClient,
37
41
  ShieldedSwapClient: () => ShieldedSwapClient,
38
42
  StealthClient: () => StealthClient,
39
43
  TOKEN_DECIMALS: () => TOKEN_DECIMALS,
44
+ VM31BridgeClient: () => VM31BridgeClient,
45
+ VM31VaultClient: () => VM31VaultClient,
40
46
  VM31_ASSET_IDS: () => VM31_ASSET_IDS,
41
47
  commitmentToHash: () => commitmentToHash,
42
48
  createAEHint: () => createAEHint,
@@ -996,6 +1002,124 @@ var DarkPoolClient = class {
996
1002
  await this.obelysk.provider.waitForTransaction(result.transaction_hash);
997
1003
  return { txHash: result.transaction_hash };
998
1004
  }
1005
+ /** Cancel an order before reveal. */
1006
+ async cancelOrder(orderId) {
1007
+ const account = this.obelysk.requireAccount();
1008
+ const low = (orderId & (1n << 128n) - 1n).toString();
1009
+ const high = (orderId >> 128n).toString();
1010
+ const result = await account.execute([{
1011
+ contractAddress: this.darkPoolAddress,
1012
+ entrypoint: "cancel_order",
1013
+ calldata: [low, high]
1014
+ }]);
1015
+ return result.transaction_hash;
1016
+ }
1017
+ /** Claim fills after epoch settlement. */
1018
+ async claimFill(params) {
1019
+ const account = this.obelysk.requireAccount();
1020
+ const oLow = (params.orderId & (1n << 128n) - 1n).toString();
1021
+ const oHigh = (params.orderId >> 128n).toString();
1022
+ const result = await account.execute([{
1023
+ contractAddress: this.darkPoolAddress,
1024
+ entrypoint: "claim_fill",
1025
+ calldata: [
1026
+ oLow,
1027
+ oHigh,
1028
+ params.receiveCipher.c1.x.toString(),
1029
+ params.receiveCipher.c1.y.toString(),
1030
+ params.receiveCipher.c2.x.toString(),
1031
+ params.receiveCipher.c2.y.toString(),
1032
+ params.receiveHint.toString(),
1033
+ params.receiveProof.commitment.toString(),
1034
+ params.receiveProof.challenge.toString(),
1035
+ params.receiveProof.response.toString(),
1036
+ params.spendCipher.c1.x.toString(),
1037
+ params.spendCipher.c1.y.toString(),
1038
+ params.spendCipher.c2.x.toString(),
1039
+ params.spendCipher.c2.y.toString(),
1040
+ params.spendHint.toString(),
1041
+ params.spendProof.commitment.toString(),
1042
+ params.spendProof.challenge.toString(),
1043
+ params.spendProof.response.toString()
1044
+ ]
1045
+ }]);
1046
+ return result.transaction_hash;
1047
+ }
1048
+ /** Register your ElGamal public key with the DarkPool. */
1049
+ async registerPubkey(pubkey) {
1050
+ const account = this.obelysk.requireAccount();
1051
+ const result = await account.execute([{
1052
+ contractAddress: this.darkPoolAddress,
1053
+ entrypoint: "register_pubkey",
1054
+ calldata: [pubkey.x.toString(), pubkey.y.toString()]
1055
+ }]);
1056
+ return result.transaction_hash;
1057
+ }
1058
+ /** Get the result of a settled epoch. */
1059
+ async getEpochResult(epochId) {
1060
+ try {
1061
+ const result = await this.obelysk.provider.callContract({
1062
+ contractAddress: this.darkPoolAddress,
1063
+ entrypoint: "get_epoch_result",
1064
+ calldata: [epochId.toString()]
1065
+ });
1066
+ if (result.length < 2) return null;
1067
+ const settled = BigInt(result[0]) !== 0n;
1068
+ const priceCount = Number(BigInt(result[1]));
1069
+ const clearingPrices = result.slice(2, 2 + priceCount);
1070
+ return { settled, clearingPrices };
1071
+ } catch {
1072
+ return null;
1073
+ }
1074
+ }
1075
+ /** Check if an order has been claimed. */
1076
+ async isOrderClaimed(orderId) {
1077
+ try {
1078
+ const low = (orderId & (1n << 128n) - 1n).toString();
1079
+ const high = (orderId >> 128n).toString();
1080
+ const result = await this.obelysk.provider.callContract({
1081
+ contractAddress: this.darkPoolAddress,
1082
+ entrypoint: "is_order_claimed",
1083
+ calldata: [low, high]
1084
+ });
1085
+ return BigInt(result[0]) !== 0n;
1086
+ } catch {
1087
+ return false;
1088
+ }
1089
+ }
1090
+ /** Get a trader's registered public key. */
1091
+ async getTraderPubkey(address) {
1092
+ try {
1093
+ const result = await this.obelysk.provider.callContract({
1094
+ contractAddress: this.darkPoolAddress,
1095
+ entrypoint: "get_trader_pubkey",
1096
+ calldata: [address]
1097
+ });
1098
+ const x = BigInt(result[0]);
1099
+ const y = BigInt(result[1]);
1100
+ if (x === 0n && y === 0n) return null;
1101
+ return { x, y };
1102
+ } catch {
1103
+ return null;
1104
+ }
1105
+ }
1106
+ /** Get encrypted balance for a trader and asset. */
1107
+ async getEncryptedBalance(address, assetId) {
1108
+ try {
1109
+ const result = await this.obelysk.provider.callContract({
1110
+ contractAddress: this.darkPoolAddress,
1111
+ entrypoint: "get_encrypted_balance",
1112
+ calldata: [address, assetId]
1113
+ });
1114
+ if (result.length < 4) return null;
1115
+ return {
1116
+ c1: { x: BigInt(result[0]), y: BigInt(result[1]) },
1117
+ c2: { x: BigInt(result[2]), y: BigInt(result[3]) }
1118
+ };
1119
+ } catch {
1120
+ return null;
1121
+ }
1122
+ }
999
1123
  };
1000
1124
 
1001
1125
  // src/obelysk/stealth.ts
@@ -1155,6 +1279,102 @@ var StealthClient = class {
1155
1279
  await this.obelysk.provider.waitForTransaction(result.transaction_hash);
1156
1280
  return { txHash: result.transaction_hash };
1157
1281
  }
1282
+ /** Claim a stealth payment. */
1283
+ async claim(params) {
1284
+ const account = this.obelysk.requireAccount();
1285
+ const p = params.spendingProof;
1286
+ const result = await account.execute([{
1287
+ contractAddress: this.registryAddress,
1288
+ entrypoint: "claim_stealth_payment",
1289
+ calldata: [
1290
+ params.announcementIndex.toString(),
1291
+ p.commitment.toString(),
1292
+ p.challenge.toString(),
1293
+ p.response.toString(),
1294
+ p.stealthPubkey.x.toString(),
1295
+ p.stealthPubkey.y.toString(),
1296
+ params.recipient
1297
+ ]
1298
+ }]);
1299
+ return result.transaction_hash;
1300
+ }
1301
+ /** Batch claim multiple stealth payments. */
1302
+ async batchClaim(params) {
1303
+ const account = this.obelysk.requireAccount();
1304
+ const calldata = [
1305
+ params.announcementIndices.length.toString(),
1306
+ ...params.announcementIndices.map((i) => i.toString()),
1307
+ params.spendingProofs.length.toString(),
1308
+ ...params.spendingProofs.flatMap((p) => [
1309
+ p.commitment.toString(),
1310
+ p.challenge.toString(),
1311
+ p.response.toString(),
1312
+ p.stealthPubkey.x.toString(),
1313
+ p.stealthPubkey.y.toString()
1314
+ ]),
1315
+ params.recipient
1316
+ ];
1317
+ const result = await account.execute([{
1318
+ contractAddress: this.registryAddress,
1319
+ entrypoint: "batch_claim_stealth_payments",
1320
+ calldata
1321
+ }]);
1322
+ return result.transaction_hash;
1323
+ }
1324
+ /** Update your stealth meta-address. */
1325
+ async updateMetaAddress(spendPubKey, viewPubKey) {
1326
+ const account = this.obelysk.requireAccount();
1327
+ const result = await account.execute([{
1328
+ contractAddress: this.registryAddress,
1329
+ entrypoint: "update_meta_address",
1330
+ calldata: [spendPubKey.x.toString(), spendPubKey.y.toString(), viewPubKey.x.toString(), viewPubKey.y.toString()]
1331
+ }]);
1332
+ return result.transaction_hash;
1333
+ }
1334
+ /** Get a specific announcement by index. */
1335
+ async getAnnouncement(index) {
1336
+ try {
1337
+ const result = await this.obelysk.provider.callContract({
1338
+ contractAddress: this.registryAddress,
1339
+ entrypoint: "get_announcement",
1340
+ calldata: [index.toString()]
1341
+ });
1342
+ return {
1343
+ ephemeralPubkey: { x: BigInt(result[0]), y: BigInt(result[1]) },
1344
+ stealthAddress: result[2],
1345
+ viewTag: result[3],
1346
+ token: result[4],
1347
+ amount: BigInt(result[5])
1348
+ };
1349
+ } catch {
1350
+ return null;
1351
+ }
1352
+ }
1353
+ /** Get announcements in a range. */
1354
+ async getAnnouncementsRange(start, end) {
1355
+ try {
1356
+ const result = await this.obelysk.provider.callContract({
1357
+ contractAddress: this.registryAddress,
1358
+ entrypoint: "get_announcements_range",
1359
+ calldata: [start.toString(), end.toString()]
1360
+ });
1361
+ const count = Number(BigInt(result[0]));
1362
+ const items = [];
1363
+ for (let i = 0; i < count; i++) {
1364
+ const base = 1 + i * 6;
1365
+ items.push({
1366
+ ephemeralPubkey: { x: BigInt(result[base]), y: BigInt(result[base + 1]) },
1367
+ stealthAddress: result[base + 2],
1368
+ viewTag: result[base + 3],
1369
+ token: result[base + 4],
1370
+ amount: BigInt(result[base + 5])
1371
+ });
1372
+ }
1373
+ return items;
1374
+ } catch {
1375
+ return [];
1376
+ }
1377
+ }
1158
1378
  };
1159
1379
 
1160
1380
  // src/obelysk/confidentialTransfer.ts
@@ -1247,6 +1467,78 @@ var ConfidentialTransferClient = class {
1247
1467
  return null;
1248
1468
  }
1249
1469
  }
1470
+ /** Register an ElGamal public key for confidential transfers. */
1471
+ async register(publicKey) {
1472
+ const account = this.obelysk.requireAccount();
1473
+ const result = await account.execute([{
1474
+ contractAddress: this.contractAddress,
1475
+ entrypoint: "register",
1476
+ calldata: [publicKey.x.toString(), publicKey.y.toString()]
1477
+ }]);
1478
+ return result.transaction_hash;
1479
+ }
1480
+ /** Fund: deposit public tokens into encrypted balance. */
1481
+ async fund(params) {
1482
+ const account = this.obelysk.requireAccount();
1483
+ const low = (params.amount & (1n << 128n) - 1n).toString();
1484
+ const high = (params.amount >> 128n).toString();
1485
+ const result = await account.execute([{
1486
+ contractAddress: this.contractAddress,
1487
+ entrypoint: "fund",
1488
+ calldata: [params.assetId.toString(), low, high, params.encryptionRandomness.toString(), params.aeHint.toString()]
1489
+ }]);
1490
+ return result.transaction_hash;
1491
+ }
1492
+ /** Fund another account's encrypted balance. */
1493
+ async fundFor(params) {
1494
+ const signer = this.obelysk.requireAccount();
1495
+ const low = (params.amount & (1n << 128n) - 1n).toString();
1496
+ const high = (params.amount >> 128n).toString();
1497
+ const result = await signer.execute([{
1498
+ contractAddress: this.contractAddress,
1499
+ entrypoint: "fund_for",
1500
+ calldata: [params.account, params.assetId.toString(), low, high, params.encryptionRandomness.toString(), params.aeHint.toString()]
1501
+ }]);
1502
+ return result.transaction_hash;
1503
+ }
1504
+ /** Rollover: claim pending incoming transfers into your balance. */
1505
+ async rollover(assetId) {
1506
+ const account = this.obelysk.requireAccount();
1507
+ const result = await account.execute([{
1508
+ contractAddress: this.contractAddress,
1509
+ entrypoint: "rollover",
1510
+ calldata: [assetId.toString()]
1511
+ }]);
1512
+ return result.transaction_hash;
1513
+ }
1514
+ /** Withdraw: convert encrypted balance back to public tokens. */
1515
+ async withdraw(params) {
1516
+ const account = this.obelysk.requireAccount();
1517
+ const low = (params.amount & (1n << 128n) - 1n).toString();
1518
+ const high = (params.amount >> 128n).toString();
1519
+ const result = await account.execute([{
1520
+ contractAddress: this.contractAddress,
1521
+ entrypoint: "withdraw",
1522
+ calldata: [params.to, params.assetId.toString(), low, high, params.proof.commitment.toString(), params.proof.challenge.toString(), params.proof.response.toString()]
1523
+ }]);
1524
+ return result.transaction_hash;
1525
+ }
1526
+ /** Get a registered public key. */
1527
+ async getPublicKey(address) {
1528
+ try {
1529
+ const result = await this.obelysk.provider.callContract({
1530
+ contractAddress: this.contractAddress,
1531
+ entrypoint: "get_public_key",
1532
+ calldata: [address]
1533
+ });
1534
+ const x = BigInt(result[0]);
1535
+ const y = BigInt(result[1]);
1536
+ if (x === 0n && y === 0n) return null;
1537
+ return { x, y };
1538
+ } catch {
1539
+ return null;
1540
+ }
1541
+ }
1250
1542
  };
1251
1543
 
1252
1544
  // src/obelysk/proverStaking.ts
@@ -1591,6 +1883,133 @@ var PrivacyRouterClient = class {
1591
1883
  });
1592
1884
  return Number(BigInt(result[0]));
1593
1885
  }
1886
+ /** Register an account with the privacy router. */
1887
+ async registerAccount(publicKey) {
1888
+ const account = this.obelysk.requireAccount();
1889
+ const result = await account.execute([{
1890
+ contractAddress: this.contractAddress,
1891
+ entrypoint: "register_account",
1892
+ calldata: [publicKey.x.toString(), publicKey.y.toString()]
1893
+ }]);
1894
+ return result.transaction_hash;
1895
+ }
1896
+ /** Deposit tokens into encrypted balance. */
1897
+ async deposit(params) {
1898
+ const account = this.obelysk.requireAccount();
1899
+ const low = (params.amount & (1n << 128n) - 1n).toString();
1900
+ const high = (params.amount >> 128n).toString();
1901
+ const result = await account.execute([{
1902
+ contractAddress: this.contractAddress,
1903
+ entrypoint: "deposit",
1904
+ calldata: [
1905
+ low,
1906
+ high,
1907
+ params.encryptedAmount.c1.x.toString(),
1908
+ params.encryptedAmount.c1.y.toString(),
1909
+ params.encryptedAmount.c2.x.toString(),
1910
+ params.encryptedAmount.c2.y.toString(),
1911
+ params.proof.commitment.toString(),
1912
+ params.proof.challenge.toString(),
1913
+ params.proof.response.toString()
1914
+ ]
1915
+ }]);
1916
+ return result.transaction_hash;
1917
+ }
1918
+ /** Withdraw from encrypted balance to public. */
1919
+ async withdraw(params) {
1920
+ const account = this.obelysk.requireAccount();
1921
+ const low = (params.amount & (1n << 128n) - 1n).toString();
1922
+ const high = (params.amount >> 128n).toString();
1923
+ const calldata = [
1924
+ low,
1925
+ high,
1926
+ params.encryptedDelta.c1.x.toString(),
1927
+ params.encryptedDelta.c1.y.toString(),
1928
+ params.encryptedDelta.c2.x.toString(),
1929
+ params.encryptedDelta.c2.y.toString(),
1930
+ params.proof.commitment.toString(),
1931
+ params.proof.challenge.toString(),
1932
+ params.proof.response.toString()
1933
+ ];
1934
+ if (params.rangeProofData) calldata.push(...params.rangeProofData);
1935
+ const result = await account.execute([{
1936
+ contractAddress: this.contractAddress,
1937
+ entrypoint: "withdraw",
1938
+ calldata
1939
+ }]);
1940
+ return result.transaction_hash;
1941
+ }
1942
+ /** Private transfer between accounts. */
1943
+ async privateTransfer(params) {
1944
+ const account = this.obelysk.requireAccount();
1945
+ const result = await account.execute([{
1946
+ contractAddress: this.contractAddress,
1947
+ entrypoint: "private_transfer",
1948
+ calldata: [
1949
+ params.to,
1950
+ params.senderCipher.c1.x.toString(),
1951
+ params.senderCipher.c1.y.toString(),
1952
+ params.senderCipher.c2.x.toString(),
1953
+ params.senderCipher.c2.y.toString(),
1954
+ params.receiverCipher.c1.x.toString(),
1955
+ params.receiverCipher.c1.y.toString(),
1956
+ params.receiverCipher.c2.x.toString(),
1957
+ params.receiverCipher.c2.y.toString(),
1958
+ params.proof.commitment.toString(),
1959
+ params.proof.challenge.toString(),
1960
+ params.proof.response.toString(),
1961
+ params.senderAeHint.toString(),
1962
+ params.receiverAeHint.toString()
1963
+ ]
1964
+ }]);
1965
+ return result.transaction_hash;
1966
+ }
1967
+ /** Request disclosure of a nullifier (audit). */
1968
+ async requestDisclosure(nullifier, reason) {
1969
+ const account = this.obelysk.requireAccount();
1970
+ const result = await account.execute([{
1971
+ contractAddress: this.contractAddress,
1972
+ entrypoint: "request_disclosure",
1973
+ calldata: [nullifier, reason]
1974
+ }]);
1975
+ return result.transaction_hash;
1976
+ }
1977
+ /** Ragequit: emergency withdrawal with proof. */
1978
+ async ragequit(proof) {
1979
+ const account = this.obelysk.requireAccount();
1980
+ const result = await account.execute([{
1981
+ contractAddress: this.contractAddress,
1982
+ entrypoint: "ragequit",
1983
+ calldata: proof
1984
+ }]);
1985
+ return result.transaction_hash;
1986
+ }
1987
+ /** Get the nullifier tree state. */
1988
+ async getNullifierTreeState() {
1989
+ const result = await this.obelysk.provider.callContract({
1990
+ contractAddress: this.contractAddress,
1991
+ entrypoint: "get_nullifier_tree_state",
1992
+ calldata: []
1993
+ });
1994
+ return { root: result[0], size: Number(BigInt(result[1])) };
1995
+ }
1996
+ /** Get account balance hints (for O(1) decryption). */
1997
+ async getAccountHints(address) {
1998
+ try {
1999
+ const result = await this.obelysk.provider.callContract({
2000
+ contractAddress: this.contractAddress,
2001
+ entrypoint: "get_account_hints",
2002
+ calldata: [address]
2003
+ });
2004
+ return {
2005
+ balanceHint: BigInt(result[0]),
2006
+ pendingInHint: BigInt(result[1]),
2007
+ pendingOutHint: BigInt(result[2])
2008
+ };
2009
+ } catch {
2010
+ return null;
2011
+ }
2012
+ }
1594
2013
  };
1595
2014
 
1596
2015
  // src/obelysk/shieldedSwap.ts
@@ -1659,6 +2078,911 @@ var ShieldedSwapClient = class {
1659
2078
  });
1660
2079
  return result[0];
1661
2080
  }
2081
+ /**
2082
+ * Execute a shielded swap (privacy pool -> AMM -> re-deposit).
2083
+ * This is the full privacy-preserving swap flow.
2084
+ */
2085
+ async shieldedSwap(params) {
2086
+ const account = this.obelysk.requireAccount();
2087
+ const result = await account.execute([{
2088
+ contractAddress: this.contractAddress,
2089
+ entrypoint: "shielded_swap",
2090
+ calldata: [
2091
+ params.tokenIn,
2092
+ params.tokenOut,
2093
+ params.amountIn.toString(),
2094
+ params.minAmountOut.toString(),
2095
+ params.nullifier,
2096
+ params.merkleRoot,
2097
+ ...params.merkleProof,
2098
+ params.newCommitment,
2099
+ params.encryptedAmount.toString(),
2100
+ params.proof
2101
+ ]
2102
+ }]);
2103
+ return result.transaction_hash;
2104
+ }
2105
+ };
2106
+
2107
+ // src/obelysk/vm31Vault.ts
2108
+ var VM31VaultClient = class {
2109
+ constructor(obelysk) {
2110
+ this.obelysk = obelysk;
2111
+ }
2112
+ get contractAddress() {
2113
+ return this.obelysk.contracts.vm31_pool;
2114
+ }
2115
+ get relayerUrl() {
2116
+ return this.obelysk.relayerUrl ?? "https://relay.bitsage.network:3080";
2117
+ }
2118
+ get relayerApiKey() {
2119
+ return this.obelysk.relayerApiKey;
2120
+ }
2121
+ async relayerFetch(path, init) {
2122
+ const url = `${this.relayerUrl}${path}`;
2123
+ const headers = { "Content-Type": "application/json" };
2124
+ if (this.relayerApiKey) headers["x-api-key"] = this.relayerApiKey;
2125
+ const res = await fetch(url, { ...init, headers: { ...headers, ...init?.headers } });
2126
+ if (!res.ok) {
2127
+ const body = await res.text().catch(() => "");
2128
+ throw new Error(`VM31 relayer ${res.status}: ${body}`);
2129
+ }
2130
+ return res.json();
2131
+ }
2132
+ // --------------------------------------------------------------------------
2133
+ // On-chain reads (callContract to vm31_pool)
2134
+ // --------------------------------------------------------------------------
2135
+ /** Get the current Merkle root of the VM31 commitment tree */
2136
+ async getMerkleRoot() {
2137
+ const result = await this.obelysk.provider.callContract({
2138
+ contractAddress: this.contractAddress,
2139
+ entrypoint: "get_merkle_root",
2140
+ calldata: []
2141
+ });
2142
+ return { lo: result[0], hi: result[1] };
2143
+ }
2144
+ /** Get the number of leaves in the commitment tree */
2145
+ async getTreeSize() {
2146
+ const result = await this.obelysk.provider.callContract({
2147
+ contractAddress: this.contractAddress,
2148
+ entrypoint: "get_tree_size",
2149
+ calldata: []
2150
+ });
2151
+ return Number(BigInt(result[0]));
2152
+ }
2153
+ /** Check if a nullifier has been spent */
2154
+ async isNullifierSpent(nullifier) {
2155
+ const result = await this.obelysk.provider.callContract({
2156
+ contractAddress: this.contractAddress,
2157
+ entrypoint: "is_nullifier_spent",
2158
+ calldata: [nullifier.lo, nullifier.hi]
2159
+ });
2160
+ return BigInt(result[0]) !== 0n;
2161
+ }
2162
+ /** Check if a Merkle root is known (valid historical root) */
2163
+ async isKnownRoot(root) {
2164
+ const result = await this.obelysk.provider.callContract({
2165
+ contractAddress: this.contractAddress,
2166
+ entrypoint: "is_known_root",
2167
+ calldata: [root.lo, root.hi]
2168
+ });
2169
+ return BigInt(result[0]) !== 0n;
2170
+ }
2171
+ /** Get the total balance of an asset held in the pool */
2172
+ async getAssetBalance(assetId) {
2173
+ const result = await this.obelysk.provider.callContract({
2174
+ contractAddress: this.contractAddress,
2175
+ entrypoint: "get_asset_balance",
2176
+ calldata: [assetId.toString()]
2177
+ });
2178
+ return BigInt(result[0]);
2179
+ }
2180
+ /** Get on-chain batch status (0=NONE, 1=SUBMITTED, 2=FINALIZED, 3=CANCELLED) */
2181
+ async getBatchStatus(batchId) {
2182
+ const result = await this.obelysk.provider.callContract({
2183
+ contractAddress: this.contractAddress,
2184
+ entrypoint: "get_batch_status",
2185
+ calldata: [batchId]
2186
+ });
2187
+ return Number(BigInt(result[0]));
2188
+ }
2189
+ /** Get the currently active batch ID */
2190
+ async getActiveBatchId() {
2191
+ const result = await this.obelysk.provider.callContract({
2192
+ contractAddress: this.contractAddress,
2193
+ entrypoint: "get_active_batch_id",
2194
+ calldata: []
2195
+ });
2196
+ return result[0];
2197
+ }
2198
+ /** Get total transaction count in a batch */
2199
+ async getBatchTotalTxs(batchId) {
2200
+ const result = await this.obelysk.provider.callContract({
2201
+ contractAddress: this.contractAddress,
2202
+ entrypoint: "get_batch_total_txs",
2203
+ calldata: [batchId]
2204
+ });
2205
+ return Number(BigInt(result[0]));
2206
+ }
2207
+ /** Get number of processed transactions in a batch */
2208
+ async getBatchProcessedCount(batchId) {
2209
+ const result = await this.obelysk.provider.callContract({
2210
+ contractAddress: this.contractAddress,
2211
+ entrypoint: "get_batch_processed_count",
2212
+ calldata: [batchId]
2213
+ });
2214
+ return Number(BigInt(result[0]));
2215
+ }
2216
+ /** Get the ERC-20 token address for a VM31 asset ID */
2217
+ async getAssetToken(assetId) {
2218
+ const result = await this.obelysk.provider.callContract({
2219
+ contractAddress: this.contractAddress,
2220
+ entrypoint: "get_asset_token",
2221
+ calldata: [assetId.toString()]
2222
+ });
2223
+ return result[0];
2224
+ }
2225
+ /** Get the VM31 asset ID for a given ERC-20 token address */
2226
+ async getTokenAsset(tokenAddress) {
2227
+ const result = await this.obelysk.provider.callContract({
2228
+ contractAddress: this.contractAddress,
2229
+ entrypoint: "get_token_asset",
2230
+ calldata: [tokenAddress]
2231
+ });
2232
+ return Number(BigInt(result[0]));
2233
+ }
2234
+ /** Check if the VM31Pool contract is paused */
2235
+ async isPaused() {
2236
+ const result = await this.obelysk.provider.callContract({
2237
+ contractAddress: this.contractAddress,
2238
+ entrypoint: "is_paused",
2239
+ calldata: []
2240
+ });
2241
+ return BigInt(result[0]) !== 0n;
2242
+ }
2243
+ /** Get the contract owner address */
2244
+ async getOwner() {
2245
+ const result = await this.obelysk.provider.callContract({
2246
+ contractAddress: this.contractAddress,
2247
+ entrypoint: "get_owner",
2248
+ calldata: []
2249
+ });
2250
+ return result[0];
2251
+ }
2252
+ /** Get the authorized relayer address */
2253
+ async getRelayer() {
2254
+ const result = await this.obelysk.provider.callContract({
2255
+ contractAddress: this.contractAddress,
2256
+ entrypoint: "get_relayer",
2257
+ calldata: []
2258
+ });
2259
+ return result[0];
2260
+ }
2261
+ /** Get batch timeout in blocks */
2262
+ async getBatchTimeoutBlocks() {
2263
+ const result = await this.obelysk.provider.callContract({
2264
+ contractAddress: this.contractAddress,
2265
+ entrypoint: "get_batch_timeout_blocks",
2266
+ calldata: []
2267
+ });
2268
+ return Number(BigInt(result[0]));
2269
+ }
2270
+ // --------------------------------------------------------------------------
2271
+ // Relayer HTTP calls
2272
+ // --------------------------------------------------------------------------
2273
+ /** Check relayer health (no auth required) */
2274
+ async getRelayerHealth() {
2275
+ return this.relayerFetch("/health");
2276
+ }
2277
+ /** Get relayer queue status */
2278
+ async getRelayerStatus() {
2279
+ const data = await this.relayerFetch("/status");
2280
+ return {
2281
+ pendingTransactions: data.pending_transactions,
2282
+ batchMaxSize: data.batch_max_size,
2283
+ batchTimeoutSecs: data.batch_timeout_secs
2284
+ };
2285
+ }
2286
+ /** Get the relayer's public encryption key */
2287
+ async getRelayerPublicKey() {
2288
+ const data = await this.relayerFetch("/public-key");
2289
+ return {
2290
+ publicKey: data.public_key,
2291
+ version: data.version,
2292
+ algorithm: data.algorithm
2293
+ };
2294
+ }
2295
+ /** Submit a deposit transaction to the relayer */
2296
+ async submitDeposit(params) {
2297
+ return this.relayerFetch("/submit", {
2298
+ method: "POST",
2299
+ body: JSON.stringify({
2300
+ type: "deposit",
2301
+ amount: Number(params.amount),
2302
+ asset_id: params.assetId,
2303
+ recipient_pubkey: params.recipientPubkey,
2304
+ recipient_viewing_key: params.recipientViewingKey
2305
+ })
2306
+ });
2307
+ }
2308
+ /** Submit a withdrawal transaction to the relayer */
2309
+ async submitWithdraw(params) {
2310
+ return this.relayerFetch("/submit", {
2311
+ method: "POST",
2312
+ body: JSON.stringify({
2313
+ type: "withdraw",
2314
+ amount: Number(params.amount),
2315
+ asset_id: params.assetId,
2316
+ note: {
2317
+ owner_pubkey: params.note.owner_pubkey,
2318
+ asset_id: params.note.asset_id,
2319
+ amount_lo: params.note.amount_lo,
2320
+ amount_hi: params.note.amount_hi,
2321
+ blinding: params.note.blinding
2322
+ },
2323
+ spending_key: params.spendingKey,
2324
+ merkle_path: params.merklePath,
2325
+ merkle_root: params.merkleRoot,
2326
+ withdrawal_binding: params.withdrawalBinding,
2327
+ binding_salt: params.bindingSalt
2328
+ })
2329
+ });
2330
+ }
2331
+ /** Submit a private transfer transaction to the relayer */
2332
+ async submitTransfer(params) {
2333
+ return this.relayerFetch("/submit", {
2334
+ method: "POST",
2335
+ body: JSON.stringify({
2336
+ type: "transfer",
2337
+ amount: Number(params.amount),
2338
+ asset_id: params.assetId,
2339
+ recipient_pubkey: params.recipientPubkey,
2340
+ recipient_viewing_key: params.recipientViewingKey,
2341
+ sender_viewing_key: params.senderViewingKey,
2342
+ input_notes: params.inputNotes.map((n) => ({
2343
+ note: n.note,
2344
+ spending_key: n.spendingKey,
2345
+ merkle_path: n.merklePath
2346
+ })),
2347
+ merkle_root: params.merkleRoot
2348
+ })
2349
+ });
2350
+ }
2351
+ /** Query batch info from the relayer */
2352
+ async queryBatch(batchId) {
2353
+ const data = await this.relayerFetch(`/batch/${batchId}`);
2354
+ return {
2355
+ id: data.id,
2356
+ status: data.status,
2357
+ txCount: data.tx_count,
2358
+ proofHash: data.proof_hash,
2359
+ batchIdOnchain: data.batch_id_onchain,
2360
+ txHash: data.tx_hash,
2361
+ createdAt: data.created_at,
2362
+ error: data.error
2363
+ };
2364
+ }
2365
+ /** Fetch Merkle path for a commitment from the relayer */
2366
+ async fetchMerklePath(commitment) {
2367
+ const data = await this.relayerFetch(`/merkle-path/${commitment}`);
2368
+ return {
2369
+ commitment: data.commitment,
2370
+ merklePath: data.merkle_path ?? null,
2371
+ merkleRoot: data.merkle_root ?? null,
2372
+ batchId: data.batch_id ?? null,
2373
+ createdAt: data.created_at,
2374
+ status: data.status
2375
+ };
2376
+ }
2377
+ /** Force the relayer to prove the current batch immediately */
2378
+ async forceProve() {
2379
+ const data = await this.relayerFetch("/prove", { method: "POST" });
2380
+ return {
2381
+ status: data.status,
2382
+ batchId: data.batch_id
2383
+ };
2384
+ }
2385
+ // --------------------------------------------------------------------------
2386
+ // Helpers
2387
+ // --------------------------------------------------------------------------
2388
+ /** Encode a bigint amount into M31 lo/hi pair (31-bit limbs) */
2389
+ static encodeAmountM31(amount) {
2390
+ const lo = Number(amount & 0x7FFFFFFFn);
2391
+ const hi = Number(amount >> 31n);
2392
+ return { lo, hi };
2393
+ }
2394
+ /** Decode an M31 lo/hi pair back into a bigint amount */
2395
+ static decodeAmountM31(lo, hi) {
2396
+ return BigInt(lo) + BigInt(hi) * (1n << 31n);
2397
+ }
2398
+ };
2399
+
2400
+ // src/obelysk/vm31Bridge.ts
2401
+ var VM31BridgeClient = class {
2402
+ constructor(obelysk) {
2403
+ this.obelysk = obelysk;
2404
+ }
2405
+ get contractAddress() {
2406
+ return this.obelysk.contracts.vm31_bridge;
2407
+ }
2408
+ /** Get the authorized relayer address */
2409
+ async getRelayer() {
2410
+ const result = await this.obelysk.provider.callContract({
2411
+ contractAddress: this.contractAddress,
2412
+ entrypoint: "get_relayer",
2413
+ calldata: []
2414
+ });
2415
+ return result[0];
2416
+ }
2417
+ /** Get the VM31Pool contract address */
2418
+ async getVM31Pool() {
2419
+ const result = await this.obelysk.provider.callContract({
2420
+ contractAddress: this.contractAddress,
2421
+ entrypoint: "get_vm31_pool",
2422
+ calldata: []
2423
+ });
2424
+ return result[0];
2425
+ }
2426
+ /** Get the ConfidentialTransfer contract address */
2427
+ async getConfidentialTransfer() {
2428
+ const result = await this.obelysk.provider.callContract({
2429
+ contractAddress: this.contractAddress,
2430
+ entrypoint: "get_confidential_transfer",
2431
+ calldata: []
2432
+ });
2433
+ return result[0];
2434
+ }
2435
+ /** Get the asset pair mapping for a given token address */
2436
+ async getAssetPair(tokenAddress) {
2437
+ try {
2438
+ const result = await this.obelysk.provider.callContract({
2439
+ contractAddress: this.contractAddress,
2440
+ entrypoint: "get_asset_pair",
2441
+ calldata: [tokenAddress]
2442
+ });
2443
+ return {
2444
+ vm31AssetId: result[0],
2445
+ confidentialAssetId: result[1]
2446
+ };
2447
+ } catch {
2448
+ return null;
2449
+ }
2450
+ }
2451
+ /** Check if a bridge key has already been processed */
2452
+ async isBridgeKeyProcessed(bridgeKey) {
2453
+ const result = await this.obelysk.provider.callContract({
2454
+ contractAddress: this.contractAddress,
2455
+ entrypoint: "is_bridge_key_processed",
2456
+ calldata: [bridgeKey]
2457
+ });
2458
+ return BigInt(result[0]) !== 0n;
2459
+ }
2460
+ /** Compute a bridge key from withdrawal parameters */
2461
+ async computeBridgeKey(params) {
2462
+ const low = params.amount & (1n << 128n) - 1n;
2463
+ const high = params.amount >> 128n;
2464
+ const result = await this.obelysk.provider.callContract({
2465
+ contractAddress: this.contractAddress,
2466
+ entrypoint: "compute_bridge_key",
2467
+ calldata: [
2468
+ params.batchId,
2469
+ params.withdrawalIdx.toString(),
2470
+ params.payoutRecipient,
2471
+ params.creditRecipient,
2472
+ params.token,
2473
+ low.toString(),
2474
+ high.toString()
2475
+ ]
2476
+ });
2477
+ return result[0];
2478
+ }
2479
+ /** Get full bridge configuration (relayer, vm31Pool, confidentialTransfer) */
2480
+ async getConfig() {
2481
+ const [relayer, vm31Pool, confidentialTransfer] = await Promise.all([
2482
+ this.getRelayer(),
2483
+ this.getVM31Pool(),
2484
+ this.getConfidentialTransfer()
2485
+ ]);
2486
+ return { relayer, vm31Pool, confidentialTransfer };
2487
+ }
2488
+ /** Get pending upgrade info, if any */
2489
+ async getPendingUpgrade() {
2490
+ const result = await this.obelysk.provider.callContract({
2491
+ contractAddress: this.contractAddress,
2492
+ entrypoint: "get_pending_upgrade",
2493
+ calldata: []
2494
+ });
2495
+ const classHash = result[0];
2496
+ if (classHash === "0x0") return null;
2497
+ return {
2498
+ classHash,
2499
+ scheduledAt: Number(BigInt(result[1]))
2500
+ };
2501
+ }
2502
+ /** Check if the bridge contract is paused */
2503
+ async isPaused() {
2504
+ try {
2505
+ const result = await this.obelysk.provider.callContract({
2506
+ contractAddress: this.contractAddress,
2507
+ entrypoint: "is_paused",
2508
+ calldata: []
2509
+ });
2510
+ return BigInt(result[0]) !== 0n;
2511
+ } catch {
2512
+ return false;
2513
+ }
2514
+ }
2515
+ };
2516
+
2517
+ // src/obelysk/otcOrderbook.ts
2518
+ var OrderSide = /* @__PURE__ */ ((OrderSide2) => {
2519
+ OrderSide2[OrderSide2["Buy"] = 0] = "Buy";
2520
+ OrderSide2[OrderSide2["Sell"] = 1] = "Sell";
2521
+ return OrderSide2;
2522
+ })(OrderSide || {});
2523
+ var OrderType = /* @__PURE__ */ ((OrderType2) => {
2524
+ OrderType2[OrderType2["Limit"] = 0] = "Limit";
2525
+ OrderType2[OrderType2["Market"] = 1] = "Market";
2526
+ return OrderType2;
2527
+ })(OrderType || {});
2528
+ var OrderStatus = /* @__PURE__ */ ((OrderStatus2) => {
2529
+ OrderStatus2[OrderStatus2["Open"] = 0] = "Open";
2530
+ OrderStatus2[OrderStatus2["PartialFill"] = 1] = "PartialFill";
2531
+ OrderStatus2[OrderStatus2["Filled"] = 2] = "Filled";
2532
+ OrderStatus2[OrderStatus2["Cancelled"] = 3] = "Cancelled";
2533
+ OrderStatus2[OrderStatus2["Expired"] = 4] = "Expired";
2534
+ return OrderStatus2;
2535
+ })(OrderStatus || {});
2536
+ var U128_MASK = (1n << 128n) - 1n;
2537
+ function splitU256(value) {
2538
+ return {
2539
+ low: (value & U128_MASK).toString(),
2540
+ high: (value >> 128n).toString()
2541
+ };
2542
+ }
2543
+ function parseU256(result, offset) {
2544
+ return BigInt(result[offset]) + (BigInt(result[offset + 1]) << 128n);
2545
+ }
2546
+ var ORDER_SIDE_VALUES = [0 /* Buy */, 1 /* Sell */];
2547
+ var ORDER_TYPE_VALUES = [0 /* Limit */, 1 /* Market */];
2548
+ var ORDER_STATUS_VALUES = [
2549
+ 0 /* Open */,
2550
+ 1 /* PartialFill */,
2551
+ 2 /* Filled */,
2552
+ 3 /* Cancelled */,
2553
+ 4 /* Expired */
2554
+ ];
2555
+ var ORDER_FELT_COUNT = 15;
2556
+ function parseOrder(result, offset) {
2557
+ return {
2558
+ orderId: parseU256(result, offset),
2559
+ maker: result[offset + 2],
2560
+ pairId: Number(BigInt(result[offset + 3])),
2561
+ side: ORDER_SIDE_VALUES[Number(BigInt(result[offset + 4]))] ?? 0 /* Buy */,
2562
+ orderType: ORDER_TYPE_VALUES[Number(BigInt(result[offset + 5]))] ?? 0 /* Limit */,
2563
+ price: parseU256(result, offset + 6),
2564
+ amount: parseU256(result, offset + 8),
2565
+ remaining: parseU256(result, offset + 10),
2566
+ status: ORDER_STATUS_VALUES[Number(BigInt(result[offset + 12]))] ?? 0 /* Open */,
2567
+ createdAt: Number(BigInt(result[offset + 13])),
2568
+ expiresAt: Number(BigInt(result[offset + 14]))
2569
+ };
2570
+ }
2571
+ var TRADE_FELT_COUNT = 15;
2572
+ function parseTrade(result, offset) {
2573
+ return {
2574
+ tradeId: parseU256(result, offset),
2575
+ makerOrderId: parseU256(result, offset + 2),
2576
+ takerOrderId: parseU256(result, offset + 4),
2577
+ maker: result[offset + 6],
2578
+ taker: result[offset + 7],
2579
+ price: parseU256(result, offset + 8),
2580
+ amount: parseU256(result, offset + 10),
2581
+ quoteAmount: parseU256(result, offset + 12),
2582
+ executedAt: Number(BigInt(result[offset + 14]))
2583
+ };
2584
+ }
2585
+ var OTCOrderbookClient = class {
2586
+ constructor(obelysk) {
2587
+ this.obelysk = obelysk;
2588
+ }
2589
+ get contractAddress() {
2590
+ const addr = this.obelysk.contracts.otc_orderbook;
2591
+ if (!addr) throw new Error("OTC Orderbook contract not configured for this network");
2592
+ return addr;
2593
+ }
2594
+ // --------------------------------------------------------------------------
2595
+ // Write operations
2596
+ // --------------------------------------------------------------------------
2597
+ /**
2598
+ * Place a limit order on the orderbook.
2599
+ *
2600
+ * The contract handles internal matching against resting orders.
2601
+ * Returns the transaction hash.
2602
+ */
2603
+ async placeLimitOrder(params) {
2604
+ const account = this.obelysk.requireAccount();
2605
+ const { low: pLow, high: pHigh } = splitU256(params.price);
2606
+ const { low: aLow, high: aHigh } = splitU256(params.amount);
2607
+ const result = await account.execute([
2608
+ {
2609
+ contractAddress: this.contractAddress,
2610
+ entrypoint: "place_limit_order",
2611
+ calldata: [
2612
+ params.pairId.toString(),
2613
+ params.side.toString(),
2614
+ pLow,
2615
+ pHigh,
2616
+ aLow,
2617
+ aHigh,
2618
+ (params.expiresIn ?? 0).toString()
2619
+ ]
2620
+ }
2621
+ ]);
2622
+ return result.transaction_hash;
2623
+ }
2624
+ /**
2625
+ * Place a market order that fills immediately against resting liquidity.
2626
+ * Returns the transaction hash.
2627
+ */
2628
+ async placeMarketOrder(params) {
2629
+ const account = this.obelysk.requireAccount();
2630
+ const { low: aLow, high: aHigh } = splitU256(params.amount);
2631
+ const result = await account.execute([
2632
+ {
2633
+ contractAddress: this.contractAddress,
2634
+ entrypoint: "place_market_order",
2635
+ calldata: [
2636
+ params.pairId.toString(),
2637
+ params.side.toString(),
2638
+ aLow,
2639
+ aHigh
2640
+ ]
2641
+ }
2642
+ ]);
2643
+ return result.transaction_hash;
2644
+ }
2645
+ /**
2646
+ * Cancel a single order by ID.
2647
+ * Only the maker can cancel their own order.
2648
+ */
2649
+ async cancelOrder(orderId) {
2650
+ const account = this.obelysk.requireAccount();
2651
+ const { low, high } = splitU256(orderId);
2652
+ const result = await account.execute([
2653
+ {
2654
+ contractAddress: this.contractAddress,
2655
+ entrypoint: "cancel_order",
2656
+ calldata: [low, high]
2657
+ }
2658
+ ]);
2659
+ return result.transaction_hash;
2660
+ }
2661
+ /**
2662
+ * Cancel all open orders for the caller.
2663
+ */
2664
+ async cancelAllOrders() {
2665
+ const account = this.obelysk.requireAccount();
2666
+ const result = await account.execute([
2667
+ {
2668
+ contractAddress: this.contractAddress,
2669
+ entrypoint: "cancel_all_orders",
2670
+ calldata: []
2671
+ }
2672
+ ]);
2673
+ return result.transaction_hash;
2674
+ }
2675
+ /**
2676
+ * Place multiple limit orders in a single transaction.
2677
+ *
2678
+ * Cairo expects an array of (u8, OrderSide, u256, u256, u64) tuples.
2679
+ * Calldata: [length, ...flattened orders].
2680
+ */
2681
+ async batchPlaceOrders(orders) {
2682
+ const account = this.obelysk.requireAccount();
2683
+ const calldata = [orders.length.toString()];
2684
+ for (const order of orders) {
2685
+ const { low: pLow, high: pHigh } = splitU256(order.price);
2686
+ const { low: aLow, high: aHigh } = splitU256(order.amount);
2687
+ calldata.push(
2688
+ order.pairId.toString(),
2689
+ order.side.toString(),
2690
+ pLow,
2691
+ pHigh,
2692
+ aLow,
2693
+ aHigh,
2694
+ (order.expiresIn ?? 0).toString()
2695
+ );
2696
+ }
2697
+ const result = await account.execute([
2698
+ {
2699
+ contractAddress: this.contractAddress,
2700
+ entrypoint: "batch_place_orders",
2701
+ calldata
2702
+ }
2703
+ ]);
2704
+ return result.transaction_hash;
2705
+ }
2706
+ /**
2707
+ * Cancel multiple orders in a single transaction.
2708
+ *
2709
+ * Calldata: [length, ...flattened u256 order IDs].
2710
+ */
2711
+ async batchCancelOrders(orderIds) {
2712
+ const account = this.obelysk.requireAccount();
2713
+ const calldata = [orderIds.length.toString()];
2714
+ for (const id of orderIds) {
2715
+ const { low, high } = splitU256(id);
2716
+ calldata.push(low, high);
2717
+ }
2718
+ const result = await account.execute([
2719
+ {
2720
+ contractAddress: this.contractAddress,
2721
+ entrypoint: "batch_cancel_orders",
2722
+ calldata
2723
+ }
2724
+ ]);
2725
+ return result.transaction_hash;
2726
+ }
2727
+ // --------------------------------------------------------------------------
2728
+ // Read operations
2729
+ // --------------------------------------------------------------------------
2730
+ /**
2731
+ * Get a single order by ID.
2732
+ */
2733
+ async getOrder(orderId) {
2734
+ const { low, high } = splitU256(orderId);
2735
+ const result = await this.obelysk.provider.callContract({
2736
+ contractAddress: this.contractAddress,
2737
+ entrypoint: "get_order",
2738
+ calldata: [low, high]
2739
+ });
2740
+ return parseOrder(result, 0);
2741
+ }
2742
+ /**
2743
+ * Get all order IDs belonging to a user.
2744
+ */
2745
+ async getUserOrders(user) {
2746
+ const result = await this.obelysk.provider.callContract({
2747
+ contractAddress: this.contractAddress,
2748
+ entrypoint: "get_user_orders",
2749
+ calldata: [user]
2750
+ });
2751
+ const len = Number(BigInt(result[0]));
2752
+ const ids = [];
2753
+ for (let i = 0; i < len; i++) {
2754
+ ids.push(parseU256(result, 1 + i * 2));
2755
+ }
2756
+ return ids;
2757
+ }
2758
+ /**
2759
+ * Get the best (highest) bid price for a trading pair.
2760
+ */
2761
+ async getBestBid(pairId) {
2762
+ const result = await this.obelysk.provider.callContract({
2763
+ contractAddress: this.contractAddress,
2764
+ entrypoint: "get_best_bid",
2765
+ calldata: [pairId.toString()]
2766
+ });
2767
+ return parseU256(result, 0);
2768
+ }
2769
+ /**
2770
+ * Get the best (lowest) ask price for a trading pair.
2771
+ */
2772
+ async getBestAsk(pairId) {
2773
+ const result = await this.obelysk.provider.callContract({
2774
+ contractAddress: this.contractAddress,
2775
+ entrypoint: "get_best_ask",
2776
+ calldata: [pairId.toString()]
2777
+ });
2778
+ return parseU256(result, 0);
2779
+ }
2780
+ /**
2781
+ * Get the bid-ask spread for a trading pair.
2782
+ */
2783
+ async getSpread(pairId) {
2784
+ const result = await this.obelysk.provider.callContract({
2785
+ contractAddress: this.contractAddress,
2786
+ entrypoint: "get_spread",
2787
+ calldata: [pairId.toString()]
2788
+ });
2789
+ return parseU256(result, 0);
2790
+ }
2791
+ /**
2792
+ * Get trading pair configuration.
2793
+ */
2794
+ async getPair(pairId) {
2795
+ const result = await this.obelysk.provider.callContract({
2796
+ contractAddress: this.contractAddress,
2797
+ entrypoint: "get_pair",
2798
+ calldata: [pairId.toString()]
2799
+ });
2800
+ return {
2801
+ baseToken: result[0],
2802
+ quoteToken: result[1],
2803
+ minOrderSize: parseU256(result, 2),
2804
+ tickSize: parseU256(result, 4),
2805
+ isActive: BigInt(result[6]) !== 0n
2806
+ };
2807
+ }
2808
+ /**
2809
+ * Get the orderbook configuration (fees, limits, pause state).
2810
+ */
2811
+ async getConfig() {
2812
+ const result = await this.obelysk.provider.callContract({
2813
+ contractAddress: this.contractAddress,
2814
+ entrypoint: "get_config",
2815
+ calldata: []
2816
+ });
2817
+ return {
2818
+ makerFeeBps: Number(BigInt(result[0])),
2819
+ takerFeeBps: Number(BigInt(result[1])),
2820
+ defaultExpirySecs: Number(BigInt(result[2])),
2821
+ maxOrdersPerUser: Number(BigInt(result[3])),
2822
+ paused: BigInt(result[4]) !== 0n
2823
+ };
2824
+ }
2825
+ /**
2826
+ * Get aggregate orderbook statistics.
2827
+ */
2828
+ async getStats() {
2829
+ const result = await this.obelysk.provider.callContract({
2830
+ contractAddress: this.contractAddress,
2831
+ entrypoint: "get_stats",
2832
+ calldata: []
2833
+ });
2834
+ return {
2835
+ orderCount: parseU256(result, 0),
2836
+ tradeCount: parseU256(result, 2),
2837
+ totalVolume: parseU256(result, 4),
2838
+ totalFees: parseU256(result, 6)
2839
+ };
2840
+ }
2841
+ /**
2842
+ * Get total number of orders ever placed.
2843
+ */
2844
+ async getOrderCount() {
2845
+ const result = await this.obelysk.provider.callContract({
2846
+ contractAddress: this.contractAddress,
2847
+ entrypoint: "get_order_count",
2848
+ calldata: []
2849
+ });
2850
+ return parseU256(result, 0);
2851
+ }
2852
+ /**
2853
+ * Get total number of trades executed.
2854
+ */
2855
+ async getTradeCount() {
2856
+ const result = await this.obelysk.provider.callContract({
2857
+ contractAddress: this.contractAddress,
2858
+ entrypoint: "get_trade_count",
2859
+ calldata: []
2860
+ });
2861
+ return parseU256(result, 0);
2862
+ }
2863
+ /**
2864
+ * Get the time-weighted average price for a trading pair.
2865
+ */
2866
+ async getTwap(pairId) {
2867
+ const result = await this.obelysk.provider.callContract({
2868
+ contractAddress: this.contractAddress,
2869
+ entrypoint: "get_twap",
2870
+ calldata: [pairId.toString()]
2871
+ });
2872
+ return parseU256(result, 0);
2873
+ }
2874
+ /**
2875
+ * Get 24-hour rolling statistics for a trading pair.
2876
+ */
2877
+ async get24hStats(pairId) {
2878
+ const result = await this.obelysk.provider.callContract({
2879
+ contractAddress: this.contractAddress,
2880
+ entrypoint: "get_24h_stats",
2881
+ calldata: [pairId.toString()]
2882
+ });
2883
+ return {
2884
+ volume: parseU256(result, 0),
2885
+ high: parseU256(result, 2),
2886
+ low: parseU256(result, 4),
2887
+ tradeCount: parseU256(result, 6)
2888
+ };
2889
+ }
2890
+ /**
2891
+ * Get the most recent trade for a trading pair.
2892
+ */
2893
+ async getLastTrade(pairId) {
2894
+ const result = await this.obelysk.provider.callContract({
2895
+ contractAddress: this.contractAddress,
2896
+ entrypoint: "get_last_trade",
2897
+ calldata: [pairId.toString()]
2898
+ });
2899
+ return {
2900
+ price: parseU256(result, 0),
2901
+ amount: parseU256(result, 2),
2902
+ timestamp: Number(BigInt(result[4]))
2903
+ };
2904
+ }
2905
+ /**
2906
+ * Get the orderbook depth (price levels) for a trading pair.
2907
+ *
2908
+ * Returns up to `maxLevels` aggregated price levels for both
2909
+ * bids and asks. Each level contains price, total amount, and
2910
+ * number of orders at that price.
2911
+ */
2912
+ async getOrderbookDepth(pairId, maxLevels) {
2913
+ const result = await this.obelysk.provider.callContract({
2914
+ contractAddress: this.contractAddress,
2915
+ entrypoint: "get_orderbook_depth",
2916
+ calldata: [pairId.toString(), maxLevels.toString()]
2917
+ });
2918
+ let offset = 0;
2919
+ const bidCount = Number(BigInt(result[offset]));
2920
+ offset += 1;
2921
+ const bids = [];
2922
+ for (let i = 0; i < bidCount; i++) {
2923
+ bids.push({
2924
+ price: parseU256(result, offset),
2925
+ totalAmount: parseU256(result, offset + 2),
2926
+ orderCount: Number(BigInt(result[offset + 4]))
2927
+ });
2928
+ offset += 5;
2929
+ }
2930
+ const askCount = Number(BigInt(result[offset]));
2931
+ offset += 1;
2932
+ const asks = [];
2933
+ for (let i = 0; i < askCount; i++) {
2934
+ asks.push({
2935
+ price: parseU256(result, offset),
2936
+ totalAmount: parseU256(result, offset + 2),
2937
+ orderCount: Number(BigInt(result[offset + 4]))
2938
+ });
2939
+ offset += 5;
2940
+ }
2941
+ return { bids, asks };
2942
+ }
2943
+ /**
2944
+ * Get active orders for a trading pair with pagination.
2945
+ */
2946
+ async getActiveOrders(pairId, offset, limit) {
2947
+ const result = await this.obelysk.provider.callContract({
2948
+ contractAddress: this.contractAddress,
2949
+ entrypoint: "get_active_orders",
2950
+ calldata: [pairId.toString(), offset.toString(), limit.toString()]
2951
+ });
2952
+ const len = Number(BigInt(result[0]));
2953
+ const orders = [];
2954
+ for (let i = 0; i < len; i++) {
2955
+ orders.push(parseOrder(result, 1 + i * ORDER_FELT_COUNT));
2956
+ }
2957
+ return orders;
2958
+ }
2959
+ /**
2960
+ * Get trade history for a trading pair with pagination.
2961
+ */
2962
+ async getTradeHistory(pairId, offset, limit) {
2963
+ const result = await this.obelysk.provider.callContract({
2964
+ contractAddress: this.contractAddress,
2965
+ entrypoint: "get_trade_history",
2966
+ calldata: [pairId.toString(), offset.toString(), limit.toString()]
2967
+ });
2968
+ const len = Number(BigInt(result[0]));
2969
+ const trades = [];
2970
+ for (let i = 0; i < len; i++) {
2971
+ trades.push(parseTrade(result, 1 + i * TRADE_FELT_COUNT));
2972
+ }
2973
+ return trades;
2974
+ }
2975
+ /**
2976
+ * Get the contract owner address.
2977
+ */
2978
+ async getOwner() {
2979
+ const result = await this.obelysk.provider.callContract({
2980
+ contractAddress: this.contractAddress,
2981
+ entrypoint: "owner",
2982
+ calldata: []
2983
+ });
2984
+ return result[0];
2985
+ }
1662
2986
  };
1663
2987
 
1664
2988
  // src/obelysk/client.ts
@@ -1670,6 +2994,8 @@ var ObelyskClient = class {
1670
2994
  contracts;
1671
2995
  tokens;
1672
2996
  privacyPools;
2997
+ relayerUrl;
2998
+ relayerApiKey;
1673
2999
  /** Privacy Pool operations (deposit/withdraw shielded tokens) */
1674
3000
  privacyPool;
1675
3001
  /** DarkPool batch auction trading */
@@ -1684,6 +3010,12 @@ var ObelyskClient = class {
1684
3010
  router;
1685
3011
  /** Shielded swap router (privacy-preserving AMM swaps) */
1686
3012
  swap;
3013
+ /** VM31 UTXO privacy vault (deposits/withdrawals/transfers via relayer) */
3014
+ vm31;
3015
+ /** VM31 confidential bridge (bridge VM31 withdrawals to encrypted balances) */
3016
+ bridge;
3017
+ /** OTC orderbook (limit/market orders, trade history) */
3018
+ otc;
1687
3019
  constructor(config) {
1688
3020
  this.network = config.network;
1689
3021
  this.provider = new import_starknet7.RpcProvider({ nodeUrl: config.rpcUrl ?? getRpcUrl(config.network) });
@@ -1691,6 +3023,8 @@ var ObelyskClient = class {
1691
3023
  this.contracts = getContracts(config.network);
1692
3024
  this.tokens = this.contracts.tokens ?? MAINNET_TOKENS;
1693
3025
  this.privacyPools = config.network === "mainnet" ? MAINNET_PRIVACY_POOLS : {};
3026
+ this.relayerUrl = config.relayerUrl;
3027
+ this.relayerApiKey = config.relayerApiKey;
1694
3028
  this.privacy = new ObelyskPrivacy();
1695
3029
  if (config.privacyPrivateKey) {
1696
3030
  const pk = BigInt(config.privacyPrivateKey);
@@ -1703,6 +3037,9 @@ var ObelyskClient = class {
1703
3037
  this.staking = new ProverStakingClient(this);
1704
3038
  this.router = new PrivacyRouterClient(this);
1705
3039
  this.swap = new ShieldedSwapClient(this);
3040
+ this.vm31 = new VM31VaultClient(this);
3041
+ this.bridge = new VM31BridgeClient(this);
3042
+ this.otc = new OTCOrderbookClient(this);
1706
3043
  }
1707
3044
  /** Get token address by symbol */
1708
3045
  getTokenAddress(symbol) {
@@ -1733,14 +3070,20 @@ var ObelyskClient = class {
1733
3070
  GENERATOR_H,
1734
3071
  MAINNET_PRIVACY_POOLS,
1735
3072
  MAINNET_TOKENS,
3073
+ OTCOrderbookClient,
1736
3074
  ObelyskClient,
1737
3075
  ObelyskPrivacy,
3076
+ OrderSide,
3077
+ OrderStatus,
3078
+ OrderType,
1738
3079
  PrivacyPoolClient,
1739
3080
  PrivacyRouterClient,
1740
3081
  ProverStakingClient,
1741
3082
  ShieldedSwapClient,
1742
3083
  StealthClient,
1743
3084
  TOKEN_DECIMALS,
3085
+ VM31BridgeClient,
3086
+ VM31VaultClient,
1744
3087
  VM31_ASSET_IDS,
1745
3088
  commitmentToHash,
1746
3089
  createAEHint,