Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
tanpv opened this issue Oct 14, 2018 · 1 comment
Closed

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

tanpv opened this issue Oct 14, 2018 · 1 comment

Comments

@tanpv
Copy link

tanpv commented Oct 14, 2018

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]);
            }
        }
@tanpv
Copy link
Author

tanpv commented Oct 15, 2018

The original logic should be correct, I just be confused by field name "alreadyWithdrawn", this sould be "alreadyReleasedFromLock"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant