LibFlow

Git Source

Functions

stackToFlow

Converts pointers bounding an evaluated stack to a FlowTransferV1. Works by repeatedly consuming sentinel tuples from the stack, where the tuple size is 4 for ERC20, 4 for ERC721 and 5 for ERC1155. The sentinels are consumed from the stack from top to bottom, so the first sentinels consumed are the ERC20 transfers, followed by the ERC721 transfers and finally the ERC1155 transfers.

function stackToFlow(Pointer stackBottom, Pointer stackTop) internal pure returns (FlowTransferV1 memory);

Parameters

NameTypeDescription
stackBottomPointerThe bottom of the stack.
stackTopPointerThe top of the stack.

Returns

NameTypeDescription
<none>FlowTransferV1The FlowTransferV1 representing the transfers in the stack.

flowERC20

Processes the ERC20 transfers in the flow. Reverts if the from address is not either the msg.sender or the flow contract. Uses IERC20.safeTransferFrom to transfer the tokens to ensure that reverts from the token are respected.

function flowERC20(FlowTransferV1 memory flowTransfer) internal;

Parameters

NameTypeDescription
flowTransferFlowTransferV1The FlowTransferV1 to process. Tokens other than ERC20 tokens are ignored.

flowERC721

Processes the ERC721 transfers in the flow. Reverts if the from address is not either the msg.sender or the flow contract. Uses IERC721.safeTransferFrom to transfer the tokens to ensure that reverts from the token are respected.

function flowERC721(FlowTransferV1 memory flowTransfer) internal;

Parameters

NameTypeDescription
flowTransferFlowTransferV1The FlowTransferV1 to process. Tokens other than ERC721 tokens are ignored.

flowERC1155

Processes the ERC1155 transfers in the flow. Reverts if the from address is not either the msg.sender or the flow contract. Uses IERC1155.safeTransferFrom to transfer the tokens to ensure that reverts from the token are respected.

function flowERC1155(FlowTransferV1 memory flowTransfer) internal;

Parameters

NameTypeDescription
flowTransferFlowTransferV1The FlowTransferV1 to process. Tokens other than ERC1155 tokens are ignored.

flow

Processes a flow transfer. Firstly sets state for the interpreter on the interpreter store. Then processes the ERC20, ERC721 and ERC1155 transfers in the flow. Guarantees ordering of the transfers but DOES NOT prevent reentrancy attacks. This is the responsibility of the caller.

function flow(FlowTransferV1 memory flowTransfer, IInterpreterStoreV1 interpreterStore, uint256[] memory kvs)
    internal;

Parameters

NameTypeDescription
flowTransferFlowTransferV1The FlowTransferV1 to process.
interpreterStoreIInterpreterStoreV1The IInterpreterStoreV1 to set state on.
kvsuint256[]The key value pairs to set on the interpreter store.