ZapDataV1
State Variables
VERSION
Version of the Zap Data struct.
uint16 internal constant VERSION = 1;
AMOUNT_NOT_PRESENT
Value that indicates the amount is not present in the target function's payload.
uint16 internal constant AMOUNT_NOT_PRESENT = 0xFFFF;
OFFSET_AMOUNT_POSITION
uint256 private constant OFFSET_AMOUNT_POSITION = 2;
OFFSET_FINAL_TOKEN
uint256 private constant OFFSET_FINAL_TOKEN = 4;
OFFSET_FORWARD_TO
uint256 private constant OFFSET_FORWARD_TO = 24;
OFFSET_TARGET
uint256 private constant OFFSET_TARGET = 44;
OFFSET_PAYLOAD
uint256 private constant OFFSET_PAYLOAD = 64;
Functions
validateV1
Validates that encodedZapData is a tightly packed encoded payload for ZapData struct.
Checks that all the required fields are present and the version is correct.
function validateV1(bytes calldata encodedZapData) internal pure;
encodeV1
Encodes the ZapData struct by tightly packing the fields.
Note: we don't know the exact amount of tokens that will be used for the Zap at the time of encoding,
so we provide the reference index where the token amount is encoded within payload_
. This allows us to
hot-swap the token amount in the payload, when the Zap is performed.
abi.decode
will not work as a result of the tightly packed fields. Use decodeZapData
instead.
function encodeV1(
uint16 amountPosition_,
address finalToken_,
address forwardTo_,
address target_,
bytes memory payload_
)
internal
pure
returns (bytes memory encodedZapData);
Parameters
Name | Type | Description |
---|---|---|
amountPosition_ | uint16 | Position (start index) where the token amount is encoded within payload_ . This will usually be 4 + 32 * n , where n is the position of the token amount in the list of parameters of the target function (starting from 0). Or AMOUNT_NOT_PRESENT if the token amount is not encoded within payload_ . |
finalToken_ | address | The token produced as a result of the Zap action (ERC20 or native gas token). A zero address value signals that the Zap action doesn't result in any asset per se, like bridging or depositing into a vault without an LP token. Note: this parameter must be set to a non-zero value if the forwardTo_ parameter is set to a non-zero value. |
forwardTo_ | address | The address to which finalToken should be forwarded. This parameter is required only if the Zap action does not automatically transfer the token to the intended recipient. Otherwise, it must be set to address(0). |
target_ | address | Address of the target contract. |
payload_ | bytes | ABI-encoded calldata to be used for the target_ contract call. If the target function has the token amount as an argument, any placeholder amount value can be used for the original ABI encoding of payload_ . The placeholder amount will be replaced with the actual amount, when the Zap Data is decoded. |
version
Extracts the version from the encoded Zap Data.
function version(bytes calldata encodedZapData) internal pure returns (uint16 version_);
finalToken
Extracts the finalToken address from the encoded Zap Data.
function finalToken(bytes calldata encodedZapData) internal pure returns (address finalToken_);
forwardTo
Extracts the forwardTo address from the encoded Zap Data.
function forwardTo(bytes calldata encodedZapData) internal pure returns (address forwardTo_);
target
Extracts the target address from the encoded Zap Data.
function target(bytes calldata encodedZapData) internal pure returns (address target_);
payload
Extracts the payload from the encoded Zap Data. Replaces the token amount with the provided value, if it was present in the original data (if amountPosition is not AMOUNT_NOT_PRESENT).
This payload will be used as a calldata for the target contract.
function payload(bytes calldata encodedZapData, uint256 amount) internal pure returns (bytes memory);
_amountPosition
Extracts the amount position from the encoded Zap Data.
function _amountPosition(bytes calldata encodedZapData) private pure returns (uint16 amountPosition);
Errors
ZapDataV1__InvalidEncoding
error ZapDataV1__InvalidEncoding();
ZapDataV1__TargetZeroAddress
error ZapDataV1__TargetZeroAddress();
ZapDataV1__UnsupportedVersion
error ZapDataV1__UnsupportedVersion(uint16 version);