Skip to content
This repository has been archived by the owner on Sep 13, 2024. It is now read-only.

Commit

Permalink
Merge pull request #5 from FerranMarin/ron_scatter
Browse files Browse the repository at this point in the history
Add RON transactions and scatter class
  • Loading branch information
FerranMarin authored Mar 27, 2022
2 parents 41accce + 7aa52b0 commit 7a0a653
Show file tree
Hide file tree
Showing 19 changed files with 1,247 additions and 596 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ jobs:
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
packages_dir: dist/
packages_dir: ./axie-utils/dist/
2 changes: 2 additions & 0 deletions axie-utils/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

Aim of this library is to contain all the actions one might want to do when building tools around the Axie Infinity videogame. It started with me building an automation tool and needing to build different solutions. Extracting this functionality allows for that easily.

**NOTE: Only v1 of this library uses free tx, from v2 and onwards all transactions consume RON. That is due to now free tx being much more rare to have available.**


# Installation

Expand Down
5 changes: 4 additions & 1 deletion axie-utils/axie_utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = '1.1.3'
__version__ = '2.0.0'
__all__ = [
'Axies',
'AxieGraphQL',
Expand All @@ -7,13 +7,15 @@
'CustomUI',
'Morph',
'Payment',
'Scatter',
'Transfer',
'TrezorAxieGraphQL',
'TrezorBreed',
'TrezorClaim',
'TrezorConfig',
'TrezorMorph',
'TrezorPayment',
'TrezorScatter',
'TrezorTransfer',
'get_nonce',
'get_lastclaim',
Expand All @@ -26,5 +28,6 @@
from axie_utils.graphql import AxieGraphQL, TrezorAxieGraphQL
from axie_utils.morphing import Morph, TrezorMorph
from axie_utils.payments import Payment, TrezorPayment
from axie_utils.scatter import Scatter, TrezorScatter
from axie_utils.transfers import Transfer, TrezorTransfer
from axie_utils.utils import get_nonce, check_balance, CustomUI, TrezorConfig, get_lastclaim
30 changes: 30 additions & 0 deletions axie-utils/axie_utils/abis.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,33 @@
'stateMutability': 'view',
'type': 'function',
}]

SCATTER_ABI = [{
'constant': False,
'inputs': [
{'name': 'token', 'type':'address'},
{'name': 'recipients', 'type': 'address[]'},
{'name': 'values', 'type': 'uint256[]'}],
'name': 'disperseTokenSimple',
'outputs': [],
'payable': False,
'stateMutability': 'nonpayable',
'type': 'function'
}, {
'constant': False,
'inputs': [{'name': 'token', 'type': 'address'},{'name': 'recipients', 'type': 'address[]'},{'name': 'values', 'type': 'uint256[]'}],
'name': 'disperseToken',
'outputs': [],
'payable': False,
'stateMutability': 'nonpayable',
'type': 'function'
}, {
'constant': False,
'inputs': [
{'name': 'recipients', 'type': 'address[]'},{'name': 'values', 'type': 'uint256[]'}],
'name': 'disperseEther',
'outputs': [],
'payable': True,
'stateMutability': 'payable',
'type': 'function'
}]
27 changes: 15 additions & 12 deletions axie-utils/axie_utils/breeding.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from axie_utils.abis import AXIE_ABI
from axie_utils.utils import (
get_nonce,
RONIN_PROVIDER_FREE,
RONIN_PROVIDER,
AXIE_CONTRACT,
TIMEOUT_MINS,
USER_AGENT
Expand All @@ -21,7 +21,7 @@ class Breed:
def __init__(self, sire_axie, matron_axie, address, private_key):
self.w3 = Web3(
Web3.HTTPProvider(
RONIN_PROVIDER_FREE,
RONIN_PROVIDER,
request_kwargs={"headers": {"content-type": "application/json", "user-agent": USER_AGENT}}))
self.sire_axie = sire_axie
self.matron_axie = matron_axie
Expand All @@ -43,7 +43,7 @@ def execute(self):
).buildTransaction({
"chainId": 2020,
"gas": 492874,
"gasPrice": self.w3.toWei("0", "gwei"),
"gasPrice": self.w3.toWei("1", "gwei"),
"nonce": nonce
})
# Sign transaction
Expand All @@ -53,8 +53,8 @@ def execute(self):
)
# Send raw transaction
self.w3.eth.send_raw_transaction(signed.rawTransaction)
# get transaction hash
hash = self.w3.toHex(self.w3.keccak(signed.rawTransaction))
# get transaction _hash
_hash = self.w3.toHex(self.w3.keccak(signed.rawTransaction))
# Wait for transaction to finish or timeout
logging.info("{self} about to start!")
start_time = datetime.now()
Expand All @@ -65,7 +65,7 @@ def execute(self):
logging.info(f"Transaction {self}, timed out!")
break
try:
recepit = self.w3.eth.get_transaction_receipt(hash)
recepit = self.w3.eth.get_transaction_receipt(_hash)
if recepit["status"] == 1:
success = True
else:
Expand All @@ -78,6 +78,7 @@ def execute(self):

if success:
logging.info(f"{self} completed successfully")
return _hash
else:
logging.info(f"{self} failed")

Expand All @@ -90,14 +91,14 @@ class TrezorBreed:
def __init__(self, sire_axie, matron_axie, address, client, bip_path):
self.w3 = Web3(
Web3.HTTPProvider(
RONIN_PROVIDER_FREE,
RONIN_PROVIDER,
request_kwargs={"headers": {"content-type": "application/json", "user-agent": USER_AGENT}}))
self.sire_axie = sire_axie
self.matron_axie = matron_axie
self.address = address.replace("ronin:", "0x")
self.client = client
self.bip_path = parse_path(bip_path)
self.gwei = self.w3.toWei('0', 'gwei')
self.gwei = self.w3.toWei('1', 'gwei')
self.gas = 250000

def execute(self):
Expand All @@ -115,7 +116,7 @@ def execute(self):
).buildTransaction({
"chainId": 2020,
"gas": self.gas,
"gasPrice": self.w3.toWei("0", "gwei"),
"gasPrice": self.gwei,
"nonce": nonce
})
data = self.w3.toBytes(hexstr=breed_tx['data'])
Expand All @@ -134,8 +135,8 @@ def execute(self):
transaction = rlp.encode((nonce, self.gwei, self.gas, to, 0, data) + sig)
# Send raw transaction
self.w3.eth.send_raw_transaction(transaction)
# get transaction hash
hash = self.w3.toHex(self.w3.keccak(transaction))
# get transaction _hash
_hash = self.w3.toHex(self.w3.keccak(transaction))
# Wait for transaction to finish or timeout
logging.info("{self} about to start!")
start_time = datetime.now()
Expand All @@ -146,7 +147,7 @@ def execute(self):
logging.info(f"Transaction {self}, timed out!")
break
try:
recepit = self.w3.eth.get_transaction_receipt(hash)
recepit = self.w3.eth.get_transaction_receipt(_hash)
if recepit["status"] == 1:
success = True
else:
Expand All @@ -159,8 +160,10 @@ def execute(self):

if success:
logging.info(f"{self} completed successfully")
return _hash
else:
logging.info(f"{self} failed")
return

def __str__(self):
return (f"Breeding axie {self.sire_axie} with {self.matron_axie} in account "
Expand Down
14 changes: 7 additions & 7 deletions axie-utils/axie_utils/claims.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
check_balance,
get_nonce,
SLP_CONTRACT,
RONIN_PROVIDER_FREE
RONIN_PROVIDER
)
from axie_utils.graphql import AxieGraphQL, TrezorAxieGraphQL

Expand All @@ -23,7 +23,7 @@ def __init__(self, acc_name, **kwargs):
super().__init__(**kwargs)
self.w3 = Web3(
Web3.HTTPProvider(
RONIN_PROVIDER_FREE,
RONIN_PROVIDER,
request_kwargs={"headers": {"content-type": "application/json", "user-agent": self.user_agent}}))
self.slp_contract = self.w3.eth.contract(
address=Web3.toChecksumAddress(SLP_CONTRACT),
Expand Down Expand Up @@ -88,7 +88,7 @@ async def async_execute(self):
signature['amount'],
signature['timestamp'],
signature['signature']
).buildTransaction({'gas': 492874, 'gasPrice': 0, 'nonce': nonce})
).buildTransaction({'gas': 492874, 'gasPrice': 1, 'nonce': nonce})
# Sign claim
signed_claim = self.w3.eth.account.sign_transaction(
claim,
Expand Down Expand Up @@ -160,7 +160,7 @@ def execute(self):
signature['amount'],
signature['timestamp'],
signature['signature']
).buildTransaction({'gas': 492874, 'gasPrice': 0, 'nonce': nonce})
).buildTransaction({'gas': 492874, 'gasPrice': 1, 'nonce': nonce})
# Sign claim
signed_claim = self.w3.eth.account.sign_transaction(
claim,
Expand Down Expand Up @@ -197,15 +197,15 @@ def __init__(self, acc_name, **kwargs):
super().__init__(**kwargs)
self.w3 = Web3(
Web3.HTTPProvider(
RONIN_PROVIDER_FREE,
RONIN_PROVIDER,
request_kwargs={"headers": {"content-type": "application/json", "user-agent": self.user_agent}}))
self.slp_contract = self.w3.eth.contract(
address=Web3.toChecksumAddress(SLP_CONTRACT),
abi=SLP_ABI
)
self.acc_name = acc_name
self.request = requests.Session()
self.gwei = self.w3.toWei('0', 'gwei')
self.gwei = self.w3.toWei('1', 'gwei')
self.gas = 492874

def has_unclaimed_slp(self):
Expand Down Expand Up @@ -264,7 +264,7 @@ async def async_execute(self):
signature['amount'],
signature['timestamp'],
signature['signature']
).buildTransaction({'gas': self.gas, 'gasPrice': 0, 'nonce': nonce})
).buildTransaction({'gas': self.gas, 'gasPrice': 1, 'nonce': nonce})
data = self.w3.toBytes(hexstr=claim['data'])
to = self.w3.toBytes(hexstr=SLP_CONTRACT)
sig = ethereum.sign_tx(
Expand Down
Loading

0 comments on commit 7a0a653

Please sign in to comment.