@fibswap-dex/fibswap-contracts
TypeScript icon, indicating that this package has built-in type declarations

0.1.8 • Public • Published

Fibswap Contracts

System Overview

TLDR

Development

Building

First, install and build all the packages from the root:

fibswap$ yarn && yarn build:all

Then, if you are only making updates to the contracts package, rebuild by running:

fibswap$ yarn workspace @fibswap-dex/fibswap-contracts build

Running the tests

This repository uses foundry for unit tests and hardhat for integration tests.

To run the contract tests, run the appropriate command:

$ yarn workspace @fibswap-dex/fibswap-contracts test:forge # runs unit tests
$ yarn workspace @fibswap-dex/fibswap-contracts test:hardhat # runs integration tests
$ yarn workspace @fibswap-dex/fibswap-contracts test # runs both tests

Running the hardhat tests will output the gas estimates for the integration tests. You can generate a coverage output as well, but as it is not supported by foundry it is not considered to be accurate.

To run the coverage tests, run the following from the root directory:

fibswap$ yarn workspace @fibswap-dex/fibswap-contracts coverage

Contract Deployment

Contracts are deployed via the hardhat deploy. Before deploying any contracts, make sure the deploy script used is up to date with the contracts you will need deployed.

To deploy the contracts:

  1. Obtain a funded mnemonic and provider url (if there is no URL in the default hardhat config) for the network(s) you would like to deploy the contracts to. The mnemonic chosen will be a system admin, who can remove or add routers and assets so make sure to keep it handy. You may also add an api key for etherscan if you plan to verify the contracts:
export MNEMONIC="<YOUR_MNEMONIC_HERE>"
export ETH_PROVIDER_URL="<YOUR_PROVIDER_URL_HERE>"
export ETHERSCAN_API_KEY="<ETHERSCAN_API_KEY_HERE>" # optional, but highly recommended

You can also add a .env to the packages/contracts dir with the above env vars.

  1. Once the proper environment variables are added to your environment, you can begin the contract deployments by running the following from the root directory:
yarn workspace @fibswap-dex/fibswap-contracts hardhat deploy --network \<NETWORK_NAME\> # e.g. yarn workspace @fibswap-dex/fibswap-contracts deploy --network goerli

You should use the NETWORK_NAME that corresponds to the correct network within the hardhat.config.ts file.

NOTE: You will have to run the enroll-remote task if deploying custom bridge routers.

  1. After the contracts are deployed, you must enroll the remote handlers. This is done so the handlers know to accept messages from each other across chains:
yarn workspace @fibswap-dex/fibswap-contracts hardhat enroll-handler --handler \<REMOTE_HANDLER_ADDR\> --chain \<REMOTE_CHAIN_ID\> --network \<NETWORK_NAME\>

NOTE: This step should be removed from the process once the router responsibility is handed to the nomad team.

  1. (optional) To verify the contracts (works with Etherscan-based networks):
yarn workspace @fibswap-dex/fibswap-contracts hardhat etherscan-verify --solc-input --network \<NETWORK_NAME\>
  1. Once the contracts have been deployed, export them using:
yarn workspace @fibswap-dex/fibswap-contracts export

Congratulations! You have deployed the contracts. To configure them properly, see the Amarok Tasks below.

NOTE: Once you have deployed the contracts, you will then need to update (if necessary) and redeploy the subgraphs. See here for details.

Helper Tasks

There are helper tasks defined in the ./src/tasks directory. These can be run using the following example command structure:

yarn workspace @fibswap-dex/fibswap-contracts hardhat add-liquidity --network goerli --amount 2500000000000000000000000 --router 0xDc150c5Db2cD1d1d8e505F824aBd90aEF887caC6 --asset-id 0x8a1Cad3703E0beAe0e0237369B4fcD04228d1682
  • Deploy Router Factory
yarn workspace @fibswap-dex/fibswap-contracts hardhat deploy-router-factory --network <Network-Name> --signer <Router Signer> --recipient <Router Recipient>
  • Create Router Contract
yarn workspace @fibswap-dex/fibswap-contracts hardhat create-router --network <Network-Name> --signer <Router Signer> --recipient <Router Recipient>
  • whitelist command for multiple networks
yarn workspace @fibswap-dex/fibswap-contracts whitelist <router-address>
  • create-router for RouterContract multiple network in one-step
yarn workspace @fibswap-dex/fibswap-contracts create-router <signer-address> <recipient-address>

Dependencies (10)

Dev Dependencies (29)

Package Sidebar

Install

npm i @fibswap-dex/fibswap-contracts

Weekly Downloads

0

Version

0.1.8

License

ISC

Unpacked Size

18.8 MB

Total Files

392

Last publish

Collaborators

  • h8090