move all state variables to seperate contract
By placing all state variables in 1 place, this allows us to add additional state at a later date, and not overwrite an existing state variable. Also optimized struct layout to better pack
This commit is contained in:
parent
6c8355e346
commit
93e910cc97
|
@ -54,7 +54,7 @@ contract LiquidPledging is LiquidPledgingBase {
|
|||
public payable
|
||||
{
|
||||
require(idGiver > 0); // prevent burning donations. idReceiver is checked in _transfer
|
||||
PledgeAdmins.PledgeAdmin storage sender = _findAdmin(idGiver);
|
||||
PledgeAdmin storage sender = _findAdmin(idGiver);
|
||||
require(sender.adminType == PledgeAdminType.Giver);
|
||||
|
||||
uint amount = msg.value;
|
||||
|
@ -70,10 +70,10 @@ contract LiquidPledging is LiquidPledgingBase {
|
|||
0,
|
||||
0,
|
||||
0,
|
||||
Pledges.PledgeState.Pledged
|
||||
PledgeState.Pledged
|
||||
);
|
||||
|
||||
Pledges.Pledge storage pTo = _findPledge(idPledge);
|
||||
Pledge storage pTo = _findPledge(idPledge);
|
||||
pTo.amount += amount;
|
||||
|
||||
Transfer(0, idPledge, amount);
|
||||
|
@ -108,10 +108,10 @@ contract LiquidPledging is LiquidPledgingBase {
|
|||
function withdraw(uint64 idPledge, uint amount) public {
|
||||
idPledge = normalizePledge(idPledge); // Updates pledge info
|
||||
|
||||
Pledges.Pledge storage p = _findPledge(idPledge);
|
||||
Pledge storage p = _findPledge(idPledge);
|
||||
require(p.pledgeState == PledgeState.Pledged);
|
||||
|
||||
PledgeAdmins.PledgeAdmin storage owner = _findAdmin(p.owner);
|
||||
PledgeAdmin storage owner = _findAdmin(p.owner);
|
||||
require(canPerform(msg.sender, PLEDGE_ADMIN_ROLE, arr(uint(p.owner))));
|
||||
|
||||
uint64 idNewPledge = _findOrCreatePledge(
|
||||
|
@ -120,7 +120,7 @@ contract LiquidPledging is LiquidPledgingBase {
|
|||
0,
|
||||
0,
|
||||
p.oldPledge,
|
||||
Pledges.PledgeState.Paying
|
||||
PledgeState.Paying
|
||||
);
|
||||
|
||||
_doTransfer(idPledge, idNewPledge, amount);
|
||||
|
@ -128,14 +128,14 @@ contract LiquidPledging is LiquidPledgingBase {
|
|||
vault.authorizePayment(bytes32(idNewPledge), owner.addr, amount);
|
||||
}
|
||||
|
||||
/// @notice `onlyVault` Confirms a withdraw request changing the Pledges.PledgeState
|
||||
/// @notice `onlyVault` Confirms a withdraw request changing the PledgeState
|
||||
/// from Paying to Paid
|
||||
/// @param idPledge Id of the pledge that is to be withdrawn
|
||||
/// @param amount Quantity of ether (in wei) to be withdrawn
|
||||
function confirmPayment(uint64 idPledge, uint amount) public onlyVault {
|
||||
Pledges.Pledge storage p = _findPledge(idPledge);
|
||||
Pledge storage p = _findPledge(idPledge);
|
||||
|
||||
require(p.pledgeState == Pledges.PledgeState.Paying);
|
||||
require(p.pledgeState == PledgeState.Paying);
|
||||
|
||||
uint64 idNewPledge = _findOrCreatePledge(
|
||||
p.owner,
|
||||
|
@ -143,20 +143,20 @@ contract LiquidPledging is LiquidPledgingBase {
|
|||
0,
|
||||
0,
|
||||
p.oldPledge,
|
||||
Pledges.PledgeState.Paid
|
||||
PledgeState.Paid
|
||||
);
|
||||
|
||||
_doTransfer(idPledge, idNewPledge, amount);
|
||||
}
|
||||
|
||||
/// @notice `onlyVault` Cancels a withdraw request, changing the Pledges.PledgeState
|
||||
/// @notice `onlyVault` Cancels a withdraw request, changing the PledgeState
|
||||
/// from Paying back to Pledged
|
||||
/// @param idPledge Id of the pledge that's withdraw is to be canceled
|
||||
/// @param amount Quantity of ether (in wei) to be canceled
|
||||
function cancelPayment(uint64 idPledge, uint amount) public onlyVault {
|
||||
Pledges.Pledge storage p = _findPledge(idPledge);
|
||||
Pledge storage p = _findPledge(idPledge);
|
||||
|
||||
require(p.pledgeState == Pledges.PledgeState.Paying);
|
||||
require(p.pledgeState == PledgeState.Paying);
|
||||
|
||||
// When a payment is canceled, never is assigned to a project.
|
||||
uint64 idOldPledge = _findOrCreatePledge(
|
||||
|
@ -165,7 +165,7 @@ contract LiquidPledging is LiquidPledgingBase {
|
|||
0,
|
||||
0,
|
||||
p.oldPledge,
|
||||
Pledges.PledgeState.Pledged
|
||||
PledgeState.Pledged
|
||||
);
|
||||
|
||||
idOldPledge = normalizePledge(idOldPledge);
|
||||
|
@ -176,7 +176,7 @@ contract LiquidPledging is LiquidPledgingBase {
|
|||
/// @notice Changes the `project.canceled` flag to `true`; cannot be undone
|
||||
/// @param idProject Id of the project that is to be canceled
|
||||
function cancelProject(uint64 idProject) authP(PLEDGE_ADMIN_ROLE, arr(uint(idProject))) public {
|
||||
PledgeAdmins.PledgeAdmin storage project = _findAdmin(idProject);
|
||||
PledgeAdmin storage project = _findAdmin(idProject);
|
||||
// _checkAdminOwner(project);
|
||||
project.canceled = true;
|
||||
|
||||
|
@ -191,7 +191,7 @@ contract LiquidPledging is LiquidPledgingBase {
|
|||
function cancelPledge(uint64 idPledge, uint amount) public {
|
||||
idPledge = normalizePledge(idPledge);
|
||||
|
||||
Pledges.Pledge storage p = _findPledge(idPledge);
|
||||
Pledge storage p = _findPledge(idPledge);
|
||||
require(p.oldPledge != 0);
|
||||
|
||||
require(canPerform(msg.sender, PLEDGE_ADMIN_ROLE, arr(uint(p.owner))));
|
||||
|
|
|
@ -19,31 +19,20 @@ pragma solidity ^0.4.18;
|
|||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import "./ILiquidPledgingPlugin.sol";
|
||||
// import "giveth-common-contracts/contracts/Escapable.sol";
|
||||
import "./EscapableApp.sol";
|
||||
import "./LiquidPledgingStorage.sol";
|
||||
import "./PledgeAdmins.sol";
|
||||
import "./Pledges.sol";
|
||||
|
||||
/// @dev This is an interface for `LPVault` which serves as a secure storage for
|
||||
/// the ETH that backs the Pledges, only after `LiquidPledging` authorizes
|
||||
/// payments can Pledges be converted for ETH
|
||||
interface ILPVault {
|
||||
function authorizePayment(bytes32 _ref, address _dest, uint _amount) public;
|
||||
function () public payable;
|
||||
}
|
||||
import "./EscapableApp.sol";
|
||||
|
||||
/// @dev `LiquidPledgingBase` is the base level contract used to carry out
|
||||
/// liquidPledging's most basic functions, mostly handling and searching the
|
||||
/// data structures
|
||||
contract LiquidPledgingBase is PledgeAdmins, Pledges, EscapableApp {
|
||||
contract LiquidPledgingBase is LiquidPledgingStorage, PledgeAdmins, Pledges, EscapableApp {
|
||||
|
||||
// Event Declarations
|
||||
event Transfer(uint indexed from, uint indexed to, uint amount);
|
||||
event CancelProject(uint indexed idProject);
|
||||
|
||||
ILPVault public vault;
|
||||
|
||||
/////////////
|
||||
// Modifiers
|
||||
/////////////
|
||||
|
@ -99,7 +88,7 @@ contract LiquidPledgingBase is PledgeAdmins, Pledges, EscapableApp {
|
|||
name = delegate.name;
|
||||
}
|
||||
|
||||
/// @notice Only affects pledges with the Pledged Pledges.PledgeState for 2 things:
|
||||
/// @notice Only affects pledges with the Pledged PledgeState for 2 things:
|
||||
/// #1: Checks if the pledge should be committed. This means that
|
||||
/// if the pledge has an intendedProject and it is past the
|
||||
/// commitTime, it changes the owner to be the proposed project
|
||||
|
@ -117,11 +106,11 @@ contract LiquidPledgingBase is PledgeAdmins, Pledges, EscapableApp {
|
|||
/// @param idPledge This is the id of the pledge that will be normalized
|
||||
/// @return The normalized Pledge!
|
||||
function normalizePledge(uint64 idPledge) public returns(uint64) {
|
||||
Pledges.Pledge storage p = _findPledge(idPledge);
|
||||
Pledge storage p = _findPledge(idPledge);
|
||||
|
||||
// Check to make sure this pledge hasn't already been used
|
||||
// or is in the process of being used
|
||||
if (p.pledgeState != Pledges.PledgeState.Pledged) {
|
||||
if (p.pledgeState != PledgeState.Pledged) {
|
||||
return idPledge;
|
||||
}
|
||||
|
||||
|
@ -133,7 +122,7 @@ contract LiquidPledgingBase is PledgeAdmins, Pledges, EscapableApp {
|
|||
0,
|
||||
0,
|
||||
p.oldPledge,
|
||||
Pledges.PledgeState.Pledged
|
||||
PledgeState.Pledged
|
||||
);
|
||||
uint64 toPledge = _findOrCreatePledge(
|
||||
p.intendedProject,
|
||||
|
@ -141,7 +130,7 @@ contract LiquidPledgingBase is PledgeAdmins, Pledges, EscapableApp {
|
|||
0,
|
||||
0,
|
||||
oldPledge,
|
||||
Pledges.PledgeState.Pledged
|
||||
PledgeState.Pledged
|
||||
);
|
||||
_doTransfer(idPledge, toPledge, p.amount);
|
||||
idPledge = toPledge;
|
||||
|
@ -170,19 +159,19 @@ contract LiquidPledgingBase is PledgeAdmins, Pledges, EscapableApp {
|
|||
require(idReceiver > 0); // prevent burning value
|
||||
idPledge = normalizePledge(idPledge);
|
||||
|
||||
Pledges.Pledge storage p = _findPledge(idPledge);
|
||||
PledgeAdmins.PledgeAdmin storage receiver = _findAdmin(idReceiver);
|
||||
Pledge storage p = _findPledge(idPledge);
|
||||
PledgeAdmin storage receiver = _findAdmin(idReceiver);
|
||||
|
||||
require(p.pledgeState == PledgeState.Pledged);
|
||||
|
||||
// If the sender is the owner of the Pledge
|
||||
if (p.owner == idSender) {
|
||||
|
||||
if (receiver.adminType == PledgeAdmins.PledgeAdminType.Giver) {
|
||||
if (receiver.adminType == PledgeAdminType.Giver) {
|
||||
_transferOwnershipToGiver(idPledge, amount, idReceiver);
|
||||
} else if (receiver.adminType == PledgeAdmins.PledgeAdminType.Project) {
|
||||
} else if (receiver.adminType == PledgeAdminType.Project) {
|
||||
_transferOwnershipToProject(idPledge, amount, idReceiver);
|
||||
} else if (receiver.adminType == PledgeAdmins.PledgeAdminType.Delegate) {
|
||||
} else if (receiver.adminType == PledgeAdminType.Delegate) {
|
||||
|
||||
uint recieverDIdx = _getDelegateIdx(p, idReceiver);
|
||||
if (p.intendedProject > 0 && recieverDIdx != NOTFOUND) {
|
||||
|
@ -197,7 +186,7 @@ contract LiquidPledgingBase is PledgeAdmins, Pledges, EscapableApp {
|
|||
0,
|
||||
0,
|
||||
p.oldPledge,
|
||||
Pledges.PledgeState.Pledged);
|
||||
PledgeState.Pledged);
|
||||
_doTransfer(idPledge, toPledge, amount);
|
||||
} else {
|
||||
_undelegate(idPledge, amount, p.delegationChain.length - receiverDIdx - 1);
|
||||
|
@ -226,7 +215,7 @@ contract LiquidPledgingBase is PledgeAdmins, Pledges, EscapableApp {
|
|||
if (senderDIdx != NOTFOUND) {
|
||||
|
||||
// And the receiver is another Giver
|
||||
if (receiver.adminType == PledgeAdmins.PledgeAdminType.Giver) {
|
||||
if (receiver.adminType == PledgeAdminType.Giver) {
|
||||
// Only transfer to the Giver who owns the pledge
|
||||
assert(p.owner == idReceiver);
|
||||
_undelegate(idPledge, amount, p.delegationChain.length);
|
||||
|
@ -234,7 +223,7 @@ contract LiquidPledgingBase is PledgeAdmins, Pledges, EscapableApp {
|
|||
}
|
||||
|
||||
// And the receiver is another Delegate
|
||||
if (receiver.adminType == PledgeAdmins.PledgeAdminType.Delegate) {
|
||||
if (receiver.adminType == PledgeAdminType.Delegate) {
|
||||
uint receiverDIdx = _getDelegateIdx(p, idReceiver);
|
||||
|
||||
// And not in the delegationChain
|
||||
|
@ -272,7 +261,7 @@ contract LiquidPledgingBase is PledgeAdmins, Pledges, EscapableApp {
|
|||
|
||||
// And the receiver is a Project, all the delegates after the sender
|
||||
// are removed and the amount is pre-committed to the project
|
||||
if (receiver.adminType == PledgeAdmins.PledgeAdminType.Project) {
|
||||
if (receiver.adminType == PledgeAdminType.Project) {
|
||||
idPledge = _undelegate(
|
||||
idPledge,
|
||||
amount,
|
||||
|
@ -297,7 +286,7 @@ contract LiquidPledgingBase is PledgeAdmins, Pledges, EscapableApp {
|
|||
uint64 idReceiver
|
||||
) internal
|
||||
{
|
||||
Pledges.Pledge storage p = _findPledge(idPledge);
|
||||
Pledge storage p = _findPledge(idPledge);
|
||||
|
||||
// Ensure that the pledge is not already at max pledge depth
|
||||
// and the project has not been canceled
|
||||
|
@ -310,7 +299,7 @@ contract LiquidPledgingBase is PledgeAdmins, Pledges, EscapableApp {
|
|||
0,
|
||||
0,
|
||||
p.oldPledge,
|
||||
Pledges.PledgeState.Pledged
|
||||
PledgeState.Pledged
|
||||
);
|
||||
uint64 toPledge = _findOrCreatePledge(
|
||||
idReceiver, // Set the new owner
|
||||
|
@ -318,7 +307,7 @@ contract LiquidPledgingBase is PledgeAdmins, Pledges, EscapableApp {
|
|||
0,
|
||||
0,
|
||||
uint64(oldPledge),
|
||||
Pledges.PledgeState.Pledged
|
||||
PledgeState.Pledged
|
||||
);
|
||||
_doTransfer(idPledge, toPledge, amount);
|
||||
}
|
||||
|
@ -342,7 +331,7 @@ contract LiquidPledgingBase is PledgeAdmins, Pledges, EscapableApp {
|
|||
0,
|
||||
0,
|
||||
0,
|
||||
Pledges.PledgeState.Pledged
|
||||
PledgeState.Pledged
|
||||
);
|
||||
_doTransfer(idPledge, toPledge, amount);
|
||||
}
|
||||
|
@ -358,7 +347,7 @@ contract LiquidPledgingBase is PledgeAdmins, Pledges, EscapableApp {
|
|||
uint64 idReceiver
|
||||
) internal
|
||||
{
|
||||
Pledges.Pledge storage p = _findPledge(idPledge);
|
||||
Pledge storage p = _findPledge(idPledge);
|
||||
|
||||
require(p.delegationChain.length < MAX_DELEGATES);
|
||||
uint64[] memory newDelegationChain = new uint64[](
|
||||
|
@ -377,7 +366,7 @@ contract LiquidPledgingBase is PledgeAdmins, Pledges, EscapableApp {
|
|||
0,
|
||||
0,
|
||||
p.oldPledge,
|
||||
Pledges.PledgeState.Pledged
|
||||
PledgeState.Pledged
|
||||
);
|
||||
_doTransfer(idPledge, toPledge, amount);
|
||||
}
|
||||
|
@ -394,7 +383,7 @@ contract LiquidPledgingBase is PledgeAdmins, Pledges, EscapableApp {
|
|||
uint q
|
||||
) internal returns (uint64 toPledge)
|
||||
{
|
||||
Pledges.Pledge storage p = _findPledge(idPledge);
|
||||
Pledge storage p = _findPledge(idPledge);
|
||||
uint64[] memory newDelegationChain = new uint64[](
|
||||
p.delegationChain.length - q
|
||||
);
|
||||
|
@ -408,7 +397,7 @@ contract LiquidPledgingBase is PledgeAdmins, Pledges, EscapableApp {
|
|||
0,
|
||||
0,
|
||||
p.oldPledge,
|
||||
Pledges.PledgeState.Pledged
|
||||
PledgeState.Pledged
|
||||
);
|
||||
_doTransfer(idPledge, toPledge, amount);
|
||||
}
|
||||
|
@ -426,7 +415,7 @@ contract LiquidPledgingBase is PledgeAdmins, Pledges, EscapableApp {
|
|||
uint64 idReceiver
|
||||
) internal
|
||||
{
|
||||
Pledges.Pledge storage p = _findPledge(idPledge);
|
||||
Pledge storage p = _findPledge(idPledge);
|
||||
|
||||
require(_getPledgeLevel(p) < MAX_INTERPROJECT_LEVEL);
|
||||
require(!_isProjectCanceled(idReceiver));
|
||||
|
@ -437,7 +426,7 @@ contract LiquidPledgingBase is PledgeAdmins, Pledges, EscapableApp {
|
|||
idReceiver,
|
||||
uint64(_getTime() + _maxCommitTime(p)),
|
||||
p.oldPledge,
|
||||
Pledges.PledgeState.Pledged
|
||||
PledgeState.Pledged
|
||||
);
|
||||
_doTransfer(idPledge, toPledge, amount);
|
||||
}
|
||||
|
@ -456,8 +445,8 @@ contract LiquidPledgingBase is PledgeAdmins, Pledges, EscapableApp {
|
|||
return;
|
||||
}
|
||||
|
||||
Pledges.Pledge storage pFrom = _findPledge(from);
|
||||
Pledges.Pledge storage pTo = _findPledge(to);
|
||||
Pledge storage pFrom = _findPledge(from);
|
||||
Pledge storage pTo = _findPledge(to);
|
||||
|
||||
require(pFrom.amount >= amount);
|
||||
pFrom.amount -= amount;
|
||||
|
@ -486,7 +475,7 @@ contract LiquidPledgingBase is PledgeAdmins, Pledges, EscapableApp {
|
|||
}
|
||||
|
||||
/// @notice A getter to find the oldest pledge that hasn't been canceled
|
||||
/// @param idPledge The starting place to lookup the pledges
|
||||
/// @param idPledge The starting place to lookup the pledges
|
||||
/// @return The oldest idPledge that hasn't been canceled (DUH!)
|
||||
function _getOldestPledgeNotCanceled(
|
||||
uint64 idPledge
|
||||
|
@ -534,14 +523,13 @@ contract LiquidPledgingBase is PledgeAdmins, Pledges, EscapableApp {
|
|||
uint amount
|
||||
) internal returns (uint allowedAmount)
|
||||
{
|
||||
|
||||
uint newAmount;
|
||||
allowedAmount = amount;
|
||||
PledgeAdmins.PledgeAdmin storage admin = _findAdmin(adminId);
|
||||
PledgeAdmin storage admin = _findAdmin(adminId);
|
||||
|
||||
// Checks admin has a plugin assigned and a non-zero amount is requested
|
||||
if (address(admin.plugin) != 0 && allowedAmount > 0) {
|
||||
// There are two seperate functions called in the plugin.
|
||||
// There are two separate functions called in the plugin.
|
||||
// One is called before the transfer and one after
|
||||
if (before) {
|
||||
newAmount = admin.plugin.beforeTransfer(
|
||||
|
@ -588,7 +576,7 @@ contract LiquidPledgingBase is PledgeAdmins, Pledges, EscapableApp {
|
|||
// or transferring context
|
||||
uint64 offset = idPledge == fromPledge ? 0 : 256;
|
||||
allowedAmount = amount;
|
||||
Pledges.Pledge storage p = _findPledge(idPledge);
|
||||
Pledge storage p = _findPledge(idPledge);
|
||||
|
||||
// Always call the plugin on the owner
|
||||
allowedAmount = _callPlugin(
|
||||
|
@ -644,7 +632,7 @@ contract LiquidPledgingBase is PledgeAdmins, Pledges, EscapableApp {
|
|||
{
|
||||
allowedAmount = amount;
|
||||
|
||||
// Call the pledges plugins in the transfer context
|
||||
// Call the plugins in the transfer context
|
||||
allowedAmount = _callPluginsPledge(
|
||||
before,
|
||||
fromPledge,
|
||||
|
@ -653,7 +641,7 @@ contract LiquidPledgingBase is PledgeAdmins, Pledges, EscapableApp {
|
|||
allowedAmount
|
||||
);
|
||||
|
||||
// Call the pledges plugins in the receive context
|
||||
// Call the plugins in the receive context
|
||||
allowedAmount = _callPluginsPledge(
|
||||
before,
|
||||
toPledge,
|
||||
|
|
|
@ -20,17 +20,15 @@ pragma solidity ^0.4.18;
|
|||
*/
|
||||
|
||||
import "@aragon/os/contracts/apps/AragonApp.sol";
|
||||
import "./LiquidPledgingStorage.sol";
|
||||
|
||||
/// NOTICE: This contract is not using EternalStorage. This is done to save gas. The pluginWhitelist
|
||||
/// should be fairly small, and would be trivial and relatively cheap to re-add all valid plugins
|
||||
/// when the LiquidPledging contract is upgraded
|
||||
contract LiquidPledgingPlugins is AragonApp {
|
||||
contract LiquidPledgingPlugins is LiquidPledgingStorage, AragonApp {
|
||||
|
||||
bytes32 constant public PLUGIN_MANAGER_ROLE = keccak256("PLUGIN_MANAGER_ROLE");
|
||||
|
||||
mapping (bytes32 => bool) pluginWhitelist;
|
||||
bool public whitelistDisabled = false;
|
||||
|
||||
function addValidPlugin(bytes32 contractHash) auth(PLUGIN_MANAGER_ROLE) public {
|
||||
pluginWhitelist[contractHash] = true;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,57 @@
|
|||
pragma solidity ^0.4.18;
|
||||
|
||||
import "./ILiquidPledgingPlugin.sol";
|
||||
|
||||
/// @dev This is an interface for `LPVault` which serves as a secure storage for
|
||||
/// the ETH that backs the Pledges, only after `LiquidPledging` authorizes
|
||||
/// payments can Pledges be converted for ETH
|
||||
interface ILPVault {
|
||||
function authorizePayment(bytes32 _ref, address _dest, uint _amount) public;
|
||||
function () public payable;
|
||||
}
|
||||
|
||||
/// This contract contains all state variables used in LiquidPledging contracts
|
||||
/// This is done to have everything in 1 location, b/c state variable layout
|
||||
/// is MUST have be the same when performing an upgrade.
|
||||
contract LiquidPledgingStorage {
|
||||
enum PledgeAdminType { Giver, Delegate, Project }
|
||||
enum PledgeState { Pledged, Paying, Paid }
|
||||
|
||||
/// @dev This struct defines the details of a `PledgeAdmin` which are
|
||||
/// commonly referenced by their index in the `admins` array
|
||||
/// and can own pledges and act as delegates
|
||||
struct PledgeAdmin {
|
||||
PledgeAdminType adminType; // Giver, Delegate or Project
|
||||
address addr; // Account or contract address for admin
|
||||
uint64 commitTime; // In seconds, used for time Givers' & Delegates' have to veto
|
||||
uint64 parentProject; // Only for projects
|
||||
bool canceled; //Always false except for canceled projects
|
||||
|
||||
/// @dev if the plugin is 0x0 then nothing happens, if its an address
|
||||
// than that smart contract is called when appropriate
|
||||
ILiquidPledgingPlugin plugin;
|
||||
string name;
|
||||
string url; // Can be IPFS hash
|
||||
}
|
||||
|
||||
struct Pledge {
|
||||
uint amount;
|
||||
uint64[] delegationChain; // List of delegates in order of authority
|
||||
uint64 owner; // PledgeAdmin
|
||||
uint64 intendedProject; // Used when delegates are sending to projects
|
||||
uint64 commitTime; // When the intendedProject will become the owner
|
||||
uint64 oldPledge; // Points to the id that this Pledge was derived from
|
||||
PledgeState pledgeState; // Pledged, Paying, Paid
|
||||
}
|
||||
|
||||
PledgeAdmin[] admins; //The list of pledgeAdmins 0 means there is no admin
|
||||
Pledge[] pledges;
|
||||
/// @dev this mapping allows you to search for a specific pledge's
|
||||
/// index number by the hash of that pledge
|
||||
mapping (bytes32 => uint64) hPledge2idx;
|
||||
|
||||
mapping (bytes32 => bool) pluginWhitelist;
|
||||
bool public whitelistDisabled = false;
|
||||
|
||||
ILPVault public vault;
|
||||
}
|
|
@ -18,8 +18,6 @@ pragma solidity ^0.4.18;
|
|||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import "./ILiquidPledgingPlugin.sol";
|
||||
import "./LiquidPledgingPlugins.sol";
|
||||
import "@aragon/os/contracts/apps/AragonApp.sol";
|
||||
import "@aragon/os/contracts/acl/ACL.sol";
|
||||
|
@ -32,25 +30,6 @@ contract PledgeAdmins is AragonApp, LiquidPledgingPlugins {
|
|||
uint constant MAX_SUBPROJECT_LEVEL = 20;
|
||||
uint constant MAX_INTERPROJECT_LEVEL = 20;
|
||||
|
||||
enum PledgeAdminType { Giver, Delegate, Project }
|
||||
|
||||
/// @dev This struct defines the details of a `PledgeAdmin` which are
|
||||
/// commonly referenced by their index in the `admins` array
|
||||
/// and can own pledges and act as delegates
|
||||
struct PledgeAdmin {
|
||||
PledgeAdminType adminType; // Giver, Delegate or Project
|
||||
address addr; // Account or contract address for admin
|
||||
string name;
|
||||
string url; // Can be IPFS hash
|
||||
uint64 commitTime; // In seconds, used for Givers' & Delegates' vetos
|
||||
uint64 parentProject; // Only for projects
|
||||
bool canceled; //Always false except for canceled projects
|
||||
|
||||
/// @dev if the plugin is 0x0 then nothing happens, if its an address
|
||||
// than that smart contract is called when appropriate
|
||||
ILiquidPledgingPlugin plugin;
|
||||
}
|
||||
|
||||
// Events
|
||||
event GiverAdded(uint64 indexed idGiver);
|
||||
event GiverUpdated(uint64 indexed idGiver);
|
||||
|
@ -59,8 +38,6 @@ contract PledgeAdmins is AragonApp, LiquidPledgingPlugins {
|
|||
event ProjectAdded(uint64 indexed idProject);
|
||||
event ProjectUpdated(uint64 indexed idProject);
|
||||
|
||||
PledgeAdmin[] admins; //The list of pledgeAdmins 0 means there is no admin
|
||||
|
||||
////////////////////
|
||||
// Public functions
|
||||
////////////////////
|
||||
|
@ -105,13 +82,13 @@ contract PledgeAdmins is AragonApp, LiquidPledgingPlugins {
|
|||
admins.push(
|
||||
PledgeAdmin(
|
||||
PledgeAdminType.Giver,
|
||||
addr, // TODO: is this needed?
|
||||
name,
|
||||
url,
|
||||
addr, // TODO: is this needed? Yes, until aragon has an easy way to see who has permissions
|
||||
commitTime,
|
||||
0,
|
||||
false,
|
||||
plugin)
|
||||
plugin,
|
||||
name,
|
||||
url)
|
||||
);
|
||||
|
||||
_grantPledgeAdminPermission(msg.sender, idGiver);
|
||||
|
@ -175,12 +152,12 @@ contract PledgeAdmins is AragonApp, LiquidPledgingPlugins {
|
|||
PledgeAdmin(
|
||||
PledgeAdminType.Delegate,
|
||||
msg.sender,
|
||||
name,
|
||||
url,
|
||||
commitTime,
|
||||
0,
|
||||
false,
|
||||
plugin)
|
||||
plugin,
|
||||
name,
|
||||
url)
|
||||
);
|
||||
|
||||
_grantPledgeAdminPermission(msg.sender, idDelegate);
|
||||
|
@ -257,12 +234,12 @@ contract PledgeAdmins is AragonApp, LiquidPledgingPlugins {
|
|||
PledgeAdmin(
|
||||
PledgeAdminType.Project,
|
||||
projectAdmin,
|
||||
name,
|
||||
url,
|
||||
commitTime,
|
||||
parentProject,
|
||||
false,
|
||||
plugin)
|
||||
plugin,
|
||||
name,
|
||||
url)
|
||||
);
|
||||
|
||||
_grantPledgeAdminPermission(projectAdmin, idProject);
|
||||
|
@ -294,7 +271,6 @@ contract PledgeAdmins is AragonApp, LiquidPledgingPlugins {
|
|||
PledgeAdmin storage project = _findAdmin(idProject);
|
||||
|
||||
require(project.adminType == PledgeAdminType.Project);
|
||||
// require(project.addr == msg.sender);
|
||||
|
||||
project.addr = newAddr;
|
||||
project.name = newName;
|
||||
|
@ -397,8 +373,8 @@ contract PledgeAdmins is AragonApp, LiquidPledgingPlugins {
|
|||
return(1);
|
||||
}
|
||||
|
||||
PledgeAdmin storage parentA = _findAdmin(a.parentProject);
|
||||
return _getProjectLevel(parentA) + 1;
|
||||
PledgeAdmin storage parent = _findAdmin(a.parentProject);
|
||||
return _getProjectLevel(parent) + 1;
|
||||
}
|
||||
|
||||
function _grantPledgeAdminPermission(address _who, uint64 idPledge) internal {
|
||||
|
|
|
@ -20,8 +20,9 @@ pragma solidity ^0.4.18;
|
|||
*/
|
||||
|
||||
import "@aragon/os/contracts/apps/AragonApp.sol";
|
||||
import "./LiquidPledgingStorage.sol";
|
||||
|
||||
contract Pledges is AragonApp {
|
||||
contract Pledges is LiquidPledgingStorage, AragonApp {
|
||||
|
||||
// Limits inserted to prevent large loops that could prevent canceling
|
||||
uint constant MAX_DELEGATES = 10;
|
||||
|
@ -29,25 +30,6 @@ contract Pledges is AragonApp {
|
|||
// a constant for when a delegate is requested that is not in the system
|
||||
uint64 constant NOTFOUND = 0xFFFFFFFFFFFFFFFF;
|
||||
|
||||
enum PledgeState { Pledged, Paying, Paid }
|
||||
|
||||
struct Pledge {
|
||||
// uint id; // the id of this Pledge
|
||||
uint amount;
|
||||
uint64 owner; // PledgeAdmin
|
||||
uint64[] delegationChain; // List of delegates in order of authority
|
||||
uint64 intendedProject; // Used when delegates are sending to projects
|
||||
uint64 commitTime; // When the intendedProject will become the owner
|
||||
uint64 oldPledge; // Points to the id that this Pledge was derived from
|
||||
PledgeState pledgeState; // Pledged, Paying, Paid
|
||||
}
|
||||
|
||||
Pledge[] pledges;
|
||||
/// @dev this mapping allows you to search for a specific pledge's
|
||||
/// index number by the hash of that pledge
|
||||
mapping (bytes32 => uint64) hPledge2idx;
|
||||
|
||||
|
||||
/////////////////////////////
|
||||
// Public constant functions
|
||||
////////////////////////////
|
||||
|
@ -112,7 +94,7 @@ contract Pledges is AragonApp {
|
|||
PledgeState state
|
||||
) internal returns (uint64)
|
||||
{
|
||||
bytes32 hPledge = keccak256(owner, delegationChain, intendedProject, commitTime, oldPledge, state);
|
||||
bytes32 hPledge = keccak256(delegationChain, owner, intendedProject, commitTime, oldPledge, state);
|
||||
uint64 id = hPledge2idx[hPledge];
|
||||
if (id > 0) {
|
||||
return id;
|
||||
|
@ -123,8 +105,8 @@ contract Pledges is AragonApp {
|
|||
pledges.push(
|
||||
Pledge(
|
||||
0,
|
||||
owner,
|
||||
delegationChain,
|
||||
owner,
|
||||
intendedProject,
|
||||
commitTime,
|
||||
oldPledge,
|
||||
|
|
Loading…
Reference in New Issue