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

refactor: improve LSP23 readability #650

Merged
merged 13 commits into from
Aug 4, 2023
Merged

Conversation

b00ste
Copy link
Member

@b00ste b00ste commented Aug 2, 2023

What does this PR introduce?

♻️ Refactor

This PR applies the following changes:

  • Split the main contract in:
    1. main contract
    2. interface
    3. errors file
  • Split deployContracts(...) in another 2 internal functions for better readability and separation of concern.
  • Move the salt parameter into the ControlledContract struct because it is only used when deploying the initial contract. Makes it cluttered having it as a separate parameter.
  • Move Natspec to the interface and inheriting it in the main contract.
  • Natspec improvements. Added Natspec to structs and errors.
  • Moved salt generation to internal overridable functions. Separating concern and less prone to errors.

With all these changes the tests were running good, no issues.

PR Checklist

  • Wrote Tests
  • Wrote & Generated Documentation (readme/natspec/dodoc)
  • Ran npm run lint && npm run lint:solidity (solhint)
  • Ran npm run format (prettier)
  • Ran npm run build
  • Ran npm run test

@github-actions
Copy link
Contributor

github-actions bot commented Aug 2, 2023

👋 Hello
⛽ I am the Gas Bot Reporter. I keep track of the gas costs of common interactions using Universal Profiles 🆙 !
📊 Here is a summary of the gas cost with the code introduced by this PR.

⛽📊 See Gas Benchmark report of Using UniversalProfile owned by an EOA

🔀 execute scenarios

execute scenarios - 👑 UP Owner ⛽ Gas Usage
Transfer 1 LYX to an EOA without data 37537
Transfer 1 LYX to a UP without data 36639
Transfer 1 LYX to an EOA with 256 bytes of data 42198
Transfer 1 LYX to a UP with 256 bytes of data 44762
Transfer 0.1 LYX to 3x EOA without data 70862
Transfer 0.1 LYX to 3x UP without data 75680
Transfer 0.1 LYX to 3x EOA with 256 bytes of data 84850
Transfer 0.1 LYX to 3x EOA with 256 bytes of data 100042

🗄️ setData scenarios

setData scenarios - 👑 UP Owner ⛽ Gas Usage
Set a 20 bytes long value 49971
Set a 60 bytes long value 95293
Set a 160 bytes long value 164453
Set a 300 bytes long value 279688
Set a 600 bytes long value 484124
Change the value of a data key already set 32859
Remove the value of a data key already set 27333
Set 2 data keys of 20 bytes long value 78416
Set 2 data keys of 100 bytes long value 260568
Set 3 data keys of 20 bytes long value 105145
Change the value of three data keys already set of 20 bytes long value 45433
Remove the value of three data keys already set 41339

🗄️ Tokens scenarios

Tokens scenarios - 👑 UP Owner ⛽ Gas Usage
Minting a LSP7Token to a UP (No Delegate) from an EOA 91241
Minting a LSP7Token to an EOA from an EOA 59206
Transferring an LSP7Token from a UP to another UP (No Delegate) 98689
Minting a LSP8Token to a UP (No Delegate) from an EOA 158192
Minting a LSP8Token to an EOA from an EOA 126157
Transferring an LSP8Token from a UP to another UP (No Delegate) 147236

📝 Notes

  • The execute and setData scenarios are executed on a fresh UniversalProfile smart contract, deployed as standard contracts (not as proxy behind a base contract implementation).
⛽📊 See Gas Benchmark report of Using UniversalProfile owned by an LSP6KeyManager

This document contains the gas usage for common interactions and scenarios when using UniversalProfile smart contracts.

🔀 execute scenarios

👑 unrestricted controller

execute scenarios - 👑 main controller ⛽ Gas Usage
transfer LYX to an EOA 60439
transfer LYX to a UP 62041
transfer tokens (LSP7) to an EOA (no data) 107162
transfer tokens (LSP7) to a UP (no data) 242734
transfer a NFT (LSP8) to a EOA (no data) 171009
transfer a NFT (LSP8) to a UP (no data) 289909

🛃 restricted controller

execute scenarios - 🛃 restricted controller ⛽ Gas Usage
transfer some LYXes to an EOA - restricted to 1 x allowed address only (TRANSFERVALUE + 1x AllowedCalls) 72648
transfers some tokens (LSP7) to an EOA - restricted to LSP7 + 2x allowed contracts only (CALL + 2x AllowedCalls) (no data) 122941
transfers some tokens (LSP7) to an other UP - restricted to LSP7 + 2x allowed contracts only (CALL + 2x AllowedCalls) (no data) 258513
transfers a NFT (LSP8) to an EOA - restricted to LSP8 + 2x allowed contracts only (CALL + 2x AllowedCalls) (no data) 186776
transfers a NFT (LSP8) to an other UP - restricted to LSP8 + 2x allowed contracts only (CALL + 2x AllowedCalls) (no data) 305676

🗄️ setData scenarios

👑 unrestricted controller

setData scenarios - 👑 main controller ⛽ Gas Usage
updates profile details (LSP3Profile metadata) 136875
give permissions to a controller (AddressPermissions[] + AddressPermissions[index] + AddressPermissions:Permissions:) 132906
restrict a controller to some specific ERC725Y Data Keys 139282
restrict a controller to interact only with 3x specific addresses 161986
remove a controller (its permissions + its address from the AddressPermissions[] array) 67871
write 5x LSP12 Issued Assets 233253

🛃 restricted controller

setData scenarios - 🛃 restricted controller ⛽ Gas Usage
setData(bytes32,bytes) -> updates 1x data key 102626
setData(bytes32[],bytes[]) -> updates 3x data keys (first x3) 161440
setData(bytes32[],bytes[]) -> updates 3x data keys (middle x3) 145519
setData(bytes32[],bytes[]) -> updates 3x data keys (last x3) 170752
setData(bytes32[],bytes[]) -> updates 2x data keys + add 3x new controllers (including setting the array length + indexes under AddressPermissions[index]) 249872

📝 Notes

  • The execute and setData scenarios are executed on a fresh UniversalProfile and LSP6KeyManager smart contracts, deployed as standard contracts (not as proxy behind a base contract implementation).

@skimaharvey
Copy link
Member

Thanks for the PR 🚀

  • ✅ splitted contracts is better
  • ✅ 2 internal functions witht the deployContracts function makes sense
  • 🚫 would not split the event into different events it would be more difficult to retrieve them. The end goal is to make it easy to retrieve all infos at once
  • ✔️ thats a good point, we use to have two different salts but its true than now salt is used only in the OwnerControlledContract so it may make sense to add it to the struct directly. Need to check with the rest of team

tests/testBug.test.ts Outdated Show resolved Hide resolved
Copy link
Member

@CJ42 CJ42 left a comment

Choose a reason for hiding this comment

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

Added first round of review

if (!success) {
revert ControlledContractProxyInitFailureError(returnedData);
}

emit DeployedERC1167Proxie(
Copy link
Member

Choose a reason for hiding this comment

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

Since the param of this event do not depend on the success and returnedData, we could emit it before the external to avoid out of order events in the logs.

I suggest move this emit statement before the external call.

Copy link
Member

@skimaharvey skimaharvey left a comment

Choose a reason for hiding this comment

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

Would revert to single event for now

Copy link
Member

@skimaharvey skimaharvey left a comment

Choose a reason for hiding this comment

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

Looks great! Thanks

@CJ42 CJ42 merged commit f8e69ae into feat/lsp23 Aug 4, 2023
24 checks passed
@CJ42 CJ42 deleted the refactor/improve-readability branch August 4, 2023 09:52
CJ42 added a commit that referenced this pull request Aug 4, 2023
* feat: create LSP23MultiChainDeployment

* refactor: improve LSP23 readability (#650)

* refactor: improve LSP23 readability

* tests: create helper to calculate deployed addresses

* tests: add test for lsp23

* refactor: add suggested changes & surther simplify

* refactor: remove event split, restore the initial events.

* refactor: fix generation of salt

* refactor: make salt generation functions virtual

* chore: fix typo

* refactor: move `emit` before external call to `IPostDeploymentModule`

* chore: add suggested changes

* docs: improve Natspec as suggetsed

* docs: fix Natspec typo

* chore: remove unrelated file

---------

Co-authored-by: maxvia87 <maximeviard@hotmail.fr>

---------

Co-authored-by: b00ste.lyx <62855857+b00ste@users.noreply.github.com>
Co-authored-by: Jean Cvllr <31145285+CJ42@users.noreply.github.com>
@CJ42 CJ42 mentioned this pull request Aug 4, 2023
CJ42 added a commit that referenced this pull request Aug 7, 2023
* Add virtual (#644)

* chore: add missing virtual keyword in LSP6

* chore: add missing virtual keyword in LSP7

* chore: add missing virtual keyword in LSP8

* chore: add missing virtual keyword in LSP9

* chore: add missing virtual keyword in LSP20

* chore: add missing virtual keyword in LSP0

* refactor: add virtual to target() in LSP6 core

* chore: rename _revert in LSP20CallVerification

* refactor: add virtual to all LSP6 _isAllowed checks

* feat: create LSP23MultiChainDeployment (#649)

* feat: create LSP23MultiChainDeployment

* refactor: improve LSP23 readability (#650)

* refactor: improve LSP23 readability

* tests: create helper to calculate deployed addresses

* tests: add test for lsp23

* refactor: add suggested changes & surther simplify

* refactor: remove event split, restore the initial events.

* refactor: fix generation of salt

* refactor: make salt generation functions virtual

* chore: fix typo

* refactor: move `emit` before external call to `IPostDeploymentModule`

* chore: add suggested changes

* docs: improve Natspec as suggetsed

* docs: fix Natspec typo

* chore: remove unrelated file

---------

Co-authored-by: maxvia87 <maximeviard@hotmail.fr>

---------

Co-authored-by: b00ste.lyx <62855857+b00ste@users.noreply.github.com>
Co-authored-by: Jean Cvllr <31145285+CJ42@users.noreply.github.com>

* feat!: make reentracy status internal (#651)

* chore(release): 0.11.0-rc.0 (#652)

* fix: failing tests for lsp23 + add LSP23 test suite in CI (#657)

* tests: fix lsp23 tests

* ci: add lsp23 tests to lint workflow

---------

Co-authored-by: Callum Grindle <callumgrindle@gmail.com>
Co-authored-by: Skima Harvey <64636974+skimaharvey@users.noreply.github.com>
Co-authored-by: b00ste.lyx <62855857+b00ste@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants