Skip to content

Commit 438eb6a

Browse files
committed
use if-let, remove redundant type annotations and force unwraps
1 parent d3ed3ce commit 438eb6a

7 files changed

Lines changed: 24 additions & 25 deletions

File tree

cadence/contracts/FlowYieldVaultsAutoBalancers.cdc

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ access(all) contract FlowYieldVaultsAutoBalancers {
114114
}
115115

116116
let currentTimestamp = getCurrentBlock().timestamp
117-
let optimisticExecutionGracePeriod: UFix64 = 15.0
117+
let optimisticExecutionGracePeriod = 15.0
118118
let txnIDs = autoBalancer!.getScheduledTransactionIDs()
119119
for txnID in txnIDs {
120120
if let scheduledTxn = autoBalancer!.borrowScheduledTransaction(id: txnID) {
@@ -270,9 +270,8 @@ access(all) contract FlowYieldVaultsAutoBalancers {
270270
// This schedules the first rebalance; subsequent ones are scheduled automatically
271271
// by the AutoBalancer after each execution (via recurringConfig)
272272
if recurringConfig != nil {
273-
let scheduleError = autoBalancerRef.scheduleNextRebalance(whileExecuting: nil)
274-
if scheduleError != nil {
275-
panic("Failed to schedule first rebalance for AutoBalancer \(uniqueID.id): ".concat(scheduleError!))
273+
if let scheduleError = autoBalancerRef.scheduleNextRebalance(whileExecuting: nil) {
274+
panic("Failed to schedule first rebalance for AutoBalancer \(uniqueID.id): \(scheduleError)")
276275
}
277276
}
278277

cadence/contracts/FlowYieldVaultsStrategiesV2.cdc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ access(all) contract FlowYieldVaultsStrategiesV2 {
159159
)
160160

161161
// Step 2: Calculate total debt amount
162-
var totalDebtAmount: UFix64 = 0.0
162+
var totalDebtAmount = 0.0
163163
for debtAmount in debtsByType.values {
164164
totalDebtAmount = totalDebtAmount + debtAmount
165165
}
@@ -193,7 +193,7 @@ access(all) contract FlowYieldVaultsStrategiesV2 {
193193
?? panic("Could not create external source from AutoBalancer")
194194

195195
// Step 5: Retrieve yield→MOET swapper from contract config
196-
let swapperKey = FlowYieldVaultsStrategiesV2.getYieldToMoetSwapperConfigKey(self.uniqueID)!
196+
let swapperKey = FlowYieldVaultsStrategiesV2.getYieldToMoetSwapperConfigKey(self.uniqueID)
197197
let yieldToMoetSwapper = FlowYieldVaultsStrategiesV2.config[swapperKey] as! {DeFiActions.Swapper}?
198198
?? panic("No yield→MOET swapper found for strategy \(self.id()!)")
199199

@@ -464,7 +464,7 @@ access(all) contract FlowYieldVaultsStrategiesV2 {
464464
balancerIO.autoBalancer.setSource(positionSwapSource, updateSourceID: true)
465465

466466
// Store yield→MOET swapper in contract config for later access during closePosition
467-
let yieldToMoetSwapperKey = FlowYieldVaultsStrategiesV2.getYieldToMoetSwapperConfigKey(uniqueID)!
467+
let yieldToMoetSwapperKey = FlowYieldVaultsStrategiesV2.getYieldToMoetSwapperConfigKey(uniqueID)
468468
FlowYieldVaultsStrategiesV2.config[yieldToMoetSwapperKey] = yieldToMoetSwapper
469469

470470
// @TODO implement moet to collateral swapper
@@ -907,7 +907,7 @@ access(all) contract FlowYieldVaultsStrategiesV2 {
907907
for stratType in config {
908908
let newPerCollateral = config[stratType]!
909909
let existingPerCollateral = mergedComposerConfig[stratType] ?? {}
910-
var mergedPerCollateral: {Type: FlowYieldVaultsStrategiesV2.CollateralConfig} = existingPerCollateral
910+
var mergedPerCollateral = existingPerCollateral
911911

912912
for collateralType in newPerCollateral {
913913
mergedPerCollateral[collateralType] = newPerCollateral[collateralType]!

cadence/contracts/PMStrategiesV1.cdc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -603,12 +603,12 @@ access(all) contract PMStrategiesV1 {
603603
}
604604
// Merge instead of overwrite
605605
let existingComposerConfig = self.configs[composer] ?? {}
606-
var mergedComposerConfig: {Type: {Type: {String: AnyStruct}}} = existingComposerConfig
606+
var mergedComposerConfig = existingComposerConfig
607607

608608
for stratType in config {
609609
let newPerCollateral = config[stratType]!
610610
let existingPerCollateral = mergedComposerConfig[stratType] ?? {}
611-
var mergedPerCollateral: {Type: {String: AnyStruct}} = existingPerCollateral
611+
var mergedPerCollateral = existingPerCollateral
612612

613613
for collateralType in newPerCollateral {
614614
mergedPerCollateral[collateralType] = newPerCollateral[collateralType]!

cadence/contracts/mocks/EVM.cdc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -736,7 +736,7 @@ contract EVM {
736736
let seenAccountKeyIndices: {Int: Int} = {}
737737
for signatureIndex, signature in signatures{
738738
// index of the key on the account
739-
let accountKeyIndex = Int(keyIndices[signatureIndex]!)
739+
let accountKeyIndex = Int(keyIndices[signatureIndex])
740740
// index of the key in the key list
741741
var keyListIndex = 0
742742

cadence/contracts/mocks/FlowTransactionScheduler.cdc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -548,8 +548,8 @@ access(all) contract FlowTransactionScheduler {
548548

549549
access(all) init() {
550550
self.nextID = 1
551-
self.canceledTransactions = [0 as UInt64]
552-
551+
self.canceledTransactions = [0]
552+
553553
self.transactions = {}
554554
self.slotUsedEffort = {}
555555
self.slotQueue = {}
@@ -707,7 +707,7 @@ access(all) contract FlowTransactionScheduler {
707707
/// @return Status: The status of the transaction, if the transaction is not found Unknown is returned.
708708
access(contract) view fun getStatus(id: UInt64): Status? {
709709
// if the transaction ID is greater than the next ID, it is not scheduled yet and has never existed
710-
if id == 0 as UInt64 || id >= self.nextID {
710+
if id == 0 || id >= self.nextID {
711711
return nil
712712
}
713713

@@ -772,8 +772,8 @@ access(all) contract FlowTransactionScheduler {
772772
executionEffort: executionEffort
773773
)
774774

775-
if estimate.error != nil {
776-
panic(estimate.error!)
775+
if let estimationError = estimate.error {
776+
panic(estimationError)
777777
}
778778

779779
assert (
@@ -1299,7 +1299,7 @@ access(all) contract FlowTransactionScheduler {
12991299
self.slotQueue = {}
13001300
self.slotUsedEffort = {}
13011301
self.sortedTimestamps = SortedTimestamps()
1302-
self.canceledTransactions = [0 as UInt64]
1302+
self.canceledTransactions = [0]
13031303
}
13041304
}
13051305

cadence/contracts/mocks/MockStrategies.cdc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ access(all) contract MockStrategies {
109109
let debtsByType = self.position.getTotalDebt()
110110

111111
// Step 2: Calculate total debt amount across all debt types
112-
var totalDebtAmount: UFix64 = 0.0
112+
var totalDebtAmount = 0.0
113113
for debtAmount in debtsByType.values {
114114
totalDebtAmount = totalDebtAmount + debtAmount
115115
}
@@ -282,7 +282,7 @@ access(all) contract MockStrategies {
282282

283283
// assign token types
284284

285-
let moetTokenType: Type = Type<@MOET.Vault>()
285+
let moetTokenType = Type<@MOET.Vault>()
286286
let yieldTokenType = Type<@YieldToken.Vault>()
287287
// assign collateral & flow token types
288288
let collateralType = withFunds.getType()

cadence/contracts/mocks/incrementfi/SwapPairTemplate.cdc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -407,14 +407,14 @@ access(all) fun swap(vaultIn: @{FungibleToken.Vault}, exactAmountOut: UFix64?):
407407
}
408408
}
409409
/// Check and swap exact output amount if specified in argument
410-
if exactAmountOut != nil {
411-
assert(amountOut >= exactAmountOut!, message:
410+
if let exactAmountOut = exactAmountOut {
411+
assert(amountOut >= exactAmountOut, message:
412412
SwapError.ErrorEncode(
413413
msg: "SwapPair: INSUFFICIENT_OUTPUT_AMOUNT",
414414
err: SwapError.ErrorCode.INSUFFICIENT_OUTPUT_AMOUNT
415415
)
416416
)
417-
amountOut = exactAmountOut!
417+
amountOut = exactAmountOut
418418
}
419419

420420
if (vaultIn.isInstance(self.token0VaultType)) {
@@ -573,12 +573,12 @@ self.lock = false
573573
}
574574

575575
access(all) view fun _rootK(balance0: UFix64, balance1: UFix64): UFix64 {
576-
let e18: UInt256 = SwapConfig.scaleFactor
576+
let e18 = SwapConfig.scaleFactor
577577
let balance0Scaled = SwapConfig.UFix64ToScaledUInt256(balance0)
578578
let balance1Scaled = SwapConfig.UFix64ToScaledUInt256(balance1)
579579
if self.isStableSwap() {
580-
let _p_scaled: UInt256 = SwapConfig.UFix64ToScaledUInt256(self.getStableCurveP())
581-
let _k_scaled: UInt256 = SwapConfig.k_stable_p(balance0Scaled, balance1Scaled, _p_scaled)
580+
let _p_scaled = SwapConfig.UFix64ToScaledUInt256(self.getStableCurveP())
581+
let _k_scaled = SwapConfig.k_stable_p(balance0Scaled, balance1Scaled, _p_scaled)
582582
return SwapConfig.ScaledUInt256ToUFix64(SwapConfig.sqrt(SwapConfig.sqrt(_k_scaled / 2)))
583583
} else {
584584
return SwapConfig.ScaledUInt256ToUFix64(SwapConfig.sqrt(balance0Scaled * balance1Scaled / e18))

0 commit comments

Comments
 (0)