From 7669382991e6d1a6ee9a83648dd439be5d975c84 Mon Sep 17 00:00:00 2001 From: Charlie Andrews Date: Sun, 17 Jul 2022 17:06:26 -0700 Subject: [PATCH 1/4] added farm bot registry contract (just copied from Ubeswap farm registry contract so far) --- contracts/registry/FarmBotRegistry.sol | 50 ++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 contracts/registry/FarmBotRegistry.sol diff --git a/contracts/registry/FarmBotRegistry.sol b/contracts/registry/FarmBotRegistry.sol new file mode 100644 index 0000000..5a236ac --- /dev/null +++ b/contracts/registry/FarmBotRegistry.sol @@ -0,0 +1,50 @@ +// SPDX-License-Identifier: MIT + +pragma solidity ^0.8.3; + +import "../openzeppelin-solidity/contracts/Ownable.sol"; + + +interface ILP { + function token0() external view returns (address); + + function token1() external view returns (address); +} + +interface IFarm { + function stakingToken() external view returns (address); +} + +contract FarmBotRegistry is Ownable { + event FarmInfo( + address indexed stakingAddress, + bytes32 indexed farmName, + address indexed lpAddress + ); + event LPInfo( + address indexed lpAddress, + address indexed token0Address, + address indexed token1Address + ); + event FarmData( + address indexed stakingAddress, + uint256 indexed tvlUSD, + uint256 indexed rewardsUSDPerYear + ); + + constructor() {} + + function addFarmInfo(bytes32 farmName, IFarm farm) public onlyOwner { + ILP lp = ILP(farm.stakingToken()); + emit FarmInfo(address(farm), farmName, address(lp)); + emit LPInfo(address(lp), lp.token0(), lp.token1()); + } + + function updateFarmData( + address farm, + uint256 tvlUSD, + uint256 rewardsUSDPerYear + ) public onlyOwner { + emit FarmData(farm, tvlUSD, rewardsUSDPerYear); + } +} From 16925918f2a7116d0929398128ce32c725ee4570 Mon Sep 17 00:00:00 2001 From: Charlie Andrews Date: Sun, 17 Jul 2022 17:18:49 -0700 Subject: [PATCH 2/4] renamed stuff, upgraded access control --- contracts/registry/FarmBotRegistry.sol | 47 ++++++++++++++++++-------- 1 file changed, 33 insertions(+), 14 deletions(-) diff --git a/contracts/registry/FarmBotRegistry.sol b/contracts/registry/FarmBotRegistry.sol index 5a236ac..fe0b254 100644 --- a/contracts/registry/FarmBotRegistry.sol +++ b/contracts/registry/FarmBotRegistry.sol @@ -2,7 +2,7 @@ pragma solidity ^0.8.3; -import "../openzeppelin-solidity/contracts/Ownable.sol"; +import "../openzeppelin-solidity/contracts/AccessControl.sol"; interface ILP { @@ -11,32 +11,51 @@ interface ILP { function token1() external view returns (address); } -interface IFarm { +interface IFarmBot { function stakingToken() external view returns (address); } -contract FarmBotRegistry is Ownable { - event FarmInfo( - address indexed stakingAddress, +contract FarmBotRegistry is AccessControl { + event FarmBotInfo( + address indexed farmBotAddress, bytes32 indexed farmName, - address indexed lpAddress + address indexed lpAddress, + bool indexed isMetaFarm ); event LPInfo( address indexed lpAddress, address indexed token0Address, address indexed token1Address ); - event FarmData( - address indexed stakingAddress, + event FarmBotData( + address indexed farmBotAddress, uint256 indexed tvlUSD, uint256 indexed rewardsUSDPerYear ); + event GrantRole( + address indexed by, + address indexed newRoleRecipient, + bytes32 role + ); - constructor() {} + function grantRole(bytes32 role, address account) + public + virtual + override + onlyRole(getRoleAdmin(role)) + { + super.grantRole(role, account); + emit GrantRole(msg.sender, account, role); + } + + constructor(address _owner) { + _setupRole(DEFAULT_ADMIN_ROLE, _owner); + emit GrantRole(msg.sender, _owner, DEFAULT_ADMIN_ROLE); + } - function addFarmInfo(bytes32 farmName, IFarm farm) public onlyOwner { - ILP lp = ILP(farm.stakingToken()); - emit FarmInfo(address(farm), farmName, address(lp)); + function addFarmInfo(bytes32 farmName, IFarmBot farmBot, bool isMetaFarm) public onlyRole(DEFAULT_ADMIN_ROLE) { + ILP lp = ILP(farmBot.stakingToken()); + emit FarmBotInfo(address(farmBot), farmName, address(lp), isMetaFarm); emit LPInfo(address(lp), lp.token0(), lp.token1()); } @@ -44,7 +63,7 @@ contract FarmBotRegistry is Ownable { address farm, uint256 tvlUSD, uint256 rewardsUSDPerYear - ) public onlyOwner { - emit FarmData(farm, tvlUSD, rewardsUSDPerYear); + ) public onlyRole(DEFAULT_ADMIN_ROLE) { + emit FarmBotData(farm, tvlUSD, rewardsUSDPerYear); } } From f86c5e128bb073ebf6315691b5400855979a22c0 Mon Sep 17 00:00:00 2001 From: Charlie Andrews Date: Sun, 17 Jul 2022 21:04:19 -0700 Subject: [PATCH 3/4] added operator role --- contracts/registry/FarmBotRegistry.sol | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/contracts/registry/FarmBotRegistry.sol b/contracts/registry/FarmBotRegistry.sol index fe0b254..6955fb5 100644 --- a/contracts/registry/FarmBotRegistry.sol +++ b/contracts/registry/FarmBotRegistry.sol @@ -16,6 +16,8 @@ interface IFarmBot { } contract FarmBotRegistry is AccessControl { + bytes32 public constant OPERATOR_ROLE = keccak256("OPERATOR_ROLE"); + event FarmBotInfo( address indexed farmBotAddress, bytes32 indexed farmName, @@ -53,7 +55,7 @@ contract FarmBotRegistry is AccessControl { emit GrantRole(msg.sender, _owner, DEFAULT_ADMIN_ROLE); } - function addFarmInfo(bytes32 farmName, IFarmBot farmBot, bool isMetaFarm) public onlyRole(DEFAULT_ADMIN_ROLE) { + function addFarmInfo(bytes32 farmName, IFarmBot farmBot, bool isMetaFarm) public onlyRole(OPERATOR_ROLE) { ILP lp = ILP(farmBot.stakingToken()); emit FarmBotInfo(address(farmBot), farmName, address(lp), isMetaFarm); emit LPInfo(address(lp), lp.token0(), lp.token1()); @@ -63,7 +65,7 @@ contract FarmBotRegistry is AccessControl { address farm, uint256 tvlUSD, uint256 rewardsUSDPerYear - ) public onlyRole(DEFAULT_ADMIN_ROLE) { + ) public onlyRole(OPERATOR_ROLE) { emit FarmBotData(farm, tvlUSD, rewardsUSDPerYear); } } From 9d8f358ce7c0a94a977ec52e0347c13437c004b0 Mon Sep 17 00:00:00 2001 From: Charlie Andrews Date: Sun, 17 Jul 2022 21:04:44 -0700 Subject: [PATCH 4/4] pragma 0.8.4 --- contracts/registry/FarmBotRegistry.sol | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/contracts/registry/FarmBotRegistry.sol b/contracts/registry/FarmBotRegistry.sol index 6955fb5..68c6d72 100644 --- a/contracts/registry/FarmBotRegistry.sol +++ b/contracts/registry/FarmBotRegistry.sol @@ -1,6 +1,5 @@ // SPDX-License-Identifier: MIT - -pragma solidity ^0.8.3; +pragma solidity 0.8.4; import "../openzeppelin-solidity/contracts/AccessControl.sol";