Skip to content

fluencelabs/deal

Repository files navigation

Deal Contracts System

This repo consists of 3 main parts:

  • src - Foundry contracts (read more https://book.getfoundry.sh/). Generally, repo follow structure of Foundry repo.
  • subgraph - javascript client to interact with the graph node, called subgraph (read more https://thegraph.com/docs/quick-start), README
  • ts-client - npm package from contract developers to interact with contracts, more in README
  • integration-tests - npm module to prepare integration tests for Deal contracts flow, more in README

To access to the general points of the each part in the repo root makefile is presented. Below are main commands of the makefile.

| The root package.json consists of dev packages for prettier and code linting via Husky. More about in

Table of contents

Requirements

Full requirements to develop in this repo.

Contract

To work with contracts we use forge (foundry): to deploy, to test unittests. Thus, to work in the repo you first of all should install Foundry: https://book.getfoundry.sh/

To run foundry commands and commands that create artifacts and insert contract artifacts into packages/modules: ts-client, subgraph we use makefile (and we use makefile for even further steps after: to build & deploy those modules after injecting artefacts of contracts into them).

Env

Because scripts and makefile supports env (actually makefile reads env from .env) we note that in the repo we leave .example.env.

Notable Env

Below is the list of env. For description we aim you to .example.env directly.

  • PRIVATE_KEY
  • LOCAL_CHAIN_BLOCK_MINING_INTERVAL
  • MAX_FAILED_RATIO
  • IS_MOCKED_RANDOMX

Makefile

Below is some of useful makefile commands with their descriptions.

To check out all commands and their descriptions run make help.

Install NPM packages

$ make install-npms

Build

Build contracts and deal-ts-clients and subgraph

$ make build-all

Build only contracts

$ make build-contracts

Build only in npm packages

$ make build-npms

Start Local Subgraph

$ make deploy-subgraph-local

Start local network using docker

$ docker compose -f docker/docker-compose.yml up

RPC: http://0.0.0.0:8545

Explorer: http://localhost:4000

Start local network locally

$ make start-local-chain
$ make deploy-contracts-local

Deploy to network

$ PRIVATE_KEY=${} make deploy-{network_name}

Test

  • Contracts
$ forge test
  • TS Clients
cd ts-client && npm test unittests
cd ts-client && npm test integrational-tests

Format

$ forge fmt

Troubleshooting

Error on make <soemthing>: No such file or directory (os error 2); check configured remappings.

git submodule update --init --recursive

Gas Snapshots

$ forge snapshot

Subgraph (Contract Indexer)

It is a backend for the contracts that collects info from contract events into graphQL schemes.

For more info check out README.md.

Development Tricks & Tips

After starting local network you could create market on our contracts:

$ make create-pure-market-local

Development Guide

Lint and Prettier

In the monorepo we use general code style defined in .editorconfig and mirrored in .prettierrc (it is mirrored coz of this issue).

Note, that in repo CI process maintain the prettier check.

Configure Pre Commit Hook

To install pre-commit follow instruction here: https://pre-commit.com/

Setup Deal Infrastructure

TODO: add flow on how to work with already built images from registry.

Let`s suppose you want to boot up local network and subgraph (thus, all deal infrastructure) to develop on the repo locally.

  1. Clone this repo. Clone with submodules, e.g.: git submodule update --init --recursive
2. Start local chain node containers (chain, explorer, deploy script):

```bash
docker compose -f docker/docker-compose.yml up -d --build

| Note, you can omit --build flag if you have already built images locally, nothing to rebuild.

| Note, that chain-deploy-script will produce deployment/local.json file that is used in the next steps.

  1. Prepare npm packages:
make install-npms
make build-npms
  1. Deploy subgraph:
make deploy-subgraph-local
  1. [Optional] Since contracts are fresh and empty you can fill them with test data:
make create-pure-market-local

Tips

  • To stop and cleanup dev environment run:
docker-compose -f docker/docker-compose.yml down --volumes
  • To redeploy contracts:
make deploy-contracts-local

and do not forget to repeat from 3d step (depends on your needs).