prevent total liquidity stat from going negative
This commit is contained in:
		
							parent
							
								
									cc4b9abd9f
								
							
						
					
					
						commit
						c3b15ac5dc
					
				|  | @ -78,7 +78,13 @@ export const withdrawLiquidity = functions | ||||||
|           } as Partial<User>) |           } as Partial<User>) | ||||||
| 
 | 
 | ||||||
|           const newPool = subtractObjects(contract.pool, userShares) |           const newPool = subtractObjects(contract.pool, userShares) | ||||||
|           const newTotalLiquidity = contract.totalLiquidity - payout | 
 | ||||||
|  |           const minPoolShares = Math.min(...Object.values(newPool)) | ||||||
|  |           const adjustedTotal = contract.totalLiquidity - payout | ||||||
|  | 
 | ||||||
|  |           // total liquidity is a bogus number; use minPoolShares to prevent from going negative
 | ||||||
|  |           const newTotalLiquidity = Math.max(adjustedTotal, minPoolShares) | ||||||
|  | 
 | ||||||
|           trans.update(contractDoc, { |           trans.update(contractDoc, { | ||||||
|             pool: newPool, |             pool: newPool, | ||||||
|             totalLiquidity: newTotalLiquidity, |             totalLiquidity: newTotalLiquidity, | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user