Permalink
Browse files

Merge pull request #38 from eosdac/cdt1.4

Upgrade to CDT 1.4
  • Loading branch information...
michaeljyeates committed Nov 28, 2018
2 parents e1d6e95 + 238f173 commit e8a61478cf721ccd2720efff975babd26e6c7461
Showing with 2,654 additions and 780 deletions.
  1. +1 −0 .gitignore
  2. +20 −8 CMakeLists.txt
  3. +0 −471 daccustodian.abi
  4. +5 −0 daccustodian.clauses.md
  5. +209 −0 daccustodian.contracts.md
  6. +11 −8 daccustodian.hpp
  7. +3 −2 external_types.hpp
  8. +2 −2 newperiod_components.cpp
  9. +4 −2 output/jungle/compile.sh
  10. +0 −1 output/jungle/daccustodian/daccustodian.abi
  11. +508 −0 output/jungle/daccustodian/daccustodian.abi
  12. BIN output/jungle/daccustodian/daccustodian.wasm
  13. BIN output/jungle/daccustodian/daccustodian.wast
  14. +3 −2 output/mainnet_votingdisabled/compile.sh
  15. +0 −1 output/mainnet_votingdisabled/daccustodian/daccustodian.abi
  16. +508 −0 output/mainnet_votingdisabled/daccustodian/daccustodian.abi
  17. BIN output/mainnet_votingdisabled/daccustodian/daccustodian.wasm
  18. BIN output/mainnet_votingdisabled/daccustodian/daccustodian.wast
  19. +3 −2 output/mainnet_votingenabled/compile.sh
  20. +0 −1 output/mainnet_votingenabled/daccustodian/daccustodian.abi
  21. +508 −0 output/mainnet_votingenabled/daccustodian/daccustodian.abi
  22. BIN output/mainnet_votingenabled/daccustodian/daccustodian.wasm
  23. BIN output/mainnet_votingenabled/daccustodian/daccustodian.wast
  24. +3 −2 output/unit_tests/compile.sh
  25. +0 −1 output/unit_tests/daccustodian/daccustodian.abi
  26. +508 −0 output/unit_tests/daccustodian/daccustodian.abi
  27. BIN output/unit_tests/daccustodian/daccustodian.wasm
  28. BIN output/unit_tests/daccustodian/daccustodian.wast
  29. +1 −1 pay_handling.cpp
  30. +2 −2 registering.cpp
  31. +8 −8 tests/contract_spec.rb
  32. +347 −266 tests/dependencies/eosdactokens/eosdactokens.abi
  33. BIN tests/dependencies/eosdactokens/eosdactokens.wasm
  34. BIN tests/dependencies/eosdactokens/eosdactokens.wast
@@ -17,3 +17,4 @@ Project\.build/
Makefile
node_modules
.idea
cmake-build-release
@@ -1,8 +1,20 @@
file(GLOB ABI_FILES "*.abi")
configure_file("${ABI_FILES}" "${CMAKE_CURRENT_BINARY_DIR}" COPYONLY)
# Change "daccustodian" with the name of the folder containing your smart contracts
add_wast_executable(TARGET daccustodian
INCLUDE_FOLDERS "${STANDARD_INCLUDE_FOLDERS}"
LIBRARIES libc libc++ eosiolib
DESTINATION_FOLDER ${CMAKE_CURRENT_BINARY_DIR}
)

cmake_minimum_required(VERSION 3.5)
project(daccustodian VERSION 1.0.0)

find_package(eosio.cdt)

### Generate the wasm and abi
add_contract( daccustodian daccustodian
daccustodian.cpp
external_observable_actions.cpp
newperiod_components.cpp
pay_handling.cpp
migration.cpp
privatehelpers.cpp
registering.cpp
update_member_details.cpp
)

### add the path to where the ricardian contracts/clauses are found
target_compile_options( daccustodian.wasm PUBLIC -R${CMAKE_CURRENT_SOURCE_DIR} )

This file was deleted.

Oops, something went wrong.
@@ -0,0 +1,5 @@
<h1 class="clause">ENTIRE AGREEMENT</h1>
This contract contains the entire agreement of the parties, for all described actions, and there are no other promises or conditions in any other agreement whether oral or written concerning the subject matter of this Contract. This contract supersedes any prior written or oral agreements between the parties.

<h1 class="clause">BINDING CONSTITUTION</h1>
All the the action descibed in this contract are subject to the EOSDAC consitution as held at http://eosdac.io. This includes, but is not limited to membership terms and conditions, dispute resolution and severability.
@@ -0,0 +1,209 @@
<h1 class="contract">
stprofile
</h1>

## ACTION: stprofile
**PARAMETERS:**
* __cand__ is an eosio account name.
* __profile__ is a string that provides a hash of the details of the candidate.

**INTENT** The intent of stprofile is to record an update the user's profile.
#### Warning: This action will store the content on the chain in the history logs and the data cannot be deleted later so therefore should only store a unidentifiable hash of content rather than human readable content.

<h1 class="contract">
stprofileuns
</h1>

## ACTION: stprofileuns
**PARAMETERS:**
* __cand__ is an eosio account name.
* __profile__ is a string that provides a hash of the details of the candidate.

**INTENT:**
The intent of stprofileuns is to record an update the user's profile. ##Warning: This action will store the content on the chain in the history logs and the data cannot be deleted later.

<h1 class="contract">
updatebio
</h1>

## ACTION: updatebio
**PARAMETERS:**
* __cand__ is an eosio account name.
* __profile__ is a string that provides a hash of the details of the candidate.

**INTENT:**
The intent of updatebio is to record an update the user's bio. Unlike `stprofileuns` this action does not require auth of the cand to execute.
####Warning: This action will store the content on the chain in the history logs and the data cannot be deleted later.

<h1 class="contract">
firecust
</h1>

## ACTION: firecust
**PARAMETERS:**
* __cand__ is an eosio account name.

**INTENT:** The intent of firecust is to allow elected custodians to (where quorum and configured majorities are met) to remove a fellow custodian and lock up their tokens until the configured delay period has passed.
**TERM:** This action lasts for the duration of the time taken to process the transaction.

<h1 class="contract">
resigncust
</h1>
## ACTION: resigncust
**PARAMETERS:**
* __cust__ is an eosio account name.

**INTENT:** The intent of resigncust is to remove an elected custodian. This action must be run by the resigning custodian and the outcome should remove the elected custodian and lock up their tokens until the delay period has passed so the tokens can be claimed with the unstake action.
**TERM:** This action lasts for the duration of the time taken to process the transaction.

<h1 class="contract">
firecand
</h1>

## ACTION: firecand
**PARAMETERS:**
* __cand__ is an eosio account name.
* __lockupStake__ is an indicator to show whether stake is being locked up or not

**INTENT:**
The intent of forehand is to set a candidate to a state of inactive so they will be excluded from the next election round. This action may only be run by the by elected custodians (where quorum and configured majorities are met). There is an option to lock up the candidate's tokens until a delay period has passed based on the delay set in the config after which the tokens can be claimed with the unstake action. If the option passed is false and there is an existing lockup delay on the tokens then this lockup will continue to be active until the lock up time has passed.

**TERM:** This action lasts for the duration of the time taken to process the transaction.

<h1 class="contract">
unstake
</h1>

## ACTION: unstake
**PARAMETERS:**
* __cand__ is an eosio account name.

**INTENT** The intent of unstake is to return staked tokens back to the candidate if the user is no longer an active candidate and there is no delay set on the candidate the staked tokens will be returned to the candidate.
**TERM:** This action lasts for the duration of the time taken to process the transaction.

<h1 class="contract">
updateconfig
</h1>

## ACTION: updateconfig
**PARAMETERS:**
* __lockupasset__ is an asset to be locked up as part of the nominating process for a custodian passed to the action in the format: \"10.0000 EOSDAC\". default value: \"10.0000 EOSDAC\"
* __maxvotes__ is a integer to configure the maximum number of allowed votes for a nominated member in any single voting action. The default value is 5.
* __numelected__ is a integer to configure the number of candidates that will be elected as custodians of the DAC. default value is 12.
* __periodlength__ the length of office of a custodian vote (in seconds) before a new period . Default to 7 days.
* __authaccount__ The authorised account to change the contract which should be protected via a multisig of custodians,
* __tokenholder__ The account that controls the funds for the DAC.
* __initial_vote_quorum_percent__ The percent of voters required to activate the DAC for the first election period.
* __auth_threshold_high__ percentage of votes of custodians required to approve highest level actions.
* __auth_threshold_mid__ percentage of votes of custodians required to approve medium level actions.
* __auth_threshold_low__ percentage of votes of custodians required to approve lowest level actions.
* __lockup_release_time_delay__ The time before locked up stake can be released back to the candidate using the unstake action.
* __asset requested_pay_max__

**INTENT:** The intent of {{ updateconfig }} is update the configuration for the running contract of selected parameters without needing change the source code. This requires a privileged account.
**TERM:** The action sets the configuration until it is set by a subsequent updateconfig action.

<h1 class="contract">
nominatecand
</h1>

## ACTION: nominatecand
**PARAMETERS:**
* __cand__ is an account_name parameter for the nominating candidate.
* __requestedpay__ is an asset requested by the candidate as pay for being an elected custodian. It should be passed to the action in the format: \"10.0000 EOSDAC\".

**INTENT:** The intent of {{ nominatecand }} is to nominates a candidate to custodian election, Accounts must nominate as a candidate before they can be voted for. The candidate must lock a configurable number of tokens before trying to nominate (configurable via {{ updateconfig }} in the parameter lockupasset which will be sent from the token contract as defined and set in the code of the contract. If a user previously been a candidate they may have enough staked tokens to not require further staking but will otherwise need to transfer the difference to meet the required stake.

**TERM:** A candidate remains a candidate until they are removed from candidate status by a subsequent transaction.

<h1 class="contract">
withdrawcand
</h1>

## ACTION: withdrawcand
**PARAMETERS:**
* __cand__ is an account_name parameter for the nominating candidate.

**INTENT:** The intent of withdrawcand is to withdraw a candidate for becoming an elected custodian. The action ensures the {{ cand }} account is currently nominated. On success the amount of tokens that was locked up via the {{ nominatecand }} action will be added to a list of pending transactions to transfer back to the {{ cand }} account. The actual transfer would be performed by a separate action due to the auth requirement for sending funds from the contract's account.

**TERM:** The account will no longer be a candidate unless they it is nominated again.

## ACTION: updatebio
**PARAMETERS:**
* __cand__ is an account_name parameter for the nominating candidate.
* __bio__ is a string representing a bio for candidate. This should be a hash or a link where data is under the control of the individual.

**INTENT:** The intent of updatebio is to allow a candidate update their bio information after they have nominated. The action ensures the user has agreed to the latest terms and conditions, has the correct authorization of the {{ cand }} to perform the action and is already nominated as a candidate. Then the bio information for the candidate will be updated leaving all other data of the candidate unchanged.

**WARNING:** The action records information on the blockchain and hence should not include directly entered personally identifiable information. Instead hashes or links under the control of the individual should be used.

<h1 class="contract">
updatereqpay
</h1>

## ACTION: updatereqpay
**PARAMETERS:**
* __cand__ is an account_name parameter for the nominating candidate.
* __requestedpay__ is an asset requested by the candidate as pay for being an elected custodian. It should be passed to the action in the format: \"10.0000 EOSDAC\".

**INTENT:** The intent of updatereqpay is to allow a candidate update their requested pay after they have nominated. The action ensures the user has agreed to the latest terms and conditions, has the correct authorization of the {{ cand }} to perform the action and is already nominated as a candidate. All other data of the candidate will remain unchanged. If the custodian is elected, this requested pay is used along with other elected custodians requested pay to determine the level of pay for custodians

**TERM:** The action changes the values until superseded by another action.

<h1 class="contract">
votecust
</h1>

## ACTION: votecust
**PARAMETERS:**
* __voter__ is an eosio account_name parameter for the voting member.
* __newvotes__ is an array of nominated candidates account names that the voter intends to vote for with a maximum number of votes as configured by the contract.

**INTENT:** The intent of votecust is to allow a member of the DAC to vote for candidates that are eligible become custodians after the next call to {{ newperiod }}. The action ensures the user has agreed to the latest terms and conditions and has the correct authorization of the account: {{ voter }} to place or change an active vote. Upon success this action will either update an existing vote with a new set of candidates or create a new active vote for the {{ voter }} for candidates eligible for election. This action will replace an existing vote for a proxy for {{ voter }} if one exists.

**TERM:** The action changes the preferred custodians for an account until superseded by another action.

<h1 class="contract">
voteproxy
</h1>

## ACTION: voteproxy
**PARAMETERS:**
* __voter__ is an eosio account_name .
* __proxy__ is an account name that the voter intends to vote for with a maximum number of votes as configured by the contract.

**INTENT:** The intent of voteproxy is to vote another single voter account that may vote with {{ voter }} weight for custodians as a proxy. The action ensures the {{ voter }} has agreed to the latest terms and conditions and has the correct authorization of the {{ voter }} to place or change an active vote. Upon success this action will either update an existing {{ proxy }} vote or create a new active vote for {{ proxy }}. This action will replace an existing vote for a custodians as created by the votecust action if one exists. This action will fail if {{ voter }} attempts to vote for a user who is already voting for a proxy or if they attempt to proxy vote for themselves.

**TERM:** The action changes the proxy until superseded by another action.

<h1 class="contract">
newperiod
</h1>

## ACTION: newperiod
**PARAMETERS:**
* __message__ is string used only for logging in the blockchain history and serves no purpose in the action contract logic.

**INTENT:** The intent of {{ newperiod }} is to signal the end of one election period and commence the next. It performs several actions after the following conditions are met:
* The action is not called before the period should have ended
* Enough voter value has participated to trigger the initial running of the DAC
* After the Dac has started enough voter value has continued engagement with the dac voting process.
1. Calculate the mean `requestedpay` of all the currently elected custodians.
2. Distribute the median pay amount to all the currently elected custodians. This is achieved by adding a record to the `pendingpay` table with the custodian and the amount payable in preparation for an authorised action to `claimpay`.
3. Captures the highest voted candidates to set them as the custodians for the next period based on the accumulated vote weight.
4. Set the permissions for the elected custodians so they have sufficient permission to run the dac according to the constitution and technical permissions design.
5. Set the time for the beginning of the next period to mark the reset anniversary for the dac.

**TERM:** The action changes the relevant contract data until a subsequent newperiod is called.

<h1 class="contract">
claimpay
</h1>

## ACTION: claimpay
**PARAMETERS:**
* __claimer__ account claiming the pay. This account must match the destination account for which the claim is for.

**INTENT:** The intent of {{ claimpay }} is to allow an account to claim pending payment amounts due to the account. The pay claim they are claiming needs to be visible in the `pendingpay` table. transfers to the claimer via an inline transfer on the eosdactoken contract and then removes the pending payment record from the `pending_pay` table. The active auth of this claimer is required to complete this action.

**TERM:** This action lasts for the duration of the time taken to process the transaction.
@@ -1,5 +1,8 @@
#include <eosiolib/eosio.hpp>
#include <eosiolib/multi_index.hpp>
#include <eosiolib/singleton.hpp>
#include <eosiolib/time.hpp>

#include "external_types.hpp"

#define _STRINGIZE(x) #x
@@ -25,7 +28,7 @@ const name HIGH_PERMISSION = "high"_n;
using namespace eosio;
using namespace std;

struct [[eosio::table("config")]] contr_config {
struct [[eosio::table("config"), eosio::contract("daccustodian")]] contr_config {
// The amount of assets that are locked up by each candidate applying for election.
asset lockupasset;
// The maximum number of votes that each member can make for a candidate.
@@ -84,7 +87,7 @@ struct [[eosio::table("config")]] contr_config {

typedef singleton<"config"_n, contr_config> configscontainer;

struct [[eosio::table("state")]] contr_state {
struct [[eosio::table("state"), eosio::contract("daccustodian")]] contr_state {
uint32_t lastperiodtime = 0;
int64_t total_weight_of_votes = 0;
int64_t total_votes_on_candidates = 0;
@@ -106,13 +109,13 @@ uint128_t combine_ids(const uint8_t &boolvalue, const uint64_t &longValue) {
return (uint128_t{boolvalue} << 8) | longValue;
}

struct [[eosio::table("candidates")]] candidate {
struct [[eosio::table("candidates"), eosio::contract("daccustodian")]] candidate {
name candidate_name;
asset requestedpay;
asset locked_tokens;
uint64_t total_votes;
uint8_t is_active;
uint32_t custodian_end_time_stamp;
time_point_sec custodian_end_time_stamp;

uint64_t primary_key() const { return candidate_name.value; }

@@ -133,7 +136,7 @@ typedef multi_index<"candidates"_n, candidate,
indexed_by<"byreqpay"_n, const_mem_fun<candidate, uint64_t, &candidate::by_requested_pay> >
> candidates_table;

struct [[eosio::table("custodians")]] custodian {
struct [[eosio::table("custodians"), eosio::contract("daccustodian")]] custodian {
name cust_name;
asset requestedpay;
uint64_t total_votes;
@@ -153,7 +156,7 @@ typedef multi_index<"custodians"_n, custodian,
indexed_by<"byreqpay"_n, const_mem_fun<custodian, uint64_t, &custodian::by_requested_pay> >
> custodians_table;

struct [[eosio::table("votes")]]vote {
struct [[eosio::table("votes"), eosio::contract("daccustodian")]] vote {
name voter;
name proxy;
std::vector<name> candidates;
@@ -169,7 +172,7 @@ typedef eosio::multi_index<"votes"_n, vote,
indexed_by<"byproxy"_n, const_mem_fun<vote, uint64_t, &vote::by_proxy> >
> votes_table;

struct [[eosio::table("pendingpay")]] pay {
struct [[eosio::table("pendingpay"), eosio::contract("daccustodian")]] pay {
uint64_t key;
name receiver;
asset quantity;
@@ -185,7 +188,7 @@ typedef multi_index<"pendingpay"_n, pay,
indexed_by<"byreceiver"_n, const_mem_fun<pay, uint64_t, &pay::byreceiver> >
> pending_pay_table;

struct [[eosio::table("pendingstake")]] tempstake {
struct [[eosio::table("pendingstake"), eosio::contract("daccustodian")]] tempstake {
name sender;
asset quantity;
string memo;
@@ -1,11 +1,12 @@
#include <eosiolib/eosio.hpp>
#include <eosiolib/asset.hpp>

using namespace eosio;
using namespace std;

struct currency_stats {
asset supply;
asset max_supply;
eosio::asset supply;
eosio::asset max_supply;
name issuer;
bool transfer_locked = false;

@@ -51,7 +51,7 @@ void daccustodian::allocateCustodians(bool early_election) {
const auto &reg_candidate = registered_candidates.get(cust_itr->cust_name.value, "ERR::NEWPERIOD_EXPECTED_CAND_NOT_FOUND::Corrupt data: Trying to set a lockup delay on candidate leaving office.");
registered_candidates.modify(reg_candidate, cust_itr->cust_name, [&](candidate &c) {
eosio::print("Lockup stake for release delay.");
c.custodian_end_time_stamp = now() + configs().lockup_release_time_delay;
c.custodian_end_time_stamp = time_point_sec(now() + configs().lockup_release_time_delay);
});
cust_itr = custodians.erase(cust_itr);
}
@@ -78,7 +78,7 @@ void daccustodian::allocateCustodians(bool early_election) {

byvotes.modify(cand_itr, cand_itr->candidate_name, [&](candidate &c) {
eosio::print("Lockup stake for release delay.");
c.custodian_end_time_stamp = now() + configs().lockup_release_time_delay;
c.custodian_end_time_stamp = time_point_sec(now() + configs().lockup_release_time_delay);
});

currentCustodianCount++;
@@ -1,3 +1,5 @@
#!/usr/bin/env bash
#eosio-cpp -DTOKEN_CONTRACT='"kasdactokens"' -DTRANSFER_DELAY=20 -o output/jungle/daccustodian/daccustodian.wast daccustodian.cpp
~/Documents/code/EOSIO/eosio.cdt/build/bin/eosio-cpp -DTOKENCONTRACT='"kasdactokens"' -DTRANSFER_DELAY=20 -o output/jungle/daccustodian/daccustodian.wast daccustodian.cpp

eosio-cpp -DTOKENCONTRACT='"kasdactokens"' -DTRANSFER_DELAY=20 -o output/jungle/daccustodian/daccustodian.wasm daccustodian.cpp

eosio-abigen daccustodian.hpp -contract daccustodian -output output/jungle/daccustodian/daccustodian.abi

This file was deleted.

Oops, something went wrong.
Oops, something went wrong.

0 comments on commit e8a6147

Please sign in to comment.