Skip to content

Commit

Permalink
Add some docs to tf (#6095) (#6104)
Browse files Browse the repository at this point in the history
  • Loading branch information
mergify[bot] committed Aug 17, 2023
1 parent e4f2c3e commit ea8b741
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions x/tokenfactory/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,42 @@ created denom. Once a denom is created, the original creator is given
account, or even setting it to `""`, meaning no account has admin privileges
of the asset.

## Bank hooks
Token factory supports better integration with contracts using bank hooks.

Token factory is integrated with Before Send bank hooks, `TrackBeforeSend` and `BlockBeforeSend`. Both hooks gets called whenever a bank send takes place, the difference between two hooks is that `TrackBeforeSend` would not error and `BlockBeforeSend` errors. Due to this difference `TrackBeforeSend` is useful for cases when a contract needs to track specific send actions of the token factory denom, whilst `BlockBeforeSend` would be more useful for situations when we want to block specific sends using contracts.

Each Token Factory denom allows the registration of one contract address. This contract is sudo-called every time the aforementioned bank hooks are activated.

Contracts are able to integrate with these hooks by implementing `BlockBeforeSend` and `TrackBeforeSend` message as the following example:

```rust
#[entry_point]
pub fn sudo(deps: DepsMut, env: Env, msg: SudoMsg) -> StdResult<Response> {
match &msg{
SudoMsg::BlockBeforeSend { from, to, amount} => {
Ok(Response::new().add_attributes(vec![
("hook", "block"),
("from", from),
("to", to),
("amount", &amount.to_string())
]))
},
SudoMsg::TrackBeforeSend { from, to, amount} => {
Ok(Response::new().add_attributes(vec![
("hook", "track"),
("from", from),
("to", to),
("amount", &amount.to_string())
]))
}
}
}
```


Note that since `TrackBeforeSend` hook can also be triggered upon module to module send (which is not gas metered), we internally gas meter `TrackBeforeSend` with a gas limit of 100_000.

## Messages

### CreateDenom
Expand Down

0 comments on commit ea8b741

Please sign in to comment.