Skip to content

Commit 88d583e

Browse files
authored
Merge branch 'main' into simulator-refactor
2 parents f5cb342 + 5db7fbb commit 88d583e

7 files changed

Lines changed: 65 additions & 28 deletions

File tree

crates/database/src/ethflow_orders.rs

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ pub async fn insert_or_overwrite_ethflow_order(
3737
)
3838
.await?;
3939

40+
// Update true_valid_to field if order already in the database
41+
// as the Ethflow orders get inserted with validity of u32::MAX
42+
// and the true validity is contained in the EthOrderPlacement
4043
const UPDATE_TRUE_VALID_TO_QUERY: &str = r#"
4144
UPDATE orders
4245
SET true_valid_to = $1
@@ -51,26 +54,6 @@ pub async fn insert_or_overwrite_ethflow_order(
5154
Ok(())
5255
}
5356

54-
// Ethflow orders are created with valid_to equal to u32::MAX, their
55-
// true validity is parsed from Settlement contract events.
56-
#[instrument(skip_all)]
57-
pub async fn update_true_valid_to_for_ethflow_order(
58-
ex: &mut PgConnection,
59-
event: &EthOrderPlacement,
60-
) -> Result<(), sqlx::Error> {
61-
const QUERY: &str = r#"
62-
UPDATE orders
63-
SET true_valid_to = $1
64-
WHERE uid = $2
65-
"#;
66-
sqlx::query(QUERY)
67-
.bind(event.valid_to)
68-
.bind(event.uid)
69-
.execute(ex)
70-
.await?;
71-
Ok(())
72-
}
73-
7457
#[derive(Clone, Debug, Default, sqlx::FromRow, Eq, PartialEq)]
7558
pub struct EthOrderData {
7659
pub uid: OrderUid,

crates/database/src/orders.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,18 @@ INSERT INTO orders (
148148
class,
149149
true_valid_to
150150
)
151-
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21)
151+
VALUES (
152+
$1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20,
153+
-- Ethflow orders are inserted with valid_to set to u32::MAX. Their true validity is stored in
154+
-- the ethflow_orders table.
155+
-- If there already exists an Ethflow order with the same uid, take smaller of the two valid_to values
156+
CASE
157+
WHEN $21 = 4294967295 THEN -- u32::MAX
158+
COALESCE((SELECT valid_to FROM ethflow_orders WHERE uid = $1), $21)
159+
ELSE
160+
$21
161+
END
162+
)
152163
"#;
153164

154165
#[instrument(skip_all)]

crates/e2e/tests/e2e/ethflow.rs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use {
66
anyhow::bail,
77
autopilot::database::onchain_order_events::ethflow_events::WRAP_ALL_SELECTOR,
88
contracts::alloy::{CoWSwapEthFlow, ERC20Mintable, WETH9},
9-
database::order_events::OrderEventLabel,
9+
database::{byte_array::ByteArray, order_events::OrderEventLabel},
1010
e2e::setup::{
1111
ACCOUNT_ENDPOINT,
1212
API_HOST,
@@ -49,6 +49,7 @@ use {
4949
refunder::RefundStatus,
5050
reqwest::Client,
5151
shared::signature_validator::check_erc1271_result,
52+
std::ops::DerefMut,
5253
};
5354

5455
const DAI_PER_ETH: u64 = 1_000;
@@ -243,6 +244,28 @@ async fn eth_flow_tx(web3: Web3) {
243244
.await
244245
.unwrap();
245246
assert_eq!(allowance, alloy::primitives::U256::ZERO);
247+
248+
// Check that true_valid_to is equal to the ethflow_order's valid to
249+
let uid = ethflow_order
250+
.uid(onchain.contracts(), ethflow_contract)
251+
.await;
252+
let mut db = services.db().acquire().await.unwrap();
253+
let true_valid_to: (i64,) = sqlx::query_as("SELECT true_valid_to FROM orders WHERE uid = $1")
254+
.bind(ByteArray(uid.0))
255+
.fetch_one(db.deref_mut())
256+
.await
257+
.unwrap();
258+
assert_eq!(
259+
true_valid_to.0,
260+
services
261+
.get_order(&uid)
262+
.await
263+
.unwrap()
264+
.metadata
265+
.ethflow_data
266+
.unwrap()
267+
.user_valid_to
268+
);
246269
}
247270

248271
async fn eth_flow_without_quote(web3: Web3) {

playground/Dockerfile.cowswap

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ RUN corepack enable \
1010
ARG REACT_APP_NETWORK_URL_1=https://rpc.mevblocker.io
1111
ARG REACT_APP_NETWORK_URL_5=https://ethereum-goerli.publicnode.com
1212
ARG REACT_APP_NETWORK_URL_100=https://gnosis.publicnode.com
13+
ARG REACT_APP_EXPLORER_URL_DEV=http://localhost:8001
14+
15+
# Block explorer URL (Otterscan for local development)
16+
ARG REACT_APP_BLOCK_EXPLORER_URL=http://localhost:8003
1317

1418
# Orderbook URL args
1519
ARG REACT_APP_ORDER_BOOK_URLS='{"1":"https://api.cow.fi/mainnet","100":"https://api.cow.fi/goerli","5":"https://api.cow.fi/xdai"}'
@@ -37,6 +41,8 @@ ENV REACT_APP_NETWORK_URL_1="$REACT_APP_NETWORK_URL_1"
3741
ENV REACT_APP_NETWORK_URL_5="$REACT_APP_NETWORK_URL_5"
3842
ENV REACT_APP_NETWORK_URL_100="$REACT_APP_NETWORK_URL_100"
3943
ENV REACT_APP_ORDER_BOOK_URLS="$REACT_APP_ORDER_BOOK_URLS"
44+
ENV REACT_APP_EXPLORER_URL_DEV="$REACT_APP_EXPLORER_URL_DEV"
45+
ENV REACT_APP_BLOCK_EXPLORER_URL="$REACT_APP_BLOCK_EXPLORER_URL"
4046

4147
# Update environment variables based on "chain" and "ETH_RPC_URL", then build safely
4248
RUN set -e; \
@@ -56,12 +62,14 @@ RUN set -e; \
5662
;; \
5763
esac; \
5864
fi; \
59-
export REACT_APP_NETWORK_URL_1 REACT_APP_NETWORK_URL_5 REACT_APP_NETWORK_URL_100 REACT_APP_ORDER_BOOK_URLS; \
65+
export REACT_APP_NETWORK_URL_1 REACT_APP_NETWORK_URL_5 REACT_APP_NETWORK_URL_100 REACT_APP_ORDER_BOOK_URLS REACT_APP_EXPLORER_URL_DEV REACT_APP_BLOCK_EXPLORER_URL; \
6066
NODE_OPTIONS="--max-old-space-size=4096" NX_NO_CLOUD=true pnpm run build \
6167
--env REACT_APP_NETWORK_URL_1="$REACT_APP_NETWORK_URL_1" \
6268
--env REACT_APP_NETWORK_URL_5="$REACT_APP_NETWORK_URL_5" \
6369
--env REACT_APP_NETWORK_URL_100="$REACT_APP_NETWORK_URL_100" \
64-
--env REACT_APP_ORDER_BOOK_URLS="$REACT_APP_ORDER_BOOK_URLS"
70+
--env REACT_APP_ORDER_BOOK_URLS="$REACT_APP_ORDER_BOOK_URLS" \
71+
--env REACT_APP_EXPLORER_URL_DEV="$REACT_APP_EXPLORER_URL_DEV" \
72+
--env REACT_APP_BLOCK_EXPLORER_URL="$REACT_APP_BLOCK_EXPLORER_URL"
6573

6674
# Stage 2: Copy the frontend build to the nginx container
6775
FROM docker.io/nginx:1.21-alpine AS frontend

playground/Dockerfile.explorer

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,16 @@ RUN git clone https://github.com/cowprotocol/cowswap . \
1616
&& git submodule update --init --recursive \
1717
&& pnpm install --frozen-lockfile
1818

19-
# Set environment variable for the order book
19+
# Build environment variables
2020
ENV REACT_APP_ORDER_BOOK_URLS='{"1":"http://localhost:8080"}'
21+
ENV REACT_APP_BLOCK_EXPLORER_URL=http://localhost:8003
2122

2223
# Build the frontend
23-
RUN APP_ID=1 pnpm run build:explorer
24+
RUN APP_ID=1 REACT_APP_BLOCK_EXPLORER_URL=$REACT_APP_BLOCK_EXPLORER_URL pnpm run build:explorer
2425

2526
# Stage 2: Copy the frontend build to the nginx container
2627
FROM docker.io/nginx:1.21-alpine AS frontend
2728
COPY --from=node-build /usr/src/app/build/explorer /usr/share/nginx/html
29+
COPY nginx-spa.conf /etc/nginx/conf.d/default.conf
2830
EXPOSE 80
2931
CMD ["nginx", "-g", "daemon off;"]

playground/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ Now with Rabby configured, and the services started, you can browse to http://lo
4242
> The EthFlow is not configured by default, the next section explains how to set it up.
4343
> You can follow along with watching the logs of the `autopilot`, `driver`, and `baseline` solver to see how the Protocol interacts.
4444
> If you make any changes to the files in your repo directory, services will automatically be recompiled and restarted.
45-
> The CoW Explorer is avialable at http://localhost:8001 to see more information about transaction status
45+
> The CoW Explorer is available at http://localhost:8001 to see more information about transaction status
4646
4747
### Resetting the playground
4848

@@ -147,7 +147,7 @@ In this mode, the stack will spin up:
147147
- Driver
148148
- Baseline
149149
- Cow Swap
150-
- Cow Explorer (*not yet implemented*)
150+
- Cow Explorer
151151

152152
### Local
153153

playground/nginx-spa.conf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
server {
2+
listen 80;
3+
server_name localhost;
4+
root /usr/share/nginx/html;
5+
index index.html;
6+
7+
location / {
8+
try_files $uri $uri/ /index.html;
9+
}
10+
}

0 commit comments

Comments
 (0)