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

UDC deposit and withdraw API #6821

Merged
merged 4 commits into from
Feb 25, 2021
Merged

Conversation

manuelwedler
Copy link
Contributor

Description

Fixes: #5497

This adds a api/v1/user_deposit endpoint as specified in the linked issue for interacting with the UDC.
It has three possibilities for POST requests depending on the body parameter:

  • deposit: {total_deposit: <amount>}
  • plan a withdraw: {planned_withdraw_amount: <amount>}
  • withdraw: {withdraw_amount: <amount>}

This is needed for having a user-friendly interface to the UDC in the WebUI.

@auto-assign auto-assign bot requested a review from ulope February 12, 2021 13:35
@manuelwedler manuelwedler requested review from karlb and removed request for ulope February 18, 2021 11:00
Copy link
Contributor

@karlb karlb left a comment

Choose a reason for hiding this comment

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

Very thorough PR with lots of error case handling, tests and documentation!

I'm just not sure about the right place for the error checks (api vs proxy). Maybe we should ask someone else for his opinion in this regard?

current_total_deposit = user_deposit.get_total_deposit(
address=self.address, block_identifier=confirmed_block_identifier
)
addendum = new_total_deposit - current_total_deposit
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think the work "addendum" is used in the context of summing up numbers. Counter suggestion: deposit_increase.

Comment on lines 1214 to 1229
if new_total_deposit <= current_total_deposit:
raise DepositMismatch("Total deposit did not increase.")

if whole_balance + addendum > UINT256_MAX:
raise DepositOverLimit("Deposit overflow.")

if whole_balance + addendum > whole_balance_limit:
msg = f"Deposit of {addendum} would have exceeded the UDC balance limit."
raise DepositOverLimit(msg)

if balance < addendum:
msg = f"Not enough balance to deposit. Available={balance} Needed={addendum}"
raise InsufficientFunds(msg)
Copy link
Contributor

Choose a reason for hiding this comment

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

Should these checks be in the contract proxy, instead? Do we ever want to call the contract with any of these violated or unkown?

See also https://github.com/raiden-network/raiden/blob/develop/docs/proxies.rst#state-modifying-case

Copy link
Contributor Author

Choose a reason for hiding this comment

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

They are in both places at the moment. This is quite redundant, but I tried to be consistent with the other API functions. The channel deposit function does the same for example.
One advantage I see is that we can show more specific error codes like this. For example a 402 if the RDN balance is too low.

The guide for using the proxies also says for a raised BrokenPreconditionError:

This means there is a mistake in the Raiden codebase, and a check must be added before calling the proxy.

And yes, it would be good to hear someone else's opinion on that.

Copy link
Contributor

Choose a reason for hiding this comment

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

@ulope @palango Any opinions on this?

Copy link
Contributor

Choose a reason for hiding this comment

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

I pointed this out repeatedly during our stand-up. Apparently nobody feels strong enough about this to comment. Feel free to proceed with the current approach.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Alright then. Thanks for your help!

Comment on lines +1416 to +1420
if total_deposit is not None and planned_withdraw_amount is not None:
return api_error(
errors="Cannot deposit to UDC and plan a withdraw at the same time",
status_code=HTTPStatus.BAD_REQUEST,
)
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't like such multi-purpose functions, but since other API endpoints work in the same way, this seems to be the right thing to do for consistency's sake.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, I agree. We should probably improve in that sense in a v2 of the API.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

API endpoint for UDC contract to deposit and withdraw RDN tokens
2 participants