Skip to content

Commit

Permalink
chore: add READMEs to hook and ism folders (#4637)
Browse files Browse the repository at this point in the history
### Description

Copies in docs for reference in published NPM package

Co-authored-by: Paul Balaji <[email protected]>
  • Loading branch information
yorhodes and paulbalaji authored Jan 8, 2025
1 parent 9a8974b commit 71dd0f1
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 0 deletions.
58 changes: 58 additions & 0 deletions solidity/contracts/hooks/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Post-Dispatch Hooks

Post-dispatch hooks allow developers to configure additional origin chain behavior with message content dispatched via the Mailbox.

```mermaid
flowchart TB
subgraph Origin
Sender
M_O[(Mailbox)]
Hook[IPostDispatchHook]
Sender -- "dispatch(..., metadata, hook)\n{value}" --> M_O
M_O -- "postDispatch(message, metadata)\n{value}" --> Hook
end
```

If the `postDispatch` function receives insufficient payment, it may revert.

> [!WARNING]
> Post-Dispatch Hooks may be replayable. Developers creating custom hooks should implement safe checks to prevent this behavior. [Here](./warp-route/RateLimitedHook.sol#L16) is an example implementation.
### Quote Dispatch (Fees)

Fees are often charged in `postDispatch` to cover costs such as destination chain transaction submission and security provisioning. To receive a quote for a corresponding `postDispatch` call, you can query the `quoteDispatch` function.

The Mailbox has a `quoteDispatch` function that returns the aggregate fee required for a `dispatch` call to be successful.

```mermaid
flowchart TB
subgraph Origin
Sender
M_O[(Mailbox)]
R_H[RequiredHook]
Hook[Hook]
Sender -- "quoteDispatch(..., metadata, hook)" --> M_O
M_O -- "required = quoteDispatch(message, metadata)" --> R_H
M_O -- "fee = hook.quoteDispatch(message, metadata)" --> Hook
M_O -- "required + fee" --> Sender
end
```

The custom `metadata` will be passed to the required hook's `quoteDispatch` and `postDispatch` functions, before being passed to the default hook's `postDispatch` function.

```mermaid
flowchart LR
subgraph Origin Chain
Sender
M_O[(Mailbox)]
R_H[RequiredHook]
D_H[DefaultHook]
Sender -- "dispatch(..., metadata){value}" --> M_O
M_O -. "fee = quoteDispatch(...)" .- R_H
M_O -- "postDispatch(metadata, ...)\n{fee}" --> R_H
M_O -. "postDispatch(metadata, ...)\n{value - fee}" ..-> D_H
end
```
20 changes: 20 additions & 0 deletions solidity/contracts/isms/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Interchain Security Modules

Interchain security modules allow developers to configure additional security checks for message content dispatched via the Mailbox.

```mermaid
flowchart LR
subgraph Destination Chain
ISM[InterchainSecurityModule]
Recipient[Recipient]
M_D[(Mailbox)]
M_D -- "verify(metadata, message)" --> ISM
ISM -. "interchainSecurityModule()" .- Recipient
M_D -- "handle(origin, sender, body)" --> Recipient
end
```

> [!WARNING]
> Interchain security modules may be replayable. Developers creating custom modules should include replay protection if necessary. [Here](./warp-route/RateLimitedIsm.sol#L23) is an example implementation.

0 comments on commit 71dd0f1

Please sign in to comment.