Skip to content
This repository has been archived by the owner on Aug 6, 2021. It is now read-only.

Commit

Permalink
Merge 374d0c3 into 6734253
Browse files Browse the repository at this point in the history
  • Loading branch information
jo-es committed Jun 30, 2020
2 parents 6734253 + 374d0c3 commit 6e7a893
Show file tree
Hide file tree
Showing 51 changed files with 2,049 additions and 126 deletions.
34 changes: 26 additions & 8 deletions packages/actus-solidity/contracts/Core/Utils/CycleUtils.sol
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,13 @@ contract CycleUtils is ACTUSConstants, PeriodUtils {
}

/**
* This function computes an array of UNIX timestamps that
* represent dates in a cycle falling within a given segment.
* Computes an array of timestamps that represent dates in a cycle falling within a given segment.
* @dev There are some notable edge cases: If the cycle is "not set" we return the start end end dates
* of the cycle if they lie within the segment. Otherwise and empty array is returned.
* @param cycleStart the start time of the cycle
* @param cycleEnd the end time of the cycle
* @param cycle struct that describe sthe cycle
* @param addEndTime specifies if the timestamp of the end of the cycle should be added to the result if it falls in the segment
* @param cycleStart start time of the cycle
* @param cycleEnd end time of the cycle
* @param cycle IPS cycle
* @param addEndTime timestamp of the end of the cycle should be added to the result if it falls in the segment
* @param segmentStart start time of the segment
* @param segmentEnd end time of the segment
* @return an array of timestamps from the given cycle that fall within the specified segement
Expand Down Expand Up @@ -102,9 +101,7 @@ contract CycleUtils is ACTUSConstants, PeriodUtils {

cycleIndex++;


date = getNextCycleDate(cycle, cycleStart, cycleIndex);

}

// add additional time at the end if addEndTime
Expand All @@ -126,6 +123,27 @@ contract CycleUtils is ACTUSConstants, PeriodUtils {
}

/**
* Computes the next date for a given an IPS cycle.
* @param cycle IPS cycle
* @param precedingDate the previous date of the cycle
* @return next date of the cycle
*/
function computeNextCycleDateFromPrecedingDate(
IPS memory cycle,
uint256 precedingDate
)
internal
pure
returns (uint256)
{
if (cycle.isSet == false) {
return 0;
}

return getNextCycleDate(cycle, precedingDate, 1);
}

/*
* @notice Checks if a timestamp is in a given range.
*/
function isInSegment(
Expand Down
76 changes: 76 additions & 0 deletions packages/actus-solidity/contracts/Engines/ANN/ANNEngine.sol
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,82 @@ contract ANNEngine is Core, ANNSTF, ANNPOF, IANNEngine {
return schedule;
}

/**
* @notice Computes a schedule segment of cyclic contract events based on the contract terms
* and the specified timestamps.
* @param terms terms of the contract
* @param lastScheduleTime last occurrence of cyclic event
* @param eventType eventType of the cyclic schedule
* @return event schedule segment
*/
function computeNextCyclicEvent(
ANNTerms calldata terms,
uint256 lastScheduleTime,
EventType eventType
)
external
pure
override
returns(bytes32)
{
// IP
if (eventType == EventType.IP) {
// interest payment related (starting with PRANX interest is paid following the PR schedule)
if (
terms.cycleOfInterestPayment.isSet == true && terms.cycleAnchorDateOfInterestPayment != 0) {
uint256 nextInterestPaymentDate = computeNextCycleDateFromPrecedingDate(
terms.cycleOfInterestPayment,
(lastScheduleTime == 0) ? terms.cycleAnchorDateOfInterestPayment : lastScheduleTime
);
if (nextInterestPaymentDate == 0) return bytes32(0);
if (nextInterestPaymentDate <= terms.capitalizationEndDate) return bytes32(0);
return encodeEvent(EventType.IP, nextInterestPaymentDate);
}
}

// IPCI
if (eventType == EventType.IPCI) {
if (
terms.cycleOfInterestPayment.isSet == true
&& terms.cycleAnchorDateOfInterestPayment != 0
&& terms.capitalizationEndDate != 0
) {
IPS memory cycleOfInterestCapitalization = terms.cycleOfInterestPayment;
cycleOfInterestCapitalization.s = S.SHORT;
uint256 nextInterestCapitalizationDate = computeNextCycleDateFromPrecedingDate(
cycleOfInterestCapitalization,
(lastScheduleTime == 0) ? terms.cycleAnchorDateOfInterestPayment : lastScheduleTime
);
if (nextInterestCapitalizationDate == 0) return bytes32(0);
return encodeEvent(EventType.IPCI, nextInterestCapitalizationDate);
}
}

// fees
if (eventType == EventType.FP) {
if (terms.cycleOfFee.isSet == true && terms.cycleAnchorDateOfFee != 0) {
uint256 nextFeeDate = computeNextCycleDateFromPrecedingDate(
terms.cycleOfFee,
(lastScheduleTime == 0) ? terms.cycleAnchorDateOfFee : lastScheduleTime
);
if (nextFeeDate == 0) return bytes32(0);
return encodeEvent(EventType.FP, nextFeeDate);
}
}

// principal redemption
if (eventType == EventType.PR) {
uint256 nextPrincipalRedemptionDate = computeNextCycleDateFromPrecedingDate(
terms.cycleOfPrincipalRedemption,
(lastScheduleTime == 0) ? terms.cycleAnchorDateOfPrincipalRedemption : lastScheduleTime
);
if (nextPrincipalRedemptionDate == 0) return bytes32(0);
return encodeEvent(EventType.PR, nextPrincipalRedemptionDate);
}

return bytes32(0);
}

/**
* @notice Verifies that the provided event is still scheduled under the terms, the current state of the
* contract and the current state of the underlying.
Expand Down
17 changes: 17 additions & 0 deletions packages/actus-solidity/contracts/Engines/ANN/IANNEngine.sol
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,23 @@ interface IANNEngine is IEngine {
pure
returns (bytes32[] memory);

/**
* @notice Computes a schedule segment of cyclic contract events based on the contract terms
* and the specified timestamps.
* @param terms terms of the contract
* @param lastScheduleTime last occurrence of cyclic event
* @param eventType eventType of the cyclic schedule
* @return event schedule segment
*/
function computeNextCyclicEvent(
ANNTerms calldata terms,
uint256 lastScheduleTime,
EventType eventType
)
external
pure
returns(bytes32);

/**
* @notice Computes a schedule segment of cyclic contract events based on the contract terms
* and the specified timestamps.
Expand Down
21 changes: 21 additions & 0 deletions packages/actus-solidity/contracts/Engines/CEC/CECEngine.sol
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,27 @@ contract CECEngine is Core, CECSTF, CECPOF, ICECEngine {
return schedule;
}

/**
* @notice Computes a schedule segment of cyclic contract events based on the contract terms
* and the specified timestamps.
* @param terms terms of the contract
* @param lastScheduleTime last occurrence of cyclic event
* @param eventType eventType of the cyclic schedule
* @return event schedule segment
*/
function computeNextCyclicEvent(
CECTerms calldata terms,
uint256 lastScheduleTime,
EventType eventType
)
external
pure
override
returns(bytes32)
{
return bytes32(0);
}

/**
* @notice Verifies that the provided event is still scheduled under the terms, the current state of the
* contract and the current state of the underlying.
Expand Down
17 changes: 17 additions & 0 deletions packages/actus-solidity/contracts/Engines/CEC/ICECEngine.sol
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,23 @@ interface ICECEngine is IEngine {
pure
returns (bytes32[] memory);

/**
* @notice Computes a schedule segment of cyclic contract events based on the contract terms
* and the specified timestamps.
* @param terms terms of the contract
* @param lastScheduleTime last occurrence of cyclic event
* @param eventType eventType of the cyclic schedule
* @return event schedule segment
*/
function computeNextCyclicEvent(
CECTerms calldata terms,
uint256 lastScheduleTime,
EventType eventType
)
external
pure
returns(bytes32);

/**
* @notice Verifies that the provided event is still scheduled under the terms, the current state of the
* contract and the current state of the underlying.
Expand Down
33 changes: 33 additions & 0 deletions packages/actus-solidity/contracts/Engines/CEG/CEGEngine.sol
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,39 @@ contract CEGEngine is Core, CEGSTF, CEGPOF, ICEGEngine {
return schedule;
}

/**
* @notice Computes a schedule segment of cyclic contract events based on the contract terms
* and the specified timestamps.
* @param terms terms of the contract
* @param lastScheduleTime last occurrence of cyclic event
* @param eventType eventType of the cyclic schedule
* @return event schedule segment
*/
function computeNextCyclicEvent(
CEGTerms calldata terms,
uint256 lastScheduleTime,
EventType eventType
)
external
pure
override
returns(bytes32)
{
if (eventType == EventType.FP) {
// fees
if (terms.cycleOfFee.isSet == true && terms.cycleAnchorDateOfFee != 0) {
uint256 nextFeeDate = computeNextCycleDateFromPrecedingDate(
terms.cycleOfFee,
(lastScheduleTime == 0) ? terms.cycleAnchorDateOfFee : lastScheduleTime
);
if (nextFeeDate == 0) return bytes32(0);
return encodeEvent(EventType.FP, nextFeeDate);
}
}

return bytes32(0);
}

/**
* @notice Verifies that the provided event is still scheduled under the terms, the current state of the
* contract and the current state of the underlying.
Expand Down
17 changes: 17 additions & 0 deletions packages/actus-solidity/contracts/Engines/CEG/ICEGEngine.sol
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,23 @@ interface ICEGEngine is IEngine {
pure
returns (bytes32[] memory);

/**
* @notice Computes a schedule segment of cyclic contract events based on the contract terms
* and the specified timestamps.
* @param terms terms of the contract
* @param lastScheduleTime last occurrence of cyclic event
* @param eventType eventType of the cyclic schedule
* @return event schedule segment
*/
function computeNextCyclicEvent(
CEGTerms calldata terms,
uint256 lastScheduleTime,
EventType eventType
)
external
pure
returns(bytes32);

/**
* @notice Verifies that the provided event is still scheduled under the terms, the current state of the
* contract and the current state of the underlying.
Expand Down
80 changes: 80 additions & 0 deletions packages/actus-solidity/contracts/Engines/CERTF/CERTFEngine.sol
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,86 @@ contract CERTFEngine is Core, CERTFSTF, CERTFPOF, ICERTFEngine {
return schedule;
}

/**
* @notice Computes a schedule segment of cyclic contract events based on the contract terms
* and the specified timestamps.
* @param terms terms of the contract
* @param lastScheduleTime last occurrence of cyclic event
* @param eventType eventType of the cyclic schedule
* @return event schedule segment
*/
function computeNextCyclicEvent(
CERTFTerms calldata terms,
uint256 lastScheduleTime,
EventType eventType
)
external
pure
override
returns(bytes32)
{
if (eventType == EventType.CFD) {
if (terms.cycleOfCoupon.isSet == true && terms.cycleAnchorDateOfCoupon != 0) {
uint256 nextCouponDate = computeNextCycleDateFromPrecedingDate(
terms.cycleOfCoupon,
(lastScheduleTime == 0) ? terms.cycleAnchorDateOfCoupon : lastScheduleTime
);
if (nextCouponDate == uint256(0)) return bytes32(0);
return encodeEvent(EventType.CFD, nextCouponDate);
}
}

if (eventType == EventType.CPD) {
if (terms.cycleOfCoupon.isSet == true && terms.cycleAnchorDateOfCoupon != 0) {
uint256 nextCouponDate = computeNextCycleDateFromPrecedingDate(
terms.cycleOfCoupon,
(lastScheduleTime == 0) ? terms.cycleAnchorDateOfCoupon : lastScheduleTime
);
if (nextCouponDate == uint256(0)) return bytes32(0);
uint256 couponPaymentDayScheduleTime = getTimestampPlusPeriod(terms.settlementPeriod, nextCouponDate);
return encodeEvent(EventType.CFD, couponPaymentDayScheduleTime);
}
}

if (eventType == EventType.RFD) {
if (terms.cycleOfRedemption.isSet == true && terms.cycleAnchorDateOfRedemption != 0) {
uint256 nextRedemptionDate = computeNextCycleDateFromPrecedingDate(
terms.cycleOfRedemption,
(lastScheduleTime == 0) ? terms.cycleAnchorDateOfRedemption : lastScheduleTime
);
if (nextRedemptionDate == uint256(0)) return bytes32(0);
return encodeEvent(EventType.RFD, nextRedemptionDate);
}
}

if (eventType == EventType.RPD) {
if (terms.cycleOfRedemption.isSet == true && terms.cycleAnchorDateOfRedemption != 0) {
uint256 nextRedemptionDate = computeNextCycleDateFromPrecedingDate(
terms.cycleOfRedemption,
(lastScheduleTime == 0) ? terms.cycleAnchorDateOfRedemption : lastScheduleTime
);
if (nextRedemptionDate == uint256(0)) return bytes32(0);
uint256 redemptionPaymentDayScheduleTime = getTimestampPlusPeriod(terms.settlementPeriod, nextRedemptionDate);
return encodeEvent(EventType.RPD, redemptionPaymentDayScheduleTime);
}
}

if (eventType == EventType.XD) {
if (terms.cycleOfRedemption.isSet == true && terms.cycleAnchorDateOfRedemption != 0) {
uint256 nextRedemptionDate = computeNextCycleDateFromPrecedingDate(
terms.cycleOfRedemption,
(lastScheduleTime == 0) ? terms.cycleAnchorDateOfRedemption : lastScheduleTime
);
if (nextRedemptionDate == uint256(0)) return bytes32(0);
if (nextRedemptionDate == terms.maturityDate) return bytes32(0);
uint256 executionDateScheduleTime = getTimestampPlusPeriod(terms.exercisePeriod, nextRedemptionDate);
return encodeEvent(EventType.XD, executionDateScheduleTime);
}
}

return bytes32(0);
}

/**
* @notice Verifies that the provided event is still scheduled under the terms, the current state of the
* contract and the current state of the underlying.
Expand Down
17 changes: 17 additions & 0 deletions packages/actus-solidity/contracts/Engines/CERTF/ICERTFEngine.sol
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,23 @@ interface ICERTFEngine is IEngine {
pure
returns (bytes32[] memory);

/**
* @notice Computes a schedule segment of cyclic contract events based on the contract terms
* and the specified timestamps.
* @param terms terms of the contract
* @param lastScheduleTime last occurrence of cyclic event
* @param eventType eventType of the cyclic schedule
* @return event schedule segment
*/
function computeNextCyclicEvent(
CERTFTerms calldata terms,
uint256 lastScheduleTime,
EventType eventType
)
external
pure
returns(bytes32);

/**
* @notice Verifies that the provided event is still scheduled under the terms, the current state of the
* contract and the current state of the underlying.
Expand Down
Loading

0 comments on commit 6e7a893

Please sign in to comment.