DefiTxBase.sol
The DefiTxBase
contract is an abstract Solidity smart contract that implements a common interface and provides common helper functions for executing decentralized finance (DeFi) transactions within a decentralized application (DApp) or smart contract ecosystem. It offers flexibility for passing inputs, mapping return values, and handling various types of DeFi transactions. This documentation will provide a detailed overview of the contract's components, functions, and usage.
Contract Information
SPDX-License-Identifier: MIT
Solidity Version: 0.8.10
State Variables
BaseRegistry public constant registry
: A constant reference to theBaseRegistry
contract, which is used to manage base addresses within the system.BaseLogger public constant logger
: A constant reference to theBaseLogger
contract, which is used for logging events.
Constants and Enums
DefiTxType
DefiTxType
An enumeration representing different types of DeFi transactions:
FL_DEFI_TX
: Flash loan DeFi transaction.STANDARD_DEFI_TX
: Standard DeFi transaction.FEE_DEFI_TX
: Fee-based DeFi transaction.CHECK_DEFI_TX
: DeFi transaction for checking purposes.CUSTOM_DEFI_TX
: Custom DeFi transaction type.
Other Constants
SUB_MIN_INDEX_VALUE
andSUB_MAX_INDEX_VALUE
: The minimum and maximum values for subscription parameter indices (128 and 255, respectively).RETURN_MIN_INDEX_VALUE
andRETURN_MAX_INDEX_VALUE
: The minimum and maximum values for return parameter indices (1 and 127, respectively).NO_PARAM_MAPPING
: A constant indicating that no parameter mapping is needed.
Events
DefiTxEvent(string indexed logName, bytes data)
: An event emitted when a DeFi transaction is executed, providing a log name and transaction data.
Abstract Functions
executeDefiTx
Visibility: Public
Parameters:
_callData
: An array of input values, each encoded as bytes._subData
: An array of subscribed values, which can replace input values if specified._paramMapping
: An array that specifies how return and subscribed values are mapped in inputs._returnValues
: An array of return values from DeFi transactions before, which can be injected into inputs.
Returns: A bytes32 value returned through the
DSProxy
contract, with each DeFi transaction implementing its specific return value.
This abstract function defines the interface for executing a DeFi transaction with the provided input values.
_parseParamUint
Visibility: Internal
Parameters:
_param
: The original uint256 input value._mapType
: Indicates the type of the input inparamMapping
._subData
: An array of subscription data that can replace the input value._returnValues
: An array of subscription data that can replace the input value.
Returns: The modified uint256 value after injecting return/sub values if specified.
This internal helper method takes a uint256 input parameter,
_param
, and injects return/sub values into it based on the specified mapping type,_mapType
. If the mapping type indicates a return injection, the method injects the corresponding value from_returnValues
. If the mapping type indicates a subscription replacement, the method injects the value from_subData
. The modified value is then returned._parseParamAddr
Visibility: Internal
Parameters:
_param
: The original address input value._mapType
: Indicates the type of the input inparamMapping
._subData
: An array of subscription data that can replace the input value._returnValues
: An array of subscription data that can replace the input value.
Returns: The modified address value after injecting return/sub values if specified.
This internal helper method takes an address input parameter,
_param
, and injects return/sub values into it based on the specified mapping type,_mapType
. If the mapping type indicates a return injection, the method injects the corresponding value from_returnValues
. If the mapping type indicates a subscription replacement, the method injects the value from_subData
. The modified address value is then returned._parseParamABytes32
Visibility: Internal
Parameters:
_param
: The original bytes32 input value._mapType
: Indicates the type of the input inparamMapping
._subData
: An array of subscription data that can replace the input value._returnValues
: An array of subscription data that can replace the input value.
Returns: The modified bytes32 value after injecting return/sub values if specified.
This internal helper method takes a bytes32 input parameter,
_param
, and injects return/sub values into it based on the specified mapping type,_mapType
. If the mapping type indicates a return injection, the method injects the corresponding value from_returnValues
. If the mapping type indicates a subscription replacement, the method injects the value from_subData
. The modified bytes32 value is then returned.isReplaceable
Visibility: Internal
Parameters:
_type
: Indicates the type of the input inparamMapping
.
Returns: A boolean value indicating whether the paramMapping value
_type
indicates the need for value injection (true) or not (false).
This internal helper method checks whether the paramMapping value
_type
indicates the need for value injection. If_type
is not equal toNO_PARAM_MAPPING
, it returnstrue
, indicating that value injection is required. Otherwise, it returnsfalse
.isReturnInjection
Visibility: Internal
Parameters:
_type
: Indicates the type of the input inparamMapping
.
Returns: A boolean value indicating whether the paramMapping value
_type
is in the return value range (true) or not (false).
This internal helper method checks whether the paramMapping value
_type
is within the return value range. If_type
is within the range, it returnstrue
, indicating that it is a return value injection. Otherwise, it returnsfalse
.getReturnIndex
Visibility: Internal
Parameters:
_type
: Indicates the type of the input inparamMapping
.
Returns: An unsigned integer representing the index in the return array value corresponding to the paramMapping value
_type
.
This internal helper method transforms the paramMapping value
_type
into an index in the return array value. It ensures that_type
is within the valid return index range before performing the transformation and returning the index.getSubIndex
Visibility: Internal
Parameters:
_type
: Indicates the type of the input inparamMapping
.
Returns: An unsigned integer representing the index in the sub-array value corresponding to the paramMapping value
_type
.
This internal helper method transforms the paramMapping value
_type
into an index in the sub-array value. It ensures that_type
is within the valid subscription index range before performing the transformation and returning the index.These helper methods are crucial for handling parameter mapping, value injection, and ensuring that the correct values are used in DeFi transactions based on the specified logic. They contribute to the flexibility and functionality of the
DefiTxBase
contract, making it suitable for various types of DeFi transactions within a smart contract ecosystem.
Last updated