Skip to content

Commit

Permalink
fix: removed useAsCollateral flag in supply
Browse files Browse the repository at this point in the history
  • Loading branch information
The-3D committed Sep 22, 2021
1 parent 9c8112f commit 891da9b
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 69 deletions.
12 changes: 3 additions & 9 deletions contracts/interfaces/IPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,14 @@ interface IPool {
* @param user The address initiating the supply
* @param onBehalfOf The beneficiary of the supply, receiving the aTokens
* @param amount The amount supplied
* @param referral The referral code used
* @param useAsCollateral True if the user wants to use the supplied asset as collateral, false otherwise
* @param referralCode The referral code used
**/
event Supply(
address indexed reserve,
address user,
address indexed onBehalfOf,
uint256 amount,
uint16 indexed referral,
bool useAsCollateral
uint16 indexed referralCode
);

/**
Expand Down Expand Up @@ -175,14 +173,12 @@ interface IPool {
* is a different wallet
* @param referralCode Code used to register the integrator originating the operation, for potential rewards.
* 0 if the action is executed directly by the user, without any middle-man
* @param useAsCollateral True if the user wants to use the supplied asset as collateral, false otherwise
**/
function supply(
address asset,
uint256 amount,
address onBehalfOf,
uint16 referralCode,
bool useAsCollateral
uint16 referralCode
) external;

/**
Expand All @@ -196,7 +192,6 @@ interface IPool {
* @param deadline The deadline timestamp that the permit is valid
* @param referralCode Code used to register the integrator originating the operation, for potential rewards.
* 0 if the action is executed directly by the user, without any middle-man
* @param useAsCollateral True if the user wants to use the supplied asset as collateral, false otherwise
* @param permitV The V parameter of ERC712 permit sig
* @param permitR The R parameter of ERC712 permit sig
* @param permitS The S parameter of ERC712 permit sig
Expand All @@ -207,7 +202,6 @@ interface IPool {
address onBehalfOf,
uint16 referralCode,
uint256 deadline,
bool useAsCollateral,
uint8 permitV,
bytes32 permitR,
bytes32 permitS
Expand Down
42 changes: 5 additions & 37 deletions contracts/protocol/libraries/logic/SupplyLogic.sol
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,12 @@ library SupplyLogic {
address user,
address indexed onBehalfOf,
uint256 amount,
uint16 indexed referral,
bool useAsCollateral
uint16 indexed referralCode
);

function executeSupply(
mapping(address => DataTypes.ReserveData) storage reserves,
DataTypes.UserConfigurationMap storage userConfig,
mapping(uint256 => address) storage reservesList,
DataTypes.ExecuteSupplyParams memory params
) internal {
DataTypes.ReserveData storage reserve = reserves[params.asset];
Expand All @@ -65,42 +63,12 @@ library SupplyLogic {
reserveCache.nextLiquidityIndex
);

// Apply `useAsCollateral` if:
// - user supplies assets on its own
// - user supplies assets on behalf of another user and it's their first supplied assets
if (params.onBehalfOf == msg.sender || (params.onBehalfOf != msg.sender && isFirstSupply)) {
if (params.useAsCollateral) {
userConfig.setUsingAsCollateral(reserve.id, true);
emit ReserveUsedAsCollateralEnabled(params.asset, params.onBehalfOf);
} else {
// Validate HF in case its needed
if (userConfig.isUsingAsCollateral(reserve.id)) {
userConfig.setUsingAsCollateral(reserve.id, false);
if (userConfig.isBorrowingAny()) {
ValidationLogic.validateHFAndLtv(
params.asset,
params.onBehalfOf,
reserves,
userConfig,
reservesList,
params.reservesCount,
params.oracle
);
}
}

emit ReserveUsedAsCollateralDisabled(params.asset, params.onBehalfOf);
}
if (isFirstSupply) {
userConfig.setUsingAsCollateral(reserve.id, true);
emit ReserveUsedAsCollateralEnabled(params.asset, params.onBehalfOf);
}

emit Supply(
params.asset,
msg.sender,
params.onBehalfOf,
params.amount,
params.referralCode,
params.useAsCollateral
);
emit Supply(params.asset, msg.sender, params.onBehalfOf, params.amount, params.referralCode);
}

function executeWithdraw(
Expand Down
3 changes: 0 additions & 3 deletions contracts/protocol/libraries/types/DataTypes.sol
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,6 @@ library DataTypes {
uint256 amount;
address onBehalfOf;
uint16 referralCode;
bool useAsCollateral;
uint256 reservesCount;
address oracle;
}

struct ExecuteBorrowParams {
Expand Down
22 changes: 4 additions & 18 deletions contracts/protocol/pool/Pool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -84,21 +84,16 @@ contract Pool is VersionedInitializable, IPool, PoolStorage {
address asset,
uint256 amount,
address onBehalfOf,
uint16 referralCode,
bool useAsCollateral
uint16 referralCode
) external override {
SupplyLogic.executeSupply(
_reserves,
_usersConfig[onBehalfOf],
_reservesList,
DataTypes.ExecuteSupplyParams(
asset,
amount,
onBehalfOf,
referralCode,
useAsCollateral,
_reservesCount,
_addressesProvider.getPriceOracle()
referralCode
)
);
}
Expand All @@ -110,7 +105,6 @@ contract Pool is VersionedInitializable, IPool, PoolStorage {
address onBehalfOf,
uint16 referralCode,
uint256 deadline,
bool useAsCollateral,
uint8 permitV,
bytes32 permitR,
bytes32 permitS
Expand All @@ -127,15 +121,11 @@ contract Pool is VersionedInitializable, IPool, PoolStorage {
SupplyLogic.executeSupply(
_reserves,
_usersConfig[onBehalfOf],
_reservesList,
DataTypes.ExecuteSupplyParams(
asset,
amount,
onBehalfOf,
referralCode,
useAsCollateral,
_reservesCount,
_addressesProvider.getPriceOracle()
referralCode
)
);
}
Expand Down Expand Up @@ -612,15 +602,11 @@ contract Pool is VersionedInitializable, IPool, PoolStorage {
SupplyLogic.executeSupply(
_reserves,
_usersConfig[onBehalfOf],
_reservesList,
DataTypes.ExecuteSupplyParams(
asset,
amount,
onBehalfOf,
referralCode,
true,
_reservesCount,
_addressesProvider.getPriceOracle()
referralCode
)
);
}
Expand Down
2 changes: 0 additions & 2 deletions test-suites/helpers/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,6 @@ export const supplyWithPermit = async (
onBehalfOf,
'0',
highDeadline,
useAsCollateral,
v,
r,
s,
Expand Down Expand Up @@ -634,7 +633,6 @@ export const supplyWithPermit = async (
onBehalfOf,
'0',
highDeadline,
useAsCollateral,
v,
r,
s,
Expand Down

0 comments on commit 891da9b

Please sign in to comment.