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!: replace ValueReceived with UniversalReceiver #759

Merged
merged 16 commits into from
Oct 27, 2023

Conversation

YamenMerhi
Copy link
Member

@YamenMerhi YamenMerhi commented Oct 24, 2023

What does this PR introduce?

⚠️ BREAKING CHANGES

♻️ Refactor

  • Emitting UniversalReceiver event instead of ValueReceived in owner functions (setData, execute, ..)
  • Emitting UniversalReceiver event instead of ValueReceived and reacting on the call using UniversalReceiverDelegates in the receive, fallback and the universalReceiver function.
  • Update LSP17 to optionally forward value in LSP0 and LSP9

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

👋 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.

⛽📊 Gas Benchmark Report

Deployment Costs

Deployed contracts ⛽ Deployment cost
UniversalProfile 3085304 (97,011 📈❌)
KeyManager 3481039 (0 )
LSP1DelegateUP 1616585 (28,659 📈❌)
LSP7Mintable 2337563 (0 )
LSP8Mintable 2452847 (0 )

Runtime Costs

UniversalProfile owned by an 🔑 EOA

🔀 execute scenarios

execute scenarios - UP owned by 🔑 EOA ⛽ Gas Usage
Transfer 1 LYX to an EOA without data 37537 (0 )
Transfer 1 LYX to a UP without data 46236 (9,597 📈❌)
Transfer 1 LYX to an EOA with 256 bytes of data 42198 (0 )
Transfer 1 LYX to a UP with 256 bytes of data 54425 (9,570 📈❌)
Transfer 0.1 LYX to 3x EOA without data 70862 (0 )
Transfer 0.1 LYX to 3x UP without data 104471 (28,791 📈❌)
Transfer 0.1 LYX to 3x EOA with 256 bytes of data 84838 (12 📈❌)
Transfer 0.1 LYX to 3x UPs with 256 bytes of data 129031 (28,674 📈❌)

🗄️ setData scenarios

setData scenarios - UP owned by 🔑 EOA ⛽ Gas Usage
Set a 20 bytes long value 49971 (0 )
Set a 60 bytes long value 95293 (0 )
Set a 160 bytes long value 164465 (0 )
Set a 300 bytes long value 279700 (12 📈❌)
Set a 600 bytes long value 484160 (36 📈❌)
Change the value of a data key already set 32859 (0 )
Remove the value of a data key already set 27333 (0 )
Set 2 data keys of 20 bytes long value 78454 (12 📈❌)
Set 2 data keys of 100 bytes long value 260618 (0 )
Set 3 data keys of 20 bytes long value 105171 (0 )
Change the value of three data keys already set of 20 bytes long value 45471 (0 )
Remove the value of three data keys already set 41360 (0 )

🗄️ Tokens scenarios

Tokens scenarios - UP owned by 🔑 EOA ⛽ Gas Usage
Minting a LSP7Token to a UP (No Delegate) from an EOA 92641 (659 📈❌)
Minting a LSP7Token to an EOA from an EOA 59289 (0 )
Transferring an LSP7Token from a UP to another UP (No Delegate) 101410 (1,318 📈❌)
Minting a LSP8Token to a UP (No Delegate) from an EOA 159581 (659 📈❌)
Minting a LSP8Token to an EOA from an EOA 126229 (0 )
Transferring an LSP8Token from a UP to another UP (No Delegate) 150217 (1,318 📈❌)
UniversalProfile owned by a 🔒📄 LSP6KeyManager

🔀 execute scenarios

execute scenarios 👑 main controller 🛃 restricted controller
LYX transfer --> to an EOA 66244 (-42 📉✅) 77036 (-43 📉✅)
LYX transfer --> to a UP 80589 (13,021 📈❌) 95567 (16,017 📈❌)
LSP7 token transfer --> to an EOA 119027 (963 📈❌) 133718 (963 📈❌)
LSP7 token transfer --> to a UP 254424 (1,929 📈❌) 269115 (1,929 📈❌)
LSP8 NFT transfer --> to an EOA 183270 (963 📈❌) 197938 (963 📈❌)
LSP8 NFT transfer --> to a UP 301914 (1,929 📈❌) 316582 (1,929 📈❌)

🗄️ setData scenarios

setData scenarios 👑 main controller 🛃 restricted controller
Update Profile details (LSP3Profile Metadata) 68853 (-53 📉✅) 78852 (-53 📉✅)
Add a new controller with permission to SET_DATA + 3x allowed data keys:
AddressPermissions[]
+ AddressPermissions[index]
+ AddressPermissions:Permissions:<controller>
+ AddressPermissions:AllowedERC725YDataKeys:<controller)
212252 (-53 📉✅) 222317 (-53 📉✅)
Update permissions of previous controller. Allow it now to SUPER_SETDATA 53740 (-53 📉✅) 56723 (-53 📉✅)
Remove a controller:
1. decrease AddressPermissions[] Array length
2. remove the controller address at AddressPermissions[index]
3. set "0x" for the controller permissions under AddressPermissions:Permissions:
80673 (-43 📉✅) 91898 (-42 📉✅)
Write 5x new LSP12 Issued Assets 68406 (-53 📉✅) 103010 (-53 📉✅)
Update 3x data keys (first 3) 127694 (-53 📉✅) 161775 (-53 📉✅)
Update 3x data keys (middle 3) 107782 (-53 📉✅) 145929 (-53 📉✅)
Update 3x data keys (last 3) 127694 (-53 📉✅) 171262 (-53 📉✅)
Set 2 x new data keys + add 3x new controllers 816141 (-53 📉✅) 877688 (-53 📉✅)

@github-actions
Copy link
Contributor

github-actions bot commented Oct 24, 2023

Changes to gas cost

Generated at commit: 64089757e331e4afe6fa9817a6b812735a89f81d, compared to commit: e2ec65aeba2aca8351d9a9e71e08e34a004ae483

🧾 Summary (10% most significant diffs)

Contract Method Avg (+/-) %
LSP6ExecuteRestrictedController transferLYXToUP
transferNFTToRandomEOA
transferNFTToRandomUP
+12,982 ❌
-1,288 ✅
-2,595 ✅
+30.36%
-0.89%
-1.03%
LSP6ExecuteUnrestrictedController transferLYXToUP
transferNFTToRandomEOA
transferNFTToRandomUP
transferTokensToRandomEOA
+12,982 ❌
-1,265 ✅
-2,571 ✅
+610 ❌
+29.27%
-0.88%
-1.03%
+0.83%

Full diff report 👇
Contract Deployment Cost (+/-) Method Min (+/-) % Avg (+/-) % Median (+/-) % Max (+/-) % # Calls (+/-)
LSP6ExecuteRestrictedController 3,044,307 (+138,364) lsp20VerifyCall
transferLYXToEOA
transferLYXToUP
transferNFTToRandomEOA
transferNFTToRandomUP
transferTokensToRandomEOA
transferTokensToRandomUP
14,773 (-44)
62,408 (-102)
55,739 (+12,982)
143,316 (-1,288)
248,936 (-2,595)
75,230 (+586)
206,059 (-790)
-0.30%
-0.16%
+30.36%
-0.89%
-1.03%
+0.79%
-0.38%
16,996 (-20)
62,408 (-102)
55,739 (+12,982)
143,316 (-1,288)
248,936 (-2,595)
75,230 (+586)
206,059 (-790)
-0.12%
-0.16%
+30.36%
-0.89%
-1.03%
+0.79%
-0.38%
17,738 (-11)
62,408 (-102)
55,739 (+12,982)
143,316 (-1,288)
248,936 (-2,595)
75,230 (+586)
206,059 (-790)
-0.06%
-0.16%
+30.36%
-0.89%
-1.03%
+0.79%
-0.38%
17,738 (-11)
62,408 (-102)
55,739 (+12,982)
143,316 (-1,288)
248,936 (-2,595)
75,230 (+586)
206,059 (-790)
-0.06%
-0.16%
+30.36%
-0.89%
-1.03%
+0.79%
-0.38%
8 (0)
1 (0)
1 (0)
1 (0)
1 (0)
1 (0)
1 (0)
LSP6ExecuteUnrestrictedController 3,044,307 (+138,364) lsp20VerifyCall
transferLYXToEOA
transferLYXToUP
transferNFTToRandomEOA
transferNFTToRandomUP
transferTokensToRandomEOA
transferTokensToRandomUP
14,773 (-44)
62,935 (-79)
57,339 (+12,982)
142,088 (-1,265)
247,709 (-2,571)
74,003 (+610)
204,525 (-760)
-0.30%
-0.13%
+29.27%
-0.88%
-1.03%
+0.83%
-0.37%
16,996 (-20)
62,935 (-79)
57,339 (+12,982)
142,088 (-1,265)
247,709 (-2,571)
74,003 (+610)
204,525 (-760)
-0.12%
-0.13%
+29.27%
-0.88%
-1.03%
+0.83%
-0.37%
17,738 (-11)
62,935 (-79)
57,339 (+12,982)
142,088 (-1,265)
247,709 (-2,571)
74,003 (+610)
204,525 (-760)
-0.06%
-0.13%
+29.27%
-0.88%
-1.03%
+0.83%
-0.37%
17,738 (-11)
62,935 (-79)
57,339 (+12,982)
142,088 (-1,265)
247,709 (-2,571)
74,003 (+610)
204,525 (-760)
-0.06%
-0.13%
+29.27%
-0.88%
-1.03%
+0.83%
-0.37%
8 (0)
1 (0)
1 (0)
1 (0)
1 (0)
1 (0)
1 (0)
LSP6SetDataRestrictedController 3,032,291 (+141,571) execute
givePermissionsToController
restrictControllerToERC725YKeys
30,680 (-90)
122,686 (-173)
141,473 (-228)
-0.29%
-0.14%
-0.16%
34,514 (-102)
122,686 (-173)
141,473 (-228)
-0.29%
-0.14%
-0.16%
34,514 (-102)
122,686 (-173)
141,473 (-228)
-0.29%
-0.14%
-0.16%
38,349 (-114)
122,686 (-173)
141,473 (-228)
-0.30%
-0.14%
-0.16%
2 (0)
1 (0)
1 (0)
LSP6SetDataUnrestrictedController 3,032,291 (+141,571) execute
givePermissionsToController
restrictControllerToERC725YKeys
30,680 (-90)
128,686 (-173)
149,973 (-228)
-0.29%
-0.13%
-0.15%
34,514 (-102)
128,686 (-173)
149,973 (-228)
-0.29%
-0.13%
-0.15%
34,514 (-102)
128,686 (-173)
149,973 (-228)
-0.29%
-0.13%
-0.15%
38,349 (-114)
128,686 (-173)
149,973 (-228)
-0.30%
-0.13%
-0.15%
2 (0)
1 (0)
1 (0)

@YamenMerhi YamenMerhi marked this pull request as draft October 24, 2023 12:16
@skimaharvey skimaharvey marked this pull request as ready for review October 27, 2023 10:32
contracts/LSP0ERC725Account/LSP0ERC725AccountCore.sol Outdated Show resolved Hide resolved
contracts/LSP0ERC725Account/LSP0ERC725AccountCore.sol Outdated Show resolved Hide resolved
contracts/LSP17ContractExtension/LSP17Extendable.sol Outdated Show resolved Hide resolved
contracts/LSP17ContractExtension/LSP17Extendable.sol Outdated Show resolved Hide resolved

const amountTransferred = 20;

const transferFunctionSignature =
Copy link
Member

Choose a reason for hiding this comment

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

Suggest to use Typechain for this:

TransferExtension__factory.interface.encodeFunctionData("transferFunction(uint256)", argument)

).to.not.be.reverted;
});

it('should revert with custom error `CannotRegisterEOAsAsAssets` if its a typeId of LSP7/LSP8', async () => {
Copy link
Member

Choose a reason for hiding this comment

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

nice test 👌

});
});

describe('when NOT sending any `msg.value`', () => {
it('should NOT emit a `ValueReceived` event', async () => {
it('should NOT emit a `UniversalReceiver` event', async () => {
Copy link
Member

Choose a reason for hiding this comment

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

Tests that test "something must not happen" are great. Super nice! 👌

@@ -559,6 +594,148 @@ export const shouldBehaveLikeLSP3 = (
});
});
});

describe('when setting a UniversalReceiverDelegate for typeId of LYX receiving', () => {
Copy link
Member

Choose a reason for hiding this comment

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

suggestion

Suggested change
describe('when setting a UniversalReceiverDelegate for typeId of LYX receiving', () => {
describe('when setting a UniversalReceiverDelegate for typeId `LSP0ValueReceived`', () => {

to: context.universalProfile.address,
});

expect(tx).to.not.emit(context.universalProfile, 'UniversalReceiver');
Copy link
Member

Choose a reason for hiding this comment

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

amazing, great not test 👌

@CJ42
Copy link
Member

CJ42 commented Oct 27, 2023

We wil implement the suggested changes for the tests in a separate PR

@CJ42 CJ42 merged commit 0c17386 into develop Oct 27, 2023
26 checks passed
@CJ42 CJ42 deleted the reactOnNativeToken branch October 27, 2023 18:23
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.

4 participants