@gooddollar/goodcollective-contracts 1.2.0 → 1.3.1

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 (62) hide show
  1. package/contracts/DirectPayments/DirectPaymentsFactory.sol +31 -12
  2. package/contracts/DirectPayments/DirectPaymentsLibrary.sol +208 -0
  3. package/contracts/DirectPayments/DirectPaymentsPool.sol +19 -151
  4. package/contracts/GoodCollective/GoodCollectiveSuperApp.sol +72 -19
  5. package/contracts/GoodCollective/IGoodCollectiveSuperApp.sol +10 -0
  6. package/contracts/GoodCollective/SuperAppBaseFlow.sol +6 -0
  7. package/contracts/Interfaces.sol +25 -0
  8. package/contracts/UBI/UBIPool.sol +76 -75
  9. package/contracts/UBI/UBIPoolFactory.sol +34 -13
  10. package/contracts/utils/HelperLibrary.sol +66 -23
  11. package/package.json +3 -3
  12. package/releases/deployment.json +8486 -30703
  13. package/typechain-types/contracts/DirectPayments/DirectPaymentsFactory.ts +16 -4
  14. package/typechain-types/contracts/DirectPayments/DirectPaymentsLibrary.ts +146 -0
  15. package/typechain-types/contracts/DirectPayments/DirectPaymentsPool.sol/DirectPaymentsPool.ts +191 -20
  16. package/typechain-types/contracts/DirectPayments/DirectPaymentsPool.sol/IMembersValidator.ts +6 -8
  17. package/typechain-types/contracts/DirectPayments/index.ts +1 -0
  18. package/typechain-types/contracts/GoodCollective/GoodCollectiveSuperApp.ts +141 -6
  19. package/typechain-types/contracts/{DirectPayments/DirectPaymentsFactory.sol/IRegistry.ts → GoodCollective/IGoodCollectiveSuperApp.sol/IGoodCollectiveSuperApp.ts} +32 -20
  20. package/typechain-types/contracts/GoodCollective/IGoodCollectiveSuperApp.sol/IRegistry.ts +38 -1
  21. package/typechain-types/contracts/GoodCollective/IGoodCollectiveSuperApp.sol/index.ts +1 -0
  22. package/typechain-types/contracts/GoodCollective/SuperAppBaseFlow.sol/IRegisterSuperapp.ts +152 -0
  23. package/typechain-types/contracts/GoodCollective/SuperAppBaseFlow.sol/SuperAppBaseFlow.ts +523 -0
  24. package/typechain-types/contracts/GoodCollective/SuperAppBaseFlow.sol/index.ts +5 -0
  25. package/typechain-types/contracts/GoodCollective/index.ts +2 -1
  26. package/typechain-types/contracts/{UBI/UBIPool.sol → Interfaces.sol}/IIdentityV2.ts +1 -1
  27. package/typechain-types/contracts/{UBI/UBIPool.sol → Interfaces.sol}/IMembersValidator.ts +1 -1
  28. package/typechain-types/contracts/{UBI/UBIPool.sol → Interfaces.sol}/index.ts +0 -1
  29. package/typechain-types/contracts/UBI/{UBIPool.sol/UBIPool.ts → UBIPool.ts} +279 -47
  30. package/typechain-types/contracts/UBI/UBIPoolFactory.ts +58 -34
  31. package/typechain-types/contracts/UBI/index.ts +1 -2
  32. package/typechain-types/contracts/index.ts +2 -0
  33. package/typechain-types/contracts/utils/HelperLibrary.ts +46 -4
  34. package/typechain-types/factories/contracts/DirectPayments/DirectPaymentsFactory__factory.ts +16 -1
  35. package/typechain-types/factories/contracts/DirectPayments/DirectPaymentsLibrary__factory.ts +169 -0
  36. package/typechain-types/factories/contracts/DirectPayments/DirectPaymentsPool.sol/DirectPaymentsPool__factory.ts +101 -2
  37. package/typechain-types/factories/contracts/DirectPayments/DirectPaymentsPool.sol/IMembersValidator__factory.ts +1 -1
  38. package/typechain-types/factories/contracts/DirectPayments/index.ts +1 -0
  39. package/typechain-types/factories/contracts/GoodCollective/GoodCollectiveSuperApp__factory.ts +66 -0
  40. package/typechain-types/factories/contracts/{DirectPayments/DirectPaymentsFactory.sol/IRegistry__factory.ts → GoodCollective/IGoodCollectiveSuperApp.sol/IGoodCollectiveSuperApp__factory.ts} +21 -12
  41. package/typechain-types/factories/contracts/GoodCollective/IGoodCollectiveSuperApp.sol/IRegistry__factory.ts +24 -0
  42. package/typechain-types/factories/contracts/GoodCollective/IGoodCollectiveSuperApp.sol/index.ts +1 -0
  43. package/typechain-types/factories/contracts/GoodCollective/SuperAppBaseFlow.sol/IRegisterSuperapp__factory.ts +62 -0
  44. package/typechain-types/factories/contracts/GoodCollective/SuperAppBaseFlow.sol/SuperAppBaseFlow__factory.ts +335 -0
  45. package/typechain-types/factories/contracts/GoodCollective/SuperAppBaseFlow.sol/index.ts +5 -0
  46. package/typechain-types/factories/contracts/GoodCollective/index.ts +1 -1
  47. package/typechain-types/factories/contracts/{UBI/UBIPool.sol → Interfaces.sol}/IIdentityV2__factory.ts +1 -1
  48. package/typechain-types/factories/contracts/{UBI/UBIPool.sol → Interfaces.sol}/IMembersValidator__factory.ts +1 -1
  49. package/typechain-types/factories/contracts/{UBI/UBIPool.sol → Interfaces.sol}/index.ts +0 -1
  50. package/typechain-types/factories/contracts/UBI/UBIPoolFactory__factory.ts +56 -7
  51. package/typechain-types/factories/contracts/UBI/UBIPool__factory.ts +2070 -0
  52. package/typechain-types/factories/contracts/UBI/index.ts +1 -1
  53. package/typechain-types/factories/contracts/index.ts +1 -0
  54. package/typechain-types/factories/contracts/test/HelperLibraryTest__factory.ts +1 -1
  55. package/typechain-types/factories/contracts/utils/HelperLibrary__factory.ts +41 -1
  56. package/typechain-types/hardhat.d.ts +35 -8
  57. package/typechain-types/index.ts +10 -4
  58. package/typechain-types/contracts/DirectPayments/DirectPaymentsFactory.sol/DirectPaymentsFactory.ts +0 -1327
  59. package/typechain-types/contracts/DirectPayments/DirectPaymentsFactory.sol/index.ts +0 -5
  60. package/typechain-types/factories/contracts/DirectPayments/DirectPaymentsFactory.sol/DirectPaymentsFactory__factory.ts +0 -1004
  61. package/typechain-types/factories/contracts/DirectPayments/DirectPaymentsFactory.sol/index.ts +0 -5
  62. package/typechain-types/factories/contracts/UBI/UBIPool.sol/UBIPool__factory.ts +0 -1916
@@ -10,10 +10,15 @@ import { CFAv1Library } from "@superfluid-finance/ethereum-contracts/contracts/a
10
10
 
11
11
  import "../GoodCollective/IGoodCollectiveSuperApp.sol";
12
12
 
13
+ // import "hardhat/console.sol";
14
+
13
15
  library HelperLibrary {
14
16
  using SuperTokenV1Library for ISuperToken;
15
17
  using CFAv1Library for CFAv1Library.InitData;
16
18
 
19
+ error ZERO_AMOUNT();
20
+ error ZERO_ADDRESS();
21
+
17
22
  /**
18
23
  * @dev A struct containing information about a token swap
19
24
  * @param swapFrom The address of the token being swapped
@@ -81,14 +86,33 @@ library HelperLibrary {
81
86
  function getRealtimeStats(
82
87
  IGoodCollectiveSuperApp.Stats memory stats,
83
88
  ISuperToken superToken
84
- ) external view returns (uint256 netIncome, uint256 totalFees, int96 incomeFlowRate, int96 feeRate) {
89
+ )
90
+ external
91
+ view
92
+ returns (
93
+ uint256 netIncome,
94
+ uint256 totalFees,
95
+ uint256 protocolFees,
96
+ uint256 managerFees,
97
+ int96 incomeFlowRate,
98
+ int96 feeRate,
99
+ int96 managerFeeRate
100
+ )
101
+ {
85
102
  incomeFlowRate = stats.lastIncomeRate;
86
103
  netIncome = stats.netIncome + uint96(stats.lastIncomeRate) * (block.timestamp - stats.lastUpdate);
87
104
  feeRate = superToken.getFlowRate(address(this), stats.lastFeeRecipient);
88
- totalFees =
89
- stats.totalFees +
105
+ managerFeeRate = superToken.getFlowRate(address(this), stats.lastManagerFeeRecipient);
106
+
107
+ protocolFees =
108
+ stats.protocolFees +
90
109
  uint96(superToken.getFlowRate(address(this), stats.lastFeeRecipient)) *
91
110
  (block.timestamp - stats.lastUpdate);
111
+ managerFees =
112
+ stats.managerFees +
113
+ uint96(superToken.getFlowRate(address(this), stats.lastManagerFeeRecipient)) *
114
+ (block.timestamp - stats.lastUpdate);
115
+ totalFees = protocolFees + managerFees;
92
116
  }
93
117
 
94
118
  // this should be called before any flow rate changes
@@ -96,54 +120,73 @@ library HelperLibrary {
96
120
  IGoodCollectiveSuperApp.Stats storage stats,
97
121
  ISuperToken superToken,
98
122
  IRegistry registry,
123
+ uint32 managerFeeBps,
99
124
  uint256 _amount
100
125
  ) external {
101
- //use last rate before the current possible rate update
102
- stats.netIncome += uint96(stats.lastIncomeRate) * (block.timestamp - stats.lastUpdate);
103
126
  uint feeBps;
104
127
  if (address(registry) != address(0)) {
105
128
  feeBps = registry.feeBps();
129
+ }
130
+ //use last rate before the current possible rate update
131
+ stats.netIncome += uint96(stats.lastIncomeRate) * (block.timestamp - stats.lastUpdate);
132
+ if (stats.lastFeeRecipient != address(0)) {
106
133
  //fees sent to last recipient, the flowRate to recipient still wasnt updated.
107
- stats.totalFees +=
134
+ stats.protocolFees +=
108
135
  uint96(superToken.getFlowRate(address(this), stats.lastFeeRecipient)) *
109
136
  (block.timestamp - stats.lastUpdate);
110
137
  }
138
+ if (stats.lastManagerFeeRecipient != address(0)) {
139
+ //fees sent to last recipient, the flowRate to recipient still wasnt updated.
140
+ stats.managerFees +=
141
+ uint96(superToken.getFlowRate(address(this), stats.lastManagerFeeRecipient)) *
142
+ (block.timestamp - stats.lastUpdate);
143
+ }
144
+
111
145
  if (_amount > 0) {
112
- stats.netIncome += (_amount * (10000 - feeBps)) / 10000;
113
- stats.totalFees += (_amount * feeBps) / 10000;
146
+ stats.netIncome += (_amount * (10000 - feeBps - managerFeeBps)) / 10000;
147
+ stats.protocolFees += (_amount * feeBps) / 10000;
148
+ stats.managerFees += (_amount * managerFeeBps) / 10000;
114
149
  }
150
+ stats.totalFees = stats.managerFees + stats.protocolFees;
115
151
  stats.lastUpdate = block.timestamp;
116
152
  }
117
153
 
118
154
  function takeFeeFlow(
119
155
  CFAv1Library.InitData storage cfaV1,
120
- IGoodCollectiveSuperApp.Stats storage stats,
121
156
  ISuperToken superToken,
122
- IRegistry registry,
157
+ address prevRecipient,
158
+ address recipient,
159
+ uint32 feeBps,
123
160
  int96 _diffRate,
124
161
  bytes memory _ctx
125
162
  ) public returns (bytes memory newCtx) {
126
163
  newCtx = _ctx;
127
- if (address(registry) == address(0)) return newCtx;
128
- address recipient = registry.feeRecipient();
129
- int96 curFeeRate = superToken.getFlowRate(address(this), stats.lastFeeRecipient);
164
+ if (address(recipient) == address(0)) return newCtx;
165
+ int96 curFeeRate = superToken.getFlowRate(address(this), prevRecipient);
130
166
  bool newRecipient;
131
- if (recipient != stats.lastFeeRecipient) {
167
+ if (recipient != prevRecipient) {
132
168
  newRecipient = true;
133
- if (stats.lastFeeRecipient != address(0)) {
169
+ if (prevRecipient != address(0)) {
134
170
  //delete old recipient flow
135
- if (curFeeRate > 0)
136
- newCtx = cfaV1.deleteFlowWithCtx(newCtx, address(this), stats.lastFeeRecipient, superToken); //passing in the ctx which is sent to the callback here
171
+ if (curFeeRate > 0) newCtx = cfaV1.deleteFlowWithCtx(newCtx, address(this), prevRecipient, superToken); //passing in the ctx which is sent to the callback here
137
172
  }
138
- stats.lastFeeRecipient = recipient;
139
173
  }
140
174
  if (recipient == address(0)) return newCtx;
141
175
 
142
- int96 newFeeRate = curFeeRate + (_diffRate * int32(registry.feeBps())) / 10000;
143
- if (newFeeRate <= 0 && newRecipient == false) {
144
- newCtx = cfaV1.deleteFlowWithCtx(newCtx, address(this), recipient, superToken); //passing in the ctx which is sent to the callback here
145
- } else if (curFeeRate > 0 && newRecipient == false) {
146
- newCtx = cfaV1.updateFlowWithCtx(newCtx, recipient, superToken, newFeeRate); //passing in the ctx which is sent to the callback here
176
+ int96 newFeeRate = curFeeRate + (_diffRate * int32(feeBps)) / 10000;
177
+ if (newRecipient == false && curFeeRate > 0) {
178
+ if (newFeeRate <= 0) {
179
+ newCtx = cfaV1.deleteFlowWithCtx(newCtx, address(this), recipient, superToken); //passing in the ctx which is sent to the callback here
180
+ } else {
181
+ newCtx = cfaV1.updateFlowWithCtx(newCtx, recipient, superToken, newFeeRate); //passing in the ctx which is sent to the callback here
182
+ }
147
183
  } else if (newFeeRate > 0) newCtx = cfaV1.createFlowWithCtx(newCtx, recipient, superToken, newFeeRate); //passing in the ctx which is sent to the callback here
148
184
  }
185
+
186
+ function recoverFunds(ISuperToken superToken, address recipient, uint256 amount) external {
187
+ require(IGoodCollectiveSuperApp(address(this)).getRegistry().hasRole(0x00, msg.sender), "not owner");
188
+ if (amount == 0) revert ZERO_AMOUNT();
189
+ if (recipient == address(0)) revert ZERO_ADDRESS();
190
+ superToken.transfer(recipient, amount);
191
+ }
149
192
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@gooddollar/goodcollective-contracts",
3
3
  "packageManager": "yarn@3.2.1",
4
- "version": "1.2.0",
4
+ "version": "1.3.1",
5
5
  "license": "MIT",
6
6
  "types": "./typechain-types/index.ts",
7
7
  "files": [
@@ -35,11 +35,11 @@
35
35
  "dotenv": "^16.3.1",
36
36
  "ethereum-waffle": "^3.0.0",
37
37
  "graphql": "^16.7.1",
38
- "hardhat": "^2.17.1",
38
+ "hardhat": "^2.26.2",
39
39
  "hardhat-abi-exporter": "^2.10.1",
40
40
  "hardhat-celo": "^0.0.4",
41
41
  "hardhat-contract-sizer": "^2.10.0",
42
- "hardhat-deploy": "^0.12.4",
42
+ "hardhat-deploy": "^1.0.4",
43
43
  "hardhat-gas-reporter": "^1.0.8",
44
44
  "prettier": "^2.8.8",
45
45
  "prettier-plugin-solidity": "^1.1.3",