LibCommand

enum MathOperation {
    None,
    Add,
    Sub,
    Mul,
    Div,
    Pow,
    Abs128,
    Abs256,
    Shr,
    Shl
}

FieldDescription
None

A default operation indicating no mathematical operation is to be performed or possibly used as a placeholder.

Add

Represents addition, the operation of adding two numbers together to find their sum.

Sub

Represents subtraction, the operation of taking one number away from another to find the difference.

Mul

Represents multiplication, the operation of scaling one number by another to find the product.

Div

Represents division, the operation of determining how many times one number is contained within another to find the quotient.

Pow

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.

Abs128

Likely represents an operation to find the absolute value of a number within a 128-bit context, ensuring the result is positive or zero.

Abs256

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.

Shr

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.

Shl

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.

enum CommandAction {
    Call,
    Approval,
    TransferFrom,
    Transfer,
    Wrap,
    Unwrap,
    Balance,
    UniswapV2,
    UniswapV3,
    TraderJoeV2_1,
    Solidly,
    KyberSwapClassic,
    Ambient
}
FieldDescription
Call

This action representa a generic call to a function within a contract.

Approval

Represents an approval operation.

TransferFrom

Indicates a transfer-from operation.

Transfer

Represents a direct transfer operation.

Wrap

This action is used for wrapping tokens, such as converting Ether to Wrapped Ether (WETH).

Unwrap

The opposite of Wrap, this is used for unwrapping tokens, like converting WETH back to Ether.

Balance

to check the balance of an account or contract for a specific asset.

UniswapV2

Represents an swap operation related to the Uniswap V2 protocol.

UniswapV3

For swap operation specific to Uniswap V3.

TraderJoeV2_1

Indicates swap operation related to Trader Joe V2.1.

Solidly

Represents swap operation related to the Solidly protocol.

KyberSwapClassic

Indicates swap operation related to KyberSwap Classic

Ambient

Indicates swap operation related to Ambient Protocol.

enum SequenceType {
    NativeAmount,
    Selector,
    Address,
    Amount,
    Data,
    LastAmountOut,
    RouterAddress,
    SenderAddress
}
FieldDescription
NativeAmount

The amountIn in native tokens.

Selector

The function selector for the command.

Address

The recipient address.

Amount

The amount in.

Data

The data that contains information for the command to be performed.

LastAmountOut

The amount received after the previous swap.

RouterAddress

The address of the protocol router used for swapping.

SenderAddress

The address who requested the command to be performed.

struct CommandData {
    CommandAction commandAction;
    uint8 outputType;
    uint16 inputLength;
    uint16 sequencesPosition;
    uint16 sequencesPositionEnd;
    address targetAddress;
}
FieldTypeDescription
commandAction
CommandAction

This field uses the previously defined CommandAction enum to specify the type of action this command represents.

outputType
uint8

The specific meaning of this value would depend on the context in which the CommandData struct is used.

inputLength
uint16

indicating the length of the input data for this command.

sequencesPosition
uint16

specifies the starting position of a sequence of data related to this command.

sequencesPositionEnd
uint16

marks the end position of the sequence of data.

targetAddress
address

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

FieldTypeDescription

i

uint16

the starting position in the calldata from where data extraction should begin.

output

FieldTypeDescription

commandData

CommandData
struct CommandData {
    CommandAction commandAction;
    uint8 outputType;
    uint16 inputLength;
    uint16 sequencesPosition;
    uint16 sequencesPositionEnd;
    address targetAddress;
}

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

FieldTypeDescription

lastAmountOut

uint256

The amount received after the previous swap.

commandData

CommandData

struct CommandData {
    CommandAction commandAction;
    uint8 outputType;
    uint16 inputLength;
    uint16 sequencesPosition;
    uint16 sequencesPositionEnd;
    address targetAddress;
}

Output

FieldTypeDescription

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

FieldTypeDescription

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

FieldTypeDescription

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

FieldTypeDescription

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

FieldTypeDescription

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

FieldTypeDescription

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

FieldTypeDescription

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

FieldTypeDescription

commandData

CommandData

struct CommandData {
    CommandAction commandAction;
    uint8 outputType;
    uint16 inputLength;
    uint16 sequencesPosition;
    uint16 sequencesPositionEnd;
    address targetAddress;
}

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

FieldTypeDescription

amountOut

uint256

The amount received after the swap.

Last updated