Skip to content
Verified contractPartialBUSL-1.1

AdvancedStakeV2ActionMsgTranslator

Address0xb6bccfae4d48477525db42b5f75f0d763dcfef03
Balance

0 ETH

 

Transactions

1

 

Compiler

solc 0.8.16

 

Same code

1 more contract

 

Details

Compiler
solc 0.8.16+commit.07a7930e
Language
solidity
Optimization
Yes, 800 runs
EVM version
london
License
BUSL-1.1
Match
Partialcreation code: yes, runtime code: yes
Verified on Sourcify
Created in block
17,045,747
Creation transaction
0x573dd65e8a…ccb59687c9

contracts/staking/AdvancedStakeV2ActionMsgTranslator.sol

// SPDX-License-Identifier: BUSL-1.1
// SPDX-FileCopyrightText: Copyright 2023 Panther Ventures Limited Gibraltar
pragma solidity 0.8.16;

import "./interfaces/IRewardAdviser.sol";
import "./interfaces/IActionMsgReceiver.sol";
import { ADVANCED_STAKE, ADVANCED_STAKE_V2, ADVANCED_UNSTAKE_V2 } from "./actions/Constants.sol";

/**
 * @title AdvancedStakeV2ActionMsgTranslator
 * @notice It processes action messages for stakes of the `advanced-v2` type.
 * @dev It "translates" the `action` in messages so that other contracts may
 * process `advanced-v2` type stakes exactly like `advanced` type stakes.
 * It shall run on the Polygon (or Mumbai) network and be registered with the
 * `RewardMaster` as the "RewardAdviser" for `advanced-v2` type stakes and the
 * "ActionOracle" for `advanced` type stakes.
 * Being called `getRewardAdvice` by the RewardMaster for a message with the
 * `advanced-v2` STAKE action, it replaces the `action` to be the `advanced`
 * (but not `advanced-v2`) STAKE action.
 * Then it calls `onAction` on the RewardMaster with the substituted message.
 * When called back, the latter processes the substituted action message as if
 * it is the `advanced` (not `advanced-v2`) STAKE action, passing the message
 * to the `AdvancedStakeRewardController` (that rewards `advanced`, but not
 * `advanced-v2`, stakes).
 */
contract AdvancedStakeV2ActionMsgTranslator is IRewardAdviser {
    // solhint-disable var-name-mixedcase

    /// @notice RewardMaster contract instance
    address private immutable REWARD_MASTER;

    // solhint-enable var-name-mixedcase

    constructor(address rewardMaster) {
        require(rewardMaster != address(0), "Zero address");

        REWARD_MASTER = rewardMaster;
    }

    /// @dev To be called by the {RewardMaster} on `advanced-v2` type stakes actions.
    /// It changes the action to `advanced` stake type one and passes it back to the {RewardMaster}.
    function getRewardAdvice(
        bytes4 action,
        bytes memory message
    ) external override returns (Advice memory) {
        require(msg.sender == REWARD_MASTER, "AMT: unauthorized");

        if (action == ADVANCED_STAKE_V2) {
            // Replace the action and return the message back to REWARD_MASTER
            IActionMsgReceiver(REWARD_MASTER).onAction(ADVANCED_STAKE, message);
        } else {
            require(action == ADVANCED_UNSTAKE_V2, "AMT: unsupported action");
        }

        // Return "zero" advice
        return
            Advice(
                address(0), // createSharesFor
                0, // sharesToCreate
                address(0), // redeemSharesFrom
                0, // sharesToRedeem
                address(0) // sendRewardTo
            );
    }
}

contracts/staking/actions/Constants.sol

// SPDX-License-Identifier: BUSL-1.1
// SPDX-FileCopyrightText: Copyright 2021-22 Panther Ventures Limited Gibraltar
// slither-disable-next-line solc-version
pragma solidity ^0.8.4;

// solhint-disable var-name-mixedcase

// The "stake type" for the "classic staking"
// bytes4(keccak256("classic"))
bytes4 constant CLASSIC_STAKE_TYPE = 0x4ab0941a;

// STAKE "action type" for the "classic staking"
// bytes4(keccak256(abi.encodePacked(bytes4(keccak256("stake"), CLASSIC_STAKE_TYPE)))
bytes4 constant CLASSIC_STAKE = 0x1e4d02b5;

// UNSTAKE "action type" for the "classic staking"
// bytes4(keccak256(abi.encodePacked(bytes4(keccak256("unstake"), CLASSIC_STAKE_TYPE)))
bytes4 constant CLASSIC_UNSTAKE = 0x493bdf45;

// The "stake type" for the "advance staking"
// bytes4(keccak256("advanced"))
bytes4 constant ADVANCED_STAKE_TYPE = 0x7ec13a06;

// STAKE "action type" for the "advanced staking"
// bytes4(keccak256(abi.encodePacked(bytes4(keccak256("stake"), ADVANCED_STAKE_TYPE)))
bytes4 constant ADVANCED_STAKE = 0xcc995ce8;

// UNSTAKE "action type" for the "advanced staking"
// bytes4(keccak256(abi.encodePacked(bytes4(keccak256("unstake"), ADVANCED_STAKE_TYPE)))
bytes4 constant ADVANCED_UNSTAKE = 0xb8372e55;

// The "stake type" for the "advance staking"
// bytes4(keccak256("advanced-v2"))
bytes4 constant ADVANCED_STAKE_V2_TYPE = 0x8496de05;

// STAKE "action type" for the "advanced staking V2"
// bytes4(keccak256(abi.encodePacked(bytes4(keccak256("stake"), ADVANCED_STAKE_V2_TYPE)))
bytes4 constant ADVANCED_STAKE_V2 = 0x1954e321;

// UNSTAKE "action type" for the "advanced staking v2"
// bytes4(keccak256(abi.encodePacked(bytes4(keccak256("unstake"), ADVANCED_STAKE_V2_TYPE)))
bytes4 constant ADVANCED_UNSTAKE_V2 = 0x6a8ecb81;

// PRP grant type for the "advanced" stake
// bytes4(keccak256("forAdvancedStakeGrant"))
bytes4 constant FOR_ADVANCED_STAKE_GRANT = 0x31a180d4;

// solhint-enable var-name-mixedcase

contracts/staking/interfaces/IActionMsgReceiver.sol

// SPDX-License-Identifier: MIT
// slither-disable-next-line solc-version
pragma solidity ^0.8.4;

interface IActionMsgReceiver {
    function onAction(bytes4 action, bytes memory message) external;
}

contracts/staking/interfaces/IRewardAdviser.sol

// SPDX-License-Identifier: MIT
// slither-disable-next-line solc-version
pragma solidity ^0.8.4;

interface IRewardAdviser {
    struct Advice {
        // advice on new "shares" (in the reward pool) to create
        address createSharesFor;
        uint96 sharesToCreate;
        // advice on "shares" to redeem
        address redeemSharesFrom;
        uint96 sharesToRedeem;
        // advice on address the reward against redeemed shares to send to
        address sendRewardTo;
    }

    function getRewardAdvice(bytes4 action, bytes memory message)
        external
        returns (Advice memory);
}
Compiler settingsShow
{
  "metadata": {
    "bytecodeHash": "none",
    "useLiteralContent": true
  },
  "libraries": {},
  "optimizer": {
    "runs": 800,
    "enabled": true
  },
  "evmVersion": "london",
  "remappings": []
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.