Keydonix / liquid-long

The Unlicense
8 stars 1 forks source link

Updates liquid long client library to be able to close positions. #109

Closed MicahZoltu closed 5 years ago

MicahZoltu commented 5 years ago

This change required some contract changes, and I figured I would take the opportunity to make a couple quility of life contract changes while I was at it, since we need to re-deploy the contracts anyway.

  1. Changed CDP ID input/output parameter to a number instead of bytes32. Normally I would argue that the fact that it is a number is an implementation detail we should not rely on, unfortunately, we iterate it like a number, so we are tightly coupled with the implementation detail that is the ID selection algorithm.
  2. Added an event for when CDPs are closed by the system.
  3. Made closeCdp early return with result 0 when someone tries to close an empty CDP. This is added mainly because the UI will sometimes do an off-chain closure attempt for an already closed CDP and having it not throw is a quality of life improvement.
  4. Added the owner to the returned datastructure. This is necessary so we know the address we need to use when doing the delegated closure call.

In the client library, the main change is the addition of closePosition and a minor bugfix when processing the newCupEvent. There is some funky stuff with the nesting of the implementation. This is so we can utilize the generated encoder/decoder to generate the delegated call and then forward the result.

epheph commented 5 years ago

All looks great. Maybe a comment around the stashing thing because it's a little weird (dealing with the two calls of a DSproxy).