@@ -22,6 +22,7 @@ import {XTokenType} from "../../../interfaces/IXTokenType.sol";
2222import {INTokenUniswapV3} from "../../../interfaces/INTokenUniswapV3.sol " ;
2323import {GenericLogic} from "./GenericLogic.sol " ;
2424import {IPriceOracleGetter} from "../../../interfaces/IPriceOracleGetter.sol " ;
25+ import {Helpers} from "../helpers/Helpers.sol " ;
2526
2627/**
2728 * @title SupplyLogic library
@@ -85,7 +86,7 @@ library SupplyLogic {
8586 mapping (address => DataTypes.ReserveData) storage reservesData ,
8687 DataTypes.UserConfigurationMap storage userConfig ,
8788 DataTypes.ExecuteSupplyParams memory params
88- ) external {
89+ ) public {
8990 DataTypes.ReserveData storage reserve = reservesData[params.asset];
9091 DataTypes.ReserveCache memory reserveCache = reserve.cache ();
9192
@@ -206,15 +207,12 @@ library SupplyLogic {
206207 tokenType == XTokenType.NTokenBAYC ||
207208 tokenType == XTokenType.NTokenMAYC
208209 ) {
209- uint16 sApeReserveId = reservesData[DataTypes.SApeAddress].id;
210- bool currentStatus = userConfig.isUsingAsCollateral (sApeReserveId);
211- if (! currentStatus) {
212- userConfig.setUsingAsCollateral (sApeReserveId, true );
213- emit ReserveUsedAsCollateralEnabled (
214- DataTypes.SApeAddress,
215- params.onBehalfOf
216- );
217- }
210+ Helpers.setAssetUsedAsCollateral (
211+ userConfig,
212+ reservesData,
213+ DataTypes.SApeAddress,
214+ params.onBehalfOf
215+ );
218216 }
219217 for (uint256 index = 0 ; index < params.tokenData.length ; index++ ) {
220218 IERC721 (params.asset).safeTransferFrom (
@@ -465,7 +463,6 @@ library SupplyLogic {
465463
466464 function executeDecreaseUniswapV3Liquidity (
467465 mapping (address => DataTypes.ReserveData) storage reservesData ,
468- mapping (uint256 => address ) storage reservesList ,
469466 DataTypes.UserConfigurationMap storage userConfig ,
470467 DataTypes.ExecuteDecreaseUniswapV3LiquidityParams memory params
471468 ) external {
@@ -490,29 +487,61 @@ library SupplyLogic {
490487 tokenIds
491488 );
492489
493- INTokenUniswapV3 (reserveCache.xTokenAddress).decreaseUniswapV3Liquidity (
494- params.user,
495- params.tokenId,
496- params.liquidityDecrease,
497- params.amount0Min,
498- params.amount1Min,
499- params.receiveEthAsWeth
500- );
501-
490+ (
491+ address token0 ,
492+ address token1 ,
493+ uint256 amount0 ,
494+ uint256 amount1
495+ ) = INTokenUniswapV3 (reserveCache.xTokenAddress)
496+ .decreaseUniswapV3Liquidity (
497+ params.user,
498+ params.tokenId,
499+ params.liquidityDecrease,
500+ params.amount0Min,
501+ params.amount1Min
502+ );
502503 bool isUsedAsCollateral = ICollateralizableERC721 (
503504 reserveCache.xTokenAddress
504505 ).isUsedAsCollateral (params.tokenId);
505- if (isUsedAsCollateral) {
506- if (userConfig.isBorrowingAny ()) {
507- ValidationLogic.validateHFAndLtvERC721 (
506+ if (amount0 > 0 ) {
507+ executeSupply (
508+ reservesData,
509+ userConfig,
510+ DataTypes.ExecuteSupplyParams ({
511+ asset: token0,
512+ amount: amount0,
513+ onBehalfOf: params.user,
514+ payer: address (this ),
515+ referralCode: 0
516+ })
517+ );
518+ if (isUsedAsCollateral) {
519+ Helpers.setAssetUsedAsCollateral (
520+ userConfig,
508521 reservesData,
509- reservesList,
522+ token0,
523+ params.user
524+ );
525+ }
526+ }
527+ if (amount1 > 0 ) {
528+ executeSupply (
529+ reservesData,
530+ userConfig,
531+ DataTypes.ExecuteSupplyParams ({
532+ asset: token1,
533+ amount: amount1,
534+ onBehalfOf: params.user,
535+ payer: address (this ),
536+ referralCode: 0
537+ })
538+ );
539+ if (isUsedAsCollateral) {
540+ Helpers.setAssetUsedAsCollateral (
510541 userConfig,
511- params.asset,
512- tokenIds,
513- params.user,
514- params.reservesCount,
515- params.oracle
542+ reservesData,
543+ token1,
544+ params.user
516545 );
517546 }
518547 }
0 commit comments