Skip to content

Commit

Permalink
fix: lint
Browse files Browse the repository at this point in the history
  • Loading branch information
Schlagonia committed Aug 14, 2023
1 parent 7368170 commit 6f06601
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 124 deletions.
47 changes: 18 additions & 29 deletions src/Depositer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,9 @@ contract Depositer {

event Cloned(address indexed clone);

function cloneDepositer(address _comet)
external
returns (address newDepositer)
{
function cloneDepositer(
address _comet
) external returns (address newDepositer) {
require(original, "!original");

Check warning on line 67 in src/Depositer.sol

View workflow job for this annotation

GitHub Actions / solidity

Use Custom Errors instead of require statements
newDepositer = _clone(_comet);
}
Expand Down Expand Up @@ -203,11 +202,9 @@ contract Depositer {
return accrued > claimed ? accrued - claimed : 0;
}

function getNetBorrowApr(uint256 newAmount)
public
view
returns (uint256 netApr)
{
function getNetBorrowApr(
uint256 newAmount
) public view returns (uint256 netApr) {
uint256 newUtilization = ((comet.totalBorrow() + newAmount) * 1e18) /
(comet.totalSupply() + newAmount);
uint256 borrowApr = getBorrowApr(newUtilization);
Expand All @@ -219,11 +216,9 @@ contract Depositer {
/*
* Get the current supply APR in Compound III
*/
function getSupplyApr(uint256 newUtilization)
public
view
returns (uint256)
{
function getSupplyApr(
uint256 newUtilization
) public view returns (uint256) {
unchecked {
return
comet.getSupplyRate(
Expand All @@ -235,11 +230,9 @@ contract Depositer {
/*
* Get the current borrow APR in Compound III
*/
function getBorrowApr(uint256 newUtilization)
public
view
returns (uint256)
{
function getBorrowApr(
uint256 newUtilization
) public view returns (uint256) {
unchecked {
return
comet.getBorrowRate(
Expand All @@ -261,11 +254,9 @@ contract Depositer {
* @param newAmount The new amount we will be supplying
* @return The reward APR in USD as a decimal scaled up by 1e18
*/
function getRewardAprForSupplyBase(uint256 newAmount)
public
view
returns (uint256)
{
function getRewardAprForSupplyBase(
uint256 newAmount
) public view returns (uint256) {
Comet _comet = comet;
unchecked {
uint256 rewardToSuppliersPerDay = _comet.baseTrackingSupplySpeed() *
Expand All @@ -285,11 +276,9 @@ contract Depositer {
* @param newAmount The new amount we will be borrowing
* @return The reward APR in USD as a decimal scaled up by 1e18
*/
function getRewardAprForBorrowBase(uint256 newAmount)
public
view
returns (uint256)
{
function getRewardAprForBorrowBase(
uint256 newAmount
) public view returns (uint256) {
// borrowBaseRewardApr = (rewardTokenPriceInUsd * rewardToBorrowersPerDay / (baseTokenTotalBorrow * baseTokenPriceInUsd)) * DAYS_PER_YEAR;
Comet _comet = comet;
unchecked {
Expand Down
54 changes: 23 additions & 31 deletions src/Strategy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,10 @@ contract Strategy is BaseTokenizedStrategy, UniswapV3Swapper {
maxGasPriceToTend = _maxGasPriceToTend;
}

function setPriceFeed(address token, address priceFeed)
external
onlyManagement
{
function setPriceFeed(
address token,
address priceFeed
) external onlyManagement {
// just check it doesnt revert
comet.getPrice(priceFeed);
priceFeeds[token] = priceFeed;
Expand Down Expand Up @@ -531,11 +531,9 @@ contract Strategy is BaseTokenizedStrategy, UniswapV3Swapper {
}
}

function _calculateAmountToRepay(uint256 amount)
internal
view
returns (uint256)
{
function _calculateAmountToRepay(
uint256 amount
) internal view returns (uint256) {
if (amount == 0) return 0;
uint256 collateral = balanceOfCollateral();
// to unlock all collateral we must repay all the debt
Expand All @@ -554,30 +552,28 @@ contract Strategy is BaseTokenizedStrategy, UniswapV3Swapper {
// ----------------- INTERNAL CALCS -----------------

// Returns the _amount of _token in terms of USD, i.e 1e8
function _toUsd(uint256 _amount, address _token)
internal
view
returns (uint256)
{
function _toUsd(
uint256 _amount,
address _token
) internal view returns (uint256) {
if (_amount == 0) return _amount;
// usd price is returned as 1e8
unchecked {
return
(_amount * getCompoundPrice(_token)) /
(10**ERC20(_token).decimals());
(10 ** ERC20(_token).decimals());
}
}

// Returns the _amount of usd (1e8) in terms of _token
function _fromUsd(uint256 _amount, address _token)
internal
view
returns (uint256)
{
function _fromUsd(
uint256 _amount,
address _token
) internal view returns (uint256) {
if (_amount == 0) return _amount;
unchecked {
return
(_amount * (10**ERC20(_token).decimals())) /
(_amount * (10 ** ERC20(_token).decimals())) /
getCompoundPrice(_token);
}
}
Expand Down Expand Up @@ -653,11 +649,9 @@ contract Strategy is BaseTokenizedStrategy, UniswapV3Swapper {
/*
* Get the price feed address for an asset
*/
function getPriceFeedAddress(address _asset)
internal
view
returns (address priceFeed)
{
function getPriceFeedAddress(
address _asset
) internal view returns (address priceFeed) {
priceFeed = priceFeeds[_asset];
if (priceFeed == address(0)) {
priceFeed = comet.getAssetInfoByAddress(_asset).priceFeed;
Expand All @@ -667,11 +661,9 @@ contract Strategy is BaseTokenizedStrategy, UniswapV3Swapper {
/*
* Get the current price of an _asset from the protocol's persepctive
*/
function getCompoundPrice(address _asset)
internal
view
returns (uint256 price)
{
function getCompoundPrice(
address _asset
) internal view returns (uint256 price) {
price = comet.getPrice(getPriceFeedAddress(_asset));
// If weth is base token we need to scale response to e18
if (price == 1e8 && _asset == base) price = 1e18;
Expand Down
6 changes: 1 addition & 5 deletions src/TokenizedCompV3LenderBorrowerFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,7 @@ contract TokenizedCompV3LenderBorrowerFactory {

event Deployed(address indexed depositer, address indexed strategy);

constructor(
address _managment,
address _rewards,
address _keeper
) {
constructor(address _managment, address _rewards, address _keeper) {
managment = _managment;
rewards = _rewards;
keeper = _keeper;
Expand Down
77 changes: 32 additions & 45 deletions src/interfaces/Compound/V3/CompoundV3.sol
Original file line number Diff line number Diff line change
Expand Up @@ -62,46 +62,39 @@ interface Comet is IERC20 {

function supply(address asset, uint256 amount) external;

function supplyTo(
address to,
address asset,
uint256 amount
) external;
function supplyTo(address to, address asset, uint256 amount) external;

function withdraw(address asset, uint256 amount) external;

function getSupplyRate(uint256 utilization) external view returns (uint256);

function getBorrowRate(uint256 utilization) external view returns (uint256);

function getAssetInfoByAddress(address asset)
external
view
returns (CometStructs.AssetInfo memory);
function getAssetInfoByAddress(
address asset
) external view returns (CometStructs.AssetInfo memory);

function getAssetInfo(uint8 i)
external
view
returns (CometStructs.AssetInfo memory);
function getAssetInfo(
uint8 i
) external view returns (CometStructs.AssetInfo memory);

function borrowBalanceOf(address account) external view returns (uint256);

function getPrice(address priceFeed) external view returns (uint128);

function userBasic(address)
external
view
returns (CometStructs.UserBasic memory);
function userBasic(
address
) external view returns (CometStructs.UserBasic memory);

function totalsBasic()
external
view
returns (CometStructs.TotalsBasic memory);

function userCollateral(address, address)
external
view
returns (CometStructs.UserCollateral memory);
function userCollateral(
address,
address
) external view returns (CometStructs.UserCollateral memory);

function baseTokenPriceFeed() external view returns (address);

Expand All @@ -119,15 +112,13 @@ interface Comet is IERC20 {

function baseIndexScale() external pure returns (uint64);

function baseTrackingAccrued(address account)
external
view
returns (uint64);
function baseTrackingAccrued(
address account
) external view returns (uint64);

function totalsCollateral(address asset)
external
view
returns (CometStructs.TotalsCollateral memory);
function totalsCollateral(
address asset
) external view returns (CometStructs.TotalsCollateral memory);

function baseMinForRewards() external view returns (uint256);

Expand All @@ -141,23 +132,19 @@ interface Comet is IERC20 {
}

interface CometRewards {
function getRewardOwed(address comet, address account)
external
returns (CometStructs.RewardOwed memory);

function claim(
function getRewardOwed(
address comet,
address src,
bool shouldAccrue
) external;
address account
) external returns (CometStructs.RewardOwed memory);

function rewardsClaimed(address comet, address account)
external
view
returns (uint256);
function claim(address comet, address src, bool shouldAccrue) external;

function rewardConfig(address comet)
external
view
returns (CometStructs.RewardConfig memory);
function rewardsClaimed(
address comet,
address account
) external view returns (uint256);

function rewardConfig(
address comet
) external view returns (CometStructs.RewardConfig memory);
}
10 changes: 4 additions & 6 deletions src/periphery/StrategyAprOracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,10 @@ contract StrategyAprOracle is AprOracleBase {
* @param _delta The difference in debt.
* @return . The expected apr for the strategy represented as 1e18.
*/
function aprAfterDebtChange(address _strategy, int256 _delta)
external
view
override
returns (uint256)
{
function aprAfterDebtChange(
address _strategy,
int256 _delta
) external view override returns (uint256) {
// TODO: Implement any necessary logic to return the most accurate
// APR estimation for the strategy.
return 1e17;
Expand Down
7 changes: 4 additions & 3 deletions src/test/Operation.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,10 @@ contract OperationTest is Setup {
);
}

function test_profitableReport(uint256 _amount, uint16 _profitFactor)
public
{
function test_profitableReport(
uint256 _amount,
uint16 _profitFactor
) public {
vm.assume(_amount > minFuzzAmount && _amount < maxFuzzAmount);
_profitFactor = uint16(bound(uint256(_profitFactor), 10, MAX_BPS));

Expand Down
6 changes: 1 addition & 5 deletions src/test/utils/Setup.sol
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,7 @@ contract Setup is ExtendedTest, IEvents {
assertEq(_totalAssets, _totalDebt + _totalIdle, "!Added");
}

function airdrop(
ERC20 _asset,
address _to,
uint256 _amount
) public {
function airdrop(ERC20 _asset, address _to, uint256 _amount) public {
uint256 balanceBefore = _asset.balanceOf(_to);
deal(address(_asset), _to, balanceBefore + _amount);
}
Expand Down

0 comments on commit 6f06601

Please sign in to comment.