|
| 1 | +// SPDX-License-Identifier: MIT |
| 2 | +pragma solidity 0.8.26; |
| 3 | + |
| 4 | +import { Initializable } from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol"; |
| 5 | +import { UUPSUpgradeable } from "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol"; |
| 6 | +import { EnumerableSet } from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol"; |
| 7 | +import { ERC165Checker } from "@openzeppelin/contracts/utils/introspection/ERC165Checker.sol"; |
| 8 | + |
| 9 | +import { AccessControlledUpgradeable } from "@synaps3/primitives/upgradeable/AccessControlledUpgradeable.sol"; |
| 10 | +import { IRightsPolicyManager } from "@synaps3/interfaces/rights/IRightsPolicyManager.sol"; |
| 11 | +import { IRightsAccessAgreement } from "@synaps3/interfaces/rights/IRightsAccessAgreement.sol"; |
| 12 | + |
| 13 | +contract AgreementPortal is Initializable, UUPSUpgradeable, AccessControlledUpgradeable { |
| 14 | + /// @custom:oz-upgrades-unsafe-allow state-variable-immutable |
| 15 | + IRightsPolicyManager public immutable RIGHTS_POLICY_MANAGER; |
| 16 | + /// @custom:oz-upgrades-unsafe-allow state-variable-immutable |
| 17 | + IRightsAccessAgreement public immutable RIGHTS_AGREEMENT; |
| 18 | + |
| 19 | + /// @custom:oz-upgrades-unsafe-allow constructor |
| 20 | + constructor(address rightsPolicyManager, address rightsAgreement) { |
| 21 | + /// https://forum.openzeppelin.com/t/uupsupgradeable-vulnerability-post-mortem/15680 |
| 22 | + /// https://forum.openzeppelin.com/t/what-does-disableinitializers-function-mean/28730/5 |
| 23 | + _disableInitializers(); |
| 24 | + RIGHTS_POLICY_MANAGER = IRightsPolicyManager(rightsPolicyManager); |
| 25 | + RIGHTS_AGREEMENT = IRightsAccessAgreement(rightsAgreement); |
| 26 | + } |
| 27 | + |
| 28 | + /// @notice Initializes the proxy state. |
| 29 | + function initialize(address accessManager) public initializer { |
| 30 | + __UUPSUpgradeable_init(); |
| 31 | + __AccessControlled_init(accessManager); |
| 32 | + } |
| 33 | + |
| 34 | + function flashAgreement( |
| 35 | + uint256 amount, |
| 36 | + address holder, |
| 37 | + address currency, |
| 38 | + address policyAddress, |
| 39 | + address[] calldata parties, |
| 40 | + bytes calldata payload |
| 41 | + ) public returns (uint256) { |
| 42 | + address broker = address(RIGHTS_POLICY_MANAGER); |
| 43 | + uint256 proof = RIGHTS_AGREEMENT.createAgreement(amount, currency, broker, parties, payload); |
| 44 | + return RIGHTS_POLICY_MANAGER.registerPolicy(proof, holder, policyAddress); |
| 45 | + } |
| 46 | + |
| 47 | + /// @notice Function that should revert when msg.sender is not authorized to upgrade the contract. |
| 48 | + /// @param newImplementation The address of the new implementation contract. |
| 49 | + /// @dev See https://docs.openzeppelin.com/contracts/4.x/api/proxy#UUPSUpgradeable-_authorizeUpgrade-address- |
| 50 | + function _authorizeUpgrade(address newImplementation) internal override onlyAdmin {} |
| 51 | +} |
0 commit comments