Skip to content

Commit

Permalink
Extra logic for reverse purchase
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesmorgan committed Mar 23, 2022
2 parents daa0494 + 0f6ffb9 commit ab035e4
Show file tree
Hide file tree
Showing 10 changed files with 7,568 additions and 14,889 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/node_test_runner.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ jobs:
- name: Install and test
run: |
npm install
npm run test
npm run test-fast
env:
CI: true
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ coverage.json
coverage
.idea/
.env
.openzeppelin/unknown-31337.json
6,746 changes: 0 additions & 6,746 deletions .openzeppelin/unknown-31337.json

This file was deleted.

37 changes: 21 additions & 16 deletions contracts/marketplace/KODAV3UpgradableGatedMarketplace.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import {IKODAV3} from "../core/IKODAV3.sol";
import {IKOAccessControlsLookup} from "../access/IKOAccessControlsLookup.sol";
import {IKODAV3GatedMarketplace} from "./IKODAV3Marketplace.sol";

import "hardhat/console.sol";

contract KODAV3UpgradableGatedMarketplace is IKODAV3GatedMarketplace, BaseUpgradableMarketplace {

/// @notice emitted when admin updates funds receiver
Expand Down Expand Up @@ -145,7 +147,7 @@ contract KODAV3UpgradableGatedMarketplace is IKODAV3GatedMarketplace, BaseUpgrad
creator : _creator,
fundsReceiver : koda.getRoyaltiesReceiver(_editionId),
editionId : _editionId,
maxEditionId : koda.maxTokenIdOfEdition(_editionId),
maxEditionId : koda.maxTokenIdOfEdition(_editionId) - 1,
paused : 0,
mintCounter : 0
});
Expand Down Expand Up @@ -285,16 +287,19 @@ contract KODAV3UpgradableGatedMarketplace is IKODAV3GatedMarketplace, BaseUpgrad
address _recipient
) internal {
require(_mintCount > 0, "Nothing being minted");
uint256 startId = _editionId + sales[_saleId].mintCounter;

address creator = sales[_saleId].creator;
uint256 startId = sales[_saleId].maxEditionId - sales[_saleId].mintCounter;

for (uint256 i; i < _mintCount; ++i) {
uint256 tokenId = getNextAvailablePrimarySaleToken(startId, sales[_saleId].maxEditionId, sales[_saleId].creator);
uint256 tokenId = getNextAvailablePrimarySaleToken(startId, _editionId, creator);

// send token to buyer (assumes approval has been made, if not then this will fail)
koda.safeTransferFrom(sales[_saleId].creator, _recipient, tokenId);
koda.safeTransferFrom(creator, _recipient, tokenId);

emit MintFromSale(_saleId, _phaseId, tokenId, _recipient);

unchecked {startId = tokenId++;}
unchecked {startId = tokenId--;}
}
_handleSaleFunds(sales[_saleId].fundsReceiver, getPlatformSaleCommissionForSale(_saleId));
}
Expand All @@ -306,9 +311,9 @@ contract KODAV3UpgradableGatedMarketplace is IKODAV3GatedMarketplace, BaseUpgrad
return platformPrimaryCommission;
}

function getNextAvailablePrimarySaleToken(uint256 _startId, uint256 _maxEditionId, address creator) internal view returns (uint256 _tokenId) {
for (uint256 tokenId = _startId; tokenId < _maxEditionId; ++tokenId) {
if (koda.ownerOf(tokenId) == creator) {
function getNextAvailablePrimarySaleToken(uint256 _startId, uint256 _editionId, address creator) internal view returns (uint256 _tokenId) {
for (uint256 tokenId = _startId; tokenId >= _editionId; --tokenId) {
if(koda.ownerOf(tokenId) == creator){
return tokenId;
}
}
Expand Down Expand Up @@ -358,14 +363,14 @@ contract KODAV3UpgradableGatedMarketplace is IKODAV3GatedMarketplace, BaseUpgrad

// Add the phase to the phases mapping
phases[_saleId].push(Phase({
startTime : _startTime,
endTime : _endTime,
priceInWei : _priceInWei,
mintCounter : 0,
mintCap : _mintCap,
walletMintLimit : _walletMintLimit,
merkleRoot : _merkleRoot,
merkleIPFSHash : _merkleIPFSHash
startTime : _startTime,
endTime : _endTime,
priceInWei : _priceInWei,
mintCounter : 0,
mintCap : _mintCap,
walletMintLimit : _walletMintLimit,
merkleRoot : _merkleRoot,
merkleIPFSHash : _merkleIPFSHash
}));

emit PhaseCreated(_saleId, phases[_saleId].length - 1);
Expand Down
Loading

0 comments on commit ab035e4

Please sign in to comment.