Skip to main content

Reusable Logic

You might be wondering: How can I create a new project without deploying new smart contracts?

The answer lies in Compose's smart contract architecture, which is based on diamond contracts.

Understanding Reusability

A diamond contract is a simple, small proxy contract that delegates to the code of other on-chain contracts called facets. Each diamond uses the code of other contracts (facets) to execute logic and maintain its storage data.

When you use Compose, you do deploy a new contract, this small contract is called a diamond.

What You're NOT Deploying

When you create a new diamond, you avoid redeploying:

  • Existing standard functionality such as
    • ERC20Facet
    • ERC20PermitFacet
    • ERC721Facet
    • OwnerFacet
    • AccessControlFacet
    • etc.

Instead, you deploy:

  • A lightweight diamond contract
  • Your unique initialization data (name, symbol, supply)
  • Configuration linking to existing facet addresses

Example

Suppose you want to create a new ERC-20 token that supports gasless approvals (permit) and cross-chain bridging.

With Compose, you:

  1. Select existing facets: ERC20Facet, ERC20PermitFacet, and ERC20BridgeableFacet are already deployed on-chain
  2. Provide initialization data: your token's name, symbol, and total supply
  3. Deploy your diamond: a small proxy contract that references the facet addresses and logic

The Power of Reusability

One facet, thousands of projects:

If 1,000 projects use the same ERC20Facet:

  • That's 999 deployments saved
  • Millions in gas costs avoided
  • 1,000 projects benefit from the same audited, battle-tested code
Key Insight

Many diamond contracts can be deployed that reuse the same on-chain facets.

Key Insight

Each diamond manages its own storage data by using the code from facets.

Benefits of Reusable Facets

  1. Lower Deployment Costs: Deploy only a small proxy instead of thousands of lines of logic
  2. Shared Security Audits: When a facet is audited, all diamonds using it benefit
  3. Consistent Behavior: Same code means same behavior across all implementations