Skip to content

Instantly share code, notes, and snippets.

@buendiadas
Last active March 11, 2021 19:11
Show Gist options
  • Save buendiadas/7b1d522705144a9c0b134ce91d1740db to your computer and use it in GitHub Desktop.
Save buendiadas/7b1d522705144a9c0b134ce91d1740db to your computer and use it in GitHub Desktop.
borrowing solution examples

Given the integrations above, the following example shows how we could manag

Solution 1: Collateral and debt positions registered as a single asset

  • Collateralized assets and debt could be modeled as a single asset (CDP)
  • The CDP value would be calculated as: CDP_VALUE = Σ COLLATERAL_ASSET_VALUE - DEBT
  • With this new implementation, GAV would be calculated as: GAV_NEXT = GAV_CURRENT + Σ CDP, where current and next represent the current and next release.

Solution 2: Collateral and debt positions registered as different assets

  • In a CDP collateralized assets and debt don't necessarily need to be in modeled as a single asset
  • Instead, in most of the cases it makes more sense to just split lending positions, which also accrue interest (cTokens) from debt positions.
  • With this new implementation, GAV would be calculated as: GAV_NEXT = GAV_CURRENT * ΣlendingPositions - Σ debtPositions, where current and next represent the current and next release.

Examples

Let's see how the previous solutions would work on a real example:

  • Portfolio_before: { ETH: $1500, DAI: 0, CDPs: {} }
  • Action: Borrow $1000 DAI using $1500 ETH as collateral.

Solution 1

With solution 1, we would first calculate the total value of the CDP = $1500 * (1 + lending interest) - $1000 * (1 + borrow interest). From the protocol point of view we would "trade" $1500 usd for that CDP, so GAV after purchasing could be calculated as follows:

  • Portfolio_after: { ETH: 0, DAI: $1000, CDPs: {cdp_ref: $500} }
GAV_BEFORE = ETH_VALUE = $1500
CDP_VALUE (t = t0) =  COLLATERAL * (1 + lendingInterestPerSecond * (t - t0)) - DEBT * (1 + borrowInterestPerSecond * (t - t0) = COLLATERAL - DEBT = $1500 - $1000 = $500
GAV_AFTER = $1000 DAI + $500 CDP = $1500

Solution 2

From the protocol point of view we would first "trade" $1500 usd for a $1500 lending position, we would then "trade" a "-$1000" debt position for $1000 DAI.

  • Portfolio_after: { ETH: 0, DAI: $1000, CETH: $1500, DEBT: { DAI: -$1000 } }
GAV_BEFORE = ETH_VALUE = $1500
GAV_AFTER = $1000 DAI + $1500 CETH + (-$1000) = $1500

Conclusions

  • Solution 1 is probably closer to the way Maker CDPs work
  • However, modeling those assets as a pack is less flexible
  • I can also be incompatible with previously included lending protocols. For example, on Compound or Aave, we would have to remove value from the cTokens already lent, to include that value into the CDP.
  • Solution 2, however seems to be flexible enough to any solution, as it is only adding negative values to the GAV. A Maker CDP could be modeled as a lending position (collateral) with 0% lending interest, and a borrowing position (dai drawed) at e.g 4.5% borrowing interest.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment