Skip to content

Instantly share code, notes, and snippets.

@larry0x
Created August 19, 2021 19:28
Show Gist options
  • Save larry0x/300534035b097d79f71b2aa2d017b335 to your computer and use it in GitHub Desktop.
Save larry0x/300534035b097d79f71b2aa2d017b335 to your computer and use it in GitHub Desktop.
const MONTHLY_PAYMENT = 558;
const BORROW_APR = 0.2607;
const REWARD_APR = 0.446;
const TARGET_LTV = 0.3;
const ETH_STAKING_APR = 0.0483;
let collateral = 100000;
let debt = 30000;
let cost = 0;
for (let month = 1; debt > 0; month++) {
const interest = (debt * BORROW_APR) / 12;
const reward = (debt * REWARD_APR) / 12;
debt += interest - reward;
if (debt > MONTHLY_PAYMENT) {
cost += MONTHLY_PAYMENT;
debt -= MONTHLY_PAYMENT;
} else {
cost += debt;
debt = 0;
}
cost += (collateral * ETH_STAKING_APR) / 12;
collateral = debt / TARGET_LTV;
console.log(
`month ${month},`,
`debt: $${debt.toFixed(2)},`,
`cost: $${cost.toFixed(2)}`
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment