@oddmaki-protocol/sdk 0.1.3 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -594,6 +594,11 @@ var VenueFacet_default = [
594
594
  name: "InvalidTickSize",
595
595
  inputs: []
596
596
  },
597
+ {
598
+ type: "error",
599
+ name: "InvalidUmaMinBond",
600
+ inputs: []
601
+ },
597
602
  {
598
603
  type: "error",
599
604
  name: "InvalidVenueFee",
@@ -909,6 +914,11 @@ var MarketsFacet_default = [
909
914
  name: "creatorFeeBps",
910
915
  type: "uint256",
911
916
  internalType: "uint256"
917
+ },
918
+ {
919
+ name: "protocolFeeBps",
920
+ type: "uint256",
921
+ internalType: "uint256"
912
922
  }
913
923
  ]
914
924
  }
@@ -1999,6 +2009,25 @@ var MatchingFacet_default = [
1999
2009
  ],
2000
2010
  anonymous: false
2001
2011
  },
2012
+ {
2013
+ type: "event",
2014
+ name: "OrderAutoCancelled",
2015
+ inputs: [
2016
+ {
2017
+ name: "orderId",
2018
+ type: "uint256",
2019
+ indexed: true,
2020
+ internalType: "uint256"
2021
+ },
2022
+ {
2023
+ name: "refundedCollateral",
2024
+ type: "uint256",
2025
+ indexed: false,
2026
+ internalType: "uint256"
2027
+ }
2028
+ ],
2029
+ anonymous: false
2030
+ },
2002
2031
  {
2003
2032
  type: "event",
2004
2033
  name: "OrderDeleted",
@@ -2752,6 +2781,11 @@ var MarketGroupFacet_default = [
2752
2781
  name: "liveness",
2753
2782
  type: "uint64",
2754
2783
  internalType: "uint64"
2784
+ },
2785
+ {
2786
+ name: "reward",
2787
+ type: "uint256",
2788
+ internalType: "uint256"
2755
2789
  }
2756
2790
  ]
2757
2791
  }
@@ -2897,6 +2931,12 @@ var MarketGroupFacet_default = [
2897
2931
  type: "bytes32[]",
2898
2932
  indexed: false,
2899
2933
  internalType: "bytes32[]"
2934
+ },
2935
+ {
2936
+ name: "reward",
2937
+ type: "uint256",
2938
+ indexed: false,
2939
+ internalType: "uint256"
2900
2940
  }
2901
2941
  ],
2902
2942
  anonymous: false
@@ -3487,6 +3527,11 @@ var ResolutionFacet_default = [
3487
3527
  name: "settled",
3488
3528
  type: "bool",
3489
3529
  internalType: "bool"
3530
+ },
3531
+ {
3532
+ name: "asserter",
3533
+ type: "address",
3534
+ internalType: "address"
3490
3535
  }
3491
3536
  ]
3492
3537
  }
@@ -3675,6 +3720,31 @@ var ResolutionFacet_default = [
3675
3720
  ],
3676
3721
  anonymous: false
3677
3722
  },
3723
+ {
3724
+ type: "event",
3725
+ name: "RewardPaid",
3726
+ inputs: [
3727
+ {
3728
+ name: "assertionId",
3729
+ type: "bytes32",
3730
+ indexed: true,
3731
+ internalType: "bytes32"
3732
+ },
3733
+ {
3734
+ name: "asserter",
3735
+ type: "address",
3736
+ indexed: true,
3737
+ internalType: "address"
3738
+ },
3739
+ {
3740
+ name: "reward",
3741
+ type: "uint256",
3742
+ indexed: false,
3743
+ internalType: "uint256"
3744
+ }
3745
+ ],
3746
+ anonymous: false
3747
+ },
3678
3748
  {
3679
3749
  type: "error",
3680
3750
  name: "ApproveFailed",
@@ -3725,6 +3795,11 @@ var ResolutionFacet_default = [
3725
3795
  name: "OutcomeMismatch",
3726
3796
  inputs: []
3727
3797
  },
3798
+ {
3799
+ type: "error",
3800
+ name: "TransferFailed",
3801
+ inputs: []
3802
+ },
3728
3803
  {
3729
3804
  type: "error",
3730
3805
  name: "TransferFromFailed",
@@ -4023,6 +4098,19 @@ var NegRiskFacet_default = [
4023
4098
 
4024
4099
  // src/contracts/abis/ProtocolFacet.json
4025
4100
  var ProtocolFacet_default = [
4101
+ {
4102
+ type: "function",
4103
+ name: "getProtocolFeeBps",
4104
+ inputs: [],
4105
+ outputs: [
4106
+ {
4107
+ name: "",
4108
+ type: "uint256",
4109
+ internalType: "uint256"
4110
+ }
4111
+ ],
4112
+ stateMutability: "view"
4113
+ },
4026
4114
  {
4027
4115
  type: "function",
4028
4116
  name: "getProtocolPaused",
@@ -4138,6 +4226,19 @@ var ProtocolFacet_default = [
4138
4226
  outputs: [],
4139
4227
  stateMutability: "nonpayable"
4140
4228
  },
4229
+ {
4230
+ type: "function",
4231
+ name: "setProtocolFeeBps",
4232
+ inputs: [
4233
+ {
4234
+ name: "bps",
4235
+ type: "uint256",
4236
+ internalType: "uint256"
4237
+ }
4238
+ ],
4239
+ outputs: [],
4240
+ stateMutability: "nonpayable"
4241
+ },
4141
4242
  {
4142
4243
  type: "function",
4143
4244
  name: "setProtocolTreasury",
@@ -4309,6 +4410,19 @@ var ProtocolFacet_default = [
4309
4410
  ],
4310
4411
  anonymous: false
4311
4412
  },
4413
+ {
4414
+ type: "event",
4415
+ name: "ProtocolFeeBpsUpdated",
4416
+ inputs: [
4417
+ {
4418
+ name: "bps",
4419
+ type: "uint256",
4420
+ indexed: false,
4421
+ internalType: "uint256"
4422
+ }
4423
+ ],
4424
+ anonymous: false
4425
+ },
4312
4426
  {
4313
4427
  type: "event",
4314
4428
  name: "ProtocolPausedEvent",
@@ -6006,6 +6120,30 @@ var WhitelistAccessControl_default = [
6006
6120
 
6007
6121
  // src/contracts/abis/ConditionalTokens.json
6008
6122
  var ConditionalTokens_default = [
6123
+ {
6124
+ type: "function",
6125
+ name: "balanceOf",
6126
+ inputs: [
6127
+ {
6128
+ name: "account",
6129
+ type: "address",
6130
+ internalType: "address"
6131
+ },
6132
+ {
6133
+ name: "id",
6134
+ type: "uint256",
6135
+ internalType: "uint256"
6136
+ }
6137
+ ],
6138
+ outputs: [
6139
+ {
6140
+ name: "",
6141
+ type: "uint256",
6142
+ internalType: "uint256"
6143
+ }
6144
+ ],
6145
+ stateMutability: "view"
6146
+ },
6009
6147
  {
6010
6148
  type: "function",
6011
6149
  name: "getCollectionId",
@@ -6028,7 +6166,7 @@ var ConditionalTokens_default = [
6028
6166
  ],
6029
6167
  outputs: [
6030
6168
  {
6031
- name: "",
6169
+ name: "collectionId",
6032
6170
  type: "bytes32",
6033
6171
  internalType: "bytes32"
6034
6172
  }
@@ -6057,7 +6195,7 @@ var ConditionalTokens_default = [
6057
6195
  ],
6058
6196
  outputs: [
6059
6197
  {
6060
- name: "",
6198
+ name: "conditionId",
6061
6199
  type: "bytes32",
6062
6200
  internalType: "bytes32"
6063
6201
  }
@@ -6076,13 +6214,37 @@ var ConditionalTokens_default = [
6076
6214
  ],
6077
6215
  outputs: [
6078
6216
  {
6079
- name: "",
6217
+ name: "outcomeSlotCount",
6080
6218
  type: "uint256",
6081
6219
  internalType: "uint256"
6082
6220
  }
6083
6221
  ],
6084
6222
  stateMutability: "view"
6085
6223
  },
6224
+ {
6225
+ type: "function",
6226
+ name: "getPositionId",
6227
+ inputs: [
6228
+ {
6229
+ name: "collateralToken",
6230
+ type: "address",
6231
+ internalType: "contract IERC20"
6232
+ },
6233
+ {
6234
+ name: "collectionId",
6235
+ type: "bytes32",
6236
+ internalType: "bytes32"
6237
+ }
6238
+ ],
6239
+ outputs: [
6240
+ {
6241
+ name: "positionId",
6242
+ type: "uint256",
6243
+ internalType: "uint256"
6244
+ }
6245
+ ],
6246
+ stateMutability: "pure"
6247
+ },
6086
6248
  {
6087
6249
  type: "function",
6088
6250
  name: "mergePositions",
@@ -6116,6 +6278,49 @@ var ConditionalTokens_default = [
6116
6278
  outputs: [],
6117
6279
  stateMutability: "nonpayable"
6118
6280
  },
6281
+ {
6282
+ type: "function",
6283
+ name: "payoutDenominator",
6284
+ inputs: [
6285
+ {
6286
+ name: "conditionId",
6287
+ type: "bytes32",
6288
+ internalType: "bytes32"
6289
+ }
6290
+ ],
6291
+ outputs: [
6292
+ {
6293
+ name: "",
6294
+ type: "uint256",
6295
+ internalType: "uint256"
6296
+ }
6297
+ ],
6298
+ stateMutability: "view"
6299
+ },
6300
+ {
6301
+ type: "function",
6302
+ name: "payoutNumerators",
6303
+ inputs: [
6304
+ {
6305
+ name: "conditionId",
6306
+ type: "bytes32",
6307
+ internalType: "bytes32"
6308
+ },
6309
+ {
6310
+ name: "index",
6311
+ type: "uint256",
6312
+ internalType: "uint256"
6313
+ }
6314
+ ],
6315
+ outputs: [
6316
+ {
6317
+ name: "",
6318
+ type: "uint256",
6319
+ internalType: "uint256"
6320
+ }
6321
+ ],
6322
+ stateMutability: "view"
6323
+ },
6119
6324
  {
6120
6325
  type: "function",
6121
6326
  name: "prepareCondition",
@@ -6139,6 +6344,34 @@ var ConditionalTokens_default = [
6139
6344
  outputs: [],
6140
6345
  stateMutability: "nonpayable"
6141
6346
  },
6347
+ {
6348
+ type: "function",
6349
+ name: "redeemPositions",
6350
+ inputs: [
6351
+ {
6352
+ name: "collateralToken",
6353
+ type: "address",
6354
+ internalType: "contract IERC20"
6355
+ },
6356
+ {
6357
+ name: "parentCollectionId",
6358
+ type: "bytes32",
6359
+ internalType: "bytes32"
6360
+ },
6361
+ {
6362
+ name: "conditionId",
6363
+ type: "bytes32",
6364
+ internalType: "bytes32"
6365
+ },
6366
+ {
6367
+ name: "indexSets",
6368
+ type: "uint256[]",
6369
+ internalType: "uint256[]"
6370
+ }
6371
+ ],
6372
+ outputs: [],
6373
+ stateMutability: "nonpayable"
6374
+ },
6142
6375
  {
6143
6376
  type: "function",
6144
6377
  name: "reportPayouts",
@@ -6198,14 +6431,19 @@ var ERC20_default = [
6198
6431
  type: "constructor",
6199
6432
  inputs: [
6200
6433
  {
6201
- name: "name_",
6434
+ name: "_name",
6202
6435
  type: "string",
6203
6436
  internalType: "string"
6204
6437
  },
6205
6438
  {
6206
- name: "symbol_",
6439
+ name: "_symbol",
6207
6440
  type: "string",
6208
6441
  internalType: "string"
6442
+ },
6443
+ {
6444
+ name: "_decimals",
6445
+ type: "uint8",
6446
+ internalType: "uint8"
6209
6447
  }
6210
6448
  ],
6211
6449
  stateMutability: "nonpayable"
@@ -6215,12 +6453,12 @@ var ERC20_default = [
6215
6453
  name: "allowance",
6216
6454
  inputs: [
6217
6455
  {
6218
- name: "owner",
6456
+ name: "",
6219
6457
  type: "address",
6220
6458
  internalType: "address"
6221
6459
  },
6222
6460
  {
6223
- name: "spender",
6461
+ name: "",
6224
6462
  type: "address",
6225
6463
  internalType: "address"
6226
6464
  }
@@ -6263,7 +6501,7 @@ var ERC20_default = [
6263
6501
  name: "balanceOf",
6264
6502
  inputs: [
6265
6503
  {
6266
- name: "account",
6504
+ name: "",
6267
6505
  type: "address",
6268
6506
  internalType: "address"
6269
6507
  }
@@ -6292,50 +6530,20 @@ var ERC20_default = [
6292
6530
  },
6293
6531
  {
6294
6532
  type: "function",
6295
- name: "decreaseAllowance",
6296
- inputs: [
6297
- {
6298
- name: "spender",
6299
- type: "address",
6300
- internalType: "address"
6301
- },
6302
- {
6303
- name: "subtractedValue",
6304
- type: "uint256",
6305
- internalType: "uint256"
6306
- }
6307
- ],
6308
- outputs: [
6309
- {
6310
- name: "",
6311
- type: "bool",
6312
- internalType: "bool"
6313
- }
6314
- ],
6315
- stateMutability: "nonpayable"
6316
- },
6317
- {
6318
- type: "function",
6319
- name: "increaseAllowance",
6533
+ name: "mint",
6320
6534
  inputs: [
6321
6535
  {
6322
- name: "spender",
6536
+ name: "to",
6323
6537
  type: "address",
6324
6538
  internalType: "address"
6325
6539
  },
6326
6540
  {
6327
- name: "addedValue",
6541
+ name: "amount",
6328
6542
  type: "uint256",
6329
6543
  internalType: "uint256"
6330
6544
  }
6331
6545
  ],
6332
- outputs: [
6333
- {
6334
- name: "",
6335
- type: "bool",
6336
- internalType: "bool"
6337
- }
6338
- ],
6546
+ outputs: [],
6339
6547
  stateMutability: "nonpayable"
6340
6548
  },
6341
6549
  {
@@ -6626,6 +6834,33 @@ var VenueModule = class extends BaseModule {
6626
6834
  args: [user, venueId]
6627
6835
  });
6628
6836
  }
6837
+ // ---- Protocol Fee (owner-only) ----
6838
+ /**
6839
+ * Get the current protocol fee in basis points. Snapshotted per market at creation.
6840
+ */
6841
+ async getProtocolFeeBps() {
6842
+ return this.publicClient.readContract({
6843
+ address: this.config.diamondAddress,
6844
+ abi: ProtocolFacet_default,
6845
+ functionName: "getProtocolFeeBps"
6846
+ });
6847
+ }
6848
+ /**
6849
+ * Set the protocol fee in basis points. Owner-only. Max 200 bps (2%).
6850
+ * Only affects markets created after this call (existing markets retain their snapshot).
6851
+ */
6852
+ async setProtocolFeeBps(bps) {
6853
+ const wallet = this.walletClient;
6854
+ const [account] = await wallet.getAddresses();
6855
+ const { request } = await this.publicClient.simulateContract({
6856
+ address: this.config.diamondAddress,
6857
+ abi: ProtocolFacet_default,
6858
+ functionName: "setProtocolFeeBps",
6859
+ args: [bps],
6860
+ account
6861
+ });
6862
+ return wallet.writeContract(request);
6863
+ }
6629
6864
  };
6630
6865
  var TICK_SIZE_STANDARD = 10000000000000000n;
6631
6866
  var TICK_SIZE_FINE = 1000000000000000n;
@@ -6742,6 +6977,72 @@ function getOutcomePrice(market, outcomeIndex) {
6742
6977
  const yesPercent = tickToPercentage(yesTick, tickSize);
6743
6978
  return outcomeIndex === 0 ? yesPercent : 100 - yesPercent;
6744
6979
  }
6980
+ var MARK_PRICE_SPREAD_THRESHOLD = 0.1;
6981
+ function calculateChancePercent(market) {
6982
+ const tickSizeNum = parseFloat(market.tickSize || "0");
6983
+ if (tickSizeNum === 0) return 50;
6984
+ if (market.status === "Resolved" && market.resolvedOutcome != null) {
6985
+ return parseInt(String(market.resolvedOutcome)) === 0 ? 100 : 0;
6986
+ }
6987
+ const maxTicks = 1e18 / tickSizeNum;
6988
+ if (market.topOfBook && market.topOfBook.length > 0) {
6989
+ const tob = parseTopOfBook(market.topOfBook);
6990
+ const result = computeImpliedMidpoint(tob, maxTicks, tickSizeNum);
6991
+ if (result !== null) return result;
6992
+ }
6993
+ return lastTradeFallback(market, tickSizeNum);
6994
+ }
6995
+ function parseTopOfBook(entries) {
6996
+ const result = { yesBid: 0, yesAsk: 0, noBid: 0, noAsk: 0 };
6997
+ for (const entry of entries) {
6998
+ const tick = parseFloat(entry.topTick || "0");
6999
+ const outcome = entry.outcome?.toString();
7000
+ const side = entry.side;
7001
+ if (outcome === "0" && side === "BUY") result.yesBid = tick;
7002
+ else if (outcome === "0" && side === "SELL") result.yesAsk = tick;
7003
+ else if (outcome === "1" && side === "BUY") result.noBid = tick;
7004
+ else if (outcome === "1" && side === "SELL") result.noAsk = tick;
7005
+ }
7006
+ return result;
7007
+ }
7008
+ function computeImpliedMidpoint(tob, maxTicks, tickSize) {
7009
+ const bidCandidates = [];
7010
+ if (tob.yesBid > 0) bidCandidates.push(tob.yesBid);
7011
+ if (tob.noAsk > 0) bidCandidates.push(maxTicks - tob.noAsk);
7012
+ const askCandidates = [];
7013
+ if (tob.yesAsk > 0) askCandidates.push(tob.yesAsk);
7014
+ if (tob.noBid > 0) askCandidates.push(maxTicks - tob.noBid);
7015
+ if (bidCandidates.length === 0 || askCandidates.length === 0) return null;
7016
+ const impliedBid = Math.max(...bidCandidates);
7017
+ const impliedAsk = Math.min(...askCandidates);
7018
+ const spreadDollars = (impliedAsk - impliedBid) * tickSize / 1e18;
7019
+ if (spreadDollars > MARK_PRICE_SPREAD_THRESHOLD) return null;
7020
+ const midTick = (impliedBid + impliedAsk) / 2;
7021
+ const percent = midTick * tickSize / 1e18 * 100;
7022
+ return parseFloat(Math.max(0, Math.min(100, percent)).toFixed(2));
7023
+ }
7024
+ function lastTradeFallback(market, tickSize) {
7025
+ const tick0 = parseFloat(market.lastPriceTick_0 || "0");
7026
+ const tick1 = parseFloat(market.lastPriceTick_1 || "0");
7027
+ const ts0 = parseFloat(market.lastTradeTimestamp_0 || "0");
7028
+ const ts1 = parseFloat(market.lastTradeTimestamp_1 || "0");
7029
+ if (tick0 > 0 && tick1 > 0) {
7030
+ if (ts0 > 0 || ts1 > 0) {
7031
+ if (ts0 >= ts1) {
7032
+ return parseFloat((tick0 * tickSize / 1e18 * 100).toFixed(2));
7033
+ }
7034
+ return parseFloat(((1 - tick1 * tickSize / 1e18) * 100).toFixed(2));
7035
+ }
7036
+ return parseFloat((tick0 * tickSize / 1e18 * 100).toFixed(2));
7037
+ }
7038
+ if (tick0 > 0) {
7039
+ return parseFloat((tick0 * tickSize / 1e18 * 100).toFixed(2));
7040
+ }
7041
+ if (tick1 > 0) {
7042
+ return parseFloat(((1 - tick1 * tickSize / 1e18) * 100).toFixed(2));
7043
+ }
7044
+ return 50;
7045
+ }
6745
7046
 
6746
7047
  // src/utils/decimals.ts
6747
7048
  async function getTokenDecimals(publicClient, token) {
@@ -6818,17 +7119,19 @@ var MarketModule = class extends BaseModule {
6818
7119
  functionName: "getVenue",
6819
7120
  args: [params.venueId]
6820
7121
  });
6821
- const feeRequired = venue.marketCreationFee;
6822
- if (feeRequired > 0n) {
7122
+ const feeRequired = BigInt(venue.marketCreationFee);
7123
+ const reward = BigInt(venue.umaRewardAmount) + (params.additionalReward ?? 0n);
7124
+ const totalRequired = feeRequired + reward;
7125
+ if (totalRequired > 0n) {
6823
7126
  const allowance = await this.publicClient.readContract({
6824
7127
  address: params.collateralToken,
6825
7128
  abi: viem.erc20Abi,
6826
7129
  functionName: "allowance",
6827
7130
  args: [account, this.config.diamondAddress]
6828
7131
  });
6829
- if (allowance < feeRequired) {
7132
+ if (allowance < totalRequired) {
6830
7133
  throw new Error(
6831
- `Insufficient allowance for Market Creation Fee. Approved: ${allowance.toString()}, Required: ${feeRequired.toString()}. Please approve the Diamond (${this.config.diamondAddress}).`
7134
+ `Insufficient allowance. Approved: ${allowance.toString()}, Required: ${totalRequired.toString()} (fee: ${feeRequired.toString()}, reward: ${reward.toString()}). Please approve the Diamond (${this.config.diamondAddress}).`
6832
7135
  );
6833
7136
  }
6834
7137
  const balance = await this.publicClient.readContract({
@@ -6837,9 +7140,9 @@ var MarketModule = class extends BaseModule {
6837
7140
  functionName: "balanceOf",
6838
7141
  args: [account]
6839
7142
  });
6840
- if (balance < feeRequired) {
7143
+ if (balance < totalRequired) {
6841
7144
  throw new Error(
6842
- `Insufficient collateral balance for Market Creation Fee. Have: ${balance.toString()}, Required: ${feeRequired.toString()}. Please acquire more tokens.`
7145
+ `Insufficient collateral balance. Have: ${balance.toString()}, Required: ${totalRequired.toString()} (fee: ${feeRequired.toString()}, reward: ${reward.toString()}).`
6843
7146
  );
6844
7147
  }
6845
7148
  }
@@ -7085,17 +7388,19 @@ var MarketModule = class extends BaseModule {
7085
7388
  functionName: "getVenue",
7086
7389
  args: [params.venueId]
7087
7390
  });
7088
- const feeRequired = venue.marketCreationFee;
7089
- if (feeRequired > 0n) {
7391
+ const feeRequired = BigInt(venue.marketCreationFee);
7392
+ const reward = BigInt(venue.umaRewardAmount) + (params.additionalReward ?? 0n);
7393
+ const totalRequired = feeRequired + reward;
7394
+ if (totalRequired > 0n) {
7090
7395
  const allowance = await this.publicClient.readContract({
7091
7396
  address: params.collateralToken,
7092
7397
  abi: viem.erc20Abi,
7093
7398
  functionName: "allowance",
7094
7399
  args: [account, this.config.diamondAddress]
7095
7400
  });
7096
- if (allowance < feeRequired) {
7401
+ if (allowance < totalRequired) {
7097
7402
  throw new Error(
7098
- `Insufficient allowance for Market Group Creation Fee. Approved: ${allowance.toString()}, Required: ${feeRequired.toString()}. Please approve the Diamond (${this.config.diamondAddress}).`
7403
+ `Insufficient allowance. Approved: ${allowance.toString()}, Required: ${totalRequired.toString()} (fee: ${feeRequired.toString()}, reward: ${reward.toString()}). Please approve the Diamond (${this.config.diamondAddress}).`
7099
7404
  );
7100
7405
  }
7101
7406
  const balance = await this.publicClient.readContract({
@@ -7104,9 +7409,9 @@ var MarketModule = class extends BaseModule {
7104
7409
  functionName: "balanceOf",
7105
7410
  args: [account]
7106
7411
  });
7107
- if (balance < feeRequired) {
7412
+ if (balance < totalRequired) {
7108
7413
  throw new Error(
7109
- `Insufficient collateral balance for Market Group Creation Fee. Have: ${balance.toString()}, Required: ${feeRequired.toString()}.`
7414
+ `Insufficient collateral balance. Have: ${balance.toString()}, Required: ${totalRequired.toString()} (fee: ${feeRequired.toString()}, reward: ${reward.toString()}).`
7110
7415
  );
7111
7416
  }
7112
7417
  }
@@ -7635,6 +7940,80 @@ var TradeModule = class extends BaseModule {
7635
7940
  });
7636
7941
  return result;
7637
7942
  }
7943
+ /**
7944
+ * Execute a market sell order (FOK or FAK)
7945
+ *
7946
+ * @param params.marketId - The market to sell on
7947
+ * @param params.outcomeId - Which outcome to sell (0=YES, 1=NO)
7948
+ * @param params.tokenAmount - Amount of outcome tokens to sell
7949
+ * @param params.minPriceTick - Minimum price tick willing to accept (slippage protection)
7950
+ * @param params.orderType - 0=FOK (Fill-Or-Kill), 1=FAK (Fill-And-Kill)
7951
+ */
7952
+ async placeMarketSell(params) {
7953
+ const wallet = this.walletClient;
7954
+ const [account] = await wallet.getAddresses();
7955
+ const { request } = await this.publicClient.simulateContract({
7956
+ address: this.config.diamondAddress,
7957
+ abi: MarketOrdersFacet_default,
7958
+ functionName: "placeMarketSell",
7959
+ args: [
7960
+ params.marketId,
7961
+ params.outcomeId,
7962
+ params.tokenAmount,
7963
+ params.minPriceTick,
7964
+ params.orderType
7965
+ ],
7966
+ account
7967
+ });
7968
+ return wallet.writeContract(request);
7969
+ }
7970
+ /**
7971
+ * Execute a market sell order with simple string inputs (recommended for frontends)
7972
+ * @param params.amount - Token amount as decimal string (e.g., "100.5")
7973
+ * @param params.minPrice - Minimum price as decimal string (e.g., "0.70")
7974
+ * @param params.orderType - 'FOK' or 'FAK' (default: 'FAK')
7975
+ */
7976
+ async placeMarketSellSimple(params) {
7977
+ const tradingData = await this.publicClient.readContract({
7978
+ address: this.config.diamondAddress,
7979
+ abi: MarketsFacet_default,
7980
+ functionName: "getMarketTradingData",
7981
+ args: [params.marketId]
7982
+ });
7983
+ const collateralToken = tradingData.collateralToken;
7984
+ const decimals = await getCachedTokenDecimals(this.publicClient, collateralToken);
7985
+ const tokenAmount = parseTokenAmount(params.amount, decimals);
7986
+ const minPriceTick = priceToTick(params.minPrice);
7987
+ const orderType = params.orderType === "FOK" ? 0 : 1;
7988
+ return this.placeMarketSell({
7989
+ marketId: params.marketId,
7990
+ outcomeId: params.outcomeId,
7991
+ tokenAmount,
7992
+ minPriceTick,
7993
+ orderType
7994
+ });
7995
+ }
7996
+ /**
7997
+ * Preview a market sell order (simulate transaction)
7998
+ */
7999
+ async previewMarketSell(params) {
8000
+ const wallet = this.walletClient;
8001
+ const [account] = await wallet.getAddresses();
8002
+ const { result } = await this.publicClient.simulateContract({
8003
+ address: this.config.diamondAddress,
8004
+ abi: MarketOrdersFacet_default,
8005
+ functionName: "placeMarketSell",
8006
+ args: [
8007
+ params.marketId,
8008
+ params.outcomeId,
8009
+ params.tokenAmount,
8010
+ params.minPriceTick,
8011
+ params.orderType
8012
+ ],
8013
+ account
8014
+ });
8015
+ return result;
8016
+ }
7638
8017
  /**
7639
8018
  * Watch for MarketOrderExecuted events
7640
8019
  */
@@ -7647,6 +8026,18 @@ var TradeModule = class extends BaseModule {
7647
8026
  onLogs
7648
8027
  });
7649
8028
  }
8029
+ /**
8030
+ * Watch for MarketSellExecuted events
8031
+ */
8032
+ watchMarketSell(marketId, onLogs) {
8033
+ return this.publicClient.watchContractEvent({
8034
+ address: this.config.diamondAddress,
8035
+ abi: MarketOrdersFacet_default,
8036
+ eventName: "MarketSellExecuted",
8037
+ args: { marketId },
8038
+ onLogs
8039
+ });
8040
+ }
7650
8041
  /**
7651
8042
  * Check whether any orders are matchable in the given market.
7652
8043
  * Returns a preview of which fill paths have crossing conditions,
@@ -7961,6 +8352,13 @@ var GET_MARKETS = graphqlRequest.gql`
7961
8352
  lastPriceTick_0
7962
8353
  lastPriceTick_1
7963
8354
  lastTradeTimestamp
8355
+ lastTradeTimestamp_0
8356
+ lastTradeTimestamp_1
8357
+ topOfBook {
8358
+ outcome
8359
+ side
8360
+ topTick
8361
+ }
7964
8362
  tags
7965
8363
  metadataURI
7966
8364
  }
@@ -7991,6 +8389,14 @@ var GET_MARKETS_WITH_PRICING = graphqlRequest.gql`
7991
8389
  lastPriceTick_0
7992
8390
  lastPriceTick_1
7993
8391
  lastTradeTimestamp
8392
+ lastTradeTimestamp_0
8393
+ lastTradeTimestamp_1
8394
+ # Top of book for mark price calculation
8395
+ topOfBook {
8396
+ outcome
8397
+ side
8398
+ topTick
8399
+ }
7994
8400
  # Statistics
7995
8401
  totalVolume
7996
8402
  totalOrders
@@ -8008,12 +8414,20 @@ var GET_MARKET = graphqlRequest.gql`
8008
8414
  question
8009
8415
  outcomes
8010
8416
  status
8417
+ resolvedOutcome
8011
8418
  collateralToken
8012
8419
  conditionId
8013
8420
  tickSize
8014
8421
  lastPriceTick_0
8015
8422
  lastPriceTick_1
8016
8423
  lastTradeTimestamp
8424
+ lastTradeTimestamp_0
8425
+ lastTradeTimestamp_1
8426
+ topOfBook {
8427
+ outcome
8428
+ side
8429
+ topTick
8430
+ }
8017
8431
  totalVolume
8018
8432
  totalOrders
8019
8433
  totalFees
@@ -8253,6 +8667,7 @@ var GET_MARKET_GROUPS = graphqlRequest.gql`
8253
8667
  totalMarkets
8254
8668
  activeMarketCount
8255
8669
  resolvedMarketId
8670
+ reward
8256
8671
  tags
8257
8672
  metadataURI
8258
8673
  venue {
@@ -8312,6 +8727,7 @@ var GET_GROUP_MARKETS = graphqlRequest.gql`
8312
8727
  question
8313
8728
  outcomes
8314
8729
  status
8730
+ resolvedOutcome
8315
8731
  collateralToken
8316
8732
  conditionId
8317
8733
  tickSize
@@ -8325,6 +8741,13 @@ var GET_GROUP_MARKETS = graphqlRequest.gql`
8325
8741
  lastPriceTick_0
8326
8742
  lastPriceTick_1
8327
8743
  lastTradeTimestamp
8744
+ lastTradeTimestamp_0
8745
+ lastTradeTimestamp_1
8746
+ topOfBook {
8747
+ outcome
8748
+ side
8749
+ topTick
8750
+ }
8328
8751
  totalVolume
8329
8752
  totalOrders
8330
8753
  createdAt
@@ -8380,6 +8803,13 @@ var GET_UNIFIED_MARKET_FEED = graphqlRequest.gql`
8380
8803
  lastPriceTick_0
8381
8804
  lastPriceTick_1
8382
8805
  lastTradeTimestamp
8806
+ lastTradeTimestamp_0
8807
+ lastTradeTimestamp_1
8808
+ topOfBook {
8809
+ outcome
8810
+ side
8811
+ topTick
8812
+ }
8383
8813
  # Statistics
8384
8814
  totalVolume
8385
8815
  totalOrders
@@ -8472,8 +8902,17 @@ var GET_UNIFIED_MARKET_FEED_BY_VOLUME = graphqlRequest.gql`
8472
8902
  status
8473
8903
  collateralToken
8474
8904
  groupId
8905
+ tickSize
8475
8906
  lastPriceTick_0
8476
8907
  lastPriceTick_1
8908
+ lastTradeTimestamp
8909
+ lastTradeTimestamp_0
8910
+ lastTradeTimestamp_1
8911
+ topOfBook {
8912
+ outcome
8913
+ side
8914
+ topTick
8915
+ }
8477
8916
  totalVolume
8478
8917
  totalOrders
8479
8918
  uniqueTraders
@@ -8500,17 +8939,28 @@ var GET_UNIFIED_MARKET_FEED_BY_VOLUME = graphqlRequest.gql`
8500
8939
  marketQuestion
8501
8940
  status
8502
8941
  totalMarkets
8942
+ activeMarketCount
8943
+ resolvedMarketId
8503
8944
  tags
8504
8945
  metadataURI
8505
- resolvedMarketId
8506
8946
  createdAt
8947
+ activatedAt
8948
+ resolvedAt
8507
8949
  venue {
8508
8950
  id
8509
8951
  venueId
8510
8952
  name
8511
8953
  }
8954
+ creator {
8955
+ id
8956
+ address
8957
+ }
8512
8958
  markets {
8959
+ id
8513
8960
  marketId
8961
+ question
8962
+ status
8963
+ groupId
8514
8964
  tickSize
8515
8965
  lastPriceTick_0
8516
8966
  lastPriceTick_1
@@ -8545,6 +8995,13 @@ var GET_ALL_MARKETS_FEED = graphqlRequest.gql`
8545
8995
  lastPriceTick_0
8546
8996
  lastPriceTick_1
8547
8997
  lastTradeTimestamp
8998
+ lastTradeTimestamp_0
8999
+ lastTradeTimestamp_1
9000
+ topOfBook {
9001
+ outcome
9002
+ side
9003
+ topTick
9004
+ }
8548
9005
  totalVolume
8549
9006
  totalOrders
8550
9007
  uniqueTraders
@@ -8626,9 +9083,19 @@ var GET_ALL_MARKETS_FEED_BY_VOLUME = graphqlRequest.gql`
8626
9083
  outcomes
8627
9084
  status
8628
9085
  collateralToken
9086
+ conditionId
9087
+ tickSize
8629
9088
  groupId
8630
9089
  lastPriceTick_0
8631
9090
  lastPriceTick_1
9091
+ lastTradeTimestamp
9092
+ lastTradeTimestamp_0
9093
+ lastTradeTimestamp_1
9094
+ topOfBook {
9095
+ outcome
9096
+ side
9097
+ topTick
9098
+ }
8632
9099
  totalVolume
8633
9100
  totalOrders
8634
9101
  uniqueTraders
@@ -8639,6 +9106,10 @@ var GET_ALL_MARKETS_FEED_BY_VOLUME = graphqlRequest.gql`
8639
9106
  venueId
8640
9107
  name
8641
9108
  }
9109
+ creator {
9110
+ id
9111
+ address
9112
+ }
8642
9113
  }
8643
9114
 
8644
9115
  marketGroups(
@@ -8653,16 +9124,28 @@ var GET_ALL_MARKETS_FEED_BY_VOLUME = graphqlRequest.gql`
8653
9124
  marketQuestion
8654
9125
  status
8655
9126
  totalMarkets
8656
- metadataURI
9127
+ activeMarketCount
8657
9128
  resolvedMarketId
9129
+ metadataURI
8658
9130
  createdAt
9131
+ activatedAt
9132
+ resolvedAt
8659
9133
  venue {
8660
9134
  id
8661
9135
  venueId
8662
9136
  name
8663
9137
  }
9138
+ creator {
9139
+ id
9140
+ address
9141
+ }
8664
9142
  markets {
9143
+ id
8665
9144
  marketId
9145
+ question
9146
+ status
9147
+ groupId
9148
+ tickSize
8666
9149
  lastPriceTick_0
8667
9150
  lastPriceTick_1
8668
9151
  totalVolume
@@ -8686,6 +9169,7 @@ var GET_RECENT_TRADES = graphqlRequest.gql`
8686
9169
  market {
8687
9170
  marketId
8688
9171
  question
9172
+ outcomes
8689
9173
  venue {
8690
9174
  venueId
8691
9175
  name
@@ -9132,20 +9616,21 @@ var PublicModule = class extends BaseModule {
9132
9616
  return limit ? merged.slice(0, limit) : merged;
9133
9617
  }
9134
9618
  /**
9135
- * Calculate probability for a market using last trade price
9619
+ * Calculate probability for a market using mark price waterfall.
9136
9620
  * Returns probability as a decimal string (e.g., "0.65" for 65%)
9137
9621
  *
9138
- * @param market - Market object from subgraph
9622
+ * Uses Polymarket-style pricing: implied midpoint → last trade → default 50%.
9623
+ *
9624
+ * @param market - Market object from subgraph (with topOfBook and timestamp fields)
9139
9625
  * @returns Probability string or null if no data available
9140
9626
  */
9141
9627
  calculateMarketProbability(market) {
9142
- if (market.lastPriceTick_0 && market.tickSize) {
9143
- const tick = BigInt(market.lastPriceTick_0);
9144
- const tickSize = BigInt(market.tickSize);
9145
- const price = Number(tick * tickSize) / 1e18;
9146
- return price.toFixed(2);
9628
+ if (!market.tickSize) return null;
9629
+ const chance = calculateChancePercent(market);
9630
+ if (chance === 50 && !market.lastPriceTick_0 && !market.lastPriceTick_1) {
9631
+ return null;
9147
9632
  }
9148
- return null;
9633
+ return (chance / 100).toFixed(2);
9149
9634
  }
9150
9635
  /**
9151
9636
  * Format market group for display (Polymarket-style)
@@ -9374,6 +9859,15 @@ var TokenModule = class extends BaseModule {
9374
9859
  });
9375
9860
  }
9376
9861
  };
9862
+ var optimisticOracleV3Abi = [
9863
+ {
9864
+ inputs: [{ name: "currency", type: "address" }],
9865
+ name: "getMinimumBond",
9866
+ outputs: [{ name: "", type: "uint256" }],
9867
+ stateMutability: "view",
9868
+ type: "function"
9869
+ }
9870
+ ];
9377
9871
  var UmaModule = class extends BaseModule {
9378
9872
  /**
9379
9873
  * Assert an outcome for a market question
@@ -9395,14 +9889,8 @@ var UmaModule = class extends BaseModule {
9395
9889
  args: [params.marketId]
9396
9890
  });
9397
9891
  const questionId = registryData.questionId;
9398
- const oracleData = await this.publicClient.readContract({
9399
- address: this.config.diamondAddress,
9400
- abi: MarketsFacet_default,
9401
- functionName: "getMarketOracleData",
9402
- args: [params.marketId]
9403
- });
9404
- const bondAmount = BigInt(oracleData.requiredBond);
9405
- const currency = oracleData.currency;
9892
+ const { effectiveBond, currency } = await this.getEffectiveBond(params.marketId);
9893
+ const bondAmount = effectiveBond;
9406
9894
  const currentAllowance = await this.publicClient.readContract({
9407
9895
  address: currency,
9408
9896
  abi: viem.erc20Abi,
@@ -9459,6 +9947,33 @@ var UmaModule = class extends BaseModule {
9459
9947
  });
9460
9948
  return wallet.writeContract(request);
9461
9949
  }
9950
+ /**
9951
+ * Get the effective bond for a market, accounting for UMA's minimum bond.
9952
+ * The contract uses max(requiredBond, oo.getMinimumBond(currency)).
9953
+ */
9954
+ async getEffectiveBond(marketId) {
9955
+ const oracleData = await this.publicClient.readContract({
9956
+ address: this.config.diamondAddress,
9957
+ abi: MarketsFacet_default,
9958
+ functionName: "getMarketOracleData",
9959
+ args: [marketId]
9960
+ });
9961
+ const requiredBond = BigInt(oracleData.requiredBond);
9962
+ const currency = oracleData.currency;
9963
+ const umaOracle = await this.publicClient.readContract({
9964
+ address: this.config.diamondAddress,
9965
+ abi: ProtocolFacet_default,
9966
+ functionName: "getUmaOracle"
9967
+ });
9968
+ const minimumBond = await this.publicClient.readContract({
9969
+ address: umaOracle,
9970
+ abi: optimisticOracleV3Abi,
9971
+ functionName: "getMinimumBond",
9972
+ args: [currency]
9973
+ });
9974
+ const effectiveBond = requiredBond > minimumBond ? requiredBond : minimumBond;
9975
+ return { requiredBond, minimumBond, effectiveBond, currency };
9976
+ }
9462
9977
  /**
9463
9978
  * Settle an assertion after the liveness period
9464
9979
  */
@@ -10246,11 +10761,19 @@ function createOddMakiClient(params) {
10246
10761
 
10247
10762
  // src/constants.ts
10248
10763
  var PROTOCOL_FEES = {
10249
- /** Protocol fee: 20 bps (0.20%) */
10250
- PROTOCOL_FEE_BPS: 20n,
10764
+ /** Protocol fee: 50 bps (0.50%) — configurable via ProtocolFacet.setProtocolFeeBps() */
10765
+ PROTOCOL_FEE_BPS: 50n,
10251
10766
  /** Operator fee: 10 bps (0.10%) for match operators */
10252
10767
  OPERATOR_FEE_BPS: 10n
10253
10768
  };
10769
+ var UMA_DEFAULTS = {
10770
+ /** Recommended reward: 5 USDC. Incentivizes third-party resolution. */
10771
+ REWARD_USDC: 5000000n,
10772
+ /** Recommended minimum bond: 750 USDC. Matches Polymarket's production bond. */
10773
+ MIN_BOND_USDC: 750000000n,
10774
+ /** Default liveness period: 2 hours (7200 seconds). */
10775
+ LIVENESS: 7200n
10776
+ };
10254
10777
 
10255
10778
  // src/utils/metadata.ts
10256
10779
  var DEFAULT_IPFS_GATEWAY = "https://gateway.pinata.cloud/ipfs/";
@@ -10338,12 +10861,14 @@ exports.TICK_SIZE_STANDARD = TICK_SIZE_STANDARD;
10338
10861
  exports.TagsFacetABI = TagsFacet_default;
10339
10862
  exports.TokenModule = TokenModule;
10340
10863
  exports.TradeModule = TradeModule;
10864
+ exports.UMA_DEFAULTS = UMA_DEFAULTS;
10341
10865
  exports.UmaModule = UmaModule;
10342
10866
  exports.VALID_TICK_SIZES = VALID_TICK_SIZES;
10343
10867
  exports.VaultFacetABI = VaultFacet_default;
10344
10868
  exports.VenueFacetABI = VenueFacet_default;
10345
10869
  exports.VenueModule = VenueModule;
10346
10870
  exports.WhitelistAccessControlABI = WhitelistAccessControl_default;
10871
+ exports.calculateChancePercent = calculateChancePercent;
10347
10872
  exports.clearDecimalsCache = clearDecimalsCache;
10348
10873
  exports.createExpiry = createExpiry;
10349
10874
  exports.createOddMakiClient = createOddMakiClient;