JustLend Protocol is an TRON smart contract protocol for supplying or borrowing assets. Through the jToken contracts, accounts on the TRON blockchain supply capital (TRX or TRC20 tokens) to receive jTokens or borrow assets from the protocol (holding other assets as collateral). The JustLend jToken contracts track these balances and algorithmically set interest rates for borrowers.
Before getting started with this repo, please read:
For questions about interacting with JustLend, please visit our Telegram Group.
We detail a few of the core contracts in the Justlend protocol.
- CToken, CErc20 and CEther
- The Justlend jTokens which are self-contained borrowing and lending contracts, are deployed from the code of CToken and CEther contracts. CToken contains the core logic and CErc20 and CEther add public interfaces for TRC20 tokens and TRX, respectively. Each jToken is assigned an interest rate and risk model (see InterestRateModel and Comptroller parts), and allows accounts to mint (supply capital), redeem (withdraw capital), borrow and repay a borrow. Each jToken is an TRC20 compliant token where balances represent ownership of the market.
- Comptroller
- The risk model contract, which validates permissible user actions and disallows actions if they do not fit certain risk parameters. For instance, the Comptroller enforces that each borrowing user must maintain a sufficient collateral balance across all cTokens.
- GovernorAlpha (Deprecated)
- Old governance contract. The administrator of the Justlend timelock contract. Holders of JST token may create and vote on proposals which will be queued into the Justlend timelock and then have effects on Justlend jToken and Comptroller contracts.
- GovernorBravo
- The current used governance contract. The administrator of the Justlend timelock contract. Holders of JST token may create and vote on proposals which will be queued into the Justlend timelock and then have effects on Justlend jToken and Comptroller contracts.
- InterestRateModel
- Contracts which define interest rate models. These models algorithmically determine interest rates based on the current utilization of a given market (that is, how much of the supplied assets are liquid versus borrowed).
- ErrorReporter
- Library for tracking error codes and failure conditions.
- Exponential
- Library for handling fixed-point decimal numbers.
- WhitePaperInterestRateModel
- Initial interest rate model, as defined in the Whitepaper. This contract accepts a base rate and slope parameter in its constructor.
- Careful Math
- Library for safe math operations.
- SafeToken
- Library for safely handling Trc20 interaction.
TronBox is being used in this project. Before getting started with the deployment script, please read:
To get started, first create and initialize a NodeJS 8.0+ environment. Next, clone the repo and install the developer dependencies:
npm i
- Linux
- Mac OS X
Run this by using tronbox embedded solc:
tronbox compile
Or you may want to use external compilers. You can get the compiler from here
And rename the compiler executable file to solc512
, then compile the contracts with these commands.
./solc512 --allow-paths $YOUR_PATH/justlend-protocol/, --bin --abi --optimize $YOUR_PATH/justlend-protocol/Unitroller.sol
./solc512 --allow-paths $YOUR_PATH/justlend-protocol/, --bin --abi --optimize $YOUR_PATH/justlend-protocol/Comptroller.sol
./solc512 --allow-paths $YOUR_PATH/justlend-protocol/, --bin --abi --optimize $YOUR_PATH/justlend-protocol/Governance/WJST.sol
./solc512 --allow-paths $YOUR_PATH/justlend-protocol/, --bin --abi --optimize $YOUR_PATH/justlend-protocol/Governance/GovernorBravoDelegator.sol
./solc512 --allow-paths $YOUR_PATH/justlend-protocol/, --bin --abi --optimize $YOUR_PATH/justlend-protocol/Timelock.sol
./solc512 --allow-paths $YOUR_PATH/justlend-protocol/, --bin --abi --optimize $YOUR_PATH/justlend-protocol/JumpRateModelV2.sol
./solc512 --allow-paths $YOUR_PATH/justlend-protocol/, --bin --abi --optimize $YOUR_PATH/justlend-protocol/WhitePaperInterestRateModel.sol
./solc512 --allow-paths $YOUR_PATH/justlend-protocol/, --bin --abi --optimize $YOUR_PATH/justlend-protocol/CEther.sol
./solc512 --allow-paths $YOUR_PATH/justlend-protocol/, --bin --abi --optimize $YOUR_PATH/justlend-protocol/CErc20Delegate.sol
./solc512 --allow-paths $YOUR_PATH/justlend-protocol/, --bin --abi --optimize $YOUR_PATH/justlend-protocol/CErc20Delegator.sol
./solc512 --allow-paths $YOUR_PATH/justlend-protocol/, --bin --abi --optimize $YOUR_PATH/justlend-protocol/PriceOracle/PriceOracle.sol
./solc512 --allow-paths $YOUR_PATH/justlend-protocol/, --bin --abi --optimize $YOUR_PATH/justlend-protocol/PriceOracleProxy.sol
./solc512 --allow-paths $YOUR_PATH/justlend-protocol/, --bin --abi --optimize $YOUR_PATH/justlend-protocol/PriceOracle/PriceOracle.sol
./solc512 --allow-paths $YOUR_PATH/justlend-protocol/, --bin --abi --optimize $YOUR_PATH/justlend-protocol/PriceOracleProxy.sol
./solc512 --allow-paths $YOUR_PATH/justlend-protocol/, --bin --abi --optimize $YOUR_PATH/justlend-protocol/Lens/CompoundLens.sol
Before use, sample-env
should be renamed to .env
with the added network config:
PRIVATE_KEY_NILE=YOUR_PRIVATE_KEY
RESERVER_ADMIN=YOUR_RESERVE_ADMIN_ADMIN_ADDRESS
ADMIN=YOUR_ADMIN_ADDRESS
Assuming all contracts haven't been deployed, the user must deploy the script one by one individually by replacing xx
with the correct number of the file and then record the contract addresses and data to ../data/test-xxx.json
. Please feel free to modify the migrations
and contract data.
tronbox migrate --network nile -f xx --to xx
For example, if you want to run 3_deploy_comptroller.js
, the command will be tronbox migrate --network nile -f 3 --to 3
.
Due to the limitation of Tronbox, Governor.setTimelock()
is unable to be invoked among the migration script. Therefore, the related script is inside script/2_setTimelock.js
. Please run it for setting up the timelock address from Governor.
The sample of contract invokers is inside the script
folder.
For any concerns with the protocol, open an issue or visit us on Telegram to discuss.
For security concerns, please email [email protected].
_© Copyright 2022 JustLend DAO