prepareServiceStaking
Function Type: external
Function Signature: prepareServiceStaking(uint256)
Access Control: onlyCA (Contract Accounts Only)
The prepareServiceStaking function is the first step in the service staking process. It records the pre-staking state and prepares the necessary metadata for validation. This function must be followed by payment via EVVM.caPay() and completion via confirmServiceStaking() in the same transaction.
All three steps MUST occur in the same transaction:
- Call
prepareServiceStaking(amount)- Records balances and metadata - Use
EVVM.caPay()to transfer Principal Tokens to the staking contract - Call
confirmServiceStaking()- Validates payment and completes staking
CRITICAL WARNING: If the process is not completed properly (especially if caPay is called but confirmServiceStaking is not), the Principal Tokens will remain locked in the staking contract with no way to recover them. The service will lose the tokens permanently.
Parameters
| Parameter | Type | Description |
|---|---|---|
amountOfStaking | uint256 | Amount of staking tokens the service intends to stake |
Workflow
Preparation Process
- Access Control: Verifies caller is a contract account using
onlyCAmodifier - Metadata Recording: Stores critical pre-staking information:
- Service address (
msg.sender) - Current timestamp
- Intended staking amount
- Service's Principal Token balance before staking
- Staking contract's Principal Token balance before staking
- Service address (
State Changes
The function populates the serviceStakingData struct with:
struct ServiceStakingMetadata {
address service; // Service contract address
uint256 timestamp; // Block timestamp when prepare was called
uint256 amountOfStaking; // Intended staking amount
uint256 amountServiceBeforeStaking; // Service balance before staking
uint256 amountStakingBeforeStaking; // Contract balance before staking
}
Integration Requirements
Following Steps Required
After calling prepareServiceStaking(), the service must:
- Make Payment: Use
EVVM.caPay()to transferamountOfStaking * PRICE_OF_STAKINGPrincipal Tokens to the staking contract - Confirm Staking: Call
confirmServiceStaking()to validate payment and complete the staking process
Access Control
- Only Contract Accounts: Function restricted to smart contracts via
onlyCAmodifier - Same Transaction: All steps must occur in a single transaction
- Balance Validation: Subsequent confirmation validates exact payment amounts
Example Usage
// Step 1: Prepare staking for 5 tokens
stakingContract.prepareServiceStaking(5);
// Step 2: Transfer required Principal Tokens
uint256 cost = 5 * stakingContract.priceOfStaking();
evvmContract.caPay(address(stakingContract), PRINCIPAL_TOKEN_ADDRESS, cost);
// Step 3: Confirm and complete staking
stakingContract.confirmServiceStaking();
This function only records metadata and does not perform any token transfers. The actual payment and staking completion occurs in the subsequent steps.
Failure to complete all three steps in the same transaction will result in permanent loss of Principal Tokens. Always ensure proper transaction atomicity when implementing service staking.