Skip to content

Commit

Permalink
deploy ss bonus week
Browse files Browse the repository at this point in the history
  • Loading branch information
PengDeng-Cyber committed Sep 5, 2024
1 parent 4bc3e1e commit 25a18cc
Show file tree
Hide file tree
Showing 6 changed files with 200 additions and 12 deletions.
1 change: 1 addition & 0 deletions docs/deploy/cyber-7560/contract.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@
| CyberRelayer | 0x0e3ba6be9b3aaf4c6de0c9aee2b2c565e29437ae |
| WorkInCryptoNFT | 0x28cd7b0e0e927a8b627e96a0ba598d7101d87b2d |
| CyberProjectNFTV2 | 0x5239edbdafeddd6a6659e74a99bf99ed32717184 |
| SSBonusWeek | 0x760e1298f1b8c491e2715b2989861c5a994db672 |
1 change: 1 addition & 0 deletions docs/deploy/cyber_testnet-111557560/contract.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@
| CyberRelayer | 0x0e3ba6be9b3aaf4c6de0c9aee2b2c565e29437ae |
| WorkInCryptoNFT | 0x7edb358e871ff2aa79239d408aa53ce3d73b6fb1 |
| CyberProjectNFTV2 | 0xf78df34502fe8553512f83c56f3e0b8878512706 |
| SSBonusWeek | 0x760e1298f1b8c491e2715b2989861c5a994db672 |
2 changes: 1 addition & 1 deletion script/DeployCyberProjectNFTV2.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ contract DeployCyberProjectNFTV2 is Script, DeploySetting {
vm,
deployParams.deployerContract,
deployParams.protocolOwner,
0x5B56aeBACc4c2994C9A6572527A6c2296e6D34F6
0x300e65412d8fc248CDD0429b2e10aD2360094B00
);
}
vm.stopBroadcast();
Expand Down
5 changes: 1 addition & 4 deletions script/WithdrawGasBridge.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@ contract WithdrawGasBridge is Script, DeploySetting {
block.chainid == DeploySetting.BASE ||
block.chainid == DeploySetting.BLAST
) {
LibDeploy.withdrawGasBridge(
vm,
address(0xFdF7c22ca4704dfEF46E7e5eF53dcA1d5a9f8E12)
);
LibDeploy.withdrawGasBridge(vm);
}
vm.stopBroadcast();
}
Expand Down
25 changes: 18 additions & 7 deletions script/libraries/LibDeploy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import { CyberVaultV3 } from "../../src/periphery/CyberVaultV3.sol";
import { WorkInCryptoNFT } from "../../src/periphery/WorkInCryptoNFT.sol";
import { CyberNFTGate } from "../../src/periphery/CyberNFTGate.sol";
import { CyberProjectNFTV2 } from "../../src/periphery/CyberProjectNFTV2.sol";
import { SSBonusWeek } from "../../src/periphery/SSBonusWeek.sol";
import { GasBridge } from "../../src/periphery/GasBridge.sol";
import { CyberNewEraGate } from "../../src/periphery/CyberNewEraGate.sol";
import { CyberNewEra } from "../../src/periphery/CyberNewEra.sol";
Expand Down Expand Up @@ -231,8 +232,18 @@ library LibDeploy {
require(ISoul(soul).isMinter(target) == isMinter, "NOT_CORRECT_MINTER");
}

function withdrawGasBridge(Vm, address gasBridge) internal {
GasBridge(gasBridge).withdraw(address(0), gasBridge.balance);
function withdrawGasBridge(Vm) internal {
GasBridge(0xFdF7c22ca4704dfEF46E7e5eF53dcA1d5a9f8E12).withdraw(
address(0),
0xFdF7c22ca4704dfEF46E7e5eF53dcA1d5a9f8E12.balance
);
CyberNewEraGate(0x23e235aE376F08a9C2e6d08A8Bfa8F171306A112).withdraw(
address(0),
0xFdF7c22ca4704dfEF46E7e5eF53dcA1d5a9f8E12.balance
);
CyberNFTGate(0xb636433D8081593b02b1ecCF1118Ad05c100e0A4).withdraw(
address(0)
);
}

function deployFactory(
Expand Down Expand Up @@ -782,18 +793,18 @@ library LibDeploy {
Vm vm,
address _dc,
address owner,
address phi
address cyber
) internal {
Create2Deployer dc = Create2Deployer(_dc);
address cyberProjectNFTV2 = dc.deploy(
address ssBonusWeek = dc.deploy(
abi.encodePacked(
type(CyberProjectNFTV2).creationCode,
abi.encode(owner, phi, owner)
type(SSBonusWeek).creationCode,
abi.encode(owner, cyber)
),
SALT
);

_write(vm, "CyberProjectNFTV2", cyberProjectNFTV2);
_write(vm, "SSBonusWeek", ssBonusWeek);
}

function changeOwnership(
Expand Down
178 changes: 178 additions & 0 deletions src/periphery/SSBonusWeek.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
// SPDX-License-Identifier: GPL-3.0-or-later

pragma solidity 0.8.14;

import { Address } from "openzeppelin-contracts/contracts/utils/Address.sol";
import { AccessControl } from "openzeppelin-contracts/contracts/access/AccessControl.sol";
import { Pausable } from "openzeppelin-contracts/contracts/security/Pausable.sol";
import { ERC1155 } from "openzeppelin-contracts/contracts/token/ERC1155/ERC1155.sol";
import { ERC1155Supply } from "openzeppelin-contracts/contracts/token/ERC1155/extensions/ERC1155Supply.sol";

contract SSBonusWeek is ERC1155Supply, AccessControl, Pausable {
using Address for address payable;

/*//////////////////////////////////////////////////////////////
ERRORS
//////////////////////////////////////////////////////////////*/
/// @notice Address provided is invalid
error InvalidAddressZero();
/// @notice Token has not been created
error NotCreatedToken();
/// @notice Token minting is not started
error MintNotStarted();
/// @notice Incorrect payment
error IncorrectPayment();
/// @notice Invalid amount
error InvalidAmount();

/*//////////////////////////////////////////////////////////////
STORAGE
//////////////////////////////////////////////////////////////*/
uint96 internal constant MINT_FEE = 0.00003 ether;
uint96 internal constant CREATOR_SHARE = 0.000024 ether; // 80% of mint fee
uint96 internal constant CYBER_SHARE = 0.000006 ether; // 20% of mint fee

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

address private immutable cyberTreasury;

struct TokenInfo {
string tokenURI;
address creator;
uint256 mintStartTimestamp;
}

/// @notice Mapping of token ID to token info
mapping(uint256 => TokenInfo) public tokenInfo;

/*//////////////////////////////////////////////////////////////
EVENTS
//////////////////////////////////////////////////////////////*/
/// @notice Emitted when a user mints
event Mint(address indexed to, uint256 indexed tokenId, uint256 amount);

/// @notice Emitted when a token is created or updated
event TokenInfoUpdated(
uint256 indexed tokenId,
string tokenURI,
address indexed creator,
uint256 mintStartTimestamp
);

/// @notice Emitted when the mint start time of a token is updated
event TokenMintStartTimestampUpdated(
uint256 indexed tokenId,
uint256 mintStartTimestamp
);

/*//////////////////////////////////////////////////////////////
CONSTRUCTOR
//////////////////////////////////////////////////////////////*/
constructor(address owner_, address cyberTreasury_) ERC1155("") {
if (owner_ == address(0)) {
revert InvalidAddressZero();
}
cyberTreasury = cyberTreasury_;

_grantRole(MANAGER_ROLE, owner_);
_grantRole(DEFAULT_ADMIN_ROLE, owner_);
}

function name() public pure returns (string memory) {
return "Social Summer Bonus Week";
}

/// @dev Returns the token collection symbol.
function symbol() public pure returns (string memory) {
return "SocialSummerBonusWeek-NFT";
}

/*//////////////////////////////////////////////////////////////
EXTERNAL UPDATE
//////////////////////////////////////////////////////////////*/
function setTokenInfo(
uint256 tokenId,
string calldata _tokenURI,
address _creator,
uint256 _mintStartTimestamp
) external onlyRole(MANAGER_ROLE) {
tokenInfo[tokenId] = TokenInfo(
_tokenURI,
_creator,
_mintStartTimestamp
);
emit TokenInfoUpdated(
tokenId,
_tokenURI,
_creator,
_mintStartTimestamp
);
}

function setTokenMintStartTimestamp(
uint256 tokenId,
uint256 _mintStartTimestamp
) external onlyRole(MANAGER_ROLE) {
tokenInfo[tokenId].mintStartTimestamp = _mintStartTimestamp;
emit TokenMintStartTimestampUpdated(tokenId, _mintStartTimestamp);
}

function pause() external onlyRole(MANAGER_ROLE) {
_pause();
}

function unpause() external onlyRole(MANAGER_ROLE) {
_unpause();
}

function claim(
address to,
uint256 tokenId,
uint256 amount
) external payable whenNotPaused {
if (amount == 0) {
revert InvalidAmount();
}
if (to == address(0)) {
revert InvalidAddressZero();
}
if (bytes(tokenInfo[tokenId].tokenURI).length == 0) {
revert NotCreatedToken();
}
if (tokenInfo[tokenId].mintStartTimestamp > block.timestamp) {
revert MintNotStarted();
}
if (msg.value != MINT_FEE * amount) {
revert IncorrectPayment();
}

_distributeFunds(tokenId, amount);

emit Mint(to, tokenId, amount);
_mint(to, tokenId, amount, "");
}

/*//////////////////////////////////////////////////////////////
EXTERNAL VIEW
//////////////////////////////////////////////////////////////*/
// Returns the URI for a token ID
function uri(uint256 tokenId) public view override returns (string memory) {
return tokenInfo[tokenId].tokenURI;
}

function supportsInterface(
bytes4 interfaceId
) public view override(ERC1155, AccessControl) returns (bool) {
return
ERC1155.supportsInterface(interfaceId) ||
AccessControl.supportsInterface(interfaceId);
}

/*//////////////////////////////////////////////////////////////
INTERNAL LOGIC
//////////////////////////////////////////////////////////////*/
function _distributeFunds(uint256 tokenId, uint256 amount) internal {
payable(tokenInfo[tokenId].creator).sendValue(CREATOR_SHARE * amount);
payable(cyberTreasury).sendValue(CYBER_SHARE * amount);
}
}

0 comments on commit 25a18cc

Please sign in to comment.