-
Notifications
You must be signed in to change notification settings - Fork 261
Expand file tree
/
Copy pathGDAv1Forwarder.sol
More file actions
243 lines (219 loc) · 9.31 KB
/
GDAv1Forwarder.sol
File metadata and controls
243 lines (219 loc) · 9.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
// SPDX-License-Identifier: AGPLv3
pragma solidity ^0.8.23;
import { ISuperfluid, ISuperfluidToken } from "../interfaces/superfluid/ISuperfluid.sol";
import { ISuperfluidPool } from "../agreements/gdav1/SuperfluidPool.sol";
import {
IGeneralDistributionAgreementV1,
PoolConfig
} from "../interfaces/agreements/gdav1/IGeneralDistributionAgreementV1.sol";
import { ForwarderBase } from "./ForwarderBase.sol";
/**
* @title GDAv1Forwarder
* @author Superfluid
* The GDAv1Forwarder contract provides an easy to use interface to
* GeneralDistributionAgreementV1 specific functionality of Super Tokens.
* Instances of this contract can operate on the protocol only if configured as "trusted forwarder"
* by protocol governance.
*/
contract GDAv1Forwarder is ForwarderBase {
IGeneralDistributionAgreementV1 internal immutable _gda;
// is tied to a specific instance of host and agreement contracts at deploy time
constructor(ISuperfluid host) ForwarderBase(host) {
_gda = IGeneralDistributionAgreementV1(
address(
_host.getAgreementClass(keccak256("org.superfluid-finance.agreements.GeneralDistributionAgreement.v1"))
)
);
}
/**
* @dev Creates a new Superfluid Pool.
* @param token The Super Token address.
* @param admin The pool admin address.
* @param config The pool configuration (see PoolConfig in IGeneralDistributionAgreementV1.sol)
* @return success A boolean value indicating whether the pool was created successfully.
* @return pool The address of the deployed Superfluid Pool
*/
function createPool(ISuperfluidToken token, address admin, PoolConfig memory config)
external
returns (bool success, ISuperfluidPool pool)
{
pool = _gda.createPool(token, admin, config);
success = true;
}
/**
* @dev Updates the units of a pool member.
* @param pool The Superfluid Pool to update.
* @param memberAddress The address of the member to update.
* @param newUnits The new units of the member.
* @param userData User-specific data.
*/
function updateMemberUnits(ISuperfluidPool pool, address memberAddress, uint128 newUnits, bytes memory userData)
external
returns (bool success)
{
bytes memory callData = abi.encodeCall(_gda.updateMemberUnits, (pool, memberAddress, newUnits, new bytes(0)));
return _forwardBatchCall(address(_gda), callData, userData);
}
/**
* @dev Claims all tokens from the pool.
* @param pool The Superfluid Pool to claim from.
* @param memberAddress The address of the member to claim for.
* @param userData User-specific data.
*/
function claimAll(ISuperfluidPool pool, address memberAddress, bytes memory userData)
external
returns (bool success)
{
bytes memory callData = abi.encodeCall(_gda.claimAll, (pool, memberAddress, new bytes(0)));
return _forwardBatchCall(address(_gda), callData, userData);
}
/**
* @dev Connects a pool member to `pool`.
* @param pool The Superfluid Pool to connect.
* @param userData User-specific data.
* @return A boolean value indicating whether the connection was successful.
*/
function connectPool(ISuperfluidPool pool, bytes memory userData) external returns (bool) {
bytes memory callData = abi.encodeCall(_gda.connectPool, (pool, new bytes(0)));
return _forwardBatchCall(address(_gda), callData, userData);
}
/**
* @dev Disconnects a pool member from `pool`.
* @param pool The Superfluid Pool to disconnect.
* @param userData User-specific data.
* @return A boolean value indicating whether the disconnection was successful.
*/
function disconnectPool(ISuperfluidPool pool, bytes memory userData) external returns (bool) {
bytes memory callData = abi.encodeCall(_gda.disconnectPool, (pool, new bytes(0)));
return _forwardBatchCall(address(_gda), callData, userData);
}
/**
* @dev Tries to distribute `requestedAmount` amount of `token` from `from` to `pool`.
* @param token The Super Token address.
* @param from The address from which to distribute tokens.
* @param pool The Superfluid Pool address.
* @param requestedAmount The amount of tokens to distribute.
* @param userData User-specific data.
* @return A boolean value indicating whether the distribution was successful.
*/
function distribute(
ISuperfluidToken token,
address from,
ISuperfluidPool pool,
uint256 requestedAmount,
bytes memory userData
) external returns (bool) {
bytes memory callData = abi.encodeCall(_gda.distribute, (token, from, pool, requestedAmount, new bytes(0)));
return _forwardBatchCall(address(_gda), callData, userData);
}
/**
* @dev Tries to distribute flow at `requestedFlowRate` of `token` from `from` to `pool`.
* @param token The Super Token address.
* @param from The address from which to distribute tokens.
* @param pool The Superfluid Pool address.
* @param requestedFlowRate The flow rate of tokens to distribute.
* @param userData User-specific data.
* @return A boolean value indicating whether the distribution was successful.
*/
function distributeFlow(
ISuperfluidToken token,
address from,
ISuperfluidPool pool,
int96 requestedFlowRate,
bytes memory userData
) external returns (bool) {
bytes memory callData =
abi.encodeCall(_gda.distributeFlow, (token, from, pool, requestedFlowRate, new bytes(0)));
return _forwardBatchCall(address(_gda), callData, userData);
}
/**
* @dev Checks if the specified account is a pool.
* @param token The Super Token address.
* @param account The account address to check.
* @return A boolean value indicating whether the account is a pool.
*/
function isPool(ISuperfluidToken token, address account) external view virtual returns (bool) {
return _gda.isPool(token, account);
}
/**
* @dev Gets the GDA net flow rate for the specified account.
* @param token The Super Token address.
* @param account The account address.
* @return The gda net flow rate for the account.
*/
function getNetFlow(ISuperfluidToken token, address account) external view returns (int96) {
return _gda.getNetFlow(token, account);
}
/**
* @dev Gets the flow rate of tokens between the specified accounts.
* @param token The Super Token address.
* @param from The sender address.
* @param to The receiver address (the pool address).
* @return The flow distribution flow rate
*/
function getFlowDistributionFlowRate(ISuperfluidToken token, address from, ISuperfluidPool to)
external
view
returns (int96)
{
return _gda.getFlowRate(token, from, to);
}
/**
* @dev Gets the pool adjustment flow rate for the specified pool.
* @param pool The pool address.
* @return The pool adjustment flow rate.
*/
function getPoolAdjustmentFlowRate(address pool) external view virtual returns (int96) {
return _gda.getPoolAdjustmentFlowRate(pool);
}
/**
* @dev Estimates the actual flow rate for flow distribution to the specified pool.
* @param token The Super Token address.
* @param from The sender address.
* @param to The pool address.
* @param requestedFlowRate The requested flow rate.
* @return actualFlowRate
* @return totalDistributionFlowRate
*/
function estimateFlowDistributionActualFlowRate(
ISuperfluidToken token,
address from,
ISuperfluidPool to,
int96 requestedFlowRate
) external view returns (int96 actualFlowRate, int96 totalDistributionFlowRate) {
return _gda.estimateFlowDistributionActualFlowRate(token, from, to, requestedFlowRate);
}
/**
* @dev Estimates the actual amount for distribution to the specified pool.
* @param token The Super Token address.
* @param from The sender address.
* @param to The pool address.
* @param requestedAmount The requested amount.
* @return actualAmount The actual amount for distribution.
*/
function estimateDistributionActualAmount(
ISuperfluidToken token,
address from,
ISuperfluidPool to,
uint256 requestedAmount
) external view returns (uint256 actualAmount) {
return _gda.estimateDistributionActualAmount(token, from, to, requestedAmount);
}
/**
* @dev Checks if the specified member is connected to the pool.
* @param pool The Superfluid Pool address.
* @param member The member address.
* @return A boolean value indicating whether the member is connected to the pool.
*/
function isMemberConnected(ISuperfluidPool pool, address member) external view returns (bool) {
return _gda.isMemberConnected(pool, member);
}
/**
* @dev Gets the pool adjustment flow information for the specified pool.
* @param pool The pool address.
* @return The pool admin, pool ID, and pool adjustment flow rate.
*/
function getPoolAdjustmentFlowInfo(ISuperfluidPool pool) external view virtual returns (address, bytes32, int96) {
return _gda.getPoolAdjustmentFlowInfo(pool);
}
}