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
|
public payable
|
||||||
{
|
{
|
||||||
require(idGiver > 0); // prevent burning donations. idReceiver is checked in _transfer
|
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);
|
require(sender.adminType == PledgeAdminType.Giver);
|
||||||
|
|
||||||
uint amount = msg.value;
|
uint amount = msg.value;
|
||||||
|
@ -70,10 +70,10 @@ contract LiquidPledging is LiquidPledgingBase {
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
Pledges.PledgeState.Pledged
|
PledgeState.Pledged
|
||||||
);
|
);
|
||||||
|
|
||||||
Pledges.Pledge storage pTo = _findPledge(idPledge);
|
Pledge storage pTo = _findPledge(idPledge);
|
||||||
pTo.amount += amount;
|
pTo.amount += amount;
|
||||||
|
|
||||||
Transfer(0, idPledge, amount);
|
Transfer(0, idPledge, amount);
|
||||||
|
@ -108,10 +108,10 @@ contract LiquidPledging is LiquidPledgingBase {
|
||||||
function withdraw(uint64 idPledge, uint amount) public {
|
function withdraw(uint64 idPledge, uint amount) public {
|
||||||
idPledge = normalizePledge(idPledge); // Updates pledge info
|
idPledge = normalizePledge(idPledge); // Updates pledge info
|
||||||
|
|
||||||
Pledges.Pledge storage p = _findPledge(idPledge);
|
Pledge storage p = _findPledge(idPledge);
|
||||||
require(p.pledgeState == PledgeState.Pledged);
|
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))));
|
require(canPerform(msg.sender, PLEDGE_ADMIN_ROLE, arr(uint(p.owner))));
|
||||||
|
|
||||||
uint64 idNewPledge = _findOrCreatePledge(
|
uint64 idNewPledge = _findOrCreatePledge(
|
||||||
|
@ -120,7 +120,7 @@ contract LiquidPledging is LiquidPledgingBase {
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
p.oldPledge,
|
p.oldPledge,
|
||||||
Pledges.PledgeState.Paying
|
PledgeState.Paying
|
||||||
);
|
);
|
||||||
|
|
||||||
_doTransfer(idPledge, idNewPledge, amount);
|
_doTransfer(idPledge, idNewPledge, amount);
|
||||||
|
@ -128,14 +128,14 @@ contract LiquidPledging is LiquidPledgingBase {
|
||||||
vault.authorizePayment(bytes32(idNewPledge), owner.addr, amount);
|
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
|
/// from Paying to Paid
|
||||||
/// @param idPledge Id of the pledge that is to be withdrawn
|
/// @param idPledge Id of the pledge that is to be withdrawn
|
||||||
/// @param amount Quantity of ether (in wei) to be withdrawn
|
/// @param amount Quantity of ether (in wei) to be withdrawn
|
||||||
function confirmPayment(uint64 idPledge, uint amount) public onlyVault {
|
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(
|
uint64 idNewPledge = _findOrCreatePledge(
|
||||||
p.owner,
|
p.owner,
|
||||||
|
@ -143,20 +143,20 @@ contract LiquidPledging is LiquidPledgingBase {
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
p.oldPledge,
|
p.oldPledge,
|
||||||
Pledges.PledgeState.Paid
|
PledgeState.Paid
|
||||||
);
|
);
|
||||||
|
|
||||||
_doTransfer(idPledge, idNewPledge, amount);
|
_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
|
/// from Paying back to Pledged
|
||||||
/// @param idPledge Id of the pledge that's withdraw is to be canceled
|
/// @param idPledge Id of the pledge that's withdraw is to be canceled
|
||||||
/// @param amount Quantity of ether (in wei) to be canceled
|
/// @param amount Quantity of ether (in wei) to be canceled
|
||||||
function cancelPayment(uint64 idPledge, uint amount) public onlyVault {
|
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.
|
// When a payment is canceled, never is assigned to a project.
|
||||||
uint64 idOldPledge = _findOrCreatePledge(
|
uint64 idOldPledge = _findOrCreatePledge(
|
||||||
|
@ -165,7 +165,7 @@ contract LiquidPledging is LiquidPledgingBase {
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
p.oldPledge,
|
p.oldPledge,
|
||||||
Pledges.PledgeState.Pledged
|
PledgeState.Pledged
|
||||||
);
|
);
|
||||||
|
|
||||||
idOldPledge = normalizePledge(idOldPledge);
|
idOldPledge = normalizePledge(idOldPledge);
|
||||||
|
@ -176,7 +176,7 @@ contract LiquidPledging is LiquidPledgingBase {
|
||||||
/// @notice Changes the `project.canceled` flag to `true`; cannot be undone
|
/// @notice Changes the `project.canceled` flag to `true`; cannot be undone
|
||||||
/// @param idProject Id of the project that is to be canceled
|
/// @param idProject Id of the project that is to be canceled
|
||||||
function cancelProject(uint64 idProject) authP(PLEDGE_ADMIN_ROLE, arr(uint(idProject))) public {
|
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);
|
// _checkAdminOwner(project);
|
||||||
project.canceled = true;
|
project.canceled = true;
|
||||||
|
|
||||||
|
@ -191,7 +191,7 @@ contract LiquidPledging is LiquidPledgingBase {
|
||||||
function cancelPledge(uint64 idPledge, uint amount) public {
|
function cancelPledge(uint64 idPledge, uint amount) public {
|
||||||
idPledge = normalizePledge(idPledge);
|
idPledge = normalizePledge(idPledge);
|
||||||
|
|
||||||
Pledges.Pledge storage p = _findPledge(idPledge);
|
Pledge storage p = _findPledge(idPledge);
|
||||||
require(p.oldPledge != 0);
|
require(p.oldPledge != 0);
|
||||||
|
|
||||||
require(canPerform(msg.sender, PLEDGE_ADMIN_ROLE, arr(uint(p.owner))));
|
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/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import "./ILiquidPledgingPlugin.sol";
|
import "./LiquidPledgingStorage.sol";
|
||||||
// import "giveth-common-contracts/contracts/Escapable.sol";
|
|
||||||
import "./EscapableApp.sol";
|
|
||||||
import "./PledgeAdmins.sol";
|
import "./PledgeAdmins.sol";
|
||||||
import "./Pledges.sol";
|
import "./Pledges.sol";
|
||||||
|
import "./EscapableApp.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;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @dev `LiquidPledgingBase` is the base level contract used to carry out
|
/// @dev `LiquidPledgingBase` is the base level contract used to carry out
|
||||||
/// liquidPledging's most basic functions, mostly handling and searching the
|
/// liquidPledging's most basic functions, mostly handling and searching the
|
||||||
/// data structures
|
/// data structures
|
||||||
contract LiquidPledgingBase is PledgeAdmins, Pledges, EscapableApp {
|
contract LiquidPledgingBase is LiquidPledgingStorage, PledgeAdmins, Pledges, EscapableApp {
|
||||||
|
|
||||||
// Event Declarations
|
// Event Declarations
|
||||||
event Transfer(uint indexed from, uint indexed to, uint amount);
|
event Transfer(uint indexed from, uint indexed to, uint amount);
|
||||||
event CancelProject(uint indexed idProject);
|
event CancelProject(uint indexed idProject);
|
||||||
|
|
||||||
ILPVault public vault;
|
|
||||||
|
|
||||||
/////////////
|
/////////////
|
||||||
// Modifiers
|
// Modifiers
|
||||||
/////////////
|
/////////////
|
||||||
|
@ -99,7 +88,7 @@ contract LiquidPledgingBase is PledgeAdmins, Pledges, EscapableApp {
|
||||||
name = delegate.name;
|
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
|
/// #1: Checks if the pledge should be committed. This means that
|
||||||
/// if the pledge has an intendedProject and it is past the
|
/// if the pledge has an intendedProject and it is past the
|
||||||
/// commitTime, it changes the owner to be the proposed project
|
/// 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
|
/// @param idPledge This is the id of the pledge that will be normalized
|
||||||
/// @return The normalized Pledge!
|
/// @return The normalized Pledge!
|
||||||
function normalizePledge(uint64 idPledge) public returns(uint64) {
|
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
|
// Check to make sure this pledge hasn't already been used
|
||||||
// or is in the process of being used
|
// or is in the process of being used
|
||||||
if (p.pledgeState != Pledges.PledgeState.Pledged) {
|
if (p.pledgeState != PledgeState.Pledged) {
|
||||||
return idPledge;
|
return idPledge;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -133,7 +122,7 @@ contract LiquidPledgingBase is PledgeAdmins, Pledges, EscapableApp {
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
p.oldPledge,
|
p.oldPledge,
|
||||||
Pledges.PledgeState.Pledged
|
PledgeState.Pledged
|
||||||
);
|
);
|
||||||
uint64 toPledge = _findOrCreatePledge(
|
uint64 toPledge = _findOrCreatePledge(
|
||||||
p.intendedProject,
|
p.intendedProject,
|
||||||
|
@ -141,7 +130,7 @@ contract LiquidPledgingBase is PledgeAdmins, Pledges, EscapableApp {
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
oldPledge,
|
oldPledge,
|
||||||
Pledges.PledgeState.Pledged
|
PledgeState.Pledged
|
||||||
);
|
);
|
||||||
_doTransfer(idPledge, toPledge, p.amount);
|
_doTransfer(idPledge, toPledge, p.amount);
|
||||||
idPledge = toPledge;
|
idPledge = toPledge;
|
||||||
|
@ -170,19 +159,19 @@ contract LiquidPledgingBase is PledgeAdmins, Pledges, EscapableApp {
|
||||||
require(idReceiver > 0); // prevent burning value
|
require(idReceiver > 0); // prevent burning value
|
||||||
idPledge = normalizePledge(idPledge);
|
idPledge = normalizePledge(idPledge);
|
||||||
|
|
||||||
Pledges.Pledge storage p = _findPledge(idPledge);
|
Pledge storage p = _findPledge(idPledge);
|
||||||
PledgeAdmins.PledgeAdmin storage receiver = _findAdmin(idReceiver);
|
PledgeAdmin storage receiver = _findAdmin(idReceiver);
|
||||||
|
|
||||||
require(p.pledgeState == PledgeState.Pledged);
|
require(p.pledgeState == PledgeState.Pledged);
|
||||||
|
|
||||||
// If the sender is the owner of the Pledge
|
// If the sender is the owner of the Pledge
|
||||||
if (p.owner == idSender) {
|
if (p.owner == idSender) {
|
||||||
|
|
||||||
if (receiver.adminType == PledgeAdmins.PledgeAdminType.Giver) {
|
if (receiver.adminType == PledgeAdminType.Giver) {
|
||||||
_transferOwnershipToGiver(idPledge, amount, idReceiver);
|
_transferOwnershipToGiver(idPledge, amount, idReceiver);
|
||||||
} else if (receiver.adminType == PledgeAdmins.PledgeAdminType.Project) {
|
} else if (receiver.adminType == PledgeAdminType.Project) {
|
||||||
_transferOwnershipToProject(idPledge, amount, idReceiver);
|
_transferOwnershipToProject(idPledge, amount, idReceiver);
|
||||||
} else if (receiver.adminType == PledgeAdmins.PledgeAdminType.Delegate) {
|
} else if (receiver.adminType == PledgeAdminType.Delegate) {
|
||||||
|
|
||||||
uint recieverDIdx = _getDelegateIdx(p, idReceiver);
|
uint recieverDIdx = _getDelegateIdx(p, idReceiver);
|
||||||
if (p.intendedProject > 0 && recieverDIdx != NOTFOUND) {
|
if (p.intendedProject > 0 && recieverDIdx != NOTFOUND) {
|
||||||
|
@ -197,7 +186,7 @@ contract LiquidPledgingBase is PledgeAdmins, Pledges, EscapableApp {
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
p.oldPledge,
|
p.oldPledge,
|
||||||
Pledges.PledgeState.Pledged);
|
PledgeState.Pledged);
|
||||||
_doTransfer(idPledge, toPledge, amount);
|
_doTransfer(idPledge, toPledge, amount);
|
||||||
} else {
|
} else {
|
||||||
_undelegate(idPledge, amount, p.delegationChain.length - receiverDIdx - 1);
|
_undelegate(idPledge, amount, p.delegationChain.length - receiverDIdx - 1);
|
||||||
|
@ -226,7 +215,7 @@ contract LiquidPledgingBase is PledgeAdmins, Pledges, EscapableApp {
|
||||||
if (senderDIdx != NOTFOUND) {
|
if (senderDIdx != NOTFOUND) {
|
||||||
|
|
||||||
// And the receiver is another Giver
|
// 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
|
// Only transfer to the Giver who owns the pledge
|
||||||
assert(p.owner == idReceiver);
|
assert(p.owner == idReceiver);
|
||||||
_undelegate(idPledge, amount, p.delegationChain.length);
|
_undelegate(idPledge, amount, p.delegationChain.length);
|
||||||
|
@ -234,7 +223,7 @@ contract LiquidPledgingBase is PledgeAdmins, Pledges, EscapableApp {
|
||||||
}
|
}
|
||||||
|
|
||||||
// And the receiver is another Delegate
|
// And the receiver is another Delegate
|
||||||
if (receiver.adminType == PledgeAdmins.PledgeAdminType.Delegate) {
|
if (receiver.adminType == PledgeAdminType.Delegate) {
|
||||||
uint receiverDIdx = _getDelegateIdx(p, idReceiver);
|
uint receiverDIdx = _getDelegateIdx(p, idReceiver);
|
||||||
|
|
||||||
// And not in the delegationChain
|
// 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
|
// And the receiver is a Project, all the delegates after the sender
|
||||||
// are removed and the amount is pre-committed to the project
|
// 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 = _undelegate(
|
||||||
idPledge,
|
idPledge,
|
||||||
amount,
|
amount,
|
||||||
|
@ -297,7 +286,7 @@ contract LiquidPledgingBase is PledgeAdmins, Pledges, EscapableApp {
|
||||||
uint64 idReceiver
|
uint64 idReceiver
|
||||||
) internal
|
) internal
|
||||||
{
|
{
|
||||||
Pledges.Pledge storage p = _findPledge(idPledge);
|
Pledge storage p = _findPledge(idPledge);
|
||||||
|
|
||||||
// Ensure that the pledge is not already at max pledge depth
|
// Ensure that the pledge is not already at max pledge depth
|
||||||
// and the project has not been canceled
|
// and the project has not been canceled
|
||||||
|
@ -310,7 +299,7 @@ contract LiquidPledgingBase is PledgeAdmins, Pledges, EscapableApp {
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
p.oldPledge,
|
p.oldPledge,
|
||||||
Pledges.PledgeState.Pledged
|
PledgeState.Pledged
|
||||||
);
|
);
|
||||||
uint64 toPledge = _findOrCreatePledge(
|
uint64 toPledge = _findOrCreatePledge(
|
||||||
idReceiver, // Set the new owner
|
idReceiver, // Set the new owner
|
||||||
|
@ -318,7 +307,7 @@ contract LiquidPledgingBase is PledgeAdmins, Pledges, EscapableApp {
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
uint64(oldPledge),
|
uint64(oldPledge),
|
||||||
Pledges.PledgeState.Pledged
|
PledgeState.Pledged
|
||||||
);
|
);
|
||||||
_doTransfer(idPledge, toPledge, amount);
|
_doTransfer(idPledge, toPledge, amount);
|
||||||
}
|
}
|
||||||
|
@ -342,7 +331,7 @@ contract LiquidPledgingBase is PledgeAdmins, Pledges, EscapableApp {
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
Pledges.PledgeState.Pledged
|
PledgeState.Pledged
|
||||||
);
|
);
|
||||||
_doTransfer(idPledge, toPledge, amount);
|
_doTransfer(idPledge, toPledge, amount);
|
||||||
}
|
}
|
||||||
|
@ -358,7 +347,7 @@ contract LiquidPledgingBase is PledgeAdmins, Pledges, EscapableApp {
|
||||||
uint64 idReceiver
|
uint64 idReceiver
|
||||||
) internal
|
) internal
|
||||||
{
|
{
|
||||||
Pledges.Pledge storage p = _findPledge(idPledge);
|
Pledge storage p = _findPledge(idPledge);
|
||||||
|
|
||||||
require(p.delegationChain.length < MAX_DELEGATES);
|
require(p.delegationChain.length < MAX_DELEGATES);
|
||||||
uint64[] memory newDelegationChain = new uint64[](
|
uint64[] memory newDelegationChain = new uint64[](
|
||||||
|
@ -377,7 +366,7 @@ contract LiquidPledgingBase is PledgeAdmins, Pledges, EscapableApp {
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
p.oldPledge,
|
p.oldPledge,
|
||||||
Pledges.PledgeState.Pledged
|
PledgeState.Pledged
|
||||||
);
|
);
|
||||||
_doTransfer(idPledge, toPledge, amount);
|
_doTransfer(idPledge, toPledge, amount);
|
||||||
}
|
}
|
||||||
|
@ -394,7 +383,7 @@ contract LiquidPledgingBase is PledgeAdmins, Pledges, EscapableApp {
|
||||||
uint q
|
uint q
|
||||||
) internal returns (uint64 toPledge)
|
) internal returns (uint64 toPledge)
|
||||||
{
|
{
|
||||||
Pledges.Pledge storage p = _findPledge(idPledge);
|
Pledge storage p = _findPledge(idPledge);
|
||||||
uint64[] memory newDelegationChain = new uint64[](
|
uint64[] memory newDelegationChain = new uint64[](
|
||||||
p.delegationChain.length - q
|
p.delegationChain.length - q
|
||||||
);
|
);
|
||||||
|
@ -408,7 +397,7 @@ contract LiquidPledgingBase is PledgeAdmins, Pledges, EscapableApp {
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
p.oldPledge,
|
p.oldPledge,
|
||||||
Pledges.PledgeState.Pledged
|
PledgeState.Pledged
|
||||||
);
|
);
|
||||||
_doTransfer(idPledge, toPledge, amount);
|
_doTransfer(idPledge, toPledge, amount);
|
||||||
}
|
}
|
||||||
|
@ -426,7 +415,7 @@ contract LiquidPledgingBase is PledgeAdmins, Pledges, EscapableApp {
|
||||||
uint64 idReceiver
|
uint64 idReceiver
|
||||||
) internal
|
) internal
|
||||||
{
|
{
|
||||||
Pledges.Pledge storage p = _findPledge(idPledge);
|
Pledge storage p = _findPledge(idPledge);
|
||||||
|
|
||||||
require(_getPledgeLevel(p) < MAX_INTERPROJECT_LEVEL);
|
require(_getPledgeLevel(p) < MAX_INTERPROJECT_LEVEL);
|
||||||
require(!_isProjectCanceled(idReceiver));
|
require(!_isProjectCanceled(idReceiver));
|
||||||
|
@ -437,7 +426,7 @@ contract LiquidPledgingBase is PledgeAdmins, Pledges, EscapableApp {
|
||||||
idReceiver,
|
idReceiver,
|
||||||
uint64(_getTime() + _maxCommitTime(p)),
|
uint64(_getTime() + _maxCommitTime(p)),
|
||||||
p.oldPledge,
|
p.oldPledge,
|
||||||
Pledges.PledgeState.Pledged
|
PledgeState.Pledged
|
||||||
);
|
);
|
||||||
_doTransfer(idPledge, toPledge, amount);
|
_doTransfer(idPledge, toPledge, amount);
|
||||||
}
|
}
|
||||||
|
@ -456,8 +445,8 @@ contract LiquidPledgingBase is PledgeAdmins, Pledges, EscapableApp {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Pledges.Pledge storage pFrom = _findPledge(from);
|
Pledge storage pFrom = _findPledge(from);
|
||||||
Pledges.Pledge storage pTo = _findPledge(to);
|
Pledge storage pTo = _findPledge(to);
|
||||||
|
|
||||||
require(pFrom.amount >= amount);
|
require(pFrom.amount >= amount);
|
||||||
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
|
/// @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!)
|
/// @return The oldest idPledge that hasn't been canceled (DUH!)
|
||||||
function _getOldestPledgeNotCanceled(
|
function _getOldestPledgeNotCanceled(
|
||||||
uint64 idPledge
|
uint64 idPledge
|
||||||
|
@ -534,14 +523,13 @@ contract LiquidPledgingBase is PledgeAdmins, Pledges, EscapableApp {
|
||||||
uint amount
|
uint amount
|
||||||
) internal returns (uint allowedAmount)
|
) internal returns (uint allowedAmount)
|
||||||
{
|
{
|
||||||
|
|
||||||
uint newAmount;
|
uint newAmount;
|
||||||
allowedAmount = amount;
|
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
|
// Checks admin has a plugin assigned and a non-zero amount is requested
|
||||||
if (address(admin.plugin) != 0 && allowedAmount > 0) {
|
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
|
// One is called before the transfer and one after
|
||||||
if (before) {
|
if (before) {
|
||||||
newAmount = admin.plugin.beforeTransfer(
|
newAmount = admin.plugin.beforeTransfer(
|
||||||
|
@ -588,7 +576,7 @@ contract LiquidPledgingBase is PledgeAdmins, Pledges, EscapableApp {
|
||||||
// or transferring context
|
// or transferring context
|
||||||
uint64 offset = idPledge == fromPledge ? 0 : 256;
|
uint64 offset = idPledge == fromPledge ? 0 : 256;
|
||||||
allowedAmount = amount;
|
allowedAmount = amount;
|
||||||
Pledges.Pledge storage p = _findPledge(idPledge);
|
Pledge storage p = _findPledge(idPledge);
|
||||||
|
|
||||||
// Always call the plugin on the owner
|
// Always call the plugin on the owner
|
||||||
allowedAmount = _callPlugin(
|
allowedAmount = _callPlugin(
|
||||||
|
@ -644,7 +632,7 @@ contract LiquidPledgingBase is PledgeAdmins, Pledges, EscapableApp {
|
||||||
{
|
{
|
||||||
allowedAmount = amount;
|
allowedAmount = amount;
|
||||||
|
|
||||||
// Call the pledges plugins in the transfer context
|
// Call the plugins in the transfer context
|
||||||
allowedAmount = _callPluginsPledge(
|
allowedAmount = _callPluginsPledge(
|
||||||
before,
|
before,
|
||||||
fromPledge,
|
fromPledge,
|
||||||
|
@ -653,7 +641,7 @@ contract LiquidPledgingBase is PledgeAdmins, Pledges, EscapableApp {
|
||||||
allowedAmount
|
allowedAmount
|
||||||
);
|
);
|
||||||
|
|
||||||
// Call the pledges plugins in the receive context
|
// Call the plugins in the receive context
|
||||||
allowedAmount = _callPluginsPledge(
|
allowedAmount = _callPluginsPledge(
|
||||||
before,
|
before,
|
||||||
toPledge,
|
toPledge,
|
||||||
|
|
|
@ -20,17 +20,15 @@ pragma solidity ^0.4.18;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import "@aragon/os/contracts/apps/AragonApp.sol";
|
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
|
/// 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
|
/// should be fairly small, and would be trivial and relatively cheap to re-add all valid plugins
|
||||||
/// when the LiquidPledging contract is upgraded
|
/// 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");
|
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 {
|
function addValidPlugin(bytes32 contractHash) auth(PLUGIN_MANAGER_ROLE) public {
|
||||||
pluginWhitelist[contractHash] = true;
|
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
|
You should have received a copy of the GNU General Public License
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import "./ILiquidPledgingPlugin.sol";
|
|
||||||
import "./LiquidPledgingPlugins.sol";
|
import "./LiquidPledgingPlugins.sol";
|
||||||
import "@aragon/os/contracts/apps/AragonApp.sol";
|
import "@aragon/os/contracts/apps/AragonApp.sol";
|
||||||
import "@aragon/os/contracts/acl/ACL.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_SUBPROJECT_LEVEL = 20;
|
||||||
uint constant MAX_INTERPROJECT_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
|
// Events
|
||||||
event GiverAdded(uint64 indexed idGiver);
|
event GiverAdded(uint64 indexed idGiver);
|
||||||
event GiverUpdated(uint64 indexed idGiver);
|
event GiverUpdated(uint64 indexed idGiver);
|
||||||
|
@ -59,8 +38,6 @@ contract PledgeAdmins is AragonApp, LiquidPledgingPlugins {
|
||||||
event ProjectAdded(uint64 indexed idProject);
|
event ProjectAdded(uint64 indexed idProject);
|
||||||
event ProjectUpdated(uint64 indexed idProject);
|
event ProjectUpdated(uint64 indexed idProject);
|
||||||
|
|
||||||
PledgeAdmin[] admins; //The list of pledgeAdmins 0 means there is no admin
|
|
||||||
|
|
||||||
////////////////////
|
////////////////////
|
||||||
// Public functions
|
// Public functions
|
||||||
////////////////////
|
////////////////////
|
||||||
|
@ -105,13 +82,13 @@ contract PledgeAdmins is AragonApp, LiquidPledgingPlugins {
|
||||||
admins.push(
|
admins.push(
|
||||||
PledgeAdmin(
|
PledgeAdmin(
|
||||||
PledgeAdminType.Giver,
|
PledgeAdminType.Giver,
|
||||||
addr, // TODO: is this needed?
|
addr, // TODO: is this needed? Yes, until aragon has an easy way to see who has permissions
|
||||||
name,
|
|
||||||
url,
|
|
||||||
commitTime,
|
commitTime,
|
||||||
0,
|
0,
|
||||||
false,
|
false,
|
||||||
plugin)
|
plugin,
|
||||||
|
name,
|
||||||
|
url)
|
||||||
);
|
);
|
||||||
|
|
||||||
_grantPledgeAdminPermission(msg.sender, idGiver);
|
_grantPledgeAdminPermission(msg.sender, idGiver);
|
||||||
|
@ -175,12 +152,12 @@ contract PledgeAdmins is AragonApp, LiquidPledgingPlugins {
|
||||||
PledgeAdmin(
|
PledgeAdmin(
|
||||||
PledgeAdminType.Delegate,
|
PledgeAdminType.Delegate,
|
||||||
msg.sender,
|
msg.sender,
|
||||||
name,
|
|
||||||
url,
|
|
||||||
commitTime,
|
commitTime,
|
||||||
0,
|
0,
|
||||||
false,
|
false,
|
||||||
plugin)
|
plugin,
|
||||||
|
name,
|
||||||
|
url)
|
||||||
);
|
);
|
||||||
|
|
||||||
_grantPledgeAdminPermission(msg.sender, idDelegate);
|
_grantPledgeAdminPermission(msg.sender, idDelegate);
|
||||||
|
@ -257,12 +234,12 @@ contract PledgeAdmins is AragonApp, LiquidPledgingPlugins {
|
||||||
PledgeAdmin(
|
PledgeAdmin(
|
||||||
PledgeAdminType.Project,
|
PledgeAdminType.Project,
|
||||||
projectAdmin,
|
projectAdmin,
|
||||||
name,
|
|
||||||
url,
|
|
||||||
commitTime,
|
commitTime,
|
||||||
parentProject,
|
parentProject,
|
||||||
false,
|
false,
|
||||||
plugin)
|
plugin,
|
||||||
|
name,
|
||||||
|
url)
|
||||||
);
|
);
|
||||||
|
|
||||||
_grantPledgeAdminPermission(projectAdmin, idProject);
|
_grantPledgeAdminPermission(projectAdmin, idProject);
|
||||||
|
@ -294,7 +271,6 @@ contract PledgeAdmins is AragonApp, LiquidPledgingPlugins {
|
||||||
PledgeAdmin storage project = _findAdmin(idProject);
|
PledgeAdmin storage project = _findAdmin(idProject);
|
||||||
|
|
||||||
require(project.adminType == PledgeAdminType.Project);
|
require(project.adminType == PledgeAdminType.Project);
|
||||||
// require(project.addr == msg.sender);
|
|
||||||
|
|
||||||
project.addr = newAddr;
|
project.addr = newAddr;
|
||||||
project.name = newName;
|
project.name = newName;
|
||||||
|
@ -397,8 +373,8 @@ contract PledgeAdmins is AragonApp, LiquidPledgingPlugins {
|
||||||
return(1);
|
return(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
PledgeAdmin storage parentA = _findAdmin(a.parentProject);
|
PledgeAdmin storage parent = _findAdmin(a.parentProject);
|
||||||
return _getProjectLevel(parentA) + 1;
|
return _getProjectLevel(parent) + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
function _grantPledgeAdminPermission(address _who, uint64 idPledge) internal {
|
function _grantPledgeAdminPermission(address _who, uint64 idPledge) internal {
|
||||||
|
|
|
@ -20,8 +20,9 @@ pragma solidity ^0.4.18;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import "@aragon/os/contracts/apps/AragonApp.sol";
|
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
|
// Limits inserted to prevent large loops that could prevent canceling
|
||||||
uint constant MAX_DELEGATES = 10;
|
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
|
// a constant for when a delegate is requested that is not in the system
|
||||||
uint64 constant NOTFOUND = 0xFFFFFFFFFFFFFFFF;
|
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
|
// Public constant functions
|
||||||
////////////////////////////
|
////////////////////////////
|
||||||
|
@ -112,7 +94,7 @@ contract Pledges is AragonApp {
|
||||||
PledgeState state
|
PledgeState state
|
||||||
) internal returns (uint64)
|
) 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];
|
uint64 id = hPledge2idx[hPledge];
|
||||||
if (id > 0) {
|
if (id > 0) {
|
||||||
return id;
|
return id;
|
||||||
|
@ -123,8 +105,8 @@ contract Pledges is AragonApp {
|
||||||
pledges.push(
|
pledges.push(
|
||||||
Pledge(
|
Pledge(
|
||||||
0,
|
0,
|
||||||
owner,
|
|
||||||
delegationChain,
|
delegationChain,
|
||||||
|
owner,
|
||||||
intendedProject,
|
intendedProject,
|
||||||
commitTime,
|
commitTime,
|
||||||
oldPledge,
|
oldPledge,
|
||||||
|
|
Loading…
Reference in New Issue