onflow/flow-core-contracts

LockedTokens getLockedAccountBalance underflows

Closed this issue · 3 comments

Problem

LockedAccount sometimes underflow when getting balance

Steps to Reproduce

import LockedTokens from 0x8d0e87b65159ae63

pub fun main(address:Address) : UFix64? {

    let account=getAccount(address)

 
    if let lockedAccountInfo = account.getCapability<&LockedTokens.TokenHolder{LockedTokens.LockedAccountInfo}>(LockedTokens.LockedAccountInfoPublicPath).borrow() {

        return lockedAccountInfo.getLockedAccountBalance()

    }
    return nil
}

Run this script on for instance user 0x0a3446b4dbbaf585

Acceptance Criteria

Should not underflow

Context

Update state of flow for all account in flowdiver

`❌ Invalid argument: failed to execute script: [Error Code: 1101] failed to execute script at block (d752bb273260dc7eaa869c48ccea45e5ec33387e24a1bc36f655b4a696c761b0): [Error Code: 1101] error caused by: 1 error occurred:
* [Error Code: 1101] cadence runtime error: Execution failed:
--> c3504069b2030b7beed3014930938e1aa9e6660e67b9348f3de7e62975f004bb:11:15
|
11 | return lockedAccountInfo.getLockedAccountBalance()
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: underflow
--> 8d0e87b65159ae63.LockedTokens:321:19
|
321 | return self.borrowTokenManager().getBalance() - FlowStorageFees.minimumStorageReservation
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^`

I dont know why minimumStorageReservation is subtracted here, but this account has Result: 0.00099831 in locked balance and that is below that.

it is subtracted to show how much is actually available in the locked account