@@ -1116,26 +1116,23 @@ access(all) contract FlowALPv0 {
11161116 // Deposit rate limiting: prevent a single large deposit from monopolizing capacity.
11171117 // Excess is queued to be processed asynchronously (see asyncUpdatePosition).
11181118 let depositAmount = from .balance
1119- let depositLimit = tokenState .depositLimit ()
1120-
1121- if depositAmount > depositLimit {
1122- // The deposit is too big, so we need to queue the excess
1123- let queuedDeposit <- from .withdraw (amount : depositAmount - depositLimit )
1124-
1125- position .depositToQueue (type , vault : <- queuedDeposit )
1126- }
1119+ var depositLimit = tokenState .depositLimit ()
11271120
11281121 // Per-user deposit limit: check if user has exceeded their per-user limit
11291122 let userDepositLimitCap = tokenState .getUserDepositLimitCap ()
11301123 let currentUsage = tokenState .getDepositUsageForPosition (pid )
11311124 let remainingUserLimit = userDepositLimitCap - currentUsage
1125+ if remainingUserLimit < depositLimit {
1126+ depositLimit = remainingUserLimit
1127+ }
11321128
1133- // If the deposit would exceed the user's limit, queue or reject the excess
1134- if from .balance > remainingUserLimit {
1135- let excessAmount = from .balance - remainingUserLimit
1136- let queuedForUserLimit <- from .withdraw (amount : excessAmount )
1137-
1138- position .depositToQueue (type , vault : <- queuedForUserLimit )
1129+ // depositAmount is bounded by the smaller of:
1130+ // User deposit limit, per-deposit limit, and global deposit capacity
1131+ // If the deposit would exceed a limit, queue or reject the excess
1132+ if depositAmount > depositLimit {
1133+ let excessAmount = depositAmount - depositLimit
1134+ let queuedDeposit <- from .withdraw (amount : excessAmount )
1135+ position .depositToQueue (type , vault : <- queuedDeposit )
11391136 }
11401137
11411138 // If this position doesn't currently have an entry for this token, create one.
0 commit comments