stakingBaseProcess
Function Type: internal
The stakingBaseProcess function implements the core staking logic that handles both service and user staking operations. It processes payments, updates history, handles time locks, and manages EVVM integration for all staking types.
Parameters
| Parameter | Type | Description |
|---|---|---|
account | AccountMetadata | Metadata of the account performing the staking operation |
isStaking | bool | true = Stake (requires payment), false = Unstake (provides refund) |
amountOfStaking | uint256 | Amount of staking tokens to stake/unstake |
priorityFee_EVVM | uint256 | Priority fee for EVVM transaction |
nonce_EVVM | uint256 | Nonce for EVVM contract transaction |
priorityFlag_EVVM | bool | true = async EVVM transaction, false = sync |
signature_EVVM | bytes | Signature for EVVM contract transaction |
AccountMetadata Structure
The account parameter uses the following struct:
struct AccountMetadata {
address Address; // Address of the account
bool IsAService; // Boolean indicating if the account is a smart contract (service) account
}
Workflow
The function processes two distinct operation types with different validation and execution flows:
- Staking Operations: Payment processing, cooldown validation, and stake assignment
- Unstaking Operations: Conditional payments, token refunds, and stake removal
Staking Process
- Re-Staking Cooldown Check: Verifies
getTimeToUserUnlockStakingTime(account.Address) <= block.timestamp, reverts withAddressMustWaitToStakeAgain()if cooldown period hasn't elapsed - Payment Processing:
- For Users (!account.IsAService): Calls
makePay(account.Address, PRICE_OF_STAKING * amountOfStaking, priorityFee_EVVM, priorityFlag_EVVM, nonce_EVVM, signature_EVVM) - For Services (account.IsAService): Skips payment processing (already handled in preparation phase)
- For Users (!account.IsAService): Calls
- Staker Status Assignment: Sets
Evvm(EVVM_ADDRESS).pointStaker(account.Address, 0x01)to mark as active staker - Balance Calculation: Calculates new total stake:
- First time staking:
auxSMsteBalance = amountOfStaking - Additional staking:
auxSMsteBalance = lastTotalStaked + amountOfStaking
- First time staking:
- History Update: Pushes
HistoryMetadatawith transaction typebytes32(uint256(1)), amount, timestamp, and total staked - Executor Rewards: If
msg.senderis a staker and!account.IsAService, pays(getRewardAmount() * 2) + priorityFee_EVVMviamakeCaPay()
Unstaking Process
- Full Unstaking Validation: If
amountOfStaking == getUserAmountStaked(account.Address)(complete unstaking):- Cooldown Check: Verifies
getTimeToUserUnlockFullUnstakingTime(account.Address) <= block.timestamp, reverts withAddressMustWaitToFullUnstake()if cooldown not met - Status Removal: Sets
Evvm(EVVM_ADDRESS).pointStaker(account.Address, 0x00)to remove staker status
- Cooldown Check: Verifies
- Optional Priority Payment: If
priorityFee_EVVM != 0 && !account.IsAService(user unstaking with priority fee):- Priority Fee Payment: Calls
makePay(account.Address, priorityFee_EVVM, 0, priorityFlag_EVVM, nonce_EVVM, signature_EVVM)
- Priority Fee Payment: Calls
- Balance Calculation:
auxSMsteBalance = lastTotalStaked - amountOfStaking - Token Refund: Calls
makeCaPay(PRINCIPAL_TOKEN_ADDRESS, account.Address, PRICE_OF_STAKING * amountOfStaking)to return tokens - History Update: Pushes
HistoryMetadatawith transaction typebytes32(uint256(2)), amount, timestamp, and remaining total staked - Executor Rewards: If
msg.senderis a staker and!account.IsAService, pays(getRewardAmount() * 2) + priorityFee_EVVMviamakeCaPay()
info
For detailed information about the helper functions, refer to:
- makePay - Handles EVVM payment processing
- makeCaPay - Handles token distributions
- Getter Functions - Time lock and balance functions