-
Notifications
You must be signed in to change notification settings - Fork 0
Kan/add admin tx schedule supervisor recurring #106
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
Open
Kay-Zee
wants to merge
2
commits into
main
Choose a base branch
from
kan/add-admin-tx-schedule-supervisor-recurring
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
|
|
@@ -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 | ||
|
|
||
| init( | ||
| feesCap: Capability<auth(FungibleToken.Withdraw) &FlowToken.Vault> | ||
| ) { | ||
| self.feesCap = feesCap | ||
| self._scheduledTransaction <- nil | ||
| self.selfSchedulingFeeEstimate = FlowYieldVaultsSchedulerV1.MIN_FEE_FALLBACK | ||
| } | ||
|
|
||
| /* --- TRANSACTION HANDLER --- */ | ||
|
|
@@ -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, | ||
|
|
@@ -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 { | ||
|
|
@@ -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
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
|
||
35 changes: 35 additions & 0 deletions
35
cadence/transactions/flow-yield-vaults/admin/schedule_supervisor_recurring.cdc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| ) | ||
| } | ||
| } | ||
|
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
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.