Skip to content

Commit 4cb6fdb

Browse files
authored
feat: add collect_royalties method in the group module (#135)
* feat: add claim rewards functionality to Group and GroupingModuleClient * feat: add integration test for claiming rewards in Group functionality * feat: add unit tests for Group.claim_rewards method with various scenarios * feat: add claimReward function to GroupingModule in config.json * feat: update imports in __init__.py to include ClaimReward and RegisterPILTermsAndAttachResponse * refactor: remove debug print statements from Group and integration tests * refactor: update claim_rewards method in Group to enhance response structure and remove unused parsing function * refactor: improve claim_rewards method in Group to process logs directly and enhance error handling * refactor: simplify test assertions in TestGroupClaimRewards for claim_rewards method * feat: add collect_royalties functionality to Group and GroupingModuleClient * chore: update .gitignore to include .cursor directory * fix: improve royalty collection logic in Group by processing logs directly for event signatures * refactor: restructure integration tests for Group functionality by introducing a helper class and enhancing test methods for royalty collection and reward claiming * test: add unit tests for Group.collect_royalties method covering various scenarios including invalid inputs and successful transactions * refactor: update type hint for mint_and_register_ip_asset_with_pil_terms method in GroupTestHelper to use 'Any' for improved clarity
1 parent be2a6c2 commit 4cb6fdb

File tree

8 files changed

+401
-452
lines changed

8 files changed

+401
-452
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,3 +112,4 @@ web3py.md
112112

113113
# AI Assistant Configuration
114114
CLAUDE.md
115+
.cursor/

src/story_protocol_python_sdk/__init__.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@
88
from .resources.WIP import WIP
99
from .story_client import StoryClient
1010
from .types.common import AccessPermission
11-
from .types.resource.Group import ClaimReward, ClaimRewardsResponse
11+
from .types.resource.Group import (
12+
ClaimReward,
13+
ClaimRewardsResponse,
14+
CollectRoyaltiesResponse,
15+
)
1216
from .types.resource.IPAsset import (
1317
RegisterPILTermsAndAttachResponse,
1418
RegistrationResponse,
@@ -40,6 +44,7 @@
4044
"RegistrationResponse",
4145
"ClaimRewardsResponse",
4246
"ClaimReward",
47+
"CollectRoyaltiesResponse",
4348
"RegisterPILTermsAndAttachResponse",
4449
# Constants
4550
"ZERO_ADDRESS",

src/story_protocol_python_sdk/abi/GroupingModule/GroupingModule_client.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,14 @@ def build_claimReward_transaction(self, groupId, token, ipIds, tx_params):
5151
groupId, token, ipIds
5252
).build_transaction(tx_params)
5353

54+
def collectRoyalties(self, groupId, token):
55+
return self.contract.functions.collectRoyalties(groupId, token).transact()
56+
57+
def build_collectRoyalties_transaction(self, groupId, token, tx_params):
58+
return self.contract.functions.collectRoyalties(
59+
groupId, token
60+
).build_transaction(tx_params)
61+
5462
def registerGroup(self, groupPool):
5563
return self.contract.functions.registerGroup(groupPool).transact()
5664

src/story_protocol_python_sdk/resources/Group.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
from story_protocol_python_sdk.types.resource.Group import (
3030
ClaimReward,
3131
ClaimRewardsResponse,
32+
CollectRoyaltiesResponse,
3233
)
3334
from story_protocol_python_sdk.utils.constants import ZERO_ADDRESS, ZERO_HASH
3435
from story_protocol_python_sdk.utils.license_terms import LicenseTerms
@@ -597,6 +598,55 @@ def claim_rewards(
597598
except Exception as e:
598599
raise ValueError(f"Failed to claim rewards: {str(e)}")
599600

601+
def collect_royalties(
602+
self,
603+
group_ip_id: Address,
604+
currency_token: Address,
605+
tx_options: dict | None = None,
606+
) -> CollectRoyaltiesResponse:
607+
"""
608+
Collects royalties into the pool, making them claimable by group member IPs.
609+
610+
:param group_ip_id Address: The ID of the group IP.
611+
:param currency_token Address: The address of the currency (revenue) token to collect.
612+
:param tx_options dict: [Optional] The transaction options.
613+
:return CollectRoyaltiesResponse: A response object with the transaction hash and collected royalties.
614+
"""
615+
try:
616+
if not self.web3.is_address(group_ip_id):
617+
raise ValueError(f"Invalid group IP ID: {group_ip_id}")
618+
if not self.web3.is_address(currency_token):
619+
raise ValueError(f"Invalid currency token: {currency_token}")
620+
621+
response = build_and_send_transaction(
622+
self.web3,
623+
self.account,
624+
self.grouping_module_client.build_collectRoyalties_transaction,
625+
group_ip_id,
626+
currency_token,
627+
tx_options=tx_options,
628+
)
629+
630+
event_signature = self.web3.keccak(
631+
text="CollectedRoyaltiesToGroupPool(address,address,address,uint256)"
632+
).hex()
633+
634+
collected_royalties = 0
635+
for log in response["tx_receipt"]["logs"]:
636+
if log["topics"][0].hex() == event_signature:
637+
event_results = self.grouping_module_client.contract.events.CollectedRoyaltiesToGroupPool.process_log(
638+
log
639+
)
640+
collected_royalties = event_results["args"]["amount"]
641+
break
642+
643+
return CollectRoyaltiesResponse(
644+
tx_hash=response["tx_hash"],
645+
collected_royalties=collected_royalties,
646+
)
647+
except Exception as e:
648+
raise ValueError(f"Failed to collect royalties: {str(e)}")
649+
600650
def _get_license_data(self, license_data: list) -> list:
601651
"""
602652
Process license data into the format expected by the contracts.

src/story_protocol_python_sdk/scripts/config.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,8 @@
183183
"registerGroup",
184184
"addIp",
185185
"IPGroupRegistered",
186-
"claimReward"
186+
"claimReward",
187+
"collectRoyalties"
187188
]
188189
},
189190
{

src/story_protocol_python_sdk/types/resource/Group.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,12 @@ class ClaimRewardsResponse(TypedDict):
2121

2222
tx_hash: HexBytes
2323
claimed_rewards: ClaimReward
24+
25+
26+
class CollectRoyaltiesResponse(TypedDict):
27+
"""
28+
Response structure for Group.collect_royalties method.
29+
"""
30+
31+
tx_hash: HexBytes
32+
collected_royalties: int

0 commit comments

Comments
 (0)