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
28 changes: 3 additions & 25 deletions src/story_protocol_python_sdk/resources/Group.py
Original file line number Diff line number Diff line change
Expand Up @@ -547,34 +547,12 @@ def _get_license_data(self, license_data: list) -> list:
f'License template address "{license_template}" is invalid.'
)

# Validate licensing config
licensing_config = item.get("licensing_config", {})

try:
self.license_terms_util.validate_licensing_config(licensing_config)
except Exception as e:
raise ValueError(f"Licensing config validation failed: {str(e)}")

# Convert to camelCase for contract interaction
camelcase_config = {
"isSet": licensing_config.get("is_set", True),
"mintingFee": licensing_config.get("minting_fee", 0),
"hookData": licensing_config.get("hook_data", ZERO_ADDRESS),
"licensingHook": licensing_config.get("licensing_hook", ZERO_ADDRESS),
"commercialRevShare": licensing_config.get("commercial_rev_share", 0),
"disabled": licensing_config.get("disabled", False),
"expectMinimumGroupRewardShare": licensing_config.get(
"expect_minimum_group_reward_share", 0
),
"expectGroupRewardPool": licensing_config.get(
"expect_group_reward_pool", ZERO_ADDRESS
),
}

processed_item = {
"licenseTemplate": license_template,
"licenseTermsId": item["license_terms_id"],
"licensingConfig": camelcase_config,
"licensingConfig": self.license_terms_util.validate_licensing_config(
item.get("licensing_config", {})
),
}

result.append(processed_item)
Expand Down
123 changes: 22 additions & 101 deletions src/story_protocol_python_sdk/resources/IPAsset.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Module for handling IP Account operations and transactions."""

from ens.ens import HexStr
from web3 import Web3

from story_protocol_python_sdk.abi.AccessController.AccessController_client import (
Expand Down Expand Up @@ -173,7 +174,7 @@ def register(
signature_response = self.sign_util.get_permission_signature(
ip_id=ip_id,
deadline=calculated_deadline,
state=self.web3.to_bytes(hexstr=ZERO_HASH),
state=self.web3.to_bytes(hexstr=HexStr(ZERO_HASH)),
permissions=[
{
"ipId": ip_id,
Expand Down Expand Up @@ -366,7 +367,7 @@ def mint_and_register_ip_asset_with_pil_terms(
:param commercializer_checker str: Allowed commercializers or zero
address for none.
:param commercializer_checker_data str: Data for checker contract.
:param commercial_rev_share int: Revenue share percentage.
:param commercial_rev_share int: The commercial revenue share percentage (from 0 to 100%, represented as 100_000_000).
:param commercial_rev_ceiling int: Maximum commercial revenue.
:param derivatives_allowed bool: Whether derivatives are allowed.
:param derivatives_attribution bool: Whether attribution is needed
Expand All @@ -384,10 +385,10 @@ def mint_and_register_ip_asset_with_pil_terms(
:param hook_data str: The data used by the licensing hook.
:param licensing_hook str: The licensing hook contract address or
address(0) if none.
:param commercial_rev_share int: Commercial revenue share percent.
:param commercial_rev_share int: The commercial revenue share percentage (from 0 to 100%, represented as 100_000_000).
:param disabled bool: Whether the license is disabled.
:param expect_minimum_group_reward_share int: Minimum group reward
share (0-100%, as 100 * 10^6).
share percentage (from 0 to 100%, represented as 100_000_000).
:param expect_group_reward_pool str: Address of the expected group
reward pool.
:param ip_metadata dict: [Optional] NFT and IP metadata.
Expand All @@ -405,57 +406,17 @@ def mint_and_register_ip_asset_with_pil_terms(
raise ValueError(
f"The NFT contract address {spg_nft_contract} is not valid."
)

license_terms = []
for term in terms:
self.license_terms_util.validate_license_terms(term["terms"])
validated_licensing_config = (
self.license_terms_util.validate_licensing_config(
term["licensing_config"]
)
)

camelcase_term = {
"transferable": term["terms"]["transferable"],
"royaltyPolicy": term["terms"]["royalty_policy"],
"defaultMintingFee": term["terms"]["default_minting_fee"],
"expiration": term["terms"]["expiration"],
"commercialUse": term["terms"]["commercial_use"],
"commercialAttribution": term["terms"]["commercial_attribution"],
"commercializerChecker": term["terms"]["commercializer_checker"],
"commercializerCheckerData": term["terms"][
"commercializer_checker_data"
],
"commercialRevShare": term["terms"]["commercial_rev_share"],
"commercialRevCeiling": term["terms"]["commercial_rev_ceiling"],
"derivativesAllowed": term["terms"]["derivatives_allowed"],
"derivativesAttribution": term["terms"]["derivatives_attribution"],
"derivativesApproval": term["terms"]["derivatives_approval"],
"derivativesReciprocal": term["terms"]["derivatives_reciprocal"],
"derivativeRevCeiling": term["terms"]["derivative_rev_ceiling"],
"currency": term["terms"]["currency"],
"uri": term["terms"]["uri"],
}

camelcase_config = {
"isSet": validated_licensing_config["is_set"],
"mintingFee": validated_licensing_config["minting_fee"],
"hookData": validated_licensing_config["hook_data"],
"licensingHook": validated_licensing_config["licensing_hook"],
"commercialRevShare": validated_licensing_config[
"commercial_rev_share"
],
"disabled": validated_licensing_config["disabled"],
"expectMinimumGroupRewardShare": validated_licensing_config[
"expect_minimum_group_reward_share"
],
"expectGroupRewardPool": validated_licensing_config[
"expect_group_reward_pool"
],
}

license_terms.append(
{"terms": camelcase_term, "licensingConfig": camelcase_config}
{
"terms": self.license_terms_util.validate_license_terms(
term["terms"]
),
"licensingConfig": self.license_terms_util.validate_licensing_config(
term["licensing_config"]
),
}
)

metadata = {
Expand Down Expand Up @@ -632,57 +593,17 @@ def register_ip_and_attach_pil_terms(
raise ValueError(
f"The NFT with id {token_id} is already registered as IP."
)

license_terms = []
for term in license_terms_data:
self.license_terms_util.validate_license_terms(term["terms"])
validated_licensing_config = (
self.license_terms_util.validate_licensing_config(
term["licensing_config"]
)
)

camelcase_term = {
"transferable": term["terms"]["transferable"],
"royaltyPolicy": term["terms"]["royalty_policy"],
"defaultMintingFee": term["terms"]["default_minting_fee"],
"expiration": term["terms"]["expiration"],
"commercialUse": term["terms"]["commercial_use"],
"commercialAttribution": term["terms"]["commercial_attribution"],
"commercializerChecker": term["terms"]["commercializer_checker"],
"commercializerCheckerData": term["terms"][
"commercializer_checker_data"
],
"commercialRevShare": term["terms"]["commercial_rev_share"],
"commercialRevCeiling": term["terms"]["commercial_rev_ceiling"],
"derivativesAllowed": term["terms"]["derivatives_allowed"],
"derivativesAttribution": term["terms"]["derivatives_attribution"],
"derivativesApproval": term["terms"]["derivatives_approval"],
"derivativesReciprocal": term["terms"]["derivatives_reciprocal"],
"derivativeRevCeiling": term["terms"]["derivative_rev_ceiling"],
"currency": term["terms"]["currency"],
"uri": term["terms"]["uri"],
}

camelcase_config = {
"isSet": validated_licensing_config["is_set"],
"mintingFee": validated_licensing_config["minting_fee"],
"hookData": validated_licensing_config["hook_data"],
"licensingHook": validated_licensing_config["licensing_hook"],
"commercialRevShare": validated_licensing_config[
"commercial_rev_share"
],
"disabled": validated_licensing_config["disabled"],
"expectMinimumGroupRewardShare": validated_licensing_config[
"expect_minimum_group_reward_share"
],
"expectGroupRewardPool": validated_licensing_config[
"expect_group_reward_pool"
],
}

license_terms.append(
{"terms": camelcase_term, "licensingConfig": camelcase_config}
{
"terms": self.license_terms_util.validate_license_terms(
term["terms"]
),
"licensingConfig": self.license_terms_util.validate_licensing_config(
term["licensing_config"]
),
}
)

calculated_deadline = self.sign_util.get_deadline(deadline=deadline)
Expand All @@ -691,7 +612,7 @@ def register_ip_and_attach_pil_terms(
signature_response = self.sign_util.get_permission_signature(
ip_id=ip_id,
deadline=calculated_deadline,
state=self.web3.to_bytes(hexstr=ZERO_HASH),
state=self.web3.to_bytes(hexstr=HexStr(ZERO_HASH)),
permissions=[
{
"ipId": ip_id,
Expand Down
63 changes: 21 additions & 42 deletions src/story_protocol_python_sdk/resources/License.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,48 +99,27 @@ def register_pil_terms(
:return dict: A dictionary with the transaction hash and license terms ID.
"""
try:
license_terms = {
"transferable": transferable,
"royaltyPolicy": royalty_policy,
"defaultMintingFee": default_minting_fee,
"expiration": expiration,
"commercialUse": commercial_use,
"commercialAttribution": commercial_attribution,
"commercializerChecker": commercializer_checker,
"commercializerCheckerData": commercializer_checker_data,
"commercialRevShare": commercial_rev_share,
"commercialRevCeiling": commercial_rev_ceiling,
"derivativesAllowed": derivatives_allowed,
"derivativesAttribution": derivatives_attribution,
"derivativesApproval": derivatives_approval,
"derivativesReciprocal": derivatives_reciprocal,
"derivativeRevCeiling": derivative_rev_ceiling,
"currency": currency,
"uri": uri,
}

license_terms_snake = {
"transferable": transferable,
"royalty_policy": royalty_policy,
"default_minting_fee": default_minting_fee,
"expiration": expiration,
"commercial_use": commercial_use,
"commercial_attribution": commercial_attribution,
"commercializer_checker": commercializer_checker,
"commercializer_checker_data": commercializer_checker_data,
"commercial_rev_share": commercial_rev_share,
"commercial_rev_ceiling": commercial_rev_ceiling,
"derivatives_allowed": derivatives_allowed,
"derivatives_attribution": derivatives_attribution,
"derivatives_approval": derivatives_approval,
"derivatives_reciprocal": derivatives_reciprocal,
"derivative_rev_ceiling": derivative_rev_ceiling,
"currency": currency,
"uri": uri,
}

# Validate the license terms
self.license_terms_util.validate_license_terms(license_terms_snake)
license_terms = self.license_terms_util.validate_license_terms(
{
"transferable": transferable,
"royalty_policy": royalty_policy,
"default_minting_fee": default_minting_fee,
"expiration": expiration,
"commercial_use": commercial_use,
"commercial_attribution": commercial_attribution,
"commercializer_checker": commercializer_checker,
"commercializer_checker_data": commercializer_checker_data,
"commercial_rev_share": commercial_rev_share,
"commercial_rev_ceiling": commercial_rev_ceiling,
"derivatives_allowed": derivatives_allowed,
"derivatives_attribution": derivatives_attribution,
"derivatives_approval": derivatives_approval,
"derivatives_reciprocal": derivatives_reciprocal,
"derivative_rev_ceiling": derivative_rev_ceiling,
"currency": currency,
"uri": uri,
}
)

license_terms_id = self._get_license_terms_id(license_terms)
if (license_terms_id is not None) and (license_terms_id != 0):
Expand Down
7 changes: 4 additions & 3 deletions src/story_protocol_python_sdk/types/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@


class RevShareType(Enum):
COMMERCIAL_REVENUE_SHARE = "commercialRevShare"
MAX_REVENUE_SHARE = "maxRevenueShare"
MAX_ALLOWED_REWARD_SHARE = "maxAllowedRewardShare"
COMMERCIAL_REVENUE_SHARE = "commercial_rev_share"
MAX_REVENUE_SHARE = "max_revenue_share"
MAX_ALLOWED_REWARD_SHARE = "max_allowed_reward_share"
EXPECT_MINIMUM_GROUP_REWARD_SHARE = "expect_minimum_group_reward_share"


class AccessPermission(Enum):
Expand Down
6 changes: 1 addition & 5 deletions src/story_protocol_python_sdk/utils/constants.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
from eth_typing import HexStr

ZERO_ADDRESS = "0x0000000000000000000000000000000000000000"
ZERO_HASH: HexStr = HexStr(
"0x0000000000000000000000000000000000000000000000000000000000000000"
)
ZERO_HASH = "0x0000000000000000000000000000000000000000000000000000000000000000"
ZERO_FUNC = "0x00000000"
DEFAULT_FUNCTION_SELECTOR = "0x00000000"
MAX_ROYALTY_TOKEN = 100000000
Expand Down
Loading
Loading