> ## Documentation Index
> Fetch the complete documentation index at: https://docs.story.foundation/llms.txt
> Use this file to discover all available pages before exploring further.

# RoyaltyPolicyLRP

The RoyaltyPolicyLRP (Liquid Relative Percentage) contract defines the logic for splitting royalties for a given IP asset using a liquid relative percentage mechanism. It manages the royalty relationships between IP assets and their ancestors, allowing for the transfer of revenue tokens to the appropriate royalty vaults.

## State Variables

### RoyaltyPolicyLRPStorage

```solidity theme={null}
struct RoyaltyPolicyLRPStorage {
    mapping(address ipId => uint32) royaltyStackLRP;
    mapping(address ipId => mapping(address ancestorIpId => uint32)) ancestorPercentLRP;
    mapping(address ipId => mapping(address ancestorIpId => mapping(address token => uint256))) transferredTokenLRP;
}
```

Storage structure for the RoyaltyPolicyLRP containing:

* `royaltyStackLRP`: Sum of the royalty percentages to be paid to all ancestors for LRP royalty policy
* `ancestorPercentLRP`: The royalty percentage between an IP asset and a given ancestor for LRP royalty policy
* `transferredTokenLRP`: Total lifetime revenue tokens transferred to a vault from a descendant IP via LRP

### IP\_GRAPH

```solidity theme={null}
address public constant IP_GRAPH = address(0x0101)
```

The address of the IP Graph precompile contract that tracks relationships between IPs.

### ROYALTY\_MODULE

```solidity theme={null}
IRoyaltyModule public immutable ROYALTY_MODULE
```

The address of the Royalty Module contract.

### ROYALTY\_POLICY\_LAP

```solidity theme={null}
IGraphAwareRoyaltyPolicy public immutable ROYALTY_POLICY_LAP
```

The address of the RoyaltyPolicyLAP contract.

### IP\_GRAPH\_ACL

```solidity theme={null}
IPGraphACL public immutable IP_GRAPH_ACL
```

The address of the IP Graph Access Control List contract.

## Functions

### constructor

```solidity theme={null}
constructor(address royaltyModule, address royaltyPolicyLAP, address ipGraphAcl)
```

Constructor for the RoyaltyPolicyLRP contract.

**Parameters:**

* `royaltyModule`: The RoyaltyModule address
* `royaltyPolicyLAP`: The RoyaltyPolicyLAP address
* `ipGraphAcl`: The IPGraphACL address

### initialize

```solidity theme={null}
function initialize(address accessManager) external initializer
```

Initializer for this implementation contract.

**Parameters:**

* `accessManager`: The address of the protocol admin roles contract.

### onLicenseMinting

```solidity theme={null}
function onLicenseMinting(
    address ipId,
    uint32 licensePercent,
    bytes calldata
) external nonReentrant onlyRoyaltyModule
```

Executes royalty related logic on minting a license.

**Parameters:**

* `ipId`: The ipId whose license is being minted (licensor)
* `licensePercent`: The license percentage of the license being minted

### onLinkToParents

```solidity theme={null}
function onLinkToParents(
    address ipId,
    address[] calldata parentIpIds,
    address[] memory licenseRoyaltyPolicies,
    uint32[] calldata licensesPercent,
    bytes calldata
) external nonReentrant onlyRoyaltyModule returns (uint32 newRoyaltyStackLRP)
```

Executes royalty related logic on linking to parents.

**Parameters:**

* `ipId`: The children ipId that is being linked to parents
* `parentIpIds`: The parent ipIds that the children ipId is being linked to
* `licenseRoyaltyPolicies`: The royalty policies of the licenses
* `licensesPercent`: The license percentage of the licenses being minted

**Returns:**

* `newRoyaltyStackLRP`: The royalty stack of the child ipId for LRP royalty policy

### transferToVault

```solidity theme={null}
function transferToVault(
    address ipId,
    address ancestorIpId,
    address token
) external whenNotPaused returns (uint256)
```

Transfers to vault an amount of revenue tokens claimable via LRP royalty policy.

**Parameters:**

* `ipId`: The ipId of the IP asset
* `ancestorIpId`: The ancestor ipId of the IP asset
* `token`: The token address to transfer

**Returns:**

* The amount of revenue tokens transferred

### getPolicyRtsRequiredToLink

```solidity theme={null}
function getPolicyRtsRequiredToLink(address ipId, uint32 licensePercent) external view returns (uint32)
```

Returns the amount of royalty tokens required to link a child to a given IP asset.

**Parameters:**

* `ipId`: The ipId of the IP asset
* `licensePercent`: The percentage of the license

**Returns:**

* The amount of royalty tokens required to link a child to a given IP asset (always 0 for LRP)

### getPolicyRoyaltyStack

```solidity theme={null}
function getPolicyRoyaltyStack(address ipId) external view returns (uint32)
```

Returns the LRP royalty stack for a given IP asset.

**Parameters:**

* `ipId`: The ipId to get the royalty stack for

**Returns:**

* Sum of the royalty percentages to be paid to all ancestors for LRP royalty policy

### getPolicyRoyalty

```solidity theme={null}
function getPolicyRoyalty(address ipId, address ancestorIpId) external returns (uint32)
```

Returns the royalty percentage between an IP asset and its ancestors via LRP.

**Parameters:**

* `ipId`: The ipId to get the royalty for
* `ancestorIpId`: The ancestor ipId to get the royalty for

**Returns:**

* The royalty percentage between an IP asset and its ancestors via LRP

### getTransferredTokens

```solidity theme={null}
function getTransferredTokens(address ipId, address ancestorIpId, address token) external view returns (uint256)
```

Returns the total lifetime revenue tokens transferred to a vault from a descendant IP via LRP.

**Parameters:**

* `ipId`: The ipId of the IP asset
* `ancestorIpId`: The ancestor ipId of the IP asset
* `token`: The token address to transfer

**Returns:**

* The total lifetime revenue tokens transferred to a vault from a descendant IP via LRP

### isSupportGroup

```solidity theme={null}
function isSupportGroup() external view returns (bool)
```

Returns whether the royalty policy supports working with groups.

**Returns:**

* True (LRP royalty policy supports working with groups)

## Internal Functions

### \_getRoyaltyStackLRP

```solidity theme={null}
function _getRoyaltyStackLRP(address ipId) internal returns (uint32)
```

Returns the royalty stack for a given IP asset for LRP royalty policy.

**Parameters:**

* `ipId`: The ipId to get the royalty stack for

**Returns:**

* The royalty stack for a given IP asset for LRP royalty policy

### \_setRoyaltyLRP

```solidity theme={null}
function _setRoyaltyLRP(address ipId, address parentIpId, uint32 royalty) internal
```

Sets the LRP royalty for a given link between an IP asset and its ancestor.

**Parameters:**

* `ipId`: The ipId to set the royalty for
* `parentIpId`: The parent ipId to set the royalty for
* `royalty`: The LRP license royalty percentage

### \_getRoyaltyLRP

```solidity theme={null}
function _getRoyaltyLRP(address ipId, address ancestorIpId) internal returns (uint32)
```

Returns the royalty percentage between an IP asset and its ancestor via royalty policy LRP.

**Parameters:**

* `ipId`: The ipId to get the royalty for
* `ancestorIpId`: The ancestor ipId to get the royalty for

**Returns:**

* The royalty percentage between an IP asset and its ancestor via royalty policy LRP

### \_getRoyaltyPolicyLRPStorage

```solidity theme={null}
function _getRoyaltyPolicyLRPStorage() private pure returns (RoyaltyPolicyLRPStorage storage $)
```

Returns the storage struct of RoyaltyPolicyLRP.

**Returns:**

* The storage structure for the RoyaltyPolicyLRP

### \_authorizeUpgrade

```solidity theme={null}
function _authorizeUpgrade(address newImplementation) internal override restricted
```

Hook to authorize the upgrade according to UUPSUpgradeable.

**Parameters:**

* `newImplementation`: The address of the new implementation

## Events

### RevenueTransferredToVault

```solidity theme={null}
event RevenueTransferredToVault(address ipId, address ancestorIpId, address token, uint256 amount)
```

Emitted when revenue tokens are transferred to a vault.

**Parameters:**

* `ipId`: The ipId of the IP asset
* `ancestorIpId`: The ancestor ipId of the IP asset
* `token`: The token address transferred
* `amount`: The amount of tokens transferred

## Security Considerations

The RoyaltyPolicyLRP contract implements several security measures:

1. **Access Control**: Functions like `onLicenseMinting` and `onLinkToParents` can only be called by the Royalty Module through the `onlyRoyaltyModule` modifier.

2. **Reentrancy Protection**: The `nonReentrant` modifier is used on functions that handle token transfers to prevent reentrancy attacks.

3. **Pausability**: The contract can be paused in emergency situations using the `whenNotPaused` modifier.

4. **Safe Token Transfers**: The contract uses OpenZeppelin's SafeERC20 library to ensure safe token transfers.

5. **Upgradability**: The contract is upgradable using the UUPS pattern, with upgrade authorization restricted to the protocol admin.

6. **Input Validation**: The contract validates inputs and checks for edge cases, such as preventing transfers between the same IP.

## Royalty Dilution Considerations

The LRP (Liquid Relative Percentage) royalty policy allows each remixed IP to receive a percentage of the revenue generated by its direct derivatives. However, it's important to understand the potential dilution of royalties as more derivatives are created between two IPs.

This dilution can reduce the earnings of the original IP creator as more layers of derivatives are added. For example:

1. Creator 1 - Registers IP1, mints an LRP license of 10%, and sells the license to Creator 2.
2. Creator 2 - Registers IP2 as a derivative of IP1 and mints an LRP license of 20% for himself/herself.
3. Creator 2 - Registers IP3 as a derivative of IP2 and promotes IP3 commercially in the market.

The earnings for Creator 1 are diluted because they will only receive 10% of the 20% royalties from IP3, resulting in an effective royalty of 2%. If Creator 2 had chosen to promote IP2 instead, Creator 1 would have earned 10% directly, avoiding this dilution.

In contrast, the LAP (Liquid Absolute Percentage) royalty policy enforces a fixed percentage on every descendant IP, protecting the original creator from dilution.
