Fibrous Finance Python Client.
Project description
Fibrous Finance Router Client for Python
Python client for Fibrous Router. It makes it easy to get the tokens and protocols supported by Fibrous, choose the best route for your swap from the Fibrous API and build those swap transactions. Compatible with Starknetpy.
Installation
You can install fibrouspy via Pip.
pip install fibrouspy
Or
git clone https://github.com/hkey0/fibrous-py
cd fibrous-py
pip install .
Usage
Create Fibrous client:
from fibrouspy import FibrousClient
client = FibrousClient()
# or you can specify custom rpc url (you probably you won't need this)
client = FibrousClient(route_url="https://api.fibrous.finance",
graph_url="https://graph.fibrous.finance",
router_address="0x00f6f4CF62E3C010E0aC2451cC7807b5eEc19a40b0FaaCd00CCA3914280FDf5a")
Get supported tokens by Fibrous.
tokens = client.supported_tokens()
tokens["eth"]
# expected output:
Token(
address='0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7',
name='Ether',
symbol='eth',
decimals=18,
price='3841.3',
imageUrl='https://assets.coingecko.com/coins/images/279/small/ethereum.png?1696501628',
valuable=True,
verified=True,
category=None
)
Get best route:
tokens = client.supported_tokens()
route = client.get_best_route(amount=10**12,
token_in_address=tokens["eth"].address,
token_out_address=tokens["usdc"].address)
route
# expected output:
RouteSuccess(
success=True,
inputToken=Token(...),
inputAmount='1000000000000',
outputToken=Token(...),
outputAmount='4117',
route=[Route...],
estimatedGasUsed='8975364622720',
bestQuotesByProtocols=['3821', '3876', '3815', '3878', '3838', '4117', '3883', '0', '3838', '5467'],
time=1.354,
initial=True
)
Build transaction:
tokens = client.supported_tokens()
swap_call = client.build_transaction(input_amount=10**12,
token_in_address=tokens["eth"].address,
token_out_address=tokens["usdc"].address,
slippage=0.01,
# starknet address
destination="0x07bfe36393355f52844e45622ef0f0fd9bcb18c63f9004060effc8cc0970f8e1")
# expected output:
Call(
to_addr=436333995167355148017722927569021171726157728206902557777108018048487382874,
selector=602962535134499854912799851629033993488593928113527484350375636311213640489,
calldata=[int, int, int....]
)
An example swap with Starknet.py
import asyncio
from starknet_py.net.account.account import Account
from starknet_py.net.full_node_client import FullNodeClient
from starknet_py.net.models.chains import StarknetChainId
from starknet_py.net.signer.stark_curve_signer import KeyPair
from fibrouspy.core import FibrousClient
from fibrouspy.utils import build_approve_call
async def main():
your_public_key = "0x123456"
your_private_key = "0x123456"
account0 = Account(
address=your_public_key,
client=FullNodeClient("https://rpc.starknet.lava.build:443"),
key_pair=KeyPair(private_key=your_private_key,
public_key=your_public_key),
chain=StarknetChainId.MAINNET)
client = FibrousClient()
tokens = client.supported_tokens()
# amount to swap
amount = 0.001 * (10**tokens["eth"].decimals)
# swap call
swap_call = client.build_transaction(
amount,
tokens["eth"].address,
tokens["usdc"].address,
0.01,
your_public_key)
# approve call
approve_call = build_approve_call(
token_address=tokens["eth"].address,
amount=amount)
txre = await account0.execute(calls=[approve_call,
swap_call],
max_fee=int(1e16))
print(f"Transaction hash: {hex(txre.transaction_hash)}")
if __name__ == "__main__":
asyncio.run(main())
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fibrouspy-0.1.0.tar.gz.
File metadata
- Download URL: fibrouspy-0.1.0.tar.gz
- Upload date:
- Size: 7.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.9.19
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1cbb82d6de47709fc9f6512720bc11ae10c5a0a252eb5a9b31fff4ffbc03b56d
|
|
| MD5 |
036e141ee2a376ed849ac834e1288d5a
|
|
| BLAKE2b-256 |
9d790224503ad76852e28c0291a60a1b5df65363b64ab5510696ce8aca57b5c6
|
File details
Details for the file fibrouspy-0.1.0-py3-none-any.whl.
File metadata
- Download URL: fibrouspy-0.1.0-py3-none-any.whl
- Upload date:
- Size: 8.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.9.19
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e6c7fc1b9641402c2c1c9b839e427f8a8444b8bc3e07d45b1c6937e91771a2c2
|
|
| MD5 |
2bc02793acd3d85945345e426f9d75d4
|
|
| BLAKE2b-256 |
06eda28e25171f14850c75ae714d48e6dff6c1fe30e7700826735fc0f529299f
|