@@ -25,12 +25,12 @@ struct BondTranches {
2525 */
2626library BondTranchesHelpers {
2727 /// @notice Iterates through the tranche data to find the seniority index of the given tranche.
28- /// @param td The tranche data object.
28+ /// @param bt The tranche data object.
2929 /// @param t The address of the tranche to check.
3030 /// @return the index of the tranche in the tranches array.
31- function indexOf (BondTranches memory td , ITranche t ) internal pure returns (uint8 ) {
32- for (uint8 i = 0 ; i < td .tranches.length ; i++ ) {
33- if (td .tranches[i] == t) {
31+ function indexOf (BondTranches memory bt , ITranche t ) internal pure returns (uint8 ) {
32+ for (uint8 i = 0 ; i < bt .tranches.length ; i++ ) {
33+ if (bt .tranches[i] == t) {
3434 return i;
3535 }
3636 }
@@ -50,11 +50,11 @@ library TrancheHelpers {
5050 /// @return The collateral balance and the tranche token supply.
5151 function getTrancheCollateralization (ITranche t ) internal view returns (uint256 , uint256 ) {
5252 IBondController bond = IBondController (t.bond ());
53- BondTranches memory td ;
53+ BondTranches memory bt ;
5454 uint256 [] memory collateralBalances;
5555 uint256 [] memory trancheSupplies;
56- (td , collateralBalances, trancheSupplies) = BondHelpers.getTrancheCollateralizations (bond);
57- uint256 trancheIndex = BondTranchesHelpers.indexOf (td , t);
56+ (bt , collateralBalances, trancheSupplies) = BondHelpers.getTrancheCollateralizations (bond);
57+ uint256 trancheIndex = BondTranchesHelpers.indexOf (bt , t);
5858 return (collateralBalances[trancheIndex], trancheSupplies[trancheIndex]);
5959 }
6060}
@@ -86,17 +86,17 @@ library BondHelpers {
8686 /// @param b The address of the bond contract.
8787 /// @return The tranche data.
8888 function getTranches (IBondController b ) internal view returns (BondTranches memory ) {
89- BondTranches memory td ;
89+ BondTranches memory bt ;
9090 uint8 trancheCount = b.trancheCount ().toUint8 ();
91- td .tranches = new ITranche [](trancheCount);
92- td .trancheRatios = new uint256 [](trancheCount);
91+ bt .tranches = new ITranche [](trancheCount);
92+ bt .trancheRatios = new uint256 [](trancheCount);
9393 // Max tranches per bond < 2**8 - 1
9494 for (uint8 i = 0 ; i < trancheCount; i++ ) {
9595 (ITranche t , uint256 ratio ) = b.tranches (i);
96- td .tranches[i] = t;
97- td .trancheRatios[i] = ratio;
96+ bt .tranches[i] = t;
97+ bt .trancheRatios[i] = ratio;
9898 }
99- return td ;
99+ return bt ;
100100 }
101101
102102 /// @notice Given a bond, returns the tranche at the specified index.
@@ -122,29 +122,29 @@ library BondHelpers {
122122 uint256 [] memory
123123 )
124124 {
125- BondTranches memory td = getTranches (b);
126- uint256 [] memory trancheAmts = new uint256 [](td .tranches.length );
127- uint256 [] memory fees = new uint256 [](td .tranches.length );
125+ BondTranches memory bt = getTranches (b);
126+ uint256 [] memory trancheAmts = new uint256 [](bt .tranches.length );
127+ uint256 [] memory fees = new uint256 [](bt .tranches.length );
128128
129129 uint256 totalDebt = b.totalDebt ();
130130 uint256 collateralBalance = IERC20Upgradeable (b.collateralToken ()).balanceOf (address (b));
131131 uint256 feeBps = b.feeBps ();
132132
133- for (uint8 i = 0 ; i < td .tranches.length ; i++ ) {
134- trancheAmts[i] = collateralAmount.mulDiv (td .trancheRatios[i], TRANCHE_RATIO_GRANULARITY);
133+ for (uint8 i = 0 ; i < bt .tranches.length ; i++ ) {
134+ trancheAmts[i] = collateralAmount.mulDiv (bt .trancheRatios[i], TRANCHE_RATIO_GRANULARITY);
135135 if (collateralBalance > 0 ) {
136136 trancheAmts[i] = trancheAmts[i].mulDiv (totalDebt, collateralBalance);
137137 }
138138 }
139139
140140 if (feeBps > 0 ) {
141- for (uint8 i = 0 ; i < td .tranches.length ; i++ ) {
141+ for (uint8 i = 0 ; i < bt .tranches.length ; i++ ) {
142142 fees[i] = trancheAmts[i].mulDiv (feeBps, BPS);
143143 trancheAmts[i] -= fees[i];
144144 }
145145 }
146146
147- return (td , trancheAmts, fees);
147+ return (bt , trancheAmts, fees);
148148 }
149149
150150 /// @notice Given a bond, for each tranche token retrieves the total collateral redeemable
@@ -162,24 +162,24 @@ library BondHelpers {
162162 uint256 [] memory
163163 )
164164 {
165- BondTranches memory td = getTranches (b);
166- uint256 [] memory collateralBalances = new uint256 [](td .tranches.length );
167- uint256 [] memory trancheSupplies = new uint256 [](td .tranches.length );
165+ BondTranches memory bt = getTranches (b);
166+ uint256 [] memory collateralBalances = new uint256 [](bt .tranches.length );
167+ uint256 [] memory trancheSupplies = new uint256 [](bt .tranches.length );
168168
169169 // When the bond is mature, the collateral is transferred over to the individual tranche token contracts
170170 if (b.isMature ()) {
171- for (uint8 i = 0 ; i < td .tranches.length ; i++ ) {
172- trancheSupplies[i] = td .tranches[i].totalSupply ();
173- collateralBalances[i] = IERC20Upgradeable (b.collateralToken ()).balanceOf (address (td .tranches[i]));
171+ for (uint8 i = 0 ; i < bt .tranches.length ; i++ ) {
172+ trancheSupplies[i] = bt .tranches[i].totalSupply ();
173+ collateralBalances[i] = IERC20Upgradeable (b.collateralToken ()).balanceOf (address (bt .tranches[i]));
174174 }
175- return (td , collateralBalances, trancheSupplies);
175+ return (bt , collateralBalances, trancheSupplies);
176176 }
177177
178178 // Before the bond is mature, all the collateral is held by the bond contract
179179 uint256 bondCollateralBalance = IERC20Upgradeable (b.collateralToken ()).balanceOf (address (b));
180- uint256 zTrancheIndex = td .tranches.length - 1 ;
181- for (uint8 i = 0 ; i < td .tranches.length ; i++ ) {
182- trancheSupplies[i] = td .tranches[i].totalSupply ();
180+ uint256 zTrancheIndex = bt .tranches.length - 1 ;
181+ for (uint8 i = 0 ; i < bt .tranches.length ; i++ ) {
182+ trancheSupplies[i] = bt .tranches[i].totalSupply ();
183183
184184 // a to y tranches
185185 if (i != zTrancheIndex) {
@@ -194,7 +194,7 @@ library BondHelpers {
194194 }
195195 }
196196
197- return (td , collateralBalances, trancheSupplies);
197+ return (bt , collateralBalances, trancheSupplies);
198198 }
199199
200200 /// @notice For a given bond and user address, computes the maximum number of each of the bond's tranches
@@ -207,29 +207,29 @@ library BondHelpers {
207207 view
208208 returns (BondTranches memory , uint256 [] memory )
209209 {
210- BondTranches memory td = getTranches (b);
211- uint256 [] memory redeemableAmts = new uint256 [](td .tranches.length );
210+ BondTranches memory bt = getTranches (b);
211+ uint256 [] memory redeemableAmts = new uint256 [](bt .tranches.length );
212212
213213 // Calculate how many underlying assets could be redeemed from each tranche balance,
214214 // assuming other tranches are not an issue, and record the smallest amount.
215215 uint256 minUnderlyingOut = type (uint256 ).max;
216216 uint8 i;
217- for (i = 0 ; i < td .tranches.length ; i++ ) {
218- uint256 d = td .tranches[i].balanceOf (u).mulDiv (TRANCHE_RATIO_GRANULARITY, td .trancheRatios[i]);
217+ for (i = 0 ; i < bt .tranches.length ; i++ ) {
218+ uint256 d = bt .tranches[i].balanceOf (u).mulDiv (TRANCHE_RATIO_GRANULARITY, bt .trancheRatios[i]);
219219 if (d < minUnderlyingOut) {
220220 minUnderlyingOut = d;
221221 }
222222
223223 // if one of the balances is zero, we return
224224 if (minUnderlyingOut == 0 ) {
225- return (td , redeemableAmts);
225+ return (bt , redeemableAmts);
226226 }
227227 }
228228
229- for (i = 0 ; i < td .tranches.length ; i++ ) {
230- redeemableAmts[i] = td .trancheRatios[i].mulDiv (minUnderlyingOut, TRANCHE_RATIO_GRANULARITY);
229+ for (i = 0 ; i < bt .tranches.length ; i++ ) {
230+ redeemableAmts[i] = bt .trancheRatios[i].mulDiv (minUnderlyingOut, TRANCHE_RATIO_GRANULARITY);
231231 }
232232
233- return (td , redeemableAmts);
233+ return (bt , redeemableAmts);
234234 }
235235}
0 commit comments