From 3d50cf09089c31d9b8c0fa753148cde6fc272b4c Mon Sep 17 00:00:00 2001 From: Billy Rennekamp Date: Sun, 11 Aug 2024 10:12:11 +0200 Subject: [PATCH] deployed new metadata and modified mint/pay logic in anybodyproblem --- contracts/AnybodyProblem.sol | 50 +++++++++++-------- .../contractData/84532-ExternalMetadata.json | 2 +- .../ABI-84532-ExternalMetadata.json | 22 ++++++++ 3 files changed, 52 insertions(+), 22 deletions(-) diff --git a/contracts/AnybodyProblem.sol b/contracts/AnybodyProblem.sol index f4a6f4fb..2ce8cf9f 100644 --- a/contracts/AnybodyProblem.sol +++ b/contracts/AnybodyProblem.sol @@ -21,7 +21,8 @@ contract AnybodyProblem is Ownable, ERC2981 { uint256 public constant FIRST_SUNDAY_AT_6_PM_UTC = 324000; bool public paused = false; - uint256 public price = 0.0025 ether; + uint256 public priceToMint = 0.0025 ether; + uint256 public priceToSave = 0 ether; uint256 public discount = 2; address payable public proceedRecipient; address public externalMetadata; @@ -139,6 +140,7 @@ contract AnybodyProblem is Ownable, ERC2981 { function batchSolve( uint256 runId, bool alsoMint, + uint256 day, uint256[] memory tickCounts, uint[2][] memory a, uint[2][2][] memory b, @@ -146,7 +148,7 @@ contract AnybodyProblem is Ownable, ERC2981 { uint[][] memory input ) public payable { require(!paused, 'Contract is paused'); - uint256 day = currentDay(); + // uint256 day = currentDay(); // TODO: this version does not enforce day for solving, just for minting NFT if (runId == 0) { runId = addNewRun(day); addNewLevelData(runId); @@ -420,16 +422,9 @@ contract AnybodyProblem is Ownable, ERC2981 { if (level == LEVELS) { runs[runId].solved = true; if (alsoMint) { - require(msg.value >= price / discount, 'Incorrect payment'); - require( - proceedRecipient != address(0), - 'Invalid recipient' - ); - (bool sent, bytes memory data) = proceedRecipient.call{ - value: msg.value - }(''); - Speedruns(speedruns).__mint(msg.sender, day, 1, ''); - emit EthMoved(proceedRecipient, sent, data, msg.value); + mint(priceToSave + (priceToMint / discount), day); + } else if (priceToSave > 0) { + makePayment(priceToSave); } emit RunSolved( msg.sender, @@ -445,15 +440,24 @@ contract AnybodyProblem is Ownable, ERC2981 { } } - function mint() public payable { - uint256 day = currentDay(); - require(msg.value == price, 'Incorrect payment'); + function makePayment(uint256 payment) internal { + require(msg.value >= payment, 'Incorrect payment'); require(proceedRecipient != address(0), 'Invalid recipient'); - (bool sent, bytes memory data) = proceedRecipient.call{ - value: msg.value - }(''); + (bool sent, bytes memory data) = proceedRecipient.call{value: payment}( + '' + ); + emit EthMoved(proceedRecipient, sent, data, payment); + } + + function mint(uint256 payment, uint256 day) internal { + require(day == currentDay(), 'Can only mint on the current day'); + require(payment == priceToMint, 'Incorrect price'); + makePayment(payment); Speedruns(speedruns).__mint(msg.sender, day, 1, ''); - emit EthMoved(proceedRecipient, sent, data, msg.value); + } + + function mint() public payable { + mint(msg.value, currentDay()); } function addToLeaderboard(uint256 runId) internal { @@ -865,8 +869,12 @@ contract AnybodyProblem is Ownable, ERC2981 { discount = discount_; } - function updatePrice(uint256 price_) public onlyOwner { - price = price_; + function updatePriceToSave(uint256 priceToSave_) public onlyOwner { + priceToSave = priceToSave_; + } + + function updatePriceToMint(uint256 priceToMint_) public onlyOwner { + priceToMint = priceToMint_; } function updatePaused(bool paused_) public onlyOwner { diff --git a/server/contractData/84532-ExternalMetadata.json b/server/contractData/84532-ExternalMetadata.json index 82186b20..7a1c5d7b 100644 --- a/server/contractData/84532-ExternalMetadata.json +++ b/server/contractData/84532-ExternalMetadata.json @@ -1,4 +1,4 @@ { - "address": "0x731D1B164F2BAad81810152163787D1E1eDBcFd0", + "address": "0x7BAfC364a068134dAE05525ce005A16601769c9A", "chain": { "chainId": 84532, "name": "unknown" } } diff --git a/server/contractData/ABI-84532-ExternalMetadata.json b/server/contractData/ABI-84532-ExternalMetadata.json index 73d6fcf3..37c71418 100644 --- a/server/contractData/ABI-84532-ExternalMetadata.json +++ b/server/contractData/ABI-84532-ExternalMetadata.json @@ -74,6 +74,28 @@ "stateMutability": "view", "type": "function" }, + { + "inputs": [ + { "internalType": "uint256", "name": "date", "type": "uint256" } + ], + "name": "getBestTimeEncoded", + "outputs": [{ "internalType": "string", "name": "", "type": "string" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "uint256", "name": "date", "type": "uint256" }, + { "internalType": "uint256", "name": "placeIndex", "type": "uint256" } + ], + "name": "getFastestTime", + "outputs": [ + { "internalType": "address", "name": "", "type": "address" }, + { "internalType": "string", "name": "sec", "type": "string" } + ], + "stateMutability": "view", + "type": "function" + }, { "inputs": [ { "internalType": "uint256", "name": "date", "type": "uint256" }