Skip to content
This repository was archived by the owner on Jan 19, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions .github/workflows/publish_to_pypy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
name: publish_to_pypi
on:
push:
branches:
- quant-852
pull_request:
branches:
- main
types:
- closed
jobs:
build-n-publish:
#if: github.event.pull_request.merged == true
name: Build and publish Python 🐍 distributions 📦 to PyPI and TestPyPI
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: Set up Python 3.10
uses: actions/setup-python@v3
with:
python-version: "3.10"
- name: Install pypa/build
run: python -m pip install build --user
- name: Build a binary wheel and a source tarball
run: python -m build --sdist --wheel --outdir dist/ .
- name: Publish distribution 📦 to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_KEY }}
skip_existing: true
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build
6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"[python]": {
"editor.defaultFormatter": "ms-python.black-formatter",
"editor.formatOnSave": true
}
}
78 changes: 78 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# Changes w.r.t old library

## Initialisation change

1. The way we initialise is still the same, the difference is that NOW we give `SEED_PHRASE` as `TEST_ACCT_KEY`
2. Currently we support test phrase only and we sign it using ED25519

## Sockets

1. Nothing is changes in sockets except for the url link

## Signing (internal)

1. We do not sign our transaction using ETH library anymore. We now use `nacl` and `hashlib` in order to sign the messages.
2. For signing orders we sign it using the following scheme

1. Assuming we have the order with values in sui format.
2. We first get the `orderhash` of the order using the following method

```python flags = self.get_order_flags(order)
flags = hexToByteArray(numberToHex(flags,2))

buffer=bytearray()
orderPriceHex=hexToByteArray(numberToHex(int(order["price"])))
orderQuantityHex=hexToByteArray(numberToHex(int(order['quantity'])))
orderLeverageHex=hexToByteArray (numberToHex(int(order['leverage'])))
orderSalt=hexToByteArray(numberToHex(int(order['salt'])))
orderExpiration=hexToByteArray(numberToHex(int(order['expiration']),16))
orderMaker=hexToByteArray(numberToHex(int(order['maker'],16),64))
orderMarket=hexToByteArray(numberToHex(int(order['market'],16),64))
bluefin=bytearray("Bluefin", encoding="utf-8")

buffer=orderPriceHex+orderQuantityHex+orderLeverageHex+orderSalt+orderExpiration+orderMaker+orderMarket+flags+bluefin
```

3. We then get the sha256 of the buffer.hex()
4. We then sign it and append '1' to it, specifying that we signed it using ed25519

3. For signing onboarding signer we follow a different approach.

1. What is onboarding signer: When we are calling a Bluefin init function we sign a string using our private key and send it to bluefin exchange along with our public key, bluefin exchange verifies it and returns us a token.
2. For signing it we first convert our message to bytes and then add [3,0,0, len(message)] to the start of our bytearray and then our message. if our message length is greater than 256 then it wont fit in a byte in this case we follow BCS methodology to send our message.

4. For signing cancel order, there are two ways.
1. We first sign the order and send it to bluefin. Now we have the hash of the order. We first change our encode our hash to BCS format.
```python
sigDict={}
sigDict['orderHashes']=order_hash
encodedMessage=self.encode_message(sigDict)
```
2. Please have a look at signer.py to see the implementation or encode_message.
3. Then we sign the encodedMessage and send the signature to bluefin for cancelling order
5. For signing cancel order second method.
1. We sign the order and send it to bluefin, now imagine we do not have the hash of our order.
2. We resign our order and get the hash and then we follow the similar approach as above. Please have a look at `7.cancelling_orders.py` in our examples file.

## A detailed Guide on Onboarding:

1. Basically as explained earlier when sign the onboarding url and send it to bluefin, bluefin returns us the TOKEN.
2. The change in this repo is following.
3. ```python
# imagine msg="https://testnet.bluefin.io"
msgDict={}
msgDict['onboardingUrl']=msg
msg=json.dumps(msgDict,separators=(',', ':'))
# we first create a json something like this '{"onboardingURL":"https://testnet.bluefin.io"}

# we then convert this json to a bytearray
msg_bytearray=bytearray(msg.encode("utf-8"))
intent=bytearray()
#we then append [3,0,0,length of our json object] to our intent bytearray
intent.extend([3,0,0, len(msg_bytearray)])
intent=intent+msg_bytearray

# we then take a blake2b hash of intent bytearray we created
hash=hashlib.blake2b(intent,digest_size=32)
#then we finally sign the hash
```
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) [2022] [Seed Labs]

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.
Loading