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
441 changes: 441 additions & 0 deletions cadence/contracts/FlowALPHealth.cdc

Large diffs are not rendered by default.

43 changes: 43 additions & 0 deletions cadence/contracts/FlowALPModels.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -2073,6 +2073,49 @@ access(all) contract FlowALPModels {
}
}

/* --- POSITION POOL API --- */

/// PositionPool defines the subset of Pool functionality required by user-held Position wrappers.
/// This interface is intentionally narrow so Position resources can live outside the main ALP contract.
access(all) resource interface PositionPool {

/// Locks a position for mutation.
access(EPosition) fun lockPosition(_ pid: UInt64)

/// Unlocks a position after mutation.
access(EPosition) fun unlockPosition(_ pid: UInt64)

/// Returns details for a position.
access(all) fun getPositionDetails(pid: UInt64): PositionDetails

/// Returns currently available withdrawal capacity for a position/token pair.
access(all) fun availableBalance(pid: UInt64, type: Type, pullFromTopUpSource: Bool): UFix64

/// Returns current position health.
access(all) fun positionHealth(pid: UInt64): UFix128

/// Borrows an authorized internal position reference.
access(EPosition) view fun borrowPosition(pid: UInt64): auth(EImplementation) &{InternalPosition}

/// Deposits funds to a position and optionally pushes excess to draw-down sink.
access(EPosition) fun depositAndPush(
pid: UInt64,
from: @{FungibleToken.Vault},
pushToDrawDownSink: Bool
)

/// Withdraws funds from a position and optionally pulls deficit from top-up source.
access(EPosition) fun withdrawAndPull(
pid: UInt64,
type: Type,
amount: UFix64,
pullFromTopUpSource: Bool
): @{FungibleToken.Vault}

/// Rebalances the specified position.
access(EPosition | ERebalance) fun rebalancePosition(pid: UInt64, force: Bool)
}

/// Factory function to create a new InternalPositionImplv1 resource.
/// Required because Cadence resources can only be created within their containing contract.
access(all) fun createInternalPosition(): @{InternalPosition} {
Expand Down
506 changes: 506 additions & 0 deletions cadence/contracts/FlowALPPositionResources.cdc

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion cadence/contracts/FlowALPRebalancerPaidv1.cdc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import "FlowALPv0"
import "FlowALPPositionResources"
import "FlowALPModels"
import "FlowALPRebalancerv1"
import "FlowTransactionScheduler"
Expand Down Expand Up @@ -34,7 +35,7 @@ access(all) contract FlowALPRebalancerPaidv1 {
/// Returns a RebalancerPaid resource; the underlying Rebalancer is stored in this contract and
/// the first run is scheduled. Caller should register the returned uuid with a Supervisor.
access(all) fun createPaidRebalancer(
positionRebalanceCapability: Capability<auth(FlowALPModels.ERebalance) &FlowALPv0.Position>,
positionRebalanceCapability: Capability<auth(FlowALPModels.ERebalance) &FlowALPPositionResources.Position>,
): @RebalancerPaid {
assert(positionRebalanceCapability.check(), message: "Invalid position rebalance capability")
let rebalancer <- FlowALPRebalancerv1.createRebalancer(
Expand Down
7 changes: 4 additions & 3 deletions cadence/contracts/FlowALPRebalancerv1.cdc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import "DeFiActions"
import "FlowALPv0"
import "FlowALPPositionResources"
import "FlowALPModels"
import "FlowToken"
import "FlowTransactionScheduler"
Expand Down Expand Up @@ -131,7 +132,7 @@ access(all) contract FlowALPRebalancerv1 {
access(all) var recurringConfig: {RecurringConfig}

access(self) var _selfCapability: Capability<auth(FlowTransactionScheduler.Execute) &{FlowTransactionScheduler.TransactionHandler}>?
access(self) var _positionRebalanceCapability: Capability<auth(FlowALPModels.ERebalance) &FlowALPv0.Position>
access(self) var _positionRebalanceCapability: Capability<auth(FlowALPModels.ERebalance) &FlowALPPositionResources.Position>
/// Scheduled transaction id -> ScheduledTransaction (used to cancel/refund).
access(self) var scheduledTransactions: @{UInt64: FlowTransactionScheduler.ScheduledTransaction}

Expand All @@ -142,7 +143,7 @@ access(all) contract FlowALPRebalancerv1 {

init(
recurringConfig: {RecurringConfig},
positionRebalanceCapability: Capability<auth(FlowALPModels.ERebalance) &FlowALPv0.Position>
positionRebalanceCapability: Capability<auth(FlowALPModels.ERebalance) &FlowALPPositionResources.Position>
) {
self._selfCapability = nil
self.lastRebalanceTimestamp = getCurrentBlock().timestamp
Expand Down Expand Up @@ -328,7 +329,7 @@ access(all) contract FlowALPRebalancerv1 {
/// call setSelfCapability with that capability, then call fixReschedule() to start the schedule.
access(all) fun createRebalancer(
recurringConfig: {RecurringConfig},
positionRebalanceCapability: Capability<auth(FlowALPModels.ERebalance) &FlowALPv0.Position>,
positionRebalanceCapability: Capability<auth(FlowALPModels.ERebalance) &FlowALPPositionResources.Position>,
): @Rebalancer {
let rebalancer <- create Rebalancer(
recurringConfig: recurringConfig,
Expand Down
Loading
Loading