Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,7 @@ func New(
&app.EsmKeeper,
&app.TokenmintKeeper,
&app.Rewardskeeper,
&app.LiquidityKeeper,
)

app.TokenmintKeeper = tokenmintkeeper.NewKeeper(
Expand Down Expand Up @@ -669,6 +670,7 @@ func New(
&app.TokenmintKeeper,
&app.EsmKeeper,
&app.LendKeeper,
&app.LiquidityKeeper,
)

app.CollectorKeeper = collectorkeeper.NewKeeper(
Expand Down
8 changes: 7 additions & 1 deletion proto/comdex/liquidity/v1beta1/liquidity.proto
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ message Pair {
uint64 app_id = 9;
}

// Farm Coin defines the basic implementation and meta data for the farm token.
message FarmCoin {
string denom = 1;
uint64 decimals = 2;
}

// Pool defines a basic liquidity pool with no min-price and max-price.
message Pool {
uint64 id = 1;
Expand All @@ -55,7 +61,7 @@ message Pool {

string max_price = 12 [(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec"];


FarmCoin farm_coin = 13;


}
Expand Down
2 changes: 2 additions & 0 deletions proto/comdex/liquidity/v1beta1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,8 @@ message PoolResponse {

bool disabled = 15;

FarmCoin farm_coin = 16;

}

message PoolBalances {
Expand Down
14 changes: 13 additions & 1 deletion scripts/comdex_local_setup/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,19 @@
NODE_MONIKER = "testdev"
CHAIN_ID = "test-1"
GENESIS_ACCOUNT_NAME = "cooluser"
GENESIS_TOKENS = "1000000000000000000000stake,1000000000000000000000ucmst,100000000000000000000000000ucmdx,100000000000000000000000uosmo,100000000000000000000000000uatom,10000000000000000000000000000000000000000weth-wei,10000000000000000000000000000ucgold,1000000000000000000000000000usdc"

GENESIS_MINTING_TEST_TOKENS = [
"100000000000000000000000000stake",
"100000000000000000000000000ucmdx",
"100000000000000000000000000ucmst",
"100000000000000000000000000ibc/C4CFF46FD6DE35CA4CF4CE031E643C8FDC9BA4B99AE598E9B0ED98FE3A2319F9", # ATOM
"100000000000000000000000000ibc/05AC4BBA78C5951339A47DD1BC1E7FC922A9311DF81C85745B1C162F516FF2F1", # OSMO
"100000000000000000000000000ibc/96CF88731A06654F8510473865C75200005B81A2A9FECB90389034F787015CA3", # AXLUSDC
"100000000000000000000000000ibc/065AD21492A7749E283A37AC469426562F988B7BA59712C0C545F381865A66BA", # AXLWETH
"100000000000000000000000000ibc/50EF138042B553362774A8A9DE967F610E52CAEB3BA864881C9A1436DED98075", # AXLDAI
]

GENESIS_TOKENS = ",".join(GENESIS_MINTING_TEST_TOKENS)

VOTING_PERIOD_IN_SEC = 10
DEPOSIT_PERIOD_IN_SEC = 10
4 changes: 4 additions & 0 deletions x/auction/expected/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,7 @@ type LendKeeper interface {
SetAllReserveStatsByAssetID(ctx sdk.Context, allReserveStats lendtypes.AllReserveStats)
GetAllReserveStatsByAssetID(ctx sdk.Context, id uint64) (allReserveStats lendtypes.AllReserveStats, found bool)
}

type LiquidityKeeper interface {
TransferFarmCoinOwnership(ctx sdk.Context, from, to sdk.AccAddress, farmCoin sdk.Coin) error
}
14 changes: 14 additions & 0 deletions x/auction/keeper/dutch.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"time"

liquidationtypes "github.com/comdex-official/comdex/x/liquidation/types"
liquiditytypes "github.com/comdex-official/comdex/x/liquidity/types"

sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"

Expand Down Expand Up @@ -264,6 +265,19 @@ func (k Keeper) PlaceDutchAuctionBid(ctx sdk.Context, appID, auctionMappingID, a
return err
}
}

// if the bid is on farm token, then we have the transfer the ownership of that farm token from vault owner to bidder.
if liquiditytypes.IsFarmCoinDenom(outFlowTokenCoin.Denom) {
vaultOwner, err := sdk.AccAddressFromBech32(lockedVault.Owner)
if err != nil {
return err
}
err = k.liquidity.TransferFarmCoinOwnership(ctx, vaultOwner, bidder, outFlowTokenCoin)
if err != nil {
return err
}
}

if outFlowTokenCoin.Amount.GT(sdk.ZeroInt()) {
err = k.bank.SendCoinsFromModuleToAccount(ctx, auctiontypes.ModuleName, bidder, sdk.NewCoins(outFlowTokenCoin))
if err != nil {
Expand Down
3 changes: 3 additions & 0 deletions x/auction/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type (
tokenMint expected.TokenMintKeeper
esm expected.EsmKeeper
lend expected.LendKeeper
liquidity expected.LiquidityKeeper
}
)

Expand All @@ -47,6 +48,7 @@ func NewKeeper(
tokenMintKeeper expected.TokenMintKeeper,
esm expected.EsmKeeper,
lend expected.LendKeeper,
liquidity expected.LiquidityKeeper,
) Keeper {
// set KeyTable if it has not already been set
if !ps.HasKeyTable() {
Expand All @@ -68,6 +70,7 @@ func NewKeeper(
tokenMint: tokenMintKeeper,
esm: esm,
lend: lend,
liquidity: liquidity,
}
}

Expand Down
3 changes: 2 additions & 1 deletion x/auction/keeper/keeper_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package keeper_test

import (
lendkeeper "github.com/comdex-official/comdex/x/lend/keeper"
"testing"
"time"

lendkeeper "github.com/comdex-official/comdex/x/lend/keeper"

"github.com/stretchr/testify/suite"

sdk "github.com/cosmos/cosmos-sdk/types"
Expand Down
1 change: 1 addition & 0 deletions x/liquidity/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ func EndBlocker(ctx sdk.Context, k keeper.Keeper, assetKeeper expected.AssetKeep
k.ExecuteRequests(ctx, app.Id)
k.ProcessQueuedFarmers(ctx, app.Id)
}
k.BlockAllFarmCoinTransfers(ctx, app.Id)
return nil
})
}
Expand Down
3 changes: 3 additions & 0 deletions x/liquidity/expected/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ type AccountKeeper interface {

// BankKeeper is the expected bank keeper.
type BankKeeper interface {
GetParams(ctx sdk.Context) (params banktypes.Params)
SetParams(ctx sdk.Context, params banktypes.Params)
IsSendEnabledCoin(ctx sdk.Context, coin sdk.Coin) bool
GetBalance(ctx sdk.Context, addr sdk.AccAddress, denom string) sdk.Coin
GetAllBalances(ctx sdk.Context, addr sdk.AccAddress) sdk.Coins
GetSupply(ctx sdk.Context, denom string) sdk.Coin
Expand Down
2 changes: 1 addition & 1 deletion x/liquidity/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ func (s *ModuleTestSuite) TestMsgUnfarm() {
s.Require().Equal(queuedFarmer.QueudCoins[0].FarmedPoolCoin.Denom, "pool1-1")
s.Require().Equal(queuedFarmer.QueudCoins[0].FarmedPoolCoin.Amount, sdk.NewInt(5000000000))

msgUnlock := types.NewMsgUnfarm(appID1, pool.Id, liquidityProvider1, utils.ParseCoin("5000000000pool1-1"))
msgUnlock := types.NewMsgUnfarm(appID1, pool.Id, liquidityProvider1, utils.ParseCoin("5000000000farm1-1"))
_, err = handler(s.ctx, msgUnlock)
s.Require().NoError(err)

Expand Down
20 changes: 20 additions & 0 deletions x/liquidity/keeper/block_coin_transfers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package keeper

import (
sdk "github.com/cosmos/cosmos-sdk/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
)

func (k Keeper) IsCoinTransferBlocked(ctx sdk.Context, coin sdk.Coin) bool {
return !k.bankKeeper.IsSendEnabledCoin(ctx, coin)
}

func (k Keeper) BlockCoinTransferIfNotAlready(ctx sdk.Context, coin sdk.Coin) {
if !k.IsCoinTransferBlocked(ctx, coin) {
bankParams := k.bankKeeper.GetParams(ctx)
bankParams.SendEnabled = append(bankParams.SendEnabled,
banktypes.NewSendEnabled(coin.Denom, false),
)
k.bankKeeper.SetParams(ctx, bankParams)
}
}
15 changes: 15 additions & 0 deletions x/liquidity/keeper/block_coin_transfers_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package keeper_test

import (
utils "github.com/comdex-official/comdex/types"
_ "github.com/stretchr/testify/suite"
)

func (s *KeeperTestSuite) TestBlockCoinTransferIfNotAlready() {
coin1 := utils.ParseCoin("1000coin1")
isBlocked := s.keeper.IsCoinTransferBlocked(s.ctx, coin1)
s.Require().False(isBlocked)
s.keeper.BlockCoinTransferIfNotAlready(s.ctx, coin1)
isBlocked = s.keeper.IsCoinTransferBlocked(s.ctx, coin1)
s.Require().True(isBlocked)
}
4 changes: 4 additions & 0 deletions x/liquidity/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ func (s *KeeperTestSuite) TestPools() {
s.Require().Equal(resp.Pools[0].LastWithdrawRequestId, pool.LastWithdrawRequestId)
s.Require().Equal(resp.Pools[0].AppId, pool.AppId)
s.Require().Equal(resp.Pools[0].PoolCoinSupply, s.getBalance(addr1, pool.PoolCoinDenom).Amount)
s.Require().Equal(resp.Pools[0].FarmCoin, pool.FarmCoin)
}

func (s *KeeperTestSuite) TestPool() {
Expand Down Expand Up @@ -161,6 +162,7 @@ func (s *KeeperTestSuite) TestPool() {
s.Require().Equal(resp.Pool.LastWithdrawRequestId, pool.LastWithdrawRequestId)
s.Require().Equal(resp.Pool.AppId, pool.AppId)
s.Require().Equal(resp.Pool.PoolCoinSupply, s.getBalance(addr1, pool.PoolCoinDenom).Amount)
s.Require().Equal(resp.Pool.FarmCoin, pool.FarmCoin)
}
})
}
Expand Down Expand Up @@ -233,6 +235,7 @@ func (s *KeeperTestSuite) TestPoolByReserveAddress() {
s.Require().Equal(resp.Pool.LastWithdrawRequestId, pool.LastWithdrawRequestId)
s.Require().Equal(resp.Pool.AppId, pool.AppId)
s.Require().Equal(resp.Pool.PoolCoinSupply, s.getBalance(addr1, pool.PoolCoinDenom).Amount)
s.Require().Equal(resp.Pool.FarmCoin, pool.FarmCoin)
}
})
}
Expand Down Expand Up @@ -305,6 +308,7 @@ func (s *KeeperTestSuite) TestPoolByPoolCoinDenom() {
s.Require().Equal(resp.Pool.LastWithdrawRequestId, pool.LastWithdrawRequestId)
s.Require().Equal(resp.Pool.AppId, pool.AppId)
s.Require().Equal(resp.Pool.PoolCoinSupply, s.getBalance(addr1, pool.PoolCoinDenom).Amount)
s.Require().Equal(resp.Pool.FarmCoin, pool.FarmCoin)
}
})
}
Expand Down
5 changes: 5 additions & 0 deletions x/liquidity/keeper/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"

v2 "github.com/comdex-official/comdex/x/liquidity/legacy/v2"
v3 "github.com/comdex-official/comdex/x/liquidity/legacy/v3"
)

type Migrator struct {
Expand All @@ -17,3 +18,7 @@ func NewMigrator(keeper Keeper) Migrator {
func (m Migrator) Migrate1to2(ctx sdk.Context) error {
return v2.MigrateStore(ctx, m.keeper.assetKeeper, m.keeper.storeKey, m.keeper.cdc)
}

func (m Migrator) Migrate2to3(ctx sdk.Context) error {
return v3.MigrateStore(ctx, m.keeper.assetKeeper, m.keeper.bankKeeper, m.keeper.storeKey, m.keeper.cdc)
}
37 changes: 35 additions & 2 deletions x/liquidity/keeper/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,14 @@ func (k Keeper) ValidateMsgCreatePool(ctx sdk.Context, msg *types.MsgCreatePool)
return sdkerrors.Wrapf(sdkerrors.ErrNotFound, "pair %d not found", msg.PairId)
}

if !k.assetKeeper.HasAssetForDenom(ctx, pair.BaseCoinDenom) {
return sdkerrors.Wrapf(types.ErrAssetNotWhiteListed, "asset with denom %s is not white listed - expired pair", pair.BaseCoinDenom)
}

if !k.assetKeeper.HasAssetForDenom(ctx, pair.QuoteCoinDenom) {
return sdkerrors.Wrapf(types.ErrAssetNotWhiteListed, "asset with denom %s is not white listed - expired pair", pair.QuoteCoinDenom)
}

params, err := k.GetGenericParams(ctx, msg.AppId)
if err != nil {
return sdkerrors.Wrap(err, "params retreval failed")
Expand Down Expand Up @@ -138,12 +146,17 @@ func (k Keeper) CreatePool(ctx sdk.Context, msg *types.MsgCreatePool) (types.Poo
return types.Pool{}, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, err.Error())
}

// asset existence validation in already done at this stage
baseAsset, _ := k.assetKeeper.GetAssetForDenom(ctx, pair.BaseCoinDenom)
quoteAsset, _ := k.assetKeeper.GetAssetForDenom(ctx, pair.QuoteCoinDenom)

// Create and save the new pool object.
poolID := k.getNextPoolIDWithUpdate(ctx, msg.AppId)
pool := types.NewBasicPool(msg.AppId, poolID, pair.Id, msg.GetCreator())
pool := types.NewBasicPool(msg.AppId, poolID, pair.Id, msg.GetCreator(), baseAsset, quoteAsset)
k.SetPool(ctx, pool)
k.SetPoolByReserveIndex(ctx, pool)
k.SetPoolsByPairIndex(ctx, pool)
k.BlockCoinTransferIfNotAlready(ctx, sdk.NewCoin(pool.FarmCoin.Denom, sdk.NewInt(0)))

// Send deposit coins to the pool's reserve account.
creator := msg.GetCreator()
Expand Down Expand Up @@ -244,6 +257,14 @@ func (k Keeper) ValidateMsgCreateRangedPool(ctx sdk.Context, msg *types.MsgCreat
return sdkerrors.Wrapf(sdkerrors.ErrNotFound, "pair %d not found", msg.PairId)
}

if !k.assetKeeper.HasAssetForDenom(ctx, pair.BaseCoinDenom) {
return sdkerrors.Wrapf(types.ErrAssetNotWhiteListed, "asset with denom %s is not white listed - expired pair", pair.BaseCoinDenom)
}

if !k.assetKeeper.HasAssetForDenom(ctx, pair.QuoteCoinDenom) {
return sdkerrors.Wrapf(types.ErrAssetNotWhiteListed, "asset with denom %s is not white listed - expired pair", pair.QuoteCoinDenom)
}

for _, coin := range msg.DepositCoins {
if coin.Denom != pair.BaseCoinDenom && coin.Denom != pair.QuoteCoinDenom {
return sdkerrors.Wrapf(types.ErrInvalidCoinDenom, "coin denom %s is not in the pair", coin.Denom)
Expand Down Expand Up @@ -289,12 +310,17 @@ func (k Keeper) CreateRangedPool(ctx sdk.Context, msg *types.MsgCreateRangedPool
return types.Pool{}, types.ErrInsufficientDepositAmount
}

// asset existence validation in already done at this stage
baseAsset, _ := k.assetKeeper.GetAssetForDenom(ctx, pair.BaseCoinDenom)
quoteAsset, _ := k.assetKeeper.GetAssetForDenom(ctx, pair.QuoteCoinDenom)

// Create and save the new pool object.
poolID := k.getNextPoolIDWithUpdate(ctx, msg.AppId)
pool := types.NewRangedPool(msg.AppId, poolID, pair.Id, msg.GetCreator(), msg.MinPrice, msg.MaxPrice)
pool := types.NewRangedPool(msg.AppId, poolID, pair.Id, msg.GetCreator(), msg.MinPrice, msg.MaxPrice, baseAsset, quoteAsset)
k.SetPool(ctx, pool)
k.SetPoolByReserveIndex(ctx, pool)
k.SetPoolsByPairIndex(ctx, pool)
k.BlockCoinTransferIfNotAlready(ctx, sdk.NewCoin(pool.FarmCoin.Denom, sdk.NewInt(0)))

// Send deposit coins to the pool's reserve account.
creator := msg.GetCreator()
Expand Down Expand Up @@ -817,3 +843,10 @@ func (k Keeper) WasmMsgAddEmissionPoolRewards(ctx sdk.Context, appID, cswapAppID

return nil
}

func (k Keeper) BlockAllFarmCoinTransfers(ctx sdk.Context, appID uint64) {
pools := k.GetAllPools(ctx, appID)
for _, pool := range pools {
k.BlockCoinTransferIfNotAlready(ctx, sdk.NewCoin(pool.FarmCoin.Denom, sdk.NewInt(0)))
}
}
Loading