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

StaticAddr: Withdraw arbitrary amounts #860

Open
wants to merge 72 commits into
base: master
Choose a base branch
from

Conversation

hieblmi
Copy link
Collaborator

@hieblmi hieblmi commented Dec 2, 2024

This PR adds an amount field to the withdrawal rpc.

It allows to withdraw a fraction of the sum of selected deposits to withdraw. The change is sent back to the static address.
If the change is below the dust limit it goes towards miner fees, but warns the user beforehand.

loop static withdraw --utxo XXX ---utxo YYY --dest_addr ZZZ --amount 1500000

We remove the static address client and add its
rpcs into the SwapClient
Deposit schema extension with a withdrawal
sweep address. If the user selects a deposit
for withdrawal the destination address of the
sweep is stored here.
A new rpc for deposit withdrawals is added.
A withdrawal cooperatively spends the 2/2
musig deposit outpoint to a client-specified
address.
A server endpoint to obtain a partial sig
to cooperatively spend a 2/2 musig deposit
outpoint.
@hieblmi hieblmi self-assigned this Dec 2, 2024
@hieblmi hieblmi changed the base branch from master to static-addr-staging December 2, 2024 11:03
@hieblmi hieblmi marked this pull request as draft December 2, 2024 11:03
looprpc/client.proto Outdated Show resolved Hide resolved
@hieblmi hieblmi force-pushed the withdraw-amounts branch 5 times, most recently from 4f2ff5d to f7af7b4 Compare December 3, 2024 12:44
@hieblmi hieblmi marked this pull request as ready for review December 3, 2024 12:44
swapserverrpc/staticaddr.proto Show resolved Hide resolved
staticaddr/withdraw/manager.go Outdated Show resolved Hide resolved
@hieblmi hieblmi force-pushed the static-addr-staging branch from 5b68e42 to fb9562b Compare December 3, 2024 18:28
@hieblmi hieblmi requested a review from starius December 5, 2024 13:13
@hieblmi hieblmi force-pushed the static-addr-staging branch 3 times, most recently from 818562f to 9342b0f Compare December 12, 2024 17:31
Copy link
Collaborator

@starius starius left a comment

Choose a reason for hiding this comment

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

LGTM 🎉
I left few comments.
Also I notices that there are no tests in staticaddr/withdraw package. Does it make sense to add some to cover all withdrawing cases (full amount, with change, gifting dust change to miners)?

outpoints []wire.OutPoint, destAddr string, satPerVbyte int64) (string,
string, error) {
outpoints []wire.OutPoint, destAddr string, satPerVbyte int64,
amount int64) (string, string, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I propose to add to godoc, that amount=0 means "withdraw everything".

}

addressParams, err := m.cfg.AddressManager.GetStaticAddressParameters(
ctx,
// Send change back to the static address.
Copy link
Collaborator

Choose a reason for hiding this comment

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

I propose this change to make it more clear that address is the same.

s/to the static address/to the same static address/

// the withdrawal.
return nil, 0, 0, fmt.Errorf("the change doesn't " +
"cover for fees. Consider lowering the fee " +
"rate or increase the withdrawal amount")
Copy link
Collaborator

Choose a reason for hiding this comment

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

s/increase/decrease/ IIUC

withdrawalAmount = selectedWithdrawalAmount

default:
// If the fees eat into our withdrawal amount, we fail
Copy link
Collaborator

Choose a reason for hiding this comment

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

Actually, the feeWithChange fees eat into our withdrawal amount, but this doesn't mean that feeWithoutChange do, since it is lower than feeWithChange. This means, that some amounts fail, even though it is possible to withdraw without change. And we fallback to withdrawing without change in general case when it is not enough funds for the change. So I think for consistency we should do the same here. Can we replace case change-feeWithChange >= 0: with case change-feeWithoutChange >= 0: above?

@hieblmi hieblmi changed the base branch from static-addr-staging to master December 14, 2024 11:22
@lightninglabs-deploy
Copy link

@bhandras: review reminder
@sputn1ck: review reminder

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.

4 participants