Skip to content

Commit

Permalink
Address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
m30m committed Feb 7, 2024
1 parent 214fcb4 commit 33f0ed1
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 29 deletions.
11 changes: 7 additions & 4 deletions auction-server/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ impl IntoResponse for RestError {
),
RestError::OpportunityNotFound => (
StatusCode::NOT_FOUND,
"Order with the specified id was not found".to_string(),
"Opportunity with the specified id was not found".to_string(),
),
RestError::TemporarilyUnavailable => (
StatusCode::SERVICE_UNAVAILABLE,
Expand Down Expand Up @@ -241,16 +241,19 @@ pub async fn start_server(run_options: RunOptions) -> Result<()> {
let app: Router<()> = Router::new()
.merge(SwaggerUi::new("/docs").url("/docs/openapi.json", ApiDoc::openapi()))
.route("/", get(root))
.route("/v1/bid", post(bid::bid))
.route("/v1/bids", post(bid::bid))
.route(
"/v1/liquidation/opportunity",
"/v1/liquidation/opportunities",
post(liquidation::post_opportunity),
)
.route(
"/v1/liquidation/opportunities",
get(liquidation::get_opportunities),
)
.route("/v1/liquidation/bid", post(liquidation::post_bid))
.route(
"/v1/liquidation/opportunities/:opportunity_id/bids",
post(liquidation::post_bid),
)
.layer(CorsLayer::permissive())
.with_state(server_store);

Expand Down
2 changes: 1 addition & 1 deletion auction-server/src/api/bid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ pub struct BidResult {
///
/// Your bid will be simulated and verified by the server. Depending on the outcome of the auction, a transaction
/// containing the contract call will be sent to the blockchain expecting the bid amount to be paid after the call.
#[utoipa::path(post, path = "/v1/bid", request_body = Bid, responses(
#[utoipa::path(post, path = "/v1/bids", request_body = Bid, responses(
(status = 200, description = "Bid was placed succesfully", body = BidResult, example = json!({"status": "OK"})),
(status = 400, response = ErrorBodyResponse),
(status = 404, description = "Chain id was not found", body = ErrorBodyResponse),
Expand Down
12 changes: 6 additions & 6 deletions auction-server/src/api/liquidation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use {
},
axum::{
extract::{
Path,
Query,
State,
},
Expand Down Expand Up @@ -72,7 +73,7 @@ pub struct OpportunityParamsWithId {
///
/// The opportunity will be verified by the server. If the opportunity is valid, it will be stored in the database
/// and will be available for bidding.
#[utoipa::path(post, path = "/v1/liquidation/opportunity", request_body = OpportunityParams, responses(
#[utoipa::path(post, path = "/v1/liquidation/opportunities", request_body = OpportunityParams, responses(
(status = 200, description = "The created opportunity", body = OpportunityParamsWithId),
(status = 400, response = ErrorBodyResponse),
(status = 404, description = "Chain id was not found", body = ErrorBodyResponse),
Expand Down Expand Up @@ -164,9 +165,6 @@ pub async fn get_opportunities(

#[derive(Serialize, Deserialize, ToSchema, Clone)]
pub struct OpportunityBid {
/// The opportunity id to bid on.
#[schema(example = "f47ac10b-58cc-4372-a567-0e02b2c3d479",value_type=String)]
pub opportunity_id: Uuid,
/// The opportunity permission key
#[schema(example = "0xdeadbeefcafe", value_type=String)]
pub permission_key: Bytes,
Expand All @@ -190,13 +188,15 @@ pub struct OpportunityBid {
}

/// Bid on liquidation opportunity
#[utoipa::path(post, path = "/v1/liquidation/bid", request_body=OpportunityBid, responses(
#[utoipa::path(post, path = "/v1/liquidation/opportunities/{opportunity_id}/bids", request_body=OpportunityBid,
params(("opportunity_id", description = "Opportunity id to bid on")), responses(
(status = 200, description = "Bid Result", body = BidResult, example = json!({"status": "OK"})),
(status = 400, response = ErrorBodyResponse),
(status = 404, description = "Opportunity or chain id was not found", body = ErrorBodyResponse),
),)]
pub async fn post_bid(
State(store): State<Arc<Store>>,
Path(opportunity_id): Path<Uuid>,
Json(opportunity_bid): Json<OpportunityBid>,
) -> Result<Json<BidResult>, RestError> {
let opportunity = store
Expand All @@ -209,7 +209,7 @@ pub async fn post_bid(
.clone();


if opportunity.id != opportunity_bid.opportunity_id {
if opportunity.id != opportunity_id {
return Err(RestError::BadParameters(
"Invalid opportunity_id".to_string(),
));
Expand Down
1 change: 0 additions & 1 deletion auction-server/src/liquidation_adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ pub async fn verify_opportunity(
let client = Arc::new(chain_store.provider.clone());
let fake_wallet = LocalWallet::new(&mut rand::thread_rng());
let mut fake_bid = OpportunityBid {
opportunity_id: Default::default(),
liquidator: fake_wallet.address(),
valid_until: U256::max_value(),
permission_key: opportunity.permission_key.clone(),
Expand Down
2 changes: 1 addition & 1 deletion per_sdk/protocols/token_vault_monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ async def main():
try:
resp = await client.post(
urllib.parse.urljoin(
args.liquidation_server_url, "/v1/liquidation/opportunity"
args.liquidation_server_url, "/v1/liquidation/opportunities"
),
json=opp,
)
Expand Down
29 changes: 20 additions & 9 deletions per_sdk/searcher/simple_searcher.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
import argparse
import asyncio
import logging
import urllib.parse
from typing import TypedDict

import httpx
from eth_account import Account

from per_sdk.searcher.searcher_utils import BidInfo, construct_signature_liquidator
from per_sdk.utils.endpoints import (
LIQUIDATION_SERVER_ENDPOINT_BID,
LIQUIDATION_SERVER_ENDPOINT_GETOPPS,
)
from per_sdk.utils.types_liquidation_adapter import LiquidationOpportunity

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -116,6 +113,12 @@ async def main():
default=10,
help="Default amount of bid for liquidation opportunities",
)
parser.add_argument(
"--liquidation-server-url",
type=str,
required=True,
help="Liquidation server endpoint to use for fetching opportunities and submitting bids",
)
args = parser.parse_args()

logger.setLevel(logging.INFO if args.verbose == 0 else logging.DEBUG)
Expand All @@ -135,7 +138,9 @@ async def main():
try:
accounts_liquidatable = (
await client.get(
LIQUIDATION_SERVER_ENDPOINT_GETOPPS,
urllib.parse.urljoin(
args.liquidation_server_url, "/v1/liquidation/opportunities"
),
params={"chain_id": args.chain_id},
)
).json()
Expand All @@ -146,26 +151,32 @@ async def main():

logger.debug("Found %d liquidation opportunities", len(accounts_liquidatable))
for liquidation_opp in accounts_liquidatable:
opp_id = liquidation_opp["opportunity_id"]
if liquidation_opp["version"] != "v1":
logger.warning(
"Opportunity %s has unsupported version %s",
liquidation_opp["opportunity_id"],
opp_id,
liquidation_opp["version"],
)
continue
bid_info = assess_liquidation_opportunity(args.bid, liquidation_opp)

if bid_info is not None:

tx = create_liquidation_transaction(
liquidation_opp, sk_liquidator, bid_info
)

resp = await client.post(LIQUIDATION_SERVER_ENDPOINT_BID, json=tx)
resp = await client.post(
urllib.parse.urljoin(
args.liquidation_server_url,
f"/v1/liquidation/opportunities/{opp_id}/bids",
),
json=tx,
)
logger.info(
"Submitted bid amount %s for opportunity %s, server response: %s",
bid_info["bid"],
liquidation_opp["opportunity_id"],
opp_id,
resp.text,
)

Expand Down
7 changes: 0 additions & 7 deletions per_sdk/utils/endpoints.py

This file was deleted.

0 comments on commit 33f0ed1

Please sign in to comment.