Cash Modules
This contract is the main neobank financial operations module for EtherFi Safe users. User interactions with the EtherFi Cash system occur via the CashModule contract.
CashModule
allows users to:
Spend funds in Direct Pay mode or Credit mode
Set spending limits
Request and process withdrawals
Earn cashback rewards
Repay borrowed funds
Switch between operational modes
Configure cashback splits
CashModule is implemented as a set of contracts following the proxy pattern with distinct components:
CashModuleCore
: Core financial operationsCashModuleSetters
: Configuration managementCashModuleStorageContract
: Storage implementationCashLens
: Read-only views
Write Methods
setupModule
Initializes the Cash Module for a new Safe.
Function is invoked when the Cash Module is added to an EtherFi Safe.
Sets up default spending limits and mode configuration.
Input Parameters:
data
bytes
The encoded initialization data containing daily limit, monthly limit, and timezone offset
spend
Processes a spending transaction, transferring funds from the Safe in either Direct Pay or Credit mode.
Requires the caller to have the ETHER_FI_WALLET_ROLE
.
When spending in Direct Pay mode, tokens are transferred directly from the Safe to the settlement dispatcher. In Credit mode, tokens are borrowed against the Safe's collateral.
Input Parameters:
safe
address
The address of the EtherFi Safe
spender
address
The address of the user initiating the spend
referrer
address
The address of the referrer (or address(0) if none)
txId
bytes32
Unique transaction identifier
binSponsor
BinSponsor
Identifier of the bin sponsor (Rain or Reap)
tokens
address[]
Array of token addresses to spend
amountsInUsd
uint256[]
Array of amounts in USD value to spend (must match tokens array length)
shouldReceiveCashback
bool
Flag indicating if the transaction should earn cashback
repay
Repays borrowed tokens in Credit mode.
When repaying, the Safe must have sufficient balance of the token being used for repayment.
Input Parameters:
safe
address
The address of the EtherFi Safe
token
address
The address of the token used for repayment
amountInUsd
uint256
The amount to repay, expressed in USD value
requestWithdrawal
Requests a withdrawal of tokens from the Safe to a recipient address.
The function requires valid signatures from the Safe owners according to the Safe's threshold configuration.
Initiates a withdrawal request that will be available for processing after the withdrawal delay period.
Input Parameters:
safe
address
The address of the EtherFi Safe
tokens
address[]
Array of token addresses to withdraw
amounts
uint256[]
Array of token amounts to withdraw
recipient
address
Address that will receive the tokens
signers
address[]
Array of Safe owner addresses that signed the withdrawal request
signatures
bytes[]
Array of signatures corresponding to the signers
processWithdrawal
Processes a pending withdrawal request after the delay period has passed.
The function executes the token transfers to the recipient specified in the withdrawal request.
Fails if the withdrawal delay period has not yet elapsed.
Input Parameters:
safe
address
The address of the EtherFi Safe
setMode
Sets the operational mode for a Safe (Direct Pay or Credit).
Switching to Credit mode may have a delay period depending on configuration. Switching to Direct Pay mode happens immediately after verification.
Input Parameters:
safe
address
The address of the EtherFi Safe
mode
Mode
The target mode (Direct Pay or Credit)
signer
address
Address of the Safe admin signing the transaction
signature
bytes
Signature from the signer authorizing this mode change
updateSpendingLimit
Updates the spending limits for a Safe.
Changes to spending limits take effect after the configured delay period.
Input Parameters:
safe
address
The address of the EtherFi Safe
dailyLimitInUsd
uint256
New daily spending limit in USD
monthlyLimitInUsd
uint256
New monthly spending limit in USD
signer
address
Address of the Safe admin signing the transaction
signature
bytes
Signature from the signer authorizing this update
setCashbackSplitToSafeBps
Sets the percentage of cashback that goes to the Safe (versus the spender).
The split is expressed in basis points, where 10000 represents 100%.
Input Parameters:
safe
address
The address of the EtherFi Safe
splitInBps
uint256
Percentage in basis points to allocate to the Safe
signer
address
Address of the Safe admin signing the transaction
signature
bytes
Signature from the signer authorizing this change
clearPendingCashback
Clears pending cashback for a list of users.
Attempts to retrieve any pending cashback and distribute it to the specified users.
Input Parameters:
users
address[]
Array of user addresses to clear pending cashback for
Read Methods
getMode
Gets the current operational mode of a Safe.
Considers pending mode changes that have passed their delay period.
Input Parameters:
safe
address
The address of the EtherFi Safe
Return Values:
Mode
The current operational mode (Direct Pay or Credit)
canSpend
Checks if a spending transaction can be executed.
Validates if the Safe has sufficient balance or borrowing power for the specified tokens and amounts.
Input Parameters:
safe
address
The address of the EtherFi Safe
txId
bytes32
Transaction identifier
tokens
address[]
Array of token addresses to spend
amountsInUsd
uint256[]
Array of amounts in USD to spend
Return Values:
bool
Whether the spending is allowed
string
Error message if spending is not allowed
maxCanSpend
Calculates the maximum amount that can be spent in both Credit and Direct Pay modes.
Input Parameters:
safe
address
The address of the EtherFi Safe
token
address
The address of the token to spend
Return Values:
uint256
Maximum amount that can be spent in Credit mode (USD)
uint256
Maximum amount that can be spent in Direct Pay mode (USD)
uint256
Remaining spending limit allowance
getSafeCashData
Gets comprehensive cash data for a Safe.
Aggregates data from multiple sources including DebtManager and CashModule.
Input Parameters:
safe
address
The address of the EtherFi Safe
Return Values:
SafeCashData
Comprehensive data structure containing mode, balances, borrowing power, and more
getPendingCashback
Gets the pending cashback amount for an account in USD.
Input Parameters:
account
address
Address of the account (Safe or spender)
Return Values:
uint256
Pending cashback amount in USD
getData
Retrieves cash configuration data for a Safe.
Input Parameters:
safe
address
Address of the EtherFi Safe
Return Values:
SafeData
Data structure containing Safe cash configuration
Events
The CashModule emits events for all major operations through the CashEventEmitter:
WithdrawalRequested
Emitted when a withdrawal is requested.
WithdrawalProcessed
Emitted when a withdrawal is processed.
Spend
Emitted when tokens are spent from a Safe.
Cashback
Emitted when cashback is calculated and potentially distributed.
ReferrerCashback
Emitted when referral cashback is calculated and potentially distributed.
ModeSet
Emitted when the operational mode of a Safe is changed.
SpendingLimitChanged
Emitted when a spending limit is changed.
Last updated