-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: minimum_balance for placing orders set to 1 atom for FOK (#2558)
# Description The frontend wants to enable placement of LIMIT orders without requiring the full balance. It can be tested here cowprotocol/cowswap#3742 It is already possible for Partially fillable orders due to the partial fill nature, but Fill or kill orders still require the full balance. The arguments for the feature is: 1. allow users setting up a limit order in advance of receiving funds, for example in a newly created Safe. Once funds are received, order becomes valid and trade-able The argument to remove the Fill or kill limitation is: 1. allow users a seamless experience when placing LIMIT orders across both sub-types, without requiring a different balance constraint Due to spam protection, 1 atom of the sell token balance is still required, and that is not being removed. # Changes - [ ] Remove full balance limitation for both order types (Fill or kill and Partially fillable) - [ ] Turn `minimum_balance` function into a constant of value `1`. ## How to test This change relies on existing unit tests ## Notes Please do let me know where best to put the constant, whether there is need to add any specific unit test and so on --------- Co-authored-by: Martin Beckmann <martin.beckmann@protonmail.com>
- Loading branch information
1 parent
48ad4c9
commit 5950d92
Showing
3 changed files
with
91 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
use { | ||
e2e::{setup::*, tx, tx_value}, | ||
ethcontract::U256, | ||
model::{ | ||
order::{OrderCreation, OrderKind}, | ||
signature::EcdsaSigningScheme, | ||
}, | ||
secp256k1::SecretKey, | ||
shared::ethrpc::Web3, | ||
web3::signing::SecretKeyRef, | ||
}; | ||
|
||
#[tokio::test] | ||
#[ignore] | ||
async fn local_node_uncovered_order() { | ||
run_test(test).await; | ||
} | ||
|
||
/// Tests that a user can already create an order if they only have | ||
/// 1 wei of the sell token and later fund their account to get the | ||
/// order executed. | ||
async fn test(web3: Web3) { | ||
tracing::info!("Setting up chain state."); | ||
let mut onchain = OnchainComponents::deploy(web3).await; | ||
|
||
let [solver] = onchain.make_solvers(to_wei(10)).await; | ||
let [trader] = onchain.make_accounts(to_wei(10)).await; | ||
let [token] = onchain | ||
.deploy_tokens_with_weth_uni_v2_pools(to_wei(1_000), to_wei(1_000)) | ||
.await; | ||
let weth = &onchain.contracts().weth; | ||
|
||
tx!( | ||
trader.account(), | ||
weth.approve(onchain.contracts().allowance, to_wei(3)) | ||
); | ||
|
||
tracing::info!("Starting services."); | ||
let services = Services::new(onchain.contracts()).await; | ||
services.start_protocol(solver).await; | ||
|
||
tracing::info!("Placing order with 0 sell tokens"); | ||
let order = OrderCreation { | ||
sell_token: weth.address(), | ||
sell_amount: to_wei(2), | ||
fee_amount: 0.into(), | ||
buy_token: token.address(), | ||
buy_amount: to_wei(1), | ||
valid_to: model::time::now_in_epoch_seconds() + 300, | ||
kind: OrderKind::Sell, | ||
partially_fillable: false, | ||
..Default::default() | ||
} | ||
.sign( | ||
EcdsaSigningScheme::Eip712, | ||
&onchain.contracts().domain_separator, | ||
SecretKeyRef::from(&SecretKey::from_slice(trader.private_key()).unwrap()), | ||
); | ||
// This order can't be created because we require the trader | ||
// to have at least 1 wei of sell tokens. | ||
services.create_order(&order).await.unwrap_err(); | ||
|
||
tracing::info!("Placing order with 1 wei of sell_tokens"); | ||
tx_value!(trader.account(), 1.into(), weth.deposit()); | ||
// Now that the trader has some funds they are able to create | ||
// an order (even if it exceeds their current balance). | ||
services.create_order(&order).await.unwrap(); | ||
|
||
tracing::info!("Deposit ETH to make order executable"); | ||
tx_value!(trader.account(), to_wei(2), weth.deposit()); | ||
|
||
tracing::info!("Waiting for order to show up in auction"); | ||
wait_for_condition(TIMEOUT, || async { services.solvable_orders().await == 1 }) | ||
.await | ||
.unwrap(); | ||
|
||
// Drive solution | ||
tracing::info!("Waiting for trade."); | ||
wait_for_condition(TIMEOUT, || async { services.solvable_orders().await == 0 }) | ||
.await | ||
.unwrap(); | ||
let balance_after = weth.balance_of(trader.address()).call().await.unwrap(); | ||
assert_eq!(U256::one(), balance_after); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters