Skip to content

Instantly share code, notes, and snippets.

@raymondjacobson
Created July 24, 2022 21:25
Show Gist options
  • Save raymondjacobson/697441861b47a5849d617c40082b1717 to your computer and use it in GitHub Desktop.
Save raymondjacobson/697441861b47a5849d617c40082b1717 to your computer and use it in GitHub Desktop.
const Web3 = require('web3')
const fs = require('fs')
const StakingABI = JSON.parse(fs.readFileSync('./abi/Staking.json'))
const DelegationABI = JSON.parse(fs.readFileSync('./abi/DelegateManager.json'))
const ServiceABI = JSON.parse(fs.readFileSync('./abi/ServiceProviderFactory.json'))
const AdminABI = JSON.parse(fs.readFileSync('./abi/AudiusAdminUpgradeabilityProxy.json'))
const ServiceTypeABI = JSON.parse(fs.readFileSync('./abi/ServiceTypeManager.json'))
const StakingAddress = '0xe6D97B2099F142513be7A2a068bE040656Ae4591'
const DelegationAddress = '0x4d7968ebfD390D5E7926Cb3587C39eFf2F9FB225'
const ServiceAddress = '0xD17A9bc90c582249e211a4f4b16721e7f65156c8'
const ServiceTypeAddress = '0x9EfB0f4F38aFbb4b0984D00C126E97E21b8417C5'
const main = async () => {
const w3 = new Web3('http://34.132.89.145:8545')
const n = await w3.eth.getBlockNumber()
console.log({ n })
const stakingContract = new w3.eth.Contract(StakingABI.abi, StakingAddress)
const delegationContract = new w3.eth.Contract(DelegationABI.abi, DelegationAddress)
const serviceContract = new w3.eth.Contract(ServiceABI.abi, ServiceAddress)
const serviceTypeContract = new w3.eth.Contract(ServiceTypeABI.abi, ServiceTypeAddress)
console.log('Staking contract storage')
for (let i = 0; i < 200; ++i) {
const s = await w3.eth.getStorageAt(StakingAddress, i)
console.log(`[${i}]` + s)
}
console.log('Delegation contract storage')
for (let i = 0; i < 200; ++i) {
const s = await w3.eth.getStorageAt(DelegationAddress, i)
console.log(`[${i}]` + s)
}
console.log('Service contract storage')
for (let i = 0; i < 200; ++i) {
const s = await w3.eth.getStorageAt(ServiceAddress, i)
console.log(`[${i}]` + s)
}
console.log('Staking contract exploration')
const totalStake = await stakingContract.methods.totalStakedAt(n).call()
console.log({ totalStake })
const serviceTypes = await serviceTypeContract.methods.getValidServiceTypes().call()
console.log({ serviceTypes: serviceTypes.map(t => w3.utils.hexToUtf8(t)) })
const maxSPID = 100
const serviceProviders = new Set([])
for (let i = 0; i < maxSPID; ++i) {
const discoveryNodeSP = await serviceContract.methods.getServiceEndpointInfo(
w3.utils.utf8ToHex('discovery-node'),
i)
.call()
if (discoveryNodeSP.owner !== '0x0000000000000000000000000000000000000000') {
serviceProviders.add(discoveryNodeSP.owner)
}
const contentNodeSP = await serviceContract.methods.getServiceEndpointInfo(
w3.utils.utf8ToHex('content-node'),
i)
.call()
if (contentNodeSP.owner !== '0x0000000000000000000000000000000000000000') {
serviceProviders.add(contentNodeSP.owner)
}
}
for (const sp of serviceProviders) {
console.log(`Info for SP ${sp}`)
const totalSPStake = await stakingContract.methods.totalStakedFor(sp).call()
console.log(`SP ${sp} has total stake ${totalSPStake}`)
const lastSPStake = await stakingContract.methods.lastStakedFor(sp).call()
console.log(`SP ${sp} has last stake of ${lastSPStake}`)
const totalDelegation = await delegationContract.methods.getTotalDelegatedToServiceProvider(sp).call()
console.log(`SP ${sp} has total delegation ${totalDelegation}`)
console.log('\n')
const delegators = await delegationContract.methods.getDelegatorsList(sp).call()
for (const delegator of delegators) {
const delegatorStake = await delegationContract.methods.getTotalDelegatorStake(delegator).call()
console.log(`Delegator ${delegator} has ${delegatorStake}`)
const delegationToSP = await delegationContract.methods.getDelegatorStakeForServiceProvider(delegator, sp).call()
console.log(`Delegator ${delegator} has ${delegationToSP} for ${sp}`)
}
console.log('===================================================================')
}
}
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment