Skip to content

Commit

Permalink
feat(nfts): add galxe mapping contract and deploy script (#17563)
Browse files Browse the repository at this point in the history
  • Loading branch information
2manslkh authored Jun 25, 2024
1 parent 990085e commit 03f686c
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 3 deletions.
14 changes: 14 additions & 0 deletions packages/nfts/contracts/galxe/RegisterGalxePoints.sol
Original file line number Diff line number Diff line change
@@ -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);
}
}
5 changes: 2 additions & 3 deletions packages/nfts/foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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/",
Expand All @@ -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
Expand All @@ -53,4 +53,3 @@ line_length = 100
multiline_func_header = "all"
number_underscore = "thousands"
wrap_comments = true

1 change: 1 addition & 0 deletions packages/nfts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
25 changes: 25 additions & 0 deletions packages/nfts/script/galxe/Deploy.s.sol
Original file line number Diff line number Diff line change
@@ -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();
}
}
40 changes: 40 additions & 0 deletions packages/nfts/test/galxe/RegisterGalxePoints.t.sol
Original file line number Diff line number Diff line change
@@ -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();
}
}

0 comments on commit 03f686c

Please sign in to comment.