@@ -103,7 +103,7 @@ abstract contract CFASuperAppBase is ISuperApp {
103103
104104 /// @dev override if the SuperApp shall have custom logic invoked when a new flow
105105 /// to it is created.
106- function onFlowCreated (
106+ function onInflowCreated (
107107 ISuperToken /*superToken*/ ,
108108 address /*sender*/ ,
109109 bytes calldata ctx
@@ -113,7 +113,7 @@ abstract contract CFASuperAppBase is ISuperApp {
113113
114114 /// @dev override if the SuperApp shall have custom logic invoked when an existing flow
115115 /// to it is updated (flowrate change).
116- function onFlowUpdated (
116+ function onInflowUpdated (
117117 ISuperToken /*superToken*/ ,
118118 address /*sender*/ ,
119119 int96 /*previousFlowRate*/ ,
@@ -127,9 +127,25 @@ abstract contract CFASuperAppBase is ISuperApp {
127127 /// to it is deleted (flowrate set to 0).
128128 /// Unlike the other callbacks, this method is NOT allowed to revert.
129129 /// Failing to satisfy that requirement leads to jailing (defunct SuperApp).
130- function onFlowDeleted (
130+ function onInflowDeleted (
131131 ISuperToken /*superToken*/ ,
132132 address /*sender*/ ,
133+ int96 /*previousFlowRate*/ ,
134+ uint256 /*lastUpdated*/ ,
135+ bytes calldata ctx
136+ ) internal virtual returns (bytes memory /*newCtx*/ ) {
137+ return ctx;
138+ }
139+
140+ /// @dev override if the SuperApp shall have custom logic invoked when an outgoing flow
141+ /// is deleted by the receiver (it's not triggered when deleted by the SuperApp itself).
142+ /// A possible implementation is to make outflows "sticky" by simply reopening it.
143+ /// Like onInflowDeleted, this method is NOT allowed to revert.
144+ /// Note: In theory this hook could also be triggered by a liquidation, but this would imply
145+ /// that the SuperApp is insolvent, and would thus be jailed already.
146+ /// Thus in practice this is triggered only when a receiver deletes the flow.
147+ function onOutflowDeleted (
148+ ISuperToken /*superToken*/ ,
133149 address /*receiver*/ ,
134150 int96 /*previousFlowRate*/ ,
135151 uint256 /*lastUpdated*/ ,
@@ -173,7 +189,7 @@ abstract contract CFASuperAppBase is ISuperApp {
173189 (address sender , ) = abi.decode (agreementData, (address , address ));
174190
175191 return
176- onFlowCreated (
192+ onInflowCreated (
177193 superToken,
178194 sender,
179195 ctx // userData can be acquired with `host.decodeCtx(ctx).userData`
@@ -218,7 +234,7 @@ abstract contract CFASuperAppBase is ISuperApp {
218234 (int96 previousFlowRate , uint256 lastUpdated ) = abi.decode (cbdata, (int96 , uint256 ));
219235
220236 return
221- onFlowUpdated (
237+ onInflowUpdated (
222238 superToken,
223239 sender,
224240 previousFlowRate,
@@ -272,15 +288,26 @@ abstract contract CFASuperAppBase is ISuperApp {
272288 (address sender , address receiver ) = abi.decode (agreementData, (address , address ));
273289 (uint256 lastUpdated , int96 previousFlowRate ) = abi.decode (cbdata, (uint256 , int96 ));
274290
275- return
276- onFlowDeleted (
277- superToken,
278- sender,
279- receiver,
280- previousFlowRate,
281- lastUpdated,
282- ctx
291+ if (receiver == address (this )) {
292+ return
293+ onInflowDeleted (
294+ superToken,
295+ sender,
296+ previousFlowRate,
297+ lastUpdated,
298+ ctx
299+ );
300+ } else {
301+ return
302+ onOutflowDeleted (
303+ superToken,
304+ receiver,
305+ previousFlowRate,
306+ lastUpdated,
307+ ctx
308+ )
283309 );
310+ }
284311 }
285312
286313
0 commit comments