Created
March 14, 2022 21:32
-
-
Save RiccardoBiosas/8e69e30996196e77af4bb54fb7f72b3a to your computer and use it in GitHub Desktop.
BondEvent monitoring
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const axios = require("axios"); | |
const livepeerSubgraphEndpoint = | |
"https://api.thegraph.com/subgraphs/name/livepeer/arbitrum-one"; | |
const bondEventQuery = ` | |
query BondEvents { | |
bondEvents(first: 1000) { | |
id | |
transaction { | |
id | |
from | |
to | |
} | |
timestamp | |
bondedAmount | |
oldDelegate { | |
id | |
} | |
newDelegate { | |
id | |
} | |
delegator { | |
id | |
} | |
} | |
} | |
`; | |
const l2MigratorAddress = "0x148D5b6B4df9530c7C76A810bd1Cdf69EC4c2085"; | |
const queryBondEvent = async () => { | |
const headers = { | |
"content-type": "application/json", | |
}; | |
const graphqlQuery = { | |
query: bondEventQuery, | |
variables: {}, | |
}; | |
const response = await axios({ | |
url: livepeerSubgraphEndpoint, | |
method: "post", | |
headers, | |
data: graphqlQuery, | |
}); | |
return response.data.data.bondEvents; | |
}; | |
/** | |
* An occurrence of the vulnerability needs to match the following criteria: | |
* - the Transaction `from` value must be different from the bondForWithHint `owner` (referenced as `Delegator` in the subgraph BondEvent entity) | |
* - the BondEvent entity's `newDelegate` and `oldDelegate` must be different | |
* - the BondEvent `owner` value must not be the L2Migrator address | |
*/ | |
const main = async () => { | |
const result = await queryBondEvent(); | |
const filteredResult = result | |
.filter((entity) => { | |
entity.transaction.to.toLowerCase() !== l2MigratorAddress.toLowerCase(); | |
}) | |
.filter((entity) => entity.transaction.from !== entity.delegator.id) | |
.filter((entity) => entity.newDelegate.id !== entity.oldDelegate.id) | |
.filter( | |
(entity) => | |
entity.oldDelegate.id !== "0x0000000000000000000000000000000000000000" | |
); | |
console.log(filteredResult); | |
return filteredResult; | |
}; | |
main() | |
.then(() => process.exit(0)) | |
.catch((error) => { | |
console.error(error); | |
process.exit(1); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment