feat: single funded contracts - #256
Conversation
Tibo-lg
left a comment
There was a problem hiding this comment.
It's a nice feature to have! I feel the implementation and usage could be made a bit clearer, and also please add an integration test to make sure it's working as expected.
| } | ||
|
|
||
| // If own_collateral is zero, appr_required_amount is zero. | ||
| // If own_collateral is equal to total_collateral, appr_required_amount is the common fee. |
There was a problem hiding this comment.
It feels like it would be easier to just pass a bool like pay_all_fee to this method
There was a problem hiding this comment.
I'm not sure, to flag pay_all_fee then we still need to do the same check if they are paying all or zero collateral
|
|
||
| // first check if a party does not need to fund the contract if so, then it is zero | ||
| if self.collateral == Amount::ZERO { | ||
| // We use a zero value output to indicate that the party does not need to fund the contract |
There was a problem hiding this comment.
It would be clearer to return an option so that it can be None in that case.
There was a problem hiding this comment.
I disagree, making it an Option requires extra checks in the callers that I think is cleaner to set to just Amount::ZERO
|
|
||
| let (offer_change_output, offer_fund_fee, offer_cet_fee) = | ||
| offer_params.get_change_output_and_fees(fee_rate_per_vb, extra_fee)?; | ||
| offer_params.get_change_output_and_fees(total_collateral, fee_rate_per_vb, extra_fee)?; |
There was a problem hiding this comment.
Or maybe just don't call this method when it's not needed?
There was a problem hiding this comment.
You still need to include the accept_change to create_fund_transaction even if it is dust which is then discarded
e389637 to
d215bc7
Compare
Going through this PR again, I wonder if it would make more sense to just have a setting that enables setting a single party to pay the entire fee regardless of the collateral values. It would also make things more explicit. |
This PR implements single-funded DLCs where only one party provides collateral and covers all transaction fees, while the other party contributes no inputs or fees.
Problem
The current implementation requires both parties to split transaction fees (funding, CET, and refund), even when one party provides zero collateral. This prevents true single-funded DLCs where the acceptor contributes nothing.
Solution
Fee calculation is now dynamic based on collateral contribution:
Additional Changes
Contract Input Validation: Added dust limit checks per DLC specifications - offer collateral and total collateral must be above dust limit when non-zero. Follow spec for offer collateral
Code Quality: Fixed clippy warnings throughout the codebase.
Backward Compatibility
Existing dual-funded DLCs work unchanged. API changes are additive with no breaking changes to existing functionality.