-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP]: Polymarket support #195
base: main
Are you sure you want to change the base?
Changes from all commits
aa71fd3
9cc04d3
aa9a330
d004f23
ed30ffb
0f3a621
8c5806e
e06a52d
0bf24eb
dfc4949
6c6716e
42f77b3
3d51104
9783160
38b34ce
19c47fa
87eb59c
e76eca9
a188ba5
fe8c69b
d698fc7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
# -*- coding: utf-8 -*- | ||
# ------------------------------------------------------------------------------ | ||
# | ||
# Copyright 2023 Valory AG | ||
# Copyright 2023-2024 Valory AG | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
|
@@ -24,11 +24,21 @@ | |
import dataclasses | ||
import json | ||
import sys | ||
from datetime import datetime, timezone | ||
from enum import Enum, auto | ||
from typing import Any, Dict, List, Optional, Union | ||
|
||
|
||
BINARY_N_SLOTS = 2 | ||
USDC = "0x2791bca1f2de4661ed88a30c99a7a9449aa84174" | ||
NULL_ADDRESS = "0x" + "0" * 40 | ||
OMEN_TO_POLYWRAP = dict( | ||
id="marketMakerAddress", | ||
market="market", | ||
title="question", | ||
fee="fee", | ||
scaledLiquidityMeasure="liquidity", | ||
) | ||
|
||
|
||
class BetStatus(Enum): | ||
|
@@ -58,6 +68,32 @@ class Bet: | |
status: BetStatus = BetStatus.UNPROCESSED | ||
blacklist_expiration: float = -1 | ||
|
||
@classmethod | ||
def from_gamma_subgraph(cls, **kwargs: Any) -> "Bet": | ||
"""Initialize a bet's instance from gamma subgraph's attributes.""" | ||
Adamantios marked this conversation as resolved.
Show resolved
Hide resolved
|
||
outcomes = eval(kwargs["outcomes"]) # nosec | ||
outcome_token_amounts = [0] * len(outcomes) | ||
Adamantios marked this conversation as resolved.
Show resolved
Hide resolved
|
||
end_date = datetime.strptime(kwargs["endDate"], "%Y-%m-%dT%H:%M:%S.%fZ") | ||
opening_timestamp = int(end_date.replace(tzinfo=timezone.utc).timestamp()) | ||
submitted_by = kwargs["submitted_by"] or NULL_ADDRESS | ||
outcome_prices = eval(kwargs["outcomePrices"]) # nosec | ||
|
||
omen_to_polywrap_mapping = { | ||
omen_key: kwargs[polywrap_key] | ||
for omen_key, polywrap_key in OMEN_TO_POLYWRAP.items() | ||
} | ||
|
||
return cls( | ||
collateralToken=USDC, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TODO: make sure Note: we need to interact with both gnosis and polygon chains for Polymarket. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do you need to interact with both chains? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To interact with the mech on Gnosis. Is the mech deployed on Polygon? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We will deploy it on Polygon eventually. For testing use it on Gnosis There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If this is only for testing then it would be faster to test this by mocking the mech request-response part locally and keep the code unchanged for when the mech is deployed on Polygon. |
||
creator=submitted_by, | ||
openingTimestamp=opening_timestamp, | ||
outcomeSlotCount=len(outcomes), | ||
outcomeTokenAmounts=outcome_token_amounts, | ||
outcomeTokenMarginalPrices=outcome_prices, | ||
outcomes=outcomes, | ||
**omen_to_polywrap_mapping, | ||
) | ||
|
||
def __post_init__(self) -> None: | ||
"""Post initialization to adjust the values.""" | ||
self._validate() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
# -*- coding: utf-8 -*- | ||
# ------------------------------------------------------------------------------ | ||
# | ||
# Copyright 2023-2024 Valory AG | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
# ------------------------------------------------------------------------------ | ||
|
||
"""Polymarket queries.""" | ||
|
||
from string import Template | ||
|
||
|
||
questions_polymarket_gamma = Template( | ||
""" | ||
{ | ||
markets( | ||
where: "active=true AND closed=false AND outcomes='[\\\"Yes\\\", \\\"No\\\"]' AND NOT market_maker_address=''" | ||
order: "start_date DESC" | ||
limit: 100 | ||
) { | ||
marketMakerAddress | ||
question | ||
denominationToken | ||
submitted_by | ||
fee | ||
endDate | ||
outcomes | ||
outcomePrices | ||
liquidity | ||
} | ||
} | ||
""" | ||
) | ||
|
||
|
||
questions_polymarket = Template( | ||
""" | ||
{ | ||
fixedProductMarketMakers( | ||
where: { | ||
outcomeSlotCount: ${slot_count}, | ||
}, | ||
orderBy: creationTimestamp | ||
orderDirection: desc | ||
first: 1000 | ||
){ | ||
id | ||
collateralToken { | ||
id | ||
name | ||
symbol | ||
} | ||
creator | ||
fee | ||
outcomeSlotCount | ||
outcomeTokenAmounts | ||
outcomeTokenPrices | ||
scaledLiquidityParameter | ||
conditions { | ||
id | ||
questionId | ||
} | ||
} | ||
} | ||
""" | ||
) | ||
|
||
# Missing fields: | ||
# language_in: ${languages}, | ||
# openingTimestamp | ||
# outcomes | ||
|
||
|
||
# Different fields: | ||
# outcomeTokenMarginalPrices == outcomeTokenPrices ? | ||
# scaledLiquidityParameter == scaledLiquidityMeasure ? | ||
|
||
|
||
trades = Template( | ||
""" | ||
{ | ||
fpmmTrades ( | ||
where: { | ||
type: Buy, | ||
creator: "${creator}", | ||
fpmm_: { | ||
creationTimestamp_gt: "${creationTimestamp_gt}", | ||
answerFinalizedTimestamp_not: null, | ||
isPendingArbitration: false | ||
} | ||
} | ||
orderBy: fpmm__creationTimestamp | ||
orderDirection: asc | ||
first: ${first} | ||
){ | ||
fpmm { | ||
answerFinalizedTimestamp | ||
collateralToken | ||
condition { | ||
id | ||
outcomeSlotCount | ||
} | ||
creator | ||
creationTimestamp | ||
currentAnswer | ||
question { | ||
id | ||
data | ||
} | ||
templateId | ||
} | ||
outcomeIndex | ||
outcomeTokenMarginalPrice | ||
outcomeTokensTraded | ||
transactionHash | ||
} | ||
} | ||
""" | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
sample_bets_closing_days
override can be set to a large value to test kelly for Polymarket.