This PR is an amendment to the ERC20 Extendable PR. It replaces the back-bone architecture for TokenExtensions from a proxy pattern to the diamond pattern. In the diamond architecture, all TokenExtension instances registered are treated as diamond facets. This also means that the storage layout was changed to use Diamond Storage.
Motivation and Context
Reason
The EIP-2535: Diamonds, Multi-Facet Proxy is becoming more standard in the ecosystem and seems advantages for us to support this spec by implementing it for TokenExtensions. This is also more gas efficient when extension external functions are called.
Diamond Implementation
The Diamond implementation used in this PR is diamond-3. This is because diamond-3 uses less gas to call the diamond loupe functions. The tradeoff is that diamond-3 uses more gas for diamond cutting for Extensions.
Diamond storage seems more likely for the OpenZeppelin in the near future, full support is unlikely (however we only need Diamond Storage minimum).
Removal of ExtensionProxy and ExtendableProxy
Both the ExtensionProxy and ExtendableProxy were removed in this PR as they are no longer required. ExtendableProxy is replaced with ExtendableDiamond, and ExtensionProxy is replaced with the functionality in Diamond + DiamondLib.
How Has This Been Tested?
All unit tests in original PR #129 are passing.
Some unit tests were updated to check state of Diamond proxy to make sure it follows expected behavior for registering/removing/disabling extensions.
Types of changes
[ ] Bug fix (non-breaking change which fixes an issue)
[ ] New feature (non-breaking change which adds functionality)
[x] Breaking change (fix or feature that would cause existing functionality to change)
Checklist:
[x] My code follows the code style of this project.
[x] My change requires a change to the documentation.
Description
This PR is an amendment to the ERC20 Extendable PR. It replaces the back-bone architecture for
TokenExtension
s from a proxy pattern to the diamond pattern. In the diamond architecture, allTokenExtension
instances registered are treated as diamond facets. This also means that the storage layout was changed to use Diamond Storage.Motivation and Context
Reason
The EIP-2535: Diamonds, Multi-Facet Proxy is becoming more standard in the ecosystem and seems advantages for us to support this spec by implementing it for
TokenExtensions
. This is also more gas efficient when extension external functions are called.Diamond Implementation
The Diamond implementation used in this PR is diamond-3. This is because diamond-3 uses less gas to call the diamond loupe functions. The tradeoff is that diamond-3 uses more gas for diamond cutting for Extensions.
Dependency change
@openzeppelin/contracts-upgradeable
--->@gnus.ai/contracts-upgradeable-diamond@^4.5.0
The dependency for OpenZeppelin contracts (used in
ERC20Logic
) was replaced with one that supports Diamond Storage.OpenZeppelin does have an open issue for both implementing the diamond proy and implementing diamond storage.
Diamond storage seems more likely for the OpenZeppelin in the near future, full support is unlikely (however we only need Diamond Storage minimum).
Removal of
ExtensionProxy
andExtendableProxy
Both the
ExtensionProxy
andExtendableProxy
were removed in this PR as they are no longer required.ExtendableProxy
is replaced withExtendableDiamond
, andExtensionProxy
is replaced with the functionality inDiamond
+DiamondLib
.How Has This Been Tested?
All unit tests in original PR #129 are passing.
Some unit tests were updated to check state of Diamond proxy to make sure it follows expected behavior for registering/removing/disabling extensions.
Types of changes
Checklist: