(goCtx context.Context, msg *types.MsgAddLiquidity)
| 645 | } |
| 646 | |
| 647 | func (k msgServer) AddLiquidity(goCtx context.Context, msg *types.MsgAddLiquidity) (*types.MsgAddLiquidityResponse, error) { |
| 648 | ctx := sdk.UnwrapSDKContext(goCtx) |
| 649 | registry := k.tokenRegistryKeeper.GetRegistry(ctx) |
| 650 | |
| 651 | nAsset, err := k.tokenRegistryKeeper.GetEntry(registry, types.NativeSymbol) |
| 652 | if err != nil { |
| 653 | return nil, types.ErrTokenNotSupported |
| 654 | } |
| 655 | |
| 656 | eAsset, err := k.tokenRegistryKeeper.GetEntry(registry, msg.ExternalAsset.Symbol) |
| 657 | if err != nil { |
| 658 | return nil, types.ErrTokenNotSupported |
| 659 | } |
| 660 | |
| 661 | if !k.tokenRegistryKeeper.CheckEntryPermissions(eAsset, []tokenregistrytypes.Permission{tokenregistrytypes.Permission_CLP}) { |
| 662 | return nil, tokenregistrytypes.ErrPermissionDenied |
| 663 | } |
| 664 | |
| 665 | pool, err := k.Keeper.GetPool(ctx, msg.ExternalAsset.Symbol) |
| 666 | if err != nil { |
| 667 | return nil, types.ErrPoolDoesNotExist |
| 668 | } |
| 669 | |
| 670 | pmtpCurrentRunningRate := k.GetPmtpRateParams(ctx).PmtpCurrentRunningRate |
| 671 | sellNativeSwapFeeRate := k.GetSwapFeeRate(ctx, types.GetSettlementAsset(), false) |
| 672 | buyNativeSwapFeeRate := k.GetSwapFeeRate(ctx, *msg.ExternalAsset, false) |
| 673 | |
| 674 | nativeAssetDepth, externalAssetDepth := pool.ExtractDebt(pool.NativeAssetBalance, pool.ExternalAssetBalance, false) |
| 675 | |
| 676 | newPoolUnits, lpUnits, swapStatus, swapAmount, err := CalculatePoolUnits( |
| 677 | pool.PoolUnits, |
| 678 | nativeAssetDepth, |
| 679 | externalAssetDepth, |
| 680 | msg.NativeAssetAmount, |
| 681 | msg.ExternalAssetAmount, |
| 682 | sellNativeSwapFeeRate, |
| 683 | buyNativeSwapFeeRate, |
| 684 | pmtpCurrentRunningRate) |
| 685 | if err != nil { |
| 686 | return nil, err |
| 687 | } |
| 688 | |
| 689 | switch swapStatus { |
| 690 | case NoSwap: |
| 691 | // do nothing |
| 692 | case SellNative: |
| 693 | // check sell permission for native |
| 694 | if k.tokenRegistryKeeper.CheckEntryPermissions(nAsset, []tokenregistrytypes.Permission{tokenregistrytypes.Permission_DISABLE_SELL}) { |
| 695 | return nil, tokenregistrytypes.ErrNotAllowedToSellAsset |
| 696 | } |
| 697 | // check buy permission for external |
| 698 | if k.tokenRegistryKeeper.CheckEntryPermissions(eAsset, []tokenregistrytypes.Permission{tokenregistrytypes.Permission_DISABLE_BUY}) { |
| 699 | return nil, tokenregistrytypes.ErrNotAllowedToBuyAsset |
| 700 | } |
| 701 | |
| 702 | if k.GetLiquidityProtectionParams(ctx).IsActive { |
| 703 | price, err := k.GetNativePrice(ctx) |
| 704 | if err != nil { |
nothing calls this directly
no test coverage detected