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 fibrous-python via Pip.
pip install fibrous-python
Or
git clone https://github.com/Fibrous-Finance/router-python-sdk
cd fibrous_python
pip install .
Usage
Create Fibrous client:
from fibrous_python import FibrousClient
client = FibrousClient()
# or you can specify custom API url (you probably 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.
chainName="" #starknet or scroll
tokens = client.supported_tokens(chainId)
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:
chainName="" #starknet or scroll
tokens = client.supported_tokens(chainId)
route = client.get_best_route(amount=10**12,
token_in_address=tokens["eth"].address,
token_out_address=tokens["usdc"].address),
chainName
route
# expected output:
RouteSuccess(
success=True,
inputToken=Token(...),
inputAmount='1000000000000',
outputToken=Token(...),
outputAmount='4117',
route=[Route...],
Slippage(input_token_value=0.00381994, output_token_value=0.005948858756000001, slippage=0.5573173285444276),
estimatedGasUsed='8975364622720',
bestQuotesByProtocols=['3821', '3876', '3815', '3878', '3838', '4117', '3883', '0', '3838', '5467'],
time=1.354,
initial=True
)
The slippage object contains the slippage value calculated by processing the input/output amount and token prices. In the example, the slipage object shows that the value of the tokens we send to fibrous is $0.00381, in return we will receive an output token with a value of $0.0059 and we will profit 55.73% from this transaction.
Slippage(input_token_value=0.00381994, output_token_value=0.005948858756000001, slippage=0.5573173285444276)
Build transaction:
chainName="" # Chain name should be "starknet" for StarkNet and "scroll" for Scroll
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",
chain_name
)
# expected output:
Call(
to_addr=436333995167355148017722927569021171726157728206902557777108018048487382874,
selector=602962535134499854912799851629033993488593928113527484350375636311213640489,
calldata=[int, int, int....]
)
Swap example 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 fibrous_python.core import FibrousClient
from fibrous_python.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)
chainName="starknet"
client = FibrousClient()
tokens = client.supported_tokens(chainName)
# amount to swap
amount: int = int(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,
chainName)
# 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())
Metadata
Release files for fibrous-python 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| fibrous-python-0.1.0.tar.gz | 11.1 kB | Without provenance | Details for fibrous-python-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| fibrous_python-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for fibrous_python-0.1.0-py3-none-any.whl |
Total release size: 22.9 kB
Release files / fibrous-python-0.1.0.tar.gz
| Download URL | fibrous-python-0.1.0.tar.gz |
|---|---|
| Size | 11.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
746ebb6c07ddbd4734845355dc7f5acb6b74b4872183b0c736443b8b00b6c9e1
|
|
BLAKE2b-256 checksum How to use checksums |
79c70fdc5af87395c6844c662dec307b617686d7cb788320c5154fdd696e1857
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.10.0
|
Release files / fibrous_python-0.1.0-py3-none-any.whl
| Download URL | fibrous_python-0.1.0-py3-none-any.whl |
|---|---|
| Size | 11.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
80a102af178618d348a04e1e0d75a37302488df98eea8f23673ef2603269b9a9
|
|
BLAKE2b-256 checksum How to use checksums |
66041e63c7b520da5083fcb65d7eee539ff228b6dbddf0e159e0a42a2f3d493c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.10.0
|
Security for fibrous-python 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.