Skip to content

Commit 3a34ff7

Browse files
sasuke0787Isa McConeySofi De Bittern
authored
[donor-voice] refactor cw unlocked advance workflow (#393)
Co-authored-by: Isa McConey <[email protected]> Co-authored-by: Sofi De Bittern <[email protected]>
1 parent 5a5f5ec commit 3a34ff7

File tree

8 files changed

+534
-221
lines changed

8 files changed

+534
-221
lines changed

framework/cached-packages/src/libra_framework_sdk_builder.rs

Lines changed: 23 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -191,13 +191,8 @@ pub enum EntryFunctionCall {
191191
/// Public function for production triggering of epoch boundary.
192192
DiemGovernanceTriggerEpoch {},
193193

194-
/// A signer of the multisig can propose a payment
195-
/// Public entry function required for txs cli
196-
DonorVoiceTxsProposeAdvanceTx {
194+
DonorVoiceTxsMaybeCloseReauth {
197195
multisig_address: AccountAddress,
198-
payee: AccountAddress,
199-
value: u64,
200-
description: Vec<u8>,
201196
},
202197

203198
/// A donor can propose the liquidation of a Donor Voice account
@@ -206,13 +201,12 @@ pub enum EntryFunctionCall {
206201
multisig_address: AccountAddress,
207202
},
208203

209-
/// A signer of the multisig can propose a payment
210-
/// Public entry function required for txs cli.
211204
DonorVoiceTxsProposePaymentTx {
212205
multisig_address: AccountAddress,
213206
payee: AccountAddress,
214207
value: u64,
215208
description: Vec<u8>,
209+
advance_unlocked: bool,
216210
},
217211

218212
/// A donor of the program can propose a veto to a scheduled transaction
@@ -499,12 +493,9 @@ impl EntryFunctionCall {
499493
} => diem_governance_ol_vote(proposal_id, should_pass),
500494
DiemGovernanceSmokeTriggerEpoch {} => diem_governance_smoke_trigger_epoch(),
501495
DiemGovernanceTriggerEpoch {} => diem_governance_trigger_epoch(),
502-
DonorVoiceTxsProposeAdvanceTx {
503-
multisig_address,
504-
payee,
505-
value,
506-
description,
507-
} => donor_voice_txs_propose_advance_tx(multisig_address, payee, value, description),
496+
DonorVoiceTxsMaybeCloseReauth { multisig_address } => {
497+
donor_voice_txs_maybe_close_reauth(multisig_address)
498+
}
508499
DonorVoiceTxsProposeLiquidateTx { multisig_address } => {
509500
donor_voice_txs_propose_liquidate_tx(multisig_address)
510501
}
@@ -513,7 +504,14 @@ impl EntryFunctionCall {
513504
payee,
514505
value,
515506
description,
516-
} => donor_voice_txs_propose_payment_tx(multisig_address, payee, value, description),
507+
advance_unlocked,
508+
} => donor_voice_txs_propose_payment_tx(
509+
multisig_address,
510+
payee,
511+
value,
512+
description,
513+
advance_unlocked,
514+
),
517515
DonorVoiceTxsProposeVetoTx {
518516
multisig_address,
519517
tx_id,
@@ -998,14 +996,7 @@ pub fn diem_governance_trigger_epoch() -> TransactionPayload {
998996
))
999997
}
1000998

1001-
/// A signer of the multisig can propose a payment
1002-
/// Public entry function required for txs cli
1003-
pub fn donor_voice_txs_propose_advance_tx(
1004-
multisig_address: AccountAddress,
1005-
payee: AccountAddress,
1006-
value: u64,
1007-
description: Vec<u8>,
1008-
) -> TransactionPayload {
999+
pub fn donor_voice_txs_maybe_close_reauth(multisig_address: AccountAddress) -> TransactionPayload {
10091000
TransactionPayload::EntryFunction(EntryFunction::new(
10101001
ModuleId::new(
10111002
AccountAddress::new([
@@ -1014,14 +1005,9 @@ pub fn donor_voice_txs_propose_advance_tx(
10141005
]),
10151006
ident_str!("donor_voice_txs").to_owned(),
10161007
),
1017-
ident_str!("propose_advance_tx").to_owned(),
1008+
ident_str!("maybe_close_reauth").to_owned(),
10181009
vec![],
1019-
vec![
1020-
bcs::to_bytes(&multisig_address).unwrap(),
1021-
bcs::to_bytes(&payee).unwrap(),
1022-
bcs::to_bytes(&value).unwrap(),
1023-
bcs::to_bytes(&description).unwrap(),
1024-
],
1010+
vec![bcs::to_bytes(&multisig_address).unwrap()],
10251011
))
10261012
}
10271013

@@ -1044,13 +1030,12 @@ pub fn donor_voice_txs_propose_liquidate_tx(
10441030
))
10451031
}
10461032

1047-
/// A signer of the multisig can propose a payment
1048-
/// Public entry function required for txs cli.
10491033
pub fn donor_voice_txs_propose_payment_tx(
10501034
multisig_address: AccountAddress,
10511035
payee: AccountAddress,
10521036
value: u64,
10531037
description: Vec<u8>,
1038+
advance_unlocked: bool,
10541039
) -> TransactionPayload {
10551040
TransactionPayload::EntryFunction(EntryFunction::new(
10561041
ModuleId::new(
@@ -1067,6 +1052,7 @@ pub fn donor_voice_txs_propose_payment_tx(
10671052
bcs::to_bytes(&payee).unwrap(),
10681053
bcs::to_bytes(&value).unwrap(),
10691054
bcs::to_bytes(&description).unwrap(),
1055+
bcs::to_bytes(&advance_unlocked).unwrap(),
10701056
],
10711057
))
10721058
}
@@ -1845,15 +1831,12 @@ mod decoder {
18451831
}
18461832
}
18471833

1848-
pub fn donor_voice_txs_propose_advance_tx(
1834+
pub fn donor_voice_txs_maybe_close_reauth(
18491835
payload: &TransactionPayload,
18501836
) -> Option<EntryFunctionCall> {
18511837
if let TransactionPayload::EntryFunction(script) = payload {
1852-
Some(EntryFunctionCall::DonorVoiceTxsProposeAdvanceTx {
1838+
Some(EntryFunctionCall::DonorVoiceTxsMaybeCloseReauth {
18531839
multisig_address: bcs::from_bytes(script.args().first()?).ok()?,
1854-
payee: bcs::from_bytes(script.args().get(1)?).ok()?,
1855-
value: bcs::from_bytes(script.args().get(2)?).ok()?,
1856-
description: bcs::from_bytes(script.args().get(3)?).ok()?,
18571840
})
18581841
} else {
18591842
None
@@ -1881,6 +1864,7 @@ mod decoder {
18811864
payee: bcs::from_bytes(script.args().get(1)?).ok()?,
18821865
value: bcs::from_bytes(script.args().get(2)?).ok()?,
18831866
description: bcs::from_bytes(script.args().get(3)?).ok()?,
1867+
advance_unlocked: bcs::from_bytes(script.args().get(4)?).ok()?,
18841868
})
18851869
} else {
18861870
None
@@ -2291,8 +2275,8 @@ static SCRIPT_FUNCTION_DECODER_MAP: once_cell::sync::Lazy<EntryFunctionDecoderMa
22912275
Box::new(decoder::diem_governance_trigger_epoch),
22922276
);
22932277
map.insert(
2294-
"donor_voice_txs_propose_advance_tx".to_string(),
2295-
Box::new(decoder::donor_voice_txs_propose_advance_tx),
2278+
"donor_voice_txs_maybe_close_reauth".to_string(),
2279+
Box::new(decoder::donor_voice_txs_maybe_close_reauth),
22962280
);
22972281
map.insert(
22982282
"donor_voice_txs_propose_liquidate_tx".to_string(),

framework/libra-framework/sources/ol_sources/community_wallet_advance.move

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ module ol_framework::community_wallet_advance {
2121
use std::error;
2222
use std::signer;
2323
use std::timestamp;
24-
use diem_framework::account::{Self, WithdrawCapability};
24+
use diem_framework::account::{Self, GUIDCapability, WithdrawCapability};
2525
use diem_framework::coin::{Coin};
2626
use ol_framework::ol_account;
2727
use ol_framework::libra_coin::{Self, LibraCoin};
@@ -100,13 +100,6 @@ module ol_framework::community_wallet_advance {
100100
}
101101
}
102102

103-
/// check if amount withdrawn will be below credit limit
104-
fun can_withdraw_amount(dv_account: address, amount: u64):bool acquires Advances {
105-
assert!(amount> 0, error::invalid_argument(EAMOUNT_IS_ZERO));
106-
assert!(!is_delinquent(dv_account), error::invalid_state(ELOAN_OVERDUE));
107-
let available = total_credit_available(dv_account);
108-
available > amount
109-
}
110103
/// Only can be called on epoch boundary as part of the donor_voice_txs.move authorization flow.
111104
/// Will withdraw funds and track the logger
112105
public(friend) fun transfer_credit(withdraw_cap: &WithdrawCapability, recipient: address, amount: u64): u64 acquires Advances {
@@ -124,6 +117,22 @@ module ol_framework::community_wallet_advance {
124117
amount
125118
}
126119

120+
public(friend) fun transfer_credit_vm(framework: &signer, guid_cap: &GUIDCapability, recipient: address, amount: u64): u64 acquires Advances {
121+
let dv_account = account::get_guid_capability_address(guid_cap);
122+
123+
can_withdraw_amount(dv_account, amount);
124+
log_withdrawal(dv_account, amount);
125+
126+
ol_account::vm_transfer(
127+
framework,
128+
dv_account,
129+
recipient,
130+
amount,
131+
);
132+
// TODO: check if there is any possibility of partial amount sent
133+
amount
134+
}
135+
127136
/// Service the loan with new coins
128137
/// If the balance outstanding is lower than the coin value,
129138
/// then only log the amount which is to be debited.
@@ -175,6 +184,17 @@ module ol_framework::community_wallet_advance {
175184
}
176185
}
177186

187+
//////// VIEW FUNCTIONS ////////
188+
189+
#[view]
190+
/// check if amount withdrawn will be below credit limit
191+
public fun can_withdraw_amount(dv_account: address, amount: u64): bool acquires Advances {
192+
assert!(amount> 0, error::invalid_argument(EAMOUNT_IS_ZERO));
193+
assert!(!is_delinquent(dv_account), error::invalid_state(ELOAN_OVERDUE));
194+
let available = total_credit_available(dv_account);
195+
available > amount
196+
}
197+
178198
#[view]
179199
/// Has the CW account made a payment in the last year
180200
// TODO: need to check amount of payment history in the last year, but we're not tracking individual payments.

framework/libra-framework/sources/ol_sources/donor_voice_migration.move

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ module ol_framework::donor_voice_migration {
1919
use ol_framework::migration_capability::{Self, MigrationCapability};
2020
use ol_framework::donor_voice;
2121
use ol_framework::donor_voice_governance;
22+
use ol_framework::community_wallet_advance;
2223

2324

2425
friend ol_framework::migrations;
@@ -60,6 +61,8 @@ module ol_framework::donor_voice_migration {
6061
// create Offer structure
6162
multi_action::maybe_init_auth_offer(&multisig_signer, multisig_address);
6263

64+
community_wallet_advance::initialize(&multisig_signer);
65+
6366
donor_voice_governance::maybe_init_dv_governance(&multisig_signer);
6467
activity::lazy_initialize(&multisig_signer, timestamp::now_seconds());
6568

0 commit comments

Comments
 (0)