-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAVAXAPI.py
More file actions
119 lines (95 loc) · 5.5 KB
/
Copy pathAVAXAPI.py
File metadata and controls
119 lines (95 loc) · 5.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# -------------------------------- LIBRARIES -------------------------------- #
from web3 import Web3
from web3.middleware import geth_poa_middleware
import Config as config
# ------------------------------- MAIN CLASS -------------------------------- #
class AvalancheAPI(object):
# ------------------------------- INITIALIZE -------------------------------- #
def __init__(self):
self.web3 = Web3(Web3.HTTPProvider(config.AVAX_RPC_URL))
self.web3.middleware_onion.inject(geth_poa_middleware, layer=0)
self.spend = self.web3.toChecksumAddress(config.WAVAX_ADDRESS)
self.start_balance = self.getBalance()
self.contractdolla = self.web3.eth.contract(address=self.web3.toChecksumAddress(config.DOLLA_CONTRACT_ADRESS), abi=config.DOLLA_ABI)
self.contractbiz = self.web3.eth.contract(address=self.web3.toChecksumAddress(config.BIZ_CONTRACT_ADRESS), abi=config.BIZ_ABI)
self.contractvmt = self.web3.eth.contract(address=self.web3.toChecksumAddress(config.VMT_CONTRACT_ADRESS), abi=config.VMT_ABI)
print('Starting Balance (AVAX): ', self.start_balance)
# ---------------------------------- UTILS ---------------------------------- #
def getBalance(self): # Get AVAX balance
return self.web3.fromWei(self.web3.eth.get_balance(config.SENDER_ADDRESS), 'ether')
def getNonce(self): # Get address nonce
return self.web3.eth.get_transaction_count(config.SENDER_ADDRESS)
def get_token_info(self, token_address): # Get symbol and decimal count from contract address
contract_id = self.web3.toChecksumAddress(token_address)
sell_token_contract = self.web3.eth.contract(contract_id, abi=config.SELL_ABI)
symbol = sell_token_contract.functions.symbol().call()
decimals = sell_token_contract.functions.decimals().call()
return symbol, decimals
def get_token_holdings(self, token_address): # Get amount of tokens hold and value(in AVAX) of these tokens
contract_id = self.web3.toChecksumAddress(token_address)
sell_token_contract = self.web3.eth.contract(contract_id, abi=config.SELL_ABI)
balance = sell_token_contract.functions.balanceOf(config.SENDER_ADDRESS).call() # How many tokens do we have?
return balance
# --------------------------------- VMTycoon --------------------------------- #
def getTycoonIds(self):
balance = self.contractvmt.functions.balanceOf(config.SENDER_ADDRESS).call()
Tycoons = []
if balance > 0:
for i in range(0, balance):
TycoonID = self.contractvmt.functions.tokenOfOwnerByIndex(config.SENDER_ADDRESS, i).call()
Tycoons.append(TycoonID)
return Tycoons
def getLevelInfo(self, level):
reqDolla= self.contractbiz.functions.dollaLevelingRate(level).call()
return reqDolla
def getTycoonInfo(self, tid):
myTycoon = self.contractbiz.functions.stakedVMTycoon(tid).call()
return myTycoon
def addDolla(self, tid, amount):
sender = self.web3.toChecksumAddress(config.SENDER_ADDRESS)
nonce = self.web3.eth.get_transaction_count(sender)
approve = self.contractdolla.functions.equipVMTycoon(vmtycoonId = tid, amount = amount).buildTransaction({
'from': sender,
'nonce': nonce
})
signed_txn = self.web3.eth.account.sign_transaction(approve, private_key=config.PRIVATE_KEY)
tx_token = self.web3.eth.send_raw_transaction(signed_txn.rawTransaction)
tx = self.web3.toHex(tx_token)
return tx
def lvlTycoon(self, tid):
sender = self.web3.toChecksumAddress(config.SENDER_ADDRESS)
nonce = self.web3.eth.get_transaction_count(sender)
approve = self.contractbiz.functions.levelUpVMTycoon(tid = tid).buildTransaction({
'from': sender,
'nonce': nonce
})
signed_txn = self.web3.eth.account.sign_transaction(approve, private_key=config.PRIVATE_KEY)
tx_token = self.web3.eth.send_raw_transaction(signed_txn.rawTransaction)
tx = self.web3.toHex(tx_token)
return tx
# --------------------------------- Claiming --------------------------------- #
def getClaimableDolla(self):
myDolla = self.contractdolla.functions.claimableView(config.SENDER_ADDRESS).call()
return myDolla
def claimBiz(self, tokenIds):
sender = self.web3.toChecksumAddress(config.SENDER_ADDRESS)
nonce = self.web3.eth.get_transaction_count(sender)
approve = self.contractbiz.functions.claimBusinesses(tokenIds = tokenIds).buildTransaction({
'from': sender,
'nonce': nonce
})
signed_txn = self.web3.eth.account.sign_transaction(approve, private_key=config.PRIVATE_KEY)
tx_token = self.web3.eth.send_raw_transaction(signed_txn.rawTransaction)
tx = self.web3.toHex(tx_token)
return tx
def stakeBiz(self, amount):
sender = self.web3.toChecksumAddress(config.SENDER_ADDRESS)
nonce = self.web3.eth.get_transaction_count(sender)
approve = self.contractdolla.functions.staking(amount = amount).buildTransaction({
'from': sender,
'nonce': nonce
})
signed_txn = self.web3.eth.account.sign_transaction(approve, private_key=config.PRIVATE_KEY)
tx_token = self.web3.eth.send_raw_transaction(signed_txn.rawTransaction)
tx = self.web3.toHex(tx_token)
return tx