Skip to content

Commit

Permalink
build deposit
Browse files Browse the repository at this point in the history
  • Loading branch information
sanbir committed Dec 9, 2024
1 parent 6d519d1 commit fc98f0f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 23 deletions.
4 changes: 2 additions & 2 deletions src/p2pLendingProxy/P2pLendingProxy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ contract P2pLendingProxy is ERC165, IP2pLendingProxy {
);

SafeERC20.safeApprove(
permitSingleForP2pLendingProxy.details.token,
IERC20(permitSingleForP2pLendingProxy.details.token),
address(Permit2Lib.PERMIT2),
type(uint256).max
);
Expand All @@ -93,7 +93,7 @@ contract P2pLendingProxy is ERC165, IP2pLendingProxy {
}

/// @inheritdoc ERC165
function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165) returns (bool) {
function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) {
return interfaceId == type(IP2pLendingProxy).interfaceId ||
super.supportsInterface(interfaceId);
}
Expand Down
7 changes: 0 additions & 7 deletions src/p2pLendingProxyFactory/IP2pLendingProxyFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,6 @@ interface IP2pLendingProxyFactory is IERC165 {
uint96 _clientBasisPoints
) external view returns (address);

/// @notice Deploy P2pLendingProxy instance if not deployed before
/// @param _feeDistributorInstance The address of FeeDistributor instance
/// @return p2pLendingProxyInstance client P2pLendingProxy instance that has been deployed
function createP2pLendingProxy(
address _feeDistributorInstance
) external returns(address p2pLendingProxyInstance);

function getHashForP2pSigner(
address _client,
uint96 _clientBasisPoints,
Expand Down
31 changes: 17 additions & 14 deletions src/p2pLendingProxyFactory/P2pLendingProxyFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ contract P2pLendingProxyFactory is P2pLendingProxyFactoryStructs, ERC165, IP2pLe
}

constructor(address _p2pSigner) {
i_referenceP2pLendingProxy = new P2pLendingProxy(this);
i_referenceP2pLendingProxy = new P2pLendingProxy(address(this));

s_p2pSigner = _p2pSigner;
}
Expand Down Expand Up @@ -149,29 +149,33 @@ contract P2pLendingProxyFactory is P2pLendingProxyFactoryStructs, ERC165, IP2pLe
Rule memory rule = rules[i];

RuleType ruleType = rule.ruleType;
uint32 bytesCount = rule.allowedBytes.length;
uint32 bytesCount = uint32(rule.allowedBytes.length);

if (ruleType == RuleType.None) {
return false;
} else if (ruleType == RuleType.AnyCalldata) {
return true;
continue; // skip further checks for this rule
} else if (ruleType == RuleType.StartsWith) {
// Ensure the calldata is at least as long as the range defined by startIndex and bytesCount
if (_calldataAfterSelector.length < rule.index + bytesCount)
return false;
// Compare the specified range in the calldata with the allowed bytes
return
keccak256(
_calldataAfterSelector[rule.index:rule.index + bytesCount]
) == keccak256(rule.allowedBytes);
bool isAllowed = keccak256(_calldataAfterSelector[rule.index:rule.index + bytesCount]) == keccak256(rule.allowedBytes);
if (!isAllowed) {
return false;
} else {
continue; // skip further checks for this rule
}
} else if (ruleType == RuleType.EndsWith) {
// Ensure the calldata is at least as long as bytesCount
if (_calldataAfterSelector.length < bytesCount) return false;
// Compare the end of the calldata with the allowed bytes
return
keccak256(
_calldataAfterSelector[_calldataAfterSelector.length - bytesCount:]
) == keccak256(rule.allowedBytes);
bool isAllowed = keccak256(_calldataAfterSelector[_calldataAfterSelector.length - bytesCount:]) == keccak256(rule.allowedBytes);
if (!isAllowed) {
return false;
} else {
continue; // skip further checks for this rule
}
}

return false; // Default to false if none of the conditions are met
Expand All @@ -181,7 +185,6 @@ contract P2pLendingProxyFactory is P2pLendingProxyFactoryStructs, ERC165, IP2pLe
}

/// @notice Creates a new P2pLendingProxy contract instance
/// @return P2pLendingProxy The new P2pLendingProxy contract instance
function _createP2pLendingProxy(uint96 _clientBasisPoints)
private
returns (P2pLendingProxy p2pLendingProxy)
Expand Down Expand Up @@ -246,7 +249,7 @@ contract P2pLendingProxyFactory is P2pLendingProxyFactoryStructs, ERC165, IP2pLe
/// @notice Calculates the salt required for deterministic clone creation
/// depending on client address and client basis points
/// @param _clientAddress address
/// @param _clientBasisPoints
/// @param _clientBasisPoints basis points (10000 = 100%)
/// @return bytes32 salt
function _getSalt(
address _clientAddress,
Expand All @@ -257,7 +260,7 @@ contract P2pLendingProxyFactory is P2pLendingProxyFactoryStructs, ERC165, IP2pLe
}

/// @inheritdoc ERC165
function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165) returns (bool) {
function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) {
return interfaceId == type(IP2pLendingProxyFactory).interfaceId ||
super.supportsInterface(interfaceId);
}
Expand Down

0 comments on commit fc98f0f

Please sign in to comment.