Skip to content

Commit

Permalink
processVoteINTERNAL
Browse files Browse the repository at this point in the history
  • Loading branch information
ridev6 committed Apr 18, 2024
1 parent ed45bab commit 6ca6d6f
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions ride/voting_emission.ride
Original file line number Diff line number Diff line change
Expand Up @@ -517,31 +517,33 @@ func processVoteINTERNAL(poolStr: String, userAddressStr: String) = {
let gwxAmountAtEndTotalPrevious = this.invoke("getUserGwxAmountAtHeight", [userAddressStr, endHeightPrevious], []).exactAs[Int]
let totalVotes = epoch.keyTotalVotes().getInteger().valueOrElse(0)
let votingResult = pool.keyVotingResult(epoch).getInteger().valueOrElse(0)
let votePrevious = pool.keyVote(userAddress, epochPrevious).getInteger()
.valueOrErrorMessage(("processVoteINTERNAL " + poolStr + " " + userAddressStr + ": no previous vote").wrapErr())
let votePreviousOption = pool.keyVote(userAddress, epochPrevious).getInteger()
let votePrevious = votePreviousOption.valueOrErrorMessage(
wrapErr("processVoteINTERNAL " + poolStr + " " + userAddressStr + ": no previous vote")
)
let used = this.getInteger(userAddress.keyUsed(epoch)).valueOrElse(0)

# staked votes
let lpAssetIdStr = getLpAssetByPoolAssets(amountAssetId, priceAssetId)
let votingResultStakedPrevious = lpAssetIdStr.keyVotingResultStaked(epochPrevious).getInteger().valueOrElse(0)
let stakingContract = this.getStrOrFail(keyStakingContract).addressFromStringValue()
let stakedByUser = stakingContract.getInteger(lpAssetIdStr.keyStakedByUser(userAddressStr)).valueOrElse(0)
let votingResultStakedActions = if (stakedByUser == 0) then [] else [
let votingResultStakedActions = if (stakedByUser == 0 || votePreviousOption == unit) then [] else [
IntegerEntry(lpAssetIdStr.keyVotingResultStaked(epochPrevious), votingResultStakedPrevious + votePrevious)
]

let lpAssetId = getLpAssetByPoolAssets(amountAssetId, priceAssetId)

let newVote = if (gwxAmountAtEndTotalPrevious > 0) then fraction(votePrevious, gwxAmountAtEndTotal, gwxAmountAtEndTotalPrevious) else 0
let actions = if (newVote > 0) then {
let actions = if (votePreviousOption == unit || newVote <= 0) then {
pool.getVotesListName().deleteNodeActions(userAddressStr)
} else {
[
IntegerEntry(pool.keyVote(userAddress, epoch), newVote),
IntegerEntry(epoch.keyTotalVotes(), totalVotes + newVote),
IntegerEntry(pool.keyVotingResult(epoch), votingResult + newVote),
IntegerEntry(userAddress.keyUsed(epoch), used + newVote)
]
} else {
pool.getVotesListName().deleteNodeActions(userAddressStr)
}

(
Expand Down

0 comments on commit 6ca6d6f

Please sign in to comment.