ghoUtilities.spec.ts
1 import { weightedAverageAPY } from '../ghoUtilities'; 2 3 describe('gho utilities', () => { 4 it('calculates the weighted average APY correctly', () => { 5 const baseBorrowRate = 0.02; // 2% 6 const totalBorrowAmount = 1000; 7 const discountableAmount = 100; 8 const borrowRateAfterDiscount = 0.016; // 1.6% 9 10 const apy = weightedAverageAPY( 11 baseBorrowRate, 12 totalBorrowAmount, 13 discountableAmount, 14 borrowRateAfterDiscount 15 ); 16 17 expect(apy.toPrecision(3)).toEqual('0.0196'); 18 }); 19 20 it('calculates the weighted average APY correctly when total borrow amount is 0', () => { 21 const baseBorrowRate = 0.02; // 2% 22 const totalBorrowAmount = 0; 23 const discountableAmount = 100; 24 const borrowRateAfterDiscount = 0.016; // 1.6% 25 26 const apy = weightedAverageAPY( 27 baseBorrowRate, 28 totalBorrowAmount, 29 discountableAmount, 30 borrowRateAfterDiscount 31 ); 32 33 expect(apy.toPrecision(3)).toEqual('0.0160'); 34 }); 35 it('calculates the weighted average APY correctly when total borrow amount is less then the discountable amount', () => { 36 const baseBorrowRate = 0.02; // 2% 37 const totalBorrowAmount = 500; 38 const discountableAmount = 1000; 39 const borrowRateAfterDiscount = 0.016; // 1.6% 40 41 const apy = weightedAverageAPY( 42 baseBorrowRate, 43 totalBorrowAmount, 44 discountableAmount, 45 borrowRateAfterDiscount 46 ); 47 48 expect(apy.toPrecision(3)).toEqual('0.0160'); 49 }); 50 });