# Base

### StakingPoolBase

#### **`receiveTokenWalletAddress`**

Store vault's token wallet address.\
Only root can call with correct params.

```
function receiveTokenWalletAddress(address wallet) external
```

**Parameters:**

| Name   | Type    | Description          |
| ------ | ------- | -------------------- |
| wallet | address | Token wallet address |

#### **`startNewRewardRound`**

Checks whether there are any rounds if so, sets last round to previous, updates pool about it, adds new round to the list and transfers remaining gas to the address from params.

```
function startNewRewardRound(address send_gas_to) external onlyRewarder
```

**Parameters:**

| Name      | Type    | Description                     |
| --------- | ------- | ------------------------------- |
| sendGasTo | address | Address where to send spent gas |
|           |         | spent gas                       |

**Events emitted:**

* NewRewardRound

#### **`onAcceptTokensTransfer`**

Deposit occurs here.

```
function onAcceptTokensTransfer(
        address tokenRoot,
        uint128 amount,
        address sender,
        address senderWallet,
        address remainingGasTo,
        TvmCell payload
    ) external override
```

**Parameters:**

| Name           | Type    | Description                                         |
| -------------- | ------- | --------------------------------------------------- |
| tokenRoot      | address | Token root address                                  |
| amount         | uint128 | Amount of tokens in transfer                        |
| sender         | address | Address of the sender                               |
| senderWallet   | address | Wallet address of the sender                        |
| remainingGasTo | address | Address where the remaining gas will be transferred |
| payload        | TvmCell | Deposit payload data encoded to Cell                |

**Events emitted:**

* RewardDeposit

#### **`revertDeposit`**

Reverts the action of depositing.

```
function revertDeposit(uint64 _deposit_nonce) external override
```

**Parameters:**

| Name             | Type   | Description                                |
| ---------------- | ------ | ------------------------------------------ |
| \_deposit\_nonce | uint64 | Id of the deposit which should be reverted |

**Events emitted:**

* DepositReverted

#### **`finishDeposit`**

Finishes the depositing with incrementing token balance for deposit amount.

```
function finishDeposit(uint64 _deposit_nonce) external override
```

**Parameters:**

| Name             | Type   | Description                                 |
| ---------------- | ------ | ------------------------------------------- |
| \_deposit\_nonce | uint64 | Id of the deposit which should be finalized |

**Events emitted:**

* Deposit

#### **`withdraw`**

Withdraw action

```
function withdraw(uint128 amount, address send_gas_to) public onlyActive
```

**Parameters:**

| Name      | Type    | Description                         |
| --------- | ------- | ----------------------------------- |
| amount    | uint128 | Amount to withdraw                  |
| sendGasTo | address | Address where to send remaining gas |

#### **`finishWithdraw`**

Finishes the withdrawal with decrementing token balance for deposit amount.

```
function finishWithdraw(
        address user,
        uint128 withdraw_amount,
        address send_gas_to
    ) public override onlyUserData(user)
```

**Parameters:**

| Name             | Type    | Description                         |
| ---------------- | ------- | ----------------------------------- |
| user             | address | User address who initiates withdraw |
| withdraw\_amount | uint128 | Amount to withdraw                  |
| sendGasTo        | address | Address where to send remaining gas |

**Events emitted:**

* Withdraw

#### **`claimReward`**

Claiming reward for user.

```
function claimReward(address send_gas_to) external onlyActive
```

**Parameters:**

| Name      | Type    | Description                         |
| --------- | ------- | ----------------------------------- |
| sendGasTo | address | Address where to send remaining gas |

#### **`finishClaimReward`**

Finishes the reward claiming with incrementing user token reward and decrementing reward token balance

```
function finishClaimReward(address user, uint128[] rewards, address send_gas_to) external override onlyUserData(user)
```

**Parameters:**

| Name      | Type       | Description                              |
| --------- | ---------- | ---------------------------------------- |
| user      | address    | Address of the user that claims a reward |
| rewards   | uint128\[] | List of rewards                          |
| sendGasTo | address    | Address where to send remaining gas      |

**Events emitted:**

* RewardClaimed

#### **`pendingReward`**

Synchronizes rewards, updates pool info if not empty, gets rewards for old user rounds, synchronizes new user rounds, calculates user reward tokens and returns them.

```
function pendingReward(uint256 user_token_balance, IUserData.RewardRoundData[] user_reward_data) external view responsible returns (uint256)
```

**Parameters:**

| Name                 | Type                         | Description                     |
| -------------------- | ---------------------------- | ------------------------------- |
| user\_token\_balance | uint256                      | Balance of user’s tokens        |
| user\_reward\_data   | IUserData.RewardRoundData\[] | List of all synced user rewards |

**Returns value:**

| Type    | Description                         |
| ------- | ----------------------------------- |
| address | Address where to send remaining gas |

updatePoolInfo Updates pool information about last reward time and total reward

function updatePoolInfo() internal

#### **`deployUserData`**

Deploys Platform contract with the user data

```
function deployUserData(address user_data_owner) internal returns (address)
```

**Parameters:**

| Name              | Type    | Description                          |
| ----------------- | ------- | ------------------------------------ |
| user\_data\_owner | address | Address of the deployer of user data |

**Returns value:**

| Type    | Description                               |
| ------- | ----------------------------------------- |
| address | Address of the deployed UserData contract |

#### **`castVoteWithReason`**

Casts user's vote.

```
function castVote(uint32 proposal_id, bool support) public view override
```

**Parameters:**

| Name         | Type   | Description                               |
| ------------ | ------ | ----------------------------------------- |
| proposal\_id | uint32 | Id of the proposal                        |
| support      | bool   | True if voted for, false if voted against |

#### **`castVoteWithReason`**

Casts user's vote with specified reason

```
function castVoteWithReason(
        uint32 proposal_id,
        bool support,
        string reason
    ) public view override
```

**Parameters:**

| Name         | Type   | Description                               |
| ------------ | ------ | ----------------------------------------- |
| proposal\_id | uint32 | Id of the proposal                        |
| support      | bool   | True if voted for, false if voted against |
| reason       | string | Reason for voting                         |

#### **`withdrawTonsUserEmergency`**

User withdraws tons in case of emergency

```
function withdrawTonsUserEmergency() external
```

#### **`withdrawTonsEmergency`**

Checks all the necessary requirements regarding the balance and amount, and does the transfer to the receiver address

```
function withdrawTonsEmergency(uint128 amount, address receiver, bool all, address send_gas_to) external onlyRescuer
```

**Parameters:**

| Name      | Type    | Description                                        |
| --------- | ------- | -------------------------------------------------- |
| amount    | uint128 | Amount of tons to withdraw                         |
| receiver  | address | Receiver address where tons will be sent           |
| all       | bool    | True if all tons should be withdrawn, false if not |
| sendGasTo | address | Address where to send remaining gas                |

#### **`withdrawTokensEmergency`**

Tokens withdraw in case of emergency.

```
function withdrawTokensEmergency(uint128 amount, address receiver, bool all, address send_gas_to) external onlyRescuer
```

**Parameters:**

| Name      | Type    | Description                                          |
| --------- | ------- | ---------------------------------------------------- |
| amount    | uint128 | Amount of tokens to withdraw                         |
| receiver  | address | Receiver address where tokens will be sent           |
| all       | bool    | True if all tokens should be withdrawn, false if not |
| sendGasTo | address | Address where to send spent gas                      |

### StakingPoolRelay

#### **`linkRelayAccounts`**

Gets user data and processes linking of relayer eth and ton accounts.

```
function linkRelayAccounts(uint256 ton_pubkey, uint160 eth_address) external view onlyActive
```

**Parameters:**

| Name         | Type    | Description                     |
| ------------ | ------- | ------------------------------- |
| ton\_pubkey  | uint256 | Public key of the ton account   |
| eth\_address | uint160 | Address of the ethereum account |

#### **`onEventConfirmed`**

Confirms transaction from everscale to ethereum.

```
function onEventConfirmed(
        IEthereumEvent.EthereumEventInitData eventData,
        address gasBackAddress
    ) external override onlyEthTonConfig
```

**Parameters:**

| Name           | Type                                 | Description                         |
| -------------- | ------------------------------------ | ----------------------------------- |
| eventData      | IEthereumEvent.EthereumEventInitData | EthereumEvent data                  |
| gasBackAddress | address                              | Address where to send remaining gas |

#### **`confirmEthAccount`**

Processes confirmation of ethereum account.

```
function confirmEthAccount(address staker_addr, uint160 eth_address, address send_gas_to) internal
```

**Parameters:**

| Name         | Type    | Description                         |
| ------------ | ------- | ----------------------------------- |
| staker\_addr | address | Address of the staker               |
| eth\_address | uint160 | Ethereum account address            |
| sendGasTo    | address | Address where to send remaining gas |

#### **`slashRelay`**

Slashes specified relayer.

```
function slashRelay(address relay_staker_addr, address send_gas_to) external onlyDaoRoot
```

**Parameters:**

| Name                | Type    | Description                                  |
| ------------------- | ------- | -------------------------------------------- |
| relay\_staker\_addr | address | Address of the relayer which will be slashed |
| sendGasTo           | address | Address where to send remaining gas          |

#### **`_syncUserRewardData`**

Calculates user's reward based on params.

```
function _syncUserRewardData(
        uint128[] user_rewards,
        uint128[] user_debts,
        uint128 ban_token_balance
    ) private view returns (uint128[])
```

**Parameters:**

| Name                | Type       | Description                                                     |
| ------------------- | ---------- | --------------------------------------------------------------- |
| user\_rewards       | uint128\[] | List of all user rewards                                        |
| user\_debts         | uint128\[] | List of all user debts                                          |
| ban\_token\_balance | uint128    | Used for calculating new user reward that is not already synced |

**Returns value:**

| Type       | Description              |
| ---------- | ------------------------ |
| uint128\[] | Synced user rewards list |

#### **`confirmSlash`**

Confirms slashing by burning gas of slashed user and recalculates round's balance.

function confirmSlash( address user, uint128\[] user\_rewards, uint128\[] user\_debts, uint128 ban\_token\_balance, address send\_gas\_to ) external override onlyUserData(user)

**Parameters:**

| Name                | Type       | Description                         |
| ------------------- | ---------- | ----------------------------------- |
| user                | address    | Address of the slashed user         |
| user\_rewards       | uint128\[] | Rewards list of the slashed user    |
| user\_debts         | uint128\[] | Debts list of the slashed user      |
| ban\_token\_balance | uint128    | Balance of banned tokens            |
| sendGasTo           | address    | Address where to send remaining gas |

**Events emitted:**

* RelaySlashed

#### **`createOriginRelayRound`**

Creates and deploys new relayer round and sets relayers for that round.

```
function createOriginRelayRound(
        address[] staker_addrs,
        uint256[] ton_pubkeys,
        uint160[] eth_addrs,
        uint128[] staked_tokens,
        uint128 ton_deposit,
        address send_gas_to
    ) external onlyAdmin
```

**Parameters:**

| Name           | Type       | Description                         |
| -------------- | ---------- | ----------------------------------- |
| staker\_addrs  | address\[] | List of stakers in the round        |
| ton\_pubkeys   | uint256\[] | List of ton accounts’ public keys   |
| eth\_addrs     | uint160\[] | List of ethereum’s accounts         |
| staked\_tokens | uint128\[] | List of staked tokens               |
| ton\_deposit   | uint128    | Amount of tons deposited            |
| sendGasTo      | address    | Address where to send remaining gas |
|                |            | remaining gas                       |

#### **`processBecomeRelayNextRound`**

Processes new relayers for the next relayer round.

```
function processBecomeRelayNextRound(address user) external view override onlyActive onlyUserData(user)
```

**Parameters:**

| Name | Type    | Description                                                           |
| ---- | ------- | --------------------------------------------------------------------- |
| user | address | Address of the user that will be processed for a next round’s relayer |

#### **`processGetRewardForRelayRound`**

Processes rewards for current relayer round.

```
function processGetRewardForRelayRound(address user, uint32 round_num) external override onlyActive onlyUserData(user)
```

**Parameters:**

| Name       | Type    | Description                                      |
| ---------- | ------- | ------------------------------------------------ |
| user       | address | Address of the user that should get a reward     |
| round\_num | uint32  | Number of the round for which he will be awarded |

#### **`startElectionOnNewRound`**

Deploys election for a new round.

```
function startElectionOnNewRound() external onlyActive
```

#### **`endElection`**

Based on election's address finishes the current election.

```
function endElection() external onlyActive
```

#### **`onElectionStarted`**

Sets start time of the election.

```
function onElectionStarted(uint32 round_num) external override onlyElection(round_num)
```

**Parameters:**

| Name       | Type   | Description                                |
| ---------- | ------ | ------------------------------------------ |
| round\_num | uint32 | Round number in which election has started |

**Events emitted:**

* ElectionStarted

#### **`onElectionEnded`**

Sets round details and deploys new relayer round.

```
function onElectionEnded(
        uint32 round_num,
        uint32 relay_requests_count
    ) external override onlyElection(round_num)
```

**Parameters:**

| Name                   | Type   | Description                                                                                             |
| ---------------------- | ------ | ------------------------------------------------------------------------------------------------------- |
| round\_num             | uint32 | Round number in which election has ended                                                                |
| relay\_requests\_count | uint32 | Number of relayer’s requests (used to check whether there were enough of them for election to be valid) |

**Events emitted:**

* ElectionEnded

#### **`_relaysPacksCount`**

Returns number of relayer packs.

```
function _relaysPacksCount() private view returns (uint8)
```

**Return value:**

| Type  | Description              |
| ----- | ------------------------ |
| uint8 | Number of relayers packs |

#### **`onRelayRoundDeployed`**

Sends relayers to relayer round.

```
function onRelayRoundDeployed(
        uint32 round_num,
        bool duplicate
    ) external override onlyRelayRound(round_num)
```

**Parameters:**

| Name       | Type   | Description               |
| ---------- | ------ | ------------------------- |
| round\_num | uint32 | Round number              |
| duplicate  | bool   | True if yes, false if not |

#### **`onRelayRoundInitialized`**

Sets round details, deploys new event and destroys previous round.

```
function onRelayRoundInitialized(
        uint32 round_num,
        uint32 round_start_time,
        uint32 round_end_time,
        uint32 relays_count,
        uint128 round_reward,
        uint32 reward_round_num,
        bool duplicate,
        uint160[] eth_keys
    ) external override onlyRelayRound(round_num)
```

**Parameters:**

| Name               | Type       | Description                                                         |
| ------------------ | ---------- | ------------------------------------------------------------------- |
| round\_num         | uint32     | Round number                                                        |
| round\_start\_time | uint32     | Time when the round will start                                      |
| round\_end\_time   | uint32     | End of the round                                                    |
| relays\_count      | uint32     | Number of relayers                                                  |
| round\_reward      | uint128    | Reward for the round                                                |
| reward\_round\_num | uint32     | Number of reward round (index for base\_details.rewardRounds array) |
|                    |            | (index for base\_details.rewardRounds array)                        |
| duplicate          | bool       | True if yes, false if not                                           |
| eth\_keys          | uint160\[] | List of ethereum accounts                                           |

**Events emitted:**

* RelayRoundInitialized

#### **`deployElection`**

Creates new platform for the new election.

```
function deployElection(uint32 round_num) private returns (address)
```

**Parameters:**

| Name       | Type   | Description  |
| ---------- | ------ | ------------ |
| round\_num | uint32 | Round number |

**Return value:**

| Type    | Description               |
| ------- | ------------------------- |
| address | Deployed election address |

#### **`deployRelayRound`**

Creates platform for the new relayer round.

```
function deployRelayRound(
        uint32 round_num,
        uint32 start_time,
        uint32 end_time,
        bool duplicate,
        uint8 packs_num,
        address election_addr,
        address prev_relay_round_addr,
        uint16 msg_flag
    ) private returns (address)
```

**Parameters:**

| Name                     | Type    | Description                                    |
| ------------------------ | ------- | ---------------------------------------------- |
| round\_num               | uint32  | Round number                                   |
| start\_time              | uint32  | Round start time                               |
| end\_time                | uint32  | Round end time                                 |
| duplicate                | bool    | True if yes, false if not                      |
| packs\_num               | uint8   | Number of relayer packs                        |
| election\_addr           | address | Address of the election                        |
| prev\_relay\_round\_addr | address | Previous relayer round address                 |
| msg\_flag                | uint16  | Flag used for building new RelayRound platform |

**Return value:**

| Type    | Description                       |
| ------- | --------------------------------- |
| address | Address of deployed relayer round |

### StakingUpgradable

#### **`installPlatformOnce`**

Installs updated platform.

```
function installPlatformOnce(TvmCell code, address send_gas_to) external onlyAdmin
```

**Parameters:**

| Name      | Type    | Description                         |
| --------- | ------- | ----------------------------------- |
| code      | TvmCell | Platform code encoded to cell       |
| sendGasTo | address | Address where to send remaining gas |

#### **`installOrUpdateUserDataCode`**

Upgrades user data version.

```
function installOrUpdateUserDataCode(TvmCell code, address send_gas_to) external onlyAdmin
```

**Parameters:**

| Name      | Type    | Description                         |
| --------- | ------- | ----------------------------------- |
| code      | TvmCell | User data code in cell format       |
| sendGasTo | address | Address where to send remaining gas |

**Events emitted:**

* UserDataCodeUpgraded

#### **`installOrUpdateElectionCode`**

Upgrades election version.

```
function installOrUpdateElectionCode(TvmCell code, address send_gas_to) external onlyAdmin
```

**Parameters:**

| Name      | Type    | Description                         |
| --------- | ------- | ----------------------------------- |
| code      | TvmCell | Election code in cell format        |
| sendGasTo | address | Address where to send remaining gas |

**Events emitted:**

* ElectionCodeUpgraded

#### **`installOrUpdateRelayRoundCode`**

Upgrades relayer round version.

```
function installOrUpdateRelayRoundCode(TvmCell code, address send_gas_to) external onlyAdmin
```

**Parameters:**

| Name      | Type    | Description                         |
| --------- | ------- | ----------------------------------- |
| code      | TvmCell | relayer round code in cell format   |
| sendGasTo | address | Address where to send remaining gas |

**Events emitted:**

* RelayRoundCodeUpgraded

#### *`upgradeUserData`*\*

Upgrades user data.

```
function upgradeUserData(address send_gas_to) external view onlyActive
```

**Parameters:**

| Name      | Type    | Description                         |
| --------- | ------- | ----------------------------------- |
| sendGasTo | address | Address where to send remaining gas |

#### **`forceUpgradeUserData`**

Upgrades user data.

```
function forceUpgradeUserData(
        address user,
        address send_gas_to
    ) external view onlyAdmin
```

**Parameters:**

| Name      | Type    | Description                         |
| --------- | ------- | ----------------------------------- |
| user      | address | User address                        |
| sendGasTo | address | Address where to send remaining gas |

#### **`_upgradeUserData`**

Upgrades user data code and version by request.

```
function _upgradeUserData(address user, uint128 gas_value, address send_gas_to) internal view
```

**Parameters:**

| Name       | Type    | Description                         |
| ---------- | ------- | ----------------------------------- |
| user       | address | User address                        |
| gas\_value | uint128 | Gas value spent for upgrade         |
| sendGasTo  | address | Address where to send remaining gas |

**Events emitted:**

* RequestedUserDataUpgrade

#### **`upgradeElection`**

Upgrades election code and version by request.

```
function upgradeElection(
        uint32 round_num,
        address send_gas_to
    ) external view onlyAdmin
```

**Parameters:**

| Name       | Type    | Description                         |
| ---------- | ------- | ----------------------------------- |
| round\_num | uint32  | Round number                        |
| sendGasTo  | address | Address where to send remaining gas |

**Events emitted:**

* RequestedElectionUpgrade

#### **`upgradeRelayRound`**

Upgrades relayer round code and version by request.

```
function upgradeRelayRound(
        uint32 round_num,
        address send_gas_to
    ) external view onlyAdmin
```

**Parameters:**

| Name       | Type    | Description                         |
| ---------- | ------- | ----------------------------------- |
| round\_num | uint32  | Round number                        |
| sendGasTo  | address | Address where to send remaining gas |

**Events emitted:**

* RequestedRelayRoundUpgrade

#### **`_buildElectionParams`**

Returns election params in cell format based on the round number.

```
function _buildElectionParams(uint32 round_num) internal inline view returns (TvmCell)
```

**Parameters:**

| Name       | Type   | Description  |
| ---------- | ------ | ------------ |
| round\_num | uint32 | Round number |

**Return value:**

| Type    | Description                              |
| ------- | ---------------------------------------- |
| TvmCell | Election parameters data encoded to cell |

#### **`_buildRelayRoundParams`**

Returns relayer round params in cell format based on the round number.

```
function _buildRelayRoundParams(uint32 round_num) internal inline view returns (TvmCell)
```

**Parameters:**

| Name       | Type   | Description  |
| ---------- | ------ | ------------ |
| round\_num | uint32 | Round number |

| Type    | Description                          |
| ------- | ------------------------------------ |
| TvmCell | Relayer round params encoded to cell |


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.octusbridge.io/integrate/octus-bridge-contracts/everscale/staking-section/base.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
