Skip to content

Commit

Permalink
Fix Legacy Solver (#1998)
Browse files Browse the repository at this point in the history
# Description
Solvers already submit self computed fee amounts even for orders that
still work with a protocol specified fee (e.g. market orders). See this
barter response for instance: http://jsonblob.com/1164883806913421312

The code currently rejects those solutions with "invalid trade
execution" errors. This PR makes the legacy adapter compliant with the
current system where we ignore the fee_amount for orders that don't
require them (rather than erroring if it specified)

# Changes

- Instead of erroring when a surplus fee is specified although the
solver doesn't determine the fee we now always use the protocol fee
instead
- adjust unit test to demonstrate the response is now accepted

## How to test
Unit test

Fixes #1996
  • Loading branch information
fleupold authored Oct 20, 2023
1 parent addef7a commit 11f62fd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
9 changes: 6 additions & 3 deletions crates/solvers/src/boundary/legacy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -405,9 +405,12 @@ fn to_domain_solution(
order::Side::Buy => execution.exec_buy_amount,
order::Side::Sell => execution.exec_sell_amount,
},
match execution.exec_fee_amount {
Some(fee) => solution::Fee::Surplus(fee),
None => solution::Fee::Protocol,
match order.solver_determines_fee() {
true => execution
.exec_fee_amount
.map(solution::Fee::Surplus)
.context("no surplus fee")?,
false => solution::Fee::Protocol,
},
)
.context("invalid trade execution")?,
Expand Down
2 changes: 2 additions & 0 deletions crates/solvers/src/tests/legacy/market_order.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ async fn quote() {
"0": {
"exec_sell_amount": "133700000000000000",
"exec_buy_amount": "6000000000000000000000",
"exec_fee_amount": "6900000000000000"
}
},
"prices": {
Expand Down Expand Up @@ -295,6 +296,7 @@ async fn solve() {
"0": {
"exec_sell_amount": "133700000000000000",
"exec_buy_amount": "6000000000000000000000",
"exec_fee_amount": "6900000000000000",
}
},
"prices": {
Expand Down

0 comments on commit 11f62fd

Please sign in to comment.