From 03f686c931e66e579b96650dca1158043d8669e7 Mon Sep 17 00:00:00 2001 From: Kenk Date: Tue, 25 Jun 2024 11:35:06 +0800 Subject: [PATCH] feat(nfts): add galxe mapping contract and deploy script (#17563) --- .../contracts/galxe/RegisterGalxePoints.sol | 14 +++++++ packages/nfts/foundry.toml | 5 +-- packages/nfts/package.json | 1 + packages/nfts/script/galxe/Deploy.s.sol | 25 ++++++++++++ .../nfts/test/galxe/RegisterGalxePoints.t.sol | 40 +++++++++++++++++++ 5 files changed, 82 insertions(+), 3 deletions(-) create mode 100644 packages/nfts/contracts/galxe/RegisterGalxePoints.sol create mode 100644 packages/nfts/script/galxe/Deploy.s.sol create mode 100644 packages/nfts/test/galxe/RegisterGalxePoints.t.sol diff --git a/packages/nfts/contracts/galxe/RegisterGalxePoints.sol b/packages/nfts/contracts/galxe/RegisterGalxePoints.sol new file mode 100644 index 00000000000..c303158754a --- /dev/null +++ b/packages/nfts/contracts/galxe/RegisterGalxePoints.sol @@ -0,0 +1,14 @@ +// SPDX-License-Identifier: MIT +pragma solidity 0.8.24; + +contract RegisterGalxePoints { + mapping(address => bool) public alreadyRegistered; + + event Registered(address registrant); + + function register() public { + require(!alreadyRegistered[msg.sender], "Address already registered"); + alreadyRegistered[msg.sender] = true; + emit Registered(msg.sender); + } +} diff --git a/packages/nfts/foundry.toml b/packages/nfts/foundry.toml index 49cf0e8ab15..ca822e9ad28 100644 --- a/packages/nfts/foundry.toml +++ b/packages/nfts/foundry.toml @@ -11,7 +11,7 @@ ffi = true memory_limit = 2_073_741_824 solc_version = "0.8.24" evm_version = "cancun" -ast=true +ast = true remappings = [ "@openzeppelin/contracts-upgradeable/=node_modules/@openzeppelin/contracts-upgradeable/", "@openzeppelin/contracts/=node_modules/@openzeppelin/contracts/", @@ -35,7 +35,7 @@ fs_permissions = [ { access = "read-write", path = "./deployments/" }, { access = "read", path = "./test" }, { access = "read", path = "./genesis" }, - {access = "read", path="./data/"}, + { access = "read", path = "./data/" }, ] # 2394: Transient storage warning @@ -53,4 +53,3 @@ line_length = 100 multiline_func_header = "all" number_underscore = "thousands" wrap_comments = true - diff --git a/packages/nfts/package.json b/packages/nfts/package.json index 1c172cd0593..44cf5533955 100644 --- a/packages/nfts/package.json +++ b/packages/nfts/package.json @@ -24,6 +24,7 @@ "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:hekla": "forge clean && pnpm compile && forge script script/trailblazers-badges/sol/Deploy.s.sol --rpc-url https://rpc.hekla.taiko.xyz --broadcast --gas-estimate-multiplier 200", + "galxe:deploy:mainnet": "forge clean && pnpm compile && forge script script/galxe/Deploy.s.sol --rpc-url https://rpc.mainnet.taiko.xyz --legacy --with-gas-price 1", "tbzb:deploy:mainnet": "forge clean && pnpm compile && forge script script/trailblazers-badges/sol/Deploy.s.sol --rpc-url https://rpc.mainnet.taiko.xyz --broadcast --legacy --with-gas-price 13 ", "taikoon:deploy:v2": "forge clean && pnpm compile && forge script script/taikoon/sol/UpgradeV2.sol --rpc-url https://rpc.mainnet.taiko.xyz --broadcast" }, diff --git a/packages/nfts/script/galxe/Deploy.s.sol b/packages/nfts/script/galxe/Deploy.s.sol new file mode 100644 index 00000000000..7517fb18744 --- /dev/null +++ b/packages/nfts/script/galxe/Deploy.s.sol @@ -0,0 +1,25 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.0; + +import { Script, console } from "forge-std/src/Script.sol"; +import { RegisterGalxePoints } from "../../contracts/galxe/RegisterGalxePoints.sol"; + +contract DeployRegisterMyGalaxyPointScript is Script { + function run() public { + uint256 deployerPrivateKey = vm.envUint("MAINNET_PRIVATE_KEY"); + address deployerAddress = vm.addr(deployerPrivateKey); + + vm.startBroadcast(deployerPrivateKey); + + RegisterGalxePoints registerGalxePoints = new RegisterGalxePoints(); + + console.log( + "Deployed RegisterGalxePoints to:", + address(registerGalxePoints), + "from", + deployerAddress + ); + + vm.stopBroadcast(); + } +} diff --git a/packages/nfts/test/galxe/RegisterGalxePoints.t.sol b/packages/nfts/test/galxe/RegisterGalxePoints.t.sol new file mode 100644 index 00000000000..fa4539035f7 --- /dev/null +++ b/packages/nfts/test/galxe/RegisterGalxePoints.t.sol @@ -0,0 +1,40 @@ +// SPDX-License-Identifier: MIT +pragma solidity 0.8.24; + +import { Test } from "forge-std/src/Test.sol"; + +import { RegisterGalxePoints } from "../../contracts/galxe/RegisterGalxePoints.sol"; + +contract RegisterGalxePointsTest is Test { + RegisterGalxePoints public registerGalxePoints; + + address public owner = vm.addr(0x1); + + function setUp() public { + // create whitelist merkle tree + vm.startBroadcast(owner); + + registerGalxePoints = new RegisterGalxePoints(); + + vm.stopBroadcast(); + } + // Test register function on RegisterGalxePoints also test for Registered event emitted + + function testRegister() public { + vm.startPrank(owner); + vm.expectEmit(true, false, false, true); + emit RegisterGalxePoints.Registered(owner); + registerGalxePoints.register(); + + vm.stopPrank(); + } + + // Test case to check if already registered user is not allowed to register again + function testCannotRegisterTwice() public { + vm.startPrank(owner); + registerGalxePoints.register(); + vm.expectRevert("Address already registered"); + registerGalxePoints.register(); + vm.stopPrank(); + } +}