Skip to content

Commit

Permalink
*: Apply prettier and lint suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
fordN authored and juanmardefago committed Dec 2, 2021
1 parent 44dfaad commit 39f5c02
Show file tree
Hide file tree
Showing 15 changed files with 97 additions and 118 deletions.
3 changes: 2 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
build/
node_modules/
src/types
src/types
generated/
2 changes: 1 addition & 1 deletion config/addresses.template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@ export let addresses: Addresses = {
ensPublicResolver: '{{ensPublicResolver}}',
blockNumber: '{{blockNumber}}',
network: '{{network}}',
tokenLockManager: '{{tokenLockManager}}}'
tokenLockManager: '{{tokenLockManager}}}',
}
5 changes: 3 additions & 2 deletions config/mainnetAddressScript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import * as networkAddresses from '@graphprotocol/contracts/addresses.json'
import { Addresses } from './addresses.template'

// mustache doesn't like numbered object keys
// eslint-disable-next-line @typescript-eslint/no-explicit-any
let renameAddresses: any = networkAddresses
renameAddresses['mainnet'] = networkAddresses['1']

Expand All @@ -21,15 +22,15 @@ export let addresses: Addresses = {
ensPublicResolver: '{{mainnet.IPublicResolver}}',
blockNumber: '',
network: '',
tokenLockManager: ''
tokenLockManager: '',
}

const main = (): void => {
try {
let output = JSON.parse(mustache.render(JSON.stringify(addresses), renameAddresses))
output.blockNumber = '11440000' // Hardcoded a few thousand blocks before 1st contract deployed
output.network = 'mainnet'
output.tokenLockManager = "0xFCf78AC094288D7200cfdB367A8CD07108dFa128"
output.tokenLockManager = '0xFCf78AC094288D7200cfdB367A8CD07108dFa128'
fs.writeFileSync(__dirname + '/generatedAddresses.json', JSON.stringify(output, null, 2))
} catch (e) {
console.log(`Error saving artifacts: ${e.message}`)
Expand Down
1 change: 1 addition & 0 deletions config/rinkebyAddressScript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import * as networkAddresses from '@graphprotocol/contracts/addresses.json'
import { Addresses } from './addresses.template'

// mustache doesn't like numbered object keys
// eslint-disable-next-line @typescript-eslint/no-explicit-any
let renameAddresses: any = networkAddresses
renameAddresses['rinkeby'] = networkAddresses['4']

Expand Down
10 changes: 2 additions & 8 deletions src/mappings/curation.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
import {
Signalled,
Burned,
Collected,
Curation,
ParameterUpdated,
} from '../types/Curation/Curation'
import { Signalled, Burned, Curation, ParameterUpdated } from '../types/Curation/Curation'
import {
Curator,
GraphNetwork,
Signal,
SubgraphDeployment,
SignalTransaction,
} from '../types/schema'
import { Address, BigInt } from '@graphprotocol/graph-ts'
import { BigInt } from '@graphprotocol/graph-ts'

import {
createOrLoadSignal,
Expand Down
9 changes: 1 addition & 8 deletions src/mappings/disputeManager.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
import { Address, BigDecimal, BigInt, ByteArray } from '@graphprotocol/graph-ts'
import {
Indexer,
Allocation,
GraphNetwork,
SubgraphDeployment,
Dispute,
Attestation,
} from '../types/schema'
import { Allocation, GraphNetwork, Dispute, Attestation } from '../types/schema'
import {
ParameterUpdated,
QueryDisputeCreated,
Expand Down
1 change: 0 additions & 1 deletion src/mappings/epochManager.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { GraphNetwork } from '../types/schema'
import { EpochRun, EpochLengthUpdate } from '../types/EpochManager/EpochManager'
import { createOrLoadEpoch, createEpoch } from './helpers'
import { log, BigInt } from '@graphprotocol/graph-ts'

/**
* @dev handleEpochRun
Expand Down
14 changes: 2 additions & 12 deletions src/mappings/gns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,11 +234,7 @@ export function handleSubgraphPublished(event: SubgraphPublished): void {
oldDeployment = SubgraphDeployment.load(oldVersion.subgraphDeployment)!
}
// create deployment - named subgraph relationship, and update the old one
updateCurrentDeploymentLinks(
oldDeployment,
deployment,
subgraph as Subgraph,
)
updateCurrentDeploymentLinks(oldDeployment, deployment, subgraph as Subgraph)
}
/**
* @dev handleSubgraphDeprecated
Expand All @@ -259,17 +255,11 @@ export function handleSubgraphDeprecated(event: SubgraphDeprecated): void {
graphNetwork.activeSubgraphCount = graphNetwork.activeSubgraphCount - 1
graphNetwork.save()


let version = SubgraphVersion.load(subgraph.currentVersion!)
if (version != null) {
let deployment = SubgraphDeployment.load(version.subgraphDeployment)

updateCurrentDeploymentLinks(
deployment,
null,
subgraph as Subgraph,
true
)
updateCurrentDeploymentLinks(deployment, null, subgraph as Subgraph, true)
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/mappings/graphToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export function handleTransfer(event: Transfer): void {

// no need to do any updates if it was a self transfer
if (to == from) return

// Mint Transfer
if (from.toHexString() == '0x0000000000000000000000000000000000000000') {
graphNetwork.totalSupply = graphNetwork.totalSupply.plus(value)
Expand Down
5 changes: 2 additions & 3 deletions src/mappings/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ export function createOrLoadSubgraphDeployment(
subgraphID: string,
timestamp: BigInt,
): SubgraphDeployment {
let graphNetwork = GraphNetwork.load('1')!
let deployment = SubgraphDeployment.load(subgraphID)
if (deployment == null) {
let graphNetwork = GraphNetwork.load('1')!
let prefix = '1220'
deployment = new SubgraphDeployment(subgraphID)
deployment.ipfsHash = Bytes.fromHexString(prefix.concat(subgraphID.slice(2))).toBase58()
Expand Down Expand Up @@ -96,7 +96,6 @@ export function createOrLoadSubgraphDeployment(
deployment.deprecatedSubgraphCount = 0
deployment.save()

let graphNetwork = GraphNetwork.load('1')!
graphNetwork.subgraphDeploymentCount = graphNetwork.subgraphDeploymentCount + 1
graphNetwork.save()
}
Expand Down Expand Up @@ -819,7 +818,7 @@ export function updateCurrentDeploymentLinks(
if (oldDeployment != null) {
if (!deprecated) {
let oldRelationEntity = CurrentSubgraphDeploymentRelation.load(
subgraph.currentVersionRelationEntity!
subgraph.currentVersionRelationEntity!,
)!
oldRelationEntity.active = false
oldRelationEntity.save()
Expand Down
4 changes: 2 additions & 2 deletions src/mappings/rewardsManager.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Address, BigDecimal, BigInt } from '@graphprotocol/graph-ts'
import { Indexer, Allocation, GraphNetwork, Epoch, SubgraphDeployment } from '../types/schema'
import { Address, BigInt } from '@graphprotocol/graph-ts'
import { Indexer, Allocation, GraphNetwork, SubgraphDeployment } from '../types/schema'
import {
RewardsAssigned,
ParameterUpdated,
Expand Down
16 changes: 8 additions & 8 deletions src/mappings/staking.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BigInt, Address, BigDecimal, Bytes, ipfs, log } from '@graphprotocol/graph-ts'
import { BigInt, BigDecimal } from '@graphprotocol/graph-ts'
import {
StakeDeposited,
StakeWithdrawn,
Expand Down Expand Up @@ -223,12 +223,11 @@ export function handleStakeDelegated(event: StakeDelegated): void {
let graphNetwork = GraphNetwork.load('1')!
graphNetwork.totalDelegatedTokens = graphNetwork.totalDelegatedTokens.plus(event.params.tokens)


if(isStakeBecomingActive) {
if (isStakeBecomingActive) {
graphNetwork.activeDelegationCount = graphNetwork.activeDelegationCount + 1
delegator.activeStakesCount = delegator.activeStakesCount + 1
// Is delegator becoming active because of the stake becoming active?
if(delegator.activeStakesCount == 1) {
if (delegator.activeStakesCount == 1) {
graphNetwork.activeDelegatorCount = graphNetwork.activeDelegatorCount + 1
}
}
Expand Down Expand Up @@ -258,7 +257,8 @@ export function handleStakeDelegatedLocked(event: StakeDelegatedLocked): void {
let id = joinID([delegatorID, indexerID])
let delegatedStake = DelegatedStake.load(id)!

let isStakeBecomingInactive = !delegatedStake.shareAmount.isZero() && delegatedStake.shareAmount == event.params.shares
let isStakeBecomingInactive =
!delegatedStake.shareAmount.isZero() && delegatedStake.shareAmount == event.params.shares

delegatedStake.unstakedTokens = delegatedStake.unstakedTokens.plus(event.params.tokens)
delegatedStake.shareAmount = delegatedStake.shareAmount.minus(event.params.shares)
Expand All @@ -282,11 +282,11 @@ export function handleStakeDelegatedLocked(event: StakeDelegatedLocked): void {
let graphNetwork = GraphNetwork.load('1')!
graphNetwork.totalDelegatedTokens = graphNetwork.totalDelegatedTokens.minus(event.params.tokens)

if(isStakeBecomingInactive) {
if (isStakeBecomingInactive) {
graphNetwork.activeDelegationCount = graphNetwork.activeDelegationCount - 1
delegator.activeStakesCount = delegator.activeStakesCount - 1
// Is delegator becoming inactive because of the stake becoming inactive?
if(delegator.activeStakesCount == 0) {
if (delegator.activeStakesCount == 0) {
graphNetwork.activeDelegatorCount = graphNetwork.activeDelegatorCount - 1
}
}
Expand Down Expand Up @@ -458,7 +458,7 @@ export function handleAllocationClosed(event: AllocationClosed): void {
const indexerAccount = GraphAccount.load(indexer.account)!
const closedByIndexer = event.params.sender == event.params.indexer
const closedByOperator = indexerAccount.operators.includes(event.params.sender.toHexString())

if (!closedByIndexer && !closedByOperator) {
indexer.forcedClosures = indexer.forcedClosures + 1
}
Expand Down
2 changes: 1 addition & 1 deletion src/mappings/tokenLockWallets/tokenLockWallet.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BigInt, log } from '@graphprotocol/graph-ts'
import { log } from '@graphprotocol/graph-ts'
import {
TokensReleased,
TokensWithdrawn,
Expand Down
66 changes: 26 additions & 40 deletions tests/factories/staking.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { newMockEvent } from "matchstick-as/assembly/index"
import { AllocationClosed, AllocationClosed__Params } from "../../src/types/Staking/Staking";
import { Address, BigInt, ByteArray, Bytes, ethereum } from "@graphprotocol/graph-ts"
import { newMockEvent } from 'matchstick-as/assembly/index'
import { AllocationClosed } from '../../src/types/Staking/Staking'
import { Address, BigInt, Bytes, ethereum } from '@graphprotocol/graph-ts'

export function mockAllocationClosed(
indexer: Address,
Expand All @@ -11,47 +11,33 @@ export function mockAllocationClosed(
effectiveAllocation: BigInt,
sender: Address,
poi: Bytes,
isDelegator: boolean
isDelegator: boolean,
): AllocationClosed {
const event = changetype<AllocationClosed>(newMockEvent())

event.parameters = []
event.parameters.push(new ethereum.EventParam(
"indexer",
ethereum.Value.fromAddress(indexer)
))
event.parameters.push(new ethereum.EventParam(
"subgraphDeploymentID",
ethereum.Value.fromBytes(subgraphDeploymentID)
))
event.parameters.push(new ethereum.EventParam(
"epoch",
ethereum.Value.fromUnsignedBigInt(epoch)
))
event.parameters.push(new ethereum.EventParam(
"tokens",
ethereum.Value.fromUnsignedBigInt(tokens)
))
event.parameters.push(new ethereum.EventParam(
"allocationID",
ethereum.Value.fromAddress(allocationID)
))
event.parameters.push(new ethereum.EventParam(
"effectiveAllocation",
ethereum.Value.fromUnsignedBigInt(effectiveAllocation)
))
event.parameters.push(new ethereum.EventParam(
"sender",
ethereum.Value.fromAddress(sender)
))
event.parameters.push(new ethereum.EventParam(
"poi",
ethereum.Value.fromBytes(poi)
))
event.parameters.push(new ethereum.EventParam(
"isDelegator",
ethereum.Value.fromBoolean(isDelegator)
))
event.parameters.push(new ethereum.EventParam('indexer', ethereum.Value.fromAddress(indexer)))
event.parameters.push(
new ethereum.EventParam('subgraphDeploymentID', ethereum.Value.fromBytes(subgraphDeploymentID)),
)
event.parameters.push(new ethereum.EventParam('epoch', ethereum.Value.fromUnsignedBigInt(epoch)))
event.parameters.push(
new ethereum.EventParam('tokens', ethereum.Value.fromUnsignedBigInt(tokens)),
)
event.parameters.push(
new ethereum.EventParam('allocationID', ethereum.Value.fromAddress(allocationID)),
)
event.parameters.push(
new ethereum.EventParam(
'effectiveAllocation',
ethereum.Value.fromUnsignedBigInt(effectiveAllocation),
),
)
event.parameters.push(new ethereum.EventParam('sender', ethereum.Value.fromAddress(sender)))
event.parameters.push(new ethereum.EventParam('poi', ethereum.Value.fromBytes(poi)))
event.parameters.push(
new ethereum.EventParam('isDelegator', ethereum.Value.fromBoolean(isDelegator)),
)

return event
}
Loading

0 comments on commit 39f5c02

Please sign in to comment.