-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make upgradable #3
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.17; | ||
|
||
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol"; | ||
import "./Administration.sol"; | ||
import "./MintManager.sol"; | ||
import "./interfaces/IHenkakuToken.sol"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
abstract contract InteractCommunityToken is Administration, MintManager { | ||
address public communityToken; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
function initializeInteractCommunityToken(address _communityToken) public virtual initializer { | ||
communityToken = _communityToken; | ||
} | ||
|
||
function transferCommunityToken(uint256 _amount, address _to) internal { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. この関数が今使われてないようなので、いったん消しました |
||
_checkCommunityTokenBalance(_amount); | ||
bool sent = IHenkakuToken(communityToken).transferFrom(msg.sender, _to, _amount); | ||
require(sent, "Ticket: ERC20 token transfer failed"); | ||
} | ||
|
||
function batchTransferCommunityToken(uint256 totalPrice, uint256[] memory _amounts, address[] memory _to) internal { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
_checkCommunityTokenBalance(totalPrice); | ||
|
||
uint256[] memory amounts = _amounts; | ||
uint256 amountsLength = amounts.length; | ||
require(amountsLength == _to.length, "amounts and to length mismatch"); | ||
|
||
for (uint256 i = 0; i < amountsLength; ) { | ||
bool sent = IHenkakuToken(communityToken).transferFrom(msg.sender, _to[i], amounts[i]); | ||
require(sent, "Ticket: ERC20 Token transfer failed"); | ||
|
||
unchecked { | ||
++i; | ||
} | ||
} | ||
} | ||
|
||
function _checkCommunityTokenBalance(uint256 _requiredAmount) internal view { | ||
require( | ||
IHenkakuToken(communityToken).balanceOf(msg.sender) >= _requiredAmount, | ||
"Ticket: Insufficient ERC20 token" | ||
); | ||
} | ||
} |
This file was deleted.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 今回のアップデートとは関係のないところで、 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 64でもかなりでかいのでこれで良さそうです There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. こちらも今回のアプデとは関係なく、45~49行目の関数へのコメントは削除するのはいかがでしょうか? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 26~27行目の
ですが、 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 関数内で_つかっている同じ名前の変数があるのでこのままにしておきます |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,21 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.9; | ||
pragma solidity ^0.8.17; | ||
|
||
import "@openzeppelin/contracts/token/ERC1155/extensions/ERC1155Supply.sol"; | ||
import "@openzeppelin/contracts-upgradeable/token/ERC1155/extensions/ERC1155SupplyUpgradeable.sol"; | ||
import "@openzeppelin/contracts/utils/Counters.sol"; | ||
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol"; | ||
import "./Administration.sol"; | ||
import "./InteractHenkakuToken.sol"; | ||
import "./InteractCommunityToken.sol"; | ||
import "./MintManager.sol"; | ||
|
||
contract Ticket is ERC1155, ERC1155Supply, Administration, MintManager, InteractHenakuToken { | ||
contract Ticket is | ||
Initializable, | ||
ERC1155Upgradeable, | ||
ERC1155SupplyUpgradeable, | ||
Administration, | ||
MintManager, | ||
InteractCommunityToken | ||
{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. アップグレーダブルのパターンとしてUUPSを採用するのはいかがでしょうか? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ちょっと時間が...ww |
||
//@dev count up tokenId from 0 | ||
using Counters for Counters.Counter; | ||
Counters.Counter private _tokenIds; | ||
|
@@ -53,20 +61,19 @@ contract Ticket is ERC1155, ERC1155Supply, Administration, MintManager, Interact | |
|
||
TicketInfo[] private registeredTickets; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
constructor( | ||
string memory _name, | ||
string memory _symbol, | ||
address _communityToken | ||
) ERC1155("") MintManager() InteractHenakuToken(_communityToken) { | ||
function initialize(string memory _name, string memory _symbol, address _communityToken) public initializer { | ||
name = _name; | ||
symbol = _symbol; | ||
|
||
registeredTickets.push(TicketInfo(address(0), 0, 0, 0, 0, 0, "", new uint256[](0), new address[](0))); | ||
_tokenIds.increment(); | ||
|
||
super.initializeAdministration(); | ||
super.initializeInteractCommunityToken(_communityToken); | ||
} | ||
|
||
modifier onlyHenkakuHolders() { | ||
_checkHenkakuV2Balance(1); | ||
modifier onlyCommunityTokenHolders() { | ||
_checkCommunityTokenBalance(1); | ||
_; | ||
} | ||
|
||
|
@@ -91,7 +98,7 @@ contract Ticket is ERC1155, ERC1155Supply, Administration, MintManager, Interact | |
uint64 _close_blockTimestamp, | ||
address[] memory _shareholdersAddresses, | ||
uint256[] memory _sharesAmounts | ||
) external onlyHenkakuHolders { | ||
) external onlyCommunityTokenHolders { | ||
if ( | ||
_maxSupply == 0 || | ||
keccak256(bytes(_metaDataURL)) == keccak256(bytes("")) || | ||
|
@@ -158,7 +165,7 @@ contract Ticket is ERC1155, ERC1155Supply, Administration, MintManager, Interact | |
} | ||
|
||
// @dev mint function | ||
function mint(uint256 _tokenId) external onlyHenkakuHolders { | ||
function mint(uint256 _tokenId) external onlyCommunityTokenHolders { | ||
require(mintable, "Ticket: Not mintable"); | ||
require(balanceOf(msg.sender, _tokenId) == 0, "Ticket: You already have this ticket"); | ||
|
||
|
@@ -169,7 +176,7 @@ contract Ticket is ERC1155, ERC1155Supply, Administration, MintManager, Interact | |
|
||
ownerOfMintedIds[msg.sender].push(_tokenId); | ||
|
||
batchTransferHenkakuV2(ticket.price, ticket.sharesAmounts, ticket.shareholdersAddresses); | ||
batchTransferCommunityToken(ticket.price, ticket.sharesAmounts, ticket.shareholdersAddresses); | ||
|
||
_mint(msg.sender, _tokenId, 1, ""); | ||
|
||
|
@@ -195,7 +202,7 @@ contract Ticket is ERC1155, ERC1155Supply, Administration, MintManager, Interact | |
} | ||
|
||
// @return token metadata uri | ||
function uri(uint256 _tokenId) public view override(ERC1155) returns (string memory) { | ||
function uri(uint256 _tokenId) public view override(ERC1155Upgradeable) returns (string memory) { | ||
return retrieveRegisteredTicket(_tokenId).uri; | ||
} | ||
|
||
|
@@ -211,7 +218,7 @@ contract Ticket is ERC1155, ERC1155Supply, Administration, MintManager, Interact | |
uint256[] memory _ids, | ||
uint256[] memory _amounts, | ||
bytes memory _data | ||
) internal virtual override(ERC1155, ERC1155Supply) { | ||
ERC1155Supply._beforeTokenTransfer(_operator, _from, _to, _ids, _amounts, _data); | ||
) internal virtual override(ERC1155Upgradeable, ERC1155SupplyUpgradeable) { | ||
ERC1155SupplyUpgradeable._beforeTokenTransfer(_operator, _from, _to, _ids, _amounts, _data); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
あいまいな記憶で申し訳ないのですが、Upgradeableのinitialize系の関数名には、先頭に
__
(アンダースコア2つ)をつけるという慣習があったような気がしています。(
initializeAdministration()
のようなイメージ)違ったらすみません…
関数修飾子が
internal
だと安心かもです。There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Openzeppelinのドキュメントとかは普通にinitialize()ですね、もし参考になるものがあったら言ってください!
ただ、InteractCommunityToken.solとAdministration.solのinitializeはinternalのほうが良さそうなので、_つけるようにします