Skip to content

Commit

Permalink
[Stdlib] VoteLib and MultiSig, plus refactors and new policies in Don…
Browse files Browse the repository at this point in the history
…orDirectedAccounts (CommunityWallet). (#1249)

* Scaffold and doc for ParticipationVote

* initializing ballots

* refactor so that external contracts import the type.

* refactor vote, and add test

* add meta test for importing voting.

* flesh out extension logic

* patch tests

* tests for the threshold curve

* rename folder

* patch tests

* tests for retract

* votelib tests passing

* text

* initial scaffold of a multisig account.

* can init, propose and vote for a multi sig transaction

* test for init multisig

* governance functions for multisig

* add billing

* refactor using generics to create Types of MultiSig

* builds

* refactor governance

* update authorities

* refactor (again) assuming the generic use case. Proposal struct can have a nested prop_type with the data needed for a handler.

* separate multisig handler for payments from the multsig contract

* builds

* tests WIP

* tests passing and docs

* cleanup

* refactor so actions are separate from the governance. Signers are same for all Actions. Builds

* refactored. builds

* governance is just an instance of Action.

* clean

* separate init of Gov struct from Action

* root service initialization

* patch billing

* update expiration logic

* split logic of Wallet into DonorDirected and CommunityWallet

* rename modules. builds

* renames. builds

* remove donor directed from diemaccount

* clean

* patch multisig tests

* cleanup wip. builds

* start directed account governance

* refactor votelib to include ballot data

* can add a veto to a tx

* refactor processing. builds

* veto handler implemented. clean build

* allow donor directed governance to extend to match

* patch community wallet

* refactor governance to use Poll struct. builds

* make Poll and Ballot generic

* make Poll and Ballot generic

* renames

* wip refactoring participation vote

* wip refactor multisig to use Vote

* refactored multisig to use VoteLib. feature complete. Builds

* cleanup

* wip migrating MultiSig implementations

* WIP standalone

* refactored standalone poll as own module. builds.

* naming and documentation

* docs

* cleanup new multisig implementation

* remove deprecated multisig, builds

* refactored payment multisig

* rename VoteLib module to Ballot

* turnouttally type refactored.

* make votereceipt a separate module

* docs

* refactor binary tally to be stateless. Make a separate stateful simple turnkey contract.

* refactor DonorDirectedGovernance. builds

* refactored donor directed governance. apis fixed. builds

* WIP refactoring votelib tests

* vote_lib tests passing.

* refactor searching by ballot data

* multisig tests passing

* wip community wallet tests

* wip

* refactor donordirected structs, names. builds

* clean up traits in multisig

* patch test

* WIP tests

* fix issues with donation and receipt tracking.

* community transfer tx script passing.

* test payment to non-slow passing.

* patched diem_account tests

* patch burn deposit index

* patch burn ratios

* added unit tests for burn

* burn tests passing

* refactor autopay to respect transfer limits

* patch and add autopay tests. passing.

* all tests passing
  • Loading branch information
0o-de-lally authored Apr 4, 2023
1 parent 248002e commit cd2bac0
Show file tree
Hide file tree
Showing 221 changed files with 17,625 additions and 3,271 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ compiled_package_info:
? address: "00000000000000000000000000000001"
name: BCS
: Std
? address: "00000000000000000000000000000001"
name: Ballot
: DiemFramework
? address: "00000000000000000000000000000001"
name: BinaryTally
: DiemFramework
? address: "00000000000000000000000000000001"
name: BitVector
: Std
Expand All @@ -67,6 +73,9 @@ compiled_package_info:
? address: "00000000000000000000000000000001"
name: ChainId
: DiemFramework
? address: "00000000000000000000000000000001"
name: CommunityWallet
: DiemFramework
? address: "00000000000000000000000000000001"
name: CoreAddresses
: DiemFramework
Expand Down Expand Up @@ -118,6 +127,12 @@ compiled_package_info:
? address: "00000000000000000000000000000001"
name: DiemVersion
: DiemFramework
? address: "00000000000000000000000000000001"
name: DonorDirected
: DiemFramework
? address: "00000000000000000000000000000001"
name: DonorDirectedGovernance
: DiemFramework
? address: "00000000000000000000000000000001"
name: DualAttestation
: DiemFramework
Expand Down Expand Up @@ -178,6 +193,12 @@ compiled_package_info:
? address: "00000000000000000000000000000001"
name: Mock
: DiemFramework
? address: "00000000000000000000000000000001"
name: MultiSig
: DiemFramework
? address: "00000000000000000000000000000001"
name: MultiSigPayment
: DiemFramework
? address: "00000000000000000000000000000001"
name: NetworkIdentity
: DiemFramework
Expand Down Expand Up @@ -262,6 +283,15 @@ compiled_package_info:
? address: "00000000000000000000000000000001"
name: TreasuryComplianceScripts
: DiemFramework
? address: "00000000000000000000000000000001"
name: TurnkeyBinaryPoll
: DiemFramework
? address: "00000000000000000000000000000001"
name: TurnoutTally
: DiemFramework
? address: "00000000000000000000000000000001"
name: TurnoutTallyDemo
: DiemFramework
? address: "00000000000000000000000000000001"
name: Upgrade
: DiemFramework
Expand Down Expand Up @@ -296,13 +326,13 @@ compiled_package_info:
name: VectorHelper
: DiemFramework
? address: "00000000000000000000000000000001"
name: Vouch
name: VoteReceipt
: DiemFramework
? address: "00000000000000000000000000000001"
name: VouchScripts
name: Vouch
: DiemFramework
? address: "00000000000000000000000000000001"
name: Wallet
name: VouchScripts
: DiemFramework
? address: "00000000000000000000000000000001"
name: WalletScripts
Expand All @@ -316,7 +346,7 @@ compiled_package_info:
? address: "00000000000000000000000000000001"
name: XUS
: DiemFramework
source_digest: D38221DF89B01EE8625F117F721CF161438C44A5D125072BCD2CB904C10AFCB5
source_digest: E73442AD7A1B65175ABE2ACCB60D6A59204FBFD1C63E20E767E29AAC56BD3285
build_flags:
dev_mode: false
test_mode: false
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Module which manages freezing of accounts.
- [Constants](#@Constants_0)
- [Function `initialize`](#0x1_AccountFreezing_initialize)
- [Function `create`](#0x1_AccountFreezing_create)
- [Function `self_freeze_account`](#0x1_AccountFreezing_self_freeze_account)
- [Function `freeze_account`](#0x1_AccountFreezing_freeze_account)
- [Function `unfreeze_account`](#0x1_AccountFreezing_unfreeze_account)
- [Function `account_is_frozen`](#0x1_AccountFreezing_account_is_frozen)
Expand Down Expand Up @@ -304,6 +305,44 @@ The <code><a href="AccountFreezing.md#0x1_AccountFreezing_FreezingBit">FreezingB



</details>

<a name="0x1_AccountFreezing_self_freeze_account"></a>

## Function `self_freeze_account`

Freeze my account


<pre><code><b>public</b> <b>fun</b> <a href="AccountFreezing.md#0x1_AccountFreezing_self_freeze_account">self_freeze_account</a>(account: &signer)
</code></pre>



<details>
<summary>Implementation</summary>


<pre><code><b>public</b> <b>fun</b> <a href="AccountFreezing.md#0x1_AccountFreezing_self_freeze_account">self_freeze_account</a>(
account: &signer,
)
<b>acquires</b> <a href="AccountFreezing.md#0x1_AccountFreezing_FreezingBit">FreezingBit</a>, <a href="AccountFreezing.md#0x1_AccountFreezing_FreezeEventsHolder">FreezeEventsHolder</a> {
<a href="DiemTimestamp.md#0x1_DiemTimestamp_assert_operating">DiemTimestamp::assert_operating</a>();
<b>let</b> frozen_address = <a href="../../../../../../../DPN/releases/artifacts/current/build/MoveStdlib/docs/Signer.md#0x1_Signer_address_of">Signer::address_of</a>(account);
<b>borrow_global_mut</b>&lt;<a href="AccountFreezing.md#0x1_AccountFreezing_FreezingBit">FreezingBit</a>&gt;(frozen_address).is_frozen = <b>true</b>;

<a href="../../../../../../../DPN/releases/artifacts/current/build/MoveStdlib/docs/Event.md#0x1_Event_emit_event">Event::emit_event</a>&lt;<a href="AccountFreezing.md#0x1_AccountFreezing_FreezeAccountEvent">FreezeAccountEvent</a>&gt;(
&<b>mut</b> <b>borrow_global_mut</b>&lt;<a href="AccountFreezing.md#0x1_AccountFreezing_FreezeEventsHolder">FreezeEventsHolder</a>&gt;(@DiemRoot).freeze_event_handle,
<a href="AccountFreezing.md#0x1_AccountFreezing_FreezeAccountEvent">FreezeAccountEvent</a> {
initiator_address: frozen_address,
frozen_address
},
);
}
</code></pre>



</details>

<a name="0x1_AccountFreezing_freeze_account"></a>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@
- [Function `set_tree`](#0x1_Ancestry_set_tree)
- [Function `get_tree`](#0x1_Ancestry_get_tree)
- [Function `is_family`](#0x1_Ancestry_is_family)
- [Function `is_family_one_in_list`](#0x1_Ancestry_is_family_one_in_list)
- [Function `any_family_in_list`](#0x1_Ancestry_any_family_in_list)
- [Function `migrate`](#0x1_Ancestry_migrate)


<pre><code><b>use</b> <a href="CoreAddresses.md#0x1_CoreAddresses">0x1::CoreAddresses</a>;
<b>use</b> <a href="Debug.md#0x1_Debug">0x1::Debug</a>;
<b>use</b> <a href="../../../../../../../DPN/releases/artifacts/current/build/MoveStdlib/docs/Option.md#0x1_Option">0x1::Option</a>;
<b>use</b> <a href="../../../../../../../DPN/releases/artifacts/current/build/MoveStdlib/docs/Signer.md#0x1_Signer">0x1::Signer</a>;
<b>use</b> <a href="../../../../../../../DPN/releases/artifacts/current/build/MoveStdlib/docs/Vector.md#0x1_Vector">0x1::Vector</a>;
</code></pre>
Expand Down Expand Up @@ -220,6 +223,76 @@



</details>

<a name="0x1_Ancestry_is_family_one_in_list"></a>

## Function `is_family_one_in_list`



<pre><code><b>public</b> <b>fun</b> <a href="Ancestry.md#0x1_Ancestry_is_family_one_in_list">is_family_one_in_list</a>(left: <b>address</b>, list: &vector&lt;<b>address</b>&gt;): (bool, <a href="../../../../../../../DPN/releases/artifacts/current/build/MoveStdlib/docs/Option.md#0x1_Option_Option">Option::Option</a>&lt;<b>address</b>&gt;, <a href="../../../../../../../DPN/releases/artifacts/current/build/MoveStdlib/docs/Option.md#0x1_Option_Option">Option::Option</a>&lt;<b>address</b>&gt;)
</code></pre>



<details>
<summary>Implementation</summary>


<pre><code><b>public</b> <b>fun</b> <a href="Ancestry.md#0x1_Ancestry_is_family_one_in_list">is_family_one_in_list</a>(left: <b>address</b>, list: &vector&lt;<b>address</b>&gt;):(bool, <a href="../../../../../../../DPN/releases/artifacts/current/build/MoveStdlib/docs/Option.md#0x1_Option">Option</a>&lt;<b>address</b>&gt;, <a href="../../../../../../../DPN/releases/artifacts/current/build/MoveStdlib/docs/Option.md#0x1_Option">Option</a>&lt;<b>address</b>&gt;) <b>acquires</b> <a href="Ancestry.md#0x1_Ancestry">Ancestry</a> {
<b>let</b> k = 0;
<b>while</b> (k &lt; <a href="../../../../../../../DPN/releases/artifacts/current/build/MoveStdlib/docs/Vector.md#0x1_Vector_length">Vector::length</a>(list)) {
<b>let</b> right = <a href="../../../../../../../DPN/releases/artifacts/current/build/MoveStdlib/docs/Vector.md#0x1_Vector_borrow">Vector::borrow</a>(list, k);
<b>let</b> (fam, _) = <a href="Ancestry.md#0x1_Ancestry_is_family">is_family</a>(left, *right);
<b>if</b> (fam) {
<b>return</b> (<b>true</b>, <a href="../../../../../../../DPN/releases/artifacts/current/build/MoveStdlib/docs/Option.md#0x1_Option_some">Option::some</a>(left), <a href="../../../../../../../DPN/releases/artifacts/current/build/MoveStdlib/docs/Option.md#0x1_Option_some">Option::some</a>(*right))
};
k = k + 1;
};

(<b>false</b>, <a href="../../../../../../../DPN/releases/artifacts/current/build/MoveStdlib/docs/Option.md#0x1_Option_none">Option::none</a>(), <a href="../../../../../../../DPN/releases/artifacts/current/build/MoveStdlib/docs/Option.md#0x1_Option_none">Option::none</a>())
}
</code></pre>



</details>

<a name="0x1_Ancestry_any_family_in_list"></a>

## Function `any_family_in_list`



<pre><code><b>public</b> <b>fun</b> <a href="Ancestry.md#0x1_Ancestry_any_family_in_list">any_family_in_list</a>(addr_vec: vector&lt;<b>address</b>&gt;): (bool, <a href="../../../../../../../DPN/releases/artifacts/current/build/MoveStdlib/docs/Option.md#0x1_Option_Option">Option::Option</a>&lt;<b>address</b>&gt;, <a href="../../../../../../../DPN/releases/artifacts/current/build/MoveStdlib/docs/Option.md#0x1_Option_Option">Option::Option</a>&lt;<b>address</b>&gt;)
</code></pre>



<details>
<summary>Implementation</summary>


<pre><code><b>public</b> <b>fun</b> <a href="Ancestry.md#0x1_Ancestry_any_family_in_list">any_family_in_list</a>(addr_vec: vector&lt;<b>address</b>&gt;):(bool, <a href="../../../../../../../DPN/releases/artifacts/current/build/MoveStdlib/docs/Option.md#0x1_Option">Option</a>&lt;<b>address</b>&gt;, <a href="../../../../../../../DPN/releases/artifacts/current/build/MoveStdlib/docs/Option.md#0x1_Option">Option</a>&lt;<b>address</b>&gt;) <b>acquires</b> <a href="Ancestry.md#0x1_Ancestry">Ancestry</a> {
<b>let</b> i = 0;
<b>while</b> (<a href="../../../../../../../DPN/releases/artifacts/current/build/MoveStdlib/docs/Vector.md#0x1_Vector_length">Vector::length</a>(&addr_vec) &gt; 1) {
<b>let</b> left = <a href="../../../../../../../DPN/releases/artifacts/current/build/MoveStdlib/docs/Vector.md#0x1_Vector_pop_back">Vector::pop_back</a>(&<b>mut</b> addr_vec);

<b>let</b> (fam, left_opt, right_opt) = <a href="Ancestry.md#0x1_Ancestry_is_family_one_in_list">is_family_one_in_list</a>(left, &addr_vec);
<b>if</b> (fam) {
<b>return</b> (fam, left_opt, right_opt)
};

i = i + 1;
};

(<b>false</b>, <a href="../../../../../../../DPN/releases/artifacts/current/build/MoveStdlib/docs/Option.md#0x1_Option_none">Option::none</a>(), <a href="../../../../../../../DPN/releases/artifacts/current/build/MoveStdlib/docs/Option.md#0x1_Option_none">Option::none</a>())
}
</code></pre>



</details>

<a name="0x1_Ancestry_migrate"></a>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ This module enables automatic payments from accounts to community wallets at epo
- [Function `find`](#0x1_AutoPay_find)


<pre><code><b>use</b> <a href="DiemAccount.md#0x1_DiemAccount">0x1::DiemAccount</a>;
<pre><code><b>use</b> <a href="CommunityWallet.md#0x1_CommunityWallet">0x1::CommunityWallet</a>;
<b>use</b> <a href="DiemAccount.md#0x1_DiemAccount">0x1::DiemAccount</a>;
<b>use</b> <a href="DiemConfig.md#0x1_DiemConfig">0x1::DiemConfig</a>;
<b>use</b> <a href="../../../../../../../DPN/releases/artifacts/current/build/MoveStdlib/docs/Errors.md#0x1_Errors">0x1::Errors</a>;
<b>use</b> <a href="../../../../../../../DPN/releases/artifacts/current/build/MoveStdlib/docs/FixedPoint32.md#0x1_FixedPoint32">0x1::FixedPoint32</a>;
Expand All @@ -46,7 +47,6 @@ This module enables automatic payments from accounts to community wallets at epo
<b>use</b> <a href="Roles.md#0x1_Roles">0x1::Roles</a>;
<b>use</b> <a href="../../../../../../../DPN/releases/artifacts/current/build/MoveStdlib/docs/Signer.md#0x1_Signer">0x1::Signer</a>;
<b>use</b> <a href="../../../../../../../DPN/releases/artifacts/current/build/MoveStdlib/docs/Vector.md#0x1_Vector">0x1::Vector</a>;
<b>use</b> <a href="Wallet.md#0x1_Wallet">0x1::Wallet</a>;
</code></pre>


Expand Down Expand Up @@ -650,7 +650,7 @@ Attempt to use a UID that is already taken
): bool {
// check payees are community wallets, only community wallets are allowed
// <b>to</b> receive autopay (bypassing account limits)
<b>if</b> (!<a href="Wallet.md#0x1_Wallet_is_comm">Wallet::is_comm</a>(payment.payee)) { <b>return</b> <b>false</b> }; // do nothing but don't delete instruction };
<b>if</b> (!<a href="CommunityWallet.md#0x1_CommunityWallet_is_comm">CommunityWallet::is_comm</a>(payment.payee)) { <b>return</b> <b>false</b> }; // do nothing but don't delete instruction };

<a href="Roles.md#0x1_Roles_assert_diem_root">Roles::assert_diem_root</a>(vm);
<b>let</b> epoch = <a href="DiemConfig.md#0x1_DiemConfig_get_current_epoch">DiemConfig::get_current_epoch</a>();
Expand Down Expand Up @@ -815,7 +815,7 @@ Attempt to use a UID that is already taken

// TODO: This check already <b>exists</b> at the time of execution.
<b>if</b> (<b>borrow_global</b>&lt;<a href="AutoPay.md#0x1_AutoPay_AccountLimitsEnable">AccountLimitsEnable</a>&gt;(@DiemRoot).enabled) {
<b>assert</b>!(<a href="Wallet.md#0x1_Wallet_is_comm">Wallet::is_comm</a>(payee), <a href="../../../../../../../DPN/releases/artifacts/current/build/MoveStdlib/docs/Errors.md#0x1_Errors_invalid_argument">Errors::invalid_argument</a>(<a href="AutoPay.md#0x1_AutoPay_PAYEE_NOT_COMMUNITY_WALLET">PAYEE_NOT_COMMUNITY_WALLET</a>));
<b>assert</b>!(<a href="CommunityWallet.md#0x1_CommunityWallet_is_comm">CommunityWallet::is_comm</a>(payee), <a href="../../../../../../../DPN/releases/artifacts/current/build/MoveStdlib/docs/Errors.md#0x1_Errors_invalid_argument">Errors::invalid_argument</a>(<a href="AutoPay.md#0x1_AutoPay_PAYEE_NOT_COMMUNITY_WALLET">PAYEE_NOT_COMMUNITY_WALLET</a>));
};

<b>let</b> payments = &<b>mut</b> <b>borrow_global_mut</b>&lt;<a href="AutoPay.md#0x1_AutoPay_UserAutoPay">UserAutoPay</a>&gt;(addr).payments;
Expand Down
Loading

0 comments on commit cd2bac0

Please sign in to comment.