Conversation
| * @return address Address of the resulting lp token | ||
| */ | ||
| function _getResultToken(address) internal view override returns (address) { | ||
| return liquityBorrowerOperations.lusdToken(); |
There was a problem hiding this comment.
It's a little weird to have LUSD as the result token, since it doesn't reflect the amount of ETH that we deposited to our trove. Is this OK?
There was a problem hiding this comment.
Yes this is fine but when we return the price of the result token we need to account for the value of the collateral. See below
| address[] memory outputTokens = new address[](1); | ||
| // outputTokens[0] is address(0) (ether) | ||
| uint256[] memory outputAmounts = new uint256[](1); | ||
| outputAmounts[0] = _getCollateral(_strategy); // TODO: deal with fees |
There was a problem hiding this comment.
Actually - I think the fees are taken in LUSD, so we don't need to do anything here. Will update....
There was a problem hiding this comment.
the output amount should be the LUSD amount right and not the value of the collateral?
There was a problem hiding this comment.
The output token is Ether, so this should be the value of our Ether collateral, no?
There was a problem hiding this comment.
correct, naming is a bit confusing xD
There was a problem hiding this comment.
This function is simple, just return the current collateral amount.
| address /* _tokenDenominator */ | ||
| ) external pure override returns (uint256) { | ||
| (, uint amountLUSDToBorrow) = abi.decode(_data, (address, uint)); | ||
| return amountLUSDToBorrow; // we receive the exact number of LUSD tokens that we requested |
There was a problem hiding this comment.
See note above about using LUSD as the result token. Is this ok?
There was a problem hiding this comment.
we need to do something special here. Basically we want to return in total the value of the collateral minus the value of the LUSD taken as debt.
So the price per token should be : (Collateral in LUSD - Debt in LUSD)/ debt in LUSD
There was a problem hiding this comment.
I don't believe this function knows how much collateralInLUSD there is, however?
There was a problem hiding this comment.
you would need the strategy address to fetch it right?
| // when creating this custom strategy, don't allow borrowing up | ||
| // to the maximum collateral ratio. ensure that users have at least | ||
| // a 5% buffer. | ||
| babylonLiquidationBuffer = 50000000000000000; |
|
|
||
| return pricePerTokenUsd.preciseMul( | ||
| // convert from USD -> tokenDenominator | ||
| // TODO: use USD here, instead of LUSD? But how would we do that? |
| // transfer additional LUSD to strategy | ||
| // borrowed 9853.51 LUSD | ||
| // need additional 0.5% = 49.267551980000000000 | ||
| // TODO: for some reason, this fails if the number is not exact? |
There was a problem hiding this comment.
tests are failing here: help please? :)
This one is a little different.
I previously asked if lend / borrow should be in separate steps like AAVE, but it actually turns out that you can't do that with Liquity. When you open a trove, you must specify a borrow amount greater than the minimum (which is currently 1,800 LUSD.)
I will add some inline code comments, but also, the tests are currently failing and I'm not sure why:
Something in the finalization step is failing, but I'm not sure how to debug this within this repo;.
(Also, it will probably be helpful to your sanity to comment-out the Idle Finance test suite before running
npm test. You could useOPTIMIZER=false npx hardhat test --grep "Liquity", but as I've mentioned before, the test suite seems to share some state between the individual specs.)