Skip to content
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

【LocalNouns】ミント条件の整備 #157

Merged
merged 17 commits into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ pnpm-debug.log*

*~

contract/contracts/fonts/font.sol
contract/contracts/fonts/font.sol
src/utils/addresses/*_localhost.ts
35 changes: 12 additions & 23 deletions contract/contracts/LocalNounsToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -67,36 +67,20 @@ contract LocalNounsToken is ProviderTokenA2, ILocalNounsToken {
);
}

function mintSelectedPrefecture(address _to, uint256 _prefectureId) public virtual returns (uint256 tokenId) {
require(msg.sender == minter, 'Sender is not the minter');
assetProvider2.mint(_prefectureId, _nextTokenId());

_safeMint(_to, 1);

return _nextTokenId() - 1;
}

function mintSelectedPrefectureBatch(
function mintSelectedPrefecture(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

memo
minterが指定する県をnのmintする。
LocalNounsProvider.solがよばれる。
mint(uint256 prefectureId, uint256 _assetId)

1,2桁目:都道府県番号、3桁目以降:バージョン番号??

Copy link
Contributor

@isamu isamu Oct 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@EibaKatsu
150, 73など、2桁が都道府県番号じゃない場合にはどうなりますか?
どこかでvalidationいれたほうがよさそうですね。

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

「バージョン番号??」は使ってないように見えますが必要ですか?
必要でないのであれば0 ~ 47指定にして0ならランダムのほうが良いですね。

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LocalNounsMinter.solのmintSelectedPrefectureから呼び出しいるのだと思いますが、
ここはpriceがあるので一般ユーザが使うと理解しています。
であれば
require(msg.sender == minter, 'Sender is not the minter');
があるので、呼べないとなりませんか?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

「バージョン番号??」は使ってないように見えますが必要ですか? 必要でないのであれば0 ~ 47指定にして0ならランダムのほうが良いですね。

初回セールではバージョンを使用しません。
今後HEADパーツが追加された場合に、追加したパーツだけのセールをしたいのでバージョンを設けています。

filenameの先頭がバージョン+都道府県番号で以下のイメージになります。

バージョンなし(初回)
image

バージョンあり(パーツ追加後)
image

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1,2桁目:都道府県番号、3桁目以降:バージョン番号??

表現がおかしいですね、、
下2桁:都道府県番号、下3桁より上位:バージョン番号です。
コメント修正しておきます。

Copy link
Collaborator Author

@EibaKatsu EibaKatsu Oct 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@EibaKatsu 150, 73など、2桁が都道府県番号じゃない場合にはどうなりますか? どこかでvalidationいれたほうがよさそうですね。

追加しました。55e49ad

追記:
存在しないバージョン+都道府県番号だとミント時にエラーになるので、厳密な存在チェックは割愛します。

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LocalNounsMinter.solのmintSelectedPrefectureから呼び出しいるのだと思いますが、 ここはpriceがあるので一般ユーザが使うと理解しています。 であれば require(msg.sender == minter, 'Sender is not the minter'); があるので、呼べないとなりませんか?

mintPrice, mintLimit のミント条件は、Minterコントラクト側で制御します。
この変数を使用しないことをコメントしておきました。

1f91eed
2331227

address _to,
uint256[] memory _prefectureId,
uint256[] memory _amount
uint256 _prefectureId,
uint256 _amount
) public virtual returns (uint256 tokenId) {
require(msg.sender == minter, 'Sender is not the minter');
require(_prefectureId.length == _amount.length, 'parametars length are different');
require(_prefectureId.length > 0, 'parametars length is zero');

uint256 counter = 0;
for (uint256 i = 0; i < _prefectureId.length; i++) {
for (uint256 j = 0; j < _amount[i]; j++) {
assetProvider2.mint(_prefectureId[i], _nextTokenId() + counter++);
}
for (uint256 i = 0; i < _amount; i++) {
assetProvider2.mint(_prefectureId, _nextTokenId());
}

_safeMint(_to, counter);

_safeMint(_to, _amount);
return _nextTokenId() - 1;
}


function mint() public payable override returns (uint256 tokenId) {
revert('Cannot use this function');
}
Expand All @@ -109,6 +93,10 @@ contract LocalNounsToken is ProviderTokenA2, ILocalNounsToken {
administratorsAddress = _admin;
}

/**
* @param _tokenId the token id for put on the trade list.
* @param _prefectures prefectures that you want to trade. if you don't want specific prefecture, you don't need to set.
*/
function putTradeLocalNoun(uint256 _tokenId, uint256[] memory _prefectures) public {
for (uint256 i = 0; i < _prefectures.length; i++) {
require(_prefectures[i] > 0 && _prefectures[i] <= 47, 'incorrect prefecutre id');
Expand All @@ -134,6 +122,7 @@ contract LocalNounsToken is ProviderTokenA2, ILocalNounsToken {
}

function executeTradeLocalNoun(uint256 _myTokenId, uint256 _targetTokenId) public {
// tradePrefectureがない場合は、希望都道府県がないためチェック不要
if (tradePrefecture[_targetTokenId].length > 0) {
uint256 myTokenIdPrefecture = assetProvider2.getPrefectureId(_myTokenId);
bool isIncludesList = false;
Expand Down
2 changes: 1 addition & 1 deletion contract/contracts/libs/AssetTokenGate.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import '@openzeppelin/contracts/token/ERC721/IERC721.sol';
import '../interfaces/ITokenGate.sol';

contract AssetTokenGate is Ownable, ITokenGate {
IERC721[] whitelist;
IERC721[] public whitelist;

function setWhitelist(IERC721[] memory _whitelist) external onlyOwner {
whitelist = _whitelist;
Expand Down
65 changes: 57 additions & 8 deletions contract/contracts/localNouns/LocalNounsMinter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,76 @@ pragma solidity ^0.8.6;

import { Ownable } from '@openzeppelin/contracts/access/Ownable.sol';
import './interfaces/ILocalNounsToken.sol';
import '../interfaces/ITokenGate.sol';

contract LocalNounsMinter is Ownable {
ILocalNounsToken public token;
ITokenGate public immutable tokenGate;

constructor(ILocalNounsToken _token) {
uint256 public mintPriceForSpecified = 0.003 ether;
uint256 public mintPriceForNotSpecified = 0.001 ether;

uint256 public constant mintMax = 1500;

mapping(address => uint256) public preferentialPurchacedCount;

enum SalePhase {
Locked,
PreSale,
PublicSale
}

SalePhase public phase = SalePhase.Locked; // セールフェーズ

address public administratorsAddress; // 運営ウォレット

constructor(ILocalNounsToken _token, ITokenGate _tokenGate) {
token = _token;
administratorsAddress = msg.sender;
tokenGate = _tokenGate;
}

function setLocalNounsToken(ILocalNounsToken _token) external onlyOwner {
token = _token;
}

function mintSelectedPrefecture(uint256 _prefectureId) public payable returns (uint256 tokenId) {
return token.mintSelectedPrefecture(msg.sender, _prefectureId);
function setMintPriceForSpecified(uint256 _price) external onlyOwner {
mintPriceForSpecified = _price;
}

function mintSelectedPrefectureBatch(
uint256[] memory _prefectureId,
uint256[] memory _amount
) public payable returns (uint256 tokenId) {
function setMintPriceForNotSpecified(uint256 _price) external onlyOwner {
mintPriceForNotSpecified = _price;
}

function setPhase(SalePhase _phase) external onlyOwner {
phase = _phase;
}

function setAdministratorsAddress(address _admin) external onlyOwner {
administratorsAddress = _admin;
}

function mintSelectedPrefecture(uint256 _prefectureId, uint256 _amount) public payable returns (uint256 tokenId) {
if (phase == SalePhase.Locked) {
revert('Sale is locked');
} else if (phase == SalePhase.PreSale) {
require(tokenGate.balanceOf(msg.sender) > 0, 'TokenGate token is needed');
}

uint256 mintPrice;
if(_prefectureId == 0){
mintPrice = mintPriceForNotSpecified;
}else{
mintPrice = mintPriceForSpecified;
}
require(msg.value >= mintPrice * _amount, 'Must send the mint price');

return token.mintSelectedPrefecture(msg.sender, _prefectureId, _amount);
}

return token.mintSelectedPrefectureBatch(msg.sender, _prefectureId, _amount);
function withdraw() external payable onlyOwner {
require(administratorsAddress != address(0), "administratorsAddress shouldn't be 0");
(bool sent, ) = payable(administratorsAddress).call{ value: address(this).balance }('');
require(sent, 'failed to move fund to administratorsAddress contract');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,7 @@
pragma solidity ^0.8.6;

interface ILocalNounsToken {
function mintSelectedPrefecture(address to, uint256 prefectureId) external returns (uint256 tokenId);

function mintSelectedPrefectureBatch(
address _to,
uint256[] memory _prefectureId,
uint256[] memory _amount
) external returns (uint256 tokenId);
function mintSelectedPrefecture(address to, uint256 prefectureId, uint256 _amount) external returns (uint256 tokenId);

function setMinter(address _minter) external;

Expand Down
6 changes: 5 additions & 1 deletion contract/scripts/deploy_localNouns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ async function main() {
const [minter] = await ethers.getSigners();
console.log(`##minter="${minter.address}"`);

const factoryTokenGate = await ethers.getContractFactory('AssetTokenGate');
const tokenGate = await factoryTokenGate.deploy();
await tokenGate.deployed();

const factorySeeder = await ethers.getContractFactory('LocalNounsSeeder');
const localseeder = await factorySeeder.deploy();
await localseeder.deployed();
Expand Down Expand Up @@ -57,7 +61,7 @@ async function main() {
await writeFile(`../src/utils/addresses/localNounsToken_${network.name}.ts`, addresses4, () => { });

const factoryMinter = await ethers.getContractFactory('LocalNounsMinter');
const minterContract = await factoryMinter.deploy(token.address);
const minterContract = await factoryMinter.deploy(token.address, tokenGate.address);
await minterContract.deployed();
console.log(`##LocalNounsMinter="${minterContract.address}"`);
await runCommand(`npx hardhat verify ${minterContract.address} ${token.address} --network ${network.name} &`);
Expand Down
Loading
Loading