@@ -10,6 +10,7 @@ import {
10
10
buildNetworkEndpoint ,
11
11
} from './helpers'
12
12
import { ConnectedStaking , ConnectedGraphToken } from './connectedContracts'
13
+ import { utils , BigNumber } from 'ethers'
13
14
14
15
const {
15
16
network,
@@ -19,6 +20,10 @@ const {
19
20
channelPubKey,
20
21
channelProxy,
21
22
price,
23
+ channelID,
24
+ restake,
25
+ indexer,
26
+ newIndexer,
22
27
} = minimist . default ( process . argv . slice ( 2 ) , {
23
28
string : [
24
29
'network' ,
@@ -28,6 +33,10 @@ const {
28
33
'channelPubKey' ,
29
34
'channelProxy' ,
30
35
'price' ,
36
+ 'channelID' ,
37
+ 'restake' ,
38
+ 'indexer' ,
39
+ 'newIndexer' ,
31
40
] ,
32
41
} )
33
42
@@ -37,7 +46,8 @@ if (!network || !func) {
37
46
Usage: ${ path . basename ( process . argv [ 1 ] ) }
38
47
--network <string> - options: ganache, kovan, rinkeby
39
48
40
- --func <text> - options: stake, unstake, withdraw, allocate, settle
49
+ --func <text> - options: stake, unstake, withdraw, allocate, settle, collect, claim, delegate
50
+ undelegate, withdrawDelegated
41
51
42
52
Function arguments:
43
53
stake
@@ -52,12 +62,33 @@ Usage: ${path.basename(process.argv[1])}
52
62
allocate
53
63
--subgraphDeploymentID <bytes32> - The subgraph deployment ID being allocated on
54
64
--amount <number> - Amount of tokens being allocated (script adds 10^18)
55
- --channelPubKey <bytes> - The subgraph deployment ID being allocated on
56
- --channelProxy <address> - The subgraph deployment ID being allocated on
65
+ --channelPubKey <bytes> - The public key used by the indexer to setup the off-chain channel
66
+ --channelProxy <address> - Address of the multisig proxy used to hold channel funds
57
67
--price <number> - Price the indexer will charge for serving queries of the subgraphID
58
68
59
- settle (Note - settle must be called by the channelProxy that created the allocation)
60
- --amount <number> - Amount of tokens being settled (script adds 10^18)
69
+ settle (note - must pass at least one epoch)
70
+ --channelID <number> - Channel being settled
71
+
72
+ collect (Note - collect must be called by the channelProxy)
73
+ --channelID - ID of the channel we are collecting funds from
74
+ --from - Multisig channel address that triggered the withdrawal
75
+ --amount - Token amount to withdraw
76
+
77
+ claim (note - you must have settled the channel already)
78
+ --channelID - ID of the channel we are claiming funds from
79
+ --restake - True if you are restaking the fees, rather than withdrawing
80
+
81
+ delegate
82
+ --indexer - Indexer being delegated to
83
+ --amount - Amount of tokens being delegated (automatically adds 10^18)
84
+
85
+ undelegate
86
+ --indexer - Indexer being delegated to
87
+ --amount - Amount of shares being undelegated
88
+
89
+ withdrawDelegated
90
+ --indexer - Indexer being withdrawn from
91
+ --newIndexer - Indexer being delegated to
61
92
` ,
62
93
)
63
94
process . exit ( 1 )
@@ -79,7 +110,7 @@ const main = async () => {
79
110
80
111
try {
81
112
if ( func == 'stake' ) {
82
- checkFuncInputs ( [ amount ] , [ 'amount' ] , 'stake' )
113
+ checkFuncInputs ( [ amount ] , [ 'amount' ] , func )
83
114
console . log ( ' First calling approve() to ensure staking contract can call transferFrom()...' )
84
115
await executeTransaction (
85
116
connectedGT . approveWithDecimals ( staking . contract . address , amount ) ,
@@ -88,30 +119,66 @@ const main = async () => {
88
119
console . log ( `Staking ${ amount } tokens in the staking contract...` )
89
120
await executeTransaction ( staking . stakeWithDecimals ( amount ) , network )
90
121
} else if ( func == 'unstake' ) {
91
- checkFuncInputs ( [ amount ] , [ 'amount' ] , 'unstake' )
122
+ checkFuncInputs ( [ amount ] , [ 'amount' ] , func )
92
123
console . log ( `Unstaking ${ amount } tokens. Tokens will be locked...` )
93
124
await executeTransaction ( staking . unstakeWithDecimals ( amount ) , network )
94
125
} else if ( func == 'withdraw' ) {
95
126
console . log ( `Unlock tokens and withdraw them from the staking contract...` )
96
127
await executeTransaction ( staking . contract . withdraw ( ) , network )
97
128
} else if ( func == 'allocate' ) {
98
- checkFuncInputs ( [ amount , price ] , [ 'amount' , 'price' ] , 'allocate' )
129
+ checkFuncInputs ( [ amount , price ] , [ 'amount' , 'price' ] , func )
99
130
console . log ( `Allocating ${ amount } tokens on state channel ${ subgraphDeploymentID } ...` )
100
131
await executeTransaction (
101
132
staking . allocateWithDecimals (
102
- amount ,
103
- price ,
104
133
subgraphDeploymentID ,
134
+ amount ,
105
135
channelPubKey ,
106
136
channelProxy ,
137
+ price ,
107
138
) ,
108
139
network ,
109
140
)
110
141
} else if ( func == 'settle' ) {
111
- // Note - this function must be called by the channel proxy eth address
112
- checkFuncInputs ( [ amount ] , [ 'amount' ] , 'settle' )
113
- console . log ( `Settling ${ amount } tokens on state channel with proxy address TODO` )
114
- await executeTransaction ( staking . settleWithDecimals ( amount ) , network )
142
+ checkFuncInputs ( [ channelID ] , [ 'channelID' ] , func )
143
+ console . log ( `Settling channel: ${ channelID } ...` )
144
+ await executeTransaction ( staking . contract . settle ( channelID ) , network )
145
+ } else if ( func == 'collect' ) {
146
+ console . log ( 'COLLECT NOT IMPLEMENTED. NORMALLY CALLED FROM PROXY ACCOUNT' )
147
+ process . exit ( 1 )
148
+ } else if ( func == 'claim' ) {
149
+ checkFuncInputs ( [ channelID , restake ] , [ 'channelID' , 'restake' ] , func )
150
+ console . log ( `Claiming channel: ${ channelID } ...` )
151
+ await executeTransaction ( staking . contract . claim ( channelID , restake ) , network )
152
+ } else if ( func == 'delegate' ) {
153
+ checkFuncInputs ( [ amount , indexer ] , [ 'amount' , 'indexer' ] , func )
154
+ console . log ( ' First calling approve() to ensure staking contract can call transferFrom()...' )
155
+ await executeTransaction (
156
+ connectedGT . approveWithDecimals ( staking . contract . address , amount ) ,
157
+ network ,
158
+ )
159
+ console . log ( `Delegating ${ amount } tokens to indexer: ${ indexer } ...` )
160
+ const amountParseDecimals = utils . parseUnits ( amount as string , 18 )
161
+ await executeTransaction ( staking . contract . delegate ( indexer , amountParseDecimals ) , network )
162
+ } else if ( func == 'undelegate' ) {
163
+ checkFuncInputs ( [ amount , indexer ] , [ 'amount' , 'indexer' ] , func )
164
+ console . log ( `Undelegating ${ amount } shares from indexer: ${ indexer } ...` )
165
+ const amountParseDecimals = utils . parseUnits ( amount as string , 18 )
166
+ await executeTransaction ( staking . contract . undelegate ( indexer , amountParseDecimals ) , network )
167
+ } else if ( func == 'withdrawDelegated' ) {
168
+ checkFuncInputs ( [ newIndexer , indexer ] , [ 'newIndexer' , 'indexer' ] , func )
169
+ console . log ( `Withdrawing from ${ indexer } ` )
170
+ if ( newIndexer != '0x0000000000000000000000000000000000000000' ) {
171
+ console . log ( `Depositing to : ${ newIndexer } ...` )
172
+ }
173
+ await executeTransaction ( staking . contract . withdrawDelegated ( indexer , newIndexer ) , network )
174
+ } else if ( func == 'getDelegationShares' ) {
175
+ checkFuncInputs ( [ indexer ] , [ 'indexer' ] , func )
176
+ console . log ( `Getting delegation shares....` )
177
+ const shares = await staking . contract . getDelegationShares (
178
+ indexer ,
179
+ staking . configuredWallet . address ,
180
+ )
181
+ console . log ( shares . div ( BigNumber . from ( '1000000000000000000' ) ) . toString ( ) )
115
182
} else {
116
183
console . log ( `Wrong func name provided` )
117
184
process . exit ( 1 )
0 commit comments