Skip to content

Commit

Permalink
#6 breakdown pt4 - add generated files and subgraph (#13)
Browse files Browse the repository at this point in the history
* 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

* add generated subgraph files

* add contract abis

* add generated codegen

* add generated order_book

* add generated api model

* add python-dotenv package

* refactor importing sort

* refactor .env usage and variables requested

* chore: disable subgraph codegen in codegen Makefile command

---------

Co-authored-by: José Ribeiro <me@joseribeiro.dev>
  • Loading branch information
yvesfracari and ribeirojose committed Sep 10, 2024
1 parent 20bdb73 commit 55f17b7
Show file tree
Hide file tree
Showing 26 changed files with 4,552 additions and 6 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.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 python -m cow_py.codegen.main
Expand Down
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,33 @@ Generate the SDK from the CoW Protocol smart contracts, Subgraph, and Orderbook
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
```

## 🐄 Contributing to the Herd

Interested in contributing? Here's how you can help:
Expand Down
72 changes: 72 additions & 0 deletions cow_py/codegen/__generated__/Milkman.py

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

1 change: 0 additions & 1 deletion cow_py/common/api/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import httpx
from aiolimiter import AsyncLimiter


DEFAULT_LIMITER_OPTIONS = {"rate": 5, "per": 1.0}

DEFAULT_BACKOFF_OPTIONS = {
Expand Down
140 changes: 140 additions & 0 deletions cow_py/contracts/abi/Milkman.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
[
{ "inputs": [], "stateMutability": "nonpayable", "type": "constructor" },
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "address",
"name": "orderContract",
"type": "address"
},
{
"indexed": false,
"internalType": "address",
"name": "orderCreator",
"type": "address"
},
{
"indexed": false,
"internalType": "uint256",
"name": "amountIn",
"type": "uint256"
},
{
"indexed": false,
"internalType": "address",
"name": "fromToken",
"type": "address"
},
{
"indexed": false,
"internalType": "address",
"name": "toToken",
"type": "address"
},
{
"indexed": false,
"internalType": "address",
"name": "to",
"type": "address"
},
{
"indexed": false,
"internalType": "address",
"name": "priceChecker",
"type": "address"
},
{
"indexed": false,
"internalType": "bytes",
"name": "priceCheckerData",
"type": "bytes"
}
],
"name": "SwapRequested",
"type": "event"
},
{
"inputs": [],
"name": "DOMAIN_SEPARATOR",
"outputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{ "internalType": "uint256", "name": "amountIn", "type": "uint256" },
{
"internalType": "contract IERC20",
"name": "fromToken",
"type": "address"
},
{
"internalType": "contract IERC20",
"name": "toToken",
"type": "address"
},
{ "internalType": "address", "name": "to", "type": "address" },
{ "internalType": "address", "name": "priceChecker", "type": "address" },
{ "internalType": "bytes", "name": "priceCheckerData", "type": "bytes" }
],
"name": "cancelSwap",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "contract IERC20",
"name": "fromToken",
"type": "address"
},
{ "internalType": "bytes32", "name": "_swapHash", "type": "bytes32" }
],
"name": "initialize",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{ "internalType": "bytes32", "name": "orderDigest", "type": "bytes32" },
{ "internalType": "bytes", "name": "encodedOrder", "type": "bytes" }
],
"name": "isValidSignature",
"outputs": [{ "internalType": "bytes4", "name": "", "type": "bytes4" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{ "internalType": "uint256", "name": "amountIn", "type": "uint256" },
{
"internalType": "contract IERC20",
"name": "fromToken",
"type": "address"
},
{
"internalType": "contract IERC20",
"name": "toToken",
"type": "address"
},
{ "internalType": "address", "name": "to", "type": "address" },
{ "internalType": "address", "name": "priceChecker", "type": "address" },
{ "internalType": "bytes", "name": "priceCheckerData", "type": "bytes" }
],
"name": "requestSwapExactTokensForTokens",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "swapHash",
"outputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }],
"stateMutability": "view",
"type": "function"
}
]
Empty file.
2 changes: 1 addition & 1 deletion cow_py/order_book/generated/model.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# generated by datamodel-codegen:
# filename: https://raw.githubusercontent.com/cowprotocol/services/main/crates/orderbook/openapi.yml
# timestamp: 2024-09-10T00:11:37+00:00
# timestamp: 2024-09-10T14:37:35+00:00

from __future__ import annotations

Expand Down
Empty file added cow_py/subgraph/__init__.py
Empty file.
115 changes: 115 additions & 0 deletions cow_py/subgraph/client/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
# Generated by ariadne-codegen

from .async_base_client import AsyncBaseClient
from .base_model import BaseModel, Upload
from .enums import (
Aggregation_interval,
Bundle_orderBy,
DailyTotal_orderBy,
HourlyTotal_orderBy,
Order_orderBy,
OrderDirection,
Pair_orderBy,
PairDaily_orderBy,
PairHourly_orderBy,
Settlement_orderBy,
Token_orderBy,
TokenDailyTotal_orderBy,
TokenHourlyTotal_orderBy,
TokenTradingEvent_orderBy,
Total_orderBy,
Trade_orderBy,
UniswapPool_orderBy,
UniswapToken_orderBy,
User_orderBy,
_SubgraphErrorPolicy_,
)
from .exceptions import (
GraphQLClientError,
GraphQLClientGraphQLError,
GraphQLClientGraphQLMultiError,
GraphQLClientHttpError,
GraphQLClientInvalidResponseError,
)
from .input_types import (
Block_height,
BlockChangedFilter,
Bundle_filter,
DailyTotal_filter,
HourlyTotal_filter,
Order_filter,
Pair_filter,
PairDaily_filter,
PairHourly_filter,
Settlement_filter,
Token_filter,
TokenDailyTotal_filter,
TokenHourlyTotal_filter,
TokenTradingEvent_filter,
Total_filter,
Trade_filter,
UniswapPool_filter,
UniswapToken_filter,
User_filter,
)
from .last_days_volume import LastDaysVolume, LastDaysVolumeDailyTotals
from .last_hours_volume import LastHoursVolume, LastHoursVolumeHourlyTotals
from .subgraph_client import SubgraphClient
from .totals import Totals, TotalsTotals

__all__ = [
"Aggregation_interval",
"AsyncBaseClient",
"BaseModel",
"BlockChangedFilter",
"Block_height",
"Bundle_filter",
"Bundle_orderBy",
"DailyTotal_filter",
"DailyTotal_orderBy",
"GraphQLClientError",
"GraphQLClientGraphQLError",
"GraphQLClientGraphQLMultiError",
"GraphQLClientHttpError",
"GraphQLClientInvalidResponseError",
"HourlyTotal_filter",
"HourlyTotal_orderBy",
"LastDaysVolume",
"LastDaysVolumeDailyTotals",
"LastHoursVolume",
"LastHoursVolumeHourlyTotals",
"OrderDirection",
"Order_filter",
"Order_orderBy",
"PairDaily_filter",
"PairDaily_orderBy",
"PairHourly_filter",
"PairHourly_orderBy",
"Pair_filter",
"Pair_orderBy",
"Settlement_filter",
"Settlement_orderBy",
"SubgraphClient",
"TokenDailyTotal_filter",
"TokenDailyTotal_orderBy",
"TokenHourlyTotal_filter",
"TokenHourlyTotal_orderBy",
"TokenTradingEvent_filter",
"TokenTradingEvent_orderBy",
"Token_filter",
"Token_orderBy",
"Total_filter",
"Total_orderBy",
"Totals",
"TotalsTotals",
"Trade_filter",
"Trade_orderBy",
"UniswapPool_filter",
"UniswapPool_orderBy",
"UniswapToken_filter",
"UniswapToken_orderBy",
"Upload",
"User_filter",
"User_orderBy",
"_SubgraphErrorPolicy_",
]
Loading

0 comments on commit 55f17b7

Please sign in to comment.