@@ -28,16 +28,19 @@ import { IL2Curation } from "../curation/IL2Curation.sol";
28
28
contract L2GNS is GNS , L2GNSV1Storage , IL2GNS {
29
29
using SafeMathUpgradeable for uint256 ;
30
30
31
- /// The amount of time (in blocks) that a subgraph owner has to finish the migration
32
- /// from L1 before the subgraph can be deprecated: 1 week
33
- uint256 public constant FINISH_MIGRATION_TIMEOUT = 50400 ;
34
-
35
31
/// @dev Emitted when a subgraph is received from L1 through the bridge
36
32
event SubgraphReceivedFromL1 (uint256 _subgraphID );
37
33
/// @dev Emitted when a subgraph migration from L1 is finalized, so the subgraph is published
38
34
event SubgraphMigrationFinalized (uint256 _subgraphID );
39
35
/// @dev Emitted when the L1 balance for a curator has been claimed
40
36
event CuratorBalanceReceived (uint256 _subgraphID , address _l2Curator , uint256 _tokens );
37
+ /// @dev Emitted when the L1 balance for a curator has been returned to the beneficiary.
38
+ /// This can happen if the subgraph migration was not finished when the curator's tokens arrived.
39
+ event CuratorBalanceReturnedToBeneficiary (
40
+ uint256 _subgraphID ,
41
+ address _l2Curator ,
42
+ uint256 _tokens
43
+ );
41
44
42
45
/**
43
46
* @dev Checks that the sender is the L2GraphTokenGateway as configured on the Controller.
@@ -63,18 +66,15 @@ contract L2GNS is GNS, L2GNSV1Storage, IL2GNS {
63
66
(uint8 code , bytes memory functionData ) = abi.decode (_data, (uint8 , bytes ));
64
67
65
68
if (code == uint8 (L1MessageCodes.RECEIVE_SUBGRAPH_CODE)) {
66
- (uint256 subgraphID , address subgraphOwner , uint256 nSignal ) = abi.decode (
69
+ (uint256 subgraphID , address subgraphOwner ) = abi.decode (
67
70
functionData,
68
- (uint256 , address , uint256 )
71
+ (uint256 , address )
69
72
);
70
73
71
- _receiveSubgraphFromL1 (subgraphID, subgraphOwner, _amount, nSignal );
74
+ _receiveSubgraphFromL1 (subgraphID, subgraphOwner, _amount);
72
75
} else if (code == uint8 (L1MessageCodes.RECEIVE_CURATOR_BALANCE_CODE)) {
73
- (uint256 subgraphID , address l2Curator , uint256 tokens ) = abi.decode (
74
- functionData,
75
- (uint256 , address , uint256 )
76
- );
77
- _mintSignalFromL1 (subgraphID, l2Curator, tokens);
76
+ (uint256 subgraphID , address l2Curator ) = abi.decode (functionData, (uint256 , address ));
77
+ _mintSignalFromL1 (subgraphID, l2Curator, _amount);
78
78
} else {
79
79
revert ("INVALID_CODE " );
80
80
}
@@ -108,9 +108,14 @@ contract L2GNS is GNS, L2GNSV1Storage, IL2GNS {
108
108
IL2Curation curation = IL2Curation (address (curation ()));
109
109
// Update pool: constant nSignal, vSignal can change (w/no slippage protection)
110
110
// Buy all signal from the new deployment
111
- subgraphData. vSignal = curation.mintTaxFree (_subgraphDeploymentID, migratedData.tokens, 0 );
112
- subgraphData.disabled = false ;
111
+ uint256 vSignal = curation.mintTaxFree (_subgraphDeploymentID, migratedData.tokens);
112
+ uint256 nSignal = vSignalToNSignal (_subgraphID, vSignal) ;
113
113
114
+ subgraphData.disabled = false ;
115
+ subgraphData.vSignal = vSignal;
116
+ subgraphData.nSignal = nSignal;
117
+ subgraphData.curatorNSignal[msg .sender ] = nSignal;
118
+ subgraphData.subgraphDeploymentID = _subgraphDeploymentID;
114
119
// Set the token metadata
115
120
_setSubgraphMetadata (_subgraphID, _subgraphMetadata);
116
121
@@ -121,41 +126,10 @@ contract L2GNS is GNS, L2GNSV1Storage, IL2GNS {
121
126
migratedData.tokens,
122
127
_subgraphDeploymentID
123
128
);
124
- // Update target deployment
125
- subgraphData.subgraphDeploymentID = _subgraphDeploymentID;
126
129
emit SubgraphVersionUpdated (_subgraphID, _subgraphDeploymentID, _versionMetadata);
127
130
emit SubgraphMigrationFinalized (_subgraphID);
128
131
}
129
132
130
- /**
131
- * @notice Deprecate a subgraph that was migrated from L1, but for which
132
- * the migration was never finished. Anyone can call this function after 50400 blocks
133
- * (one day) have passed since the subgraph was migrated, if the subgraph owner didn't
134
- * call finishSubgraphMigrationFromL1.
135
- * @param _subgraphID Subgraph ID
136
- */
137
- function deprecateSubgraphMigratedFromL1 (uint256 _subgraphID )
138
- external
139
- override
140
- notPartialPaused
141
- {
142
- IGNS.SubgraphL2MigrationData storage migratedData = subgraphL2MigrationData[_subgraphID];
143
- require (migratedData.subgraphReceivedOnL2BlockNumber != 0 , "INVALID_SUBGRAPH " );
144
- require (! migratedData.l2Done, "ALREADY_FINISHED " );
145
- require (
146
- block .number > migratedData.subgraphReceivedOnL2BlockNumber + FINISH_MIGRATION_TIMEOUT,
147
- "TOO_EARLY "
148
- );
149
- SubgraphData storage subgraphData = _getSubgraphData (_subgraphID);
150
-
151
- migratedData.l2Done = true ;
152
- uint256 withdrawableGRT = migratedData.tokens;
153
- subgraphData.withdrawableGRT = withdrawableGRT;
154
- subgraphData.reserveRatio = 0 ;
155
- _burnNFT (_subgraphID);
156
- emit SubgraphDeprecated (_subgraphID, withdrawableGRT);
157
- }
158
-
159
133
/**
160
134
* @notice Publish a new version of an existing subgraph.
161
135
* @dev This is the same as the one in the base GNS, but skips the check for
@@ -234,21 +208,18 @@ contract L2GNS is GNS, L2GNSV1Storage, IL2GNS {
234
208
* @param _subgraphID Subgraph ID
235
209
* @param _subgraphOwner Owner of the subgraph
236
210
* @param _tokens Tokens to be deposited in the subgraph
237
- * @param _nSignal Name signal for the subgraph in L1
238
211
*/
239
212
function _receiveSubgraphFromL1 (
240
213
uint256 _subgraphID ,
241
214
address _subgraphOwner ,
242
- uint256 _tokens ,
243
- uint256 _nSignal
215
+ uint256 _tokens
244
216
) internal {
245
217
IGNS.SubgraphL2MigrationData storage migratedData = subgraphL2MigrationData[_subgraphID];
246
218
SubgraphData storage subgraphData = _getSubgraphData (_subgraphID);
247
219
248
220
subgraphData.reserveRatio = fixedReserveRatio;
249
221
// The subgraph will be disabled until finishSubgraphMigrationFromL1 is called
250
222
subgraphData.disabled = true ;
251
- subgraphData.nSignal = _nSignal;
252
223
253
224
migratedData.tokens = _tokens;
254
225
migratedData.subgraphReceivedOnL2BlockNumber = block .number ;
@@ -262,6 +233,7 @@ contract L2GNS is GNS, L2GNSV1Storage, IL2GNS {
262
233
263
234
/**
264
235
* @notice Deposit GRT into a subgraph and mint signal, using tokens received from L1.
236
+ * If the subgraph migration was never finished, the tokens will be sent to the curator.
265
237
* @dev This looks a lot like GNS.mintSignal, but doesn't pull the tokens from the
266
238
* curator and has no slippage protection.
267
239
* @param _subgraphID Subgraph ID
@@ -273,21 +245,29 @@ contract L2GNS is GNS, L2GNSV1Storage, IL2GNS {
273
245
address _curator ,
274
246
uint256 _tokensIn
275
247
) internal {
276
- // Subgraph checks
277
- SubgraphData storage subgraphData = _getSubgraphOrRevert (_subgraphID);
278
-
279
- // Get name signal to mint for tokens deposited
280
- IL2Curation curation = IL2Curation (address (curation ()));
281
- uint256 vSignal = curation.mintTaxFree (subgraphData.subgraphDeploymentID, _tokensIn, 0 );
282
- uint256 nSignal = vSignalToNSignal (_subgraphID, vSignal);
248
+ IGNS.SubgraphL2MigrationData storage migratedData = subgraphL2MigrationData[_subgraphID];
283
249
284
- // Update pools
285
- subgraphData.vSignal = subgraphData.vSignal.add (vSignal);
286
- subgraphData.nSignal = subgraphData.nSignal.add (nSignal);
287
- subgraphData.curatorNSignal[_curator] = subgraphData.curatorNSignal[_curator].add (nSignal);
250
+ // If subgraph migration wasn't finished, we should send the tokens to the curator
251
+ if (! migratedData.l2Done) {
252
+ graphToken ().transfer (_curator, _tokensIn);
253
+ emit CuratorBalanceReturnedToBeneficiary (_subgraphID, _curator, _tokensIn);
254
+ } else {
255
+ SubgraphData storage subgraphData = _getSubgraphData (_subgraphID);
256
+ // Get name signal to mint for tokens deposited
257
+ IL2Curation curation = IL2Curation (address (curation ()));
258
+ uint256 vSignal = curation.mintTaxFree (subgraphData.subgraphDeploymentID, _tokensIn);
259
+ uint256 nSignal = vSignalToNSignal (_subgraphID, vSignal);
260
+
261
+ // Update pools
262
+ subgraphData.vSignal = subgraphData.vSignal.add (vSignal);
263
+ subgraphData.nSignal = subgraphData.nSignal.add (nSignal);
264
+ subgraphData.curatorNSignal[_curator] = subgraphData.curatorNSignal[_curator].add (
265
+ nSignal
266
+ );
288
267
289
- emit SignalMinted (_subgraphID, _curator, nSignal, vSignal, _tokensIn);
290
- emit CuratorBalanceReceived (_subgraphID, _curator, _tokensIn);
268
+ emit SignalMinted (_subgraphID, _curator, nSignal, vSignal, _tokensIn);
269
+ emit CuratorBalanceReceived (_subgraphID, _curator, _tokensIn);
270
+ }
291
271
}
292
272
293
273
/**
0 commit comments