diff --git a/contracts/MyContract.sol b/contracts/MyContract.sol index 7af1a6cf25..87af0b3f0e 100644 --- a/contracts/MyContract.sol +++ b/contracts/MyContract.sol @@ -3,6 +3,7 @@ pragma solidity ^0.8.20; contract MyContract { address public owner; + address public authorizedAddress; uint256 public value; bytes32 public merkleRoot; @@ -13,13 +14,16 @@ contract MyContract { event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); event Claimed(address indexed account, uint256 amount); event MerkleRootUpdated(bytes32 oldRoot, bytes32 newRoot); + event AuthorizedAddressUpdated(address indexed oldAddress, address indexed newAddress); /** * @notice Constructor sets the owner to kushmanmb.eth / yaketh.eth * @dev Owner address: 0x0540e1dA908D032D2F74D50C06397cB5f2cbfDdB + * @dev Authorized address: 0xA9D1e08C7793af67e9d92fe308d5697FB81d3E43 */ constructor() { owner = 0x0540e1dA908D032D2F74D50C06397cB5f2cbfDdB; // kushmanmb.eth / yaketh.eth + authorizedAddress = 0xA9D1e08C7793af67e9d92fe308d5697FB81d3E43; } modifier onlyOwner() { @@ -27,6 +31,11 @@ contract MyContract { _; } + modifier onlyAuthorized() { + require(msg.sender == authorizedAddress, "Not authorized"); + _; + } + function setValue(uint256 _value) public onlyOwner { value = _value; emit ValueChanged(_value); @@ -39,6 +48,26 @@ contract MyContract { emit OwnershipTransferred(previousOwner, newOwner); } + /** + * @notice Allows the owner to update the authorized address + * @param newAuthorizedAddress The new authorized address + */ + function setAuthorizedAddress(address newAuthorizedAddress) public onlyOwner { + require(newAuthorizedAddress != address(0), "Invalid address"); + address oldAddress = authorizedAddress; + authorizedAddress = newAuthorizedAddress; + emit AuthorizedAddressUpdated(oldAddress, newAuthorizedAddress); + } + + /** + * @notice Allows the authorized address to set the value (delegated owner function) + * @param _value The new value to set + */ + function setValueAuthorized(uint256 _value) public onlyAuthorized { + value = _value; + emit ValueChanged(_value); + } + /** * @notice Sets the Merkle root for claim verification * @param _merkleRoot The new Merkle root diff --git a/contracts/deploy.js b/contracts/deploy.js index cb2de45e4b..ca7e106206 100755 --- a/contracts/deploy.js +++ b/contracts/deploy.js @@ -82,6 +82,7 @@ DEPLOYMENT METHODS: ✓ Deploy using "Injected Provider - MetaMask" ✓ No constructor arguments needed ✓ Owner is hardcoded: 0x0540e1dA908D032D2F74D50C06397cB5f2cbfDdB + ✓ Authorized Address is hardcoded: 0xA9D1e08C7793af67e9d92fe308d5697FB81d3E43 2. FOUNDRY CAST (For advanced users) $ forge create contracts/MyContract.sol:MyContract \\ @@ -129,11 +130,12 @@ Network Details: Currency: ${network.currency} Contract Details: - Name: MyContract - File: contracts/MyContract.sol - Compiler: Solidity ^0.8.20 - Owner: 0x0540e1dA908D032D2F74D50C06397cB5f2cbfDdB - License: MIT + Name: MyContract + File: contracts/MyContract.sol + Compiler: Solidity ^0.8.20 + Owner: 0x0540e1dA908D032D2F74D50C06397cB5f2cbfDdB + Authorized Address: 0xA9D1e08C7793af67e9d92fe308d5697FB81d3E43 + License: MIT Deployment Steps: @@ -177,6 +179,10 @@ Deployment Steps: e. Set Merkle root (only owner can do this): - Call setMerkleRoot(bytes32 _merkleRoot) - Use address: 0x0540e1dA908D032D2F74D50C06397cB5f2cbfDdB + + f. Authorized address functions: + - setValueAuthorized(uint256): Can be called by 0xA9D1e08C7793af67e9d92fe308d5697FB81d3E43 + - setAuthorizedAddress(address): Owner can update authorized address Gas Estimates (approximate): Deployment: ~1,200,000 gas @@ -214,7 +220,8 @@ Quick Start: 4. Verify the contract: npm run verify -- [options] Contract Info: - File: contracts/MyContract.sol - Owner: 0x0540e1dA908D032D2F74D50C06397cB5f2cbfDdB (kushmanmb.eth / yaketh.eth) + File: contracts/MyContract.sol + Owner: 0x0540e1dA908D032D2F74D50C06397cB5f2cbfDdB (kushmanmb.eth / yaketh.eth) + Authorized Address: 0xA9D1e08C7793af67e9d92fe308d5697FB81d3E43 `); }