Conversation
| assertGt(CometInterface(comet).getReserves(), initialReserves); | ||
| } | ||
|
|
||
| // XXX test actually liquidating an underwater account |
There was a problem hiding this comment.
I have not yet figured out the best way to mimic an underwater account. If you take out a borrow position and then fast-forward until the interest put the position underwater, then the forked chain's block timestamp is set significantly higher than the current head of the chain in reality.
this causes issues when you request routes from 1inch: the rates returned are for the current block timestamp. if your forked chain is too far ahead of reality, some of the swap contracts will revert saying that your rates are stale (this happens with Curve most often, "src rate stale or flagged").
There was a problem hiding this comment.
Not an answer to your original question, but I Googled that error and it seems to be coming from Synthetix. Is Curve routing through Synthetix (or maybe the other way around)?
There was a problem hiding this comment.
My bad, I meant Synthetix not Curve. It comes from this contract:
https://github.com/Synthetixio/synthetix/blob/v2.80.0-alpha/contracts/Exchanger.sol#L527
There was a problem hiding this comment.
How about prank as chainlink and decrease the price of the assets in it's price feed contract?
There was a problem hiding this comment.
oh that's an interesting idea
| address[] calldata swapTargets, | ||
| bytes[] calldata swapTransactions, |
There was a problem hiding this comment.
Should we validate that these lengths match?
| function swap(address asset) public { | ||
| address[] memory liquidatableAccounts; | ||
|
|
||
| // XXX not a static call; will actually absorb the liquidatableAccounts |
There was a problem hiding this comment.
If you want to do a static call, you can wrap this around a snapshot() and revertTo(): foundry-rs/foundry#2463 (comment)
| // expect the protocol reserves to have increased | ||
| assertGt(CometInterface(comet).getReserves(), initialReserves); | ||
|
|
||
| // XXX make sure that you're making > 1% of the value of the swap |
There was a problem hiding this comment.
Why >1%? Is that a threshold we set somewhere?
There was a problem hiding this comment.
no, it's just an approximation of how much you should be making. if the protocol is selling at a 2.5% discount, and you have to pay some fee for the flash loan and there is some slippage in the swap, you should end up receiving ~1-2% of the value of the collateral
| FlashCallbackData memory flashCallbackData = abi.decode(data, (FlashCallbackData)); | ||
| CallbackValidation.verifyCallback(factory, flashCallbackData.poolKey); | ||
|
|
||
| TransferHelper.safeApprove(CometInterface(flashCallbackData.comet).baseToken(), address(flashCallbackData.comet), flashCallbackData.flashLoanAmount); |
There was a problem hiding this comment.
use baseToken from line 220
Extremely rough version of a 1inch-enabled liquidation bot. Lots of changes to make still, but want to get some visibility on the decisions I'm making and thoughts on the remaining issues.
Some outstanding issues:
Sometimes, the 1inch router will use a route that involves swapping via the DAI/USDC pool, and the transaction will fail with "LOK".