Skip to content

Commit

Permalink
jbpermissionids
Browse files Browse the repository at this point in the history
  • Loading branch information
filipviz committed Feb 23, 2024
1 parent e339183 commit 0680dd3
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 26 deletions.
15 changes: 11 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@bananapus/buyback-hook",
"version": "0.0.1",
"version": "0.0.2",
"license": "MIT",
"repository": {
"type": "git",
Expand All @@ -16,7 +16,8 @@
"deploy:optimism-sepolia": "source .env && forge script Deploy --chain-id 11155420 --rpc-url $RPC_OPTIMISM_SEPOLIA --broadcast --verify --etherscan-api-key $OPTIMISTIC_ETHERSCAN_API_KEY --interactives 1 --sender $SENDER_OPTIMISM_SEPOLIA -vvv"
},
"dependencies": {
"@bananapus/core": "^0.0.2",
"@bananapus/core": "^0.0.4",
"@bananapus/permission-ids": "^0.0.2",
"@exhausted-pigeon/uniswap-v3-forge-quoter": "^1.0.1",
"@openzeppelin/contracts": "^5.0.1",
"@uniswap/v3-core": "1.0.2-solc-0.8-simulate",
Expand Down
14 changes: 7 additions & 7 deletions src/JBBuybackHook.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {JBBeforeRedeemRecordedContext} from "@bananapus/core/src/structs/JBBefor
import {JBRedeemHookSpecification} from "@bananapus/core/src/structs/JBRedeemHookSpecification.sol";
import {JBConstants} from "@bananapus/core/src/libraries/JBConstants.sol";
import {JBMetadataResolver} from "@bananapus/core/src/libraries/JBMetadataResolver.sol";
import {JBBuybackPermissionIds} from "./libraries/JBBuybackPermissionIds.sol";
import {JBPermissionIds} from "@bananapus/permission-ids/src/JBPermissionIds.sol";
import {IJBBuybackHook} from "./interfaces/IJBBuybackHook.sol";
import {IWETH9} from "./interfaces/external/IWETH9.sol";

Expand Down Expand Up @@ -387,7 +387,7 @@ contract JBBuybackHook is ERC165, JBPermissioned, IJBBuybackHook {
/// @notice Set the pool to use for a given project and terminal token (the default for the project's token <->
/// terminal token pair).
/// @dev Uses create2 for callback auth and to allow adding pools which haven't been deployed yet.
/// This can be called by the project's owner or an address which has the `JBBuybackPermissionIds.SET_POOL`
/// This can be called by the project's owner or an address which has the `JBPermissionIds.CHANGE_BUYBACK_POOL`
/// permission from the owner.
/// @param projectId The ID of the project to set the pool for.
/// @param fee The fee used in the pool being set, as a fixed-point number of basis points with 2 decimals. A 0.01%
Expand All @@ -410,7 +410,7 @@ contract JBBuybackHook is ERC165, JBPermissioned, IJBBuybackHook {
_requirePermissionFrom({
account: PROJECTS.ownerOf(projectId),
projectId: projectId,
permissionId: JBBuybackPermissionIds.CHANGE_POOL
permissionId: JBPermissionIds.CHANGE_BUYBACK_POOL
});

// Make sure the provided TWAP slippage tolerance is within reasonable bounds.
Expand Down Expand Up @@ -477,7 +477,7 @@ contract JBBuybackHook is ERC165, JBPermissioned, IJBBuybackHook {

/// @notice Change the TWAP window for a project.
/// The TWAP window is the period of time over which the TWAP is computed.
/// @dev This can be called by the project's owner or an address with `JBBuybackPermissionIds.SET_POOL_PARAMS`
/// @dev This can be called by the project's owner or an address with `JBPermissionIds.SET_BUYBACK_POOL_PARAMS`
/// permission from the owner.
/// @param projectId The ID of the project to set the TWAP window of.
/// @param newWindow The new TWAP window.
Expand All @@ -486,7 +486,7 @@ contract JBBuybackHook is ERC165, JBPermissioned, IJBBuybackHook {
_requirePermissionFrom({
account: PROJECTS.ownerOf(projectId),
projectId: projectId,
permissionId: JBBuybackPermissionIds.SET_POOL_PARAMS
permissionId: JBPermissionIds.SET_BUYBACK_POOL_PARAMS
});

// Make sure the specified window is within reasonable bounds.
Expand All @@ -508,7 +508,7 @@ contract JBBuybackHook is ERC165, JBPermissioned, IJBBuybackHook {

/// @notice Set the TWAP slippage tolerance for a project.
/// The TWAP slippage tolerance is the maximum spread allowed between the amount received and the TWAP.
/// @dev This can be called by the project's owner or an address with `JBBuybackPermissionIds.SET_POOL_PARAMS`
/// @dev This can be called by the project's owner or an address with `JBPermissionIds.SET_BUYBACK_POOL_PARAMS`
/// permission from the owner.
/// @param projectId The ID of the project to set the TWAP slippage tolerance of.
/// @param newSlippageTolerance The new TWAP slippage tolerance, out of `TWAP_SLIPPAGE_DENOMINATOR`.
Expand All @@ -517,7 +517,7 @@ contract JBBuybackHook is ERC165, JBPermissioned, IJBBuybackHook {
_requirePermissionFrom({
account: PROJECTS.ownerOf(projectId),
projectId: projectId,
permissionId: JBBuybackPermissionIds.SET_POOL_PARAMS
permissionId: JBPermissionIds.SET_BUYBACK_POOL_PARAMS
});

// Make sure the provided TWAP slippage tolerance is within reasonable bounds.
Expand Down
26 changes: 13 additions & 13 deletions test/Unit.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import "@bananapus/core/src/interfaces/IJBController.sol";
import "@bananapus/core/src/interfaces/IJBDirectory.sol";
import "@bananapus/core/src/interfaces/IJBRedeemHook.sol";
import "@bananapus/core/src/libraries/JBConstants.sol";
import "@bananapus/permission-ids/src/JBPermissionIds.sol";

import {MetadataResolverHelper} from "@bananapus/core/src/../test/helpers/MetadataResolverHelper.sol";

Expand All @@ -18,7 +19,6 @@ import "forge-std/Test.sol";

import "./helpers/PoolAddress.sol";
import "src/JBBuybackHook.sol";
import "src/libraries/JBBuybackPermissionIds.sol";

/// @notice Unit tests for `JBBuybackHook`.
contract Test_BuybackHook_Unit is Test {
Expand Down Expand Up @@ -1279,22 +1279,22 @@ contract Test_BuybackHook_Unit is Test {
// Mock and expect calls to check the permissions of the caller.
vm.mockCall(
address(permissions),
abi.encodeCall(permissions.hasPermission, (dude, owner, projectId, JBBuybackPermissionIds.CHANGE_POOL)),
abi.encodeCall(permissions.hasPermission, (dude, owner, projectId, JBPermissionIds.CHANGE_BUYBACK_POOL)),
abi.encode(false)
);
vm.expectCall(
address(permissions),
abi.encodeCall(permissions.hasPermission, (dude, owner, projectId, JBBuybackPermissionIds.CHANGE_POOL))
abi.encodeCall(permissions.hasPermission, (dude, owner, projectId, JBPermissionIds.CHANGE_BUYBACK_POOL))
);

vm.mockCall(
address(permissions),
abi.encodeCall(permissions.hasPermission, (dude, owner, 0, JBBuybackPermissionIds.CHANGE_POOL)),
abi.encodeCall(permissions.hasPermission, (dude, owner, 0, JBPermissionIds.CHANGE_BUYBACK_POOL)),
abi.encode(false)
);
vm.expectCall(
address(permissions),
abi.encodeCall(permissions.hasPermission, (dude, owner, 0, JBBuybackPermissionIds.CHANGE_POOL))
abi.encodeCall(permissions.hasPermission, (dude, owner, 0, JBPermissionIds.CHANGE_BUYBACK_POOL))
);

// Expect revert on account of the caller not being authorized.
Expand Down Expand Up @@ -1408,25 +1408,25 @@ contract Test_BuybackHook_Unit is Test {
vm.mockCall(
address(permissions),
abi.encodeCall(
permissions.hasPermission, (notOwner, owner, projectId, JBBuybackPermissionIds.SET_POOL_PARAMS)
permissions.hasPermission, (notOwner, owner, projectId, JBPermissionIds.SET_BUYBACK_POOL_PARAMS)
),
abi.encode(false)
);
vm.expectCall(
address(permissions),
abi.encodeCall(
permissions.hasPermission, (notOwner, owner, projectId, JBBuybackPermissionIds.SET_POOL_PARAMS)
permissions.hasPermission, (notOwner, owner, projectId, JBPermissionIds.SET_BUYBACK_POOL_PARAMS)
)
);

vm.mockCall(
address(permissions),
abi.encodeCall(permissions.hasPermission, (notOwner, owner, 0, JBBuybackPermissionIds.SET_POOL_PARAMS)),
abi.encodeCall(permissions.hasPermission, (notOwner, owner, 0, JBPermissionIds.SET_BUYBACK_POOL_PARAMS)),
abi.encode(false)
);
vm.expectCall(
address(permissions),
abi.encodeCall(permissions.hasPermission, (notOwner, owner, 0, JBBuybackPermissionIds.SET_POOL_PARAMS))
abi.encodeCall(permissions.hasPermission, (notOwner, owner, 0, JBPermissionIds.SET_BUYBACK_POOL_PARAMS))
);

// Expect revert on account of the caller not being authorized to set the TWAP window.
Expand Down Expand Up @@ -1495,25 +1495,25 @@ contract Test_BuybackHook_Unit is Test {
vm.mockCall(
address(permissions),
abi.encodeCall(
permissions.hasPermission, (notOwner, owner, projectId, JBBuybackPermissionIds.SET_POOL_PARAMS)
permissions.hasPermission, (notOwner, owner, projectId, JBPermissionIds.SET_BUYBACK_POOL_PARAMS)
),
abi.encode(false)
);
vm.expectCall(
address(permissions),
abi.encodeCall(
permissions.hasPermission, (notOwner, owner, projectId, JBBuybackPermissionIds.SET_POOL_PARAMS)
permissions.hasPermission, (notOwner, owner, projectId, JBPermissionIds.SET_BUYBACK_POOL_PARAMS)
)
);

vm.mockCall(
address(permissions),
abi.encodeCall(permissions.hasPermission, (notOwner, owner, 0, JBBuybackPermissionIds.SET_POOL_PARAMS)),
abi.encodeCall(permissions.hasPermission, (notOwner, owner, 0, JBPermissionIds.SET_BUYBACK_POOL_PARAMS)),
abi.encode(false)
);
vm.expectCall(
address(permissions),
abi.encodeCall(permissions.hasPermission, (notOwner, owner, 0, JBBuybackPermissionIds.SET_POOL_PARAMS))
abi.encodeCall(permissions.hasPermission, (notOwner, owner, 0, JBPermissionIds.SET_BUYBACK_POOL_PARAMS))
);

// Expect revert on account of the caller not being authorized to set the TWAP slippage tolerance.
Expand Down

0 comments on commit 0680dd3

Please sign in to comment.