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

bug: ETH Flow quote not found #2435

Closed
fleupold opened this issue Feb 26, 2024 · 1 comment
Closed

bug: ETH Flow quote not found #2435

fleupold opened this issue Feb 26, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@fleupold
Copy link
Contributor

Problem

This order was placed according to a valid quote:

2024-02-25T20:22:13.738Z DEBUG request{id="4e226f55378439c6ac9507fdfedda687"}: shared::order_quoting: computed quote quote=Quote { id: None, data: QuoteData { sell_token: 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2, buy_token: 0xaaee1a9723aadb7afa2810263653a34ba2c21c7a, quoted_sell_amount: 100000000000000000, quoted_buy_amount: 1844714818733742689606655748, fee_parameters: FeeParameters { gas_amount: 191658.0, gas_price: 41113761724.0, sell_token_price: 1.0 }, kind: Sell, expiration: 2024-02-25T23:22:10.613226020Z, quote_kind: Eip1271OnchainOrder, solver: 0x9b7e7f21d98f21c0354035798c40e9040e25787f, verified: false }, sell_amount: 92120218655501608, buy_amount: 1699355324587963905038683186, fee_amount: 7879781344498392 }

Yet, when the autopilot indexed the order it didn't find a quote:

2024-02-25T20:22:31.890Z DEBUG service_maintenance:maintenance{block=19306952}: autopilot::database::onchain_order_events: Could not retrieve a quote for order 0x17fff9a7d0dd6fbc477b7b33d998625ce46f20a533f2ee3e53b4a3bfd5e33ec240a50cf069e992aa4536211b23f286ef88752187ffffffff: no_quote

Impact

User didn't get automatically refunded. Required manual claim and led to a bad user experience (where is my money)

To reproduce

Write an e2e that places a native eth order according to a valid quote, but manipulate the AMM before placing the order in a way that it is no longer executable.

Expected behaviour

Automated refund service will refund the order

Additional context

Pointer to where we compute the DB parameters for finding quotes:

pub fn create_db_search_parameters(
params: QuoteSearchParameters,
expiration: DateTime<Utc>,
) -> DbQuoteSearchParameters {
DbQuoteSearchParameters {
sell_token: ByteArray(params.sell_token.0),
buy_token: ByteArray(params.buy_token.0),
sell_amount_0: u256_to_big_decimal(&params.sell_amount),
sell_amount_1: u256_to_big_decimal(&(params.sell_amount + params.fee_amount)),
buy_amount: u256_to_big_decimal(&params.buy_amount),
kind: order_kind_into(params.kind),
expiration,
quote_kind: quote_kind_from_signing_scheme(&params.signing_scheme),
}
}

and the query for finding quotes:

SELECT *
FROM quotes
WHERE
sell_token = $1 AND
buy_token = $2 AND
(
(order_kind = 'sell' AND sell_amount = $3) OR
(order_kind = 'sell' AND sell_amount = $4) OR
(order_kind = 'buy' AND buy_amount = $5)
) AND
order_kind = $6 AND
expiration_timestamp >= $7 AND
quote_kind = $8
ORDER BY gas_amount * gas_price * sell_token_price ASC
LIMIT 1

Note, that amounts are stored after fee and thus the sellAmount in the quotes table should have been 100000000000000000

@fleupold fleupold added the bug Something isn't working label Feb 26, 2024
@fleupold
Copy link
Contributor Author

Upon further investigation, it turns out that their order referenced a very old quote id (422843629 which is the first 8 bytes of the data field in the order creation event, cf. tenderly), which was no longer valid or available in the db.

The order uid that actually confirmed to their quote is 424048610.

If a quote id is specified but cannot be found we reject this order as QuoteNotFound. So this is expected behaviour...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant