-
Notifications
You must be signed in to change notification settings - Fork 1
docs: permissioned mts tokens #50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
bguiz
wants to merge
9
commits into
main
Choose a base branch
from
docs/permissions-mts
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
012896e
docs: minor - syntax cleanup of MTS page
bguiz 7c7c3f6
docs: add permissioned MTS page (blank)
bguiz c192f37
docs: add docs for permissioned MTS tokens
bguiz 19c66c1
fix: nav menu error
bguiz aec3883
docs: instructions on registering a hook
bguiz 62f3c2d
docs: minor - fix typos
bguiz 6b4f5b0
docs: add reference impl for stablecoins:
bguiz b6a0c01
docs: minor - fix typos
bguiz a7881f2
docs: updates basd on feedback from @kakysha
bguiz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,168 @@ | ||
| --- | ||
| title: Permissioned MTS Tokens | ||
| description: Leverage Injective's permissions module in MultiVM Token Standard (MTS) tokens | ||
| --- | ||
|
|
||
| ## Injective's Permissions Module | ||
|
|
||
| The [`permissions` module](https://docs.injective.network/developers-native/injective/permissions) | ||
| is native to Injective, and allows custom management (e.g. roles) for Denoms. | ||
| This capability is extended to MultiVM Token Standard (MTS) tokens, | ||
| where you can implement those custom management rules within your EVM smart contract code. | ||
|
|
||
| ## Why Use Permissions on MTS Tokens? | ||
|
|
||
| If you are tokenizing real-world assets (RWAs) using MTS on Injective, | ||
| and that underlying asset inherently requires permissions, | ||
| that is a great use case for tapping into Injective's `permissions` module. | ||
|
|
||
| The EVM smart contract of your MTS token simply needs to implement | ||
| an additional Solidity interface to leverage the power of the `permissions` module. | ||
|
|
||
| ## Smart Contract Implementation | ||
|
|
||
| In your smart contract, import `IPermissionsHook` from `PermissionsHook.sol` and extend it. | ||
|
|
||
| ```solidity | ||
| interface IPermissionsHook | ||
| ``` | ||
|
|
||
| This will involve implementing the `isTransferRestricted` function, | ||
| with the following signature: | ||
|
|
||
| ```solidity | ||
| function isTransferRestricted( | ||
| address from, | ||
| address to, | ||
| Cosmos.Coin calldata amount | ||
| ) | ||
| ``` | ||
|
|
||
| You may find the full file on Github: | ||
| [`PermissionsHook.sol`](https://github.com/InjectiveLabs/solidity-contracts/blob/master/src/PermissionsHook.sol) | ||
|
|
||
| ### Smart Contract Example | ||
|
|
||
| Create a smart contract that extends `PermissionsHook`: | ||
|
|
||
| ```solidity | ||
| import { Cosmos } from "../src/CosmosTypes.sol"; | ||
| import { PermissionsHook } from "../src/PermissionsHook.sol"; | ||
| contract RestrictedAddressTransferHook is PermissionsHook { | ||
| /* | ||
| ... | ||
| */ | ||
| } | ||
| ``` | ||
|
|
||
| Add a custom implementation of the `isTransferRestricted` function. | ||
| For example, this function will allow all transfers, | ||
| except for ones involving a specific address: | ||
|
|
||
| ```solidity | ||
| function isTransferRestricted( | ||
| address from, | ||
| address to, | ||
| Cosmos.Coin calldata amount | ||
| ) external pure override returns (bool) { | ||
| address restrictedAddress = "0x..."; | ||
| if (from == restrictedAddress || to == restrictedAddress) { | ||
| // this particular address is not allowed to transfer | ||
| return true; | ||
| } | ||
|
|
||
| // All other transfers are allowed | ||
| return false; | ||
| } | ||
| ``` | ||
|
|
||
| You may find a more detailed example of this on Github: | ||
| [`PermissionsHookExamples.sol`](https://github.com/InjectiveLabs/solidity-contracts/blob/master/examples/PermissionsHookExamples.sol) | ||
|
|
||
| ## Registering Hook | ||
|
|
||
| To register the hook for the permissions, | ||
| you will need the following: | ||
|
|
||
| - Control of the same account that deployed the MTS token. | ||
| - The deployed address of the MTS token | ||
| - The deployed address of the Permissions Hook | ||
|
|
||
| With the above, you can create | ||
| [a JSON file similar to this one](https://github.com/InjectiveLabs/stablecoin-evm/blob/fiattoken-inj/scripts/demo/namespace.json). | ||
|
|
||
| Then run `injectived` for the registration, | ||
| using the same account that deployed the MTS token. | ||
|
|
||
| ```shell | ||
| injectived tx permissions create-namespace ... | ||
| ``` | ||
|
|
||
| <Info> | ||
| Note that the MTS token and the Permissions Hook can have the same address. | ||
| That is an architectural decision that is up to you. | ||
| </Info> | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| ### Registering Hook Example | ||
|
|
||
| Create a file named `register-hooks.json`, with the following content: | ||
|
|
||
| ```jsonc | ||
| { | ||
| "denom": "erc20:0x...", // <-- EVM address of the MTS token | ||
| "evm_hook": "0x...", // <-- EVM address of the permissions hook | ||
| "role_permissions": [ | ||
| { | ||
| "name": "EVERYONE", | ||
| "role_id": 0, | ||
| "permissions": 10 | ||
| } | ||
| ], | ||
| "actor_roles": [ | ||
| ] | ||
| } | ||
| ``` | ||
|
|
||
| Be sure to replace the value of the | ||
| `denom` and `evm_hook` fields with the appropriate values. | ||
|
|
||
| <Info> | ||
| Delete all comments as well, so that the file is valid JSON. | ||
| </Info> | ||
|
|
||
| Then run the following command: | ||
|
|
||
| ```shell | ||
| injectived tx permissions create-namespace register-hooks.json [flags] | ||
| ``` | ||
|
|
||
| Note that this is merely one specific way to define permissions hooks on an MTS token. | ||
| There are multiple variations. | ||
| For additional details on this step, including other variations, refer to | ||
| [How to Launch Permissioned Assets](https://docs.injective.network/developers-native/injective/permissions/04_launch_permissioned_asset). | ||
|
|
||
| ## Reference Implementation | ||
|
|
||
| A more complete example that demonstrates the use of permissioned MTS tokens | ||
| for a stable coin is also available. | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| This example involves a permissions hook which prevents transfers | ||
| when the token is paused, and also maintains a blacklist of addresses. | ||
|
|
||
| ```solidity | ||
| function isTransferRestricted( | ||
| address _from, | ||
| address _to, | ||
| Cosmos.Coin calldata /* _amount */ | ||
| ) external view returns (bool) { | ||
| if (fiatToken.paused()) { | ||
| return true; | ||
| } else if (fiatToken.isBlacklisted(_from) || fiatToken.isBlacklisted(_to)) { | ||
| return true; | ||
| } | ||
|
|
||
| return false; | ||
| } | ||
| ``` | ||
|
|
||
| See [`PermissionsHook_Inj.sol`](https://github.com/InjectiveLabs/stablecoin-evm/blob/fiattoken-inj/contracts/v2/PermissionsHook_Inj.sol). | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix Solidity syntax error in code example.
Line 68 contains invalid Solidity syntax. Address literals in Solidity must not use quotes (single or double). The current example uses
"0x..."which will cause a compilation error.🔎 Proposed fix
function isTransferRestricted( address from, address to, Cosmos.Coin calldata amount ) external pure override returns (bool) { - address restrictedAddress = "0x..."; + address restrictedAddress = 0x0000000000000000000000000000000000000000; // Replace with actual address if (from == restrictedAddress || to == restrictedAddress) { // this particular address is not allowed to transfer return true; } // All other transfers are allowed return false; }Alternatively, for a more realistic example, consider using a state variable or constructor parameter as shown in the previous review.
🤖 Prompt for AI Agents