From bda4ee8eea4a34c872bee2a2dcf679d4b8221b4f Mon Sep 17 00:00:00 2001 From: thounyy Date: Fri, 27 Sep 2024 11:49:04 +0200 Subject: [PATCH] feat: add proposal deletion --- packages/actions/sources/config.move | 11 +++++++ packages/actions/sources/currency.move | 31 +++++++++++++++++++ packages/actions/sources/kiosk.move | 20 ++++++++++++ packages/actions/sources/owned.move | 20 ++++++++++++ packages/actions/sources/payments.move | 11 +++++++ packages/actions/sources/transfers.move | 11 +++++++ packages/actions/sources/treasury.move | 11 +++++++ .../actions/sources/upgrade_policies.move | 13 ++++++++ packages/multisig/sources/multisig.move | 27 ++++++++-------- packages/multisig/sources/proposals.move | 13 ++++++++ 10 files changed, 154 insertions(+), 14 deletions(-) diff --git a/packages/actions/sources/config.move b/packages/actions/sources/config.move index 77b3e8f..3c23da7 100644 --- a/packages/actions/sources/config.move +++ b/packages/actions/sources/config.move @@ -279,6 +279,17 @@ public fun config_deps( *multisig.deps_mut(executable, witness) = inner; } +// === [CORE DEPS] Public functions === + +public fun delete_config_action( + action: ConfigAction, + multisig: &Multisig, + witness: W, +) { + multisig.deps().assert_core_dep(witness); + let ConfigAction { .. } = action; +} + // === Private functions === fun verify_new_rules( diff --git a/packages/actions/sources/currency.move b/packages/actions/sources/currency.move index c2f51b7..b59c421 100644 --- a/packages/actions/sources/currency.move +++ b/packages/actions/sources/currency.move @@ -337,6 +337,37 @@ public fun destroy_update(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( + action: MintAction, + multisig: &Multisig, + witness: W, +) { + multisig.deps().assert_core_dep(witness); + let MintAction { .. } = action; +} + +public fun delete_burn_action( + action: BurnAction, + multisig: &Multisig, + witness: W, +) { + multisig.deps().assert_core_dep(witness); + let BurnAction { .. } = action; +} + +public fun delete_update_action( + action: UpdateAction, + multisig: &Multisig, + witness: W, +) { + multisig.deps().assert_core_dep(witness); + let UpdateAction { .. } = action; +} + +// === Private functions === + fun type_to_name(): String { type_name::get().into_string().to_string() } diff --git a/packages/actions/sources/kiosk.move b/packages/actions/sources/kiosk.move index 5a1837b..2c595de 100644 --- a/packages/actions/sources/kiosk.move +++ b/packages/actions/sources/kiosk.move @@ -323,3 +323,23 @@ public fun destroy_list(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( + action: TakeAction, + multisig: &Multisig, + witness: W +) { + multisig.deps().assert_core_dep(witness); + let TakeAction { .. } = action; +} + +public fun delete_list_action( + action: ListAction, + multisig: &Multisig, + witness: W +) { + multisig.deps().assert_core_dep(witness); + let ListAction { .. } = action; +} diff --git a/packages/actions/sources/owned.move b/packages/actions/sources/owned.move index 64b7f6e..08bd4a9 100644 --- a/packages/actions/sources/owned.move +++ b/packages/actions/sources/owned.move @@ -102,3 +102,23 @@ public fun destroy_borrow(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( + action: WithdrawAction, + multisig: &Multisig, + witness: W +) { + multisig.deps().assert_core_dep(witness); + let WithdrawAction { .. } = action; +} + +public fun delete_return_action( + action: ReturnAction, + multisig: &Multisig, + witness: W +) { + multisig.deps().assert_core_dep(witness); + let ReturnAction { .. } = action; +} diff --git a/packages/actions/sources/payments.move b/packages/actions/sources/payments.move index e69467b..6221b5a 100644 --- a/packages/actions/sources/payments.move +++ b/packages/actions/sources/payments.move @@ -329,6 +329,17 @@ public fun recipient(self: &Stream): address { self.recipient } +// === [CORE DEPS] Public functions === + +public fun delete_pay_action( + 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 diff --git a/packages/actions/sources/transfers.move b/packages/actions/sources/transfers.move index a2d4dec..4647548 100644 --- a/packages/actions/sources/transfers.move +++ b/packages/actions/sources/transfers.move @@ -319,6 +319,17 @@ public fun destroy_transfer_coin( assert!(recipient == @0xF, ETransferNotExecuted); } +// === [CORE DEPS] Public functions === + +public fun delete_transfer_action( + action: TransferAction, + multisig: &Multisig, + witness: W +) { + multisig.deps().assert_core_dep(witness); + let TransferAction { .. } = action; +} + // === Private functions === fun is_withdraw(executable: &Executable): bool { diff --git a/packages/actions/sources/treasury.move b/packages/actions/sources/treasury.move index 4fd3bbf..defe0b7 100644 --- a/packages/actions/sources/treasury.move +++ b/packages/actions/sources/treasury.move @@ -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( + action: SpendAction, + multisig: &Multisig, + witness: W +) { + multisig.deps().assert_core_dep(witness); + let SpendAction { .. } = action; +} diff --git a/packages/actions/sources/upgrade_policies.move b/packages/actions/sources/upgrade_policies.move index 7169e5e..f5b747e 100644 --- a/packages/actions/sources/upgrade_policies.move +++ b/packages/actions/sources/upgrade_policies.move @@ -335,6 +335,19 @@ public fun destroy_restrict(executable: &mut Executable, witness assert!(policy == 0, ERestrictNotExecuted); } +// === [CORE DEPS] Public functions === + +public fun delete_upgrade_action( + 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 {}); diff --git a/packages/multisig/sources/multisig.move b/packages/multisig/sources/multisig.move index 456e3d4..0b28747 100644 --- a/packages/multisig/sources/multisig.move +++ b/packages/multisig/sources/multisig.move @@ -20,6 +20,7 @@ use sui::{ transfer::Receiving, clock::Clock, dynamic_field as df, + bag::Bag, }; use kraken_multisig::{ auth, @@ -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 === diff --git a/packages/multisig/sources/proposals.move b/packages/multisig/sources/proposals.move index 42e3117..e2be89d 100644 --- a/packages/multisig/sources/proposals.move +++ b/packages/multisig/sources/proposals.move @@ -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 === @@ -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,