Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

use proxied simpleswaps #120

Merged
merged 8 commits into from
Mar 26, 2021
Merged

use proxied simpleswaps #120

merged 8 commits into from
Mar 26, 2021

Conversation

ralph-pichler
Copy link
Member

@ralph-pichler ralph-pichler commented Mar 5, 2021

  • uses proxies for cheaper simpleswap deployment
  • uses create2 for deterministic address derivation

Copy link
Collaborator

@Eknir Eknir left a comment

Choose a reason for hiding this comment

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

some comments.

@param _issuer the issuer of cheques from this chequebook (needed as an argument for "Setting up a chequebook as a payment").
_issuer must be an Externally Owned Account, or it must support calling the function cashCheque
@param _defaultHardDepositTimeout duration in seconds which by default will be used to reduce hardDeposit allocations
*/
constructor(address _issuer, address _token, uint _defaultHardDepositTimeout) public {
function init(address _issuer, address _token, uint _defaultHardDepositTimeout) public {
require(issuer == address(0), "already initialized");
Copy link
Collaborator

Choose a reason for hiding this comment

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

You are not protecting that _issuer is not equal to address(0). Hence, it may be that the contract is already initialized when this function is called. Why don't you use the Initializable.initializer modifier from OpenZeppelin?

Copy link
Member Author

Choose a reason for hiding this comment

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

cost primarily. Initializable.initializer implies setting more storage fields. by reusing the issuer field for the check we save about 20k gas.

Copy link
Collaborator

@Eknir Eknir Mar 26, 2021

Choose a reason for hiding this comment

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

Ok, but then at least we should have a require statement, guaranteeing that _issuer (init argument) is not equal to address(0). Because otherwise, init can be called multiple times.

address contractAddress = address(new ERC20SimpleSwap(issuer, ERC20Address, defaultHardDepositTimeoutDuration));
function deploySimpleSwap(address issuer, uint defaultHardDepositTimeoutDuration, bytes32 salt)
public returns (address) {
address contractAddress = Clones.cloneDeterministic(master, keccak256(abi.encode(msg.sender, salt)));
Copy link
Collaborator

Choose a reason for hiding this comment

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

What is the advantage of using cloneDeterministic over clone?

Copy link
Member Author

Choose a reason for hiding this comment

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

deterministic addresses. right now we actually have an (undocumented) issue in bee where if you deploy the chequebook but then there is a reorg with transaction reordering (after parsing the deploy receipt) you might end up with a chequebook for another overlay in your state store.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ok, thanks!


constructor(address _ERC20Address) public {
constructor(address _ERC20Address, address _master) public {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it is cleaner if you deploy the master contract as part of the constructor of the factory

Copy link
Member Author

Choose a reason for hiding this comment

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

that is a good idea, that also solves the master initialisation problem. will do that.

Copy link
Member Author

Choose a reason for hiding this comment

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

done

@ralph-pichler ralph-pichler requested a review from Eknir March 26, 2021 17:23
Copy link
Collaborator

@Eknir Eknir left a comment

Choose a reason for hiding this comment

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

Looks good to me! Great PR!

@@ -1,8 +1,11 @@
// SPDX-License-Identifier: BSD-3-Clause
Copy link
Collaborator

Choose a reason for hiding this comment

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

If this is merged, we can close #122

@ralph-pichler ralph-pichler merged commit d515641 into master Mar 26, 2021
# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants