Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
from web3 import Web3
import json
import pandas as pd
from abi import voting_machine_abi
w3 = Web3(Web3.HTTPProvider('https://mainnet.infura.io/v3/INFURA_KEY'))
VOTING_MACHINE_0 = '0x1C18bAd5a3ee4e96611275B13a8ed062B4a13055'
VOTING_MACHINE_1 = '0x332B8C9734b4097dE50f302F7D9F273FFdB45B84'
DXdao_AVATAR = '0x519b70055af55A007110B4Ff99b0eA33071c720a'
abi = json.loads(voting_machine_abi)
fromBlock = 12738509
toBlock = 13330089
txs_info = []
def get_txs(voting_machine):
contract = w3.eth.contract(address=voting_machine, abi=abi)
votes = contract.events.VoteProposal.createFilter(
fromBlock=fromBlock,
toBlock=toBlock,
argument_filters={'_organization': DXdao_AVATAR}
)
stakes = contract.events.Stake.createFilter(
fromBlock=fromBlock,
toBlock=toBlock,
argument_filters={'_organization': DXdao_AVATAR}
)
redeems = contract.events.Redeem.createFilter(
fromBlock=fromBlock,
toBlock=toBlock,
argument_filters={'_organization': DXdao_AVATAR}
)
boosts = contract.events.StateChange.createFilter(
fromBlock=fromBlock,
toBlock=toBlock
)
proposal_creation = contract.events.NewProposal.createFilter(
fromBlock=fromBlock,
toBlock=toBlock,
argument_filters={'_organization': DXdao_AVATAR}
)
# Get all proposals to filter boosts later - someone could boost a proposal
# which was not submitted in the same quarter - so querying all proposals.
proposal_all = contract.events.NewProposal.createFilter(
fromBlock=0,
toBlock=toBlock,
argument_filters={'_organization': DXdao_AVATAR}
)
proposal_execution = contract.events.ExecuteProposal.createFilter(
fromBlock=fromBlock,
toBlock=toBlock,
argument_filters={'_organization': DXdao_AVATAR}
)
vote_events = votes.get_all_entries()
stake_events = stakes.get_all_entries()
redeem_events = redeems.get_all_entries()
proposal_events = proposal_creation.get_all_entries()
execution_events = proposal_execution.get_all_entries()
proposal_all = proposal_all.get_all_entries()
boost_events = boosts.get_all_entries() # needs to be filtered to DXdao doesn't support avatar filtering
vote_txs = [i['transactionHash'] for i in vote_events]
stake_txs = [i['transactionHash'] for i in stake_events]
redeem_txs = [i['transactionHash'] for i in redeem_events]
proposal_txs = [i['transactionHash'] for i in proposal_events]
execution_txs = [i['transactionHash'] for i in execution_events]
proposal_ids_all = [i['args']['_proposalId'] for i in proposal_all]
# Filter DXdao boosts - by DXdao proposals and by boosted state 5
boost_txs = [i['transactionHash'] for i in boost_events if i['args']['_proposalId'] in proposal_ids_all if i['args']['_proposalState'] == 5]
def get_gasUsed(txs_list, label):
for tx in txs_list:
tx_data = w3.eth.get_transaction_receipt(tx)
if tx_data['from'].lower() == "0x4D953115678b15CE0B0396bCF95Db68003f86FB5".lower():
gas_used = tx_data['effectiveGasPrice'] * tx_data['gasUsed'] / 10**18
txs_info.append([label, tx_data['to'], gas_used])
else:
gas_used = tx_data['effectiveGasPrice'] * tx_data['gasUsed'] / 10**18
txs_info.append([label, tx_data['from'], gas_used])
get_gasUsed(vote_txs, 'vote')
get_gasUsed(stake_txs, 'stake')
get_gasUsed(redeem_txs, 'redeem')
get_gasUsed(proposal_txs, 'proposal')
get_gasUsed(execution_txs, 'execute')
get_gasUsed(boost_txs, 'boost')
if __name__ == '__main__':
get_txs(VOTING_MACHINE_0)
get_txs(VOTING_MACHINE_1)
print("Gas governance refunds are here -- please see below the details and provide feedback. Will be looking to deploy the smart contract during the next 7 days.\n")
print(f"Parameters: \n```\n \
FROM_BLOCK={fromBlock}\n \
TO_BLOCK={toBlock}\n \
\n\
# Refund % per action\n \
vote = 90%\n \
stake = 90%\n \
redeem = 90%\n \
proposal_creation = 90%\n \
execute = 100%\n \
boost = 100%\n \
```")
df = pd.DataFrame(txs_info, columns=['action', 'spender', 'spent'])
actions = df.groupby(['spender', 'action']).count().unstack().fillna(0)['spent']
print("**Account Actions:**")
print(actions.to_markdown())
df.replace(['vote', 'stake', 'redeem', 'proposal', 'execute', 'boost'], [0.9, 0.9, 0.9, 0.9, 1, 1], inplace=True)
df.spent = df.spent*df.action
df.drop(['action'], axis=1, inplace=True)
refunds = df.groupby(df.spender).sum()['spent']
refunds = refunds.reset_index()
print("**Refund Amounts:**")
print(refunds.to_markdown())
print("**Total ETH:**", refunds.spent.sum())
print(refunds['spender'].to_list())
x = refunds['spent']*10**18
print([str(int(i)) for i in x])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment