Skip to content

Commit

Permalink
bup v1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
0xKermo committed May 4, 2024
0 parents commit aa76462
Show file tree
Hide file tree
Showing 33 changed files with 6,757 additions and 0 deletions.
Binary file added .DS_Store
Binary file not shown.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/.pylintrc
/.venv
/.vscode
/pylint.rc
**/__pycache__
/dist
21 changes: 21 additions & 0 deletions LICENCE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 Fibrous Finance

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<p align="center">
<a href="https://fibrous.finance">
<img src="./docs/assets/logo.png" width="400px" >
</a>
</p>

# Fibrous Finance Limit Order Python SDK (v1.0.0)

The Fibrous Finance Limit Order SDK is a Python library that provides tools and functionalities for interacting with the Fibrous Finance Limit Order protocol. It allows developers to programmatically access and utilize various features of the protocol, such as retrieving orders, placing orders, canceling orders, and more.


## Installation

```bash
pip install fibrous_limit_order
```

## Documentation

The complete documentation for the Fibrous Finance Limit Order SDK can be found [here](https://docs.fibrous.finance/fibrous-solutions/fibrous-limit-order).

## Contributing

Contributions to the Fibrous Finance Limit Order SDK are welcome! If you find any issues or have suggestions for improvement, feel free to open an issue or submit a pull request.

## License

This project is licensed under the MIT License.
54 changes: 54 additions & 0 deletions docs/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Contributing

Thank you for considering contributing to Fibrous SDK!
We appreciate your time and effort.
Please take a moment to review the guidelines below.

## Issue Tracker

If you find any bugs or have a feature request, please open an issue on the [issue tracker](https://github.com/Fibrous-Finance/limit-order-sdk/issues). We welcome bug reports, feature suggestions, and pull requests.

## Pull Requests

1. Fork the repository and create your branch from `main`.
2. Make sure your code follows our code style and conventions.
3. Ensure that your commits are concise, well-documented, and address a specific issue.
4. Commit messages should follow the format:

```
fix: Brief description of the fix
feat: Brief description of the feature
chore: Non-breaking change
```

For example:

```
fix: Correct the typo in the README file
feat: Implement a new authentication module
chore: Update dependencies to the latest version
```

5. If your pull request addresses an issue, reference it using the syntax `Fixes #issue_number` in the commit message.
6. Push your changes to your forked repository.
7. Submit a pull request to the `main` branch of the original repository.
8. Provide a clear and descriptive title for your pull request and explain the motivation behind the changes.
9. Be responsive to any feedback or questions that may arise during the review process.

## Code Style and Conventions

Please adhere to the following guidelines when submitting code:

- Use 4 spaces for indentation.
- Follow the naming conventions for variables, functions, and classes.
- Write clear and concise comments to explain the code's intent.
- Keep code lines within a reasonable length (usually less than 80 characters).
- Avoid unnecessary dependencies and ensure all external packages are properly licensed.

## License

By contributing to this project, you agree that your contributions will be licensed under the [project's license](../LICENSE).

## Conclusion

We greatly appreciate your contribution! Your efforts will help make this project even better. If you have any questions or need further assistance, please don't hesitate to reach out.
Binary file added docs/assets/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions fibrous_limit_order/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .src import *
1 change: 1 addition & 0 deletions fibrous_limit_order/src/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .limit_order import *
Empty file.
23 changes: 23 additions & 0 deletions fibrous_limit_order/src/examples/cancel_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import sys
import os
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

import asyncio
from starknet_py.net.client_models import Call
from limit_order.limit_order import LimitOrder
from limit_order.mock_data import RPC_URL, ACCOUNT_PRIVATE_KEY, ACCOUNT_PUBLIC_KEY
from limit_order.accounts import account

async def cancel_order():
limit_order = LimitOrder(RPC_URL)
nonce = await limit_order.get_nonce(ACCOUNT_PUBLIC_KEY)
cancel_order_call_data: Call = await limit_order.cancel_order(nonce['data'])
my_account = account(RPC_URL, ACCOUNT_PUBLIC_KEY, ACCOUNT_PRIVATE_KEY, '1')
tx_hash = await my_account.execute_v1(cancel_order_call_data)
print(f'tx_hash: {tx_hash}')

def main():
asyncio.run(cancel_order())

if __name__ == '__main__':
main()
20 changes: 20 additions & 0 deletions fibrous_limit_order/src/examples/fill_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import sys
import os
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

import asyncio
from fibrous_limit_order import *

async def fill_order(orderHash, fill_amount=None):
limit_order = LimitOrder()
response = await limit_order.fill_order(orderHash, fill_amount)
print(response)
return response

FILL_AMOUNT = str(1000000000000000000)

def main():
asyncio.run(fill_order('orderHash', FILL_AMOUNT))

if __name__ == '__main__':
main()
37 changes: 37 additions & 0 deletions fibrous_limit_order/src/examples/full_create_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import sys
import os
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

import asyncio
from fibrous_limit_order import *


async def full_place_order():
limit_order = LimitOrder(RPC_URL)

sign_message_resp: SignMessageResponse = await limit_order.sign_message(mock_order)
my_account = account(RPC_URL, ACCOUNT_PUBLIC_KEY, ACCOUNT_PRIVATE_KEY, '1')

signed_message: any = my_account.sign_message(sign_message_resp.typedData)

approve_call_data = await limit_order.approve_order_amount(mock_order.maker_asset, mock_order.maker_amount)

#tx_hash = await my_account.execute_v1(approve_call_data, auto_estimate = True)

mock_order.order_hash = hex(sign_message_resp.orderHash)
mock_order.signature = [str(signed_message[0]), str(signed_message[1])]

place_order_resp = await limit_order.place_order(mock_order)

print(f'sign_message_resp: {sign_message_resp}')
print(f'signed_message: {signed_message}')
print(f'approve_call_data: {approve_call_data}')
print(f'mock_order: {mock_order}')
print(f'place_order_resp: {place_order_resp}')
print(f'status: {place_order_resp["status"]} code {place_order_resp["code"]}')

def main():
asyncio.run(full_place_order())

if __name__ == '__main__':
main()
45 changes: 45 additions & 0 deletions fibrous_limit_order/src/examples/full_fill_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import sys
import os
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

import asyncio
import aiohttp
from fibrous_limit_order import *


async def full_fill_order():
limit_order = LimitOrder(RPC_URL)
my_account = account(RPC_URL, ACCOUNT_PUBLIC_KEY, ACCOUNT_PRIVATE_KEY, '1')

orders = await limit_order.get_orders({'maker_asset': '0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7'})
fill_amount = 10000 # ETH makerAmount of order
selected_order = orders.data[0]

async with aiohttp.ClientSession() as session:
async with session.get('https://graph.fibrous.finance/tokens') as tokens:
tokens_data = await tokens.json()

print(utils.order_to_human_readable(selected_order, tokens_data))

fill_order_resp = await limit_order.fill_order(selected_order.order_hash, str(fill_amount))
if fill_order_resp['status'] != 'success':
print('Error message: ', fill_order_resp['message'])
return

fill_order_call_data = {
'contractAddress':limit_order.default_contract_address,
'entrypoint':'fillOrder',
'calldata':fill_order_resp['data']
}

approve_call_data = await limit_order.approve_order_amount(selected_order.taker_asset, int(selected_order.taker_amount))
call_data = [approve_call_data, fill_order_call_data]
tx_hash = await my_account.execute_v1(call_data, auto_estimate = True)

print(tx_hash)

def main():
asyncio.run(full_fill_order())

if __name__ == '__main__':
main()
25 changes: 25 additions & 0 deletions fibrous_limit_order/src/examples/get_nonce.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import sys
import os
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

import asyncio
import timeit
from fibrous_limit_order import *


async def get_nonce() -> NonceResponse:
limit_order = LimitOrder()
nonce = await limit_order.get_nonce(WALLET_ADDRESS)
print(nonce)

async def run_code():
start_time = timeit.default_timer()
await get_nonce()
end_time = timeit.default_timer()
print(f"Execution time: {end_time - start_time} seconds")

def main():
asyncio.run(run_code())

if __name__ == '__main__':
main()
37 changes: 37 additions & 0 deletions fibrous_limit_order/src/examples/get_orders.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import sys
import os


import asyncio
import aiohttp

from fibrous_limit_order import *

async def get_orders() -> GetOrdersResponse:
limit_order = LimitOrder()
filters: OrdersFilter = {
'wallet_address': '',
'makerAsset': '',
'takerAsset': '',
'makerAmount': '',
'takerAmount': '',
'orderPrice': '',
'page': 1,
'pageSize': 10,
}

open_orders: GetOrdersResponse = await limit_order.get_orders(filter=None)
async with aiohttp.ClientSession() as session:
async with session.get('https://graph.fibrous.finance/tokens') as response:
tokens_data = await response.json()

# Convert the first order to human readable format
human_readable_order = utils.order_to_human_readable(open_orders.data[0], tokens_data)
print('humanReadableOrder', human_readable_order)
return open_orders

def main():
asyncio.run(get_orders())

if __name__ == '__main__':
main()
19 changes: 19 additions & 0 deletions fibrous_limit_order/src/examples/get_remaining_amount.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import sys
import os
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

import asyncio
from fibrous_limit_order import *


async def get_remaining_amount(orderHash):
limit_order = LimitOrder(RPC_URL)
remaining_amount = await limit_order.get_remaining_amount(orderHash)
print(remaining_amount)
return remaining_amount

def main():
asyncio.run(get_remaining_amount('order_hash'))

if __name__ == '__main__':
main()
34 changes: 34 additions & 0 deletions fibrous_limit_order/src/examples/place_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import sys
import os
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

import asyncio
from fibrous_limit_order import *


async def place_order(_order) -> PlaceOrderResponse:
limit_order = LimitOrder()
response = await limit_order.place_order(_order)
print(response)
return response

order = Order(
signer='0x00c2fd8e',
maker_asset='0x00c2fd8e',
taker_asset='0x00c2fd8e',
maker_amount=1000000000000000000,
taker_amount=1000000000000000000,
order_price=2770000000000000000000, # price of the maker asset in terms of the taker asset (unit amount)
expiration=convert_date_to_unix_timestamp(days=1), # expiration in 1 day
use_solver=False, # if true, the order will be executed with the solver
partial_fill=True, # if true, the order will be partially filled
nonce=1, # ref. ./getNonce.ts
order_hash='order_hash', # ref. ./signMessage.ts
signature=['sig_r', 'sign_s'] # ref. ./signMessage.ts
)

def main():
asyncio.run(place_order(order))

if __name__ == '__main__':
main()
23 changes: 23 additions & 0 deletions fibrous_limit_order/src/examples/sign_message.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import sys
import os
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

import asyncio
from fibrous_limit_order import *


async def sign_message(_mock_order) -> SignMessageResponse:
limit_order = _limit_order.LimitOrder(RPC_URL)

sign_message_resp: SignMessageResponse = await limit_order.sign_message(_mock_order)

for key, value in sign_message_resp.__dict__.items():
print(f'{key}: {value}')

return sign_message_resp

def main():
asyncio.run(sign_message(mock_order))

if __name__ == "__main__":
main()
Loading

0 comments on commit aa76462

Please sign in to comment.