@@ -50,12 +50,6 @@ library MarketplaceLogic {
5050 uint16 indexed referralCode
5151 );
5252
53- /**
54- * @dev Default percentage of listing price to be supplied on behalf of the seller in a marketplace exchange.
55- * Expressed in bps, a value of 0.9e4 results in 90.00%
56- */
57- uint256 internal constant DEFAULT_SUPPLY_RATIO = 0.9e4 ;
58-
5953 event BuyWithCredit (
6054 bytes32 indexed marketplaceId ,
6155 DataTypes.OrderInfo orderInfo ,
@@ -158,7 +152,7 @@ library MarketplaceLogic {
158152 )
159153 );
160154
161- _handleFlashSupplyRepayment (vars, params.orderInfo.maker );
155+ _handleFlashSupplyRepayment (params, vars, address ( this ) );
162156 _handleFlashLoanRepayment (ps, params, vars, params.orderInfo.taker);
163157
164158 emit BuyWithCredit (
@@ -356,7 +350,7 @@ library MarketplaceLogic {
356350 )
357351 );
358352
359- _handleFlashSupplyRepayment (vars, params.orderInfo.taker );
353+ _handleFlashSupplyRepayment (params, vars, address ( this ) );
360354 _handleFlashLoanRepayment (ps, params, vars, params.orderInfo.maker);
361355
362356 emit AcceptBidWithCredit (
@@ -446,11 +440,11 @@ library MarketplaceLogic {
446440 MarketplaceLocalVars memory vars ,
447441 address seller
448442 ) internal {
449- if (vars.isETH) {
450- return ; // impossible to supply ETH on behalf of the
443+ DataTypes.ReserveData storage reserve = ps._reserves[vars.creditToken];
444+ if (reserve.xTokenAddress == address (0 )) {
445+ return ;
451446 }
452447
453- DataTypes.ReserveData storage reserve = ps._reserves[vars.creditToken];
454448 DataTypes.UserConfigurationMap storage sellerConfig = ps._usersConfig[
455449 seller
456450 ];
@@ -459,31 +453,25 @@ library MarketplaceLogic {
459453
460454 reserve.updateState (reserveCache);
461455
462- uint256 supplyAmount = Math.min (
463- IERC20 (vars.creditToken).allowance (seller, address (this )),
464- vars.price.percentMul (DEFAULT_SUPPLY_RATIO)
465- );
466- if (supplyAmount == 0 ) {
467- return ;
468- }
456+ vars.supplyAmount = vars.price;
469457
470458 ValidationLogic.validateSupply (
471459 reserveCache,
472- supplyAmount,
460+ vars. supplyAmount,
473461 DataTypes.AssetType.ERC20
474462 );
475463
476464 reserve.updateInterestRates (
477465 reserveCache,
478466 vars.creditToken,
479- supplyAmount,
467+ vars. supplyAmount,
480468 0
481469 );
482470
483471 bool isFirstSupply = IPToken (reserveCache.xTokenAddress).mint (
484472 msg .sender ,
485473 seller,
486- supplyAmount,
474+ vars. supplyAmount,
487475 reserveCache.nextLiquidityIndex
488476 );
489477
@@ -496,12 +484,9 @@ library MarketplaceLogic {
496484 vars.creditToken,
497485 msg .sender ,
498486 seller,
499- supplyAmount,
487+ vars. supplyAmount,
500488 params.referralCode
501489 );
502-
503- // set supplyAmount for future repayment
504- vars.supplyAmount = supplyAmount;
505490 }
506491
507492 /**
@@ -608,19 +593,25 @@ library MarketplaceLogic {
608593 /**
609594 * @notice "Repay" minted pToken by transferring funds from the seller to xTokenAddress
610595 * @dev
596+ * @param params The additional parameters needed to execute the buyWithCredit/acceptBidWithCredit function
611597 * @param vars The marketplace local vars for caching storage values for future reads
612- * @param seller The NFT seller
598+ * @param recipient The ERC20 recipient
613599 */
614600 function _handleFlashSupplyRepayment (
601+ DataTypes.ExecuteMarketplaceParams memory params ,
615602 MarketplaceLocalVars memory vars ,
616- address seller
603+ address recipient
617604 ) internal {
618- if (vars.isETH || vars. supplyAmount == 0 ) {
605+ if (vars.supplyAmount == 0 ) {
619606 return ;
620607 }
621608
609+ if (vars.isETH) {
610+ IWETH (params.weth).deposit {value: vars.supplyAmount}();
611+ }
612+
622613 IERC20 (vars.creditToken).safeTransferFrom (
623- seller ,
614+ recipient ,
624615 vars.creditXTokenAddress,
625616 vars.supplyAmount
626617 );
@@ -702,7 +693,7 @@ library MarketplaceLogic {
702693 function _validateAndGetPrice (
703694 DataTypes.ExecuteMarketplaceParams memory params ,
704695 MarketplaceLocalVars memory vars
705- ) internal pure returns (uint256 price ) {
696+ ) internal view returns (uint256 price ) {
706697 for (uint256 i = 0 ; i < params.orderInfo.consideration.length ; i++ ) {
707698 ConsiderationItem memory item = params.orderInfo.consideration[i];
708699 require (
@@ -718,7 +709,7 @@ library MarketplaceLogic {
718709 item.token == params.credit.token,
719710 Errors.CREDIT_DOES_NOT_MATCH_ORDER
720711 );
721- price += item.startAmount;
712+ if (item.recipient == address ( this )) price += item.startAmount;
722713 }
723714 }
724715}
0 commit comments