LibTransferKey
The LibTransferKey library provides functionality for encoding, decoding, and validating TransferKey structs, which are used to represent transfer keys in the application.
struct TransferKey {
uint16 networkId;
bytes32 senderAddress;
uint64 swapSequence;
}networkId of the current chain in Magpie protocol, it is different from the actual networkId ethereum: 1 polygon: 2 bsc: 3 avalanche: 4 arbitrum: 5 optimism: 6
The address who initiated the transfer.
The magpie sequence for the current swap.
encode():
In the encode function, a new bytes array (payload) of size 42 is created to store the encoded transfer key.
Input:
Output:
The transferKey concatenated and converted to bytes
decode():
In the decode function, the assembly block is used to extract the values of each field from the payload array and store them in the transferKey struct.
Input:
The data which contains the transferKey.
Output:
validate():
The validate function checks if the networkId, senderAddress, and swapSequence fields of both TransferKey structs are equal. If any of the fields differ, indicating an invalid transfer key, the function reverts with an InvalidTransferKey error.
Input:
Last updated