Skip to content

cryptexfinance/crypdex

Repository files navigation

crypdex

Index token collateralized as a weighted basket of tokens.

Note

This is a fork of the index coop smart contracts. We've only kept the contracts that we need for this project. We've re-written the tests in foundry for the sake of our understanding and to also show that this not a blind fork.

Testing

After cloning the repository, make sure that all the github modules have been updated

git submodule update --init

To run the tests run:

forge build -o out/
forge test -vvv

To run fork tests

FOUNDRY_PROFILE="fork" forge test -vvv --fork-url https://eth-mainnet.g.alchemy.com/v2/<token>

Smart Contracts

Protocol contracts

  • SetToken: ERC20 token that allows modules to be added to it that can make changes to its positon through the invoke function. It also holds the components of the index token as collateral.
  • SetTokenCreator: Factory contract to create index tokens.
  • PriceOracle: Contract that returns the price for any given asset pair. Price is retrieved either directly from an oracle, calculated using common asset pairs, or uses external data to calculate price.
  • SetValuer: returns the valuation of SetTokens using price oracle data used in contracts.
  • IntegrationRegistry: The IntegrationRegistry holds state relating to the Modules and the integrations they are connected with.
  • Controller: Contract used to add or remove sets, modules, factories, price oracles, and edit protocol fee configurations.

Modules

Modules are contracts that have priviledges to invoke calls to the SetToken.

  • BasicIssuanceModule: Module that is used to issue and redeem set tokens.
  • AuctionRebalanceModuleV1: Module that allows manager to rebalance sets through an auction. Manager are EOA's or multisigs that have priviledges to rebablance sets.
  • StreamingFeeModule: Module that accrues fees for set Manager. It issues set tokens to the manager by diluting the the existing collateral using the position multiplier.

Libraries

The lib directory has miscellaneous libraries that act as helpers for the math, data structures, etc used the smart contracts in this repo.

Interfaces

The interfaces directory has all the interface contracts.

auction-pricing

The auction-pricing has adapeters that are used by AuctionRebalanceModuleV1 module to calculate the price of the components in the auction.

Architecture Diagram

Architecture