@@ -12,6 +12,7 @@ import {IBorrower} from "./interfaces/IBorrower.sol";
1212import {IWrappedNativeToken} from "./interfaces/IWrappedNativeToken.sol " ;
1313import {HelperLib} from "./utils/HelperLib.sol " ;
1414import {NATIVE_TOKEN} from "./utils/Constants.sol " ;
15+ import {ISigner} from "./interfaces/ISigner.sol " ;
1516
1617/// @title Liquidity pool contract holds the liquidity asset and allows solvers to borrow
1718/// the asset from the pool and to perform an external function call upon providing the MPC signature.
@@ -23,7 +24,7 @@ import {NATIVE_TOKEN} from "./utils/Constants.sol";
2324/// Borrowing can be paused by the WITHDRAW_PROFIT_ROLE before withdrawing the profit.
2425/// The contract is pausable by the PAUSER_ROLE.
2526/// @author Tanya Bushenyova <[email protected] > 26- contract LiquidityPool is ILiquidityPool , AccessControl , EIP712 {
27+ contract LiquidityPool is ILiquidityPool , AccessControl , EIP712 , ISigner {
2728 using SafeERC20 for IERC20 ;
2829 using ECDSA for bytes32 ;
2930 using BitMaps for BitMaps.BitMap;
@@ -64,11 +65,15 @@ contract LiquidityPool is ILiquidityPool, AccessControl, EIP712 {
6465 bool public borrowPaused;
6566 address public mpcAddress;
6667
67- bytes32 public constant LIQUIDITY_ADMIN_ROLE = "LIQUIDITY_ADMIN_ROLE " ;
68- bytes32 public constant WITHDRAW_PROFIT_ROLE = "WITHDRAW_PROFIT_ROLE " ;
69- bytes32 public constant PAUSER_ROLE = "PAUSER_ROLE " ;
68+ bytes32 private constant LIQUIDITY_ADMIN_ROLE = "LIQUIDITY_ADMIN_ROLE " ;
69+ bytes32 private constant WITHDRAW_PROFIT_ROLE = "WITHDRAW_PROFIT_ROLE " ;
70+ bytes32 private constant PAUSER_ROLE = "PAUSER_ROLE " ;
71+ // bytes4(keccak256("isValidSignature(bytes32,bytes)")
72+ bytes4 constant internal MAGICVALUE = 0x1626ba7e ;
7073 IWrappedNativeToken immutable public WRAPPED_NATIVE_TOKEN;
7174
75+ address public signerAddress;
76+
7277 error ZeroAddress ();
7378 error InvalidSignature ();
7479 error NotEnoughToDeposit ();
@@ -91,6 +96,7 @@ contract LiquidityPool is ILiquidityPool, AccessControl, EIP712 {
9196 event BorrowPaused ();
9297 event BorrowUnpaused ();
9398 event MPCAddressSet (address oldMPCAddress , address newMPCAddress );
99+ event SignerAddressSet (address oldSignerAddress , address newSignerAddress );
94100 event Paused (address account );
95101 event Unpaused (address account );
96102
@@ -113,7 +119,8 @@ contract LiquidityPool is ILiquidityPool, AccessControl, EIP712 {
113119 address liquidityToken ,
114120 address admin ,
115121 address mpcAddress_ ,
116- address wrappedNativeToken
122+ address wrappedNativeToken ,
123+ address signerAddress_
117124 ) EIP712 ("LiquidityPool " , "1.0.0 " ) {
118125 require (liquidityToken != address (0 ), ZeroAddress ());
119126 ASSETS = IERC20 (liquidityToken);
@@ -122,6 +129,8 @@ contract LiquidityPool is ILiquidityPool, AccessControl, EIP712 {
122129 require (mpcAddress_ != address (0 ), ZeroAddress ());
123130 mpcAddress = mpcAddress_;
124131 WRAPPED_NATIVE_TOKEN = IWrappedNativeToken (wrappedNativeToken);
132+ require (signerAddress_ != address (0 ), ZeroAddress ());
133+ signerAddress = signerAddress_;
125134 }
126135
127136 receive () external payable {
@@ -309,6 +318,12 @@ contract LiquidityPool is ILiquidityPool, AccessControl, EIP712 {
309318 emit MPCAddressSet (oldMPCAddress, mpcAddress_);
310319 }
311320
321+ function setSignerAddress (address signerAddress_ ) external onlyRole (DEFAULT_ADMIN_ROLE) {
322+ address oldSignerAddress = signerAddress;
323+ signerAddress = signerAddress_;
324+ emit SignerAddressSet (oldSignerAddress, signerAddress_);
325+ }
326+
312327 function pauseBorrow () external override onlyRole (WITHDRAW_PROFIT_ROLE) {
313328 borrowPaused = true ;
314329 emit BorrowPaused ();
@@ -530,4 +545,15 @@ contract LiquidityPool is ILiquidityPool, AccessControl, EIP712 {
530545 function notPassed (uint256 timestamp ) internal view returns (bool ) {
531546 return ! passed (timestamp);
532547 }
548+
549+ function isValidSignature (bytes32 hash , bytes memory signature ) external view returns (bytes4 magicValue ) {
550+ if (signerAddress.code.length == 0 ) {
551+ // EOA
552+ address signerAddressRecovered = ECDSA.recover (hash, signature);
553+ if (signerAddressRecovered == signerAddress) return MAGICVALUE;
554+ else return 0xffffffff ;
555+ }
556+ // Contract
557+ return ISigner (signerAddress).isValidSignature (hash, signature);
558+ }
533559}
0 commit comments