Verified contractExactMIT
MetamotocarRegional
Address0x45e7d55ff173c10cff3ececf57da4a4413ed9019
- Balance
0 ETH
- Transactions
51
- Compiler
solc 0.8.30
- Same code
Only this contract
Details
- Compiler
- solc 0.8.30+commit.73712a01
- Language
- solidity
- Optimization
- Yes, 1 runs
- EVM version
- shanghai
- Via IR
- yes
- License
- MIT
- Match
- Exactcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 26,386,918
- Creation transaction
- 0xafe06db372…1928e474be
MetamotocarRegional.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
interface IERC721Receiver {
function onERC721Received(address operator, address from, uint256 tokenId, bytes calldata data)
external returns (bytes4);
}
interface IMotoToken {
function decimals() external view returns (uint8);
function balanceOf(address account) external view returns (uint256);
function transfer(address to, uint256 amount) external returns (bool);
function transferFrom(address from, address to, uint256 amount) external returns (bool);
}
interface IUsdPriceFeed {
function decimals() external view returns (uint8);
function latestRoundData() external view returns (uint80, int256, uint256, uint256, uint80);
}
contract MetamotocarRegional {
string public constant name = "Metamotocar";
string public constant symbol = "META";
struct PropertySpecs {
int32 north;
int32 south;
int32 east;
int32 west;
uint16 rotation;
}
int32 private constant MAX_LATITUDE = 90_000_000;
int32 private constant MAX_LONGITUDE = 180_000_000;
uint256 public constant MAX_PARCELS_PER_ZONE = 150;
uint256 public constant MAX_BATCH_MINT = 10;
uint256 public constant MAX_SUPPLY = 11_000;
uint256 public constant MAX_PUBLIC_SUPPLY = 10_800;
uint256 public constant DEVELOPER_RESERVE = 200;
uint256 public constant MAX_PRICE_AGE = 2 hours;
// National reference. Actual rate is fixed by the parcel's zone.
uint256 public constant MOTO_PER_SQ_FT = 1 ether;
IMotoToken public immutable motoToken;
IUsdPriceFeed public immutable ethUsdFeed;
address public immutable developerWallet;
address payable public immutable mintProceedsRecipient;
uint8 public immutable feedDecimals;
uint256 public immutable maxMintsPerWallet;
uint8 public mintStage = 1;
uint256 public publicMinted;
uint256 public developerMinted;
struct Zone {
int32 north;
int32 south;
int32 east;
int32 west;
bytes32 sectionKey;
bool approved;
bool exists;
}
address public owner;
string public constant baseURI = "https://api.metamotocar.com/v12/metadata/";
uint256 public nextTokenId = 1;
mapping(uint256 => PropertySpecs) public propertySpecs;
mapping(uint256 => address) private _owners;
mapping(address => uint256) private _balances;
mapping(address => uint256[]) private _ownedTokenIds;
mapping(uint256 => uint256) private _ownedTokenIndex;
mapping(address => uint256) public mintedByWallet;
mapping(uint256 => address) private _tokenApprovals;
mapping(address => mapping(address => bool)) private _operatorApprovals;
mapping(uint32 => uint256[]) private _zoneTokenIds;
// 150 rectangles: north, south, east, west as signed 32-bit millionths of a degree.
bytes private constant PACKED_ZONES = hex"026d0314026bea5cfb988214fb9710020207a49e02068be6f8f1db0ff8f0885f027eee51027dd599fac6c51afac54c5001c70aeb01c5f233fa511d34fa4fd9c00200d19601ffb8def9524c62f950fb7602630afc0261f244fb86459ffb84d71d01c21d7501c104bdfa21435bfa2000ef01f5801301f4675bf9058770f904395a01f4ef5101f3d699fa3c1cc8fa3aced601f4c2de01f3aa26fa333b16fa31ed3001cf73bc01ce5b04fb2293fefb214ebc01cede5a01cdc5a2fa2d067bfa2bc1590239a3e702388b2ff8bdf259f8bc91770219cbb10218b2f9fb2f49bcfb2df2280262add70261951ffb0e74b7fb0d065502403863023f1fabf8ab5ed1f8a9fbe502d7296302d610abf8b5e08af8b44012025f4416025e2b5ef9c05ac7f9beed97021dbba3021ca2ebfa30bb9efa2f62f001e681c001e56908f9a8a2bbf9a7584102296d77022854bff921e3def92087d80286955302857c9bfbc516d6fbc39b100287431902862a61fb0cb3e9fb0b37dd02b7631302b64a5bf8b14af0f8afba2a0218458802172cd0faa3dc15faa284ed0258381c02571f64fb6fb9b6fb6e4ef20291a49002908bd8fac27c37fac0fbfb0218346802171bb0f9a55e79f9a407550231ceb80230b600f8dcc871f8db69f101eb2a2801ea1170f964e4d5f9639941024d0b6a024bf2b2f8c33e84f8c1d77a0203bab90202a201faf878c3faf7271702558cff02547447fa5dfbc5fa5c91e901fe2e9701fd15dff95801a0f956b16002234c98022233e0fb50b58ffb4f5b4d02519d93025084dbf9c22e99f9c0c60d0189d8970188bfdffb38b8f7fb37813b02762acd02751215fa4711d7fa459c630231c2610230a9a9fb789269fb7733eb020400930202e7dbf8f58e6bf8f43cad0240ded2023fc61af8b7ad77f8b64a5502aea25802ad89a0fa719d00fa701040021bfeaf021ae5f7f8e84c39f8e6f4090227d1290226b871fa49535bfa47f7cd01ab568201aa3dcafb1614b4fb14d6da025e77bd025d5f05f9c2cdf7f9c1610f01f3858001f26cc8fa36a579fa3557e1023fa96a023e90b2fa335034fa31ed740279759a02785ce2fb22670efb20f05c01cb208801ca07d0faa45784faa313300226005a0224e7a2f9258214f924270c0205246a02040bb2f8fbce44f8fa7c3a01b3024e01b1e996fb27c67bfb268721024500c20243e80afaf7f718faf692a8024406450242ed8df8c5ac5af8c4483a026df358026cdaa0fb94f097fb937e2d0206673b02054e83f901621ff9000fc10202709b020157e3f8fb9cb6f8fa4b5e01a80b6801a6f2b0fa35df13fa34a1db020352e802023a30f8f9e8b5f8f897230255c7b30254aefbfaf74013faf5d62302274fde02263726fb3eaaacfb3d4f4402699cdc02688424fb3c6370fb3af29802ae6a0102ad5149fa741e94fa7291ee0225872402246e6cfb4cc9b6fb4b6ed0026dc155026ca89dfb9695b4fb95235c026f4388026e2ad0fa3d954bfa3c2265022a49a5022930edf9248f06f92332c001f8dced01f7c435fa3c65cdfa3b16e301fcd2e501fbba2df9579763f956477b03a5fe4603a4e58ef71b3d35f718f6f9029204230290eb6bfaac28d2faaaa86e025c0505025aec4df8dbf255f8da864501fc672901fb4e71f955eebcf9549eee024e150f024cfc57fa9fadcbfa9e466901f2683201f14f7af9072427f905d6d50273811d02726865faed8d34faec18be028f0928028df070fb4d71f0fb4bf2c40200a98901ff90d1f9edf4fef9eca41c01a5161701a3fd5ffa1288b7fa114c0f01a0d106019fb84efb35fd48fb34c16e01a82c8301a713cbfb1391fcfb1254be027c4aa3027b31ebfb05603efb03e8780200391301ff205bf950c696f94f75d002276f2b02265673fb37fedcfb36a36a01f5eaf001f4d238fa3901f2fa37b3c202303b2c022f2274fb746928fb730b2001f6b65e01f59da6fa3e30f3fa3ce2910202878c02016ed4f955c9e7f95478890299cd3e0298b486f9133425f911b083023d3b63023c22abfb628056fb611e5801fa75bf01f95d07fa3b4264fa39f314019717540195fe9cfb1d6ed5fb1c34c301fb284101fa0f89fa3dad5efa3c5de00211fe540210e59cfad615fbfad4c0890233f2e30232da2bfb7548f2fb73e9cc018b4ad1018a3219fb3748edfb3610f102d7e35302d6ca9bf900ec83f8ff4ba902d18f4302d0768bf8b43811f8b29a7f020db3d4020c9b1cf8f07cd0f8ef2886023cab18023b9260f8bc044af8baa27a0209803002086778f902e36cf901903e020905520207ec9af900521ef8feff12023ed9f9023dc141f8ca5517f8c8f297026ec13c026da884f954caecf953583602062d1102051459f9043e72f902ec240285878202846ecafbb90a87fbb78f2b0298ed340297d47cfa3cbe68fa3b3b240271552202703c6afb99991efb982576027ae54a0279cc92fa6c5a9cfa6ae35e01f3306e01f217b6fa383b7bfa36edf70217de6a0216c5b2fb4ba13bfb4a4a2f02126a6d021151b5fa7f632bfa7e0d9d029344e302922c2bfb606979fb5ee8910219a7fb02188f43f9eedd93f9ed860901d13b7501d022bdfafb0c63faf9c6bd0251f2ae0250d9f6fa5bd73cfa5a6e9401f09d4b01ef8493faf18fb0faf042cc02256ad40224521cfaffb698fafe5bbc02901560028efca8fae5bfbafae44022020415a60202fceef94ef998f94da7d401d4823201d3697afac037e2fabef18402b8ea8002b7d1c8f8b21be8f8b08a6a020a63e802094b30f8e5b35af8e45ff0020021e201ff092afad43d74fad2ecb4027eb7ac027d9ef4fbbef8bafbbd800601ee25b301ed0cfbfadc507afadb043002179cc20216840afaebe1fbfaea8b01018d1d78018c04c0fa312c76fa2ff4280202bd330201a47bf8f8103bf8f6bed101fe03da01fceb22f954b695f953665f027362e402724a2cfb24cf20fb235ab6022e81fa022d6942facbe682faca88fe018f6e87018e55cffb39ab30fb38727a020a1d6d020904b5f8f45fe5f8f30c8f0207e98e0206d0d6f8fe231df8fcd05b024ab57902499cc1f8c48322f8c31cdc0222871202216e5afb4decf0fb4c92e8023649040235304cfb710df1fb6fae1702ae085802acefa0f8ab979ef8aa0b24027dcedb027cb623fabd88fafabc10a0024b2f5c024a16a4f8b05a32f8aef3c402a0cd6c029fb4b4f8aa1da5f8a89705020955de02083d26f8febf1ef8fd6bfc018d8058018c67a0fb36b765fb357f0501eff41b01eedb63fa697e9cfa6831e2020252ed02013a35f94cc4e6f94b7396026b43d4026a2b1cf9bd8f37f9bc1dc70223a2b7022289fffad9fe45fad8a3eb01fb83f501fa6b3df902b417f9016483";
// FHFA 2022 CBSA as-is land-value ratios, six decimal MOTO units, zone IDs 1..150.
bytes private constant PACKED_ZONE_RATES = hex"003877170048d289000893ac0006bf4a000ca9e8000bb5e6000419ff0028dc43000782d5000782d50005b8e5000efefb0079508c00044c8d00045e8500802d16001a349b0013bbed000281c80003531c000b723600160a510003f7bc0012ab16000267750009bfac0003c95b0005010e0007fc0100063211000fd6940003e5c400034980000ca9e800050e6c000754df0016f15f0002fbc90006d7f10048d28900802d160006cca90004cb9200028d7b000a883a0013bbed000782d5000177350002b6d8000a49f9000b72360048d28900057d260003d00a00116e6000387717001140d50048d2890002fff70048d2890002a4760001ba0f00031f4d0006cca90003edb500387717000431d0000b7236000782d5000ca9e8000486a1000b38f8000b1070000ca9e800038b190028dc430001c05400025eaf000226b2000579ce00090ac1000a883a000236fd000ca9e800018bae000782d50006d7f1000782d5000ca9e8000b9b930003bfbf000782d5000870fe000782d500014c2c0006d7f10016f15f0005b6cf001a349b0048d28900802d16001140d5001140d5000c2a0e0011bad6001140d500038d300003c3ec00387717000323e5000782d500014d02000180660001eddf00016327000273fe00034980000184ff00017de40002f9b2000ca9e8000126fc0012ab1600255b3000023fc300071ef9000153b10001b9390002a4e10048d289000ca9e80001eff5000199780016f15f0048d289001140d5000fd69400050e6c0006d7f10007b991000893ac0010f535000785c2001140d50016f15f000140e4000ca9e80009eee3000521a50028dc43";
// Sine for 0 through 90 degrees, scaled by one million.
bytes private constant SIN_TABLE = hex"000000000000442c000088530000cc700001107c00015474000198500001dc0d00021fa5000263120002a6500002e95900032c2800036eb70003b1020003f303000434b5000476140004b7190004f7c000053804000577e00005b74f0005f64b000634d1000672da0006b0630006ed66000729e0000765ca0007a1200007dbde000815ff00084f7f000888590008c0880008f80900092ed7000964ed00099a480009cee4000a02bb000a35cb000a680e000a9982000aca23000af9ec000b28da000b56e9000b8416000bb05c000bdbba000c062b000c2fac000c5839000c7fd0000ca66e000ccc0f000cf0b0000d144f000d36e9000d587c000d7904000d987f000db6ea000dd444000df089000e0bb9000e25d0000e3ecc000e56ad000e6d6f000e8311000e9791000eaaee000ebd26000ece38000ede22000eece4000efa7b000f06e8000f1228000f1c3c000f2522000f2cda000f3363000f38bc000f3ce6000f3fdf000f41a8000f4240";
mapping(uint256 => uint32) private _tokenZone;
mapping(uint256 => uint32) public purchasedLotSqFt;
bool private _minting;
bool private _resizing;
event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);
event Approval(address indexed tokenOwner, address indexed approved, uint256 indexed tokenId);
event ApprovalForAll(address indexed tokenOwner, address indexed operator, bool approved);
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
event MetadataUpdate(uint256 tokenId);
event BatchMetadataUpdate(uint256 fromTokenId, uint256 toTokenId);
event ParcelPlaced(uint256 indexed tokenId, uint32 indexed zoneId);
event LotSizeChanged(uint256 indexed tokenId, int32 changeSqFt, uint256 currentLotSqFt, uint256 motoAmount);
event MintStageChanged(uint8 indexed stage, uint256 supplyCap);
event MintPaid(address indexed buyer, uint256 indexed firstTokenId, uint256 quantity, uint256 usdCents, uint256 ethPaid);
event MintProceedsWithdrawn(address indexed recipient, uint256 amount);
modifier onlyOwner() {
require(msg.sender == owner, "Not contract owner");
_;
}
modifier nonReentrantMint() {
require(!_minting, "Mint in progress");
_minting = true;
_;
_minting = false;
}
modifier nonReentrantResize() {
require(!_resizing, "Resize in progress");
_resizing = true;
_;
_resizing = false;
}
constructor(uint256 walletMintLimit, address motoToken_, address ethUsdFeed_,
address developerWallet_, address payable mintProceedsRecipient_)
{
require(walletMintLimit > 0 && walletMintLimit <= 10_000, "Invalid wallet mint limit");
require(motoToken_ != address(0) && motoToken_.code.length != 0, "Invalid MOTO token");
require(IMotoToken(motoToken_).decimals() == 18, "MOTO must use 18 decimals");
require(ethUsdFeed_ != address(0) && ethUsdFeed_.code.length != 0, "Invalid ETH/USD feed");
uint8 decimals_ = IUsdPriceFeed(ethUsdFeed_).decimals();
require(decimals_ <= 18, "Unsupported feed decimals");
require(developerWallet_ != address(0) && mintProceedsRecipient_ != address(0), "Invalid payout wallet");
motoToken = IMotoToken(motoToken_);
ethUsdFeed = IUsdPriceFeed(ethUsdFeed_);
feedDecimals = decimals_;
developerWallet = developerWallet_;
mintProceedsRecipient = mintProceedsRecipient_;
maxMintsPerWallet = walletMintLimit;
owner = msg.sender;
emit OwnershipTransferred(address(0), msg.sender);
}
function supportsInterface(bytes4 interfaceId) external pure returns (bool) {
return interfaceId == 0x01ffc9a7 || interfaceId == 0x80ac58cd
|| interfaceId == 0x5b5e139f || interfaceId == 0x49064906;
}
function notifyMetadataUpdate(uint256 tokenId) external {
require(msg.sender == ownerOf(tokenId), "Not token owner");
emit MetadataUpdate(tokenId);
}
function transferOwnership(address newOwner) external onlyOwner {
require(newOwner != address(0), "Zero address");
emit OwnershipTransferred(owner, newOwner);
owner = newOwner;
}
// Four owner-opened public stages: 1,000 + 2,000 + 3,000 + 4,800 NFTs.
function mintStageCap() public view returns (uint256) {
if (mintStage == 1) return 1_000;
if (mintStage == 2) return 3_000;
if (mintStage == 3) return 6_000;
return MAX_PUBLIC_SUPPLY;
}
function mintStageRemaining() external view returns (uint256) {
return mintStageCap() - publicMinted;
}
function setMintStage(uint8 nextStage) external onlyOwner {
require(nextStage == mintStage + 1 && nextStage <= 4, "Open the next mint stage");
mintStage = nextStage;
emit MintStageChanged(nextStage, mintStageCap());
}
function balanceOf(address tokenOwner) public view returns (uint256) {
require(tokenOwner != address(0), "Zero address");
return _balances[tokenOwner];
}
function tokensOfOwner(address tokenOwner) external view returns (uint256[] memory) {
return _ownedTokenIds[tokenOwner];
}
function ownerOf(uint256 tokenId) public view returns (address) {
address tokenOwner = _owners[tokenId];
require(tokenOwner != address(0), "Unknown parcel");
return tokenOwner;
}
function approve(address to, uint256 tokenId) external {
address tokenOwner = ownerOf(tokenId);
require(to != tokenOwner, "Approval to owner");
require(msg.sender == tokenOwner || isApprovedForAll(tokenOwner, msg.sender), "Not authorized");
_tokenApprovals[tokenId] = to;
emit Approval(tokenOwner, to, tokenId);
}
function getApproved(uint256 tokenId) public view returns (address) {
ownerOf(tokenId);
return _tokenApprovals[tokenId];
}
function setApprovalForAll(address operator, bool approved) external {
require(operator != msg.sender, "Self approval");
_operatorApprovals[msg.sender][operator] = approved;
emit ApprovalForAll(msg.sender, operator, approved);
}
function isApprovedForAll(address tokenOwner, address operator) public view returns (bool) {
return _operatorApprovals[tokenOwner][operator];
}
function transferFrom(address from, address to, uint256 tokenId) public {
address tokenOwner = ownerOf(tokenId);
require(tokenOwner == from, "Wrong owner");
require(to != address(0), "Zero address");
require(
msg.sender == tokenOwner || getApproved(tokenId) == msg.sender || isApprovedForAll(tokenOwner, msg.sender),
"Not authorized"
);
delete _tokenApprovals[tokenId];
_removeOwnedToken(from, tokenId);
_ownedTokenIndex[tokenId] = _ownedTokenIds[to].length;
_ownedTokenIds[to].push(tokenId);
_balances[from] -= 1;
_balances[to] += 1;
_owners[tokenId] = to;
emit Transfer(from, to, tokenId);
}
function _removeOwnedToken(address tokenOwner, uint256 tokenId) private {
uint256 index = _ownedTokenIndex[tokenId];
uint256 lastIndex = _ownedTokenIds[tokenOwner].length - 1;
if (index != lastIndex) {
uint256 lastId = _ownedTokenIds[tokenOwner][lastIndex];
_ownedTokenIds[tokenOwner][index] = lastId;
_ownedTokenIndex[lastId] = index;
}
_ownedTokenIds[tokenOwner].pop();
}
function safeTransferFrom(address from, address to, uint256 tokenId) external {
safeTransferFrom(from, to, tokenId, "");
}
function safeTransferFrom(address from, address to, uint256 tokenId, bytes memory data) public {
transferFrom(from, to, tokenId);
_checkReceiver(msg.sender, from, to, tokenId, data);
}
/// @notice Allocate IDs 10801 through 11000 to the developer wallet, independently of public minting.
function mintDeveloperReserve(uint256 quantity) external onlyOwner nonReentrantMint {
require(quantity != 0 && quantity <= MAX_BATCH_MINT, "Invalid batch size");
require(developerMinted + quantity <= DEVELOPER_RESERVE, "Reserve exhausted");
uint256 firstTokenId = MAX_PUBLIC_SUPPLY + developerMinted + 1;
developerMinted += quantity;
for (uint256 i; i < quantity; ++i) _mintParcel(developerWallet, firstTokenId + i, false);
}
/// @notice USD cents for one future public NFT, including its deterministic lot premium.
function _mintPriceUsdCents(uint256 publicIndex, uint256 tokenId) private pure returns (uint256) {
uint256 cents = publicIndex < 500 ? 300 : publicIndex < 1_000 ? 600 :
publicIndex < 3_000 ? 900 : publicIndex < 6_000 ? 1_300 : 1_800;
if (_lotSize(tokenId) >= 20_000) cents = cents * 5 / 4;
return cents;
}
/// @notice Quote the next sequential public tokens using a fresh ETH/USD feed answer.
function mintQuote(uint256 quantity)
public view returns (uint256 firstTokenId, uint256 usdCents, uint256 ethWei)
{
_validateMint();
require(quantity != 0 && quantity <= MAX_BATCH_MINT, "Invalid batch size");
require(quantity <= mintStageCap() - publicMinted, "Mint stage sold out");
firstTokenId = nextTokenId;
for (uint256 i; i < quantity; ++i) {
usdCents += _mintPriceUsdCents(publicMinted + i, firstTokenId + i);
}
(uint80 roundId, int256 answer,, uint256 updatedAt, uint80 answeredInRound) = ethUsdFeed.latestRoundData();
require(answer > 0 && updatedAt != 0 && updatedAt <= block.timestamp &&
block.timestamp - updatedAt <= MAX_PRICE_AGE && answeredInRound >= roundId && roundId != 0,
"ETH/USD price unavailable");
uint256 numerator = usdCents * 10 ** (18 + feedDecimals);
uint256 denominator = uint256(answer) * 100;
ethWei = (numerator + denominator - 1) / denominator;
}
function mintParcel() external payable nonReentrantMint returns (uint256 tokenId) {
tokenId = _mintPaid(1);
}
function mintBatch(uint256 quantity) external payable nonReentrantMint returns (uint256 firstTokenId) {
firstTokenId = _mintPaid(quantity);
}
function _mintPaid(uint256 quantity) private returns (uint256 firstTokenId) {
require(quantity <= maxMintsPerWallet - mintedByWallet[msg.sender], "Wallet mint limit");
uint256 usdCents;
uint256 requiredWei;
(firstTokenId, usdCents, requiredWei) = mintQuote(quantity);
require(msg.value >= requiredWei, "Insufficient ETH for mint");
publicMinted += quantity;
nextTokenId += quantity;
for (uint256 i; i < quantity; ++i) _mintParcel(msg.sender, firstTokenId + i, true);
uint256 refund = msg.value - requiredWei;
if (refund != 0) {
(bool sent,) = payable(msg.sender).call{value: refund}("");
require(sent, "ETH refund failed");
}
emit MintPaid(msg.sender, firstTokenId, quantity, usdCents, requiredWei);
}
function withdrawMintProceeds() external onlyOwner nonReentrantMint {
uint256 amount = address(this).balance;
require(amount != 0, "No mint proceeds");
(bool sent,) = mintProceedsRecipient.call{value: amount}("");
require(sent, "ETH withdrawal failed");
emit MintProceedsWithdrawn(mintProceedsRecipient, amount);
}
function totalSupply() external view returns (uint256) {
return publicMinted + developerMinted;
}
function lotSizeSqFt(uint256 tokenId) external view returns (uint256) {
ownerOf(tokenId);
return uint256(_lotSize(tokenId)) + purchasedLotSqFt[tokenId];
}
function baseLotSizeSqFt(uint256 tokenId) external view returns (uint32) {
ownerOf(tokenId);
return _lotSize(tokenId);
}
function previewBaseLotSizeSqFt(uint256 tokenId) external pure returns (uint32) {
require(tokenId >= 1 && tokenId <= MAX_SUPPLY, "Invalid token ID");
return _lotSize(tokenId);
}
function propertySizeSqFt(uint256 tokenId) external view returns (uint32) {
ownerOf(tokenId);
return _propertySize(tokenId);
}
function _lotSize(uint256 tokenId) private pure returns (uint32) {
uint32[26] memory sizes = [uint32(15617), 15617, 20210, 18121, 15899, 16005, 16072,
16643, 17102, 17707, 18172, 17730, 19217, 22284, 18060, 18544, 19555,
20205, 21231, 20857, 20032, 21300, 21780, 21823, 22165, 26252];
uint256 index = uint256(keccak256(abi.encodePacked("LAND", _toString(tokenId)))) % sizes.length;
return sizes[index];
}
function _propertySize(uint256 tokenId) private pure returns (uint32) {
uint32[26] memory sizes = [uint32(5617), 5617, 4210, 8121, 5899, 6005, 6072,
6643, 7102, 7707, 8172, 7730, 9217, 4284, 8060, 9124, 9707,
7205, 1231, 7857, 12032, 8300, 5780, 6823, 7165, 3252];
uint256 index = uint256(keccak256(abi.encodePacked("HOMESIZE", _toString(tokenId)))) % sizes.length;
return sizes[index];
}
function zoneOf(uint256 tokenId) external view returns (uint32) {
ownerOf(tokenId);
return _tokenZone[tokenId];
}
function zoneParcelCount(uint32 zoneId) external view returns (uint256) {
return _zoneTokenIds[zoneId].length;
}
function placeParcel(uint256 tokenId, uint32 zoneId, int32 north, int32 south, int32 east, int32 west, uint16 rotation) external
{
address tokenOwner = ownerOf(tokenId);
require(msg.sender == tokenOwner, "Not token owner");
require(_tokenZone[tokenId] == 0, "Already placed");
require(isZoneApproved(zoneId), "Unknown zone");
_validateBounds(north, south, east, west);
require(rotation < 360, "Invalid rotation");
PropertySpecs memory specs = PropertySpecs(north, south, east, west, rotation);
require(_withinZone(_zone(zoneId), specs), "Parcel outside zone");
require(_lotMatches(uint256(_lotSize(tokenId)) + purchasedLotSqFt[tokenId], lotAreaSqFt(zoneId, north, south, east, west)), "Lot size mismatch");
require(_zoneTokenIds[zoneId].length < MAX_PARCELS_PER_ZONE, "Zone full");
_requireNoOverlap(zoneId, specs, 0);
propertySpecs[tokenId] = specs;
_tokenZone[tokenId] = zoneId;
_zoneTokenIds[zoneId].push(tokenId);
emit ParcelPlaced(tokenId, zoneId);
emit MetadataUpdate(tokenId);
}
// The zone's midpoint fixes the longitude scale for every parcel in that zone.
// The result is a rounded geographic estimate in square feet, not a survey.
function lotAreaSqFt(uint32 zoneId, int32 north, int32 south, int32 east, int32 west)
public pure returns (uint256)
{
Zone memory zone = _zone(zoneId);
_validateBounds(north, south, east, west);
uint256 lat = uint256(_abs((int256(zone.north) + int256(zone.south)) / 2));
uint256 cosine = _cosineScaled(lat);
uint256 areaUnits = uint256(int256(north) - int256(south)) * uint256(int256(east) - int256(west));
return (areaUnits * 133_163_176 * cosine + 500_000_000_000_000_000) / 1_000_000_000_000_000_000;
}
function _cosineScaled(uint256 lat) private pure returns (uint256) {
uint256 x = lat * 3_141_592_654 / 180_000_000; // radians, 1e9 scale
uint256 x2 = x * x / 1_000_000_000;
uint256 x4 = x2 * x2 / 1_000_000_000;
uint256 x6 = x4 * x2 / 1_000_000_000;
uint256 x8 = x6 * x2 / 1_000_000_000;
uint256 x10 = x8 * x2 / 1_000_000_000;
uint256 cosine = 1_000_000_000 + x4 / 24 + x8 / 40_320;
uint256 subtract = x2 / 2 + x6 / 720 + x10 / 3_628_800;
if (cosine <= subtract) return 0;
return cosine - subtract;
}
function _abs(int256 value) private pure returns (int256) {
return value < 0 ? -value : value;
}
function zoneCatalogFixed() external pure returns (bool) { return true; }
function _zone(uint32 zoneId) private pure returns (Zone memory zone) {
require(zoneId >= 1 && zoneId <= 150, "Unknown zone");
bytes memory packed = PACKED_ZONES;
uint256 offset = uint256(zoneId - 1) * 16;
uint128 rectangle;
assembly { rectangle := shr(128, mload(add(add(packed, 32), offset))) }
zone = Zone(
int32(uint32(rectangle >> 96)),
int32(uint32(rectangle >> 64)),
int32(uint32(rectangle >> 32)),
int32(uint32(rectangle)),
bytes32(0), true, true
);
}
function zones(uint32 zoneId) external pure returns (int32 north, int32 south, int32 east, int32 west,
bytes32 sectionKey, bool approved, bool exists)
{
if (zoneId == 0 || zoneId > 150) return (0, 0, 0, 0, bytes32(0), false, false);
Zone memory zone = _zone(zoneId);
return (zone.north, zone.south, zone.east, zone.west, bytes32(0), zone.approved, true);
}
function isZoneApproved(uint32 zoneId) public pure returns (bool) {
return zoneId >= 1 && zoneId <= 150;
}
function zoneCount() external pure returns (uint256) { return 150; }
/// @notice Fixed 2022 FHFA metro ratio applied to the national 1 MOTO/sq-ft reference.
/// @dev These are relative game rates, not current market quotes or real land appraisals.
function zoneMotoPerSqFt(uint32 zoneId) public pure returns (uint256) {
require(zoneId >= 1 && zoneId <= 150, "Unknown zone");
bytes memory packed = PACKED_ZONE_RATES;
uint256 offset = uint256(zoneId - 1) * 4;
uint32 rateMicro;
assembly { rateMicro := shr(224, mload(add(add(packed, 32), offset))) }
return uint256(rateMicro) * 1e12;
}
function zoneIdAt(uint256 index) external pure returns (uint32) {
require(index < 150, "Zone index out of range");
return uint32(index + 1);
}
function zoneTokenIdAt(uint32 zoneId, uint256 index) external view returns (uint256) {
return _zoneTokenIds[zoneId][index];
}
function zoneRemainingCapacity(uint32 zoneId) external view returns (uint256) {
if (!isZoneApproved(zoneId)) return 0;
return MAX_PARCELS_PER_ZONE - _zoneTokenIds[zoneId].length;
}
function relocateParcel(uint256 tokenId, int32 north, int32 south, int32 east, int32 west, uint16 rotation) external {
address tokenOwner = ownerOf(tokenId);
require(msg.sender == tokenOwner, "Not token owner");
_validateBounds(north, south, east, west);
require(rotation < 360, "Invalid rotation");
uint32 zoneId = _tokenZone[tokenId];
require(zoneId != 0, "Parcel not placed");
PropertySpecs memory updated = propertySpecs[tokenId];
updated.north = north;
updated.south = south;
updated.east = east;
updated.west = west;
updated.rotation = rotation;
require(_withinZone(_zone(zoneId), updated), "Parcel outside zone");
require(_lotMatches(uint256(_lotSize(tokenId)) + purchasedLotSqFt[tokenId], lotAreaSqFt(zoneId, north, south, east, west)), "Lot size changed");
_requireNoOverlap(zoneId, updated, tokenId);
propertySpecs[tokenId] = updated;
emit MetadataUpdate(tokenId);
}
/// @notice Expand or reduce a placed parcel at its fixed regional MOTO rate.
/// @dev The original lot must be placed before expansion so a cheaper zone cannot be
/// selected before placement. The full deposit stays here to back later refunds.
function changeLotSize(uint256 tokenId, int32 changeSqFt, int32 north, int32 south, int32 east, int32 west, uint16 rotation)
external nonReentrantResize
{
address tokenOwner = ownerOf(tokenId);
require(msg.sender == tokenOwner, "Not token owner");
require(changeSqFt != 0, "No size change");
int256 nextPurchased = int256(uint256(purchasedLotSqFt[tokenId])) + int256(changeSqFt);
require(nextPurchased >= 0, "Below original lot size");
uint256 nextLotSize = uint256(_lotSize(tokenId)) + uint256(nextPurchased);
require(nextLotSize <= type(uint32).max, "Lot too large");
uint32 zoneId = _tokenZone[tokenId];
require(zoneId != 0, "Place parcel before resizing");
_validateBounds(north, south, east, west);
require(rotation < 360, "Invalid rotation");
_resizePlacedParcel(tokenId, zoneId, nextLotSize, changeSqFt, PropertySpecs(north, south, east, west, rotation));
uint256 amount = uint256(changeSqFt > 0 ? int256(changeSqFt) : -int256(changeSqFt)) * zoneMotoPerSqFt(zoneId);
if (changeSqFt > 0) {
uint256 priorBalance = motoToken.balanceOf(address(this));
require(motoToken.transferFrom(msg.sender, address(this), amount), "MOTO payment failed");
require(motoToken.balanceOf(address(this)) == priorBalance + amount, "MOTO amount received differs");
}
purchasedLotSqFt[tokenId] = uint32(uint256(nextPurchased));
if (changeSqFt < 0) require(motoToken.transfer(tokenOwner, amount), "MOTO refund failed");
emit LotSizeChanged(tokenId, changeSqFt, nextLotSize, amount);
emit MetadataUpdate(tokenId);
}
function _resizePlacedParcel(uint256 tokenId, uint32 zoneId, uint256 nextLotSize, int32 changeSqFt,
PropertySpecs memory updated) private
{
require(_withinZone(_zone(zoneId), updated), "Parcel outside zone");
uint256 newArea = lotAreaSqFt(zoneId, updated.north, updated.south, updated.east, updated.west);
require(_lotMatches(nextLotSize, newArea), "Lot size mismatch");
PropertySpecs memory previous = propertySpecs[tokenId];
uint256 oldArea = lotAreaSqFt(zoneId, previous.north, previous.south, previous.east, previous.west);
if (changeSqFt > 0) require(newArea >= oldArea + uint256(int256(changeSqFt)), "Area did not grow");
else require(oldArea >= newArea + uint256(-int256(changeSqFt)), "Area did not shrink");
_requireNoOverlap(zoneId, updated, tokenId);
propertySpecs[tokenId] = updated;
}
function _validateMint() private view {
require(publicMinted < mintStageCap(), "Mint stage sold out");
}
function _mintParcel(address to, uint256 tokenId, bool countWalletMint) private {
if (countWalletMint) mintedByWallet[to] += 1;
_ownedTokenIndex[tokenId] = _ownedTokenIds[to].length;
_ownedTokenIds[to].push(tokenId);
_balances[to] += 1;
_owners[tokenId] = to;
emit Transfer(address(0), to, tokenId);
_checkReceiver(msg.sender, address(0), to, tokenId, "");
}
function _validateSpecs(PropertySpecs calldata specs) private pure {
_validateBounds(specs.north, specs.south, specs.east, specs.west);
require(specs.rotation < 360, "Invalid rotation");
}
function _lotMatches(uint256 saved, uint256 measured) private pure returns (bool) {
uint256 tolerance = saved / 200; // 0.5%, or one square foot for small lots
if (tolerance == 0) tolerance = 1;
return measured >= saved && measured - saved <= tolerance;
}
function _validateBounds(int32 north, int32 south, int32 east, int32 west) private pure {
require(north <= MAX_LATITUDE && north >= -MAX_LATITUDE, "Invalid north");
require(south <= MAX_LATITUDE && south >= -MAX_LATITUDE, "Invalid south");
require(east <= MAX_LONGITUDE && east >= -MAX_LONGITUDE, "Invalid east");
require(west <= MAX_LONGITUDE && west >= -MAX_LONGITUDE, "Invalid west");
require(north > south, "Invalid latitude range");
require(east > west, "Invalid longitude range");
}
function _withinZone(Zone memory zone, PropertySpecs memory specs) private pure returns (bool) {
if (specs.rotation == 0) {
return specs.north <= zone.north && specs.south >= zone.south
&& specs.east <= zone.east && specs.west >= zone.west;
}
int256[8] memory points = _corners(specs);
int256 scale = 2_000_000;
for (uint256 i; i < 4; ++i) {
if (points[2 * i] < int256(zone.west) * scale || points[2 * i] > int256(zone.east) * scale
|| points[2 * i + 1] < int256(zone.south) * scale || points[2 * i + 1] > int256(zone.north) * scale) return false;
}
return true;
}
function _sinDeg(uint16 degrees) private pure returns (int256) {
uint16 quadrant = degrees / 90;
uint16 offset = degrees % 90;
uint16 index = quadrant % 2 == 0 ? offset : 90 - offset;
bytes memory table = SIN_TABLE;
uint256 value;
assembly { value := shr(224, mload(add(add(table, 32), mul(index, 4)))) }
return quadrant < 2 ? int256(value) : -int256(value);
}
function _corners(PropertySpecs memory specs) private pure returns (int256[8] memory points) {
int256 cosine = _sinDeg(uint16((uint256(specs.rotation) + 90) % 360));
int256 sine = _sinDeg(specs.rotation);
int256 centerX = int256(specs.east) + int256(specs.west);
int256 centerY = int256(specs.north) + int256(specs.south);
int256 width = int256(specs.east) - int256(specs.west);
int256 height = int256(specs.north) - int256(specs.south);
for (uint256 i; i < 4; ++i) {
int256 dx = i == 0 || i == 3 ? -width : width;
int256 dy = i < 2 ? -height : height;
points[2 * i] = centerX * 1_000_000 + dx * cosine - dy * sine;
points[2 * i + 1] = centerY * 1_000_000 + dx * sine + dy * cosine;
}
}
function _separated(int256[8] memory a, int256[8] memory b, uint256 edge) private pure returns (bool) {
int256 dx = a[2 * ((edge + 1) % 4)] - a[2 * edge];
int256 dy = a[2 * ((edge + 1) % 4) + 1] - a[2 * edge + 1];
int256 minA = type(int256).max;
int256 minB = type(int256).max;
int256 maxA = type(int256).min;
int256 maxB = type(int256).min;
for (uint256 i; i < 4; ++i) {
int256 pa = a[2 * i + 1] * dx - a[2 * i] * dy;
int256 pb = b[2 * i + 1] * dx - b[2 * i] * dy;
if (pa < minA) minA = pa;
if (pa > maxA) maxA = pa;
if (pb < minB) minB = pb;
if (pb > maxB) maxB = pb;
}
return maxA <= minB || maxB <= minA;
}
function _overlaps(PropertySpecs memory a, PropertySpecs memory b) private pure returns (bool) {
if (a.rotation == 0 && b.rotation == 0) {
return !(a.south >= b.north || a.north <= b.south || a.west >= b.east || a.east <= b.west);
}
int256[8] memory ap = _corners(a);
int256[8] memory bp = _corners(b);
for (uint256 i; i < 4; ++i) {
if (_separated(ap, bp, i) || _separated(bp, ap, i)) return false;
}
return true;
}
function _requireNoOverlap(uint32 zoneId, PropertySpecs memory specs, uint256 excludedTokenId)
private view
{
uint256[] storage tokens = _zoneTokenIds[zoneId];
for (uint256 i; i < tokens.length; ++i) {
uint256 tokenId = tokens[i];
if (tokenId == excludedTokenId) continue;
require(!_overlaps(specs, propertySpecs[tokenId]), "Parcel overlaps");
}
}
function tokenURI(uint256 tokenId) external view returns (string memory) {
ownerOf(tokenId);
return string.concat(baseURI, _toString(tokenId), ".json");
}
function _toString(uint256 value) private pure returns (string memory) {
if (value == 0) return "0";
uint256 digits;
uint256 temp = value;
while (temp != 0) {
digits++;
temp /= 10;
}
bytes memory buffer = new bytes(digits);
while (value != 0) {
digits--;
buffer[digits] = bytes1(uint8(48 + value % 10));
value /= 10;
}
return string(buffer);
}
function _checkReceiver(address operator, address from, address to, uint256 tokenId, bytes memory data) private {
if (to.code.length == 0) return;
try IERC721Receiver(to).onERC721Received(operator, from, tokenId, data) returns (bytes4 response) {
require(response == IERC721Receiver.onERC721Received.selector, "Invalid receiver");
} catch {
revert("Invalid receiver");
}
}
}
Compiler settingsShow
{
"viaIR": true,
"optimizer": {
"runs": 1,
"enabled": true
},
"evmVersion": "shanghai"
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.