Skip to content

Instantly share code, notes, and snippets.

@retotrinkler
Created September 14, 2017 16:57
Show Gist options
  • Save retotrinkler/5900837398356e128722e6d53b87048c to your computer and use it in GitHub Desktop.
Save retotrinkler/5900837398356e128722e6d53b87048c to your computer and use it in GitHub Desktop.
An example of how uPort, Zug Gov and Melon could collaborate - Modifications welcome!
pragma solidity ^0.4.16;
/// @title Desing by contract (Hoare logic)
/// @author Melonport AG <[email protected]>
/// @notice Gives deriving contracts design by contract modifiers
contract DBC {
// MODIFIERS
modifier pre_cond(bool condition) {
require(condition);
_;
}
modifier post_cond(bool condition) {
_;
assert(condition);
}
modifier invariant(bool condition) {
require(condition);
_;
assert(condition);
}
}
contract Owned {
// FIELDS
address public owner;
// PRE, POST, INVARIANT CONDITIONS
function isOwner() internal returns (bool) { return msg.sender == owner; }
// NON-CONSTANT METHODS
function Owned() { owner = msg.sender; }
}
contract ParticipationInterface {
// CONSTANT METHODS
function isSubscriptionPermitted(
address owner,
uint256 numShares,
uint256 offeredValue
) constant returns (bool) {}
function isRedemptionPermitted(
address owner,
uint256 numShares,
uint256 requestedValue
) constant returns (bool) {}
}
/// @title Participation Contract
/// @author Melonport AG <[email protected]>
/// @notice Example for uPort, Zug Gov, Melonport collaboration
contract Participation is ParticipationInterface, DBC, Owned {
// TYPES
struct Identity { // Using uPort and attestation from Zug Government
bool hasUportId; // Whether identiy has registered a uPort identity w Zug Gov
/* .. additional information
* for example how much identity is eligible to invest
*/
}
// FIELDS
// Function fields
mapping (address => Identity) public identities;
// CONSTANT METHODS
/// @notice Required for Melon protocol interaction.
/// @param ofParticipant Address requesting to invest in a Melon fund
/// @param numShares Quantity of shares times 10 ** 18 requested to be received
/// @param offeredValue Quantity of Melon token times 10 ** 18 offered to receive numShares
/// @return Whether identity is eligible to invest in a Melon fund.
function isSubscriptionPermitted(
address ofParticipant,
uint256 numShares,
uint256 offeredValue
)
constant
returns (bool)
{
return identities[ofParticipant].hasUportId; // Eligible iff has uPort identity
}
/// @notice Required for Melon protocol interaction.
/// @param ofParticipant Address requesting to redeem from a Melon fund
/// @param numShares Quantity of shares times 10 ** 18 offered to redeem
/// @param requestedValue Quantity of Melon token times 10 ** 18 requested to receive for numShares
/// @return Whether identity is eligible to redeem from a Melon fund.
function isRedemptionPermitted(
address ofParticipant,
uint256 numShares,
uint256 requestedValue
)
constant
returns (bool)
{
return true; // No need for KYC/AML in case of redeeming shares
}
// NON-CONSTANT METHODS
/// @notice Creates attestation of a participant
/// @dev Maintainer of above identities mapping (== owner) can trigger this function
/// @param ofParticipant Adresses to receive attestation
function attestForIdentity(address ofParticipant)
pre_cond(isOwner())
{
identities[ofParticipant].hasUportId = true;
}
/// @notice Removes attestation of a participant
/// @dev Maintainer of above identities mapping (== owner) can trigger this function
/// @param ofParticipant Adresses to have attestation removed
function removeAttestation(address ofParticipant)
pre_cond(isOwner())
{
identities[ofParticipant].hasUportId = false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment