Skip to content

Missing Error Handler for SendCoin Function #851

Description

@Hellobloc

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions