From 2cedff273ec626b6e3468caf79cdcbfbf43aa123 Mon Sep 17 00:00:00 2001 From: Ayush Tiwari Date: Fri, 13 Sep 2024 00:35:55 +0530 Subject: [PATCH] feat: added logic to calculate protocol fee individually for bundled assets --- .../marketplace/contracts/TransferManager.sol | 266 +++++++++++++----- .../test/exchange/Bundle.behavior.ts | 138 ++++++--- 2 files changed, 294 insertions(+), 110 deletions(-) diff --git a/packages/marketplace/contracts/TransferManager.sol b/packages/marketplace/contracts/TransferManager.sol index 83d3d1ee24..80c2c08c0a 100644 --- a/packages/marketplace/contracts/TransferManager.sol +++ b/packages/marketplace/contracts/TransferManager.sol @@ -204,59 +204,98 @@ abstract contract TransferManager is Initializable, ITransferManager { function _doTransfersWithFeesAndRoyalties(DealSide memory paymentSide, DealSide memory nftSide) internal { uint256 fees; uint256 remainder = paymentSide.asset.value; - if (_isTSBSeller(nftSide.account) || _isPrimaryMarket(nftSide)) { - fees = protocolFeePrimary; - // No royalties + (, address nftSideRecipient) = _getRecipients(paymentSide, nftSide); + + if (nftSide.asset.assetType.assetClass == LibAsset.AssetClass.BUNDLE) { + LibAsset.Bundle memory bundle = LibAsset.decodeBundle(nftSide.asset.assetType); + if (_isTSBSeller(nftSide.account)) { + fees = protocolFeePrimary; + // No royalties + if (fees > 0 && remainder > 0) { + remainder = _transferPercentage( + remainder, + paymentSide, + paymentSide.asset.value, + defaultFeeReceiver, + fees, + PROTOCOL_FEE_MULTIPLIER + ); + } + } else { + remainder = _doTransfersWithFeesAndRoyaltiesForBundledERC721( + paymentSide, + nftSide, + bundle, + remainder, + nftSideRecipient + ); + + remainder = _doTransfersWithFeesAndRoyaltiesForBundledERC1155( + paymentSide, + nftSide, + bundle, + remainder, + nftSideRecipient + ); + + remainder = _doTransfersWithFeesAndRoyaltiesForBundledQuads( + paymentSide, + bundle, + remainder, + nftSideRecipient + ); + } } else { - fees = protocolFeeSecondary; - remainder = _transferRoyalties(remainder, paymentSide, nftSide); - } - if (fees > 0 && remainder > 0) { - remainder = _transferPercentage( - remainder, - paymentSide, - paymentSide.asset.value, - defaultFeeReceiver, - fees, - PROTOCOL_FEE_MULTIPLIER - ); + if (_isTSBSeller(nftSide.account) || _isPrimaryMarket(nftSide)) { + fees = protocolFeePrimary; + // No royalties + } else { + fees = protocolFeeSecondary; + remainder = _transferRoyalties(remainder, paymentSide, nftSide); + } + + if (fees > 0 && remainder > 0) { + remainder = _transferPercentage( + remainder, + paymentSide, + paymentSide.asset.value, + defaultFeeReceiver, + fees, + PROTOCOL_FEE_MULTIPLIER + ); + } } if (remainder > 0) { - (, address nftSideRecipient) = _getRecipients(paymentSide, nftSide); _transfer(LibAsset.Asset(paymentSide.asset.assetType, remainder), paymentSide.account, nftSideRecipient); } } - /// @notice Return if this tx is on primary market - /// @param nftSide DealSide of the nft-side order - /// @return creator Address or zero if is not able to retrieve it - function _isPrimaryMarket(DealSide memory nftSide) internal view returns (bool) { - address creator = _getCreator(nftSide.asset.assetType); - return creator != address(0) && nftSide.account == creator; - } - - /// @notice Transfer royalties. - /// @param remainder How much of the amount left after previous transfers - /// @param paymentSide DealSide of the fee-side order - /// @param nftSide DealSide of the nft-side order - /// @return How much left after paying royalties - function _transferRoyalties( - uint256 remainder, + function _doTransfersWithFeesAndRoyaltiesForBundledERC721( DealSide memory paymentSide, - DealSide memory nftSide + DealSide memory nftSide, + LibAsset.Bundle memory bundle, + uint256 remainder, + address nftSideRecipient ) internal returns (uint256) { - (, address nftSideRecipient) = _getRecipients(paymentSide, nftSide); - if (nftSide.asset.assetType.assetClass == LibAsset.AssetClass.BUNDLE) { - LibAsset.Bundle memory bundle = LibAsset.decodeBundle(nftSide.asset.assetType); + uint256 fees; + address creator; + IRoyaltiesProvider.Part[] memory royalties; + + for (uint256 i; i < bundle.bundledERC721.length; i++) { + address token = bundle.bundledERC721[i].erc721Address; + uint256 idLength = bundle.bundledERC721[i].ids.length; + for (uint256 j; j < idLength; j++) { + if (token.supportsInterface(type(IRoyaltyUGC).interfaceId)) { + creator = IRoyaltyUGC(token).getCreatorAddress(bundle.bundledERC721[i].ids[j]); + } - for (uint256 i; i < bundle.bundledERC721.length; i++) { - address token = bundle.bundledERC721[i].erc721Address; - uint256 idLength = bundle.bundledERC721[i].ids.length; - for (uint256 j; j < idLength; j++) { - IRoyaltiesProvider.Part[] memory royalties = royaltiesRegistry.getRoyalties( - token, - bundle.bundledERC721[i].ids[j] - ); + if (creator != address(0) && nftSide.account == creator) { + fees = protocolFeePrimary; + // No royalties + } else { + royalties = royaltiesRegistry.getRoyalties(token, bundle.bundledERC721[i].ids[j]); + + fees = protocolFeeSecondary; remainder = _applyRoyalties( remainder, @@ -265,21 +304,52 @@ abstract contract TransferManager is Initializable, ITransferManager { royalties, nftSideRecipient ); + if (fees > 0 && remainder > 0) { + remainder = _transferPercentage( + remainder, + paymentSide, + bundle.priceDistribution.erc721Prices[i][j], + defaultFeeReceiver, + fees, + PROTOCOL_FEE_MULTIPLIER + ); + } } } + } + return remainder; + } - for (uint256 i; i < bundle.bundledERC1155.length; i++) { - address token = bundle.bundledERC1155[i].erc1155Address; - uint256 idLength = bundle.bundledERC1155[i].ids.length; - require(idLength == bundle.bundledERC1155[i].supplies.length, "ERC1155 array error"); - for (uint256 j; j < idLength; j++) { - IRoyaltiesProvider.Part[] memory royalties = royaltiesRegistry.getRoyalties( - token, - bundle.bundledERC1155[i].ids[j] - ); + function _doTransfersWithFeesAndRoyaltiesForBundledERC1155( + DealSide memory paymentSide, + DealSide memory nftSide, + LibAsset.Bundle memory bundle, + uint256 remainder, + address nftSideRecipient + ) internal returns (uint256) { + uint256 fees; + address creator; + IRoyaltiesProvider.Part[] memory royalties; + + for (uint256 i; i < bundle.bundledERC1155.length; i++) { + address token = bundle.bundledERC1155[i].erc1155Address; + uint256 idLength = bundle.bundledERC1155[i].ids.length; + require(idLength == bundle.bundledERC1155[i].supplies.length, "ERC1155 array error"); + + for (uint256 j; j < idLength; j++) { + if (token.supportsInterface(type(IRoyaltyUGC).interfaceId)) { + creator = IRoyaltyUGC(token).getCreatorAddress(bundle.bundledERC1155[i].ids[j]); + } + if (creator != address(0) && nftSide.account == creator) { + fees = protocolFeePrimary; + // No royalties + } else { + royalties = royaltiesRegistry.getRoyalties(token, bundle.bundledERC1155[i].ids[j]); // royalty transfer when exchanging one or more than one bundle of ERC1155s for (uint256 k; k < nftSide.asset.value; k++) { + fees = protocolFeeSecondary; + remainder = _applyRoyalties( remainder, paymentSide, @@ -287,40 +357,94 @@ abstract contract TransferManager is Initializable, ITransferManager { royalties, nftSideRecipient ); + if (fees > 0 && remainder > 0) { + remainder = _transferPercentage( + remainder, + paymentSide, + bundle.priceDistribution.erc1155Prices[i][j], + defaultFeeReceiver, + fees, + PROTOCOL_FEE_MULTIPLIER + ); + } } } } + } + return remainder; + } - uint256 quadSize = bundle.quads.xs.length; - if (quadSize > 0) { - for (uint256 i = 0; i < quadSize; i++) { - uint256 size = bundle.quads.sizes[i]; - uint256 x = bundle.quads.xs[i]; - uint256 y = bundle.quads.ys[i]; - - uint256 tokenId = idInPath(0, size, x, y); - IRoyaltiesProvider.Part[] memory royalties = royaltiesRegistry.getRoyalties( - address(landContract), - tokenId - ); + function _doTransfersWithFeesAndRoyaltiesForBundledQuads( + DealSide memory paymentSide, + LibAsset.Bundle memory bundle, + uint256 remainder, + address nftSideRecipient + ) internal returns (uint256) { + uint256 fees; + IRoyaltiesProvider.Part[] memory royalties; - remainder = _applyRoyalties( + uint256 quadSize = bundle.quads.xs.length; + if (quadSize > 0) { + for (uint256 i = 0; i < quadSize; i++) { + uint256 size = bundle.quads.sizes[i]; + uint256 x = bundle.quads.xs[i]; + uint256 y = bundle.quads.ys[i]; + + uint256 tokenId = idInPath(0, size, x, y); + + royalties = royaltiesRegistry.getRoyalties(address(landContract), tokenId); + + fees = protocolFeeSecondary; + + remainder = _applyRoyalties( + remainder, + paymentSide, + bundle.priceDistribution.quadPrices[i], + royalties, + nftSideRecipient + ); + if (fees > 0 && remainder > 0) { + remainder = _transferPercentage( remainder, paymentSide, bundle.priceDistribution.quadPrices[i], - royalties, - nftSideRecipient + defaultFeeReceiver, + fees, + PROTOCOL_FEE_MULTIPLIER ); } } - } else { - (address token, uint256 tokenId) = LibAsset.decodeToken(nftSide.asset.assetType); - IRoyaltiesProvider.Part[] memory royalties = royaltiesRegistry.getRoyalties(token, tokenId); - remainder = _applyRoyalties(remainder, paymentSide, remainder, royalties, nftSideRecipient); } return remainder; } + /// @notice Return if this tx is on primary market + /// @param nftSide DealSide of the nft-side order + /// @return creator Address or zero if is not able to retrieve it + function _isPrimaryMarket(DealSide memory nftSide) internal view returns (bool) { + address creator = _getCreator(nftSide.asset.assetType); + return creator != address(0) && nftSide.account == creator; + } + + /// @notice Transfer royalties. + /// @param remainder How much of the amount left after previous transfers + /// @param paymentSide DealSide of the fee-side order + /// @param nftSide DealSide of the nft-side order + /// @return How much left after paying royalties + function _transferRoyalties( + uint256 remainder, + DealSide memory paymentSide, + DealSide memory nftSide + ) internal returns (uint256) { + (, address nftSideRecipient) = _getRecipients(paymentSide, nftSide); + + (address token, uint256 tokenId) = LibAsset.decodeToken(nftSide.asset.assetType); + IRoyaltiesProvider.Part[] memory royalties = royaltiesRegistry.getRoyalties(token, tokenId); + remainder = _applyRoyalties(remainder, paymentSide, remainder, royalties, nftSideRecipient); + + return remainder; + } + /// @notice Apply and transfer royalties based on the asset price and royalties information. /// @param remainder How much of the amount left after previous transfers /// @param paymentSide DealSide of the fee-side order diff --git a/packages/marketplace/test/exchange/Bundle.behavior.ts b/packages/marketplace/test/exchange/Bundle.behavior.ts index 43262dc698..29477680bc 100644 --- a/packages/marketplace/test/exchange/Bundle.behavior.ts +++ b/packages/marketplace/test/exchange/Bundle.behavior.ts @@ -255,18 +255,22 @@ export function shouldMatchOrdersForBundle() { ).to.be.equal(1); expect(await ERC20Contract.balanceOf(makerAddress)).to.be.equal( - 9750000000 // 10000000000 - protocolFee + 9885000000 // 10000000000 - protocolFee ); expect(await ERC20Contract.balanceOf(takerAddress)).to.be.equal( 20000000000 ); - // check protocol fee -> 250 * 10000000000 / 10000 = 250000000 + // TODO : check protocol fee expect( await ERC20Contract.balanceOf(defaultFeeReceiver.getAddress()) ).to.be.equal( - (Number(protocolFeeSecondary) * Number(takerAsset.value)) / 10000 + (Number(protocolFeeSecondary) * + Number(priceDistribution.erc721Prices[0][0]) + + Number(protocolFeeSecondary) * + Number(priceDistribution.erc1155Prices[0][0])) / + 10000 ); }); @@ -428,7 +432,7 @@ export function shouldMatchOrdersForBundle() { ).to.be.equal(1); expect(await ERC20Contract.balanceOf(makerAddress)).to.be.equal( - 9750000000 + 9975000000 ); expect(await ERC20Contract.balanceOf(taker)).to.be.equal(20000000000); @@ -437,7 +441,7 @@ export function shouldMatchOrdersForBundle() { await ERC20Contract.balanceOf(defaultFeeReceiver.getAddress()) ).to.be.equal( (Number(protocolFeeSecondary) * - Number(ERC20AssetForRightOrder.value)) / + Number(priceDistribution.erc1155Prices[0][0])) / 10000 ); @@ -622,13 +626,16 @@ export function shouldMatchOrdersForBundle() { expect(await ERC20Contract.balanceOf(takerAddress)).to.be.equal( 10000000000 ); - expect(await ERC20Contract.balanceOf(maker)).to.be.equal(19500000000); + expect(await ERC20Contract.balanceOf(makerAddress)).to.be.equal( + 19950000000 + ); expect( await ERC20Contract.balanceOf(defaultFeeReceiver.getAddress()) ).to.be.equal( - (Number(protocolFeeSecondary) * - Number(ERC20AssetForRightOrder.value)) / + (2 * + (Number(protocolFeeSecondary) * + Number(priceDistribution.erc1155Prices[0][0]))) / 10000 ); @@ -723,7 +730,7 @@ export function shouldMatchOrdersForBundle() { ).to.be.equal(1); expect(await ERC20Contract.balanceOf(makerAddress)).to.be.equal( - 9750000000 + 9975000000 ); expect(await ERC20Contract.balanceOf(taker)).to.be.equal(20000000000); @@ -731,7 +738,7 @@ export function shouldMatchOrdersForBundle() { await ERC20Contract.balanceOf(defaultFeeReceiver.getAddress()) ).to.be.equal( (Number(protocolFeeSecondary) * - Number(ERC20AssetForRightOrder.value)) / + Number(priceDistribution.erc1155Prices[0][0])) / 10000 ); // 1 * partial fills => 1 * fee taken @@ -776,7 +783,7 @@ export function shouldMatchOrdersForBundle() { ).to.be.equal(1); expect(await ERC20Contract.balanceOf(makerAddress)).to.be.equal( - 19500000000 + 19950000000 ); expect(await ERC20Contract.balanceOf(taker)).to.be.equal(10000000000); 0; @@ -785,7 +792,7 @@ export function shouldMatchOrdersForBundle() { await ERC20Contract.balanceOf(defaultFeeReceiver.getAddress()) ).to.be.equal( (Number(protocolFeeSecondary) * - Number(ERC20AssetForRightOrder.value) * + Number(priceDistribution.erc1155Prices[0][0]) * 2) / 10000 ); // 2 * partial fills => 2 * fee taken @@ -969,18 +976,26 @@ export function shouldMatchOrdersForBundle() { ).to.be.equal(1); expect(await ERC20Contract.balanceOf(makerAddress)).to.be.equal( - 9750000000 // 10000000000 - protocolFee + 9862500000 // 10000000000 - protocolFee ); expect(await ERC20Contract.balanceOf(takerAddress)).to.be.equal( 20000000000 ); - // check protocol fee -> 250 * 10000000000 / 10000 = 250000000 + // check protocol fee expect( await ERC20Contract.balanceOf(await defaultFeeReceiver.getAddress()) ).to.be.equal( - (Number(protocolFeeSecondary) * Number(takerAsset.value)) / 10000 + (Number(protocolFeeSecondary) * + Number(priceDistribution.erc721Prices[0][0]) + + Number(protocolFeeSecondary) * + Number(priceDistribution.erc1155Prices[0][0]) + + Number(protocolFeeSecondary) * + Number(priceDistribution.quadPrices[0]) + + Number(protocolFeeSecondary) * + Number(priceDistribution.quadPrices[1])) / + 10000 ); // check maker received quads @@ -1231,7 +1246,7 @@ export function shouldMatchOrdersForBundle() { ).to.be.equal(1); expect(await ERC20Contract.balanceOf(makerAddress)).to.be.equal( - 8950000000 // 10000000000 - royalty - protocolFee + 9085000000 // 10000000000 - royalty - protocolFee ); expect(await ERC20Contract.balanceOf(takerAddress)).to.be.equal( @@ -1243,11 +1258,15 @@ export function shouldMatchOrdersForBundle() { await ERC20Contract.balanceOf(royaltyReceiver.getAddress()) ).to.be.equal(800000000); // 20% of asset price for ERC721 token - // check protocol fee -> 250 * 10000000000 / 10000 = 250000000 + // check protocol fee expect( await ERC20Contract.balanceOf(defaultFeeReceiver.getAddress()) ).to.be.equal( - (Number(protocolFeeSecondary) * Number(takerAsset.value)) / 10000 + (Number(protocolFeeSecondary) * + Number(priceDistribution.erc721Prices[0][0]) + + Number(protocolFeeSecondary) * + Number(priceDistribution.erc1155Prices[0][0])) / + 10000 ); }); @@ -1350,7 +1369,7 @@ export function shouldMatchOrdersForBundle() { ).to.be.equal(1); expect(await ERC20Contract.balanceOf(makerAddress)).to.be.equal( - 8950000000 // 10000000000 - royalty - protocolFee + 9062500000 // 10000000000 - royalty - protocolFee ); expect(await ERC20Contract.balanceOf(takerAddress)).to.be.equal( 20000000000 @@ -1364,11 +1383,17 @@ export function shouldMatchOrdersForBundle() { await ERC20Contract.balanceOf(royaltyReceiver2.getAddress()) ).to.be.equal(600000000); // 20% of asset price for ERC721 token with id:2 - // check protocol fee -> 250 * 10000000000 / 10000 = 250000000 + // check protocol fee expect( await ERC20Contract.balanceOf(defaultFeeReceiver.getAddress()) ).to.be.equal( - (Number(protocolFeeSecondary) * Number(takerAsset.value)) / 10000 + (Number(protocolFeeSecondary) * + Number(priceDistribution.erc721Prices[0][0]) + + Number(protocolFeeSecondary) * + Number(priceDistribution.erc721Prices[0][1]) + + Number(protocolFeeSecondary) * + Number(priceDistribution.erc1155Prices[0][0])) / + 10000 ); }); @@ -1530,7 +1555,7 @@ export function shouldMatchOrdersForBundle() { ).to.be.equal(1); expect(await ERC20Contract.balanceOf(makerAddress)).to.be.equal( - 9720000000 // 10000000000 - royalty - protocolFee + 9855000000 // 10000000000 - royalty - protocolFee ); expect(await ERC20Contract.balanceOf(takerAddress)).to.be.equal( 20000000000 @@ -1541,11 +1566,15 @@ export function shouldMatchOrdersForBundle() { await ERC20Contract.balanceOf(royaltyReceiver.getAddress()) ).to.be.equal(30000000); // 5% of asset price for ERC1155 token with id:1 - // check protocol fee -> 250 * 10000000000 / 10000 = 250000000 + // check protocol fee expect( await ERC20Contract.balanceOf(defaultFeeReceiver.getAddress()) ).to.be.equal( - (Number(protocolFeeSecondary) * Number(takerAsset.value)) / 10000 + (Number(protocolFeeSecondary) * + Number(priceDistribution.erc721Prices[0][0]) + + Number(protocolFeeSecondary) * + Number(priceDistribution.erc1155Prices[0][0])) / + 10000 ); }); @@ -1657,7 +1686,7 @@ export function shouldMatchOrdersForBundle() { ).to.be.equal(1); expect(await ERC20Contract.balanceOf(makerAddress)).to.be.equal( - 9695000000 // 10000000000 - royalty - protocolFee + 9802500000 // 10000000000 - royalty - protocolFee ); expect(await ERC20Contract.balanceOf(takerAddress)).to.be.equal( @@ -1672,11 +1701,17 @@ export function shouldMatchOrdersForBundle() { await ERC20Contract.balanceOf(royaltyReceiver2.getAddress()) ).to.be.equal(40000000); // 10% of asset price for ERC1155 token with id:2 - // check protocol fee -> 250 * 10000000000 / 10000 = 250000000 + // check protocol fee expect( await ERC20Contract.balanceOf(defaultFeeReceiver.getAddress()) ).to.be.equal( - (Number(protocolFeeSecondary) * Number(takerAsset.value)) / 10000 + (Number(protocolFeeSecondary) * + Number(priceDistribution.erc721Prices[0][0]) + + Number(protocolFeeSecondary) * + Number(priceDistribution.erc1155Prices[0][0]) + + Number(protocolFeeSecondary) * + Number(priceDistribution.erc1155Prices[0][1])) / + 10000 ); }); @@ -1784,7 +1819,7 @@ export function shouldMatchOrdersForBundle() { ).to.be.equal(2); expect(await ERC20Contract.balanceOf(makerAddress)).to.be.equal( - 19300000000 // 10000000000 - royalty - protocolFee + 19750000000 // 10000000000 - royalty - protocolFee ); expect(await ERC20Contract.balanceOf(takerAddress)).to.be.equal( 10000000000 @@ -1798,8 +1833,9 @@ export function shouldMatchOrdersForBundle() { expect( await ERC20Contract.balanceOf(defaultFeeReceiver.getAddress()) ).to.be.equal( - (Number(protocolFeeSecondary) * - Number(ERC20AssetForRightOrder.value)) / + (2 * + (Number(protocolFeeSecondary) * + Number(priceDistribution.erc1155Prices[0][0]))) / 10000 ); @@ -1902,7 +1938,7 @@ export function shouldMatchOrdersForBundle() { ).to.be.equal(1); expect(await ERC20Contract.balanceOf(makerAddress)).to.be.equal( - 9650000000 // 10000000000 - protocolFee - royalty + 9762500000 // 10000000000 - protocolFee - royalty ); expect(await ERC20Contract.balanceOf(takerAddress)).to.be.equal( @@ -1914,11 +1950,19 @@ export function shouldMatchOrdersForBundle() { await ERC20Contract.balanceOf(royaltyReceiver.getAddress()) ).to.be.equal(100000000); // 10% of asset price for quad (3,0) & (0,3) - // check protocol fee -> 250 * 10000000000 / 10000 = 250000000 + // check protocol fee expect( await ERC20Contract.balanceOf(await defaultFeeReceiver.getAddress()) ).to.be.equal( - (Number(protocolFeeSecondary) * Number(takerAsset.value)) / 10000 + (Number(protocolFeeSecondary) * + Number(priceDistribution.erc721Prices[0][0]) + + Number(protocolFeeSecondary) * + Number(priceDistribution.erc1155Prices[0][0]) + + Number(protocolFeeSecondary) * + Number(priceDistribution.quadPrices[0]) + + Number(protocolFeeSecondary) * + Number(priceDistribution.quadPrices[1])) / + 10000 ); // check maker received quads @@ -2032,7 +2076,7 @@ export function shouldMatchOrdersForBundle() { ).to.be.equal(1); expect(await ERC20Contract.balanceOf(makerAddress)).to.be.equal( - 9590000000 // 10000000000 - protocolFee - royalty + 9702500000 // 10000000000 - protocolFee - royalty ); expect(await ERC20Contract.balanceOf(takerAddress)).to.be.equal( 20000000000 @@ -2046,11 +2090,19 @@ export function shouldMatchOrdersForBundle() { await ERC20Contract.balanceOf(royaltyReceiver2.getAddress()) ).to.be.equal(120000000); // 20% of asset price for quad(0,3) - // check protocol fee -> 250 * 10000000000 / 10000 = 250000000 + // check protocol fee expect( await ERC20Contract.balanceOf(await defaultFeeReceiver.getAddress()) ).to.be.equal( - (Number(protocolFeeSecondary) * Number(takerAsset.value)) / 10000 + (Number(protocolFeeSecondary) * + Number(priceDistribution.erc721Prices[0][0]) + + Number(protocolFeeSecondary) * + Number(priceDistribution.erc1155Prices[0][0]) + + Number(protocolFeeSecondary) * + Number(priceDistribution.quadPrices[0]) + + Number(protocolFeeSecondary) * + Number(priceDistribution.quadPrices[1])) / + 10000 ); // check maker received quads @@ -2165,7 +2217,7 @@ export function shouldMatchOrdersForBundle() { ).to.be.equal(1); expect(await ERC20Contract.balanceOf(makerAddress)).to.be.equal( - 9200000000 // 10000000000 - protocolFee - royalty + 9312500000 // 10000000000 - protocolFee - royalty ); expect(await ERC20Contract.balanceOf(takerAddress)).to.be.equal( 20000000000 @@ -2182,11 +2234,19 @@ export function shouldMatchOrdersForBundle() { await ERC20Contract.balanceOf(royaltyReceiver3.getAddress()) ).to.be.equal(400000000); // 10% of asset price for quad (3,0) & (0,3) - // check protocol fee -> 250 * 10000000000 / 10000 = 250000000 + // check protocol fee expect( await ERC20Contract.balanceOf(await defaultFeeReceiver.getAddress()) ).to.be.equal( - (Number(protocolFeeSecondary) * Number(takerAsset.value)) / 10000 + (Number(protocolFeeSecondary) * + Number(priceDistribution.erc721Prices[0][0]) + + Number(protocolFeeSecondary) * + Number(priceDistribution.erc1155Prices[0][0]) + + Number(protocolFeeSecondary) * + Number(priceDistribution.quadPrices[0]) + + Number(protocolFeeSecondary) * + Number(priceDistribution.quadPrices[1])) / + 10000 ); // check maker received quads