-
Notifications
You must be signed in to change notification settings - Fork 50
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
feat: Add LSP7Votes and LSP8Votes extension to support LSP-based Governance #980
Open
YamenMerhi
wants to merge
5
commits into
develop
Choose a base branch
from
governance-lsp
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.
Open
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
225d30c
feat: Add LSP7Votes and LSP8Votes extensions
YamenMerhi f693398
test: Add LSP8Votes tests
YamenMerhi 30dcf4a
test: Add LSP7Votes test
YamenMerhi 08fbfcf
Merge branch 'develop' into governance-lsp
YamenMerhi 8e64b80
chore: resolver linter issues
YamenMerhi 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -441,19 +441,7 @@ abstract contract LSP7DigitalAssetCore is ILSP7DigitalAsset { | |
|
||
_beforeTokenTransfer(address(0), to, amount, data); | ||
|
||
// tokens being minted | ||
_existingTokens += amount; | ||
|
||
_tokenOwnerBalances[to] += amount; | ||
|
||
emit Transfer({ | ||
operator: msg.sender, | ||
from: address(0), | ||
to: to, | ||
amount: amount, | ||
force: force, | ||
data: data | ||
}); | ||
_update(address(0), to, amount, force, data); | ||
|
||
_afterTokenTransfer(address(0), to, amount, data); | ||
|
||
|
@@ -503,23 +491,7 @@ abstract contract LSP7DigitalAssetCore is ILSP7DigitalAsset { | |
|
||
_beforeTokenTransfer(from, address(0), amount, data); | ||
|
||
uint256 balance = _tokenOwnerBalances[from]; | ||
if (amount > balance) { | ||
revert LSP7AmountExceedsBalance(balance, from, amount); | ||
} | ||
// tokens being burnt | ||
_existingTokens -= amount; | ||
|
||
_tokenOwnerBalances[from] -= amount; | ||
|
||
emit Transfer({ | ||
operator: msg.sender, | ||
from: from, | ||
to: address(0), | ||
amount: amount, | ||
force: false, | ||
data: data | ||
}); | ||
_update(from, address(0), amount, false, data); | ||
|
||
_afterTokenTransfer(from, address(0), amount, data); | ||
|
||
|
@@ -614,29 +586,64 @@ abstract contract LSP7DigitalAssetCore is ILSP7DigitalAsset { | |
|
||
_beforeTokenTransfer(from, to, amount, data); | ||
|
||
uint256 balance = _tokenOwnerBalances[from]; | ||
if (amount > balance) { | ||
revert LSP7AmountExceedsBalance(balance, from, amount); | ||
_update(from, to, amount, force, data); | ||
|
||
_afterTokenTransfer(from, to, amount, data); | ||
|
||
bytes memory lsp1Data = abi.encode(msg.sender, from, to, amount, data); | ||
|
||
_notifyTokenSender(from, lsp1Data); | ||
_notifyTokenReceiver(to, force, lsp1Data); | ||
} | ||
|
||
/** | ||
* @dev Transfers a `value` amount of tokens from `from` to `to`, or alternatively mints (or burns) if `from` | ||
* (or `to`) is the zero address. All customizations to transfers, mints, and burns should be done by overriding | ||
* this function. | ||
* | ||
* Emits a {Transfer} event. | ||
*/ | ||
function _update( | ||
address from, | ||
address to, | ||
uint256 value, | ||
bool force, | ||
bytes memory data | ||
) internal virtual { | ||
if (from == address(0)) { | ||
// Overflow check required: The rest of the code assumes that totalSupply never overflows | ||
_existingTokens += value; | ||
} else { | ||
uint256 fromBalance = _tokenOwnerBalances[from]; | ||
if (fromBalance < value) { | ||
revert LSP7AmountExceedsBalance(fromBalance, from, value); | ||
} | ||
unchecked { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice this is inspired from OZ 🫡 |
||
// Overflow not possible: value <= fromBalance <= totalSupply. | ||
_tokenOwnerBalances[from] = fromBalance - value; | ||
} | ||
} | ||
|
||
_tokenOwnerBalances[from] -= amount; | ||
_tokenOwnerBalances[to] += amount; | ||
if (to == address(0)) { | ||
unchecked { | ||
// Overflow not possible: value <= totalSupply or value <= fromBalance <= totalSupply. | ||
_existingTokens -= value; | ||
} | ||
} else { | ||
unchecked { | ||
// Overflow not possible: balance + value is at most totalSupply, which we know fits into a uint256. | ||
_tokenOwnerBalances[to] += value; | ||
} | ||
} | ||
|
||
emit Transfer({ | ||
operator: msg.sender, | ||
from: from, | ||
to: to, | ||
amount: amount, | ||
amount: value, | ||
force: force, | ||
data: data | ||
}); | ||
|
||
_afterTokenTransfer(from, to, amount, data); | ||
|
||
bytes memory lsp1Data = abi.encode(msg.sender, from, to, amount, data); | ||
|
||
_notifyTokenSender(from, lsp1Data); | ||
_notifyTokenReceiver(to, force, lsp1Data); | ||
} | ||
|
||
/** | ||
|
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,65 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.0; | ||
|
||
import "@openzeppelin/contracts/governance/Governor.sol"; | ||
import "@openzeppelin/contracts/governance/extensions/GovernorSettings.sol"; | ||
import "@openzeppelin/contracts/governance/extensions/GovernorCountingSimple.sol"; | ||
import "@openzeppelin/contracts/governance/extensions/GovernorVotes.sol"; | ||
import "@openzeppelin/contracts/governance/extensions/GovernorVotesQuorumFraction.sol"; | ||
|
||
contract MyGovernor is | ||
Governor, | ||
GovernorSettings, | ||
GovernorCountingSimple, | ||
GovernorVotes, | ||
GovernorVotesQuorumFraction | ||
{ | ||
constructor( | ||
IVotes _token | ||
) | ||
Governor("MyGovernor") | ||
GovernorSettings(7200 /* 1 day */, 7200 /* 1 day */, 1e18) | ||
GovernorVotes(_token) | ||
GovernorVotesQuorumFraction(1) | ||
{} | ||
|
||
// The following functions are overrides required by Solidity. | ||
|
||
function votingDelay() | ||
public | ||
view | ||
override(IGovernor, GovernorSettings) | ||
returns (uint256) | ||
{ | ||
return super.votingDelay(); | ||
} | ||
|
||
function votingPeriod() | ||
public | ||
view | ||
override(IGovernor, GovernorSettings) | ||
returns (uint256) | ||
{ | ||
return super.votingPeriod(); | ||
} | ||
|
||
function quorum( | ||
uint256 blockNumber | ||
) | ||
public | ||
view | ||
override(IGovernor, GovernorVotesQuorumFraction) | ||
returns (uint256) | ||
{ | ||
return super.quorum(blockNumber); | ||
} | ||
|
||
function proposalThreshold() | ||
public | ||
view | ||
override(Governor, GovernorSettings) | ||
returns (uint256) | ||
{ | ||
return super.proposalThreshold(); | ||
} | ||
} |
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,19 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity ^0.8.0; | ||
|
||
import "../extensions/LSP7Votes.sol"; | ||
|
||
/** | ||
* @dev Mock of an LSP7Votes token | ||
*/ | ||
contract MyVotingToken is LSP7Votes { | ||
constructor() | ||
LSP7DigitalAsset("MyVotingToken", "MYVTKN", msg.sender, 0, false) | ||
EIP712("MyVotingToken", "1") | ||
{} | ||
|
||
function mint(address rec, uint256 amount) public { | ||
_mint(rec, amount, true, ""); | ||
} | ||
} |
Oops, something went wrong.
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.
Let's wait for #974 to be merged first, as the
Core
contract does not exist anymore,