[DRAFT] Extract ALP components into separate contracts#160
Draft
jordanschalm wants to merge 12 commits intomainfrom
Draft
[DRAFT] Extract ALP components into separate contracts#160jordanschalm wants to merge 12 commits intomainfrom
jordanschalm wants to merge 12 commits intomainfrom
Conversation
Move InterestCurve interface, FixedRateInterestCurve, and KinkInterestCurve from FlowALPv1 into a new standalone FlowALPRateCurves contract to improve modularity and allow rate curve types to be reused independently. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…rve to FixedCurve, KinkInterestCurve to KinkCurve Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Move 9 pool config fields (priceOracle, collateralFactor, borrowFactor, positionsProcessedPerCallback, liquidationTargetHF, warmupSec, lastUnpausedAt, dex, dexOracleDeviationBps) into a PoolConfigImpl struct in a new FlowALPModels contract, centralizing config validation logic. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Replace pure-delegation Pool wrapper functions (setDexOracleDeviationBps, setDEX) with a single borrowConfig() function that returns a mutable reference to the pool's PoolConfig. Callers can now invoke config setters directly. Wrapper functions with events/side effects are preserved. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Move TokenState struct and EImplementation entitlement to FlowALPModels. Create PoolStateImpl resource in FlowALPModels to hold Pool's movable state fields (globalLedger, reserves, insuranceFund, etc.). Move pure utility functions (perSecondInterestRate, compoundInterestIndex, dexOraclePriceDeviationInRange) to FlowALPMath, keeping thin wrappers in FlowALPv1 for backwards compatibility. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Pool.state is now typed as @{FlowALPModels.PoolState} instead of the
concrete @FlowALPModels.PoolStateImpl, matching the PoolConfig/PoolConfigImpl
pattern and allowing the implementation to be swapped in future upgrades.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
These are configuration fields, not state fields. Moving them to PoolConfig with getter/setter methods ensures they are upgradeable. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
All fields on the PoolState interface are now accessed through getter/setter methods rather than direct field access. This ensures the interface is upgradeable - fields cannot be changed in interface upgrades, but function signatures can evolve. Also fixes a test that relied on dictionary key ordering for position balances. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
These functions interact with pool-level state (reserves, insurance fund) and are better suited as Pool methods that accept a TokenState reference. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Base supported token logic on collateralFactor dictionary keys in PoolConfig rather than globalLedger keys in PoolState. Pool methods now delegate to config. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Move _borrowOrCreateReserveVault to PoolState as borrowOrCreateReserve - Move _getSwapperForLiquidation to PoolConfig as getSwapperForLiquidation - Remove setLiquidationParams, setPauseParams, pausePool wrappers - Remove setDebugLogging wrapper (callers use borrowConfig() directly) - Remove unused events: LiquidationParamsUpdated, PauseParamsUpdated, PoolPaused - Update transactions to use borrowConfig() for pause and debug logging Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
jordanschalm
commented
Feb 13, 2026
| @@ -1735,22 +999,11 @@ access(all) contract FlowALPv1 { | |||
|
|
|||
| /// Returns a reference to the reserve vault for the given type, if the token type is supported. | |||
| /// If no reserve vault exists yet, and the token type is supported, the reserve vault is created. | |||
| access(self) fun _borrowOrCreateReserveVault(type: Type): &{FungibleToken.Vault} { | |||
Member
Author
There was a problem hiding this comment.
Didn't move docs over when refactoring
jordanschalm
commented
Feb 13, 2026
| @@ -1996,13 +1249,6 @@ access(all) contract FlowALPv1 { | |||
| /// - No swapper is configured for the given token pair (seizeType -> debtType) | |||
| /// | |||
| /// @param seizeType: The collateral token type to swap from | |||
| /// @param debtType: The debt token type to swap to | |||
jordanschalm
commented
Feb 13, 2026
| let diffPct: UFix64 = dexPrice < oraclePrice ? diff / dexPrice : diff / oraclePrice | ||
| let diffBps = UInt16(diffPct * 10_000.0) | ||
| return diffBps <= maxDeviationBps | ||
| return FlowALPMath.dexOraclePriceDeviationInRange(dexPrice: dexPrice, oraclePrice: oraclePrice, maxDeviationBps: maxDeviationBps) |
Member
Author
There was a problem hiding this comment.
fix this duplication
|
I did something similar, MVC pattern ( like https://github.com/jordanschalm/cadence-interface-upgrade-pattern) I took a different approach ( used attachments basically ) and state code is generated. ( just pushed maybe inspires something: https://github.com/bluesign/upgradeable Also my old splitting attempt on credit market ( https://github.com/bluesign/fcm-core/tree/master/cadence/contracts ) ( not using the upgradeable but similar ideas ) |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This PR refactors ALP types and state fields. The PR is not ready for detailed review, but is ready for feedback on the high-level approach.
The goal is to:
FlowALPv1contract by moving code into separate contracts and removing duplicated functionalityChanges
FlowALPModelsPool.borrowConfigfunction, rather thanPooldefining setters itselfFlowALPMath. In this PR we decided to retain the separate Math contract. Given that, I think it makes sense to delegate pure math-related functions into that contract.Comments
FlowALPModelsand havingaccess(account) fun emitEventfunctions for them.EImplementationis useful. If it is, apply and use it consistently.