async def build_transfer( self, to: str, amount: int, token: Token, fee: int, nonce: Optional[int] = None, valid_from: int = DEFAULT_VALID_FROM, valid_until: int = DEFAULT_VALID_UNTIL, ) -> Tuple[Transfer, TxEthSignature]: """ This function takes as a parameter the integer amount/fee of lowest token denominations (wei, satoshi, etc.) """ if nonce is None: nonce = await self.zk_provider.get_account_nonce(self.address()) account_id = await self.get_account_id() transfer = Transfer(account_id=account_id, from_address=self.address(), to_address=to.lower(), amount=amount, fee=fee, nonce=nonce, valid_from=valid_from, valid_until=valid_until, token=token) eth_signature = self.eth_signer.sign_tx(transfer) zk_signature = self.zk_signer.sign_tx(transfer) transfer.signature = zk_signature return transfer, eth_signature
async def build_transfer( self, to: str, amount: Decimal, token: TokenLike, fee: Decimal = None, valid_from=DEFAULT_VALID_FROM, valid_until=DEFAULT_VALID_UNTIL ) -> Tuple[Transfer, TxEthSignature]: account_id, nonce = await self.zk_provider.get_account_nonce( self.address()) token = await self.resolve_token(token) if fee is None: fee = await self.zk_provider.get_transaction_fee( FeeTxType.transfer, to, token.id) fee = fee.total_fee else: fee = token.from_decimal(fee) transfer = Transfer(account_id=account_id, from_address=self.address(), to_address=to, amount=token.from_decimal(amount), fee=fee, nonce=nonce, valid_from=valid_from, valid_until=valid_until, token=token) eth_signature = await self.eth_signer.sign_tx(transfer) zk_signature = self.zk_signer.sign_tx(transfer) transfer.signature = zk_signature return transfer, eth_signature
async def _process_transfer(self, obj): if not obj[self.IS_ENCODED_TRANSACTION]: account_id = await self.wallet.get_account_id() token = await self.wallet.resolve_token(obj["token"]) fee = obj["fee"] if fee is None: fee = await self.wallet.zk_provider.get_transaction_fee( FeeTxType.transfer, obj["to_address"], token.id) fee = fee.total_fee else: fee = token.from_decimal(fee) amount = token.from_decimal(obj["amount"]) transfer = Transfer(account_id=account_id, from_address=obj["from_address"].lower(), to_address=obj["to_address"].lower(), token=token, amount=amount, fee=fee, nonce=self.nonce, valid_from=obj["valid_from"], valid_until=obj["valid_until"]) zk_signature = self.wallet.zk_signer.sign_tx(transfer) transfer.signature = zk_signature else: token = await self.wallet.resolve_token(obj["token"]) transfer = Transfer(account_id=obj["accountId"], from_address=obj["from"], to_address=obj["to"], token=token, amount=obj["amount"], fee=obj["fee"], nonce=self.nonce, valid_from=obj["validFrom"], valid_until=obj["validUntil"], signature=obj["signature"]) self.nonce += 1 return transfer