LibCommand
A default operation indicating no mathematical operation is to be performed or possibly used as a placeholder.
Represents addition, the operation of adding two numbers together to find their sum.
Represents subtraction, the operation of taking one number away from another to find the difference.
Represents multiplication, the operation of scaling one number by another to find the product.
Represents division, the operation of determining how many times one number is contained within another to find the quotient.
Stands for power, an operation that raises a number to the exponent of another number, essentially multiplying a number by itself a specified number of times.
Likely represents an operation to find the absolute value of a number within a 128-bit context, ensuring the result is positive or zero.
Similar to Abs128
, this likely refers to finding the absolute value of a number within a 256-bit context, which allows for handling larger numbers.
Stands for "shift right", a bitwise operation that shifts all bits in a binary representation of a number to the right by a specified number of positions, effectively dividing the number by a power of two.
Stands for "shift left", a bitwise operation that shifts all bits in a binary representation of a number to the left by a specified number of positions, effectively multiplying the number by a power of two.
This action representa a generic call to a function within a contract.
Represents an approval operation.
Indicates a transfer-from operation.
Represents a direct transfer operation.
This action is used for wrapping tokens, such as converting Ether to Wrapped Ether (WETH).
The opposite of Wrap, this is used for unwrapping tokens, like converting WETH back to Ether.
to check the balance of an account or contract for a specific asset.
Represents an swap operation related to the Uniswap V2 protocol.
For swap operation specific to Uniswap V3.
Indicates swap operation related to Trader Joe V2.1.
Represents swap operation related to the Solidly protocol.
Indicates swap operation related to KyberSwap Classic
Indicates swap operation related to Ambient Protocol.
The amountIn in native tokens.
The function selector for the command.
The recipient address.
The amount in.
The data that contains information for the command to be performed.
The amount received after the previous swap.
The address of the protocol router used for swapping.
The address who requested the command to be performed.
This field uses the previously defined CommandAction enum to specify the type of action this command represents.
The specific meaning of this value would depend on the context in which the CommandData struct is used.
indicating the length of the input data for this command.
specifies the starting position of a sequence of data related to this command.
marks the end position of the sequence of data.
the address of a contract or an account that is the target of this command.
getData():
The getData
function in Solidity is designed to extract and assemble a CommandData
structure from transaction calldata using low-level assembly operations for efficiency. It takes a single uint16
parameter i
, which specifies the starting position in the calldata from where data extraction should begin.
input
i
uint16
the starting position in the calldata from where data extraction should begin.
output
commandData
getInput():
The getInput
function is a complex and versatile internal function designed for processing a sequence of commands encoded in a CommandData
structure, typically used in a blockchain transaction context. It starts by initializing a dynamic input
byte array and other local variables, including nativeAmount
, selector
, and various counters. The function iterates over a range of command sequences, each identified by a SequenceType
(like NativeAmount
, Selector
, Address
, etc.), and processes each sequence differently based on its type. For instance, it extracts and stores native token amounts, contract function selectors, addresses, and other data into the input
array, adjusting the offset for each entry. The function also handles special cases, such as using the lastAmountOut
as an input or rejecting certain types of transactions (like transferFrom
calls in custom actions). It ensures that the length of the processed sequences matches the expected inputLength
from commandData
, and validates the selector for contract calls. Overall, getInput
is a sophisticated function that dynamically constructs a transaction input from a series of encoded commands, ensuring flexibility and security in executing complex transaction sequences on the blockchain.
Input
lastAmountOut
uint256
The amount received after the previous swap.
commandData
CommandData
Output
nativeAmount
uint256
The amountIn in native tokens.
selector
bytes4
The function selector for the command.
input
bytes
The data that contains information for the command to be performed.
approve():
the approve function is a utility function within a smart contract to perform an ERC-20 token approval operation. It extracts the token address, spender address, and amount from a byte array and then calls the approve function on the specified ERC-20 token contract.
input
input
bytes memory
A byte array containing necessary approve parameters.
transferFrom():
the transferFrom function is a utility function within a smart contract to perform an ERC-20 token transfer from one address to another. It extracts the token address, sender address, recipient address, and amount from a byte array and then calls the transferFrom function on the specified ERC-20 token contract.
input
input
bytes memory
A byte array containing necessary transferFrom parameters.
transfer():
the transfer function is a utility function within a smart contract to perform an ERC-20 token transfer to a specified address. It extracts the token address, recipient address, and amount from a byte array and then calls the transfer function on the specified ERC-20 token contract.
input
input
bytes memory
A byte array containing necessary transfer parameters.
wrap():
the wrap function is a utility function within a smart contract to convert Ether into Wrapped Ether (WETH). It extracts the WETH contract address and the amount of Ether to be wrapped from a byte array and then calls the deposit function on the WETH contract, sending the specified amount of Ether.
input
input
bytes memory
A byte array containing necessary wrap parameters.
unwrap():
the unwrap function is a utility function within a smart contract to convert Wrapped Ether (WETH) back into Ether. It extracts the WETH contract address and the amount of WETH to be unwrapped from a byte array and then calls the withdraw function on the WETH contract.
Input
input
bytes memory
A byte array containing necessary unwrap parameters.
balance():
the balance function is a utility function within a smart contract to query the balance of a specific asset (like an ERC-20 token) held by the contract. It extracts the asset's address from a byte array and then queries the balance of that asset for the contract's address.
Input
input
bytes memory
A byte array containing necessary balance parameters.
execute():
the execute function is a central part of a smart contract that needs to perform a variety of operations based on dynamic inputs. It can handle standard ERC-20 operations like approvals and transfers, wrap and unwrap Ether, interact with various DeFi protocols, and make generic contract calls.
Input
commandData
CommandData
nativeAmount
uint256
The amountIn in native tokens.
selector
bytes4
The function selector for the command.
input
bytes
The data that contains information for the command to be performed.
Output
amountOut
uint256
The amount received after the swap.
Last updated