Skip to content

Commit

Permalink
Fix off-by-one in BoostManager and add BorrowerLens.isInUse
Browse files Browse the repository at this point in the history
  • Loading branch information
haydenshively committed Oct 28, 2023
1 parent 6fb1d96 commit 29e9641
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 6 deletions.
2 changes: 1 addition & 1 deletion periphery/foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ cache_path = 'cache'

via_ir = true
optimizer = true
optimizer_runs = 800
optimizer_runs = 65536
gas_reports = []

auto_detect_remappings = false
Expand Down
12 changes: 12 additions & 0 deletions periphery/src/BorrowerLens.sol
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,18 @@ contract BorrowerLens {
healthB = liabilities > 0 ? (assets * 1e18) / liabilities : 1000e18;
}

function isInUse(Borrower borrower) external view returns (bool, IUniswapV3Pool) {
IUniswapV3Pool pool = borrower.UNISWAP_POOL();

if (borrower.getUniswapPositions().length > 0) return (true, pool);
if (borrower.TOKEN0().balanceOf(address(borrower)) > 0) return (true, pool);
if (borrower.TOKEN1().balanceOf(address(borrower)) > 0) return (true, pool);
if (borrower.LENDER0().borrowBalanceStored(address(borrower)) > 0) return (true, pool);
if (borrower.LENDER1().borrowBalanceStored(address(borrower)) > 0) return (true, pool);

return (false, pool);
}

function getUniswapFees(Borrower account) external view returns (bytes32[] memory keys, uint256[] memory fees) {
IUniswapV3Pool pool = account.UNISWAP_POOL();
Uniswap.FeeComputationCache memory c;
Expand Down
4 changes: 2 additions & 2 deletions periphery/src/managers/BoostManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ contract BoostManager is IManager, IUniswapV3SwapCallback {
TickMath.getSqrtRatioAtTick(upper),
liquidity
);
amount0 = needs0 > amount0 ? needs0 - amount0 : 0;
amount1 = needs1 > amount1 ? needs1 - amount1 : 0;
amount0 = (needs0 + 1) > amount0 ? (needs0 + 1 - amount0) : 0;
amount1 = (needs1 + 1) > amount1 ? (needs1 + 1 - amount1) : 0;
}

borrower.borrow(amount0, amount1, msg.sender);
Expand Down
13 changes: 10 additions & 3 deletions periphery/test/managers/BoostManager.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {IUniswapV3Pool} from "v3-core/contracts/interfaces/IUniswapV3Pool.sol";

import {Borrower, IManager} from "aloe-ii-core/Borrower.sol";
import {Factory, BorrowerDeployer} from "aloe-ii-core/Factory.sol";
import {Lender} from "aloe-ii-core/Lender.sol";
import {RateModel} from "aloe-ii-core/RateModel.sol";
import {VolatilityOracle} from "aloe-ii-core/VolatilityOracle.sol";

Expand All @@ -26,7 +27,7 @@ contract BoostManagerTest is Test {

function setUp() public {
vm.createSelectFork(vm.rpcUrl("optimism"));
vm.rollFork(111258011);
vm.rollFork(111336182);

RateModel rateModel = new RateModel();
VolatilityOracle oracle = new VolatilityOracle();
Expand All @@ -36,9 +37,15 @@ contract BoostManagerTest is Test {

borrowerNft = new BorrowerNFT(factory, IBorrowerURISource(address(0)));
boostManager = new BoostManager(factory, address(borrowerNft), UNISWAP_NFT);

(Lender lender0, Lender lender1, ) = factory.getMarket(POOL);
deal(address(POOL.token0()), address(lender0), 1e18);
deal(address(POOL.token1()), address(lender1), 1e18);
lender0.deposit(1e18, address(0));
lender1.deposit(1e18, address(0));
}

function test_mint() public {
function test_mint() public {
address owner = 0xde8E7d3fFada10dE2A57E7bAc090dB06596F51Cd;

bytes memory mintCall;
Expand All @@ -60,7 +67,7 @@ contract BoostManagerTest is Test {
managers[0] = boostManager;
datas[0] = abi.encode(
uint8(0),
abi.encode(uint256(425835), int24(70020), int24(71700), uint128(550621657107328270), 10_000)
abi.encode(uint256(425835), int24(70020), int24(71700), uint128(344339104909795631), 10_000)
);
antes[0] = 0.01 ether / 1e13;
modifyCall = abi.encodeCall(borrowerNft.modify, (owner, indices, managers, datas, antes));
Expand Down

0 comments on commit 29e9641

Please sign in to comment.