cashubtc / nuts

Cashu protocol specifications https://cashubtc.github.io/nuts/
MIT License
152 stars 52 forks source link

Add fees to NUT-02 #126

Closed callebtc closed 4 months ago

callebtc commented 5 months ago

Proposing to add fees to the mandatory part of the spec as I expect most public mints will require fees at some point. If the fees are not set, we should assume it as being 0.

Moved around some existing text. The new part is:

Fees (parts per thousand)

Keysets indicate the fee input_fee_ppk that is charged when a Proof of that keyset is spent as an input to a transaction. The fee is given in parts per thousand (ppk) per input measured in the unit of the keyset and the sum is rounded up to the next larger integer.

As an example, we construct a transaction spending 3 inputs (Proofs) from a keyset with unit sat and input_fee_ppk of 100. A fee of 100 ppk means 0.1 sat per input. The sum of the fees would be 300 ppk for this transaction and the mint would charge 1 sat in fees (ceil(0.3) == 1). The fees for spending 1-10 inputs is 1 sat, 11-20 inputs is 2 sat and so on.

...

Wallet input and output construction

When constructing a transaction with ecash inputs (example: /v1/swap or /v1/melt), wallets MUST add fees to the inputs (or subtract from the outputs) if they spent ecash from a keyset with fees. The mint checks the following equation:

sum(inputs) - sum(fees) == sum(outputs)

The fees are calculated for each input individually (by summing the fee from the keyset they are from) and then rounded up to the next integer.

Tracking progress

Mints:

Wallets

Semisol commented 5 months ago

unintended side effect: this has a negative effect on privacy measures and offline spending

lescuer97 commented 3 months ago

merged in nutmix. https://github.com/lescuer97/nutmix/pull/74