Skip to content

Commit

Permalink
chore: nft rent with permit, factory salt depends on sender
Browse files Browse the repository at this point in the history
  • Loading branch information
kostyamospan committed May 29, 2024
1 parent 5835fb2 commit 58f6b23
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 5 deletions.
15 changes: 13 additions & 2 deletions contracts/SmartWalletFactoryV1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@ contract SmartWalletFactoryV1 is ISmartWalletFactory {
function create2Wallet(
address owner,
address allowlistOperator,
bytes32 salt
bytes32 baseSalt
) public returns (address) {
bytes32 salt = getSalt(msg.sender, baseSalt);
SmartWalletV1 wallet = SmartWalletV1(
payable(Clones.cloneDeterministic(implementation, salt))
);
Expand All @@ -69,8 +70,11 @@ contract SmartWalletFactoryV1 is ISmartWalletFactory {
}

function predictCreate2Wallet(
bytes32 salt
address sender,
bytes32 baseSalt
) external view returns (address) {
bytes32 salt = getSalt(sender, baseSalt);

return
Clones.predictDeterministicAddress(
implementation,
Expand All @@ -87,4 +91,11 @@ contract SmartWalletFactoryV1 is ISmartWalletFactory {
);
return expectedAddress == wallet;
}

function getSalt(
address sender,
bytes32 baseSalt
) public pure returns (bytes32) {
return keccak256(abi.encodePacked(sender, baseSalt));
}
}
2 changes: 1 addition & 1 deletion contracts/integration/NftRent.sol
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ contract NftRent is ERC721Holder, IAutoExecuteCallback {
_resetSmartWallet(listInfo, msg.sender);
}

function _rent(bytes32 id, address smartWallet) private {
function _rent(bytes32 id, address smartWallet) internal {
require(
ISmartWalletFactory(smartWalletFactory).validateWallet(smartWallet),
"NR: not a smart wallet"
Expand Down
25 changes: 25 additions & 0 deletions contracts/integration/NftRentWithPermit.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//SPDX-License-Identifier: Unlicense
pragma solidity ^0.8.23;

import "./NftRent.sol";

contract NftRentWithPermit is NftRent {
constructor(address _smartWalletFactory) NftRent(_smartWalletFactory) {}

function rentExternalWithPermit(
bytes32 id,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) external payable {
ISmartWallet(msg.sender).addToAllowlistWithPermit(
address(this),
deadline,
v,
r,
s
);
_rent(id, msg.sender);
}
}
5 changes: 4 additions & 1 deletion contracts/interfaces/ISmartWalletFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ interface ISmartWalletFactory {
bytes32 salt
) external returns (address);

function predictCreate2Wallet(bytes32 salt) external view returns (address);
function predictCreate2Wallet(
address sender,
bytes32 baseSalt
) external view returns (address);

function validateWallet(address wallet) external view returns (bool);
}
2 changes: 1 addition & 1 deletion docs/main.js

Large diffs are not rendered by default.

0 comments on commit 58f6b23

Please sign in to comment.