Skip to content
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

Feat/permissions module support #364

Draft
wants to merge 7 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

All notable changes to this project will be documented in this file.

## [1.9.0] - 9999-99-99
### Added
- Added support for all new queries and messages from the new Permissions module

## [1.8.1] - 2024-12-04
### Changed
- Updated OFAC list link and contents

## [1.8.0] - 2024-11-14
### Changed
- The markets initialization in AsyncClient has been modified to get markets information from the chain endpoints instead of the Indexer endpoints
Expand Down
8 changes: 4 additions & 4 deletions buf.gen.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ inputs:
# - git_repo: https://github.com/InjectiveLabs/wasmd
# branch: v0.51.x-inj
# subdir: proto
- git_repo: https://github.com/InjectiveLabs/injective-core
tag: v1.13.0
subdir: proto
# - git_repo: https://github.com/InjectiveLabs/injective-core
# branch: master
# tag: v1.13.0
# subdir: proto
- git_repo: https://github.com/InjectiveLabs/injective-core
branch: f/permissions-rework
subdir: proto
- directory: proto
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ async def main() -> None:
min_price_tick_size=Decimal("0.001"),
min_quantity_tick_size=Decimal("0.01"),
min_notional=Decimal("1"),
base_decimals=18,
quote_decimals=6,
)

# broadcast the transaction
Expand Down
68 changes: 55 additions & 13 deletions examples/chain_client/permissions/1_MsgCreateNamespace.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,68 @@ async def main() -> None:
pub_key = priv_key.to_public_key()
address = pub_key.to_address()

blocked_address = "inj1hkhdaj2a2clmq5jq6mspsggqs32vynpk228q3r"
denom = "factory/inj1hkhdaj2a2clmq5jq6mspsggqs32vynpk228q3r/inj_test"
role1 = composer.permissions_role(
role=composer.DEFAULT_PERMISSIONS_EVERYONE_ROLE,
permissions=composer.MINT_ACTION_PERMISSION
| composer.RECEIVE_ACTION_PERMISSION
| composer.BURN_ACTION_PERMISSION,
name="EVERYONE",
role_id=0,
permissions=composer.PERMISSIONS_ACTION["RECEIVE"] | composer.PERMISSIONS_ACTION["SEND"],
)
role2 = composer.permissions_role(
name="admin",
role_id=1,
permissions=composer.PERMISSIONS_ACTION["MODIFY_ROLE_PERMISSIONS"]
| composer.PERMISSIONS_ACTION["MODIFY_ADDRESS_ROLES"],
)
role3 = composer.permissions_role(
name="user",
role_id=2,
permissions=composer.PERMISSIONS_ACTION["MINT"]
| composer.PERMISSIONS_ACTION["RECEIVE"]
| composer.PERMISSIONS_ACTION["BURN"]
| composer.PERMISSIONS_ACTION["SEND"],
)

actor_role1 = composer.permissions_actor_roles(
actor="inj1specificactoraddress",
roles=["admin"],
)
actor_role2 = composer.permissions_actor_roles(
actor="inj1anotheractoraddress",
roles=["user"],
)

role_manager = composer.permissions_role_manager(
manager="inj1manageraddress",
roles=["admin"],
)

policy_status1 = composer.permissions_policy_status(
action=composer.PERMISSIONS_ACTION["MINT"],
is_disabled=False,
is_sealed=False,
)
policy_status2 = composer.permissions_policy_status(
action=composer.PERMISSIONS_ACTION["BURN"],
is_disabled=False,
is_sealed=False,
)

policy_manager_capability = composer.permissions_policy_manager_capability(
manager="inj1policymanageraddress",
action=composer.PERMISSIONS_ACTION["MODIFY_CONTRACT_HOOK"],
can_disable=True,
can_seal=False,
)
role2 = composer.permissions_role(role="blacklisted", permissions=composer.UNDEFINED_ACTION_PERMISSION)
address_role1 = composer.permissions_address_roles(address=blocked_address, roles=["blacklisted"])

message = composer.msg_create_namespace(
sender=address.to_acc_bech32(),
denom=denom,
wasm_hook="",
mints_paused=False,
sends_paused=False,
burns_paused=False,
role_permissions=[role1, role2],
address_roles=[address_role1],
contract_hook="",
role_permissions=[role1, role2, role3],
actor_roles=[actor_role1, actor_role2],
role_managers=[role_manager],
policy_statuses=[policy_status1, policy_status2],
policy_manager_capabilities=[policy_manager_capability],
)

# broadcast the transaction
Expand Down
42 changes: 0 additions & 42 deletions examples/chain_client/permissions/2_MsgDeleteNamespace.py

This file was deleted.

82 changes: 82 additions & 0 deletions examples/chain_client/permissions/2_MsgUpdateNamespace.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import asyncio
import os

import dotenv

from pyinjective.composer import Composer as ProtoMsgComposer
from pyinjective.core.broadcaster import MsgBroadcasterWithPk
from pyinjective.core.network import Network
from pyinjective.wallet import PrivateKey


async def main() -> None:
dotenv.load_dotenv()
private_key_in_hexa = os.getenv("INJECTIVE_PRIVATE_KEY")

# select network: local, testnet, mainnet
network = Network.devnet()
composer = ProtoMsgComposer(network=network.string())

message_broadcaster = MsgBroadcasterWithPk.new_using_simulation(
network=network,
private_key=private_key_in_hexa,
)

priv_key = PrivateKey.from_hex(private_key_in_hexa)
pub_key = priv_key.to_public_key()
address = pub_key.to_address()

denom = "factory/inj1hkhdaj2a2clmq5jq6mspsggqs32vynpk228q3r/inj_test"

role1 = composer.permissions_role(
name="EVERYONE",
role_id=0,
permissions=composer.PERMISSIONS_ACTION["UNSPECIFIED"], # revoke all permissions
)
role2 = composer.permissions_role(
name="user",
role_id=2,
permissions=composer.PERMISSIONS_ACTION["RECEIVE"] | composer.PERMISSIONS_ACTION["SEND"],
)

role_manager = composer.permissions_role_manager(
manager="inj1manageraddress",
roles=["admin", "user"],
)

policy_status1 = composer.permissions_policy_status(
action=composer.PERMISSIONS_ACTION["MINT"],
is_disabled=True,
is_sealed=False,
)
policy_status2 = composer.permissions_policy_status(
action=composer.PERMISSIONS_ACTION["BURN"],
is_disabled=False,
is_sealed=True,
)

policy_manager_capability = composer.permissions_policy_manager_capability(
manager="inj1policymanageraddress",
action=composer.PERMISSIONS_ACTION["MODIFY_ROLE_PERMISSIONS"],
can_disable=True,
can_seal=False,
)

message = composer.msg_update_namespace(
sender=address.to_acc_bech32(),
denom=denom,
contract_hook="inj19ld6swyldyujcn72j7ugnu9twafhs9wxlyye5m",
role_permissions=[role1, role2],
role_managers=[role_manager],
policy_statuses=[policy_status1, policy_status2],
policy_manager_capabilities=[policy_manager_capability],
)

# broadcast the transaction
result = await message_broadcaster.broadcast([message])
print("---Transaction Response---")
print(result)


if __name__ == "__main__":
asyncio.get_event_loop().run_until_complete(main())
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,30 @@ async def main() -> None:
pub_key = priv_key.to_public_key()
address = pub_key.to_address()

blocked_address = "inj1hkhdaj2a2clmq5jq6mspsggqs32vynpk228q3r"
denom = "factory/inj1hkhdaj2a2clmq5jq6mspsggqs32vynpk228q3r/inj_test"
role1 = composer.permissions_role(
role=composer.DEFAULT_PERMISSIONS_EVERYONE_ROLE,
permissions=composer.RECEIVE_ACTION_PERMISSION,

role_actors1 = composer.permissions_role_actors(
role="admin",
actors=["inj1actoraddress1", "inj1actoraddress2"],
)
role_actors2 = composer.permissions_role_actors(
role="user",
actors=["inj1actoraddress3"],
)
role_actors3 = composer.permissions_role_actors(
role="user",
actors=["inj1actoraddress4"],
)
role_actors4 = composer.permissions_role_actors(
role="admin",
actors=["inj1actoraddress5"],
)
role2 = composer.permissions_role(role="blacklisted", permissions=composer.UNDEFINED_ACTION_PERMISSION)
address_role1 = composer.permissions_address_roles(address=blocked_address, roles=["blacklisted"])

message = composer.msg_update_namespace_roles(
message = composer.msg_update_actor_roles(
sender=address.to_acc_bech32(),
namespace_denom=denom,
role_permissions=[role1, role2],
address_roles=[address_role1],
denom=denom,
role_actors_to_add=[role_actors1, role_actors2],
role_actors_to_revoke=[role_actors3, role_actors4],
)

# broadcast the transaction
Expand Down
47 changes: 0 additions & 47 deletions examples/chain_client/permissions/3_MsgUpdateNamespace.py

This file was deleted.

46 changes: 0 additions & 46 deletions examples/chain_client/permissions/5_MsgRevokeNamespaceRoles.py

This file was deleted.

Loading
Loading