Skip to main content

Implement Hooks

Hooks provide an interface for recipient contracts to react upon cancellations and withdrawals. In order to allow your contract to be able to hook into Sablier, you must implement this interface and it must have been allowlisted by the Lockup contract's admin.

info

allowToHook is an irreversible operation, i.e., once a contract has been added to the allowlist, it can never be removed. This is to ensure stronger immutability and decentralization guarantees. Once a recipient contract is allowlisted, integrators should NOT have to trust us to keep their contract on the allowlist.

In this guide, we will explain how to implement hooks in your smart contract to allow interacting with Sablier streams.

Overview

Requirements

The recipient contract should implement the {IERC165-supportsInterface} method, which MUST return true when called with 0xf8ee98d3, which is the interface ID for ISablierLockupRecipient.

function supportsInterface(bytes4 interfaceId)
public
view
override(IERC165, ERC165)
returns (bool) {
return interfaceId == 0xf8ee98d3;
}

Hook Functions

These are the hooks that can be implemented by a recipient contract:

HookArgumentsReturn valueDescription
onSablierLockupCancel(streamId, sender, senderAmount, recipientAmount)function selectorCalled when the stream is canceled by the sender.
onSablierLockupWithdraw(streamId, caller, to, amount)function selectorCalled when an amount is withdrawn from the stream.

The complete interface for ISablierLockupRecipient can be found here.

Sample Implementations

Recipient

Sablier Recipient Hooks
loading...