Consensys / UniversalToken

Implementation of Universal Token for Assets and Payments
Apache License 2.0
347 stars 188 forks source link

Rebuild/Replace ExtendableProxy to ExtendableDiamond #145

Closed ecp4224 closed 2 years ago

ecp4224 commented 2 years ago

Description

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.

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

Checklist:

github-actions[bot] commented 2 years ago

CLA Assistant Lite bot All contributors have signed the CLA ✍️