Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions contracts/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ pub struct Config {
pub withdrawal_fee_bps: u32,
pub performance_fee_bps: u32,
pub paused: bool,
pub upgrade_delay: u64,
}

// ========== Admin Verification ==========
Expand Down Expand Up @@ -63,6 +64,7 @@ pub fn initialize_config(
deposit_fee_bps: u32,
withdrawal_fee_bps: u32,
performance_fee_bps: u32,
upgrade_delay: u64,
) -> Result<(), SavingsError> {
// Prevent re-initialization
let already_init: bool = env
Expand Down Expand Up @@ -98,6 +100,9 @@ pub fn initialize_config(
env.storage()
.instance()
.set(&DataKey::PerformanceFeeBps, &performance_fee_bps);
env.storage()
.instance()
.set(&DataKey::NextTimelockId, &1u64); // Initialize timelock counter
env.storage()
.instance()
.set(&DataKey::ConfigInitialized, &true);
Expand All @@ -106,7 +111,7 @@ pub fn initialize_config(
crate::treasury::initialize_treasury(env);

env.events()
.publish((symbol_short!("cfg_init"),), performance_fee_bps);
.publish((), crate::events::ProtocolEvent::CfgInit(performance_fee_bps));

Ok(())
}
Expand Down Expand Up @@ -166,6 +171,7 @@ pub fn get_config(env: &Env) -> Result<Config, SavingsError> {
withdrawal_fee_bps,
performance_fee_bps,
paused,
upgrade_delay: 86400 * 2, // 2 days default
})
}

Expand All @@ -186,7 +192,7 @@ pub fn set_treasury(env: &Env, admin: Address, new_treasury: Address) -> Result<
.set(&DataKey::TreasuryAddress, &new_treasury);

env.events()
.publish((symbol_short!("set_trs"),), new_treasury);
.publish((), crate::events::ProtocolEvent::SetTreasury(new_treasury));

Ok(())
}
Expand Down Expand Up @@ -225,7 +231,7 @@ pub fn set_fees(
.set(&DataKey::PerformanceFeeBps, &performance_fee);

env.events()
.publish((symbol_short!("set_fee"),), performance_fee);
.publish((), crate::events::ProtocolEvent::SetFees(performance_fee));

Ok(())
}
Expand All @@ -243,7 +249,8 @@ pub fn pause_contract(env: &Env, admin: Address) -> Result<(), SavingsError> {

env.storage().persistent().set(&DataKey::Paused, &true);

env.events().publish((symbol_short!("pause"),), admin);
env.events()
.publish((), crate::events::ProtocolEvent::CfgPause(admin));

Ok(())
}
Expand All @@ -261,7 +268,8 @@ pub fn unpause_contract(env: &Env, admin: Address) -> Result<(), SavingsError> {

env.storage().persistent().set(&DataKey::Paused, &false);

env.events().publish((symbol_short!("unpause"),), admin);
env.events()
.publish((), crate::events::ProtocolEvent::CfgUnpause(admin));

Ok(())
}
Expand Down
90 changes: 90 additions & 0 deletions contracts/src/events.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
use soroban_sdk::{contractevent, Address, BytesN, Symbol};

#[contractevent]
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum ProtocolEvent {
// Core
Init(BytesN<32>),
CreatePlan(Address, u64, i128),
SetAdmin(Address),
SetEarlyBreakFee(u32),
SetFeeRecipient(Address),
Pause(Address),
Unpause(Address),
EmergencyWithdraw(Address, u64, i128),

// Config
CfgInit(u32),
SetTreasury(Address),
SetFees(u32),
CfgPause(Address),
CfgUnpause(Address),

// Staking
Stake(Address, i128, i128),
Unstake(Address, i128, i128),
StakeRewards(Address, i128),

// Treasury
FeeCollected(Symbol, i128),
YieldDistributed(i128, i128),
TreasuryWithdrawn(Address, Symbol, i128),
ReserveUsed(Address, i128),
TreasuryAllocated(Address, i128, i128, i128),
LimitsUpdated(i128, i128),

// Rewards
PointsAwarded(Address, i128),
BonusAwarded(Address, i128, Symbol),
PointsRedeemed(Address, i128),
RewardsClaimed(Address, i128),
StreakUpdated(Address, u32),

// Governance
GovCreated(u64, Address),
GovVoted(u64, Address, u32, i128),
GovQueued(u64, u64),
GovExecuted(u64, u64),
GovCanceled(u64, u64),

// Token
Mint(Address, i128),
Burn(Address, i128),

// Goal
GoalCreated(Address, Symbol, i128, u64),
GoalDeposit(Address, u64, i128),
GoalWithdraw(Address, u64, i128),
GoalBreak(Address, u64, i128),
GoalFee(Address, u64, i128, Symbol),

// Flexi
FlexiDeposit(Address, i128),
FlexiWithdraw(Address, i128),
FlexiFee(Address, i128, Symbol),

// Group
GroupCreated(Address, Symbol, i128, u64),
GroupJoin(Address, u64),
GroupContribute(Address, u64, i128),
GroupBreak(Address, u64),
GroupFee(Address, u64, i128),

// Lock
LockCreated(Address, i128, u64, u64),
LockWithdraw(Address, u64, i128),

// Strategy
StratRegistered(Address),
StratDisabled(Address),
StratDeposit(Address, i128, i128),
StratWithdraw(Address, i128, i128),
StratHarvest(Address, i128, i128, i128),
StratYieldDistributed(Address, i128, i128, i128),

// Security
UpgradeScheduled(Address, BytesN<32>),
ContractUpgraded(BytesN<32>),
TimelockQueued(u64, Address, Symbol),
TimelockExecuted(u64, Address, Symbol),
}
12 changes: 8 additions & 4 deletions contracts/src/flexi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,10 @@ pub fn flexi_deposit(env: Env, user: Address, amount: i128) -> Result<(), Saving
.checked_add(fee_amount)
.ok_or(SavingsError::Overflow)?;
env.storage().persistent().set(&fee_key, &new_fee_balance);
env.events()
.publish((symbol_short!("dep_fee"), fee_recipient), fee_amount);
env.events().publish(
(),
crate::events::FlexiEvent::Fee(fee_recipient, fee_amount, soroban_sdk::Symbol::new(&env, "deposit")),
);
}
// Record fee in treasury struct
crate::treasury::record_fee(&env, fee_amount, soroban_sdk::Symbol::new(&env, "deposit"));
Expand Down Expand Up @@ -163,8 +165,10 @@ pub fn flexi_withdraw(env: Env, user: Address, amount: i128) -> Result<(), Savin
.checked_add(fee_amount)
.ok_or(SavingsError::Overflow)?;
env.storage().persistent().set(&fee_key, &new_fee_balance);
env.events()
.publish((symbol_short!("wth_fee"), fee_recipient), fee_amount);
env.events().publish(
(),
crate::events::FlexiEvent::Fee(fee_recipient, fee_amount, soroban_sdk::Symbol::new(&env, "withdraw")),
);
}
// Record fee in treasury struct
crate::treasury::record_fee(&env, fee_amount, soroban_sdk::Symbol::new(&env, "withdraw"));
Expand Down
12 changes: 6 additions & 6 deletions contracts/src/goal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,8 @@ pub fn withdraw_completed_goal_save(
.ok_or(SavingsError::Overflow)?;
env.storage().persistent().set(&fee_key, &new_fee_balance);
env.events().publish(
(symbol_short!("gwth_fee"), fee_recipient, goal_id),
fee_amount,
(),
crate::events::GoalEvent::Fee(fee_recipient, goal_id, fee_amount, soroban_sdk::Symbol::new(env, "withdraw")),
);
}
// Record fee in treasury struct
Expand Down Expand Up @@ -385,15 +385,15 @@ pub fn break_goal_save(env: &Env, user: Address, goal_id: u64) -> Result<i128, S
ttl::extend_config_ttl(env, &fee_key);

env.events().publish(
(symbol_short!("brk_fee"), fee_recipient, goal_id),
fee_amount,
(),
crate::events::GoalEvent::Fee(fee_recipient, goal_id, fee_amount, soroban_sdk::Symbol::new(env, "break")),
);
}
}

env.events().publish(
(symbol_short!("goal_brk"), user.clone(), goal_id),
net_amount,
(),
crate::events::GoalEvent::Break(user.clone(), goal_id, net_amount),
);

remove_goal_from_user(env, &user, goal_id);
Expand Down
96 changes: 21 additions & 75 deletions contracts/src/governance_events.rs
Original file line number Diff line number Diff line change
@@ -1,91 +1,37 @@
use soroban_sdk::{contracttype, symbol_short, Address, Env, String};

#[contracttype]
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct ProposalCreated {
pub proposal_id: u64,
pub creator: Address,
pub description: String,
}

#[contracttype]
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct VoteCast {
pub proposal_id: u64,
pub voter: Address,
pub vote_type: u32,
pub weight: u128,
}

#[contracttype]
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct ProposalQueued {
pub proposal_id: u64,
pub queued_at: u64,
}

#[contracttype]
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct ProposalExecuted {
pub proposal_id: u64,
pub executed_at: u64,
}

#[contracttype]
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct ProposalCanceled {
pub proposal_id: u64,
pub canceled_at: u64,
}

pub fn emit_proposal_created(env: &Env, proposal_id: u64, creator: Address, description: String) {
let event = ProposalCreated {
proposal_id,
creator: creator.clone(),
description,
};
use crate::events::ProtocolEvent;
use soroban_sdk::{Address, Env};

pub fn emit_proposal_created(env: &Env, proposal_id: u64, creator: Address, _description: soroban_sdk::String) {
env.events().publish(
(symbol_short!("gov"), symbol_short!("created"), creator),
event,
(),
ProtocolEvent::GovCreated(proposal_id, creator),
);
}

pub fn emit_vote_cast(env: &Env, proposal_id: u64, voter: Address, vote_type: u32, weight: u128) {
let event = VoteCast {
proposal_id,
voter: voter.clone(),
vote_type,
weight,
};

env.events()
.publish((symbol_short!("gov"), symbol_short!("voted"), voter), event);
env.events().publish(
(),
ProtocolEvent::GovVoted(proposal_id, voter, vote_type, weight as i128),
);
}

pub fn emit_proposal_queued(env: &Env, proposal_id: u64, queued_at: u64) {
let event = ProposalQueued {
proposal_id,
queued_at,
};
env.events()
.publish((symbol_short!("gov"), symbol_short!("queued")), event);
env.events().publish(
(),
ProtocolEvent::GovQueued(proposal_id, queued_at),
);
}

pub fn emit_proposal_executed(env: &Env, proposal_id: u64, executed_at: u64) {
let event = ProposalExecuted {
proposal_id,
executed_at,
};
env.events()
.publish((symbol_short!("gov"), symbol_short!("executed")), event);
env.events().publish(
(),
ProtocolEvent::GovExecuted(proposal_id, executed_at),
);
}

pub fn emit_proposal_canceled(env: &Env, proposal_id: u64, canceled_at: u64) {
let event = ProposalCanceled {
proposal_id,
canceled_at,
};
env.events()
.publish((symbol_short!("gov"), symbol_short!("canceled")), event);
env.events().publish(
(),
ProtocolEvent::GovCanceled(proposal_id, canceled_at),
);
}
12 changes: 6 additions & 6 deletions contracts/src/group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ pub fn create_group_save(

// Emit event for group creation
env.events()
.publish((soroban_sdk::symbol_short!("grp_new"), creator), group_id);
.publish((), crate::events::ProtocolEvent::GroupCreated(creator, new_group.title.clone(), new_group.target_amount, group_id));

Ok(group_id)
}
Expand Down Expand Up @@ -335,7 +335,7 @@ pub fn join_group_save(env: &Env, user: Address, group_id: u64) -> Result<(), Sa

// Emit event for joining group
env.events()
.publish((soroban_sdk::symbol_short!("grp_join"), user), group_id);
.publish((), crate::events::ProtocolEvent::GroupJoin(user, group_id));

Ok(())
}
Expand Down Expand Up @@ -476,8 +476,8 @@ pub fn contribute_to_group_save(

// Emit event for contribution
env.events().publish(
(soroban_sdk::symbol_short!("grp_cont"), user, group_id),
amount,
(),
crate::events::ProtocolEvent::GroupContribute(user, group_id, amount),
);

Ok(())
Expand Down Expand Up @@ -674,8 +674,8 @@ pub fn break_group_save(env: &Env, user: Address, group_id: u64) -> Result<(), S

// Emit event for leaving group
env.events().publish(
(soroban_sdk::symbol_short!("grp_leave"), user, group_id),
user_contribution,
(),
crate::events::ProtocolEvent::GroupBreak(user, group_id),
);

Ok(())
Expand Down
Loading
Loading