Skip to content

xmtp/smart-contracts

XMTP Contracts

⚠️ Experimental: This software is in early development. Expect frequent changes and unresolved issues.

This repository contains all the smart contracts that underpin the XMTP decentralized network.

Contracts documentation can be found here.

Solidity

Usage

The project is built with the Foundry framework, and dependency management is handled using native git submodules.

Additionally, it uses slither for static analysis.

Prerequisites

Install foundry

Install slither

Install node

Install prettier

Optionally, install yarn or any other preferred JS package manager.

Initialize project

Initialize the project dependencies:

yarn install # if using yarn

Initialize foundry:

forge update

Developer tools

The following can be run using npm, yarn and similar JS package managers.

# Forge scripts
build:          Builds the contracts.
test:           Tests the contracts.
clean:          Cleans the forge environment.
coverage:       Shows the test coverage.
gas-report:     Shows the gas costs.
doc:            Serves the project documentation at http://localhost:4000

# Static analysis
slither:        Runs slither static analysis.

# Linters
solhint:        Runs solhint.
solhint-fix:    Runs solhint in fix mode, potentially modifying files.
lint-staged:    Runs linters only on files that are staged in git.

# Formatters
prettier:       Runs prettier in write mode, potentially modifying files.
prettier-check: Runs prettier in check mode.

Scripts

The project includes deploy and upgrade scripts.

Deploying Base Contract

The FeeToken is a singleton with respect to the app chain, regardless of environment, and the FeeToken relies on a single ParameterRegistry. Further, the Factory is also a singleton on each chain as it enables deterministic and consistent addresses across all chains, and it also relies on a single ParameterRegistry. And lastly, the Gateway is also a singleton on each chain as it not only relies on a single ParameterRegistry, but also relays parameters between settlement chain and app chain parameter registries.

Because of this, for each settlement chain, regardless of environment, a set of base contracts must be deployed only once for each settlement chain. This deployment includes the Factory, SettlementChaiParameterRegistry, FeeToken (and MockUnderlyingFeeToken if it is a testnet), and SettlementChainGateway for the settlement chain, and the Factory, AppChainParameterRegistry, and AppChainGateway for the app chain.

These are deployed via:

./dev/deploy-base <CHAIN_NAME>

They are verified via:

./dev/verify-base <CHAIN_NAME> basescan
./dev/verify-base <CHAIN_NAME> blockscout

Deploying Environment Contracts

This deployment includes the PayerRegistry, RateRegistry, NodeRegistry, PayerReportManager, DistributionManager, and DepositSplitter for the settlement chain, and the GroupMessageBroadcaster, IdentityUpdateBroadcaster for the app chain.

These are deployed via:

./dev/deploy <ENVIRONMENT> settlement-chain
./dev/deploy <ENVIRONMENT> app-chain

They are verified via:

./dev/verify <ENVIRONMENT> settlement-chain basescan
./dev/verify <ENVIRONMENT> settlement-chain blockscout
./dev/verify <ENVIRONMENT> app-chain alchemy

The starting parameters are defined via:

./dev/set-starting-parameters <ENVIRONMENT>

They are bridged via:

./dev/bridge-starting-parameters <ENVIRONMENT>

The parameters are applied at each contract via:

./dev/update-starting-parameters <ENVIRONMENT> settlement-chain
./dev/update-starting-parameters <ENVIRONMENT> app-chain

About

XMTP Smart Contracts

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Packages

 
 
 

Contributors 5