Skip to content

tw is thirdweb next iteration of thirdweb solidity smart contracts. Install extensions into core contracts.

Notifications You must be signed in to change notification settings

web3Dai/twcontracts-next

 
 

Repository files navigation



thirdweb Contracts-Next

Next iteration of thirdweb smart contracts. Install extensions in core contracts.


📣 Call for feedback: These contracts are NOT AUDITED. This design update is WIP and we encourage opening an issue with feedback.

Run this repo

Clone the repo:

git clone https://github.com/thirdweb-dev/contracts-next.git

Install dependencies:

forge install && yarn

Run benchmark comparison tests:

forge test --mc Thirdweb # or Manifold / Zora

Usage

You can find testnet deployments of this extensions design setup, and JS scripts to interact with an ERC-721 core contract and its extensions here: https://github.com/thirdweb-dev/contracts-next-scripts

Benchmarks

ERC-721 Core Benchmarks via transactions on Goerli

Action Gas consumption Transaction
Mint 1 token (token ID 0) 145_373 ref
Mint 1 token (token ID >0) 116_173 ref
Mint 10 tokens (including token ID 0) 365_414 ref
Mint 10 tokens (not including token ID 0) 331_214 ref
Transfer token 64_389 ref
Install 1 extension 105_455 ref
Install 5 extensions 191_918 ref
Uninstall 1 extension 43_468 ref
Uninstall 5 extensions 57_839 ref

Note:

  • 'Minting tokens' benchmarks use the AllowlistMintExtension contract as the beforeMint extension. All token minting benchmarks include distributing non-zero primary sale value and platform fee.
  • All extensions used in these benchmarks are minimal clone proxy contracts pointing to extension contract implementations.

ERC-721 Contracts Benchmarks Comparison via transactions on Sepolia

Action Thirdweb (Extensions) Thirdweb Drop Zora Manifold
Deploy (developer-facing) 213_434 tx 719_842 tx 499_968 tx 232_917 tx
Claim 1 token 149_142 tx 196_540 tx 160_447 tx 184_006 tx
Transfer token 59_587 tx 76_102 tx 71_362 tx 69_042 tx
Setup token metadata 60_217 tx 47_528 tx 54_612 tx 29_789 tx

Design Overview

Developers deploy non-upgradeable minimal clones of token core contracts e.g. the ERC-721 Core contract.

  • This contract is initializable, and meant to be used with proxy contracts.
  • Implements the token standard (and the respective token metadata standard).
  • Uses the role based permission model of the Permission contract.
  • Implements the ExtensionInstaller interface.

Core contracts are deliberately written as non-upgradeable foundations that contain minimal code with fixed behaviour. These contracts are meant to be extended by developers using extensions.

Extensions and Modularity

mint tokens via extensions

Extensions are an external call made to a contract that implements the IExtension interface.

The purpose of extensions is to allow developers to extend their contract's functionality by running custom logic right before a token is minted, transferred, burned, or approved, or for returning a token's metadata or royalty info.

For example, there is a fixed, defined set of 6 ERC-721 extensions:

  • BeforeMint: called before a token is minted in the ERC721Core.mint call.
  • BeforeTransfer: called before a token is transferred in the ERC721.transferFrom call.
  • BeforeBurn: called before a token is burned in the ERC721.burn call.
  • BeforeApprove: called before the ERC721.approve and ERC721.setApprovalForAll call.
  • Token URI: called when the ERC721Metadata.tokenURI function is called.
  • Royalty: called when the ERC2981.royaltyInfo function is called.

Developers can install extensions into their core contracts, and uninstall extensions at any time. On installation, a extension contract tells the extension consumer which extension functions it implements -- the extension consumer maps all these extension functions to the mentioned extension contract as their implemention.

Upgradeability

beacon upgrade

thirdweb will publish upgradeable, 'shared state' extensions for developers (see src/extensions).

These extension contracts are designed to be used by developers as a shared resource, and are upgradeable by thirdweb. This allows thirdweb to make beacon upgrades to developer contracts using these extensions.

At any point, developers can opt to use any custom, non-thirdweb extensions along with their core contract. Without the involvement on delegateCall based upgradeability, writing extensions should be accessible for more developers, and we expect to form a vibrant extensions ecosystem.

That said, opting out of using extensions where thirdweb has upgrade authority also means that thirdweb will not be able to perform beacon upgrades to those extensions in the event of a security incident.

Feedback

If you have any feedback, please create an issue or reach out to us at support@thirdweb.com.

Authors

License

Apache 2.0

About

tw is thirdweb next iteration of thirdweb solidity smart contracts. Install extensions into core contracts.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Solidity 99.7%
  • TypeScript 0.3%