LibSwap

struct SwapData {
    uint16 amountsOffset;
    uint16 dataOffset;
    uint16 commandsOffset;
    uint16 commandsOffsetEnd;
    uint16 outputsLength;
    uint256 amountIn;
    address toAddress;
    address fromAssetAddress;
    address toAssetAddress;
    uint256 deadline;
    uint256 amountOutMin;
}
Field
Type
Description

This is a 16-bit unsigned integer representing the offset for the amounts section in the transaction calldata. Offsets are used to locate specific data within a block of calldata.

Similar to amountsOffset, this is a 16-bit unsigned integer representing the offset for another data section in the calldata. The specific nature of this data depends on the context in which SwapData is used.

This is a 16-bit unsigned integer indicating the starting point of the commands section in the calldata. Commands in the context of a swap refers to specific actions.

This is a 16-bit unsigned integer marking the end of the commands section in the calldata. Knowing the start and end of the commands section helps in parsing and executing them correctly.

Represents the length of all of the commands.

A 256-bit unsigned integer representing the amount of the asset being provided in the swap.

This is the Ethereum address to which the output of the swap (the swapped asset) will be sent.

The Ethereum address of the asset being swapped from. This could be the contract address of an ERC-20 token or another type of asset.

The Ethereum address of the asset being swapped to. Like fromAssetAddress, this is typically the contract address of the target ERC-20 token or other asset types.

A timestamp (usually in seconds since the Unix epoch) indicating the deadline by which the swap must be completed.

The minimum amount of the output asset that must be received for the swap to be considered successful.

getAmountIn():

getAmountIn is a function that iterates over a portion of the transaction calldata, extracting and summing up amounts of an asset.

Input:

Field
Type
Description

startOffset

uint16

The location starting position

endOffset

uint16

The location ending position

positionOffset

uint16

The location of the current position

Ouput:

Field
Type
Description

amountIn

uint256

The Amount for the current swap.

getFirstAmountIn():

the getFirstAmountIn function is a utility function used to extract the first amount of an asset involved in a swap operation directly from the calldata of a transaction.

Input:

Field
Type
Description

swapArgsOffset

uint16

The location where the swapping data is stored.

Output:

Field
Type
Description

amountIn

uint256

The first amount in.

getData():

getData is a function that parses and organizes data from a transaction's calldata for a token swap operation.

Input:

Field
Type
Description

swapArgsOffset

uint16

The location where the swapping data is stored.

Output:

Field
Type
Description

swapData

SwapData memory

Last updated