|
29 | 29 | from story_protocol_python_sdk.types.resource.Group import ( |
30 | 30 | ClaimReward, |
31 | 31 | ClaimRewardsResponse, |
| 32 | + CollectRoyaltiesResponse, |
32 | 33 | ) |
33 | 34 | from story_protocol_python_sdk.utils.constants import ZERO_ADDRESS, ZERO_HASH |
34 | 35 | from story_protocol_python_sdk.utils.license_terms import LicenseTerms |
@@ -597,6 +598,55 @@ def claim_rewards( |
597 | 598 | except Exception as e: |
598 | 599 | raise ValueError(f"Failed to claim rewards: {str(e)}") |
599 | 600 |
|
| 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 | + |
600 | 650 | def _get_license_data(self, license_data: list) -> list: |
601 | 651 | """ |
602 | 652 | Process license data into the format expected by the contracts. |
|
0 commit comments