@@ -112,6 +112,9 @@ fun test_per_user_deposit_limits() {
112112 // Calculate expected per-user limit
113113 let expectedUserLimit = initialCap * depositLimitFraction // 10000 * 0.05 = 500
114114
115+ var capacityInfo = getDepositCapacityInfo (vaultIdentifier : MOET_TOKEN_IDENTIFIER )
116+ Test .assertEqual (initialCap , capacityInfo [" depositCapacity" ]! )
117+
115118 // Setup user 1
116119 let user1 = Test .createAccount ()
117120 setupMoetVault (user1 , beFailed : false )
@@ -124,15 +127,23 @@ fun test_per_user_deposit_limits() {
124127 // User 1 deposits more (should be accepted up to limit)
125128 let user1Deposit1 = 300.0 // After this: usage = 400 (out of 500 limit)
126129 depositToPosition (signer : user1 , positionID : 0 , amount : user1Deposit1 , vaultStoragePath : MOET .VaultStoragePath , pushToDrawDownSink : false )
127-
130+
131+ capacityInfo = getDepositCapacityInfo (vaultIdentifier : MOET_TOKEN_IDENTIFIER )
132+ Test .assertEqual (initialCap - 400.0 , capacityInfo [" depositCapacity" ]! )
133+
128134 // User 1 deposits more (should be partially accepted, partially queued)
129135 let user1Deposit2 = 200.0 // Only 100 more can be accepted to reach limit of 500, 100 will be queued
130136 depositToPosition (signer : user1 , positionID : 0 , amount : user1Deposit2 , vaultStoragePath : MOET .VaultStoragePath , pushToDrawDownSink : false )
131137 // After this: usage = 500 (at limit), 100 queued
138+ capacityInfo = getDepositCapacityInfo (vaultIdentifier : MOET_TOKEN_IDENTIFIER )
139+ Test .assertEqual (initialCap - 500.0 , capacityInfo [" depositCapacity" ]! )
132140
133141 // User 1 tries to deposit more (should be queued due to per-user limit)
134142 let user1Deposit3 = 100.0 // This should be queued (user already at limit)
135- depositToPosition (signer : user1 , positionID : 0 , amount : user1Deposit3 , vaultStoragePath : MOET .VaultStoragePath , pushToDrawDownSink : false ) // Transaction succeeds but deposit is queued
143+ depositToPosition (signer : user1 , positionID : 0 , amount : user1Deposit3 , vaultStoragePath : MOET .VaultStoragePath , pushToDrawDownSink : false )
144+ // Transaction succeeds but deposit is queued
145+ capacityInfo = getDepositCapacityInfo (vaultIdentifier : MOET_TOKEN_IDENTIFIER )
146+ Test .assertEqual (initialCap - 500.0 , capacityInfo [" depositCapacity" ]! )
136147
137148 // Setup user 2 - they should have their own independent limit
138149 let user2 = Test .createAccount ()
@@ -141,25 +152,35 @@ fun test_per_user_deposit_limits() {
141152
142153 let initialDeposit2 = 100.0
143154 createPosition (admin : PROTOCOL_ACCOUNT , signer : user2 , amount : initialDeposit2 , vaultStoragePath : MOET .VaultStoragePath , pushToDrawDownSink : false )
144- // After position creation: usage = 100 (out of 500 limit)
155+ // After position creation: user usage = 100 (out of 500 limit); total usage is 600
156+ capacityInfo = getDepositCapacityInfo (vaultIdentifier : MOET_TOKEN_IDENTIFIER )
157+ Test .assertEqual (initialCap - 600.0 , capacityInfo [" depositCapacity" ]! )
145158
146159 // User 2 should be able to deposit up to their own limit (500 total, so 400 more)
147160 let user2Deposit = 400.0
148161 depositToPosition (signer : user2 , positionID : 1 , amount : user2Deposit , vaultStoragePath : MOET .VaultStoragePath , pushToDrawDownSink : false )
149- // After this: usage = 500 (at limit)
150-
151- // Verify that both users have independent limits by checking capacity
152- // Get capacity after all deposits
153- var capacityInfo = getDepositCapacityInfo (vaultIdentifier : MOET_TOKEN_IDENTIFIER )
154- let finalCapacity = capacityInfo [" depositCapacity" ]!
162+ // After this: user usage = 500 (at limit); total usage is 1000
163+ capacityInfo = getDepositCapacityInfo (vaultIdentifier : MOET_TOKEN_IDENTIFIER )
164+ Test .assertEqual (initialCap - 1000.0 , capacityInfo [" depositCapacity" ]! )
155165
166+ // Setup user 3 - they should be able to deposit up to the user limit in a single deposit
167+ let user3 = Test .createAccount ()
168+ setupMoetVault (user3 , beFailed : false )
169+ mintMoet (signer : PROTOCOL_ACCOUNT , to : user3 .address , amount : 10000.0 , beFailed : false )
170+
171+ let initialDeposit3 = 500.0
172+ createPosition (admin : PROTOCOL_ACCOUNT , signer : user3 , amount : initialDeposit3 , vaultStoragePath : MOET .VaultStoragePath , pushToDrawDownSink : false )
173+ // After position creation: user usage = 500 (out of 500 limit); total usage is 1500
174+ capacityInfo = getDepositCapacityInfo (vaultIdentifier : MOET_TOKEN_IDENTIFIER )
175+ Test .assertEqual (initialCap - 1500.0 , capacityInfo [" depositCapacity" ]! )
176+
156177 // Total accepted deposits:
157178 // user1 = 500 (100 initial + 300 + 100 from deposit2, 100 from deposit2 queued, 100 from deposit3 queued)
158179 // user2 = 500 (100 initial + 400)
159- // total = 1000
160- // We need to check that capacity decreased by at least 1000 from some initial value
161- Test . assert ( finalCapacity < = initialCap - 1000.0 ,
162- message : " Final capacity \( finalCapacity ) should be <= initial cap \( initialCap ) - 1000 " )
180+ // user3 = 500 (500 initial)
181+ // total = 1500
182+ // since queued deposits do not consume any deposit capacity, and none of the deposits should have been
183+ // affected by the per-deposit limit, the total capacity should have decreased by exactly 1500.0
163184}
164185
165186// -----------------------------------------------------------------------------
0 commit comments