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

Add function to combine open and deposit #1436

Closed
karlb opened this issue Mar 4, 2021 · 2 comments · Fixed by #1486
Closed

Add function to combine open and deposit #1436

karlb opened this issue Mar 4, 2021 · 2 comments · Fixed by #1486
Assignees
Milestone

Comments

@karlb
Copy link
Contributor

karlb commented Mar 4, 2021

When a channel is opened, the user usually also wants to deposit tokens into the channel. Right now, this involves two transactions and waiting for confirmation in between. Adding a function that combines these two operations will allow them to happen in a single transaction, thus reducing the time until the channel can be used. (An approve transaction has to be done in both cases, in addition to the transactions mentioned)

This function could be in an auxiliary contract. But if there is enough space left if the TokenNetwork contract, I suggest adding it there to keep the number of contracts low.

The expectation is that this is a low effort thing to add. If this is not the case, please bring up the complications in this issue before spending much time on the implementation, so we can reconsider if it's worth implementing.

@karlb karlb added this to the Coruscant milestone Mar 4, 2021
@palango palango self-assigned this Jul 1, 2021
@palango
Copy link
Contributor

palango commented Jul 1, 2021

@karlb Some questions to the prototype below:

  • We don't need a way to deposit for participant2 in this call, with the assumption that every user deposits for itself.
  • Do you think we should rename participant1_total_deposit to participant1_deposit as it's always the first deposit?
+    /// @notice Opens a new channel between `participant1` and `participant2`
+    /// Can be called by anyone
+    /// @param participant1 Ethereum address of a channel participant
+    /// @param participant2 Ethereum address of the other channel participant
+    /// @param settle_timeout Number of blocks that need to be mined between a
+    /// call to closeChannel and settleChannel
+    /// @param participant1_total_deposit The total amount of tokens that participant1
+    /// will have as a deposit
+    function openChannelWithDeposit(
+        address participant1,
+        address participant2,
+        uint256 settle_timeout,
+        uint256 participant1_total_deposit
+    )
+        public
+        isSafe
+        settleTimeoutValid(settle_timeout)
+        returns (uint256)
+    {
+        uint256 channel_identifier;
+
+        channel_identifier = openChannel(participant1, participant2, settle_timeout);
+        setTotalDeposit(channel_identifier, participant1, participant1_total_deposit, participant2);
+
+        return channel_identifier;
+    }

@karlb
Copy link
Contributor Author

karlb commented Jul 1, 2021

We don't need a way to deposit for participant2 in this call, with the assumption that every user deposits for itself.

With the above code, you already can deposit for the other participant by choosing him as participant1. Depositing to both doesn't seem very useful, since depositing to yourself and sending a transfer is cheaper.

Do you think we should rename participant1_total_deposit to participant1_deposit as it's always the first deposit?

I would keep it as participant1_total_deposit for consistency, although I see the point in renaming it.

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 a pull request may close this issue.

2 participants