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

Commit

Permalink
Refactor getExternalDataForSTF method
Browse files Browse the repository at this point in the history
  • Loading branch information
jo-es committed Nov 9, 2020
1 parent 8f7fe3a commit f750167
Show file tree
Hide file tree
Showing 13 changed files with 262 additions and 91 deletions.
4 changes: 2 additions & 2 deletions packages/protocol/build/contracts/ANNActor.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions packages/protocol/build/contracts/CECActor.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions packages/protocol/build/contracts/CEGActor.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions packages/protocol/build/contracts/CERTFActor.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions packages/protocol/build/contracts/PAMActor.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions packages/protocol/build/contracts/STKActor.json

Large diffs are not rendered by default.

30 changes: 30 additions & 0 deletions packages/protocol/contracts/Core/ANN/ANNActor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,34 @@ contract ANNActor is BaseActor {

return (state, payoff);
}

/**
* @notice Retrieves external data (such as market object data, block time, underlying asset state)
* used for evaluating the STF for a given event.
*/
function getExternalDataForSTF(
bytes32 assetId,
EventType eventType,
uint256 timestamp
)
internal
view
override
returns (bytes32)
{
if (eventType == EventType.RR) {
// get rate from DataRegistry
(int256 resetRate, bool isSet) = dataRegistry.getDataPoint(
assetRegistry.getBytes32ValueForTermsAttribute(assetId, "marketObjectCodeRateReset"),
timestamp
);
if (isSet) return bytes32(resetRate);
} else if (eventType == EventType.CE) {
// get current timestamp
// solium-disable-next-line
return bytes32(block.timestamp);
}

return bytes32(0);
}
}
72 changes: 2 additions & 70 deletions packages/protocol/contracts/Core/Base/AssetActor/BaseActor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -274,76 +274,8 @@ abstract contract BaseActor is Conversions, EventUtils, BusinessDayConventions,
)
internal
view
returns (bytes32)
{
if (eventType == EventType.RR) {
// get rate from DataRegistry
(int256 resetRate, bool isSet) = dataRegistry.getDataPoint(
assetRegistry.getBytes32ValueForTermsAttribute(assetId, "marketObjectCodeRateReset"),
timestamp
);
if (isSet) return bytes32(resetRate);
} else if (eventType == EventType.CE) {
// get current timestamp
// solium-disable-next-line
return bytes32(block.timestamp);
} else if (eventType == EventType.EXE) {
// get the remaining notionalPrincipal from the underlying
ContractReference memory contractReference_1 = assetRegistry.getContractReferenceValueForTermsAttribute(
assetId,
"contractReference_1"
);
if (contractReference_1.role == ContractReferenceRole.COVE) {
bytes32 underlyingAssetId = contractReference_1.object;
address underlyingRegistry = address(uint160(uint256(contractReference_1.object2)));
require(
IAssetRegistry(underlyingRegistry).isRegistered(underlyingAssetId) == true,
"BaseActor.getExternalDataForSTF: ASSET_DOES_NOT_EXIST"
);
return bytes32(
IAssetRegistry(underlyingRegistry).getIntValueForStateAttribute(underlyingAssetId, "notionalPrincipal")
);
}
ContractReference memory contractReference_2 = assetRegistry.getContractReferenceValueForTermsAttribute(
assetId,
"contractReference_2"
);
if (
contractReference_2._type == ContractReferenceType.MOC
&& contractReference_2.role == ContractReferenceRole.UDL
) {
(int256 quantity, bool isSet) = dataRegistry.getDataPoint(
contractReference_2.object,
timestamp
);
if (isSet) return bytes32(quantity);
}
} else if (eventType == EventType.REF) {
ContractReference memory contractReference_1 = assetRegistry.getContractReferenceValueForTermsAttribute(
assetId,
"contractReference_1"
);
if (
contractReference_1._type == ContractReferenceType.MOC
&& contractReference_1.role == ContractReferenceRole.UDL
) {
(int256 marketValueScheduleTime, bool isSetScheduleTime) = dataRegistry.getDataPoint(
contractReference_1.object,
timestamp
);
(int256 marketValueAnchorDate, bool isSetAnchorDate) = dataRegistry.getDataPoint(
contractReference_1.object,
assetRegistry.getUIntValueForTermsAttribute(assetId, "issueDate")
);
if (isSetScheduleTime && isSetAnchorDate) {
return bytes32(marketValueScheduleTime.floatDiv(marketValueAnchorDate));
}
}
return bytes32(0);
}

return bytes32(0);
}
virtual
returns (bytes32);

/**
* @notice Retrieves external data (such as market object data)
Expand Down
38 changes: 38 additions & 0 deletions packages/protocol/contracts/Core/CEC/CECActor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import "./ICECRegistry.sol";
*/
contract CECActor is BaseActor {

using SignedMath for int;


constructor(IAssetRegistry assetRegistry, IDataRegistry dataRegistry) BaseActor(assetRegistry, dataRegistry) {}

Expand Down Expand Up @@ -148,4 +150,40 @@ contract CECActor is BaseActor {

return (state, payoff);
}

/**
* @notice Retrieves external data (such as market object data, block time, underlying asset state)
* used for evaluating the STF for a given event.
*/
function getExternalDataForSTF(
bytes32 assetId,
EventType eventType,
uint256 /* timestamp */
)
internal
view
override
returns (bytes32)
{
if (eventType == EventType.EXE) {
// get the remaining notionalPrincipal from the underlying
ContractReference memory contractReference_1 = assetRegistry.getContractReferenceValueForTermsAttribute(
assetId,
"contractReference_1"
);
if (contractReference_1.role == ContractReferenceRole.COVE) {
bytes32 underlyingAssetId = contractReference_1.object;
address underlyingRegistry = address(uint160(uint256(contractReference_1.object2)));
require(
IAssetRegistry(underlyingRegistry).isRegistered(underlyingAssetId) == true,
"BaseActor.getExternalDataForSTF: ASSET_DOES_NOT_EXIST"
);
return bytes32(
IAssetRegistry(underlyingRegistry).getIntValueForStateAttribute(underlyingAssetId, "notionalPrincipal")
);
}
}

return bytes32(0);
}
}
43 changes: 43 additions & 0 deletions packages/protocol/contracts/Core/CEG/CEGActor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ import "./ICEGRegistry.sol";
*/
contract CEGActor is BaseActor {

using SignedMath for int;


constructor(IAssetRegistry assetRegistry, IDataRegistry dataRegistry) BaseActor(assetRegistry, dataRegistry) {}

/**
Expand Down Expand Up @@ -103,4 +106,44 @@ contract CEGActor is BaseActor {

return (state, payoff);
}

/**
* @notice Retrieves external data (such as market object data, block time, underlying asset state)
* used for evaluating the STF for a given event.
*/
function getExternalDataForSTF(
bytes32 assetId,
EventType eventType,
uint256 /* timestamp */
)
internal
view
override
returns (bytes32)
{
if (eventType == EventType.CE) {
// get current timestamp
// solium-disable-next-line
return bytes32(block.timestamp);
} else if (eventType == EventType.EXE) {
// get the remaining notionalPrincipal from the underlying
ContractReference memory contractReference_1 = assetRegistry.getContractReferenceValueForTermsAttribute(
assetId,
"contractReference_1"
);
if (contractReference_1.role == ContractReferenceRole.COVE) {
bytes32 underlyingAssetId = contractReference_1.object;
address underlyingRegistry = address(uint160(uint256(contractReference_1.object2)));
require(
IAssetRegistry(underlyingRegistry).isRegistered(underlyingAssetId) == true,
"BaseActor.getExternalDataForSTF: ASSET_DOES_NOT_EXIST"
);
return bytes32(
IAssetRegistry(underlyingRegistry).getIntValueForStateAttribute(underlyingAssetId, "notionalPrincipal")
);
}
}

return bytes32(0);
}
}
64 changes: 64 additions & 0 deletions packages/protocol/contracts/Core/CERTF/CERTFActor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ import "./ICERTFRegistry.sol";
*/
contract CERTFActor is BaseActor {

using SignedMath for int;


constructor(IAssetRegistry assetRegistry, IDataRegistry dataRegistry) BaseActor(assetRegistry, dataRegistry) {}

/**
Expand Down Expand Up @@ -93,4 +96,65 @@ contract CERTFActor is BaseActor {

return (state, payoff);
}

/**
* @notice Retrieves external data (such as market object data, block time, underlying asset state)
* used for evaluating the STF for a given event.
*/
function getExternalDataForSTF(
bytes32 assetId,
EventType eventType,
uint256 timestamp
)
internal
view
override
returns (bytes32)
{
if (eventType == EventType.CE) {
// get current timestamp
// solium-disable-next-line
return bytes32(block.timestamp);
} else if (eventType == EventType.EXE) {
// get quantity
ContractReference memory contractReference_2 = assetRegistry.getContractReferenceValueForTermsAttribute(
assetId,
"contractReference_2"
);
if (
contractReference_2._type == ContractReferenceType.MOC
&& contractReference_2.role == ContractReferenceRole.UDL
) {
(int256 quantity, bool isSet) = dataRegistry.getDataPoint(
contractReference_2.object,
timestamp
);
if (isSet) return bytes32(quantity);
}
} else if (eventType == EventType.REF) {
ContractReference memory contractReference_1 = assetRegistry.getContractReferenceValueForTermsAttribute(
assetId,
"contractReference_1"
);
if (
contractReference_1._type == ContractReferenceType.MOC
&& contractReference_1.role == ContractReferenceRole.UDL
) {
(int256 marketValueScheduleTime, bool isSetScheduleTime) = dataRegistry.getDataPoint(
contractReference_1.object,
timestamp
);
(int256 marketValueAnchorDate, bool isSetAnchorDate) = dataRegistry.getDataPoint(
contractReference_1.object,
assetRegistry.getUIntValueForTermsAttribute(assetId, "issueDate")
);
if (isSetScheduleTime && isSetAnchorDate) {
return bytes32(marketValueScheduleTime.floatDiv(marketValueAnchorDate));
}
}
return bytes32(0);
}

return bytes32(0);
}
}
30 changes: 30 additions & 0 deletions packages/protocol/contracts/Core/PAM/PAMActor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,34 @@ contract PAMActor is BaseActor {

return (state, payoff);
}

/**
* @notice Retrieves external data (such as market object data, block time, underlying asset state)
* used for evaluating the STF for a given event.
*/
function getExternalDataForSTF(
bytes32 assetId,
EventType eventType,
uint256 timestamp
)
internal
view
override
returns (bytes32)
{
if (eventType == EventType.RR) {
// get rate from DataRegistry
(int256 resetRate, bool isSet) = dataRegistry.getDataPoint(
assetRegistry.getBytes32ValueForTermsAttribute(assetId, "marketObjectCodeRateReset"),
timestamp
);
if (isSet) return bytes32(resetRate);
} else if (eventType == EventType.CE) {
// get current timestamp
// solium-disable-next-line
return bytes32(block.timestamp);
}

return bytes32(0);
}
}
Loading

0 comments on commit f750167

Please sign in to comment.