Skip to content

Commit

Permalink
Merge branch 'main' into unit-tests-revision
Browse files Browse the repository at this point in the history
  • Loading branch information
zajck committed Oct 13, 2021
2 parents 9511db4 + 5319bbb commit 3ed1d65
Show file tree
Hide file tree
Showing 20 changed files with 617 additions and 333 deletions.
22 changes: 20 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ tools installed.

At a minimum, you'll need:
* Node (12.20)
* NPM (> 6)
* NPM (7)
* Ruby (2.7)
* Bundler (> 2)
* Git
Expand Down Expand Up @@ -90,9 +90,27 @@ If preferred by those who are familiar with Hardhat, the standard Hardhat comman
In a separate terminal, contracts can be deployed using
```shell
npx hardhat --network [customNetworkName] deploy
npx hardhat --network localhost deploy
```
#### Forking Rinkeby to localnode
It is possible to fork the state of the Rinkeby chain to have it deployed locally.
The following hardhat commands will achieve this:
```shell script
npx hardhat node --fork https://eth-rinkeby.alchemyapi.io/v2/<<alchemy key>>
```
Alchemy is recommended by Hardhat over Infura because it's free accounts provide archived data, which is required for successful forking.

You can then deploy from a separate terminal using the command

```shell script
npx hardhat deploy --network localhost
```

This makes the BOSON test token deployed on Rinkeby (0xEDa08eF1c6ff51Ca7Fd681295797102c1B84606c) and the official DAI token
deployed on Rinkeby (0x6A9865aDE2B6207dAAC49f8bCba9705dEB0B0e6D) available to your local hardhat chain.

---
### Test
Expand Down
6 changes: 3 additions & 3 deletions contracts/BosonRouter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -826,7 +826,7 @@ contract BosonRouter is
/**
* @notice Call permit on either a token directly or on a token wrapper
* @param _token Address of the token owner who is approving tokens to be transferred by spender
* @param _owner Address of the token owner who is approving tokens to be transferred by spender
* @param _tokenOwner Address of the token owner who is approving tokens to be transferred by spender
* @param _spender Address of the party who is transferring tokens on owner's behalf
* @param _value Number of tokens to be transferred
* @param _deadline Time after which this permission to transfer is no longer valid. See EIP-2612
Expand All @@ -836,7 +836,7 @@ contract BosonRouter is
*/
function _permit(
address _token,
address _owner,
address _tokenOwner,
address _spender,
uint256 _value,
uint256 _deadline,
Expand All @@ -851,7 +851,7 @@ contract BosonRouter is
//The BosonToken contract conforms to this spec, so it will be callable this way
//if it's address is mapped to itself in the TokenRegistry
ITokenWrapper(tokenWrapper).permit(
_owner,
_tokenOwner,
_spender,
_value,
_deadline,
Expand Down
15 changes: 7 additions & 8 deletions contracts/DAITokenWrapper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -36,33 +36,32 @@ contract DAITokenWrapper is

/**
* @notice Conforms to EIP-2612. Calls permit on token, which may or may not have a permit function that conforms to EIP-2612
* @param _owner Address of the token owner who is approving tokens to be transferred by spender
* @param _tokenOwner Address of the token owner who is approving tokens to be transferred by spender
* @param _spender Address of the party who is transferring tokens on owner's behalf
* @param _value Number of tokens to be transferred
* @param _deadline Time after which this permission to transfer is no longer valid
* @param _v Part of the owner's signatue
* @param _r Part of the owner's signatue
* @param _s Part of the owner's signatue
*/
function permit(
address _owner,
address _tokenOwner,
address _spender,
uint256 _value,
uint256,
uint256 _deadline,
uint8 _v,
bytes32 _r,
bytes32 _s
)
external
override
notZeroAddress(_owner)
notZeroAddress(_tokenOwner)
notZeroAddress(_spender)
{
require(_deadline == 0 || block.timestamp <= _deadline, "PERMIT_EXPIRED");
require(_r != bytes32(0) && _s != bytes32(0), "INVALID_SIGNATURE_COMPONENTS");
uint nonce = IDAI(daiTokenAddress).nonces(_owner);
IDAI(daiTokenAddress).permit(_owner, _spender, nonce, _deadline, true, _v, _r, _s);
emit LogPermitCalledOnToken(daiTokenAddress, _owner, _spender, 0);
uint nonce = IDAI(daiTokenAddress).nonces(_tokenOwner);
IDAI(daiTokenAddress).permit(_tokenOwner, _spender, nonce, _deadline, true, _v, _r, _s);
emit LogPermitCalledOnToken(daiTokenAddress, _tokenOwner, _spender, 0);
}

/**
Expand Down
32 changes: 16 additions & 16 deletions contracts/ERC1155ERC721.sol
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ contract ERC1155ERC721 is IERC1155ERC721, Ownable {
address _from,
address _to,
uint256 _tokenId
) public override {
) external override {
safeTransferFrom(_from, _to, _tokenId, "");
}

Expand Down Expand Up @@ -228,7 +228,7 @@ contract ERC1155ERC721 is IERC1155ERC721, Ownable {
* @param _to address to be approved for the given token ID
* @param _tokenId uint256 ID of the token to be approved
*/
function approve(address _to, uint256 _tokenId) public override {
function approve(address _to, uint256 _tokenId) external override {
address tokenOwner = ownerOf(_tokenId);
require(_to != tokenOwner, "REDUNDANT_CALL");

Expand All @@ -251,7 +251,7 @@ contract ERC1155ERC721 is IERC1155ERC721, Ownable {
* @return address currently approved for the given token ID
*/
function getApproved(uint256 _tokenId)
public
external
view
override
returns (address)
Expand Down Expand Up @@ -401,12 +401,12 @@ contract ERC1155ERC721 is IERC1155ERC721, Ownable {

/// @notice Count all NFTs assigned to an owner
/// @dev ERC-721
/// @param _owner An address for whom to query the balance
/// @param _tokenOwner An address for whom to query the balance
/// @return The number of NFTs owned by `_owner`, possibly zero
function balanceOf(address _owner) public view override returns (uint256) {
require(_owner != address(0), "UNSPECIFIED_ADDRESS");
function balanceOf(address _tokenOwner) external view override returns (uint256) {
require(_tokenOwner != address(0), "UNSPECIFIED_ADDRESS");

return balance721[_owner];
return balance721[_tokenOwner];
}

/**
Expand Down Expand Up @@ -470,7 +470,7 @@ contract ERC1155ERC721 is IERC1155ERC721, Ownable {
@return True if the operator is approved, false if not
*/
function isApprovedForAll(address _account, address _operator)
public
external
view
override
returns (bool)
Expand Down Expand Up @@ -514,7 +514,7 @@ contract ERC1155ERC721 is IERC1155ERC721, Ownable {
uint256 _tokenId,
uint256 _value,
bytes memory _data
) public override onlyFromVoucherKernel {
) external override onlyFromVoucherKernel {
_mint(_to, _tokenId, _value, _data);
}

Expand Down Expand Up @@ -555,7 +555,7 @@ contract ERC1155ERC721 is IERC1155ERC721, Ownable {
* @return A boolean that indicates if the operation was successful.
*/
function mint(address _to, uint256 _tokenId)
public
external
override
onlyFromVoucherKernel
returns (bool)
Expand Down Expand Up @@ -598,7 +598,7 @@ contract ERC1155ERC721 is IERC1155ERC721, Ownable {
uint256[] memory _tokenIds,
uint256[] memory _values,
bytes memory _data
) public onlyFromVoucherKernel {
) external onlyFromVoucherKernel {
//require approved minter

_mintBatch(_to, _tokenIds, _values, _data);
Expand Down Expand Up @@ -650,7 +650,7 @@ contract ERC1155ERC721 is IERC1155ERC721, Ownable {
address _account,
uint256 _tokenId,
uint256 _value
) public override onlyFromVoucherKernel {
) external override onlyFromVoucherKernel {
_burn(_account, _tokenId, _value);
}

Expand Down Expand Up @@ -685,7 +685,7 @@ contract ERC1155ERC721 is IERC1155ERC721, Ownable {
address _account,
uint256[] memory _tokenIds,
uint256[] memory _values
) public onlyFromVoucherKernel {
) external onlyFromVoucherKernel {
_burnBatch(_account, _tokenIds, _values);
}

Expand Down Expand Up @@ -726,23 +726,23 @@ contract ERC1155ERC721 is IERC1155ERC721, Ownable {
* @notice Setting the URL prefix for tokens metadata
* @param _newBase New prefix to be used
*/
function _setMetadataBase(string memory _newBase) public onlyOwner {
function _setMetadataBase(string memory _newBase) external onlyOwner {
metadataBase = _newBase;
}

/**
* @notice Setting the URL route for ERC1155 tokens metadata
* @param _newRoute New route to be used
*/
function _set1155Route(string memory _newRoute) public onlyOwner {
function _set1155Route(string memory _newRoute) external onlyOwner {
metadata1155Route = _newRoute;
}

/**
* @notice Setting the URL route for ERC721 tokens metadata
* @param _newRoute New route to be used
*/
function _set721Route(string memory _newRoute) public onlyOwner {
function _set721Route(string memory _newRoute) external onlyOwner {
metadata721Route = _newRoute;
}

Expand Down
28 changes: 19 additions & 9 deletions contracts/ERC1155NonTransferable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@ pragma solidity 0.7.6;
import "@openzeppelin/contracts/token/ERC1155/ERC1155Pausable.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "./interfaces/IERC1155NonTransferable.sol";
import "./MetaTransactionReceiver.sol";

/**
* @title Non transferable token contract, implementing ERC-1155, but preventing transfers
*/
contract ERC1155NonTransferable is
IERC1155NonTransferable,
ERC1155Pausable,
Ownable
Ownable,
MetaTransactionReceiver
{

event LogUriSet(string _newUri, address _triggeredBy);
Expand All @@ -36,7 +38,7 @@ contract ERC1155NonTransferable is
uint256 _tokenId,
uint256 _value,
bytes memory _data
) public override onlyOwner {
) external override onlyOwnerOrSelf {
_mint(_to, _tokenId, _value, _data);
}

Expand All @@ -53,7 +55,7 @@ contract ERC1155NonTransferable is
uint256[] memory _tokenIds,
uint256[] memory _values,
bytes memory _data
) public onlyOwner {
) external onlyOwnerOrSelf {
_mintBatch(_to, _tokenIds, _values, _data);
}

Expand All @@ -68,7 +70,7 @@ contract ERC1155NonTransferable is
address _account,
uint256 _tokenId,
uint256 _value
) public override onlyOwner {
) external override onlyOwnerOrSelf {
_burn(_account, _tokenId, _value);
}

Expand All @@ -83,7 +85,7 @@ contract ERC1155NonTransferable is
address _account,
uint256[] memory _tokenIds,
uint256[] memory _values
) public onlyOwner {
) external onlyOwnerOrSelf {
_burnBatch(_account, _tokenIds, _values);
}

Expand Down Expand Up @@ -115,24 +117,32 @@ contract ERC1155NonTransferable is
/**
* @notice Pause all token mint, transfer, burn
*/
function pause() external override onlyOwner {
function pause() external override onlyOwnerOrSelf {
_pause();
}

/**
* @notice Unpause the contract and allows mint, transfer, burn
*/
function unpause() external override onlyOwner {
function unpause() external override onlyOwnerOrSelf {
_unpause();
}

/**
* @notice Setting the metadata uri
* @param _newUri New uri to be used
*/
function setUri(string memory _newUri) external onlyOwner {
function setUri(string memory _newUri) external onlyOwnerOrSelf {
require(bytes(_newUri).length != 0, "INVALID_VALUE");
_setURI(_newUri);
emit LogUriSet(_newUri, msg.sender);
emit LogUriSet(_newUri, _msgSender());
}

/**
* @notice When functions are invoked via metatransactions, it is already checked there that signer is the owner of transaction
* and we can declare it as a message sender
*/
function _msgSender() internal view virtual override returns (address payable) {
return msg.sender == address(this) ? payable(owner()) : msg.sender;
}
}
2 changes: 1 addition & 1 deletion contracts/Gate.sol
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ contract Gate is IGate, Ownable, Pausable {
external
override
whenNotPaused
onlyOwner
{
require(msg.sender == bosonRouterAddress || msg.sender == owner(), "UNAUTHORIZED_O_BR");
require(_nftTokenId != 0, "TOKEN_ID_0_NOT_ALLOWED");
require(_tokenIdSupply != 0, "INVALID_TOKEN_SUPPLY");

Expand Down
Loading

0 comments on commit 3ed1d65

Please sign in to comment.