diff --git a/x/tokenfactory/README.md b/x/tokenfactory/README.md index 4d011d21c71..1419d6d6456 100644 --- a/x/tokenfactory/README.md +++ b/x/tokenfactory/README.md @@ -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 { + 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