Skip to content

Commit

Permalink
balance of batch
Browse files Browse the repository at this point in the history
  • Loading branch information
bearni95 committed Jun 10, 2024
1 parent 811af2b commit e120976
Show file tree
Hide file tree
Showing 8 changed files with 111 additions and 428 deletions.

This file was deleted.

99 changes: 61 additions & 38 deletions packages/nfts/contracts/trailblazers-badges/TrailblazersBadges.sol
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;

import { ERC1155Upgradeable } from
"@openzeppelin/contracts-upgradeable/token/ERC1155/ERC1155Upgradeable.sol";
import { ERC721EnumerableUpgradeable } from
"@openzeppelin/contracts-upgradeable/token/ERC721/extensions/ERC721EnumerableUpgradeable.sol";
import { ECDSAWhitelist } from "./ECDSAWhitelist.sol";
import { IMinimalBlacklist } from "@taiko/blacklist/IMinimalBlacklist.sol";
import { Strings } from "@openzeppelin/contracts/utils/Strings.sol";

contract TrailblazersBadges is ERC1155Upgradeable, ECDSAWhitelist {
contract TrailblazersBadges is ERC721EnumerableUpgradeable, ECDSAWhitelist {
/// @notice Base URI required to interact with IPFS
string private _baseURIExtended;
/// @notice Movement IDs
Expand All @@ -26,9 +26,14 @@ contract TrailblazersBadges is ERC1155Upgradeable, ECDSAWhitelist {
uint256 public constant BADGE_ANDROIDS = 6;
uint256 public constant BADGE_SHINTO = 7;

/// @notice Token ID to badge ID mapping
mapping(uint256 _tokenId => uint256 _badgeId) public badges;
/// @notice Wallet to badge ID, token ID mapping
mapping(address _user => mapping(uint256 _badgeId => uint256 _tokenId)) public userBadges;
/// @notice Movement to badge ID, token ID mapping
mapping(bytes32 movementBadgeHash => uint256[2] movementBadge) public movementBadges;

uint256[][] public tokenIds;
/// @notice Token count, used to generate tokenIds
uint256 public tokenCount;

/// @notice Gap for upgrade safety
uint256[48] private __gap;
Expand All @@ -38,7 +43,7 @@ contract TrailblazersBadges is ERC1155Upgradeable, ECDSAWhitelist {
error INVALID_BADGE_ID();
error INVALID_MOVEMENT_ID();

event BadgeCreated(uint256 _badgeId, string _badgeName);
event BadgeCreated(uint256 _tokenId, address _minter, uint256 _badgeId);
event MovementSet(address _user, uint256 _movementId);
event UriSet(string _uri);

Expand All @@ -56,19 +61,28 @@ contract TrailblazersBadges is ERC1155Upgradeable, ECDSAWhitelist {
external
initializer
{
__ERC1155_init(_rootURI);
__ERC721_init("TrailblazersBadges", "TBB");
_baseURIExtended = _rootURI;
__ECDSAWhitelist_init(_owner, _mintSigner, _blacklistAddress);

_initializeMovementBadges();
}

function _initializeMovementBadges() internal {
for (uint256 i = MOVEMENT_NEUTRAL; i < MOVEMENT_BOOSTED; i++) {
for (uint256 j = BADGE_RAVERS; j < BADGE_SHINTO; j++) {
tokenIds.push([i, j]);
}
}
/// @notice Ensure update of userBadges on transfers
/// @param to The address to transfer to
/// @param tokenId The token id to transfer
/// @param auth The authorizer of the transfer
function _update(
address to,
uint256 tokenId,
address auth
)
internal
virtual
override
returns (address)
{
// userBadges[_ownerOf(tokenId)][badges[tokenId]] = 0;
userBadges[to][badges[tokenId]] = tokenId;
return super._update(to, tokenId, auth);
}

/// @notice Update the base URI
Expand All @@ -78,19 +92,15 @@ contract TrailblazersBadges is ERC1155Upgradeable, ECDSAWhitelist {
emit UriSet(_uri);
}

/// @notice Get the URI for a badge
/// @notice Get the URI for a tokenId
/// @param _tokenId The badge ID
/// @return URI The URI for the badge
function uri(uint256 _tokenId) public view override returns (string memory) {
uint256[] memory tokenData = tokenIds[_tokenId];
function tokenURI(uint256 _tokenId) public view override returns (string memory) {
uint256 movementId = movements[ownerOf(_tokenId)];
uint256 badgeId = badges[_tokenId];
return string(
abi.encodePacked(
_baseURIExtended,
"/",
Strings.toString(tokenData[0]), // movement
"/",
Strings.toString(tokenData[1]), // badge
".json"
_baseURIExtended, "/", Strings.toString(movementId), "/", Strings.toString(badgeId)
)
);
}
Expand Down Expand Up @@ -118,13 +128,15 @@ contract TrailblazersBadges is ERC1155Upgradeable, ECDSAWhitelist {
function _mintBadgeTo(bytes memory _signature, address _minter, uint256 _badgeId) internal {
if (_badgeId > BADGE_SHINTO) revert INVALID_BADGE_ID();
if (!canMint(_signature, _minter, _badgeId)) revert MINTER_NOT_WHITELISTED();

_consumeMint(_signature, _minter, _badgeId);
_mint(
_minter,
_badgeId,
1, // amount
"" // empty data
);

badges[tokenCount] = _badgeId;

_mint(_minter, tokenCount);

emit BadgeCreated(tokenCount, _minter, _badgeId);
tokenCount++;
}

/// @notice Sets movement for the calling wallet
Expand All @@ -150,18 +162,29 @@ contract TrailblazersBadges is ERC1155Upgradeable, ECDSAWhitelist {
emit MovementSet(_user, _movementId);
}

function tokenId(
uint256 _badgeId,
uint256 _movementId
/// @notice Retrieve a token ID given their owner and Badge ID
/// @param _user The address of the badge owner
/// @param _badgeId The badge ID
/// @return tokenId The token ID
function getTokenId(address _user, uint256 _badgeId) public view returns (uint256) {
return userBadges[_user][_badgeId];
}

/// @notice Retrieve a batch of balances
/// @param _owners The addresses to check
/// @param _ids The badge IDs to check
function balanceOfBatch(
address[] memory _owners,
uint256[] memory _ids
)
public
view
returns (uint256 _tokenId)
returns (uint256[] memory)
{
for (uint256 i = 0; i < tokenIds.length; i++) {
if (tokenIds[i][0] == _movementId && tokenIds[i][1] == _badgeId) {
return i;
}
uint256[] memory balances = new uint256[](_owners.length);
for (uint256 i; i < _owners.length; i++) {
balances[i] = userBadges[_owners[i]][_ids[i]] == 0 ? 0 : 1;
}
return balances;
}
}
5 changes: 5 additions & 0 deletions packages/nfts/deployments/trailblazers-badges/hekla.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"MintSigner": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
"Owner": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
"TrailblazersBadges": "0xaFA5bE0e03287B77CE952f6C733b1b1036fa9FaF"
}
5 changes: 5 additions & 0 deletions packages/nfts/deployments/trailblazers-badges/mainnet.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"MintSigner": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
"Owner": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
"TrailblazersBadges": "0x5f350Ded5710F248832B88E5742A704E8D9a4C5e"
}
3 changes: 2 additions & 1 deletion packages/nfts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
"taikoon:deploy:mainnet": "forge clean && pnpm compile && forge script script/taikoon/sol/Deploy.s.sol --rpc-url https://rpc.mainnet.taiko.xyz --broadcast --legacy --with-gas-price 13 ",
"snaefell:deploy:mainnet": "forge clean && pnpm compile && forge script script/snaefell/sol/Deploy.s.sol --rpc-url https://rpc.mainnet.taiko.xyz --broadcast --legacy --with-gas-price 13 ",
"taikoon:deploy:holesky": "forge clean && pnpm compile && forge script script/taikoon/sol/Deploy.s.sol --rpc-url https://1rpc.io/holesky --broadcast --gas-estimate-multiplier 200",
"tbzb:deploy:localhost": "forge clean && pnpm compile && forge script script/trailblazers-badges/sol/Deploy.s.sol --rpc-url http://localhost:8545 --broadcast"
"tbzb:deploy:localhost": "forge clean && pnpm compile && forge script script/trailblazers-badges/sol/Deploy.s.sol --rpc-url http://localhost:8545 --broadcast",
"tbzb:deploy:hekla": "forge clean && pnpm compile && forge script script/trailblazers-badges/sol/Deploy.s.sol --rpc-url https://rpc.hekla.taiko.xyz --broadcast"
},
"devDependencies": {
"@types/node": "^20.11.30",
Expand Down
3 changes: 3 additions & 0 deletions packages/nfts/script/trailblazers-badges/sol/Utils.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ contract UtilsScript is Script {
} else if (chainId == 167_000) {
lowercaseNetworkKey = "mainnet";
uppercaseNetworkKey = "MAINNET";
} else if (chainId == 167_009) {
lowercaseNetworkKey = "hekla";
uppercaseNetworkKey = "HEKLA";
} else {
revert("Unsupported chainId");
}
Expand Down
Loading

0 comments on commit e120976

Please sign in to comment.