Complete reference for all StellopayCore contract functions, events, and data structures.
Initializes the contract with an owner/admin address. This should be called once when deploying the contract.
Parameters:
env: Environment contextowner: Address of the contract owner
Authorization: Requires owner signature
Errors:
- Panics if contract is already initialized
Example:
contract.initialize(&env, &owner_address);Pauses all contract operations. Only callable by the contract owner.
Parameters:
env: Environment contextcaller: Address attempting to pause (must be owner)
Authorization: Requires caller signature
Returns:
Ok(())on successPayrollError::Unauthorizedif caller is not the owner
Events: Emits PAUSED_EVENT
Resumes contract operations. Only callable by the contract owner.
Parameters:
env: Environment contextcaller: Address attempting to unpause (must be owner)
Authorization: Requires caller signature
Returns:
Ok(())on successPayrollError::Unauthorizedif caller is not the owner
Events: Emits UNPAUSED_EVENT
Checks if the contract is currently paused.
Parameters:
env: Environment context
Returns: true if paused, false otherwise
Returns the current owner of the contract.
Parameters:
env: Environment context
Returns: Some(Address) if owner is set, None otherwise
Transfers ownership to a new address.
Parameters:
env: Environment contextcaller: Current owner addressnew_owner: New owner address
Authorization: Requires caller signature
Returns:
Ok(())on successPayrollError::Unauthorizedif caller is not the current owner
Adds a new supported token for payroll payments.
Parameters:
env: Environment contexttoken: Token contract address
Authorization: Requires owner signature
Returns:
Ok(())on successPayrollError::Unauthorizedif caller is not the owner
Removes a token from the supported tokens list.
Parameters:
env: Environment contexttoken: Token contract address
Authorization: Requires owner signature
Returns:
Ok(())on successPayrollError::Unauthorizedif caller is not the owner
Checks if a token is supported for payroll payments.
Parameters:
env: Environment contexttoken: Token contract address
Returns: true if supported, false otherwise
Returns token metadata (decimals).
Parameters:
env: Environment contexttoken: Token contract address
Returns: Some(decimals) if metadata exists, None otherwise
create_or_update_escrow(env: Env, employer: Address, employee: Address, token: Address, amount: i128, interval: u64, recurrence_frequency: u64) -> Result<Payroll, PayrollError>
Creates or updates a payroll escrow for an employee.
Parameters:
env: Environment contextemployer: Employer addressemployee: Employee addresstoken: Payment token addressamount: Payment amount per disbursementinterval: Legacy parameter (kept for compatibility)recurrence_frequency: Time between payments in seconds
Authorization: Requires employer signature
Returns:
Ok(Payroll)on successPayrollError::Unauthorizedif not authorizedPayrollError::InvalidDataif parameters are invalidPayrollError::ContractPausedif contract is paused
Events: Emits UPDATED_EVENT
Requirements:
- Contract must not be paused
- Only owner can create new payrolls
- Only owner or existing employer can update payrolls
- Amount must be positive
- Interval and recurrence_frequency must be greater than 0
Retrieves payroll information for an employee.
Parameters:
env: Environment contextemployee: Employee address
Returns: Some(Payroll) if exists, None otherwise
Gets the next scheduled payout timestamp for an employee.
Parameters:
env: Environment contextemployee: Employee address
Returns: Some(timestamp) if payroll exists, None otherwise
Gets the recurrence frequency for an employee's payroll.
Parameters:
env: Environment contextemployee: Employee address
Returns: Some(frequency) in seconds if payroll exists, None otherwise
Checks if an employee is eligible for salary disbursement.
Parameters:
env: Environment contextemployee: Employee address
Returns: true if eligible (next payout time reached), false otherwise
deposit_tokens(env: Env, employer: Address, token: Address, amount: i128) -> Result<(), PayrollError>
Deposits tokens to an employer's salary pool.
Parameters:
env: Environment contextemployer: Employer addresstoken: Token contract addressamount: Amount to deposit
Authorization: Requires employer signature
Returns:
Ok(())on successPayrollError::InvalidDataif amount is not positivePayrollError::TransferFailedif token transfer failsPayrollError::ContractPausedif contract is paused
Events: Emits DEPOSIT_EVENT
Returns an employer's token balance in the contract.
Parameters:
env: Environment contextemployer: Employer addresstoken: Token contract address
Returns: Balance amount (0 if no balance)
Disburses salary to an employee.
Parameters:
env: Environment contextcaller: Address initiating the disbursement (must be employer)employee: Employee address
Authorization: Requires caller signature
Returns:
Ok(())on successPayrollError::Unauthorizedif caller is not the employerPayrollError::PayrollNotFoundif no payroll existsPayrollError::NextPayoutTimeNotReachedif payout time not reachedPayrollError::InsufficientBalanceif employer has insufficient balancePayrollError::TransferFailedif token transfer failsPayrollError::ContractPausedif contract is paused
Events: Emits SalaryDisbursed event
Allows an employee to withdraw their salary.
Parameters:
env: Environment contextemployee: Employee address
Authorization: Requires employee signature
Returns: Same as disburse_salary
Processes recurring disbursements for multiple employees.
Parameters:
env: Environment contextcaller: Address initiating the process (must be owner)employees: List of employee addresses to process
Authorization: Requires caller signature (must be owner)
Returns: List of successfully processed employee addresses
Events: Emits RECUR_EVENT and individual SalaryDisbursed events
Represents a payroll configuration for an employee.
pub struct Payroll {
pub employer: Address, // Employer address
pub token: Address, // Payment token address
pub amount: i128, // Payment amount per disbursement
pub interval: u64, // Legacy interval field
pub last_payment_time: u64, // Timestamp of last payment
pub recurrence_frequency: u64, // Frequency in seconds
pub next_payout_timestamp: u64, // Next scheduled payout
}Error types that can be returned by contract functions.
pub enum PayrollError {
Unauthorized = 1, // Non-authorized access
IntervalNotReached = 2, // Payment interval not reached
InvalidData = 3, // Invalid input data
PayrollNotFound = 4, // Payroll record not found
TransferFailed = 5, // Token transfer failed
InsufficientBalance = 6, // Insufficient employer balance
ContractPaused = 7, // Contract is paused
InvalidRecurrenceFrequency = 8, // Invalid recurrence frequency
NextPayoutTimeNotReached = 9, // Next payout time not reached
NoEligibleEmployees = 10, // No eligible employees
}Emitted when the contract is paused.
Topics: ("paused",)
Data: caller: Address
Emitted when the contract is unpaused.
Topics: ("unpaused",)
Data: caller: Address
Emitted when tokens are deposited to an employer's balance.
Topics: ("deposit", employer: Address, token: Address)
Data: amount: i128
Emitted when a payroll is created or updated.
Topics: ("updated",)
Data: (employer: Address, employee: Address, recurrence_frequency: u64)
Emitted when recurring disbursements are processed.
Topics: ("recur",)
Data: (caller: Address, processed_count: u32)
Emitted when salary is disbursed to an employee.
Topics: ("SalaryDisbursed",)
Data:
pub struct SalaryDisbursed {
pub employer: Address,
pub employee: Address,
pub token: Address,
pub amount: i128,
pub timestamp: u64,
}The contract uses the following storage keys:
pub enum DataKey {
// Payroll data, keyed by employee address
PayrollEmployer(Address),
PayrollToken(Address),
PayrollAmount(Address),
PayrollInterval(Address),
PayrollLastPayment(Address),
PayrollRecurrenceFrequency(Address),
PayrollNextPayoutTimestamp(Address),
// Employer balance, keyed by (employer, token)
Balance(Address, Address),
// Admin data
Owner,
Paused,
// Token support
SupportedToken(Address),
TokenMetadata(Address),
}// Always check if contract is paused before operations
if contract.is_paused(&env) {
return Err(PayrollError::ContractPaused);
}// Most functions require caller authentication
caller.require_auth();
// Owner-only functions check ownership
let owner = contract.get_owner(&env).ok_or(PayrollError::Unauthorized)?;
if caller != owner {
return Err(PayrollError::Unauthorized);
}// Check token support before operations
if !contract.is_token_supported(&env, &token) {
return Err(PayrollError::InvalidData);
}