Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
6141772
feat: add claim rewards functionality to Group and GroupingModuleClient
bonnie57 Aug 29, 2025
68666a2
feat: add integration test for claiming rewards in Group functionality
bonnie57 Aug 29, 2025
13346e3
feat: add unit tests for Group.claim_rewards method with various scen…
bonnie57 Aug 29, 2025
8278136
feat: add claimReward function to GroupingModule in config.json
bonnie57 Aug 29, 2025
4c2b698
feat: update imports in __init__.py to include ClaimReward and Regist…
bonnie57 Aug 29, 2025
97378e6
refactor: remove debug print statements from Group and integration tests
bonnie57 Aug 29, 2025
e56a03a
Merge branch 'main' into PYSDK-46
bonnie57 Sep 1, 2025
695e9d2
refactor: update claim_rewards method in Group to enhance response st…
bonnie57 Sep 1, 2025
ce27ca2
refactor: improve claim_rewards method in Group to process logs direc…
bonnie57 Sep 2, 2025
2911569
refactor: simplify test assertions in TestGroupClaimRewards for claim…
bonnie57 Sep 2, 2025
fafe899
feat: add collect_royalties functionality to Group and GroupingModule…
bonnie57 Sep 1, 2025
63f3f1f
chore: update .gitignore to include .cursor directory
bonnie57 Sep 2, 2025
dde2284
fix: improve royalty collection logic in Group by processing logs dir…
bonnie57 Sep 2, 2025
0f00bbe
refactor: restructure integration tests for Group functionality by in…
bonnie57 Sep 2, 2025
d634f53
test: add unit tests for Group.collect_royalties method covering vari…
bonnie57 Sep 2, 2025
2fb7f21
refactor: update type hint for mint_and_register_ip_asset_with_pil_te…
bonnie57 Sep 2, 2025
441743c
Merge branch 'main' into PYSDK-47
bonnie57 Sep 3, 2025
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,4 @@ web3py.md

# AI Assistant Configuration
CLAUDE.md
.cursor/
7 changes: 6 additions & 1 deletion src/story_protocol_python_sdk/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@
from .resources.WIP import WIP
from .story_client import StoryClient
from .types.common import AccessPermission
from .types.resource.Group import ClaimReward, ClaimRewardsResponse
from .types.resource.Group import (
ClaimReward,
ClaimRewardsResponse,
CollectRoyaltiesResponse,
)
from .types.resource.IPAsset import (
RegisterPILTermsAndAttachResponse,
RegistrationResponse,
Expand Down Expand Up @@ -40,6 +44,7 @@
"RegistrationResponse",
"ClaimRewardsResponse",
"ClaimReward",
"CollectRoyaltiesResponse",
"RegisterPILTermsAndAttachResponse",
# Constants
"ZERO_ADDRESS",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ def build_claimReward_transaction(self, groupId, token, ipIds, tx_params):
groupId, token, ipIds
).build_transaction(tx_params)

def collectRoyalties(self, groupId, token):
return self.contract.functions.collectRoyalties(groupId, token).transact()

def build_collectRoyalties_transaction(self, groupId, token, tx_params):
return self.contract.functions.collectRoyalties(
groupId, token
).build_transaction(tx_params)

def registerGroup(self, groupPool):
return self.contract.functions.registerGroup(groupPool).transact()

Expand Down
50 changes: 50 additions & 0 deletions src/story_protocol_python_sdk/resources/Group.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
from story_protocol_python_sdk.types.resource.Group import (
ClaimReward,
ClaimRewardsResponse,
CollectRoyaltiesResponse,
)
from story_protocol_python_sdk.utils.constants import ZERO_ADDRESS, ZERO_HASH
from story_protocol_python_sdk.utils.license_terms import LicenseTerms
Expand Down Expand Up @@ -597,6 +598,55 @@ def claim_rewards(
except Exception as e:
raise ValueError(f"Failed to claim rewards: {str(e)}")

def collect_royalties(
self,
group_ip_id: Address,
currency_token: Address,
tx_options: dict | None = None,
) -> CollectRoyaltiesResponse:
"""
Collects royalties into the pool, making them claimable by group member IPs.

:param group_ip_id Address: The ID of the group IP.
:param currency_token Address: The address of the currency (revenue) token to collect.
:param tx_options dict: [Optional] The transaction options.
:return CollectRoyaltiesResponse: A response object with the transaction hash and collected royalties.
"""
try:
if not self.web3.is_address(group_ip_id):
raise ValueError(f"Invalid group IP ID: {group_ip_id}")
if not self.web3.is_address(currency_token):
raise ValueError(f"Invalid currency token: {currency_token}")

response = build_and_send_transaction(
self.web3,
self.account,
self.grouping_module_client.build_collectRoyalties_transaction,
group_ip_id,
currency_token,
tx_options=tx_options,
)

event_signature = self.web3.keccak(
text="CollectedRoyaltiesToGroupPool(address,address,address,uint256)"
).hex()

collected_royalties = 0
for log in response["tx_receipt"]["logs"]:
if log["topics"][0].hex() == event_signature:
event_results = self.grouping_module_client.contract.events.CollectedRoyaltiesToGroupPool.process_log(
log
)
collected_royalties = event_results["args"]["amount"]
break

return CollectRoyaltiesResponse(
tx_hash=response["tx_hash"],
collected_royalties=collected_royalties,
)
except Exception as e:
raise ValueError(f"Failed to collect royalties: {str(e)}")

def _get_license_data(self, license_data: list) -> list:
"""
Process license data into the format expected by the contracts.
Expand Down
3 changes: 2 additions & 1 deletion src/story_protocol_python_sdk/scripts/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,8 @@
"registerGroup",
"addIp",
"IPGroupRegistered",
"claimReward"
"claimReward",
"collectRoyalties"
]
},
{
Expand Down
9 changes: 9 additions & 0 deletions src/story_protocol_python_sdk/types/resource/Group.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,12 @@ class ClaimRewardsResponse(TypedDict):

tx_hash: HexBytes
claimed_rewards: ClaimReward


class CollectRoyaltiesResponse(TypedDict):
"""
Response structure for Group.collect_royalties method.
"""

tx_hash: HexBytes
collected_royalties: int
Loading
Loading