Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions .github/workflows/cadence_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ jobs:
path: ./imports
key: flow-deps-${{ hashFiles('flow.json') }}
- name: Install Flow CLI
env:
FLOW_CLI_VERSION: v2.7.2
run: sh -ci "$(curl -fsSL https://raw.githubusercontent.com/onflow/flow-cli/master/install.sh)"
run: sh -ci "$(curl -fsSL https://raw.githubusercontent.com/onflow/flow-cli/master/install.sh)" -- v2.15.3
- name: Update PATH and show Flow version
run: |
echo "/root/.local/bin" >> $GITHUB_PATH
Expand All @@ -45,7 +43,7 @@ jobs:
- name: Install dependencies
run: flow deps install --skip-alias --skip-deployments
- name: Run tests
run: flow test --cover --covercode="contracts" --coverprofile="coverage.lcov" ./cadence/tests/*_test.cdc
run: make ci
- name: Upload coverage report
uses: codecov/codecov-action@v5
with:
Expand Down
11 changes: 11 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.PHONY: test
test:
flow test --cover --covercode="contracts" --coverprofile="coverage.lcov" ./cadence/tests/*_test.cdc

.PHONY: lint
lint:
find cadence/contracts -name "*.cdc" | xargs flow cadence lint \
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Kay-Zee why only lint contracts and not tests? 59af50b (this PR)

| tee /dev/stderr | tail -n2 | grep -q "Lint passed"
Comment thread
turbolent marked this conversation as resolved.

.PHONY: ci
ci: lint test
4 changes: 2 additions & 2 deletions cadence/contracts/FlowALPHealth.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ access(all) contract FlowALPHealth {
initial: FlowALPModels.Balance,
target: FlowALPModels.Balance
): UFix128 {
let Credit = FlowALPModels.BalanceDirection.Credit
let Credit = FlowALPModels.BalanceDirection.Credit
let Debit = FlowALPModels.BalanceDirection.Debit

if target.direction == Credit && initial.direction == Credit {
Expand Down Expand Up @@ -194,7 +194,7 @@ access(all) contract FlowALPHealth {
initial: FlowALPModels.Balance,
target: FlowALPModels.Balance
): UFix128 {
let Credit = FlowALPModels.BalanceDirection.Credit
let Credit = FlowALPModels.BalanceDirection.Credit
let Debit = FlowALPModels.BalanceDirection.Debit

if target.direction == Debit && initial.direction == Debit {
Expand Down
5 changes: 4 additions & 1 deletion cadence/contracts/FlowALPInterestRates.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ access(all) contract FlowALPInterestRates {
self.yearlyRate = yearlyRate
}

access(all) fun interestRate(creditBalance: UFix128, debitBalance: UFix128): UFix128 {
access(all) fun interestRate(
creditBalance _creditBalance: UFix128,
debitBalance _debitBalance: UFix128
): UFix128 {
return self.yearlyRate
}
}
Expand Down
10 changes: 5 additions & 5 deletions cadence/contracts/FlowALPModels.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -579,8 +579,8 @@ access(all) contract FlowALPModels {
let newDebt = self.effectiveDebtByToken

// Remove old entries for this token from both maps
newCollateral.remove(key: tokenType)
newDebt.remove(key: tokenType)
let _oldCollateral = newCollateral.remove(key: tokenType)
let _oldDebt = newDebt.remove(key: tokenType)

// Add new entry based on direction (only if non-zero)
if effectiveBalance.quantity > 0.0 {
Expand Down Expand Up @@ -951,7 +951,7 @@ access(all) contract FlowALPModels {
/// Gets a swapper from the DEX for the given token pair. See PoolConfig.getSwapperForLiquidation.
access(all) fun getSwapperForLiquidation(seizeType: Type, debtType: Type): {DeFiActions.Swapper} {
return self.dex.getSwapper(inType: seizeType, outType: debtType)
?? panic("No DEX swapper configured for liquidation pair: ".concat(seizeType.identifier).concat(" -> ").concat(debtType.identifier))
?? panic("No DEX swapper configured for liquidation pair: \(seizeType.identifier) -> \(debtType.identifier)")
}

// Setters
Expand Down Expand Up @@ -2202,7 +2202,7 @@ access(all) contract FlowALPModels {

/// Returns an authorized reference to the draw-down sink, or nil if none is configured.
access(EImplementation) fun borrowDrawDownSink(): auth(FungibleToken.Withdraw) &{DeFiActions.Sink}? {
return &self.drawDownSink as auth(FungibleToken.Withdraw) &{DeFiActions.Sink}?
return &self.drawDownSink
}

/// Sets the draw-down sink. Sink must accept MOET deposits, or be nil.
Expand All @@ -2218,7 +2218,7 @@ access(all) contract FlowALPModels {

/// Returns an authorized reference to the top-up source, or nil if none is configured.
access(EImplementation) fun borrowTopUpSource(): auth(FungibleToken.Withdraw) &{DeFiActions.Source}? {
return &self.topUpSource as auth(FungibleToken.Withdraw) &{DeFiActions.Source}?
return &self.topUpSource
}

/// Sets the top-up source. See InternalPosition.setTopUpSource.
Expand Down
6 changes: 3 additions & 3 deletions cadence/contracts/FlowALPPositionResources.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ access(all) contract FlowALPPositionResources {
}

/// Returns the maximum amount of the given token type that could be deposited into this position
access(all) fun getDepositCapacity(type: Type): UFix64 {
access(all) fun getDepositCapacity(type _: Type): UFix64 {
// There's no limit on deposits from the position's perspective
return UFix64.max
}
Expand Down Expand Up @@ -181,7 +181,7 @@ access(all) contract FlowALPPositionResources {
type: Type,
pushToDrawDownSink: Bool
): {DeFiActions.Sink} {
let pool = self.pool.borrow()!
let _pool = self.pool.borrow()!
return PositionSink(
id: self.id,
pool: self.pool,
Expand Down Expand Up @@ -212,7 +212,7 @@ access(all) contract FlowALPPositionResources {
type: Type,
pullFromTopUpSource: Bool
): {DeFiActions.Source} {
let pool = self.pool.borrow()!
let _pool = self.pool.borrow()!
return PositionSource(
id: self.id,
pool: self.pool,
Expand Down
4 changes: 2 additions & 2 deletions cadence/contracts/FlowALPRebalancerv1.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ access(all) contract FlowALPRebalancerv1 {
txFunder: {DeFiActions.Sink, DeFiActions.Source}
) {
pre {
interval > UInt64(0):
interval > 0:
"Invalid interval: \(interval) - must be greater than 0"
interval < UInt64(UFix64.max) - UInt64(getCurrentBlock().timestamp):
"Invalid interval: \(interval) - must be less than the maximum interval of \(UInt64(UFix64.max) - UInt64(getCurrentBlock().timestamp))"
Expand Down Expand Up @@ -171,7 +171,7 @@ access(all) contract FlowALPRebalancerv1 {
/// @param id: The id of the scheduled transaction
/// @param data: The data that was passed when the transaction was originally scheduled
///
access(FlowTransactionScheduler.Execute) fun executeTransaction(id: UInt64, data: AnyStruct?) {
access(FlowTransactionScheduler.Execute) fun executeTransaction(id: UInt64, data _: AnyStruct?) {
// we want to panic and not keep spending fees on scheduled transactions if borrow fails
let positionRebalanceCap = self._positionRebalanceCapability.borrow()!
positionRebalanceCap.rebalance(force: self.recurringConfig.getForceRebalance())
Expand Down
2 changes: 1 addition & 1 deletion cadence/contracts/FlowALPSupervisorv1.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ access(all) contract FlowALPSupervisorv1 {
/// Scheduler callback: on each tick, call fixReschedule on every registered paid rebalancer,
/// recovering any that failed to schedule their next transaction. Stale UUIDs (rebalancer
/// deleted without being removed from this set) are pruned automatically.
access(FlowTransactionScheduler.Execute) fun executeTransaction(id: UInt64, data: AnyStruct?) {
access(FlowTransactionScheduler.Execute) fun executeTransaction(id: UInt64, data _: AnyStruct?) {
emit Executed(id: id)
for positionID in self.paidRebalancers.keys {
let found = FlowALPRebalancerPaidv1.fixReschedule(positionID: positionID)
Expand Down
24 changes: 10 additions & 14 deletions cadence/contracts/FlowALPv0.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -865,7 +865,7 @@ access(all) contract FlowALPv0 {
/// the target health, given pre-adjusted effective collateral and debt values.
///
/// @param position The position reference.
/// @param initialBalanceSheet The position's current balance sheet
/// @param initialBalanceSheet The position's current balance sheet
/// @param targetHealth The minimum health to maintain after withdrawal.
/// @return The maximum withdrawable amount of withdrawType.
access(self) fun computeAvailableWithdrawal(
Expand Down Expand Up @@ -971,7 +971,6 @@ access(all) contract FlowALPv0 {

// assign issuance & repayment connectors within the InternalPosition
let iPos = self._borrowPosition(pid: id)
let fundsType = funds.getType()
iPos.setDrawDownSink(issuanceSink)
if repaymentSource != nil {
iPos.setTopUpSource(repaymentSource)
Expand All @@ -987,12 +986,10 @@ access(all) contract FlowALPv0 {

// Create a capability to the Pool for the Position resource
// The Pool is stored in the FlowALPv0 contract account
let poolCap = FlowALPv0.account.capabilities.storage.issue<auth(FlowALPModels.EPosition) &{FlowALPModels.PositionPool}>(
Comment thread
turbolent marked this conversation as resolved.
FlowALPv0.PoolStoragePath
)
let poolCap = FlowALPv0.account.capabilities.storage
.issue<auth(FlowALPModels.EPosition) &{FlowALPModels.PositionPool}>(FlowALPv0.PoolStoragePath)

// Create and return the Position resource

let position <- FlowALPPositionResources.createPosition(id: id, pool: poolCap)

self.unlockPosition(id)
Expand Down Expand Up @@ -1214,7 +1211,7 @@ access(all) contract FlowALPv0 {
withdrawType: type,
withdrawAmount: amount
)

let pulledVault <- topUpSource.withdrawAvailable(maxAmount: targetHealthDeposit)
assert(pulledVault.getType() == purportedTopUpType, message: "topUpSource returned unexpected token type")
self._depositEffectsOnly(
Expand Down Expand Up @@ -1302,7 +1299,7 @@ access(all) contract FlowALPv0 {
/// Returns a mutable reference to the pool's configuration.
/// Use this to update config fields that don't require events or side effects.
access(FlowALPModels.EGovernance) fun borrowConfig(): auth(FlowALPModels.EImplementation) &{FlowALPModels.PoolConfig} {
return &self.config as auth(FlowALPModels.EImplementation) &{FlowALPModels.PoolConfig}
return &self.config
}

/// Pauses the pool, temporarily preventing further withdrawals, deposits, and liquidations
Expand Down Expand Up @@ -1508,7 +1505,7 @@ access(all) contract FlowALPv0 {

// Recalculate currentCreditRate for a given token to reflect the new stability rate
tsRef.updateInterestRates()

FlowALPEvents.emitStabilityFeeRateUpdated(
poolUUID: self.uuid,
tokenType: tokenType.identifier,
Expand Down Expand Up @@ -1858,7 +1855,7 @@ access(all) contract FlowALPv0 {
}

if insuranceAmountUFix64 > reserveVault.balance {
// do not collect the insurance fee if the reserve doesn't have enough tokens to cover the full amount
// do not collect the insurance fee if the reserve doesn't have enough tokens to cover the full amount
return nil
}

Expand Down Expand Up @@ -1914,11 +1911,11 @@ access(all) contract FlowALPv0 {
}

if stabilityAmountUFix64 > reserveVault.balance {
// do not collect the stability fee if the reserve doesn't have enough tokens to cover the full amount
// do not collect the stability fee if the reserve doesn't have enough tokens to cover the full amount
return nil
}

let stabilityVault <- reserveVault.withdraw(amount: stabilityAmountUFix64)
let stabilityVault <- reserveVault.withdraw(amount: stabilityAmountUFix64)
tokenState.setLastStabilityFeeCollectionTime(currentTime)
return <-stabilityVault
}
Expand Down Expand Up @@ -2135,7 +2132,7 @@ access(all) contract FlowALPv0 {
)
FlowALPv0.account.storage.save(<-pool, to: FlowALPv0.PoolStoragePath)
let cap = FlowALPv0.account.capabilities.storage.issue<&Pool>(FlowALPv0.PoolStoragePath)
FlowALPv0.account.capabilities.unpublish(FlowALPv0.PoolPublicPath)
let _ = FlowALPv0.account.capabilities.unpublish(FlowALPv0.PoolPublicPath)
FlowALPv0.account.capabilities.publish(cap, at: FlowALPv0.PoolPublicPath)
}
}
Expand Down Expand Up @@ -2167,6 +2164,5 @@ access(all) contract FlowALPv0 {
<-create PoolFactory(),
to: self.PoolFactoryPath
)
let factory = self.account.storage.borrow<&PoolFactory>(from: self.PoolFactoryPath)!
Comment thread
turbolent marked this conversation as resolved.
}
}
6 changes: 3 additions & 3 deletions cadence/contracts/MOET.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ access(all) contract MOET : FungibleToken {
/// and store the returned Vault in their storage in order to allow their
/// account to be able to receive deposits of this token type.
///
access(all) fun createEmptyVault(vaultType: Type): @MOET.Vault {
access(all) fun createEmptyVault(vaultType _: Type): @MOET.Vault {
return <- create Vault(balance: 0.0)
}

access(all) view fun getContractViews(resourceType: Type?): [Type] {
access(all) view fun getContractViews(resourceType _: Type?): [Type] {
return [
Type<FungibleTokenMetadataViews.FTView>(),
Type<FungibleTokenMetadataViews.FTDisplay>(),
Expand All @@ -38,7 +38,7 @@ access(all) contract MOET : FungibleToken {
]
}

access(all) fun resolveContractView(resourceType: Type?, viewType: Type): AnyStruct? {
access(all) fun resolveContractView(resourceType _: Type?, viewType: Type): AnyStruct? {
switch viewType {
case Type<FungibleTokenMetadataViews.FTView>():
return FungibleTokenMetadataViews.FTView(
Expand Down
3 changes: 2 additions & 1 deletion cadence/contracts/PriceOracleAggregatorv1.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,8 @@ access(all) contract PriceOracleAggregatorv1 {
}

/// Function called by the scheduler to update the price history.
access(FlowTransactionScheduler.Execute) fun executeTransaction(id: UInt64, data: AnyStruct?) {
access(FlowTransactionScheduler.Execute)
fun executeTransaction(id _id: UInt64, data _data: AnyStruct?) {
let priceOracleAggregator = self.borrowPriceOracleAggregator()
priceOracleAggregator.tryAddPriceToHistory()
}
Expand Down
2 changes: 1 addition & 1 deletion cadence/contracts/mocks/DummyConnectors.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ access(all) contract DummyConnectors {
return UFix64.max
}

access(all) fun depositCapacity(from: auth(FungibleToken.Withdraw) &{FungibleToken.Vault}) {
access(all) fun depositCapacity(from _: auth(FungibleToken.Withdraw) &{FungibleToken.Vault}) {
// no-op
}

Expand Down
4 changes: 2 additions & 2 deletions cadence/contracts/mocks/MockDexSwapper.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ access(all) contract MockDexSwapper {
/// Panics if no swapper for the given pair exists.
access(all) fun removeMockDEXSwapperForPair(inType: Type, outType: Type) {
let swappersForInTypeRef = &self.swappers[inType]! as auth(Mutate) &{Type: Swapper}
swappersForInTypeRef.remove(key: outType)
let _ = swappersForInTypeRef.remove(key: outType)
}

access(all) struct BasicQuote : DeFiActions.Quote {
Expand Down Expand Up @@ -117,7 +117,7 @@ access(all) contract MockDexSwapper {
return <- src.withdraw(amount: outAmt)
}

access(all) fun swapBack(quote: {DeFiActions.Quote}?, residual: @{FungibleToken.Vault}): @{FungibleToken.Vault} {
access(all) fun swapBack(quote _: {DeFiActions.Quote}?, residual: @{FungibleToken.Vault}): @{FungibleToken.Vault} {
// Not needed in tests; burn residual and panic to surface misuse
Burner.burn(<-residual)
panic("MockSwapper.swapBack() not implemented")
Expand Down
6 changes: 3 additions & 3 deletions cadence/contracts/mocks/MockYieldToken.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ access(all) contract MockYieldToken : FungibleToken {
/// and store the returned Vault in their storage in order to allow their
/// account to be able to receive deposits of this token type.
///
access(all) fun createEmptyVault(vaultType: Type): @MockYieldToken.Vault {
access(all) fun createEmptyVault(vaultType _: Type): @MockYieldToken.Vault {
return <- create Vault(balance: 0.0)
}

access(all) view fun getContractViews(resourceType: Type?): [Type] {
access(all) view fun getContractViews(resourceType _: Type?): [Type] {
return [
Type<FungibleTokenMetadataViews.FTView>(),
Type<FungibleTokenMetadataViews.FTDisplay>(),
Expand All @@ -42,7 +42,7 @@ access(all) contract MockYieldToken : FungibleToken {
]
}

access(all) fun resolveContractView(resourceType: Type?, viewType: Type): AnyStruct? {
access(all) fun resolveContractView(resourceType _: Type?, viewType: Type): AnyStruct? {
switch viewType {
case Type<FungibleTokenMetadataViews.FTView>():
return FungibleTokenMetadataViews.FTView(
Expand Down
Loading