1
1
import consola from 'consola'
2
2
import yargs , { Argv } from 'yargs'
3
- import { constants , utils , Wallet , providers , BigNumber } from 'ethers'
3
+ import { constants , utils , Wallet } from 'ethers'
4
4
import { createAttestation , Attestation , Receipt } from '@graphprotocol/common-ts'
5
5
6
- import { sendTransaction } from '../../network'
6
+ import { sendTransaction , getChainID , getProvider , toGRT , randomHexBytes } from '../../network'
7
7
import { loadEnv , CLIArgs , CLIEnvironment } from '../../env'
8
8
9
9
const { HashZero } = constants
10
- const { defaultAbiCoder : abi , arrayify, concat, hexlify, randomBytes , parseUnits } = utils
10
+ const { defaultAbiCoder : abi , arrayify, concat, hexlify } = utils
11
11
12
12
interface ChannelKey {
13
13
privKey : string
@@ -16,16 +16,6 @@ interface ChannelKey {
16
16
}
17
17
18
18
const logger = consola . create ( { } )
19
- export const randomHexBytes = ( n = 32 ) : string => hexlify ( randomBytes ( n ) )
20
- export const toGRT = ( value : string | number ) : BigNumber => {
21
- return parseUnits ( typeof value === 'number' ? value . toString ( ) : value , '18' )
22
- }
23
- export const getProvider = ( providerUrl : string , network ?: number ) : providers . JsonRpcProvider =>
24
- new providers . JsonRpcProvider ( providerUrl , network )
25
-
26
- export const getChainID = ( ) : number => {
27
- return 4 // Only works for rinkeby right now
28
- }
29
19
30
20
async function buildAttestation ( receipt : Receipt , signer : string , disputeManagerAddress : string ) {
31
21
const attestation = await createAttestation ( signer , getChainID ( ) , disputeManagerAddress , receipt )
@@ -77,12 +67,12 @@ async function setupIndexer(
77
67
logger . log ( 'Staking...' )
78
68
await sendTransaction ( cli . wallet , staking , 'stake' , [ indexerTokens ] )
79
69
logger . log ( 'Allocating...' )
80
- await sendTransaction (
81
- cli . wallet ,
82
- staking ,
83
- 'allocate' ,
84
- [ receipt . subgraphDeploymentID , indexerAllocatedTokens , indexerChannelKey . address , metadata ] ,
85
- )
70
+ await sendTransaction ( cli . wallet , staking , 'allocate' , [
71
+ receipt . subgraphDeploymentID ,
72
+ indexerAllocatedTokens ,
73
+ indexerChannelKey . address ,
74
+ metadata ,
75
+ ] )
86
76
}
87
77
88
78
// This just creates any query dispute conflict to test the subgraph, no real data is sent
@@ -122,12 +112,10 @@ export const createTestQueryDisputeConflict = async (
122
112
)
123
113
124
114
logger . log ( `Creating conflicting attestations...` )
125
- await sendTransaction (
126
- cli . wallet ,
127
- disputeManager ,
128
- 'createQueryDisputeConflict' ,
129
- [ encodeAttestation ( attestation1 ) , encodeAttestation ( attestation2 ) ] ,
130
- )
115
+ await sendTransaction ( cli . wallet , disputeManager , 'createQueryDisputeConflict' , [
116
+ encodeAttestation ( attestation1 ) ,
117
+ encodeAttestation ( attestation2 ) ,
118
+ ] )
131
119
}
132
120
133
121
// This just creates any indexing dispute to test the subgraph, no real data is sent
@@ -156,12 +144,10 @@ export const createTestIndexingDispute = async (
156
144
await sendTransaction ( cli . wallet , grt , 'approve' , [ disputeManager . address , deposit ] )
157
145
158
146
logger . log ( `Creating indexing dispute...` )
159
- await sendTransaction (
160
- cli . wallet ,
161
- disputeManager ,
162
- 'createIndexingDispute' ,
163
- [ indexerChannelKey . address , deposit ] ,
164
- )
147
+ await sendTransaction ( cli . wallet , disputeManager , 'createIndexingDispute' , [
148
+ indexerChannelKey . address ,
149
+ deposit ,
150
+ ] )
165
151
}
166
152
167
153
export const accept = async ( cli : CLIEnvironment , cliArgs : CLIArgs ) : Promise < void > => {
0 commit comments