Skip to content

Commit

Permalink
fix: inconsistent price handling for bundled ERC1155
Browse files Browse the repository at this point in the history
  • Loading branch information
capedcrusader21 committed Sep 16, 2024
1 parent e46a762 commit 1aed585
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 42 deletions.
4 changes: 1 addition & 3 deletions packages/marketplace/contracts/libraries/LibAsset.sol
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,7 @@ library LibAsset {
// total price of all bundled ERC1155 assets
for (uint256 i = 0; i < priceDistribution.erc1155Prices.length; i++) {
for (uint256 j = 0; j < priceDistribution.erc1155Prices[i].length; j++) {
collectiveBundlePrice +=
bundle.bundledERC1155[i].supplies[j] *
priceDistribution.erc1155Prices[i][j];
collectiveBundlePrice += priceDistribution.erc1155Prices[i][j];
}
}

Expand Down
26 changes: 13 additions & 13 deletions packages/marketplace/test/exchange/Bundle.behavior.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export function shouldMatchOrdersForBundle() {

priceDistribution = {
erc721Prices: [[4000000000]],
erc1155Prices: [[600000000]],
erc1155Prices: [[6000000000]],
quadPrices: [],
};

Expand Down Expand Up @@ -247,7 +247,7 @@ export function shouldMatchOrdersForBundle() {
).to.be.equal(1);

expect(await ERC20Contract.balanceOf(makerAddress)).to.be.equal(
9885000000 // 10000000000 - protocolFee
9750000000 // 10000000000 - protocolFee
);

expect(await ERC20Contract.balanceOf(takerAddress)).to.be.equal(
Expand All @@ -270,7 +270,7 @@ export function shouldMatchOrdersForBundle() {
// to bypass price distribution check as fill.leftValue = 2
priceDistribution = {
erc721Prices: [[2000000000]],
erc1155Prices: [[300000000]],
erc1155Prices: [[3000000000]],
quadPrices: [],
};

Expand Down Expand Up @@ -347,7 +347,7 @@ export function shouldMatchOrdersForBundle() {

priceDistribution = {
erc721Prices: [[]], // price distribution without ERC721
erc1155Prices: [[1000000000]],
erc1155Prices: [[10000000000]],
quadPrices: [],
};

Expand Down Expand Up @@ -424,7 +424,7 @@ export function shouldMatchOrdersForBundle() {
).to.be.equal(1);

expect(await ERC20Contract.balanceOf(makerAddress)).to.be.equal(
9975000000
9750000000
);

expect(await ERC20Contract.balanceOf(taker)).to.be.equal(20000000000);
Expand Down Expand Up @@ -462,7 +462,7 @@ export function shouldMatchOrdersForBundle() {

priceDistribution = {
erc721Prices: [[]], // price distribution without ERC721
erc1155Prices: [[1000000000]],
erc1155Prices: [[10000000000]],
quadPrices: [],
};

Expand Down Expand Up @@ -541,7 +541,7 @@ export function shouldMatchOrdersForBundle() {

priceDistribution = {
erc721Prices: [[]], // price distribution without ERC721
erc1155Prices: [[1000000000]],
erc1155Prices: [[10000000000]],
quadPrices: [],
};

Expand Down Expand Up @@ -619,7 +619,7 @@ export function shouldMatchOrdersForBundle() {
10000000000
);
expect(await ERC20Contract.balanceOf(makerAddress)).to.be.equal(
19950000000
19500000000
);

expect(
Expand Down Expand Up @@ -656,7 +656,7 @@ export function shouldMatchOrdersForBundle() {

priceDistribution = {
erc721Prices: [[]], // price distribution without ERC721
erc1155Prices: [[1000000000]],
erc1155Prices: [[10000000000]],
quadPrices: [],
};

Expand Down Expand Up @@ -722,7 +722,7 @@ export function shouldMatchOrdersForBundle() {
).to.be.equal(1);

expect(await ERC20Contract.balanceOf(makerAddress)).to.be.equal(
9975000000
9750000000
);
expect(await ERC20Contract.balanceOf(taker)).to.be.equal(20000000000);

Expand Down Expand Up @@ -775,7 +775,7 @@ export function shouldMatchOrdersForBundle() {
).to.be.equal(1);

expect(await ERC20Contract.balanceOf(makerAddress)).to.be.equal(
19950000000
19500000000
);
expect(await ERC20Contract.balanceOf(taker)).to.be.equal(10000000000);
0;
Expand Down Expand Up @@ -818,7 +818,7 @@ export function shouldMatchOrdersForBundle() {

priceDistribution = {
erc721Prices: [[4000000000]], // price distribution without ERC721
erc1155Prices: [[500000000]],
erc1155Prices: [[5000000000]],
quadPrices: [500000000, 500000000],
};

Expand Down Expand Up @@ -967,7 +967,7 @@ export function shouldMatchOrdersForBundle() {
).to.be.equal(1);

expect(await ERC20Contract.balanceOf(makerAddress)).to.be.equal(
9862500000 // 10000000000 - protocolFee
9750000000 // 10000000000 - protocolFee
);

expect(await ERC20Contract.balanceOf(takerAddress)).to.be.equal(
Expand Down
50 changes: 25 additions & 25 deletions packages/marketplace/test/exchange/BundleWithRoyalties.behaviour.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export function shouldMatchOrdersForBundleWithRoyalty() {

priceDistribution = {
erc721Prices: [[4000000000]],
erc1155Prices: [[600000000]],
erc1155Prices: [[6000000000]],
quadPrices: [],
};

Expand Down Expand Up @@ -381,7 +381,7 @@ export function shouldMatchOrdersForBundleWithRoyalty() {
).to.be.equal(1);

expect(await ERC20Contract.balanceOf(makerAddress)).to.be.equal(
9875800000 // 10000000000 - protocolFee - royalty
9200800000 // 10000000000 - protocolFee - royalty
);

expect(await ERC20Contract.balanceOf(takerAddress)).to.be.equal(
Expand All @@ -402,7 +402,7 @@ export function shouldMatchOrdersForBundleWithRoyalty() {
// check paid royalty
expect(
await ERC20Contract.balanceOf(royaltyReceiver.getAddress())
).to.be.equal(60000000); // 10% of asset price for ERC1155 token with id:1
).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 () {
Expand Down Expand Up @@ -508,7 +508,7 @@ export function shouldMatchOrdersForBundleWithRoyalty() {
).to.be.equal(1);

expect(await ERC20Contract.balanceOf(makerAddress)).to.be.equal(
9492620000 // 10000000000 - protocolFee - royalty
9426200000 // 10000000000 - protocolFee - royalty
);

expect(await ERC20Contract.balanceOf(takerAddress)).to.be.equal(
Expand Down Expand Up @@ -559,7 +559,7 @@ export function shouldMatchOrdersForBundleWithRoyalty() {

priceDistribution = {
erc721Prices: [[4000000000]],
erc1155Prices: [[600000000]],
erc1155Prices: [[6000000000]],
quadPrices: [],
};

Expand Down Expand Up @@ -775,7 +775,7 @@ export function shouldMatchOrdersForBundleWithRoyalty() {
).to.be.equal(1);

expect(await ERC20Contract.balanceOf(makerAddress)).to.be.equal(
9085000000 // 10000000000 - royalty - protocolFee
8950000000 // 10000000000 - royalty - protocolFee
);

expect(await ERC20Contract.balanceOf(takerAddress)).to.be.equal(
Expand Down Expand Up @@ -809,7 +809,7 @@ export function shouldMatchOrdersForBundleWithRoyalty() {

priceDistribution = {
erc721Prices: [[2000000000, 3000000000]],
erc1155Prices: [[500000000]],
erc1155Prices: [[5000000000]],
quadPrices: [],
};

Expand Down Expand Up @@ -898,7 +898,7 @@ export function shouldMatchOrdersForBundleWithRoyalty() {
).to.be.equal(1);

expect(await ERC20Contract.balanceOf(makerAddress)).to.be.equal(
9062500000 // 10000000000 - royalty - protocolFee
8950000000 // 10000000000 - royalty - protocolFee
);
expect(await ERC20Contract.balanceOf(takerAddress)).to.be.equal(
20000000000
Expand Down Expand Up @@ -1084,7 +1084,7 @@ export function shouldMatchOrdersForBundleWithRoyalty() {
).to.be.equal(1);

expect(await ERC20Contract.balanceOf(makerAddress)).to.be.equal(
9855000000 // 10000000000 - royalty - protocolFee
9450000000 // 10000000000 - royalty - protocolFee
);
expect(await ERC20Contract.balanceOf(takerAddress)).to.be.equal(
20000000000
Expand All @@ -1093,7 +1093,7 @@ export function shouldMatchOrdersForBundleWithRoyalty() {
// check paid royalty
expect(
await ERC20Contract.balanceOf(royaltyReceiver.getAddress())
).to.be.equal(30000000); // 5% of asset price for ERC1155 token with id:1
).to.be.equal(300000000); // 5% of asset price for ERC1155 token with id:1

// check protocol fee
expect(
Expand All @@ -1118,7 +1118,7 @@ export function shouldMatchOrdersForBundleWithRoyalty() {

priceDistribution = {
erc721Prices: [[5000000000]],
erc1155Prices: [[300000000, 400000000]],
erc1155Prices: [[3000000000, 2000000000]],
quadPrices: [],
};

Expand Down Expand Up @@ -1215,7 +1215,7 @@ export function shouldMatchOrdersForBundleWithRoyalty() {
).to.be.equal(1);

expect(await ERC20Contract.balanceOf(makerAddress)).to.be.equal(
9802500000 // 10000000000 - royalty - protocolFee
9400000000 // 10000000000 - royalty - protocolFee
);

expect(await ERC20Contract.balanceOf(takerAddress)).to.be.equal(
Expand All @@ -1225,10 +1225,10 @@ export function shouldMatchOrdersForBundleWithRoyalty() {
// check paid royalty
expect(
await ERC20Contract.balanceOf(royaltyReceiver.getAddress())
).to.be.equal(15000000); // 5% of asset price for ERC1155 token with id:1
).to.be.equal(150000000); // 5% of asset price for ERC1155 token with id:1
expect(
await ERC20Contract.balanceOf(royaltyReceiver2.getAddress())
).to.be.equal(40000000); // 10% of asset price for ERC1155 token with id:2
).to.be.equal(200000000); // 10% of asset price for ERC1155 token with id:2

// check protocol fee
expect(
Expand Down Expand Up @@ -1261,7 +1261,7 @@ export function shouldMatchOrdersForBundleWithRoyalty() {

priceDistribution = {
erc721Prices: [[]], // price distribution without ERC721
erc1155Prices: [[1000000000]],
erc1155Prices: [[10000000000]],
quadPrices: [],
};

Expand Down Expand Up @@ -1348,16 +1348,16 @@ export function shouldMatchOrdersForBundleWithRoyalty() {
).to.be.equal(2);

expect(await ERC20Contract.balanceOf(makerAddress)).to.be.equal(
19750000000 // 10000000000 - royalty - protocolFee
17500000000 // 10000000000 - royalty - protocolFee
);
expect(await ERC20Contract.balanceOf(takerAddress)).to.be.equal(
10000000000
);
100000000;

// check paid royalty
expect(
await ERC20Contract.balanceOf(royaltyReceiver.getAddress())
).to.be.equal(200000000); // 10% of asset price for ERC1155 token with id:1 for 2 bundles
).to.be.equal(2000000000); // 10% of asset price for ERC1155 token with id:1 for 2 bundles

expect(
await ERC20Contract.balanceOf(defaultFeeReceiver.getAddress())
Expand Down Expand Up @@ -1386,7 +1386,7 @@ export function shouldMatchOrdersForBundleWithRoyalty() {

priceDistribution = {
erc721Prices: [[4000000000]],
erc1155Prices: [[500000000]],
erc1155Prices: [[5000000000]],
quadPrices: [400000000, 600000000],
};

Expand Down Expand Up @@ -1467,7 +1467,7 @@ export function shouldMatchOrdersForBundleWithRoyalty() {
).to.be.equal(1);

expect(await ERC20Contract.balanceOf(makerAddress)).to.be.equal(
9762500000 // 10000000000 - protocolFee - royalty
9650000000 // 10000000000 - protocolFee - royalty
);

expect(await ERC20Contract.balanceOf(takerAddress)).to.be.equal(
Expand Down Expand Up @@ -1509,7 +1509,7 @@ export function shouldMatchOrdersForBundleWithRoyalty() {

priceDistribution = {
erc721Prices: [[4000000000]],
erc1155Prices: [[500000000]],
erc1155Prices: [[5000000000]],
quadPrices: [400000000, 600000000],
};

Expand Down Expand Up @@ -1605,7 +1605,7 @@ export function shouldMatchOrdersForBundleWithRoyalty() {
).to.be.equal(1);

expect(await ERC20Contract.balanceOf(makerAddress)).to.be.equal(
9702500000 // 10000000000 - protocolFee - royalty
9590000000 // 10000000000 - protocolFee - royalty
);
expect(await ERC20Contract.balanceOf(takerAddress)).to.be.equal(
20000000000
Expand Down Expand Up @@ -1649,7 +1649,7 @@ export function shouldMatchOrdersForBundleWithRoyalty() {

priceDistribution = {
erc721Prices: [[1000000000]],
erc1155Prices: [[500000000]],
erc1155Prices: [[5000000000]],
quadPrices: [1000000000, 3000000000],
};

Expand Down Expand Up @@ -1746,7 +1746,7 @@ export function shouldMatchOrdersForBundleWithRoyalty() {
).to.be.equal(1);

expect(await ERC20Contract.balanceOf(makerAddress)).to.be.equal(
9312500000 // 10000000000 - protocolFee - royalty
8750000000 // 10000000000 - protocolFee - royalty
);
expect(await ERC20Contract.balanceOf(takerAddress)).to.be.equal(
20000000000
Expand All @@ -1758,7 +1758,7 @@ export function shouldMatchOrdersForBundleWithRoyalty() {
).to.be.equal(100000000); // 10% of the amount
expect(
await ERC20Contract.balanceOf(royaltyReceiver2.getAddress())
).to.be.equal(50000000); // 10% of asset price for ERC1155 token with id:1
).to.be.equal(500000000); // 10% of asset price for ERC1155 token with id:1
expect(
await ERC20Contract.balanceOf(royaltyReceiver3.getAddress())
).to.be.equal(400000000); // 10% of asset price for quad (3,0) & (0,3)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ export function shouldCheckForWhitelisting() {

priceDistribution = {
erc721Prices: [[4000000000]],
erc1155Prices: [[600000000]],
erc1155Prices: [[6000000000]],
quadPrices: [],
};

Expand Down

1 comment on commit 1aed585

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage for this commit

98.22%

Coverage Report
FileStmtsBranchesFuncsLinesUncovered Lines
packages/marketplace/contracts
   Exchange.sol94.52%93.33%94.44%96%126, 194, 72
   ExchangeCore.sol98.84%96.67%100%100%85
   OrderValidator.sol98.44%96.15%100%100%36
   RoyaltiesRegistry.sol96.32%88.89%100%98.78%194, 216–217, 263, 65
   TransferManager.sol95.42%85.71%100%99.42%163, 225, 247, 333, 393, 430, 580, 585, 596, 608–609, 620, 93
   Whitelist.sol75.81%60%85.71%82.14%104, 108–109, 122, 125, 141–142, 54, 66, 66–67, 71, 76
packages/marketplace/contracts/interfaces
   IOrderValidator.sol100%100%100%100%
   IRoyaltiesProvider.sol100%100%100%100%
   ITransferManager.sol100%100%100%100%
   IWhitelist.sol100%100%100%100%
packages/marketplace/contracts/libraries
   LibAsset.sol100%100%100%100%
   LibMath.sol100%100%100%100%
   LibOrder.sol100%100%100%100%

Please sign in to comment.