Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

account may have currency with zero balance #677

Closed
unclezoro opened this issue Oct 23, 2019 · 0 comments
Closed

account may have currency with zero balance #677

unclezoro opened this issue Oct 23, 2019 · 0 comments

Comments

@unclezoro
Copy link
Collaborator

unclezoro commented Oct 23, 2019

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
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants
@unclezoro and others