Skip to content

Instantly share code, notes, and snippets.

@zemse
Last active August 24, 2020 21:19
Show Gist options
  • Save zemse/94db15aa1544f1afaa2fcf52ed96d807 to your computer and use it in GitHub Desktop.
Save zemse/94db15aa1544f1afaa2fcf52ed96d807 to your computer and use it in GitHub Desktop.
eraswapnetwork dependency contract abstracts
/// VERSION: 1.1.0
/// Please note that the following APIs (function name, args and return values) may be changed to
/// incorporate proper logic in ES whitepaper. Please recheck that your contracts use the latest version.
/// This gist is intended for reference purpose of the Era Swap Team and buidlers building dApps that
/// will be a part Era Swap Ecosystem.
pragma solidity 0.7.0;
/// KYC DApp
/// @notice if your platform needs to store user information like name, you can instead use KycDapp
/// @dev https://github.com/KMPARDS/esn-contracts/blob/master/contracts/ESN/KycDapp/IKycDapp.sol
interface KycDapp {
function isKycLevel1(address _wallet) external view returns (bool);
function isKycLevel2(address _wallet, address _platform) external view returns (bool);
}
/// @dev integrating KycDapp in your platform
contract Platform1 {
KycDapp kycDappContract;
/// @dev checking for KYC approved
modifier onlyKycApproved() {
require(kycDappContract.isKycLevel1(msg.sender), 'KYC is not approved');
_;
}
}
/// Dayswappers Referral Program of Era Swap Ecosystem
/// @dev you can use Dayswappers smart contract to reward users on your platform
abstract contract Dayswappers {
/// @dev use when you want to reward to the entire introducer chain of a user
/// @notice being payable, you also need to send ES appropriately (on ESN, Ether is ES)
/// @param _walletAddress: wallet address of current user
/// @param _rewardRatio: percentages to divide reward into [liquid, prepaid, staking]
function payToTree(address _networker, uint256[3] memory _rewardRatio) external payable virtual;
/// @dev use when you want to reward only to the introducer of a user
/// @notice being payable, you also need to send ES appropriately (on ESN, Ether is ES)
/// @param _walletAddress: wallet address of current user
/// @param _rewardRatio: percentages to divide reward into [liquid, prepaid, staking]
function payToIntroducer(address _networker, uint256[3] memory _rewardRatio) external payable virtual;
/// @dev use when you want to report volume generated by a user on your platform
function reportVolume(address _networker, uint256 _amount) external;
}
/// @dev integrating Dayswappers in your platform
contract Platform2 {
Dayswappers dayswappersContract;
/// @dev sending amount to dayswappers
function payMoney() public {
address _userAddress; // @dev address of user to who's tree we want to send ES
uint256 _txAmount = 1 ether; // @dev on ESN, ether is ES
uint256 _treeAmount = _txAmount.mul(2).div(100); // 2% of txAmount
uint256 _introducerAmount = _txAmount.mul(5).div(1000); // 0.5% of txAmount
/// @dev sending value to a payable function along with giving an argument to the method
dayswappersContract.payToTree{value: _treeAmount}(_userAddress, [50, 0, 50]);
dayswappersContract.payToIntroducer{value: _introducerAmount}(_userAddress, [50, 0, 50]);
/// @dev report volume generated. useful for user to attain a active status.
dayswappersContract.reportVolume(_userAddress, _txAmount);
}
}
/// Era Swap Court
/// @dev you can use this contract if you have any scope of disputes (voting required of two people / even no. of people)
abstract contract EraSwapCourt {
/// @dev platforms call this function of EraSwapCourt from their contract, along with necessary setup (see Platform3 example)
/// this function will store the caseId by platform address using msg.sender and process further for curation
function createDispute(uint256 _caseIdOnPlatfrom) external virtual;
/// @dev platforms do not have to call this. when all curators have voted, window for this function will be open anyone can call to trigger
function endDispute(address _platfrom, uint256 _disputeId) public {
/// @dev checks if case is ok to end
/// @dev calculate the result what ever it is based on curator votings
bool _result = true;
/// @dev communicate the answer true or false to the platfrom contract
_platfrom.call(abi.encode(bytes4(keccak256("resolveDispute(uint256,bool)")), _disputeId, _result));
/// @notice this contract calls an external marked resolveCase(uint256,bool) method
/// the platform contract should have this method implemented
/// to be able to allow the outcome based on this answer
}
}
/// @dev integrating Era Swap Court in your dapps for resolving disputes
/// this is a simple example, your case might be complex
/// when not sure about anything please consult any one from Era Swap Team.
contract Platform {
EraSwapCourt eraSwapCourtContract;
/// @dev working with eraswap court:
/// era swap court is used when an action needs two approvals,
/// and being even number of approvals a disagreement is possible
/// @dev in this example we have an update request which one party requests and other party has to react to within a time limit
/// @dev an example of a request method, this can be anything relevant, it requires a datastructure similar to below Request.
enum RequestStatus { PENDING, ACCEPTED, REJECTED }
enum RequestType { AMOUNT_UPDATE } /// @dev can add more type of requests depending on dispute possibility of the platform
struct Request {
RequestType requestType;
uint256 projectId; /// @dev you can reference these variables as required, you can put appropriate property names
uint256 newAmount; /// @dev any data that is required
bytes32 explainationIPFS; /// @dev IPFS hash of description
RequestStatus status; /// @dev status to store current request status
uint256 timestamp;
}
enum DisputeStatus { PENDING, SUPPORTING, AGAINST }
struct Dispute {
RequestType requestType;
uint256 projectId;
uint256 requestId;
uint256 againstAmount;
bytes32 explainationIPFS;
DisputeStatus disputeStatus;
}
struct Project {
uint256 amount; /// @dev amount whose change needs acceptance of both employer and freelancer
}
Project[] projects;
/// @dev for standardization of disputes on all platforms and data to be properly fetched on UI, a common request list is required
/// type of the request can be identified from the requestType in Request structure
Request[] public requests;
/// @dev similarly for disputes too, since only dispute id is being passed
/// type of the dispute can be identified from the requestType property in Dispute structure
Dispute[] public disputes;
/// @dev this function can be called by one of the two members
function updateRequest(uint256 _projectId, uint256 _newAmount, bytes32 _explainationIPFS) public payable {
/// create a request
requests.push(Request({
requestType: RequestType.AMOUNT_UPDATE,
projectId: _projectId,
newAmount: _newAmount,
explainationIPFS: _explainationIPFS,
status: RequestStatus.PENDING,
timestamp: now
}));
}
/// @dev other member can accept
function accept(uint256 _requestId) public payable {
requests[_requestId].status = RequestStatus.ACCEPTED;
/// @dev accept extra funds if _newAmount is increased
/// @dev if _newAmount is decreased, then transfer the balance amount back to relavant member
}
function finalize(uint256 _projectId, uint256 _requestId) public {
/// @dev check if other member is responding within reasonable time, if not responded can accept the request
}
function raiseDispute(uint256 _projectId, uint256 _requestId, uint256 _againstAmount, bytes32 _explainationIPFS) public {
/// @dev store relavant details about the dispute
disputes.push(Dispute({
requestType: RequestType.AMOUNT_UPDATE,
projectId: _projectId,
requestId: _requestId,
againstAmount: _againstAmount,
explainationIPFS: _explainationIPFS,
disputeStatus: DisputeStatus.PENDING
}));
/// @dev generate a dispute id
uint256 _disputeId = disputes.length - 1;
/// @dev send the dispute id to era swap court contract
eraSwapCourtContract.createDispute(_disputeId);
}
/// @dev the signature of this function needs to be same, i.e name of function and arguments
function resolveDispute(uint256 _disputeId, bool _solution) public {
require(msg.sender == address(eraSwapCourtContract), 'caller should be court');
/// @dev mark dispute as SUPPORTING for true and AGAINST for false and process the outcome based on the _solution
/// based on the requestType in the dispute and make appropriate state updates and fund transfers
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment