Skip to content
Merged
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
59 changes: 22 additions & 37 deletions src/story_protocol_python_sdk/resources/Group.py
Original file line number Diff line number Diff line change
Expand Up @@ -543,9 +543,9 @@ def claim_rewards(
"""
Claim rewards for the entire group.

:param group_ip_id str: The ID of the group IP.
:param currency_token str: The address of the currency (revenue) token to claim..
:param member_ip_ids list: The IDs of the member IPs to distribute the rewards to.
:param group_ip_id Address: The ID of the group IP.
:param currency_token Address: The address of the currency (revenue) token to claim.
:param member_ip_ids list[Address]: The IDs of the member IPs to distribute the rewards to.
:param tx_options dict: [Optional] The transaction options.
:return ClaimRewardsResponse: A response object with the transaction hash and claimed rewards.
"""
Expand All @@ -571,14 +571,27 @@ def claim_rewards(
*claim_reward_param.values(),
tx_options=tx_options,
)

claimed_rewards = self._parse_tx_claimed_reward_event(
response["tx_receipt"]
)

event_signature = self.web3.keccak(
text="ClaimedReward(address,address,address[],uint256[])"
).hex()
claimed_rewards = None
for log in response["tx_receipt"]["logs"]:
if log["topics"][0].hex() == event_signature:
event_result = self.grouping_module_client.contract.events.ClaimedReward.process_log(
log
)
claimed_rewards = event_result["args"]
break
if not claimed_rewards:
raise ValueError("Not found ClaimedReward event in transaction logs.")
return ClaimRewardsResponse(
tx_hash=response["tx_hash"],
claimed_rewards=claimed_rewards,
claimed_rewards=ClaimReward(
ip_ids=claimed_rewards["ipId"],
amounts=claimed_rewards["amount"],
token=claimed_rewards["token"],
group_id=claimed_rewards["groupId"],
),
)

except Exception as e:
Expand Down Expand Up @@ -748,31 +761,3 @@ def _parse_tx_royalty_paid_event(self, tx_receipt: dict) -> list:
)

return royalties_distributed

def _parse_tx_claimed_reward_event(self, tx_receipt: dict) -> list[ClaimReward]:
"""
Parse the ClaimedReward event from a transaction receipt.

:param tx_receipt dict: The transaction receipt.
:return list: List of claimed rewards.
"""
event_signature = self.web3.keccak(
text="ClaimedReward(address,address,address,uint256)"
).hex()
claimed_rewards = []

for log in tx_receipt["logs"]:
if log["topics"][0].hex() == event_signature:
ip_id = "0x" + log["topics"][0].hex()[24:]
amount = int(log["data"][:66].hex(), 16)
token = "0x" + log["topics"][2].hex()[24:]

claimed_rewards.append(
ClaimReward(
ip_id=ip_id,
amount=amount,
token=token,
)
)

return claimed_rewards
11 changes: 6 additions & 5 deletions src/story_protocol_python_sdk/types/resource/Group.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
from typing import TypedDict

from ens.ens import Address, HexStr
from ens.ens import Address, HexBytes


class ClaimReward(TypedDict):
"""
Structure for a claimed reward.
"""

ip_id: Address
amount: int
ip_ids: list[Address]
amounts: list[int]
token: Address
group_id: Address


class ClaimRewardsResponse(TypedDict):
"""
Response structure for Group.claim_rewards method.
"""

tx_hash: HexStr
claimed_rewards: list[ClaimReward]
tx_hash: HexBytes
claimed_rewards: ClaimReward
16 changes: 5 additions & 11 deletions tests/integration/test_integration_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -549,22 +549,16 @@ def test_claim_rewards(self, story_client: StoryClient, setup_royalty_collection
story_client.Group.collect_and_distribute_group_royalties(
group_ip_id=group_ip_id, currency_tokens=[MockERC20], member_ip_ids=ip_ids
)

# Test claiming rewards for specific members
response = story_client.Group.claim_rewards(
group_ip_id=group_ip_id,
currency_token=MockERC20,
member_ip_ids=ip_ids,
)
# Verify response structure
assert "tx_hash" in response
assert isinstance(response["tx_hash"], str)
assert len(response["tx_hash"]) > 0

# Verify claimed rewards details if any are present
if response["claimed_rewards"]:
for reward in response["claimed_rewards"]:
assert "amount" in reward
assert isinstance(reward["amount"], int)
assert "token" in reward
assert story_client.web3.is_address(reward["token"])
assert "claimed_rewards" in response
assert len(response["claimed_rewards"]["ip_ids"]) == 2
assert len(response["claimed_rewards"]["amounts"]) == 2
assert response["claimed_rewards"]["token"] == MockERC20
assert response["claimed_rewards"]["group_id"] == group_ip_id
Loading
Loading