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

Fix parsing of input and return empty solution #25

Merged
merged 3 commits into from
Sep 11, 2023
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
72 changes: 11 additions & 61 deletions src/_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,68 +69,18 @@ async def solve(problem: BatchAuctionModel, request: Request): # type: ignore
# 1. Solve BatchAuction: update batch_auction with
# batch.solve()

sample_output = {
"ref_token": batch.ref_token.value,
"orders": {order.order_id: order.as_dict() for order in batch.orders},
"prices": {
"0x4e3fbd56cd56c3e72c1403e103b45db9da5b9d2b": 10658174560450550,
"0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2": 1000000000000000000,
"0xdac17f958d2ee523a2206206994597c13d831ec7": 314968423380884,
},
"amms": {
"6": {
"kind": "ConstantProduct",
"reserves": {
"0x4e3fbd56cd56c3e72c1403e103b45db9da5b9d2b": "151047198637918194794625",
"0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2": "1615731604381456130940",
},
"fee": "0.003",
"cost": {
"amount": "1668264347574664",
"token": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
},
"mandatory": False,
"id": "6",
"execution": [
{
"buy_token": "0x4e3fbd56cd56c3e72c1403e103b45db9da5b9d2b",
"exec_buy_amount": 4416092913242591886,
"sell_token": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
"exec_sell_amount": 47095265163205056,
"exec_sell_amount_nfee": 47236971948467672,
"liquidity_fee": 1.3248278739727776e16,
"exec_plan": {"position": 0, "sequence": 0},
}
],
},
"3": {
"kind": "ConstantProduct",
"reserves": {
"0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2": "10052659476364989570713",
"0xdac17f958d2ee523a2206206994597c13d831ec7": "31939939882438",
},
"fee": "0.003",
"cost": {
"amount": "1668264347574664",
"token": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
},
"mandatory": False,
"id": "3",
"execution": [
{
"buy_token": "0xdac17f958d2ee523a2206206994597c13d831ec7",
"exec_buy_amount": 55272822,
"sell_token": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
"exec_sell_amount": 17344146155103392,
"exec_sell_amount_nfee": 17396335070270996,
"liquidity_fee": 165818.46600000001,
"exec_plan": {"position": 1, "sequence": 0},
}
],
},
},
trivial_solution = {
"orders": {},
"foreign_liquidity_orders": [],
"amms": {},
"prices": {},
"approvals": [],
"interaction_data": [],
"score": "0",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fine for the workshop. Later on it might be useful to have an example solution which follows the correct format

}
return sample_output

print("\n\n*************\n\nReturning solution: " + str(trivial_solution))
return trivial_solution


# ++++ Server setup: ++++
Expand Down
1 change: 1 addition & 0 deletions src/util/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class AMMKind(Enum):
CONSTANT_PRODUCT = "ConstantProduct"
WEIGHTED_PRODUCT = "WeightedProduct"
STABLE = "Stable"
CONCENTRATED = "Concentrated"

def __str__(self) -> str:
"""Represent as string."""
Expand Down
16 changes: 7 additions & 9 deletions src/util/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ class AmmKindEnum(str, Enum):
CONSTANT_PRODUCT = "ConstantProduct"
WEIGHTED_PRODUCT = "WeightedProduct"
STABLE = "Stable"
CONCENTRATED = "Concentrated"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it already parsed into something? If not, this should be added at some point, see #19

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Univ3 is not supported here, and I think it's a bit out of scope, at least for now.



class ConstantProductReservesModel(BigInt):
Expand All @@ -295,10 +296,12 @@ class AmmModel(BaseModel):
"""AMM data."""

kind: AmmKindEnum = Field(..., description="AMM type.")
reserves: Dict[
TokenId, Union[ConstantProductReservesModel, WeightedProductReservesModel]
] = Field(..., description="AMM tokens and balances.")
fee: Decimal = Field(..., description="AMM trading fee (e.g. 0.003 for 0.3% fee).")
reserves: Optional[
Dict[TokenId, Union[ConstantProductReservesModel, WeightedProductReservesModel]]
] = Field(None, description="AMM tokens and balances.")
fee: Optional[Decimal] = Field(
None, description="AMM trading fee (e.g. 0.003 for 0.3% fee)."
)
cost: Optional[TokenAmountModel] = Field(
None, description="Cost of using the pool."
)
Expand Down Expand Up @@ -383,11 +386,6 @@ class InteractionData(BaseModel):
class SettledBatchAuctionModel(BaseModel):
"""Settled batch auction data (solution)."""

ref_token: TokenId = Field(
...,
description="Token used for price vector normalization in case price "
"vector is normalized.",
)
orders: Dict[OrderId, ExecutedOrderModel] = Field(
..., description="Executed orders."
)
Expand Down