Liquidate the Loans!
Installation
- Navigate to the target directory in the terminal and run the following command
https://github.com/atrivedi1/get_liquidatable_loan_algo.git
- In the
getLiqidatableLoans
folder, run:
npm install
npm run test
Implementation
As it pertains to my v1 implementation of the getLiquidatableLoans
function, there are a few things worth calling out:
- I assumed that the data provided was merely sample data, and that the implementation of
getLiquidatableLoans
would ultimately need to handle:
- Much larger data sets
- Defaulted Loans
-
I assumed that the data in the
loans.json
andeth-prices.json
files would always be sorted in decesending order. -
Given #1 and #2, I decided to leverage a binary search algorithm twice in my implementation: first, to identify the price of ETH at a given point in time; and second, to determine which loans, if any, are in default (based on the given time)
Test
To validate my implementation I added an additional loan object to the end of loans.json
with a filledAt
value ~90 days before the first timestamp in eth-prices.json
and created the following tests:
-
Confirm that the
getLiquidatableLoans
function returns an array of length 7 with the given sample input: 1558650159442 -
Confirm that the
getLiquidatableLoans
function returns an array of length 8 when the given time input is equal to the FIRST timestamp in theeth-prices.json
file - meaning that the result should include a defaulted loan -
Confirm that the
getLiquidatableLoans
function returns an array of length 7 when the given time input is equal to the LAST timestamp in the that thegetLiquidatableLoans
function returns an array of length 7 file (to ensure that the binary search functionality works at the extremes of the provided dataset) -
Confirm that that the
getLiquidatableLoans
function returns an empty array when the given time input is OUTSIDE of the date range in theeth-prices.json
file.
Outstanding Items
If I had more time, I would refector my binary search implementation to address:
-
Readability - for v1, I abstracted out the binary search logic such that I can leverage it to both find defaulted loans AND the price of ETH at a given point in time. However in doing so, the code is a little harder to reason about.
-
Conciseness - Right now I have some verbose MVP logic to handle edge cases (see note on line 84 of
getLiquidatableLoans/main.js
).