account may have currency with zero balance
unclezoro opened this issue · comments
For the account:
https://dex-atlantic.binance.org/api/v1/account/bnb1xwalxpaes9r0z0fqdy70j3kz6aayetegur38gl
MDAB-D42
, BOLT-4C6
, AWC-986
get zero balance, while the account have hold BHFT-BBE
before but did not show it.
The reason is that AWC-986
is sold by order, while BHFT-BBE
is transferred to others.
refer: https://explorer.binance.org/api/v1/txs?address=bnb1xwalxpaes9r0z0fqdy70j3kz6aayetegur38gl&txAsset=AWC-986&page=1&rows=100
When handle orders, tran.unlock - tran.out
is equal to zero and cause the problem.
func (kp *Keeper) doTransfer(ctx sdk.Context, tran *Transfer) sdk.Error {
account := kp.am.GetAccount(ctx, tran.accAddress).(types.NamedAccount)
newLocked := account.GetLockedCoins().Minus(sdk.Coins{sdk.NewCoin(tran.outAsset, tran.unlock)})
// these two non-negative check are to ensure the Transfer gen result is correct before we actually operate the acc.
// they should never happen, there would be a severe bug if happen and we have to cancel all orders when app restarts.
if !newLocked.IsNotNegative() {
panic(fmt.Errorf(
"no enough locked tokens to unlock, oid: %s, newLocked: %s, unlock: %d",
tran.Oid,
newLocked.String(),
tran.unlock))
}
if tran.unlock < tran.out {
panic(errors.New("unlocked tokens cannot cover the expense"))
}
account.SetLockedCoins(newLocked)
account.SetCoins(account.GetCoins().
Plus(sdk.Coins{sdk.NewCoin(tran.inAsset, tran.in)}).
Plus(sdk.Coins{sdk.NewCoin(tran.outAsset, tran.unlock-tran.out)}))
kp.am.SetAccount(ctx, account)
kp.logger.Debug("Performed Trade Allocation", "account", account, "allocation", tran.String())
return nil
}