Skip to content

Commit

Permalink
feat: add proposal deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
thounyy committed Sep 27, 2024
1 parent 8505ff6 commit bda4ee8
Show file tree
Hide file tree
Showing 10 changed files with 154 additions and 14 deletions.
11 changes: 11 additions & 0 deletions packages/actions/sources/config.move
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,17 @@ public fun config_deps<W: copy + drop>(
*multisig.deps_mut(executable, witness) = inner;
}

// === [CORE DEPS] Public functions ===

public fun delete_config_action<T: drop, W: copy + drop>(
action: ConfigAction<T>,
multisig: &Multisig,
witness: W,
) {
multisig.deps().assert_core_dep(witness);
let ConfigAction { .. } = action;
}

// === Private functions ===

fun verify_new_rules(
Expand Down
31 changes: 31 additions & 0 deletions packages/actions/sources/currency.move
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,37 @@ public fun destroy_update<C: drop, W: copy + drop>(executable: &mut Executable,
assert!(name.is_none() && symbol.is_none() && description.is_none() && icon_url.is_none(), EUpdateNotExecuted);
}

// === [CORE DEPS] Public functions ===

public fun delete_mint_action<C: drop, W: copy + drop>(
action: MintAction<C>,
multisig: &Multisig,
witness: W,
) {
multisig.deps().assert_core_dep(witness);
let MintAction { .. } = action;
}

public fun delete_burn_action<C: drop, W: copy + drop>(
action: BurnAction<C>,
multisig: &Multisig,
witness: W,
) {
multisig.deps().assert_core_dep(witness);
let BurnAction { .. } = action;
}

public fun delete_update_action<C: drop, W: copy + drop>(
action: UpdateAction<C>,
multisig: &Multisig,
witness: W,
) {
multisig.deps().assert_core_dep(witness);
let UpdateAction { .. } = action;
}

// === Private functions ===

fun type_to_name<T: drop>(): String {
type_name::get<T>().into_string().to_string()
}
20 changes: 20 additions & 0 deletions packages/actions/sources/kiosk.move
Original file line number Diff line number Diff line change
Expand Up @@ -323,3 +323,23 @@ public fun destroy_list<W: copy + drop>(executable: &mut Executable, witness: W)
let ListAction { nfts_prices_map, .. } = executable.remove_action(witness);
assert!(nfts_prices_map.is_empty(), EListAllNftsBefore);
}

// === [CORE DEPS] Public functions ===

public fun delete_take_action<W: copy + drop>(
action: TakeAction,
multisig: &Multisig,
witness: W
) {
multisig.deps().assert_core_dep(witness);
let TakeAction { .. } = action;
}

public fun delete_list_action<W: copy + drop>(
action: ListAction,
multisig: &Multisig,
witness: W
) {
multisig.deps().assert_core_dep(witness);
let ListAction { .. } = action;
}
20 changes: 20 additions & 0 deletions packages/actions/sources/owned.move
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,23 @@ public fun destroy_borrow<W: copy + drop>(executable: &mut Executable, witness:
let ReturnAction { to_return } = executable.remove_action(witness);
assert!(to_return.is_empty(), EReturnAllObjectsBefore);
}

// === [CORE DEPS] Public functions ===

public fun delete_withdraw_action<W: copy + drop>(
action: WithdrawAction,
multisig: &Multisig,
witness: W
) {
multisig.deps().assert_core_dep(witness);
let WithdrawAction { .. } = action;
}

public fun delete_return_action<W: copy + drop>(
action: ReturnAction,
multisig: &Multisig,
witness: W
) {
multisig.deps().assert_core_dep(witness);
let ReturnAction { .. } = action;
}
11 changes: 11 additions & 0 deletions packages/actions/sources/payments.move
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,17 @@ public fun recipient<C: drop>(self: &Stream<C>): address {
self.recipient
}

// === [CORE DEPS] Public functions ===

public fun delete_pay_action<W: copy + drop>(
action: PayAction,
multisig: &Multisig,
witness: W
) {
multisig.deps().assert_core_dep(witness);
let PayAction { .. } = action;
}

// === Private functions ===

// retrieves an object from the Multisig owned or managed assets
Expand Down
11 changes: 11 additions & 0 deletions packages/actions/sources/transfers.move
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,17 @@ public fun destroy_transfer_coin<C: drop, W: copy + drop>(
assert!(recipient == @0xF, ETransferNotExecuted);
}

// === [CORE DEPS] Public functions ===

public fun delete_transfer_action<W: copy + drop>(
action: TransferAction,
multisig: &Multisig,
witness: W
) {
multisig.deps().assert_core_dep(witness);
let TransferAction { .. } = action;
}

// === Private functions ===

fun is_withdraw<C: drop>(executable: &Executable): bool {
Expand Down
11 changes: 11 additions & 0 deletions packages/actions/sources/treasury.move
Original file line number Diff line number Diff line change
Expand Up @@ -226,3 +226,14 @@ public fun spend_is_executed(executable: &Executable): bool {
let spend: &SpendAction = executable.action();
spend.coins_amounts_map.is_empty()
}

// === [CORE DEPS] Public functions ===

public fun delete_spend_action<W: copy + drop>(
action: SpendAction,
multisig: &Multisig,
witness: W
) {
multisig.deps().assert_core_dep(witness);
let SpendAction { .. } = action;
}
13 changes: 13 additions & 0 deletions packages/actions/sources/upgrade_policies.move
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,19 @@ public fun destroy_restrict<W: copy + drop>(executable: &mut Executable, witness
assert!(policy == 0, ERestrictNotExecuted);
}

// === [CORE DEPS] Public functions ===

public fun delete_upgrade_action<W: copy + drop>(
action: UpgradeAction,
multisig: &Multisig,
witness: W
) {
multisig.deps().assert_core_dep(witness);
let UpgradeAction { .. } = action;
}

// === Private Functions ===

fun time_delay(lock: &UpgradeLock): u64 {
if (lock.has_rule(TimeLockKey {})) {
let timelock: &TimeLock = df::borrow(&lock.id, TimeLockKey {});
Expand Down
27 changes: 13 additions & 14 deletions packages/multisig/sources/multisig.move
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use sui::{
transfer::Receiving,
clock::Clock,
dynamic_field as df,
bag::Bag,
};
use kraken_multisig::{
auth,
Expand Down Expand Up @@ -162,20 +163,18 @@ public fun execute_proposal(
executable::new(auth, actions)
}

// TODO: manage actions in bag (drop?)
// removes a proposal if it has expired
// public fun delete_proposal(
// multisig: &mut Multisig,
// key: String,
// ctx: &mut TxContext
// ): Bag {
// let (_, proposal) = multisig.proposals.remove(&key);
// assert!(proposal.expiration_epoch() <= ctx.epoch(), EHasntExpired);
// let (auth, actions) = proposal.destroy();
// multisig.deps.assert_version(&auth, VERSION);

// actions
// }
/// Removes a proposal if it has expired
/// Needs to delete each action in the bag within their own module
public fun delete_proposal(
multisig: &mut Multisig,
key: String,
ctx: &mut TxContext
): Bag {
let (auth, actions) = multisig.proposals.delete(key, ctx);
multisig.deps.assert_version(&auth, VERSION);

actions
}

// === View functions ===

Expand Down
13 changes: 13 additions & 0 deletions packages/multisig/sources/proposals.move
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const EAlreadyApproved: u64 = 0;
const ENotApproved: u64 = 1;
const EProposalNotFound: u64 = 2;
const EProposalKeyAlreadyExists: u64 = 3;
const EHasntExpired: u64 = 4;

// === Events ===

Expand Down Expand Up @@ -210,6 +211,18 @@ public(package) fun remove(
(auth, actions)
}

public(package) fun delete(
proposals: &mut Proposals,
key: String,
ctx: &TxContext
): (Auth, Bag) {
let idx = proposals.get_idx(key);
let Proposal { auth, expiration_epoch, actions, .. } = proposals.inner.remove(idx);
assert!(expiration_epoch <= ctx.epoch(), EHasntExpired);

(auth, actions)
}

public(package) fun approve(
proposal: &mut Proposal,
member: &Member,
Expand Down

0 comments on commit bda4ee8

Please sign in to comment.