initial commit
This commit is contained in:
86
src/LikeRegistry.sol
Normal file
86
src/LikeRegistry.sol
Normal file
@@ -0,0 +1,86 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.8.19;
|
||||
|
||||
import "./SoulboundProfileNFT.sol";
|
||||
import "@openzeppelin/contracts/access/Ownable.sol";
|
||||
import "./MultiSig.sol";
|
||||
|
||||
contract LikeRegistry is Ownable{
|
||||
struct Like {
|
||||
address liker;
|
||||
address liked;
|
||||
uint256 timestamp;
|
||||
}
|
||||
|
||||
SoulboundProfileNFT public profileNFT;
|
||||
|
||||
uint256 immutable FIXEDFEE = 10;
|
||||
uint256 totalFees;
|
||||
|
||||
mapping(address => mapping(address => bool)) public likes;
|
||||
mapping(address => address[]) public matches;
|
||||
mapping(address => uint256) public userBalances;
|
||||
|
||||
event Liked(address indexed liker, address indexed liked);
|
||||
event Matched(address indexed user1, address indexed user2);
|
||||
|
||||
constructor(address _profileNFT) Ownable(msg.sender){
|
||||
profileNFT = SoulboundProfileNFT(_profileNFT);
|
||||
}
|
||||
|
||||
function likeUser(
|
||||
address liked
|
||||
) external payable {
|
||||
require(msg.value >= 1 ether, "Must send at least 1 ETH");
|
||||
require(!likes[msg.sender][liked], "Already liked");
|
||||
require(msg.sender != liked, "Cannot like yourself");
|
||||
require(profileNFT.profileToToken(msg.sender) != 0, "Must have a profile NFT");
|
||||
require(profileNFT.profileToToken(liked) != 0, "Liked user must have a profile NFT");
|
||||
|
||||
likes[msg.sender][liked] = true;
|
||||
emit Liked(msg.sender, liked);
|
||||
|
||||
// Check if mutual like
|
||||
if (likes[liked][msg.sender]) {
|
||||
matches[msg.sender].push(liked);
|
||||
matches[liked].push(msg.sender);
|
||||
emit Matched(msg.sender, liked);
|
||||
matchRewards(liked, msg.sender);
|
||||
}
|
||||
}
|
||||
|
||||
function matchRewards(address from, address to) internal {
|
||||
uint256 matchUserOne = userBalances[from];
|
||||
uint256 matchUserTwo = userBalances[to];
|
||||
userBalances[from] = 0;
|
||||
userBalances[to] = 0;
|
||||
|
||||
uint256 totalRewards = matchUserOne + matchUserTwo;
|
||||
uint256 matchingFees = (totalRewards * FIXEDFEE ) / 100;
|
||||
uint256 rewards = totalRewards - matchingFees;
|
||||
totalFees += matchingFees;
|
||||
|
||||
// Deploy a MultiSig contract for the matched users
|
||||
MultiSigWallet multiSigWallet = new MultiSigWallet(from, to);
|
||||
|
||||
// Send ETH to the deployed multisig wallet
|
||||
(bool success, ) = payable(address(multiSigWallet)).call{value: rewards}("");
|
||||
require(success, "Transfer failed");
|
||||
}
|
||||
|
||||
function getMatches() external view returns (address[] memory) {
|
||||
return matches[msg.sender];
|
||||
}
|
||||
|
||||
function withdrawFees() external onlyOwner {
|
||||
require(totalFees > 0, "No fees to withdraw");
|
||||
uint256 totalFeesToWithdraw = totalFees;
|
||||
|
||||
totalFees = 0;
|
||||
(bool success, ) = payable(owner()).call{value: totalFeesToWithdraw}("");
|
||||
require(success, "Transfer failed");
|
||||
}
|
||||
|
||||
/// @notice Allows the contract to receive ETH
|
||||
receive() external payable {}
|
||||
}
|
||||
83
src/MultiSig.sol
Normal file
83
src/MultiSig.sol
Normal file
@@ -0,0 +1,83 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.8.19;
|
||||
|
||||
contract MultiSigWallet {
|
||||
error NotAnOwner();
|
||||
error AlreadyApproved();
|
||||
error NotEnoughApprovals();
|
||||
error InvalidRecipient();
|
||||
error InvalidAmount();
|
||||
|
||||
address public owner1;
|
||||
address public owner2;
|
||||
|
||||
struct Transaction {
|
||||
address to;
|
||||
uint256 value;
|
||||
bool approvedByOwner1;
|
||||
bool approvedByOwner2;
|
||||
bool executed;
|
||||
}
|
||||
|
||||
Transaction[] public transactions;
|
||||
|
||||
event TransactionCreated(uint256 indexed txId, address indexed to, uint256 value);
|
||||
event TransactionApproved(uint256 indexed txId, address indexed owner);
|
||||
event TransactionExecuted(uint256 indexed txId, address indexed to, uint256 value);
|
||||
|
||||
modifier onlyOwners() {
|
||||
if (msg.sender != owner1 && msg.sender != owner2) revert NotAnOwner();
|
||||
_;
|
||||
}
|
||||
|
||||
constructor(address _owner1, address _owner2) {
|
||||
require(_owner1 != address(0) && _owner2 != address(0), "Invalid owner address");
|
||||
require(_owner1 != _owner2, "Owners must be different");
|
||||
owner1 = _owner1;
|
||||
owner2 = _owner2;
|
||||
}
|
||||
|
||||
/// @notice Submit a transaction for approval
|
||||
function submitTransaction(address _to, uint256 _value) external onlyOwners {
|
||||
if (_to == address(0)) revert InvalidRecipient();
|
||||
if (_value == 0) revert InvalidAmount();
|
||||
|
||||
transactions.push(Transaction(_to, _value, false, false, false));
|
||||
uint256 txId = transactions.length - 1;
|
||||
emit TransactionCreated(txId, _to, _value);
|
||||
}
|
||||
|
||||
/// @notice Approve a pending transaction
|
||||
function approveTransaction(uint256 _txId) external onlyOwners {
|
||||
require(_txId < transactions.length, "Invalid transaction ID");
|
||||
Transaction storage txn = transactions[_txId];
|
||||
require(!txn.executed, "Transaction already executed");
|
||||
|
||||
if (msg.sender == owner1) {
|
||||
if (txn.approvedByOwner1) revert AlreadyApproved();
|
||||
txn.approvedByOwner1 = true;
|
||||
} else {
|
||||
if (txn.approvedByOwner2) revert AlreadyApproved();
|
||||
txn.approvedByOwner2 = true;
|
||||
}
|
||||
|
||||
emit TransactionApproved(_txId, msg.sender);
|
||||
}
|
||||
|
||||
/// @notice Execute a fully-approved transaction
|
||||
function executeTransaction(uint256 _txId) external onlyOwners {
|
||||
require(_txId < transactions.length, "Invalid transaction ID");
|
||||
Transaction storage txn = transactions[_txId];
|
||||
require(!txn.executed, "Transaction already executed");
|
||||
require(txn.approvedByOwner1 && txn.approvedByOwner2, "Not enough approvals");
|
||||
|
||||
txn.executed = true;
|
||||
(bool success, ) = payable(txn.to).call{value: txn.value}("");
|
||||
require(success, "Transaction failed");
|
||||
|
||||
emit TransactionExecuted(_txId, txn.to, txn.value);
|
||||
}
|
||||
|
||||
/// @notice Allows the contract to receive ETH
|
||||
receive() external payable {}
|
||||
}
|
||||
104
src/SoulboundProfileNFT.sol
Normal file
104
src/SoulboundProfileNFT.sol
Normal file
@@ -0,0 +1,104 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.8.19;
|
||||
|
||||
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
|
||||
import "@openzeppelin/contracts/access/Ownable.sol";
|
||||
import {Base64} from "@openzeppelin/contracts/utils/Base64.sol";
|
||||
import "@openzeppelin/contracts/utils/Strings.sol";
|
||||
|
||||
|
||||
contract SoulboundProfileNFT is ERC721, Ownable {
|
||||
error ERC721Metadata__URI_QueryFor_NonExistentToken();
|
||||
error SoulboundTokenCannotBeTransferred();
|
||||
|
||||
uint256 private _nextTokenId;
|
||||
|
||||
struct Profile {
|
||||
string name;
|
||||
uint8 age;
|
||||
string profileImage; // IPFS or other hosted image URL
|
||||
}
|
||||
|
||||
mapping(address => uint256) public profileToToken; // Maps user to their profile NFT
|
||||
mapping(uint256 => Profile) private _profiles; // Stores profile metadata
|
||||
|
||||
event ProfileMinted(address indexed user, uint256 tokenId, string name, uint8 age, string profileImage);
|
||||
event ProfileBurned(address indexed user, uint256 tokenId);
|
||||
|
||||
constructor() ERC721("DatingDapp", "DTN") Ownable(msg.sender) {}
|
||||
|
||||
/// @notice Mint a soulbound NFT representing the user's profile.
|
||||
function mintProfile(string memory name, uint8 age, string memory profileImage) external {
|
||||
require(profileToToken[msg.sender] == 0, "Profile already exists");
|
||||
|
||||
uint256 tokenId = ++_nextTokenId;
|
||||
_safeMint(msg.sender, tokenId);
|
||||
|
||||
// Store metadata on-chain
|
||||
_profiles[tokenId] = Profile(name, age, profileImage);
|
||||
profileToToken[msg.sender] = tokenId;
|
||||
|
||||
emit ProfileMinted(msg.sender, tokenId, name, age, profileImage);
|
||||
}
|
||||
|
||||
/// @notice Allow users to delete their profile (burn the NFT).
|
||||
function burnProfile() external {
|
||||
uint256 tokenId = profileToToken[msg.sender];
|
||||
require(tokenId != 0, "No profile found");
|
||||
require(ownerOf(tokenId) == msg.sender, "Not profile owner");
|
||||
|
||||
_burn(tokenId);
|
||||
delete profileToToken[msg.sender];
|
||||
delete _profiles[tokenId];
|
||||
|
||||
emit ProfileBurned(msg.sender, tokenId);
|
||||
}
|
||||
|
||||
/// @notice App owner can block users
|
||||
function blockProfile(address blockAddress) external onlyOwner {
|
||||
uint256 tokenId = profileToToken[blockAddress];
|
||||
require(tokenId != 0, "No profile found");
|
||||
|
||||
_burn(tokenId);
|
||||
delete profileToToken[blockAddress];
|
||||
delete _profiles[tokenId];
|
||||
|
||||
emit ProfileBurned(blockAddress, tokenId);
|
||||
}
|
||||
|
||||
/// @notice Override of transferFrom to prevent any transfer.
|
||||
function transferFrom(address, address, uint256) public pure override{
|
||||
// Soulbound token cannot be transferred
|
||||
revert SoulboundTokenCannotBeTransferred();
|
||||
}
|
||||
|
||||
function safeTransferFrom(address, address, uint256, bytes memory) public pure override{
|
||||
// Soulbound token cannot be transferred
|
||||
revert SoulboundTokenCannotBeTransferred();
|
||||
}
|
||||
|
||||
/// @notice Return on-chain metadata
|
||||
function tokenURI(uint256 tokenId) public view virtual override returns (string memory) {
|
||||
if (ownerOf(tokenId) == address(0)) {
|
||||
revert ERC721Metadata__URI_QueryFor_NonExistentToken();
|
||||
}
|
||||
string memory profileName = _profiles[tokenId].name;
|
||||
uint256 profileAge = _profiles[tokenId].age;
|
||||
string memory imageURI = _profiles[tokenId].profileImage;
|
||||
return string(
|
||||
abi.encodePacked(
|
||||
_baseURI(),
|
||||
Base64.encode(
|
||||
bytes( // bytes casting actually unnecessary as 'abi.encodePacked()' returns a bytes
|
||||
abi.encodePacked(
|
||||
'{"name":"', profileName, '", ',
|
||||
'"description":"A soulbound dating profile NFT.", ',
|
||||
'"attributes": [{"trait_type": "Age", "value": ', Strings.toString(profileAge), '}], ',
|
||||
'"image":"', imageURI, '"}'
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user