From 964eaba0a5d6344989a2900ec9743a097d77ba5f Mon Sep 17 00:00:00 2001 From: Charles Dusek Date: Thu, 18 Apr 2024 13:30:09 -0500 Subject: [PATCH] Create Pool Logic finished --- x/market/keeper/msg_server_create_pool.go | 56 ++++++++++++++++++++--- 1 file changed, 49 insertions(+), 7 deletions(-) diff --git a/x/market/keeper/msg_server_create_pool.go b/x/market/keeper/msg_server_create_pool.go index a3aef1a..4e8cd4f 100644 --- a/x/market/keeper/msg_server_create_pool.go +++ b/x/market/keeper/msg_server_create_pool.go @@ -64,13 +64,55 @@ func (k msgServer) CreatePool(goCtx context.Context, msg *types.MsgCreatePool) ( return nil, sdkError } - _ = member1 - _ = member2 - _ = pair - _ = pool - _ = found - _ = ctx - _ = creator + // Drops define proportional ownership to the liquidity in the pool + drops := coinPair.AmountOf(denom1).Mul(coinPair.AmountOf(denom2)) + + leader := types.Leader{ + Address: msg.Creator, + Drops: drops, + } + + if found { + pool.Drops = drops + pool.Leaders = []*types.Leader{&leader} + member1.Balance = coinPair.AmountOf(denom1) + member2.Balance = coinPair.AmountOf(denom2) + } else { + pool = types.Pool{ + Pair: pair, + Leaders: []*types.Leader{&leader}, + Denom1: coinPair.GetDenomByIndex(0), + Denom2: coinPair.GetDenomByIndex(1), + Volume1: &types.Volume{ + Denom: coinPair.GetDenomByIndex(0), + Amount: math.ZeroInt(), + }, + Volume2: &types.Volume{ + Denom: coinPair.GetDenomByIndex(1), + Amount: math.ZeroInt(), + }, + Drops: drops, + History: uint64(0), + } + + member1 = types.Member{ + Pair: pair, + DenomA: denom2, + DenomB: denom1, + Balance: coinPair.AmountOf(denom1), + Limit: 0, + Stop: 0, + } + + member2 = types.Member{ + Pair: pair, + DenomA: denom1, + DenomB: denom2, + Balance: coinPair.AmountOf(denom2), + Limit: 0, + Stop: 0, + } + } return &types.MsgCreatePoolResponse{}, nil }