@@ -49,12 +49,14 @@ contract Staking is Governed {
49
49
// Indexer stake tracking : indexer => Stake
50
50
mapping (address => Stakes.Indexer) public stakes;
51
51
52
- // Channels : channelID => Channel
53
- mapping (address => Channel) public channels;
54
-
55
52
// Rebate pools : epoch => Pool
56
53
mapping (uint256 => Rebates.Pool) public rebates;
57
54
55
+ // Channels : channelID => Channel
56
+ mapping (address => Channel) public channels;
57
+ // Channels Proxy : Channel Multisig Proxy => channelID
58
+ mapping (address => address ) public channelsProxy;
59
+
58
60
// List of addresses allowed to slash stakes
59
61
mapping (address => bool ) public slashers;
60
62
@@ -96,14 +98,16 @@ contract Staking is Governed {
96
98
* during `epoch`.
97
99
* `channelID` is the address of the indexer in the channel multisig.
98
100
* `channelPubKey` is the public key used for routing payments to the indexer channel.
101
+ * `price` price the `indexer` will charge for serving queries of the `subgraphID`.
99
102
*/
100
103
event AllocationCreated (
101
104
address indexed indexer ,
102
105
bytes32 indexed subgraphID ,
103
106
uint256 epoch ,
104
107
uint256 tokens ,
105
108
address channelID ,
106
- bytes channelPubKey
109
+ bytes channelPubKey ,
110
+ uint256 price
107
111
);
108
112
109
113
/**
@@ -374,11 +378,15 @@ contract Staking is Governed {
374
378
* @param _subgraphID ID of the subgraph where tokens will be allocated
375
379
* @param _tokens Amount of tokens to allocate
376
380
* @param _channelPubKey The public key used by the indexer to setup the off-chain channel
381
+ * @param _channelProxy Address of the multisig proxy used to hold channel funds
382
+ * @param _price Price the `indexer` will charge for serving queries of the `subgraphID`
377
383
*/
378
384
function allocate (
379
385
bytes32 _subgraphID ,
380
386
uint256 _tokens ,
381
- bytes calldata _channelPubKey
387
+ bytes calldata _channelPubKey ,
388
+ address _channelProxy ,
389
+ uint256 _price
382
390
) external {
383
391
address indexer = msg .sender ;
384
392
Stakes.Indexer storage indexerStake = stakes[indexer];
@@ -406,35 +414,39 @@ contract Staking is Governed {
406
414
alloc.channelID = channelID;
407
415
alloc.createdAtEpoch = epochManager.currentEpoch ();
408
416
channels[channelID] = Channel (indexer, _subgraphID);
417
+ channelsProxy[_channelProxy] = channelID;
409
418
410
419
emit AllocationCreated (
411
420
indexer,
412
421
_subgraphID,
413
422
alloc.createdAtEpoch,
414
423
alloc.tokens,
415
424
channelID,
416
- _channelPubKey
425
+ _channelPubKey,
426
+ _price
417
427
);
418
428
}
419
429
420
430
/**
421
431
* @dev Settle a channel after receiving collected query fees from it
422
- * @param _channelID Address of the indexer in the channel
432
+ * Funds are received from a channel multisig proxy contract
423
433
* @param _tokens Amount of tokens to settle
424
434
*/
425
- function settle (address _channelID , uint256 _tokens ) external {
426
- address channelMultisig = msg .sender ;
435
+ function settle (uint256 _tokens ) external {
436
+ // Get the channelID the caller is related
437
+ address channelID = channelsProxy[msg .sender ];
438
+ delete channelsProxy[msg .sender ]; // Remove to avoid re-entrancy
427
439
428
440
// Receive funds from the channel multisig
429
441
// We use channelID to find the indexer owner of the channel
430
- require (isChannel (_channelID ), "Channel: does not exist " );
442
+ require (isChannel (channelID ), "Channel: does not exist " );
431
443
432
444
// Transfer tokens to settle from multisig to this contract
433
445
require (
434
- token.transferFrom (channelMultisig , address (this ), _tokens),
446
+ token.transferFrom (msg . sender , address (this ), _tokens),
435
447
"Channel: Cannot transfer tokens to settle "
436
448
);
437
- _settle (_channelID, channelMultisig , _tokens);
449
+ _settle (channelID, msg . sender , _tokens);
438
450
}
439
451
440
452
/**
0 commit comments