Skip to content

Commit 1873e09

Browse files
committed
remove hook tag requirement
1 parent 3cb21cc commit 1873e09

5 files changed

Lines changed: 3 additions & 140 deletions

File tree

src/core/hub/PWNHubTags.sol

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,4 @@ library PWNHubTags {
1212
/// @dev Address can revoke nonces on other addresses behalf.
1313
bytes32 internal constant NONCE_MANAGER = keccak256("PWN_NONCE_MANAGER");
1414

15-
/// @dev Address can be used as a loan hook.
16-
bytes32 internal constant HOOK = keccak256("PWN_HOOK");
17-
1815
}

src/core/loan/PWNLoan.sol

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ import { MultiToken, IMultiTokenCategoryRegistry } from "MultiToken/MultiToken.s
66
import { Math } from "openzeppelin/utils/math/Math.sol";
77

88
import { PWNConfig } from "pwn/core/config/PWNConfig.sol";
9-
import { PWNHub } from "pwn/core/hub/PWNHub.sol";
10-
import { PWNHubTags } from "pwn/core/hub/PWNHubTags.sol";
119
import { IPWNBorrowerCreateHook, BORROWER_CREATE_HOOK_RETURN_VALUE } from "pwn/core/loan/hook/IPWNBorrowerCreateHook.sol";
1210
import { IPWNBorrowerCollateralRepaymentHook, BORROWER_COLLATERAL_REPAYMENT_HOOK_RETURN_VALUE } from "pwn/core/loan/hook/IPWNBorrowerCollateralRepaymentHook.sol";
1311
import { IPWNLenderCreateHook, LENDER_CREATE_HOOK_RETURN_VALUE } from "pwn/core/loan/hook/IPWNLenderCreateHook.sol";
@@ -38,7 +36,6 @@ contract PWNLoan is PWNProposalManager, PWNVault, IERC5646, IPWNLoanMetadataProv
3836
bytes32 internal constant _EMPTY_LENDER_SPEC_HASH = keccak256(abi.encode(LenderSpec(IPWNLenderCreateHook(address(0)), "", IPWNLenderRepaymentHook(address(0)), "")));
3937
bytes32 internal constant _EMPTY_BORROWER_SPEC_HASH = keccak256(abi.encode(BorrowerSpec(IPWNBorrowerCreateHook(address(0)), "")));
4038

41-
PWNHub public immutable hub;
4239
PWNLOAN public immutable loanToken;
4340
PWNConfig public immutable config;
4441
IMultiTokenCategoryRegistry public immutable categoryRegistry;
@@ -140,8 +137,6 @@ contract PWNLoan is PWNProposalManager, PWNVault, IERC5646, IPWNLoanMetadataProv
140137

141138
/** @notice Thrown when a call tries to enter locked loan context.*/
142139
error LoanContextLocked(uint256 loanId);
143-
/** @notice Thrown when an address is missing a PWN Hub tag.*/
144-
error AddressMissingHubTag(address addr, bytes32 tag);
145140
/** @notice Thrown when managed loan is not running.*/
146141
error LoanNotRunning();
147142
/** @notice Thrown when managed loan is not defaulted.*/
@@ -177,12 +172,10 @@ contract PWNLoan is PWNProposalManager, PWNVault, IERC5646, IPWNLoanMetadataProv
177172
|*----------------------------------------------------------*/
178173

179174
constructor(
180-
address _hub,
181175
address _loanToken,
182176
address _config,
183177
address _categoryRegistry
184178
) {
185-
hub = PWNHub(_hub);
186179
loanToken = PWNLOAN(_loanToken);
187180
config = PWNConfig(_config);
188181
categoryRegistry = IMultiTokenCategoryRegistry(_categoryRegistry);
@@ -333,7 +326,6 @@ contract PWNLoan is PWNProposalManager, PWNVault, IERC5646, IPWNLoanMetadataProv
333326
) private {
334327
// Call lender create hook
335328
if (address(lenderSpec.createHook) != address(0)) {
336-
_checkHubTag(address(lenderSpec.createHook), PWNHubTags.HOOK);
337329
bytes32 hookReturnValue = lenderSpec.createHook.onLoanCreated(
338330
loanId,
339331
lender,
@@ -364,7 +356,6 @@ contract PWNLoan is PWNProposalManager, PWNVault, IERC5646, IPWNLoanMetadataProv
364356

365357
// Call borrower create hook
366358
if (address(borrowerSpec.createHook) != address(0)) {
367-
_checkHubTag(address(borrowerSpec.createHook), PWNHubTags.HOOK);
368359
bytes32 hookReturnValue = borrowerSpec.createHook.onLoanCreated(
369360
loanId,
370361
borrower,
@@ -498,9 +489,6 @@ contract PWNLoan is PWNProposalManager, PWNVault, IERC5646, IPWNLoanMetadataProv
498489
address borrowerHook,
499490
bytes memory borrowerHookData
500491
) internal {
501-
// Check that hook has PWN Hub tag
502-
_checkHubTag(borrowerHook, PWNHubTags.HOOK);
503-
504492
// Transfer collateral to borrower hook
505493
_push(loan.collateral, borrowerHook);
506494

@@ -549,7 +537,6 @@ contract PWNLoan is PWNProposalManager, PWNVault, IERC5646, IPWNLoanMetadataProv
549537
) external {
550538
if (msg.sender != address(this)) revert CallerNotVault();
551539
if (address(hookData.hook) == address(0)) revert HookZeroAddress();
552-
_checkHubTag(address(hookData.hook), PWNHubTags.HOOK);
553540

554541
// Transfer repayment to lender repayment hook
555542
_pushFrom(creditAddress.ERC20(repaymentAmount), repaymentOrigin, address(hookData.hook));
@@ -745,7 +732,6 @@ contract PWNLoan is PWNProposalManager, PWNVault, IERC5646, IPWNLoanMetadataProv
745732
if (address(newHook) == address(0)) {
746733
delete lenderRepaymentHook[msg.sender][loanId];
747734
} else {
748-
_checkHubTag(address(newHook), PWNHubTags.HOOK);
749735
lenderRepaymentHook[msg.sender][loanId] = LenderRepaymentHookData(newHook, newHookData);
750736
}
751737
}
@@ -824,12 +810,6 @@ contract PWNLoan is PWNProposalManager, PWNVault, IERC5646, IPWNLoanMetadataProv
824810
|* # UTILS *|
825811
|*----------------------------------------------------------*/
826812

827-
function _checkHubTag(address addr, bytes32 tag) internal view {
828-
if (!hub.hasTag(addr, tag)) {
829-
revert AddressMissingHubTag({ addr: addr, tag: tag });
830-
}
831-
}
832-
833813
function _tryIsDefaulted(uint256 loanId) internal view returns (bool) {
834814
try LOANs[loanId].product.isDefaulted(address(this), loanId) returns (bool isDefaulted) {
835815
return isDefaulted;

test/DeploymentTest.t.sol

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ abstract contract DeploymentTest is Deployments, Test {
9292

9393
__d.loanToken = new PWNLOAN(address(__d.hub));
9494
__d.loan = new PWNLoan(
95-
address(__d.hub),
9695
address(__d.loanToken),
9796
address(__d.config),
9897
address(__d.categoryRegistry)
@@ -151,7 +150,7 @@ abstract contract DeploymentTest is Deployments, Test {
151150
__d.hooks.directLenderRepayment = new PWNDirectLenderRepaymentHook();
152151

153152
// Set hub tags
154-
address[] memory addrs = new address[](16);
153+
address[] memory addrs = new address[](11);
155154
addrs[0] = address(__d.loan);
156155

157156
addrs[1] = address(__d.products.stable);
@@ -166,13 +165,7 @@ abstract contract DeploymentTest is Deployments, Test {
166165
addrs[9] = address(__d.products.uniswapV3Individual);
167166
addrs[10] = address(__d.products.uniswapV3Set);
168167

169-
addrs[11] = address(__d.hooks.refinanceBorrowerCreate);
170-
addrs[12] = address(__d.hooks.vaultLender);
171-
addrs[13] = address(__d.hooks.aaveLender);
172-
addrs[14] = address(__d.hooks.compoundLender);
173-
addrs[15] = address(__d.hooks.directLenderRepayment);
174-
175-
bytes32[] memory tags = new bytes32[](16);
168+
bytes32[] memory tags = new bytes32[](11);
176169
tags[0] = PWNHubTags.ACTIVE_LOAN;
177170

178171
tags[1] = PWNHubTags.NONCE_MANAGER;
@@ -187,12 +180,6 @@ abstract contract DeploymentTest is Deployments, Test {
187180
tags[9] = PWNHubTags.LOAN_PROPOSAL;
188181
tags[10] = PWNHubTags.LOAN_PROPOSAL;
189182

190-
tags[11] = PWNHubTags.HOOK;
191-
tags[12] = PWNHubTags.HOOK;
192-
tags[13] = PWNHubTags.HOOK;
193-
tags[14] = PWNHubTags.HOOK;
194-
tags[15] = PWNHubTags.HOOK;
195-
196183
vm.prank(__e.protocolTimelock);
197184
__d.hub.setTags(addrs, tags, true);
198185
}

test/fork/PWNCrowdsourceLenderVault.fork.t.sol

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,6 @@ contract PWNCrowdsourceLenderVaultForkTest is DeploymentTest {
127127
acceptorValues = PWNInstallmentsProduct.AcceptorValues({
128128
creditAmount: 180_000 * 10 ** decimals
129129
});
130-
131-
vm.prank(__e.protocolTimelock);
132-
__d.hub.setTag(address(lenderVault), PWNHubTags.HOOK, true);
133130
}
134131

135132
}

test/unit/PWNLOAN.t.sol

Lines changed: 1 addition & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import { IERC721Receiver } from "openzeppelin/token/ERC721/IERC721Receiver.sol";
88
import {
99
PWNLoan,
1010
LOANStatus,
11-
PWNHubTags,
1211
Math,
1312
MultiToken,
1413
Terms,
@@ -42,7 +41,6 @@ abstract contract PWNLoanTest is Test {
4241
bytes32 internal constant LOAN_LOCK_SLOT = bytes32(uint256(4)); // `loanLock` mapping position
4342

4443
PWNLoan loanContract;
45-
address hub = makeAddr("hub");
4644
address loanToken = makeAddr("loanToken");
4745
address config = makeAddr("config");
4846
address categoryRegistry = makeAddr("categoryRegistry");
@@ -80,14 +78,13 @@ abstract contract PWNLoanTest is Test {
8078
event LOANLiquidated(uint256 indexed loanId, address indexed liquidator, uint256 liquidationAmount);
8179

8280
function setUp() virtual public {
83-
vm.etch(hub, bytes("data"));
8481
vm.etch(loanToken, bytes("data"));
8582
vm.etch(config, bytes("data"));
8683

8784
(lender, lenderPK) = makeAddrAndKey("lender");
8885
(borrower, borrowerPK) = makeAddrAndKey("borrower");
8986

90-
loanContract = new PWNLoan(hub, loanToken, config, categoryRegistry);
87+
loanContract = new PWNLoan(loanToken, config, categoryRegistry);
9188
fungibleAsset = new T20();
9289
nonFungibleAsset = new T721();
9390

@@ -173,12 +170,6 @@ abstract contract PWNLoanTest is Test {
173170
vm.mockCall(config, abi.encodeWithSignature("fee()"), abi.encode(0));
174171
vm.mockCall(config, abi.encodeWithSignature("feeCollector()"), abi.encode(feeCollector));
175172

176-
vm.mockCall(hub, abi.encodeWithSignature("hasTag(address,bytes32)"), abi.encode(false));
177-
_mockHubTag(address(lenderCreateHook), PWNHubTags.HOOK);
178-
_mockHubTag(address(lenderRepaymentHook), PWNHubTags.HOOK);
179-
_mockHubTag(address(borrowerCreateHook), PWNHubTags.HOOK);
180-
_mockHubTag(address(borrowerCollateralRepaymentHook), PWNHubTags.HOOK);
181-
182173
vm.mockCall(
183174
address(lenderCreateHook),
184175
abi.encodeWithSelector(IPWNLenderCreateHook.onLoanCreated.selector),
@@ -269,14 +260,6 @@ abstract contract PWNLoanTest is Test {
269260
vm.mockCall(loanToken, abi.encodeWithSignature("ownerOf(uint256)", _loanId), abi.encode(_owner));
270261
}
271262

272-
function _mockHubTag(address _contract, bytes32 _tag) internal {
273-
_mockHubTag(_contract, _tag, true);
274-
}
275-
276-
function _mockHubTag(address _contract, bytes32 _tag, bool _set) internal {
277-
vm.mockCall(hub, abi.encodeWithSignature("hasTag(address,bytes32)", _contract, _tag), abi.encode(_set));
278-
}
279-
280263
function _mockIsDefaulted(uint256 _loanId, bool _defaulted) internal {
281264
vm.mockCall(
282265
address(product),
@@ -573,19 +556,6 @@ contract PWNLoan_Create_Test is PWNLoanTest {
573556
loanContract.create(proposalSpec, lenderSpec, borrowerSpec, "");
574557
}
575558

576-
function test_shouldFail_whenLenderCreateHookNotTaggedInHub() external {
577-
lenderSpec.createHook = IPWNLenderCreateHook(makeAddr("not tagged lender create hook"));
578-
579-
terms.proposerSpecHash = loanContract.getLenderSpecHash(lenderSpec);
580-
_mockLoanTerms(terms);
581-
582-
vm.expectRevert(
583-
abi.encodeWithSelector(PWNLoan.AddressMissingHubTag.selector, address(lenderSpec.createHook), PWNHubTags.HOOK)
584-
);
585-
vm.prank(borrower);
586-
loanContract.create(proposalSpec, lenderSpec, borrowerSpec, "");
587-
}
588-
589559
function test_shouldFail_whenLenderCreateHookReturnsWrongValue() external {
590560
lenderSpec.createHook = lenderCreateHook;
591561

@@ -656,16 +626,6 @@ contract PWNLoan_Create_Test is PWNLoanTest {
656626
loanContract.create(proposalSpec, lenderSpec, borrowerSpec, "");
657627
}
658628

659-
function test_shouldFail_whenBorrowerCreateHookNotTaggedInHub() external {
660-
borrowerSpec.createHook = IPWNBorrowerCreateHook(makeAddr("not tagged lender create hook"));
661-
662-
vm.expectRevert(
663-
abi.encodeWithSelector(PWNLoan.AddressMissingHubTag.selector, address(borrowerSpec.createHook), PWNHubTags.HOOK)
664-
);
665-
vm.prank(borrower);
666-
loanContract.create(proposalSpec, lenderSpec, borrowerSpec, "");
667-
}
668-
669629
function test_shouldFail_whenBorrowerCreateHookReturnsWrongValue() external {
670630
borrowerSpec.createHook = borrowerCreateHook;
671631

@@ -968,30 +928,6 @@ contract PWNLoan_Repay_Test is PWNLoanTest {
968928
loanContract.repay(loanId, repayment);
969929
}
970930

971-
function testFuzz_shouldTransferRepaymentToVault_whenLenderRepaymentHookSet_whenNotTaggedInHub(uint256 repayment) external {
972-
repayment = bound(repayment, 1, loanContract.getLOANDebt(loanId));
973-
974-
vm.prank(lender);
975-
loanContract.updateLenderRepaymentHook(loanId, lenderRepaymentHook, "");
976-
977-
_mockHubTag(address(lenderRepaymentHook), PWNHubTags.HOOK, false);
978-
979-
vm.expectCall(
980-
loan.creditAddress,
981-
abi.encodeWithSignature(
982-
"transferFrom(address,address,uint256)", borrower, address(loanContract), repayment
983-
)
984-
);
985-
986-
uint256 vaultBalanceBefore = fungibleAsset.balanceOf(address(loanContract));
987-
988-
vm.prank(borrower);
989-
loanContract.repay(loanId, repayment);
990-
991-
assertEq(fungibleAsset.balanceOf(address(loanContract)), vaultBalanceBefore + repayment);
992-
assertEq(fungibleAsset.balanceOf(address(lenderRepaymentHook)), 0);
993-
}
994-
995931
function testFuzz_shouldTransferRepaymentToVault_whenLenderRepaymentHookSet_whenWrongReturnValue(uint256 repayment) external {
996932
repayment = bound(repayment, 1, loanContract.getLOANDebt(loanId));
997933

@@ -1117,16 +1053,6 @@ contract PWNLoan_RepayWithCollateral_Test is PWNLoanTest {
11171053
loanContract.repayWithCollateral(loanId, borrowerCollateralRepaymentHook, "hook data");
11181054
}
11191055

1120-
function test_shouldFail_whenBorrowerCollateralRepaymentHookNotTaggedInHub() external {
1121-
IPWNBorrowerCollateralRepaymentHook hook = IPWNBorrowerCollateralRepaymentHook(makeAddr("not tagged hook"));
1122-
1123-
vm.expectRevert(
1124-
abi.encodeWithSelector(PWNLoan.AddressMissingHubTag.selector, address(hook), PWNHubTags.HOOK)
1125-
);
1126-
vm.prank(borrower);
1127-
loanContract.repayWithCollateral(loanId, hook, "");
1128-
}
1129-
11301056
function test_shouldFail_whenBorrowerCollateralRepaymentHookReturnsWrongValue() external {
11311057
bytes32 wrongReturn = keccak256("wrong return");
11321058
vm.mockCall(
@@ -1226,19 +1152,6 @@ contract PWNLoan_TryCallLenderRepaymentHook_Test is PWNLoanTest {
12261152
);
12271153
}
12281154

1229-
function test_shouldFail_whenLenderRepaymentHookNotTaggedInHub() external {
1230-
_mockHubTag(address(lenderRepaymentHook), PWNHubTags.HOOK, false);
1231-
1232-
vm.expectRevert(
1233-
abi.encodeWithSelector(PWNLoan.AddressMissingHubTag.selector, address(lenderRepaymentHook), PWNHubTags.HOOK)
1234-
);
1235-
vm.prank(address(loanContract));
1236-
loanContract.tryCallLenderRepaymentHook(
1237-
PWNLoan.LenderRepaymentHookData(lenderRepaymentHook, ""),
1238-
borrower, lender, loan.creditAddress, 1 ether
1239-
);
1240-
}
1241-
12421155
function test_shouldFail_whenLenderRepaymentHookReverts() external {
12431156
vm.mockCallRevert(
12441157
address(lenderRepaymentHook),
@@ -1801,17 +1714,7 @@ contract PWNLoan_GetBorrowerSpecHash_Test is PWNLoanTest {
18011714

18021715
contract PWNLoan_UpdateLenderRepaymentHook_Test is PWNLoanTest {
18031716

1804-
function test_shouldFail_whenNewHookIsNotTagged() external {
1805-
_mockHubTag(address(lenderRepaymentHook), PWNHubTags.HOOK, false);
1806-
1807-
vm.expectRevert(abi.encodeWithSelector(PWNLoan.AddressMissingHubTag.selector, lenderRepaymentHook, PWNHubTags.HOOK));
1808-
vm.prank(lender);
1809-
loanContract.updateLenderRepaymentHook(loanId, lenderRepaymentHook, "new repayment hook data");
1810-
}
1811-
18121717
function test_shouldUpdateLenderRepaymentHook() external {
1813-
_mockHubTag(address(lenderRepaymentHook), PWNHubTags.HOOK);
1814-
18151718
vm.prank(lender);
18161719
loanContract.updateLenderRepaymentHook(loanId, lenderRepaymentHook, "new repayment hook data");
18171720

@@ -1821,7 +1724,6 @@ contract PWNLoan_UpdateLenderRepaymentHook_Test is PWNLoanTest {
18211724

18221725
// Rewrite to new hook
18231726
IPWNLenderRepaymentHook newHook = IPWNLenderRepaymentHook(makeAddr("newHook"));
1824-
_mockHubTag(address(newHook), PWNHubTags.HOOK);
18251727

18261728
vm.prank(lender);
18271729
loanContract.updateLenderRepaymentHook(loanId, newHook, "");

0 commit comments

Comments
 (0)