all files / contracts/utils/ PolicyDescriptorV2.sol

100% Statements 7/7
100% Branches 0/0
100% Functions 4/4
100% Lines 7/7
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59                                                                                                    12×    
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity 0.8.6;
 
import "@openzeppelin/contracts/utils/Strings.sol";
import "../utils/Governable.sol";
import "../interfaces/risk/IPolicyManager.sol";
import "../interfaces/utils/IPolicyDescriptorV2.sol";
 
/**
 * @title PolicyDescriptor
 * @author solace.fi
 * @notice Produces a string containing the data URI for a JSON metadata string of a policy.
 * It is inspired from Uniswap V3 [`NonfungibleTokenPositionDescriptor`](https://docs.uniswap.org/protocol/reference/periphery/NonfungibleTokenPositionDescriptor).
 */
contract PolicyDescriptorV2 is IPolicyDescriptorV2, Governable {
 
    string _baseUri;
 
    /**
     * @notice Constructs the policy descriptor contract.
     * @param governance_ The address of the [governor](/docs/protocol/governance).
     */
    //constructor(address governance_, string memory base) Governable(governance_) {
        //_baseUri = base;
    constructor(address governance_) Governable(governance_) {
        string memory base = string(abi.encodePacked("https://paclas.solace.fi/policy/?chainid=", Strings.toString(block.chainid), "&policyid="));
        _baseUri = base;
        emit BaseUriSet(base);
    }
 
    /**
     * @notice Describes a policy.
     * @param policyManager The policy manager to retrieve policy info to produce URI description.
     * @param policyID The ID of the policy for which to produce a description.
     * @return description The URI of the ERC721-compliant metadata.
     */
    // solhint-disable-next-line no-unused-vars
    function tokenURI(IPolicyManager policyManager, uint256 policyID) external view override returns (string memory description) {
        return string(abi.encodePacked(_baseUri, Strings.toString(policyID)));
    }
 
    /**
     * @notice Returns the base of the URI descriptor.
     * @return base The base URI of the ERC721-compliant metadata.
     */
    function baseURI() external view override returns (string memory base) {
        return _baseUri;
    }
 
    /**
     * @notice Sets the base URI descriptor.
     * Can only be called by the current [**governor**](/docs/protocol/governance).
     * @param base The new base URI.
     */
    function setBaseURI(string calldata base) external override onlyGovernance {
        _baseUri = base;
        emit BaseUriSet(base);
    }
}