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

feat(nfts): taikoons upgradeable v2 #17580

Merged
merged 11 commits into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
Changes from 7 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
4 changes: 2 additions & 2 deletions .github/workflows/nfts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ jobs:
- name: Install pnpm dependencies
uses: ./.github/actions/install-pnpm-dependencies

- name: Check formatting
- name: Format solidity && update contract layout table
working-directory: ./packages/nfts
run: forge fmt --check
run: pnpm layout && forge fmt

- name: Solidity compilation
working-directory: ./packages/nfts
Expand Down
56 changes: 56 additions & 0 deletions packages/nfts/contract_layout.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
## MerkleWhitelist

| Name | Type | Slot | Offset | Bytes | Contract |
| --------- | -------------------------- | ---- | ------ | ----- | ------------------------------------------------------ |
| root | bytes32 | 0 | 0 | 32 | contracts/snaefell/MerkleWhitelist.sol:MerkleWhitelist |
| minted | mapping(bytes32 => bool) | 1 | 0 | 32 | contracts/snaefell/MerkleWhitelist.sol:MerkleWhitelist |
| blacklist | contract IMinimalBlacklist | 2 | 0 | 20 | contracts/snaefell/MerkleWhitelist.sol:MerkleWhitelist |
| \_\_gap | uint256[48] | 3 | 0 | 1536 | contracts/snaefell/MerkleWhitelist.sol:MerkleWhitelist |

## TaikoonToken

| Name | Type | Slot | Offset | Bytes | Contract |
| ----------------- | -------------------------- | ---- | ------ | ----- | ----------------------------------------------- |
| root | bytes32 | 0 | 0 | 32 | contracts/taikoon/TaikoonToken.sol:TaikoonToken |
| minted | mapping(bytes32 => bool) | 1 | 0 | 32 | contracts/taikoon/TaikoonToken.sol:TaikoonToken |
| blacklist | contract IMinimalBlacklist | 2 | 0 | 20 | contracts/taikoon/TaikoonToken.sol:TaikoonToken |
| \_\_gap | uint256[47] | 3 | 0 | 1504 | contracts/taikoon/TaikoonToken.sol:TaikoonToken |
| \_totalSupply | uint256 | 50 | 0 | 32 | contracts/taikoon/TaikoonToken.sol:TaikoonToken |
| \_baseURIExtended | string | 51 | 0 | 32 | contracts/taikoon/TaikoonToken.sol:TaikoonToken |
| \_\_gap | uint256[47] | 52 | 0 | 1504 | contracts/taikoon/TaikoonToken.sol:TaikoonToken |

## SnaefellToken

| Name | Type | Slot | Offset | Bytes | Contract |
| ----------------- | -------------------------- | ---- | ------ | ----- | -------------------------------------------------- |
| root | bytes32 | 0 | 0 | 32 | contracts/snaefell/SnaefellToken.sol:SnaefellToken |
| minted | mapping(bytes32 => bool) | 1 | 0 | 32 | contracts/snaefell/SnaefellToken.sol:SnaefellToken |
| blacklist | contract IMinimalBlacklist | 2 | 0 | 20 | contracts/snaefell/SnaefellToken.sol:SnaefellToken |
| \_\_gap | uint256[48] | 3 | 0 | 1536 | contracts/snaefell/SnaefellToken.sol:SnaefellToken |
| \_totalSupply | uint256 | 51 | 0 | 32 | contracts/snaefell/SnaefellToken.sol:SnaefellToken |
| \_baseURIExtended | string | 52 | 0 | 32 | contracts/snaefell/SnaefellToken.sol:SnaefellToken |
| \_\_gap | uint256[48] | 53 | 0 | 1536 | contracts/snaefell/SnaefellToken.sol:SnaefellToken |

## ECDSAWhitelist

| Name | Type | Slot | Offset | Bytes | Contract |
| ---------- | -------------------------- | ---- | ------ | ----- | --------------------------------------------------------------- |
| mintSigner | address | 0 | 0 | 20 | contracts/trailblazers-badges/ECDSAWhitelist.sol:ECDSAWhitelist |
| minted | mapping(bytes32 => bool) | 1 | 0 | 32 | contracts/trailblazers-badges/ECDSAWhitelist.sol:ECDSAWhitelist |
| blacklist | contract IMinimalBlacklist | 2 | 0 | 20 | contracts/trailblazers-badges/ECDSAWhitelist.sol:ECDSAWhitelist |
| \_\_gap | uint256[47] | 3 | 0 | 1504 | contracts/trailblazers-badges/ECDSAWhitelist.sol:ECDSAWhitelist |

## TrailblazersBadges

| Name | Type | Slot | Offset | Bytes | Contract |
| ----------------- | ----------------------------------------------- | ---- | ------ | ----- | ----------------------------------------------------------------------- |
| mintSigner | address | 0 | 0 | 20 | contracts/trailblazers-badges/TrailblazersBadges.sol:TrailblazersBadges |
| minted | mapping(bytes32 => bool) | 1 | 0 | 32 | contracts/trailblazers-badges/TrailblazersBadges.sol:TrailblazersBadges |
| blacklist | contract IMinimalBlacklist | 2 | 0 | 20 | contracts/trailblazers-badges/TrailblazersBadges.sol:TrailblazersBadges |
| \_\_gap | uint256[47] | 3 | 0 | 1504 | contracts/trailblazers-badges/TrailblazersBadges.sol:TrailblazersBadges |
| \_baseURIExtended | string | 50 | 0 | 32 | contracts/trailblazers-badges/TrailblazersBadges.sol:TrailblazersBadges |
| badges | mapping(uint256 => uint256) | 51 | 0 | 32 | contracts/trailblazers-badges/TrailblazersBadges.sol:TrailblazersBadges |
| movements | mapping(address => uint256) | 52 | 0 | 32 | contracts/trailblazers-badges/TrailblazersBadges.sol:TrailblazersBadges |
| userBadges | mapping(address => mapping(uint256 => uint256)) | 53 | 0 | 32 | contracts/trailblazers-badges/TrailblazersBadges.sol:TrailblazersBadges |
| movementBadges | mapping(bytes32 => uint256[2]) | 54 | 0 | 32 | contracts/trailblazers-badges/TrailblazersBadges.sol:TrailblazersBadges |
| \_\_gap | uint256[43] | 55 | 0 | 1376 | contracts/trailblazers-badges/TrailblazersBadges.sol:TrailblazersBadges |
21 changes: 21 additions & 0 deletions packages/nfts/contracts/taikoon/TaikoonToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,25 @@ contract TaikoonToken is ERC721EnumerableUpgradeable, MerkleWhitelist {
_mint(_to, tokenIds[i]);
}
}

/// @dev V2 code additions

/// @notice Contract initializer
/// @param _rootURI Base URI for the token metadata
function initializeV2(string memory _rootURI) external {
bearni95 marked this conversation as resolved.
Show resolved Hide resolved
_baseURIExtended = _rootURI;
}

/// @notice Update the base URI
/// @param _rootURI The new base URI
/// @dev Only the owner can update the base URI
function updateBaseURI(string memory _rootURI) public onlyOwner {
bearni95 marked this conversation as resolved.
Show resolved Hide resolved
_baseURIExtended = _rootURI;
}

/// @notice Get the base URI
/// @return The base URI
function baseURI() public view returns (string memory) {
return _baseURIExtended;
}
}
25 changes: 25 additions & 0 deletions packages/nfts/deployments/gen-layouts.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash

# Define the list of contracts to inspect
contracts=(
"MerkleWhitelist"
"TaikoonToken"
"SnaefellToken"
"ECDSAWhitelist"
"TrailblazersBadges"
)

# Empty the output file initially
output_file="contract_layout.md"
> $output_file

# Loop over each contract
for contract in "${contracts[@]}"; do
# Run forge inspect and append to the file
# Ensure correct concatenation of the command without commas
echo "forge inspect ${contract} storagelayout --pretty >> $output_file"

echo "## ${contract}" >> $output_file
forge inspect ${contract} storagelayout --pretty >> $output_file
echo "" >> $output_file
done
1 change: 1 addition & 0 deletions packages/nfts/foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ remappings = [
"murky/=node_modules/murky/src/",
"solidity-stringutils/=node_modules/solidity-stringutils/",
"@taiko/blacklist/=node_modules/@taiko/supplementary-contracts/contracts/blacklist/",
"openzeppelin-foundry-upgrades/=node_modules/openzeppelin-foundry-upgrades/src/",
]

# Do not change the block_gas_limit value, TaikoL2.t.sol depends on it.
Expand Down
5 changes: 3 additions & 2 deletions packages/nfts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"lint:sol": "forge fmt && pnpm solhint 'contracts/**/*.sol'",
"test": "pnpm clean && pnpm compile && forge test --match-path 'test/*.t.sol' -vvv",
"node": "anvil",
"layout": "./deployments/gen-layouts.sh",
"taikoon:merkle": "node script/taikoon/js/generate-merkle-tree.js",
"snaefell:merkle": "node script/snaefell/js/generate-merkle-tree.js",
"taikoon:deploy:localhost": "forge clean && pnpm compile && forge script script/taikoon/sol/Deploy.s.sol --rpc-url http://localhost:8545 --broadcast",
Expand Down Expand Up @@ -47,6 +48,7 @@
"@openzeppelin/contracts": "5.0.2",
"@openzeppelin/contracts-upgradeable": "5.0.2",
"@openzeppelin/merkle-tree": "^1.0.6",
"@taiko/supplementary-contracts": "workspace:*",
"convert-csv-to-json": "^2.46.0",
"dotenv": "^16.4.5",
"ds-test": "github:dapphub/ds-test#e282159d5170298eb2455a6c05280ab5a73a4ef0",
Expand All @@ -57,7 +59,6 @@
"p256-verifier": "github:taikoxyz/p256-verifier#v0.1.0",
"sharp": "^0.33.3",
"solady": "github:Vectorized/solady#v0.0.167",
"solidity-stringutils": "github:Arachnid/solidity-stringutils",
"@taiko/supplementary-contracts": "workspace:*"
"solidity-stringutils": "github:Arachnid/solidity-stringutils"
}
}
61 changes: 45 additions & 16 deletions packages/nfts/test/taikoon/Upgradeable.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ import "forge-std/src/StdJson.sol";
import { UtilsScript } from "../../script/taikoon/sol/Utils.s.sol";
import { MockBlacklist } from "../util/Blacklist.sol";

import "@openzeppelin/contracts/proxy/transparent/ProxyAdmin.sol";
import { ITransparentUpgradeableProxy } from
"@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol";
import "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol";
import { ERC1967Proxy } from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol";

contract UpgradeableTest is Test {
Expand All @@ -16,6 +20,7 @@ contract UpgradeableTest is Test {
UtilsScript public utils;

TaikoonToken public token;
TaikoonToken public tokenV2;

address public owner = vm.addr(0x5);

Expand All @@ -34,26 +39,50 @@ contract UpgradeableTest is Test {
blacklist = new MockBlacklist();

// create whitelist merkle tree
vm.startPrank(owner);
vm.startBroadcast(owner);
bytes32 root = tree.getRoot(leaves);

// deploy token with empty root
address impl = address(new TaikoonToken());
address proxy = address(
new ERC1967Proxy(
impl,
abi.encodeCall(TaikoonToken.initialize, (address(0), "ipfs://", root, blacklist))
)
token = new TaikoonToken();
address impl = address(token);

ERC1967Proxy proxy = new ERC1967Proxy(
impl, abi.encodeCall(TaikoonToken.initialize, (owner, "ipfs://", root, blacklist))
);
token = TaikoonToken(address(proxy));

// mint tokens on the v1 deployment
token.mint(minters[0], 5);

// upgrade to v2

token.upgradeToAndCall(
address(new TaikoonToken()), abi.encodeCall(TaikoonToken.initializeV2, ("ipfs://v2//"))
);

tokenV2 = TaikoonToken(address(proxy));

vm.stopBroadcast();
}

function test_upgraded_v2() public view {
assertEq(tokenV2.name(), token.name());
assertEq(tokenV2.symbol(), token.symbol());
assertEq(tokenV2.totalSupply(), token.totalSupply());
assertEq(tokenV2.maxSupply(), token.maxSupply());
}

function test_tokenURI() public view {
assertEq(tokenV2.baseURI(), "ipfs://v2//");
string memory uri = tokenV2.tokenURI(0);
assertEq(uri, "ipfs://v2///0.json");
}

function test_updateBaseURI() public {
vm.startBroadcast(owner);
tokenV2.updateBaseURI("ipfs://test//");
vm.stopBroadcast();

token = TaikoonToken(proxy);
// use the token to calculate leaves
for (uint256 i = 0; i < minters.length; i++) {
leaves[i] = token.leaf(minters[i], FREE_MINTS);
}
// update the root
root = tree.getRoot(leaves);
token.updateRoot(root);
vm.stopPrank();
assertEq(tokenV2.baseURI(), "ipfs://test//");
}
}
Loading