@@ -49,12 +49,14 @@ contract Staking is Governed {
4949 // Indexer stake tracking : indexer => Stake
5050 mapping (address => Stakes.Indexer) public stakes;
5151
52- // Channels : channelID => Channel
53- mapping (address => Channel) public channels;
54-
5552 // Rebate pools : epoch => Pool
5653 mapping (uint256 => Rebates.Pool) public rebates;
5754
55+ // Channels : channelID => Channel
56+ mapping (address => Channel) public channels;
57+ // Channels Proxy : Channel Multisig Proxy => channelID
58+ mapping (address => address ) public channelsProxy;
59+
5860 // List of addresses allowed to slash stakes
5961 mapping (address => bool ) public slashers;
6062
@@ -96,14 +98,16 @@ contract Staking is Governed {
9698 * during `epoch`.
9799 * `channelID` is the address of the indexer in the channel multisig.
98100 * `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`.
99102 */
100103 event AllocationCreated (
101104 address indexed indexer ,
102105 bytes32 indexed subgraphID ,
103106 uint256 epoch ,
104107 uint256 tokens ,
105108 address channelID ,
106- bytes channelPubKey
109+ bytes channelPubKey ,
110+ uint256 price
107111 );
108112
109113 /**
@@ -374,11 +378,15 @@ contract Staking is Governed {
374378 * @param _subgraphID ID of the subgraph where tokens will be allocated
375379 * @param _tokens Amount of tokens to allocate
376380 * @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`
377383 */
378384 function allocate (
379385 bytes32 _subgraphID ,
380386 uint256 _tokens ,
381- bytes calldata _channelPubKey
387+ bytes calldata _channelPubKey ,
388+ address _channelProxy ,
389+ uint256 _price
382390 ) external {
383391 address indexer = msg .sender ;
384392 Stakes.Indexer storage indexerStake = stakes[indexer];
@@ -406,35 +414,39 @@ contract Staking is Governed {
406414 alloc.channelID = channelID;
407415 alloc.createdAtEpoch = epochManager.currentEpoch ();
408416 channels[channelID] = Channel (indexer, _subgraphID);
417+ channelsProxy[_channelProxy] = channelID;
409418
410419 emit AllocationCreated (
411420 indexer,
412421 _subgraphID,
413422 alloc.createdAtEpoch,
414423 alloc.tokens,
415424 channelID,
416- _channelPubKey
425+ _channelPubKey,
426+ _price
417427 );
418428 }
419429
420430 /**
421431 * @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
423433 * @param _tokens Amount of tokens to settle
424434 */
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
427439
428440 // Receive funds from the channel multisig
429441 // 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 " );
431443
432444 // Transfer tokens to settle from multisig to this contract
433445 require (
434- token.transferFrom (channelMultisig , address (this ), _tokens),
446+ token.transferFrom (msg . sender , address (this ), _tokens),
435447 "Channel: Cannot transfer tokens to settle "
436448 );
437- _settle (_channelID, channelMultisig , _tokens);
449+ _settle (channelID, msg . sender , _tokens);
438450 }
439451
440452 /**
0 commit comments