Skip to content

Commit e36bfa7

Browse files
Merge pull request #112 from FigureTechnologies/brashidnia/fix-bid-zero-fee-cancel
Fix bug that bid.fee.amount = 0 cannot be cancelled
2 parents 52685c4 + 936810d commit e36bfa7

File tree

4 files changed

+117
-15
lines changed

4 files changed

+117
-15
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "ats-smart-contract"
3-
version = "0.18.1"
3+
version = "0.18.2"
44
authors = ["Ken Talley <ktalley@figure.com>"]
55
edition = "2018"
66

src/contract.rs

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -980,19 +980,21 @@ fn reverse_bid(
980980

981981
// add 'send fee back to owner' message
982982
if let Some(fee) = effective_cancel_fee_size {
983-
response = response.add_message(match is_quote_restricted_marker {
984-
true => transfer_marker_coins(
985-
fee.amount.u128(),
986-
bid_order.quote.denom.to_owned(),
987-
bid_order.owner.to_owned(),
988-
env.contract.address,
989-
)?,
990-
false => BankMsg::Send {
991-
to_address: bid_order.owner.to_string(),
992-
amount: vec![coin(fee.amount.u128(), bid_order.quote.denom.to_owned())],
993-
}
994-
.into(),
995-
});
983+
if fee.amount.gt(&Uint128::zero()) {
984+
response = response.add_message(match is_quote_restricted_marker {
985+
true => transfer_marker_coins(
986+
fee.amount.u128(),
987+
bid_order.quote.denom.to_owned(),
988+
bid_order.owner.to_owned(),
989+
env.contract.address,
990+
)?,
991+
false => BankMsg::Send {
992+
to_address: bid_order.owner.to_string(),
993+
amount: vec![coin(fee.amount.u128(), bid_order.quote.denom.to_owned())],
994+
}
995+
.into(),
996+
});
997+
}
996998
}
997999

9981000
let mut bid_storage = get_bid_storage(deps.storage);

src/tests/execute/cancel_bid_tests.rs

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,106 @@ mod cancel_bid_tests {
399399
.is_err());
400400
}
401401

402+
#[test]
403+
fn cancel_bid_with_fees_eq_zero_valid() {
404+
let mut deps = mock_dependencies(&[]);
405+
setup_test_base(
406+
&mut deps.storage,
407+
&ContractInfoV3 {
408+
name: "contract_name".into(),
409+
bind_name: "contract_bind_name".into(),
410+
base_denom: "base_denom".into(),
411+
convertible_base_denoms: vec!["con_base_1".into(), "con_base_2".into()],
412+
supported_quote_denoms: vec!["quote_1".into(), "quote_2".into()],
413+
approvers: vec![Addr::unchecked("exec_1"), Addr::unchecked("exec_2")],
414+
executors: vec![Addr::unchecked("exec_1"), Addr::unchecked("exec_2")],
415+
ask_fee_info: None,
416+
bid_fee_info: Some(FeeInfo {
417+
account: Addr::unchecked("bid_fee_account"),
418+
rate: "0.1".to_string(),
419+
}),
420+
ask_required_attributes: vec!["ask_tag_1".into(), "ask_tag_2".into()],
421+
bid_required_attributes: vec!["bid_tag_1".into(), "bid_tag_2".into()],
422+
price_precision: Uint128::new(0),
423+
size_increment: Uint128::new(1),
424+
},
425+
);
426+
427+
// create bid data
428+
store_test_bid(
429+
&mut deps.storage,
430+
&BidOrderV2 {
431+
base: Coin {
432+
amount: Uint128::new(100),
433+
denom: "base_1".into(),
434+
},
435+
events: vec![],
436+
fee: Some(Coin {
437+
denom: "quote_1".to_string(),
438+
amount: Uint128::new(0),
439+
}),
440+
id: "c13f8888-ca43-4a64-ab1b-1ca8d60aa49b".into(),
441+
owner: Addr::unchecked("bidder"),
442+
price: "2".into(),
443+
quote: Coin {
444+
amount: Uint128::new(200),
445+
denom: "quote_1".into(),
446+
},
447+
},
448+
);
449+
450+
// cancel bid order
451+
let bidder_info = mock_info("bidder", &[]);
452+
453+
let cancel_bid_msg = ExecuteMsg::CancelBid {
454+
id: "c13f8888-ca43-4a64-ab1b-1ca8d60aa49b".to_string(),
455+
};
456+
457+
let cancel_bid_response = execute(
458+
deps.as_mut(),
459+
mock_env(),
460+
bidder_info.clone(),
461+
cancel_bid_msg,
462+
);
463+
464+
match cancel_bid_response {
465+
Ok(cancel_bid_response) => {
466+
assert_eq!(cancel_bid_response.attributes.len(), 4);
467+
assert_eq!(
468+
cancel_bid_response.attributes[0],
469+
attr("action", "cancel_bid")
470+
);
471+
assert_eq!(
472+
cancel_bid_response.attributes[1],
473+
attr("id", "c13f8888-ca43-4a64-ab1b-1ca8d60aa49b")
474+
);
475+
assert_eq!(
476+
cancel_bid_response.attributes[2],
477+
attr("reverse_size", "100")
478+
);
479+
assert_eq!(
480+
cancel_bid_response.attributes[3],
481+
attr("order_open", "false")
482+
);
483+
assert_eq!(cancel_bid_response.messages.len(), 1);
484+
assert_eq!(
485+
cancel_bid_response.messages[0].msg,
486+
CosmosMsg::Bank(BankMsg::Send {
487+
to_address: bidder_info.sender.to_string(),
488+
amount: coins(200, "quote_1"),
489+
})
490+
);
491+
}
492+
Err(error) => panic!("unexpected error: {:?}", error),
493+
}
494+
495+
// verify bid order removed from storage
496+
let bid_storage = get_bid_storage_read(&deps.storage);
497+
assert!(bid_storage
498+
.load("c13f8888-ca43-4a64-ab1b-1ca8d60aa49b".as_bytes())
499+
.is_err());
500+
}
501+
402502
#[test]
403503
fn cancel_bid_restricted_marker_with_fees() {
404504
let mut deps = mock_dependencies(&[]);

0 commit comments

Comments
 (0)