Skip to content

Commit

Permalink
feat: removed price oracle features
Browse files Browse the repository at this point in the history
  • Loading branch information
Yashiru committed May 3, 2024
1 parent 055c916 commit 1a5bb86
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 53 deletions.
20 changes: 1 addition & 19 deletions src/token/CountdownERC721.sol
Original file line number Diff line number Diff line change
Expand Up @@ -336,13 +336,6 @@ contract CountdownERC721 is NonReentrant, ContractMetadata, ERC721H, ICustomERC7
return NFTMetadataRenderer.createMetadataEdition(params);
}

/**
* @notice Convert USD price to current price in native Ether units
*/
function getNativePrice() external view returns (uint256) {
return _usdToWei(salesConfig.publicSalePrice);
}

/**
* @notice Returns the name of the token through the holographer entrypoint
*/
Expand All @@ -369,7 +362,7 @@ contract CountdownERC721 is NonReentrant, ContractMetadata, ERC721H, ICustomERC7
function purchase(
uint256 quantity
) external payable nonReentrant canMintTokens(quantity) onlyPublicSaleActive returns (uint256) {
uint256 salePrice = _usdToWei(salesConfig.publicSalePrice);
uint256 salePrice = salesConfig.publicSalePrice;

if (msg.value < (salePrice) * quantity) {
// The error will display what the correct price should be
Expand Down Expand Up @@ -526,17 +519,6 @@ contract CountdownERC721 is NonReentrant, ContractMetadata, ERC721H, ICustomERC7
return START_DATE <= block.timestamp;
}

/**
* @dev Converts the given amount in USD to the equivalent amount in wei using the price oracle.
* @param amount The amount in USD to convert to wei
*/
function _usdToWei(uint256 amount) internal view returns (uint256 weiAmount) {
if (amount == 0) {
return 0;
}
weiAmount = dropsPriceOracle.convertUsdToWei(amount);
}

/* -------------------------------------------------------------------------- */
/* INTERNAL FUNCTIONS */
/* state changing */
Expand Down
9 changes: 4 additions & 5 deletions test/foundry/CountdownERC721/CountdownERC721.admin.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -79,19 +79,18 @@ contract CountdownERC721AdminTest is CountdownERC721Fixture, ICustomERC721Errors
}

function test_SetSalesConfiguration() public setupTestCountdownErc721(DEFAULT_MAX_SUPPLY) {
uint104 price = usd10;
vm.prank(DEFAULT_OWNER_ADDRESS);
countdownErc721.setSaleConfiguration({publicSalePrice: price, maxSalePurchasePerAddress: 10});
countdownErc721.setSaleConfiguration({publicSalePrice: mintEthPrice, maxSalePurchasePerAddress: 10});

(uint104 publicSalePrice, uint24 maxSalePurchasePerAddress) = countdownErc721.salesConfig();
assertEq(publicSalePrice, price);
assertEq(publicSalePrice, mintEthPrice);
assertEq(maxSalePurchasePerAddress, 10);

vm.startPrank(DEFAULT_OWNER_ADDRESS);
countdownErc721.setSaleConfiguration({publicSalePrice: price * 2, maxSalePurchasePerAddress: 5});
countdownErc721.setSaleConfiguration({publicSalePrice: mintEthPrice * 2, maxSalePurchasePerAddress: 5});

(publicSalePrice, maxSalePurchasePerAddress) = countdownErc721.salesConfig();
assertEq(publicSalePrice, price * 2);
assertEq(publicSalePrice, mintEthPrice * 2);
assertEq(maxSalePurchasePerAddress, 5);
}

Expand Down
12 changes: 6 additions & 6 deletions test/foundry/CountdownERC721/CountdownERC721.countdown.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ contract CountdownERC721CountdownTest is CountdownERC721Fixture, ICustomERC721Er

// Purchase all the supply
for (uint256 i = 0; i < maxSupply; i++) {
countdownErc721.purchase{value: totalCost}(1);
countdownErc721.purchase{value: mintEthPrice}(1);
}

// Try to purchase one more
vm.expectRevert(abi.encodeWithSelector(Purchase_CountdownCompleted.selector));
countdownErc721.purchase{value: totalCost}(1);
countdownErc721.purchase{value: mintEthPrice}(1);

assertEq(countdownErc721.totalMinted(), maxSupply, "Wrong total minted");
assertEq(countdownErc721.endDate(), start, "Wrong end date");
Expand All @@ -81,12 +81,12 @@ contract CountdownERC721CountdownTest is CountdownERC721Fixture, ICustomERC721Er

// Purchase all the supply
for (uint256 i = 0; i < newMaxSupply; i++) {
countdownErc721.purchase{value: totalCost}(1);
countdownErc721.purchase{value: mintEthPrice}(1);
}

// Try to purchase one more
vm.expectRevert(abi.encodeWithSelector(Purchase_CountdownCompleted.selector));
countdownErc721.purchase{value: totalCost}(1);
countdownErc721.purchase{value: mintEthPrice}(1);

assertEq(countdownErc721.totalMinted(), initialMaxSupply / 2, "Wrong total minted");
}
Expand All @@ -112,7 +112,7 @@ contract CountdownERC721CountdownTest is CountdownERC721Fixture, ICustomERC721Er
// Purchase all the supply
uint256 i = 1;
while (countdownErc721.totalMinted() < countdownErc721.currentTheoricalMaxSupply()) {
countdownErc721.purchase{value: totalCost}(1);
countdownErc721.purchase{value: mintEthPrice}(1);

vm.warp(block.timestamp + elapsedTimeBetweenPurchase);

Expand All @@ -128,7 +128,7 @@ contract CountdownERC721CountdownTest is CountdownERC721Fixture, ICustomERC721Er

// Try to purchase one more
vm.expectRevert(abi.encodeWithSelector(Purchase_CountdownCompleted.selector));
countdownErc721.purchase{value: totalCost}(1);
countdownErc721.purchase{value: mintEthPrice}(1);
uint256 totalMinted = countdownErc721.totalMinted();
uint256 expectedMaxSupply;

Expand Down
13 changes: 6 additions & 7 deletions test/foundry/CountdownERC721/CountdownERC721.purchase.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ contract CountdownERC721PurchaseTest is CountdownERC721Fixture, ICustomERC721Err
function test_Purchase() public setupTestCountdownErc721(DEFAULT_MAX_SUPPLY) setUpPurchase {
/* -------------------------------- Purchase -------------------------------- */
vm.prank(address(TEST_ACCOUNT));
vm.deal(address(TEST_ACCOUNT), totalCost);
uint256 tokenId = countdownErc721.purchase{value: totalCost}(1);
vm.deal(address(TEST_ACCOUNT), mintEthPrice);
uint256 tokenId = countdownErc721.purchase{value: mintEthPrice}(1);

// First token ID is this long number due to the chain id prefix
require(erc721Enforcer.ownerOf(tokenId) == address(TEST_ACCOUNT), "Incorrect owner for newly minted token");
assertEq(address(sourceContractAddress).balance, nativePrice);
assertEq(address(sourceContractAddress).balance, mintEthPrice);

}

Expand All @@ -45,12 +45,11 @@ contract CountdownERC721PurchaseTest is CountdownERC721Fixture, ICustomERC721Err
/* -------------------------------- Purchase -------------------------------- */

uint256 amount = 1;
uint104 price = usd100;
vm.prank(address(TEST_ACCOUNT));
vm.deal(address(TEST_ACCOUNT), totalCost - 1);
vm.expectRevert(abi.encodeWithSelector(ICountdownERC721.Purchase_WrongPrice.selector, uint256(price)));
vm.deal(address(TEST_ACCOUNT), mintEthPrice - 1);
vm.expectRevert(abi.encodeWithSelector(ICountdownERC721.Purchase_WrongPrice.selector, uint256(mintEthPrice)));

countdownErc721.purchase{value: totalCost - 1}(amount);
countdownErc721.purchase{value: mintEthPrice - 1}(amount);
}

function test_GetContractURI() public setupTestCountdownErc721(DEFAULT_MAX_SUPPLY) setUpPurchase {
Expand Down
6 changes: 3 additions & 3 deletions test/foundry/CountdownERC721/CountdownERC721.tokenUri.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ contract CountdownERC721PurchaseTest is CountdownERC721Fixture, ICustomERC721Err
function test_tokenUri() public setupTestCountdownErc721(DEFAULT_MAX_SUPPLY) setUpPurchase {
/* -------------------------------- Purchase -------------------------------- */
vm.prank(address(TEST_ACCOUNT));
vm.deal(address(TEST_ACCOUNT), totalCost);
uint256 tokenId = countdownErc721.purchase{value: totalCost}(1);
vm.deal(address(TEST_ACCOUNT), mintEthPrice);
uint256 tokenId = countdownErc721.purchase{value: mintEthPrice}(1);

// First token ID is this long number due to the chain id prefix
require(erc721Enforcer.ownerOf(tokenId) == address(TEST_ACCOUNT), "Incorrect owner for newly minted token");
assertEq(address(sourceContractAddress).balance, nativePrice);
assertEq(address(sourceContractAddress).balance, mintEthPrice);

/* ----------------------------- Check tokenURI ----------------------------- */

Expand Down
17 changes: 4 additions & 13 deletions test/foundry/fixtures/CountdownERC721Fixture.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,8 @@ contract CountdownERC721Fixture is Test {
DummyDropsPriceOracle public dummyPriceOracle;

/* ---------------------------- Test environment ---------------------------- */
uint256 nativePrice;
uint104 mintEthPrice = 0.1 ether;
uint256 public chainPrepend;
uint256 totalCost;
uint104 constant usd10 = 10 * (10 ** 6); // 10 USD (6 decimal places)
uint104 constant usd100 = 100 * (10 ** 6); // 100 USD (6 decimal places)
uint104 constant usd1000 = 1000 * (10 ** 6); // 1000 USD (6 decimal places)
uint256 internal fuzzingMaxSupply;

uint256 public constant FIRST_TOKEN_ID =
Expand Down Expand Up @@ -144,11 +140,6 @@ contract CountdownERC721Fixture is Test {
sourceContractAddress = holographerInterface.getSourceContract();
erc721Enforcer = HolographERC721(payable(address(countdownErc721)));

uint104 price = usd100;
nativePrice = dummyPriceOracle.convertUsdToWei(price);

totalCost = (nativePrice);

vm.warp(countdownErc721.START_DATE());
}

Expand All @@ -162,16 +153,16 @@ contract CountdownERC721Fixture is Test {
for (uint256 i = 0; i < countdownErc721.currentTheoricalMaxSupply(); i++) {
address user = address(uint160(uint256(keccak256(abi.encodePacked(i)))));
vm.startPrank(address(user));
vm.deal(address(user), totalCost);
countdownErc721.purchase{value: totalCost}(1);
vm.deal(address(user), mintEthPrice);
countdownErc721.purchase{value: mintEthPrice}(1);
vm.stopPrank();
}
}

function _deployAndSetupProtocol(uint32 maxSupply) private {
// Setup sale config for edition
CustomERC721SalesConfiguration memory saleConfig = CustomERC721SalesConfiguration({
publicSalePrice: usd100,
publicSalePrice: uint104(mintEthPrice),
maxSalePurchasePerAddress: 0 // no limit
});

Expand Down

0 comments on commit 1a5bb86

Please sign in to comment.