Skip to content

Should add "amount" to "alreadyWithdrawn", not add "tokenSums[0]" #341

Closed
@tanpv

Description

@tanpv

File : LockupVolumeRestrictionTM.sol
Function : _checkIfValidTransfer
Original code add "tokenSums[0]" to "alreadyWithdrawn". This logic seem wrong, here we only use "tokenSums[0]" to make sure transfer could happen, but the real transfer is "amount", so here should add "amount" to "alreadyWithdrawn".

        // subtract amounts so they are now known to be withdrawen            
        for (i = 0; i < userLockUps.length; i++) {
            aLockUp = userLockUps[i];

            // tokenSums[0] is allowed sum
            if (allowedAmountPerLockup[i] >= tokenSums[0]) {
                aLockUp.alreadyWithdrawn = aLockUp.alreadyWithdrawn.add(tokenSums[0]);
                // we withdrew the entire tokenSums[0] from the lockup.  We are done.
                break;
            } else {
                // we have to split the tokenSums[0] across mutiple lockUps
                aLockUp.alreadyWithdrawn = aLockUp.alreadyWithdrawn.add(allowedAmountPerLockup[i]);
                // subtract the amount withdrawn from this lockup
                // allow sum
                tokenSums[0] = tokenSums[0].sub(allowedAmountPerLockup[i]);
            }
        }

Above code should be changed to

       // subtract amounts so they are now known to be withdrawen
        for (i = 0; i < userLockUps.length; i++) {
            aLockUp = userLockUps[i];

            if (allowedAmountPerLockup[i] >= amount) {
                // update already with draw
                aLockUp.alreadyWithdrawn = aLockUp.alreadyWithdrawn.add(amount);
                break;
            } else {
                aLockUp.alreadyWithdrawn = aLockUp.alreadyWithdrawn.add(allowedAmountPerLockup[i]);
                amount = amount.sub(allowedAmountPerLockup[i]);
            }
        }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions