ProtocolApplicationHandler
Inherits: ActionTypesArray, Ownable, RuleAdministratorOnly, IApplicationHandlerEvents, ICommonApplicationHandlerEvents, IInputErrors, IZeroAddressError, IAppHandlerErrors, ProtocolApplicationHandlerCommon
Author: @ShaneDuncan602, @oscarsernarosero, @TJ-Everett
This contract is the rules handler for all application level rules. It is implemented via the AppManager
This contract is injected into the appManagers.
State Variables
VERSION
appManager
appManagerAddress
ruleProcessor
ruleProcessorAddress
accountMaxValueByAccessLevel
Rule mappings
accountMaxValueByRiskScore
accountMaxTxValueByRiskScore
accountMaxValueOutByAccessLevel
accountDenyForNoAccessLevel
pauseRuleActive
Pause Rule on-off switch
erc20Pricer
Pricing Module interfaces
nftPricer
erc20PricingAddress
nftPricingAddress
usdValueTransactedInRiskPeriod
MaxTxSizePerPeriodByRisk data
lastTxDateRiskRule
usdValueTotalWithrawals
Functions
constructor
Initializes the contract setting the AppManager address as the one provided and setting the ruleProcessor for protocol access
Parameters
Name | Type | Description |
---|---|---|
_ruleProcessorProxyAddress | address | of the protocol’s Rule Processor contract. |
_appManagerAddress | address | address of the application AppManager. |
_checkWhichApplicationRulesActive
_checkNonCustodialRules
requireApplicationRulesChecked
checks if any of the Application level rules are active
Parameters
Name | Type | Description |
---|---|---|
_action | ActionTypes | the current action type |
_sender | address |
Returns
Name | Type | Description |
---|---|---|
<none> | bool | true if one or more rules are active |
checkApplicationRules
Check Application Rules for valid transaction.
Parameters
Name | Type | Description |
---|---|---|
_tokenAddress | address | address of the token |
_sender | address | address of the calling account passed through from the token |
_from | address | address of the from account |
_to | address | address of the to account |
_amount | uint256 | amount of tokens to be transferred |
_nftValuationLimit | uint16 | number of tokenID’s per collection before checking collection price vs individual token price |
_tokenId | uint256 | tokenId of the NFT token |
_action | ActionTypes | Action to be checked. This param is intentially added for future enhancements. |
_handlerType | HandlerTypes | the type of handler, used to direct to correct token pricing |
_checkRiskRules
Based on the Handler Type retrieve pricing valuations
This function consolidates all the Risk rule checks.
Parameters
Name | Type | Description |
---|---|---|
_from | address | address of the from account |
_to | address | address of the to account |
_sender | address | address of the caller |
_balanceValuation | uint128 | recepient address current total application valuation in USD with 18 decimals of precision |
_transferValuation | uint128 | valuation of the token being transferred in USD with 18 decimals of precision |
_action | ActionTypes | the current user action |
_checkAccessLevelRules
non custodial buy non custodial sell
This function consolidates all the Access Level rule checks.
Parameters
Name | Type | Description |
---|---|---|
_from | address | address of the from account |
_to | address | address of the to account |
_sender | address | address of the to caller |
_balanceValuation | uint128 | recepient address current total application valuation in USD with 18 decimals of precision |
_transferValuation | uint128 | valuation of the token being transferred in USD with 18 decimals of precision |
_action | ActionTypes | the current user action |
_checkAccountMaxTxValueByRiskScore
Non custodial buy Non custodial sell
This function consolidates the MaxTXValueByRiskScore rule checks for the from address.
Parameters
Name | Type | Description |
---|---|---|
_action | ActionTypes | the current user action |
_address | address | address of the account |
_riskScoreFrom | uint8 | sender address risk score |
_transferValuation | uint128 | valuation of the token being transferred in USD with 18 decimals of precision |
setNFTPricingAddress
-------------- Pricing Module Configurations ---------------
Sets the address of the nft pricing contract and loads the contract.
Parameters
Name | Type | Description |
---|---|---|
_address | address | Nft Pricing Contract address. |
setERC20PricingAddress
Sets the address of the erc20 pricing contract and loads the contract.
Parameters
Name | Type | Description |
---|---|---|
_address | address | ERC20 Pricing Contract address. |
getAccTotalValuation
This gets the account’s balance in dollars.
Get the account’s balance in dollars. It uses the registered tokens in the app manager.
Parameters
Name | Type | Description |
---|---|---|
_account | address | address to get the balance for |
_nftValuationLimit | uint256 |
Returns
Name | Type | Description |
---|---|---|
totalValuation | uint256 | of the account in dollars |
_getERC20Price
check if _account is zero address. If zero address we return a valuation of zero to allow for burning tokens when rules that need valuations are active. Loop through all Nfts and ERC20s and add values to balance for account valuation Check to see if user owns the asset
This gets the token’s value in dollars.
Get the value for a specific ERC20. This is done by interacting with the pricing module
Parameters
Name | Type | Description |
---|---|---|
_tokenAddress | address | the address of the token |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | price the price of 1 in dollars |
_getNFTValuePerCollection
This gets the token’s value in dollars.
Get the value for a specific ERC721. This is done by interacting with the pricing module
Parameters
Name | Type | Description |
---|---|---|
_tokenAddress | address | the address of the token |
_account | address | of the token holder |
_tokenAmount | uint256 | amount of NFTs from _tokenAddress contract |
Returns
Name | Type | Description |
---|---|---|
totalValueInThisContract | uint256 | in whole USD |
_getNFTCollectionValue
This function gets the total token value in dollars of all tokens owned in each collection by address.
Get the total value for all tokens held by a wallet for a specific collection. This is done by interacting with the pricing module
Parameters
Name | Type | Description |
---|---|---|
_tokenAddress | address | the address of the token |
_tokenAmount | uint256 | amount of NFTs from _tokenAddress contract |
Returns
Name | Type | Description |
---|---|---|
totalValueInThisContract | uint256 | total valuation of tokens by collection in whole USD |
setAccountMaxValueByRiskScoreId
that setting a rule will automatically activate it.
Set the accountMaxValueByRiskScoreRule. Restricted to app administrators only.
Parameters
Name | Type | Description |
---|---|---|
_actions | ActionTypes[] | action types in which to apply the rules |
_ruleId | uint32 | Rule Id to set |
setAccountMaxValueByRiskScoreIdFull
that setting a rule will automatically activate it.
Set the accountMaxValueByRiskScoreRule. Restricted to app administrators only.
Parameters
Name | Type | Description |
---|---|---|
_actions | ActionTypes[] | actions to have the rule applied to |
_ruleIds | uint32[] | Rule Id corresponding to the actions |
clearAccountMaxValueByRiskScore
Clear the rule data structure
setAccountMaxValueByRiskScoreIdUpdate
that setting a rule will automatically activate it.
Set the AccountMaxValuebyRiskSCoreRuleId.
Parameters
Name | Type | Description |
---|---|---|
_action | ActionTypes | the action type to set the rule |
_ruleId | uint32 | Rule Id to set |
activateAccountMaxValueByRiskScore
enable/disable rule. Disabling a rule will save gas on transfer transactions.
Parameters
Name | Type | Description |
---|---|---|
_actions | ActionTypes[] | action types |
_on | bool | boolean representing if a rule must be checked or not. |
isAccountMaxValueByRiskScoreActive
Tells you if the accountMaxValueByRiskScore Rule is active or not.
Parameters
Name | Type | Description |
---|---|---|
_action | ActionTypes | the action type |
Returns
Name | Type | Description |
---|---|---|
<none> | bool | boolean representing if the rule is active |
getAccountMaxValueByRiskScoreId
Retrieve the accountMaxValueByRiskScore rule id
Parameters
Name | Type | Description |
---|---|---|
_action | ActionTypes | action type |
Returns
Name | Type | Description |
---|---|---|
<none> | uint32 | accountMaxValueByRiskScoreId rule id |
setAccountDenyForNoAccessLevelId
that setting a rule will automatically activate it.
Set the activateAccountDenyForNoAccessLevel. Restricted to app administrators only.
Parameters
Name | Type | Description |
---|---|---|
_actions | ActionTypes[] | action types in which to apply the rules |
setAccountDenyForNoAccessLevelIdFull
that setting a rule will automatically activate it.
Set the activateAccountDenyForNoAccessLevel. Restricted to app administrators only.
Parameters
Name | Type | Description |
---|---|---|
_actions | ActionTypes[] | actions to have the rule applied to |
clearAccountDenyForNoAccessLevel
Clear the rule data structure
setAccountDenyForNoAccessLevelIdUpdate
that setting a rule will automatically activate it.
Set the AccountDenyForNoAccessLevelRuleId.
Parameters
Name | Type | Description |
---|---|---|
_action | ActionTypes | the action type to set the rule |
activateAccountDenyForNoAccessLevelRule
enable/disable rule. Disabling a rule will save gas on transfer transactions.
Parameters
Name | Type | Description |
---|---|---|
_actions | ActionTypes[] | action types |
_on | bool | boolean representing if a rule must be checked or not. |
isAccountDenyForNoAccessLevelActive
Tells you if the AccountDenyForNoAccessLevel Rule is active or not.
Parameters
Name | Type | Description |
---|---|---|
_action | ActionTypes | the action type |
Returns
Name | Type | Description |
---|---|---|
<none> | bool | boolean representing if the rule is active |
setAccountMaxValueByAccessLevelId
that setting a rule will automatically activate it.
Set the accountMaxValueByAccessLevelRule. Restricted to app administrators only.
Parameters
Name | Type | Description |
---|---|---|
_actions | ActionTypes[] | action types in which to apply the rules |
_ruleId | uint32 | Rule Id to set |
setAccountMaxValueByAccessLevelIdFull
that setting a rule will automatically activate it.
Set the accountMaxValueByAccessLevelRule. Restricted to app administrators only.
Parameters
Name | Type | Description |
---|---|---|
_actions | ActionTypes[] | actions to have the rule applied to |
_ruleIds | uint32[] | Rule Id corresponding to the actions |
clearAccountMaxValueByAccessLevel
Clear the rule data structure
setAccountMaxValuebyAccessLevelIdUpdate
that setting a rule will automatically activate it.
Set the AccountMaxValuebyAccessLevelRuleId.
Parameters
Name | Type | Description |
---|---|---|
_action | ActionTypes | the action type to set the rule |
_ruleId | uint32 | Rule Id to set |
activateAccountMaxValueByAccessLevel
enable/disable rule. Disabling a rule will save gas on transfer transactions.
Parameters
Name | Type | Description |
---|---|---|
_actions | ActionTypes[] | action types |
_on | bool | boolean representing if a rule must be checked or not. |
isAccountMaxValueByAccessLevelActive
Tells you if the accountMaxValueByAccessLevel Rule is active or not.
Parameters
Name | Type | Description |
---|---|---|
_action | ActionTypes | the action type |
Returns
Name | Type | Description |
---|---|---|
<none> | bool | boolean representing if the rule is active |
getAccountMaxValueByAccessLevelId
Retrieve the accountMaxValueByAccessLevel rule id
Parameters
Name | Type | Description |
---|---|---|
_action | ActionTypes | action type |
Returns
Name | Type | Description |
---|---|---|
<none> | uint32 | accountMaxValueByAccessLevelId rule id |
setAccountMaxValueOutByAccessLevelId
that setting a rule will automatically activate it.
Set the AccountMaxValueOutByAccessLevel. Restricted to app administrators only.
Parameters
Name | Type | Description |
---|---|---|
_actions | ActionTypes[] | action types in which to apply the rules |
_ruleId | uint32 | Rule Id to set |
setAccountMaxValueOutByAccessLevelIdFull
that setting a rule will automatically activate it.
Set the AccountMaxValueOutByAccessLevel. Restricted to app administrators only.
Parameters
Name | Type | Description |
---|---|---|
_actions | ActionTypes[] | actions to have the rule applied to |
_ruleIds | uint32[] | Rule Id corresponding to the actions |
clearAccountMaxValueOutByAccessLevel
Clear the rule data structure
setAccountMaxValueOutByAccessLevelIdUpdate
that setting a rule will automatically activate it.
Set the AccountMaxValueOutByAccessLevelRuleId.
Parameters
Name | Type | Description |
---|---|---|
_action | ActionTypes | the action type to set the rule |
_ruleId | uint32 | Rule Id to set |
activateAccountMaxValueOutByAccessLevel
enable/disable rule. Disabling a rule will save gas on transfer transactions.
Parameters
Name | Type | Description |
---|---|---|
_actions | ActionTypes[] | action types |
_on | bool | boolean representing if a rule must be checked or not. |
isAccountMaxValueOutByAccessLevelActive
Tells you if the AccountMaxValueOutByAccessLevel Rule is active or not.
Parameters
Name | Type | Description |
---|---|---|
_action | ActionTypes | the action type |
Returns
Name | Type | Description |
---|---|---|
<none> | bool | boolean representing if the rule is active |
getAccountMaxValueOutByAccessLevelId
Retrieve the accountMaxValueOutByAccessLevel rule id
Parameters
Name | Type | Description |
---|---|---|
_action | ActionTypes | action type |
Returns
Name | Type | Description |
---|---|---|
<none> | uint32 | accountMaxValueOutByAccessLevelId rule id |
setAccountMaxTxValueByRiskScoreId
that setting a rule will automatically activate it.
Set the accountMaxTxValueByRiskScore. Restricted to app administrators only.
Parameters
Name | Type | Description |
---|---|---|
_actions | ActionTypes[] | action types in which to apply the rules |
_ruleId | uint32 | Rule Id to set |
setAccountMaxTxValueByRiskScoreIdFull
that setting a rule will automatically activate it.
Set the accountMaxTxValueByRiskScore. Restricted to app administrators only.
Parameters
Name | Type | Description |
---|---|---|
_actions | ActionTypes[] | actions to have the rule applied to |
_ruleIds | uint32[] | Rule Id corresponding to the actions |
clearAccountMaxTxValueByRiskScore
Clear the rule data structure
setAccountMaxTxValueByRiskScoreIdUpdate
that setting a rule will automatically activate it.
Set the AccountMaxTxValueByRiskScoreRuleId.
Parameters
Name | Type | Description |
---|---|---|
_action | ActionTypes | the action type to set the rule |
_ruleId | uint32 | Rule Id to set |
activateAccountMaxTxValueByRiskScore
enable/disable rule. Disabling a rule will save gas on transfer transactions.
Parameters
Name | Type | Description |
---|---|---|
_actions | ActionTypes[] | action types |
_on | bool | boolean representing if a rule must be checked or not. |
isAccountMaxTxValueByRiskScoreActive
Tells you if the accountMaxTxValueByRiskScore Rule is active or not.
Parameters
Name | Type | Description |
---|---|---|
_action | ActionTypes | the action type |
Returns
Name | Type | Description |
---|---|---|
<none> | bool | boolean representing if the rule is active |
getAccountMaxTxValueByRiskScoreId
Retrieve the AccountMaxTxValueByRiskScore rule id
Parameters
Name | Type | Description |
---|---|---|
_action | ActionTypes | action type |
Returns
Name | Type | Description |
---|---|---|
<none> | uint32 | accountMaxTxValueByRiskScoreId rule id |
activatePauseRule
This function uses the onlyOwner modifier since the appManager contract is calling this function when adding a pause rule or removing the final pause rule of the array.
enable/disable rule. Disabling a rule will save gas on transfer transactions. This function does not use ruleAdministratorOnly modifier, the onlyOwner modifier checks that the caller is the appManager contract.
Parameters
Name | Type | Description |
---|---|---|
_on | bool | boolean representing if a rule must be checked or not. |
isPauseRuleActive
Tells you if the pause rule check is active or not.
Returns
Name | Type | Description |
---|---|---|
<none> | bool | boolean representing if the rule is active for specified token |
version
gets the version of the contract
Returns
Name | Type | Description |
---|---|---|
<none> | string | VERSION |
isContract
Check if the addresss is a contract
Parameters
Name | Type | Description |
---|---|---|
account | address | address to check |
Returns
Name | Type | Description |
---|---|---|
<none> | bool | bool |
getRuleProcessAddress
Getter for rule processor address
Returns
Name | Type | Description |
---|---|---|
<none> | address | ruleProcessorAddress |