Skip to content
Open
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
20 changes: 11 additions & 9 deletions cadence/contracts/FlowYieldVaultsSchedulerV1.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ access(all) contract FlowYieldVaultsSchedulerV1 {
/// Default lookahead seconds for scheduling first execution
access(all) let DEFAULT_LOOKAHEAD_SECS: UFix64


/* --- PATHS --- */

/// Storage path for the Supervisor resource
Expand Down Expand Up @@ -95,12 +96,14 @@ access(all) contract FlowYieldVaultsSchedulerV1 {
/// Capability to withdraw FLOW for Supervisor's own scheduling fees
access(self) let feesCap: Capability<auth(FungibleToken.Withdraw) &FlowToken.Vault>
access(self) var _scheduledTransaction: @FlowTransactionScheduler.ScheduledTransaction?
access(contract) var selfSchedulingFeeEstimate: UFix64
Copy link
Contributor

Choose a reason for hiding this comment

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

This will be a non-upgradeable change. If we want to add it, we'll need to redeploy, add another versioned contract, or version the supervisor.


init(
feesCap: Capability<auth(FungibleToken.Withdraw) &FlowToken.Vault>
) {
self.feesCap = feesCap
self._scheduledTransaction <- nil
self.selfSchedulingFeeEstimate = FlowYieldVaultsSchedulerV1.MIN_FEE_FALLBACK
}

/* --- TRANSACTION HANDLER --- */
Expand Down Expand Up @@ -193,6 +196,11 @@ access(all) contract FlowYieldVaultsSchedulerV1 {
}
}

/// Sets the estimated cost of scheduling a transaction at a given timestamp
access(Schedule) fun setSelfSchedulingCostEstimate(estimate: UFix64) {
self.selfSchedulingFeeEstimate = estimate
}

/// Self-reschedules the Supervisor for perpetual operation.
///
/// This function handles the scheduling of the next Supervisor execution,
Expand Down Expand Up @@ -226,13 +234,7 @@ access(all) contract FlowYieldVaultsSchedulerV1 {
return
}

let est = FlowYieldVaultsSchedulerV1.estimateSchedulingCost(
timestamp: nextTimestamp,
priority: priority,
executionEffort: executionEffort
)
let baseFee = est.flowFee ?? FlowYieldVaultsSchedulerV1.MIN_FEE_FALLBACK
let required = baseFee * FlowYieldVaultsSchedulerV1.FEE_MARGIN_MULTIPLIER
let required = self.selfSchedulingFeeEstimate * FlowYieldVaultsSchedulerV1.FEE_MARGIN_MULTIPLIER

if let vaultRef = self.feesCap.borrow() {
if vaultRef.balance >= required {
Expand Down Expand Up @@ -341,8 +343,8 @@ access(all) contract FlowYieldVaultsSchedulerV1 {
init() {
// Initialize constants
self.DEFAULT_RECURRING_INTERVAL = 60.0 // 60 seconds
self.DEFAULT_PRIORITY = 1 // Medium
self.DEFAULT_EXECUTION_EFFORT = 800
self.DEFAULT_PRIORITY = FlowTransactionScheduler.Priority.Low.rawValue
self.DEFAULT_EXECUTION_EFFORT = 400
Comment on lines +346 to +347
Copy link
Contributor

@sisyphusSmiling sisyphusSmiling Dec 11, 2025

Choose a reason for hiding this comment

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

FYI the contract won't initialize on updating. If we want to set these on the existing deployment, we'll need to add setters. I've included these changes in my WIP PR #109

self.MIN_FEE_FALLBACK = 0.00005
self.FEE_MARGIN_MULTIPLIER = 1.2
self.DEFAULT_LOOKAHEAD_SECS = 10.0
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import "FlowYieldVaultsSchedulerV1"
import "FlowTransactionScheduler"

/// Admin transaction to kick off scheduled transactions for FlowYieldVaults
/// by calling scheduleNextRecurringExecution on the Supervisor with default parameters.
///
/// This transaction must be signed by the contract account that owns the Supervisor resource.
/// It uses the default parameters from FlowYieldVaultsSchedulerV1:
/// - recurringInterval: 60.0 seconds
/// - priority: Medium (1)
/// - executionEffort: 800
/// - scanForStuck: true
///
transaction {
let supervisorRef: auth(FlowYieldVaultsSchedulerV1.Schedule) &FlowYieldVaultsSchedulerV1.Supervisor

prepare(signer: auth(BorrowValue) &Account) {
// Borrow the Supervisor resource with Schedule entitlement from the contract account storage
self.supervisorRef = signer.storage.borrow<auth(FlowYieldVaultsSchedulerV1.Schedule) &FlowYieldVaultsSchedulerV1.Supervisor>(
from: FlowYieldVaultsSchedulerV1.SupervisorStoragePath
) ?? panic("Supervisor not found at expected storage path")
}

execute {
// Call scheduleNextRecurringExecution with default parameters
self.supervisorRef.scheduleNextRecurringExecution(
recurringInterval: FlowYieldVaultsSchedulerV1.DEFAULT_RECURRING_INTERVAL,
priority: FlowTransactionScheduler.Priority.Medium,
priorityRaw: FlowYieldVaultsSchedulerV1.DEFAULT_PRIORITY,
executionEffort: FlowYieldVaultsSchedulerV1.DEFAULT_EXECUTION_EFFORT,
scanForStuck: true
)
}
}