Skip to content

Commit

Permalink
Added totalUnitStaked
Browse files Browse the repository at this point in the history
  • Loading branch information
bra1nsurfer committed Oct 15, 2024
1 parent 2674cee commit 6a9a49d
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions ride/l2mp_leasing.ride
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ func keyUserToClaim(userAddress: String) =
func keyUserTotalLocked(userAddress: String) =
["%s%s", "userTotalLocked", userAddress].makeString(SEP)

func keyClaimedBlock(userAddress: String) =
["%s%s", userAddress, "claimedBlock"].makeString(SEP)

func keyTotalUnitsClaimed(userAddress: String) =
["%s%s", userAddress, "totalUnitsClaimed"].makeString(SEP)

# History keys
func keyNodeLeasingByHeight(nodeAddress: String) = {
let h = if (periodOffsetHeight == -1) then 0 else height
Expand Down Expand Up @@ -112,10 +118,6 @@ func genVotesKeys(keyPrefix: String) = {
result
}

func keyClaimedBlock(userAddress: String) =
["%s", userAddress, "claimedBlock"].makeString(SEP)


# Count all votes for Prefix
func countVotesHelper(result: Int, voteKey: String) = {
result + getInteger(voteKey).valueOrElse(0)
Expand Down Expand Up @@ -458,10 +460,17 @@ func claimUnit() = {
let userAddress = i.caller.toString()

let toClaimNow = calculateClaim(userAddress)

let totalUnitClaimed = this.getInteger(keyTotalUnitsClaimed(userAddress)).valueOrElse(0)
let totalL2Staked = getUserTotalLocked(userAddress)

strict check = [
totalUnitClaimed + toClaimNow <= totalL2Staked || throwErr("Can't claim more than staked")
]

let claimedBlockKey = keyClaimedBlock(userAddress)
let actions = [
IntegerEntry(claimedBlockKey, height)
IntegerEntry(claimedBlockKey, height),
IntegerEntry(keyTotalUnitsClaimed(userAddress), totalUnitClaimed + toClaimNow)
]
let transferUnits = ScriptTransfer(i.caller, toClaimNow, unit)

Expand Down

0 comments on commit 6a9a49d

Please sign in to comment.