Skip to content

Commit

Permalink
Feat/leverage (#295)
Browse files Browse the repository at this point in the history
* fix conflict

* chore: complete rebase

---------

Co-authored-by: kenta-elys <kenta@elys.enetwork>
  • Loading branch information
kenta-elys and kenta-elys authored Dec 8, 2023
1 parent eae6a1c commit 5201e91
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 106 deletions.
7 changes: 4 additions & 3 deletions proto/elys/amm/types.proto
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ enum FilterType {
FilterPerpetual = 1;
FilterFixedWeight = 2;
FilterDynamicWeight = 3;
FilterLeverage = 4;
}

message QueryEarnPoolRequest {
Expand All @@ -22,9 +23,9 @@ message QueryEarnPoolRequest {

message EarnPool {
repeated PoolAsset assets = 1 [(gogoproto.nullable) = false];
string pool_ratio = 2 [(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", (gogoproto.nullable) = false];
string dex_apr = 3 [(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", (gogoproto.nullable) = false];
string eden_apr = 4 [(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", (gogoproto.nullable) = false];
string pool_ratio = 2;
string rewards_apr = 3 [(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", (gogoproto.nullable) = false];
string borrow_apr = 4 [(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", (gogoproto.nullable) = false];
string leverage_lp = 5 [(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", (gogoproto.nullable) = false];
string perpetual = 6 [(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", (gogoproto.nullable) = false];
string tvl = 7 [(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", (gogoproto.nullable) = false];
Expand Down
2 changes: 1 addition & 1 deletion wasmbindings/client/register_custom_plugins.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func RegisterCustomPlugins(
accountedpoolQuerier := accountedpoolclientwasm.NewQuerier(accountedpool)
accountedpoolMessenger := accountedpoolclientwasm.NewMessenger(accountedpool)

ammQuerier := ammclientwasm.NewQuerier(amm, bank, commitment, assetprofile, margin, incentive, oracle, leveragelp, accountedpool)
ammQuerier := ammclientwasm.NewQuerier(amm, bank, commitment, assetprofile, margin, incentive, oracle, leveragelp, accountedpool, stablestake)
ammMessenger := ammclientwasm.NewMessenger(amm)

assetprofileQuerier := assetprofileclientwasm.NewQuerier(assetprofile)
Expand Down
6 changes: 5 additions & 1 deletion x/amm/client/wasm/querier.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
leveragelpkeeper "github.com/elys-network/elys/x/leveragelp/keeper"
marginkeeper "github.com/elys-network/elys/x/margin/keeper"
oraclekeeper "github.com/elys-network/elys/x/oracle/keeper"
stablestakekeeper "github.com/elys-network/elys/x/stablestake/keeper"
)

// Querier handles queries for the AMM module.
Expand All @@ -25,6 +26,7 @@ type Querier struct {
oraclekeeper *oraclekeeper.Keeper
leveragelpKeeper *leveragelpkeeper.Keeper
accountedpoolKeeper *accountedpoolkeeper.Keeper
stablestakeKeeper *stablestakekeeper.Keeper
}

func NewQuerier(
Expand All @@ -36,7 +38,8 @@ func NewQuerier(
incentiveKeeper *incentivekeeper.Keeper,
oraclekeeper *oraclekeeper.Keeper,
leveragelpKeeper *leveragelpkeeper.Keeper,
accountedpoolKeeper *accountedpoolkeeper.Keeper) *Querier {
accountedpoolKeeper *accountedpoolkeeper.Keeper,
stablestakeKeeper *stablestakekeeper.Keeper) *Querier {
return &Querier{
keeper: keeper,
bankKeeper: bankKeeper,
Expand All @@ -47,6 +50,7 @@ func NewQuerier(
oraclekeeper: oraclekeeper,
leveragelpKeeper: leveragelpKeeper,
accountedpoolKeeper: accountedpoolKeeper,
stablestakeKeeper: stablestakeKeeper,
}
}

Expand Down
26 changes: 16 additions & 10 deletions x/amm/client/wasm/query_earn_mining_pool_all.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,37 @@ func (oq *Querier) checkFilterType(ctx sdk.Context, ammPool *types.Pool, filterT
return ammPool.PoolParams.UseOracle
case types.FilterType_FilterDynamicWeight:
return !ammPool.PoolParams.UseOracle
case types.FilterType_FilterLeverage:
_, found := oq.leveragelpKeeper.GetPool(ctx, ammPool.PoolId)
return found
}

return false
}

// Generate earn pool struct
func (oq *Querier) generateEarnPool(ctx sdk.Context, ammPool *types.Pool) types.EarnPool {
func (oq *Querier) generateEarnPool(ctx sdk.Context, ammPool *types.Pool, filterType types.FilterType) types.EarnPool {
dexApr := sdk.ZeroDec()
edenApr := sdk.ZeroDec()
borrowApr := sdk.ZeroDec()
leverageLpPercent := sdk.ZeroDec()
perpetualPercent := sdk.ZeroDec()

poolInfo, found := oq.incentiveKeeper.GetPoolInfo(ctx, ammPool.PoolId)
if found {
dexApr = poolInfo.DexApr
edenApr = poolInfo.EdenApr
}

if filterType == types.FilterType_FilterLeverage {
prams := oq.stablestakeKeeper.GetParams(ctx)
borrowApr = prams.InterestRate
}
tvl, _ := ammPool.TVL(ctx, oq.oraclekeeper)

// Get rewards amount
rewards := oq.incentiveKeeper.GetDexRewardsAmountForPool(ctx, ammPool.PoolId)

// Get pool share
poolShare, _ := oq.incentiveKeeper.CalculatePoolShare(ctx, ammPool)
// Get pool ratio
poolRatio := oq.incentiveKeeper.CalculatePoolRatio(ctx, ammPool)

leverageLpPool, found := oq.leveragelpKeeper.GetPool(ctx, ammPool.PoolId)
if found {
Expand All @@ -58,9 +64,9 @@ func (oq *Querier) generateEarnPool(ctx sdk.Context, ammPool *types.Pool) types.

return types.EarnPool{
Assets: ammPool.PoolAssets,
PoolRatio: poolShare,
DexApr: dexApr,
EdenApr: edenApr,
PoolRatio: poolRatio,
RewardsApr: dexApr,
BorrowApr: borrowApr,
LeverageLp: leverageLpPercent,
Perpetual: perpetualPercent,
Tvl: tvl,
Expand Down Expand Up @@ -106,7 +112,7 @@ func (oq *Querier) queryEarnMiningPoolAll(ctx sdk.Context, poolRequest *types.Qu
}

// Construct earn pool
earnPool := oq.generateEarnPool(ctx, &pool)
earnPool := oq.generateEarnPool(ctx, &pool, poolRequest.FilterType)
pools = append(pools, earnPool)
}
} else {
Expand All @@ -128,7 +134,7 @@ func (oq *Querier) queryEarnMiningPoolAll(ctx sdk.Context, poolRequest *types.Qu
}

// Construct earn pool
earnPool := oq.generateEarnPool(ctx, &p)
earnPool := oq.generateEarnPool(ctx, &p, poolRequest.FilterType)
pools = append(pools, earnPool)

return false
Expand Down
134 changes: 71 additions & 63 deletions x/amm/types/types.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 5201e91

Please sign in to comment.