mirror of
				https://github.com/Instadapp/assembly.git
				synced 2024-07-29 22:37:06 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			32 lines
		
	
	
		
			747 B
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
			
		
		
	
	
			32 lines
		
	
	
		
			747 B
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
| import { useBigNumber } from './useBigNumber'
 | |
| 
 | |
| export function usePosition() {
 | |
|   const { isZero, minus, gt, lt, plus } = useBigNumber()
 | |
| 
 | |
|   function getType(position) {
 | |
|     const supply = position.supply
 | |
|     let borrow = position.borrow
 | |
|     if (!isZero(position.borrowStable)) {
 | |
|       borrow = plus(borrow, position.borrowStable)
 | |
|     }
 | |
| 
 | |
|     const diff = minus(supply, borrow)
 | |
| 
 | |
|     if (isZero(diff)) return 'no'
 | |
|     if (gt(diff, '0')) return 'supply'
 | |
|     if (lt(diff, '0')) return 'borrow'
 | |
|   }
 | |
| 
 | |
|   function translateType(type) {
 | |
|     if (type === 'borrow') {
 | |
|       return 'Borrowed'
 | |
|     } else if (type === 'supply') {
 | |
|       return 'Supplied'
 | |
|     } else if (type === 'no') {
 | |
|       return 'No position'
 | |
|     }
 | |
|   }
 | |
| 
 | |
|   return { getType, translateType }
 | |
| }
 | 
