Author Topic: Collateral stuck after manual cover?!  (Read 2191 times)

0 Members and 1 Guest are viewing this topic.

Offline vikram


zerosum

  • Guest
Here's my theory. The problem is that the payout of the collateral is not handled in the same place as the actual filling of the cover.

The manual cover transaction is created by transaction_builder::submit_cover. That adds a cover operation to the transaction and deducts the cover amount from the transaction balance. It also computes the interest to be paid at the end of the transaction expiration time, and only if the cover amount covers both interest and the balance to be covered it also adds a deposit operation for the collateral.

After the cover tx has been included in the blockchain, the cover operation is executed by cover_operation::evaluate. This computes the interest owed at the current block time, and if the cover amount covers both interest and principal the cover_order is deleted.

The problem here is the different times used for interest calculation. The default transaction expiration time is 1 hour, while the actual transaction evaluation takes place only a few seconds after the transaction was created. The transaction builder computed the interest owed one hour in the future and came to the conclusion that the cover amount was not sufficient, and therefore it did not create the deposit_operation for the collateral. The transaction evaluation calculated the interest owed now, saw the the cover amount was sufficient and closed the cover_operation.

This is a serious bug, IMO. I'll have to check my TX history, this may have happened more than once.

I do not know if there is a bug or not ( I have not read the code and I suspect you might have) but  I just want to mention that wallet_market_order_list returns only the principle amount owed. And it seems you have covered only that (0.09825190 BTC in this case). If the correct interest was less more or equal to 1 satoshi at this point in time I will leave to you to investigate.

Offline pc

  • Hero Member
  • *****
  • Posts: 1530
    • View Profile
    • Bitcoin - Perspektive oder Risiko?
  • BitShares: cyrano
Here's my theory. The problem is that the payout of the collateral is not handled in the same place as the actual filling of the cover.

The manual cover transaction is created by transaction_builder::submit_cover. That adds a cover operation to the transaction and deducts the cover amount from the transaction balance. It also computes the interest to be paid at the end of the transaction expiration time, and only if the cover amount covers both interest and the balance to be covered it also adds a deposit operation for the collateral.

After the cover tx has been included in the blockchain, the cover operation is executed by cover_operation::evaluate. This computes the interest owed at the current block time, and if the cover amount covers both interest and principal the cover_order is deleted.

The problem here is the different times used for interest calculation. The default transaction expiration time is 1 hour, while the actual transaction evaluation takes place only a few seconds after the transaction was created. The transaction builder computed the interest owed one hour in the future and came to the conclusion that the cover amount was not sufficient, and therefore it did not create the deposit_operation for the collateral. The transaction evaluation calculated the interest owed now, saw the the cover amount was sufficient and closed the cover_operation.

This is a serious bug, IMO. I'll have to check my TX history, this may have happened more than once.
Bitcoin - Perspektive oder Risiko? ISBN 978-3-8442-6568-2 http://bitcoin.quisquis.de

Offline pc

  • Hero Member
  • *****
  • Posts: 1530
    • View Profile
    • Bitcoin - Perspektive oder Risiko?
  • BitShares: cyrano
I think you have note paid the small amount of interest you owe on your short.

What is the return now of:

wallet_market_order_list BTC BTS
?

Good thought. In fact that has happened before, i. e. after paying off the full amount there was still 1 satoshi left. But in that case the uncovered satoshi was shown by wallet_market_order_list. Here's the current output:

Code: [Select]
trader (unlocked) >>> wallet_market_order_list BTC BTS
TYPE                QUANTITY            PRICE                         BALANCE             COST                COLLATERAL          LIMIT               ID                                         OWNER               
==================================================================================================================================================================
cover_order         127,631.97525 BTS   0.000017627723132021 BTC / BTS2.99981483 BTC      2.24986112 BTC      255,263.95050 BTS   NONE                2c6f285f6a1eb878f484062902bf75ddf3917333   BTS84qcvLzQVyc2U2WMZe2qNd3ARJ6JTLEmJ
ask_order           0.00032 BTS         0.0000361752752312 BTC / BTS  0.00032 BTS         0.00000001 BTC      N/A                 NONE                402621d669a668fff24325e838879cc20914f7c4   BTS2hwFxMAdyZb3fPQnwwAYQC3e5arcTs9BU
ask_order           87,027.17231 BTS    0.0000361955916255 BTC / BTS  87,027.17231 BTS    3.14999998 BTC      N/A                 NONE                e8ead8c107d31d1864e452160188e2c80d793038   BTSP4uVggqTEwFoTgZRWsiT71HPm3ChmoWgh

Note that the open cover_order belongs to a different owner than the one I covered - this was from an unrelated short.
Bitcoin - Perspektive oder Risiko? ISBN 978-3-8442-6568-2 http://bitcoin.quisquis.de

zerosum

  • Guest
I think you have note paid the small amount of interest you owe on your short.

What is the return now of:

wallet_market_order_list BTC BTS
?

Offline pc

  • Hero Member
  • *****
  • Posts: 1530
    • View Profile
    • Bitcoin - Perspektive oder Risiko?
  • BitShares: cyrano
Hi,

I shorted some BTC and a little later I covered to open short. I have done this before, and the usual result is that the collateral is credited back to my wallet. This time it wasn't.

in the CLI I did

wallet_market_submit_short trader1.pmc 5417.97264 BTS 0.12 BTC 0.0000326456222794

in block 1787741, the short was filled one block later, and another 17 blocks after that I found the open cover with

wallet_account_order_list

and covered manually with

wallet_market_cover trader1.pmc 0.09825190 BTC 3f94c69c59022edde4fe2e001a63e49d169c7b80

Here's an excerpt of wallet_account_transaction_history:

Code: [Select]
2015-02-14T13:41:52 1787741   trader1.pmc         SHORT-b0958dff      5,417.97264 BTS         short BTC @ 0.12% APR                       2,710.68559 BTS         0.10000 BTS         e7d8565a
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|2015-02-14T13:42:10 1787742   SHORT-b0958dff      MARGIN-b0958dff     5,417.97264 BTS         add collateral                              2.60000 BTS             0.00000 BTS         VIRTUAL |
|                              MARKET              MARGIN-b0958dff     3,009.65008 BTS         add collateral                              2.60000 BTS                                         |
|                              MARGIN-b0958dff     MARKET              0.09825190 BTC          short proceeds @ 0.0000326456222794 BTC ... 0.00713279 BTC                                      |
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 2015-02-14T13:44:52 1787759   trader1.pmc         MARGIN-b0958dff     0.09825190 BTC          payoff debt                                 0.00611434 BTC          0.10000 BTS         25e0507e

The owner address of that short/cover is BTSLtHYNmAj3spkDezjyZRMNMPxDpFKeNtqd. wallet_account_order_list doesn't show any open orders with that owner, so I suppose it was fully covered. But my collateral wasn't returned.

Any ideas? Any hints on how/where to find information about market transactions?

Thanks,
Peter
Bitcoin - Perspektive oder Risiko? ISBN 978-3-8442-6568-2 http://bitcoin.quisquis.de