Throughout the resolved order data type, it’s necessary to specify function calls the filler has to make, where some arguments are provided by the resolver and others should be taken from the filler’s variable assignment choices.
The resolver “pre-encodes” values in a way that the filler can later “aggregate” them together with its own variable assignments into the final calldata.
A function call in Step, FromResolver, or CallResult is specified by bytes4 selector and an array bytes[] arguments. Each argument may be a resolver-provided value or it may be a variable (identified by index).
ith function argument shall be the value assigned to the kth variable in the resolved order, the resolver must set: arguments[i] = abi.encode(k).ith function argument shall be a fixed value v, of any type, the resolver must set arguments[i] = abi.encode("", v). This is the pre-encoding of v.Given this array the filler can interpret it as follows:
arguments[i] has length 32, it must be ABI decoded as a uint256, and this value k denotes that the ith argument takes the value of the kth variable.arguments[i] is a pre-encoded value. Note that a pre-encoding is at least 96 bytes long so there is no ambiguity with variables.To encode the calldata for a function call, variables must be assigned values, and once all argument values are available in pre-encoded form they can be aggregated into a single ABI-encoded byte array as follows.
Note that a pre-encoded value will have one of two forms, depending on whether the type of the value is static or dynamic:
If the type is dynamic, it will begin with the prefix below and continue with the ABI encoding of the value.
0000000000000000000000000000000000000000000000000000000000000040
0000000000000000000000000000000000000000000000000000000000000060
0000000000000000000000000000000000000000000000000000000000000000
If the type is static, it is guaranteed not to begin with the above prefix, and removing the first and last 32 bytes leaves the ABI encoding of the value.
By identifying whether the type is dynamic or static, and obtaining the ABI encoding by trimming the parts indicated above, the tuple of all arguments can be encoded following the standard procedure.
interface DestinationSetler {
function fill(Order calldata order, address fillerAddress) external;
}
bytes4 selector = DestinationSettler.fill.selector;
bytes[] memory arguments = new bytes[](2);
arguments[0] = abi.encode("", order);
arguments[1] = abi.encode(fillerAddressIndex);