Skip to content

Commit

Permalink
[EXC-1873] Update Adjust Leverage To Sign Transaction & Make API Call (
Browse files Browse the repository at this point in the history
…#42)

* Updated adjust leverage method

* Bumped version

---------

Co-authored-by: Kulsoom Malik <kulsoommalik@ip-192-168-0-116.ec2.internal>
Co-authored-by: Kulsoom Malik <kulsoommalik@Kulsooms-MacBook-Pro-2.local>
  • Loading branch information
3 people authored Nov 16, 2023
1 parent 301cab1 commit ebfc56c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "bluefin_v2_client"
version = "4.2.2"
version = "4.2.3"
description = "Library to interact with Bluefin exchange protocol including its off-chain api-gateway and on-chain contracts"
readme = "README.md"
requires-python = ">=3.8"
Expand Down
28 changes: 23 additions & 5 deletions src/bluefin_v2_client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -511,11 +511,29 @@ async def adjust_leverage(self, symbol, leverage, parentAddress: str = ""):
typeArguments=[self.contracts.get_currency_type()],
)
signature = self.contract_signer.sign_tx(txBytes, self.account)
result = rpc_sui_executeTransactionBlock(self.url, txBytes, signature)
if result["result"]["effects"]["status"]["status"] == "success":
return True
else:
return False
separator = "||||" # Choose a separator that won't appear in txBytes or signature
combined_data = f"{txBytes}{separator}{signature}"
encoded_data = combined_data.encode().hex()
res = await self.apis.post(
SERVICE_URLS["USER"]["ADJUST_LEVERAGE"],
{
"symbol": symbol.value,
"address": account_address,
"leverage": to_base18(leverage),
"marginType": MARGIN_TYPE.ISOLATED.value,
"signedTransaction": encoded_data
},
auth_required=True,
)
# If API is unsuccessful make direct contract call to update the leverage
if 'error' in res:
result = rpc_sui_executeTransactionBlock(self.url, txBytes, signature)
if result["result"]["effects"]["status"]["status"] == "success":
return True
else:
return False

return res

res = await self.apis.post(
SERVICE_URLS["USER"]["ADJUST_LEVERAGE"],
Expand Down
2 changes: 1 addition & 1 deletion src/bluefin_v2_client/contracts.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def get_perpetual_id(self, market: MARKET_SYMBOLS):
return self.contract_info[market.value]["Perpetual"]["id"]

def get_sequencer_id(self) -> str:
return self.contract_info["objects"]["Sequencer"]["id"]
return self.contracts_global_info["Sequencer"]["id"]

def get_position_table_id(self, market: MARKET_SYMBOLS) -> str:
return self.contract_info[market.value]["PositionsTable"]["id"]

0 comments on commit ebfc56c

Please sign in to comment.