defi-org-code / compoundloop Goto Github PK
View Code? Open in Web Editor NEWStablecoin leveraged reborrowing on Compound
Stablecoin leveraged reborrowing on Compound
just need to make sure this != getAccountLiquidity, as it updates accruedInterest (not a view func)
enter with $5M, check liquidity
low liquidity = 10% of start liquidity
loop jump 1 month forward until < low liquidity
exit
verify state, iterations, gas
No need for percentage, it's enough to see that the liquidiy manually is far from zero
getAccountLiquidity()
Run require(accrueInterest() == 0, "accrue interest failed") before getAccountLiquidity and remove the view from the function. We can call it with call static. I didn't find an easier way to get the most recent liquidity with latest interest inside.
Recommend to return the first arg as well (uint error) to know that getAccountLiquidity didn't fail.
repayBorrow()
why not do a simple wrapper that receives arg repayAmount and just passes it onwards? these are emergency functions, ideally they shouldn't hold any logic.
Assuming according to (1) we remove the logic, the code will once again compile (right now it doesn't compile due to the last emit using an undeclared variable).
enterPosition()
The argument amountIn is strange.. let's say the account holds $1M USDC and we choose amountIn = $100K USDC.. in the loop we're going to set amountInCurr to the full balance anyways and mint the entire amount. I recommend to remove this argument and always enter all USDC to the position.
When calling getAccountLiquidity, it will be nicer to examine the error and the shortfall as well and require that they make sense (both are zero).
exitPosition()
When calling getAccountLiquidity, it will be nicer to examine the error and the shortfall as well and require that they make sense (both are zero).
I'm not 100% certain that in all edge conditions, accountLiquidity/collateralFactor is exactly enough for redeemUnderlying (it is checked in comptroller.redeemAllowed and I didn't go through all the code). What if we introduce a fraction similar to enterPositions' uint amountToBorrowNum_ / uint amountToBorrowDenom_ that instead of redeeming 100% of the available liquidity, will redeem some percentage of the available liquidity. We will usually run it on 100%, but if we get strange errors we can reduce the percentage to 90%.
what happens to liquidity after partial exit?
expect(healthFactor).increased
We will add this function to every future strategy contract to bail us out on problems
These are emergency functions, we always want to be able to call them
Full flow sanity:
1.a. enterPosition with $1M USDC (min $10K)
1.b. exitPosition
1.c. transfer the $1M USDC out to the owner
1.d. claim COMP and transfer COMP out to the owner
Multiple enters:
2.a. enterPosition with $1M USDC (min $10K)
2.b. Transfer new $20K USDC to the contract (to simulate COMP that was sold)
2.c. enterPosition again with the $20K USDC
2.d. exitPosition
2.e. transfer the $1M+$20K out to the owner
Manual exit (simulate recovery in case exitPosition fails for some unknown reason):
3.a. enterPosition with $1M USDC (min $10K)
3.b. Manual loop calling repayBorrow and friend functions to fully exit without calling exitPosition
3.c. transfer the $1M USDC out to the owner
I have some example similar forked tests I wrote for ycrv strategy example that might be useful - https://github.com/defi-org-code/ycrv-strategy-test/blob/master/test/index.test.js
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.