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

Commit

Permalink
Merge 70f733f into e71123c
Browse files Browse the repository at this point in the history
  • Loading branch information
jo-es committed Jun 25, 2020
2 parents e71123c + 70f733f commit ba800dc
Show file tree
Hide file tree
Showing 125 changed files with 13,437 additions and 1,157 deletions.
5,602 changes: 5,602 additions & 0 deletions packages/actus-solidity/actus-resources/tests/actus-tests-CERTF.json

Large diffs are not rendered by default.

69 changes: 65 additions & 4 deletions packages/actus-solidity/contracts/Core/ACTUSTypes.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,20 @@ struct IP {
}

// Number of enum options should be limited to 256 (8 bits) such that 32 enums can be packed fit into 256 bits (bytes32)
enum Calendar {NC, MF}
enum BusinessDayConvention {NOS, SCF, SCMF, CSF, CSMF, SCP, SCMP, CSP, CSMP}
enum Calendar {NC, MF}
enum ContractPerformance {PF, DL, DQ, DF, MD, TD}
enum ContractReferenceType {CNT, CID, MOC, EID, CST}
enum ContractReferenceRole {UDL, FIL, SEL, COVE, COVI}
enum ContractRole {RPA, RPL, RFL, PFL, RF, PF, BUY, SEL, COL, CNO, UDL, UDLP, UDLM}
enum ContractType {PAM, ANN, NAM, LAM, LAX, CLM, UMP, CSH, STK, COM, SWAPS, SWPPV, FXOUT, CAPFL, FUTUR, OPTNS, CEG, CEC}
enum ContractType {PAM, ANN, NAM, LAM, LAX, CLM, UMP, CSH, STK, COM, SWAPS, SWPPV, FXOUT, CAPFL, FUTUR, OPTNS, CEG, CEC, CERTF}
enum CouponType {NOC, FIX, FCN, PRF}
enum CyclePointOfInterestPayment {B, E}
enum CyclePointOfRateReset {B, E}
enum DayCountConvention {AA, A360, A365, _30E360ISDA, _30E360, _28E336}
enum EndOfMonthConvention {SD, EOM}
// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
enum EventType {NE, IED, FP, PR, PD, PRF, PY, PP, IP, IPCI, CE, RRF, RR, DV, PRD, MR, TD, SC, IPCB, MD, XD, STD, AD}
// 0 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
enum EventType {NE, ID, IED, FP, PR, PD, PRF, PY, PP, IP, IPCI, CE, RRF, RR, DV, PRD, MR, TD, SC, IPCB, MD, CFD, CPD, RFD, RPD, XO, XD, STD, AD}
enum FeeBasis {A, N}
// enum GuaranteedExposure {NO, NI, MV} // not implemented
// enum InterestCalculationBase {NT, NTIED, NTL} // not implemented
Expand All @@ -60,6 +61,7 @@ struct State {
uint256 maturityDate;
uint256 exerciseDate;
uint256 terminationDate;
uint256 lastCouponDay;

int256 notionalPrincipal;
// int256 notionalPrincipal2;
Expand All @@ -73,6 +75,13 @@ struct State {
int256 notionalScalingMultiplier;
int256 nextPrincipalRedemptionPayment;
int256 exerciseAmount;
int256 exerciseQuantity;

int256 quantity;
int256 couponAmountFixed;
// int256 exerciseQuantityOrdered;
int256 marginFactor;
int256 adjustmentFactor;
}

struct ANNTerms {
Expand Down Expand Up @@ -225,6 +234,58 @@ struct CEGTerms {
ContractReference contractReference_2;
}

struct CERTFTerms {
ContractType contractType;
Calendar calendar;
ContractRole contractRole;
DayCountConvention dayCountConvention;
BusinessDayConvention businessDayConvention;
EndOfMonthConvention endOfMonthConvention;
ContractPerformance contractPerformance;
CouponType couponType;

address currency;
address settlementCurrency;

// bytes32 marketObjectCode;

uint256 contractDealDate;
uint256 statusDate;
uint256 initialExchangeDate;
uint256 maturityDate;
uint256 nonPerformingDate;
uint256 issueDate;
// uint256 lastCouponDay;
uint256 cycleAnchorDateOfRedemption;
uint256 cycleAnchorDateOfTermination;
uint256 cycleAnchorDateOfCoupon;

int256 nominalPrice;
int256 issuePrice;
// int256 delinquencyRate;
int256 quantity;
// int256 exerciseQuantity;
// int256 exerciseQuantityOrdered;
// int256 marginFactor;
// int256 adjustmentFactor;
int256 denominationRatio;
int256 couponRate;
// int256 exerciseAmount;
// int256 couponAmountFixed;

IP gracePeriod;
IP delinquencyPeriod;
IP settlementPeriod;
IP fixingPeriod;
IP exercisePeriod;

IPS cycleOfRedemption;
IPS cycleOfTermination;
IPS cycleOfCoupon;

ContractReference contractReference_1;
}

struct PAMTerms {
ContractType contractType;
Calendar calendar;
Expand Down
7 changes: 2 additions & 5 deletions packages/actus-solidity/contracts/Core/Core.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ pragma experimental ABIEncoderV2;

import "./ACTUSTypes.sol";
import "./ACTUSConstants.sol";
import "./Utils.sol";
import "./Schedule.sol";

import "./Utils/Utils.sol";
import "./Conventions/BusinessDayConventions.sol";
import "./Conventions/ContractDefaultConventions.sol";
import "./Conventions/ContractRoleConventions.sol";
Expand All @@ -26,6 +24,5 @@ contract Core is
ContractRoleConventions,
DayCountConventions,
EndOfMonthConventions,
Utils,
Schedule
Utils
{}
127 changes: 0 additions & 127 deletions packages/actus-solidity/contracts/Core/Utils.sol

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,20 @@
pragma solidity ^0.6.10;
pragma experimental ABIEncoderV2;

import "../external/BokkyPooBah/BokkyPooBahsDateTimeLibrary.sol";
import "../../external/BokkyPooBah/BokkyPooBahsDateTimeLibrary.sol";

import "./ACTUSTypes.sol";
import "./ACTUSConstants.sol";
import "./Utils.sol";
import "../ACTUSTypes.sol";
import "../ACTUSConstants.sol";
import "./PeriodUtils.sol";


/**
* @title Schedule
* @notice Methods related to generating event schedules.
*/
contract Schedule is ACTUSConstants, Utils {
contract CycleUtils is ACTUSConstants, PeriodUtils {

using BokkyPooBahsDateTimeLibrary for uint;

/**
* @notice Applies the cycle n - times (n := cycleIndex) to a given date
Expand All @@ -26,17 +28,17 @@ contract Schedule is ACTUSConstants, Utils {
uint256 newTimestamp;

if (cycle.p == P.D) {
newTimestamp = BokkyPooBahsDateTimeLibrary.addDays(cycleStart, cycle.i * cycleIndex);
newTimestamp = cycleStart.addDays(cycle.i * cycleIndex);
} else if (cycle.p == P.W) {
newTimestamp = BokkyPooBahsDateTimeLibrary.addDays(cycleStart, cycle.i * 7 * cycleIndex);
newTimestamp = cycleStart.addDays(cycle.i * 7 * cycleIndex);
} else if (cycle.p == P.M) {
newTimestamp = BokkyPooBahsDateTimeLibrary.addMonths(cycleStart, cycle.i * cycleIndex);
newTimestamp = cycleStart.addMonths(cycle.i * cycleIndex);
} else if (cycle.p == P.Q) {
newTimestamp = BokkyPooBahsDateTimeLibrary.addMonths(cycleStart, cycle.i * 3 * cycleIndex);
newTimestamp = cycleStart.addMonths(cycle.i * 3 * cycleIndex);
} else if (cycle.p == P.H) {
newTimestamp = BokkyPooBahsDateTimeLibrary.addMonths(cycleStart, cycle.i * 6 * cycleIndex);
newTimestamp = cycleStart.addMonths(cycle.i * 6 * cycleIndex);
} else if (cycle.p == P.Y) {
newTimestamp = BokkyPooBahsDateTimeLibrary.addYears(cycleStart, cycle.i * cycleIndex);
newTimestamp = cycleStart.addYears(cycle.i * cycleIndex);
} else {
revert("Schedule.getNextCycleDate: ATTRIBUTE_NOT_FOUND");
}
Expand Down Expand Up @@ -70,7 +72,7 @@ contract Schedule is ACTUSConstants, Utils {
returns (uint256[MAX_CYCLE_SIZE] memory)
{
uint256[MAX_CYCLE_SIZE] memory dates;
uint256 index = 0;
uint256 index;

// if the cycle is not set we return only the cycle start end end dates under these conditions:
// we return the cycle start, if it's in the segment
Expand All @@ -87,7 +89,7 @@ contract Schedule is ACTUSConstants, Utils {
}

uint256 date = cycleStart;
uint256 cycleIndex = 0;
uint256 cycleIndex;

// walk through the cycle and create the cycle dates to be returned
while (date < cycleEnd) {
Expand Down Expand Up @@ -122,4 +124,21 @@ contract Schedule is ACTUSConstants, Utils {

return dates;
}

/**
* @notice Checks if a timestamp is in a given range.
*/
function isInSegment(
uint256 timestamp,
uint256 startTimestamp,
uint256 endTimestamp
)
internal
pure
returns (bool)
{
if (startTimestamp > endTimestamp) return false;
if (startTimestamp <= timestamp && timestamp <= endTimestamp) return true;
return false;
}
}
46 changes: 46 additions & 0 deletions packages/actus-solidity/contracts/Core/Utils/EventUtils.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// "SPDX-License-Identifier: Apache-2.0"
pragma solidity ^0.6.10;
pragma experimental ABIEncoderV2;

import "../ACTUSTypes.sol";

/**
* @title EventUtils
* @notice Methods for encoding decoding events
*/
contract EventUtils {

function encodeEvent(EventType eventType, uint256 scheduleTime)
public
pure
returns (bytes32)
{
return (
bytes32(uint256(uint8(eventType))) << 248 |
bytes32(scheduleTime)
);
}

function decodeEvent(bytes32 _event)
public
pure
returns (EventType, uint256)
{
EventType eventType = EventType(uint8(uint256(_event >> 248)));
uint256 scheduleTime = uint256(uint64(uint256(_event)));

return (eventType, scheduleTime);
}

/**
* @notice Returns the epoch offset for a given event type to determine the
* correct order of events if multiple events have the same timestamp
*/
function getEpochOffset(EventType eventType)
public
pure
returns (uint256)
{
return uint256(eventType);
}
}
Loading

0 comments on commit ba800dc

Please sign in to comment.