Skip to content

Commit

Permalink
fix: bundle test by adding price distribution
Browse files Browse the repository at this point in the history
  • Loading branch information
capedcrusader21 committed Jul 22, 2024
1 parent 0cc809c commit 9e33ae6
Show file tree
Hide file tree
Showing 5 changed files with 214 additions and 34 deletions.
6 changes: 3 additions & 3 deletions packages/land/contracts/libraries/QuadHelper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ library QuadHelper {
uint256 internal constant LAYER_12x12 = 0x0300000000000000000000000000000000000000000000000000000000000000;
uint256 internal constant LAYER_24x24 = 0x0400000000000000000000000000000000000000000000000000000000000000;
/* solhint-enable const-name-snakecase */

/// @notice get the quad id given the layer and coordinates.
/// @param layer the layer of the quad see: _getQuadLayer
/// @param x The bottom left x coordinate of the quad
/// @param y The bottom left y coordinate of the quad
/// @return the tokenId of the quad
/// @dev this method is gas optimized, must be called with verified x,y and size, after a call to _isValidQuad
function getQuadId(uint256 layer, uint256 x, uint256 y) external pure returns (uint256) {
function getQuadId(uint256 layer, uint256 x, uint256 y) internal pure returns (uint256) {
unchecked {
return layer + x + y * GRID_SIZE;
}
Expand All @@ -31,7 +31,7 @@ library QuadHelper {
/// @return layer the layers that corresponds to the size
/// @return parentSize the size of the parent (bigger quad that contains the current one)
/// @return childLayer the layer of the child (smaller quad contained by this one)
function getQuadLayer(uint256 size) external pure returns (uint256 layer, uint256 parentSize, uint256 childLayer) {
function getQuadLayer(uint256 size) internal pure returns (uint256 layer, uint256 parentSize, uint256 childLayer) {
if (size == 1) {
layer = LAYER_1x1;
parentSize = 3;
Expand Down
6 changes: 5 additions & 1 deletion packages/marketplace/contracts/ExchangeCore.sol
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,11 @@ abstract contract ExchangeCore is Initializable, ITransferManager {
orderRight.makeAsset.assetType
);

LibAsset.verifyPriceDistribution(orderRight.makeAsset, orderLeft.makeAsset.priceDistribution);
LibAsset.verifyPriceDistribution(
orderRight.makeAsset,
orderRight.takeAsset,
orderRight.makeAsset.priceDistribution
);

LibOrder.FillResult memory newFill = _parseOrdersSetFillEmitMatch(sender, orderLeft, orderRight);

Expand Down
6 changes: 4 additions & 2 deletions packages/marketplace/contracts/libraries/LibAsset.sol
Original file line number Diff line number Diff line change
Expand Up @@ -158,14 +158,16 @@ library LibAsset {
}

/// @dev function to verify if the order is bundle and validate the bundle price
/// @param rightMakeAsset The make asset from buyer.
/// @param rightMakeAsset The make asset from seller. // TODO if it is seller or buyer in code and configure with tests
/// @param leftMakeAsset The make asset from buyer. // TODO if it is seller or buyer in code and configure with tests
/// @param priceDistribution The price distribution details.
function verifyPriceDistribution(
Asset memory rightMakeAsset,
Asset memory leftMakeAsset,
PriceDistribution memory priceDistribution
) internal pure {
if (rightMakeAsset.assetType.assetClass == AssetClass.BUNDLE) {
uint256 bundlePrice = rightMakeAsset.value; // bundle price provided by buyer
uint256 bundlePrice = leftMakeAsset.value; // bundle price provided by seller
Bundle memory bundle = LibAsset.decodeBundle(rightMakeAsset.assetType);
uint256 collectiveBundlePrice = 0;

Expand Down
Loading

0 comments on commit 9e33ae6

Please sign in to comment.