Skip to content

Commit

Permalink
Merge pull request #1 from gryphnft/2.0
Browse files Browse the repository at this point in the history
2.0
  • Loading branch information
cblanquera authored Mar 8, 2022
2 parents b13c8ff + 40e0a0c commit c125283
Show file tree
Hide file tree
Showing 39 changed files with 5,681 additions and 13,167 deletions.
140 changes: 80 additions & 60 deletions README.md

Large diffs are not rendered by default.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
480 changes: 480 additions & 0 deletions contracts/ERC721/ERC721.sol

Large diffs are not rendered by default.

36 changes: 36 additions & 0 deletions contracts/ERC721/ERC721Base.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import "@openzeppelin/contracts/utils/Context.sol";

import "./extensions/ERC721Pausable.sol";
import "./extensions/ERC721URIContract.sol";

abstract contract ERC721Base is
Context,
ERC721Pausable,
ERC721URIContract
{
// ============ Deploy ============

/**
* @dev Grants `DEFAULT_ADMIN_ROLE` and `PAUSER_ROLE` to the
* account that deploys the contract. Sets the contract's URI.
*/
constructor(string memory name_, string memory symbol_) ERC721(name_, symbol_) {}

// ============ Overrides ============

/**
* @dev Describes linear override for `_beforeTokenTransfer` used in
* both `ERC721` and `ERC721Pausable`
*/
function _beforeTokenTransfer(
address from,
address to,
uint256 tokenId
) internal virtual override(ERC721, ERC721Pausable) {
super._beforeTokenTransfer(from, to, tokenId);
}
}
23 changes: 23 additions & 0 deletions contracts/ERC721/extensions/ERC721Burnable.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import "../ERC721.sol";
import "@openzeppelin/contracts/utils/Context.sol";

/**
* @title ERC721 Burnable Token
* @dev ERC721 Token that can be irreversibly burned (destroyed).
*/
abstract contract ERC721Burnable is Context, ERC721 {
/**
* @dev Burns `tokenId`. See {ERC721B-_burn}.
*
* Requirements:
*
* - The caller must own `tokenId` or be an approved operator.
*/
function burn(uint256 tokenId) public virtual {
_burn(tokenId);
}
}
33 changes: 33 additions & 0 deletions contracts/ERC721/extensions/ERC721Pausable.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import "../ERC721.sol";
import "@openzeppelin/contracts/security/Pausable.sol";

error TransferWhilePaused();

/**
* @dev ERC721 token with pausable token transfers, minting and burning.
*
* Useful for scenarios such as preventing trades until the end of an evaluation
* period, or having an emergency switch for freezing all token transfers in the
* event of a large bug.
*/
abstract contract ERC721Pausable is Pausable, ERC721 {
/**
* @dev See {ERC721B-_beforeTokenTransfer}.
*
* Requirements:
*
* - the contract must not be paused.
*/
function _beforeTokenTransfer(
address from,
address to,
uint256 tokenId
) internal virtual override {
if (paused()) revert TransferWhilePaused();
super._beforeTokenTransfer(from, to, tokenId);
}
}
36 changes: 36 additions & 0 deletions contracts/ERC721/extensions/ERC721URIContract.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import "../ERC721.sol";

/**
* @dev ERC721 contract with a URI descriptor
*/
abstract contract ERC721URIContract is ERC721 {
//immutable contract uri
string private _contractURI;

/**
* @dev The URI for contract data ex. https://creatures-api.opensea.io/contract/opensea-creatures/contract.json
* Example Format:
* {
* "name": "OpenSea Creatures",
* "description": "OpenSea Creatures are adorable aquatic beings primarily for demonstrating what can be done using the OpenSea platform. Adopt one today to try out all the OpenSea buying, selling, and bidding feature set.",
* "image": "https://openseacreatures.io/image.png",
* "external_link": "https://openseacreatures.io",
* "seller_fee_basis_points": 100, # Indicates a 1% seller fee.
* "fee_recipient": "0xA97F337c39cccE66adfeCB2BF99C1DdC54C2D721" # Where seller fees will be paid to.
* }
*/
function contractURI() external view returns (string memory) {
return _contractURI;
}

/**
* @dev Sets contract uri
*/
function _setContractURI(string memory uri) internal virtual {
_contractURI = uri;
}
}
234 changes: 234 additions & 0 deletions contracts/Gryph/GryphEconomy.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,234 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";

import "@openzeppelin/contracts/access/AccessControlEnumerable.sol";
import "@openzeppelin/contracts/security/Pausable.sol";
import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
import "@openzeppelin/contracts/utils/Address.sol";
import "@openzeppelin/contracts/utils/math/SafeMath.sol";

//
// ______ _______ ____ ____ _______ ____ ____
// .' ___ ||_ __ \ |_ _||_ _| |_ __ \|_ || _|
// / .' \_| | |__) | \ \ / / | |__) | | |__| |
// | | ____ | __ / \ \/ / | ___/ | __ |
// \ `.___] |_| | \ \_ _| |_ _ _| |_ _| | | |_
// `._____.'|____| |___||______|(_)|_____| |____||____|
//
// CROSS CHAIN NFT MARKETPLACE
// https://www.gry.ph/
//

// ============ Inferfaces ============

interface IERC20Capped is IERC20 {
function cap() external returns(uint256);
}

// ============ Errors ============

error InvalidAmount();

contract GryphEconomy is
AccessControlEnumerable,
ReentrancyGuard,
Pausable
{
using Address for address;
using SafeMath for uint256;

// ============ Events ============

event ERC20Received(address indexed sender, uint256 amount);
event ERC20Sent(address indexed recipient, uint256 amount);
event DepositReceived(address from, uint256 amount);

// ============ Constants ============

bytes32 public constant PAUSER_ROLE = keccak256("PAUSER_ROLE");

//this is the contract address for $GRYPH
IERC20Capped public immutable GRYPH_TOKEN;
//this is the contract address for the $GRYPH treasury
address public immutable GRYPH_TREASURY;
//this is the token cap of $GRYPH
uint256 public immutable TOKEN_CAP;

// ============ Store ============

//where 5000 = 50.00%
uint16 private _interest = 5000;
//where 20000 = 200.00%
uint16 private _sellFor = 20000;
//where 5000 = 50.00%
uint16 private _buyFor = 5000;

// ============ Deploy ============

/**
* @dev Grants `DEFAULT_ADMIN_ROLE` to the account that deploys the
* contract.
*/
constructor(IERC20Capped token, address treasury) payable {
//set up roles for the contract creator
address sender = _msgSender();
_setupRole(DEFAULT_ADMIN_ROLE, sender);
_setupRole(PAUSER_ROLE, sender);
//set the $GRYPH addresses
GRYPH_TOKEN = token;
GRYPH_TREASURY = treasury;
//set the token cap
TOKEN_CAP = token.cap();
//start paused
_pause();
}

/**
* @dev The Ether received will be logged with {PaymentReceived}
* events. Note that these events are not fully reliable: it's
* possible for a contract to receive Ether without triggering this
* function. This only affects the reliability of the events, and not
* the actual splitting of Ether.
*
* To learn more about this see the Solidity documentation for
* https://solidity.readthedocs.io/en/latest/contracts.html#fallback-function[fallback
* functions].
*/
receive() external payable virtual {
emit DepositReceived(_msgSender(), msg.value);
}

// ============ Read Methods ============

/**
* @dev Returns the ether balance
*/
function balanceEther() public view returns(uint256) {
return address(this).balance;
}

/**
* @dev Returns the $GRYPH token balance
*/
function balanceToken() public view returns(uint256) {
return GRYPH_TOKEN.balanceOf(address(this));
}

/**
* @dev Returns the ether amount we are willing to buy $GRYPH for
*/
function buyingFor(uint256 amount) public view returns(uint256) {
return _buyingFor(amount, balanceEther());
}

/**
* @dev Returns the ether amount we are willing to sell $GRYPH for
*/
function sellingFor(uint256 amount) public view returns(uint256) {
return _sellingFor(amount, balanceEther());
}

// ============ Write Methods ============

/**
* @dev Buys `amount` of $GRYPH
*/
function buy(address recipient, uint256 amount)
public payable whenNotPaused nonReentrant
{
uint256 value = _sellingFor(amount, balanceEther() - msg.value);
if (value == 0
|| msg.value < value
|| balanceToken() < amount
) revert InvalidAmount();
//we already received the ether
//so just send the tokens
SafeERC20.safeTransfer(GRYPH_TOKEN, recipient, amount);
//send the interest
Address.sendValue(
payable(GRYPH_TREASURY),
msg.value.mul(_interest).div(10000)
);
emit ERC20Sent(recipient, amount);
}

/**
* @dev Sells `amount` of $GRYPH
*/
function sell(address recipient, uint256 amount)
public whenNotPaused nonReentrant
{
//check allowance
if(GRYPH_TOKEN.allowance(recipient, address(this)) < amount)
revert InvalidAmount();
//send the ether
Address.sendValue(payable(recipient), buyingFor(amount));
//now accept the payment
SafeERC20.safeTransferFrom(GRYPH_TOKEN, recipient, address(this), amount);
emit ERC20Received(recipient, amount);
}

// ============ Admin Methods ============

/**
* @dev Sets the buy for percent
*/
function buyFor(uint16 percent)
public payable onlyRole(DEFAULT_ADMIN_ROLE)
{
_buyFor = percent;
}

/**
* @dev Sets the interest
*/
function interest(uint16 percent)
public payable onlyRole(DEFAULT_ADMIN_ROLE)
{
_interest = percent;
}

/**
* @dev Pauses all token transfers.
*/
function pause() public virtual onlyRole(PAUSER_ROLE) {
_pause();
}

/**
* @dev Sets the sell for percent
*/
function sellFor(uint16 percent)
public payable onlyRole(DEFAULT_ADMIN_ROLE)
{
_sellFor = percent;
}

/**
* @dev Unpauses all token transfers.
*/
function unpause() public virtual onlyRole(PAUSER_ROLE) {
_unpause();
}

// ============ Internal Methods ============
/**
* @dev Returns the ether amount we are willing to buy $GRYPH for
*/
function _buyingFor(uint256 amount, uint256 balance) internal view returns(uint256) {
// (eth / cap) * amount
return balance.mul(amount).mul(_buyFor).div(TOKEN_CAP).div(1000);
}

/**
* @dev Returns the ether amount we are willing to sell $GRYPH for
*/
function _sellingFor(uint256 amount, uint256 balance) internal view returns(uint256) {
// (eth / cap) * amount
return balance.mul(amount).mul(_sellFor).div(TOKEN_CAP).div(1000);
}
}
Loading

0 comments on commit c125283

Please sign in to comment.