-
Notifications
You must be signed in to change notification settings - Fork 25
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
Add Transition Scheme #769
Changes from 6 commits
302621a
86584f3
38f4887
54a164e
9031543
8fbf04d
a273869
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
pragma solidity 0.5.17; | ||
|
||
import "../controller/Controller.sol"; | ||
|
||
/** | ||
* @title A scheme for transitioning the DAO's assets to a new one. | ||
*/ | ||
|
||
contract TransitionScheme { | ||
|
||
uint public constant ASSETS_CAP = 100; | ||
|
||
event OwnershipTransferred(Avatar indexed _avatar, address indexed _newAvatar, address indexed _asset); | ||
|
||
Avatar public avatar; | ||
address payable public newAvatar; | ||
address[] public externalTokens; | ||
address[] public assetAddresses; | ||
bytes4[] public selectors; | ||
|
||
/** | ||
* @dev initialize | ||
* @param _avatar the avatar to migrate from | ||
* @param _newAvatar the avatar to migrate to | ||
* @param _externalTokens external tokens to allow transfer to the new avatar | ||
orenyodfat marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* @param _assetAddresses the assets to transfer | ||
* @param _selectors the functions to call to to transfer the assets | ||
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. Does this include reputation? 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. No, reputation is recreated in the new DAO 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. no 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. Is there any other plan for transferring rep from a 1.0 DAO to a 2.0 DAO? 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. sure. 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. Would be good to document here the form a function must take, like what parameters and return value. 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. It is a standard selector per the ABI structure. 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. A selector is an ABI specification for any arbitrary function. Don't the selectors in this list have to specify functions that have a specific set of parameters and parameter types? |
||
*/ | ||
function initialize( | ||
Avatar _avatar, | ||
address payable _newAvatar, | ||
address[] calldata _externalTokens, | ||
address[] calldata _assetAddresses, | ||
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. how about cap the number of asserts with a number which is applicable ? 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. Why? The number of assets is determined in the initialized, so the DAO knows how many and which assets will be transferred before adding the scheme. 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. I mean in terms of gas usage ..while iterating over the assets. 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. I think we can do enough assets at a time to make it unnecessary, but if you want we can add it. I could add a test to see how many we can do at a time but it'd be just a rough estimation as different assets will probably cost differently. 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. test with normal transfer ownership 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. ok I added a test transferring 101 assets. |
||
bytes4[] calldata _selectors | ||
) external { | ||
require(_assetAddresses.length <= ASSETS_CAP, "cannot transfer more than 100 assets"); | ||
require(_assetAddresses.length == _selectors.length, "Arrays length mismatch"); | ||
require(avatar == Avatar(0), "can be called only one time"); | ||
require(_avatar != Avatar(0), "avatar cannot be zero"); | ||
avatar = _avatar; | ||
newAvatar = _newAvatar; | ||
externalTokens = _externalTokens; | ||
assetAddresses = _assetAddresses; | ||
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. lets cap this array length with 100 |
||
selectors = _selectors; | ||
} | ||
|
||
/** | ||
* @dev transferAssets function | ||
* transfer the DAO assets to a new DAO | ||
*/ | ||
function transferAssets() external { | ||
for (uint256 i=0; i < assetAddresses.length; i++) { | ||
bytes memory genericCallReturnValue; | ||
bool success; | ||
Controller controller = Controller(avatar.owner()); | ||
(success, genericCallReturnValue) = | ||
controller.genericCall( | ||
assetAddresses[i], | ||
abi.encodeWithSelector(selectors[i], newAvatar), | ||
orenyodfat marked this conversation as resolved.
Show resolved
Hide resolved
|
||
avatar, | ||
0 | ||
orenyodfat marked this conversation as resolved.
Show resolved
Hide resolved
|
||
); | ||
if (success) { | ||
emit OwnershipTransferred(avatar, newAvatar, assetAddresses[i]); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* @dev sendEther function | ||
* @param _amount the amount of ether to send to the new avatar | ||
*/ | ||
function sendEther(uint256 _amount) external { | ||
require( | ||
Controller(avatar.owner()).sendEther(_amount, newAvatar, avatar), | ||
"Sending ether should succeed" | ||
); | ||
} | ||
|
||
/** | ||
* @dev sendExternalToken function | ||
* @param _amounts the amounts of tokens to send to the new avatar | ||
*/ | ||
function sendExternalToken(uint256[] calldata _amounts) external { | ||
require(externalTokens.length == _amounts.length, "Arrays length mismatch"); | ||
for (uint256 i=0; i < externalTokens.length; i++) { | ||
if (_amounts[i] > 0) { | ||
require( | ||
Controller(avatar.owner()).externalTokenTransfer( | ||
IERC20(externalTokens[i]), | ||
newAvatar, | ||
_amounts[i], | ||
avatar | ||
), | ||
"Sending external token should succeed" | ||
); | ||
} | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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.
uint -> uint256