Last active
August 17, 2023 09:10
-
-
Save hrik2001/0e2c58a97130f1981d7a1b840b9119bc to your computer and use it in GitHub Desktop.
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(f'https://arb-mainnet.g.alchemy.com/v2/L_HXVya-RV6U6SwLHWf1eUdlgwN20J-7')) | |
| m_address = "0xEcDF2cE74e19D4921Cc89fEfb963D35E0E5171D3" | |
| datastore_address = "0xfd70de6b91282d8017aa4e741e9ae325cab992d8" | |
| # marketToken | |
| # indexToken | |
| # longToken | |
| # shortToken | |
| market = ('0x70d95587d40A2caf56bd97485aB3Eec10Bee6336', '0x82aF49447D8a07e3bd95BD0d56f35241523fBab1', '0x82aF49447D8a07e3bd95BD0d56f35241523fBab1', '0xaf88d065e77c8cC2239327C5EDb3A432268e5831') | |
| market_props = { | |
| 'marketToken': market[0], | |
| 'indexToken': market[1], | |
| 'longToken': market[2], | |
| 'shortToken': market[3] | |
| } | |
| interface = [ | |
| { | |
| "constant": True, | |
| "inputs": [ | |
| {"name": "dataStore", "type": "address"}, | |
| { | |
| "name": "market", | |
| "type": "tuple", | |
| "components": [ | |
| {"name": "marketToken", "type": "address"}, | |
| {"name": "indexToken", "type": "address"}, | |
| {"name": "longToken", "type": "address"}, | |
| {"name": "shortToken", "type": "address"}, | |
| ], | |
| }, | |
| { | |
| "name": "indexTokenPrice", | |
| "type": "tuple", | |
| "components": [ | |
| {"name": "min", "type": "uint256"}, | |
| {"name": "max", "type": "uint256"}, | |
| ], | |
| }, | |
| { | |
| "name": "longTokenPrice", | |
| "type": "tuple", | |
| "components": [ | |
| {"name": "min", "type": "uint256"}, | |
| {"name": "max", "type": "uint256"}, | |
| ], | |
| }, | |
| { | |
| "name": "shortTokenPrice", | |
| "type": "tuple", | |
| "components": [ | |
| {"name": "min", "type": "uint256"}, | |
| {"name": "max", "type": "uint256"}, | |
| ], | |
| }, | |
| {"name": "pnlFactorType", "type": "bytes32"}, | |
| {"name": "maximize", "type": "bool"}, | |
| ], | |
| "name": "getMarketTokenPrice", | |
| "outputs": [ | |
| { | |
| "name": "", | |
| "type": "tuple", | |
| "components": [ | |
| {"name": "poolValue", "type": "int256"}, | |
| {"name": "longPnl", "type": "int256"}, | |
| {"name": "shortPnl", "type": "int256"}, | |
| {"name": "netPnl", "type": "int256"}, | |
| {"name": "longTokenAmount", "type": "uint256"}, | |
| {"name": "shortTokenAmount", "type": "uint256"}, | |
| {"name": "longTokenUsd", "type": "uint256"}, | |
| {"name": "shortTokenUsd", "type": "uint256"}, | |
| {"name": "totalBorrowingFees", "type": "uint256"}, | |
| {"name": "borrowingFeePoolFactor", "type": "uint256"}, | |
| {"name": "impactPoolAmount", "type": "uint256"}, | |
| ], | |
| } | |
| ], | |
| "payable": False, | |
| "stateMutability": "view", | |
| "type": "function", | |
| } | |
| ] | |
| mUtils = w3.eth.contract(address=Web3.to_checksum_address(m_address), abi=interface) | |
| # web3py v4 converts hexstring to bytes32 on it's own | |
| # Note: use webpy v4 | |
| pnl_factory_type = "0xab15365d3aa743e766355e2557c230d8f943e195dc84d9b2b05928a07b635ee1" | |
| index_token_price_props = { | |
| # 'min': 18398363 * 10**8, | |
| # 'max': 18398363 * 10**8 | |
| 'min': 1826 * 10**12, | |
| 'max': 1826 * 10**12 | |
| } | |
| long_token_price_props = { | |
| # 'min': 18398363 * 10**8, | |
| # 'max': 18398363 * 10**8 | |
| 'min': 1826 * 10**12, | |
| 'max': 1826 * 10**12 | |
| } | |
| short_token_price_props = { | |
| 'min': 10**24, | |
| 'max': 10**24 | |
| } | |
| price = mUtils.functions.getMarketTokenPrice( | |
| Web3.to_checksum_address(datastore_address), | |
| market_props, | |
| index_token_price_props, | |
| long_token_price_props, | |
| short_token_price_props, | |
| pnl_factory_type, | |
| True | |
| ).call() | |
| print(price) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment