A dynamic interest rate strategy for SDAI on Spark Protocol using Chainlink Automation.
This project is a set of smart contracts: an interest rate strategy for Spark Protocol and an Upkeep Contract that adjusts this interest rate strategy depending on average utilisation of the reserve of SDAI in Spark Protocol.
The end goal is to have a dynamic interest rate strategy, low utilisation of the reserve means that it is too expensive to borrow, the rate should be lowered to match the market demand. High utilisation indicates that it is very cheap to borrow, the rate should be upped to match market demand. So we use Chainlink Automation to bring a dynamic rate strategy to Spark Protocol for SDAI to start with. The Upkeep Contract (called VariableRateUpdater) periodically caches the utilisation rate, if the average utilisation rate is low it decreases the slope of the variable rate of the interest rate strategy, if it's high and close to optimal it increases the rate. I test them separately and the combination of both, to show that it actually works as intended. And also wrote a script to deploy in production a dynamic interest rate policy for SDAI on Spark using Chainlink Automation. All the steps of unfreezing the reserve, making sDAI borrowable and so on are covered and displayed on a mainnet-fork by impersonating the PoolAdmins of Spark Protocol.
Full Description in the README on GitHub.
I'm using: Spark Protocol SDAI Chainlink Automation eth-brownie solidity
As mentioned earlier there is a set of two smart contracts (and some mock contracts) with tests and a script to put to production.
DynamicRateStrategy: an extension of the DefaultReserveInterestRateStrategy of Spark protocol, with some added variables and authorisations to allow the Upkeep Contract a.k.a VariableRateUpdater to update variableRateSlope1
VariableRateUpdater: a contract that implements AutomationCompatibleInterface, it's an Upkeep Contract that keeps track of the utilisation ratio of SDAI (or any asset) on Spark Protocol, it caches data of the last 30 days with a frequency of 12 hours. And performs an Upkeep every 12 hours, that caches in the latest utilisation ratio and updates variableRateSlope1 of the DynamicRateStrategy.
In the tests we play around with the contracts on their own and together to make sure that the updates to the slope are correct and as intended and there is a script that shows how to deploy this in production for SDAI.
Full description in the README on GitHub.