This repository has been archived by the owner on Sep 28, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 63
Akash leverj pyexchange changes20191206 #104
Open
mitakash
wants to merge
6
commits into
makerdao:master
Choose a base branch
from
mitakash:akashLeverjPyexchangeChanges20191206
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
229be31
added leverj-ordersigner to requirements.txt
ce0a63c
changed some names for abis
a9fccb2
added a new line to the end of requirements.txt
a34be55
made some changes to clean up code added post_pending_tx_hash function
baaff31
removed extra blank lines
ca6ae8e
removed extra line for defaultAccount
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -94,7 +94,6 @@ def __init__(self, | |
assert(isinstance(is_sell, bool)) | ||
assert(isinstance(price, Wad)) | ||
assert(isinstance(amount, Wad)) | ||
|
||
self.trade_id = trade_id | ||
self.timestamp = timestamp | ||
self.pair = pair | ||
|
@@ -143,7 +142,7 @@ def from_all_list(pair, trade): | |
|
||
class LeverjAPI(PyexAPI): | ||
"""LeverJ API interface. | ||
""" | ||
""" | ||
|
||
logger = logging.getLogger() | ||
|
||
|
@@ -175,7 +174,7 @@ def get_balance(self, coin: str): | |
balances = self.get_balances() | ||
for key in balances: | ||
if balances[key]['symbol'] == coin: | ||
return balances[key]['plasma'] | ||
return balances[key]['available'] | ||
|
||
def get_pending(self, coin: str): | ||
assert(isinstance(coin, str)) | ||
|
@@ -266,6 +265,7 @@ def place_order(self, pair: str, is_sell: bool, price: Wad, amount: Wad): | |
price = str(price) | ||
quantity = str(amount) | ||
order = self.createNewOrder(side, price, quantity, orderInstrument) | ||
self.logger.info(f'order is {order}') | ||
return self._http_authenticated("POST", "/api/v1", "/order", [order])[0]['uuid'] | ||
|
||
def cancel_order(self, order_id: str) -> bool: | ||
|
@@ -344,6 +344,7 @@ def _result(self, result) -> Optional[dict]: | |
|
||
return data | ||
|
||
|
||
class LeverJ(Contract): | ||
"""A client for the Leverj proxy exchange contract. | ||
|
||
|
@@ -355,7 +356,7 @@ class LeverJ(Contract): | |
logger = logging.getLogger() | ||
|
||
abi = Contract._load_abi(__name__, 'abi/GLUON.abi') | ||
token_abi = Contract._load_abi(__name__, 'abi/TOKEN_ABI.abi') | ||
token_abi = Contract._load_abi(__name__, 'abi/ERC20TOKEN.abi') | ||
|
||
def __init__(self, web3: Web3, address: Address): | ||
assert(isinstance(web3, Web3)) | ||
|
@@ -375,39 +376,50 @@ def approve_token(self, token_address: str, amount: int) -> Transact: | |
def deposit_ether(self, leverjobj: LeverjAPI, amount: Wad, gluon_block_number): | ||
assert(isinstance(leverjobj, LeverjAPI)) | ||
assert(isinstance(amount, Wad)) | ||
assert(isinstance(gluon_block_number, None) or isinstance(gluon_block_number, int)) | ||
|
||
custodian_account = self.address | ||
app_id = leverjobj.get_spot_exchange_id() | ||
if gluon_block_number is None: | ||
gluon_block_number = leverjobj._http_authenticated("GET", "/api/v1", f"/plasma/{app_id}", None)['number'] +2 | ||
Transact(self, self.web3, self.abi, self.address, self._contract, "depositEther",[app_id], {'value': int(amount.value)}).transact() | ||
return gluon_block_number | ||
gluon_block_number = leverjobj._http_authenticated("GET", "/api/v1", f"/plasma/{app_id}", None)['number'] + 2 | ||
receipt = Transact(self, self.web3, self.abi, self.address, self._contract, "depositEther",[app_id], {'value': int(amount.value)}).transact() | ||
return (gluon_block_number, receipt) | ||
else: | ||
current_gluon_block = leverjobj._http_authenticated("GET", "/api/v1", f"/plasma/{app_id}", None)['number'] | ||
if (current_gluon_block < gluon_block_number): | ||
return gluon_block_number | ||
return (gluon_block_number, None) | ||
else: | ||
return None | ||
return (None, None) | ||
|
||
def deposit_token(self, leverjobj: LeverjAPI, token_address: str, amount: int, gluon_block_number): | ||
assert(isinstance(leverjobj, LeverjAPI)) | ||
assert(isinstance(token_address, str)) | ||
assert(isinstance(amount, int)) | ||
assert(isinstance(gluon_block_number, None) or isinstance(gluon_block_number, int)) | ||
|
||
custodian_account = self.address | ||
app_id = leverjobj.get_spot_exchange_id() | ||
if gluon_block_number is None: | ||
gluon_block_number = leverjobj._http_authenticated("GET", "/api/v1", f"/plasma/{app_id}", None)['number'] +2 | ||
Transact(self, self.web3, self.abi, self.address, self._contract, "depositToken",[app_id, token_address, amount], {}).transact() | ||
return gluon_block_number | ||
gluon_block_number = leverjobj._http_authenticated("GET", "/api/v1", f"/plasma/{app_id}", None)['number'] + 2 | ||
receipt = Transact(self, self.web3, self.abi, self.address, self._contract, "depositToken",[app_id, token_address, amount], {}).transact() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same as above, should we just return receipt? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need to return both, gluon_block_number tells us where we are in the process, the hash in the receipt is eventually sent back into post_pending_tx_hash to let let leverj know we just sent something and to look for that transaction hash in pending transactions on ethereum block chain. |
||
return (gluon_block_number, receipt) | ||
else: | ||
current_gluon_block = leverjobj._http_authenticated("GET", "/api/v1", f"/plasma/{app_id}", None)['number'] | ||
if (current_gluon_block < gluon_block_number): | ||
return gluon_block_number | ||
return (gluon_block_number, None) | ||
else: | ||
return None | ||
return (None, None) | ||
|
||
def post_pending_tx_hash(self, leverjobj: LeverjAPI, tx_hash: str, asset_addr: str, quantity: str): | ||
assert(isinstance(tx_hash, str)) | ||
assert(isinstance(asset_addr, str)) | ||
assert(isinstance(quantity, str)) | ||
|
||
payload = { | ||
"txid": tx_hash, | ||
"asset": asset_addr, | ||
"quantity": quantity | ||
} | ||
balance_dict = leverjobj._http_authenticated("POST", "/api/v1", "/account/deposit", payload) | ||
return balance_dict | ||
|
||
def withdraw_token(self, leverjobj: LeverjAPI, token_addr: str, quantity: int) -> int: | ||
assert(isinstance(leverjobj, LeverjAPI)) | ||
|
@@ -442,24 +454,20 @@ def claim_funds(self, leverjobj: LeverjAPI, asset: str, quantity: int, gluon_blo | |
return self.withdraw_token(leverjobj, asset, int(quantity)) | ||
|
||
else: | ||
leverjobj.web3.eth.defaultAccount = leverjobj.account_id | ||
ethereum_account = leverjobj.account_id | ||
custodian_account = self.address | ||
self.logger.info(f"ethereum_account: {ethereum_account}, custodian_account: {custodian_account}, asset: {asset}") | ||
response = leverjobj._http_authenticated("GET", "/api/v1", f"/plasma/{app_id}/evmparams/withdrawals/account/{ethereum_account}/asset/{asset}", None) | ||
response_app_id = int(response[0]) | ||
response_bytes = response[1] | ||
current_block = leverjobj._http_authenticated("GET", "/api/v1", f"/plasma/{app_id}", None)['number'] | ||
|
||
if (leverjobj._http_authenticated("GET", "/api/v1", f"/plasma/{app_id}", None)['number'] >= gluon_block_number): | ||
if current_block >= gluon_block_number: | ||
leverjobj.web3.eth.defaultAccount = leverjobj.account_id | ||
ethereum_account = leverjobj.account_id | ||
custodian_account = self.address | ||
self.logger.info(f"ethereum_account: {ethereum_account}, custodian_account: {custodian_account}, asset: {asset}") | ||
response = leverjobj._http_authenticated("GET", "/api/v1", f"/plasma/{app_id}/evmparams/withdrawals/account/{ethereum_account}/asset/{asset}", None) | ||
response_app_id = int(response[0]) | ||
response_bytes = response[1] | ||
self.logger.info(f"finally gluon_block_number reached {gluon_block_number} and we are running final transact") | ||
Transact(self, self.web3, self.abi, self.address, self._contract, "withdraw",[response_app_id, response_bytes], {}).transact() | ||
return None | ||
|
||
self.logger.info(f'does not look like gluon_block_number reached {gluon_block_number} and we are currently at {leverjobj._http_authenticated("GET", "/api/v1", f"/plasma/{app_id}", None)["number"]}') | ||
return gluon_block_number | ||
|
||
|
||
|
||
|
||
current_block = leverjobj._http_authenticated("GET", "/api/v1", f"/plasma/{app_id}", None)['number'] | ||
self.logger.info(f'does not look like gluon_block_number reached {gluon_block_number} and we are currently at {current_block}') | ||
return gluon_block_number | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,5 @@ python-dateutil == 2.6.1 | |
websockets == 6.0.0 | ||
kucoin-python == 2.0.5 | ||
pyjwt == 1.7.1 | ||
leverj-ordersigner == 0.7 | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we want just to return receipt or to check here if transaction completed ok / other details?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we need to return receipt in it's full form to be checked by inventory service with gluon block to know where we are in the processing