Skip to content

Commit cd50b38

Browse files
committed
Addjust BloctoDAO vote weight
1 parent e1e0f1d commit cd50b38

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

contracts/flow/dao/BloctoDAO.cdc

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,26 @@ pub contract BloctoDAO {
155155
self.voided = false
156156
}
157157

158+
// binary search
159+
pub fun weighted (stake: UFix64): UFix64 {
160+
if stake <= 1.0 {
161+
return 0.0
162+
}
163+
164+
// ~ sqrt(500000000)
165+
var upper = 22361.0
166+
var lower = 1.0
167+
while upper - lower > 0.00000001 {
168+
let mid = (lower + upper) / 2.0
169+
if mid * mid > stake {
170+
upper = mid
171+
} else {
172+
lower = mid
173+
}
174+
}
175+
return lower
176+
}
177+
158178
pub fun update(title: String?, description: String?, startAt: UFix64?, endAt: UFix64?, voided: Bool?) {
159179
pre {
160180
title?.length ?? 0 <= 1000: "Title too long"
@@ -205,7 +225,7 @@ pub contract BloctoDAO {
205225
let address = votedList[self.countIndex]
206226
let voterStaked = BloctoDAO.getStakedBLT(address: address)
207227
let votedOptionIndex = BloctoDAO.votedRecords[self.id][address]!
208-
self.votesCountActual[votedOptionIndex] = self.votesCountActual[votedOptionIndex] + voterStaked
228+
self.votesCountActual[votedOptionIndex] = self.votesCountActual[votedOptionIndex] + self.weighted(stake: voterStaked)
209229

210230
self.countIndex = self.countIndex + 1
211231
}

0 commit comments

Comments
 (0)