Merge branch 'GriffGreen-patch-3'
This commit is contained in:
commit
e2be76ebe6
|
@ -1,13 +1,33 @@
|
||||||
pragma solidity ^0.4.11;
|
pragma solidity ^0.4.11;
|
||||||
|
|
||||||
|
/*
|
||||||
|
Copyright 2017, Jordi Baylina
|
||||||
|
Contributors: RJ Ewing, Griff Green, Arthur Lunn
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
/// @title LPVault
|
/// @title LPVault
|
||||||
/// @author Jordi Baylina
|
/// @author Jordi Baylina
|
||||||
/// @notice This contract holds ether securely for liquid pledging systems. For
|
|
||||||
/// this iteration the funds will come straight from the Giveth Multisig as a
|
/// @dev This contract holds ether securely for liquid pledging systems; for
|
||||||
/// safety precaution, but once fully tested and optimized this contract will
|
/// this iteration the funds will come often be escaped to the Giveth Multisig
|
||||||
|
/// (safety precaution), but once fully tested and optimized this contract will
|
||||||
/// be a safe place to store funds equipped with optional variable time delays
|
/// be a safe place to store funds equipped with optional variable time delays
|
||||||
/// to allow for an optional escape hatch to be implemented
|
/// to allow for an optional escapeHatch to be implemented in case of issues;
|
||||||
import "./Owned.sol";
|
/// future versions of this contract will be enabled for tokens
|
||||||
|
import "./Owned.sol";// TODO IMPORT ESCAPABLE :-D...............................???????????????????????????/
|
||||||
|
|
||||||
/// @dev `LiquidPledging` is a basic interface to allow the `LPVault` contract
|
/// @dev `LiquidPledging` is a basic interface to allow the `LPVault` contract
|
||||||
/// to confirm and cancel payments in the `LiquidPledging` contract.
|
/// to confirm and cancel payments in the `LiquidPledging` contract.
|
||||||
|
@ -19,21 +39,21 @@ contract LiquidPledging {
|
||||||
|
|
||||||
/// @dev `LPVault` is a higher level contract built off of the `Owned`
|
/// @dev `LPVault` is a higher level contract built off of the `Owned`
|
||||||
/// contract that holds funds for the liquid pledging system.
|
/// contract that holds funds for the liquid pledging system.
|
||||||
contract LPVault is Owned {
|
contract LPVault is Owned {// TODO NEEDS TO BE ESCAPABLE!!! AND WE NEED TO ADD A `WITHDRAW PARTIAL` FUNCTION????????????????
|
||||||
|
|
||||||
LiquidPledging public liquidPledging; // liquidPledging contract's address
|
LiquidPledging public liquidPledging; // LiquidPledging contract's address
|
||||||
bool public autoPay; // if false, payments will take 2 txs to be completed
|
bool public autoPay; // If false, payments will take 2 txs to be completed
|
||||||
|
|
||||||
enum PaymentStatus {
|
enum PaymentStatus {
|
||||||
Pending, // means the payment is awaiting confirmation
|
Pending, // When the payment is awaiting confirmation
|
||||||
Paid, // means the payment has been sent
|
Paid, // When the payment has been sent
|
||||||
Canceled // means the payment will never be sent
|
Canceled // When the payment will never be sent
|
||||||
}
|
}
|
||||||
/// @dev `Payment` is a public structure that describes the details of
|
/// @dev `Payment` is a public structure that describes the details of
|
||||||
/// each payment the `ref` param makes it easy to track the movements of
|
/// each payment the `ref` param makes it easy to track the movements of
|
||||||
/// funds transparently by its connection to other `Payment` structs
|
/// funds transparently by its connection to other `Payment` structs
|
||||||
struct Payment {
|
struct Payment {
|
||||||
PaymentStatus state; //
|
PaymentStatus state; // Pending, Paid or Canceled
|
||||||
bytes32 ref; // an input that references details from other contracts
|
bytes32 ref; // an input that references details from other contracts
|
||||||
address dest; // recipient of the ETH
|
address dest; // recipient of the ETH
|
||||||
uint amount; // amount of ETH (in wei) to be sent
|
uint amount; // amount of ETH (in wei) to be sent
|
||||||
|
@ -42,45 +62,49 @@ contract LPVault is Owned {
|
||||||
// @dev An array that contains all the payments for this LPVault
|
// @dev An array that contains all the payments for this LPVault
|
||||||
Payment[] public payments;
|
Payment[] public payments;
|
||||||
|
|
||||||
/// @dev `liquidPledging` is the only address that can call a function with
|
/// @dev The attached `LiquidPledging` contract is the only address that can
|
||||||
/// this modifier
|
/// call a function with this modifier
|
||||||
modifier onlyLiquidPledging() {
|
modifier onlyLiquidPledging() {
|
||||||
require(msg.sender == address(liquidPledging));
|
require(msg.sender == address(liquidPledging));
|
||||||
_;
|
_;
|
||||||
}
|
}
|
||||||
/// @dev USED FOR TESTING???
|
/// @dev Used for testing... SHOULD BE REMOVED FOR MAINNET LAUNCH OR MAYBE NOT????????????????????....................
|
||||||
function VaultMock() public pure {
|
function VaultMock() public pure {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
/// @dev The fall back function allows ETH to be deposited into the LPVault
|
||||||
|
/// through a simple send
|
||||||
function () public payable {
|
function () public payable {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @notice `setLiquidPledging` is used to attach a specific liquid pledging
|
/// @notice `onlyOwner` used to attach a specific liquidPledging instance
|
||||||
/// instance to this LPvault. Keep in mind this isn't a single pledge but
|
/// to this LPvault; keep in mind that once a liquidPledging contract is
|
||||||
/// instead an entire liquid pledging contract.
|
/// attached it cannot be undone, this vault will be forever connected
|
||||||
/// @param _newLiquidPledging A full liquid pledging contract
|
/// @param _newLiquidPledging A full liquid pledging contract
|
||||||
function setLiquidPledging(address _newLiquidPledging) public onlyOwner {
|
function setLiquidPledging(address _newLiquidPledging) public onlyOwner {
|
||||||
require(address(liquidPledging) == 0x0);
|
require(address(liquidPledging) == 0x0);
|
||||||
liquidPledging = LiquidPledging(_newLiquidPledging);
|
liquidPledging = LiquidPledging(_newLiquidPledging);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @notice `setAutopay` is used to toggle whether the LPvault will
|
/// @notice Used to decentralize, toggles whether the LPVault will
|
||||||
/// automatically confirm a payment after the payment has been authorized.
|
/// automatically confirm a payment after the payment has been authorized
|
||||||
/// @param _automatic If true payments will confirm automatically
|
/// @param _automatic If true, payments will confirm instantly, if false
|
||||||
|
/// the training wheels are put on and the owner must manually approve
|
||||||
|
/// every payment
|
||||||
function setAutopay(bool _automatic) public onlyOwner {
|
function setAutopay(bool _automatic) public onlyOwner {
|
||||||
autoPay = _automatic;
|
autoPay = _automatic;
|
||||||
|
AutoPaySet();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @notice `authorizePayment` is used in order to approve a payment
|
/// @notice `onlyLiquidPledging` authorizes payments from this contract, if
|
||||||
/// from the liquid pledging contract. Whenever a project or other address
|
/// `autoPay == true` the transfer happens automatically `else` the `owner`
|
||||||
/// needs to receive a payment it needs to be authorized with this contract.
|
/// must call `confirmPayment()` for a transfer to occur (training wheels);
|
||||||
/// @param _ref This parameter is used to reference details about the
|
/// either way, a new payment is added to `payments[]`
|
||||||
/// payment from another contract.
|
/// @param _ref References the payment will normally be the pledgeID
|
||||||
/// @param _dest This is the address that payments will end up being sent to
|
/// @param _dest The address that payments will be sent to
|
||||||
/// @param _amount This is the amount that the payment is being authorized
|
/// @param _amount The amount that the payment is being authorized for
|
||||||
/// for.
|
/// @return idPayment The id of the payment (needed by the owner to confirm)
|
||||||
function authorizePayment(
|
function authorizePayment(
|
||||||
bytes32 _ref,
|
bytes32 _ref,
|
||||||
address _dest,
|
address _dest,
|
||||||
|
@ -101,20 +125,18 @@ contract LPVault is Owned {
|
||||||
return idPayment;
|
return idPayment;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @notice `confirmPayment` is a basic function used to allow the
|
/// @notice Allows the owner to confirm payments; since
|
||||||
/// owner of the vault to initiate a payment confirmation. Since
|
/// `authorizePayment` is the only way to populate the `payments[]` array
|
||||||
/// `authorizePayment` is the only pay to populate the `payments` array
|
|
||||||
/// this is generally used when `autopay` is `false` after a payment has
|
/// this is generally used when `autopay` is `false` after a payment has
|
||||||
/// has been authorized.
|
/// has been authorized
|
||||||
/// @param _idPayment Array lookup for the payment.
|
/// @param _idPayment Array lookup for the payment.
|
||||||
function confirmPayment(uint _idPayment) public onlyOwner {
|
function confirmPayment(uint _idPayment) public onlyOwner {
|
||||||
doConfirmPayment(_idPayment);
|
doConfirmPayment(_idPayment);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @notice `doConfirmPayment` is used to actually initiate a payment
|
/// @notice Transfers ETH according to the data held within the specified
|
||||||
/// to the final destination. All of the payment information should be
|
/// payment id (internal function)
|
||||||
/// set before calling this function.
|
/// @param _idPayment id number for the payment about to be fulfilled
|
||||||
/// @param _idPayment Array lookup for the payment.
|
|
||||||
function doConfirmPayment(uint _idPayment) internal {
|
function doConfirmPayment(uint _idPayment) internal {
|
||||||
require(_idPayment < payments.length);
|
require(_idPayment < payments.length);
|
||||||
Payment storage p = payments[_idPayment];
|
Payment storage p = payments[_idPayment];
|
||||||
|
@ -123,21 +145,20 @@ contract LPVault is Owned {
|
||||||
p.state = PaymentStatus.Paid;
|
p.state = PaymentStatus.Paid;
|
||||||
liquidPledging.confirmPayment(uint64(p.ref), p.amount);
|
liquidPledging.confirmPayment(uint64(p.ref), p.amount);
|
||||||
|
|
||||||
p.dest.transfer(p.amount); // only ETH denominated in wei
|
p.dest.transfer(p.amount); // Transfers ETH denominated in wei
|
||||||
|
|
||||||
ConfirmPayment(_idPayment);
|
ConfirmPayment(_idPayment);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @notice `cancelPayment` is used when `autopay` is `false` in order
|
/// @notice When `autopay` is `false` and after a payment has been authorized
|
||||||
/// to allow the owner to cancel a payment instead of confirming it.
|
/// to allow the owner to cancel a payment instead of confirming it.
|
||||||
/// @param _idPayment Array lookup for the payment.
|
/// @param _idPayment Array lookup for the payment.
|
||||||
function cancelPayment(uint _idPayment) public onlyOwner {
|
function cancelPayment(uint _idPayment) public onlyOwner {
|
||||||
doCancelPayment(_idPayment);
|
doCancelPayment(_idPayment);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @notice `doCancelPayment` This carries out the task of actually
|
/// @notice Cancels a pending payment (internal function)
|
||||||
/// canceling a payment instead of confirming it.
|
/// @param _idPayment id number for the payment
|
||||||
/// @param _idPayment Array lookup for the payment.
|
|
||||||
function doCancelPayment(uint _idPayment) internal {
|
function doCancelPayment(uint _idPayment) internal {
|
||||||
require(_idPayment < payments.length);
|
require(_idPayment < payments.length);
|
||||||
Payment storage p = payments[_idPayment];
|
Payment storage p = payments[_idPayment];
|
||||||
|
@ -151,8 +172,7 @@ contract LPVault is Owned {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @notice `multiConfirm` allows for more efficient confirmation of
|
/// @notice `onlyOwner` An efficient way to confirm multiple payments
|
||||||
/// multiple payments.
|
|
||||||
/// @param _idPayments An array of multiple payment ids
|
/// @param _idPayments An array of multiple payment ids
|
||||||
function multiConfirm(uint[] _idPayments) public onlyOwner {
|
function multiConfirm(uint[] _idPayments) public onlyOwner {
|
||||||
for (uint i = 0; i < _idPayments.length; i++) {
|
for (uint i = 0; i < _idPayments.length; i++) {
|
||||||
|
@ -160,8 +180,7 @@ contract LPVault is Owned {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @notice `multiCancel` allows for more efficient cancellation of
|
/// @notice `onlyOwner` An efficient way to cancel multiple payments
|
||||||
/// multiple payments.
|
|
||||||
/// @param _idPayments An array of multiple payment ids
|
/// @param _idPayments An array of multiple payment ids
|
||||||
function multiCancel(uint[] _idPayments) public onlyOwner {
|
function multiCancel(uint[] _idPayments) public onlyOwner {
|
||||||
for (uint i = 0; i < _idPayments.length; i++) {
|
for (uint i = 0; i < _idPayments.length; i++) {
|
||||||
|
@ -169,14 +188,18 @@ contract LPVault is Owned {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @notice `nPayments` Basic getter to return the number of payments
|
/// @return The total number of payments that have ever been authorized
|
||||||
/// currently held in the system. Since payments are not removed from
|
|
||||||
/// the array this represents all payments over all time.
|
|
||||||
function nPayments() constant public returns (uint) {
|
function nPayments() constant public returns (uint) {
|
||||||
return payments.length;
|
return payments.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
event AutoPaySet();
|
||||||
event ConfirmPayment(uint indexed idPayment);
|
event ConfirmPayment(uint indexed idPayment);
|
||||||
event CancelPayment(uint indexed idPayment);
|
event CancelPayment(uint indexed idPayment);
|
||||||
event AuthorizePayment(uint indexed idPayment, bytes32 indexed ref, address indexed dest, uint amount);
|
event AuthorizePayment(
|
||||||
}
|
uint indexed idPayment,
|
||||||
|
bytes32 indexed ref,
|
||||||
|
address indexed dest,
|
||||||
|
uint amount
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue