-
Notifications
You must be signed in to change notification settings - Fork 18
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】都道府県ランダムミント時の割合設定 #158
Changes from 4 commits
11f78ad
699532f
f3e169b
c35e934
dcfccae
4b73f06
3ccd9a1
872fd3d
4b6a322
25178fd
ddce2f2
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 |
---|---|---|
|
@@ -33,6 +33,13 @@ contract LocalNounsProvider is IAssetProviderExMint, IERC165, Ownable { | |
mapping(uint256 => uint256) public tokenIdToPrefectureId; | ||
mapping(uint256 => string) public prefectureName; | ||
mapping(uint256 => uint256) public mintNumberPerPrefecture; // 都道府県ごとのミント数 | ||
// mapping(uint256 => uint256) public prefectureRatio; // ランダムミント時に決定される都道府県の割合 | ||
uint256 totalPrefectureRatio; | ||
|
||
uint256[5] ratioRank = [5, 4, 3, 3, 2]; | ||
uint256[5] acumurationRatioRank; | ||
uint256 acumurationRatioRankTotal; | ||
mapping(uint256 => uint256[]) public prefectureRatio; | ||
|
||
constructor( | ||
INounsDescriptor _descriptor, | ||
|
@@ -94,6 +101,17 @@ contract LocalNounsProvider is IAssetProviderExMint, IERC165, Ownable { | |
prefectureName[45] = 'Miyazaki'; | ||
prefectureName[46] = 'Kagoshima'; | ||
prefectureName[47] = 'Okinawa'; | ||
|
||
prefectureRatio[0] = [13, 14, 27, 23, 11, 12, 28, 1, 40]; | ||
prefectureRatio[1] = [22, 8, 34, 26, 4, 15, 20, 21, 10]; | ||
prefectureRatio[2] = [9, 33, 7, 24, 43, 46, 47, 25, 35]; | ||
prefectureRatio[3] = [29, 38, 42, 2, 3, 17, 44, 45, 6, 16]; | ||
prefectureRatio[4] = [37, 5, 30, 19, 41, 18, 36, 39, 32, 31]; | ||
|
||
for (uint256 i = 0; i < ratioRank.length; i++) { | ||
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. ご指摘通りです、、、 |
||
acumurationRatioRankTotal += ratioRank[i]; | ||
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. memo 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. uint256[5] acumulationRatioRank = [5, 9, 12, 15, 17]; 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. sumは使えません。擬似コードです(メモ用) |
||
acumurationRatioRank[i] = acumurationRatioRankTotal; | ||
} | ||
} | ||
|
||
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { | ||
|
@@ -166,16 +184,45 @@ contract LocalNounsProvider is IAssetProviderExMint, IERC165, Ownable { | |
); | ||
} | ||
|
||
function mint(uint256 prefectureId, uint256 _assetId) external returns (uint256) { | ||
bool randomValueForTest = false; | ||
|
||
function setRandomValueForTest(bool _test) public onlyOwner { | ||
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. ここの変更はオーナーしかできないですが、オーナーが変更してtrueのときには、誰でもdeterminePrefectureIdでassetIdを指定できます。 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. hardhatテストでだけ使用するようにします |
||
randomValueForTest = _test; | ||
} | ||
|
||
// テスト用にpublic | ||
function determinePrefectureId(uint256 _assetId) public view returns (uint256) { | ||
uint256 randomValue; | ||
if (randomValueForTest) { | ||
// For TEST | ||
randomValue = _assetId; | ||
} else { | ||
// ブロック番号とアセット番号から計算した値 -> ランダム値 | ||
randomValue = uint256(keccak256(abi.encodePacked(block.timestamp, _assetId))); | ||
} | ||
|
||
uint256 rank = randomValue % acumurationRatioRankTotal; | ||
for (uint256 i = 0; i < acumurationRatioRank.length; i++) { | ||
if (rank < acumurationRatioRank[i]) { | ||
rank = i; | ||
break; | ||
} | ||
} | ||
return prefectureRatio[rank][randomValue % prefectureRatio[rank].length]; | ||
} | ||
|
||
function mint(uint256 _prefectureId, uint256 _assetId) external returns (uint256) { | ||
uint256 prefectureId; | ||
// 末尾2桁が00の場合は都道府県をランダムに決定する | ||
if (prefectureId % 100 == 0) { | ||
prefectureId = prefectureId + ((block.number * _assetId) % 46) + 1; | ||
if (_prefectureId % 100 == 0) { | ||
prefectureId = _prefectureId + determinePrefectureId(_assetId); | ||
} else { | ||
prefectureId = _prefectureId; | ||
} | ||
|
||
seeds[_assetId] = generateSeed(prefectureId, _assetId); | ||
uint256 prefectureId = prefectureId % 100; // 下2桁:都道府県番号、下3桁より上位:バージョン番号 | ||
tokenIdToPrefectureId[_assetId] = prefectureId; | ||
mintNumberPerPrefecture[prefectureId]++; | ||
tokenIdToPrefectureId[_assetId] = prefectureId % 100; | ||
mintNumberPerPrefecture[prefectureId % 100]++; | ||
nextTokenId++; | ||
|
||
return _assetId; | ||
|
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.
acumuration -> accumulation
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.
修正しました
4b6a322
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.
cも2つ必要です。
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.
accumulation
です。