-
Notifications
You must be signed in to change notification settings - Fork 33
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
Add fees and coin selection #159
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yuge PR! thanks.
There are a lot of new functions. Please make sure that functions in the CashuWallet
class that should not be used externally are marked private
Also, please add the minimal docs to the functions that are accessible to the implementoors
I didn't mark all as comments, please go through it (CashuWallet
) again and add where required
Remove payLnInvoice helper
@gandlafbtc you're the best. thank you for doing all that work |
@Egge21M @gandlafbtc @gudnuf all changes applied. Please review again. Thanks a lot again to @gandlafbtc for the fantastic work. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Nice work!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thank you again for this @callebtc !
Introduces support for fees for spending ecash with the mint. Fees are published in the
/v1/keysets
response (see NUT-02). Also introduces a new input coinselection algorithm to minimize fees when spending coins and an output selection, to maintain a diverse set of amounts in the user's wallet, increasing the chance for being able to make offline transactions in the future.Changes
Automatic input selection
There is a rather sophisticated coinselection algorithm now that will select with fees in mind. The library will automatically fetch the keyset of the mint in order to determine the fees during selection. The implementor can decide to use
includeFees = true
in various class methods in order to include fees in the selection so that the selection can be spent. This can be used in situations where the sender pays the fees instead of the receiver (and the receiver can receive a predictable amount). It is necessary to use if we perform coin selection to pay a Lightning invoice afterwards:Output amounts
AmountPreference
is removed, useOutputAmounts
now, which can be used to definesendAmounts
andkeepAmounts
which are now both simple arrays of numbers. Previously we could only define amounts to send throughAmountPreference
.Automatic output amount selection
Users can use
proofsWeHave
to specify in various methods which proofs are present in the wallet. This will make the library to choose output amounts to refill the wallet with missing denominations:The target defaults to
DEFAULT_DENOMINATION_TARGET = 3;
but can be defined in the constructor of theCashuWallet
class.Renaming
SendResponse
,returnChange
is now calledkeep
mintTokens
is now calledmintProofs
meltTokens
is now calledmeltProofs
CashuMint.split
is now calledCashuMint.swap
Legacy code
I suggest we get rid of all functions a la
PayLNInvoice
and force the implementor to understand how to use the library themselves instead of hiding crucial details. This should be done in a separate PR after merging this.PR Tasks
npm run test
--> no failing unit testsnpm run format