Created
July 31, 2023 12:36
-
-
Save hrik2001/4b8bb85aed391dc51bea485de80bf344 to your computer and use it in GitHub Desktop.
Mantle
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
| from web3 import Web3 | |
| import json | |
| w3 = Web3(Web3.HTTPProvider("https://rpc.mantle.xyz")) | |
| # w3 = Web3(Web3.HTTPProvider("https://rpc.testnet.mantle.xyz")) | |
| # w3 = Web3(Web3.HTTPProvider(f'https://arb-mainnet.g.alchemy.com/v2/L_HXVya-RV6U6SwLHWf1eUdlgwN20J-7')) | |
| with open("abi/TimeswapV2PeripheryNoDexLendGivenPrincipal.json") as f: | |
| abi_lend_given_principal_nodex = json.load(f)["abi"] | |
| with open("abi/TimeswapV2PeripheryNoDexCloseLendGivenPosition.json") as f: | |
| abi_close_lend_given_position_nodex = json.load(f)["abi"] | |
| with open("abi/TimeswapV2PeripheryNoDexCloseBorrowGivenPosition.json") as f: | |
| abi_close_borrow_given_position_nodex = json.load(f)["abi"] | |
| with open("abi/TimeswapV2PeripheryNoDexBorrowGivenPrincipal.json") as f: | |
| abi_borrow_given_principal_nodex = json.load(f)["abi"] | |
| # pool = w3.eth.contract(address=pool_address, abi=abi) | |
| strike = 226854911280625642308916404954512140970666666667 | |
| maturity = 1690808400 | |
| # token0 = USDT | |
| # token1 = WETH | |
| lend_given_principal_nodex = w3.eth.contract(address='0x963f5BDedB314D2abA6894543EbD6Ea475656464', abi=abi_lend_given_principal_nodex) | |
| borrow_given_principal_nodex = w3.eth.contract(address='0xbD901Ec47Fc09C7dEE99606d02F8645a54e53446', abi=abi_borrow_given_principal_nodex) | |
| close_borrow_nodex = w3.eth.contract(address='0x7042161Fed19066f0989Fdc4dd81EC075698Ee83', abi=abi_close_borrow_given_position_nodex) | |
| # lend_given_principal_nodex = w3.eth.contract(address='0x0A3FEF7fb5655ed02D02Ba1e4139Ce88Ca5907fD', abi=abi_lend_given_principal_nodex) | |
| # borrow : 0xbD901Ec47Fc09C7dEE99606d02F8645a54e53446 | |
| close_lend_nodex = w3.eth.contract(address='0x8372232a2db4c04B8fF938644837eA7A69A0C2f1', abi=abi_close_lend_given_position_nodex) | |
| events_lend = lend_given_principal_nodex.events.LendGivenPrincipal.get_logs(fromBlock=5740) | |
| events_borrow = borrow_given_principal_nodex.events.BorrowGivenPrincipal.get_logs(fromBlock=5740) | |
| events_close_lend = close_lend_nodex.events.CloseLendGivenPosition.get_logs(fromBlock=5740) | |
| events_close_borrow = close_borrow_nodex.events.CloseBorrowGivenPosition.get_logs(fromBlock=5740) | |
| lent = {"token0": 0, "token1": 0} | |
| borrowed = {"token0": 0, "token1": 0} | |
| close_lent = {"token0": 0, "token1": 0} | |
| close_borrowed = {"token0": 0, "token1": 0} | |
| for i in events_lend: | |
| if i.args.strike == strike and i.args.maturity == maturity: | |
| if i.args.isToken0: | |
| lent["token0"] += i.args.tokenAmount/1e6 | |
| else: | |
| lent["token1"] += i.args.tokenAmount/1e18 | |
| for i in events_borrow: | |
| if i.args.strike == strike and i.args.maturity == maturity: | |
| if i.args.isToken0: | |
| borrowed["token0"] += i.args.tokenAmount/1e6 | |
| else: | |
| borrowed["token1"] += i.args.tokenAmount/1e18 | |
| for i in events_close_lend: | |
| if i.args.strike == strike and i.args.maturity == maturity: | |
| close_lent["token0"] += i.args.token0Amount/1e6 | |
| close_lent["token1"] += i.args.token1Amount/1e18 | |
| for i in events_close_borrow: | |
| if i.args.strike == strike and i.args.maturity == maturity: | |
| if i.args.isToken0: | |
| close_borrowed["token0"] += i.args.tokenAmount/1e6 | |
| else: | |
| close_borrowed["token1"] += i.args.tokenAmount/1e18 | |
| print(lent) | |
| print(borrowed) | |
| print(close_lent) | |
| print(close_borrowed) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment