144 lines
4.1 KiB
Python
144 lines
4.1 KiB
Python
import os
|
|
import csv
|
|
import time
|
|
import apprise
|
|
import requests
|
|
import psycopg2
|
|
import psycopg2.extras
|
|
from typing import List
|
|
from web3 import Web3
|
|
from eth_abi import abi
|
|
from cryptography.fernet import Fernet
|
|
|
|
import SendTx
|
|
|
|
# Constants
|
|
ADMIN_ADDRESS = "0x3fF44D639a4982A4436f6d737430141aBE68b4E1"
|
|
|
|
ABI = [{
|
|
"inputs": [
|
|
{
|
|
"components": [
|
|
{
|
|
"internalType": "address",
|
|
"name": "user",
|
|
"type": "address"
|
|
},
|
|
{
|
|
"internalType": "uint256",
|
|
"name": "amount",
|
|
"type": "uint256"
|
|
},
|
|
{
|
|
"internalType": "uint256",
|
|
"name": "lastClaimed",
|
|
"type": "uint256"
|
|
},
|
|
{
|
|
"internalType": "uint256",
|
|
"name": "unlockTime",
|
|
"type": "uint256"
|
|
},
|
|
{
|
|
"internalType": "uint256",
|
|
"name": "dailyRewardRate",
|
|
"type": "uint256"
|
|
}
|
|
],
|
|
"internalType": "struct PacaFinanceWithBoostAndSchedule.StakeInput[]",
|
|
"name": "stakesInput",
|
|
"type": "tuple[]"
|
|
}
|
|
],
|
|
"name": "createStakes",
|
|
"outputs": [],
|
|
"stateMutability": "payable",
|
|
"type": "function"
|
|
},]
|
|
|
|
# Initialize Web3 instances
|
|
poll_web3 = Web3(Web3.HTTPProvider("https://bsc-dataseed.binance.org"))
|
|
|
|
|
|
# Load database credentials
|
|
password = "gAAAAABk_7JkHS5QuSLOjoPp0xx2gDdaXa-NK-uFiqJwF7qIkMQhPCAshuFHUTps-DLZBhe1_OTw5gV3azlcm_1phUzfOyVPRFAdOg6BQZgYCjQMWZuXCBk="
|
|
password = Fernet(os.environ["FernetKey"].encode()).decrypt(password.encode()).decode()
|
|
db_params = {
|
|
"dbname": "avian-werebat-5297.defaultdb",
|
|
"user": "sascha",
|
|
"host": "avian-werebat-5297.g8z.cockroachlabs.cloud",
|
|
"port": "26257",
|
|
"password": password,
|
|
}
|
|
|
|
# Load Oracle address and key
|
|
with psycopg2.connect(**db_params) as conn:
|
|
with conn.cursor(cursor_factory=psycopg2.extras.DictCursor) as cur:
|
|
cur.execute(
|
|
"SELECT bnb_addr, bnb_key FROM key_data WHERE username = 'OracleBot'"
|
|
)
|
|
oracle_address, oracle_key = cur.fetchall()[0]
|
|
|
|
cur.execute(
|
|
"""SELECT id
|
|
, address
|
|
, amount
|
|
, lastclaimed
|
|
, reward
|
|
, unlocktime
|
|
from unmade2
|
|
WHERE txn_hash IS NULL
|
|
AND address = '0xf697d95b4C0403f03dA06B50faaE262Ed37f1Da4'
|
|
limit 100"""
|
|
)
|
|
unmade_list = [dict(row) for row in cur.fetchall()]
|
|
print(unmade_list)
|
|
|
|
def swap_to_bnb(stakearray):
|
|
"""Swap tokens to BNB."""
|
|
token_contract = poll_web3.eth.contract(address=ADMIN_ADDRESS, abi=ABI)
|
|
txn = token_contract.functions.createStakes(stakearray).build_transaction(
|
|
{
|
|
"chainId": 56,
|
|
"from": oracle_address,
|
|
"gas": 280000,
|
|
"gasPrice": poll_web3.to_wei(0, "gwei"),
|
|
"nonce": poll_web3.eth.get_transaction_count(oracle_address),
|
|
}
|
|
)
|
|
estimated_gas = poll_web3.eth.estimate_gas(txn)
|
|
print(estimated_gas)
|
|
txn["gas"] = int(estimated_gas * 1.05)
|
|
|
|
signed_tx = SendTx.send_zero_tx(txn)
|
|
|
|
return signed_tx
|
|
|
|
|
|
def handle_top_level_exception(e):
|
|
"""Handle top-level exceptions and sleep for a specified time."""
|
|
print(f"Top Level Exception - {e}")
|
|
time.sleep(6)
|
|
|
|
|
|
# for row in unmade_list:
|
|
# try:
|
|
# print(row)
|
|
|
|
# send_txn = swap_to_bnb(row['address'], int(row['amount']), int(row['lockup_period']), int(row['reward']))
|
|
|
|
# print(send_txn)
|
|
|
|
# with psycopg2.connect(**db_params) as conn:
|
|
# with conn.cursor(cursor_factory=psycopg2.extras.DictCursor) as cur:
|
|
# cur.execute(
|
|
# f"update unmade set creation_hash = '{send_txn['Transaction Hash']}', status = '{send_txn['status']}' WHERE id = '{row['id']}'"
|
|
# )
|
|
|
|
# break
|
|
# except Exception as e:
|
|
# handle_top_level_exception(e)
|
|
|
|
|
|
# txn_array = []
|
|
# send_txn = swap_to_bnb(txn_array) |