MCPcopy Create free account
hub / github.com/Sifchain/sifnode / AddLiquidity

Method AddLiquidity

x/clp/keeper/msg_server.go:647–772  ·  view source on GitHub ↗
(goCtx context.Context, msg *types.MsgAddLiquidity)

Source from the content-addressed store, hash-verified

645}
646
647func (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 {

Callers

nothing calls this directly

Calls 15

CalculatePoolUnitsFunction · 0.85
CalcSwapResultFunction · 0.85
GetSwapFeeRateMethod · 0.80
ExtractDebtMethod · 0.80
GetNativePriceMethod · 0.80
GetMarginKeeperMethod · 0.80
IsRemovalQueueEnabledMethod · 0.80
ProcessRemovalQueueMethod · 0.80
GetRegistryMethod · 0.65

Tested by

no test coverage detected