Skip to content

yushaku/shadow-core

 
 

Repository files navigation

High-Level Summary

This conrtacts implements a decentralized exchange (DEX) with a sophisticated vote-escrowed (ve) tokenomics model. The architecture is heavily inspired by protocols like Shadow and Velodrome, where users lock tokens to gain voting power, and then use that voting power to direct token emissions to different liquidity pools. The primary goal is to incentivize deep liquidity and long-term token holding.

Core Components

The codebase is well-structured and can be broken down into several core components:

  1. Governance and Voting:
  • AccessHub.sol: This is the central nervous system of the protocol. It acts as the main entry point for administrative functions and manages the addresses of all the other core contracts. It's designed to be the single source of truth for the protocol's configuration.
  • Voter.sol: This is the heart of the governance system. It's where users cast their votes to direct emissions to different liquidity pools (gauges). It also handles the creation of new gauges and the distribution of rewards.
  • VoteModule.sol: This is the staking and delegation module. Users stake their xShadow tokens here to get voting power, which is then used in the Voter contract. It also allows users to delegate their voting power to other addresses.
  1. Tokenomics and Emissions:
  • YSK.sol: This is the base token of the protocol.
  • x33.sol: This is a liquid staking derivative. It allows users to stake their xYSK and receive a liquid XYZ token in return, while the contract auto-compounds the rewards.
  • Minter.sol: This contract is responsible for minting new YSK tokens as emissions, which are then distributed to the gauges based on the votes they receive.
  1. DEX and Liquidity:
  • Router.sol: The main router contract that users interact with to swap tokens.
  • Pair.sol: The contract for the legacy (v2-style) liquidity pools.
  • CL/ directory: This directory contains the contracts for the concentrated liquidity (v3-style) pools, which allow for more capital-efficient liquidity provision.
  • factories/ directory: This directory contains the factory contracts that are responsible for creating new liquidity pools and gauges.
  1. Treasury and Fees:
  • Treasury.sol (ShadowTreasuryHelper): A sophisticated helper contract that manages the protocol's treasury. It automates tasks like staking, voting, claiming rewards, and distributing funds.
  • FeeDistributor.sol: This contract is responsible for distributing the fees collected from swaps to the users who have voted for the corresponding pools.

Architecture and Design Patterns

The codebase employs several modern and robust design patterns:

  • Upgradeable Contracts: The core contracts are designed to be upgradeable, using both the UUPS and Transparent Proxy patterns. This allows the protocol to be improved and patched over time without requiring a full migration.
  • Separation of Concerns: The codebase has a very clear separation of concerns between the different modules. For example, the VoteModule handles the staking logic, while the Voter handles the voting logic. This makes the system more modular, secure, and easier to maintain.
  • Diamond Storage: Some of the contracts use the diamond storage pattern to prevent storage collisions during upgrades. This is a best practice for writing upgradeable contracts.
  • Vote-Escrowed (ve) Model: The entire protocol is built around the ve-tokenomics model, which is designed to align the incentives of all participants, from liquidity providers to token holders.

How It All Fits Together

  1. Users provide liquidity to the DEX by depositing tokens into either a Pair (v2) or a CL (v3) pool.
  2. Users lock their YSK tokens to get xYSK tokens, which they then stake in the VoteModule to get voting power.
  3. Users vote in the Voter contract to direct the flow of YSK emissions from the Minter to their chosen liquidity pools.
  4. Liquidity providers earn YSK emissions as rewards for providing liquidity to the pools that receive the most votes.
  5. Voters earn a share of the fees generated by the pools they vote for.
  6. The AccessHub acts as the central administrator, and the Treasury manages the protocol's assets.

About

Core contract repository for Shadow on Sonic Mainnet

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Solidity 99.7%
  • Other 0.3%