Skip to content
Open
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
28 changes: 28 additions & 0 deletions .rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# bc-forge Rust Formatting Configuration
# https://rust-lang.github.io/rustfmt/
#
# Note: some advanced options (imports_granularity, group_imports, brace_style, etc.)
# require the nightly toolchain. This config uses stable-only options.
# To enable nightly options, run: rustup override set nightly

edition = "2021"

# Indentation
tab_spaces = 4
hard_tabs = false

# Line length
max_width = 100

# Imports
reorder_imports = true
reorder_modules = true

# Functions
fn_params_layout = "Tall"

# Misc
newline_style = "Unix"
remove_nested_parens = true
use_field_init_shorthand = true
use_try_shorthand = true
26 changes: 5 additions & 21 deletions contracts/token/src/events.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
//! # bc-forge Token Events
//!
//! Structured event emission for all token contract operations.
//! Events are emitted to the ledger for indexing by off-chain services.

use soroban_sdk::{symbol_short, Address, BytesN, Env, String};

/// Emitted when the token contract is initialized.
pub fn emit_initialized(env: &Env, admin: &Address, decimals: u32, name: &String, symbol: &String) {
env.events().publish(
(symbol_short!("init"),),
(admin.clone(), decimals, name.clone(), symbol.clone()),
);
}

/// Emitted when tokens are minted.
pub fn emit_max_supply_set(env: &Env, admin: &Address, max_supply: i128) {
env.events()
.publish((symbol_short!("max_sup"),), (admin.clone(), max_supply));
}

pub fn emit_mint(
env: &Env,
admin: &Address,
Expand All @@ -28,21 +28,18 @@ pub fn emit_mint(
);
}

/// Emitted when tokens are burned.
pub fn emit_burn(env: &Env, from: &Address, amount: i128, new_balance: i128, new_supply: i128) {
env.events().publish(
(symbol_short!("burn"),),
(from.clone(), amount, new_balance, new_supply),
);
}

/// Emitted on a standard transfer.
pub fn emit_transfer(env: &Env, from: &Address, to: &Address, amount: i128) {
env.events()
.publish((symbol_short!("xfer"),), (from.clone(), to.clone(), amount));
}

/// Emitted on a delegated transfer (transfer_from).
pub fn emit_transfer_from(
env: &Env,
spender: &Address,
Expand All @@ -63,97 +60,84 @@ pub fn emit_transfer_from(
);
}

/// Emitted when an allowance is approved.
pub fn emit_approve(env: &Env, from: &Address, spender: &Address, amount: i128) {
env.events().publish(
(symbol_short!("approve"),),
(from.clone(), spender.clone(), amount),
);
}

/// Emitted when contract ownership is transferred.
pub fn emit_ownership_transferred(env: &Env, old_admin: &Address, new_admin: &Address) {
env.events().publish(
(symbol_short!("own_xfer"),),
(old_admin.clone(), new_admin.clone()),
);
}

/// Emitted when a new admin is proposed (two-step transfer).
pub fn emit_ownership_proposed(env: &Env, old_admin: &Address, pending_admin: &Address) {
env.events().publish(
(symbol_short!("own_prop"),),
(old_admin.clone(), pending_admin.clone()),
);
}

/// Emitted when pending admin accepts ownership.
pub fn emit_ownership_accepted(env: &Env, old_admin: &Address, new_admin: &Address) {
env.events().publish(
(symbol_short!("own_acc"),),
(old_admin.clone(), new_admin.clone()),
);
}

/// Emitted when ownership transfer is cancelled.
pub fn emit_ownership_cancelled(env: &Env, admin: &Address, cancelled_admin: &Address) {
env.events().publish(
(symbol_short!("own_can"),),
(admin.clone(), cancelled_admin.clone()),
);
}

/// Emitted when the contract is paused.
pub fn emit_paused(env: &Env, admin: &Address) {
env.events()
.publish((symbol_short!("paused"),), (admin.clone(),));
}

/// Emitted when the contract is unpaused.
pub fn emit_unpaused(env: &Env, admin: &Address) {
env.events()
.publish((symbol_short!("unpause"),), (admin.clone(),));
}

/// Emitted when tokens are clawed back.
pub fn emit_clawback(env: &Env, admin: &Address, from: &Address, to: &Address, amount: i128) {
env.events().publish(
(symbol_short!("clawback"),),
(admin.clone(), from.clone(), to.clone(), amount),
);
}

/// Emitted when tokens are locked.
pub fn emit_locked(env: &Env, user: &Address, amount: i128, unlock_time: u64) {
env.events().publish(
(symbol_short!("lock"),),
(user.clone(), amount, unlock_time),
);
}

/// Emitted when locked tokens are withdrawn.
pub fn emit_withdraw_locked(env: &Env, user: &Address, amount: i128) {
env.events()
.publish((symbol_short!("unlock"),), (user.clone(), amount));
}

/// Emitted when the contract is upgraded.
pub fn emit_upgrade(env: &Env, admin: &Address, new_wasm_hash: &BytesN<32>) {
env.events().publish(
(symbol_short!("upgrade"),),
(admin.clone(), new_wasm_hash.clone()),
);
}

/// Emitted when the token name is updated.
pub fn emit_update_name(env: &Env, admin: &Address, old_name: &String, new_name: &String) {
env.events().publish(
(symbol_short!("upd_name"),),
(admin.clone(), old_name.clone(), new_name.clone()),
);
}

/// Emitted when the token symbol is updated.
pub fn emit_update_symbol(env: &Env, admin: &Address, old_symbol: &String, new_symbol: &String) {
env.events().publish(
(symbol_short!("upd_sym"),),
Expand Down
Loading
Loading