Skip to content

Commit

Permalink
feat: add admin init
Browse files Browse the repository at this point in the history
  • Loading branch information
thongxuan committed Jan 3, 2025
1 parent 33466d8 commit 6728199
Show file tree
Hide file tree
Showing 5 changed files with 141 additions and 7 deletions.
113 changes: 113 additions & 0 deletions .openzeppelin/base-sepolia.json
Original file line number Diff line number Diff line change
Expand Up @@ -2315,6 +2315,119 @@
},
"namespaces": {}
}
},
"b9fae0edd7a6a6e2cf11be93a49e48afbc82ac4e52c6892f4d200391978f5fc1": {
"address": "0x9e081e88513588376451f368fd0d8AfA7b91879A",
"txHash": "0xcc90d90ec1033d0d385c7b84fb0e61f920c428f3ce7c7cae8431aeb8a204de1e",
"layout": {
"solcVersion": "0.8.4",
"storage": [
{
"label": "_initialized",
"offset": 0,
"slot": "0",
"type": "t_uint8",
"contract": "Initializable",
"src": "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol:63",
"retypedFrom": "bool"
},
{
"label": "_initializing",
"offset": 1,
"slot": "0",
"type": "t_bool",
"contract": "Initializable",
"src": "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol:68"
},
{
"label": "__gap",
"offset": 0,
"slot": "1",
"type": "t_array(t_uint256)50_storage",
"contract": "ContextUpgradeable",
"src": "@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol:40"
},
{
"label": "_owner",
"offset": 0,
"slot": "51",
"type": "t_address",
"contract": "OwnableUpgradeable",
"src": "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol:22"
},
{
"label": "__gap",
"offset": 0,
"slot": "52",
"type": "t_array(t_uint256)49_storage",
"contract": "OwnableUpgradeable",
"src": "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol:94"
},
{
"label": "configRegistry",
"offset": 0,
"slot": "101",
"type": "t_address",
"contract": "LemonadeStakePayment",
"src": "contracts/payment/stake/LemonadeStakePayment.sol:17"
},
{
"label": "stakings",
"offset": 0,
"slot": "102",
"type": "t_mapping(t_bytes32,t_address)",
"contract": "LemonadeStakePayment",
"src": "contracts/payment/stake/LemonadeStakePayment.sol:18"
},
{
"label": "__gap",
"offset": 0,
"slot": "103",
"type": "t_array(t_uint256)5_storage",
"contract": "LemonadeStakePayment",
"src": "contracts/payment/stake/LemonadeStakePayment.sol:19"
}
],
"types": {
"t_address": {
"label": "address",
"numberOfBytes": "20"
},
"t_array(t_uint256)49_storage": {
"label": "uint256[49]",
"numberOfBytes": "1568"
},
"t_array(t_uint256)50_storage": {
"label": "uint256[50]",
"numberOfBytes": "1600"
},
"t_array(t_uint256)5_storage": {
"label": "uint256[5]",
"numberOfBytes": "160"
},
"t_bool": {
"label": "bool",
"numberOfBytes": "1"
},
"t_bytes32": {
"label": "bytes32",
"numberOfBytes": "32"
},
"t_mapping(t_bytes32,t_address)": {
"label": "mapping(bytes32 => address)",
"numberOfBytes": "32"
},
"t_uint256": {
"label": "uint256",
"numberOfBytes": "32"
},
"t_uint8": {
"label": "uint8",
"numberOfBytes": "1"
}
},
"namespaces": {}
}
}
}
}
4 changes: 2 additions & 2 deletions contracts/payment/stake/StakeVault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ contract StakeVault is Vault {

//-- ERRORS
error InvalidData();
error AccessDenied();
error AlreadyInited();

constructor(address owner) {
_grantRole(DEFAULT_ADMIN_ROLE, owner);
Expand All @@ -46,7 +46,7 @@ contract StakeVault is Vault {
uint256 ppm
) external onlyRole(OPERATOR_ROLE) {
if (inited) {
revert AccessDenied();
revert AlreadyInited();
}

inited = true;
Expand Down
5 changes: 4 additions & 1 deletion contracts/reward/RewardRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ contract RewardRegistry is IRewardRegistry, OwnableUpgradeable {
configRegistry = registry;
}

function createVault(bytes32 salt) external {
function createVault(bytes32 salt, address[] calldata admins) external {
address owner = _msgSender();

bytes memory bytecode = abi.encodePacked(
Expand All @@ -52,6 +52,9 @@ contract RewardRegistry is IRewardRegistry, OwnableUpgradeable {

address vault = Create2.deploy(0, salt, bytecode);

RewardVault rewardVault = RewardVault(payable(vault));
rewardVault.initialize(admins);

emit RewardVaultCreated(vault);
}

Expand Down
24 changes: 21 additions & 3 deletions contracts/reward/RewardVault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,13 @@ contract RewardVault is Vault, IRewardVault {
IRewardRegistry rewardRegistry;
mapping(bytes32 => EnumerableSet.AddressSet) rewardCurrencies;
mapping(bytes32 => mapping(address => uint256)) rewardSettings; //-- first key is reward id, second key is currency, value is reward amount
bool inited;

uint256[10] ___gap;

//-- ERRORS
error InvalidData();
error AlreadyInited();

//-- EVENTS
event RewardSent(
Expand All @@ -61,6 +63,24 @@ contract RewardVault is Vault, IRewardVault {
rewardRegistry = IRewardRegistry(registry);
}

function initialize(address[] calldata admins) public onlyRole(OPERATOR_ROLE) {
if (inited) {
revert AlreadyInited();
}

inited = true;

uint256 adminLength = admins.length;

for (uint256 i = 0; i < adminLength; ) {
_grantRole(DEFAULT_ADMIN_ROLE, admins[i]);

unchecked {
++i;
}
}
}

function setRewards(
bytes32[] calldata rewardIds,
RewardSetting[] calldata settings
Expand Down Expand Up @@ -136,9 +156,7 @@ contract RewardVault is Vault, IRewardVault {
return settings;
}

settings = new RewardSetting[](
currencyLength
);
settings = new RewardSetting[](currencyLength);

for (uint256 i = 0; i < currencyLength; ) {
address currency = currencies.at(i);
Expand Down
2 changes: 1 addition & 1 deletion test/RewardRegistryV1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const register = async (owners: SignerWithAddress[]) => {
const { rewardRegistry } = await deployRewardRegistry();

const createVault = async (signer: SignerWithAddress) => {
const response: ContractTransactionResponse = await rewardRegistry.connect(signer).createVault(salt);
const response: ContractTransactionResponse = await rewardRegistry.connect(signer).createVault(salt, []);

const receipt = await response.wait();

Expand Down

0 comments on commit 6728199

Please sign in to comment.