Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate twinIdsByTokenAddressAndBySeller #628

Merged
merged 3 commits into from
Jun 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 0 additions & 23 deletions contracts/protocol/bases/TwinBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -72,26 +72,6 @@ contract TwinBase is ProtocolBase, IBosonTwinEvents {
lastTokenId = tokenId + _twin.supplyAvailable - 1;
}

// Get all seller twin ids that belong to the same token address of the new twin to validate if they have not unlimited supply since ranges can overlaps each other
uint256[] storage twinIds = lookups.twinIdsByTokenAddressAndBySeller[sellerId][_twin.tokenAddress];
uint256 twinIdsLength = twinIds.length;

if (twinIdsLength > 0) {
uint256 maxInt = type(uint256).max;
uint256 supplyAvailable = _twin.supplyAvailable;

for (uint256 i = 0; i < twinIdsLength; i++) {
// Get storage location for looped twin
(, Twin storage currentTwin) = fetchTwin(twinIds[i]);

// Make sure no twins have unlimited supply, otherwise ranges would overlap
require(
currentTwin.supplyAvailable != maxInt || supplyAvailable != maxInt,
INVALID_TWIN_TOKEN_RANGE
);
}
}

// Get all ranges of twins that belong to the seller and to the same token address of the new twin to validate if range is available
TokenRange[] storage twinRanges = lookups.twinRangesBySeller[sellerId][_twin.tokenAddress];

Expand All @@ -109,9 +89,6 @@ contract TwinBase is ProtocolBase, IBosonTwinEvents {
TokenRange storage tokenRange = twinRanges.push();
tokenRange.start = tokenId;
tokenRange.end = lastTokenId;

// Add twin id to twinIdsByTokenAddressAndBySeller mapping
twinIds.push(_twin.id);
} else if (_twin.tokenType == TokenType.MultiToken) {
// If token is Fungible or MultiToken amount should not be zero
// Also, the amount of tokens should not be more than the available token supply.
Expand Down
7 changes: 0 additions & 7 deletions contracts/protocol/facets/TwinHandlerFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -82,23 +82,16 @@ contract TwinHandlerFacet is IBosonTwinHandler, TwinBase {
// Also remove from twinRangesBySeller mapping
if (twin.tokenType == TokenType.NonFungibleToken) {
TokenRange[] storage twinRanges = lookups.twinRangesBySeller[sellerId][twin.tokenAddress];
uint256[] storage twinIdsByTokenAddressAndBySeller = lookups.twinIdsByTokenAddressAndBySeller[sellerId][
twin.tokenAddress
];
uint256 lastIndex = twinRanges.length - 1;
for (uint256 index = 0; index <= lastIndex; index++) {
if (twinRanges[index].start == twin.tokenId) {
// Update twin ranges and twinIdsByTokenAddressAndBySeller

// If not removing last element, move the last to the removed index
if (index != lastIndex) {
twinRanges[index] = twinRanges[lastIndex];
twinIdsByTokenAddressAndBySeller[index] = twinIdsByTokenAddressAndBySeller[lastIndex];
}

// Remove last element
twinRanges.pop();
twinIdsByTokenAddressAndBySeller.pop();
break;
}
}
Expand Down
1 change: 1 addition & 0 deletions contracts/protocol/libs/ProtocolLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ library ProtocolLib {
// seller id => token address (only ERC721) => start and end of token ids range
mapping(uint256 => mapping(address => BosonTypes.TokenRange[])) twinRangesBySeller;
// seller id => token address (only ERC721) => twin ids
// @deprecated twinIdsByTokenAddressAndBySeller is no longer used. Keeping it for backwards compatibility.
mapping(uint256 => mapping(address => uint256[])) twinIdsByTokenAddressAndBySeller;
// exchange id => BosonTypes.TwinReceipt
mapping(uint256 => BosonTypes.TwinReceipt[]) twinReceiptsByExchange;
Expand Down
57 changes: 1 addition & 56 deletions test/protocol/TwinHandlerTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,9 @@ const PausableRegion = require("../../scripts/domain/PausableRegion.js");
const TokenType = require("../../scripts/domain/TokenType.js");
const { getInterfaceIds } = require("../../scripts/config/supported-interfaces.js");
const { RevertReasons } = require("../../scripts/config/revert-reasons.js");
const {
getEvent,
getMappingStoragePosition,
paddingType,
setupTestEnvironment,
getSnapshot,
revertToSnapshot,
} = require("../util/utils.js");
const { getEvent, setupTestEnvironment, getSnapshot, revertToSnapshot } = require("../util/utils.js");