Skip to content

Commit d37c617

Browse files
authored
Merge pull request #133 from scryptonight/main
A few fixes and a few more tests
2 parents b019aea + 96cfaa3 commit d37c617

File tree

13 files changed

+10338
-163
lines changed

13 files changed

+10338
-163
lines changed

Diff for: 5-DAO/smorgasdao/rtm/smorgasdao/execute_proposal_return.rtm

-17
This file was deleted.

Diff for: 5-DAO/smorgasdao/rtm/smorgasdao/instantiate_smorgasdao.rtm

+5-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@
99
#
1010
# $proposal_duration: Duration of proposals in epochs, e.g. 10
1111
#
12-
# $quorum: Quorum to use, e.g. Any
12+
# $quorum: Quorum to use, e.g.
13+
# "Percent",Decimal("35")
14+
# "Fixed",Decimal("10000")
15+
# "Any"
1316
#
1417
# $vote_token: Token to use for voting with, e.g. resource_sim1qqqq...yag
1518
# (even if the XRD token isn't really recommended).
@@ -30,7 +33,7 @@ CALL_FUNCTION
3033
"SmorgasDao"
3134
"instantiate_smorgasdao"
3235
${proposal_duration}u64
33-
Enum("${quorum}")
36+
Enum(${quorum})
3437
ResourceAddress("${vote_token}")
3538
${id_token}
3639
Enum("${vote_tally}")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Previously placed voting tokens are withdrawn.
2+
#
3+
# Parameters:
4+
#
5+
# $component: address of the SmorgasDao instance to use
6+
#
7+
# $account: address of the user account running this transaction
8+
#
9+
# $proposal: proposal id to withdraw votes from, e.g. 2284
10+
#
11+
# $receipt_nfres: the ResourceAddress of the receipt we received
12+
# when we placed the votes
13+
#
14+
# $receipt_nfid: the NonFungibleId of the receipt we received
15+
# when we placed the votes
16+
CALL_METHOD
17+
ComponentAddress("${account}")
18+
"lock_fee"
19+
Decimal("10");
20+
21+
CALL_METHOD
22+
ComponentAddress("${account}")
23+
"withdraw_by_ids"
24+
Set<NonFungibleId>(NonFungibleId("${receipt_nfid}"))
25+
ResourceAddress("${receipt_nfres}");
26+
27+
TAKE_FROM_WORKTOP_BY_IDS
28+
Set<NonFungibleId>(NonFungibleId("${receipt_nfid}"))
29+
ResourceAddress("${receipt_nfres}")
30+
Bucket("receipt_bucket");
31+
32+
CALL_METHOD
33+
ComponentAddress("${component}")
34+
"withdraw_votes_with_receipt"
35+
${proposal}u64
36+
Bucket("receipt_bucket");
37+
38+
CALL_METHOD
39+
ComponentAddress("${account}")
40+
"deposit_batch"
41+
Expression("ENTIRE_WORKTOP");

Diff for: 5-DAO/smorgasdao/src/intermediary.rs

+9-21
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,13 @@ blueprint! {
4848
.instantiate().globalize()
4949
}
5050

51-
/// This is the first of three stages needed for the
51+
/// This is the first of two stages needed for the
5252
/// SmorgasDAO to alter its own configuration with an
5353
/// executive proposal.
5454
///
55+
/// We need two stages because the engine doesn't allow us to
56+
/// do a re-entrant call back into the DAO direct.
57+
///
5558
/// This method receives the SmorgasDAO's admin badge after an
5659
/// executive proposal passes, and stores it for the
5760
/// multi-stage implmenetation of the proposal.
@@ -86,6 +89,8 @@ blueprint! {
8689
/// configuration change on the originating SmorgasDao
8790
/// component.
8891
///
92+
/// The badge is then sent back to the SmorgasDao.
93+
///
8994
/// ---
9095
///
9196
/// **Access control:** This method doesn't do anything useful
@@ -96,32 +101,15 @@ blueprint! {
96101
/// by a different component. Since users are not meant to
97102
/// call it directly no transaction manifest is provided.
98103
pub fn execute_dao_call(&mut self) {
99-
self.dao_admin_badge.authorize(
104+
let badge = self.dao_admin_badge.take_all();
105+
badge.authorize(
100106
||
101107
borrow_component!(self.dao_component).call::<()>(
102108
"set_proposal_duration",
103109
args!(100u64)));
104-
}
105-
106-
/// This is the third stage of effecting a configuration
107-
/// change of the SmorgasDAO.
108-
///
109-
/// This method return the Admin badge we stored here back to
110-
/// the DAO.
111-
///
112-
/// ---
113-
///
114-
/// **Access control:** This method doesn't do anything useful
115-
/// unless it's called with the DAO's admin badge in
116-
/// `badges[0]`
117-
///
118-
/// **Transaction manifest:** This method is only ever called
119-
/// by a different component. Since users are not meant to
120-
/// call it directly no transaction manifest is provided.
121-
pub fn return_dao_admin_token(&mut self) {
122110
borrow_component!(self.dao_component).call::<()>(
123111
"return_internal_badge",
124-
args!(self.dao_admin_badge.take_all()));
112+
args!(badge));
125113
}
126114

127115
/// This method relays a call from a SmorgasDAO executive

Diff for: 5-DAO/smorgasdao/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
//! and then the [intermediary module] to gain a good understanding of
1919
//! how the Radfolio functions.
2020
//!
21-
//! [radfolio module]: crate::smorgasdao
22-
//! [investment vehicle module]: crate::intermediary
21+
//! [intermediary module]: crate::intermediary
22+
//! [smorgasdao module]: crate::smorgasdao
2323
//!
2424
//! In a nutshell, the `SmorgasDAO` component stores admin badges for
2525
//! other components and calls them as its administrators would, but

Diff for: 5-DAO/smorgasdao/src/smorgasdao.rs

+31-16
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@
8080
//! complication here as the intermediary cannot call the DAO back
8181
//! directly (this would be an invalid re-entrant call) but instead it
8282
//! must store the admin token awaiting a second call from the
83-
//! transaction manifest which then calls the DAO. Finally, a third
84-
//! call must be made to return the Admin token to the DAO component.
83+
//! transaction manifest which then calls the DAO to do the
84+
//! configuration change, before returning the admin badge to the DAO.
8585
//!
8686
//! Note that the current DAO implementation only offers a single
8787
//! configuration method, for the `proposal_duration` option, but of
@@ -361,6 +361,11 @@ pub struct Proposal {
361361
target_funding: Option<Decimal>,
362362
}
363363

364+
fn blah() {
365+
let _f: PreciseDecimal;
366+
let _a = dec!("28");
367+
}
368+
364369
blueprint! {
365370
struct SmorgasDao {
366371
/// This holds the XRD we use for our vote subsidies and for
@@ -684,6 +689,9 @@ blueprint! {
684689
/// You will be returned a receipt NFT which you will need
685690
/// later to recover your voting tokens.
686691
///
692+
/// Also returns the ResourceAddress and NonFungibleId of the
693+
/// receipt NFT.
694+
///
687695
/// ---
688696
///
689697
/// **Access control:** If the DAO is configured to require an
@@ -695,7 +703,8 @@ blueprint! {
695703
#[doc = include_str!("../rtm/smorgasdao/vote_with_receipt.rtm")]
696704
/// ```
697705
pub fn vote_with_receipt(&mut self,
698-
proposal: u64, tokens: Bucket, vote_for: usize) -> Bucket {
706+
proposal: u64, tokens: Bucket, vote_for: usize)
707+
-> (Bucket, ResourceAddress, NonFungibleId) {
699708
assert!(self.id_token.is_none(),
700709
"We only accept votes with an id NFT");
701710

@@ -722,11 +731,11 @@ blueprint! {
722731
}
723732

724733
// Record votes
725-
proposal.votes_cast.insert(receipt_nfaddr, VotesCast {
734+
proposal.votes_cast.insert(receipt_nfaddr.clone(), VotesCast {
726735
option: vote_for,
727736
votes: Vault::with_bucket(tokens) });
728737

729-
receipt_nft
738+
(receipt_nft, receipt_nfaddr.resource_address(), receipt_nfaddr.non_fungible_id())
730739
}
731740

732741
/// Call this to pull out your votes from a proposal when you
@@ -747,8 +756,11 @@ blueprint! {
747756
/// **Access control:** If the DAO is configured to require an
748757
/// id, no one can call this method.
749758
///
750-
/// **Transaction manifest:** This method is not in the test
751-
/// suite and does not yet have a transaction manifest.
759+
/// **Transaction manifest:**
760+
/// `rtm/smorgasdao/withdraw_votes_with_receipt.rtm`
761+
/// ```text
762+
#[doc = include_str!("../rtm/smorgasdao/withdraw_votes_with_receipt.rtm")]
763+
/// ```
752764
pub fn withdraw_votes_with_receipt(&mut self,
753765
proposal: u64,
754766
id: Bucket) -> Bucket {
@@ -766,7 +778,7 @@ blueprint! {
766778
"This proposal does not exist");
767779

768780
let removed_votes =
769-
proposal.votes_cast.remove(&id_nfaddr);
781+
proposal.votes_cast.get_mut(&id_nfaddr);
770782

771783
// burn the temporary id NFT
772784
self.id_mint_badge.authorize(|| id.burn());
@@ -775,8 +787,8 @@ blueprint! {
775787
removed_votes.unwrap().votes.take_all()
776788
}
777789

778-
/// Call this method to vote on a DAO that identity NFTs when
779-
/// voting.
790+
/// Call this method to vote on a DAO that uses identity NFTs
791+
/// when voting.
780792
///
781793
/// Provide the unique id of the proposal to vote on, a proof
782794
/// of your identity, the bucket of tokens you want to bind up
@@ -1128,10 +1140,13 @@ blueprint! {
11281140
// already take tally type into account
11291141
let mut result = vec![Decimal::ZERO; proposal.options.len()];
11301142

1131-
// We use PreciseDecimal here and further down because
1132-
// we're multiplying Decimals together and want to prevent
1133-
// overflow when we do so.
1134-
let mut tokens_cast = PreciseDecimal::ZERO;
1143+
// We should use PreciseDecimal here and further down
1144+
// because we're multiplying Decimals together and want to
1145+
// prevent overflow when we do so. We don't do so yet
1146+
// because Decimal and PreciseDecimal don't seem to play
1147+
// nice together, you get strange results when you add a
1148+
// Decimal to a PreciseDecimal.
1149+
let mut tokens_cast = Decimal::ZERO;
11351150

11361151
for voter in proposal.votes_cast.values() {
11371152
result[voter.option] +=
@@ -1172,12 +1187,12 @@ blueprint! {
11721187
match self.quorum {
11731188
Quorum::Percent(p) => {
11741189
let cmgr: &ResourceManager = borrow_resource_manager!(self.vote_token);
1175-
let supply: PreciseDecimal = cmgr.total_supply().into();
1190+
let supply: Decimal = cmgr.total_supply().into();
11761191
if supply.is_zero() {
11771192
// Avoid divide by zero
11781193
meets_quorum = p.is_zero();
11791194
} else {
1180-
let attendance = PreciseDecimal::from("100") * tokens_cast / supply;
1195+
let attendance = Decimal::from("100") * tokens_cast / supply;
11811196
meets_quorum = attendance >= p.into();
11821197
}
11831198
},

0 commit comments

Comments
 (0)