Skip to content
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

wallet: feature: transfer amount with fee included #8861

Merged

Conversation

jeffro256
Copy link
Contributor

@jeffro256 jeffro256 commented May 16, 2023

To transfer ~5 XMR to an address such that your balance drops by exactly 5 XMR, provide a subtractfeefrom flag to the transfer command. For example:

transfer 76bDHojqFYiFCCYYtzTveJ8oFtmpNp3X1TgV2oKP7rHmZyFK1RvyE4r8vsJzf7SyNohMnbKT9wbcD3XUTgsZLX8LU5JBCfm 5 subtractfeefrom=all

If my walet balance was exactly 30 XMR before this transaction, it will be exactly 25 XMR afterwards and the destination address will receive slightly less than 5 XMR. You can manually select which destinations fund the transaction fee and which ones do not by providing the destination index. For example:

transfer 75sr8AAr... 3 74M7W4eg... 4 7AbWqDZ6... 5 subtractfeefrom=0,2

This will drop your balance by exactly 12 XMR including fees and will spread the fee cost equally over destinations with addresses 75sr8AAr... and 7AbWqDZ6....

This feature was requested by @LocalMonero.

@LocalMonero
Copy link
Contributor

This closes #7980

@jeffro256
Copy link
Contributor Author

Depends on #8888

@woodser
Copy link
Contributor

woodser commented Jun 20, 2023

This is a needed feature for application developers which I will be using too.

Is anything else needed before merging? @luigi1111

@jeffro256
Copy link
Contributor Author

@woodser if you would like to see this happen, would you mind reviewing #8888 as well if you’d like?

@selsta
Copy link
Collaborator

selsta commented Jun 20, 2023

@woodser it needs an approval for this and #8888

@woodser
Copy link
Contributor

woodser commented Jul 8, 2023

@jeffro256 Please rebase on master.

src/simplewallet/simplewallet.cpp Outdated Show resolved Hide resolved
src/wallet/wallet2.cpp Outdated Show resolved Hide resolved
src/wallet/wallet_rpc_server_commands_defs.h Show resolved Hide resolved
@@ -1086,7 +1092,7 @@ namespace tools
{
uint64_t mixin = m_wallet->adjust_mixin(req.ring_size ? req.ring_size - 1 : 0);
uint32_t priority = m_wallet->adjust_priority(req.priority);
std::vector<wallet2::pending_tx> ptx_vector = m_wallet->create_transactions_2(dsts, mixin, req.unlock_time, priority, extra, req.account_index, req.subaddr_indices);
std::vector<wallet2::pending_tx> ptx_vector = m_wallet->create_transactions_2(dsts, mixin, req.unlock_time, priority, extra, req.account_index, req.subaddr_indices, req.subtract_fee_from_outputs);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs added to on_transfer_split.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For me, it doesn't make as much sense to add this to the split transfer interface since the fees have to be paid out of certain destinations. If those certain destinations are split over multiple transactions, it's unclear which destinations should pay for transactions if a transaction doesn't contain any "subtractable" destinations. Also, this feature can be expanded upon in a future PR for reviewer's sake, and I'd imagine this feature is mainly useful for small transfers (like customers paying for an item with fee included).

Copy link
Contributor

@woodser woodser Jul 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

simplewallet.cpp already permits applying this feature across split transactions, so either that behavior needs to be well defined and supported or completely disabled.

Then monero-wallet-rpc should be consistent. So if we don't support transfer_split in monero-wallet-rpc now, this feature should be disabled for split transactions in simplewallet too.

As far as I can tell, the expected behavior with split transactions should be clear, where the fee is split across any specified destinations in each transaction, and the entire call fails if any transaction cannot be created with subtractable destinations. So my preference is to support this.

@jeffro256 jeffro256 force-pushed the subtract_fee_from_outputs branch 3 times, most recently from f1fbde1 to 6a28ed4 Compare July 9, 2023 23:58
@jeffro256
Copy link
Contributor Author

@jeffro256 Please rebase on master.

There was an issue but rebasing was fixed

@woodser
Copy link
Contributor

woodser commented Jul 10, 2023

@jeffro256 Do you mind to PR this on the release branch in addition to the master branch, so I can cherry-pick only what is necessary for my next release?

Otherwise I would have to base on master which has diverged from the release branch, so it's unofficial and could be risky.

@jeffro256
Copy link
Contributor Author

In the latest commit, I explicitly disabled using this feature split over multiple transactions to avoid user confusion.

src/simplewallet/simplewallet.cpp Outdated Show resolved Hide resolved
src/simplewallet/simplewallet.cpp Outdated Show resolved Hide resolved
src/simplewallet/simplewallet.cpp Outdated Show resolved Hide resolved
src/simplewallet/simplewallet.cpp Outdated Show resolved Hide resolved
src/wallet/wallet_rpc_server_commands_defs.h Show resolved Hide resolved
src/wallet/wallet2.cpp Show resolved Hide resolved
src/wallet/wallet2.cpp Outdated Show resolved Hide resolved
src/wallet/wallet2.cpp Outdated Show resolved Hide resolved
src/wallet/wallet2.cpp Outdated Show resolved Hide resolved
src/wallet/wallet2.cpp Outdated Show resolved Hide resolved
@woodser
Copy link
Contributor

woodser commented Nov 7, 2023

@jeffro256 mind updating the release PR too?

@woodser
Copy link
Contributor

woodser commented Jan 29, 2024

This pull request provides critical functionality to deduct and split the mining fee among transfer amounts. Haveno relies heavily on this feature in its trade protocol. Happy to help move this forward however possible.

@jeffro256
Copy link
Contributor Author

Rebased. Will acknowledge @vtnerd's comments soon...

Copy link
Contributor

@vtnerd vtnerd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One minor question.

src/simplewallet/simplewallet.cpp Show resolved Hide resolved
src/wallet/wallet2.cpp Outdated Show resolved Hide resolved
@woodser
Copy link
Contributor

woodser commented Feb 8, 2024

Thanks for your updates @jeffro256.

I can test it in the libraries and applications once the release PR is rebased.

@jeffro256 jeffro256 force-pushed the subtract_fee_from_outputs branch 2 times, most recently from ec65958 to 800c188 Compare February 8, 2024 19:05
@woodser
Copy link
Contributor

woodser commented Feb 9, 2024

I tested the latest release branch with #8945 and it's passing my tests.

Should that PR be taken out of draft mode @jeffro256?

@jeffro256
Copy link
Contributor Author

I'll keep it in draft mode as long as this PR is awaiting approval

@woodser
Copy link
Contributor

woodser commented Feb 12, 2024

Understood. @vtnerd approved these changes last week, so I guess we are just waiting on any other approvals.

Copy link
Collaborator

@selsta selsta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please bump WALLET_RPC_VERSION_MINOR

@jeffro256
Copy link
Contributor Author

Done

@jeffro256
Copy link
Contributor Author

Oh shoot you're right. I always get those mixed up

To transfer ~5 XMR to an address such that your balance drops by exactly 5 XMR, provide a `subtractfeefrom` flag to the `transfer` command. For example:

    transfer 76bDHojqFYiFCCYYtzTveJ8oFtmpNp3X1TgV2oKP7rHmZyFK1RvyE4r8vsJzf7SyNohMnbKT9wbcD3XUTgsZLX8LU5JBCfm 5 subtractfeefrom=all

If my walet balance was exactly 30 XMR before this transaction, it will be exactly 25 XMR afterwards and the destination address will receive slightly
less than 5 XMR. You can manually select which destinations fund the transaction fee and which ones do not by providing the destination index.
For example:

    transfer 75sr8AAr... 3 74M7W4eg... 4 7AbWqDZ6... 5 subtractfeefrom=0,2

This will drop your balance by exactly 12 XMR including fees and will spread the fee cost proportionally (3:5 ratio) over destinations with addresses
`75sr8AAr...` and `7AbWqDZ6...`, respectively.

Disclaimer: This feature was paid for by @LocalMonero.
@luigi1111 luigi1111 merged commit ee104bc into monero-project:master Feb 24, 2024
18 checks passed
@jeffro256 jeffro256 deleted the subtract_fee_from_outputs branch February 24, 2024 20:23
j-berman added a commit to j-berman/monero that referenced this pull request Mar 22, 2024
Looks like the logic from monero-project#8882 was accidentally removed in monero-project#8861
(regressing to the behavior noted in the monero-project#8882 description).
This commit brings that logic back.
j-berman added a commit to j-berman/monero that referenced this pull request Mar 22, 2024
Looks like the logic from monero-project#8882 was accidentally removed in monero-project#8861
(regressing to the behavior noted in the monero-project#8882 description).
This commit brings that logic back.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants