Skip to content

Instantly share code, notes, and snippets.

@deweller
Last active January 24, 2022 03:14
Show Gist options
  • Save deweller/10a62c82072640378d266d5d83afd59f to your computer and use it in GitHub Desktop.
Save deweller/10a62c82072640378d266d5d83afd59f to your computer and use it in GitHub Desktop.
EngineerDAO Contracts Pseudo Code
contract job
jobsMapStorage = {}
daoEscrow = 0
daoFunds = 0
listOfDisputeResolvers = [0xAdd11111, 0xAdd22222]
DR_SERVICE_ADDRESS = 0xAdd99999
daoFundManagerAddress = 0xAdd4e55
// start a new job
postJob(jobData)
if bounty was not included then revert
validate jobData
daoEscrow = daoEscrow + fundsSent
jobData.bounty = fundsSent
jobData.supplier = callerAddress
jobData.postTime = now
jobData.state = 'available'
jobId = generateJobId(jobData)
save jobData to jobsMapStorage using jobId
// both the supplier or the engineer must call
closeJob(jobId)
jobData = jobsMapStorage[jobId]
if jobData.state != 'available' then revert
if callerAddress != jobData.supplier and callerAddress != jobData.engineer then revert
if callerAddress == jobData.supplier
jobData.closedBySupplier = true
if callerAddress == jobData.engineer
jobData.closedByEngineer = true
if jobData.closedBySupplier and jobData.closedByEngineer
_sendJobRefund(jobId)
jobData.state = 'final-cancelled-by-both-parties'
save jobData to contract storage
// close immediately
cancelJob(jobId)
jobData = jobsMapStorage[jobId]
if jobData.state != 'available' then revert
if callerAddress != jobData.supplier then revert
jobData.state = 'final-cancelled-by-supplier'
_sendJobRefund(jobId)
save jobData to contract storage
startJob(jobId)
jobData = jobsMapStorage[jobId]
if jobData.state != 'available' then revert
if callerAddress == jobData.supplier then revert
if fundsSent < jobData.bounty * 0.1 then revert
daoEscrow = daoEscrow + fundsSent
jobData.buyIn = fundsSent
jobData.engineer = callerAddress
jobData.startTime = now
jobData.state = 'started'
save jobData to contract storage
completeJob(jobId)
jobData = jobsMapStorage[jobId]
if jobData.state != 'started' then revert
if callerAddress != jobData.engineer then revert
jobData.completeTime = now
jobData.state = 'completed'
save jobData to contract storage
requestNoResponsePayout(jobId)
jobData = jobsMapStorage[jobId]
if jobData.state != 'completed' then revert
if callerAddress != jobData.engineer then revert
if jobData.completeTime is not old enough then revert
_sendJobPayout(jobId)
jobData.state = 'final-no-response'
save jobData to contract storage
approveJob(jobId)
jobData = jobsMapStorage[jobId]
if jobData.state != 'completed' then revert
if callerAddress != jobData.supplier then revert
_sendJobPayout(jobId)
jobData.state = 'final-approved'
save jobData to contract storage
disputeJob(jobId)
jobData = jobsMapStorage[jobId]
if jobData.state != 'started' or jobData.state != 'completed' then revert
if callerAddress != jobData.supplier then revert
jobData.state = 'disputed'
save jobData to contract storage
resolveDisputeForSupplier(joibId)
jobData = jobsMapStorage[jobId]
if jobData.state != 'disputed' then revert
if callerAddress is not in listOfDisputeResolvers then revert
jobEscrow = jobData.bounty + jobData.buyIn
daoEscrow = daoEscrow - jobEscrow
send 94% of jobEscrow to jobData.supplier
send 6% of jobEscrow to DR_SERVICE_ADDRESS
jobData.state = 'final-dispute-resolved-supplier'
save jobData to contract storage
resolveDisputeForEngineer(joibId)
jobData = jobsMapStorage[jobId]
if jobData.state != 'disputed' then revert
if callerAddress is not in listOfDisputeResolvers then revert
jobEscrow = jobData.bounty + jobData.buyIn
daoEscrow = daoEscrow - jobEscrow
send 94% of jobEscrow to jobData.engineer
send 6% of jobEscrow to DR_SERVICE_ADDRESS
jobData.state = 'final-dispute-resolved-engineer'
save jobData to contract storage
resolveDisputeWithCustomAmount(joibId, engineerAmountPct)
jobData = jobsMapStorage[jobId]
if jobData.state != 'disputed' then revert
if callerAddress is not in listOfDisputeResolvers then revert
jobEscrow = jobData.bounty + jobData.buyIn
jobEscrowAfterFee = 96% of jobEscrow
feeAmount = jobEscrow - jobEscrowAfterFee
engineerAmount = jobEscrowAfterFee * engineerAmountPct / 100
supplierAmount = engineerAmount - engineerAmount
daoEscrow = daoEscrow - jobEscrow
send engineerAmount to jobData.engineer
send supplierAmount to jobData.supplier
send feeAmount to DR_SERVICE_ADDRESS
jobData.state = 'final-dispute-resolved-custom'
save jobData to contract storage
_sendJobPayout(jobId)
jobData = jobsMapStorage[jobId]
jobEscrow = jobData.bounty + jobData.buyIn
payoutAmount = jobData.bounty * 0.95 + jobData.buyIn
daoEscrow = daoEscrow - jobEscrow
daoFunds = daoFunds + (jobEscrow - payoutAmount)
send payoutAmount to jobData.engineer
_sendJobRefund(jobId)
jobData = jobsMapStorage[jobId]
daoEscrow = daoEscrow - jobData.bounty
send jobData.bounty to jobData.supplier
if jobData.buyIn
daoEscrow = daoEscrow - jobData.buyIn
send jobData.buyIn to jobData.engineer
getJob(jobId)
jobData = jobsMapStorage[jobId]
return jobData
withdrawDaoFunds(amount, recipient)
if callerAddress != daoFundManagerAddress then revert
if amount > daoFunds then revert
daoFunds = daoFunds - amount
send amount to recipient
addDaoFunds()
daoFunds = daoFunds + fundsSent
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment