Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Eden Upvote PR #364

Closed
wants to merge 56 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
98e5ab9
Fix designated initializers
Gerard097 Jul 26, 2023
7f8ce43
Fix likeable interface
Gerard097 Jul 26, 2023
ce3524e
Fix Pricing plan designated initializer
Gerard097 Jul 28, 2023
bc7d639
Merge pull request #353 from hypha-dao/feature/tokenomics
n13 Aug 1, 2023
a41d84d
intermediary check in
n13 Sep 20, 2023
088deef
Merge branch 'develop' into feature/upvote_2
n13 Sep 20, 2023
618dba5
merge accident
n13 Sep 20, 2023
5c6da1b
Merge branch 'develop' into feature/upvote_2
n13 Sep 20, 2023
9409a51
bugfix for contract create proposal
n13 Sep 21, 2023
7921eb9
many fixes to set up a DAO from zero
n13 Sep 21, 2023
8210068
intermediary check in
n13 Sep 21, 2023
38b4f0a
removed various naked send() delayed actions
n13 Sep 21, 2023
bf9c2c4
Revert "removed various naked send() delayed actions"
n13 Sep 21, 2023
bef23df
back to inline actions
n13 Sep 21, 2023
077d504
Modify setup.sh as bin/bash
Gerard097 Sep 22, 2023
d0f358f
Fix setup.sh colored text in Mac
Gerard097 Sep 22, 2023
d9392f8
intermediary check in
n13 Sep 24, 2023
b34ad2e
more testing
n13 Sep 24, 2023
5a608cb
added ElectionGroup class and docuument
n13 Sep 25, 2023
6cefd8d
intermediary check in
n13 Sep 25, 2023
37151f5
intermediary check in
n13 Sep 26, 2023
e307a4e
intermediary check in
n13 Sep 26, 2023
569e0db
intermediary check in
n13 Sep 26, 2023
ca2437e
ignoring lib folder - using vs code plugin that added libs
n13 Sep 26, 2023
17d05bf
intermediary check in
n13 Sep 26, 2023
1603d53
added edenia code to calculate group sizes
n13 Sep 27, 2023
ce3dd66
added a modified updateSeed method
n13 Sep 27, 2023
08c8f9e
winner needs to have voted for themselves
n13 Sep 28, 2023
d052172
intermediary check in
n13 Sep 29, 2023
1f4d8f2
updates
n13 Oct 2, 2023
5d21495
updates and fixes - return value on addRound fix
n13 Oct 3, 2023
e726c40
Change Voice default multiplier to x1
Gerard097 Oct 3, 2023
e1bbd5a
updates
n13 Oct 5, 2023
4b0d131
Disable membership check to create dao action
Gerard097 Oct 5, 2023
37c6c1d
reffactoring, creating subsequent rounds and winner round
n13 Oct 6, 2023
0a47c45
assignDelegateBadges can remove existing
n13 Oct 9, 2023
3c23dc4
using transaction for removing of CD edges
n13 Oct 10, 2023
e5531f9
bugfix - set seed on upcoming election
n13 Oct 10, 2023
076fdfb
bugfixes
n13 Oct 10, 2023
f3518f5
Removed Reward to Peg ration & fixed token multipliers
Gerard097 Oct 11, 2023
0745b17
add group winner edge
n13 Oct 11, 2023
9700fa0
cleanup
n13 Oct 11, 2023
23c5434
Merge branch 'develop' into feature/upvote_3_merge
n13 Oct 11, 2023
332bb43
remove title label again
n13 Oct 11, 2023
fbbc698
fix node label on upvote
n13 Oct 12, 2023
1f258a8
remove debug code
n13 Oct 12, 2023
18a8307
init last round in election
n13 Oct 12, 2023
244bfac
handle case where there's no delegates - cancel
n13 Oct 12, 2023
9069bf2
remove delete existing badges
n13 Oct 16, 2023
0daab06
added allowance for unit testing
n13 Oct 16, 2023
4f65d05
upload video link
n13 Oct 16, 2023
141d589
delete previous election edge if it exists
n13 Oct 23, 2023
20d275a
Add helper function to cleanup DAO from axuliar tables
Gerard097 Oct 26, 2023
7056daf
deploy scropts
n13 Oct 26, 2023
2c2d4e7
Merge branch 'develop' into feature/upvote_3_merge
n13 Oct 26, 2023
006e776
deploy scripts
n13 Oct 26, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ main1.go
dao-contracts
migration.sh
build_ninja
lib
File renamed without changes.
3 changes: 3 additions & 0 deletions build_only.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
cd build
make -j10
wasm-opt -O3 dao/dao.wasm -o dao/dao_O3.wasm
1 change: 1 addition & 0 deletions deploy_eos_mainnet.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
cleos -u http://eos.greymass.com set contract dao.hypha build/dao dao_O3.wasm dao.abi
1 change: 1 addition & 0 deletions deploy_eos_testnet.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
cleos -u https://jungle4.dfuse.eosnation.io set contract daoxhypha111 build/dao dao_O3.wasm dao.abi
3 changes: 3 additions & 0 deletions deploy_only.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
cd build
wasm-opt -O3 dao/dao.wasm -o dao/dao_O3.wasm
cleos set contract dao.hypha dao dao_O3.wasm dao.abi
1 change: 1 addition & 0 deletions deploy_telos_mainnet.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
cleos -u http://mainnet.telos.net set contract dao.hypha build/dao dao_O3.wasm dao.abi
1 change: 1 addition & 0 deletions deploy_testnet.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
cleos -u https://testnet.telos.net set contract mtdhoxhyphaa build/dao dao_O3.wasm dao.abi
5 changes: 2 additions & 3 deletions include/assignment.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ namespace hypha
class dao;
class TimeShare;
class Settings;
struct AssetBatch;

class Assignment : public RecurringActivity
{
Expand All @@ -26,9 +27,7 @@ namespace hypha
TimeShare getCurrentTimeShare();
TimeShare getLastTimeShare();

eosio::asset getRewardSalary();
eosio::asset getVoiceSalary();
eosio::asset getPegSalary();
AssetBatch getSalary();

inline uint64_t getDaoID() { return m_daoID; }
private:
Expand Down
4 changes: 2 additions & 2 deletions include/badges/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ namespace items {
}

namespace links {
// inline constexpr auto TREASURY_BADGE = "treasurerbdg";
inline constexpr auto TREASURY_BADGE = eosio::name("treasurerbdg");
inline constexpr auto ADMIN_BADGE = eosio::name("adminbdg");
inline constexpr auto ENROLLER_BADGE = eosio::name("enrollerbdg");
// inline constexpr auto NORTH_STAR_BADGE = "northstarbdg";
inline constexpr auto NORTH_STAR_BADGE = eosio::name("northstarbdg");
inline constexpr auto VOTER = eosio::name("voter");
inline constexpr auto DELEGATE = eosio::name("delegate");
inline constexpr auto HEAD_DELEGATE = eosio::name("headdelegate");
Expand Down
1 change: 0 additions & 1 deletion include/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ namespace hypha::common
inline constexpr auto PEG_TOKEN = "peg_token";
inline constexpr auto VOICE_TOKEN = "voice_token";
inline constexpr auto REWARD_TOKEN = "reward_token";
inline constexpr auto REWARD_TO_PEG_RATIO = "reward_to_peg_ratio";
inline constexpr auto NATIVE_TOKEN_TO_USD_RATIO = "native_token_to_usd_ratio";
inline constexpr symbol S_REWARD("BM", 2);
inline constexpr symbol S_VOICE("BMV", 2);
Expand Down
2 changes: 1 addition & 1 deletion include/config/config.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#pragma once
#define PRODUCTION_BUILD
#define USE_TREASURY
// #define USE_UPVOTE_ELECTIONS
#define USE_UPVOTE_ELECTIONS
// #define USE_PRICING_PLAN
42 changes: 40 additions & 2 deletions include/dao.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
#include <period.hpp>
#include <settings.hpp>

// TODO: Move this to upvote code section
#include <upvote_election/random_number_generator.hpp>

#include <config/config.hpp>

using eosio::multi_index;
Expand Down Expand Up @@ -192,10 +195,14 @@ namespace pricing {

ACTION remdoc(uint64_t doc_id);

ACTION cleandao(uint64_t dao_id);

ACTION createcalen(bool is_default);

ACTION initcalendar(uint64_t calendar_id, uint64_t next_period);

ACTION reset(); // debugging - maybe with the dev flags

#ifdef DEVELOP_BUILD_HELPERS

struct InputEdge {
Expand Down Expand Up @@ -297,6 +304,7 @@ namespace pricing {

ACTION createroot(const std::string &notes);
ACTION createdao(ContentGroups &config);

ACTION createdaodft(ContentGroups &config);
ACTION deletedaodft(uint64_t dao_draft_id);
ACTION archiverecur(uint64_t document_id);
Expand Down Expand Up @@ -326,11 +334,22 @@ namespace pricing {
#endif
#ifdef USE_UPVOTE_ELECTIONS
//Upvote System
// ACTION testgrouprng(std::vector<uint64_t> ids, uint32_t seed);
// ACTION testgroupr1(uint32_t num_members, uint32_t seed);
// ACTION testround(uint64_t dao_id);

ACTION castupvote(uint64_t round_id, uint64_t group_id, name voter, uint64_t voted_id);
ACTION uesubmitseed(uint64_t dao_id, eosio::checksum256 seed, name account);
ACTION upvotevideo(uint64_t group_id, name account, std::string link);


ACTION createupvelc(uint64_t dao_id, ContentGroups& election_config);
ACTION editupvelc(uint64_t election_id, ContentGroups& election_config);
ACTION cancelupvelc(uint64_t election_id);
ACTION updateupvelc(uint64_t election_id, bool reschedule);
ACTION castelctnvote(uint64_t round_id, name voter, std::vector<uint64_t> voted);
ACTION updateupvelc(uint64_t election_id, bool reschedule, bool force);



#ifdef EOS_BUILD
ACTION importelct(uint64_t dao_id, bool deferred);
#endif
Expand Down Expand Up @@ -482,6 +501,19 @@ namespace pricing {

void createToken(const std::string& contractType, name issuer, const asset& token);

template <typename T>
inline void delete_table (const name & code, const uint64_t & scope) {

T table(code, scope);
auto itr = table.begin();

while (itr != table.end()) {
itr = table.erase(itr);
}

}


private:

void onRewardTransfer(const name& from, const name& to, const asset& amount);
Expand Down Expand Up @@ -509,6 +541,12 @@ namespace pricing {

void addDefaultSettings(ContentGroup& settingsGroup, const string& daoTitle, const string& daoDescStr);

void _setupdefs(uint64_t dao_id);

void initSysBadges();
void createSystemBadge(name badge_edge, string label, string icon);


template<class Table>
std::optional<uint64_t> getNameID(const name& n) const
{
Expand Down
46 changes: 28 additions & 18 deletions include/upvote_election/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace hypha::upvote_election::common {

namespace round_types {
// TODO: We can remove round types - not needed
inline constexpr auto DELEGATE = "delegate";
inline constexpr auto CHIEF = "chief";
inline constexpr auto HEAD = "head";
Expand All @@ -17,8 +18,12 @@ namespace groups {
namespace types {
inline constexpr auto UPVOTE_ELECTION = eosio::name("upvt.electn");
inline constexpr auto ELECTION_ROUND = eosio::name("electn.round");
inline constexpr auto ELECTION_GROUP = eosio::name("electn.group");
inline constexpr auto ELECTION_VOTE = eosio::name("election.vote");
inline constexpr auto ELECTION_VOTE_GROUP = eosio::name("vote.group");
inline constexpr auto ELECTION_UP_VOTE = eosio::name("upvt.vote");

// TODO: Remove this
inline constexpr auto ELECTION_VOTE_GROUP = eosio::name("vote.group");//??
}

namespace upvote_status {
Expand All @@ -29,31 +34,36 @@ namespace upvote_status {
}

namespace links {
inline constexpr auto UPCOMING_ELECTION = eosio::name("upcomingelct");
inline constexpr auto ONGOING_ELECTION = eosio::name("ongoingelct");
inline constexpr auto PREVIOUS_ELECTION = eosio::name("previouselct");
inline constexpr auto ELECTION = eosio::name("election");
inline constexpr auto START_ROUND = eosio::name("startround");
inline constexpr auto CURRENT_ROUND = eosio::name("currentround");
inline constexpr auto CHIEF_ROUND = eosio::name("chiefround");
inline constexpr auto HEAD_ROUND = eosio::name("headround");
inline constexpr auto ROUND = eosio::name("round");
inline constexpr auto NEXT_ROUND = eosio::name("nextround");
inline constexpr auto ROUND_CANDIDATE = eosio::name("candidate");
inline constexpr auto ROUND_WINNER = eosio::name("winner");
inline constexpr auto ELECTION_GROUP = eosio::name("elctngroup");
inline constexpr auto VOTE = eosio::name("vote");
inline constexpr auto CHIEF_DELEGATE = eosio::name("chiefdelegate");
inline constexpr auto HEAD_DELEGATE = eosio::name("headdelegate");
inline constexpr auto ELECTION = eosio::name("ue.election");
inline constexpr auto UPCOMING_ELECTION = eosio::name("ue.upcoming");
inline constexpr auto ONGOING_ELECTION = eosio::name("ue.ongoing");
inline constexpr auto PREVIOUS_ELECTION = eosio::name("ue.previous");
inline constexpr auto START_ROUND = eosio::name("ue.startrnd");
inline constexpr auto CURRENT_ROUND = eosio::name("ue.currnd");
inline constexpr auto ELECTION_ROUND = eosio::name("ue.round");
inline constexpr auto ELECTION_ROUND_MEMBER = eosio::name("ue.rd.member");
inline constexpr auto ELECTION_GROUP_LINK = eosio::name("ue.group.lnk");
inline constexpr auto NEXT_ROUND = eosio::name("ue.nextrnd");
inline constexpr auto ROUND_CANDIDATE = eosio::name("ue.candidate");
inline constexpr auto ROUND_WINNER = eosio::name("ue.winner");
inline constexpr auto GROUP_WINNER = eosio::name("ue.group.win");
inline constexpr auto ELECTION_GROUP = eosio::name("ue.elctngrp");
inline constexpr auto UP_VOTE_VOTE = eosio::name("ue.vote");
inline constexpr auto UPVOTE_GROUP_WINNER = eosio::name("ue.winner");
inline constexpr auto VOTE = eosio::name("vote"); // ??

// these are defined in badges::common::links
// inline constexpr auto CHIEF_DELEGATE
// inline constexpr auto HEAD_DELEGATE
}

namespace items {
inline constexpr auto UPVOTE_STARTDATE = "upvote_start_date_time";
inline constexpr auto UPVOTE_DURATION = "upvote_duration";
inline constexpr auto ROUND_DURATION = "duration";
inline constexpr auto PASSING_AMOUNT = "passing_count";
inline constexpr auto ROUND_ID = "round_id";
inline constexpr auto ROUND_TYPE = "type";
inline constexpr auto WINNER = "winner"; // ?? delete?
}

} // namespace hypha::upvote
120 changes: 120 additions & 0 deletions include/upvote_election/convert.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
#pragma once

#include <optional>
#include <type_traits>
#include <utility>
#include <variant>
#include <vector>
#include "for_each_field.hpp"
#include "stream.hpp"

namespace eosio
{
struct no_conversion
{
using reverse = no_conversion;
};
struct widening_conversion;
// Fields must match exactly
struct strict_conversion
{
using reverse = strict_conversion;
};
// Can discard some fields
struct narrowing_conversion
{
using reverse = widening_conversion;
};
// Can default construct some fields
struct widening_conversion
{
using reverse = narrowing_conversion;
};

no_conversion conversion_kind(...);
void serialize_as(...);

template <typename T>
using serialization_type = decltype(serialize_as(std::declval<T>()));

template <typename T, typename U>
using conversion_kind_t = std::conditional_t<
std::is_same_v<decltype(conversion_kind(std::declval<T>(), std::declval<U>())),
no_conversion>,
typename decltype(conversion_kind(std::declval<U>(), std::declval<T>()))::reverse,
decltype(conversion_kind(std::declval<T>(), std::declval<U>()))>;

template <typename Field, typename T, typename U, typename F>
auto convert_impl(Field field, const T& src, U& dst, F&& f, int)
-> std::void_t<decltype(field(&src)), decltype(field(&dst))>
{
convert(field(&src), field(&dst), f);
}

template <typename Field, typename T, typename U, typename F>
auto convert_impl(Field field, const T& src, U& dst, F&& f, long)
{
static_assert(!std::is_same_v<conversion_kind_t<T, U>, strict_conversion>,
"Member not found");
static_assert(!std::is_same_v<conversion_kind_t<T, U>, widening_conversion>,
"Member not found");
}

inline constexpr auto choose_first = [](auto src, auto dest) { return src; };
inline constexpr auto choose_second = [](auto src, auto dest) { return dest; };

// TODO: add some validation

template <typename T, typename U, typename F>
void convert(const T& src, U& dst, F&& chooser)
{
if constexpr (std::is_same_v<T, U>)
{
dst = src;
}
else
{
static_assert(!std::is_same_v<conversion_kind_t<T, U>, no_conversion>,
"Conversion not defined");
for_each_field<std::decay_t<decltype(*chooser((T*)nullptr, (U*)nullptr))>>(
[&](const char*, auto field) { convert_impl(field, src, dst, chooser, 0); });
}
}

template <typename... T, typename U, typename F>
void convert(const std::variant<T...>& src, U& dst, F&& chooser)
{
std::visit([&](auto& src) { return convert(src, dst, chooser); }, src);
}

template <typename T, typename U, typename F>
void convert(const std::vector<T>& src, std::vector<U>& dst, F&& chooser)
{
dst.resize(src.size());
for (std::size_t i = 0; i < src.size(); ++i)
{
convert(src[i], dst[i], chooser);
}
}

template <typename T, typename U, typename F>
void convert(const std::optional<T>& src, std::optional<U>& dst, F&& chooser)
{
if (src)
{
dst.emplace();
convert(*src, *dst, chooser);
}
else
{
dst = std::nullopt;
}
}

struct stream;
template <typename F>
void convert(const input_stream& src, std::vector<char>& dst, F&& chooser)
{
dst.assign(src.pos, src.end);
}
} // namespace eosio
Loading
Loading