Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Review #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions aave-v3-origin/foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ test = 'tests'
script = 'scripts'
optimizer = true
optimizer_runs = 200
solc = '0.8.20'
solc = '0.8.22'
evm_version = 'shanghai'
bytecode_hash = 'none'
ignored_warnings_from = ["src/periphery/contracts/treasury/RevenueSplitter.sol"]
out = 'out'
libs = ['lib']
remappings = []
fs_permissions = [
{ access = "write", path = "./reports" },
{ access = "read", path = "./out" },
{ access = "read", path = "./config" },
{ access = "write", path = "./reports" },
{ access = "read", path = "./out" },
{ access = "read", path = "./config" },
]
ffi = true

Expand Down
19 changes: 8 additions & 11 deletions aave-v3-origin/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions aave-v3-origin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"prettier-plugin-solidity": "^1.1.1"
},
"dependencies": {
"@bgd-labs/aave-cli": "^1.1.12",
"catapulta-verify": "^1.2.1"
"@bgd-labs/aave-cli": "^1.1.14",
"catapulta-verify": "^1.3.0"
}
}
4 changes: 2 additions & 2 deletions aave-v3-origin/snapshots/Pool.Getters.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
"getUserAccountData: supplies: 1, borrows: 0 with eMode enabled": "27360",
"getUserAccountData: supplies: 2, borrows: 0": "47575",
"getUserAccountData: supplies: 2, borrows: 0 with eMode enabled": "40267",
"getUserAccountData: supplies: 2, borrows: 1": "29247",
"getUserAccountData: supplies: 2, borrows: 1 with eMode enabled": "30439"
"getUserAccountData: supplies: 2, borrows: 1": "29431",
"getUserAccountData: supplies: 2, borrows: 1 with eMode enabled": "30623"
}
16 changes: 8 additions & 8 deletions aave-v3-origin/snapshots/Pool.Operations.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"borrow: first borrow->borrowingEnabled": "256480",
"borrow: recurrent borrow": "248834",
"liquidationCall: deficit on liquidated asset": "392439",
"liquidationCall: deficit on liquidated asset + other asset": "492078",
"liquidationCall: full liquidation": "392439",
"liquidationCall: full liquidation and receive ATokens": "368797",
"liquidationCall: partial liquidation": "383954",
"liquidationCall: partial liquidation and receive ATokens": "360308",
"borrow: recurrent borrow": "249018",
"liquidationCall: deficit on liquidated asset": "392365",
"liquidationCall: deficit on liquidated asset + other asset": "491921",
"liquidationCall: full liquidation": "392365",
"liquidationCall: full liquidation and receive ATokens": "368722",
"liquidationCall: partial liquidation": "383166",
"liquidationCall: partial liquidation and receive ATokens": "359520",
"repay: full repay": "176521",
"repay: full repay with ATokens": "173922",
"repay: partial repay": "189949",
Expand All @@ -16,5 +16,5 @@
"supply: first supply->collateralEnabled": "176366",
"withdraw: full withdraw": "165226",
"withdraw: partial withdraw": "181916",
"withdraw: partial withdraw with active borrows": "239286"
"withdraw: partial withdraw with active borrows": "239471"
}
4 changes: 2 additions & 2 deletions aave-v3-origin/snapshots/Pool.Setters.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"setUserEMode: enter eMode, 1 borrow, 1 supply": "140652",
"setUserEMode: leave eMode, 1 borrow, 1 supply": "112451",
"setUserEMode: enter eMode, 1 borrow, 1 supply": "140836",
"setUserEMode: leave eMode, 1 borrow, 1 supply": "112635",
"setUserUseReserveAsCollateral: disableCollateral, 1 supply": "93456",
"setUserUseReserveAsCollateral: enableCollateral, 1 supply": "105167"
}
8 changes: 4 additions & 4 deletions aave-v3-origin/snapshots/StataTokenV2.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"deposit": "281869",
"depositATokens": "220224",
"redeem": "205695",
"redeemAToken": "153479"
"deposit": "280955",
"depositATokens": "219311",
"redeem": "205837",
"redeemAToken": "152633"
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pragma solidity ^0.8.17;
import {ERC20Upgradeable} from 'openzeppelin-contracts-upgradeable/contracts/token/ERC20/ERC20Upgradeable.sol';
import {IERC20} from 'openzeppelin-contracts/contracts/interfaces/IERC20.sol';
import {SafeERC20} from 'openzeppelin-contracts/contracts/token/ERC20/utils/SafeERC20.sol';
import {SafeCast} from 'solidity-utils/contracts/oz-common/SafeCast.sol';
import {SafeCast} from 'openzeppelin-contracts/contracts/utils/math/SafeCast.sol';

import {IRewardsController} from '../../rewards/interfaces/IRewardsController.sol';
import {IERC20AaveLM} from './interfaces/IERC20AaveLM.sol';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.10;

import {IERC20Metadata} from 'solidity-utils/contracts/oz-common/interfaces/IERC20Metadata.sol';
import {ITransparentProxyFactory, ProxyAdmin} from 'solidity-utils/contracts/transparent-proxy/interfaces/ITransparentProxyFactory.sol';
import {Initializable} from 'solidity-utils/contracts/transparent-proxy/Initializable.sol';
import {IERC20Metadata} from 'openzeppelin-contracts/contracts/token/ERC20/extensions/IERC20Metadata.sol';
import {Initializable} from 'openzeppelin-contracts/contracts/proxy/utils/Initializable.sol';
import {ITransparentProxyFactory} from 'solidity-utils/contracts/transparent-proxy/interfaces/ITransparentProxyFactory.sol';
import {IPool, DataTypes} from '../../../contracts/interfaces/IPool.sol';
import {StataTokenV2} from './StataTokenV2.sol';
import {IStataTokenFactory} from './interfaces/IStataTokenFactory.sol';
Expand All @@ -20,7 +20,7 @@ contract StataTokenFactory is Initializable, IStataTokenFactory {
IPool public immutable POOL;

///@inheritdoc IStataTokenFactory
address public immutable PROXY_ADMIN;
address public immutable INITIAL_OWNER;

///@inheritdoc IStataTokenFactory
ITransparentProxyFactory public immutable TRANSPARENT_PROXY_FACTORY;
Expand All @@ -35,12 +35,12 @@ contract StataTokenFactory is Initializable, IStataTokenFactory {

constructor(
IPool pool,
address proxyAdmin,
address initialOwner,
ITransparentProxyFactory transparentProxyFactory,
address stataTokenImpl
) {
POOL = pool;
PROXY_ADMIN = proxyAdmin;
INITIAL_OWNER = initialOwner;
TRANSPARENT_PROXY_FACTORY = transparentProxyFactory;
STATA_TOKEN_IMPL = stataTokenImpl;
}
Expand All @@ -58,7 +58,7 @@ contract StataTokenFactory is Initializable, IStataTokenFactory {
bytes memory symbol = abi.encodePacked('w', IERC20Metadata(aTokenAddress).symbol());
address stataToken = TRANSPARENT_PROXY_FACTORY.createDeterministic(
STATA_TOKEN_IMPL,
ProxyAdmin(PROXY_ADMIN),
INITIAL_OWNER,
abi.encodeWithSelector(
StataTokenV2.initialize.selector,
aTokenAddress,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ interface IStataTokenFactory {
function POOL() external view returns (IPool);

/**
* @notice The proxy admin used for all tokens created via the factory.
* @return The proxy admin address.
* @notice The initial owner used for all tokens created via the factory.
* @return The address of the initial owner.
*/
function PROXY_ADMIN() external view returns (address);
function INITIAL_OWNER() external view returns (address);

/**
* @notice The proxy factory used for all tokens created via the stata factory.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.18;

import {Address} from 'openzeppelin-contracts/contracts/utils/Address.sol';
import {CapsEngine} from './libraries/CapsEngine.sol';
import {BorrowEngine} from './libraries/BorrowEngine.sol';
import {CollateralEngine} from './libraries/CollateralEngine.sol';
import {RateEngine} from './libraries/RateEngine.sol';
import {PriceFeedEngine} from './libraries/PriceFeedEngine.sol';
import {EModeEngine} from './libraries/EModeEngine.sol';
import {ListingEngine} from './libraries/ListingEngine.sol';
import {Address} from 'solidity-utils/contracts/oz-common/Address.sol';
import './IAaveV3ConfigEngine.sol';

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.0;

import {Address} from 'solidity-utils/contracts/oz-common/Address.sol';
import {Address} from 'openzeppelin-contracts/contracts/utils/Address.sol';
import {WadRayMath} from '../../protocol/libraries/math/WadRayMath.sol';
import {IAaveV3ConfigEngine as IEngine} from './IAaveV3ConfigEngine.sol';
import {EngineFlags} from './EngineFlags.sol';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.18;

import {SafeCast} from 'openzeppelin-contracts/contracts/utils/math/SafeCast.sol';
import {EngineFlags} from '../EngineFlags.sol';
import {DataTypes} from '../../../protocol/libraries/types/DataTypes.sol';
import {SafeCast} from 'solidity-utils/contracts/oz-common/SafeCast.sol';
import {PercentageMath} from '../../../protocol/libraries/math/PercentageMath.sol';
import {IAaveV3ConfigEngine as IEngine, IPoolConfigurator, IPool} from '../IAaveV3ConfigEngine.sol';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.18;

import {Address} from 'openzeppelin-contracts/contracts/utils/Address.sol';
import {IAaveV3ConfigEngine as IEngine, IPoolConfigurator, IPool, IDefaultInterestRateStrategyV2} from '../IAaveV3ConfigEngine.sol';
import {PriceFeedEngine} from './PriceFeedEngine.sol';
import {CapsEngine} from './CapsEngine.sol';
import {BorrowEngine} from './BorrowEngine.sol';
import {CollateralEngine} from './CollateralEngine.sol';
import {EModeEngine} from './EModeEngine.sol';
import {ConfiguratorInputTypes} from '../../../protocol/libraries/types/ConfiguratorInputTypes.sol';
import {Address} from 'solidity-utils/contracts/oz-common/Address.sol';
import {SafeCast} from '../../../dependencies/openzeppelin/contracts/SafeCast.sol';

library ListingEngine {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,9 @@ contract WrappedTokenGatewayV3 is IWrappedTokenGatewayV3, Ownable {
amountToWithdraw = userBalance;
}
// permit `amount` rather than `amountToWithdraw` to make it easier for front-ends and integrators
aWETH.permit(msg.sender, address(this), amount, deadline, permitV, permitR, permitS);
try
aWETH.permit(msg.sender, address(this), amount, deadline, permitV, permitR, permitS)
{} catch {}
Comment on lines +140 to +142
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change related to bgd-labs/aave-v3-origin#50.

Fixes issues: #209

aWETH.transferFrom(msg.sender, address(this), amountToWithdraw);
POOL.withdraw(address(WETH), amountToWithdraw, address(this));
WETH.withdraw(amountToWithdraw);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
pragma solidity ^0.8.0;

import {Errors} from '../helpers/Errors.sol';
import {DataTypes} from '../types/DataTypes.sol';
import {ReserveConfiguration} from './ReserveConfiguration.sol';

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ pragma solidity ^0.8.10;

import {GPv2SafeERC20} from '../../../dependencies/gnosis/contracts/GPv2SafeERC20.sol';
import {IERC20} from '../../../dependencies/openzeppelin/contracts/IERC20.sol';
import {IPriceOracleGetter} from '../../../interfaces/IPriceOracleGetter.sol';
import {UserConfiguration} from '../configuration/UserConfiguration.sol';
import {WadRayMath} from '../math/WadRayMath.sol';
import {PercentageMath} from '../math/PercentageMath.sol';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,20 @@ library GenericLogic {
}

if (params.userConfig.isBorrowing(vars.i)) {
vars.totalDebtInBaseCurrency += _getUserDebtInBaseCurrency(
params.user,
currentReserve,
vars.assetPrice,
vars.assetUnit
);
if (currentReserve.configuration.getIsVirtualAccActive()) {
vars.totalDebtInBaseCurrency += _getUserDebtInBaseCurrency(
params.user,
currentReserve,
vars.assetPrice,
vars.assetUnit
);
} else {
// custom case for GHO, which applies the GHO discount on balanceOf
vars.totalDebtInBaseCurrency +=
(IERC20(currentReserve.variableDebtTokenAddress).balanceOf(params.user) *
vars.assetPrice) /
vars.assetUnit;
}
}

unchecked {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ library IsolationModeLogic {
event IsolationModeTotalDebtUpdated(address indexed asset, uint256 totalDebt);

/**
* @notice updated the isolated debt whenever a position collateralized by an isolated asset is repaid or liquidated
* @notice updated the isolated debt whenever a position collateralized by an isolated asset is repaid
* @param reservesData The state of all the reserves
* @param reservesList The addresses of all the active reserves
* @param userConfig The user configuration mapping
Expand All @@ -38,27 +38,43 @@ library IsolationModeLogic {
.getIsolationModeState(reservesData, reservesList);

if (isolationModeActive) {
uint128 isolationModeTotalDebt = reservesData[isolationModeCollateralAddress]
.isolationModeTotalDebt;
updateIsolatedDebt(reservesData, reserveCache, repayAmount, isolationModeCollateralAddress);
}
}

/**
* @notice updated the isolated debt whenever a position collateralized by an isolated asset is liquidated
* @param reservesData The state of all the reserves
* @param reserveCache The cached data of the reserve
* @param repayAmount The amount being repaid
* @param isolationModeCollateralAddress The address of the isolated collateral
*/
function updateIsolatedDebt(
mapping(address => DataTypes.ReserveData) storage reservesData,
DataTypes.ReserveCache memory reserveCache,
uint256 repayAmount,
address isolationModeCollateralAddress
) internal {
uint128 isolationModeTotalDebt = reservesData[isolationModeCollateralAddress]
.isolationModeTotalDebt;

uint128 isolatedDebtRepaid = (repayAmount /
10 **
(reserveCache.reserveConfiguration.getDecimals() -
ReserveConfiguration.DEBT_CEILING_DECIMALS)).toUint128();
uint128 isolatedDebtRepaid = (repayAmount /
10 **
(reserveCache.reserveConfiguration.getDecimals() -
ReserveConfiguration.DEBT_CEILING_DECIMALS)).toUint128();

// since the debt ceiling does not take into account the interest accrued, it might happen that amount
// repaid > debt in isolation mode
if (isolationModeTotalDebt <= isolatedDebtRepaid) {
reservesData[isolationModeCollateralAddress].isolationModeTotalDebt = 0;
emit IsolationModeTotalDebtUpdated(isolationModeCollateralAddress, 0);
} else {
uint256 nextIsolationModeTotalDebt = reservesData[isolationModeCollateralAddress]
.isolationModeTotalDebt = isolationModeTotalDebt - isolatedDebtRepaid;
emit IsolationModeTotalDebtUpdated(
isolationModeCollateralAddress,
nextIsolationModeTotalDebt
);
}
// since the debt ceiling does not take into account the interest accrued, it might happen that amount
// repaid > debt in isolation mode
if (isolationModeTotalDebt <= isolatedDebtRepaid) {
reservesData[isolationModeCollateralAddress].isolationModeTotalDebt = 0;
emit IsolationModeTotalDebtUpdated(isolationModeCollateralAddress, 0);
} else {
uint256 nextIsolationModeTotalDebt = reservesData[isolationModeCollateralAddress]
.isolationModeTotalDebt = isolationModeTotalDebt - isolatedDebtRepaid;
emit IsolationModeTotalDebtUpdated(
isolationModeCollateralAddress,
nextIsolationModeTotalDebt
);
}
}
}
Loading