Skip to content
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

CI FIX #13

Merged
merged 3 commits into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
strategy:
matrix:
python-version: [
"3.8", "3.9", "3.10", "3.11", "3.12",
"3.10", "3.11", "3.12",
]
timeout-minutes: 10
steps:
Expand All @@ -32,6 +32,10 @@ jobs:
cache: poetry
cache-dependency-path: poetry.lock

- name: Poetry lock
run: |
poetry lock

- name: Install dependencies
run: |
poetry install
Expand Down
14 changes: 3 additions & 11 deletions cow_py/codegen/solidity_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
"int": "int",
}
DYNAMIC_SOLIDITY_TYPES = {
f"{prefix}{i*8 if prefix != 'bytes' else i}": "int"
if prefix != "bytes"
else "HexBytes"
f"{prefix}{i*8 if prefix != 'bytes' else i}": (
"int" if prefix != "bytes" else "HexBytes"
)
for prefix in ["uint", "int", "bytes"]
for i in range(1, 33)
}
Expand Down Expand Up @@ -97,11 +97,3 @@ def _convert_array_or_basic_type(solidity_type: str) -> str:
return f'Tuple[{", ".join([SOLIDITY_TO_PYTHON_TYPES.get(base_type, "Any")] * size)}]'
else:
return SOLIDITY_TO_PYTHON_TYPES.get(solidity_type, "Any")

@staticmethod
def _get_struct_name(internal_type: str) -> str:
if not internal_type or "struct " not in internal_type:
raise SolidityConverterError(
f"Invalid internal type for struct: {internal_type}"
)
return internal_type.replace("struct ", "").replace(".", "_").replace("[]", "")
14 changes: 10 additions & 4 deletions cow_py/order_book/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from cow_py.common.api.api_base import ApiBase, Context
from cow_py.common.config import SupportedChainId
from cow_py.order_book.config import OrderBookAPIConfigFactory
from typing import Union
from cow_py.order_book.generated.model import OrderQuoteSide2, OrderQuoteValidity2

from .generated.model import (
UID,
Expand All @@ -17,6 +19,8 @@
OrderQuoteRequest,
OrderQuoteResponse,
OrderQuoteSide,
OrderQuoteSide1,
OrderQuoteSide3,
OrderQuoteValidity,
OrderQuoteValidity1,
SolverCompetitionResponse,
Expand Down Expand Up @@ -122,7 +126,7 @@ async def get_app_data(
)

async def get_solver_competition(
self, action_id: int = "latest", context_override: Context = {}
self, action_id: Union[int, str] = "latest", context_override: Context = {}
) -> SolverCompetitionResponse:
response = await self._fetch(
path=f"/api/v1/solver_competition/{action_id}",
Expand All @@ -142,8 +146,10 @@ async def get_solver_competition_by_tx_hash(
async def post_quote(
self,
request: OrderQuoteRequest,
side: OrderQuoteSide,
validity: OrderQuoteValidity = OrderQuoteValidity1(validTo=None),
side: Union[OrderQuoteSide, OrderQuoteSide1, OrderQuoteSide2, OrderQuoteSide3],
validity: Union[
OrderQuoteValidity, OrderQuoteValidity1, OrderQuoteValidity2
] = OrderQuoteValidity1(validTo=None),
context_override: Context = {},
) -> OrderQuoteResponse:
response = await self._fetch(
Expand Down Expand Up @@ -184,7 +190,7 @@ async def delete_order(
async def put_app_data(
self,
app_data: AppDataObject,
app_data_hash: str = None,
app_data_hash: str = "",
context_override: Context = {},
) -> AppDataHash:
app_data_hash_url = app_data_hash if app_data_hash else ""
Expand Down
38 changes: 21 additions & 17 deletions examples/order_posting_e2e.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@
from cow_py.contracts.sign import sign_order as _sign_order
from cow_py.order_book.api import OrderBookApi
from cow_py.order_book.config import OrderBookAPIConfigFactory
from cow_py.order_book.generated.model import OrderQuoteSide1, TokenAmount
from cow_py.order_book.generated.model import OrderQuoteSideKindSell
from cow_py.order_book.generated.model import (
UID,
OrderCreation,
OrderQuoteRequest,
OrderQuoteResponse,
OrderQuoteSide,
)

BUY_TOKEN = "0xfFf9976782d46CC05630D1f6eBAb18b2324d6B14" # WETH
Expand All @@ -41,7 +42,7 @@


async def get_order_quote(
order_quote_request: OrderQuoteRequest, order_side: OrderQuoteSide
order_quote_request: OrderQuoteRequest, order_side: OrderQuoteSide1
) -> OrderQuoteResponse:
return await ORDER_BOOK_API.post_quote(order_quote_request, order_side)

Expand All @@ -59,19 +60,21 @@ def sign_order(order: Order) -> EcdsaSignature:

async def post_order(order: Order, signature: EcdsaSignature) -> UID:
order_creation = OrderCreation(
sellToken=order.sellToken,
buyToken=order.buyToken,
sellAmount=order.sellAmount,
feeAmount=order.feeAmount,
buyAmount=order.buyAmount,
validTo=order.validTo,
kind=order.kind,
partiallyFillable=order.partiallyFillable,
appData=order.appData,
signature=signature.data,
signingScheme="eip712",
receiver=order.receiver,
**{"from": ADDRESS},
**{
"from": ADDRESS,
"sellToken": order.sellToken,
"buyToken": order.buyToken,
"sellAmount": order.sellAmount,
"feeAmount": order.feeAmount,
"buyAmount": order.buyAmount,
"validTo": order.validTo,
"kind": order.kind,
"partiallyFillable": order.partiallyFillable,
"appData": order.appData,
"signature": signature.data,
"signingScheme": "eip712",
"receiver": order.receiver,
},
)
return await ORDER_BOOK_API.post_order(order_creation)

Expand All @@ -84,8 +87,9 @@ async def main():
"from": ADDRESS,
}
)
order_side = OrderQuoteSide(
kind=ORDER_KIND, sellAmountBeforeFee=SELL_AMOUNT_BEFORE_FEE
order_side = OrderQuoteSide1(
kind=OrderQuoteSideKindSell.sell,
sellAmountBeforeFee=TokenAmount(SELL_AMOUNT_BEFORE_FEE),
)

order_quote = await get_order_quote(order_quote_request, order_side)
Expand Down
5 changes: 4 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ exclude = [
"**/node_modules",
"**/__pycache__",
"cow_py/subgraph/client/*.py",
# "cow_py/order_book/generated/*.py"
"cow_py/order_book/generated/*.py",
".venv/",
"**/__generated__"
]
reportIncompatibleVariableOverride = 'warning'
strictParameterNoneValue = false
3 changes: 2 additions & 1 deletion tests/common/api/test_api_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from cow_py.common.api.api_base import ApiBase, APIConfig
from cow_py.common.api.decorators import DEFAULT_BACKOFF_OPTIONS
from cow_py.common.config import SupportedChainId
from httpx import Request

ERROR_MESSAGE = "💣💥 Booom!"
OK_RESPONSE = {"status": 200, "ok": True, "content": {"some": "data"}}
Expand Down Expand Up @@ -48,7 +49,7 @@ def mock_success_response():
def mock_http_status_error():
return httpx.HTTPStatusError(
message=ERROR_MESSAGE,
request=None,
request=Request("GET", "http://example.com"),
response=httpx.Response(500),
)

Expand Down
39 changes: 26 additions & 13 deletions tests/order_book/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
import pytest

from cow_py.order_book.api import OrderBookApi
from cow_py.order_book.generated.model import OrderQuoteSide1
from cow_py.order_book.generated.model import OrderQuoteSideKindSell
from cow_py.order_book.generated.model import TokenAmount
from cow_py.order_book.generated.model import (
OrderQuoteRequest,
OrderQuoteResponse,
OrderQuoteSide,
Trade,
OrderCreation,
)
Expand Down Expand Up @@ -74,7 +76,10 @@ async def test_post_quote(order_book_api):
"onchainOrder": False,
}
)
mock_order_quote_side = OrderQuoteSide(sellAmountBeforeFee="0", kind="sell")

mock_order_quote_side = OrderQuoteSide1(
sellAmountBeforeFee=TokenAmount("0"), kind=OrderQuoteSideKindSell.sell
)
mock_order_quote_response_data = {
"quote": {
"sellToken": "0x",
Expand Down Expand Up @@ -112,17 +117,25 @@ async def test_post_quote(order_book_api):
async def test_post_order(order_book_api):
mock_response = "mock_uid"
mock_order_creation = OrderCreation(
sellToken="0x",
buyToken="0x",
sellAmount="0",
buyAmount="0",
validTo=0,
feeAmount="0",
kind="buy",
partiallyFillable=True,
appData="0x",
signingScheme="eip712",
signature="0x",
**{
"sellToken": "0x",
"buyToken": "0x",
"sellAmount": "0",
"buyAmount": "0",
"validTo": 0,
"feeAmount": "0",
"kind": "buy",
"partiallyFillable": True,
"appData": "0x",
"signingScheme": "eip712",
"signature": "0x",
"receiver": "0x",
"sellTokenBalance": "erc20",
"buyTokenBalance": "erc20",
"quoteId": 0,
"appDataHash": "0x",
"from_": "0x",
}
)
with patch("httpx.AsyncClient.request", new_callable=AsyncMock) as mock_request:
mock_request.return_value = AsyncMock(
Expand Down
44 changes: 0 additions & 44 deletions tests/subgraphs/deployments.py

This file was deleted.

Loading