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

Missing Error Handler for SendCoin Function #851

Open
Hellobloc opened this issue Oct 9, 2024 · 3 comments
Open

Missing Error Handler for SendCoin Function #851

Hellobloc opened this issue Oct 9, 2024 · 3 comments

Comments

@Hellobloc
Copy link

Hellobloc commented Oct 9, 2024

The Sendcoin code lacks error handling. This will lead to an inability to provide error feedback for transfer operations where the available Sencoins are insufficient to meet the userAmount during migration.

bal := k.bankKeeper.GetBalance(ctx, position.GetPositionAddress(), position.Collateral.Denom)
			userAmount := sdk.ZeroInt()
			if bal.Amount.LT(repayAmount) {
				repayAmount = bal.Amount
			} else {
				userAmount = bal.Amount.Sub(repayAmount)
			}

			if repayAmount.IsPositive() {
				k.stableKeeper.Repay(ctx, position.GetPositionAddress(), sdk.NewCoin(position.Collateral.Denom, repayAmount))
			} else {
				userAmount = bal.Amount
			}

			positionOwner := sdk.MustAccAddressFromBech32(position.Address)
			if userAmount.IsPositive() {
				k.bankKeeper.SendCoins(ctx, position.GetPositionAddress(), positionOwner, sdk.Coins{sdk.NewCoin(position.Collateral.Denom, userAmount)})
			}

			if leveragedLpAmount.IsZero() {
				// Repay any balance, delete position
				k.DestroyPosition(ctx, positionOwner, position.Id)
			} else {
				// Repay any balance and update position value
				position.LeveragedLpAmount = leveragedLpAmount
				k.SetPosition(ctx, &position)
			}
		}
https://github.com/elys-network/elys/blob/624945db82ff57077de206b2a25ed05ae4c33b14/x/leveragelp/keeper/position.go#L369

Considering that the vesting account may cause the operation k.bankKeeper.GetBalance(ctx, position.GetPositionAddress(), position.Collateral.Denom) to return a balance that includes locked coins, which cannot be transferred. This may lead to the Sendcoin not providing correct error feedback in the future when adapting to the vesting account for elys network.

@Hellobloc
Copy link
Author

@cryptokage1996

@dananganjy
Copy link

Lfgg

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