You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hey guys, been watching the project unfold for months and have learned a lot. As a way to give back I thought I'd contribute some improvements for the smart contracts. Since I'm a first time contributor I feel its probably best to start with an issue outlining some of my improvements.
Improvement 1 ⛽
Tightly pack the swap struct.
Reasoning:
Reducing the amount of data that's hashed (via keccak256) will save a decent amount of gas. Given we're hashing the struct and not storing it there's an incentive to reduce the struct size as much as possible. Below you can see I've gotten it down to 5 slots, however we could pack it further.
Use abi.encodePacked() rather than abi.encode() & unpack the struct from memory before encoding.
Reasoning:
Similarly to Improvement 1, the idea here is to reduce the amount of data that is being hashed to compute swapID. When using abi.encodePacked the returned output is tightly packed rather than including unnecessary padding. However as you may know abi.encodePacked is not supported for structs; I would suggest unpacking the Swap before encoding.
@0xClandestine hey, thanks for these suggestions! let us know if you plan to open a PR with these changes, otherwise I can add these in. if you have any contributing questions feel free to ask :)
Hey guys, been watching the project unfold for months and have learned a lot. As a way to give back I thought I'd contribute some improvements for the smart contracts. Since I'm a first time contributor I feel its probably best to start with an issue outlining some of my improvements.
Improvement 1 ⛽
Reasoning:
Improvement 2 ⛽
abi.encodePacked()
rather thanabi.encode()
& unpack the struct from memory before encoding.Reasoning:
swapID
. When usingabi.encodePacked
the returned output is tightly packed rather than including unnecessary padding. However as you may knowabi.encodePacked
is not supported forstructs
; I would suggest unpacking theSwap
before encoding.The text was updated successfully, but these errors were encountered: