Skip to content

Commit

Permalink
refactor, cleanup, goerli deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
JackBekket committed Dec 7, 2022
1 parent 8e8f10a commit 4362aae
Show file tree
Hide file tree
Showing 45 changed files with 30,514 additions and 6,015 deletions.
5 changes: 5 additions & 0 deletions addresses.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Singleton Collection deployed to: 0xEf087AaF882c22350ABc6A287563cE037AC46b06
Factory NFT deployed to: 0x3d908DF3057fC6CE7c60e9Daf34B7e80F1B53479
Our currency deployed to: 0x9024cF0a889233Af1fd4afaF949d5aF8C633D7fc
Currencies util contract deployed to: 0x81b13480622367EF2Fc4aA322e2D915ABab1755a
MetaMarketplace deployed to: 0x87da345d041359d7C080E301c06043992328683B
21 changes: 6 additions & 15 deletions contracts/CurrenciesERC20.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@ pragma solidity ^0.8.0;

//import "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import "./interfaces/ICurrenciesERC20.sol";
//import "@openzeppelin/contracts/utils/math/SafeMath.sol";

//import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
//import "../../../node_modules/@openzeppelin/contracts/utils/Counters.sol";
//import "@openzeppelin/contracts/access/Ownable.sol";

import "@openzeppelin/contracts/utils/introspection/ERC165.sol";

Expand All @@ -34,9 +30,9 @@ contract CurrenciesERC20 is ReentrancyGuard, Ownable, ERC165 {
USDT,
USDC,
DAI,
MST,
WETH,
WBTC
WBTC,
VXPPL
}

struct CurrencyERC20_Custom {
Expand Down Expand Up @@ -89,8 +85,8 @@ contract CurrenciesERC20 is ReentrancyGuard, Ownable, ERC165 {
address US_Circle,
address DAI,
address W_Ethereum,
address MST,
address WBTC
address WBTC,
address VXPPL
) {
require(US_Tether != address(0), "USDT contract address is zero!");
require(US_Circle != address(0), "US_Circle contract address is zero!");
Expand All @@ -99,22 +95,17 @@ contract CurrenciesERC20 is ReentrancyGuard, Ownable, ERC165 {
W_Ethereum != address(0),
"W_Ethereum contract address is zero!"
);
require(MST != address(0), "MST contract address is zero!");
require(WBTC != address(0), "WBTC contract address is zero!");

_currencies_hardcoded[CurrencyERC20.USDT] = IERC20Metadata(US_Tether);
_currencies_hardcoded[CurrencyERC20.USDT] == IERC20Metadata(US_Tether);
_currencies_hardcoded[CurrencyERC20.USDC] = IERC20Metadata(US_Circle);
_currencies_hardcoded[CurrencyERC20.DAI] = IERC20Metadata(DAI);
_currencies_hardcoded[CurrencyERC20.WETH] = IERC20Metadata(W_Ethereum);
_currencies_hardcoded[CurrencyERC20.MST] = IERC20Metadata(MST);
_currencies_hardcoded[CurrencyERC20.WBTC] = IERC20Metadata(WBTC);
_currencies_hardcoded[CurrencyERC20.VXPPL] = IERC20Metadata(VXPPL);


// AddCustomCurrency(US_Tether);
// AddCustomCurrency(US_Circle);
// AddCustomCurrency(DAI);
// AddCustomCurrency(W_Ethereum);
AddCustomCurrency(MST);
}

function get_hardcoded_currency(CurrencyERC20 currency)
Expand Down
31 changes: 31 additions & 0 deletions contracts/ERC20Sample.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

// in-direct imports

import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/access/Ownable.sol";


// direct imports, use it for go generation
/*
import "../../node_modules/@openzeppelin/contracts/access/Ownable.sol";
import "../../node_modules/@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import "../../node_modules/@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "../../node_modules/@openzeppelin/contracts/token/ERC20/IERC20.sol";
*/

contract ERC20Sample is ERC20, Ownable {
constructor(string memory name_, string memory symbol_, uint256 initialSupply)
ERC20(name_, symbol_)

{
mint(msg.sender,initialSupply);
}

function mint(address to, uint256 amount) public virtual onlyOwner {
super._mint(to, amount);
}
}
1 change: 1 addition & 0 deletions contracts/InterfaceRegister.sol
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ contract InterfaceRegister {
}

function calculateIERC721URIStorage() public pure returns (bytes4){
return
bytes4(keccak256("balanceOf(address)")) ^
bytes4(keccak256("ownerOf(uint256)")) ^
bytes4(keccak256("approve(address,uint256)")) ^
Expand Down
58 changes: 48 additions & 10 deletions contracts/MetaMarketplace.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ pragma solidity ^0.8.0;
import './CurrenciesERC20.sol';
import "@openzeppelin/contracts/token/ERC721/extensions/IERC721Enumerable.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/IERC721Metadata.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol";
import "@openzeppelin/contracts/token/ERC721/IERC721.sol";
//import "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import "@openzeppelin/contracts/utils/introspection/ERC165.sol";
Expand Down Expand Up @@ -68,6 +69,8 @@ contract MetaMarketplace is ERC165, Ownable {

//TODO : add royalties reciver address and royalties fee percentage here
// this value can be hold by *owners of collection*
address payable collectionOwner;
uint ownerFee;
}

// from nft token contract address to marketplace
Expand Down Expand Up @@ -107,28 +110,45 @@ contract MetaMarketplace is ERC165, Ownable {
{
_currency_contract = CurrenciesERC20(currency_contract_);
require(_checkStandard(telegram_collection_, NftType.Telegram), "Standard not supported");
SetUpMarketplace(telegram_collection_, NftType.Telegram); // set up Telegram ready for sale
SetUpMarketplace(telegram_collection_, NftType.Telegram,treasure_fund_,30); // set up Telegram ready for sale
_treasure_fund = treasure_fund_;
}



function SetUpMarketplace(address nft_token_, NftType standard_) public
function SetUpMarketplace(address nft_contract_, NftType standard_, address payable collection_owner_, uint collection_fee_) public
{
require(Marketplaces[nft_token_].initialized == false, "Marketplace is already setted up");
require(Marketplaces[nft_contract_].initialized == false, "Marketplace is already setted up");

Marketplace storage metainfo = Marketplaces[nft_token_];
Marketplace storage metainfo = Marketplaces[nft_contract_];
metainfo.nft_standard = standard_;
metainfo.initialized = true;
metainfo.collectionOwner = collection_owner_;
metainfo.ownerFee = collection_fee_;
}

// admin can change royalties reciver and fee in extreme cases
function editMarketplace(address nft_contract_, address payable collection_owner_, uint collection_fee_) onlyOwner public {
require(Marketplaces[nft_contract_].initialized == true, "Marketplace is not exist yet");
Marketplace storage metainfo = Marketplaces[nft_contract_];
metainfo.collectionOwner = collection_owner_;
metainfo.ownerFee = collection_fee_;
}

/**
* @dev set service global fee (onlyOwner)
*/
function SetServiceFee(uint promille_fee_, address payable treasure_fund_) onlyOwner public
{
promille_fee = promille_fee_;
_treasure_fund = treasure_fund_;
}

/**
* @notice check if contract support specific nft standard
* @param standard_ is one of ERC721 standards (MSNFT, 721Enumerable,721Metadata, erc721(common))
* it will return false if contract not support specific interface
* TODO: add check for URIStorage!
*
*/
function _checkStandard(address contract_, NftType standard_) internal view returns (bool) {

Expand All @@ -148,6 +168,16 @@ contract MetaMarketplace is ERC165, Ownable {
supportsInterface(_INTERFACE_ID_IERC721);
return success;
}
if (standard_ == NftType.Telegram) { // Telegram is URIStorage
(bool success) = IERC721Metadata(contract_).
supportsInterface(_INTERFACE_ID_IERC721METADATA);
return success;
}
if(standard_ == NftType.URIStorage) { // URIStorage is MetaData
(bool success) = IERC721Metadata(contract_).
supportsInterface(_INTERFACE_ID_IERC721METADATA);
return success;
}
}


Expand Down Expand Up @@ -192,7 +222,7 @@ contract MetaMarketplace is ERC165, Ownable {
}


// deduct royalties, if NFT is created in MoonShard, then applicate +1.5% royalties fee to author of nft
// deduct royalties, Service fee is promille_fee (taken when sale) + royalties to those who setted up marketplace
function _deductRoyalties(address nft_token_contract_, uint256 grossSaleValue) internal view returns (address royalties_reciver,uint256 royalties_amount) {

// check nft type
Expand All @@ -202,10 +232,11 @@ contract MetaMarketplace is ERC165, Ownable {
royalties_reciver = _treasure_fund;
royalties_amount = calculateFee(grossSaleValue,1000);
} else
// TODO: Extend work with royalties for telegram collection and user collections
{
royalties_reciver = address (0x0);
royalties_amount = 0;
Marketplace storage m = Marketplaces[nft_token_contract_];
royalties_reciver = m.collectionOwner;
uint256 royalties_ct = m.ownerFee;
royalties_amount = calculateAbstractFee(grossSaleValue,1000,royalties_ct);
}
return (royalties_reciver,royalties_amount);
}
Expand Down Expand Up @@ -415,6 +446,13 @@ contract MetaMarketplace is ERC165, Ownable {
return a * c * scale + a * d + b * c + (b * d + scale - 1) / scale;
}

function calculateAbstractFee(uint256 amount, uint256 scale, uint256 promille_fee_) public pure returns(uint256) {
uint a = amount / scale;
uint b = amount % scale;
uint c = promille_fee_ / scale;
uint d = promille_fee_ % scale;
return a * c * scale + a * d + b * c + (b * d + scale - 1) / scale;
}


/**
Expand Down Expand Up @@ -521,7 +559,7 @@ contract MetaMarketplace is ERC165, Ownable {
modifier isMarketable(uint256 tokenId, address nft_contract_) {
require(Marketplaces[nft_contract_].initialized == true,
"Marketplace for this token is not setup yet!");
IERC721Enumerable token = IERC721Enumerable(nft_contract_);
IERC721 token = IERC721(nft_contract_);
require(token.getApproved(tokenId) == address(this),
"Not approved");
_;
Expand Down
8 changes: 4 additions & 4 deletions contracts/interfaces/ICurrenciesERC20.sol
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
//SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;

import "../../node_modules/@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import "../../node_modules/@openzeppelin/contracts/utils/math/SafeMath.sol";
import "../../node_modules/@openzeppelin/contracts/security/ReentrancyGuard.sol";
import "../../node_modules/@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import "@openzeppelin/contracts/utils/math/SafeMath.sol";
import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
import "@openzeppelin/contracts/access/Ownable.sol";

interface ICurrenciesERC20 {
/**
Expand Down
3 changes: 3 additions & 0 deletions dapp/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "next/core-web-vitals"
}
32 changes: 32 additions & 0 deletions dapp/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# next.js
/.next/
/out/

# production
/build

# misc
.DS_Store
*.pem

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*
.pnpm-debug.log*

# local env files
.env*.local

# vercel
.vercel
34 changes: 34 additions & 0 deletions dapp/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app).

## Getting Started

First, run the development server:

```bash
npm run dev
# or
yarn dev
```

Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.

You can start editing the page by modifying `pages/index.js`. The page auto-updates as you edit the file.

[API routes](https://nextjs.org/docs/api-routes/introduction) can be accessed on [http://localhost:3000/api/hello](http://localhost:3000/api/hello). This endpoint can be edited in `pages/api/hello.js`.

The `pages/api` directory is mapped to `/api/*`. Files in this directory are treated as [API routes](https://nextjs.org/docs/api-routes/introduction) instead of React pages.

## Learn More

To learn more about Next.js, take a look at the following resources:

- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.

You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome!

## Deploy on Vercel

The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.

Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details.
6 changes: 6 additions & 0 deletions dapp/next.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/** @type {import('next').NextConfig} */
const nextConfig = {
reactStrictMode: true,
}

module.exports = nextConfig
20 changes: 20 additions & 0 deletions dapp/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "dapp",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint"
},
"dependencies": {
"next": "13.0.6",
"react": "18.2.0",
"react-dom": "18.2.0"
},
"devDependencies": {
"eslint": "8.29.0",
"eslint-config-next": "13.0.6"
}
}
Binary file added dapp/public/favicon.ico
Binary file not shown.
4 changes: 4 additions & 0 deletions dapp/public/vercel.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 4362aae

Please sign in to comment.