The smart contract system for the platform has one central contract (Factory) that is able to control: libraries, platforms, assets, fees, and create new Pool contracts. The Pool contract is responsible for all actions on the platform. It is capable of calling external libraries to interact with third-party protocols. The Pool contract also acts as a repository for data and investor funds. Additional libraries that are linked to the Pool contract have the ability to call third-party protocols and perform specified actions directly.
.
├── contracts/ # contracts
├────── interfaces/ # interfaces
├────── lib/ # libraries that have the ability to interact with the main contract
├────── mock/ # mock contracts
├────── FactoryLogic.sol # Factory implementation logic contract
├────── FactoryProxy.sol # Factory proxy contract
├────── PoolLogic.sol # Pool implementation logic contract
├────── PoolProxy.sol # Pool proxy contract
├── scripts/ # scripts for deploy and interaction
├── test/ # test cases
├── README.md # current file
├── .env.sample # example of .env file
├── .gitignore
├── hardhat.config.js # config for deploying or testing on various networks
└── package.json
- node v15.11.0 or higher
- hardhat v2.14.0
- solidity v0.8.19
Setup .env file
INFURA_KEY
- infura api key for upload contracts to test networkRPC_URL
- RPC provider linkPRIVATE_KEY
- private keyETHERSCAN_API_KEY
- etherscan api key for verify contracts
- Install node_modules
npm i
OR
yarn install
- Compile the contracts
npx hardhat compile
- Run the tests
npx hardhat test
- Coverage the contracts
npx hardhat coverage
- Get size of contracts
npx hardhat size-contracts
Main Contracts | Description |
---|---|
FactoryProxy | Factory upgradable proxy contract. |
FactoryLogic | Factory logic implementation used to manage the project and create new Pool contracts. |
PoolProxy | Proxy upgradable proxy contract. |
PoolLogic | Proxy logic implementation used to interact with external libraries, call basic project functions and store all funds and data. |
Library Contracts | Description |
---|---|
FuturesLibrary | Library for Futures functionality. |
LendBorrowLibrary | Library for Venus functionality. |
PoolLibrary | Library includes calculation methods, spot trading logic, and structured products. |
RevertReasonParser | Library for error detection. |
- Create Pool;
- Get params information;
- Get pool information;
- Set libraries;
- Set implementations;
- Manage assets;
- Manage platforms;
createPool
- Function for creating a new Pool contract with specified parameters.setPoolLogic
- only Manager Set different pool logic to use.setDexLibs
- only Manager Set new library for exchange tokens.setVenusLibs
- only Manager Set new Venus library.setUniAddresses
- only Manager Set new Spot trading library.manageLibrariesToWhitelist
- only Manager Add new assets to whitelistedLibraries.manageAssetsToWhitelist
- only Manager Add new assets to whitelistedAssets.managePlatformsToWhitelist
- only Manager Add new platforms to whitelistedAssets.setTreasuryFundAndFee
- only Manager Set new platform fee.setPoolLibrary
- only Manager Set pool library contracts.setHorizonProtocolLib
- only Manager Set structured products library.setLendBorrowLib
- only Manager Set Venus library.setFuturesLib
- only Manager Set Futures library.getRouterAddress
- Get router address.getPools
- Get info about pools.getPoolAddresses
- Get created pool addresses.getWhitelistedAssets
- Get whitelisted assets.getWhitelistedPlatforms
- Get whitelisted platforms.getDexLibraryData
- Get Dex library.getVenusLibraryData
- Get Venus address.getUniAddresses
- Get Spot trading.getHorizonProtocolLib
- Get Structured products librarygetFuturesLib
- Get Futures library.getPoolLibraryAddress
- Get pool library.getLendBorrowLibraryAddress
- Get Venus library.getTreasuryAddressAndFee
- Get fee value.
- Invest;
- Withdraw;
- Get pool info and pool data;
- Manage investors;
- Open/Close pool;
- Use fund for strategies;
- Manage fees;
invest
- Allows user invest funds to pool.withdraw
- Allows user withdraw funds from pool.directCallStrategy
- only Manager Call a contract with the specified data.libraryCall
- only Manager Call library contract with data by delegatecall.enter
- only Manager Enter in Pancakeswap pair.exit
- only Manager Exit from Pancakeswap pair to chosen token.setDirectCallAllowance
- only Manager Set direct call allowance.setPublishStatus
- only Manager Set publish pool status.closePool
- only Manager Close pool for use.setMinInvestmentAmount
- only Manager Sets a minimum amount below which investments cannot be made.setFeeCollectorAndFee
- only Manager sets new fee collector and fee percentage.getFeeCollected
- get amount of fee.checkUnderlyingTokens
- check pairs for pancakeswap.getFactoryAddress
- Get factory address.getFeePercentage
- Get fee percentage.getSupportLiquidityPairs
- get support liquidity pairs.assetsUnderManagement
- The function of calculating all the assets of this pool.poolInfo
- Complete information about the this pool.getInvestors
- get investor addresses.
You should make sure that all settings and ABIs are set up as you need them and the .env
file is created and contains the correct credentials.
To deploy Factory for testnet, you should use the command: npx hardhat run scripts/deploy.js --network TEST_NETWORK_NAME
To deploy Factory for mainnet, you should use the command: npx hardhat run scripts/deploy-bsc.js --network bsc
To create a pool, you should use the command: npx hardhat run scripts/createPoll.js --network NETWORK_NAME
To enter a liq pool, you should use the command: npx hardhat run scripts/enter.js --network bsc
To Invest in a pool, you should use the command: npx hardhat run scripts/invest.js --network bsc
To Withdraw from a pool, you should use the command: npx hardhat run scripts/withdraw.js --network bsc
To Set new pool library, you should use the command: npx hardhat run scripts/setPoolLib.js --network NETWORK_NAME
To deploy the required library you should to modify the script for the specific library you need (an example of a LendBorrowLibrary deployment is provided in the script).
Use the following command to call the script: npx hardhat run scripts/deploy-lib.js --network bsc
Contracts are processed in the following stages:
- Compilation
- Deployment
- Configuration
- Interactions on-chain
To compile the contracts run:
npx hardhat compile
Artifacts are stored in the artifacts
and directory.
For deployment step the following command should be used:
npx hardhat run scripts/deploy.js --network
OR
npx hardhat run scripts/SCRIPT_NAME --network
Addresses of deployed contracts are displayed in terminal.
If you'd like to run tests on the local environment, you might want to run tests using the following command:
npm run test
If you'd like to run tests on the fork node environment, you might want to run tests using the following command:
- Start fork node:
ganache-cli --fork https://bsc-dataseed2.binance.org/
- Uncomment the test called:
PoolFork.test.js
. - Comment (hide) the all other tests.
- Run test:
npx hardhat test --network localhost
- Divide the functionality within PoolLibrary into separate libraries (Spot trading and Structured Products);
- Add support for new libraries (Spot trading and Structured Products) in the
Factory
and be able to add them toPoolLogic
; - Check for new libraries when calling
libraryCall
; - Fix inaccurate way to calculate
getBorrowedPercentage
(logic with additional percentage).PoolLibrary.sol::Line(257-260);
- Add position fee calculation in
FuturesLibrary
. This feature requires a copy of LevelFinance’s_calcPositionFee
function, which has some internal dependencies such asborrowIndex
calculation, which uses the_accrueInterest
function.