tropykus is an algorithmic distributed protocol deployed on the RSK network. As such, it's main motivation is to allow users to lend crypto currencies as collateral and to borrow crypto assets based on interest rates set by real-time supply and demand smart contracts. The tropykus Protocol is developed using RSK smart contracts for supplying or borrowing assets. Through the cToken contracts, accounts on the blockchain supply capital (rBTC or ERC-20 tokens) to receive cTokens or borrow assets from the protocol (holding other assets as collateral). The tropykus cToken contracts track these balances and algorithmically set interest rates for borrowers.
You can read the protocol documentation at Gitbook
We detail a few of the core contracts in the tropykus protocol.
- CToken, CErc20 and CRBTC
- The tropykus cTokens, which are self-contained borrowing and lending contracts. CToken contains the core logic and CErc20 and CRBTC add public interfaces for Erc20 tokens and rBTC, respectively. Each CToken is assigned an interest rate and risk model (see InterestRateModel and Comptroller sections), and allows accounts to *mint* (supply capital), *redeem* (withdraw capital), *borrow* and *repay a borrow*. Each CToken is an ERC-20 compliant token where balances represent ownership of the market.
- Price Oracle Proxy
- This contract controls the adapters that link the protocol with price oracles.
- 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.
- TROP
- The tropykus Governance Token (TROP). Holders of this token have the ability to govern the protocol via the governor contract. Once the token is **launched**
- Governor Alpha
- The administrator of the tropykus timelock contract. Holders of TROP token may create and vote on proposals which will be queued into the tropykus timelock and then have effects on tropykus cToken and Comptroller contracts. This contract may be replaced in the future with a beta version.
- 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).
- Careful Math
- Library for safe math operations.
- ErrorReporter
- Library for tracking error codes and failure conditions.
- Exponential
- Library for handling fixed-point decimal numbers.
- SafeToken
- Library for safely handling Erc20 interaction.
To run tropykus, pull the repository from GitHub and install its dependencies. You will need yarn or npm installed.
git clone https://github.com/TruStartUp/tropykus-protocol
cd tropykus-protocol
yarn install --lock-file # or `npm install`
The tropykus Protocol has a simple scenario evaluation tool to test and evaluate scenarios which could occur on the blockchain. We inherited this feature from the original source code and this is primarily used for constructing high-level integration tests. The tool also has a REPL to interact with local the tropykus Protocol (similar to truffle console).
yarn repl -n development
yarn repl -n rinkeby
> Read CToken cBAT Address
Command: Read CToken cBAT Address
AddressV<val=0xAD53863b864AE703D31b819d29c14cDA93D7c6a6>
You can read more about the scenario runner in the Scenario Docs on steps for using the repl.
Jest contract tests are defined under the tests directory. To run the tests run:
yarn test
There are additional tests under the spec/scenario folder. These are high-level integration tests based on the scenario runner depicted above. The aim of these tests is to be highly literate and have high coverage in the interaction of contracts.
To run code coverage, run:
yarn coverage
To lint the code, run:
yarn lint
tropykus initially developed and tested on:
-
Operating system: macOS, debian 10 (buster), ubuntu LTS.
-
Node.js(LTS 12)
-
npm (optional)
-
ganache-cli (optional)
-
sol-select(optional)
-
node-gyp(optional)
-
[direnv] (https://direnv.net/)
#ubuntu/debian
sudo apt install g++
#ubuntu/debian
sudo apt-get install make
Recommend for GNU SO. Install build-essential package and node-gyp.
#ubuntu/debian
sudo apt-get install build-essential
npm install -g node-gyp
Also recommend seting git pull to default rebase mode.
#ubuntu/debian
git config --global pull.rebase true
To deploy the contracts we use buidler.
Copy the .envrc.example and rename it to .envrc, change the mnemonic, then use direnv allow on this directory.
Finally run yarn deploy [networkName] to deploy to the selected network
Debug in local ganache-cli with VS Code
#run ganache-cli in a terminal
ganache-cli --gasLimit 20000000 --gasPrice 20000 --defaultBalanceEther 1000000000 --allowUnlimitedContractSize true -v -k "istanbul"
Configure launch.json (VS Code).
In .buil/launch.json (create if is necesary) add the follow:****
{
"version": "0.2.0",
"configurations": [
{
"name": "dev",
"request": "launch",
"type": "node",
"runtimeExecutable": "/usr/bin/npx",
"program": "saddle",
"args": [
"test",
],
},
]
}
The following functions are deprecated and should not be used in new integrations:
- Status: DEPRECATED
- Location:
CToken.sol - Description: This function was intended to be used for the kSAT market only. If used in other markets, it can lead to read errors.
- Recommendation: Do not use this function in new code. Use standard CToken functions instead.
- Status: DEPRECATED
- Location:
CRBTC.sol - Description: This function allows anyone to add rBTC to the subsidy fund without access control. Funds added via this function become part of a shared pool and cannot be directly withdrawn. The subsidy fund is distributed proportionally to suppliers based on their interest earned, meaning users who add subsidies without minting cTokens will lose access to their funds. This can introduce risks to unaware users who may accidentally contribute funds they cannot recover.
- Risk: Users who call this function without understanding its behavior may permanently lose access to their rBTC contributions, as there is no mechanism to directly withdraw from the subsidy fund.
- Recommendation: Do not use this function in new integrations. Use alternative mechanisms for managing protocol subsidies that include proper access control and withdrawal capabilities.
- Status: DEPRECATED
- Location:
CToken.sol - Description: This function calculates interest accrued for an account using the Tropykus interest rate model. This interest rate model was used for the kSAT market, which has been deprecated. The internal accounting mechanisms introduced by this model introduce vulnerabilities and should not be used in new integrations or markets.
- Risk: The internal accounting mechanisms used by this function introduce vulnerabilities that could be exploited. This function is part of a deprecated interest rate model that was only intended for the kSAT market.
- Recommendation: Do not use this function in new code. This function must not be used as it is associated with deprecated and vulnerable accounting mechanisms from the kSAT market.
The following markets have been deprecated or are no longer actively supported:
- Status: DEPRECATED
- Address: 0xd2ec53e8dd00d204d3d9313af5474eb9f5188ef6
- Description: The kSAT (micro rBTC) market was a specialized market with unique snapshot functionality. This market is no longer actively maintained or supported as well as the Hurricane Interest Rate Model.
- Note: The
getSupplierSnapshotStoredfunction was specifically designed for this market and should not be used with other markets.
- Status: DEPRECATED
- Address: 0xedaefc6b596ed38d712100976969975a37c84464
- Description: The legacy kUSDT market was deprecated due to potential vulnerabilities that could be exploited with its integration.
- Status: DEPRECATED
- Address: 0x3134b7fbfca5db217eca523eab1941452cf35163
- Description: The kRIF market was deprecated due to potential vulnerabilities that could be exploited with its integration.
Important: When integrating with the tropykus Protocol, avoid using deprecated functions and markets. Always refer to the latest contract interfaces and documentation.
- Status: KNOWN ISSUE
- Location:
ComptrollerG6.sol - Description: The
maxAssetsvariable inComptrollerStorage.solcontrols the maximum number of assets a single account can participate in (borrow or use as collateral). However,ComptrollerG6does not implement a_setMaxAssets()function to update this value, unlike previous Comptroller versions (G1-G5) which had this functionality. - Impact: Once
maxAssetsis set (either during initialization or inherited from a previous Comptroller version), it cannot be changed inComptrollerG6. The real impact is that a large number of listed markets would consume a lot of gas for user operations, as accounts could potentially enter many markets without themaxAssetslimit being adjustable to manage gas costs. This could potentially make the protocol unusable for some users because some operations could exceed the maximum amount of gas allowed in a block, causing transactions to fail. - Workaround: If
maxAssetsneeds to be updated, the protocol would need to upgrade to a new Comptroller implementation that includes the setter function, or ensuremaxAssetsis properly initialized during deployment/upgrade.
All contracts are WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE