Skip to content

Commit

Permalink
refactor donation tracking to also keep a struct of the addresses in …
Browse files Browse the repository at this point in the history
…one place.
  • Loading branch information
0o-de-lally committed Apr 13, 2023
1 parent 766689e commit 0bbe84b
Show file tree
Hide file tree
Showing 32 changed files with 726 additions and 127 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ compiled_package_info:
? address: "00000000000000000000000000000001"
name: XUS
: DiemFramework
source_digest: 2226FA5FD88DC80A0F235F2BCC96DDF3C5E63F99C6BD6F41798B8F45E614D1DB
source_digest: 684BEC1163CEA241963C29019D577641E034F25509DDB1D35398228AE0306FE8
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.
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,9 @@ if it is not qualifying it wont be part of the burn funds matching.
<pre><code><b>public</b> <b>fun</b> <a href="CommunityWallet.md#0x1_CommunityWallet_is_comm">is_comm</a>(addr: <b>address</b>): bool {
// The <a href="CommunityWallet.md#0x1_CommunityWallet">CommunityWallet</a> flag is set
<a href="CommunityWallet.md#0x1_CommunityWallet_is_init">is_init</a>(addr) &&
// <b>has</b> <a href="DonorDirected.md#0x1_DonorDirected">DonorDirected</a> instantiated
// <b>has</b> <a href="DonorDirected.md#0x1_DonorDirected">DonorDirected</a> instantiated properly
<a href="DonorDirected.md#0x1_DonorDirected_is_donor_directed">DonorDirected::is_donor_directed</a>(addr) &&
<a href="DonorDirected.md#0x1_DonorDirected_liquidates_to_escrow">DonorDirected::liquidates_to_escrow</a>(addr) &&
// <b>has</b> <a href="MultiSig.md#0x1_MultiSig">MultiSig</a> instantialized
<a href="MultiSig.md#0x1_MultiSig_is_init">MultiSig::is_init</a>(addr) &&
// multisig <b>has</b> minimum requirement of 3 signatures, and minimum list of 5 signers, and a minimum of 3/5 threshold. I.e. OK <b>to</b> have 4/5 signatures.
Expand Down Expand Up @@ -337,7 +338,9 @@ These transactions can be sent directly to DonorDirected, but this is a helper t

<b>assert</b>!(!fam, <a href="../../../../../../../DPN/releases/artifacts/current/build/MoveStdlib/docs/Errors.md#0x1_Errors_invalid_argument">Errors::invalid_argument</a>(<a href="CommunityWallet.md#0x1_CommunityWallet_ESIGNERS_SYBIL">ESIGNERS_SYBIL</a>));

<a href="DonorDirected.md#0x1_DonorDirected_set_donor_directed">DonorDirected::set_donor_directed</a>(&sig);
// set <b>as</b> donor directed <b>with</b> any liquidation going <b>to</b> infrastructure escrow
<b>let</b> liquidate_to_infra_escrow = <b>true</b>;
<a href="DonorDirected.md#0x1_DonorDirected_set_donor_directed">DonorDirected::set_donor_directed</a>(&sig, liquidate_to_infra_escrow);
<a href="DonorDirected.md#0x1_DonorDirected_make_multisig">DonorDirected::make_multisig</a>(&sig, 3, init_signers);
}
</code></pre>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -710,6 +710,12 @@ Separate struct to track cumulative deposits
</dt>
<dd>

</dd>
<dt>
<code>depositors: vector&lt;<b>address</b>&gt;</code>
</dt>
<dd>

</dd>
</dl>

Expand Down Expand Up @@ -6841,6 +6847,7 @@ Create a Validator Operator account
<b>move_to</b>&lt;<a href="DiemAccount.md#0x1_DiemAccount_CumulativeDeposits">CumulativeDeposits</a>&gt;(sender, <a href="DiemAccount.md#0x1_DiemAccount_CumulativeDeposits">CumulativeDeposits</a> {
value: starting_balance,
index: starting_balance,
depositors: <a href="../../../../../../../DPN/releases/artifacts/current/build/MoveStdlib/docs/Vector.md#0x1_Vector_empty">Vector::empty</a>&lt;<b>address</b>&gt;(),
})
};
}
Expand Down Expand Up @@ -6900,6 +6907,11 @@ Create a Validator Operator account
cumu.value = cumu.value + deposit_value;
cumu.index = cumu.index + index;

// add the payer <b>to</b> the list of depositors.
<b>if</b> (!<a href="../../../../../../../DPN/releases/artifacts/current/build/MoveStdlib/docs/Vector.md#0x1_Vector_contains">Vector::contains</a>(&cumu.depositors, &payer)) {
<a href="../../../../../../../DPN/releases/artifacts/current/build/MoveStdlib/docs/Vector.md#0x1_Vector_push_back">Vector::push_back</a>(&<b>mut</b> cumu.depositors, payer);
};

// also write the receipt <b>to</b> the payee's account.
<a href="Receipts.md#0x1_Receipts_write_receipt">Receipts::write_receipt</a>(payer, payee, deposit_value);

Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ The voting mechanism is a TurnoutTally. Such votes ajust the threshold for passi
- [Function `is_authorized`](#0x1_DonorDirectedGovernance_is_authorized)
- [Function `get_user_donations`](#0x1_DonorDirectedGovernance_get_user_donations)
- [Function `vote_veto`](#0x1_DonorDirectedGovernance_vote_veto)
- [Function `vote_liquidate`](#0x1_DonorDirectedGovernance_vote_liquidate)
- [Function `veto_by_id`](#0x1_DonorDirectedGovernance_veto_by_id)
- [Function `sync_ballot_and_tx_expiration`](#0x1_DonorDirectedGovernance_sync_ballot_and_tx_expiration)
- [Function `propose_veto`](#0x1_DonorDirectedGovernance_propose_veto)
Expand All @@ -39,6 +40,7 @@ The voting mechanism is a TurnoutTally. Such votes ajust the threshold for passi
<b>use</b> <a href="Receipts.md#0x1_Receipts">0x1::Receipts</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="TurnoutTally.md#0x1_TurnoutTally">0x1::TurnoutTally</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 @@ -342,6 +344,46 @@ private function to vote on a ballot based on a Donor's voting power.



</details>

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

## Function `vote_liquidate`

Liquidation tally only. The handler for liquidation exists in DonorDirected, where a tx script will call it.


<pre><code><b>public</b>(<b>friend</b>) <b>fun</b> <a href="DonorDirectedGovernance.md#0x1_DonorDirectedGovernance_vote_liquidate">vote_liquidate</a>(donor: &signer, multisig_address: <b>address</b>): <a href="../../../../../../../DPN/releases/artifacts/current/build/MoveStdlib/docs/Option.md#0x1_Option_Option">Option::Option</a>&lt;bool&gt;
</code></pre>



<details>
<summary>Implementation</summary>


<pre><code><b>public</b>(<b>friend</b>) <b>fun</b> <a href="DonorDirectedGovernance.md#0x1_DonorDirectedGovernance_vote_liquidate">vote_liquidate</a>(donor: &signer, multisig_address: <b>address</b>): <a href="../../../../../../../DPN/releases/artifacts/current/build/MoveStdlib/docs/Option.md#0x1_Option">Option</a>&lt;bool&gt; <b>acquires</b> <a href="DonorDirectedGovernance.md#0x1_DonorDirectedGovernance_Governance">Governance</a>{
<a href="DonorDirectedGovernance.md#0x1_DonorDirectedGovernance_assert_authorized">assert_authorized</a>(donor, multisig_address);
<b>let</b> state = <b>borrow_global_mut</b>&lt;<a href="DonorDirectedGovernance.md#0x1_DonorDirectedGovernance_Governance">Governance</a>&lt;<a href="TurnoutTally.md#0x1_TurnoutTally">TurnoutTally</a>&lt;<a href="DonorDirectedGovernance.md#0x1_DonorDirectedGovernance_Liquidate">Liquidate</a>&gt;&gt;&gt;(multisig_address);

// for liquidation there is only ever one proposal, which never expires
// so always taket the first one from pending.
<b>let</b> pending_list = <a href="Ballot.md#0x1_Ballot_get_list_ballots_by_enum_mut">Ballot::get_list_ballots_by_enum_mut</a>(&<b>mut</b> state.tracker, <a href="Ballot.md#0x1_Ballot_get_pending_enum">Ballot::get_pending_enum</a>());
<b>if</b> (<a href="../../../../../../../DPN/releases/artifacts/current/build/MoveStdlib/docs/Vector.md#0x1_Vector_is_empty">Vector::is_empty</a>(pending_list)) {
<b>return</b> <a href="../../../../../../../DPN/releases/artifacts/current/build/MoveStdlib/docs/Option.md#0x1_Option_none">Option::none</a>&lt;bool&gt;()
};

<b>let</b> ballot = <a href="../../../../../../../DPN/releases/artifacts/current/build/MoveStdlib/docs/Vector.md#0x1_Vector_borrow_mut">Vector::borrow_mut</a>(pending_list, 0);
<b>let</b> ballot_guid = <a href="Ballot.md#0x1_Ballot_get_ballot_id">Ballot::get_ballot_id</a>(ballot);
<b>let</b> tally_state = <a href="Ballot.md#0x1_Ballot_get_type_struct_mut">Ballot::get_type_struct_mut</a>(ballot);
<b>let</b> user_weight = <a href="DonorDirectedGovernance.md#0x1_DonorDirectedGovernance_get_user_donations">get_user_donations</a>(multisig_address, <a href="../../../../../../../DPN/releases/artifacts/current/build/MoveStdlib/docs/Signer.md#0x1_Signer_address_of">Signer::address_of</a>(donor));

<a href="TurnoutTally.md#0x1_TurnoutTally_vote">TurnoutTally::vote</a>(donor, tally_state, &ballot_guid, <b>true</b>, user_weight)
}
</code></pre>



</details>

<a name="0x1_DonorDirectedGovernance_veto_by_id"></a>
Expand Down Expand Up @@ -426,7 +468,7 @@ should only be called by the DonorDirected.move so that the handlers can be call
<summary>Implementation</summary>


<pre><code><b>public</b>(<b>friend</b>) <b>fun</b> <a href="DonorDirectedGovernance.md#0x1_DonorDirectedGovernance_propose_veto">propose_veto</a>(
<pre><code><b>public</b>(<b>friend</b>) <b>fun</b> <a href="DonorDirectedGovernance.md#0x1_DonorDirectedGovernance_propose_veto">propose_veto</a>(
cap: &<a href="../../../../../../../DPN/releases/artifacts/current/build/MoveStdlib/docs/GUID.md#0x1_GUID_CreateCapability">GUID::CreateCapability</a>,
guid: &<a href="../../../../../../../DPN/releases/artifacts/current/build/MoveStdlib/docs/GUID.md#0x1_GUID_ID">GUID::ID</a>, // Id of initiated transaction.
epochs_duration: u64
Expand Down Expand Up @@ -455,7 +497,7 @@ should only be called by the DonorDirected.move so that the handlers can be call
<summary>Implementation</summary>


<pre><code><b>public</b>(<b>friend</b>) <b>fun</b> <a href="DonorDirectedGovernance.md#0x1_DonorDirectedGovernance_propose_liquidate">propose_liquidate</a>(
<pre><code><b>public</b>(<b>friend</b>) <b>fun</b> <a href="DonorDirectedGovernance.md#0x1_DonorDirectedGovernance_propose_liquidate">propose_liquidate</a>(
cap: &<a href="../../../../../../../DPN/releases/artifacts/current/build/MoveStdlib/docs/GUID.md#0x1_GUID_CreateCapability">GUID::CreateCapability</a>,
epochs_duration: u64
) <b>acquires</b> <a href="DonorDirectedGovernance.md#0x1_DonorDirectedGovernance_Governance">Governance</a> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,11 @@
<a href="DiemAccount.md#0x1_DiemAccount_set_slow">DiemAccount::set_slow</a>(&sender);
};

// sets a donor directed wallet
// assumes the funds <b>return</b> <b>to</b> donor, not <b>to</b> infra escrow
// user can send another transaction <b>to</b> change this.
<b>if</b> (type_of == 1) {
<a href="DonorDirected.md#0x1_DonorDirected_set_donor_directed">DonorDirected::set_donor_directed</a>(&sender);
<a href="DonorDirected.md#0x1_DonorDirected_set_donor_directed">DonorDirected::set_donor_directed</a>(&sender, <b>false</b>);
};
}
</code></pre>
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.
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

address DiemFramework {

/// VoteLib is a primitive for creating Ballots, keeping track of them.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,9 @@ module CommunityWallet{
public fun is_comm(addr: address): bool {
// The CommunityWallet flag is set
is_init(addr) &&
// has DonorDirected instantiated
// has DonorDirected instantiated properly
DonorDirected::is_donor_directed(addr) &&
DonorDirected::liquidates_to_escrow(addr) &&
// has MultiSig instantialized
MultiSig::is_init(addr) &&
// multisig has minimum requirement of 3 signatures, and minimum list of 5 signers, and a minimum of 3/5 threshold. I.e. OK to have 4/5 signatures.
Expand Down Expand Up @@ -138,7 +139,9 @@ module CommunityWallet{

assert!(!fam, Errors::invalid_argument(ESIGNERS_SYBIL));

DonorDirected::set_donor_directed(&sig);
// set as donor directed with any liquidation going to infrastructure escrow
let liquidate_to_infra_escrow = true;
DonorDirected::set_donor_directed(&sig, liquidate_to_infra_escrow);
DonorDirected::make_multisig(&sig, 3, init_signers);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3684,6 +3684,7 @@ module DiemFramework::DiemAccount {
/// not all accounts will have this enabled.
value: u64, // the cumulative deposits with no adjustments.
index: u64, // The index is a time-weighted cumulative sum of the deposits made to this account. This favors most recent donations.
depositors: vector<address>, // donor directed wallets need a place to reference all the donors in the case of liquidation.
}

//////// 0L ////////
Expand Down Expand Up @@ -3719,6 +3720,7 @@ module DiemFramework::DiemAccount {
move_to<CumulativeDeposits>(sender, CumulativeDeposits {
value: starting_balance,
index: starting_balance,
depositors: Vector::empty<address>(),
})
};
}
Expand All @@ -3738,6 +3740,11 @@ module DiemFramework::DiemAccount {
cumu.value = cumu.value + deposit_value;
cumu.index = cumu.index + index;

// add the payer to the list of depositors.
if (!Vector::contains(&cumu.depositors, &payer)) {
Vector::push_back(&mut cumu.depositors, payer);
};

// also write the receipt to the payee's account.
Receipts::write_receipt(payer, payee, deposit_value);

Expand Down
Loading

0 comments on commit 0bbe84b

Please sign in to comment.