This repository contains all the smart contracts that underpin the XMTP decentralized network.
Contracts documentation can be found here.
The project is built with the Foundry
framework, and dependency management is handled using native git submodules.
Additionally, it uses slither
for static analysis.
Optionally, install yarn or any other preferred JS package manager.
Initialize the project dependencies:
yarn install # if using yarn
Initialize foundry:
forge update
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.
The project includes deploy and upgrade scripts.
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
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