Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Addjust BloctoDAO vote weight #43

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion contracts/flow/dao/BloctoDAO.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,26 @@ pub contract BloctoDAO {
self.voided = false
}

// binary search
pub fun weighted (stake: UFix64): UFix64 {
if stake <= 1.0 {
return 0.0
}

// ~ sqrt(500000000)
var upper = 22361.0
var lower = 1.0
while upper - lower > 0.00000001 {
let mid = (lower + upper) / 2.0
if mid * mid > stake {
upper = mid
} else {
lower = mid
}
}
return lower
}

pub fun update(title: String?, description: String?, startAt: UFix64?, endAt: UFix64?, voided: Bool?) {
pre {
title?.length ?? 0 <= 1000: "Title too long"
Expand Down Expand Up @@ -205,7 +225,7 @@ pub contract BloctoDAO {
let address = votedList[self.countIndex]
let voterStaked = BloctoDAO.getStakedBLT(address: address)
let votedOptionIndex = BloctoDAO.votedRecords[self.id][address]!
self.votesCountActual[votedOptionIndex] = self.votesCountActual[votedOptionIndex] + voterStaked
self.votesCountActual[votedOptionIndex] = self.votesCountActual[votedOptionIndex] + self.weighted(stake: voterStaked)

self.countIndex = self.countIndex + 1
}
Expand Down