Skip to content

Commit

Permalink
Merge branch 'main' into peter/gcp-secrets-labels
Browse files Browse the repository at this point in the history
  • Loading branch information
kongzii authored Feb 15, 2024
2 parents 6539291 + 9234c2b commit 0079c55
Show file tree
Hide file tree
Showing 22 changed files with 258 additions and 183 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/python_ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,23 @@ jobs:
- uses: ./.github/actions/python_prepare
- name: Check with black
run: poetry run black --check .

autoflake:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: ./.github/actions/python_prepare
- name: Check with autoflake
run: |
poetry run autoflake --in-place --remove-all-unused-imports --remove-unused-variables --recursive .
git diff --exit-code --quiet || exit 1
isort:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: ./.github/actions/python_prepare
- name: Check with isort
run: |
poetry run isort --profile black .
git diff --exit-code --quiet || exit 1
7 changes: 4 additions & 3 deletions examples/cloud_deployment/gcp/agent.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from flask.wrappers import Request
import functions_framework
import random

from prediction_market_agent_tooling.markets.data_models import AgentMarket
import functions_framework
from flask.wrappers import Request

from prediction_market_agent_tooling.deploy.agent import DeployableAgent
from prediction_market_agent_tooling.markets.data_models import AgentMarket
from prediction_market_agent_tooling.markets.markets import MarketType


Expand Down
1 change: 1 addition & 0 deletions examples/cloud_deployment/gcp/deploy.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
import getpass

from prediction_market_agent_tooling.config import APIKeys
from prediction_market_agent_tooling.deploy.gcp.deploy import (
deploy_to_gcp,
remove_deployed_gcp_function,
Expand Down
1 change: 1 addition & 0 deletions examples/monitor/monitor.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from datetime import datetime, timedelta
from zoneinfo import ZoneInfo

import streamlit as st

from prediction_market_agent_tooling.markets.manifold import get_authenticated_user
Expand Down
248 changes: 144 additions & 104 deletions poetry.lock

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion prediction_market_agent_tooling/config.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import typing as t

from pydantic_settings import BaseSettings, SettingsConfigDict

from prediction_market_agent_tooling.gtypes import ChecksumAddress, PrivateKey
from prediction_market_agent_tooling.tools.utils import check_not_none
from prediction_market_agent_tooling.tools.web3_utils import verify_address
from prediction_market_agent_tooling.gtypes import ChecksumAddress, PrivateKey


class APIKeys(BaseSettings):
Expand Down
15 changes: 8 additions & 7 deletions prediction_market_agent_tooling/deploy/agent.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import time
from decimal import Decimal
from enum import Enum

from pydantic import BaseModel
from decimal import Decimal
from prediction_market_agent_tooling.markets.data_models import AgentMarket

from prediction_market_agent_tooling.markets.data_models import (
AgentMarket,
BetAmount,
Currency,
)
from prediction_market_agent_tooling.markets.markets import (
MarketType,
get_binary_markets,
place_bet,
)
from prediction_market_agent_tooling.config import APIKeys
from prediction_market_agent_tooling.markets.data_models import (
BetAmount,
Currency,
)


class DeploymentType(str, Enum):
Expand Down
8 changes: 5 additions & 3 deletions prediction_market_agent_tooling/deploy/gcp/deploy.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import os
import requests
import shutil
import subprocess
import tempfile
import typing as t

import requests
from cron_validator import CronValidator

from prediction_market_agent_tooling.deploy.agent import DeployableAgent
from prediction_market_agent_tooling.tools.utils import export_requirements_from_toml
from prediction_market_agent_tooling.deploy.gcp.utils import (
gcloud_create_topic_cmd,
gcloud_delete_function_cmd,
Expand All @@ -16,7 +18,7 @@
get_gcloud_id_token,
)
from prediction_market_agent_tooling.markets.markets import MarketType
from cron_validator import CronValidator
from prediction_market_agent_tooling.tools.utils import export_requirements_from_toml


def deploy_to_gcp(
Expand Down
1 change: 1 addition & 0 deletions prediction_market_agent_tooling/deploy/gcp/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import subprocess
import sys

from google.cloud.functions_v2.services.function_service.client import (
FunctionServiceClient,
)
Expand Down
11 changes: 6 additions & 5 deletions prediction_market_agent_tooling/gtypes.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
from decimal import Decimal
from typing import NewType, Union
from web3.types import Wei
from eth_typing.evm import (

from eth_typing.evm import ( # noqa: F401 # Import for the sake of easy importing with others from here.
Address,
HexStr,
HexAddress,
ChecksumAddress,
) # noqa: F401 # Import for the sake of easy importing with others from here.
HexAddress,
HexStr,
)
from web3.types import Wei

Wad = Wei # Wei tends to be referred to as `wad` variable in contracts.
USD = NewType(
Expand Down
9 changes: 5 additions & 4 deletions prediction_market_agent_tooling/markets/data_models.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
import typing as t
from datetime import datetime
from decimal import Decimal
from enum import Enum
import typing as t

from pydantic import BaseModel
from web3 import Web3

from prediction_market_agent_tooling.gtypes import (
USD,
HexAddress,
ChecksumAddress,
Probability,
HexAddress,
Mana,
OmenOutcomeToken,
xDai,
Probability,
Wei,
xDai,
)


Expand Down
12 changes: 7 additions & 5 deletions prediction_market_agent_tooling/markets/manifold.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
import typing as t
from datetime import datetime

import requests
import typing as t
from prediction_market_agent_tooling.gtypes import Mana

from prediction_market_agent_tooling.config import APIKeys
from prediction_market_agent_tooling.gtypes import Mana
from prediction_market_agent_tooling.markets.data_models import (
ProfitAmount,
ResolvedBet,
BetAmount,
Currency,
ManifoldBet,
ManifoldContractMetric,
ManifoldMarket,
ManifoldUser,
ManifoldContractMetric,
ProfitAmount,
ResolvedBet,
)

"""
Expand Down
14 changes: 6 additions & 8 deletions prediction_market_agent_tooling/markets/markets.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
from decimal import Decimal
import typing as t
from decimal import Decimal
from enum import Enum
from prediction_market_agent_tooling.markets.data_models import (
BetAmount,
Currency,
)
from prediction_market_agent_tooling.markets import manifold, omen

from prediction_market_agent_tooling.config import APIKeys
from prediction_market_agent_tooling.gtypes import Mana, xDai
from prediction_market_agent_tooling.markets import manifold, omen
from prediction_market_agent_tooling.markets.data_models import BetAmount, Currency
from prediction_market_agent_tooling.tools.utils import (
should_not_happen,
check_not_none,
should_not_happen,
)
from prediction_market_agent_tooling.config import APIKeys


class MarketType(str, Enum):
Expand Down
38 changes: 20 additions & 18 deletions prediction_market_agent_tooling/markets/omen.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,33 @@
"""

import os
import requests
from typing import Optional

import requests
from web3 import Web3
from web3.types import TxReceipt, TxParams
from prediction_market_agent_tooling.markets.data_models import OmenMarket
from prediction_market_agent_tooling.tools.web3_utils import (
call_function_on_contract,
call_function_on_contract_tx,
WXDAI_ABI,
xdai_to_wei,
remove_fraction,
add_fraction,
check_tx_receipt,
ONE_NONCE,
Nonce,
)
from prediction_market_agent_tooling.tools.gnosis_rpc import GNOSIS_RPC_URL
from web3.types import TxParams, TxReceipt

from prediction_market_agent_tooling.gtypes import (
ABI,
ChecksumAddress,
HexAddress,
OmenOutcomeToken,
PrivateKey,
xDai,
Wei,
ChecksumAddress,
OmenOutcomeToken,
xDai,
)
from prediction_market_agent_tooling.markets.data_models import OmenMarket
from prediction_market_agent_tooling.tools.gnosis_rpc import GNOSIS_RPC_URL
from prediction_market_agent_tooling.tools.web3_utils import (
ONE_NONCE,
WXDAI_ABI,
Nonce,
add_fraction,
call_function_on_contract,
call_function_on_contract_tx,
check_tx_receipt,
remove_fraction,
xdai_to_wei,
)

OMEN_TRUE_OUTCOME = "Yes"
Expand Down
7 changes: 4 additions & 3 deletions prediction_market_agent_tooling/monitor/monitor.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import altair as alt
import typing as t
from datetime import datetime
from pydantic import BaseModel

import altair as alt
import pandas as pd
import streamlit as st
import typing as t
from pydantic import BaseModel

from prediction_market_agent_tooling.markets.data_models import ResolvedBet

Expand Down
2 changes: 1 addition & 1 deletion prediction_market_agent_tooling/tools/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os
import subprocess
from typing import NoReturn, Type, TypeVar, Optional
from typing import NoReturn, Optional, Type, TypeVar

T = TypeVar("T")

Expand Down
14 changes: 8 additions & 6 deletions prediction_market_agent_tooling/tools/web3_utils.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import os
from typing import Optional, Any, TypeVar
from web3 import Web3
from decimal import Decimal
from web3.types import Wei, TxReceipt, TxParams, Nonce
from typing import Any, Optional, TypeVar

from web3 import Web3
from web3.types import Nonce, TxParams, TxReceipt, Wei

from prediction_market_agent_tooling.gtypes import (
ABI,
xDai,
PrivateKey,
ChecksumAddress,
xdai_type,
HexAddress,
HexStr,
PrivateKey,
xDai,
xdai_type,
)

ONE_NONCE = Nonce(1)
Expand Down
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ web3 = "^6.15.1"
eth-typing = "^4.0.0"
pydantic-settings = "^2.1.0"
numpy = "^1.26.4"
autoflake = "^2.2.1"
isort = "^5.13.2"
streamlit = "^1.31.0"

[tool.poetry.group.dev.dependencies]
Expand Down
11 changes: 4 additions & 7 deletions scripts/bet_omen.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import typer
from prediction_market_agent_tooling.tools.web3_utils import verify_address

from prediction_market_agent_tooling.gtypes import PrivateKey, xdai_type
from prediction_market_agent_tooling.markets.omen import (
omen_buy_outcome_tx,
get_market,
omen_buy_outcome_tx,
omen_sell_outcome_tx,
)
from prediction_market_agent_tooling.gtypes import (
PrivateKey,
xdai_type,
)
from eth_typing import HexStr
from prediction_market_agent_tooling.tools.web3_utils import verify_address

app = typer.Typer()

Expand Down
5 changes: 1 addition & 4 deletions tests/deploy/test_deploy.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import random

from prediction_market_agent_tooling.deploy.agent import DeployableAgent, DeploymentType
from prediction_market_agent_tooling.markets.data_models import AgentMarket
from prediction_market_agent_tooling.deploy.agent import (
DeployableAgent,
DeploymentType,
)
from prediction_market_agent_tooling.markets.markets import MarketType


Expand Down
5 changes: 3 additions & 2 deletions tests/markets/test_manifold.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import pytest
from tests.utils import RUN_PAID_TESTS
from prediction_market_agent_tooling.markets import manifold

from prediction_market_agent_tooling.gtypes import mana_type
from prediction_market_agent_tooling.markets import manifold
from tests.utils import RUN_PAID_TESTS


@pytest.mark.skipif(not RUN_PAID_TESTS, reason="This test costs money to run.")
Expand Down
6 changes: 4 additions & 2 deletions tests/markets/test_omen.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import time

import pytest
from tests.utils import RUN_PAID_TESTS

from prediction_market_agent_tooling.config import APIKeys
from prediction_market_agent_tooling.markets.markets import omen
from prediction_market_agent_tooling.gtypes import xdai_type
from prediction_market_agent_tooling.markets.markets import omen
from tests.utils import RUN_PAID_TESTS


def test_omen_pick_binary_market() -> None:
Expand Down

0 comments on commit 0079c55

Please sign in to comment.