@gooddollar/goodcollective-contracts 1.2.0 → 1.3.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.
- package/contracts/DirectPayments/DirectPaymentsFactory.sol +12 -7
- package/contracts/DirectPayments/DirectPaymentsLibrary.sol +54 -0
- package/contracts/DirectPayments/DirectPaymentsPool.sol +13 -38
- package/contracts/GoodCollective/GoodCollectiveSuperApp.sol +65 -13
- package/contracts/GoodCollective/IGoodCollectiveSuperApp.sol +6 -0
- package/contracts/Interfaces.sol +25 -0
- package/contracts/UBI/UBIPool.sol +76 -75
- package/contracts/UBI/UBIPoolFactory.sol +15 -10
- package/contracts/utils/HelperLibrary.sol +56 -23
- package/package.json +1 -1
- package/releases/deployment.json +4836 -3746
- package/typechain-types/contracts/DirectPayments/DirectPaymentsFactory.ts +16 -4
- package/typechain-types/contracts/DirectPayments/DirectPaymentsPool.sol/DirectPaymentsPool.ts +138 -9
- package/typechain-types/contracts/GoodCollective/GoodCollectiveSuperApp.ts +101 -6
- package/typechain-types/contracts/{DirectPayments/DirectPaymentsFactory.sol/IRegistry.ts → GoodCollective/IGoodCollectiveSuperApp.sol/IGoodCollectiveSuperApp.ts} +18 -27
- package/typechain-types/contracts/GoodCollective/IGoodCollectiveSuperApp.sol/index.ts +1 -0
- package/typechain-types/contracts/{UBI/UBIPool.sol → Interfaces.sol}/IIdentityV2.ts +1 -1
- package/typechain-types/contracts/{UBI/UBIPool.sol → Interfaces.sol}/IMembersValidator.ts +1 -1
- package/typechain-types/contracts/{UBI/UBIPool.sol → Interfaces.sol}/index.ts +0 -1
- package/typechain-types/contracts/UBI/{UBIPool.sol/UBIPool.ts → UBIPool.ts} +239 -47
- package/typechain-types/contracts/UBI/UBIPoolFactory.ts +58 -34
- package/typechain-types/contracts/UBI/index.ts +1 -2
- package/typechain-types/contracts/index.ts +2 -0
- package/typechain-types/contracts/utils/HelperLibrary.ts +46 -4
- package/typechain-types/factories/contracts/DirectPayments/DirectPaymentsFactory__factory.ts +11 -1
- package/typechain-types/factories/contracts/DirectPayments/DirectPaymentsPool.sol/DirectPaymentsPool__factory.ts +72 -1
- package/typechain-types/factories/contracts/GoodCollective/GoodCollectiveSuperApp__factory.ts +48 -0
- package/typechain-types/factories/contracts/{DirectPayments/DirectPaymentsFactory.sol/IRegistry__factory.ts → GoodCollective/IGoodCollectiveSuperApp.sol/IGoodCollectiveSuperApp__factory.ts} +19 -23
- package/typechain-types/factories/contracts/GoodCollective/IGoodCollectiveSuperApp.sol/index.ts +1 -0
- package/typechain-types/factories/contracts/{UBI/UBIPool.sol → Interfaces.sol}/IIdentityV2__factory.ts +1 -1
- package/typechain-types/factories/contracts/{UBI/UBIPool.sol → Interfaces.sol}/IMembersValidator__factory.ts +1 -1
- package/typechain-types/factories/contracts/{UBI/UBIPool.sol → Interfaces.sol}/index.ts +0 -1
- package/typechain-types/factories/contracts/UBI/UBIPoolFactory__factory.ts +51 -7
- package/typechain-types/factories/contracts/UBI/UBIPool__factory.ts +2052 -0
- package/typechain-types/factories/contracts/UBI/index.ts +1 -1
- package/typechain-types/factories/contracts/index.ts +1 -0
- package/typechain-types/factories/contracts/test/HelperLibraryTest__factory.ts +1 -1
- package/typechain-types/factories/contracts/utils/HelperLibrary__factory.ts +31 -1
- package/typechain-types/hardhat.d.ts +18 -9
- package/typechain-types/index.ts +4 -2
- package/typechain-types/contracts/DirectPayments/DirectPaymentsFactory.sol/DirectPaymentsFactory.ts +0 -1327
- package/typechain-types/contracts/DirectPayments/DirectPaymentsFactory.sol/index.ts +0 -5
- package/typechain-types/factories/contracts/DirectPayments/DirectPaymentsFactory.sol/DirectPaymentsFactory__factory.ts +0 -1004
- package/typechain-types/factories/contracts/DirectPayments/DirectPaymentsFactory.sol/index.ts +0 -5
- package/typechain-types/factories/contracts/UBI/UBIPool.sol/UBIPool__factory.ts +0 -1916
|
@@ -10,7 +10,9 @@ import "@openzeppelin/contracts/proxy/beacon/UpgradeableBeacon.sol";
|
|
|
10
10
|
import { AccessControlUpgradeable } from "@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol";
|
|
11
11
|
import { UUPSUpgradeable } from "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
|
|
12
12
|
|
|
13
|
-
import "
|
|
13
|
+
import "../Interfaces.sol";
|
|
14
|
+
|
|
15
|
+
// import "hardhat/console.sol";
|
|
14
16
|
|
|
15
17
|
contract UBIPoolFactory is AccessControlUpgradeable, UUPSUpgradeable {
|
|
16
18
|
error NOT_PROJECT_OWNER();
|
|
@@ -20,7 +22,7 @@ contract UBIPoolFactory is AccessControlUpgradeable, UUPSUpgradeable {
|
|
|
20
22
|
address indexed pool,
|
|
21
23
|
string indexed projectId,
|
|
22
24
|
string ipfs,
|
|
23
|
-
|
|
25
|
+
PoolSettings poolSettings,
|
|
24
26
|
UBIPool.UBISettings poolLimits
|
|
25
27
|
);
|
|
26
28
|
|
|
@@ -84,31 +86,34 @@ contract UBIPoolFactory is AccessControlUpgradeable, UUPSUpgradeable {
|
|
|
84
86
|
function createManagedPool(
|
|
85
87
|
string memory _projectId,
|
|
86
88
|
string memory _ipfs,
|
|
87
|
-
|
|
88
|
-
UBIPool.UBISettings memory _limits
|
|
89
|
+
PoolSettings memory _settings,
|
|
90
|
+
UBIPool.UBISettings memory _limits,
|
|
91
|
+
UBIPool.ExtendedSettings memory _extendedSettings
|
|
89
92
|
) external onlyProjectOwnerOrNon(_projectId) returns (UBIPool pool) {
|
|
90
|
-
return _createPool(_projectId, _ipfs, _settings, _limits, true);
|
|
93
|
+
return _createPool(_projectId, _ipfs, _settings, _limits, _extendedSettings, true);
|
|
91
94
|
}
|
|
92
95
|
|
|
93
96
|
function createPool(
|
|
94
97
|
string memory _projectId,
|
|
95
98
|
string memory _ipfs,
|
|
96
|
-
|
|
97
|
-
UBIPool.UBISettings memory _limits
|
|
99
|
+
PoolSettings memory _settings,
|
|
100
|
+
UBIPool.UBISettings memory _limits,
|
|
101
|
+
UBIPool.ExtendedSettings memory _extendedSettings
|
|
98
102
|
) external onlyProjectOwnerOrNon(_projectId) returns (UBIPool pool) {
|
|
99
|
-
return _createPool(_projectId, _ipfs, _settings, _limits, false);
|
|
103
|
+
return _createPool(_projectId, _ipfs, _settings, _limits, _extendedSettings, false);
|
|
100
104
|
}
|
|
101
105
|
|
|
102
106
|
function _createPool(
|
|
103
107
|
string memory _projectId,
|
|
104
108
|
string memory _ipfs,
|
|
105
|
-
|
|
109
|
+
PoolSettings memory _settings,
|
|
106
110
|
UBIPool.UBISettings memory _limits,
|
|
111
|
+
UBIPool.ExtendedSettings memory _extendedSettings,
|
|
107
112
|
bool useBeacon
|
|
108
113
|
) internal returns (UBIPool pool) {
|
|
109
114
|
//TODO: add check if msg.sender is whitelisted
|
|
110
115
|
|
|
111
|
-
bytes memory initCall = abi.encodeCall(UBIPool.initialize, (_settings, _limits, this));
|
|
116
|
+
bytes memory initCall = abi.encodeCall(UBIPool.initialize, (_settings, _limits, _extendedSettings, this));
|
|
112
117
|
|
|
113
118
|
if (useBeacon) {
|
|
114
119
|
pool = UBIPool(address(new BeaconProxy(address(impl), initCall)));
|
|
@@ -10,6 +10,8 @@ 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;
|
|
@@ -81,14 +83,33 @@ library HelperLibrary {
|
|
|
81
83
|
function getRealtimeStats(
|
|
82
84
|
IGoodCollectiveSuperApp.Stats memory stats,
|
|
83
85
|
ISuperToken superToken
|
|
84
|
-
)
|
|
86
|
+
)
|
|
87
|
+
external
|
|
88
|
+
view
|
|
89
|
+
returns (
|
|
90
|
+
uint256 netIncome,
|
|
91
|
+
uint256 totalFees,
|
|
92
|
+
uint256 protocolFees,
|
|
93
|
+
uint256 managerFees,
|
|
94
|
+
int96 incomeFlowRate,
|
|
95
|
+
int96 feeRate,
|
|
96
|
+
int96 managerFeeRate
|
|
97
|
+
)
|
|
98
|
+
{
|
|
85
99
|
incomeFlowRate = stats.lastIncomeRate;
|
|
86
100
|
netIncome = stats.netIncome + uint96(stats.lastIncomeRate) * (block.timestamp - stats.lastUpdate);
|
|
87
101
|
feeRate = superToken.getFlowRate(address(this), stats.lastFeeRecipient);
|
|
88
|
-
|
|
89
|
-
|
|
102
|
+
managerFeeRate = superToken.getFlowRate(address(this), stats.lastManagerFeeRecipient);
|
|
103
|
+
|
|
104
|
+
protocolFees =
|
|
105
|
+
stats.protocolFees +
|
|
90
106
|
uint96(superToken.getFlowRate(address(this), stats.lastFeeRecipient)) *
|
|
91
107
|
(block.timestamp - stats.lastUpdate);
|
|
108
|
+
managerFees =
|
|
109
|
+
stats.managerFees +
|
|
110
|
+
uint96(superToken.getFlowRate(address(this), stats.lastManagerFeeRecipient)) *
|
|
111
|
+
(block.timestamp - stats.lastUpdate);
|
|
112
|
+
totalFees = protocolFees + managerFees;
|
|
92
113
|
}
|
|
93
114
|
|
|
94
115
|
// this should be called before any flow rate changes
|
|
@@ -96,54 +117,66 @@ library HelperLibrary {
|
|
|
96
117
|
IGoodCollectiveSuperApp.Stats storage stats,
|
|
97
118
|
ISuperToken superToken,
|
|
98
119
|
IRegistry registry,
|
|
120
|
+
uint32 managerFeeBps,
|
|
99
121
|
uint256 _amount
|
|
100
122
|
) external {
|
|
101
|
-
//use last rate before the current possible rate update
|
|
102
|
-
stats.netIncome += uint96(stats.lastIncomeRate) * (block.timestamp - stats.lastUpdate);
|
|
103
123
|
uint feeBps;
|
|
104
124
|
if (address(registry) != address(0)) {
|
|
105
125
|
feeBps = registry.feeBps();
|
|
126
|
+
}
|
|
127
|
+
//use last rate before the current possible rate update
|
|
128
|
+
stats.netIncome += uint96(stats.lastIncomeRate) * (block.timestamp - stats.lastUpdate);
|
|
129
|
+
if (stats.lastFeeRecipient != address(0)) {
|
|
106
130
|
//fees sent to last recipient, the flowRate to recipient still wasnt updated.
|
|
107
|
-
stats.
|
|
131
|
+
stats.protocolFees +=
|
|
108
132
|
uint96(superToken.getFlowRate(address(this), stats.lastFeeRecipient)) *
|
|
109
133
|
(block.timestamp - stats.lastUpdate);
|
|
110
134
|
}
|
|
135
|
+
if (stats.lastManagerFeeRecipient != address(0)) {
|
|
136
|
+
//fees sent to last recipient, the flowRate to recipient still wasnt updated.
|
|
137
|
+
stats.managerFees +=
|
|
138
|
+
uint96(superToken.getFlowRate(address(this), stats.lastManagerFeeRecipient)) *
|
|
139
|
+
(block.timestamp - stats.lastUpdate);
|
|
140
|
+
}
|
|
141
|
+
|
|
111
142
|
if (_amount > 0) {
|
|
112
|
-
stats.netIncome += (_amount * (10000 - feeBps)) / 10000;
|
|
113
|
-
stats.
|
|
143
|
+
stats.netIncome += (_amount * (10000 - feeBps - managerFeeBps)) / 10000;
|
|
144
|
+
stats.protocolFees += (_amount * feeBps) / 10000;
|
|
145
|
+
stats.managerFees += (_amount * managerFeeBps) / 10000;
|
|
114
146
|
}
|
|
147
|
+
stats.totalFees = stats.managerFees + stats.protocolFees;
|
|
115
148
|
stats.lastUpdate = block.timestamp;
|
|
116
149
|
}
|
|
117
150
|
|
|
118
151
|
function takeFeeFlow(
|
|
119
152
|
CFAv1Library.InitData storage cfaV1,
|
|
120
|
-
IGoodCollectiveSuperApp.Stats storage stats,
|
|
121
153
|
ISuperToken superToken,
|
|
122
|
-
|
|
154
|
+
address prevRecipient,
|
|
155
|
+
address recipient,
|
|
156
|
+
uint32 feeBps,
|
|
123
157
|
int96 _diffRate,
|
|
124
158
|
bytes memory _ctx
|
|
125
159
|
) public returns (bytes memory newCtx) {
|
|
126
160
|
newCtx = _ctx;
|
|
127
|
-
if (address(
|
|
128
|
-
|
|
129
|
-
int96 curFeeRate = superToken.getFlowRate(address(this), stats.lastFeeRecipient);
|
|
161
|
+
if (address(recipient) == address(0)) return newCtx;
|
|
162
|
+
int96 curFeeRate = superToken.getFlowRate(address(this), prevRecipient);
|
|
130
163
|
bool newRecipient;
|
|
131
|
-
if (recipient !=
|
|
164
|
+
if (recipient != prevRecipient) {
|
|
132
165
|
newRecipient = true;
|
|
133
|
-
if (
|
|
166
|
+
if (prevRecipient != address(0)) {
|
|
134
167
|
//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
|
|
168
|
+
if (curFeeRate > 0) newCtx = cfaV1.deleteFlowWithCtx(newCtx, address(this), prevRecipient, superToken); //passing in the ctx which is sent to the callback here
|
|
137
169
|
}
|
|
138
|
-
stats.lastFeeRecipient = recipient;
|
|
139
170
|
}
|
|
140
171
|
if (recipient == address(0)) return newCtx;
|
|
141
172
|
|
|
142
|
-
int96 newFeeRate = curFeeRate + (_diffRate * int32(
|
|
143
|
-
if (
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
173
|
+
int96 newFeeRate = curFeeRate + (_diffRate * int32(feeBps)) / 10000;
|
|
174
|
+
if (newRecipient == false && curFeeRate > 0) {
|
|
175
|
+
if (newFeeRate <= 0) {
|
|
176
|
+
newCtx = cfaV1.deleteFlowWithCtx(newCtx, address(this), recipient, superToken); //passing in the ctx which is sent to the callback here
|
|
177
|
+
} else {
|
|
178
|
+
newCtx = cfaV1.updateFlowWithCtx(newCtx, recipient, superToken, newFeeRate); //passing in the ctx which is sent to the callback here
|
|
179
|
+
}
|
|
147
180
|
} else if (newFeeRate > 0) newCtx = cfaV1.createFlowWithCtx(newCtx, recipient, superToken, newFeeRate); //passing in the ctx which is sent to the callback here
|
|
148
181
|
}
|
|
149
182
|
}
|