-
Notifications
You must be signed in to change notification settings - Fork 2
Add scheduled rebalancing #80
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
| } | ||
|
|
||
| let health = self.positionHealth(pid: pid) | ||
| let health: UFix128 = self.positionHealth(pid: pid) |
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 can be inferred
| let health: UFix128 = self.positionHealth(pid: pid) | |
| let health = self.positionHealth(pid: pid) |
| /// added in the future. | ||
| access(all) resource Registry : FlowCreditMarket.IRegistry { | ||
| /// A map of registered positions by their Position ID | ||
| access(all) let registeredPositions: {UInt64: Bool} |
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.
Does this act like a set, where only the keys matter? Or can there be entries with true and false value?
If the former, maybe switch the value type to Void and use self.registeredPositions[pid] = ()
| if viewType == Type<StoragePath>() { | ||
| return FlowCreditMarketRegistry.deriveRebalanceHandlerStoragePath(poolUUID: self.poolUUID, positionID: self.positionID) | ||
| } else if viewType == Type<PublicPath>() { | ||
| return FlowCreditMarketRegistry.deriveRebalanceHandlerPublicPath(poolUUID: self.poolUUID, positionID: self.positionID) | ||
| } else if viewType == Type<MetadataViews.Display>() { | ||
| return MetadataViews.Display( | ||
| name: "Flow Credit Market Pool Position Rebalance Scheduled Transaction Handler", | ||
| description: "Scheduled Transaction Handler that can execute rebalance transactions on behalf of a Flow Credit Market Pool with UUID \(self.poolUUID) and Position ID \(self.positionID)", | ||
| thumbnail: MetadataViews.HTTPFile(url: "") | ||
| ) | ||
| } |
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.
Use switch-case instead for repeated test of viewType:
| if viewType == Type<StoragePath>() { | |
| return FlowCreditMarketRegistry.deriveRebalanceHandlerStoragePath(poolUUID: self.poolUUID, positionID: self.positionID) | |
| } else if viewType == Type<PublicPath>() { | |
| return FlowCreditMarketRegistry.deriveRebalanceHandlerPublicPath(poolUUID: self.poolUUID, positionID: self.positionID) | |
| } else if viewType == Type<MetadataViews.Display>() { | |
| return MetadataViews.Display( | |
| name: "Flow Credit Market Pool Position Rebalance Scheduled Transaction Handler", | |
| description: "Scheduled Transaction Handler that can execute rebalance transactions on behalf of a Flow Credit Market Pool with UUID \(self.poolUUID) and Position ID \(self.positionID)", | |
| thumbnail: MetadataViews.HTTPFile(url: "") | |
| ) | |
| } | |
| switch viewType { | |
| case Type<StoragePath>(): | |
| return FlowCreditMarketRegistry.deriveRebalanceHandlerStoragePath( | |
| poolUUID: self.poolUUID, | |
| positionID: self.positionID | |
| ) | |
| case Type<PublicPath>(): | |
| return FlowCreditMarketRegistry.deriveRebalanceHandlerPublicPath( | |
| poolUUID: self.poolUUID, | |
| positionID: self.positionID | |
| ) | |
| case Type<MetadataViews.Display>(): | |
| return MetadataViews.Display( | |
| name: "Flow Credit Market Pool Position Rebalance Scheduled Transaction Handler", | |
| description: "Scheduled Transaction Handler that can execute rebalance transactions on behalf of a Flow Credit Market Pool with UUID \(self.poolUUID) and Position ID \(self.positionID)", | |
| thumbnail: MetadataViews.HTTPFile(url: "") | |
| ) | |
| } |
| let ref = self.borrowScheduledTransaction(id: id) | ||
| if ref != nil && ref!.status() != FlowTransactionScheduler.Status.Scheduled { | ||
| destroy <- self.scheduledTxns.remove(key: id) | ||
| } |
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.
| let ref = self.borrowScheduledTransaction(id: id) | |
| if ref != nil && ref!.status() != FlowTransactionScheduler.Status.Scheduled { | |
| destroy <- self.scheduledTxns.remove(key: id) | |
| } | |
| if let ref = self.borrowScheduledTransaction(id: id) { | |
| if ref.status() != FlowTransactionScheduler.Status.Scheduled { | |
| destroy <- self.scheduledTxns.remove(key: id) | |
| } | |
| } |
Description
Lifecycle
Creation
Updating Default Recurring Config
set_default_rebalance_recurring_config.cdctransaction with the desired valuesSteps to Initialize from Current State
initfor starting default config values) - Registry is initialized in account storagebackfill_positions.cdctransaction (--compute-limit 9999) which will register all existing PIDs in the Registry. This should spin up RebalanceHandlers for all existing Positionsget_position_ids.cdcscript)backfill_specific_positions.cdctransaction to backfill in partitions. Again, the transaction will fail if one of the provided IDs does not exist in the Pool as a failsafe.For contributor use:
masterbranchFiles changedin the Github PR explorer