Skip to content

Commit

Permalink
feat: Create BlastQuestFactory to configure operator
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathandiep committed May 1, 2024
1 parent d0e7c24 commit eff2ea9
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 0 deletions.
16 changes: 16 additions & 0 deletions contracts/BlastQuestFactory.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.19;

import {QuestFactory} from "./QuestFactory.sol";

interface IBlastPoints {
function configurePointsOperator(address operator) external;
function configurePointsOperatorOnBehalf(address contractAddress, address operator) external;
}

contract BlastQuestFactory is QuestFactory {
function configurePointsOperator(address operatorAddress) external onlyOwner {
address BlastPointsAddress = 0x2536FE9ab3F511540F2f9e2eC2A805005C3Dd800; // BlastPoints Mainnet address
IBlastPoints(BlastPointsAddress).configurePointsOperator(operatorAddress);
}
}
18 changes: 18 additions & 0 deletions script/QuestFactory.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {Script} from "forge-std/Script.sol";
import {Quest} from "../contracts/Quest.sol";
import {Quest1155} from "../contracts/Quest1155.sol";
import {QuestFactory} from "../contracts/QuestFactory.sol";
import {BlastQuestFactory} from "../contracts/BlastQuestFactory.sol";
import {QuestContractConstants as C} from "../contracts/libraries/QuestContractConstants.sol";
import {ProxyAdmin, ITransparentUpgradeableProxy} from "openzeppelin-contracts/proxy/transparent/ProxyAdmin.sol";

Expand All @@ -25,6 +26,23 @@ contract QuestFactoryUpgrade is Script {
}
}

// To upgrade QuestFactory.sol on Blast, run this command below
// ! important: make sure storage layouts are compatible first:
// forge clean && forge build && npx @openzeppelin/upgrades-core validate --contract QuestFactory
// forge script script/QuestFactory.s.sol:BlastQuestFactoryUpgrade --rpc-url blast --broadcast --verify -vvvv
contract BlastQuestFactoryUpgrade is Script {
function run() external {
uint256 deployerPrivateKey = vm.envUint("MAINNET_PRIVATE_KEY");
ITransparentUpgradeableProxy questfactoryProxy = ITransparentUpgradeableProxy(C.QUEST_FACTORY_ADDRESS);

vm.startBroadcast(deployerPrivateKey);

ProxyAdmin(C.PROXY_ADMIN_ADDRESS).upgrade(questfactoryProxy, address(new BlastQuestFactory()));

vm.stopBroadcast();
}
}

contract QuestFactoryDeploy is Script {
function run() external {
uint256 deployerPrivateKey = vm.envUint("MAINNET_PRIVATE_KEY");
Expand Down
70 changes: 70 additions & 0 deletions test/BlastQuestFactory.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// SPDX-License-Identifier: Unlicense
pragma solidity 0.8.19;

// solhint-disable no-global-import, no-console
import "forge-std/Test.sol";
import "forge-std/console.sol";

import {BlastQuestFactory} from "contracts/BlastQuestFactory.sol";
import {QuestFactory} from "contracts/QuestFactory.sol";
import {IQuestFactory} from "contracts/interfaces/IQuestFactory.sol";
import {Quest} from "contracts/Quest.sol";
import {Quest1155} from "contracts/Quest1155.sol";
import {LibClone} from "solady/utils/LibClone.sol";
import {LibString} from "solady/utils/LibString.sol";
import {ECDSA} from "openzeppelin-contracts/utils/cryptography/ECDSA.sol";
import {LibZip} from "solady/utils/LibZip.sol";
import {JSONParserLib} from "solady/utils/JSONParserLib.sol";
import {Errors} from "./helpers/Errors.sol";
import {Events} from "./helpers/Events.sol";
import {TestUtils} from "./helpers/TestUtils.sol";
import {QuestContractConstants as C} from "../contracts/libraries/QuestContractConstants.sol";
import {ProxyAdmin, ITransparentUpgradeableProxy} from "openzeppelin-contracts/proxy/transparent/ProxyAdmin.sol";

interface IBlastPoints {
function configurePointsOperator(address operator) external;
function configurePointsOperatorOnBehalf(address contractAddress, address operator) external;
function operators(address operator) external returns (address);
}

// forge test --fork-url https://rpc.blast.io --match-path test/BlastQuestFactory.t.sol
contract TestQuestFactory is Test, Errors, Events, TestUtils {
using LibClone for address;
using LibString for address;
using LibString for string;
using JSONParserLib for string;
using LibString for uint256;

QuestFactory questFactory;
BlastQuestFactory blastQuestFactory;
address owner;
address random = makeAddr("random");
address blastPointsAddress = 0x2536FE9ab3F511540F2f9e2eC2A805005C3Dd800; // BlastPoints Mainnet address

function setUp() public {
questFactory = QuestFactory(C.QUEST_FACTORY_ADDRESS);
owner = questFactory.owner();

vm.startPrank(owner);
// upgrade QuestFactory to BlastQuestFactory
ITransparentUpgradeableProxy questfactoryProxy = ITransparentUpgradeableProxy(C.QUEST_FACTORY_ADDRESS);
ProxyAdmin(C.PROXY_ADMIN_ADDRESS).upgrade(questfactoryProxy, address(new BlastQuestFactory()));
blastQuestFactory = BlastQuestFactory(C.QUEST_FACTORY_ADDRESS);
vm.stopPrank();
}

function test_configurePointsOperator() public {
vm.deal(random, 1 ether);

vm.prank(random);
vm.expectRevert();
blastQuestFactory.configurePointsOperator(random);

vm.prank(owner);
blastQuestFactory.configurePointsOperator(owner);

address operatorAddress = IBlastPoints(blastPointsAddress).operators(C.QUEST_FACTORY_ADDRESS);
assertEq(operatorAddress, owner);
}

}

0 comments on commit eff2ea9

Please sign in to comment.