Skip to content

Commit

Permalink
Use nft address for filtering predictoor contracts (#692)
Browse files Browse the repository at this point in the history
  • Loading branch information
trizin authored Aug 19, 2023
1 parent a9bdee9 commit 7ad957f
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 7 deletions.
4 changes: 3 additions & 1 deletion df_py/predictoor/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ def from_query_result(cls, prediction_dict: Dict) -> "Prediction":
ValueError: If the input dictionary is invalid.
"""
try:
contract_addr = prediction_dict["slot"]["predictContract"]["id"]
contract_addr = prediction_dict["slot"]["predictContract"]["token"]["nft"][
"id"
]
slot = int(prediction_dict["slot"]["slot"])
payout = float(prediction_dict["payout"]["payout"])
except (KeyError, TypeError, ValueError) as exc:
Expand Down
7 changes: 6 additions & 1 deletion df_py/predictoor/predictoor_testutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,12 @@ def create_mock_response(statuses: List[str], payouts: List[float], users: List[
"status": status,
"predictContract": {
"id": "0x1733696512e69cd0c4430f909dcbf54c54c15441",
"token": {"nft": {"owner": {"id": "0x0"}}},
"token": {
"nft": {
"id": "0x0000cB88fbf9F240835fCd26BD903C4de1761cEa",
"owner": {"id": "0x0"},
}
},
},
"slot": "5520",
},
Expand Down
8 changes: 5 additions & 3 deletions df_py/predictoor/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def query_predictoor_contracts(chain_id: int) -> Dict[str, PredictContract]:
name
symbol
nft {
id
owner {
id
}
Expand Down Expand Up @@ -67,16 +68,16 @@ def query_predictoor_contracts(chain_id: int) -> Dict[str, PredictContract]:
if chain_id != DEV_CHAINID and owner["id"] not in DEPLOYER_ADDRS:
continue

contract_addr = contract["id"]
nft_addr = contract["nft"]["id"]
contract_obj = PredictContract(
chain_id,
contract_addr,
nft_addr,
contract["token"]["name"],
contract["token"]["symbol"],
contract["blocksPerEpoch"],
contract["blocksPerSubscription"],
)
contracts_dict[contract_addr] = contract_obj
contracts_dict[nft_addr] = contract_obj

return contracts_dict

Expand Down Expand Up @@ -120,6 +121,7 @@ def query_predictoors(
id
token {
nft {
id
owner {
id
}
Expand Down
4 changes: 2 additions & 2 deletions df_py/predictoor/test/test_predictoor_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ def test_prediction_is_correct():
def test_prediction_from_query_result():
prediction_dict = {
"slot": {
"predictContract": {"id": "0x1"},
"predictContract": {"id": "0x1", "token": {"nft": {"id": "0x2"}}},
"slot": "123",
},
"payout": {"payout": "1.23"},
}
prediction = Prediction.from_query_result(prediction_dict)
assert prediction.slot == 123
assert prediction.payout == 1.23
assert prediction.contract_addr == "0x1"
assert prediction.contract_addr == "0x2"
with pytest.raises(ValueError):
prediction_dict = {"slot": {"predictContract": "0x123"}, "payout": "invalid"}
Prediction.from_query_result(prediction_dict)
Expand Down

0 comments on commit 7ad957f

Please sign in to comment.