LibTransaction

The LibTransaction library provides functions for encoding and decoding a Transaction struct into a byte array.

struct Transaction {
    DataTransferType dataTransferType;
    BridgeType bridgeType;
    uint16 recipientNetworkId;
    bytes32 fromAssetAddress;
    bytes32 toAssetAddress;
    bytes32 toAddress;
    bytes32 recipientAggregatorAddress;
    uint256 amountOutMin;
    uint256 swapOutGasFee;
    uint64 tokenSequence;
}
FieldTypeDescription
dataTransferType
DataTransferType

DataTransferType has two named values: Wormhole and LayerZero.

Each named value is assigned an implicit integer value, starting at 0 for the first value and incrementing by 1 for each subsequent value. In this case, Wormhole is assigned the value 0, and LayerZero is assigned the value 1.

bridgeType
BridgeType

BridgeType has two named values: Wormhole and Stargate.

Each named value is assigned an implicit integer value, starting at 0 for the first value and incrementing by 1 for each subsequent value. In this case, Wormhole is assigned the value 0, and Stargate is assigned the value 1.

recipientNetworkId

uint16

the network id of the recipient chain.

fromAssetAddress
bytes32

the address of the source asset address that will get swapped. Example: 0x0000000000000000000000007b155e039f60ad89b3b3761a513238dfeebd8ab1

toAssetAddress
bytes32

the address of the destination asset address that will be received after swapping. Example: 0x0000000000000000000000003b981e413aedcd075d96a8f28d2aaff9b15f4f01

toAddress
bytes32

the address of the recipient. Example: 0x000000000000000000000000EE2249f8E5c4E84882eBA16DC991F3Fd4404C955

recipientAggregatorAddress
bytes32

the address of the aggregator at the destionation address.

amountOutMin
uint256

the minimum swapped amount that is acceptable by the user. Example: 100000000000000000

swapOutGasFee
uint256

the gas fee that the user can pay for the swapping. Example: 100000

tokenSequence
uint64

the sequence we receive while transferring the tokens over the bridge.

struct TransactionValidation {
    bytes32 fromAssetAddress;
    bytes32 toAssetAddress;
    bytes32 toAddress;
    uint256 amountOutMin;
    uint256 swapOutGasFee;
}
FieldTypeDescription
fromAssetAddress
bytes32

This field is of type bytes32 and represents the address of the asset being transferred from. The address is typically encoded as a 32-byte value.

toAssetAddress
bytes32

This field is of type bytes32 and represents the address of the asset being transferred to. Similar to fromAssetAddress, it is encoded as a 32-byte value.

toAddress
bytes32

This field is of type bytes32 and represents the destination address of the transfer. It is also encoded as a 32-byte value.

amountOutMin
uint256

This field is of type uint256 and represents the minimum amount of the transferred asset that should be received. It defines a threshold for the expected output amount.

swapOutGasFee
uint256

This field is of type uint256 and represents the gas fee associated with the swap or transfer operation. It specifies the amount of gas required for completing the transaction.

encode()

The encode function takes a Transaction struct and converts it into a byte array.

Input

FieldTypeDescription
transaction
Transaction

the transaction struct to perform the encoding.

Output

Field TypeDescription
transactionPayload
bytes

returns the encoded data in the form of bytes.

decode()

The decode function takes a byte array and converts it back into a Transaction struct.

Input

FieldTypeDescription
transactionPayload
bytes

the payload in bytes that needs to be decoded

Output

FieldTypeDescription
transaction
Transaction

returns the Transaction struct after the decoding is completed.

Last updated