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
uint16
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
senderAddress
bytes32
The address who initiated the transfer.
swapSequence
uint64
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:
transferKey
TransferKey
struct TransferKey {
uint16 networkId;
bytes32 senderAddress;
uint64 swapSequence;
}
Output:
payload
bytes
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:
payload
bytes
The data which contains the transferKey.
Output:
transferKey
TransferKey
struct TransferKey {
uint16 networkId;
bytes32 senderAddress;
uint64 swapSequence;
}
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:
self
TransferKey
struct TransferKey {
uint16 networkId;
bytes32 senderAddress;
uint64 swapSequence;
}
transferKey
TransferKey
struct TransferKey {
uint16 networkId;
bytes32 senderAddress;
uint64 swapSequence;
}
Last updated