Skip to content
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

Merged
merged 7 commits into from
Jul 12, 2020
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 100 additions & 0 deletions contracts/schemes/TransitionScheme.sol
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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

uint -> uint256


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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this include reputation?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, reputation is recreated in the new DAO

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no

Copy link
Contributor

Choose a reason for hiding this comment

The 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?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure.

Copy link
Contributor

Choose a reason for hiding this comment

The 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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a standard selector per the ABI structure.

Copy link
Contributor

@dkent600 dkent600 Jul 9, 2020

Choose a reason for hiding this comment

The 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,
Copy link
Contributor

Choose a reason for hiding this comment

The 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 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean in terms of gas usage ..while iterating over the assets.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test with normal transfer ownership

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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;
Copy link
Contributor

Choose a reason for hiding this comment

The 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"
);
}
}
}
}
58 changes: 44 additions & 14 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@daostack/arc",
"version": "0.0.1-rc.41",
"version": "0.0.1-rc.42",
"description": "A platform for building DAOs",
"files": [
"contracts/",
Expand Down
Loading