// "SPDX-License-Identifier: Apache-2.0" pragma solidity ^0.6.11; pragma experimental ABIEncoderV2; import "@atpar/actus-solidity/contracts/Engines/CERTF/ICERTFEngine.sol"; import "../Base/AssetActor/BaseActor.sol"; import "./ICERTFRegistry.sol"; /** * @title CERTFActor * @notice TODO */ contract CERTFActor is BaseActor { constructor(IAssetRegistry assetRegistry, IDataRegistry dataRegistry) public BaseActor(assetRegistry, dataRegistry) {} /** * @notice Derives initial state of the asset terms and stores together with * terms, schedule, ownership, engine, admin of the asset in the contract types specific AssetRegistry. * @param terms asset specific terms * @param schedule schedule of the asset * @param ownership ownership of the asset * @param engine address of the ACTUS engine used for the spec. ContractType * @param admin address of the admin of the asset (optional) */ function initialize( CERTFTerms calldata terms, bytes32[] calldata schedule, AssetOwnership calldata ownership, address engine, address admin ) external { require( engine != address(0) && IEngine(engine).contractType() == ContractType.CERTF, "CERTFActor.initialize: CONTRACT_TYPE_OF_ENGINE_UNSUPPORTED" ); // solium-disable-next-line bytes32 assetId = keccak256(abi.encode(terms, block.timestamp)); // compute the initial state of the asset State memory initialState = ICERTFEngine(engine).computeInitialState(terms); // register the asset in the AssetRegistry ICERTFRegistry(address(assetRegistry)).registerAsset( assetId, terms, initialState, schedule, ownership, engine, address(this), admin ); emit InitializedAsset(assetId, ContractType.CEG, ownership.creatorObligor, ownership.counterpartyObligor); } function computeStateAndPayoffForEvent(bytes32 assetId, State memory state, bytes32 _event) internal view override returns (State memory, int256) { address engine = assetRegistry.getEngine(assetId); CERTFTerms memory terms = ICERTFRegistry(address(assetRegistry)).getTerms(assetId); (EventType eventType, uint256 scheduleTime) = decodeEvent(_event); int256 payoff = ICERTFEngine(engine).computePayoffForEvent( terms, state, _event, getExternalDataForPOF( assetId, eventType, shiftCalcTime(scheduleTime, terms.businessDayConvention, terms.calendar, terms.maturityDate) ) ); state = ICERTFEngine(engine).computeStateForEvent( terms, state, _event, getExternalDataForSTF( assetId, eventType, shiftCalcTime(scheduleTime, terms.businessDayConvention, terms.calendar, terms.maturityDate) ) ); return (state, payoff); } }