# Royalty Automation

Picardy royalty contracts have automation ability built in them, this allows easy update of royalty data on-chain using chainlink keepers and chainlink external adapters. The automation is broken into several parts.

<figure><img src="/files/0tr92E6ABCJgOLpKNd01" alt=""><figcaption></figcaption></figure>

<details>

<summary>Automated  royalty sale contract (Chainlink Automation Compatible)</summary>

This contract inherits the Chainlink Automation Compatible Interface that exposes two functions to the royalty contract *checkUpkeep()* and *performUpkeep().* This contract has to be registered for automation to work. A minimum of 4 LINK token to pay for upkeep. *Picardy automation registrar page Coming Soon.*

All automated contracts inherit the Picardy Automation Adapter Interface, which enables it to make off-chain requests for the royalty data.

</details>

<details>

<summary>External royalty adapter</summary>

This contract makes requests to the chainlink node, returns the royalty amount on-chain based on the ticker. It inherits the PayMaster contract interface that acts as a reserve for paying royalties.

### RoyaltyAdapterV2

#### addPicardyReg

```
function addPicardyReg(address _picardyReg) external
```

This function is called by the Picardy Hub Admin to add the picardyReg address

#### addValidSaleAddress

```
function addValidSaleAddress(address _royaltySaleAddress) external
```

this function is called on the registration of automation

*this function should only be called by the picardy automation Registrar*

#### checkIsValidSaleAddress

```
function checkIsValidSaleAddress(address _royaltySaleAddress) external view returns (bool)
```

this function is called to check the validity of the royalty sale address

#### requestRoyaltyAmount

```
function requestRoyaltyAmount(address _royaltySaleAddress, address _oracle, uint256 _royaltyType, string _jobId) external
```

this function is called by a valid royalty sale contract to request the royalty amount to be sent to the paymaster

*this function should only be called by a registered royalty sale contract*

#### fulfillrequestRoyaltyAmount

```
function fulfillrequestRoyaltyAmount(bytes32 _requestId, uint256 amount, address _royaltySaleAddress) public
```

this function is called by the oracle to fulfill the request and send the royalty amount to the paymaster

*this function should only be called by the oracle*

#### onTokenTransfer

```
function onTokenTransfer(address _sender, uint256 _amount, bytes _data) external
```

this is an implimentation of the ERC677 callback function for LINK token

*this function should only be called by the LINK token contrac*

#### getRoyaltyLinkBalance

```
function getRoyaltyLinkBalance(address _royaltySaleAddress) external view returns (uint256)
```

this function gets the link token balance of the royalty sale contract

#### getPicardyReg

```
function getPicardyReg() external view returns (address)
```

this function is called to get the picardy automation registrar address

#### contractBalances

```
function contractBalances() public view returns (uint256 eth, uint256 link)
```

#### getPayMaster

```
function getPayMaster() external view returns (address)
```

#### getChainlinkToken

```
function getChainlinkToken() external view returns (address)
```

#### withdrawLink

```
function withdrawLink() external
```

this function is called to withdraw LINK from the contract and should be called only by the picardy hub admin

#### adminWithdrawLink

```
function adminWithdrawLink(address _royaltyAddress) external
```

this function is called by the royalty admin to take out link balance from the contract

*this function should only be called by the royalty admin*

#### withdrawBalance

```
function withdrawBalance() external
```

this function is called to withdraw ETH from the contract and should be called only by the picardy hub admin

#### updateOraclePayment

```
function updateOraclePayment(uint256 _newPayment) external
```

ths function is called to update the oracle payment and should be called only by the picardy hub admin

#### cancelRequest

```
function cancelRequest(bytes32 _requestId, uint256 _payment, bytes4 _callbackFunctionId, uint256 _expiration) public
```

</details>

<details>

<summary>Chainlink node</summary>

Picardy Protocol will also serve as a chainlink node provider for custom royalty jobs. The chainlink node process requests, does computation and makes API calls off chain and returns the processed data on chain. This is the core of Picardy automated royalty contracts, it allows the royalty sale contracts get the royalty data on chain and updates holders royalty balance.

</details>

<details>

<summary>PayMaster</summary>

The PayMaster contract acts as a reserve for the royalty payments.&#x20;

</details>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://picardy-protocol.gitbook.io/picardy-protocol-docs/automation/royalty-automation.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
