-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
commitment allowlist managers #44
Draft
ethereumdegen
wants to merge
17
commits into
develop
Choose a base branch
from
feature/commitment-allowlists
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
74ee0c4
drafted and compiles
ethereumdegen aa5cbfd
tests compile
ethereumdegen 11af358
added fix to require legacy commitments with nonzero allowlist to set…
ethereumdegen 7f871a2
conv to storage
ethereumdegen d96677e
test passes
ethereumdegen d8fe3a2
adding tests for 721
ethereumdegen 20a2c08
adding method to update the manager address for a commitment
ethereumdegen bb0981f
emit second event
ethereumdegen 7a0e6f3
yarn lock
ethereumdegen 18abc29
ignore
ethereumdegen 71d8d67
Merge branch 'develop' into feature/commitment-allowlists
ethereumdegen 6ab0ffa
restructure enumerable set allowlist
ethereumdegen 6c43d7d
trying to call set allowlist
ethereumdegen 9b69489
tests pass
ethereumdegen 16f6dc2
Merge branch 'develop' into feature/commitment-allowlists
ethereumdegen 58cc530
merge
ethereumdegen 2eee3b0
fix up deploy scripts
ethereumdegen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
packages/contracts/contracts/allowlist/ERC721Allowlist.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
|
||
pragma solidity >=0.8.0 <0.9.0; | ||
// SPDX-License-Identifier: MIT | ||
import "../interfaces/allowlist/IAllowlistManager.sol"; | ||
|
||
import "../interfaces/allowlist/IERC721Allowlist.sol"; | ||
|
||
import "@openzeppelin/contracts-upgradeable/token/ERC721/IERC721Upgradeable.sol"; | ||
|
||
contract ERC721Allowlist is IAllowlistManager,IERC721Allowlist { | ||
|
||
event UpdatedAllowList(uint256 commitmentId); | ||
|
||
|
||
IERC721Upgradeable public immutable accessToken; //IERC721 | ||
|
||
|
||
|
||
constructor(address _accessToken){ | ||
accessToken = IERC721Upgradeable(_accessToken); | ||
} | ||
|
||
function addressIsAllowed(uint256 _commitmentId, address _account) public virtual returns (bool) { | ||
return accessToken.balanceOf(_account) >= 1; | ||
} | ||
|
||
/* | ||
function getAllowedAddresses(uint256 _commitmentId) | ||
public | ||
view | ||
returns (address[] memory borrowers_) | ||
{ | ||
borrowers_ = allowList[_commitmentId].values(); | ||
}*/ | ||
|
||
} |
72 changes: 72 additions & 0 deletions
72
packages/contracts/contracts/allowlist/EnumerableSetAllowlist.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
pragma solidity >=0.8.0 <0.9.0; | ||
// SPDX-License-Identifier: MIT | ||
|
||
import "../interfaces/allowlist/IAllowlistManager.sol"; | ||
import "../interfaces/allowlist/IEnumerableSetAllowlist.sol"; | ||
|
||
import "../interfaces/ILenderCommitmentForwarder.sol"; | ||
|
||
import "@openzeppelin/contracts-upgradeable/utils/structs/EnumerableSetUpgradeable.sol"; | ||
|
||
|
||
contract EnumerableSetAllowlist is IAllowlistManager,IEnumerableSetAllowlist { | ||
using EnumerableSetUpgradeable for EnumerableSetUpgradeable.AddressSet; | ||
|
||
event UpdatedAllowList(uint256 commitmentId); | ||
|
||
address public immutable commitmentManager; | ||
|
||
mapping(uint256 => EnumerableSetUpgradeable.AddressSet) internal allowList; | ||
|
||
modifier onlyCommitmentOwner(uint256 _commitmentId){ | ||
require(msg.sender == ILenderCommitmentForwarder(commitmentManager).getCommitmentLender(_commitmentId),"Must be the lender of the commitment."); | ||
_; | ||
} | ||
|
||
constructor(address _commitmentManager){ | ||
commitmentManager = _commitmentManager; | ||
} | ||
|
||
|
||
function setAllowlist( | ||
uint256 _commitmentId, | ||
address[] calldata _addressList | ||
) public | ||
onlyCommitmentOwner(_commitmentId) | ||
{ | ||
|
||
delete allowList[_commitmentId]; | ||
_addToAllowlist(_commitmentId, _addressList); | ||
} | ||
|
||
|
||
/** | ||
* @notice Adds a addresses to the allowlist for a commmitment. | ||
* @param _commitmentId The id of the commitment that will allow the new borrower | ||
* @param _addressList the address array that will be allowed to accept loans using the commitment | ||
*/ | ||
function _addToAllowlist( | ||
uint256 _commitmentId, | ||
address[] calldata _addressList | ||
) internal virtual { | ||
|
||
for (uint256 i = 0; i < _addressList.length; i++) { | ||
allowList[_commitmentId].add(_addressList[i]); | ||
} | ||
emit UpdatedAllowList(_commitmentId); | ||
} | ||
|
||
|
||
function addressIsAllowed(uint256 _commitmentId, address _account) public virtual returns (bool) { | ||
return allowList[_commitmentId].contains(_account); | ||
} | ||
|
||
function getAllowedAddresses(uint256 _commitmentId) | ||
public | ||
view | ||
returns (address[] memory borrowers_) | ||
{ | ||
borrowers_ = allowList[_commitmentId].values(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
|
||
pragma solidity >=0.8.0 <0.9.0; | ||
// SPDX-License-Identifier: MIT | ||
import "../interfaces/allowlist/IAllowlistManager.sol"; | ||
|
||
|
||
contract OpenAllowlist is IAllowlistManager { | ||
|
||
event UpdatedAllowList(uint256 commitmentId); | ||
|
||
constructor( ){ | ||
|
||
} | ||
|
||
function addressIsAllowed(uint256, address) public virtual returns (bool) { | ||
return true; | ||
} | ||
|
||
|
||
} |
9 changes: 9 additions & 0 deletions
9
packages/contracts/contracts/interfaces/ILenderCommitmentForwarder.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// SPDX-Licence-Identifier: MIT | ||
pragma solidity >=0.8.0 <0.9.0; | ||
|
||
|
||
interface ILenderCommitmentForwarder { | ||
|
||
function getCommitmentLender(uint256 _commitmentId) external returns (address lender_); | ||
|
||
} |
9 changes: 9 additions & 0 deletions
9
packages/contracts/contracts/interfaces/allowlist/IAllowlistManager.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
|
||
|
||
|
||
interface IAllowlistManager { | ||
|
||
|
||
function addressIsAllowed(uint256 _commitmentId,address _account) external returns (bool allowed_) ; | ||
|
||
} |
6 changes: 6 additions & 0 deletions
6
packages/contracts/contracts/interfaces/allowlist/IERC721Allowlist.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
|
||
|
||
interface IERC721Allowlist { | ||
|
||
|
||
} |
11 changes: 11 additions & 0 deletions
11
packages/contracts/contracts/interfaces/allowlist/IEnumerableSetAllowlist.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
|
||
|
||
|
||
interface IEnumerableSetAllowlist { | ||
|
||
function setAllowlist( | ||
uint256 _commitmentId, | ||
address[] calldata _addressList | ||
) external; | ||
|
||
} |
11 changes: 11 additions & 0 deletions
11
packages/contracts/contracts/mock/AllowlistManagerMock.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
|
||
import "../interfaces/allowlist/IAllowlistManager.sol"; | ||
contract AllowlistManagerMock is IAllowlistManager { | ||
|
||
|
||
function addressIsAllowed(uint256 _commitmentId, address _account) public returns (bool _allowed) { | ||
return true; | ||
} | ||
|
||
|
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we want to include this in the repo - this is a link to the commit used by the submodule