Skip to content

Commit

Permalink
Merge pull request #413 from BoostryJP/feature/#421
Browse files Browse the repository at this point in the history
Add ERC20/721 support
  • Loading branch information
YoshihitoAso authored Mar 27, 2023
2 parents 535b1fe + 709d8ca commit 82f355d
Show file tree
Hide file tree
Showing 15 changed files with 231 additions and 13 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ English | [日本語](README_JA.md)
- `exchange`: Implementations of the various exchanges.
- `ledger`: A data storage system that manages the data required as additional information in the ledger.
- `payment`: A set of functions required to build an off-chain payment system.
- `token`: Implementation of the various token formats: Bonds, Shares, etc.
- `token`: Implementation of the various token formats: ERC20, ERC721, Bonds, Shares, etc.
- `utils`: A set of other utility functions.

## Install
Expand All @@ -57,7 +57,7 @@ $ pip install -r requirements.txt
Install openzeppelin-contracts.

```bash
$ brownie pm install OpenZeppelin/[email protected].1
$ brownie pm install OpenZeppelin/[email protected].2
```

## Compile Contracts
Expand Down
4 changes: 2 additions & 2 deletions README_JA.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
- `exchange`: 様々な取引機能(Exchange)の実装です。
- `ledger`: 法定原簿に必要な付加情報を管理するためのデータストレージ機能を提供します。
- `payment`: オフチェーン決済を実現するため機能群です。
- `token`: 各種トークンフォーマットの実装です(Bond型、Share型など)。
- `token`: 各種トークンフォーマットの実装です(ERC20、ERC721、Bond型、Share型など)。
- `utils`: その他のユーティリティ機能です。

## インストール
Expand All @@ -55,7 +55,7 @@ $ pip install -r requirements.txt

openzeppelin-contractsをインストールします。
```bash
$ brownie pm install OpenZeppelin/[email protected].1
$ brownie pm install OpenZeppelin/[email protected].2
```

## コントラクトのコンパイル
Expand Down
2 changes: 1 addition & 1 deletion brownie-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ compiler:
solc:
version: 0.8.19
dependencies:
OpenZeppelin/[email protected].1
OpenZeppelin/[email protected].2
2 changes: 1 addition & 1 deletion contracts/exchange/IbetEscrow.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/
pragma solidity ^0.8.0;

import "OpenZeppelin/[email protected].1/contracts/utils/math/SafeMath.sol";
import "OpenZeppelin/[email protected].2/contracts/utils/math/SafeMath.sol";
import "./EscrowStorage.sol";
import "../access/Ownable.sol";
import "../utils/Errors.sol";
Expand Down
2 changes: 1 addition & 1 deletion contracts/exchange/IbetExchange.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

pragma solidity ^0.8.0;

import "OpenZeppelin/[email protected].1/contracts/utils/math/SafeMath.sol";
import "OpenZeppelin/[email protected].2/contracts/utils/math/SafeMath.sol";
import "./ExchangeStorage.sol";
import "../access/Ownable.sol";
import "../utils/Errors.sol";
Expand Down
2 changes: 1 addition & 1 deletion contracts/exchange/IbetSecurityTokenEscrow.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/
pragma solidity ^0.8.0;

import "OpenZeppelin/[email protected].1/contracts/utils/math/SafeMath.sol";
import "OpenZeppelin/[email protected].2/contracts/utils/math/SafeMath.sol";
import "./EscrowStorage.sol";
import "../access/Ownable.sol";
import "../utils/Errors.sol";
Expand Down
2 changes: 1 addition & 1 deletion contracts/token/IbetCoupon.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

pragma solidity ^0.8.0;

import "OpenZeppelin/[email protected].1/contracts/utils/math/SafeMath.sol";
import "OpenZeppelin/[email protected].2/contracts/utils/math/SafeMath.sol";
import "../access/Ownable.sol";
import "../utils/Errors.sol";
import "../../interfaces/ContractReceiver.sol";
Expand Down
31 changes: 31 additions & 0 deletions contracts/token/IbetERC20.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* Copyright BOOSTRY Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
*
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
* See the License for the specific language governing permissions and
* limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
*/
pragma solidity ^0.8.0;

import "OpenZeppelin/[email protected]/contracts/token/ERC20/ERC20.sol";
import "OpenZeppelin/[email protected]/contracts/token/ERC20/extensions/ERC20Burnable.sol";
import "OpenZeppelin/[email protected]/contracts/access/Ownable.sol";

contract IbetERC20 is ERC20, ERC20Burnable, Ownable {
constructor() ERC20("IbetERC20", "") {}

function mint(address to, uint256 amount) public onlyOwner {
_mint(to, amount);
}
}
31 changes: 31 additions & 0 deletions contracts/token/IbetERC721.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* Copyright BOOSTRY Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
*
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
* See the License for the specific language governing permissions and
* limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
*/
pragma solidity ^0.8.0;

import "OpenZeppelin/[email protected]/contracts/token/ERC721/ERC721.sol";
import "OpenZeppelin/[email protected]/contracts/token/ERC721/extensions/ERC721Burnable.sol";
import "OpenZeppelin/[email protected]/contracts/access/Ownable.sol";

contract IbetERC721 is ERC721, ERC721Burnable, Ownable {
constructor() ERC721("IbetERC721", "") {}

function safeMint(address to, uint256 tokenId) public onlyOwner {
_safeMint(to, tokenId);
}
}
2 changes: 1 addition & 1 deletion contracts/token/IbetMembership.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

pragma solidity ^0.8.0;

import "OpenZeppelin/[email protected].1/contracts/utils/math/SafeMath.sol";
import "OpenZeppelin/[email protected].2/contracts/utils/math/SafeMath.sol";
import "../access/Ownable.sol";
import "../utils/Errors.sol";
import "../../interfaces/ContractReceiver.sol";
Expand Down
2 changes: 1 addition & 1 deletion contracts/token/IbetShare.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/
pragma solidity ^0.8.0;

import "OpenZeppelin/[email protected].1/contracts/utils/math/SafeMath.sol";
import "OpenZeppelin/[email protected].2/contracts/utils/math/SafeMath.sol";
import "../access/Ownable.sol";
import "../ledger/PersonalInfo.sol";
import "../utils/Errors.sol";
Expand Down
2 changes: 1 addition & 1 deletion contracts/token/IbetStandardToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

pragma solidity ^0.8.0;

import "OpenZeppelin/[email protected].1/contracts/utils/math/SafeMath.sol";
import "OpenZeppelin/[email protected].2/contracts/utils/math/SafeMath.sol";
import "../access/Ownable.sol";
import "../utils/Errors.sol";
import "../../interfaces/ContractReceiver.sol";
Expand Down
2 changes: 1 addition & 1 deletion contracts/token/IbetStraightBond.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/
pragma solidity ^0.8.0;

import "OpenZeppelin/[email protected].1/contracts/utils/math/SafeMath.sol";
import "OpenZeppelin/[email protected].2/contracts/utils/math/SafeMath.sol";
import "../access/Ownable.sol";
import "../ledger/PersonalInfo.sol";
import "../utils/Errors.sol";
Expand Down
80 changes: 80 additions & 0 deletions tests/token/test_IbetERC20.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
"""
Copyright BOOSTRY Co., Ltd.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
SPDX-License-Identifier: Apache-2.0
"""
import brownie


class TestDeploy:

##########################################################
# Normal
##########################################################

# Normal_1
def test_normal_1(self, IbetERC20, users):
issuer = users["issuer"]

# deploy
token = issuer.deploy(IbetERC20)

# assertion
assert token.name() == "IbetERC20"
assert token.symbol() == ""
assert token.decimals() == 18
assert token.totalSupply() == 0
assert token.balanceOf(issuer.address) == 0


class TestMint:

##########################################################
# Normal
##########################################################

# Normal_1
def test_normal_1(self, IbetERC20, users):
issuer = users["issuer"]

# deploy
token = issuer.deploy(IbetERC20)

# mint
token.mint(issuer.address, 10, {"from": issuer})

# assertion
assert token.name() == "IbetERC20"
assert token.symbol() == ""
assert token.decimals() == 18
assert token.totalSupply() == 10
assert token.balanceOf(issuer.address) == 10

##########################################################
# Error
##########################################################

# Error_1
def test_error_1(self, IbetERC20, users):
issuer = users["issuer"]
other = users["user1"]

# deploy
token = issuer.deploy(IbetERC20)

# mint
with brownie.reverts(revert_msg="Ownable: caller is not the owner"):
token.mint(issuer.address, 10, {"from": other})
76 changes: 76 additions & 0 deletions tests/token/test_IbetERC721.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
"""
Copyright BOOSTRY Co., Ltd.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
SPDX-License-Identifier: Apache-2.0
"""
import brownie


class TestDeploy:

##########################################################
# Normal
##########################################################

# Normal_1
def test_normal_1(self, IbetERC721, users):
issuer = users["issuer"]

# deploy
token = issuer.deploy(IbetERC721)

# assertion
assert token.name() == "IbetERC721"
assert token.balanceOf(issuer.address) == 0


class TestSafeMint:

##########################################################
# Normal
##########################################################

# Normal_1
def test_normal_1(self, IbetERC721, users):
issuer = users["issuer"]

# deploy
token = issuer.deploy(IbetERC721)

# mint
token.safeMint(issuer.address, 123, {"from": issuer})

# assertion
assert token.name() == "IbetERC721"
assert token.balanceOf(issuer.address) == 1
assert token.ownerOf(123) == issuer.address


##########################################################
# Error
##########################################################

# Error_1
def test_error_1(self, IbetERC721, users):
issuer = users["issuer"]
other = users["user1"]

# deploy
token = issuer.deploy(IbetERC721)

# mint
with brownie.reverts(revert_msg="Ownable: caller is not the owner"):
token.safeMint(issuer.address, 123, {"from": other})

0 comments on commit 82f355d

Please sign in to comment.