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 |
---|---|---|
userAccount | address | Address of the user paying for the transaction |
stakingAccount | address | Address that will receive the stake/unstake (can be same as userAccount) |
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 |
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(stakingAccount) <= block.timestamp
, reverts withUserMustWaitToStakeAgain()
if cooldown period hasn't elapsed - Payment Processing: Calls
makePay(userAccount, PRICE_OF_STAKING * amountOfStaking, priorityFee_EVVM, priorityFlag_EVVM, nonce_EVVM, signature_EVVM)
to process payment through EVVM - Staker Status Assignment: Sets
Evvm(EVVM_ADDRESS).pointStaker(stakingAccount, 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
HistoryMetadata
with transaction typebytes32(uint256(1))
, amount, timestamp, and total staked - Executor Rewards: If
msg.sender
is a staker, pays(getRewardAmount() * 2) + priorityFee_EVVM
viamakeCaPay()
Unstaking Process
- Full Unstaking Validation: If
amountOfStaking == getUserAmountStaked(stakingAccount)
(complete unstaking):- Cooldown Check: Verifies
getTimeToUserUnlockFullUnstakingTime(stakingAccount) <= block.timestamp
, reverts withUserMustWaitToFullUnstake()
if cooldown not met - Status Removal: Sets
Evvm(EVVM_ADDRESS).pointStaker(stakingAccount, 0x00)
to remove staker status
- Cooldown Check: Verifies
- Optional Priority Payment: If
userAccount == stakingAccount && priorityFee_EVVM != 0
(user unstaking with priority fee):- Priority Fee Payment: Calls
makePay(userAccount, 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, stakingAccount, PRICE_OF_STAKING * amountOfStaking)
to return tokens - History Update: Pushes
HistoryMetadata
with transaction typebytes32(uint256(2))
, amount, timestamp, and remaining total staked - Executor Rewards: If
msg.sender
is a staker, pays(getRewardAmount() * 2) + priorityFee_EVVM
viamakeCaPay()
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