Skip to content

Commit

Permalink
Merge pull request #54 from mysofinance/v_1_1_lpWhitelist
Browse files Browse the repository at this point in the history
V 1 1 lp whitelist
  • Loading branch information
jpick713 authored Jan 13, 2023
2 parents ca66f4e + 7a7420e commit 8bf42c9
Show file tree
Hide file tree
Showing 11 changed files with 406 additions and 42 deletions.
45 changes: 28 additions & 17 deletions contracts/BasePool_v_1_1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ abstract contract BasePool_v_1_1 is IBasePool_v_1_1 {
uint256 constant MAX_FEE = 500 * 10 ** 14; // 5%, denominated in BASE
uint256 minLiquidity; // denominated in loanCcy decimals

address poolCreator;
address public poolCreator;
address poolCreatorProposal;
address collCcyToken;
address loanCcyToken;
Expand All @@ -74,6 +74,7 @@ abstract contract BasePool_v_1_1 is IBasePool_v_1_1 {
mapping(address => uint256) lastAddOfTxOrigin;
mapping(uint256 => LoanInfo) public loanIdxToLoanInfo;
mapping(uint256 => address) public loanIdxToBorrower;
mapping(address => bool) public lpWhitelist;

mapping(address => mapping(address => mapping(IBasePool_v_1_1.ApprovalTypes => bool)))
public isApproved;
Expand Down Expand Up @@ -145,11 +146,10 @@ abstract contract BasePool_v_1_1 is IBasePool_v_1_1 {
uint256 _referralCode
) external override {
// verify LP info and eligibility
if (!(msg.sender == _onBehalfOf && lpWhitelist[msg.sender])) {
revert UnapprovedSender();
}
checkTimestamp(_deadline);
checkSenderApproval(
_onBehalfOf,
IBasePool_v_1_1.ApprovalTypes.ADD_LIQUIDITY
);

uint128 _inAmountAfterFees = _sendAmount -
getLoanCcyTransferFee(_sendAmount);
Expand Down Expand Up @@ -551,15 +551,31 @@ abstract contract BasePool_v_1_1 is IBasePool_v_1_1 {
}

function proposeNewCreator(address newAddr) external {
if (msg.sender == poolCreator) {
poolCreatorProposal = newAddr;
if (msg.sender != poolCreator) {
revert UnapprovedSender();
}
poolCreatorProposal = newAddr;
}

function claimCreator() external {
if (msg.sender == poolCreatorProposal) {
poolCreator = msg.sender;
if (msg.sender != poolCreatorProposal) {
revert UnapprovedSender();
}
address prevPoolCreator = poolCreator;
lpWhitelist[prevPoolCreator] = false;
lpWhitelist[msg.sender] = true;
poolCreator = msg.sender;
emit LpWhitelistUpdate(prevPoolCreator, false);
emit LpWhitelistUpdate(msg.sender, true);
}

function toggleLpWhitelist(address newAddr) external {
if (msg.sender != poolCreator) {
revert UnapprovedSender();
}
bool newIsApproved = !lpWhitelist[newAddr];
lpWhitelist[newAddr] = newIsApproved;
emit LpWhitelistUpdate(newAddr, newIsApproved);
}

function getLpInfo(
Expand Down Expand Up @@ -1138,25 +1154,20 @@ abstract contract BasePool_v_1_1 is IBasePool_v_1_1 {
* @notice Helper function called whenever reinvestment is possible
* @dev This function is called by claim and claimFromAggregated if reinvestment is desired
* @param _deadline Last timestamp after which function will revert
* @param _onBehalfOf Recipient of the reinvested LP shares
*/
function claimReinvestmentCheck(
uint256 _deadline,
address _onBehalfOf
address /*_onBehalfOf*/
) internal view {
checkTimestamp(_deadline);
checkSenderApproval(
_onBehalfOf,
IBasePool_v_1_1.ApprovalTypes.ADD_LIQUIDITY
);
}

/**
* @notice Helper function checks if function caller is a valid sender
* @dev This function is called by addLiquidity, removeLiquidity, repay,
* rollOver, claim, claimFromAggregated, claimReinvestmentCheck (ADD_LIQUIDITY)
* rollOver, claim, claimFromAggregated, claimReinvestmentCheck
* @param _ownerOrBeneficiary Address which will be owner or beneficiary of transaction if approved
* @param _approvalType Type of approval requested { REPAY, ROLLOVER, ADD_LIQUIDITY, REMOVE_LIQUIDITY, CLAIM }
* @param _approvalType Type of approval requested { REPAY, ROLLOVER, REMOVE_LIQUIDITY, CLAIM }
*/
function checkSenderApproval(
address _ownerOrBeneficiary,
Expand Down
3 changes: 1 addition & 2 deletions contracts/interfaces/IBasePool_v_1_1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,9 @@ interface IBasePool_v_1_1 {
uint256 liquidityBnd1,
uint256 liquidityBnd2
);

event LpWhitelistUpdate(address indexed lpAddr, bool isApproved);
enum ApprovalTypes {
REPAY,
ADD_LIQUIDITY,
REMOVE_LIQUIDITY,
CLAIM
}
Expand Down
2 changes: 1 addition & 1 deletion contracts/pools/rpl-usdc/PoolRplUsdc_v_1_1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ contract PoolRplUsdc_v_1_1 is BasePool_v_1_1 {
uint256 _liquidityBnd2
) external {
if (msg.sender != poolCreator) {
revert();
revert UnapprovedSender();
}
if (_maxLoanPerColl == 0) revert InvalidMaxLoanPerColl();
if (_r1 <= _r2 || _r2 == 0) revert InvalidRateParams();
Expand Down
72 changes: 72 additions & 0 deletions docs/BasePool_v_1_1.md
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,28 @@ Function which calculates loan terms
| _creatorFee | uint256 | Amount of collateral currency to be transferred to treasury |
| _totalLiquidity | uint256 | The total liquidity of the pool (pre-borrow) that is available for new loans |

### lpWhitelist

```solidity
function lpWhitelist(address) external view returns (bool)
```





#### Parameters

| Name | Type | Description |
|---|---|---|
| _0 | address | undefined |

#### Returns

| Name | Type | Description |
|---|---|---|
| _0 | bool | undefined |

### overrideSharePointer

```solidity
Expand All @@ -326,6 +348,23 @@ Function will update the share pointer for the LP
|---|---|---|
| _newSharePointer | uint256 | New location of the LP&#39;s current share pointer |

### poolCreator

```solidity
function poolCreator() external view returns (address)
```






#### Returns

| Name | Type | Description |
|---|---|---|
| _0 | address | undefined |

### proposeNewCreator

```solidity
Expand Down Expand Up @@ -394,6 +433,22 @@ Function which sets approval for another to perform a certain function on sender
| _approvee | address | This address is being given approval for the action(s) by the current sender |
| _packedApprovals | uint256 | Packed boolean flags to set which actions are approved or not approved, where e.g. &quot;00001&quot; refers to ApprovalTypes.Repay (=0) and &quot;10000&quot; to ApprovalTypes.Claim (=4) |

### toggleLpWhitelist

```solidity
function toggleLpWhitelist(address newAddr) external nonpayable
```





#### Parameters

| Name | Type | Description |
|---|---|---|
| newAddr | address | undefined |



## Events
Expand Down Expand Up @@ -501,6 +556,23 @@ event ClaimFromAggregated(address indexed lp, uint256 fromLoanIdx, uint256 toLoa
| repayments | uint256 | undefined |
| collateral | uint256 | undefined |

### LpWhitelistUpdate

```solidity
event LpWhitelistUpdate(address indexed lpAddr, bool isApproved)
```





#### Parameters

| Name | Type | Description |
|---|---|---|
| lpAddr `indexed` | address | undefined |
| isApproved | bool | undefined |

### NewSubPool

```solidity
Expand Down
17 changes: 17 additions & 0 deletions docs/interfaces/IBasePool_v_1_1.md
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,23 @@ event ClaimFromAggregated(address indexed lp, uint256 fromLoanIdx, uint256 toLoa
| repayments | uint256 | undefined |
| collateral | uint256 | undefined |

### LpWhitelistUpdate

```solidity
event LpWhitelistUpdate(address indexed lpAddr, bool isApproved)
```





#### Parameters

| Name | Type | Description |
|---|---|---|
| lpAddr `indexed` | address | undefined |
| isApproved | bool | undefined |

### NewSubPool

```solidity
Expand Down
72 changes: 72 additions & 0 deletions docs/pools/rpl-usdc/PoolRplUsdc_v_1_1.md
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,28 @@ Function which calculates loan terms
| _creatorFee | uint256 | Amount of collateral currency to be transferred to treasury |
| _totalLiquidity | uint256 | The total liquidity of the pool (pre-borrow) that is available for new loans |

### lpWhitelist

```solidity
function lpWhitelist(address) external view returns (bool)
```





#### Parameters

| Name | Type | Description |
|---|---|---|
| _0 | address | undefined |

#### Returns

| Name | Type | Description |
|---|---|---|
| _0 | bool | undefined |

### overrideSharePointer

```solidity
Expand All @@ -326,6 +348,23 @@ Function will update the share pointer for the LP
|---|---|---|
| _newSharePointer | uint256 | New location of the LP&#39;s current share pointer |

### poolCreator

```solidity
function poolCreator() external view returns (address)
```






#### Returns

| Name | Type | Description |
|---|---|---|
| _0 | address | undefined |

### proposeNewCreator

```solidity
Expand Down Expand Up @@ -394,6 +433,22 @@ Function which sets approval for another to perform a certain function on sender
| _approvee | address | This address is being given approval for the action(s) by the current sender |
| _packedApprovals | uint256 | Packed boolean flags to set which actions are approved or not approved, where e.g. &quot;00001&quot; refers to ApprovalTypes.Repay (=0) and &quot;10000&quot; to ApprovalTypes.Claim (=4) |

### toggleLpWhitelist

```solidity
function toggleLpWhitelist(address newAddr) external nonpayable
```





#### Parameters

| Name | Type | Description |
|---|---|---|
| newAddr | address | undefined |

### updateTerms

```solidity
Expand Down Expand Up @@ -522,6 +577,23 @@ event ClaimFromAggregated(address indexed lp, uint256 fromLoanIdx, uint256 toLoa
| repayments | uint256 | undefined |
| collateral | uint256 | undefined |

### LpWhitelistUpdate

```solidity
event LpWhitelistUpdate(address indexed lpAddr, bool isApproved)
```





#### Parameters

| Name | Type | Description |
|---|---|---|
| lpAddr `indexed` | address | undefined |
| isApproved | bool | undefined |

### NewSubPool

```solidity
Expand Down
Loading

0 comments on commit 8bf42c9

Please sign in to comment.