Skip to content

Commit 38d2a04

Browse files
authored
Merge branch 'main' into holyfuchs/FLO-18-nominal-interets
2 parents 1ac2446 + 786f928 commit 38d2a04

37 files changed

Lines changed: 1724 additions & 613 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ coverage.json
77
/.pr-body.md
88
/.github/pr_bodies/
99
lcov.info
10+
.flow-fork-cache

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636

3737
## 🏦 About FlowALP
3838

39-
FlowALP is a decentralized lending and borrowing protocol built on the Flow blockchain. This repository contains the v1 Cadence implementation deployed as the `FlowALPv0` contract. It is token-agnostic (operates over any `FungibleToken.Vault`) and integrates with DeFi Actions for composability.
39+
FlowALP is a decentralized lending and borrowing protocol built on the Flow blockchain. This repository contains the current Cadence implementation deployed as the `FlowALPv0` contract. It is token-agnostic (operates over any `FungibleToken.Vault`) and integrates with DeFi Actions for composability.
4040

4141
### Key Features
4242

RebalanceArchitecture.md

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
## Updated Rebalance Architecture
22

3-
This system **rebalances Flow Credit Market (FCM) positions on a schedule**: at a configurable interval, a rebalancer triggers the position’s `rebalance` function. **FCM** holds positions and exposes `rebalance`.
3+
This system **rebalances FlowALP positions on a schedule**: at a configurable interval, a rebalancer triggers the position’s `rebalance` function. **FlowALP** holds positions and exposes `rebalance`.
4+
5+
**Implementation note:** In the current implementation, the FlowALP pool is `FlowALPv0.Pool`.
46

57
A **Rebalancer** when invoked, calls `rebalance` on the position and tries to schedules the next run.
68

79
A **Supervisor** runs on its own schedule (cron) and calls `fixReschedule()` on each registered rebalancer so that transient scheduling failures (e.g. temporary lack of funds) don’t leave rebalancers stuck.
810

911
### Key Principles
1012

11-
* **Isolation:** FCM, Rebalancer, and Supervisor are fully independent.
13+
* **Isolation:** FlowALP, Rebalancer, and Supervisor are fully independent.
1214
* **Least Privilege:** The Rebalancer can *only* trigger the `rebalance` function.
1315
* **Resilience:** The `fixReschedule()` call is idempotent and permissionless, ensuring the system can recover without complex auth (see below).
1416

@@ -39,7 +41,7 @@ There are two rebalancer types; they behave the same for triggering rebalances;
3941
| **User’s control** | Full: config, fixReschedule, withdraw/destroy | Only: fixReschedule by UUID, or delete their RebalancerPaid (stops and removes the rebalancer) |
4042
| **Use case** | User wants full autonomy and to pay their own fees | Admin retains autonomy and pays fees for users (us only) |
4143

42-
**Note:** The Supervisor and the Paid Rebalancer are only intended for use by us; the Standard Rebalancer is for users who self-custody. The bundled `FlowALPSupervisorV1` only tracks **paid** rebalancers (`addPaidRebalancer` / `removePaidRebalancer`). For standard rebalancers, users can call `fixReschedule()` themselves when needed.
44+
**Note:** The Supervisor and the Paid Rebalancer are only intended for use by us; the Standard Rebalancer is for users who self-custody. The bundled `FlowALPSupervisorv1` only tracks **paid** rebalancers (`addPaidRebalancer` / `removePaidRebalancer`). For standard rebalancers, users can call `fixReschedule()` themselves when needed.
4345

4446
### Why calls `fixReschedule()` are necessary
4547

@@ -57,12 +59,12 @@ User creates a position, then creates a **paid** rebalancer (which lives in the
5759
sequenceDiagram
5860
actor admin
5961
actor User
60-
participant FCM
62+
participant FlowALP
6163
participant Paid as Paid Rebalancer Contract
6264
participant Supervisor
6365
Note over admin,Paid: One-time: admin sets defaultRecurringConfig (incl. txFunder)
6466
admin->>Paid: updateDefaultRecurringConfig(config)
65-
User->>FCM: createPosition()
67+
User->>FlowALP: createPosition()
6668
User->>Paid: createPaidRebalancer(positionRebalanceCapability)
6769
Paid-->>User: RebalancerPaid(uuid)
6870
User->>User: save RebalancerPaid
@@ -87,17 +89,17 @@ sequenceDiagram
8789
```mermaid
8890
sequenceDiagram
8991
participant AB1 as AutoRebalancer1
90-
participant FCM
92+
participant FlowALP
9193
participant AB2 as AutoRebalancer2
9294
participant SUP as Supervisor
9395
loop every x min
94-
AB1->>FCM: rebalance()
96+
AB1->>FlowALP: rebalance()
9597
end
9698
loop every y min
97-
AB2->>FCM: rebalance()
99+
AB2->>FlowALP: rebalance()
98100
end
99101
loop every z min
100102
SUP->>AB2: fixReschedule()
101103
SUP->>AB1: fixReschedule()
102104
end
103-
```
105+
```

cadence/contracts/FlowALPModels.cdc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1883,6 +1883,9 @@ access(all) contract FlowALPModels {
18831883
/// Returns whether a queued deposit exists for the given token type
18841884
access(all) view fun hasQueuedDeposit(_ type: Type): Bool
18851885

1886+
/// Returns the queued deposit balance for the given token type, or nil if none exists
1887+
access(all) view fun getQueuedDepositBalance(_ type: Type): UFix64?
1888+
18861889
// --- Draw Down Sink ---
18871890

18881891
/// Returns an authorized reference to the draw-down sink, or nil if none is configured.
@@ -2042,6 +2045,14 @@ access(all) contract FlowALPModels {
20422045
return self.queuedDeposits[type] != nil
20432046
}
20442047

2048+
/// Returns the queued deposit balance for the given token type, or nil if none exists.
2049+
access(all) view fun getQueuedDepositBalance(_ type: Type): UFix64? {
2050+
if let queued = &self.queuedDeposits[type] as &{FungibleToken.Vault}? {
2051+
return queued.balance
2052+
}
2053+
return nil
2054+
}
2055+
20452056
// --- Draw Down Sink ---
20462057

20472058
/// Returns an authorized reference to the draw-down sink, or nil if none is configured.
@@ -2114,6 +2125,9 @@ access(all) contract FlowALPModels {
21142125

21152126
/// Rebalances the specified position.
21162127
access(EPosition | ERebalance) fun rebalancePosition(pid: UInt64, force: Bool)
2128+
2129+
/// Queues the position for rebalance/update if its health bounds have changed.
2130+
access(EPosition) fun queuePositionForUpdateIfNecessary(pid: UInt64)
21172131
}
21182132

21192133
/// Factory function to create a new InternalPositionImplv1 resource.

0 commit comments

Comments
 (0)