Giter Club home page Giter Club logo

dfktools's Introduction

Pypi_repo GitHub license GitHub stars Join Discord Join Discord Follow @twitter handle

Install with pip install dfktools

https://pypi.org/project/dfktools/

DefiKingdoms toolbox

This is a simple toolbox to interact with the contracts of DefiKingdoms

This software is not endorsed by, directly affiliated with, maintained, authorized, or sponsored by the DefiKingdoms team. All product and company names are the registered trademarks of their original owners. The use of any trade name or trademark is for identification and reference purposes only and does not imply any association with the trademark holder of their product brand.


Like this project ? Consider supporting future developments by:

  • Delegating AVAX to our Avalanche node NodeID-4btZGj8TmrycK22kwgBK5wJEFighAFWiZ
  • Making a donation to 0xA68fBfa3E0c86D1f3fF071853df6DAe8753095E2

Need help ? Join the GameFi Developers Discord

Code guidelines

  1. Indent with Tab
  2. 1 empty line within a function, 2 empty lines between function
  3. Use trait(s) to name any or all of the 8 value strength, agility, intelligence, wisdom, luck, vitality, endurance, dexterity
  4. Use ability(ies) to name any or all of the 4 value passive1, passive2, active1, active2
  5. Use stat(s) as a generic term for any or all the characteristics of a hero (traits, abilities, HP, MP, stamina, etc)
  6. A function should support all realms, except if contracts differs across realms
  7. All hardcoded addresses should be CheckSummed
  8. Use logging, not print
  9. No other third-party libraries (if really needed, please explain why in the PR)
  10. A short & meaningful comment is better than a long & unfathomable documentation

Hero contract

The hero contract is accessible with hero/hero.py

Quickstart

hero_example.py

Transfer

Transfer a hero from one address to another

Info

Hero's data can be retrieved with the get_hero method. A more human-friendly format can be generated by passing the result of get_hero to the human_readable_hero method.

Owner

The owner of a hero can be retrieved with the method get_owner

Profile contract

The profile contract is accessible with profile/profile_v2.py

Quickstart

profile_example.py

In-game profile

In-game profile can be retrieved with the get_profile method

Summoning contract

The summoning contract is accessible with summoning/summoning.py

Quickstart

summoning_example.py

Create crystal

Summoning crystal are created with summon_crystal method

Crystal id

Crystal id can be retrieved with get_user_crystal_ids method

Open summoning crystal

Summoning crystal can be open with open_crystal method

Rent auction

Put a hero up for hire with put_hero_for_rent and cancel with cancel_rent Use is_on_rent and get_rent_auction to monitor auction

Gene science contract

The gene science contract is accessible with genes/gene_science_v2.py

Quickstart

genes_example.py

Mix genes

Statistics and visual of summoned hero can be forecasted with the mix_genes method. Note that mix_genes is pseudo random and the resulting traits will be different for each block. However, a statistical analysis can be used to optimize the summoning of desirable traits

Auction contract

The hero sale auction contract is accessible with auctions/hero/sale_auctions.py The hero rent auction contract is accessible with auctions/hero/rent_auctions.py Generic sale auction (ex: land) contract are accessible with auctions/auction.py

Quickstart

auction_example.py land_example.py

Sale auction

bid_hero and get_auction interact directly with the contract.

get_recent_open_auctions and get_hero_open_auctions use Graphql.

Rent auction

get_recent_open_auctions and get_hero_open_auctions use Graphql.

Quest

All quest contracts are located in module quests

Quickstart

quest_example.py

Foraging & Fishing quest

Each quest requires at least 7 stamina to complete. Check the current stamina of any given hero with get_current_stamina. Start the quest with start_quest. The second parameter is the number of attempt. To optimize the cost of gas, it is recommended to use a hero at full stamina and do 3 attempts every call.

Uses V2 quest

Gardening & Mining quest

Gardening and mining quest can be started with just one stamina. Mining quest can be done with up to 6 heroes while only 1 hero at a time can be sent on a gardening quest to a specific garden (liquidity pool).

Uses V1 quest

Legacy wishing well quest

wishing_well_quest_example.py

DEX & tokens

In game tokens and AMM exchange are available in module dex

Quickstart

dex_example.py

Balance of token

Use dex.erc20.balance_of to retrieve the balance of an item for the specified address

Liquidity pool

Use wrapper class dex.uniswap_v2_pair.UniswapV2Pair and call expected_amount0 to get the estimated amount of token0 received in exchange of token1. Alternatively, call dex.uniswap_v2_router.quote

Swap token

Use call dex.uniswap_v2_router.swap_exact_tokens_for_eth to swap erc20 token for ONE. Use call dex.uniswap_v2_router.swap_exact_tokens_for_tokens to swap erc20 tokens for other erc20 tokens.

Staking pool

Use wrapper class dex.master_gardener.Garden to retrieve staking pool info

Meditation circle

Meditation circle contract is accessible with meditation/meditation.py

Quickstart

meditation_example.py

Hero level up

Use start_meditation and complete_meditation to level up a hero. Make sure to have enough rune for the hero's level with get_required_runes

Duel

All duel contracts are located in module duel

Quickstart

duel_example.py

Raffle master

All raffle contracts are located in module raffle

Quickstart

raffle_example.py

Pets

All pet related contracts are located in module pets

Use pet.py to manage pet NFT

Use hatchery.py to hatch pet egg

Use exchange.py to exchange 2 pets for an egg

Quickstart

pet_example.py

Bridge

All bridge contracts are located in module bridge

Be careful to not mix up RPCs when dealing with multichain transaction

Quickstart

bridge_example.py

dfktools's People

Contributors

0rtis avatar athiriyya avatar chimupaul avatar hmcdias avatar kanasite avatar markperkins avatar mrzipper7 avatar sammyd24 avatar semok95 avatar xxlongzaixx avatar youraveragelord avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

dfktools's Issues

Not getting Gaia's Tears on wishing well / Auction tool not working

I was using wishing well tool for exping heroes. After few days I've noticed that tears gain drastically dropped. Many complete quest transactions were revered. Every revered quest had mined gaia's tears in internal transaction log. Another attempt to finish this quest was succeed but without additional xp/tears.
reverted tears.txt
succeed quests.txt
I figured out that reason of reverting quests with mined tears was lack of maxGasUsed variable in buildTransaction:

tx = contract.functions.completeQuest(hero_id).buildTransaction(
        {'gasPrice': w3.toWei(gas_price_gwei, 'gwei'), 'nonce': `nonce})

after adding maxGasUsed heroes normally started to earn bonus XP and tears

tx = contract.functions.completeQuest(hero_id).buildTransaction(
        {'gasPrice': w3.toWei(gas_price_gwei, 'gwei'), 'nonce': nonce, 'gas': 600000})

Another issue is that auction tool stopped working since they changed graphql query. Unfortunately I have no skills to fix this

Golding Mining Quest Contract not current

When attempting to send heroes on the gold mining quest with the following code:

questV2.start_quest(quest_contract, group, attempts, level, private_key, w3.eth.getTransactionCount(account_address), gas_price_gwei, tx_timeout)

The following error occurs:

execution reverted: quest not active

startQuest() on new fishing/foraging contract

startQuest() does not work for me on the new contract

Start Quest (Uint256[], Address, Uint8, Uint8)
seems like a 4th input is needed. just in case it helps:
hex:'0x8a2da17b0000000000000000000000000000000000000000000000000000000000000080
000000000000000000000000b465f4590095dad50fee6ee0b7c6700ac2b04df8 <- new fishing/foraging address
0000000000000000000000000000000000000000000000000000000000000001 <- number of quests
0000000000000000000000000000000000000000000000000000000000000000 <- (quest level?)
0000000000000000000000000000000000000000000000000000000000000002 <- number of heroes
00000000000000000000000000000000000000000000000000000000HERO_ID1
00000000000000000000000000000000000000000000000000000000HERO_ID2'

profession quests

Hello.
I'm not a professional python programmer but i've made profession questing (based on your wishing_well.py). It works fine but it may containes some newbie bugs. I hope it will be useful for ur project.
https://pastebin.com/xVNqQwwr

saleAuctions is not recent data

This isn't an issue with this code but rather the graphql query. When I use saleAuctions the most recent data is a few days old. Am I doing something wrong?

I'm using get_open_auctions as is.

How to retrieve latest hero purchases?

Hi, in the spirit of DFK Heroes Price Prediction, I would like to retrieve the last N purchases of heroes together with their paid price. From them, I already know how to query for IDs and get all the hero stats ("hero_example.py"), but I do not know how to do the first step.

Is this possible with "dfktools"?

Many thanks

Example for querying price of a token pair?

Can someone write a quick example for how to query the current price of a token pair? I fail to understand the get_amount_in function in dex/uniswap_v2_router.py or how to pass what tokens I want or what the reserve values are supposed to be. I've read the uniswap docs and its still a complete mystery to me

Unable to call functions with Crystalvale's JEWEL address. ERROR: InsufficientDataBytes: Tried to read 32 bytes. Only got 0 bytes

Attempting to use CV's JEWEL address in any functions that uses "token_address" as the variable causes the error "InsufficientDataBytes: Tried to read 32 bytes. Only got 0 bytes".

`import dfktools.dex.erc20 as tokens
import logging
import sys
from web3 import Web3
log_format = '%(asctime)s|%(name)s|%(levelname)s: %(message)s'

logger = logging.getLogger("DFK-erc20")
logger.setLevel(logging.DEBUG)
logging.basicConfig(level=logging.INFO, format=log_format, stream=sys.stdout)

rpc_server = 'https://subnets.avax.network/defi-kingdoms/dfk-chain/rpc'
logger.info("Using RPC server " + rpc_server)

w3 = Web3(Web3.HTTPProvider(rpc_server))

realm = 'crystalvale'
crystalvale_items = tokens.get_realm_item_list(realm)
logger.info('{} items in {}'.format(len(serendale_items), realm))
token_address = tokens.symbol2address('JEWEL', realm)
name = tokens.name(token_address, rpc_server)
`

^Errors out at "tokens.name(token_address, rpc_server)" or any other functions that uses CV JEWEL's token address. Functions work for other token addresses that is not CV JEWEL. i.e. CV Crystal address works fine.

Any ideas?

pip package

Have you considered build this package and upload to pip so it's easier to use as a lib? Thanks.

question

Is there a way to search thru the entire hero catalog?

How to start crystalvale mining quest or v1 quests

There is no info on how to start v1 quests for crystalvale like mining, also it seems that quest_core_v1 needs to be updated as to reflect the changes. If anyone can help us please let us know in a comment

dfktear address fix

it should be: DFKTEAR = "0x24eA0D436d3c2602fbfEfBe6a16bBc304C963D04" in items

Quest cannot be started: "Error execution reverted: level not found"

level = 1
questV2.start_quest(quest_contract, my_heroes_id, attempts, level, private_key, w3.eth.getTransactionCount(account_address), gas_price_gwei, tx_timeout)

What is the level? Tried it with the current level of the hero, but this didn't work and currently I don't know what I need to enter there.

Error Message is always: "Error execution reverted: level not found"

Single quest support

Hi,

any plans to add a single quest support (for example gardening, probably mining, etc)?

Thanks for this nice repo

Quest is not working. Error:"is not in the chain after 30 seconds"

I guess I'm doing something wrong, but I tried the quest_example.py and changed the PrivateKey and heros_id

Error I receive:

2022-02-10 09:00:38,248|DFK-quest|INFO: Waiting for transaction https://explorer.harmony.one/tx/ to be mined
Traceback (most recent call last):
File "/home/environments/dfk/lib/python3.8/site-packages/web3/eth.py", line 740, in wait_for_transaction_receipt
_timeout.sleep(poll_latency)
File "/home/environments/dfk/lib/python3.8/site-packages/web3/_utils/threads.py", line 89, in sleep
self.check()
File "/home/environments/dfk/lib/python3.8/site-packages/web3/_utils/threads.py", line 82, in check
raise self
web3._utils.threads.Timeout: 30 seconds

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "test.py", line 35, in
quest.start_quest(quest_contract, my_heroes_id, 3, private_key, w3.eth.getTransactionCount(account_address), gas_price_gwei, tx_timeout)
File "/home/environments/dfk/code/quest/quest.py", line 10, in start_quest
return quest_core.start_quest(quest_address, hero_ids, attempts, private_key, nonce, gas_price_gwei, tx_timeout_seconds, self.rpc_address, self.logger)
File "/home/environments/dfk/code/quest/quest_core.py", line 86, in start_quest
tx_receipt = w3.eth.wait_for_transaction_receipt(transaction_hash=signed_tx.hash, timeout=tx_timeout_seconds,
File "/home/environments/dfk/lib/python3.8/site-packages/web3/eth.py", line 744, in wait_for_transaction_receipt
raise TimeExhausted(
web3.exceptions.TimeExhausted: Transaction HexBytes('') is not in the chain after 30 seconds

If I go to the explorer link, I also don't see the transaction.

I guess I'm missing something?

cant read some hero data

I am trying to read data for hero #58642

when I try to get his current stamina i get error

Traceback (most recent call last):
File "c:_code\Python\dfk_multi_questing\src\dfktools\src\dfktools\quest_example.py", line 68, in
hero_stam = questV2.get_current_stamina(hero_id)
File "c:_code\Python\dfk_multi_questing\src\dfktools\src\dfktools\quests\quest_v2.py", line 42, in get_current_stamina
return quest_core_v2.get_current_stamina(self.quest_core_contract_address, hero_id, self.rpc_address)
File "c:_code\Python\dfk_multi_questing\src\dfktools\src\dfktools\quests\quest_core_v2.py", line 320, in get_current_stamina
result = contract.functions.getCurrentStamina(hero_id).call()
File "C:\Python\lib\site-packages\web3\contract.py", line 957, in call
return call_contract_function(
File "C:\Python\lib\site-packages\web3\contract.py", line 1501, in call_contract_function
return_data = web3.eth.call(
File "C:\Python\lib\site-packages\web3\module.py", line 57, in caller
result = w3.manager.request_blocking(method_str,
File "C:\Python\lib\site-packages\web3\manager.py", line 198, in request_blocking
return self.formatted_response(response,
File "C:\Python\lib\site-packages\web3\manager.py", line 170, in formatted_response
apply_error_formatters(error_formatters, response)
File "C:\Python\lib\site-packages\web3\manager.py", line 70, in apply_error_formatters
formatted_resp = pipe(response, error_formatters)
File "cytoolz\functoolz.pyx", line 667, in cytoolz.functoolz.pipe
File "cytoolz\functoolz.pyx", line 642, in cytoolz.functoolz.c_pipe
File "C:\Python\lib\site-packages\web3_utils\method_formatters.py", line 576, in raise_solidity_error_on_revert
raise ContractLogicError(response['error']['message'])
web3.exceptions.ContractLogicError: execution reverted

this is both on DFK and Klaytn


when I try to read owner of this hero i get error

Traceback (most recent call last):
File "c:_code\Python\dfk_multi_questing\src\dfktools\src\dfktools\hero_example.py", line 57, in
owner = crystalvale_heroes.get_owner(cv_hero_id)
File "c:_code\Python\dfk_multi_questing\src\dfktools\src\dfktools\hero\hero.py", line 14, in get_owner
return hero_core.get_owner(self.contract_address, hero_id, self.rpc_address, block_identifier)
File "c:_code\Python\dfk_multi_questing\src\dfktools\src\dfktools\hero\hero_core.py", line 124, in get_owner
return str(contract.functions.ownerOf(hero_id).call(block_identifier=block_identifier))
File "C:\Python\lib\site-packages\web3\contract.py", line 957, in call
return call_contract_function(
File "C:\Python\lib\site-packages\web3\contract.py", line 1501, in call_contract_function
return_data = web3.eth.call(
File "C:\Python\lib\site-packages\web3\module.py", line 57, in caller
result = w3.manager.request_blocking(method_str,
File "C:\Python\lib\site-packages\web3\manager.py", line 198, in request_blocking
return self.formatted_response(response,
File "C:\Python\lib\site-packages\web3\manager.py", line 170, in formatted_response
apply_error_formatters(error_formatters, response)
File "C:\Python\lib\site-packages\web3\manager.py", line 70, in apply_error_formatters
formatted_resp = pipe(response, error_formatters)
File "cytoolz\functoolz.pyx", line 667, in cytoolz.functoolz.pipe
File "cytoolz\functoolz.pyx", line 642, in cytoolz.functoolz.c_pipe
File "C:\Python\lib\site-packages\web3_utils\method_formatters.py", line 576, in raise_solidity_error_on_revert
raise ContractLogicError(response['error']['message'])
web3.exceptions.ContractLogicError: execution reverted: ERC721: owner query for nonexistent token


when i try to read hero data I get a result but all attributes are 0

{'id': 58642, 'summoningInfo': {'summonedTime': 0, 'nextSummonTime': 0, 'summonerId': 0, 'assistantId': 0, 'summons': 0, 'maxSummons': 0}, 'info': {'statGenes': 0, 'visualGenes': 0, 'rarity': 0, 'shiny': False, 'generation': 0, 'firstName': 0, 'lastName': 0, 'shinyStyle': 0, 'class': 0, 'subClass': 0}, 'state': {'staminaFullAt': 0, 'hpFullAt': 0, 'mpFullAt': 0, 'level': 0, 'xp': 0, 'currentQuest': '0x0000000000000000000000000000000000000000', 'sp': 0, 'status': 0}, 'stats': {'strength': 0, 'intelligence': 0, 'wisdom': 0, 'luck': 0, 'agility': 0, 'vitality': 0, 'endurance': 0, 'dexterity': 0, 'hp': 0, 'mp': 0, 'stamina': 0}, 'primaryStatGrowth': {'strength': 0, 'intelligence': 0, 'wisdom': 0, 'luck': 0, 'agility': 0, 'vitality': 0, 'endurance': 0, 'dexterity': 0, 'hpSm': 0, 'hpRg': 0, 'hpLg': 0, 'mpSm': 0, 'mpRg': 0, 'mpLg': 0}, 'secondaryStatGrowth': {'strength': 0, 'intelligence': 0, 'wisdom': 0, 'luck': 0, 'agility': 0, 'vitality': 0, 'endurance': 0, 'dexterity': 0, 'hpSm': 0, 'hpRg': 0, 'hpLg': 0, 'mpSm': 0, 'mpRg': 0, 'mpLg': 0}, 'professions': {'mining': 0, 'gardening': 0, 'foraging': 0, 'fishing': 0}}


hero works normally in the games official interface and shows all data in dfk tools so it must be accessible through the rpc calls

all code works fine with all other hero IDs i tried

I sent hero to different account and bridged from klaytn to serendale, it still behaves the same

Issue with bid_hero

I am trying to use the auction modules, but when trying to call bid_hero I get this error.

image

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.