View Source: contracts/governance/ApprovalReceiver.sol
↗ Extends: ErrorDecoder, IApproveAndCall ↘ Derived Contracts: FourYearVestingLogic, StakingStakeModule, VestingLogic
modifier onlyThisContract() internal
- receiveApproval(address _sender, uint256 _amount, address _token, bytes _data)
- _getToken()
- _getSelectors()
- _call(bytes _data)
- _getSig(bytes _data)
⤾ overrides IApproveAndCall.receiveApproval
Receives approval from SOV token.
function receiveApproval(address _sender, uint256 _amount, address _token, bytes _data) external nonpayable
Arguments
Name | Type | Description |
---|---|---|
_sender | address | |
_amount | uint256 | |
_token | address | |
_data | bytes | The data will be used for low level call. |
Source Code
function receiveApproval(
address _sender,
uint256 _amount,
address _token,
bytes calldata _data
) external {
// Accepts calls only from SOV token.
require(msg.sender == _getToken(), "unauthorized");
require(msg.sender == _token, "unauthorized");
// Only allowed methods.
bool isAllowed = false;
bytes4[] memory selectors = _getSelectors();
bytes4 sig = _getSig(_data);
for (uint256 i = 0; i < selectors.length; i++) {
if (sig == selectors[i]) {
isAllowed = true;
break;
}
}
require(isAllowed, "method is not allowed");
// Check sender and amount.
address sender;
uint256 amount;
(, sender, amount) = abi.decode(
abi.encodePacked(bytes28(0), _data),
(bytes32, address, uint256)
);
require(sender == _sender, "sender mismatch");
require(amount == _amount, "amount mismatch");
_call(_data);
}
⤿ Overridden Implementation(s): FourYearVestingLogic._getToken,VestingLogic._getToken
Returns token address, only this address can be a sender for receiveApproval.
function _getToken() internal view
returns(address)
Source Code
function _getToken() internal view returns (address) {
return address(0);
}
⤿ Overridden Implementation(s): FourYearVestingLogic._getSelectors,VestingLogic._getSelectors
Returns list of function selectors allowed to be invoked.
function _getSelectors() internal pure
returns(bytes4[])
Source Code
function _getSelectors() internal pure returns (bytes4[] memory) {
return new bytes4[](0);
}
Makes call and reverts w/ enhanced error message.
function _call(bytes _data) internal nonpayable
Arguments
Name | Type | Description |
---|---|---|
_data | bytes | Error message as bytes. |
Source Code
function _call(bytes memory _data) internal {
(bool success, bytes memory returnData) = address(this).call(_data);
if (!success) {
if (returnData.length <= ERROR_MESSAGE_SHIFT) {
revert("receiveApproval: Transaction execution reverted.");
} else {
revert(_addErrorMessage("receiveApproval: ", string(returnData)));
}
}
}
Extracts the called function selector, a hash of the signature.
function _getSig(bytes _data) internal pure
returns(sig bytes4)
Arguments
Name | Type | Description |
---|---|---|
_data | bytes | The msg.data from the low level call. |
Returns
sig First 4 bytes of msg.data i.e. the selector, hash of the signature.
Source Code
function _getSig(bytes memory _data) internal pure returns (bytes4 sig) {
assembly {
sig := mload(add(_data, 32))
}
}
- Address
- Administered
- AdminRole
- AdvancedToken
- AdvancedTokenStorage
- Affiliates
- AffiliatesEvents
- ApprovalReceiver
- BProPriceFeed
- CheckpointsShared
- Constants
- Context
- DevelopmentFund
- DummyContract
- EnumerableAddressSet
- EnumerableBytes32Set
- EnumerableBytes4Set
- ERC20
- ERC20Detailed
- ErrorDecoder
- Escrow
- EscrowReward
- FeedsLike
- FeesEvents
- FeeSharingCollector
- FeeSharingCollectorProxy
- FeeSharingCollectorStorage
- FeesHelper
- FourYearVesting
- FourYearVestingFactory
- FourYearVestingLogic
- FourYearVestingStorage
- GenericTokenSender
- GovernorAlpha
- GovernorVault
- IApproveAndCall
- IChai
- IContractRegistry
- IConverterAMM
- IERC1820Registry
- IERC20_
- IERC20
- IERC777
- IERC777Recipient
- IERC777Sender
- IFeeSharingCollector
- IFourYearVesting
- IFourYearVestingFactory
- IFunctionsList
- ILiquidityMining
- ILiquidityPoolV1Converter
- ILoanPool
- ILoanToken
- ILoanTokenLogicBeacon
- ILoanTokenLogicModules
- ILoanTokenLogicProxy
- ILoanTokenModules
- ILoanTokenWRBTC
- ILockedSOV
- IMoCState
- IModulesProxyRegistry
- Initializable
- InterestUser
- IPot
- IPriceFeeds
- IPriceFeedsExt
- IProtocol
- IRSKOracle
- ISovryn
- ISovrynSwapNetwork
- IStaking
- ISwapsImpl
- ITeamVesting
- ITimelock
- IV1PoolOracle
- IVesting
- IVestingFactory
- IVestingRegistry
- IWrbtc
- IWrbtcERC20
- LenderInterestStruct
- LiquidationHelper
- LiquidityMining
- LiquidityMiningConfigToken
- LiquidityMiningProxy
- LiquidityMiningStorage
- LoanClosingsEvents
- LoanClosingsLiquidation
- LoanClosingsRollover
- LoanClosingsShared
- LoanClosingsWith
- LoanClosingsWithoutInvariantCheck
- LoanInterestStruct
- LoanMaintenance
- LoanMaintenanceEvents
- LoanOpenings
- LoanOpeningsEvents
- LoanParamsStruct
- LoanSettings
- LoanSettingsEvents
- LoanStruct
- LoanToken
- LoanTokenBase
- LoanTokenLogicBeacon
- LoanTokenLogicLM
- LoanTokenLogicProxy
- LoanTokenLogicStandard
- LoanTokenLogicStorage
- LoanTokenLogicWrbtc
- LoanTokenSettingsLowerAdmin
- LockedSOV
- MarginTradeStructHelpers
- Medianizer
- ModuleCommonFunctionalities
- ModulesCommonEvents
- ModulesProxy
- ModulesProxyRegistry
- MultiSigKeyHolders
- MultiSigWallet
- Mutex
- Objects
- OrderStruct
- OrigingVestingCreator
- OriginInvestorsClaim
- Ownable
- Pausable
- PausableOz
- PreviousLoanToken
- PreviousLoanTokenSettingsLowerAdmin
- PriceFeedRSKOracle
- PriceFeeds
- PriceFeedsLocal
- PriceFeedsMoC
- PriceFeedV1PoolOracle
- ProtocolAffiliatesInterface
- ProtocolLike
- ProtocolSettings
- ProtocolSettingsEvents
- ProtocolSettingsLike
- ProtocolSwapExternalInterface
- ProtocolTokenUser
- Proxy
- ProxyOwnable
- ReentrancyGuard
- RewardHelper
- RSKAddrValidator
- SafeERC20
- SafeMath
- SafeMath96
- setGet
- SharedReentrancyGuard
- SignedSafeMath
- SOV
- sovrynProtocol
- StakingAdminModule
- StakingGovernanceModule
- StakingInterface
- StakingProxy
- StakingRewards
- StakingRewardsProxy
- StakingRewardsStorage
- StakingShared
- StakingStakeModule
- StakingStorageModule
- StakingStorageShared
- StakingVestingModule
- StakingWithdrawModule
- State
- SwapsEvents
- SwapsExternal
- SwapsImplLocal
- SwapsImplSovrynSwap
- SwapsUser
- TeamVesting
- Timelock
- TimelockHarness
- TimelockInterface
- TokenSender
- UpgradableProxy
- USDTPriceFeed
- Utils
- VaultController
- Vesting
- VestingCreator
- VestingFactory
- VestingLogic
- VestingRegistry
- VestingRegistry2
- VestingRegistry3
- VestingRegistryLogic
- VestingRegistryProxy
- VestingRegistryStorage
- VestingStorage
- WeightedStakingModule
- WRBTC