Skip to content

Instantly share code, notes, and snippets.

@stevenc81
Created December 26, 2019 03:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stevenc81/419b8d16314424587c622fdec2980042 to your computer and use it in GitHub Desktop.
Save stevenc81/419b8d16314424587c622fdec2980042 to your computer and use it in GitHub Desktop.
from web3 import Web3
import requests
CONTRACT_ADDRESS = '0x39aa39c021dfbae8fac545936693ac917d5e7563'
def main():
w3 = Web3(Web3.HTTPProvider('https://mainnet.infura.io/v3/<YOUR PROJECT ID>'))
r = requests.get(f'https://api.etherscan.io/api?module=contract&action=getabi&address={CONTRACT_ADDRESS}')
checksummed_address = w3.toChecksumAddress(CONTRACT_ADDRESS)
contract = w3.eth.contract(address=checksummed_address, abi=r.json()['result'])
liquidity = contract.functions.getCash().call()
total_borrow = contract.functions.totalBorrows().call()
total_supply = liquidity + total_borrow
if (total_borrow / total_supply) > 0.65 or liquidity < 10000000000000:
r = requests.post(
'https://api.mailgun.net/v3/<YOUR DOMAIN>/messages',
auth=('api', '<YOUR API KEY>'),
data={'from': 'DeFi Alerts <alerts@defi.com>',
'to': ['<YOUR EMAIL ADDRESS>'],
'subject': "High utilization or low liquidity",
'text': f"Current rate {total_borrow / total_supply}\n" +
f"Current liquidity {liquidity / 1000000}"})
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment