Created
November 6, 2020 03:47
-
-
Save youngkidwarrior/56b66c501cf2dcdf09820f391fae81cd to your computer and use it in GitHub Desktop.
Prtcle Staking Diamond
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
// SPDX-License-Identifier: MIT | |
pragma solidity 0.7.3; | |
pragma experimental ABIEncoderV2; | |
/******************************************************************************\ | |
* Author: Nick Mudge | |
* Aavegotchi GHST Staking Diamond | |
* 18 October 2020 | |
* | |
* | |
* Uses the diamond-2, version 1.3.4, diamond implementation: | |
* https://github.com/mudgen/diamond-2 | |
/******************************************************************************/ | |
import "./libraries/LibDiamond.sol"; | |
import "./interfaces/IDiamondLoupe.sol"; | |
import "./interfaces/IDiamondCut.sol"; | |
import "./interfaces/IERC173.sol"; | |
import "./interfaces/IERC165.sol"; | |
import "./libraries/AppStorage.sol"; | |
import "./interfaces/IERC1155Metadata_URI.sol"; | |
contract PRTCLEStakingDiamond { | |
AppStorage s; | |
event TransferSingle(address indexed _operator, address indexed _from, address indexed _to, uint256 _id, uint256 _value); | |
constructor( | |
IDiamondCut.FacetCut[] memory _diamondCut, | |
address _owner, | |
address _prtcleContract, | |
address _uniV2PoolContract, | |
string[] memory _stringHashes | |
) { | |
require(_owner != address(0), "PRTCLEStakingDiamond: _owner can't be address(0)"); | |
require(_prtcleContract != address(0), "PRTCLEStakingDiamond: _prtcleContract can't be address(0)"); | |
require(_uniV2PoolContract != address(0), "PRTCLEStakingDiamond: _uniV2PoolContract can't be address(0)"); | |
LibDiamond.diamondCut(_diamondCut, address(0), new bytes(0)); | |
LibDiamond.setContractOwner(_owner); | |
initialize(_prtcleContract, _uniV2PoolContract, _stringHashes); | |
// create wearable strings: | |
emit TransferSingle(msg.sender, address(0), address(0), 0, 0); | |
} | |
function initialize( | |
address _prtcleContract, | |
address _uniV2PoolContract, | |
string[] memory _stringHashes | |
) internal { | |
LibDiamond.DiamondStorage storage ds = LibDiamond.diamondStorage(); | |
// adding ERC165 data | |
ds.supportedInterfaces[type(IERC165).interfaceId] = true; | |
ds.supportedInterfaces[type(IDiamondCut).interfaceId] = true; | |
ds.supportedInterfaces[type(IDiamondLoupe).interfaceId] = true; | |
ds.supportedInterfaces[type(IERC173).interfaceId] = true; | |
// ERC1155 | |
// ERC165 identifier for the main token standard. | |
ds.supportedInterfaces[0xd9b67a26] = true; | |
// ERC1155 | |
// ERC1155Metadata_URI | |
ds.supportedInterfaces[IERC1155Metadata_URI.uri.selector] = true; | |
// create wearable strings: | |
} | |
// Find facet for function that is called and execute the | |
// function if a facet is found and return any value. | |
fallback() external payable { | |
LibDiamond.DiamondStorage storage ds; | |
bytes32 position = LibDiamond.DIAMOND_STORAGE_POSITION; | |
assembly { | |
ds.slot := position | |
} | |
address facet = address(bytes20(ds.facets[msg.sig])); | |
require(facet != address(0), "GHSTSTaking: Function does not exist"); | |
assembly { | |
calldatacopy(0, 0, calldatasize()) | |
let result := delegatecall(gas(), facet, 0, calldatasize(), 0, 0) | |
returndatacopy(0, 0, returndatasize()) | |
switch result | |
case 0 { | |
revert(0, returndatasize()) | |
} | |
default { | |
return(0, returndatasize()) | |
} | |
} | |
} | |
receive() external payable { | |
revert("PRTCLEStaking: Does not accept ether"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment