-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #84 from RootstockCollective/develop
Merging into nftEC branch
- Loading branch information
Showing
13 changed files
with
495 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
// SPDX-License-Identifier: MIT | ||
// Compatible with OpenZeppelin Contracts ^5.0.0 | ||
pragma solidity ^0.8.20; | ||
|
||
import {IVotes} from "@openzeppelin/contracts/governance/utils/IVotes.sol"; | ||
import {Strings} from "@openzeppelin/contracts/utils/Strings.sol"; | ||
|
||
import {ERC721UpgradableNonTransferrable} from "./ERC721UpgradableNonTransferrable.sol"; | ||
|
||
contract OGFounders is ERC721UpgradableNonTransferrable { | ||
using Strings for uint8; | ||
|
||
error WasNotEnoughStRIFToMint(uint stRIF); | ||
error CouldNotGetVotes(string); | ||
error CouldNotGetVotesBytes(bytes); | ||
error OutOfTokens(uint256 maxSupply); | ||
error ThisAddressAlreadyOwnsTheToken(address owner); | ||
|
||
/// @custom:oz-upgrades-unsafe-allow constructor | ||
constructor() { | ||
_disableInitializers(); | ||
} | ||
|
||
address public stRIF; | ||
uint256 public firstProposalDate; | ||
// Counter for the total number of minted tokens | ||
uint8 private _totalMinted; | ||
// number of metadata files in the IPFS directory | ||
uint8 private _maxSupply; | ||
|
||
function initialize( | ||
address initialOwner, | ||
address stRIFAddress, | ||
uint256 _firstProposalDate | ||
) public initializer { | ||
__ERC721UpgradableBase_init("OGFoundersRootstockCollective", "OGF", initialOwner); | ||
stRIF = stRIFAddress; | ||
firstProposalDate = _firstProposalDate; | ||
_maxSupply = 150; | ||
} | ||
|
||
/** | ||
* @dev Returns the number of tokens available for minting | ||
*/ | ||
function tokensAvailable() public view virtual returns (uint256) { | ||
if (_totalMinted >= _maxSupply) return 0; | ||
return _maxSupply - _totalMinted; | ||
} | ||
|
||
/** | ||
* @dev Returns the token ID for a given owner address. | ||
* This is a simplified version of the `tokenOfOwnerByIndex` function without the index | ||
* parameter, since a community member can only own one token. | ||
*/ | ||
function tokenIdByOwner(address owner) public view virtual returns (uint256) { | ||
return tokenOfOwnerByIndex(owner, 0); | ||
} | ||
|
||
/** | ||
* @dev Returns the token IPFS URI for the given owner address. | ||
* This utility function combines two view functions. | ||
*/ | ||
function tokenUriByOwner(address owner) public view virtual returns (string memory) { | ||
return tokenURI(tokenIdByOwner(owner)); | ||
} | ||
|
||
function mint() external virtual { | ||
address caller = _msgSender(); | ||
//5623028 | ||
try IVotes(stRIF).getPastVotes(caller, firstProposalDate) returns (uint _votes) { | ||
if (_votes < 1) { | ||
revert WasNotEnoughStRIFToMint(_votes); | ||
} | ||
// make sure we still have some CIDs for minting new tokens | ||
if (tokensAvailable() == 0) revert OutOfTokens(_maxSupply); | ||
|
||
// minting | ||
uint8 tokenId = ++_totalMinted; | ||
string memory fileName = string.concat(tokenId.toString(), ".json"); // 1.json, 2.json ... | ||
_safeMint(caller, tokenId); | ||
_setTokenURI(tokenId, fileName); | ||
} catch Error(string memory reason) { | ||
revert CouldNotGetVotes(reason); | ||
} catch (bytes memory reason) { | ||
revert CouldNotGetVotesBytes(reason); | ||
} | ||
} | ||
|
||
function _authorizeUpgrade(address newImplementation) internal virtual override onlyOwner {} | ||
|
||
function _baseURI() internal pure override returns (string memory) { | ||
return "ipfs://"; | ||
} | ||
|
||
/** | ||
* @dev Prevents the transfer and mint of tokens to addresses that already own one. | ||
* Ensures that one address cannot own more than one token. | ||
*/ | ||
function _update(address to, uint256 tokenId, address auth) internal override returns (address) { | ||
// Disallow transfers by smart contracts, as only EOAs can be community members | ||
// slither-disable-next-line tx-origin | ||
if (_msgSender() != tx.origin) revert ERC721InvalidOwner(_msgSender()); | ||
// disallow transfers to members (excluding zero-address for enabling burning) | ||
// disable minting more than one token | ||
if (to != address(0) && balanceOf(to) > 0) revert ERC721InvalidOwner(to); | ||
return super._update(to, tokenId, auth); | ||
} | ||
|
||
// overrides required | ||
|
||
function transferFrom(address from, address to, uint256 tokenId) public virtual override { | ||
super.transferFrom(from, to, tokenId); | ||
} | ||
|
||
function approve(address to, uint256 tokenId) public virtual override { | ||
super.approve(to, tokenId); | ||
} | ||
|
||
function setApprovalForAll(address operator, bool approved) public virtual override { | ||
super.setApprovalForAll(operator, approved); | ||
} | ||
|
||
function tokenURI(uint256 tokenId) public view virtual override returns (string memory) { | ||
return super.tokenURI(tokenId); | ||
} | ||
|
||
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { | ||
return super.supportsInterface(interfaceId); | ||
} | ||
|
||
function _increaseBalance(address account, uint128 value) internal override { | ||
super._increaseBalance(account, value); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { buildModule } from '@nomicfoundation/hardhat-ignition/modules' | ||
|
||
export const OGFoundersProxyModule = buildModule('OGFounders', m => { | ||
// deploy implementation | ||
const implementation = m.contract('OGFounders', [], { id: 'Implementation' }) | ||
|
||
// initializer parameters | ||
const deployer = m.getAccount(0) | ||
const stRIFAddress = m.getParameter('stRIFAddress') | ||
const firstProposalDate = m.getParameter('firstProposalDate') | ||
|
||
// deploy proxy | ||
const proxy = m.contract('ERC1967Proxy', [ | ||
implementation, | ||
m.encodeFunctionCall(implementation, 'initialize', [deployer, stRIFAddress, firstProposalDate], { | ||
id: 'Proxy', | ||
}), | ||
]) | ||
const OGFounders = m.contractAt('OGFounders', proxy, { | ||
id: 'Contract', | ||
}) | ||
|
||
return { OGFounders } | ||
}) | ||
|
||
export default OGFoundersProxyModule |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.