-
Notifications
You must be signed in to change notification settings - Fork 2
Start on interest rate implementation #75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
| } | ||
|
|
||
| // If no credit balance, nothing to collect | ||
| if self.totalCreditBalance == 0.0 as UFix128 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to static cast, the type is already inferred
| if self.totalCreditBalance == 0.0 as UFix128 { | |
| if self.totalCreditBalance == 0.0 { |
| let secondsPerYear: UFix64 = 365.25 * 24.0 * 60.0 * 60.0 | ||
| let yearsElapsed = timeElapsed / secondsPerYear | ||
| let insuranceRate: UFix128 = FlowCreditMarketMath.toUFix128(self.insuranceRate) | ||
| // Insurance amount is a percentage of total credit balance per year | ||
| let insuranceAmount: UFix128 = self.totalCreditBalance * insuranceRate * FlowCreditMarketMath.toUFix128(yearsElapsed) | ||
| let insuranceAmountUFix64 = FlowCreditMarketMath.toUFix64RoundDown(insuranceAmount) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Type annotations are not needed, types can get inferred.
Also, FlowCreditMarketMath.toUFix128 is not needed, just call the UFix128 conversion function directly
| let secondsPerYear: UFix64 = 365.25 * 24.0 * 60.0 * 60.0 | |
| let yearsElapsed = timeElapsed / secondsPerYear | |
| let insuranceRate: UFix128 = FlowCreditMarketMath.toUFix128(self.insuranceRate) | |
| // Insurance amount is a percentage of total credit balance per year | |
| let insuranceAmount: UFix128 = self.totalCreditBalance * insuranceRate * FlowCreditMarketMath.toUFix128(yearsElapsed) | |
| let insuranceAmountUFix64 = FlowCreditMarketMath.toUFix64RoundDown(insuranceAmount) | |
| let secondsPerYear = 365.25 * 24.0 * 60.0 * 60.0 | |
| let yearsElapsed = timeElapsed / secondsPerYear | |
| let insuranceRate = UFix128(self.insuranceRate) | |
| // Insurance amount is a percentage of total credit balance per year | |
| let insuranceAmount = self.totalCreditBalance * insuranceRate * FlowCreditMarketMath.toUFix128(yearsElapsed) | |
| let insuranceAmountUFix64 = FlowCreditMarketMath.toUFix64RoundDown(insuranceAmount) |
| // Validate swapper output type (input type is already validated when swapper is set) | ||
| assert(self.insuranceSwapper!.outType() == Type<@MOET.Vault>(), message: "Insurance swapper must output MOET") | ||
|
|
||
| // Get quote and perform swap | ||
| let quote = self.insuranceSwapper!.quoteOut(forProvided: amountToCollect, reverse: false) | ||
| var moetVault <- self.insuranceSwapper!.swap(quote: quote, inVault: <-insuranceVault) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid force unwrapping, repeatedly:
| // Validate swapper output type (input type is already validated when swapper is set) | |
| assert(self.insuranceSwapper!.outType() == Type<@MOET.Vault>(), message: "Insurance swapper must output MOET") | |
| // Get quote and perform swap | |
| let quote = self.insuranceSwapper!.quoteOut(forProvided: amountToCollect, reverse: false) | |
| var moetVault <- self.insuranceSwapper!.swap(quote: quote, inVault: <-insuranceVault) | |
| let insuranceSwapper = self.insuranceSwapper ?? panic("missing insurance swapper") | |
| // Validate swapper output type (input type is already validated when swapper is set) | |
| assert(insuranceSwapper.outType() == Type<@MOET.Vault>(), message: "Insurance swapper must output MOET") | |
| // Get quote and perform swap | |
| let quote = insuranceSwapper.quoteOut(forProvided: amountToCollect, reverse: false) | |
| var moetVault <- insuranceSwapper.swap(quote: quote, inVault: <-insuranceVault) |
|
|
||
| /// Returns the balance of the MOET insurance fund | ||
| access(all) view fun insuranceFundBalance(): UFix64 { | ||
| let fundRef = (&self.insuranceFund as &MOET.Vault) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here and below: Remove unnecessary parentheses
| let fundRef = (&self.insuranceFund as &MOET.Vault) | |
| let fundRef = &self.insuranceFund as &MOET.Vault |
| if swapper != nil { | ||
| // Validate swapper types match | ||
| assert(swapper!.inType() == tokenType, message: "Swapper input type must match token type") | ||
| assert(swapper!.outType() == Type<@MOET.Vault>(), message: "Swapper output type must be MOET") | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid force unwrapping, use if-let instead:
| if swapper != nil { | |
| // Validate swapper types match | |
| assert(swapper!.inType() == tokenType, message: "Swapper input type must match token type") | |
| assert(swapper!.outType() == Type<@MOET.Vault>(), message: "Swapper output type must be MOET") | |
| } | |
| if let swapper = swapper { | |
| // Validate swapper types match | |
| assert(swapper.inType() == tokenType, message: "Swapper input type must match token type") | |
| assert(swapper.outType() == Type<@MOET.Vault>(), message: "Swapper output type must be MOET") | |
| } |
Description
Implementation of insurance fund
For contributor use:
masterbranchFiles changedin the Github PR explorer