Borrowing Aggregator

Loanshark aggregates lending platforms to lower the borrowing cost of users. The protocol continuously monitors interest rates and directs new borrowing to the lender with the lowest expected borrowing rate. When users start a new borrowing position through Loanshark, they will always be borrowing through the approved lenders with the cheapest expected rates.
Several lending platforms exist with adequate liquidity on each blockchain. These protocols are all highly similar and handle mostly the same crypto assets. Their interest rate models only differ slightly in parameters.
Borrowing rate in lending platforms is extremely volatile as it is affected by the utilization ratio. If a large percentage of the pool is borrowed, the interest rate can rise rapidly to discourage further borrowing and encourage repaying. For example, this is a snapshot of the borrowing rates of different assets on the three largest lending platforms in Avalanche.
Table 1: Borrowing rates on different lending protocols in Polygon
Hundred Finance
The borrowing rate for the same asset varies from protocol to protocol. Saving opportunities are created by the interest rate differential between different lending platforms. By taking out a loan from Loanshark, users will always borrow from the lender with the cheapest rate.

Automatic Refinancing

A more advanced function of Loanshark is to refinance debt across protocols and shift funds from one protocol to another for users with a live borrowing position. Refinancing opportunities surge when the borrowing rate of different platform changes relatively. The marginal gain in yield from savings in borrowing rate differential has to be larger than the marginal cost of refinancing to trigger a refinancing action.
Flash loans are one of the tools for refinancing operations within the Loanshark protocol. Flash Loans allow you to borrow any available amount of assets without putting up any collateral, as long as the liquidity is returned to the protocol within one block transaction.
The marginal gain in yield due to the savings in borrowing rate from switching platforms can be described with the following equation:
B=D(eδE[r]t1)\begin{equation} B= D \cdot (e^{\delta E[r] t}-1) \end{equation}
where B = Refinancing benefit, D = Debt , δE[r] = Difference in expected borrowing rate, t = time before next refinancing (in seconds).
Refinancing cost is the sum of transaction cost and the flash loan fee. Refinancing cost can be expressed as shown in Equation 2. This equation assumes operation on the Polygon blockchain.
C=DFL+TGPriceMATIC\begin{equation} C= D \cdot FL+ T \cdot G \cdot Price_{MATIC} \end{equation}
where C = Refinancing cost, D = Debt , FL = Flash Loan Fee, T = transaction gas, G = Gas price, Price_{MATIC} = Price of MATIC(the Polygon blockchain token). Flash loan fee are charged differently by various providers. For example, Aave charges 0.09%.
Refinancing action (through flash loan) only triggers when B > C.