@@ -1700,8 +1700,9 @@ access(all) contract TidalProtocol {
17001700 return Position (id : pid , pool : cap )
17011701 }
17021702
1703- // A convenience function for computing a health value from effective collateral and debt values.
1704- access (all ) fun healthComputation (effectiveCollateral : UFix64 , effectiveDebt : UFix64 ): UFix64 {
1703+ /// Returns a health value computed from the provided effective collateral and debt values where health is a ratio
1704+ /// of effective collateral over effective debt
1705+ access (all ) view fun healthComputation (effectiveCollateral : UFix64 , effectiveDebt : UFix64 ): UFix64 {
17051706 var health = 0.0
17061707
17071708 if effectiveCollateral == 0.0 {
@@ -1719,20 +1720,19 @@ access(all) contract TidalProtocol {
17191720 return health
17201721 }
17211722
1722- // A multiplication function for interest calculations. It assumes that both values are very close to 1
1723- // and represent fixed point numbers with 16 decimal places of precision.
1724- access (all ) fun interestMul (_ a : UInt64 , _ b : UInt64 ): UInt64 {
1723+ /// A multiplication function for interest calculations. It assumes that both values are very close to 1 and
1724+ /// represent fixed point numbers with 16 decimal places of precision.
1725+ access (all ) view fun interestMul (_ a : UInt64 , _ b : UInt64 ): UInt64 {
17251726 let aScaled = a / 100000000
17261727 let bScaled = b / 100000000
17271728
17281729 return aScaled * bScaled
17291730 }
17301731
1731- // Converts a yearly interest rate (as a UFix64) to a per-second multiplication factor
1732- // (stored in a UInt64 as a fixed point number with 16 decimal places). The input to this function will be
1733- // just the relative interest rate (e.g. 0.05 for 5% interest), but the result will be
1734- // the per-second multiplier (e.g. 1.000000000001).
1735- access (all ) fun perSecondInterestRate (yearlyRate : UFix64 ): UInt64 {
1732+ /// Converts a yearly interest rate (as a UFix64) to a per-second multiplication factor (stored in a UInt64 as a
1733+ /// fixed point number with 16 decimal places). The input to this function will be just the relative interest rate
1734+ /// (e.g. 0.05 for 5% interest), but the result will be the per-second multiplier (e.g. 1.000000000001).
1735+ access (all ) view fun perSecondInterestRate (yearlyRate : UFix64 ): UInt64 {
17361736 // Covert the yearly rate to an integer maintaning the 10^8 multiplier of UFix64.
17371737 // We would need to multiply by an additional 10^8 to match the promised multiplier of
17381738 // 10^16. HOWEVER, since we are about to divide by 31536000, we can save multiply a factor
@@ -1743,9 +1743,9 @@ access(all) contract TidalProtocol {
17431743 return perSecondScaledValue
17441744 }
17451745
1746- // Updates an interest index to reflect the passage of time. The result is:
1747- // newIndex = oldIndex * perSecondRate^ seconds
1748- access (all ) fun compoundInterestIndex (oldIndex : UInt64 , perSecondRate : UInt64 , elapsedSeconds : UFix64 ): UInt64 {
1746+ /// Returns the compounded interest index reflecting the passage of time
1747+ /// The result is: newIndex = oldIndex * perSecondRate ^ seconds
1748+ access (all ) view fun compoundInterestIndex (oldIndex : UInt64 , perSecondRate : UInt64 , elapsedSeconds : UFix64 ): UInt64 {
17491749 var result = oldIndex
17501750 var current = perSecondRate
17511751 var secondsCounter = UInt64 (elapsedSeconds )
@@ -1761,15 +1761,19 @@ access(all) contract TidalProtocol {
17611761 return result
17621762 }
17631763
1764- access (all ) fun scaledBalanceToTrueBalance (scaledBalance : UFix64 , interestIndex : UInt64 ): UFix64 {
1764+ /// Transforms the provided `scaledBalance` to a true balance
1765+ // TODO: Clarify what "scaled" and "true" balances signify
1766+ access (all ) view fun scaledBalanceToTrueBalance (scaledBalance : UFix64 , interestIndex : UInt64 ): UFix64 {
17651767 // The interest index is essentially a fixed point number with 16 decimal places, we convert
17661768 // it to a UFix64 by copying the byte representation, and then dividing by 10^8 (leaving and
17671769 // additional 10^8 as required for the UFix64 representation).
17681770 let indexMultiplier = UFix64.fromBigEndianBytes (interestIndex .toBigEndianBytes ())! / 100000000.0
17691771 return scaledBalance * indexMultiplier
17701772 }
17711773
1772- access (all ) fun trueBalanceToScaledBalance (trueBalance : UFix64 , interestIndex : UInt64 ): UFix64 {
1774+ /// Transforms the provided `trueBalance` to a scaled balance
1775+ // TODO: Clarify what "scaled" and "true" balances signify
1776+ access (all ) view fun trueBalanceToScaledBalance (trueBalance : UFix64 , interestIndex : UInt64 ): UFix64 {
17731777 // The interest index is essentially a fixed point number with 16 decimal places, we convert
17741778 // it to a UFix64 by copying the byte representation, and then dividing by 10^8 (leaving and
17751779 // additional 10^8 as required for the UFix64 representation).
@@ -1779,11 +1783,13 @@ access(all) contract TidalProtocol {
17791783
17801784 /* --- INTERNAL METHODS --- */
17811785
1786+ /// Returns an authorized reference to the contract account's Pool resource
17821787 access (self ) view fun _borrowPool (): auth (EPosition ) &Pool {
17831788 return self .account .storage .borrow <auth (EPosition ) &Pool >(from : self .PoolStoragePath )
17841789 ?? panic (" Could not borrow reference to internal TidalProtocol Pool resource" )
17851790 }
17861791
1792+ /// Returns a reference to the contract account's MOET Minter resource
17871793 access (self ) view fun _borrowMOETMinter (): &MOET.Minter {
17881794 return self .account .storage .borrow <&MOET.Minter >(from : MOET .AdminStoragePath )
17891795 ?? panic (" Could not borrow reference to internal MOET Minter resource" )
@@ -1794,7 +1800,7 @@ access(all) contract TidalProtocol {
17941800 self .PoolFactoryPath = StoragePath (identifier : " tidalProtocolPoolFactory_\( self .account .address ) " )!
17951801 self .PoolPublicPath = PublicPath (identifier : " tidalProtocolPool_\( self .account .address ) " )!
17961802
1797- // save PoolFactory in storage & configure public Capability
1803+ // save PoolFactory in storage
17981804 self .account .storage .save (
17991805 <- create PoolFactory (),
18001806 to : self .PoolFactoryPath
0 commit comments