From 90ee70f0e4b64b06ae05d5dd053cd9b53a35b9f4 Mon Sep 17 00:00:00 2001 From: Ayush Tiwari Date: Fri, 4 Oct 2024 18:02:16 +0530 Subject: [PATCH] refactor: fixed and added tests for bundle --- .../test/exchange/Bundle.behavior.ts | 163 ++++- .../exchange/BundleWithRoyalties.behaviour.ts | 628 +++++++++++++++--- .../MatchOrdersWithRoyalties.behavior.ts | 8 +- .../exchange/WhitelistingTokens.behavior.ts | 12 +- packages/marketplace/test/fixtures/index.ts | 8 +- 5 files changed, 702 insertions(+), 117 deletions(-) diff --git a/packages/marketplace/test/exchange/Bundle.behavior.ts b/packages/marketplace/test/exchange/Bundle.behavior.ts index c388aa2c97..483cfc65dc 100644 --- a/packages/marketplace/test/exchange/Bundle.behavior.ts +++ b/packages/marketplace/test/exchange/Bundle.behavior.ts @@ -66,7 +66,7 @@ export function shouldMatchOrdersForBundle() { ERC721Contract: Contract, ERC1155Contract: Contract, LandContract: Contract, - protocolFeeSecondary: number, + protocolFeePrimary: number, defaultFeeReceiver: Signer, maker: Signer, taker: Signer, @@ -84,22 +84,31 @@ export function shouldMatchOrdersForBundle() { orderLeft: Order, orderRight: Order, makerSig: string, - takerSig: string; + takerSig: string, + TSB_SECONDARY_MARKET_SELLER_ROLE: string; describe('Bundle x ERC20', function () { beforeEach(async function () { ({ ExchangeContractAsUser, + ExchangeContractAsAdmin, OrderValidatorAsAdmin, ERC20Contract, ERC721Contract, ERC1155Contract, - protocolFeeSecondary, + protocolFeePrimary, defaultFeeReceiver, user1: maker, user2: taker, + TSB_SECONDARY_MARKET_SELLER_ROLE, } = await loadFixture(deployFixtures)); + // grant tsb bundle seller role to seller + await ExchangeContractAsAdmin.grantRole( + TSB_SECONDARY_MARKET_SELLER_ROLE, + await maker.getAddress() + ); + priceDistribution = { erc721Prices: [[4000000000]], erc1155Prices: [[6000000000]], @@ -228,6 +237,107 @@ export function shouldMatchOrdersForBundle() { ).to.be.revertedWith('Bundle price mismatch'); }); + it('should not execute match order between Bundle and Bundle', async function () { + // Set up ERC721 for maker + await ERC721Contract.mint(await maker.getAddress(), 10); + await ERC721Contract.connect(maker).approve( + await ExchangeContractAsUser.getAddress(), + 1 + ); + + // Set up ERC1155 for taker + await ERC1155Contract.mint(await taker.getAddress(), 10, 50); + + await ERC1155Contract.connect(taker).setApprovalForAll( + await ExchangeContractAsUser.getAddress(), + true + ); + + // Construct makerAsset bundle + priceDistribution = { + erc721Prices: [[10000000000]], + erc1155Prices: [[]], + quadPrices: [], + }; + + bundledERC721 = [ + { + erc721Address: ERC721Contract.target, + ids: [10], + }, + ]; + + bundledERC1155 = []; + + const bundleDataLeft: BundleData = { + bundledERC721, + bundledERC1155, + quads, + priceDistribution, + }; + + makerAsset = await AssetBundle(bundleDataLeft, 1); + + // Construct takerAsset bundle + priceDistribution = { + erc721Prices: [[]], + erc1155Prices: [[10000000000]], + quadPrices: [], + }; + + bundledERC721 = []; + + bundledERC1155 = [ + { + erc1155Address: ERC1155Contract.target, + ids: [10], + supplies: [10], + }, + ]; + + const bundleDataRight: BundleData = { + bundledERC721, + bundledERC1155, + quads, + priceDistribution, + }; + + takerAsset = await AssetBundle(bundleDataRight, 1); + + orderLeft = await OrderDefault( + maker, + makerAsset, // Bundle + ZeroAddress, + takerAsset, // Bundle + 1, + 0, + 0 + ); + orderRight = await OrderDefault( + taker, + takerAsset, // Bundle + ZeroAddress, + makerAsset, // Bundle + 1, + 0, + 0 + ); + + makerSig = await signOrder(orderLeft, maker, OrderValidatorAsAdmin); + takerSig = await signOrder(orderRight, taker, OrderValidatorAsAdmin); + + await expect( + ExchangeContractAsUser.matchOrders([ + { + orderLeft, // passing Bundle as left order + signatureLeft: makerSig, + orderRight, // passing Bundle as right order + signatureRight: takerSig, + }, + ]) + ).to.be.revertedWith('exchange not allowed'); + }); + it('should execute a complete match order between ERC20 tokens and Bundle containing ERC20, ERC721 and ERC1155', async function () { orderLeft = await OrderDefault( maker, // ERC20 @@ -288,8 +398,8 @@ export function shouldMatchOrdersForBundle() { ).to.be.equal(1); const protocolFees = { - erc721ProtocolFees: [[protocolFeeSecondary]], - erc1155ProtocolFees: [[protocolFeeSecondary]], + erc721ProtocolFees: [[protocolFeePrimary]], + erc1155ProtocolFees: [[protocolFeePrimary]], quadProtocolFees: [], }; @@ -310,9 +420,9 @@ export function shouldMatchOrdersForBundle() { expect( await ERC20Contract.balanceOf(defaultFeeReceiver.getAddress()) ).to.be.equal( - (Number(protocolFeeSecondary) * + (Number(protocolFeePrimary) * Number(priceDistribution.erc721Prices[0][0]) + - Number(protocolFeeSecondary) * + Number(protocolFeePrimary) * Number(priceDistribution.erc1155Prices[0][0])) / 10000 ); @@ -477,7 +587,7 @@ export function shouldMatchOrdersForBundle() { const protocolFees = { erc721ProtocolFees: [[]], - erc1155ProtocolFees: [[protocolFeeSecondary]], + erc1155ProtocolFees: [[protocolFeePrimary]], quadProtocolFees: [], }; @@ -495,7 +605,7 @@ export function shouldMatchOrdersForBundle() { expect( await ERC20Contract.balanceOf(defaultFeeReceiver.getAddress()) ).to.be.equal( - (Number(protocolFeeSecondary) * + (Number(protocolFeePrimary) * Number(priceDistribution.erc1155Prices[0][0])) / 10000 ); @@ -684,7 +794,7 @@ export function shouldMatchOrdersForBundle() { const protocolFees = { erc721ProtocolFees: [[]], - erc1155ProtocolFees: [[protocolFeeSecondary]], + erc1155ProtocolFees: [[protocolFeePrimary]], quadProtocolFees: [], }; @@ -701,7 +811,7 @@ export function shouldMatchOrdersForBundle() { await ERC20Contract.balanceOf(defaultFeeReceiver.getAddress()) ).to.be.equal( (2 * - (Number(protocolFeeSecondary) * + (Number(protocolFeePrimary) * Number(priceDistribution.erc1155Prices[0][0]))) / 10000 ); @@ -798,7 +908,7 @@ export function shouldMatchOrdersForBundle() { const protocolFees = { erc721ProtocolFees: [[]], - erc1155ProtocolFees: [[protocolFeeSecondary]], + erc1155ProtocolFees: [[protocolFeePrimary]], quadProtocolFees: [], }; @@ -815,7 +925,7 @@ export function shouldMatchOrdersForBundle() { expect( await ERC20Contract.balanceOf(defaultFeeReceiver.getAddress()) ).to.be.equal( - (Number(protocolFeeSecondary) * + (Number(protocolFeePrimary) * Number(priceDistribution.erc1155Prices[0][0])) / 10000 ); // 1 * partial fills => 1 * fee taken @@ -869,7 +979,7 @@ export function shouldMatchOrdersForBundle() { expect( await ERC20Contract.balanceOf(defaultFeeReceiver.getAddress()) ).to.be.equal( - (Number(protocolFeeSecondary) * + (Number(protocolFeePrimary) * Number(priceDistribution.erc1155Prices[0][0]) * 2) / 10000 @@ -893,15 +1003,22 @@ export function shouldMatchOrdersForBundle() { ERC20Contract, ERC721Contract, ERC1155Contract, - protocolFeeSecondary, + protocolFeePrimary, defaultFeeReceiver, user1: maker, user2: taker, LandContract, LandAsAdmin, landAdmin, + TSB_SECONDARY_MARKET_SELLER_ROLE, } = await loadFixture(deployFixtures)); + // grant tsb bundle seller role to seller + await ExchangeContractAsAdmin.grantRole( + TSB_SECONDARY_MARKET_SELLER_ROLE, + await maker.getAddress() + ); + priceDistribution = { erc721Prices: [[4000000000]], // price distribution without ERC721 erc1155Prices: [[5000000000]], @@ -971,7 +1088,7 @@ export function shouldMatchOrdersForBundle() { data: '0x', }; - // Create bundle for passing as right order + // Create bundle for passing as left order bundleData = { bundledERC721, bundledERC1155, @@ -1053,9 +1170,9 @@ export function shouldMatchOrdersForBundle() { ).to.be.equal(1); const protocolFees = { - erc721ProtocolFees: [[protocolFeeSecondary]], - erc1155ProtocolFees: [[protocolFeeSecondary]], - quadProtocolFees: [protocolFeeSecondary, protocolFeeSecondary], + erc721ProtocolFees: [[protocolFeePrimary]], + erc1155ProtocolFees: [[protocolFeePrimary]], + quadProtocolFees: [protocolFeePrimary, protocolFeePrimary], }; const expectedFinalReturn = calculateFinalPrice( @@ -1075,13 +1192,13 @@ export function shouldMatchOrdersForBundle() { expect( await ERC20Contract.balanceOf(await defaultFeeReceiver.getAddress()) ).to.be.equal( - (Number(protocolFeeSecondary) * + (Number(protocolFeePrimary) * Number(priceDistribution.erc721Prices[0][0]) + - Number(protocolFeeSecondary) * + Number(protocolFeePrimary) * Number(priceDistribution.erc1155Prices[0][0]) + - Number(protocolFeeSecondary) * + Number(protocolFeePrimary) * Number(priceDistribution.quadPrices[0]) + - Number(protocolFeeSecondary) * + Number(protocolFeePrimary) * Number(priceDistribution.quadPrices[1])) / 10000 ); diff --git a/packages/marketplace/test/exchange/BundleWithRoyalties.behaviour.ts b/packages/marketplace/test/exchange/BundleWithRoyalties.behaviour.ts index 5798db01fa..53381af9fd 100644 --- a/packages/marketplace/test/exchange/BundleWithRoyalties.behaviour.ts +++ b/packages/marketplace/test/exchange/BundleWithRoyalties.behaviour.ts @@ -85,7 +85,6 @@ export function shouldMatchOrdersForBundleWithRoyalty() { RoyaltiesProvider: Contract, LandAsAdmin: Contract, QuadHelper: Contract, - protocolFeeSecondary: number, protocolFeePrimary: number, defaultFeeReceiver: Signer, maker: Signer, @@ -107,7 +106,8 @@ export function shouldMatchOrdersForBundleWithRoyalty() { orderRight: Order, makerSig: string, takerSig: string, - TSB_SELLER_ROLE: string; + TSB_PRIMARY_MARKET_SELLER_ROLE: string, + TSB_SECONDARY_MARKET_SELLER_ROLE: string; describe('Bundle in primary market', function () { beforeEach(async function () { @@ -116,20 +116,23 @@ export function shouldMatchOrdersForBundleWithRoyalty() { ExchangeContractAsAdmin, OrderValidatorAsAdmin, RoyaltiesRegistryAsDeployer, + LandAsAdmin, ERC20Contract, ERC721Contract, ERC721WithRoyaltyV2981, ERC1155Contract, ERC1155WithRoyaltyV2981, + LandContract, RoyaltiesProvider, protocolFeePrimary, - protocolFeeSecondary, defaultFeeReceiver, deployer: maker, user2: taker, admin: royaltyReceiver, user: royaltyReceiver2, - TSB_SELLER_ROLE, + landAdmin, + TSB_PRIMARY_MARKET_SELLER_ROLE, + TSB_SECONDARY_MARKET_SELLER_ROLE, } = await loadFixture(deployFixtures)); priceDistribution = { @@ -172,6 +175,31 @@ export function shouldMatchOrdersForBundleWithRoyalty() { true ); + // Make sure the land contract address is set on the Exchange + const landContractAddress = await LandContract.getAddress(); + await ExchangeContractAsAdmin.setLandContract(landContractAddress); + + // Land contract setup for maker ------------------------------------------------------------- + + // Set a minter + await LandAsAdmin.setMinter(await landAdmin.getAddress(), true); + + // Ensure that the marketplace contract is an approved operator for mock land contract + await LandContract.connect(maker).setApprovalForAllWithOutFilter( + await ExchangeContractAsUser.getAddress(), + true + ); + + await LandAsAdmin.mintQuad(await maker.getAddress(), 3, 0, 0, '0x'); + await LandAsAdmin.mintQuad(await maker.getAddress(), 3, 0, 3, '0x'); + await LandAsAdmin.mintQuad(await maker.getAddress(), 3, 3, 0, '0x'); + await LandAsAdmin.mintQuad(await maker.getAddress(), 3, 3, 3, '0x'); + expect( + await LandContract.balanceOf(await maker.getAddress()) + ).to.be.equal(36); + + // End land setup for maker ------------------------------------------------------------------ + // Set up ERC20 for taker await ERC20Contract.mint(await taker.getAddress(), 30000000000); await ERC20Contract.connect(taker).approve( @@ -183,7 +211,187 @@ export function shouldMatchOrdersForBundleWithRoyalty() { takerAsset = await AssetERC20(ERC20Contract, 10000000000); }); - it('should execute complete match order for bundle without royalties but with primary market fees for address with TSB_SELLER_ROLE', async function () { + it('should execute complete match order for bundle with ERC721, ERC1155 & Quads in primary market without royalty for TSB_PRIMARY_MARKET_SELLER', async function () { + // Construct makerAsset bundle + bundledERC721 = [ + { + erc721Address: ERC721Contract.target, + ids: [1], + }, + ]; + + bundledERC1155 = [ + { + erc1155Address: ERC1155Contract.target, + ids: [1], + supplies: [10], + }, + ]; + + quads = { + sizes: [3, 3], // 3x3, 3x3 = 9+9 lands total + xs: [3, 0], + ys: [0, 3], + data: '0x', + }; + + priceDistribution = { + erc721Prices: [[4000000000]], + erc1155Prices: [[5000000000]], + quadPrices: [400000000, 600000000], + }; + + // Create bundle for passing as left order + bundleData = { + bundledERC721, + bundledERC1155, + quads, + priceDistribution, + }; + + makerAsset = await AssetBundle(bundleData, 1); + + // set up royalties by token for ERC721 token + await RoyaltiesRegistryAsDeployer.setRoyaltiesByToken( + await ERC721Contract.getAddress(), + [await LibPartData(royaltyReceiver, 1000)] // 10% royalty for ERC721 token + ); + + // configuring royalties for ERC1155 tokens + await RoyaltiesProvider.initializeProvider( + await ERC1155Contract.getAddress(), + 1, + [await LibPartData(royaltyReceiver, 1000)] // 10% royalty for ERC1155 token with id 1 + ); + await RoyaltiesRegistryAsDeployer.setProviderByToken( + await ERC1155Contract.getAddress(), + RoyaltiesProvider.getAddress() + ); + + // set up royalties by token for quad + await RoyaltiesRegistryAsDeployer.setRoyaltiesByToken( + await LandAsAdmin.getAddress(), + [await LibPartData(royaltyReceiver, 1000)] // 10% royalty for Land token + ); + + // grant tsb primary market seller role to maker + await ExchangeContractAsAdmin.grantRole( + TSB_PRIMARY_MARKET_SELLER_ROLE, + await maker.getAddress() + ); + + orderLeft = await OrderDefault( + maker, + makerAsset, // Bundle + ZeroAddress, + takerAsset, // ERC20 + 1, + 0, + 0 + ); + orderRight = await OrderDefault( + taker, + takerAsset, // ERC20 + ZeroAddress, + makerAsset, // Bundle + 1, + 0, + 0 + ); + + makerSig = await signOrder(orderLeft, maker, OrderValidatorAsAdmin); + takerSig = await signOrder(orderRight, taker, OrderValidatorAsAdmin); + + const makerAddress = await maker.getAddress(); + const takerAddress = await taker.getAddress(); + + expect(await ERC721Contract.ownerOf(1)).to.be.equal(makerAddress); + expect(await ERC20Contract.balanceOf(makerAddress)).to.be.equal(0); + expect(await ERC20Contract.balanceOf(takerAddress)).to.be.equal( + 30000000000 + ); + + expect(await ERC1155Contract.balanceOf(makerAddress, 1)).to.be.equal( + 50 + ); + expect(await ERC1155Contract.balanceOf(takerAddress, 1)).to.be.equal(0); + + await ExchangeContractAsAdmin.matchOrders([ + { + orderLeft, // passing Bundle as left order + signatureLeft: makerSig, + orderRight, // passing ERC20 as right order + signatureRight: takerSig, + }, + ]); + + expect(await ERC721Contract.ownerOf(1)).to.be.equal(takerAddress); + expect(await ERC1155Contract.balanceOf(makerAddress, 1)).to.be.equal( + 40 + ); + expect(await ERC1155Contract.balanceOf(takerAddress, 1)).to.be.equal( + 10 + ); + + expect( + await ExchangeContractAsUser.fills(hashKey(orderLeft)) + ).to.be.equal(10000000000); + expect( + await ExchangeContractAsUser.fills(hashKey(orderRight)) + ).to.be.equal(1); + + const protocolFees = { + erc721ProtocolFees: [[protocolFeePrimary]], + erc1155ProtocolFees: [[protocolFeePrimary]], + quadProtocolFees: [protocolFeePrimary, protocolFeePrimary], + }; + + const royaltyFees = { + erc721RoyaltyFees: [[0]], + erc1155RoyaltyFees: [[0]], + quadRoyaltyFees: [0, 0], + }; + + const expectedFinalReturn = calculateFinalPrice( + priceDistribution, + protocolFees, + royaltyFees + ); + + expect(await ERC20Contract.balanceOf(makerAddress)).to.be.equal( + expectedFinalReturn // 10000000000 - protocolFee - royalty + ); + + expect(await ERC20Contract.balanceOf(takerAddress)).to.be.equal( + 20000000000 + ); + + // no royalties paid + expect( + await ERC20Contract.balanceOf(royaltyReceiver.getAddress()) + ).to.be.equal(0); + + // check protocol fee + expect( + await ERC20Contract.balanceOf(await defaultFeeReceiver.getAddress()) + ).to.be.equal( + (Number(protocolFeePrimary) * + Number(priceDistribution.erc721Prices[0][0]) + + Number(protocolFeePrimary) * + Number(priceDistribution.erc1155Prices[0][0]) + + Number(protocolFeePrimary) * + Number(priceDistribution.quadPrices[0]) + + Number(protocolFeePrimary) * + Number(priceDistribution.quadPrices[1])) / + 10000 + ); + + // check maker received quads + expect(await LandContract.balanceOf(takerAddress)).to.be.equal(18); + expect(await LandContract.balanceOf(makerAddress)).to.be.equal(18); + }); + + it('should not execute match order for bundle with ERC721 & ERC1155 for regular user in secondary market', async function () { // Construct makerAsset bundle bundledERC721 = [ { @@ -207,7 +415,7 @@ export function shouldMatchOrdersForBundleWithRoyalty() { data: '0x', }; // empty quads - // Create bundle for passing as right order + // Create bundle for passing as left order bundleData = { bundledERC721, bundledERC1155, @@ -235,12 +443,6 @@ export function shouldMatchOrdersForBundleWithRoyalty() { RoyaltiesProvider.getAddress() ); - // grant tsb seller role to seller - await ExchangeContractAsAdmin.grantRole( - TSB_SELLER_ROLE, - await maker.getAddress() - ); - orderLeft = await OrderDefault( maker, makerAsset, // Bundle @@ -277,6 +479,220 @@ export function shouldMatchOrdersForBundleWithRoyalty() { ); expect(await ERC1155Contract.balanceOf(takerAddress, 1)).to.be.equal(0); + await expect( + ExchangeContractAsUser.matchOrders([ + { + orderLeft, // passing Bundle as left order + signatureLeft: makerSig, + orderRight, // passing ERC20 as right order + signatureRight: takerSig, + }, + ]) + ).to.be.revertedWith('not TSB secondary market seller'); + }); + + it('should not execute match order for bundle with quad for creator', async function () { + // Construct makerAsset bundle + bundledERC721 = [ + { + erc721Address: ERC721WithRoyaltyV2981.target, + ids: [1], + }, + ]; + + bundledERC1155 = [ + { + erc1155Address: ERC1155WithRoyaltyV2981.target, + ids: [1], + supplies: [10], + }, + ]; + + quads = { + sizes: [3, 3], + xs: [3, 0], + ys: [0, 3], + data: '0x', + }; // non empty quads + + priceDistribution = { + erc721Prices: [[4000000000]], + erc1155Prices: [[5000000000]], + quadPrices: [400000000, 600000000], + }; + + // Create bundle for passing as left order + bundleData = { + bundledERC721, + bundledERC1155, + quads, + priceDistribution, + }; + + makerAsset = await AssetBundle(bundleData, 1); // there can only ever be 1 copy of a bundle that contains ERC721 + + // set up royalties by token + await RoyaltiesRegistryAsDeployer.setRoyaltiesByToken( + await ERC721WithRoyaltyV2981.getAddress(), + [await LibPartData(royaltyReceiver, 1000)] // 10% royalty for ERC721 token + ); + + // configuring royalties + await RoyaltiesProvider.initializeProvider( + await ERC1155WithRoyaltyV2981.getAddress(), + 1, + [await LibPartData(royaltyReceiver, 1000)] // 10% royalty for ERC1155 token with id:1 + ); + + await RoyaltiesRegistryAsDeployer.setProviderByToken( + await ERC1155Contract.getAddress(), + RoyaltiesProvider.getAddress() + ); + + orderLeft = await OrderDefault( + maker, + makerAsset, // Bundle + ZeroAddress, + takerAsset, // ERC20 + 1, + 0, + 0 + ); + orderRight = await OrderDefault( + taker, + takerAsset, // ERC20 + ZeroAddress, + makerAsset, // Bundle + 1, + 0, + 0 + ); + + makerSig = await signOrder(orderLeft, maker, OrderValidatorAsAdmin); + takerSig = await signOrder(orderRight, taker, OrderValidatorAsAdmin); + + const makerAddress = await maker.getAddress(); + const takerAddress = await taker.getAddress(); + + expect(await ERC20Contract.balanceOf(makerAddress)).to.be.equal(0); + expect(await ERC20Contract.balanceOf(takerAddress)).to.be.equal( + 30000000000 + ); + + expect(await ERC721WithRoyaltyV2981.ownerOf(1)).to.be.equal( + makerAddress + ); + expect( + await ERC1155WithRoyaltyV2981.balanceOf(makerAddress, 1) + ).to.be.equal(50); + expect( + await ERC1155WithRoyaltyV2981.balanceOf(takerAddress, 1) + ).to.be.equal(0); + + await expect( + ExchangeContractAsUser.matchOrders([ + { + orderLeft, // passing Bundle as left order + signatureLeft: makerSig, + orderRight, // passing ERC20 as right order + signatureRight: takerSig, + }, + ]) + ).to.be.revertedWith('not TSB secondary market seller'); + }); + + it('should execute complete match order for bundle with ERC721 & ERC1155 assets without royalties but with primary market fees for creator', async function () { + // Construct makerAsset bundle + bundledERC721 = [ + { + erc721Address: ERC721WithRoyaltyV2981.target, + ids: [1], + }, + ]; + + bundledERC1155 = [ + { + erc1155Address: ERC1155WithRoyaltyV2981.target, + ids: [1], + supplies: [10], + }, + ]; + + quads = { + sizes: [], + xs: [], + ys: [], + data: '0x', + }; // empty quads + + // Create bundle for passing as left order + bundleData = { + bundledERC721, + bundledERC1155, + quads, + priceDistribution, + }; + + makerAsset = await AssetBundle(bundleData, 1); // there can only ever be 1 copy of a bundle that contains ERC721 + + // set up royalties by token + await RoyaltiesRegistryAsDeployer.setRoyaltiesByToken( + await ERC721WithRoyaltyV2981.getAddress(), + [await LibPartData(royaltyReceiver, 1000)] // 10% royalty for ERC721 token + ); + + // configuring royalties + await RoyaltiesProvider.initializeProvider( + await ERC1155WithRoyaltyV2981.getAddress(), + 1, + [await LibPartData(royaltyReceiver, 1000)] // 10% royalty for ERC1155 token with id:1 + ); + + await RoyaltiesRegistryAsDeployer.setProviderByToken( + await ERC1155Contract.getAddress(), + RoyaltiesProvider.getAddress() + ); + + orderLeft = await OrderDefault( + maker, + makerAsset, // Bundle + ZeroAddress, + takerAsset, // ERC20 + 1, + 0, + 0 + ); + orderRight = await OrderDefault( + taker, + takerAsset, // ERC20 + ZeroAddress, + makerAsset, // Bundle + 1, + 0, + 0 + ); + + makerSig = await signOrder(orderLeft, maker, OrderValidatorAsAdmin); + takerSig = await signOrder(orderRight, taker, OrderValidatorAsAdmin); + + const makerAddress = await maker.getAddress(); + const takerAddress = await taker.getAddress(); + + expect(await ERC20Contract.balanceOf(makerAddress)).to.be.equal(0); + expect(await ERC20Contract.balanceOf(takerAddress)).to.be.equal( + 30000000000 + ); + + expect(await ERC721WithRoyaltyV2981.ownerOf(1)).to.be.equal( + makerAddress + ); + expect( + await ERC1155WithRoyaltyV2981.balanceOf(makerAddress, 1) + ).to.be.equal(50); + expect( + await ERC1155WithRoyaltyV2981.balanceOf(takerAddress, 1) + ).to.be.equal(0); + await ExchangeContractAsUser.matchOrders([ { orderLeft, // passing Bundle as left order @@ -286,13 +702,15 @@ export function shouldMatchOrdersForBundleWithRoyalty() { }, ]); - expect(await ERC721Contract.ownerOf(1)).to.be.equal(takerAddress); - expect(await ERC1155Contract.balanceOf(makerAddress, 1)).to.be.equal( - 40 - ); - expect(await ERC1155Contract.balanceOf(takerAddress, 1)).to.be.equal( - 10 + expect(await ERC721WithRoyaltyV2981.ownerOf(1)).to.be.equal( + takerAddress ); + expect( + await ERC1155WithRoyaltyV2981.balanceOf(makerAddress, 1) + ).to.be.equal(40); + expect( + await ERC1155WithRoyaltyV2981.balanceOf(takerAddress, 1) + ).to.be.equal(10); expect( await ExchangeContractAsUser.fills(hashKey(orderLeft)) @@ -340,7 +758,7 @@ export function shouldMatchOrdersForBundleWithRoyalty() { ).to.be.equal(0); }); - it('should execute complete match order for bundle with ERC721 asset in primary market and ERC1155 asset in secondry market', async function () { + it('should execute complete match order for bundle with ERC721 asset in primary market and ERC1155 asset in secondary market for TSB_SECONDARY_MARKET_SELLER', async function () { // Construct makerAsset bundle bundledERC721 = [ { @@ -364,7 +782,7 @@ export function shouldMatchOrdersForBundleWithRoyalty() { data: '0x', }; // empty quads - // Create bundle for passing as right order + // Create bundle for passing as left order bundleData = { bundledERC721, bundledERC1155, @@ -374,6 +792,12 @@ export function shouldMatchOrdersForBundleWithRoyalty() { makerAsset = await AssetBundle(bundleData, 1); // there can only ever be 1 copy of a bundle that contains ERC721 + // set up royalties by token + await RoyaltiesRegistryAsDeployer.setRoyaltiesByToken( + await ERC721WithRoyaltyV2981.getAddress(), + [await LibPartData(royaltyReceiver, 1000)] // 10% royalty for ERC721 token + ); + // configuring royalties await RoyaltiesProvider.initializeProvider( await ERC1155Contract.getAddress(), @@ -386,6 +810,12 @@ export function shouldMatchOrdersForBundleWithRoyalty() { RoyaltiesProvider.getAddress() ); + // grant tsb secondary market seller role to maker + await ExchangeContractAsAdmin.grantRole( + TSB_SECONDARY_MARKET_SELLER_ROLE, + await maker.getAddress() + ); + orderLeft = await OrderDefault( maker, makerAsset, // Bundle @@ -424,7 +854,7 @@ export function shouldMatchOrdersForBundleWithRoyalty() { ); expect(await ERC1155Contract.balanceOf(takerAddress, 1)).to.be.equal(0); - await ExchangeContractAsUser.matchOrders([ + await ExchangeContractAsAdmin.matchOrders([ { orderLeft, // passing Bundle as left order signatureLeft: makerSig, @@ -452,7 +882,7 @@ export function shouldMatchOrdersForBundleWithRoyalty() { const protocolFees = { erc721ProtocolFees: [[protocolFeePrimary]], - erc1155ProtocolFees: [[protocolFeeSecondary]], + erc1155ProtocolFees: [[protocolFeePrimary]], quadProtocolFees: [], }; @@ -482,7 +912,7 @@ export function shouldMatchOrdersForBundleWithRoyalty() { ).to.be.equal( (Number(protocolFeePrimary) * Number(priceDistribution.erc721Prices[0][0]) + - Number(protocolFeeSecondary) * + Number(protocolFeePrimary) * Number(priceDistribution.erc1155Prices[0][0])) / 10000 ); @@ -493,7 +923,7 @@ export function shouldMatchOrdersForBundleWithRoyalty() { ).to.be.equal(600000000); // 10% of asset price for ERC1155 token with id:1 }); - it('should execute complete match order for bundle with ERC721 asset in secondry market and ERC1155 asset in primary market', async function () { + it('should execute complete match order for bundle with ERC721 asset in secondary market and ERC1155 asset in primary market for TSB_SECONDARY_MARKET_SELLER', async function () { // Construct makerAsset bundle bundledERC721 = [ { @@ -517,7 +947,7 @@ export function shouldMatchOrdersForBundleWithRoyalty() { data: '0x', }; // empty quads - // Create bundle for passing as right order + // Create bundle for passing as left order bundleData = { bundledERC721, bundledERC1155, @@ -533,6 +963,24 @@ export function shouldMatchOrdersForBundleWithRoyalty() { [await LibPartData(royaltyReceiver, 1000)] // 10% royalty for ERC721 token ); + // configuring royalties + await RoyaltiesProvider.initializeProvider( + await ERC1155WithRoyaltyV2981.getAddress(), + 1, + [await LibPartData(royaltyReceiver, 1000)] // 10% royalty for ERC1155 token with id:1 + ); + + await RoyaltiesRegistryAsDeployer.setProviderByToken( + await ERC1155WithRoyaltyV2981.getAddress(), + RoyaltiesProvider.getAddress() + ); + + // grant tsb secondary market seller role to maker + await ExchangeContractAsAdmin.grantRole( + TSB_SECONDARY_MARKET_SELLER_ROLE, + await maker.getAddress() + ); + orderLeft = await OrderDefault( maker, makerAsset, // Bundle @@ -571,7 +1019,7 @@ export function shouldMatchOrdersForBundleWithRoyalty() { await ERC1155WithRoyaltyV2981.balanceOf(takerAddress, 1) ).to.be.equal(0); - await ExchangeContractAsUser.matchOrders([ + await ExchangeContractAsAdmin.matchOrders([ { orderLeft, // passing Bundle as left order signatureLeft: makerSig, @@ -596,7 +1044,7 @@ export function shouldMatchOrdersForBundleWithRoyalty() { ).to.be.equal(1); const protocolFees = { - erc721ProtocolFees: [[protocolFeeSecondary]], + erc721ProtocolFees: [[protocolFeePrimary]], erc1155ProtocolFees: [[protocolFeePrimary]], quadProtocolFees: [], }; @@ -625,7 +1073,7 @@ export function shouldMatchOrdersForBundleWithRoyalty() { expect( await ERC20Contract.balanceOf(defaultFeeReceiver.getAddress()) ).to.be.equal( - (Number(protocolFeeSecondary) * + (Number(protocolFeePrimary) * Number(priceDistribution.erc721Prices[0][0]) + Number(protocolFeePrimary) * Number(priceDistribution.erc1155Prices[0][0])) / @@ -646,23 +1094,30 @@ export function shouldMatchOrdersForBundleWithRoyalty() { ExchangeContractAsAdmin, OrderValidatorAsAdmin, RoyaltiesRegistryAsDeployer, + LandAsAdmin, ERC20Contract, ERC721Contract, ERC1155Contract, + LandContract, RoyaltiesProvider, QuadHelper, - protocolFeeSecondary, + protocolFeePrimary, defaultFeeReceiver, user1: maker, user2: taker, deployer: royaltyReceiver, admin: royaltyReceiver2, user: royaltyReceiver3, - LandContract, - LandAsAdmin, landAdmin, + TSB_SECONDARY_MARKET_SELLER_ROLE, } = await loadFixture(deployFixtures)); + // grant tsb secondary market seller role to maker + await ExchangeContractAsAdmin.grantRole( + TSB_SECONDARY_MARKET_SELLER_ROLE, + await maker.getAddress() + ); + priceDistribution = { erc721Prices: [[4000000000]], erc1155Prices: [[6000000000]], @@ -738,7 +1193,7 @@ export function shouldMatchOrdersForBundleWithRoyalty() { data: '0x', }; // empty quads - // Create bundle for passing as right order + // Create bundle for passing as left order bundleData = { bundledERC721, bundledERC1155, @@ -802,7 +1257,7 @@ export function shouldMatchOrdersForBundleWithRoyalty() { expect(await ERC1155Contract.balanceOf(takerAddress, 1)).to.be.equal(0); await expect( - ExchangeContractAsUser.matchOrders([ + ExchangeContractAsAdmin.matchOrders([ { orderLeft, // passing Bundle as left order signatureLeft: makerSig, @@ -856,7 +1311,7 @@ export function shouldMatchOrdersForBundleWithRoyalty() { ); expect(await ERC1155Contract.balanceOf(takerAddress, 1)).to.be.equal(0); - await ExchangeContractAsUser.matchOrders([ + await ExchangeContractAsAdmin.matchOrders([ { orderLeft, // passing Bundle as left order signatureLeft: makerSig, @@ -881,8 +1336,8 @@ export function shouldMatchOrdersForBundleWithRoyalty() { ).to.be.equal(1); const protocolFees = { - erc721ProtocolFees: [[protocolFeeSecondary]], - erc1155ProtocolFees: [[protocolFeeSecondary]], + erc721ProtocolFees: [[protocolFeePrimary]], + erc1155ProtocolFees: [[protocolFeePrimary]], quadProtocolFees: [], }; @@ -905,7 +1360,6 @@ export function shouldMatchOrdersForBundleWithRoyalty() { expect(await ERC20Contract.balanceOf(takerAddress)).to.be.equal( 20000000000 ); - // check paid royalty expect( await ERC20Contract.balanceOf(royaltyReceiver.getAddress()) @@ -915,9 +1369,9 @@ export function shouldMatchOrdersForBundleWithRoyalty() { expect( await ERC20Contract.balanceOf(defaultFeeReceiver.getAddress()) ).to.be.equal( - (Number(protocolFeeSecondary) * + (Number(protocolFeePrimary) * Number(priceDistribution.erc721Prices[0][0]) + - Number(protocolFeeSecondary) * + Number(protocolFeePrimary) * Number(priceDistribution.erc1155Prices[0][0])) / 10000 ); @@ -997,7 +1451,7 @@ export function shouldMatchOrdersForBundleWithRoyalty() { ); expect(await ERC1155Contract.balanceOf(takerAddress, 1)).to.be.equal(0); - await ExchangeContractAsUser.matchOrders([ + await ExchangeContractAsAdmin.matchOrders([ { orderLeft, // passing Bundle as left order signatureLeft: makerSig, @@ -1022,8 +1476,8 @@ export function shouldMatchOrdersForBundleWithRoyalty() { ).to.be.equal(1); const protocolFees = { - erc721ProtocolFees: [[protocolFeeSecondary, protocolFeeSecondary]], - erc1155ProtocolFees: [[protocolFeeSecondary]], + erc721ProtocolFees: [[protocolFeePrimary, protocolFeePrimary]], + erc1155ProtocolFees: [[protocolFeePrimary]], quadProtocolFees: [], }; @@ -1058,11 +1512,11 @@ export function shouldMatchOrdersForBundleWithRoyalty() { expect( await ERC20Contract.balanceOf(defaultFeeReceiver.getAddress()) ).to.be.equal( - (Number(protocolFeeSecondary) * + (Number(protocolFeePrimary) * Number(priceDistribution.erc721Prices[0][0]) + - Number(protocolFeeSecondary) * + Number(protocolFeePrimary) * Number(priceDistribution.erc721Prices[0][1]) + - Number(protocolFeeSecondary) * + Number(protocolFeePrimary) * Number(priceDistribution.erc1155Prices[0][0])) / 10000 ); @@ -1133,7 +1587,7 @@ export function shouldMatchOrdersForBundleWithRoyalty() { expect(await ERC1155Contract.balanceOf(takerAddress, 1)).to.be.equal(0); await expect( - ExchangeContractAsUser.matchOrders([ + ExchangeContractAsAdmin.matchOrders([ { orderLeft, // passing Bundle as left order signatureLeft: makerSig, @@ -1201,7 +1655,7 @@ export function shouldMatchOrdersForBundleWithRoyalty() { ); expect(await ERC1155Contract.balanceOf(takerAddress, 1)).to.be.equal(0); - await ExchangeContractAsUser.matchOrders([ + await ExchangeContractAsAdmin.matchOrders([ { orderLeft, // passing Bundle as left order signatureLeft: makerSig, @@ -1226,8 +1680,8 @@ export function shouldMatchOrdersForBundleWithRoyalty() { ).to.be.equal(1); const protocolFees = { - erc721ProtocolFees: [[protocolFeeSecondary]], - erc1155ProtocolFees: [[protocolFeeSecondary]], + erc721ProtocolFees: [[protocolFeePrimary]], + erc1155ProtocolFees: [[protocolFeePrimary]], quadProtocolFees: [], }; @@ -1259,9 +1713,9 @@ export function shouldMatchOrdersForBundleWithRoyalty() { expect( await ERC20Contract.balanceOf(defaultFeeReceiver.getAddress()) ).to.be.equal( - (Number(protocolFeeSecondary) * + (Number(protocolFeePrimary) * Number(priceDistribution.erc721Prices[0][0]) + - Number(protocolFeeSecondary) * + Number(protocolFeePrimary) * Number(priceDistribution.erc1155Prices[0][0])) / 10000 ); @@ -1346,7 +1800,7 @@ export function shouldMatchOrdersForBundleWithRoyalty() { expect(await ERC1155Contract.balanceOf(takerAddress, 1)).to.be.equal(0); expect(await ERC1155Contract.balanceOf(takerAddress, 2)).to.be.equal(0); - await ExchangeContractAsUser.matchOrders([ + await ExchangeContractAsAdmin.matchOrders([ { orderLeft, // passing Bundle as left order signatureLeft: makerSig, @@ -1375,8 +1829,8 @@ export function shouldMatchOrdersForBundleWithRoyalty() { ).to.be.equal(1); const protocolFees = { - erc721ProtocolFees: [[protocolFeeSecondary]], - erc1155ProtocolFees: [[protocolFeeSecondary, protocolFeeSecondary]], + erc721ProtocolFees: [[protocolFeePrimary]], + erc1155ProtocolFees: [[protocolFeePrimary, protocolFeePrimary]], quadProtocolFees: [], }; @@ -1412,11 +1866,11 @@ export function shouldMatchOrdersForBundleWithRoyalty() { expect( await ERC20Contract.balanceOf(defaultFeeReceiver.getAddress()) ).to.be.equal( - (Number(protocolFeeSecondary) * + (Number(protocolFeePrimary) * Number(priceDistribution.erc721Prices[0][0]) + - Number(protocolFeeSecondary) * + Number(protocolFeePrimary) * Number(priceDistribution.erc1155Prices[0][0]) + - Number(protocolFeeSecondary) * + Number(protocolFeePrimary) * Number(priceDistribution.erc1155Prices[0][1])) / 10000 ); @@ -1509,7 +1963,7 @@ export function shouldMatchOrdersForBundleWithRoyalty() { await ExchangeContractAsUser.fills(hashKey(orderRight)) ).to.be.equal(0); - await ExchangeContractAsUser.matchOrders([ + await ExchangeContractAsAdmin.matchOrders([ { orderLeft, signatureLeft: makerSig, @@ -1527,7 +1981,7 @@ export function shouldMatchOrdersForBundleWithRoyalty() { const protocolFees = { erc721ProtocolFees: [[]], - erc1155ProtocolFees: [[protocolFeeSecondary]], + erc1155ProtocolFees: [[protocolFeePrimary]], quadProtocolFees: [], }; @@ -1559,7 +2013,7 @@ export function shouldMatchOrdersForBundleWithRoyalty() { await ERC20Contract.balanceOf(defaultFeeReceiver.getAddress()) ).to.be.equal( (2 * - (Number(protocolFeeSecondary) * + (Number(protocolFeePrimary) * Number(priceDistribution.erc1155Prices[0][0]))) / 10000 ); @@ -1586,7 +2040,7 @@ export function shouldMatchOrdersForBundleWithRoyalty() { quadPrices: [400000000, 600000000], }; - // Create bundle for passing as right order + // Create bundle for passing as left order bundleData = { bundledERC721, bundledERC1155, @@ -1638,7 +2092,7 @@ export function shouldMatchOrdersForBundleWithRoyalty() { ); expect(await ERC1155Contract.balanceOf(takerAddress, 1)).to.be.equal(0); - await ExchangeContractAsUser.matchOrders([ + await ExchangeContractAsAdmin.matchOrders([ { orderLeft, // passing Bundle as left order signatureLeft: makerSig, @@ -1663,9 +2117,9 @@ export function shouldMatchOrdersForBundleWithRoyalty() { ).to.be.equal(1); const protocolFees = { - erc721ProtocolFees: [[protocolFeeSecondary]], - erc1155ProtocolFees: [[protocolFeeSecondary]], - quadProtocolFees: [protocolFeeSecondary, protocolFeeSecondary], + erc721ProtocolFees: [[protocolFeePrimary]], + erc1155ProtocolFees: [[protocolFeePrimary]], + quadProtocolFees: [protocolFeePrimary, protocolFeePrimary], }; const royaltyFees = { @@ -1697,13 +2151,13 @@ export function shouldMatchOrdersForBundleWithRoyalty() { expect( await ERC20Contract.balanceOf(await defaultFeeReceiver.getAddress()) ).to.be.equal( - (Number(protocolFeeSecondary) * + (Number(protocolFeePrimary) * Number(priceDistribution.erc721Prices[0][0]) + - Number(protocolFeeSecondary) * + Number(protocolFeePrimary) * Number(priceDistribution.erc1155Prices[0][0]) + - Number(protocolFeeSecondary) * + Number(protocolFeePrimary) * Number(priceDistribution.quadPrices[0]) + - Number(protocolFeeSecondary) * + Number(protocolFeePrimary) * Number(priceDistribution.quadPrices[1])) / 10000 ); @@ -1727,7 +2181,7 @@ export function shouldMatchOrdersForBundleWithRoyalty() { quadPrices: [400000000, 600000000], }; - // Create bundle for passing as right order + // Create bundle for passing as left order bundleData = { bundledERC721, bundledERC1155, @@ -1794,7 +2248,7 @@ export function shouldMatchOrdersForBundleWithRoyalty() { ); expect(await ERC1155Contract.balanceOf(takerAddress, 1)).to.be.equal(0); - await ExchangeContractAsUser.matchOrders([ + await ExchangeContractAsAdmin.matchOrders([ { orderLeft, // passing Bundle as left order signatureLeft: makerSig, @@ -1819,9 +2273,9 @@ export function shouldMatchOrdersForBundleWithRoyalty() { ).to.be.equal(1); const protocolFees = { - erc721ProtocolFees: [[protocolFeeSecondary]], - erc1155ProtocolFees: [[protocolFeeSecondary]], - quadProtocolFees: [protocolFeeSecondary, protocolFeeSecondary], + erc721ProtocolFees: [[protocolFeePrimary]], + erc1155ProtocolFees: [[protocolFeePrimary]], + quadProtocolFees: [protocolFeePrimary, protocolFeePrimary], }; const royaltyFees = { @@ -1855,13 +2309,13 @@ export function shouldMatchOrdersForBundleWithRoyalty() { expect( await ERC20Contract.balanceOf(await defaultFeeReceiver.getAddress()) ).to.be.equal( - (Number(protocolFeeSecondary) * + (Number(protocolFeePrimary) * Number(priceDistribution.erc721Prices[0][0]) + - Number(protocolFeeSecondary) * + Number(protocolFeePrimary) * Number(priceDistribution.erc1155Prices[0][0]) + - Number(protocolFeeSecondary) * + Number(protocolFeePrimary) * Number(priceDistribution.quadPrices[0]) + - Number(protocolFeeSecondary) * + Number(protocolFeePrimary) * Number(priceDistribution.quadPrices[1])) / 10000 ); @@ -1885,7 +2339,7 @@ export function shouldMatchOrdersForBundleWithRoyalty() { quadPrices: [1000000000, 3000000000], }; - // Create bundle for passing as right order + // Create bundle for passing as left order bundleData = { bundledERC721, bundledERC1155, @@ -1953,7 +2407,7 @@ export function shouldMatchOrdersForBundleWithRoyalty() { ); expect(await ERC1155Contract.balanceOf(takerAddress, 1)).to.be.equal(0); - await ExchangeContractAsUser.matchOrders([ + await ExchangeContractAsAdmin.matchOrders([ { orderLeft, // passing Bundle as left order signatureLeft: makerSig, @@ -1978,9 +2432,9 @@ export function shouldMatchOrdersForBundleWithRoyalty() { ).to.be.equal(1); const protocolFees = { - erc721ProtocolFees: [[protocolFeeSecondary]], - erc1155ProtocolFees: [[protocolFeeSecondary]], - quadProtocolFees: [protocolFeeSecondary, protocolFeeSecondary], + erc721ProtocolFees: [[protocolFeePrimary]], + erc1155ProtocolFees: [[protocolFeePrimary]], + quadProtocolFees: [protocolFeePrimary, protocolFeePrimary], }; const royaltyFees = { @@ -2017,13 +2471,13 @@ export function shouldMatchOrdersForBundleWithRoyalty() { expect( await ERC20Contract.balanceOf(await defaultFeeReceiver.getAddress()) ).to.be.equal( - (Number(protocolFeeSecondary) * + (Number(protocolFeePrimary) * Number(priceDistribution.erc721Prices[0][0]) + - Number(protocolFeeSecondary) * + Number(protocolFeePrimary) * Number(priceDistribution.erc1155Prices[0][0]) + - Number(protocolFeeSecondary) * + Number(protocolFeePrimary) * Number(priceDistribution.quadPrices[0]) + - Number(protocolFeeSecondary) * + Number(protocolFeePrimary) * Number(priceDistribution.quadPrices[1])) / 10000 ); diff --git a/packages/marketplace/test/exchange/MatchOrdersWithRoyalties.behavior.ts b/packages/marketplace/test/exchange/MatchOrdersWithRoyalties.behavior.ts index 9db7e9c3ef..a76e7f071a 100644 --- a/packages/marketplace/test/exchange/MatchOrdersWithRoyalties.behavior.ts +++ b/packages/marketplace/test/exchange/MatchOrdersWithRoyalties.behavior.ts @@ -39,7 +39,7 @@ export function shouldMatchOrdersWithRoyalty() { orderRight: Order, makerSig: string, takerSig: string, - TSB_SELLER_ROLE: string, + TSB_PRIMARY_MARKET_SELLER_ROLE: string, FEE_WHITELIST_ROLE: string; beforeEach(async function () { @@ -62,7 +62,7 @@ export function shouldMatchOrdersWithRoyalty() { admin: receiver1, user: receiver2, deployer: royaltyReceiver, - TSB_SELLER_ROLE, + TSB_PRIMARY_MARKET_SELLER_ROLE, FEE_WHITELIST_ROLE, } = await loadFixture(deployFixtures)); @@ -571,7 +571,7 @@ export function shouldMatchOrdersWithRoyalty() { ); }); - it('should execute a complete match order without royalties but with primary market fees for address with TSB_SELLER_ROLE', async function () { + it('should execute a complete match order without royalties but with primary market fees for address with TSB_PRIMARY_MARKET_SELLER_ROLE', async function () { await ERC721WithRoyaltyV2981.mint(maker.getAddress(), 1, [ await FeeRecipientsData(maker.getAddress(), 10000), ]); @@ -589,7 +589,7 @@ export function shouldMatchOrdersWithRoyalty() { // grant exchange admin role to seller await ExchangeContractAsDeployer.connect(admin).grantRole( - TSB_SELLER_ROLE, + TSB_PRIMARY_MARKET_SELLER_ROLE, maker.getAddress() ); diff --git a/packages/marketplace/test/exchange/WhitelistingTokens.behavior.ts b/packages/marketplace/test/exchange/WhitelistingTokens.behavior.ts index c1af42fff9..ed41461857 100644 --- a/packages/marketplace/test/exchange/WhitelistingTokens.behavior.ts +++ b/packages/marketplace/test/exchange/WhitelistingTokens.behavior.ts @@ -22,6 +22,7 @@ import {ZeroAddress, Contract, Signer} from 'ethers'; export function shouldCheckForWhitelisting() { describe('Exchange MatchOrders for Whitelisting tokens', function () { let ExchangeContractAsUser: Contract, + ExchangeContractAsAdmin: Contract, OrderValidatorAsAdmin: Contract, ERC20Contract: Contract, ERC20Contract2: Contract, @@ -40,11 +41,13 @@ export function shouldCheckForWhitelisting() { orderLeft: Order, orderRight: Order, makerSig: string, - takerSig: string; + takerSig: string, + TSB_SECONDARY_MARKET_SELLER_ROLE: string; beforeEach(async function () { ({ ExchangeContractAsUser, + ExchangeContractAsAdmin, OrderValidatorAsAdmin, ERC20Contract, ERC20Contract2, @@ -53,6 +56,7 @@ export function shouldCheckForWhitelisting() { ERC1155Contract, user1: maker, user2: taker, + TSB_SECONDARY_MARKET_SELLER_ROLE, } = await loadFixture(deployFixturesWithoutWhitelist)); }); @@ -492,6 +496,12 @@ export function shouldCheckForWhitelisting() { user2: taker, } = await loadFixture(deployFixturesWithoutWhitelist)); + // grant tsb bundle seller role to seller + await ExchangeContractAsAdmin.grantRole( + TSB_SECONDARY_MARKET_SELLER_ROLE, + await maker.getAddress() + ); + priceDistribution = { erc721Prices: [[4000000000]], erc1155Prices: [[6000000000]], diff --git a/packages/marketplace/test/fixtures/index.ts b/packages/marketplace/test/fixtures/index.ts index 61fb40bb90..91b1377eaa 100644 --- a/packages/marketplace/test/fixtures/index.ts +++ b/packages/marketplace/test/fixtures/index.ts @@ -14,7 +14,10 @@ export async function deployFixturesWithoutWhitelist() { const {ExchangeContractAsAdmin} = exchange; - const TSB_SELLER_ROLE = await ExchangeContractAsAdmin.TSB_SELLER_ROLE(); + const TSB_PRIMARY_MARKET_SELLER_ROLE = + await ExchangeContractAsAdmin.TSB_PRIMARY_MARKET_SELLER_ROLE(); + const TSB_SECONDARY_MARKET_SELLER_ROLE = + await ExchangeContractAsAdmin.TSB_SECONDARY_MARKET_SELLER_ROLE(); const FEE_WHITELIST_ROLE = await ExchangeContractAsAdmin.FEE_WHITELIST_ROLE(); const EXCHANGE_ADMIN_ROLE = await ExchangeContractAsAdmin.EXCHANGE_ADMIN_ROLE(); @@ -27,7 +30,8 @@ export async function deployFixturesWithoutWhitelist() { ...exchange, ...mockAssets, EXCHANGE_ADMIN_ROLE, - TSB_SELLER_ROLE, + TSB_PRIMARY_MARKET_SELLER_ROLE, + TSB_SECONDARY_MARKET_SELLER_ROLE, FEE_WHITELIST_ROLE, DEFAULT_ADMIN_ROLE, ERC1776_OPERATOR_ROLE,