Skip to content

Commit

Permalink
Merge branch 'main' into pedro/cow-129-adddata-repo-functions
Browse files Browse the repository at this point in the history
  • Loading branch information
ribeirojose committed Sep 10, 2024
2 parents 20799ee + 55f17b7 commit 2c445e6
Show file tree
Hide file tree
Showing 29 changed files with 1,099 additions and 830 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
PRIVATE_KEY=
E2E_GNOSIS_MAINNET_TESTING_EOA_PRIVATE_KEY=
12 changes: 6 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
workflow_dispatch:
pull_request:
push:
branches: main
branches: main
release:
types: [released]

Expand All @@ -13,9 +13,7 @@ jobs:
runs-on: ubuntu-22.04
strategy:
matrix:
python-version: [
"3.10", "3.11", "3.12",
]
python-version: ["3.10", "3.11", "3.12"]
timeout-minutes: 10
steps:
- name: Checkout
Expand Down Expand Up @@ -49,6 +47,8 @@ jobs:
poetry run ruff check .
- name: Test
env:
E2E_GNOSIS_MAINNET_TESTING_EOA_PRIVATE_KEY: ${{ secrets.E2E_GNOSIS_MAINNET_TESTING_EOA_PRIVATE_KEY }}
run: |
poetry run pytest tests/
Expand All @@ -57,7 +57,7 @@ jobs:
poetry build -f sdist
- name: Archive production artifacts
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v3
with:
name: wheels
path: |
Expand All @@ -83,4 +83,4 @@ jobs:
- name: Publish package (prod)
if: github.event_name == 'release'
run: |
poetry publish --no-interaction -vvv
poetry publish --no-interaction -vvv
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ celerybeat.pid
*.sage.py

# Environments
.env
.env*
.venv
env/
venv/
Expand Down
8 changes: 0 additions & 8 deletions CODEOWNERS

This file was deleted.

9 changes: 5 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
.PHONY: codegen web3_codegen orderbook_codegen subgraph_codegen test lint format remove_unused_imports

codegen: web3_codegen orderbook_codegen subgraph_codegen
codegen: web3_codegen orderbook_codegen
# codegen: web3_codegen orderbook_codegen subgraph_codegen

# web3_codegen:
# poetry run web3_codegen
web3_codegen:
poetry run python -m cow_py.codegen.main

orderbook_codegen:
poetry run datamodel-codegen --url="https://raw.githubusercontent.com/cowprotocol/services/v2.245.1/crates/orderbook/openapi.yml" --output cow_py/order_book/generated/model.py --target-python-version 3.12 --output-model-type pydantic_v2.BaseModel --input-file-type openapi
poetry run datamodel-codegen --url="https://raw.githubusercontent.com/cowprotocol/services/main/crates/orderbook/openapi.yml" --output cow_py/order_book/generated/model.py --target-python-version 3.12 --output-model-type pydantic_v2.BaseModel --input-file-type openapi

subgraph_codegen:
poetry run ariadne-codegen
Expand Down
92 changes: 77 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ print(orders)

## 🐄 Project Structure

- `common/`(WIP): Utilities and configurations, the backbone of the SDK.
- `common/`: Utilities and configurations, the backbone of the SDK.
- `contracts/`(TODO): A pasture of Smart contract ABIs for interaction.
- `order_book/`(TODO): Functions to wrangle orders on the CoW Protocol.
- `order_book/`: Functions to wrangle orders on the CoW Protocol.
- `order_signing/`(TODO): Tools for signing and validating orders. Anything inside this module should use higher level modules, and the process of actually signing (ie. calling the web3 function to generate the signature, should be handled in contracts, not here).
- `subgraph/`(WIP): GraphQL client for querying CoW Protocol's Subgraph.
- `subgraph/`: GraphQL client for querying CoW Protocol's Subgraph.
- `web3/`: Web3 providers for blockchain interactions.

## 🐄 How to Use
Expand Down Expand Up @@ -87,20 +87,81 @@ data = client.get_data(response)
pprint(data)
```

### Signing an Order (TODO)
Or you can leverage `SubgraphClient` to use a custom query and get the results as JSON:

```python
from cow_py.order_signing import sign_order
from pprint import pprint
from cow_py.subgraph.client import SubgraphClient

# Example order details
order_details = {
"sell_token": "0x...",
"buy_token": "0x...",
"sell_amount": 100000,
}
url = build_subgraph_url() # Default network is Chain.MAINNET and env SubgraphEnvironment.PRODUCTION
client = SubgraphClient(url=url)

signed_order = sign_order(order_details, private_key="your_private_key")
print(signed_order)
response = await client.execute(query="""
query LastDaysVolume($days: Int!) {
dailyTotals(orderBy: timestamp, orderDirection: desc, first: $days) {
timestamp
volumeUsd
}
}
""", variables=dict(days=2)
)

data = client.get_data(response)
pprint(data)
```

## 🐄 Development

### 🐄 Tests

Run tests to ensure everything's working:

```bash
make test # or poetry run pytest
```

### 🐄 Formatting/Linting

Run the formatter and linter:

```bash
make format # or ruff check . --fix
make lint # or ruff format
```

### 🐄 Codegen

Generate the SDK from the CoW Protocol smart contracts, Subgraph, and Orderbook API:

```bash
make codegen
```

## 🐄 Development

### 🐄 Tests

Run tests to ensure everything's working:

```bash
make test # or poetry run pytest
```

### 🐄 Formatting/Linting

Run the formatter and linter:

```bash
make format # or ruff check . --fix
make lint # or ruff format
```

### 🐄 Codegen

Generate the SDK from the CoW Protocol smart contracts, Subgraph, and Orderbook API:

```bash
make codegen
```

## 🐄 Development
Expand Down Expand Up @@ -141,10 +202,11 @@ cd cow-py
poetry install
```

Run tests to ensure everything's working:
After making changes, make sure to run the appropriate code generation tasks and tests:

```bash
poetry run pytest
make codegen
make test
```

## 🐄 Need Help?
Expand Down
10 changes: 4 additions & 6 deletions cow_py/codegen/__generated__/ComposableCow.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 3 additions & 5 deletions cow_py/codegen/__generated__/ExtensibleFallbackHandler.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions cow_py/codegen/__generated__/Milkman.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 4 additions & 6 deletions cow_py/codegen/__generated__/TWAP.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions cow_py/codegen/abi_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,17 @@ def to_python_conventional_name(name: str) -> str:
return CAMEL_TO_SNAKE_REGEX.sub("_", name).lower()


def to_camel_case(name: str) -> str:
"""Converts a snake_case name to a camelCase name."""
name = name.lower()
return name[0] + name.title().replace("_", "")[1:]


def dict_keys_to_camel_case(d: Dict[str, Any]) -> Dict[str, Any]:
"""Converts all keys in a dictionary to camelCase."""
return {to_camel_case(k): v for k, v in d.items()}


def _get_template_file() -> str:
pkg_files = importlib.resources.files(templates)
return str(next(x for x in pkg_files.iterdir() if x.suffix == ".hbs")) # type: ignore
Expand Down
Loading

0 comments on commit 2c445e6

Please sign in to comment.