Skip to content

Commit

Permalink
Revert "feat: lock existing position and sfs (#5745) (#5760)"
Browse files Browse the repository at this point in the history
This reverts commit 9968df4.
  • Loading branch information
czarcas7ic committed Jul 12, 2023
1 parent d72fe81 commit ab77082
Show file tree
Hide file tree
Showing 13 changed files with 90 additions and 947 deletions.
16 changes: 0 additions & 16 deletions proto/osmosis/superfluid/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,6 @@ service Msg {
rpc AddToConcentratedLiquiditySuperfluidPosition(
MsgAddToConcentratedLiquiditySuperfluidPosition)
returns (MsgAddToConcentratedLiquiditySuperfluidPositionResponse);

rpc LockExistingFullRangePositionAndSFStake(
MsgLockExistingFullRangePositionAndSFStake)
returns (MsgLockExistingFullRangePositionAndSFStakeResponse);
}

message MsgSuperfluidDelegate {
Expand Down Expand Up @@ -229,16 +225,4 @@ message MsgAddToConcentratedLiquiditySuperfluidPositionResponse {
(gogoproto.nullable) = false
];
uint64 lock_id = 4 [ (gogoproto.moretags) = "yaml:\"lock_id\"" ];
}

// ===================== MsgLockExistingFullRangePositionAndSFStake
message MsgLockExistingFullRangePositionAndSFStake {
uint64 position_id = 1 [ (gogoproto.moretags) = "yaml:\"position_id\"" ];
string sender = 2 [ (gogoproto.moretags) = "yaml:\"sender\"" ];
string val_addr = 3 [ (gogoproto.moretags) = "yaml:\"val_addr\"" ];
}

message MsgLockExistingFullRangePositionAndSFStakeResponse {
uint64 concentrated_lock_id = 1
[ (gogoproto.moretags) = "yaml:\"concentrated_lock_id\"" ];
}
4 changes: 4 additions & 0 deletions x/concentrated-liquidity/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@ func (k Keeper) UpdateFullRangeLiquidityInPool(ctx sdk.Context, poolId uint64, l
return k.updateFullRangeLiquidityInPool(ctx, poolId, liquidity)
}

func (k Keeper) MintSharesAndLock(ctx sdk.Context, concentratedPoolId, positionId uint64, owner sdk.AccAddress, remainingLockDuration time.Duration) (concentratedLockID uint64, underlyingLiquidityTokenized sdk.Coins, err error) {
return k.mintSharesAndLock(ctx, concentratedPoolId, positionId, owner, remainingLockDuration)
}

func (k Keeper) SetPositionIdToLock(ctx sdk.Context, positionId, underlyingLockId uint64) {
k.setPositionIdToLock(ctx, positionId, underlyingLockId)
}
Expand Down
8 changes: 4 additions & 4 deletions x/concentrated-liquidity/position.go
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ func (k Keeper) CreateFullRangePositionLocked(ctx sdk.Context, clPoolId uint64,

// Mint CL shares (similar to GAMM shares) for the position and lock them for the remaining lock duration.
// Also sets the position ID to underlying lock ID mapping.
concentratedLockId, _, err := k.MintSharesAndLock(ctx, clPoolId, positionId, owner, remainingLockDuration)
concentratedLockId, _, err := k.mintSharesAndLock(ctx, clPoolId, positionId, owner, remainingLockDuration)
if err != nil {
return 0, sdk.Int{}, sdk.Int{}, sdk.Dec{}, 0, err
}
Expand All @@ -453,7 +453,7 @@ func (k Keeper) CreateFullRangePositionUnlocking(ctx sdk.Context, clPoolId uint6

// Mint cl shares for the position and lock them for the remaining lock duration.
// Also sets the position ID to underlying lock ID mapping.
concentratedLockId, underlyingLiquidityTokenized, err := k.MintSharesAndLock(ctx, clPoolId, positionId, owner, remainingLockDuration)
concentratedLockId, underlyingLiquidityTokenized, err := k.mintSharesAndLock(ctx, clPoolId, positionId, owner, remainingLockDuration)
if err != nil {
return 0, sdk.Int{}, sdk.Int{}, sdk.Dec{}, 0, err
}
Expand All @@ -467,11 +467,11 @@ func (k Keeper) CreateFullRangePositionUnlocking(ctx sdk.Context, clPoolId uint6
return positionId, amount0, amount1, liquidity, concentratedLockID, nil
}

// MintSharesAndLock mints the shares for the full range concentrated liquidity position and locks them for the given duration. It also updates the position ID to underlying lock ID mapping.
// mintSharesAndLock mints the shares for the full range concentrated liquidity position and locks them for the given duration. It also updates the position ID to underlying lock ID mapping.
// In the context of concentrated liquidity, shares need to be minted in order for a lock in its current form to be utilized (we cannot lock non-coin objects).
// In turn, the locks are a prerequisite for superfluid to be enabled.
// Additionally, the cl share gets sent to the lockup module account, which, in order to be sent via bank, must be minted.
func (k Keeper) MintSharesAndLock(ctx sdk.Context, concentratedPoolId, positionId uint64, owner sdk.AccAddress, remainingLockDuration time.Duration) (concentratedLockID uint64, underlyingLiquidityTokenized sdk.Coins, err error) {
func (k Keeper) mintSharesAndLock(ctx sdk.Context, concentratedPoolId, positionId uint64, owner sdk.AccAddress, remainingLockDuration time.Duration) (concentratedLockID uint64, underlyingLiquidityTokenized sdk.Coins, err error) {
// Ensure the provided position is full range.
position, err := k.GetPosition(ctx, positionId)
if err != nil {
Expand Down
9 changes: 0 additions & 9 deletions x/superfluid/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ func GetTxCmd() *cobra.Command {
osmocli.AddTxCmd(cmd, NewCreateFullRangePositionAndSuperfluidDelegateCmd)
osmocli.AddTxCmd(cmd, NewAddToConcentratedLiquiditySuperfluidPositionCmd)
osmocli.AddTxCmd(cmd, NewUnlockAndMigrateSharesToFullRangeConcentratedPositionCmd)
osmocli.AddTxCmd(cmd, NewLockExistingFullRangePositionAndSFStakeCmd)

return cmd
}
Expand Down Expand Up @@ -424,11 +423,3 @@ func NewUnlockAndMigrateSharesToFullRangeConcentratedPositionCmd() (*osmocli.TxC
Example: "unlock-and-migrate-cl 10 25000000000gamm/pool/2 1000000000uosmo,10000000uion",
}, &types.MsgUnlockAndMigrateSharesToFullRangeConcentratedPosition{}
}

func NewLockExistingFullRangePositionAndSFStakeCmd() (*osmocli.TxCliDesc, *types.MsgLockExistingFullRangePositionAndSFStake) {
return &osmocli.TxCliDesc{
Use: "lock-cl-position-and-sfs [position-id] [val-addr]",
Short: "lock and existing cl position and superfluid stake it to the provided validator",
Example: "lock-cl-position-and-sfs 22 osmovaloper1h2c47vd943scjlfum6yc5frvu2l279lwjep5d6",
}, &types.MsgLockExistingFullRangePositionAndSFStake{}
}
16 changes: 0 additions & 16 deletions x/superfluid/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,19 +242,3 @@ func (server msgServer) AddToConcentratedLiquiditySuperfluidPosition(goCtx conte

return &types.MsgAddToConcentratedLiquiditySuperfluidPositionResponse{PositionId: newPositionId, Amount0: actualAmount0, Amount1: actualAmount1, LockId: newLockId, NewLiquidity: newLiquidity}, nil
}

func (server msgServer) LockExistingFullRangePositionAndSFStake(goCtx context.Context, msg *types.MsgLockExistingFullRangePositionAndSFStake) (*types.MsgLockExistingFullRangePositionAndSFStakeResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)

sender, err := sdk.AccAddressFromBech32(msg.Sender)
if err != nil {
return nil, err
}

concentratedLockId, err := server.keeper.LockExistingFullRangePositionAndSFStake(ctx, msg.PositionId, sender, msg.ValAddr)
if err != nil {
return nil, err
}

return &types.MsgLockExistingFullRangePositionAndSFStakeResponse{ConcentratedLockId: concentratedLockId}, nil
}
79 changes: 0 additions & 79 deletions x/superfluid/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"

v8constants "github.com/osmosis-labs/osmosis/v16/app/upgrades/v8/constants"
clkeeper "github.com/osmosis-labs/osmosis/v16/x/concentrated-liquidity"
cltypes "github.com/osmosis-labs/osmosis/v16/x/concentrated-liquidity/types"
"github.com/osmosis-labs/osmosis/v16/x/gamm/pool-models/balancer"
gammtypes "github.com/osmosis-labs/osmosis/v16/x/gamm/types"
Expand Down Expand Up @@ -596,81 +595,3 @@ func (s *KeeperTestSuite) TestAddToConcentratedLiquiditySuperfluidPosition_Event
})
}
}

func (s *KeeperTestSuite) TestLockExistingFullRangePositionAndSFStake_Events() {
testcases := map[string]struct {
isFullRangePosition bool
expectedLockExistingFullRangeEvents int
expectedError error
}{
"happy path": {
isFullRangePosition: true,
expectedLockExistingFullRangeEvents: 1,
},
"non full range": {
isFullRangePosition: false,
expectedError: cltypes.PositionNotFullRangeError{PositionId: 2, LowerTick: cltypes.MinInitializedTick + 1, UpperTick: cltypes.MaxTick},
},
}

for name, tc := range testcases {
s.Run(name, func() {
s.SetupTest()

msgServer := keeper.NewMsgServerImpl(s.App.SuperfluidKeeper)
concentratedLiquidityKeeper := s.App.ConcentratedLiquidityKeeper
positionOwner := s.TestAccs[0]
prepAcc := s.TestAccs[1]

// Setup the validator, cl pool, and enable sfs on the cl pool.
_, _, _, _, valAddr, _ := s.SetupSuperfluidConcentratedPosition(s.Ctx, true, false, false, prepAcc)

// Create a new position that is not locked.
s.FundAcc(positionOwner, defaultFunds)
var posId uint64
var err error
if tc.isFullRangePosition {
posId, _, _, _, err = concentratedLiquidityKeeper.CreateFullRangePosition(s.Ctx, 1, positionOwner, defaultFunds)
s.Require().NoError(err)
} else {
msg := &cltypes.MsgCreatePosition{
PoolId: 1,
Sender: s.TestAccs[0].String(),
LowerTick: cltypes.MinInitializedTick + 1,
UpperTick: cltypes.MaxTick,
TokensProvided: defaultFunds,
TokenMinAmount0: sdk.ZeroInt(),
TokenMinAmount1: sdk.ZeroInt(),
}
msgServer := clkeeper.NewMsgServerImpl(s.App.ConcentratedLiquidityKeeper)
resp, err := msgServer.CreatePosition(sdk.WrapSDKContext(s.Ctx), msg)
s.Require().NoError(err)
posId = resp.PositionId
}

// Reset event counts to 0 by creating a new manager.
s.Ctx = s.Ctx.WithEventManager(sdk.NewEventManager())
s.Equal(0, len(s.Ctx.EventManager().Events()))

msg := &types.MsgLockExistingFullRangePositionAndSFStake{
PositionId: posId,
Sender: positionOwner.String(),
ValAddr: valAddr.String(),
}

// System under test.
response, err := msgServer.LockExistingFullRangePositionAndSFStake(sdk.WrapSDKContext(s.Ctx), msg)

if tc.expectedError == nil {
s.NoError(err)
s.NotNil(response)
s.AssertEventEmitted(s.Ctx, types.TypeEvtLockExistingFullRangePositionAndSFStake, tc.expectedLockExistingFullRangeEvents)
} else {
s.Require().Error(err)
s.Require().ErrorContains(err, tc.expectedError.Error())
s.Require().Nil(response)
s.AssertEventEmitted(s.Ctx, types.TypeEvtLockExistingFullRangePositionAndSFStake, tc.expectedLockExistingFullRangeEvents)
}
})
}
}
50 changes: 0 additions & 50 deletions x/superfluid/keeper/stake.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@ package keeper

import (
"fmt"
"strconv"

errorsmod "cosmossdk.io/errors"

"github.com/osmosis-labs/osmosis/osmoutils"
cltypes "github.com/osmosis-labs/osmosis/v16/x/concentrated-liquidity/types"
lockuptypes "github.com/osmosis-labs/osmosis/v16/x/lockup/types"
"github.com/osmosis-labs/osmosis/v16/x/superfluid/types"

Expand Down Expand Up @@ -664,51 +662,3 @@ func (k Keeper) IterateDelegations(ctx sdk.Context, delegator sdk.AccAddress, fn
fn(index+int64(i), delegation)
}
}

// LockExistingFullRangePositionAndSFStake locks existing position and superfluid stakes the position.
// This method would error if the existing position is not a full ranged position.
func (k Keeper) LockExistingFullRangePositionAndSFStake(ctx sdk.Context, positionId uint64, sender sdk.AccAddress, valAddr string) (concentratedLockID uint64, err error) {
// Retrieve position via ID.
position, err := k.clk.GetPosition(ctx, positionId)
if err != nil {
return 0, err
}

// Check that the position is full range and belongs to the owner.
if position.LowerTick != cltypes.MinInitializedTick || position.UpperTick != cltypes.MaxTick {
return 0, cltypes.PositionNotFullRangeError{PositionId: positionId, LowerTick: position.LowerTick, UpperTick: position.UpperTick}
}
if position.Address != sender.String() {
return 0, cltypes.PositionOwnerMismatchError{PositionOwner: position.Address, Sender: sender.String()}
}

// Mint CL shares (similar to GAMM shares) for the position and lock them for the unbonding duration.
// Also sets the position ID to underlying lock ID mapping.
lockDuration := k.sk.GetParams(ctx).UnbondingTime
concentratedLockId, _, err := k.clk.MintSharesAndLock(ctx, position.PoolId, positionId, sender, lockDuration)
if err != nil {
return 0, err
}

// Superfluid delegate the newly created concentrated lock.
err = k.SuperfluidDelegate(ctx, position.Address, concentratedLockId, valAddr)
if err != nil {
return 0, err
}

// Emit events.
ctx.EventManager().EmitEvents(sdk.Events{
sdk.NewEvent(
sdk.EventTypeMessage,
sdk.NewAttribute(sdk.AttributeKeySender, sender.String()),
),
sdk.NewEvent(
types.TypeEvtLockExistingFullRangePositionAndSFStake,
sdk.NewAttribute(sdk.AttributeKeySender, sender.String()),
sdk.NewAttribute(types.AttributePositionId, strconv.FormatUint(positionId, 10)),
sdk.NewAttribute(types.AttributeConcentratedLockId, strconv.FormatUint(concentratedLockId, 10)),
),
})

return concentratedLockId, nil
}
Loading

0 comments on commit ab77082

Please sign in to comment.