• Stars
    star
    257
  • Rank 158,728 (Top 4 %)
  • Language
  • License
    MIT License
  • Created about 4 years ago
  • Updated over 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Information about three diamond reference implementations.

Diamond Implementations

A diamond implementation implements EIP-2535 Diamonds. These are diamond reference implementations.

Diamonds enable you to build efficient, powerful, flexible, modular contract systems.

Every diamond implementation implements the following:

  1. diamondCut function Standard function used to add/replace/remove functions on a diamond.
  2. Loupe functions Four standard functions used to show what functions and facets a diamond has.

There are three diamond reference/example implementations that have different benefits and disadvantages in terms of code complexity and gas costs. Here is a breakdown of the differences between the three implementations. The ratings (high, medium, low) are in relation to each other.

Implementation diamondCut
complexity
diamondCut
gas cost
loupe
complexity
loupe
gas cost
diamond-1 low medium medium high
diamond-2 high low high high
diamond-3 medium high low low

It is possible to choose one implementation and then in the future upgrade the diamond to switch to a different implementation.

All three implementations pass the same tests.

diamond-1 and diamond-2 use less gas to add/replace/remove functions.

diamond-3 uses less gas to call the diamond loupe functions.

diamond-1 and diamond-2 are implemented the same way except that diamond-2 is gas optimized. To understand how diamond-2 is implemented look at diamond-1 first.

Diamond Repositories

Links to diamond reference implementation repositories:

How diamond-1 is implemented

  1. Has an bytes4[] selectors array that stores the function selectors of a diamond.
  2. Has a mapping(bytes4 => FacetAddressAndSelectorPosition) facetAddressAndSelectorPosition mapping that maps each function selector to its facet address and its position in the selectors array.

It's facets, facetFunctionSelectors, facetAddresses loupe functions should not be called in on-chain transactions because their gas cost is too high. These functions should be called by off-chain software.

The facetAddress loupe function has a low fixed gas cost in all implementations and can be called in on-chain transactions.

How diamond-2 is implemented

diamond-2 is implemented the same way as diamond-1 except that the selectors array is implemented as a mapping of 32-byte storage slots and uses various gas-optimizations to reduce storage reads and writes.

This implementation is gas-optimized for adding/replacing/removing functions on a diamond.

It's facets, facetFunctionSelectors, facetAddresses loupe functions should not be called in on-chain transactions because their gas cost is too high. These functions should be called by off-chain software.

The facetAddress loupe function has a low gas cost in all implementations and can be called in on-chain transactions.

How diamond-3 is implemented

  1. Has an address[] facetAddresses array that stores the facet addresses of a diamond.

  2. Has a mapping(address => FacetFunctionSelectors) facetFunctionSelectors mapping that maps each facet address to its array of function selectors and its position in the facetAddresses array.

  3. Has a mapping(bytes4 => FacetAddressAndPosition) selectorToFacetAndPosition mapping that maps each function selector to its facet address and its position in the facetFunctionSelectors[facetAddress].functionSelectors array.

The standard loupe functions facets, facetFunctionSelectors, facetAddresses CAN be called in on-chain transactions. Note that if a diamond has a great many functions and/or facets these functions may still cause an out-of-gas error.

The facetAddress loupe function has a low fixed gas cost in all implementations and can be called in on-chain transactions.

More Repositories

1

awesome-diamonds

A curated list of awesome EIP2535 Diamonds resources, libraries, tools, articles and more
341
star
2

diamond-3

EIP-2535 Diamonds reference implementation.
Solidity
254
star
3

diamond-3-hardhat

EIP-2535 Diamond reference implementation using Hardhat and Solidity 0.8.*
Solidity
234
star
4

diamond-1-hardhat

EIP-2535 Diamond reference implementation using Hardhat and Solidity 0.8.*
Solidity
130
star
5

runcss

A utility-first CSS runtime for rapid UI development.
TypeScript
108
star
6

diamond-2-hardhat

Gas-optimized EIP-2535 Diamond reference implementation using Hardhat and Solidity 0.8.*
Solidity
92
star
7

webscript

Webscript is a Javascript library for creating DOM elements. Use it to create web applications. It is like HTML but it is Javascript. It is designed to work with existing libraries.
JavaScript
86
star
8

diamond-1

EIP-2535 Diamonds reference implementation.
Solidity
30
star
9

diamond-2

Gas-optimized EIP-2535 Diamonds reference implementation.
Solidity
27
star
10

quickswap

Decentralized trading protocol on Matic Network.
Solidity
19
star
11

transparent-contracts-erc1538

Reference implementation of ERC1538
JavaScript
17
star
12

diamond-foundry

A reference implementation of EIP2535 Diamonds using Foundry
Solidity
12
star
13

emoji-token

💎 Token
Solidity
10
star
14

governance-token-diamond

An ERC20 governance token diamond that can be used to govern a project as well as itself.
Solidity
10
star
15

diamond-util

Javascript library for deploying and upgrading diamonds.
JavaScript
8
star
16

contracts-starter

Template for starting smart contract repos
JavaScript
8
star
17

diamond-docs

Documentation for EIP2535 Diamonds
Python
6
star
18

mokens-bug-bounty

Bug Bounty Program for Mokens Contract
6
star
19

ethers-ledger

TypeScript
5
star
20

jobboard

Clojure
5
star
21

erc998.org

Website for ERC998
HTML
4
star
22

personal-diamonds

Personal diamond
4
star
23

Telecommute-Job-Board

Free Job Board for telecommute technology jobs.
Ruby
3
star
24

ethereum-to-matic

Bridging ERC20 tokens from Ethereum to Matic Network
Solidity
3
star
25

quickswap-contracts

Solidity
3
star
26

deno-postcss

Port of postcss to deno.
JavaScript
2
star
27

SimpleCache

A Simple PHP Caching System
PHP
2
star
28

viv

Library for creating web applications in the browser.
JavaScript
2
star
29

denotailcss

Port of Tailwind CSS to deno.
JavaScript
1
star
30

hardhat-fork-test

Testing hardhat forks
JavaScript
1
star
31

matic-uniswap

Uniswap on Matic Network
1
star
32

quickswap-snapshot

Solidity
1
star
33

ideas

Some ideas
1
star
34

personal-diamonds-client

JavaScript
1
star