Skip to content

Commit e9f3cc3

Browse files
Merge branch 'main' into alex/ADR_user-balance_in_Earn-Product
2 parents 6bde638 + d29bc11 commit e9f3cc3

121 files changed

Lines changed: 3821 additions & 698 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

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

AGENTS.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,9 @@ flow test cadence/tests/interest_accrual_integration_test.cdc --name test_combin
5757
```bash
5858
grep "fun test" cadence/tests/interest_accrual_integration_test.cdc
5959
```
60+
61+
# Cadence Coding Guidelines
62+
63+
- Use string templating, not concatenation: `"Hello \(name)"` not `"Hello ".concat(name)`
64+
- Use `equalWithinVariance` from `test_helpers.cdc` for equality assertions where rounding errors are possible
65+
- Use red-green TDD for bug fixes and extensions to functionality. Tests must use assertions (eg. `Test.assert`) to verify expected behaviour, not logs.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ FlowALP/
179179

180180
- `FungibleToken.Vault`: Standard token operations
181181
- `DeFiActions.Sink/Source`: DeFi protocol composability
182-
- Entitlements: `FlowALPv0.EParticipant`, `FlowALPv0.EPosition`, `FlowALPv0.EGovernance`, `FlowALPv0.ERebalance`
182+
- Entitlements: `FlowALPModels.EParticipant`, `FlowALPModels.EPosition`, `FlowALPModels.EGovernance`, `FlowALPModels.ERebalance`
183183

184184
## 🛠️ Development
185185

cadence/contracts/FlowALPEvents.cdc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,11 @@ access(all) contract FlowALPEvents {
141141
)
142142

143143
/// Emitted when the insurance rate for a token is updated by governance.
144-
/// The insurance rate is an annual fraction of debit interest diverted to the insurance fund.
144+
/// The insurance rate is a fee of accrued debit interest diverted to the insurance fund.
145145
///
146146
/// @param poolUUID the UUID of the pool containing the token
147147
/// @param tokenType the type identifier string of the token whose rate changed
148-
/// @param insuranceRate the new annual insurance rate (e.g. 0.001 for 0.1%)
148+
/// @param insuranceRate the new insurance fee (e.g. 0.001 for 0.1%)
149149
access(all) event InsuranceRateUpdated(
150150
poolUUID: UInt64,
151151
tokenType: String,
@@ -167,11 +167,11 @@ access(all) contract FlowALPEvents {
167167
)
168168

169169
/// Emitted when the stability fee rate for a token is updated by governance.
170-
/// The stability fee rate is an annual fraction of debit interest diverted to the stability fund.
170+
/// The stability fee rate is a fee of accrued debit interest diverted to the stability fund.
171171
///
172172
/// @param poolUUID the UUID of the pool containing the token
173173
/// @param tokenType the type identifier string of the token whose rate changed
174-
/// @param stabilityFeeRate the new annual stability fee rate (e.g. 0.05 for 5%)
174+
/// @param stabilityFeeRate the new stability fee (e.g. 0.05 for 5%)
175175
access(all) event StabilityFeeRateUpdated(
176176
poolUUID: UInt64,
177177
tokenType: String,

cadence/contracts/FlowALPInterestRates.cdc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ access(all) contract FlowALPInterestRates {
44
///
55
/// A simple interface to calculate interest rate for a token type.
66
access(all) struct interface InterestCurve {
7-
/// Returns the annual interest rate for the given credit and debit balance, for some token T.
7+
/// Returns the annual nominal interest rate for the given credit and debit balance, for some token T.
88
/// @param creditBalance The credit (deposit) balance of token T
99
/// @param debitBalance The debit (withdrawal) balance of token T
1010
access(all) fun interestRate(creditBalance: UFix128, debitBalance: UFix128): UFix128 {
@@ -19,10 +19,10 @@ access(all) contract FlowALPInterestRates {
1919

2020
/// FixedCurve
2121
///
22-
/// A fixed-rate interest curve implementation that returns a constant yearly interest rate
22+
/// A fixed-rate interest curve implementation that returns a constant nominal yearly interest rate
2323
/// regardless of utilization. This is suitable for stable assets like MOET where predictable
2424
/// rates are desired.
25-
/// @param yearlyRate The fixed yearly interest rate as a UFix128 (e.g., 0.05 for 5% APY)
25+
/// @param yearlyRate The fixed yearly nominal rate as a UFix128 (e.g., 0.05 for a 5% nominal yearly rate)
2626
access(all) struct FixedCurve: InterestCurve {
2727

2828
access(all) let yearlyRate: UFix128
@@ -64,7 +64,7 @@ access(all) contract FlowALPInterestRates {
6464
/// This matches the live TokenState accounting used by FlowALP.
6565
///
6666
/// @param optimalUtilization The target utilization ratio (e.g., 0.80 for 80%)
67-
/// @param baseRate The minimum yearly interest rate (e.g., 0.01 for 1% APY)
67+
/// @param baseRate The minimum yearly nominal rate (e.g., 0.01 for a 1% nominal yearly rate)
6868
/// @param slope1 The total rate increase from 0% to optimal utilization (e.g., 0.04 for 4%)
6969
/// @param slope2 The total rate increase from optimal to 100% utilization (e.g., 0.60 for 60%)
7070
access(all) struct KinkCurve: InterestCurve {

cadence/contracts/FlowALPModels.cdc

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1037,13 +1037,13 @@ access(all) contract FlowALPModels {
10371037
/// (used when deposits are made)
10381038
access(EImplementation) fun consumeDepositCapacity(_ amount: UFix64, pid: UInt64)
10391039

1040-
/// Returns the per-deposit limit based on depositCapacity * depositLimitFraction
1041-
/// Rationale: cap per-deposit size to a fraction of the time-based
1042-
/// depositCapacity so a single large deposit cannot monopolize capacity.
1040+
/// Returns the per-deposit limit based on user deposit limit and available deposit capacity.
1041+
/// Rationale: cap per-deposit size to a fraction of the total depositCapacityCap
1042+
/// so a single large deposit cannot monopolize capacity.
10431043
/// Excess is queued and drained in chunks (see asyncUpdatePosition),
10441044
/// enabling fair throughput across many deposits in a block. The 5%
10451045
/// fraction is conservative and can be tuned by protocol parameters.
1046-
access(EImplementation) view fun depositLimit(): UFix64
1046+
access(EImplementation) view fun depositLimit(pid: UInt64): UFix64
10471047

10481048
/// Updates interest indices and regenerates deposit capacity for elapsed time
10491049
access(EImplementation) fun updateForTimeChange()
@@ -1376,9 +1376,15 @@ access(all) contract FlowALPModels {
13761376
)
13771377
}
13781378

1379-
/// Returns the per-deposit limit based on depositCapacity * depositLimitFraction.
1380-
access(EImplementation) view fun depositLimit(): UFix64 {
1381-
return self.depositCapacity * self.depositLimitFraction
1379+
/// Returns the maximum amount that can be deposited to the given position without being queued.
1380+
access(EImplementation) view fun depositLimit(pid: UInt64): UFix64 {
1381+
let userCap = self.getUserDepositLimitCap()
1382+
let userUsed = self.getDepositUsageForPosition(pid)
1383+
var available = userCap - userUsed
1384+
if self.depositCapacity < available {
1385+
available = self.depositCapacity
1386+
}
1387+
return available
13821388
}
13831389

13841390
/// Updates interest indices and regenerates deposit capacity for elapsed time.

0 commit comments

Comments
 (0)