Skip to content

Commit

Permalink
fix conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
YouStillAlive committed May 15, 2024
2 parents 1712d02 + 8719652 commit 6f26b5a
Show file tree
Hide file tree
Showing 19 changed files with 893 additions and 1,036 deletions.
39 changes: 39 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Publish on Release

on:
release:
types:
- published

jobs:
publish:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: master

- uses: actions/setup-node@v4
with:
node-version: 20
registry-url: 'https://registry.npmjs.org'

- name: Get Release Tag
run: echo "tag=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV

- name: Set git user
run: |
git config user.name github-actions
git config user.email github-actions@github.com
- name: Set version ${{ env.tag }}
run: |
npm version ${{ env.tag }}
git push
- name: Publish
run: npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
9 changes: 6 additions & 3 deletions contracts/Array.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@ pragma solidity ^0.8.0;

/// @title contains array utility functions
library Array {
error InvalidArrayLength(uint256 _arrLength, uint256 _n);
error ZeroArrayLength();

/// @dev returns a new slice of the array
function KeepNElementsInArray(uint256[] memory _arr, uint256 _n)
internal
pure
returns (uint256[] memory newArray)
{
if (_arr.length == _n) return _arr;
require(_arr.length > _n, "can't cut more then got");
if (_arr.length <= _n) revert InvalidArrayLength(_arr.length, _n);
newArray = new uint256[](_n);
for (uint256 i = 0; i < _n; ++i) {
newArray[i] = _arr[i];
Expand All @@ -25,7 +28,7 @@ library Array {
returns (address[] memory newArray)
{
if (_arr.length == _n) return _arr;
require(_arr.length > _n, "can't cut more then got");
if (_arr.length <= _n) revert InvalidArrayLength(_arr.length, _n);
newArray = new address[](_n);
for (uint256 i = 0; i < _n; ++i) {
newArray[i] = _arr[i];
Expand All @@ -39,7 +42,7 @@ library Array {
pure
returns (bool)
{
require(_arr.length > 0, "array should be greater than zero");
if (_arr.length == 0) revert ZeroArrayLength();
uint256 temp = _arr[0];
for (uint256 i = 1; i < _arr.length; ++i) {
if (temp > _arr[i]) {
Expand Down
47 changes: 27 additions & 20 deletions contracts/ERC20Helper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,36 +11,43 @@ contract ERC20Helper is FirewallConsumer {
event TransferOut(uint256 Amount, address To, address Token);
event TransferIn(uint256 Amount, address From, address Token);

error NoAllowance();
error SentIncorrectAmount();
error ReceivedIncorrectAmount();
error ZeroAmount();

modifier TestAllowance(
IERC20 token,
address owner,
uint256 amount
IERC20 _Token,
address _Owner,
uint256 _Amount
) {
require(token.allowance(owner, address(this)) >= amount, "ERC20Helper: no allowance");
if (_Token.allowance(_Owner, address(this)) < _Amount) {
revert NoAllowance();
}
_;
}

function TransferToken(IERC20 token, address receiver, uint256 amount) internal firewallProtectedSig(0x3844b707) {
uint256 oldBalance = token.balanceOf(address(this));
emit TransferOut(amount, receiver, address(token));
token.safeTransfer(receiver, amount);
require((token.balanceOf(address(this)) + amount) == oldBalance, "ERC20Helper: sent incorrect amount");
function TransferToken(IERC20 _Token, address _Reciver, uint256 _Amount) internal firewallProtectedSig(0x3844b707) {
uint256 OldBalance = _Token.balanceOf(address(this));
emit TransferOut(_Amount, _Reciver, address(_Token));
_Token.transfer(_Reciver, _Amount);
if (_Token.balanceOf(address(this)) == (OldBalance + _Amount)) revert SentIncorrectAmount();
}

function TransferInToken(IERC20 token, uint256 amount) internal TestAllowance(token, msg.sender, amount) {
require(amount > 0);
uint256 oldBalance = token.balanceOf(address(this));
token.safeTransferFrom(msg.sender, address(this), amount);
emit TransferIn(amount, msg.sender, address(token));
require((oldBalance + amount) == token.balanceOf(address(this)), "ERC20Helper: Received Incorrect Amount");
function TransferInToken(IERC20 _Token, uint256 _Amount) internal TestAllowance(_Token, msg.sender, _Amount) {
if (_Amount == 0) revert ZeroAmount();
uint256 OldBalance = _Token.balanceOf(address(this));
_Token.transferFrom(msg.sender, address(this), _Amount);
emit TransferIn(_Amount, msg.sender, address(_Token));
if (_Token.balanceOf(address(this)) != (OldBalance + _Amount)) revert ReceivedIncorrectAmount();
}

function ApproveAllowanceERC20(
IERC20 token,
address subject,
uint256 amount
IERC20 _Token,
address _Subject,
uint256 _Amount
) internal firewallProtectedSig(0x91251680) {
require(amount > 0);
token.approve(subject, amount);
if (_Amount == 0) revert ZeroAmount();
_Token.approve(_Subject, _Amount);
}
}
27 changes: 11 additions & 16 deletions contracts/ERC721Helper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,24 @@ contract ERC721Helper is FirewallConsumer, ERC721Holder {
event TransferOut(address Token, uint256 TokenId, address To);
event TransferIn(address Token, uint256 TokenId, address From);

error NoAllowance();

modifier TestNFTAllowance(
address _token,
uint256 _tokenId,
address _owner
) {
require(
IERC721(_token).isApprovedForAll(_owner, address(this)) ||
IERC721(_token).getApproved(_tokenId) == address(this),
"No Allowance"
);
if (
!IERC721(_token).isApprovedForAll(_owner, address(this)) &&
IERC721(_token).getApproved(_tokenId) != address(this)
) {
revert NoAllowance();
}
_;
}

function TransferNFTOut(
address _Token,
uint256 _TokenId,
address _To
) internal firewallProtectedSig(0x53905fab) {
IERC721(_Token).safeTransferFrom(address(this), _To, _TokenId);
function TransferNFTOut(address _Token, uint256 _TokenId, address _To) internal firewallProtectedSig(0x53905fab) {
IERC721(_Token).transferFrom(address(this), _To, _TokenId);
emit TransferOut(_Token, _TokenId, _To);
assert(IERC721(_Token).ownerOf(_TokenId) == _To);
}
Expand All @@ -43,11 +42,7 @@ contract ERC721Helper is FirewallConsumer, ERC721Holder {
assert(IERC721(_Token).ownerOf(_TokenId) == address(this));
}

function SetApproveForAllNFT(
address _Token,
address _To,
bool _Approve
) internal firewallProtectedSig(0xd5ebe78c) {
function SetApproveForAllNFT(address _Token, address _To, bool _Approve) internal firewallProtectedSig(0xd5ebe78c) {
IERC721(_Token).setApprovalForAll(_To, _Approve);
}
}
19 changes: 7 additions & 12 deletions contracts/ETHHelper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,17 @@ import "@openzeppelin/contracts/access/Ownable.sol";
import "@ironblocks/firewall-consumer/contracts/FirewallConsumer.sol";

contract ETHHelper is Ownable, FirewallConsumer {
constructor() {
IsPayble = false;
}
error InvalidAmount();
error SentIncorrectAmount();

constructor() Ownable(_msgSender()) {}

modifier ReceivETH(
uint256 msgValue,
address msgSender,
uint256 _MinETHInvest
) {
require(msgValue >= _MinETHInvest, "Send ETH to invest");
if (msgValue < _MinETHInvest) revert InvalidAmount();
emit TransferInETH(msgValue, msgSender);
_;
}
Expand All @@ -33,16 +34,10 @@ contract ETHHelper is Ownable, FirewallConsumer {
IsPayble = !IsPayble;
}

function TransferETH(address payable _Reciver, uint256 _amount)
internal
firewallProtectedSig(0xfd69c215)
{
function TransferETH(address payable _Reciver, uint256 _amount) internal firewallProtectedSig(0xfd69c215) {
emit TransferOutETH(_amount, _Reciver);
uint256 beforeBalance = address(_Reciver).balance;
_Reciver.transfer(_amount);
require(
(beforeBalance + _amount) == address(_Reciver).balance,
"The transfer did not complite"
);
if ((beforeBalance + _amount) != address(_Reciver).balance) revert SentIncorrectAmount();
}
}
16 changes: 7 additions & 9 deletions contracts/GovManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,16 @@ import "@openzeppelin/contracts/access/Ownable.sol";
import "@ironblocks/firewall-consumer/contracts/FirewallConsumer.sol";

contract GovManager is Ownable, FirewallConsumer {
event GovernorUpdated (
address indexed oldGovernor,
address indexed newGovernor
);
event GovernorUpdated(address indexed oldGovernor, address indexed newGovernor);

error AuthorizationError();

address public GovernorContract;

modifier onlyOwnerOrGov() {
require(
msg.sender == owner() || msg.sender == GovernorContract,
"Authorization Error"
);
if (msg.sender != owner() && msg.sender != GovernorContract) {
revert AuthorizationError();
}
_;
}

Expand All @@ -27,7 +25,7 @@ contract GovManager is Ownable, FirewallConsumer {
emit GovernorUpdated(oldGov, GovernorContract);
}

constructor() {
constructor() Ownable(_msgSender()) {
GovernorContract = address(0);
}
}
2 changes: 1 addition & 1 deletion contracts/PausableHelper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

pragma solidity ^0.8.4;

import "@openzeppelin/contracts/security/Pausable.sol";
import "@openzeppelin/contracts/utils/Pausable.sol";
import "./GovManager.sol";

/**
Expand Down
6 changes: 3 additions & 3 deletions contracts/mocks/ETHHelperMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ pragma solidity ^0.8.0;
import "../ETHHelper.sol";

contract ETHHelperMock is ETHHelper {
function receiveETH(
uint256 minETHInvest
) external payable ReceivETH(msg.value, msg.sender, minETHInvest) {}
constructor() ETHHelper() {}

function receiveETH(uint256 minETHInvest) external payable ReceivETH(msg.value, msg.sender, minETHInvest) {}

function transferETH(address payable reciver, uint256 amount) external {
TransferETH(reciver, amount);
Expand Down
5 changes: 4 additions & 1 deletion contracts/token/ERC20Token.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ contract ERC20Token is ERC20, Ownable {
* @dev assign totalSupply to account creating this contract
*/

constructor(string memory _TokenName, string memory _TokenSymbol) ERC20(_TokenName, _TokenSymbol) {
constructor(
string memory _TokenName,
string memory _TokenSymbol
) ERC20(_TokenName, _TokenSymbol) Ownable(_msgSender()) {
_mint(msg.sender, 5_000_000 * 10 ** 18);
}

Expand Down
8 changes: 2 additions & 6 deletions contracts/token/ERC721Token.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,17 @@ pragma solidity ^0.8.0;

import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol";
import "@openzeppelin/contracts/utils/Counters.sol";

contract ERC721Token is ERC721URIStorage {
using Counters for Counters.Counter;
Counters.Counter private _tokenIds;
uint256 private _tokenIdCounter;

constructor() ERC721("GameItem", "ITM") {}

function awardItem(address player, string memory tokenURI)
public
returns (uint256)
{
_tokenIds.increment();

uint256 newItemId = _tokenIds.current();
uint256 newItemId = ++_tokenIdCounter;
_mint(player, newItemId);
_setTokenURI(newItemId, tokenURI);

Expand Down
2 changes: 1 addition & 1 deletion hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import 'solidity-coverage';
const config: HardhatUserConfig = {
defaultNetwork: 'hardhat',
solidity: {
version: '0.8.19',
version: '0.8.24',
settings: {
evmVersion: 'istanbul',
optimizer: {
Expand Down
Loading

0 comments on commit 6f26b5a

Please sign in to comment.