# ProtocolOwner

The ProtocolOwner contract handles protocol-level functions and permissions within the Unlockd Wallet. It allows authorized protocol owners to execute specific actions and interacts with the TransactionGuard and DelegationOwner contracts.&#x20;

## Key Functions:

```solidity
function initialize(
    address _guard, 
    address _safe, 
    address _owner, 
    address _delegationOwner
) public
```

Initializes the ProtocolOwner contract with the necessary parameters.

### Parameters:

`_guard` (address): The address of the TransactionGuard contract.

`_safe` (address): The address of the GnosisSafe contract.

`_owner` (address): The address of the wallet owner.

`_delegationOwner` (address): The address of the DelegationOwner contract.

***

```solidity
function approveSale(
    address _collection, 
    uint256 _tokenId, 
    address _underlyingAsset, 
    uint256 _amount, 
    address _marketApproval, 
    bytes32 _loanId
) external;
```

Approves the sale of an asset and transfers the necessary approvals and permissions.

### Parameters:

`_collection` (address): The address of the asset collection.

`_tokenId` (uint256): The ID of the asset being sold.

`_underlyingAsset` (address): The address of the underlying asset.

`_amount` (uint256): The amount to be approved.

`_marketApproval` (address): The address of the market approval contract.

`_loanId` (bytes32): The ID of the loan associated with the sale.

***

```solidity
function execTransaction(
    address _to, 
    uint256 _value, 
    bytes calldata _data, 
    uint256 _safeTxGas, 
    uint256 _baseGas, 
    uint256 _gasPrice, 
    address _gasToken, 
    address payable _refundReceiver
) external returns (bool success)
```

Executes a transaction through the GnosisSafe wallet with protocol-level permissions.

### Parameters:

`_to` (address): The destination address of the transaction.

`_value` (uint256): The amount of ETH to be sent with the transaction.

`_data` (bytes): The data payload of the transaction.

`_safeTxGas` (uint256): The gas limit for the transaction.

`_baseGas` (uint256): The base gas cost.

`_gasPrice` (uint256): The gas price used for the transaction.

`_gasToken` (address): The address of the token used for gas payment (0 for ETH).

`_refundReceiver` (address payable): The address that receives the gas payment refund.

### Returns:

A boolean indicating the success of the transaction execution.

***

```solidity
function delegateOneExecution(
    address to, 
    bool value
) external;
```

Delegates the execution permission to a specified address for a single transaction.

### Parameters:

`to` (address): The address to delegate the execution permission to.

`value` (bool): Indicates whether to grant or revoke the execution permission.

***

```solidity
function isDelegatedExecution(
    address to
) external view returns (bool);
```

&#x20;Checks if an address has delegated execution permission.

### Parameters:

`to` (address): The address to check for delegated execution permission.&#x20;

### Returns:

(bool): Indicates whether the address has delegated execution permission or not.

***

```solidity
function isAssetLocked(
    bytes32 _id
) external view returns (bool);
```

Checks if an asset is locked.

### Parameters:

`_id` (bytes32): The ID of the asset.&#x20;

### Returns:

(bool): Indicates whether the asset is locked or not.

***

```solidity
function getLoanId(
    bytes32 index
) external view returns (bytes32);
```

Returns the loan ID assigned to a specific asset.

### Parameters:

`index` (bytes32): The index of the asset.&#x20;

### Returns:

(bytes32): The loan ID assigned to the asset.

***

```solidity
function setLoanId(
    bytes32 _index, 
    bytes32 _loanId
) external;
```

Sets the loan ID assigned to a specific asset.

### Parameters:

`_index` (bytes32): The index of the asset.

`_loanId` (bytes32): The loan ID to be assigned.

***

```solidity
function safeSetLoanId(
    address _asset, 
    uint256 _id, 
    bytes32 _loanId
) external;
```

Safely sets the loan ID assigned to a specific asset and resets approvals.

### Parameters:

`_asset` (address): The address of the asset.

`_id` (uint256): The ID of the asset.

`_loanId` (bytes32): The loan ID to be assigned.

***

```solidity
function changeOwner(
    address _asset, 
    uint256 _id, 
    address _newOwner
) external;
```

Changes the current ownership of an asset.

### Parameters:

`_asset` (address): The address of the asset.

`_id` (uint256): The ID of the asset.

`_newOwner` (address): The address of the new owner.

***

```solidity
function batchSetToZeroLoanId(
    bytes32[] calldata _assets
) external;
```

Batch function to set loan IDs to zero for a group of assets.

### Parameters:

`_assets` (bytes32\[]): An array of asset IDs.

***

```solidity
function batchSetLoanId(
    bytes32[] calldata _assets, 
    bytes32 _loanId
) external;
```

Batch function to set loan IDs to a specific value for a group of assets.

### Parameters:

`_assets` (bytes32\[]): An array of asset IDs.

`_loanId` (bytes32): The loan ID to be assigned.

***

## Interactions:

* Interacts with the TransactionGuard contract to enforce protocol-level rules and permissions.
* Interacts with the DelegationOwner contract to perform protocol-specific actions.
