@@ -77,13 +77,6 @@ library MarketplaceLogic {
7777 uint256 supplyAmount;
7878 address xTokenAddress;
7979 uint256 price;
80- uint256 ethLeft;
81- // used to avoid stack too deep
82- bytes32 marketplaceId;
83- bytes payload;
84- DataTypes.Credit credit;
85- DataTypes.SwapAdapter swapAdapter;
86- bytes swapPayload;
8780 }
8881
8982 function executeBuyWithCredit (
@@ -95,18 +88,20 @@ library MarketplaceLogic {
9588 bytes calldata swapPayload ,
9689 IPoolAddressesProvider poolAddressProvider
9790 ) external {
98- MarketplaceLocalVars memory vars;
99-
100- vars.ethLeft = msg .value ;
101- DataTypes.ExecuteMarketplaceParams memory params = _getParams (
91+ DataTypes.ExecuteMarketplaceParams memory params = _initParams (
10292 ps,
93+ poolAddressProvider
94+ );
95+ _updateParams (
96+ params,
10397 poolAddressProvider,
10498 marketplaceId,
10599 payload,
106100 credit,
107101 swapAdapter,
108102 swapPayload
109103 );
104+ params.ethLeft = msg .value ;
110105 params.orderInfo = IMarketplace (params.marketplace.adapter)
111106 .getAskOrderInfo (payload);
112107 if (params.orderInfo.isSeaport) {
@@ -115,20 +110,21 @@ library MarketplaceLogic {
115110 Errors.INVALID_ORDER_TAKER
116111 );
117112 } else {
113+ // in LooksRare, X2Y2 we dont match orders between buyer and seller
114+ // the protocol just works like an agent so taker cannot be read
115+ // from orders
118116 params.orderInfo.taker = msg .sender ;
119117 }
120118 require (
121119 params.orderInfo.maker != params.orderInfo.taker,
122120 Errors.MAKER_SAME_AS_TAKER
123121 );
124122
125- _depositETH (vars, params);
123+ _depositETH (params);
126124
127- params.ethLeft = vars.ethLeft ;
125+ params.ethLeft -= _buyWithCredit (ps, params) ;
128126
129- vars.ethLeft -= _buyWithCredit (ps, params);
130-
131- _refundETH (vars.ethLeft);
127+ _refundETH (params.ethLeft);
132128 }
133129
134130 /**
@@ -196,34 +192,32 @@ library MarketplaceLogic {
196192 bytes [] calldata swapPayloads ,
197193 IPoolAddressesProvider poolAddressProvider
198194 ) external {
199- MarketplaceLocalVars memory vars;
200-
201195 require (
202196 marketplaceIds.length == payloads.length &&
203197 swapAdapters.length == payloads.length &&
204198 swapPayloads.length == payloads.length &&
205199 credits.length == payloads.length ,
206200 Errors.INCONSISTENT_PARAMS_LENGTH
207201 );
208- vars.ethLeft = msg .value ;
202+
203+ DataTypes.ExecuteMarketplaceParams memory params = _initParams (
204+ ps,
205+ poolAddressProvider
206+ );
207+ params.ethLeft = msg .value ;
209208
210209 for (uint256 i = 0 ; i < marketplaceIds.length ; i++ ) {
211- vars.marketplaceId = marketplaceIds[i];
212- vars.payload = payloads[i];
213- vars.credit = credits[i];
214- vars.swapAdapter = swapAdapters[i];
215- vars.swapPayload = swapPayloads[i];
216- DataTypes.ExecuteMarketplaceParams memory params = _getParams (
217- ps,
210+ _updateParams (
211+ params,
218212 poolAddressProvider,
219- vars.marketplaceId ,
220- vars.payload ,
221- vars.credit ,
222- vars.swapAdapter ,
223- vars.swapPayload
213+ marketplaceIds[i] ,
214+ payloads[i] ,
215+ credits[i] ,
216+ swapAdapters[i] ,
217+ swapPayloads[i]
224218 );
225219 params.orderInfo = IMarketplace (params.marketplace.adapter)
226- .getAskOrderInfo (vars.payload );
220+ .getAskOrderInfo (payloads[i] );
227221 if (params.orderInfo.isSeaport) {
228222 require (
229223 msg .sender == params.orderInfo.taker,
@@ -251,14 +245,12 @@ library MarketplaceLogic {
251245 // batchBuyWithCredit([ETH, ETH, ETH]) => ok
252246 // batchBuyWithCredit([ETH, ETH, WETH]) => ok
253247 //
254- _depositETH (vars, params);
255-
256- params.ethLeft = vars.ethLeft;
248+ _depositETH (params);
257249
258- vars .ethLeft -= _buyWithCredit (ps, params);
250+ params .ethLeft -= _buyWithCredit (ps, params);
259251 }
260252
261- _refundETH (vars .ethLeft);
253+ _refundETH (params .ethLeft);
262254 }
263255
264256 function executeAcceptBidWithCredit (
@@ -269,8 +261,12 @@ library MarketplaceLogic {
269261 address onBehalfOf ,
270262 IPoolAddressesProvider poolAddressProvider
271263 ) external {
272- DataTypes.ExecuteMarketplaceParams memory params = _getParams (
264+ DataTypes.ExecuteMarketplaceParams memory params = _initParams (
273265 ps,
266+ poolAddressProvider
267+ );
268+ _updateParams (
269+ params,
274270 poolAddressProvider,
275271 marketplaceId,
276272 payload,
@@ -296,8 +292,12 @@ library MarketplaceLogic {
296292 address onBehalfOf ,
297293 IPoolAddressesProvider poolAddressProvider
298294 ) external {
299- DataTypes.ExecuteMarketplaceParams memory params = _getParams (
295+ DataTypes.ExecuteMarketplaceParams memory params = _initParams (
300296 ps,
297+ poolAddressProvider
298+ );
299+ _updateParams (
300+ params,
301301 poolAddressProvider,
302302 marketplaceId,
303303 payload,
@@ -337,8 +337,12 @@ library MarketplaceLogic {
337337 Errors.INCONSISTENT_PARAMS_LENGTH
338338 );
339339 for (uint256 i = 0 ; i < marketplaceIds.length ; i++ ) {
340- DataTypes.ExecuteMarketplaceParams memory params = _getParams (
340+ DataTypes.ExecuteMarketplaceParams memory params = _initParams (
341341 ps,
342+ poolAddressProvider
343+ );
344+ _updateParams (
345+ params,
342346 poolAddressProvider,
343347 marketplaceIds[i],
344348 payloads[i],
@@ -818,26 +822,32 @@ library MarketplaceLogic {
818822 );
819823 }
820824
821- function _getParams (
825+ function _initParams (
822826 DataTypes.PoolStorage storage ps ,
827+ IPoolAddressesProvider poolAddressProvider
828+ ) internal view returns (DataTypes.ExecuteMarketplaceParams memory params ) {
829+ params.weth = poolAddressProvider.getWETH ();
830+ params.reservesCount = ps._reservesCount;
831+ params.oracle = poolAddressProvider.getPriceOracle ();
832+ params.priceOracleSentinel = poolAddressProvider
833+ .getPriceOracleSentinel ();
834+ }
835+
836+ function _updateParams (
837+ DataTypes.ExecuteMarketplaceParams memory params ,
823838 IPoolAddressesProvider poolAddressProvider ,
824839 bytes32 marketplaceId ,
825840 bytes memory payload ,
826841 DataTypes.Credit memory credit ,
827842 DataTypes.SwapAdapter memory swapAdapter ,
828843 bytes memory swapPayload
829- ) internal view returns (DataTypes.ExecuteMarketplaceParams memory params ) {
844+ ) internal {
830845 params.marketplaceId = marketplaceId;
831- params.weth = poolAddressProvider.getWETH ();
832846 params.marketplace = poolAddressProvider.getMarketplace (marketplaceId);
833847 params.payload = payload;
834848 params.credit = credit;
835849 params.swapAdapter = swapAdapter;
836850 params.swapPayload = swapPayload;
837- params.reservesCount = ps._reservesCount;
838- params.oracle = poolAddressProvider.getPriceOracle ();
839- params.priceOracleSentinel = poolAddressProvider
840- .getPriceOracleSentinel ();
841851 }
842852
843853 function _refundETH (uint256 ethLeft ) internal {
@@ -846,24 +856,23 @@ library MarketplaceLogic {
846856 }
847857 }
848858
849- function _depositETH (
850- MarketplaceLocalVars memory vars ,
851- DataTypes.ExecuteMarketplaceParams memory params
852- ) internal {
859+ function _depositETH (DataTypes.ExecuteMarketplaceParams memory params )
860+ internal
861+ {
853862 if (
854- vars .ethLeft == 0 ||
863+ params .ethLeft == 0 ||
855864 params.orderInfo.consideration[0 ].itemType == ItemType.NATIVE
856865 ) {
857866 return ;
858867 }
859868
860- IWETH (params.weth).deposit {value: vars .ethLeft}();
869+ IWETH (params.weth).deposit {value: params .ethLeft}();
861870 IERC20 (params.weth).safeTransferFrom (
862871 address (this ),
863872 msg .sender ,
864- vars .ethLeft
873+ params .ethLeft
865874 );
866- vars .ethLeft = 0 ;
875+ params .ethLeft = 0 ;
867876 }
868877
869878 function _transferOrCollateralize (
0 commit comments