@oddmaki-protocol/sdk 0.2.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +194 -6
- package/dist/index.d.ts +194 -6
- package/dist/index.js +377 -34
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +376 -35
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -5,9 +5,9 @@ import { gql, GraphQLClient } from 'graphql-request';
|
|
|
5
5
|
// src/client.ts
|
|
6
6
|
var CONTRACT_ADDRESSES = {
|
|
7
7
|
[baseSepolia.id]: {
|
|
8
|
-
diamond: "
|
|
8
|
+
diamond: "0x188563069e0ae7247f0e2f0fce0382f0ed28d31a",
|
|
9
9
|
conditionalTokens: "0x7364747372Ac4a175B5326f5B2C9CB1C271d32e8",
|
|
10
|
-
usdc: "
|
|
10
|
+
usdc: "0xb7e73d2848dd908a90a50ba679719eb9375c3fdf",
|
|
11
11
|
subgraph: "https://api.studio.thegraph.com/query/1716020/oddmaki/version/latest"
|
|
12
12
|
}
|
|
13
13
|
};
|
|
@@ -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",
|
|
@@ -6718,6 +6832,33 @@ var VenueModule = class extends BaseModule {
|
|
|
6718
6832
|
args: [user, venueId]
|
|
6719
6833
|
});
|
|
6720
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
|
+
}
|
|
6721
6862
|
};
|
|
6722
6863
|
var TICK_SIZE_STANDARD = 10000000000000000n;
|
|
6723
6864
|
var TICK_SIZE_FINE = 1000000000000000n;
|
|
@@ -6834,6 +6975,72 @@ function getOutcomePrice(market, outcomeIndex) {
|
|
|
6834
6975
|
const yesPercent = tickToPercentage(yesTick, tickSize);
|
|
6835
6976
|
return outcomeIndex === 0 ? yesPercent : 100 - yesPercent;
|
|
6836
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
|
+
}
|
|
6837
7044
|
|
|
6838
7045
|
// src/utils/decimals.ts
|
|
6839
7046
|
async function getTokenDecimals(publicClient, token) {
|
|
@@ -6910,17 +7117,19 @@ var MarketModule = class extends BaseModule {
|
|
|
6910
7117
|
functionName: "getVenue",
|
|
6911
7118
|
args: [params.venueId]
|
|
6912
7119
|
});
|
|
6913
|
-
const feeRequired = venue.marketCreationFee;
|
|
6914
|
-
|
|
7120
|
+
const feeRequired = BigInt(venue.marketCreationFee);
|
|
7121
|
+
const reward = BigInt(venue.umaRewardAmount) + (params.additionalReward ?? 0n);
|
|
7122
|
+
const totalRequired = feeRequired + reward;
|
|
7123
|
+
if (totalRequired > 0n) {
|
|
6915
7124
|
const allowance = await this.publicClient.readContract({
|
|
6916
7125
|
address: params.collateralToken,
|
|
6917
7126
|
abi: erc20Abi,
|
|
6918
7127
|
functionName: "allowance",
|
|
6919
7128
|
args: [account, this.config.diamondAddress]
|
|
6920
7129
|
});
|
|
6921
|
-
if (allowance <
|
|
7130
|
+
if (allowance < totalRequired) {
|
|
6922
7131
|
throw new Error(
|
|
6923
|
-
`Insufficient allowance
|
|
7132
|
+
`Insufficient allowance. Approved: ${allowance.toString()}, Required: ${totalRequired.toString()} (fee: ${feeRequired.toString()}, reward: ${reward.toString()}). Please approve the Diamond (${this.config.diamondAddress}).`
|
|
6924
7133
|
);
|
|
6925
7134
|
}
|
|
6926
7135
|
const balance = await this.publicClient.readContract({
|
|
@@ -6929,9 +7138,9 @@ var MarketModule = class extends BaseModule {
|
|
|
6929
7138
|
functionName: "balanceOf",
|
|
6930
7139
|
args: [account]
|
|
6931
7140
|
});
|
|
6932
|
-
if (balance <
|
|
7141
|
+
if (balance < totalRequired) {
|
|
6933
7142
|
throw new Error(
|
|
6934
|
-
`Insufficient collateral balance
|
|
7143
|
+
`Insufficient collateral balance. Have: ${balance.toString()}, Required: ${totalRequired.toString()} (fee: ${feeRequired.toString()}, reward: ${reward.toString()}).`
|
|
6935
7144
|
);
|
|
6936
7145
|
}
|
|
6937
7146
|
}
|
|
@@ -7177,17 +7386,19 @@ var MarketModule = class extends BaseModule {
|
|
|
7177
7386
|
functionName: "getVenue",
|
|
7178
7387
|
args: [params.venueId]
|
|
7179
7388
|
});
|
|
7180
|
-
const feeRequired = venue.marketCreationFee;
|
|
7181
|
-
|
|
7389
|
+
const feeRequired = BigInt(venue.marketCreationFee);
|
|
7390
|
+
const reward = BigInt(venue.umaRewardAmount) + (params.additionalReward ?? 0n);
|
|
7391
|
+
const totalRequired = feeRequired + reward;
|
|
7392
|
+
if (totalRequired > 0n) {
|
|
7182
7393
|
const allowance = await this.publicClient.readContract({
|
|
7183
7394
|
address: params.collateralToken,
|
|
7184
7395
|
abi: erc20Abi,
|
|
7185
7396
|
functionName: "allowance",
|
|
7186
7397
|
args: [account, this.config.diamondAddress]
|
|
7187
7398
|
});
|
|
7188
|
-
if (allowance <
|
|
7399
|
+
if (allowance < totalRequired) {
|
|
7189
7400
|
throw new Error(
|
|
7190
|
-
`Insufficient allowance
|
|
7401
|
+
`Insufficient allowance. Approved: ${allowance.toString()}, Required: ${totalRequired.toString()} (fee: ${feeRequired.toString()}, reward: ${reward.toString()}). Please approve the Diamond (${this.config.diamondAddress}).`
|
|
7191
7402
|
);
|
|
7192
7403
|
}
|
|
7193
7404
|
const balance = await this.publicClient.readContract({
|
|
@@ -7196,9 +7407,9 @@ var MarketModule = class extends BaseModule {
|
|
|
7196
7407
|
functionName: "balanceOf",
|
|
7197
7408
|
args: [account]
|
|
7198
7409
|
});
|
|
7199
|
-
if (balance <
|
|
7410
|
+
if (balance < totalRequired) {
|
|
7200
7411
|
throw new Error(
|
|
7201
|
-
`Insufficient collateral balance
|
|
7412
|
+
`Insufficient collateral balance. Have: ${balance.toString()}, Required: ${totalRequired.toString()} (fee: ${feeRequired.toString()}, reward: ${reward.toString()}).`
|
|
7202
7413
|
);
|
|
7203
7414
|
}
|
|
7204
7415
|
}
|
|
@@ -8139,6 +8350,13 @@ var GET_MARKETS = gql`
|
|
|
8139
8350
|
lastPriceTick_0
|
|
8140
8351
|
lastPriceTick_1
|
|
8141
8352
|
lastTradeTimestamp
|
|
8353
|
+
lastTradeTimestamp_0
|
|
8354
|
+
lastTradeTimestamp_1
|
|
8355
|
+
topOfBook {
|
|
8356
|
+
outcome
|
|
8357
|
+
side
|
|
8358
|
+
topTick
|
|
8359
|
+
}
|
|
8142
8360
|
tags
|
|
8143
8361
|
metadataURI
|
|
8144
8362
|
}
|
|
@@ -8169,6 +8387,14 @@ var GET_MARKETS_WITH_PRICING = gql`
|
|
|
8169
8387
|
lastPriceTick_0
|
|
8170
8388
|
lastPriceTick_1
|
|
8171
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
|
+
}
|
|
8172
8398
|
# Statistics
|
|
8173
8399
|
totalVolume
|
|
8174
8400
|
totalOrders
|
|
@@ -8193,6 +8419,13 @@ var GET_MARKET = gql`
|
|
|
8193
8419
|
lastPriceTick_0
|
|
8194
8420
|
lastPriceTick_1
|
|
8195
8421
|
lastTradeTimestamp
|
|
8422
|
+
lastTradeTimestamp_0
|
|
8423
|
+
lastTradeTimestamp_1
|
|
8424
|
+
topOfBook {
|
|
8425
|
+
outcome
|
|
8426
|
+
side
|
|
8427
|
+
topTick
|
|
8428
|
+
}
|
|
8196
8429
|
totalVolume
|
|
8197
8430
|
totalOrders
|
|
8198
8431
|
totalFees
|
|
@@ -8432,6 +8665,7 @@ var GET_MARKET_GROUPS = gql`
|
|
|
8432
8665
|
totalMarkets
|
|
8433
8666
|
activeMarketCount
|
|
8434
8667
|
resolvedMarketId
|
|
8668
|
+
reward
|
|
8435
8669
|
tags
|
|
8436
8670
|
metadataURI
|
|
8437
8671
|
venue {
|
|
@@ -8505,6 +8739,13 @@ var GET_GROUP_MARKETS = gql`
|
|
|
8505
8739
|
lastPriceTick_0
|
|
8506
8740
|
lastPriceTick_1
|
|
8507
8741
|
lastTradeTimestamp
|
|
8742
|
+
lastTradeTimestamp_0
|
|
8743
|
+
lastTradeTimestamp_1
|
|
8744
|
+
topOfBook {
|
|
8745
|
+
outcome
|
|
8746
|
+
side
|
|
8747
|
+
topTick
|
|
8748
|
+
}
|
|
8508
8749
|
totalVolume
|
|
8509
8750
|
totalOrders
|
|
8510
8751
|
createdAt
|
|
@@ -8560,6 +8801,13 @@ var GET_UNIFIED_MARKET_FEED = gql`
|
|
|
8560
8801
|
lastPriceTick_0
|
|
8561
8802
|
lastPriceTick_1
|
|
8562
8803
|
lastTradeTimestamp
|
|
8804
|
+
lastTradeTimestamp_0
|
|
8805
|
+
lastTradeTimestamp_1
|
|
8806
|
+
topOfBook {
|
|
8807
|
+
outcome
|
|
8808
|
+
side
|
|
8809
|
+
topTick
|
|
8810
|
+
}
|
|
8563
8811
|
# Statistics
|
|
8564
8812
|
totalVolume
|
|
8565
8813
|
totalOrders
|
|
@@ -8652,8 +8900,17 @@ var GET_UNIFIED_MARKET_FEED_BY_VOLUME = gql`
|
|
|
8652
8900
|
status
|
|
8653
8901
|
collateralToken
|
|
8654
8902
|
groupId
|
|
8903
|
+
tickSize
|
|
8655
8904
|
lastPriceTick_0
|
|
8656
8905
|
lastPriceTick_1
|
|
8906
|
+
lastTradeTimestamp
|
|
8907
|
+
lastTradeTimestamp_0
|
|
8908
|
+
lastTradeTimestamp_1
|
|
8909
|
+
topOfBook {
|
|
8910
|
+
outcome
|
|
8911
|
+
side
|
|
8912
|
+
topTick
|
|
8913
|
+
}
|
|
8657
8914
|
totalVolume
|
|
8658
8915
|
totalOrders
|
|
8659
8916
|
uniqueTraders
|
|
@@ -8680,17 +8937,28 @@ var GET_UNIFIED_MARKET_FEED_BY_VOLUME = gql`
|
|
|
8680
8937
|
marketQuestion
|
|
8681
8938
|
status
|
|
8682
8939
|
totalMarkets
|
|
8940
|
+
activeMarketCount
|
|
8941
|
+
resolvedMarketId
|
|
8683
8942
|
tags
|
|
8684
8943
|
metadataURI
|
|
8685
|
-
resolvedMarketId
|
|
8686
8944
|
createdAt
|
|
8945
|
+
activatedAt
|
|
8946
|
+
resolvedAt
|
|
8687
8947
|
venue {
|
|
8688
8948
|
id
|
|
8689
8949
|
venueId
|
|
8690
8950
|
name
|
|
8691
8951
|
}
|
|
8952
|
+
creator {
|
|
8953
|
+
id
|
|
8954
|
+
address
|
|
8955
|
+
}
|
|
8692
8956
|
markets {
|
|
8957
|
+
id
|
|
8693
8958
|
marketId
|
|
8959
|
+
question
|
|
8960
|
+
status
|
|
8961
|
+
groupId
|
|
8694
8962
|
tickSize
|
|
8695
8963
|
lastPriceTick_0
|
|
8696
8964
|
lastPriceTick_1
|
|
@@ -8725,6 +8993,13 @@ var GET_ALL_MARKETS_FEED = gql`
|
|
|
8725
8993
|
lastPriceTick_0
|
|
8726
8994
|
lastPriceTick_1
|
|
8727
8995
|
lastTradeTimestamp
|
|
8996
|
+
lastTradeTimestamp_0
|
|
8997
|
+
lastTradeTimestamp_1
|
|
8998
|
+
topOfBook {
|
|
8999
|
+
outcome
|
|
9000
|
+
side
|
|
9001
|
+
topTick
|
|
9002
|
+
}
|
|
8728
9003
|
totalVolume
|
|
8729
9004
|
totalOrders
|
|
8730
9005
|
uniqueTraders
|
|
@@ -8806,9 +9081,19 @@ var GET_ALL_MARKETS_FEED_BY_VOLUME = gql`
|
|
|
8806
9081
|
outcomes
|
|
8807
9082
|
status
|
|
8808
9083
|
collateralToken
|
|
9084
|
+
conditionId
|
|
9085
|
+
tickSize
|
|
8809
9086
|
groupId
|
|
8810
9087
|
lastPriceTick_0
|
|
8811
9088
|
lastPriceTick_1
|
|
9089
|
+
lastTradeTimestamp
|
|
9090
|
+
lastTradeTimestamp_0
|
|
9091
|
+
lastTradeTimestamp_1
|
|
9092
|
+
topOfBook {
|
|
9093
|
+
outcome
|
|
9094
|
+
side
|
|
9095
|
+
topTick
|
|
9096
|
+
}
|
|
8812
9097
|
totalVolume
|
|
8813
9098
|
totalOrders
|
|
8814
9099
|
uniqueTraders
|
|
@@ -8819,6 +9104,10 @@ var GET_ALL_MARKETS_FEED_BY_VOLUME = gql`
|
|
|
8819
9104
|
venueId
|
|
8820
9105
|
name
|
|
8821
9106
|
}
|
|
9107
|
+
creator {
|
|
9108
|
+
id
|
|
9109
|
+
address
|
|
9110
|
+
}
|
|
8822
9111
|
}
|
|
8823
9112
|
|
|
8824
9113
|
marketGroups(
|
|
@@ -8833,16 +9122,28 @@ var GET_ALL_MARKETS_FEED_BY_VOLUME = gql`
|
|
|
8833
9122
|
marketQuestion
|
|
8834
9123
|
status
|
|
8835
9124
|
totalMarkets
|
|
8836
|
-
|
|
9125
|
+
activeMarketCount
|
|
8837
9126
|
resolvedMarketId
|
|
9127
|
+
metadataURI
|
|
8838
9128
|
createdAt
|
|
9129
|
+
activatedAt
|
|
9130
|
+
resolvedAt
|
|
8839
9131
|
venue {
|
|
8840
9132
|
id
|
|
8841
9133
|
venueId
|
|
8842
9134
|
name
|
|
8843
9135
|
}
|
|
9136
|
+
creator {
|
|
9137
|
+
id
|
|
9138
|
+
address
|
|
9139
|
+
}
|
|
8844
9140
|
markets {
|
|
9141
|
+
id
|
|
8845
9142
|
marketId
|
|
9143
|
+
question
|
|
9144
|
+
status
|
|
9145
|
+
groupId
|
|
9146
|
+
tickSize
|
|
8846
9147
|
lastPriceTick_0
|
|
8847
9148
|
lastPriceTick_1
|
|
8848
9149
|
totalVolume
|
|
@@ -8866,6 +9167,7 @@ var GET_RECENT_TRADES = gql`
|
|
|
8866
9167
|
market {
|
|
8867
9168
|
marketId
|
|
8868
9169
|
question
|
|
9170
|
+
outcomes
|
|
8869
9171
|
venue {
|
|
8870
9172
|
venueId
|
|
8871
9173
|
name
|
|
@@ -9312,20 +9614,21 @@ var PublicModule = class extends BaseModule {
|
|
|
9312
9614
|
return limit ? merged.slice(0, limit) : merged;
|
|
9313
9615
|
}
|
|
9314
9616
|
/**
|
|
9315
|
-
* Calculate probability for a market using
|
|
9617
|
+
* Calculate probability for a market using mark price waterfall.
|
|
9316
9618
|
* Returns probability as a decimal string (e.g., "0.65" for 65%)
|
|
9317
9619
|
*
|
|
9318
|
-
*
|
|
9620
|
+
* Uses Polymarket-style pricing: implied midpoint → last trade → default 50%.
|
|
9621
|
+
*
|
|
9622
|
+
* @param market - Market object from subgraph (with topOfBook and timestamp fields)
|
|
9319
9623
|
* @returns Probability string or null if no data available
|
|
9320
9624
|
*/
|
|
9321
9625
|
calculateMarketProbability(market) {
|
|
9322
|
-
if (market.
|
|
9323
|
-
|
|
9324
|
-
|
|
9325
|
-
|
|
9326
|
-
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;
|
|
9327
9630
|
}
|
|
9328
|
-
return
|
|
9631
|
+
return (chance / 100).toFixed(2);
|
|
9329
9632
|
}
|
|
9330
9633
|
/**
|
|
9331
9634
|
* Format market group for display (Polymarket-style)
|
|
@@ -9554,6 +9857,15 @@ var TokenModule = class extends BaseModule {
|
|
|
9554
9857
|
});
|
|
9555
9858
|
}
|
|
9556
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
|
+
];
|
|
9557
9869
|
var UmaModule = class extends BaseModule {
|
|
9558
9870
|
/**
|
|
9559
9871
|
* Assert an outcome for a market question
|
|
@@ -9575,14 +9887,8 @@ var UmaModule = class extends BaseModule {
|
|
|
9575
9887
|
args: [params.marketId]
|
|
9576
9888
|
});
|
|
9577
9889
|
const questionId = registryData.questionId;
|
|
9578
|
-
const
|
|
9579
|
-
|
|
9580
|
-
abi: MarketsFacet_default,
|
|
9581
|
-
functionName: "getMarketOracleData",
|
|
9582
|
-
args: [params.marketId]
|
|
9583
|
-
});
|
|
9584
|
-
const bondAmount = BigInt(oracleData.requiredBond);
|
|
9585
|
-
const currency = oracleData.currency;
|
|
9890
|
+
const { effectiveBond, currency } = await this.getEffectiveBond(params.marketId);
|
|
9891
|
+
const bondAmount = effectiveBond;
|
|
9586
9892
|
const currentAllowance = await this.publicClient.readContract({
|
|
9587
9893
|
address: currency,
|
|
9588
9894
|
abi: erc20Abi,
|
|
@@ -9639,6 +9945,33 @@ var UmaModule = class extends BaseModule {
|
|
|
9639
9945
|
});
|
|
9640
9946
|
return wallet.writeContract(request);
|
|
9641
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
|
+
}
|
|
9642
9975
|
/**
|
|
9643
9976
|
* Settle an assertion after the liveness period
|
|
9644
9977
|
*/
|
|
@@ -10426,11 +10759,19 @@ function createOddMakiClient(params) {
|
|
|
10426
10759
|
|
|
10427
10760
|
// src/constants.ts
|
|
10428
10761
|
var PROTOCOL_FEES = {
|
|
10429
|
-
/** Protocol fee:
|
|
10430
|
-
PROTOCOL_FEE_BPS:
|
|
10762
|
+
/** Protocol fee: 50 bps (0.50%) — configurable via ProtocolFacet.setProtocolFeeBps() */
|
|
10763
|
+
PROTOCOL_FEE_BPS: 50n,
|
|
10431
10764
|
/** Operator fee: 10 bps (0.10%) for match operators */
|
|
10432
10765
|
OPERATOR_FEE_BPS: 10n
|
|
10433
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
|
+
};
|
|
10434
10775
|
|
|
10435
10776
|
// src/utils/metadata.ts
|
|
10436
10777
|
var DEFAULT_IPFS_GATEWAY = "https://gateway.pinata.cloud/ipfs/";
|
|
@@ -10458,6 +10799,6 @@ function parseMetadata(json) {
|
|
|
10458
10799
|
// src/index.ts
|
|
10459
10800
|
var version = "0.1.0";
|
|
10460
10801
|
|
|
10461
|
-
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 };
|
|
10462
10803
|
//# sourceMappingURL=index.mjs.map
|
|
10463
10804
|
//# sourceMappingURL=index.mjs.map
|