Skip to content

Commit 06c9064

Browse files
committed
Renamed flag isDecrease to enforceDecrease
1 parent ecfd727 commit 06c9064

8 files changed

Lines changed: 47 additions & 46 deletions

src/enforcers/ERC1155BalanceChangeEnforcer.sol

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { ModeCode } from "../utils/Types.sol";
1010
* @title ERC1155BalanceChangeEnforcer
1111
* @dev This contract allows setting up some guardrails around balance changes. By specifying an amount and a direction
1212
* (decrease/increase), one can enforce a maximum decrease or minimum increase in after-execution balance.
13-
* The change can be either a decrease or increase based on the `isDecrease` flag.
13+
* The change can be either a decrease or increase based on the `enforceDecrease` flag.
1414
* @dev This contract has no enforcement of how the balance changes. It's meant to be used alongside additional enforcers to
1515
* create granular permissions.
1616
* @dev This enforcer operates only in default execution mode.
@@ -61,7 +61,7 @@ contract ERC1155BalanceChangeEnforcer is CaveatEnforcer {
6161
* - next 20 bytes: address of the recipient
6262
* - next 32 bytes: token ID
6363
* - next 32 bytes: balance change guardrail amount (i.e., minimum increase OR maximum decrease, depending on
64-
* isDecrease)
64+
* enforceDecrease)
6565
* @param _mode The execution mode. (Must be Default execType)
6666
* @param _delegationHash The hash of the delegation.
6767
*/
@@ -94,7 +94,7 @@ contract ERC1155BalanceChangeEnforcer is CaveatEnforcer {
9494
* - next 20 bytes: address of the recipient
9595
* - next 32 bytes: token ID
9696
* - next 32 bytes: balance change guardrail amount (i.e., minimum increase OR maximum decrease, depending on
97-
* isDecrease)
97+
* enforceDecrease)
9898
* @param _delegationHash The hash of the delegation.
9999
*/
100100
function afterHook(
@@ -109,11 +109,11 @@ contract ERC1155BalanceChangeEnforcer is CaveatEnforcer {
109109
public
110110
override
111111
{
112-
(bool isDecrease_, address token_, address recipient_, uint256 tokenId_, uint256 amount_) = getTermsInfo(_terms);
112+
(bool enforceDecrease_, address token_, address recipient_, uint256 tokenId_, uint256 amount_) = getTermsInfo(_terms);
113113
bytes32 hashKey_ = _getHashKey(msg.sender, token_, recipient_, tokenId_, _delegationHash);
114114
delete isLocked[hashKey_];
115115
uint256 balance_ = IERC1155(token_).balanceOf(recipient_, tokenId_);
116-
if (isDecrease_) {
116+
if (enforceDecrease_) {
117117
require(balance_ >= balanceCache[hashKey_] - amount_, "ERC1155BalanceChangeEnforcer:exceeded-balance-decrease");
118118
} else {
119119
require(balance_ >= balanceCache[hashKey_] + amount_, "ERC1155BalanceChangeEnforcer:insufficient-balance-increase");
@@ -123,20 +123,20 @@ contract ERC1155BalanceChangeEnforcer is CaveatEnforcer {
123123
/**
124124
* @notice Decodes the terms used in this CaveatEnforcer.
125125
* @param _terms Encoded data that is used during the execution hooks.
126-
* @return isDecrease_ Boolean indicating if the balance should decrease (true | 0x01) or increase (false | 0x00).
126+
* @return enforceDecrease_ Boolean indicating if the balance should decrease (true | 0x01) or increase (false | 0x00).
127127
* @return token_ The address of the ERC1155 token.
128128
* @return recipient_ The address of the recipient of the token.
129129
* @return tokenId_ The ID of the ERC1155 token.
130130
* @return amount_ Balance change guardrail amount (i.e., minimum increase OR maximum decrease, depending on
131-
* isDecrease)
131+
* enforceDecrease)
132132
*/
133133
function getTermsInfo(bytes calldata _terms)
134134
public
135135
pure
136-
returns (bool isDecrease_, address token_, address recipient_, uint256 tokenId_, uint256 amount_)
136+
returns (bool enforceDecrease_, address token_, address recipient_, uint256 tokenId_, uint256 amount_)
137137
{
138138
require(_terms.length == 105, "ERC1155BalanceChangeEnforcer:invalid-terms-length");
139-
isDecrease_ = _terms[0] != 0;
139+
enforceDecrease_ = _terms[0] != 0;
140140
token_ = address(bytes20(_terms[1:21]));
141141
recipient_ = address(bytes20(_terms[21:41]));
142142
tokenId_ = uint256(bytes32(_terms[41:73]));

src/enforcers/ERC20BalanceChangeEnforcer.sol

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { ModeCode } from "../utils/Types.sol";
1010
* @title ERC20BalanceChangeEnforcer
1111
* @dev This contract allows setting up some guardrails around balance changes. By specifying an amount and a direction
1212
* (decrease/increase), one can enforce a maximum decrease or minimum increase in after-execution balance.
13-
* The change can be either a decrease or increase based on the `isDecrease` flag.
13+
* The change can be either a decrease or increase based on the `enforceDecrease` flag.
1414
* @dev This contract has no enforcement of how the balance changes. It's meant to be used alongside additional enforcers to
1515
* create granular permissions.
1616
* @dev This enforcer operates only in default execution mode.
@@ -48,7 +48,7 @@ contract ERC20BalanceChangeEnforcer is CaveatEnforcer {
4848
* - next 20 bytes: address of the token
4949
* - next 20 bytes: address of the recipient
5050
* - next 32 bytes: balance change guardrail amount (i.e., minimum increase OR maximum decrease, depending on
51-
* isDecrease)
51+
* enforceDecrease)
5252
* @param _mode The execution mode. (Must be Default execType)
5353
*/
5454
function beforeHook(
@@ -79,7 +79,7 @@ contract ERC20BalanceChangeEnforcer is CaveatEnforcer {
7979
* - next 20 bytes: address of the token
8080
* - next 20 bytes: address of the recipient
8181
* - next 32 bytes: balance change guardrail amount (i.e., minimum increase OR maximum decrease, depending on
82-
* isDecrease)
82+
* enforceDecrease)
8383
*/
8484
function afterHook(
8585
bytes calldata _terms,
@@ -93,11 +93,11 @@ contract ERC20BalanceChangeEnforcer is CaveatEnforcer {
9393
public
9494
override
9595
{
96-
(bool isDecrease_, address token_, address recipient_, uint256 amount_) = getTermsInfo(_terms);
96+
(bool enforceDecrease_, address token_, address recipient_, uint256 amount_) = getTermsInfo(_terms);
9797
bytes32 hashKey_ = _getHashKey(msg.sender, token_, _delegationHash);
9898
delete isLocked[hashKey_];
9999
uint256 balance_ = IERC20(token_).balanceOf(recipient_);
100-
if (isDecrease_) {
100+
if (enforceDecrease_) {
101101
require(balance_ >= balanceCache[hashKey_] - amount_, "ERC20BalanceChangeEnforcer:exceeded-balance-decrease");
102102
} else {
103103
require(balance_ >= balanceCache[hashKey_] + amount_, "ERC20BalanceChangeEnforcer:insufficient-balance-increase");
@@ -107,19 +107,19 @@ contract ERC20BalanceChangeEnforcer is CaveatEnforcer {
107107
/**
108108
* @notice Decodes the terms used in this CaveatEnforcer.
109109
* @param _terms encoded data that is used during the execution hooks.
110-
* @return isDecrease_ Boolean indicating if the balance should decrease (true | 0x01) or increase (false | 0x00).
110+
* @return enforceDecrease_ Boolean indicating if the balance should decrease (true | 0x01) or increase (false | 0x00).
111111
* @return token_ The address of the token.
112112
* @return recipient_ The address of the recipient.
113113
* @return amount_ Balance change guardrail amount (i.e., minimum increase OR maximum decrease, depending on
114-
* isDecrease)
114+
* enforceDecrease)
115115
*/
116116
function getTermsInfo(bytes calldata _terms)
117117
public
118118
pure
119-
returns (bool isDecrease_, address token_, address recipient_, uint256 amount_)
119+
returns (bool enforceDecrease_, address token_, address recipient_, uint256 amount_)
120120
{
121121
require(_terms.length == 73, "ERC20BalanceChangeEnforcer:invalid-terms-length");
122-
isDecrease_ = _terms[0] != 0;
122+
enforceDecrease_ = _terms[0] != 0;
123123
token_ = address(bytes20(_terms[1:21]));
124124
recipient_ = address(bytes20(_terms[21:41]));
125125
amount_ = uint256(bytes32(_terms[41:]));

src/enforcers/ERC721BalanceChangeEnforcer.sol

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { ModeCode } from "../utils/Types.sol";
1010
* @title ERC721BalanceChangeEnforcer
1111
* @dev This contract allows setting up some guardrails around balance changes. By specifying an amount and a direction
1212
* (decrease/increase), one can enforce a maximum decrease or minimum increase in after-execution balance.
13-
* The change can be either a decrease or increase based on the `isDecrease` flag.
13+
* The change can be either a decrease or increase based on the `enforceDecrease` flag.
1414
* @dev This contract has no enforcement of how the balance changes. It's meant to be used alongside additional enforcers to
1515
* create granular permissions.
1616
* @dev This enforcer operates only in default execution mode.
@@ -58,7 +58,7 @@ contract ERC721BalanceChangeEnforcer is CaveatEnforcer {
5858
* - next 20 bytes: address of the ERC721 token
5959
* - next 20 bytes: address of the recipient
6060
* - next 32 bytes: balance change guardrail amount (i.e., minimum increase OR maximum decrease, depending on
61-
* isDecrease)
61+
* enforceDecrease)
6262
* @param _mode The execution mode. (Must be Default execType)
6363
* @param _delegationHash The hash of the delegation.
6464
*/
@@ -90,7 +90,7 @@ contract ERC721BalanceChangeEnforcer is CaveatEnforcer {
9090
* - next 20 bytes: address of the ERC721 token
9191
* - next 20 bytes: address of the recipient
9292
* - next 32 bytes: balance change guardrail amount (i.e., minimum increase OR maximum decrease, depending on
93-
* isDecrease)
93+
* enforceDecrease)
9494
* @param _delegationHash The hash of the delegation.
9595
*/
9696
function afterHook(
@@ -105,11 +105,11 @@ contract ERC721BalanceChangeEnforcer is CaveatEnforcer {
105105
public
106106
override
107107
{
108-
(bool isDecrease_, address token_, address recipient_, uint256 amount_) = getTermsInfo(_terms);
108+
(bool enforceDecrease_, address token_, address recipient_, uint256 amount_) = getTermsInfo(_terms);
109109
bytes32 hashKey_ = _getHashKey(msg.sender, token_, recipient_, _delegationHash);
110110
delete isLocked[hashKey_];
111111
uint256 balance_ = IERC721(token_).balanceOf(recipient_);
112-
if (isDecrease_) {
112+
if (enforceDecrease_) {
113113
require(balance_ >= balanceCache[hashKey_] - amount_, "ERC721BalanceChangeEnforcer:exceeded-balance-decrease");
114114
} else {
115115
require(balance_ >= balanceCache[hashKey_] + amount_, "ERC721BalanceChangeEnforcer:insufficient-balance-increase");
@@ -119,19 +119,19 @@ contract ERC721BalanceChangeEnforcer is CaveatEnforcer {
119119
/**
120120
* @notice Decodes the terms used in this CaveatEnforcer.
121121
* @param _terms Encoded data that is used during the execution hooks.
122-
* @return isDecrease_ Boolean indicating if the balance should decrease (true | 0x01) or increase (false | 0x00).
122+
* @return enforceDecrease_ Boolean indicating if the balance should decrease (true | 0x01) or increase (false | 0x00).
123123
* @return token_ The address of the ERC721 token.
124124
* @return recipient_ The address of the recipient of the token.
125125
* @return amount_ Balance change guardrail amount (i.e., minimum increase OR maximum decrease, depending on
126-
* isDecrease)
126+
* enforceDecrease)
127127
*/
128128
function getTermsInfo(bytes calldata _terms)
129129
public
130130
pure
131-
returns (bool isDecrease_, address token_, address recipient_, uint256 amount_)
131+
returns (bool enforceDecrease_, address token_, address recipient_, uint256 amount_)
132132
{
133133
require(_terms.length == 73, "ERC721BalanceChangeEnforcer:invalid-terms-length");
134-
isDecrease_ = _terms[0] != 0;
134+
enforceDecrease_ = _terms[0] != 0;
135135
token_ = address(bytes20(_terms[1:21]));
136136
recipient_ = address(bytes20(_terms[21:41]));
137137
amount_ = uint256(bytes32(_terms[41:]));

src/enforcers/NativeBalanceChangeEnforcer.sol

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { ModeCode } from "../utils/Types.sol";
88
* @title NativeBalanceChangeEnforcer
99
* @dev This contract allows setting up some guardrails around balance changes. By specifying an amount and a direction
1010
* (decrease/increase), one can enforce a maximum decrease or minimum increase in after-execution balance.
11-
* The change can be either a decrease or increase based on the `isDecrease` flag.
11+
* The change can be either a decrease or increase based on the `enforceDecrease` flag.
1212
* @dev This contract has no enforcement of how the balance changes. It's meant to be used alongside additional enforcers to
1313
* create granular permissions.
1414
* @dev This enforcer operates only in default execution mode.
@@ -44,7 +44,7 @@ contract NativeBalanceChangeEnforcer is CaveatEnforcer {
4444
* - first byte: boolean indicating if the balance should decrease (true | 0x01) or increase (false | 0x00)
4545
* - next 20 bytes: address of the recipient
4646
* - next 32 bytes: balance change guardrail amount (i.e., minimum increase OR maximum decrease, depending on
47-
* isDecrease)
47+
* enforceDecrease)
4848
* @param _mode The execution mode. (Must be Default execType)
4949
* @param _delegationHash The hash of the delegation.
5050
*/
@@ -74,7 +74,7 @@ contract NativeBalanceChangeEnforcer is CaveatEnforcer {
7474
* - first byte: boolean indicating if the balance should decrease (true | 0x01) or increase (false | 0x00)
7575
* - next 20 bytes: address of the recipient
7676
* - next 32 bytes: balance change guardrail amount (i.e., minimum increase OR maximum decrease, depending on
77-
* isDecrease)
77+
* enforceDecrease)
7878
* @param _delegationHash The hash of the delegation.
7979
*/
8080
function afterHook(
@@ -89,10 +89,10 @@ contract NativeBalanceChangeEnforcer is CaveatEnforcer {
8989
public
9090
override
9191
{
92-
(bool isDecrease_, address recipient_, uint256 amount_) = getTermsInfo(_terms);
92+
(bool enforceDecrease_, address recipient_, uint256 amount_) = getTermsInfo(_terms);
9393
bytes32 hashKey_ = _getHashKey(msg.sender, _delegationHash);
9494
delete isLocked[hashKey_];
95-
if (isDecrease_) {
95+
if (enforceDecrease_) {
9696
require(recipient_.balance >= balanceCache[hashKey_] - amount_, "NativeBalanceChangeEnforcer:exceeded-balance-decrease");
9797
} else {
9898
require(
@@ -107,15 +107,15 @@ contract NativeBalanceChangeEnforcer is CaveatEnforcer {
107107
* - first byte: boolean indicating if the balance should decrease (true | 0x01) or increase (false | 0x00)
108108
* - next 20 bytes: address of the recipient
109109
* - next 32 bytes: balance change guardrail amount (i.e., minimum increase OR maximum decrease, depending on
110-
* isDecrease)
111-
* @return isDecrease_ Boolean indicating if the balance should decrease (true) or increase (false).
110+
* enforceDecrease)
111+
* @return enforceDecrease_ Boolean indicating if the balance should decrease (true) or increase (false).
112112
* @return recipient_ The address of the recipient whose balance will change.
113113
* @return amount_ Balance change guardrail amount (i.e., minimum increase OR maximum decrease, depending on
114-
* isDecrease)
114+
* enforceDecrease)
115115
*/
116-
function getTermsInfo(bytes calldata _terms) public pure returns (bool isDecrease_, address recipient_, uint256 amount_) {
116+
function getTermsInfo(bytes calldata _terms) public pure returns (bool enforceDecrease_, address recipient_, uint256 amount_) {
117117
require(_terms.length == 53, "NativeBalanceChangeEnforcer:invalid-terms-length");
118-
isDecrease_ = _terms[0] != 0;
118+
enforceDecrease_ = _terms[0] != 0;
119119
recipient_ = address(bytes20(_terms[1:21]));
120120
amount_ = uint256(bytes32(_terms[21:]));
121121
}

test/enforcers/ERC1155BalanceChangeEnforcer.t.sol

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,9 @@ contract ERC1155BalanceChangeEnforcerTest is CaveatEnforcerBaseTest {
4747
// Terms format: [bool shouldBalanceIncrease, address token, address recipient, uint256 tokenId, uint256 amount]
4848
function test_decodedTheTerms() public {
4949
bytes memory terms_ = abi.encodePacked(true, address(token), address(delegator), uint256(tokenId), uint256(100));
50-
(bool isDecrease_, address token_, address recipient_, uint256 tokenId_, uint256 amount_) = enforcer.getTermsInfo(terms_);
51-
assertEq(isDecrease_, true);
50+
(bool enforceDecrease_, address token_, address recipient_, uint256 tokenId_, uint256 amount_) =
51+
enforcer.getTermsInfo(terms_);
52+
assertEq(enforceDecrease_, true);
5253
assertEq(token_, address(token));
5354
assertEq(recipient_, delegator);
5455
assertEq(tokenId_, tokenId);

test/enforcers/ERC20BalanceChangeEnforcer.t.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ contract ERC20BalanceChangeEnforcerTest is CaveatEnforcerBaseTest {
4343
// Validates the terms get decoded correctly for an increase scenario
4444
function test_decodedTheTerms() public {
4545
bytes memory terms_ = abi.encodePacked(false, address(token), address(recipient), uint256(100));
46-
(bool isDecrease_, address token_, address recipient_, uint256 amount_) = enforcer.getTermsInfo(terms_);
47-
assertEq(isDecrease_, false);
46+
(bool enforceDecrease_, address token_, address recipient_, uint256 amount_) = enforcer.getTermsInfo(terms_);
47+
assertEq(enforceDecrease_, false);
4848
assertEq(token_, address(token));
4949
assertEq(recipient_, address(recipient));
5050
assertEq(amount_, 100);

test/enforcers/ERC721BalanceChangeEnforcer.t.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ contract ERC721BalanceChangeEnforcerTest is CaveatEnforcerBaseTest {
4343
// Validates the terms get decoded correctly (increase scenario)
4444
function test_decodedTheTerms() public {
4545
bytes memory terms_ = abi.encodePacked(true, address(token), address(delegator), uint256(1));
46-
(bool isDecrease_, address token_, address recipient_, uint256 amount_) = enforcer.getTermsInfo(terms_);
47-
assertTrue(isDecrease_);
46+
(bool enforceDecrease_, address token_, address recipient_, uint256 amount_) = enforcer.getTermsInfo(terms_);
47+
assertTrue(enforceDecrease_);
4848
assertEq(token_, address(token));
4949
assertEq(recipient_, delegator);
5050
assertEq(amount_, 1);

test/enforcers/NativeBalanceChangeEnforcer.t.sol

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ contract NativeBalanceChangeEnforcerTest is CaveatEnforcerBaseTest {
3434
// Validates the terms get decoded correctly
3535
function test_decodedTheTerms() public {
3636
bytes memory terms_ = abi.encodePacked(false, address(users.carol.deleGator), uint256(100));
37-
bool isDecrease_;
37+
bool enforceDecrease_;
3838
uint256 amount_;
3939
address recipient_;
40-
(isDecrease_, recipient_, amount_) = enforcer.getTermsInfo(terms_);
41-
assertFalse(isDecrease_);
40+
(enforceDecrease_, recipient_, amount_) = enforcer.getTermsInfo(terms_);
41+
assertFalse(enforceDecrease_);
4242
assertEq(recipient_, address(users.carol.deleGator));
4343
assertEq(amount_, 100);
4444
}

0 commit comments

Comments
 (0)