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

feat: add _afterTokenTransfer internal function in LSP7 + LSP8 #739

Merged
merged 3 commits into from
Oct 13, 2023

Conversation

CJ42
Copy link
Member

@CJ42 CJ42 commented Oct 10, 2023

What does this PR introduce?

🚀 Feature

Add internal function _afterTokenTransfer that can be overriden to run logic after tokens have been transferred + event Transfer has been emitted.

📄 Documentation

Update auto-generated docs.

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

@CJ42 CJ42 changed the title Feat/afterTokenTransfer-hooks feat: add _afterTokenTransfer hook in LSP7 + LSP8 Oct 10, 2023
@CJ42 CJ42 changed the title feat: add _afterTokenTransfer hook in LSP7 + LSP8 feat: add _afterTokenTransfer internal function in LSP7 + LSP8 Oct 10, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Oct 10, 2023

Changes to gas cost

Generated at commit: 184d447c5898d9cd385af23a763233d9da48ae70, compared to commit: b8eca3c5696acf85239130ef67edec9e8c134bfa

🧾 Summary (10% most significant diffs)

Contract Method Avg (+/-) %
LSP6ExecuteRestrictedController transferLYXToUP +11,279 ❌ +35.81%
LSP6ExecuteUnrestrictedController transferLYXToUP +10,879 ❌ +32.48%
LSP6SetDataRestrictedController execute +6,081 ❌ +21.31%
LSP6SetDataUnrestrictedController execute +6,081 ❌ +21.31%

Full diff report 👇
Contract Deployment Cost (+/-) Method Min (+/-) % Avg (+/-) % Median (+/-) % Max (+/-) % # Calls (+/-)
LSP6ExecuteRestrictedController 2,898,727 (+23,036) lsp20VerifyCall
transferLYXToEOA
transferLYXToUP
transferNFTToRandomEOA
transferNFTToRandomUP
transferTokensToRandomEOA
transferTokensToRandomUP
14,657 (-239)
62,528 (+6,363)
42,775 (+11,279)
146,317 (+15,548)
254,922 (+15,608)
76,497 (+2,805)
211,373 (+2,214)
-1.60%
+11.33%
+35.81%
+11.89%
+6.52%
+3.81%
+1.06%
16,856 (-176)
62,528 (+6,363)
42,775 (+11,279)
146,317 (+15,548)
254,922 (+15,608)
76,497 (+2,805)
211,373 (+2,214)
-1.03%
+11.33%
+35.81%
+11.89%
+6.52%
+3.81%
+1.06%
17,589 (-156)
62,528 (+6,363)
42,775 (+11,279)
146,317 (+15,548)
254,922 (+15,608)
76,497 (+2,805)
211,373 (+2,214)
-0.88%
+11.33%
+35.81%
+11.89%
+6.52%
+3.81%
+1.06%
17,589 (-156)
62,528 (+6,363)
42,775 (+11,279)
146,317 (+15,548)
254,922 (+15,608)
76,497 (+2,805)
211,373 (+2,214)
-0.88%
+11.33%
+35.81%
+11.89%
+6.52%
+3.81%
+1.06%
8 (0)
1 (0)
1 (0)
1 (0)
1 (0)
1 (0)
1 (0)
LSP6ExecuteUnrestrictedController 2,898,727 (+23,036) lsp20VerifyCall
transferLYXToEOA
transferLYXToUP
transferNFTToRandomEOA
transferNFTToRandomUP
transferTokensToRandomEOA
transferTokensToRandomUP
14,657 (-239)
63,032 (+6,237)
44,375 (+10,879)
145,066 (+15,548)
253,671 (+15,608)
75,246 (+3,118)
209,809 (+2,214)
-1.60%
+10.98%
+32.48%
+12.00%
+6.56%
+4.32%
+1.07%
16,856 (-176)
63,032 (+6,237)
44,375 (+10,879)
145,066 (+15,548)
253,671 (+15,608)
75,246 (+3,118)
209,809 (+2,214)
-1.03%
+10.98%
+32.48%
+12.00%
+6.56%
+4.32%
+1.07%
17,589 (-156)
63,032 (+6,237)
44,375 (+10,879)
145,066 (+15,548)
253,671 (+15,608)
75,246 (+3,118)
209,809 (+2,214)
-0.88%
+10.98%
+32.48%
+12.00%
+6.56%
+4.32%
+1.07%
17,589 (-156)
63,032 (+6,237)
44,375 (+10,879)
145,066 (+15,548)
253,671 (+15,608)
75,246 (+3,118)
209,809 (+2,214)
-0.88%
+10.98%
+32.48%
+12.00%
+6.56%
+4.32%
+1.07%
8 (0)
1 (0)
1 (0)
1 (0)
1 (0)
1 (0)
1 (0)
LSP6SetDataRestrictedController 2,883,512 (+23,044) execute
givePermissionsToController
restrictControllerToERC725YKeys
30,770 (+12,280)
122,881 (+2,247)
141,590 (+2,706)
+66.41%
+1.86%
+1.95%
34,616 (+6,081)
122,881 (+2,247)
141,590 (+2,706)
+21.31%
+1.86%
+1.95%
34,616 (+6,081)
122,881 (+2,247)
141,590 (+2,706)
+21.31%
+1.86%
+1.95%
38,463 (-118)
122,881 (+2,247)
141,590 (+2,706)
-0.31%
+1.86%
+1.95%
2 (0)
1 (0)
1 (0)
LSP6SetDataUnrestrictedController 2,883,512 (+23,044) execute
givePermissionsToController
restrictControllerToERC725YKeys
30,770 (+12,280)
128,881 (+2,247)
150,090 (+2,706)
+66.41%
+1.77%
+1.84%
34,616 (+6,081)
128,881 (+2,247)
150,090 (+2,706)
+21.31%
+1.77%
+1.84%
34,616 (+6,081)
128,881 (+2,247)
150,090 (+2,706)
+21.31%
+1.77%
+1.84%
38,463 (-118)
128,881 (+2,247)
150,090 (+2,706)
-0.31%
+1.77%
+1.84%
2 (0)
1 (0)
1 (0)

@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 3007205 (0 )
KeyManager 3490991 (0 )
LSP1DelegateUP 1623804 (0 )
LSP7Mintable 2354082 (0 )
LSP8Mintable 2476554 (12 📈❌)

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 36639 (0 )
Transfer 1 LYX to an EOA with 256 bytes of data 42198 (-12 📉✅)
Transfer 1 LYX to a UP with 256 bytes of data 44867 (12 📈❌)
Transfer 0.1 LYX to 3x EOA without data 70862 (0 )
Transfer 0.1 LYX to 3x UP without data 75680 (0 )
Transfer 0.1 LYX to 3x EOA with 256 bytes of data 84850 (-12 📉✅)
Transfer 0.1 LYX to 3x UPs with 256 bytes of data 100321 (0 )

🗄️ setData scenarios

setData scenarios - UP owned by 🔑 EOA ⛽ Gas Usage
Set a 20 bytes long value 49959 (0 )
Set a 60 bytes long value 95293 (0 )
Set a 160 bytes long value 164465 (12 📈❌)
Set a 300 bytes long value 279688 (0 )
Set a 600 bytes long value 484148 (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 78442 (0 )
Set 2 data keys of 100 bytes long value 260618 (12 📈❌)
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 (12 📈❌)
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 91982 (0 )
Minting a LSP7Token to an EOA from an EOA 59289 (0 )
Transferring an LSP7Token from a UP to another UP (No Delegate) 100092 (0 )
Minting a LSP8Token to a UP (No Delegate) from an EOA 159126 (0 )
Minting a LSP8Token to an EOA from an EOA 126433 (0 )
Transferring an LSP8Token from a UP to another UP (No Delegate) 148899 (0 )
UniversalProfile owned by a 🔒📄 LSP6KeyManager

🔀 execute scenarios

execute scenarios 👑 main controller 🛃 restricted controller
LYX transfer --> to an EOA 66106 (0 ) 76899 (0 )
LYX transfer --> to a UP 67388 (0 ) 79370 (0 )
LSP7 token transfer --> to an EOA 120156 (0 ) 134847 (0 )
LSP7 token transfer --> to a UP 256711 (0 ) 271402 (0 )
LSP8 NFT transfer --> to an EOA 184399 (0 ) 199067 (0 )
LSP8 NFT transfer --> to a UP 304201 (0 ) 318869 (0 )

🗄️ setData scenarios

setData scenarios 👑 main controller 🛃 restricted controller
Update Profile details (LSP3Profile Metadata) 68714 (0 ) 78713 (0 )
Add a new controller with permission to SET_DATA + 3x allowed data keys:
AddressPermissions[]
+ AddressPermissions[index]
+ AddressPermissions:Permissions:<controller>
+ AddressPermissions:AllowedERC725YDataKeys:<controller)
212112 (0 ) 222177 (0 )
Update permissions of previous controller. Allow it now to SUPER_SETDATA 53601 (0 ) 56584 (0 )
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:
80562 (0 ) 91787 (0 )
Write 5x new LSP12 Issued Assets 68267 (0 ) 102871 (0 )
Update 3x data keys (first 3) 127555 (0 ) 161636 (0 )
Update 3x data keys (middle 3) 107643 (0 ) 145790 (0 )
Update 3x data keys (last 3) 127555 (0 ) 171123 (0 )
Set 2 x new data keys + add 3x new controllers 816000 (0 ) 877547 (0 )

@CJ42 CJ42 force-pushed the feat/afterTokenTransfer-hooks branch from 76ccd3f to 0820f42 Compare October 10, 2023 09:33
@CJ42 CJ42 force-pushed the feat/afterTokenTransfer-hooks branch from 0820f42 to 2b475b2 Compare October 10, 2023 14:12
Copy link
Member

@YamenMerhi YamenMerhi left a comment

Choose a reason for hiding this comment

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

Maybe it make sense to add the data field as well ?

@CJ42
Copy link
Member Author

CJ42 commented Oct 11, 2023

Maybe it make sense to add the data field as well ?

I guess then we would also need to add this parameter to the _beforeTokenTransfer hook, as it is not present?

@skimaharvey @b00ste wdyt?

function _beforeTokenTransfer(
address from,
address to,
uint256 amount // solhint-disable-next-line no-empty-blocks
) internal virtual {}

@skimaharvey
Copy link
Member

Maybe it make sense to add the data field as well ?

I guess then we would also need to add this parameter to the _beforeTokenTransfer hook, as it is not present?

@skimaharvey @b00ste wdyt?

function _beforeTokenTransfer(
address from,
address to,
uint256 amount // solhint-disable-next-line no-empty-blocks
) internal virtual {}

I think so as well

@CJ42 CJ42 force-pushed the feat/afterTokenTransfer-hooks branch from cc3f5a7 to 0cd0976 Compare October 13, 2023 09:47
@CJ42 CJ42 merged commit be80104 into develop Oct 13, 2023
27 checks passed
@CJ42 CJ42 deleted the feat/afterTokenTransfer-hooks branch October 13, 2023 10:54
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