@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.mjs CHANGED
@@ -592,6 +592,11 @@ var VenueFacet_default = [
592
592
  name: "InvalidTickSize",
593
593
  inputs: []
594
594
  },
595
+ {
596
+ type: "error",
597
+ name: "InvalidUmaMinBond",
598
+ inputs: []
599
+ },
595
600
  {
596
601
  type: "error",
597
602
  name: "InvalidVenueFee",
@@ -907,6 +912,11 @@ var MarketsFacet_default = [
907
912
  name: "creatorFeeBps",
908
913
  type: "uint256",
909
914
  internalType: "uint256"
915
+ },
916
+ {
917
+ name: "protocolFeeBps",
918
+ type: "uint256",
919
+ internalType: "uint256"
910
920
  }
911
921
  ]
912
922
  }
@@ -1997,6 +2007,25 @@ var MatchingFacet_default = [
1997
2007
  ],
1998
2008
  anonymous: false
1999
2009
  },
2010
+ {
2011
+ type: "event",
2012
+ name: "OrderAutoCancelled",
2013
+ inputs: [
2014
+ {
2015
+ name: "orderId",
2016
+ type: "uint256",
2017
+ indexed: true,
2018
+ internalType: "uint256"
2019
+ },
2020
+ {
2021
+ name: "refundedCollateral",
2022
+ type: "uint256",
2023
+ indexed: false,
2024
+ internalType: "uint256"
2025
+ }
2026
+ ],
2027
+ anonymous: false
2028
+ },
2000
2029
  {
2001
2030
  type: "event",
2002
2031
  name: "OrderDeleted",
@@ -2750,6 +2779,11 @@ var MarketGroupFacet_default = [
2750
2779
  name: "liveness",
2751
2780
  type: "uint64",
2752
2781
  internalType: "uint64"
2782
+ },
2783
+ {
2784
+ name: "reward",
2785
+ type: "uint256",
2786
+ internalType: "uint256"
2753
2787
  }
2754
2788
  ]
2755
2789
  }
@@ -2895,6 +2929,12 @@ var MarketGroupFacet_default = [
2895
2929
  type: "bytes32[]",
2896
2930
  indexed: false,
2897
2931
  internalType: "bytes32[]"
2932
+ },
2933
+ {
2934
+ name: "reward",
2935
+ type: "uint256",
2936
+ indexed: false,
2937
+ internalType: "uint256"
2898
2938
  }
2899
2939
  ],
2900
2940
  anonymous: false
@@ -3485,6 +3525,11 @@ var ResolutionFacet_default = [
3485
3525
  name: "settled",
3486
3526
  type: "bool",
3487
3527
  internalType: "bool"
3528
+ },
3529
+ {
3530
+ name: "asserter",
3531
+ type: "address",
3532
+ internalType: "address"
3488
3533
  }
3489
3534
  ]
3490
3535
  }
@@ -3673,6 +3718,31 @@ var ResolutionFacet_default = [
3673
3718
  ],
3674
3719
  anonymous: false
3675
3720
  },
3721
+ {
3722
+ type: "event",
3723
+ name: "RewardPaid",
3724
+ inputs: [
3725
+ {
3726
+ name: "assertionId",
3727
+ type: "bytes32",
3728
+ indexed: true,
3729
+ internalType: "bytes32"
3730
+ },
3731
+ {
3732
+ name: "asserter",
3733
+ type: "address",
3734
+ indexed: true,
3735
+ internalType: "address"
3736
+ },
3737
+ {
3738
+ name: "reward",
3739
+ type: "uint256",
3740
+ indexed: false,
3741
+ internalType: "uint256"
3742
+ }
3743
+ ],
3744
+ anonymous: false
3745
+ },
3676
3746
  {
3677
3747
  type: "error",
3678
3748
  name: "ApproveFailed",
@@ -3723,6 +3793,11 @@ var ResolutionFacet_default = [
3723
3793
  name: "OutcomeMismatch",
3724
3794
  inputs: []
3725
3795
  },
3796
+ {
3797
+ type: "error",
3798
+ name: "TransferFailed",
3799
+ inputs: []
3800
+ },
3726
3801
  {
3727
3802
  type: "error",
3728
3803
  name: "TransferFromFailed",
@@ -4021,6 +4096,19 @@ var NegRiskFacet_default = [
4021
4096
 
4022
4097
  // src/contracts/abis/ProtocolFacet.json
4023
4098
  var ProtocolFacet_default = [
4099
+ {
4100
+ type: "function",
4101
+ name: "getProtocolFeeBps",
4102
+ inputs: [],
4103
+ outputs: [
4104
+ {
4105
+ name: "",
4106
+ type: "uint256",
4107
+ internalType: "uint256"
4108
+ }
4109
+ ],
4110
+ stateMutability: "view"
4111
+ },
4024
4112
  {
4025
4113
  type: "function",
4026
4114
  name: "getProtocolPaused",
@@ -4136,6 +4224,19 @@ var ProtocolFacet_default = [
4136
4224
  outputs: [],
4137
4225
  stateMutability: "nonpayable"
4138
4226
  },
4227
+ {
4228
+ type: "function",
4229
+ name: "setProtocolFeeBps",
4230
+ inputs: [
4231
+ {
4232
+ name: "bps",
4233
+ type: "uint256",
4234
+ internalType: "uint256"
4235
+ }
4236
+ ],
4237
+ outputs: [],
4238
+ stateMutability: "nonpayable"
4239
+ },
4139
4240
  {
4140
4241
  type: "function",
4141
4242
  name: "setProtocolTreasury",
@@ -4307,6 +4408,19 @@ var ProtocolFacet_default = [
4307
4408
  ],
4308
4409
  anonymous: false
4309
4410
  },
4411
+ {
4412
+ type: "event",
4413
+ name: "ProtocolFeeBpsUpdated",
4414
+ inputs: [
4415
+ {
4416
+ name: "bps",
4417
+ type: "uint256",
4418
+ indexed: false,
4419
+ internalType: "uint256"
4420
+ }
4421
+ ],
4422
+ anonymous: false
4423
+ },
4310
4424
  {
4311
4425
  type: "event",
4312
4426
  name: "ProtocolPausedEvent",
@@ -6004,6 +6118,30 @@ var WhitelistAccessControl_default = [
6004
6118
 
6005
6119
  // src/contracts/abis/ConditionalTokens.json
6006
6120
  var ConditionalTokens_default = [
6121
+ {
6122
+ type: "function",
6123
+ name: "balanceOf",
6124
+ inputs: [
6125
+ {
6126
+ name: "account",
6127
+ type: "address",
6128
+ internalType: "address"
6129
+ },
6130
+ {
6131
+ name: "id",
6132
+ type: "uint256",
6133
+ internalType: "uint256"
6134
+ }
6135
+ ],
6136
+ outputs: [
6137
+ {
6138
+ name: "",
6139
+ type: "uint256",
6140
+ internalType: "uint256"
6141
+ }
6142
+ ],
6143
+ stateMutability: "view"
6144
+ },
6007
6145
  {
6008
6146
  type: "function",
6009
6147
  name: "getCollectionId",
@@ -6026,7 +6164,7 @@ var ConditionalTokens_default = [
6026
6164
  ],
6027
6165
  outputs: [
6028
6166
  {
6029
- name: "",
6167
+ name: "collectionId",
6030
6168
  type: "bytes32",
6031
6169
  internalType: "bytes32"
6032
6170
  }
@@ -6055,7 +6193,7 @@ var ConditionalTokens_default = [
6055
6193
  ],
6056
6194
  outputs: [
6057
6195
  {
6058
- name: "",
6196
+ name: "conditionId",
6059
6197
  type: "bytes32",
6060
6198
  internalType: "bytes32"
6061
6199
  }
@@ -6074,13 +6212,37 @@ var ConditionalTokens_default = [
6074
6212
  ],
6075
6213
  outputs: [
6076
6214
  {
6077
- name: "",
6215
+ name: "outcomeSlotCount",
6078
6216
  type: "uint256",
6079
6217
  internalType: "uint256"
6080
6218
  }
6081
6219
  ],
6082
6220
  stateMutability: "view"
6083
6221
  },
6222
+ {
6223
+ type: "function",
6224
+ name: "getPositionId",
6225
+ inputs: [
6226
+ {
6227
+ name: "collateralToken",
6228
+ type: "address",
6229
+ internalType: "contract IERC20"
6230
+ },
6231
+ {
6232
+ name: "collectionId",
6233
+ type: "bytes32",
6234
+ internalType: "bytes32"
6235
+ }
6236
+ ],
6237
+ outputs: [
6238
+ {
6239
+ name: "positionId",
6240
+ type: "uint256",
6241
+ internalType: "uint256"
6242
+ }
6243
+ ],
6244
+ stateMutability: "pure"
6245
+ },
6084
6246
  {
6085
6247
  type: "function",
6086
6248
  name: "mergePositions",
@@ -6114,6 +6276,49 @@ var ConditionalTokens_default = [
6114
6276
  outputs: [],
6115
6277
  stateMutability: "nonpayable"
6116
6278
  },
6279
+ {
6280
+ type: "function",
6281
+ name: "payoutDenominator",
6282
+ inputs: [
6283
+ {
6284
+ name: "conditionId",
6285
+ type: "bytes32",
6286
+ internalType: "bytes32"
6287
+ }
6288
+ ],
6289
+ outputs: [
6290
+ {
6291
+ name: "",
6292
+ type: "uint256",
6293
+ internalType: "uint256"
6294
+ }
6295
+ ],
6296
+ stateMutability: "view"
6297
+ },
6298
+ {
6299
+ type: "function",
6300
+ name: "payoutNumerators",
6301
+ inputs: [
6302
+ {
6303
+ name: "conditionId",
6304
+ type: "bytes32",
6305
+ internalType: "bytes32"
6306
+ },
6307
+ {
6308
+ name: "index",
6309
+ type: "uint256",
6310
+ internalType: "uint256"
6311
+ }
6312
+ ],
6313
+ outputs: [
6314
+ {
6315
+ name: "",
6316
+ type: "uint256",
6317
+ internalType: "uint256"
6318
+ }
6319
+ ],
6320
+ stateMutability: "view"
6321
+ },
6117
6322
  {
6118
6323
  type: "function",
6119
6324
  name: "prepareCondition",
@@ -6137,6 +6342,34 @@ var ConditionalTokens_default = [
6137
6342
  outputs: [],
6138
6343
  stateMutability: "nonpayable"
6139
6344
  },
6345
+ {
6346
+ type: "function",
6347
+ name: "redeemPositions",
6348
+ inputs: [
6349
+ {
6350
+ name: "collateralToken",
6351
+ type: "address",
6352
+ internalType: "contract IERC20"
6353
+ },
6354
+ {
6355
+ name: "parentCollectionId",
6356
+ type: "bytes32",
6357
+ internalType: "bytes32"
6358
+ },
6359
+ {
6360
+ name: "conditionId",
6361
+ type: "bytes32",
6362
+ internalType: "bytes32"
6363
+ },
6364
+ {
6365
+ name: "indexSets",
6366
+ type: "uint256[]",
6367
+ internalType: "uint256[]"
6368
+ }
6369
+ ],
6370
+ outputs: [],
6371
+ stateMutability: "nonpayable"
6372
+ },
6140
6373
  {
6141
6374
  type: "function",
6142
6375
  name: "reportPayouts",
@@ -6196,14 +6429,19 @@ var ERC20_default = [
6196
6429
  type: "constructor",
6197
6430
  inputs: [
6198
6431
  {
6199
- name: "name_",
6432
+ name: "_name",
6200
6433
  type: "string",
6201
6434
  internalType: "string"
6202
6435
  },
6203
6436
  {
6204
- name: "symbol_",
6437
+ name: "_symbol",
6205
6438
  type: "string",
6206
6439
  internalType: "string"
6440
+ },
6441
+ {
6442
+ name: "_decimals",
6443
+ type: "uint8",
6444
+ internalType: "uint8"
6207
6445
  }
6208
6446
  ],
6209
6447
  stateMutability: "nonpayable"
@@ -6213,12 +6451,12 @@ var ERC20_default = [
6213
6451
  name: "allowance",
6214
6452
  inputs: [
6215
6453
  {
6216
- name: "owner",
6454
+ name: "",
6217
6455
  type: "address",
6218
6456
  internalType: "address"
6219
6457
  },
6220
6458
  {
6221
- name: "spender",
6459
+ name: "",
6222
6460
  type: "address",
6223
6461
  internalType: "address"
6224
6462
  }
@@ -6261,7 +6499,7 @@ var ERC20_default = [
6261
6499
  name: "balanceOf",
6262
6500
  inputs: [
6263
6501
  {
6264
- name: "account",
6502
+ name: "",
6265
6503
  type: "address",
6266
6504
  internalType: "address"
6267
6505
  }
@@ -6290,50 +6528,20 @@ var ERC20_default = [
6290
6528
  },
6291
6529
  {
6292
6530
  type: "function",
6293
- name: "decreaseAllowance",
6294
- inputs: [
6295
- {
6296
- name: "spender",
6297
- type: "address",
6298
- internalType: "address"
6299
- },
6300
- {
6301
- name: "subtractedValue",
6302
- type: "uint256",
6303
- internalType: "uint256"
6304
- }
6305
- ],
6306
- outputs: [
6307
- {
6308
- name: "",
6309
- type: "bool",
6310
- internalType: "bool"
6311
- }
6312
- ],
6313
- stateMutability: "nonpayable"
6314
- },
6315
- {
6316
- type: "function",
6317
- name: "increaseAllowance",
6531
+ name: "mint",
6318
6532
  inputs: [
6319
6533
  {
6320
- name: "spender",
6534
+ name: "to",
6321
6535
  type: "address",
6322
6536
  internalType: "address"
6323
6537
  },
6324
6538
  {
6325
- name: "addedValue",
6539
+ name: "amount",
6326
6540
  type: "uint256",
6327
6541
  internalType: "uint256"
6328
6542
  }
6329
6543
  ],
6330
- outputs: [
6331
- {
6332
- name: "",
6333
- type: "bool",
6334
- internalType: "bool"
6335
- }
6336
- ],
6544
+ outputs: [],
6337
6545
  stateMutability: "nonpayable"
6338
6546
  },
6339
6547
  {
@@ -6624,6 +6832,33 @@ var VenueModule = class extends BaseModule {
6624
6832
  args: [user, venueId]
6625
6833
  });
6626
6834
  }
6835
+ // ---- Protocol Fee (owner-only) ----
6836
+ /**
6837
+ * Get the current protocol fee in basis points. Snapshotted per market at creation.
6838
+ */
6839
+ async getProtocolFeeBps() {
6840
+ return this.publicClient.readContract({
6841
+ address: this.config.diamondAddress,
6842
+ abi: ProtocolFacet_default,
6843
+ functionName: "getProtocolFeeBps"
6844
+ });
6845
+ }
6846
+ /**
6847
+ * Set the protocol fee in basis points. Owner-only. Max 200 bps (2%).
6848
+ * Only affects markets created after this call (existing markets retain their snapshot).
6849
+ */
6850
+ async setProtocolFeeBps(bps) {
6851
+ const wallet = this.walletClient;
6852
+ const [account] = await wallet.getAddresses();
6853
+ const { request } = await this.publicClient.simulateContract({
6854
+ address: this.config.diamondAddress,
6855
+ abi: ProtocolFacet_default,
6856
+ functionName: "setProtocolFeeBps",
6857
+ args: [bps],
6858
+ account
6859
+ });
6860
+ return wallet.writeContract(request);
6861
+ }
6627
6862
  };
6628
6863
  var TICK_SIZE_STANDARD = 10000000000000000n;
6629
6864
  var TICK_SIZE_FINE = 1000000000000000n;
@@ -6740,6 +6975,72 @@ function getOutcomePrice(market, outcomeIndex) {
6740
6975
  const yesPercent = tickToPercentage(yesTick, tickSize);
6741
6976
  return outcomeIndex === 0 ? yesPercent : 100 - yesPercent;
6742
6977
  }
6978
+ var MARK_PRICE_SPREAD_THRESHOLD = 0.1;
6979
+ function calculateChancePercent(market) {
6980
+ const tickSizeNum = parseFloat(market.tickSize || "0");
6981
+ if (tickSizeNum === 0) return 50;
6982
+ if (market.status === "Resolved" && market.resolvedOutcome != null) {
6983
+ return parseInt(String(market.resolvedOutcome)) === 0 ? 100 : 0;
6984
+ }
6985
+ const maxTicks = 1e18 / tickSizeNum;
6986
+ if (market.topOfBook && market.topOfBook.length > 0) {
6987
+ const tob = parseTopOfBook(market.topOfBook);
6988
+ const result = computeImpliedMidpoint(tob, maxTicks, tickSizeNum);
6989
+ if (result !== null) return result;
6990
+ }
6991
+ return lastTradeFallback(market, tickSizeNum);
6992
+ }
6993
+ function parseTopOfBook(entries) {
6994
+ const result = { yesBid: 0, yesAsk: 0, noBid: 0, noAsk: 0 };
6995
+ for (const entry of entries) {
6996
+ const tick = parseFloat(entry.topTick || "0");
6997
+ const outcome = entry.outcome?.toString();
6998
+ const side = entry.side;
6999
+ if (outcome === "0" && side === "BUY") result.yesBid = tick;
7000
+ else if (outcome === "0" && side === "SELL") result.yesAsk = tick;
7001
+ else if (outcome === "1" && side === "BUY") result.noBid = tick;
7002
+ else if (outcome === "1" && side === "SELL") result.noAsk = tick;
7003
+ }
7004
+ return result;
7005
+ }
7006
+ function computeImpliedMidpoint(tob, maxTicks, tickSize) {
7007
+ const bidCandidates = [];
7008
+ if (tob.yesBid > 0) bidCandidates.push(tob.yesBid);
7009
+ if (tob.noAsk > 0) bidCandidates.push(maxTicks - tob.noAsk);
7010
+ const askCandidates = [];
7011
+ if (tob.yesAsk > 0) askCandidates.push(tob.yesAsk);
7012
+ if (tob.noBid > 0) askCandidates.push(maxTicks - tob.noBid);
7013
+ if (bidCandidates.length === 0 || askCandidates.length === 0) return null;
7014
+ const impliedBid = Math.max(...bidCandidates);
7015
+ const impliedAsk = Math.min(...askCandidates);
7016
+ const spreadDollars = (impliedAsk - impliedBid) * tickSize / 1e18;
7017
+ if (spreadDollars > MARK_PRICE_SPREAD_THRESHOLD) return null;
7018
+ const midTick = (impliedBid + impliedAsk) / 2;
7019
+ const percent = midTick * tickSize / 1e18 * 100;
7020
+ return parseFloat(Math.max(0, Math.min(100, percent)).toFixed(2));
7021
+ }
7022
+ function lastTradeFallback(market, tickSize) {
7023
+ const tick0 = parseFloat(market.lastPriceTick_0 || "0");
7024
+ const tick1 = parseFloat(market.lastPriceTick_1 || "0");
7025
+ const ts0 = parseFloat(market.lastTradeTimestamp_0 || "0");
7026
+ const ts1 = parseFloat(market.lastTradeTimestamp_1 || "0");
7027
+ if (tick0 > 0 && tick1 > 0) {
7028
+ if (ts0 > 0 || ts1 > 0) {
7029
+ if (ts0 >= ts1) {
7030
+ return parseFloat((tick0 * tickSize / 1e18 * 100).toFixed(2));
7031
+ }
7032
+ return parseFloat(((1 - tick1 * tickSize / 1e18) * 100).toFixed(2));
7033
+ }
7034
+ return parseFloat((tick0 * tickSize / 1e18 * 100).toFixed(2));
7035
+ }
7036
+ if (tick0 > 0) {
7037
+ return parseFloat((tick0 * tickSize / 1e18 * 100).toFixed(2));
7038
+ }
7039
+ if (tick1 > 0) {
7040
+ return parseFloat(((1 - tick1 * tickSize / 1e18) * 100).toFixed(2));
7041
+ }
7042
+ return 50;
7043
+ }
6743
7044
 
6744
7045
  // src/utils/decimals.ts
6745
7046
  async function getTokenDecimals(publicClient, token) {
@@ -6816,17 +7117,19 @@ var MarketModule = class extends BaseModule {
6816
7117
  functionName: "getVenue",
6817
7118
  args: [params.venueId]
6818
7119
  });
6819
- const feeRequired = venue.marketCreationFee;
6820
- if (feeRequired > 0n) {
7120
+ const feeRequired = BigInt(venue.marketCreationFee);
7121
+ const reward = BigInt(venue.umaRewardAmount) + (params.additionalReward ?? 0n);
7122
+ const totalRequired = feeRequired + reward;
7123
+ if (totalRequired > 0n) {
6821
7124
  const allowance = await this.publicClient.readContract({
6822
7125
  address: params.collateralToken,
6823
7126
  abi: erc20Abi,
6824
7127
  functionName: "allowance",
6825
7128
  args: [account, this.config.diamondAddress]
6826
7129
  });
6827
- if (allowance < feeRequired) {
7130
+ if (allowance < totalRequired) {
6828
7131
  throw new Error(
6829
- `Insufficient allowance for Market Creation Fee. Approved: ${allowance.toString()}, Required: ${feeRequired.toString()}. Please approve the Diamond (${this.config.diamondAddress}).`
7132
+ `Insufficient allowance. Approved: ${allowance.toString()}, Required: ${totalRequired.toString()} (fee: ${feeRequired.toString()}, reward: ${reward.toString()}). Please approve the Diamond (${this.config.diamondAddress}).`
6830
7133
  );
6831
7134
  }
6832
7135
  const balance = await this.publicClient.readContract({
@@ -6835,9 +7138,9 @@ var MarketModule = class extends BaseModule {
6835
7138
  functionName: "balanceOf",
6836
7139
  args: [account]
6837
7140
  });
6838
- if (balance < feeRequired) {
7141
+ if (balance < totalRequired) {
6839
7142
  throw new Error(
6840
- `Insufficient collateral balance for Market Creation Fee. Have: ${balance.toString()}, Required: ${feeRequired.toString()}. Please acquire more tokens.`
7143
+ `Insufficient collateral balance. Have: ${balance.toString()}, Required: ${totalRequired.toString()} (fee: ${feeRequired.toString()}, reward: ${reward.toString()}).`
6841
7144
  );
6842
7145
  }
6843
7146
  }
@@ -7083,17 +7386,19 @@ var MarketModule = class extends BaseModule {
7083
7386
  functionName: "getVenue",
7084
7387
  args: [params.venueId]
7085
7388
  });
7086
- const feeRequired = venue.marketCreationFee;
7087
- if (feeRequired > 0n) {
7389
+ const feeRequired = BigInt(venue.marketCreationFee);
7390
+ const reward = BigInt(venue.umaRewardAmount) + (params.additionalReward ?? 0n);
7391
+ const totalRequired = feeRequired + reward;
7392
+ if (totalRequired > 0n) {
7088
7393
  const allowance = await this.publicClient.readContract({
7089
7394
  address: params.collateralToken,
7090
7395
  abi: erc20Abi,
7091
7396
  functionName: "allowance",
7092
7397
  args: [account, this.config.diamondAddress]
7093
7398
  });
7094
- if (allowance < feeRequired) {
7399
+ if (allowance < totalRequired) {
7095
7400
  throw new Error(
7096
- `Insufficient allowance for Market Group Creation Fee. Approved: ${allowance.toString()}, Required: ${feeRequired.toString()}. Please approve the Diamond (${this.config.diamondAddress}).`
7401
+ `Insufficient allowance. Approved: ${allowance.toString()}, Required: ${totalRequired.toString()} (fee: ${feeRequired.toString()}, reward: ${reward.toString()}). Please approve the Diamond (${this.config.diamondAddress}).`
7097
7402
  );
7098
7403
  }
7099
7404
  const balance = await this.publicClient.readContract({
@@ -7102,9 +7407,9 @@ var MarketModule = class extends BaseModule {
7102
7407
  functionName: "balanceOf",
7103
7408
  args: [account]
7104
7409
  });
7105
- if (balance < feeRequired) {
7410
+ if (balance < totalRequired) {
7106
7411
  throw new Error(
7107
- `Insufficient collateral balance for Market Group Creation Fee. Have: ${balance.toString()}, Required: ${feeRequired.toString()}.`
7412
+ `Insufficient collateral balance. Have: ${balance.toString()}, Required: ${totalRequired.toString()} (fee: ${feeRequired.toString()}, reward: ${reward.toString()}).`
7108
7413
  );
7109
7414
  }
7110
7415
  }
@@ -7633,6 +7938,80 @@ var TradeModule = class extends BaseModule {
7633
7938
  });
7634
7939
  return result;
7635
7940
  }
7941
+ /**
7942
+ * Execute a market sell order (FOK or FAK)
7943
+ *
7944
+ * @param params.marketId - The market to sell on
7945
+ * @param params.outcomeId - Which outcome to sell (0=YES, 1=NO)
7946
+ * @param params.tokenAmount - Amount of outcome tokens to sell
7947
+ * @param params.minPriceTick - Minimum price tick willing to accept (slippage protection)
7948
+ * @param params.orderType - 0=FOK (Fill-Or-Kill), 1=FAK (Fill-And-Kill)
7949
+ */
7950
+ async placeMarketSell(params) {
7951
+ const wallet = this.walletClient;
7952
+ const [account] = await wallet.getAddresses();
7953
+ const { request } = await this.publicClient.simulateContract({
7954
+ address: this.config.diamondAddress,
7955
+ abi: MarketOrdersFacet_default,
7956
+ functionName: "placeMarketSell",
7957
+ args: [
7958
+ params.marketId,
7959
+ params.outcomeId,
7960
+ params.tokenAmount,
7961
+ params.minPriceTick,
7962
+ params.orderType
7963
+ ],
7964
+ account
7965
+ });
7966
+ return wallet.writeContract(request);
7967
+ }
7968
+ /**
7969
+ * Execute a market sell order with simple string inputs (recommended for frontends)
7970
+ * @param params.amount - Token amount as decimal string (e.g., "100.5")
7971
+ * @param params.minPrice - Minimum price as decimal string (e.g., "0.70")
7972
+ * @param params.orderType - 'FOK' or 'FAK' (default: 'FAK')
7973
+ */
7974
+ async placeMarketSellSimple(params) {
7975
+ const tradingData = await this.publicClient.readContract({
7976
+ address: this.config.diamondAddress,
7977
+ abi: MarketsFacet_default,
7978
+ functionName: "getMarketTradingData",
7979
+ args: [params.marketId]
7980
+ });
7981
+ const collateralToken = tradingData.collateralToken;
7982
+ const decimals = await getCachedTokenDecimals(this.publicClient, collateralToken);
7983
+ const tokenAmount = parseTokenAmount(params.amount, decimals);
7984
+ const minPriceTick = priceToTick(params.minPrice);
7985
+ const orderType = params.orderType === "FOK" ? 0 : 1;
7986
+ return this.placeMarketSell({
7987
+ marketId: params.marketId,
7988
+ outcomeId: params.outcomeId,
7989
+ tokenAmount,
7990
+ minPriceTick,
7991
+ orderType
7992
+ });
7993
+ }
7994
+ /**
7995
+ * Preview a market sell order (simulate transaction)
7996
+ */
7997
+ async previewMarketSell(params) {
7998
+ const wallet = this.walletClient;
7999
+ const [account] = await wallet.getAddresses();
8000
+ const { result } = await this.publicClient.simulateContract({
8001
+ address: this.config.diamondAddress,
8002
+ abi: MarketOrdersFacet_default,
8003
+ functionName: "placeMarketSell",
8004
+ args: [
8005
+ params.marketId,
8006
+ params.outcomeId,
8007
+ params.tokenAmount,
8008
+ params.minPriceTick,
8009
+ params.orderType
8010
+ ],
8011
+ account
8012
+ });
8013
+ return result;
8014
+ }
7636
8015
  /**
7637
8016
  * Watch for MarketOrderExecuted events
7638
8017
  */
@@ -7645,6 +8024,18 @@ var TradeModule = class extends BaseModule {
7645
8024
  onLogs
7646
8025
  });
7647
8026
  }
8027
+ /**
8028
+ * Watch for MarketSellExecuted events
8029
+ */
8030
+ watchMarketSell(marketId, onLogs) {
8031
+ return this.publicClient.watchContractEvent({
8032
+ address: this.config.diamondAddress,
8033
+ abi: MarketOrdersFacet_default,
8034
+ eventName: "MarketSellExecuted",
8035
+ args: { marketId },
8036
+ onLogs
8037
+ });
8038
+ }
7648
8039
  /**
7649
8040
  * Check whether any orders are matchable in the given market.
7650
8041
  * Returns a preview of which fill paths have crossing conditions,
@@ -7959,6 +8350,13 @@ var GET_MARKETS = gql`
7959
8350
  lastPriceTick_0
7960
8351
  lastPriceTick_1
7961
8352
  lastTradeTimestamp
8353
+ lastTradeTimestamp_0
8354
+ lastTradeTimestamp_1
8355
+ topOfBook {
8356
+ outcome
8357
+ side
8358
+ topTick
8359
+ }
7962
8360
  tags
7963
8361
  metadataURI
7964
8362
  }
@@ -7989,6 +8387,14 @@ var GET_MARKETS_WITH_PRICING = gql`
7989
8387
  lastPriceTick_0
7990
8388
  lastPriceTick_1
7991
8389
  lastTradeTimestamp
8390
+ lastTradeTimestamp_0
8391
+ lastTradeTimestamp_1
8392
+ # Top of book for mark price calculation
8393
+ topOfBook {
8394
+ outcome
8395
+ side
8396
+ topTick
8397
+ }
7992
8398
  # Statistics
7993
8399
  totalVolume
7994
8400
  totalOrders
@@ -8006,12 +8412,20 @@ var GET_MARKET = gql`
8006
8412
  question
8007
8413
  outcomes
8008
8414
  status
8415
+ resolvedOutcome
8009
8416
  collateralToken
8010
8417
  conditionId
8011
8418
  tickSize
8012
8419
  lastPriceTick_0
8013
8420
  lastPriceTick_1
8014
8421
  lastTradeTimestamp
8422
+ lastTradeTimestamp_0
8423
+ lastTradeTimestamp_1
8424
+ topOfBook {
8425
+ outcome
8426
+ side
8427
+ topTick
8428
+ }
8015
8429
  totalVolume
8016
8430
  totalOrders
8017
8431
  totalFees
@@ -8251,6 +8665,7 @@ var GET_MARKET_GROUPS = gql`
8251
8665
  totalMarkets
8252
8666
  activeMarketCount
8253
8667
  resolvedMarketId
8668
+ reward
8254
8669
  tags
8255
8670
  metadataURI
8256
8671
  venue {
@@ -8310,6 +8725,7 @@ var GET_GROUP_MARKETS = gql`
8310
8725
  question
8311
8726
  outcomes
8312
8727
  status
8728
+ resolvedOutcome
8313
8729
  collateralToken
8314
8730
  conditionId
8315
8731
  tickSize
@@ -8323,6 +8739,13 @@ var GET_GROUP_MARKETS = gql`
8323
8739
  lastPriceTick_0
8324
8740
  lastPriceTick_1
8325
8741
  lastTradeTimestamp
8742
+ lastTradeTimestamp_0
8743
+ lastTradeTimestamp_1
8744
+ topOfBook {
8745
+ outcome
8746
+ side
8747
+ topTick
8748
+ }
8326
8749
  totalVolume
8327
8750
  totalOrders
8328
8751
  createdAt
@@ -8378,6 +8801,13 @@ var GET_UNIFIED_MARKET_FEED = gql`
8378
8801
  lastPriceTick_0
8379
8802
  lastPriceTick_1
8380
8803
  lastTradeTimestamp
8804
+ lastTradeTimestamp_0
8805
+ lastTradeTimestamp_1
8806
+ topOfBook {
8807
+ outcome
8808
+ side
8809
+ topTick
8810
+ }
8381
8811
  # Statistics
8382
8812
  totalVolume
8383
8813
  totalOrders
@@ -8470,8 +8900,17 @@ var GET_UNIFIED_MARKET_FEED_BY_VOLUME = gql`
8470
8900
  status
8471
8901
  collateralToken
8472
8902
  groupId
8903
+ tickSize
8473
8904
  lastPriceTick_0
8474
8905
  lastPriceTick_1
8906
+ lastTradeTimestamp
8907
+ lastTradeTimestamp_0
8908
+ lastTradeTimestamp_1
8909
+ topOfBook {
8910
+ outcome
8911
+ side
8912
+ topTick
8913
+ }
8475
8914
  totalVolume
8476
8915
  totalOrders
8477
8916
  uniqueTraders
@@ -8498,17 +8937,28 @@ var GET_UNIFIED_MARKET_FEED_BY_VOLUME = gql`
8498
8937
  marketQuestion
8499
8938
  status
8500
8939
  totalMarkets
8940
+ activeMarketCount
8941
+ resolvedMarketId
8501
8942
  tags
8502
8943
  metadataURI
8503
- resolvedMarketId
8504
8944
  createdAt
8945
+ activatedAt
8946
+ resolvedAt
8505
8947
  venue {
8506
8948
  id
8507
8949
  venueId
8508
8950
  name
8509
8951
  }
8952
+ creator {
8953
+ id
8954
+ address
8955
+ }
8510
8956
  markets {
8957
+ id
8511
8958
  marketId
8959
+ question
8960
+ status
8961
+ groupId
8512
8962
  tickSize
8513
8963
  lastPriceTick_0
8514
8964
  lastPriceTick_1
@@ -8543,6 +8993,13 @@ var GET_ALL_MARKETS_FEED = gql`
8543
8993
  lastPriceTick_0
8544
8994
  lastPriceTick_1
8545
8995
  lastTradeTimestamp
8996
+ lastTradeTimestamp_0
8997
+ lastTradeTimestamp_1
8998
+ topOfBook {
8999
+ outcome
9000
+ side
9001
+ topTick
9002
+ }
8546
9003
  totalVolume
8547
9004
  totalOrders
8548
9005
  uniqueTraders
@@ -8624,9 +9081,19 @@ var GET_ALL_MARKETS_FEED_BY_VOLUME = gql`
8624
9081
  outcomes
8625
9082
  status
8626
9083
  collateralToken
9084
+ conditionId
9085
+ tickSize
8627
9086
  groupId
8628
9087
  lastPriceTick_0
8629
9088
  lastPriceTick_1
9089
+ lastTradeTimestamp
9090
+ lastTradeTimestamp_0
9091
+ lastTradeTimestamp_1
9092
+ topOfBook {
9093
+ outcome
9094
+ side
9095
+ topTick
9096
+ }
8630
9097
  totalVolume
8631
9098
  totalOrders
8632
9099
  uniqueTraders
@@ -8637,6 +9104,10 @@ var GET_ALL_MARKETS_FEED_BY_VOLUME = gql`
8637
9104
  venueId
8638
9105
  name
8639
9106
  }
9107
+ creator {
9108
+ id
9109
+ address
9110
+ }
8640
9111
  }
8641
9112
 
8642
9113
  marketGroups(
@@ -8651,16 +9122,28 @@ var GET_ALL_MARKETS_FEED_BY_VOLUME = gql`
8651
9122
  marketQuestion
8652
9123
  status
8653
9124
  totalMarkets
8654
- metadataURI
9125
+ activeMarketCount
8655
9126
  resolvedMarketId
9127
+ metadataURI
8656
9128
  createdAt
9129
+ activatedAt
9130
+ resolvedAt
8657
9131
  venue {
8658
9132
  id
8659
9133
  venueId
8660
9134
  name
8661
9135
  }
9136
+ creator {
9137
+ id
9138
+ address
9139
+ }
8662
9140
  markets {
9141
+ id
8663
9142
  marketId
9143
+ question
9144
+ status
9145
+ groupId
9146
+ tickSize
8664
9147
  lastPriceTick_0
8665
9148
  lastPriceTick_1
8666
9149
  totalVolume
@@ -8684,6 +9167,7 @@ var GET_RECENT_TRADES = gql`
8684
9167
  market {
8685
9168
  marketId
8686
9169
  question
9170
+ outcomes
8687
9171
  venue {
8688
9172
  venueId
8689
9173
  name
@@ -9130,20 +9614,21 @@ var PublicModule = class extends BaseModule {
9130
9614
  return limit ? merged.slice(0, limit) : merged;
9131
9615
  }
9132
9616
  /**
9133
- * Calculate probability for a market using last trade price
9617
+ * Calculate probability for a market using mark price waterfall.
9134
9618
  * Returns probability as a decimal string (e.g., "0.65" for 65%)
9135
9619
  *
9136
- * @param market - Market object from subgraph
9620
+ * Uses Polymarket-style pricing: implied midpoint → last trade → default 50%.
9621
+ *
9622
+ * @param market - Market object from subgraph (with topOfBook and timestamp fields)
9137
9623
  * @returns Probability string or null if no data available
9138
9624
  */
9139
9625
  calculateMarketProbability(market) {
9140
- if (market.lastPriceTick_0 && market.tickSize) {
9141
- const tick = BigInt(market.lastPriceTick_0);
9142
- const tickSize = BigInt(market.tickSize);
9143
- const price = Number(tick * tickSize) / 1e18;
9144
- return price.toFixed(2);
9626
+ if (!market.tickSize) return null;
9627
+ const chance = calculateChancePercent(market);
9628
+ if (chance === 50 && !market.lastPriceTick_0 && !market.lastPriceTick_1) {
9629
+ return null;
9145
9630
  }
9146
- return null;
9631
+ return (chance / 100).toFixed(2);
9147
9632
  }
9148
9633
  /**
9149
9634
  * Format market group for display (Polymarket-style)
@@ -9372,6 +9857,15 @@ var TokenModule = class extends BaseModule {
9372
9857
  });
9373
9858
  }
9374
9859
  };
9860
+ var optimisticOracleV3Abi = [
9861
+ {
9862
+ inputs: [{ name: "currency", type: "address" }],
9863
+ name: "getMinimumBond",
9864
+ outputs: [{ name: "", type: "uint256" }],
9865
+ stateMutability: "view",
9866
+ type: "function"
9867
+ }
9868
+ ];
9375
9869
  var UmaModule = class extends BaseModule {
9376
9870
  /**
9377
9871
  * Assert an outcome for a market question
@@ -9393,14 +9887,8 @@ var UmaModule = class extends BaseModule {
9393
9887
  args: [params.marketId]
9394
9888
  });
9395
9889
  const questionId = registryData.questionId;
9396
- const oracleData = await this.publicClient.readContract({
9397
- address: this.config.diamondAddress,
9398
- abi: MarketsFacet_default,
9399
- functionName: "getMarketOracleData",
9400
- args: [params.marketId]
9401
- });
9402
- const bondAmount = BigInt(oracleData.requiredBond);
9403
- const currency = oracleData.currency;
9890
+ const { effectiveBond, currency } = await this.getEffectiveBond(params.marketId);
9891
+ const bondAmount = effectiveBond;
9404
9892
  const currentAllowance = await this.publicClient.readContract({
9405
9893
  address: currency,
9406
9894
  abi: erc20Abi,
@@ -9457,6 +9945,33 @@ var UmaModule = class extends BaseModule {
9457
9945
  });
9458
9946
  return wallet.writeContract(request);
9459
9947
  }
9948
+ /**
9949
+ * Get the effective bond for a market, accounting for UMA's minimum bond.
9950
+ * The contract uses max(requiredBond, oo.getMinimumBond(currency)).
9951
+ */
9952
+ async getEffectiveBond(marketId) {
9953
+ const oracleData = await this.publicClient.readContract({
9954
+ address: this.config.diamondAddress,
9955
+ abi: MarketsFacet_default,
9956
+ functionName: "getMarketOracleData",
9957
+ args: [marketId]
9958
+ });
9959
+ const requiredBond = BigInt(oracleData.requiredBond);
9960
+ const currency = oracleData.currency;
9961
+ const umaOracle = await this.publicClient.readContract({
9962
+ address: this.config.diamondAddress,
9963
+ abi: ProtocolFacet_default,
9964
+ functionName: "getUmaOracle"
9965
+ });
9966
+ const minimumBond = await this.publicClient.readContract({
9967
+ address: umaOracle,
9968
+ abi: optimisticOracleV3Abi,
9969
+ functionName: "getMinimumBond",
9970
+ args: [currency]
9971
+ });
9972
+ const effectiveBond = requiredBond > minimumBond ? requiredBond : minimumBond;
9973
+ return { requiredBond, minimumBond, effectiveBond, currency };
9974
+ }
9460
9975
  /**
9461
9976
  * Settle an assertion after the liveness period
9462
9977
  */
@@ -10244,11 +10759,19 @@ function createOddMakiClient(params) {
10244
10759
 
10245
10760
  // src/constants.ts
10246
10761
  var PROTOCOL_FEES = {
10247
- /** Protocol fee: 20 bps (0.20%) */
10248
- PROTOCOL_FEE_BPS: 20n,
10762
+ /** Protocol fee: 50 bps (0.50%) — configurable via ProtocolFacet.setProtocolFeeBps() */
10763
+ PROTOCOL_FEE_BPS: 50n,
10249
10764
  /** Operator fee: 10 bps (0.10%) for match operators */
10250
10765
  OPERATOR_FEE_BPS: 10n
10251
10766
  };
10767
+ var UMA_DEFAULTS = {
10768
+ /** Recommended reward: 5 USDC. Incentivizes third-party resolution. */
10769
+ REWARD_USDC: 5000000n,
10770
+ /** Recommended minimum bond: 750 USDC. Matches Polymarket's production bond. */
10771
+ MIN_BOND_USDC: 750000000n,
10772
+ /** Default liveness period: 2 hours (7200 seconds). */
10773
+ LIVENESS: 7200n
10774
+ };
10252
10775
 
10253
10776
  // src/utils/metadata.ts
10254
10777
  var DEFAULT_IPFS_GATEWAY = "https://gateway.pinata.cloud/ipfs/";
@@ -10276,6 +10799,6 @@ function parseMetadata(json) {
10276
10799
  // src/index.ts
10277
10800
  var version = "0.1.0";
10278
10801
 
10279
- export { AccessControlFacet_default as AccessControlFacetABI, AccessControlModule, BatchOrdersFacet_default as BatchOrdersFacetABI, CONTRACT_ADDRESSES, ConditionalTokens_default as ConditionalTokensABI, DEFAULT_CHAIN, ERC20_default as ERC20ABI, FeedProvider, GET_ALL_MARKETS_FEED, GET_ALL_MARKETS_FEED_BY_VOLUME, GET_CHART_TRADES, GET_CHART_TRADES_ALL, GET_GROUP_MARKETS, GET_LEADERBOARD, GET_MARKET, GET_MARKETS, GET_MARKETS_WITH_PRICING, GET_MARKET_GROUP, GET_MARKET_GROUPS, GET_MARKET_GROUP_ITEM, GET_MARKET_TOP_HOLDERS, GET_ORDERS, GET_PROTOCOL_STATS, GET_QUESTION, GET_QUESTIONS, GET_RECENT_MARKETS, GET_RECENT_TRADES, GET_TOP_OF_BOOK, GET_TRADER_CLOSED_POSITIONS, GET_TRADER_FILLS, GET_TRADER_POSITIONS, GET_TRADER_PROFILE, GET_TRADES, GET_UNIFIED_MARKET_FEED, GET_UNIFIED_MARKET_FEED_BY_VOLUME, GET_USER, GET_VENUES, LimitOrdersFacet_default as LimitOrdersFacetABI, MarketGroupFacet_default as MarketGroupFacetABI, MarketModule, MarketOrdersFacet_default as MarketOrdersFacetABI, MarketsFacet_default as MarketsFacetABI, MatchingFacet_default as MatchingFacetABI, MetadataFacet_default as MetadataFacetABI, NegRiskFacet_default as NegRiskFacetABI, OddMakiClient, OrderBookFacet_default as OrderBookFacetABI, PROTOCOL_FEES, PriceMarketFacet_default as PriceMarketFacetABI, PriceMarketModule, ProtocolFacet_default as ProtocolFacetABI, PublicModule, PythResolutionFacet_default as PythResolutionFacetABI, ResolutionFacet_default as ResolutionFacetABI, SubgraphClient, TICK_SIZE_FINE, TICK_SIZE_STANDARD, TagsFacet_default as TagsFacetABI, TokenModule, TradeModule, UmaModule, VALID_TICK_SIZES, VaultFacet_default as VaultFacetABI, VenueFacet_default as VenueFacetABI, VenueModule, WhitelistAccessControl_default as WhitelistAccessControlABI, clearDecimalsCache, createExpiry, createOddMakiClient, formatAmount, formatAncillaryData, formatTimestamp, getCachedTokenDecimals, getOutcomePrice, getTokenDecimals, isValidTickSize, parseAmount, parseAncillaryData, parseMetadata, parseTokenAmount, priceToTick, resolveIPFSUri, tickToPercentage, tickToPrice, version };
10802
+ export { AccessControlFacet_default as AccessControlFacetABI, AccessControlModule, BatchOrdersFacet_default as BatchOrdersFacetABI, CONTRACT_ADDRESSES, ConditionalTokens_default as ConditionalTokensABI, DEFAULT_CHAIN, ERC20_default as ERC20ABI, FeedProvider, GET_ALL_MARKETS_FEED, GET_ALL_MARKETS_FEED_BY_VOLUME, GET_CHART_TRADES, GET_CHART_TRADES_ALL, GET_GROUP_MARKETS, GET_LEADERBOARD, GET_MARKET, GET_MARKETS, GET_MARKETS_WITH_PRICING, GET_MARKET_GROUP, GET_MARKET_GROUPS, GET_MARKET_GROUP_ITEM, GET_MARKET_TOP_HOLDERS, GET_ORDERS, GET_PROTOCOL_STATS, GET_QUESTION, GET_QUESTIONS, GET_RECENT_MARKETS, GET_RECENT_TRADES, GET_TOP_OF_BOOK, GET_TRADER_CLOSED_POSITIONS, GET_TRADER_FILLS, GET_TRADER_POSITIONS, GET_TRADER_PROFILE, GET_TRADES, GET_UNIFIED_MARKET_FEED, GET_UNIFIED_MARKET_FEED_BY_VOLUME, GET_USER, GET_VENUES, LimitOrdersFacet_default as LimitOrdersFacetABI, MarketGroupFacet_default as MarketGroupFacetABI, MarketModule, MarketOrdersFacet_default as MarketOrdersFacetABI, MarketsFacet_default as MarketsFacetABI, MatchingFacet_default as MatchingFacetABI, MetadataFacet_default as MetadataFacetABI, NegRiskFacet_default as NegRiskFacetABI, OddMakiClient, OrderBookFacet_default as OrderBookFacetABI, PROTOCOL_FEES, PriceMarketFacet_default as PriceMarketFacetABI, PriceMarketModule, ProtocolFacet_default as ProtocolFacetABI, PublicModule, PythResolutionFacet_default as PythResolutionFacetABI, ResolutionFacet_default as ResolutionFacetABI, SubgraphClient, TICK_SIZE_FINE, TICK_SIZE_STANDARD, TagsFacet_default as TagsFacetABI, TokenModule, TradeModule, UMA_DEFAULTS, UmaModule, VALID_TICK_SIZES, VaultFacet_default as VaultFacetABI, VenueFacet_default as VenueFacetABI, VenueModule, WhitelistAccessControl_default as WhitelistAccessControlABI, calculateChancePercent, clearDecimalsCache, createExpiry, createOddMakiClient, formatAmount, formatAncillaryData, formatTimestamp, getCachedTokenDecimals, getOutcomePrice, getTokenDecimals, isValidTickSize, parseAmount, parseAncillaryData, parseMetadata, parseTokenAmount, priceToTick, resolveIPFSUri, tickToPercentage, tickToPrice, version };
10280
10803
  //# sourceMappingURL=index.mjs.map
10281
10804
  //# sourceMappingURL=index.mjs.map