Welcome to the official contract repository for StarkDefi, a decentralized finance (DeFi) project built on the StarkNet network. This repository houses the source code for the smart contracts that power the StarkDefi platform.
The repository is structured into several directories, each with a specific purpose:
-
src: This directory contains the Cairo source code for the StarkDefi contracts. The contracts are organized into modules such as dex for decentralized exchange functionality, token for token-related contracts, and utils for utility functions and contracts. The structure will evolve as the project expands.
-
tests: This directory houses Cairo code for testing the StarkDefi contracts.
-
StarkDFactory: This factory contract is responsible for creating new trading pairs on the StarkDefi platform. You can find the factory contract's Interface here.
-
StarkDPair: This contract represents a liquidity pool for a pair of tokens. You can find the pair contract's source code here.
-
FeeVault: This contract handles fees generated from the pair reserves. You can find it here.
-
StarkDRouter: This contract provides functions for adding and removing liquidity, as well as swapping tokens. You can find the router contract's source code here.
Scarb, a build toolchain and package manager for Cairo and Starknet ecosystems, is used for building and testing the StarkDefi contracts.
A Dockerfile is provided for building the StarkDefi contracts. As of 6th Sept 2023, the Dockerfile uses Scarb v0.6.2. You can use the Dockerfile to build the StarkDefi contracts without installing Scarb on your local machine.
To build the StarkDefi contracts using the Dockerfile, use the following command:
docker build -t starkdefi .
To run the tests, use the following command:
docker run starkdefi test
You can access the Scarb CLI with the following command:
docker run starkdefi scarb <command>
To install Scarb, follow the installation script provided in the Scarb documentation 1. Here is how you can install the latest stable release of Scarb:
curl --proto '=https' --tlsv1.2 -sSf https://docs.swmansion.com/scarb/install.sh | sh
This will install Scarb, the Cairo compiler, and the language server.
To build the StarkDefi contracts, use the following command:
scarb build
GitHub Actions is used for continuous integration. The workflow is specified in the unit-test.yaml file and tests are run on every pull request.
To run the tests directly, use the following command:
scarb test
You can filter the tests using the --filter
flag. For example, to run only tests with pair
in the test name, use the following command:
scarb test --filter pair
StarkDefi uses sncast to deploy the contracts. For more information on how to use sncast, visit the sncast documentation.
The deployment sequence is as follows:
-
Declare the following contracts (order is not important):
StarkDFactory
StarkDPair
FeeVault
StarkDRouter
-
After declaring the contracts, deploy the following 2 contracts in this order:
StarkDFactory
StarkDRouter
Note: Ensure to pass the correct arguments to both StarkDFactory
and StarkDRouter
. The StarkDPair
and FeeVault
contracts are deployed automatically whenever a new pair instance is created.
Contributions to the StarkDefi repository are welcome. Please read the contributing guidelines before making a pull request.
The StarkDefi contracts are released under the MIT License.