(clientCtx client.Context, from string, height int64, id uint64)
| 436 | } |
| 437 | |
| 438 | func VerifyClose(clientCtx client.Context, from string, height int64, id uint64) error { |
| 439 | // Lookup MTP |
| 440 | marginQueryClient := types.NewQueryClient(clientCtx.WithHeight(height - 1)) |
| 441 | mtpResponse, err := marginQueryClient.GetMTP(context.Background(), &types.MTPRequest{ |
| 442 | Address: from, |
| 443 | Id: id, |
| 444 | }) |
| 445 | if err != nil { |
| 446 | return sdkerrors.Wrap(err, fmt.Sprintf("error looking up mtp at height %d", height-1)) |
| 447 | } |
| 448 | fmt.Printf("\nMTP custody %s (%s)\n", mtpResponse.Mtp.CustodyAmount.String(), mtpResponse.Mtp.CustodyAsset) |
| 449 | fmt.Printf("MTP collateral %s (%s)\n", mtpResponse.Mtp.CollateralAmount.String(), mtpResponse.Mtp.CollateralAsset) |
| 450 | fmt.Printf("MTP leverage %s\n", mtpResponse.Mtp.Leverage.String()) |
| 451 | fmt.Printf("MTP liability %s\n", mtpResponse.Mtp.Liabilities.String()) |
| 452 | fmt.Printf("MTP health %s\n", mtpResponse.Mtp.MtpHealth) |
| 453 | fmt.Printf("MTP interest paid custody %s\n", mtpResponse.Mtp.InterestPaidCustody.String()) |
| 454 | fmt.Printf("MTP interest paid collateral %s\n", mtpResponse.Mtp.InterestPaidCollateral.String()) |
| 455 | fmt.Printf("MTP interest unpaid collateral %s\n", mtpResponse.Mtp.InterestUnpaidCollateral.String()) |
| 456 | |
| 457 | // lookup wallet before |
| 458 | bankQueryClient := banktypes.NewQueryClient(clientCtx.WithHeight(height - 1)) |
| 459 | collateralBefore, err := bankQueryClient.Balance(context.Background(), &banktypes.QueryBalanceRequest{ |
| 460 | Address: from, |
| 461 | Denom: mtpResponse.Mtp.CollateralAsset, |
| 462 | }) |
| 463 | if err != nil { |
| 464 | return err |
| 465 | } |
| 466 | custodyBefore, err := bankQueryClient.Balance(context.Background(), &banktypes.QueryBalanceRequest{ |
| 467 | Address: from, |
| 468 | Denom: mtpResponse.Mtp.CustodyAsset, |
| 469 | }) |
| 470 | if err != nil { |
| 471 | return err |
| 472 | } |
| 473 | fmt.Printf("\nWallet collateral balance before: %s\n", collateralBefore.Balance.Amount.String()) |
| 474 | fmt.Printf("Wallet custody balance before: %s\n\n", custodyBefore.Balance.Amount.String()) |
| 475 | // Ensure mtp does not exist after close |
| 476 | marginQueryClient = types.NewQueryClient(clientCtx.WithHeight(height)) |
| 477 | _, err = marginQueryClient.GetMTP(context.Background(), &types.MTPRequest{ |
| 478 | Address: from, |
| 479 | Id: id, |
| 480 | }) |
| 481 | if err != nil { |
| 482 | fmt.Printf("confirmed MTP does not exist at close height %d\n\n", height) |
| 483 | } else { |
| 484 | return sdkerrors.Wrap(err, fmt.Sprintf("error: found mtp at close height %d", height)) |
| 485 | } |
| 486 | |
| 487 | var externalAsset string |
| 488 | if types.StringCompare(mtpResponse.Mtp.CollateralAsset, "rowan") { |
| 489 | externalAsset = mtpResponse.Mtp.CustodyAsset |
| 490 | } else { |
| 491 | externalAsset = mtpResponse.Mtp.CollateralAsset |
| 492 | } |
| 493 | |
| 494 | clpQueryClient := clptypes.NewQueryClient(clientCtx.WithHeight(height - 1)) |
| 495 | poolBefore, err := clpQueryClient.GetPool(context.Background(), &clptypes.PoolReq{Symbol: externalAsset}) |
no test coverage detected