Diamond Contracts

Throughout the development of the RAIR system we’ve had to do updates to the Master Factory, the Minter Marketplace and the ERC721 contract, these updates are not backwards compatible, which means any information within the contracts is lost, and the contracts already deployed can’t receive the updates to the code.

Additionally, if the master factory or either marketplace is replaced, the connection between the contracts becomes too complicated.

The RAIR system on the blockchainAny update breaks the system

To fix this we would need a way to upgrade the contracts, but the known upgradeable contract method can’t be applied because there’s no way to upgrade an ERC721 contract that is already deployed.

To fix this problem we use a Multi-Facet Proxy “Diamond“ contract

A diamond contract delegates function calls to other contracts in the blockchain, while using the information stored inside the diamond contract. This means the information and the processing of the information are separate, and the “facets” of the diamond can be changed at any time by an administrator.

Using these upgradeable facets we can update the functionality of the contract while keeping the same address and information.

Keeping the diamond address and information while the functionality is updated

Taking advantage of the diamond’s proxies we can deploy contracts that don’t store any facets by itself, but asks their factory for the facet they needed. This means users can deploy contracts at any time and will always have the latest functionality.

The create product facet is in the Master Factory, even if the ERC721 is the one calling it

The use of the facets reduces the size of the contract’s bytecode, since the code is now elsewhere. This means we can bypass the 24 kilobyte limit that the Ethereum Virtual Machine has and have contracts with much more functionality than before, while keeping deployment costs optimized.

Taking advantage of this we can reorganize the ranges and products so they are stored on the deployed Factory, leaving the minter marketplace only to offer them and sell them.

Last updated