You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- Use `int96` cast; if perSecond==0, call `flow(token, user, 0)` to delete.
83
-
84
-
Integration outline (pseudocode)
85
-
- Import library: `using SuperTokenV1Library for ISuperToken;`
86
-
- After event, recompute and set flow:
87
-
```
88
-
function _updateFlow(address user) internal {
89
-
uint256 assets = 0;
90
-
for (address v in _userActiveVaults[user]) {
91
-
uint256 uShares = _userUnderlyingShares[user][v];
92
-
if (uShares == 0) continue;
93
-
assets += IERC4626(v).convertToAssets(uShares);
94
-
}
95
-
uint256 wad = assets * exchangeRateWad;
96
-
uint256 annual = wad * annualRateBps / 10_000;
97
-
uint256 perSec = annual / secondsPerYear / 1e18;
98
-
int96 rate = int96(int256(perSec));
99
-
sendx.flow(user, rate); // create/update/delete as needed
100
-
}
101
-
```
102
-
103
-
Operational notes
104
-
- Pre-fund with SENDx to satisfy CFA buffer or the flow creation will revert.
105
-
- Flows are per-user, from the aggregator to the user.
106
-
- If you change `annualRateBps`/`exchangeRateWad`, you may optionally batch-recompute flows for a set of users (future helper).
62
+
## CFA streaming integration (v2.1) — Professional spec
63
+
64
+
Status: planned (docs-first); implementation follows. The flowRate calculation component is not finalized; all calls to `flow` are placeholders pending that integration.
65
+
66
+
### Purpose and scope
67
+
- Provide continuous SENDx streaming to users sized by the value of their aggregated SendEarn positions held via the aggregator.
68
+
- Integrate Superfluid using SuperTokenV1Library `flow` helper to create/update/delete flows on state changes.
69
+
- Scope covers deposit (vault token ingestion), withdraw, and redeem. ERC20 share transfers do not alter ledger or flows.
70
+
71
+
### Definitions
72
+
- Vault: a SendEarn ERC4626 vault approved by the factory.
73
+
- Vault shares: ERC4626 shares of a SendEarn vault (seASSET tokens) held by the aggregator.
74
+
- Aggregated assets (per user): sum over user’s vaults of `IERC4626(v).convertToAssets(userUnderlyingShares[v])`.
75
+
- sendx: the SuperToken used for streaming (constructor arg). Must be pre-funded in the aggregator.
76
+
77
+
### External dependencies
78
+
- Superfluid protocol; use `SuperTokenV1Library` for `flow(ISuperToken token, address receiver, int96 rate)`.
- Views: `userUnderlyingShares(user, vault)`, `totalAssets()` (wrapper-wide; view-only over `_activeVaults`).
154
+
155
+
### Failure modes
156
+
- Not SendEarn vault: revert.
157
+
- Asset mismatch: revert.
158
+
- Insufficient underlying shares on Withdraw/Redeem: revert.
159
+
- Flow creation/update may revert if SENDx buffer is insufficient (operator choice: pre-fund or skip flow set).
160
+
161
+
### Implementation notes
162
+
- Keep vault interaction minimal and single-target per action.
163
+
- Flow update hooks are invoked after ledger mutation for the acting user.
164
+
- Do not attempt to adjust flows on ERC20 transfers.
165
+
166
+
### Open items
167
+
- Plug in final flowRate component (oracle/policy); unit test flow lifecycle after integration.
168
+
- Optional: on admin policy change, batch-recompute flows across a given user subset.
169
+
Status: planned in v2.1 (docs-first; implementation next). Note: we do not yet have the final flowRate calculation component; calls to `flow` should be treated as placeholders until that piece is finalized.
170
+
171
+
Library
172
+
- Use Superfluid’s SuperTokenV1Library `flow(ISuperToken token, address receiver, int96 rate)` to create/update/delete flows.
173
+
174
+
Deposit (vault token ingestion)
175
+
1) User deposits a SendEarn vault token (shares) into SendEarnRewards.
5) SendEarnRewards calls `sendx.flow(user, flowRate)` via the library to reflect the new aggregated assets (flowRate: TODO — pending final component).
180
+
181
+
Withdraw
182
+
1) SendEarnRewards withdraws assets held by the SendEarn underlying vault for the caller (redeeming vault shares it holds on behalf of the user). Receiver is the user linked to the vault.
183
+
2) SendEarnRewards updates mappings (decrement the user’s assets for that vault and total assets).
184
+
3) SendEarnRewards calls `sendx.flow(user, flowRate)` to reflect the reduced aggregated assets (flowRate: TODO — pending final component).
185
+
186
+
Redeem
187
+
- Same as withdraw but the entry uses shares (wrapper redeem path should convert shares → assets and follow the same mapping + flow update sequence).
188
+
189
+
Notes
190
+
- Exact `flowRate` computation is intentionally left as a TODO. We will integrate the final component (oracle/policy) to determine `flowRate` from the user’s aggregated assets.
191
+
- This flow does not rely on re-attributing underlying shares during ERC20 transfers. Flows and mappings update on deposit/withdraw/redeem only.
0 commit comments