From ebfc56c55b519bdd1d30b1fe0b8c154607debccd Mon Sep 17 00:00:00 2001 From: malikkulsoom <66032209+malikkulsoom@users.noreply.github.com> Date: Thu, 16 Nov 2023 13:14:20 +0500 Subject: [PATCH] [EXC-1873] Update Adjust Leverage To Sign Transaction & Make API Call (#42) * Updated adjust leverage method * Bumped version --------- Co-authored-by: Kulsoom Malik Co-authored-by: Kulsoom Malik --- pyproject.toml | 2 +- src/bluefin_v2_client/client.py | 28 +++++++++++++++++++++++----- src/bluefin_v2_client/contracts.py | 2 +- 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 89f46f7..3f877a1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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" diff --git a/src/bluefin_v2_client/client.py b/src/bluefin_v2_client/client.py index 9c5a490..51040d8 100644 --- a/src/bluefin_v2_client/client.py +++ b/src/bluefin_v2_client/client.py @@ -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"], diff --git a/src/bluefin_v2_client/contracts.py b/src/bluefin_v2_client/contracts.py index 4ad1d69..ab9c9cc 100644 --- a/src/bluefin_v2_client/contracts.py +++ b/src/bluefin_v2_client/contracts.py @@ -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"]