Skip to content

Commit

Permalink
#6 breakdown pt2 - add contracts module (#10)
Browse files Browse the repository at this point in the history
* add new repo structure

* add codegen (contracts, subgraph), order signing and order book API interface

* refactor repo configs/readme

* add codegen module

* add common module

* remove stale subgraphs/core modules

* add contracts module

* add order_book module

* add order posting example

* remove web3_codegen from Makefile

* remove order signing TODO from readme

* fix PR reviews

* remove duplicated ETH constant address

* fix lint

* remove eth but address constant

* add types of domain and add order hashing tests

* fix types

* fix type in order_posting_e2e test

* add generated files to lib

---------

Co-authored-by: José Ribeiro <me@joseribeiro.dev>
  • Loading branch information
yvesfracari and ribeirojose committed Sep 6, 2024
1 parent a0bb9d9 commit 0f163e8
Show file tree
Hide file tree
Showing 18 changed files with 2,287 additions and 12 deletions.
104 changes: 94 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,20 +87,104 @@ 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

url = build_subgraph_url() # Default network is Chain.MAINNET and env SubgraphEnvironment.PRODUCTION
client = SubgraphClient(url=url)

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)
```

Or you can leverage `SubgraphClient` to use a custom query and get the results as JSON:

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

url = build_subgraph_url() # Default network is Chain.MAINNET and env SubgraphEnvironment.PRODUCTION
client = SubgraphClient(url=url)

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

# Example order details
order_details = {
"sell_token": "0x...",
"buy_token": "0x...",
"sell_amount": 100000,
}
### 🐄 Tests

Run tests to ensure everything's working:

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

### 🐄 Formatting/Linting

signed_order = sign_order(order_details, private_key="your_private_key")
print(signed_order)
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
143 changes: 143 additions & 0 deletions cow_py/codegen/__generated__/ComposableCow.py

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

101 changes: 101 additions & 0 deletions cow_py/codegen/__generated__/ExtensibleFallbackHandler.py

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

Loading

0 comments on commit 0f163e8

Please sign in to comment.