Skip to content

Commit

Permalink
init project
Browse files Browse the repository at this point in the history
  • Loading branch information
hoanm committed Oct 14, 2024
1 parent bd7871d commit 3420cb7
Show file tree
Hide file tree
Showing 23 changed files with 2,713 additions and 0 deletions.
21 changes: 21 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# EditorConfig is awesome: https://EditorConfig.org

# top-most EditorConfig file
root = true

[*]
charset = utf-8
end_of_line = lf
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = false
max_line_length = 120

[*.sol]
indent_size = 4

[*.{js,ts}]
indent_size = 2

[*.{adoc,md}]
max_line_length = 0
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,10 @@ dist
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*


# foundry args
args

# foundry cache
forge-cache
9 changes: 9 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
build
coverage
out
/lib
assets
node_modules
.next
.idea
.github
24 changes: 24 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"plugins": ["prettier-plugin-solidity"],
"useTabs": false,
"printWidth": 120,
"trailingComma": "es5",
"tabWidth": 4,
"semi": false,
"singleQuote": false,
"bracketSpacing": true,
"overrides": [
{
"files": ["*.ts", "*.js"],
"options": {
"tabWidth": 2
}
},
{
"files": "*.sol",
"options": {
"singleQuote": false
}
}
]
}
25 changes: 25 additions & 0 deletions .solhint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"extends": "solhint:recommended",
"plugins": ["prettier"],
"rules": {
"code-complexity": ["error", 8],
"compiler-version": ["error", ">=0.8.23"],
"const-name-snakecase": "off",
"no-empty-blocks": "off",
"constructor-syntax": "error",
"func-visibility": ["error", { "ignoreConstructors": true }],
"max-line-length": ["error", 120],
"not-rely-on-time": "off",
"reason-string": ["warn", { "maxLength": 64 }],
"no-unused-import": "error",
"no-unused-vars": "off",
"no-inline-assembly": "off",
"avoid-low-level-calls": "off",
"no-global-import": "error",
"prettier/prettier": "error",
"private-vars-leading-underscore": "off",
"func-name-mixedcase": "off",
"var-name-mixedcase": "off",
"modifier-name-mixedcase": "off"
}
}
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"solidity.compileUsingRemoteVersion": "v0.8.26+commit.8a97fa7a"
}
15 changes: 15 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
-include .env

.PHONY: all test clean

all: clean install build

clean :; yarn cache clean

install :; yarn install

update :; forge update

build :; forge build

test :; forge test
59 changes: 59 additions & 0 deletions contracts/AccessControl.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.23;
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";

contract AccessControl {
using SafeERC20 for IERC20;

address payable public owner;
mapping(address => bool) public operators;

event SetOperator(address indexed add, bool value);

error OnlyOwnerAllowed();
error OnlyOperatorAllowed();
error ZeroAddressNotAllowed();

constructor(address _ownerAddress) {
owner = payable(_ownerAddress);
}

modifier onlyOwner() {
if (msg.sender != owner) {
revert OnlyOwnerAllowed();
}
_;
}

modifier onlyOperator() {
if (!operators[msg.sender]) {
revert OnlyOperatorAllowed();
}
_;
}

function setOwner(address payable _newOwner) external onlyOwner {
if (_newOwner == address(0)) {
revert ZeroAddressNotAllowed();
}
owner = _newOwner;
}

function setOperator(address _operator, bool _v) external onlyOwner {
operators[_operator] = _v;
emit SetOperator(_operator, _v);
}

function emergencyWithdraw(address _token, address payable _to, uint256 amount) external onlyOwner {
if (_token == address(0x0)) {
amount = amount != 0 ? amount : address(this).balance;
payable(_to).transfer(amount);
}
else {
amount = amount != 0 ? amount : IERC20(_token).balanceOf(address(this));
IERC20(_token).safeTransfer(_to, amount);
}
}
}
32 changes: 32 additions & 0 deletions contracts/ERC721Mock.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.23;

import { ERC721 } from "@openzeppelin/contracts/token/ERC721/ERC721.sol";

contract MockERC721 is ERC721 {
uint256 private _counter;

constructor(string memory name) ERC721(name, name) {
_counter = 0;
}

function mint(address to) public returns (uint256 tokenId) {
tokenId = ++_counter;
_safeMint(to, tokenId);
return tokenId;
}

function mintId(address to, uint256 tokenId) public returns (uint256) {
_safeMint(to, tokenId);
return tokenId;
}

function burn(uint256 tokenId) public {
_burn(tokenId);
}

function transferFrom(address from, address to, uint256 tokenId) public override {
_transfer(from, to, tokenId);
}
}
22 changes: 22 additions & 0 deletions contracts/ILaunchpadNFT.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.23;

import { IERC721Metadata } from "@openzeppelin/contracts/token/ERC721/extensions/IERC721Metadata.sol";
import { IERC721Enumerable } from "@openzeppelin/contracts/token/ERC721/extensions/IERC721Enumerable.sol";


interface ILaunchpadNFT is IERC721Metadata, IERC721Enumerable {

struct LaunchpadTokenMetadata {
address licensorIpId;
address licenseTemplate;
uint256 licenseTermsId;
bool transferable;
}

event LaunchpadNFTMinted(address indexed minter, address indexed receiver, uint256 indexed tokenId);

function mintTokens(address _receiver,
uint256 _amount // mint amount
) external;
}
69 changes: 69 additions & 0 deletions contracts/ISPGNFT.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.23;

import {IAccessControl} from "@openzeppelin/contracts/access/IAccessControl.sol";
import {IERC721} from "@openzeppelin/contracts/token/ERC721/IERC721.sol";
import {IERC721Metadata} from "@openzeppelin/contracts/token/ERC721/extensions/IERC721Metadata.sol";

interface ISPGNFT is IAccessControl, IERC721, IERC721Metadata {
/// @dev Initializes the NFT collection.
/// @dev If mint cost is non-zero, mint token must be set.
/// @param name The name of the collection.
/// @param symbol The symbol of the collection.
/// @param maxSupply The maximum supply of the collection.
/// @param mintFee The cost to mint an NFT from the collection.
/// @param mintFeeToken The token to pay for minting.
/// @param owner The owner of the collection.
function initialize(
string memory name,
string memory symbol,
uint32 maxSupply,
uint256 mintFee,
address mintFeeToken,
address owner
) external;

/// @notice Returns the total minted supply of the collection.
function totalSupply() external view returns (uint256);

/// @notice Returns the current mint token of the collection.
function mintFeeToken() external view returns (address);

/// @notice Returns the current mint fee of the collection.
function mintFee() external view returns (uint256);

/// @notice Sets the mint token for the collection.
/// @dev Only callable by the admin role.
/// @param token The new mint token for mint payment.
function setMintFeeToken(address token) external;

/// @notice Sets the fee to mint an NFT from the collection. Payment is in the designated currency.
/// @dev Only callable by the admin role.
/// @param fee The new mint fee paid in the mint token.
function setMintFee(uint256 fee) external;

/// @notice Mints an NFT from the collection. Only callable by the minter role.
/// @param to The address of the recipient of the minted NFT.
/// @param nftMetadataURI OPTIONAL. The desired metadata for the newly minted NFT.
/// @return tokenId The ID of the minted NFT.
function mint(
address to,
string calldata nftMetadataURI
) external returns (uint256 tokenId);

/// @notice Mints an NFT from the collection. Only callable by the SPG.
/// @param to The address of the recipient of the minted NFT.
/// @param payer The address of the payer for the mint fee.
/// @param nftMetadataURI OPTIONAL. The desired metadata for the newly minted NFT.
/// @return tokenId The ID of the minted NFT.
function mintBySPG(
address to,
address payer,
string calldata nftMetadataURI
) external returns (uint256 tokenId);

/// @dev Withdraws the contract's token balance to the recipient.
/// @param recipient The token to withdraw.
/// @param recipient The address to receive the withdrawn balance.
function withdrawToken(address token, address recipient) external;
}
Loading

0 comments on commit 3420cb7

Please sign in to comment.