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: 12 additions & 6 deletions contracts/revenue_pool/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![no_std]

use soroban_sdk::{contract, contractimpl, token, Address, Env, Symbol, Vec, BytesN};
use soroban_sdk::{contract, contractimpl, token, Address, BytesN, Env, Symbol, Vec};

/// Revenue settlement contract: receives USDC from vault deducts and distributes to developers.
///
Expand Down Expand Up @@ -34,7 +34,7 @@ pub const MAX_BATCH_SIZE: u32 = 50;
/// TTL bump constants for instance storage archival risk mitigation.
/// Soroban archives ledger entries after ~7 days (631 ledgers) of inactivity.
/// Bumping TTL ensures state remains accessible for critical operations.
///
///
/// # Constants
/// - `BUMP_AMOUNT`: Number of ledgers to extend TTL by (10000 ledgers ≈ 16 days)
/// - `LIFETIME_THRESHOLD`: Minimum TTL before triggering a bump (1000 ledgers ≈ 1.5 days)
Expand Down Expand Up @@ -308,7 +308,9 @@ impl RevenuePool {
panic!("{}", ERR_INSUFFICIENT_BALANCE);
}

env.storage().instance().extend_ttl(LIFETIME_THRESHOLD, BUMP_AMOUNT);
env.storage()
.instance()
.extend_ttl(LIFETIME_THRESHOLD, BUMP_AMOUNT);

usdc.transfer(&contract_address, &to, &amount);
env.events()
Expand Down Expand Up @@ -409,7 +411,9 @@ impl RevenuePool {
}

// Extend TTL before executing transfers
env.storage().instance().extend_ttl(LIFETIME_THRESHOLD, BUMP_AMOUNT);
env.storage()
.instance()
.extend_ttl(LIFETIME_THRESHOLD, BUMP_AMOUNT);

// Phase 3: Execution
// All validation passed - now perform the transfers
Expand Down Expand Up @@ -459,15 +463,17 @@ impl RevenuePool {

// Perform the on-chain upgrade via the deployer interface.
// This is a host operation and may only succeed in the live environment.
env.deployer().update_current_contract_wasm(new_wasm_hash.clone());
env.deployer()
.update_current_contract_wasm(new_wasm_hash.clone());

// Persist the version marker for on-chain queries.
env.storage()
.instance()
.set(&Symbol::new(&env, VERSION_KEY), &new_wasm_hash.clone());

// Emit an event for indexers / audit logs.
env.events().publish((Symbol::new(&env, "upgraded"), admin), new_wasm_hash);
env.events()
.publish((Symbol::new(&env, "upgraded"), admin), new_wasm_hash);
}

/// Read the stored contract version (WASM hash) as last set by `upgrade`.
Expand Down
2 changes: 1 addition & 1 deletion contracts/revenue_pool/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1977,7 +1977,7 @@ fn state_persists_after_ledger_advance() {
// set_admin extends TTL
let new_admin = Address::generate(&env);
client.set_admin(&admin, &new_admin);

// claim_admin extends TTL
client.claim_admin(&new_admin);
assert_eq!(client.get_admin(), new_admin);
Expand Down
26 changes: 13 additions & 13 deletions contracts/settlement/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,6 @@ impl CalloraSettlement {
let dev_address = developer
.unwrap_or_else(|| panic!("developer address required when to_pool=false"));



// Read current balance from persistent storage
let current_balance = env
.storage()
Expand All @@ -194,17 +192,20 @@ impl CalloraSettlement {
let new_balance = current_balance
.checked_add(amount)
.unwrap_or_else(|| panic!("developer balance overflow"));

// Write to persistent storage with TTL extension
env.storage()
.persistent()
.set(&StorageKey::DeveloperBalance(dev_address.clone()), &new_balance);

env.storage().persistent().set(
&StorageKey::DeveloperBalance(dev_address.clone()),
&new_balance,
);

// Extend TTL for the developer's balance entry (persistent storage live for 1 year)
env.storage()
.persistent()
.extend_ttl(&StorageKey::DeveloperBalance(dev_address.clone()), 50000, 50000);

env.storage().persistent().extend_ttl(
&StorageKey::DeveloperBalance(dev_address.clone()),
50000,
50000,
);

// Add developer to index if not already present
let mut index: Vec<Address> = inst
.get(&StorageKey::DeveloperIndex)
Expand All @@ -214,7 +215,6 @@ impl CalloraSettlement {
inst.set(&StorageKey::DeveloperIndex, &index);
}


env.events().publish(
(Symbol::new(&env, "payment_received"), caller.clone()),
PaymentReceivedEvent {
Expand Down Expand Up @@ -389,7 +389,7 @@ impl CalloraSettlement {
let index: Vec<Address> = inst
.get(&StorageKey::DeveloperIndex)
.unwrap_or_else(|| Vec::new(&env));

let mut result = Vec::new(&env);
for address in index.iter() {
let balance = env
Expand Down
8 changes: 5 additions & 3 deletions contracts/settlement/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ mod settlement_tests {
assert!(inst.has(&StorageKey::Vault));
assert!(inst.has(&StorageKey::DeveloperIndex));
assert!(inst.has(&StorageKey::GlobalPool));
let developer_index: Vec<Address> =
inst.get(&StorageKey::DeveloperIndex).unwrap();
let developer_index: Vec<Address> = inst.get(&StorageKey::DeveloperIndex).unwrap();

assert_eq!(developer_index.len(), 0);
});
Expand Down Expand Up @@ -115,7 +114,10 @@ mod settlement_tests {

env.set_auths(&[]);
let result = client.try_init(&admin, &vault);
assert!(result.is_err(), "expected init to require the admin signature");
assert!(
result.is_err(),
"expected init to require the admin signature"
);
}

#[test]
Expand Down
7 changes: 5 additions & 2 deletions contracts/vault/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,8 +415,11 @@ impl CalloraVault {
.instance()
.get(&StorageKey::UsdcToken)
.expect("vault not initialized");
token::Client::new(&env, &usdc_addr)
.transfer(&caller, &env.current_contract_address(), &amount);
token::Client::new(&env, &usdc_addr).transfer(
&caller,
&env.current_contract_address(),
&amount,
);
meta.balance = meta
.balance
.checked_add(amount)
Expand Down
Loading
Loading