Last active
July 19, 2022 08:28
-
-
Save JTraversa/c5fdba51286d30643b056d671f6accc6 to your computer and use it in GitHub Desktop.
Listen in batches of 10k blocks, dedupe, read vault for balances
This file contains hidden or 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
| web3 = Web3(Web3.HTTPProvider(infura)) | |
| swivelcontract = create_contract(web3, False, contract_abi, swivel) | |
| marketplacecontract = create_contract(web3, False, marketplace_abi, marketplace) | |
| vault = marketplacecontract.functions.markets('0x5592EC0cfb4dbc12D3aB100b257153436a1f0FEa',1669957199).call()[2] | |
| vaultcontract = create_contract(web3, False, vaulttracker_abi, vault) | |
| exits =[] | |
| initiates = [] | |
| both = [] | |
| diff = 11050521 - 9745116 | |
| runs = int(diff / 10000) | |
| last = 11050521 | |
| final = 0 | |
| # loop for runs | |
| for i in range(runs): | |
| start = 9745116 + i*10000 | |
| end = 9745116 + (i+1)*10000 | |
| exit = list(fetch_events(swivelcontract.events.Exit, from_block=start, to_block=end)) | |
| exits = exits + exit | |
| initiate = list(fetch_events(swivelcontract.events.Initiate, from_block=start, to_block=end)) | |
| initiates = initiates + initiate | |
| final = end | |
| lastexits = list(fetch_events(swivelcontract.events.Exit, from_block=final, to_block=last)) | |
| lastinitiates = list(fetch_events(swivelcontract.events.Initiate, from_block=final, to_block=last)) | |
| exits = exits + lastexits | |
| initiates = initiates + lastinitiates | |
| # combine initiates and exits | |
| for i in initiates: | |
| both.append(i) | |
| for i in exits: | |
| both.append(i) | |
| addresses = [] | |
| for i in both: | |
| if i['args']['maker'] not in addresses: | |
| addresses.append(i['args']['maker']) | |
| if i['args']['sender'] not in addresses: | |
| addresses.append(i['args']['sender']) | |
| market = {'market': {'underlying': '0x5592EC0cfb4dbc12D3aB100b257153436a1f0FEa', 'maturity': '1669957199'}, 'users': []} | |
| # check vault 1 balances for each address | |
| for i in addresses: | |
| user = {'user': '', 'amounts': {'notional': '', 'redeemable': ''}} | |
| balances = vaultcontract.functions.balancesOf(i).call() | |
| notional = str(balances[0]) | |
| redeemable = str(balances[1]) | |
| user['user'] = i | |
| user['amounts'] = {'notional': notional, 'redeemable': redeemable} | |
| if notional != '0' or redeemable != '0': | |
| print(user) | |
| market['users'].append(user) | |
| with open("fourthMarket.json", "w", encoding="utf-8") as writeJsonfile: | |
| json.dump(market, writeJsonfile, indent=4,default=str) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment