@superfluid-finance/ethereum-contracts 1.5.2-dev.a97f248.0 → 1.5.2-dev.fe6f63e.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (133) hide show
  1. package/build/contracts/AccessControl.json +1 -1
  2. package/build/contracts/AccessControlEnumerable.json +1 -1
  3. package/build/contracts/Address.json +1 -1
  4. package/build/contracts/AgreementBase.json +1 -1
  5. package/build/contracts/AgreementLibrary.json +1 -1
  6. package/build/contracts/BaseRelayRecipient.json +1 -1
  7. package/build/contracts/BatchLiquidator.json +1 -1
  8. package/build/contracts/BatchOperation.json +1 -1
  9. package/build/contracts/CFAv1Forwarder.json +1 -1
  10. package/build/contracts/CFAv1Library.json +1 -1
  11. package/build/contracts/CallUtils.json +1 -1
  12. package/build/contracts/ClosingOnUpdateFlowTestApp.json +1 -1
  13. package/build/contracts/ConstantFlowAgreementV1.json +1 -1
  14. package/build/contracts/Context.json +1 -1
  15. package/build/contracts/ContextDefinitions.json +1 -1
  16. package/build/contracts/CustomSuperTokenBase.json +1 -1
  17. package/build/contracts/ERC165.json +1 -1
  18. package/build/contracts/ERC1820Implementer.json +1 -1
  19. package/build/contracts/ERC1820RegistryCompiled.json +1 -1
  20. package/build/contracts/ERC20.json +1 -1
  21. package/build/contracts/ERC20WithTokenInfo.json +1 -1
  22. package/build/contracts/ERC777Helper.json +1 -1
  23. package/build/contracts/ERC777RecipientDrainingGas.json +1 -1
  24. package/build/contracts/ERC777RecipientReverting.json +1 -1
  25. package/build/contracts/EnumerableSet.json +1 -1
  26. package/build/contracts/EventsEmitter.json +1 -1
  27. package/build/contracts/ExclusiveInflowTestApp.json +1 -1
  28. package/build/contracts/FixedSizeData.json +1 -1
  29. package/build/contracts/FlowExchangeTestApp.json +1 -1
  30. package/build/contracts/FlowOperatorDefinitions.json +1 -1
  31. package/build/contracts/FullUpgradableSuperTokenProxy.json +1 -1
  32. package/build/contracts/IAccessControl.json +1 -1
  33. package/build/contracts/IAccessControlEnumerable.json +1 -1
  34. package/build/contracts/IConstantFlowAgreementHook.json +1 -1
  35. package/build/contracts/IConstantFlowAgreementV1.json +1 -1
  36. package/build/contracts/IDAv1Library.json +1 -1
  37. package/build/contracts/IERC165.json +1 -1
  38. package/build/contracts/IERC1820Implementer.json +1 -1
  39. package/build/contracts/IERC1820Registry.json +1 -1
  40. package/build/contracts/IERC20.json +1 -1
  41. package/build/contracts/IERC20Metadata.json +1 -1
  42. package/build/contracts/IERC20Permit.json +1 -1
  43. package/build/contracts/IERC777.json +1 -1
  44. package/build/contracts/IERC777Recipient.json +1 -1
  45. package/build/contracts/IERC777Sender.json +1 -1
  46. package/build/contracts/IInstantDistributionAgreementV1.json +1 -1
  47. package/build/contracts/IMultiSigWallet.json +1 -1
  48. package/build/contracts/IPureSuperToken.json +1 -1
  49. package/build/contracts/IPureSuperTokenCustom.json +1 -1
  50. package/build/contracts/IRelayRecipient.json +1 -1
  51. package/build/contracts/IResolver.json +1 -1
  52. package/build/contracts/ISETH.json +1 -1
  53. package/build/contracts/ISETHCustom.json +1 -1
  54. package/build/contracts/ISuperAgreement.json +1 -1
  55. package/build/contracts/ISuperApp.json +1 -1
  56. package/build/contracts/ISuperToken.json +1 -1
  57. package/build/contracts/ISuperTokenFactory.json +1 -1
  58. package/build/contracts/ISuperfluid.json +1 -1
  59. package/build/contracts/ISuperfluidGovernance.json +1 -1
  60. package/build/contracts/ISuperfluidToken.json +1 -1
  61. package/build/contracts/ITOGAv1.json +1 -1
  62. package/build/contracts/ITOGAv2.json +1 -1
  63. package/build/contracts/ITOGAv3.json +1 -1
  64. package/build/contracts/Initializable.json +1 -1
  65. package/build/contracts/InstantDistributionAgreementV1.json +1 -1
  66. package/build/contracts/Math.json +1 -1
  67. package/build/contracts/NonClosableOutflowTestApp.json +1 -1
  68. package/build/contracts/Ownable.json +1 -1
  69. package/build/contracts/Proxy.json +1 -1
  70. package/build/contracts/PureSuperToken.json +1 -1
  71. package/build/contracts/Resolver.json +1 -1
  72. package/build/contracts/SETHProxy.json +1 -1
  73. package/build/contracts/SafeCast.json +1 -1
  74. package/build/contracts/SafeERC20.json +1 -1
  75. package/build/contracts/SafeMath.json +1 -1
  76. package/build/contracts/SelfDeletingFlowTestApp.json +1 -1
  77. package/build/contracts/SlotsBitmapLibrary.json +1 -1
  78. package/build/contracts/StreamRedirector.json +1 -1
  79. package/build/contracts/Strings.json +1 -1
  80. package/build/contracts/SuperAppBase.json +1 -1
  81. package/build/contracts/SuperAppDefinitions.json +1 -1
  82. package/build/contracts/SuperToken.json +1 -1
  83. package/build/contracts/SuperTokenDeployerLibrary.json +1 -1
  84. package/build/contracts/SuperTokenFactory.json +1 -1
  85. package/build/contracts/SuperTokenFactoryBase.json +1 -1
  86. package/build/contracts/SuperTokenV1Library.json +1 -1
  87. package/build/contracts/SuperUpgrader.json +1 -1
  88. package/build/contracts/Superfluid.json +1 -1
  89. package/build/contracts/SuperfluidCFAv1DeployerLibrary.json +1 -1
  90. package/build/contracts/SuperfluidFrameworkDeployer.json +1 -1
  91. package/build/contracts/SuperfluidGovDeployerLibrary.json +1 -1
  92. package/build/contracts/SuperfluidGovernanceBase.json +1 -1
  93. package/build/contracts/SuperfluidGovernanceConfigs.json +1 -1
  94. package/build/contracts/SuperfluidGovernanceII.json +1 -1
  95. package/build/contracts/SuperfluidGovernanceIIProxy.json +1 -1
  96. package/build/contracts/SuperfluidHostDeployerLibrary.json +1 -1
  97. package/build/contracts/SuperfluidIDAv1DeployerLibrary.json +1 -1
  98. package/build/contracts/SuperfluidLoader.json +1 -1
  99. package/build/contracts/SuperfluidPeripheryDeployerLibrary.json +1 -1
  100. package/build/contracts/SuperfluidToken.json +1 -1
  101. package/build/contracts/TOGA.json +1 -1
  102. package/build/contracts/TestGovernance.json +1 -1
  103. package/build/contracts/TestResolver.json +1 -1
  104. package/build/contracts/TestToken.json +1 -1
  105. package/build/contracts/TokenInfo.json +1 -1
  106. package/build/contracts/UUPSProxiable.json +1 -1
  107. package/build/contracts/UUPSProxy.json +1 -1
  108. package/build/contracts/UUPSUtils.json +1 -1
  109. package/build/contracts-sizes.txt +9 -9
  110. package/package.json +2 -2
  111. package/contracts/mocks/AgreementMock.sol +0 -375
  112. package/contracts/mocks/CFAAppMocks.sol +0 -361
  113. package/contracts/mocks/CFAHookMocks.sol +0 -148
  114. package/contracts/mocks/CFALibraryMock.sol +0 -213
  115. package/contracts/mocks/CallUtilsMock.sol +0 -79
  116. package/contracts/mocks/CallUtilsTester.sol +0 -14
  117. package/contracts/mocks/CustomSuperTokenMock.sol +0 -104
  118. package/contracts/mocks/ERC777SenderRecipientMock.sol +0 -238
  119. package/contracts/mocks/FakeSuperfluidMock.sol +0 -21
  120. package/contracts/mocks/ForwarderMock.sol +0 -39
  121. package/contracts/mocks/IDASuperAppTester.sol +0 -297
  122. package/contracts/mocks/IDAv1LibraryMock.sol +0 -400
  123. package/contracts/mocks/MockSmartWallet.sol +0 -15
  124. package/contracts/mocks/MultiFlowTesterApp.sol +0 -336
  125. package/contracts/mocks/StreamRedirector.sol +0 -179
  126. package/contracts/mocks/SuperAppMocks.sol +0 -622
  127. package/contracts/mocks/SuperTokenFactoryMock.sol +0 -98
  128. package/contracts/mocks/SuperTokenLibraryV1Mock.sol +0 -583
  129. package/contracts/mocks/SuperTokenMock.sol +0 -113
  130. package/contracts/mocks/SuperfluidDestructorMock.sol +0 -14
  131. package/contracts/mocks/SuperfluidGovernanceIIMock.sol +0 -22
  132. package/contracts/mocks/SuperfluidMock.sol +0 -177
  133. package/contracts/mocks/UUPSProxiableMock.sol +0 -29
@@ -1,336 +0,0 @@
1
- // SPDX-License-Identifier: AGPLv3
2
- pragma solidity 0.8.18;
3
-
4
- import {
5
- ISuperfluid,
6
- ISuperToken,
7
- SuperAppBase,
8
- SuperAppDefinitions
9
- } from "../apps/SuperAppBase.sol";
10
- import { IConstantFlowAgreementV1 } from "../interfaces/agreements/IConstantFlowAgreementV1.sol";
11
-
12
- /**
13
- * @title Multi Flow tester App (MFA)
14
- * @author Superfluid
15
- * @dev A super app that can split incoming flows to multiple outgoing flows.
16
- * This is used for testing CFA callbacks logic.
17
- */
18
- contract MultiFlowTesterApp is SuperAppBase {
19
-
20
- struct ReceiverData {
21
- address to;
22
- uint256 proportion;
23
- }
24
-
25
- struct Configuration {
26
- uint8 ratioPct;
27
- ReceiverData[] receivers;
28
- }
29
-
30
- IConstantFlowAgreementV1 private _cfa;
31
- ISuperfluid private _host;
32
-
33
- constructor(IConstantFlowAgreementV1 cfa, ISuperfluid superfluid) {
34
- assert(address(cfa) != address(0));
35
- assert(address(superfluid) != address(0));
36
- _cfa = cfa;
37
- _host = superfluid;
38
-
39
- uint256 configWord =
40
- SuperAppDefinitions.APP_LEVEL_FINAL |
41
- SuperAppDefinitions.BEFORE_AGREEMENT_CREATED_NOOP |
42
- SuperAppDefinitions.BEFORE_AGREEMENT_TERMINATED_NOOP;
43
-
44
- _host.registerAppWithKey(configWord, "");
45
- }
46
-
47
- function _parseUserData(
48
- bytes memory userData
49
- )
50
- private pure
51
- returns (address sender, Configuration memory configuration)
52
- {
53
- // parse user data
54
- uint8 ratioPct;
55
- address[] memory receivers;
56
- uint256[] memory proportions;
57
- (sender, ratioPct, receivers, proportions) = abi.decode(
58
- userData, (address, uint8, address[], uint256[]));
59
- assert(receivers.length == proportions.length);
60
-
61
- configuration.ratioPct = ratioPct;
62
- configuration.receivers = new ReceiverData[](receivers.length);
63
- for (uint256 i = 0; i < receivers.length; ++i) {
64
- assert(proportions[i] != 0);
65
- configuration.receivers[i] = ReceiverData(receivers[i], proportions[i]);
66
- }
67
- }
68
-
69
- function _sumProportions(ReceiverData[] memory receivers) internal pure returns(uint256 sum) {
70
- for (uint256 i = 0; i < receivers.length; ++i) {
71
- sum += receivers[i].proportion;
72
- }
73
- }
74
-
75
- function _updateMultiFlow(
76
- Configuration memory configuration,
77
- ISuperToken superToken,
78
- bytes4 selector,
79
- int96 flowRate,
80
- uint256 appCreditGranted,
81
- bytes calldata ctx
82
- )
83
- private
84
- returns (bytes memory newCtx)
85
- {
86
- uint256 sum = _sumProportions(configuration.receivers);
87
-
88
- newCtx = ctx;
89
-
90
- // in case of mfa, we underutlize the app credit for simplicity
91
- uint256 flowRateDeposit = _cfa.getDepositRequiredForFlowRate(superToken, flowRate);
92
- int96 safeFlowRate = _cfa.getMaximumFlowRateFromDeposit(superToken, flowRateDeposit - 1);
93
- appCreditGranted = _cfa.getDepositRequiredForFlowRate(superToken, safeFlowRate);
94
-
95
- // scale the flow rate and app credit numbers
96
- appCreditGranted = appCreditGranted * configuration.ratioPct / 100;
97
- // NOTE casting to int96 is okay here because ratioPct is uint8
98
- flowRate = flowRate * int96(uint96(configuration.ratioPct)) / 100;
99
-
100
- for (uint256 i = 0; i < configuration.receivers.length; ++i) {
101
- ReceiverData memory receiverData = configuration.receivers[i];
102
- uint256 targetCredit = appCreditGranted * receiverData.proportion / sum;
103
- int96 targetFlowRate = _cfa.getMaximumFlowRateFromDeposit(
104
- superToken,
105
- targetCredit
106
- );
107
- flowRate -= targetFlowRate;
108
- bytes memory callData = abi.encodeWithSelector(
109
- selector,
110
- superToken,
111
- receiverData.to,
112
- targetFlowRate,
113
- new bytes(0)
114
- );
115
- (newCtx, ) = _host.callAgreementWithContext(
116
- _cfa,
117
- callData,
118
- new bytes(0), // user data
119
- newCtx
120
- );
121
- }
122
- assert(flowRate >= 0);
123
- }
124
-
125
- // this function is for testing purpose
126
- function createFlow(
127
- ISuperToken superToken,
128
- address receiver,
129
- int96 flowRate,
130
- bytes calldata ctx
131
- )
132
- external
133
- returns (bytes memory newCtx)
134
- {
135
- bytes memory callData = abi.encodeCall(
136
- _cfa.createFlow,
137
- (
138
- superToken,
139
- receiver,
140
- flowRate,
141
- new bytes(0)
142
- )
143
- );
144
- (newCtx, ) = _host.callAgreementWithContext(
145
- _cfa,
146
- callData,
147
- new bytes(0), // user data
148
- ctx
149
- );
150
- }
151
-
152
- struct StackVars {
153
- ISuperfluid.Context context;
154
- address mfaSender;
155
- Configuration configuration;
156
- address flowSender;
157
- address flowReceiver;
158
- }
159
-
160
- function afterAgreementCreated(
161
- ISuperToken superToken,
162
- address agreementClass,
163
- bytes32 agreementId,
164
- bytes calldata agreementData,
165
- bytes calldata /*cbdata*/,
166
- bytes calldata ctx
167
- )
168
- external override
169
- onlyHost
170
- returns(bytes memory newCtx)
171
- {
172
- assert(agreementClass == address(_cfa));
173
- StackVars memory vars;
174
-
175
- vars.context = _host.decodeCtx(ctx);
176
- // parse user data
177
- (vars.mfaSender, vars.configuration) = _parseUserData(vars.context.userData);
178
- // validate the context
179
- {
180
- (vars.flowSender, vars.flowReceiver) = abi.decode(agreementData, (address, address));
181
- assert(vars.flowSender == vars.context.msgSender);
182
- assert(vars.flowReceiver == address(this));
183
- assert(vars.context.appCreditGranted > 0);
184
- }
185
- int96 flowRate;
186
- (,flowRate,,) = _cfa.getFlowByID(superToken, agreementId);
187
- newCtx = _updateMultiFlow(
188
- vars.configuration,
189
- superToken,
190
- _cfa.createFlow.selector,
191
- flowRate,
192
- vars.context.appCreditGranted,
193
- ctx);
194
- }
195
-
196
- function beforeAgreementUpdated(
197
- ISuperToken superToken,
198
- address agreementClass,
199
- bytes32 agreementId,
200
- bytes calldata /*agreementData*/,
201
- bytes calldata /*ctx*/
202
- )
203
- external view override
204
- onlyHost
205
- returns (bytes memory cbdata)
206
- {
207
- assert(agreementClass == address(_cfa));
208
- (, int256 oldFlowRate, ,) = _cfa.getFlowByID(superToken, agreementId);
209
- return abi.encode(oldFlowRate);
210
- }
211
-
212
- function afterAgreementUpdated(
213
- ISuperToken superToken,
214
- address agreementClass,
215
- bytes32 agreementId,
216
- bytes calldata agreementData,
217
- bytes calldata /* cbdata */,
218
- bytes calldata ctx
219
- )
220
- external override
221
- onlyHost
222
- returns (bytes memory newCtx)
223
- {
224
- assert(agreementClass == address(_cfa));
225
- StackVars memory vars;
226
-
227
- vars.context = _host.decodeCtx(ctx);
228
- // parse user data
229
- (vars.mfaSender, vars.configuration) = _parseUserData(vars.context.userData);
230
- // validate the context
231
- {
232
- (vars.flowSender, vars.flowReceiver) = abi.decode(agreementData, (address, address));
233
- assert(vars.flowSender == vars.context.msgSender);
234
- assert(vars.flowReceiver == address(this));
235
- assert(vars.context.appCreditGranted > 0);
236
- }
237
- int96 flowRate;
238
- (,flowRate,,) = _cfa.getFlowByID(superToken, agreementId);
239
- newCtx = _updateMultiFlow(
240
- vars.configuration,
241
- superToken,
242
- _cfa.updateFlow.selector,
243
- flowRate,
244
- vars.context.appCreditGranted,
245
- ctx);
246
- }
247
-
248
- function afterAgreementTerminated(
249
- ISuperToken superToken,
250
- address agreementClass,
251
- bytes32 /*agreementId*/,
252
- bytes calldata agreementData,
253
- bytes calldata /*cbdata*/,
254
- bytes calldata ctx
255
- )
256
-
257
- external override
258
- onlyHost
259
- returns (bytes memory newCtx)
260
- {
261
- assert(agreementClass == address(_cfa));
262
- StackVars memory vars;
263
-
264
- vars.context = _host.decodeCtx(ctx);
265
-
266
- // parse user data
267
- (vars.mfaSender, vars.configuration) = _parseUserData(vars.context.userData);
268
- // validate the context
269
- (vars.flowSender, vars.flowReceiver) = abi.decode(agreementData, (address, address));
270
- assert(vars.flowSender == address(this) || vars.flowReceiver == address(this));
271
-
272
- bytes memory callData;
273
- newCtx = ctx;
274
- if (vars.flowReceiver == address(this)) {
275
- for (uint256 i = 0; i < vars.configuration.receivers.length; ++i) {
276
- callData = abi.encodeCall(
277
- _cfa.deleteFlow,
278
- (
279
- superToken,
280
- address(this),
281
- vars.configuration.receivers[i].to,
282
- new bytes(0) //placeholder ctx
283
- )
284
- );
285
- (newCtx, ) = _host.callAgreementWithContext(
286
- _cfa,
287
- callData,
288
- new bytes(0), // user data
289
- newCtx
290
- );
291
- }
292
- } else /* if (vars.flowSender == address(this)) */ {
293
- for (uint256 i = 0; i < vars.configuration.receivers.length; ++i) {
294
- // skip current closed flow
295
- if (vars.configuration.receivers[i].to == vars.flowReceiver) continue;
296
- // close the rest of the mfa receiver flows
297
- callData = abi.encodeCall(
298
- _cfa.deleteFlow,
299
- (
300
- superToken,
301
- address(this),
302
- vars.configuration.receivers[i].to,
303
- new bytes(0) //placeholder ctx
304
- )
305
- );
306
- (newCtx, ) = _host.callAgreementWithContext(
307
- _cfa,
308
- callData,
309
- new bytes(0), // user data
310
- newCtx
311
- );
312
- }
313
- // close the mfa sender flow
314
- callData = abi.encodeCall(
315
- _cfa.deleteFlow,
316
- (
317
- superToken,
318
- vars.mfaSender,
319
- address(this),
320
- new bytes(0) //placeholder ctx
321
- )
322
- );
323
- (newCtx, ) = _host.callAgreementWithContext(
324
- _cfa,
325
- callData,
326
- new bytes(0), // user data
327
- newCtx
328
- );
329
- }
330
- }
331
-
332
- modifier onlyHost() {
333
- assert(msg.sender == address(_host));
334
- _;
335
- }
336
- }
@@ -1,179 +0,0 @@
1
- // SPDX-License-Identifier: AGPLv3
2
- pragma solidity 0.8.18;
3
-
4
- import { ISuperfluid, ISuperToken, SuperAppBase, ISuperApp, SuperAppDefinitions } from "../apps/SuperAppBase.sol";
5
- import { CFAv1Library } from "../apps/CFAv1Library.sol";
6
- import { IConstantFlowAgreementV1 } from "../interfaces/agreements/IConstantFlowAgreementV1.sol";
7
- import { ISuperAgreement } from "../interfaces/superfluid/ISuperfluid.sol";
8
-
9
- contract StreamRedirector is SuperAppBase {
10
- using CFAv1Library for CFAv1Library.InitData;
11
- CFAv1Library.InitData public cfaV1;
12
- ISuperfluid public host;
13
- bytes32 public constant CFA_ID =
14
- keccak256("org.superfluid-finance.agreements.ConstantFlowAgreement.v1");
15
- address public receiver; // flow is redirected to hardcoded receiver address
16
- ISuperToken public token; // accepted super token
17
-
18
- constructor(
19
- ISuperfluid _host,
20
- ISuperToken _token,
21
- address _receiver,
22
- uint256 _appLevel
23
- ) {
24
- assert(address(_token) != address(0));
25
- assert(address(_receiver) != address(0));
26
- assert(address(_host) != address(0));
27
-
28
- host = _host;
29
-
30
- cfaV1 = CFAv1Library.InitData(
31
- host,
32
- IConstantFlowAgreementV1(address(host.getAgreementClass(CFA_ID)))
33
- );
34
-
35
- uint256 configWord = _appLevel |
36
- SuperAppDefinitions.BEFORE_AGREEMENT_CREATED_NOOP |
37
- SuperAppDefinitions.BEFORE_AGREEMENT_TERMINATED_NOOP;
38
-
39
- token = _token;
40
- receiver = _receiver;
41
-
42
- host.registerAppWithKey(configWord, "");
43
- }
44
-
45
- /**
46
- * Custom Errors
47
- */
48
- error OnlyHost();
49
- error OnlyCFA();
50
- error UnsupportedToken();
51
-
52
- /**
53
- * Creates a stream from an _originAccount who has granted this SuperApp ACL permissions
54
- * to this SuperApp.
55
- * @param _originAccount ACL permissions granter
56
- * @param _flowRate desired flow rate
57
- */
58
- function startStreamToSelf(address _originAccount, int96 _flowRate) public {
59
- cfaV1.createFlowByOperator(
60
- _originAccount,
61
- address(this),
62
- token,
63
- _flowRate
64
- );
65
- }
66
-
67
- /**
68
- * Terminates a stream from an _originAccount who has granted this SuperApp ACL permissions
69
- * @param _originAccount ACL permissions granter
70
- */
71
- function stopStreamToSelf(address _originAccount) public {
72
- cfaV1.deleteFlowByOperator(_originAccount, address(this), token);
73
- }
74
-
75
- /**
76
- * Creates a stream from this Super App to another SuperApp.
77
- * @param _superApp the targeted super app
78
- * @param _flowRate desired flow rate
79
- */
80
- function startStreamToSuperApp(address _superApp, int96 _flowRate) public {
81
- cfaV1.createFlow(_superApp, token, _flowRate);
82
- }
83
-
84
- /**
85
- * Delete a stream from sender to receiver.
86
- * @param _sender the sender super app
87
- * @param _receiver the receiver super app
88
- */
89
- function stopStreamToSuperApp(address _sender, address _receiver) public {
90
- cfaV1.deleteFlow(_sender, _receiver, token);
91
- }
92
-
93
- /**
94
- * A callback which occurs after CF agreement creation which redirects a stream.
95
- */
96
- function afterAgreementCreated(
97
- ISuperToken _superToken,
98
- address _agreementClass,
99
- bytes32, // agreementId,
100
- bytes calldata, // agreementData,
101
- bytes calldata, // cbdata,
102
- bytes calldata _ctx
103
- )
104
- external
105
- override
106
- onlyHost
107
- onlySupportedSuperToken(_superToken)
108
- onlyCFA(_agreementClass)
109
- returns (bytes memory newCtx)
110
- {
111
- newCtx = _ctx;
112
- int96 netFlowRate = cfaV1.cfa.getNetFlow(_superToken, address(this));
113
- newCtx = cfaV1.createFlowWithCtx(
114
- newCtx,
115
- receiver,
116
- _superToken,
117
- netFlowRate
118
- );
119
- }
120
-
121
- function afterAgreementTerminated(
122
- ISuperToken _superToken,
123
- address _agreementClass,
124
- bytes32, // _agreementId,
125
- bytes calldata, // calldata _agreementData,
126
- bytes calldata, // calldata _cbdata,
127
- bytes calldata _ctx
128
- ) external override onlyHost returns (bytes memory newCtx) {
129
- if (!_isCFAv1(_agreementClass) || address(_superToken) != address(token)) {
130
- return _ctx;
131
- }
132
-
133
- newCtx = _ctx;
134
- (, int96 currentFlowRate, , ) = cfaV1.cfa.getFlow(
135
- _superToken,
136
- address(this),
137
- receiver
138
- );
139
-
140
- if (currentFlowRate > 0) {
141
- newCtx = cfaV1.deleteFlowWithCtx(
142
- newCtx,
143
- address(this),
144
- receiver,
145
- _superToken
146
- );
147
- }
148
- }
149
-
150
- /**
151
- * Alleviates the composite app rule by allowing this app to call
152
- * the target app.
153
- * @param _targetApp address of the target super app, should be initialized with final_level
154
- */
155
- function allowCompositeApp(address _targetApp) public {
156
- host.allowCompositeApp(ISuperApp(_targetApp));
157
- }
158
-
159
- function _isCFAv1(address agreementClass) private view returns (bool) {
160
- return ISuperAgreement(agreementClass).agreementType() == CFA_ID;
161
- }
162
-
163
- /**
164
- * Modifiers
165
- */
166
- modifier onlyHost() {
167
- if (msg.sender != address(host)) revert OnlyHost();
168
- _;
169
- }
170
- modifier onlySupportedSuperToken(ISuperToken _superToken) {
171
- if (address(_superToken) != address(token)) revert UnsupportedToken();
172
- _;
173
- }
174
-
175
- modifier onlyCFA(address agreementClass) {
176
- if (!_isCFAv1(agreementClass)) revert OnlyCFA();
177
- _;
178
- }
179
- }