Skip to main content

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

ParameterTypeDescription
userAccountaddressAddress of the user paying for the transaction
stakingAccountaddressAddress that will receive the stake/unstake (can be same as userAccount)
isStakingbooltrue = Stake (requires payment), false = Unstake (provides refund)
amountOfStakinguint256Amount of staking tokens to stake/unstake
priorityFee_EVVMuint256Priority fee for EVVM transaction
nonce_EVVMuint256Nonce for EVVM contract transaction
priorityFlag_EVVMbooltrue = async EVVM transaction, false = sync
signature_EVVMbytesSignature 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

  1. Re-Staking Cooldown Check: Verifies getTimeToUserUnlockStakingTime(stakingAccount) <= block.timestamp, reverts with UserMustWaitToStakeAgain() if cooldown period hasn't elapsed
  2. Payment Processing: Calls makePay(userAccount, PRICE_OF_STAKING * amountOfStaking, priorityFee_EVVM, priorityFlag_EVVM, nonce_EVVM, signature_EVVM) to process payment through EVVM
  3. Staker Status Assignment: Sets Evvm(EVVM_ADDRESS).pointStaker(stakingAccount, 0x01) to mark as active staker
  4. Balance Calculation: Calculates new total stake:
    • First time staking: auxSMsteBalance = amountOfStaking
    • Additional staking: auxSMsteBalance = lastTotalStaked + amountOfStaking
  5. History Update: Pushes HistoryMetadata with transaction type bytes32(uint256(1)), amount, timestamp, and total staked
  6. Executor Rewards: If msg.sender is a staker, pays (getRewardAmount() * 2) + priorityFee_EVVM via makeCaPay()

stakingBaseProcess Staking Process - Happy Path stakingBaseProcess Staking Process - Failed Path

Unstaking Process

  1. Full Unstaking Validation: If amountOfStaking == getUserAmountStaked(stakingAccount) (complete unstaking):
    • Cooldown Check: Verifies getTimeToUserUnlockFullUnstakingTime(stakingAccount) <= block.timestamp, reverts with UserMustWaitToFullUnstake() if cooldown not met
    • Status Removal: Sets Evvm(EVVM_ADDRESS).pointStaker(stakingAccount, 0x00) to remove staker status
  2. 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)
  3. Balance Calculation: auxSMsteBalance = lastTotalStaked - amountOfStaking
  4. Token Refund: Calls makeCaPay(PRINCIPAL_TOKEN_ADDRESS, stakingAccount, PRICE_OF_STAKING * amountOfStaking) to return tokens
  5. History Update: Pushes HistoryMetadata with transaction type bytes32(uint256(2)), amount, timestamp, and remaining total staked
  6. Executor Rewards: If msg.sender is a staker, pays (getRewardAmount() * 2) + priorityFee_EVVM via makeCaPay()

stakingBaseProcess Unstaking Process - Happy Path stakingBaseProcess Unstaking Process - Failed Path

info

For detailed information about the helper functions, refer to: