Skip to content

Commit

Permalink
fix: directpool permissoins before release
Browse files Browse the repository at this point in the history
  • Loading branch information
sirpy committed Oct 20, 2024
1 parent d59b998 commit 5da4ecd
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,14 @@ contract DirectPaymentsFactory is AccessControlUpgradeable, UUPSUpgradeable {

nft.grantRole(nft.getManagerRole(nextNftType), _settings.manager);
nft.grantRole(nft.getManagerRole(nextNftType), address(pool));
pool.grantRole(pool.MINTER_ROLE(), _settings.manager);

//access control to project is determinted by the first pool access control rules
if (address(projectIdToControlPool[keccak256(bytes(_projectId))]) == address(0))
projectIdToControlPool[keccak256(bytes(_projectId))] = pool;
registry[address(pool)].ipfs = _ipfs;
registry[address(pool)].projectId = _projectId;

pool.grantRole(DEFAULT_ADMIN_ROLE, msg.sender);
pool.renounceRole(DEFAULT_ADMIN_ROLE, address(this));
pools.push(address(pool));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,10 @@ contract DirectPaymentsPool is
settings = _settings;
limits = _limits;
nft = _nft;
_setupRole(DEFAULT_ADMIN_ROLE, msg.sender);
_setupRole(DEFAULT_ADMIN_ROLE, _settings.manager);
_setupRole(DEFAULT_ADMIN_ROLE, msg.sender); // when using factory this gives factory role which then set role to the real msg.sender
_setupRole(MANAGER_ROLE, _settings.manager);
_setupRole(MINTER_ROLE, _settings.manager);

setSuperToken(ISuperToken(address(settings.rewardToken)));
}

Expand Down Expand Up @@ -398,7 +400,7 @@ contract DirectPaymentsPool is
* @dev Sets the safety limits for the pool.
* @param _limits The new safety limits.
*/
function setPoolLimits(SafetyLimits memory _limits) public onlyRole(DEFAULT_ADMIN_ROLE) {
function setPoolLimits(SafetyLimits memory _limits) public onlyRole(MANAGER_ROLE) {
limits = _limits;
emit PoolLimitsChanged(_limits);
}
Expand All @@ -407,7 +409,7 @@ contract DirectPaymentsPool is
* @dev Sets the settings for the pool.
* @param _settings The new pool settings.
*/
function setPoolSettings(PoolSettings memory _settings) public onlyRole(DEFAULT_ADMIN_ROLE) {
function setPoolSettings(PoolSettings memory _settings) public onlyRole(MANAGER_ROLE) {
if (_settings.nftType != settings.nftType) revert NFTTYPE_CHANGED();
if (_settings.manager == address(0)) revert EMPTY_MANAGER();

Expand Down
4 changes: 2 additions & 2 deletions packages/contracts/contracts/UBI/UBIPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ contract UBIPool is AccessControlUpgradeable, GoodCollectiveSuperApp, UUPSUpgrad
ubiSettings = _ubiSettings;
_verifyPoolSettings(_settings);
_verifyUBISettings(_ubiSettings);
_setupRole(DEFAULT_ADMIN_ROLE, msg.sender);
_setupRole(DEFAULT_ADMIN_ROLE, msg.sender); // when using factory this gives factory role which then set role to the real msg.sender
_setupRole(MANAGER_ROLE, _settings.manager);
setSuperToken(ISuperToken(address(settings.rewardToken)));
}
Expand Down Expand Up @@ -394,6 +394,6 @@ contract UBIPool is AccessControlUpgradeable, GoodCollectiveSuperApp, UUPSUpgrad
}

function nextClaimTime() public view returns (uint256) {
return (getCurrentDay() + 1) * (1 days);
return (getCurrentDay() + ubiSettings.claimPeriodDays) * (1 days) + 12 hours;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ describe('DirectPaymentsPool Superapp', () => {
path: '0x',
}, '0x')

console.log((await tx.wait()).events)
// console.log((await tx.wait()).events)

expect(await mockToken.balanceOf(signer.address)).eq(0);
expect(await gdframework.GoodDollar.balanceOf(signer.address)).eq(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,9 @@ describe('DirectPaymentsFactory', () => {
expect(await nft.hasRole(await nft.getManagerRole('1'), signers[1].address)).to.be.true;
expect(await nft.hasRole(await nft.getManagerRole('1'), pool.address)).to.be.true;

expect(await pool.hasRole(nft.DEFAULT_ADMIN_ROLE(), signers[1].address)).to.be.true;
expect(await pool.hasRole(nft.DEFAULT_ADMIN_ROLE(), factory.address)).to.be.false;
expect(await pool.hasRole(pool.DEFAULT_ADMIN_ROLE(), signer.address)).to.be.true;
expect(await pool.hasRole(pool.MANAGER_ROLE(), signers[1].address)).to.be.true;
expect(await pool.hasRole(pool.DEFAULT_ADMIN_ROLE(), factory.address)).to.be.false;

// datastructures
expect(await factory.projectIdToControlPool(ethers.utils.keccak256(ethers.utils.toUtf8Bytes('test')))).to.be.equal(
Expand All @@ -119,7 +120,7 @@ describe('DirectPaymentsFactory', () => {
});

it("should not be able to create pool if not project's manager", async () => {
const tx = await factory.createPool('test', 'pool1', poolSettings, poolLimits);
const tx = await factory.connect(signers[1]).createPool('test', 'pool1', poolSettings, poolLimits);

// signer 1 is the pool manager so it should not revert
await expect(factory.connect(signers[1]).createPool('test', 'pool2', poolSettings, poolLimits)).not.reverted;
Expand Down

0 comments on commit 5da4ecd

Please sign in to comment.