createStakingPool: Restricted to STAKING_MANAGER_ROLE, allows creating a new staking pool.
removeStakingPool: Restricted to STAKING_MANAGER_ROLE, allows removing a staking pool.
stakeTokens: Restricted to USER_ROLE, allows users to stake their tokens in a staking pool.
unstakeTokens: Restricted to USER_ROLE, allows users to unstake their tokens from a staking pool.
getStakingPoolInfo: Allows querying information about a specific staking pool.
AdminControl
Inherits from AccessControl contract.
Defines roles: DEFAULT_ADMIN_ROLE.
Functions:
addAdmin: Restricted to DEFAULT_ADMIN_ROLE, allows adding new administrators.
removeAdmin: Restricted to DEFAULT_ADMIN_ROLE, allows removing administrators.
banUser: Restricted to DEFAULT_ADMIN_ROLE, allows banning a user from the platform.
unbanUser: Restricted to DEFAULT_ADMIN_ROLE, allows unbanning a user from the platform.
setFees: Restricted to DEFAULT_ADMIN_ROLE, allows setting fees for various platform operations.
withdrawFees: Restricted to DEFAULT_ADMIN_ROLE, allows withdrawing accumulated fees from the contract.
AccessControl
This contract is inherited from the OpenZeppelin AccessControl contract.
Responsible for managing roles and permissions across the other contracts.
Provides functions like grantRole, revokeRole, and access control modifiers like onlyRole.
In this design, each contract inherits from the AccessControl contract and defines the necessary roles for its functionality. The AdminControl contract manages the DEFAULT_ADMIN_ROLE and provides functions for administrative tasks like adding/removing admins, banning users, and managing fees.
The other contracts define roles specific to their functionality, such as ASSET_MANAGER_ROLE, LIQUIDITY_MANAGER_ROLE, and STAKING_MANAGER_ROLE. These roles can be granted or revoked by the administrators, allowing for granular control over who can perform certain actions on the platform.
The UserRegistry contract manages user registration and assigns the USER_ROLE to registered users, allowing them to access user-specific functions like swapping tokens, adding liquidity, and staking tokens.
This design follows the principle of least privilege, where each role has the minimum required permissions to perform its intended actions. It also separates concerns by splitting functionality across multiple contracts, making the codebase more modular and easier to maintain.
https://docs.openzeppelin.com/contracts/5.x/access-control
UserRegistry
AccessControl
contract.DEFAULT_ADMIN_ROLE
,USER_ROLE
.getRegisteredUserIds
: Restricted toDEFAULT_ADMIN_ROLE
, returns an array of user IDs of all registered users.registerUser
: Restricted toDEFAULT_ADMIN_ROLE
, allows registering new users and assigning unique IDs.isRegisteredUser
: Checks if an address is a registered user.getUserId
: Returns the user ID for a given address.AssetManager (ex TokenManager)
AccessControl
contract.DEFAULT_ADMIN_ROLE
,ASSET_MANAGER_ROLE
.addAsset
: Restricted toASSET_MANAGER_ROLE
, allows adding new assets to the platform.removeAsset
: Restricted toASSET_MANAGER_ROLE
, allows removing assets from the platform.getAssetInfo
: Allows querying information about a specific asset.Exchange
AccessControl
contract.DEFAULT_ADMIN_ROLE
,USER_ROLE
.swapTokens
: Restricted toUSER_ROLE
, allows swapping tokens between users.addLiquidity
: Restricted toUSER_ROLE
, allows adding liquidity to a liquidity pool.removeLiquidity
: Restricted toUSER_ROLE
, allows removing liquidity from a liquidity pool.LiquidityPool
AccessControl
contract.DEFAULT_ADMIN_ROLE
,LIQUIDITY_MANAGER_ROLE
.createPool
: Restricted toLIQUIDITY_MANAGER_ROLE
, allows creating a new liquidity pool.removePool
: Restricted toLIQUIDITY_MANAGER_ROLE
, allows removing a liquidity pool.getPoolInfo
: Allows querying information about a specific liquidity pool.StakingPool
AccessControl
contract.DEFAULT_ADMIN_ROLE
,STAKING_MANAGER_ROLE
.createStakingPool
: Restricted toSTAKING_MANAGER_ROLE
, allows creating a new staking pool.removeStakingPool
: Restricted toSTAKING_MANAGER_ROLE
, allows removing a staking pool.stakeTokens
: Restricted toUSER_ROLE
, allows users to stake their tokens in a staking pool.unstakeTokens
: Restricted toUSER_ROLE
, allows users to unstake their tokens from a staking pool.getStakingPoolInfo
: Allows querying information about a specific staking pool.AdminControl
AccessControl
contract.DEFAULT_ADMIN_ROLE
.addAdmin
: Restricted toDEFAULT_ADMIN_ROLE
, allows adding new administrators.removeAdmin
: Restricted toDEFAULT_ADMIN_ROLE
, allows removing administrators.banUser
: Restricted toDEFAULT_ADMIN_ROLE
, allows banning a user from the platform.unbanUser
: Restricted toDEFAULT_ADMIN_ROLE
, allows unbanning a user from the platform.setFees
: Restricted toDEFAULT_ADMIN_ROLE
, allows setting fees for various platform operations.withdrawFees
: Restricted toDEFAULT_ADMIN_ROLE
, allows withdrawing accumulated fees from the contract.AccessControl
AccessControl
contract.grantRole
,revokeRole
, and access control modifiers likeonlyRole
.In this design, each contract inherits from the
AccessControl
contract and defines the necessary roles for its functionality. TheAdminControl
contract manages theDEFAULT_ADMIN_ROLE
and provides functions for administrative tasks like adding/removing admins, banning users, and managing fees.The other contracts define roles specific to their functionality, such as
ASSET_MANAGER_ROLE
,LIQUIDITY_MANAGER_ROLE
, andSTAKING_MANAGER_ROLE
. These roles can be granted or revoked by the administrators, allowing for granular control over who can perform certain actions on the platform.The
UserRegistry
contract manages user registration and assigns theUSER_ROLE
to registered users, allowing them to access user-specific functions like swapping tokens, adding liquidity, and staking tokens.This design follows the principle of least privilege, where each role has the minimum required permissions to perform its intended actions. It also separates concerns by splitting functionality across multiple contracts, making the codebase more modular and easier to maintain.