Skip to content

Commit

Permalink
add LP_MINING_PROGRAM earn type (#402)
Browse files Browse the repository at this point in the history
* add LP_MINING_PROGRAM earn type

* add join/exit pool estimation query

* add wasm query for join/exit pool

* add unit test for LP_MINING_PROGRAM claim

* add unit test for join/exit pool estimation query

---------

Co-authored-by: Cosmic Vagabond <[email protected]>
  • Loading branch information
jelysn and cosmic-vagabond authored Mar 13, 2024
1 parent d5a011a commit 60a39d8
Show file tree
Hide file tree
Showing 23 changed files with 1,902 additions and 189 deletions.
152 changes: 152 additions & 0 deletions docs/static/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37700,6 +37700,67 @@ paths:
type: string
tags:
- Query
/elys-network/elys/amm/exit_pool_estimation:
get:
summary: Queries ExistPool estimation
operationId: ElysAmmExitPoolEstimation
responses:
'200':
description: A successful response.
schema:
type: object
properties:
amounts_out:
type: array
items:
type: object
properties:
denom:
type: string
amount:
type: string
description: >-
Coin defines a token with a denomination and an amount.


NOTE: The amount field is an Int which implements the custom
method

signatures required by gogoproto.
default:
description: An unexpected error response.
schema:
type: object
properties:
code:
type: integer
format: int32
message:
type: string
details:
type: array
items:
type: object
properties:
'@type':
type: string
additionalProperties: {}
parameters:
- name: pool_id
in: query
required: false
type: string
format: uint64
- name: share_amount_in
in: query
required: false
type: string
- name: token_out_denom
in: query
required: false
type: string
tags:
- Query
/elys-network/elys/amm/in_route_by_denom/{denom_in}/{denom_out}:
get:
summary: Queries a list of InRouteByDenom items.
Expand Down Expand Up @@ -37749,6 +37810,61 @@ paths:
type: string
tags:
- Query
/elys-network/elys/amm/join_pool_estimation:
get:
summary: Queries JoinPool estimation
operationId: ElysAmmJoinPoolEstimation
responses:
'200':
description: A successful response.
schema:
type: object
properties:
share_amount_out:
type: string
amounts_in:
type: array
items:
type: object
properties:
denom:
type: string
amount:
type: string
description: >-
Coin defines a token with a denomination and an amount.


NOTE: The amount field is an Int which implements the custom
method

signatures required by gogoproto.
default:
description: An unexpected error response.
schema:
type: object
properties:
code:
type: integer
format: int32
message:
type: string
details:
type: array
items:
type: object
properties:
'@type':
type: string
additionalProperties: {}
parameters:
- name: pool_id
in: query
required: false
type: string
format: uint64
tags:
- Query
/elys-network/elys/amm/out_route_by_denom/{denom_out}/{denom_in}:
get:
summary: Queries a list of OutRouteByDenom items.
Expand Down Expand Up @@ -82951,6 +83067,23 @@ definitions:

NOTE: The amount field is an Int which implements the custom method
signatures required by gogoproto.
elys.amm.QueryExitPoolEstimationResponse:
type: object
properties:
amounts_out:
type: array
items:
type: object
properties:
denom:
type: string
amount:
type: string
description: |-
Coin defines a token with a denomination and an amount.

NOTE: The amount field is an Int which implements the custom method
signatures required by gogoproto.
elys.amm.QueryGetDenomLiquidityResponse:
type: object
properties:
Expand Down Expand Up @@ -83048,6 +83181,25 @@ definitions:
format: uint64
token_out_denom:
type: string
elys.amm.QueryJoinPoolEstimationResponse:
type: object
properties:
share_amount_out:
type: string
amounts_in:
type: array
items:
type: object
properties:
denom:
type: string
amount:
type: string
description: |-
Coin defines a token with a denomination and an amount.

NOTE: The amount field is an Int which implements the custom method
signatures required by gogoproto.
elys.amm.QueryOutRouteByDenomResponse:
type: object
properties:
Expand Down
28 changes: 28 additions & 0 deletions proto/elys/amm/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ service Query {
rpc SwapEstimation (QuerySwapEstimationRequest) returns (QuerySwapEstimationResponse) {
option (google.api.http).get = "/elys-network/elys/amm/swap_estimation";
}
// Queries JoinPool estimation
rpc JoinPoolEstimation (QueryJoinPoolEstimationRequest) returns (QueryJoinPoolEstimationResponse) {
option (google.api.http).get = "/elys-network/elys/amm/join_pool_estimation";
}
// Queries ExistPool estimation
rpc ExitPoolEstimation (QueryExitPoolEstimationRequest) returns (QueryExitPoolEstimationResponse) {
option (google.api.http).get = "/elys-network/elys/amm/exit_pool_estimation";
}
// Queries slippage track for a week.
rpc SlippageTrack (QuerySlippageTrackRequest) returns (QuerySlippageTrackResponse) {
option (google.api.http).get = "/elys-network/elys/amm/slippage_track/{pool_id}";
Expand Down Expand Up @@ -117,6 +125,26 @@ message QuerySwapEstimationRequest {
string discount = 3 [(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", (gogoproto.nullable) = false];
}

message QueryJoinPoolEstimationRequest {
uint64 pool_id = 1;
repeated cosmos.base.v1beta1.Coin amounts_in = 2 [(gogoproto.nullable) = false] ;
}

message QueryJoinPoolEstimationResponse {
string share_amount_out = 1 [(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", (gogoproto.nullable) = false];
repeated cosmos.base.v1beta1.Coin amounts_in = 2 [(gogoproto.nullable) = false] ;
}

message QueryExitPoolEstimationRequest {
uint64 pool_id = 1;
string share_amount_in = 2 [(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", (gogoproto.nullable) = false];
string token_out_denom = 3;
}

message QueryExitPoolEstimationResponse {
repeated cosmos.base.v1beta1.Coin amounts_out = 1 [(gogoproto.nullable) = false] ;
}

message QuerySwapEstimationResponse {
string spot_price = 1 [(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", (gogoproto.nullable) = false];
cosmos.base.v1beta1.Coin token_out = 2 [(gogoproto.nullable) = false ] ;
Expand Down
1 change: 1 addition & 0 deletions proto/elys/commitment/params.proto
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@ enum EarnType {
ELYS_PROGRAM = 2;
EDEN_PROGRAM = 3;
EDENB_PROGRAM = 4;
LP_MINING_PROGRAM = 5;
}
2 changes: 2 additions & 0 deletions wasmbindings/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ type ElysQuery struct {
AmmDenomLiquidityAll *ammtypes.QueryAllDenomLiquidityRequest `json:"amm_denom_liquidity_all,omitempty"`
AmmSwapEstimation *ammtypes.QuerySwapEstimationRequest `json:"amm_swap_estimation,omitempty"`
AmmSwapEstimationByDenom *ammtypes.QuerySwapEstimationByDenomRequest `json:"amm_swap_estimation_by_denom,omitempty"`
AmmJoinPoolEstimation *ammtypes.QueryJoinPoolEstimationRequest `json:"amm_join_pool_estimation,omitempty"`
AmmExitPoolEstimation *ammtypes.QueryExitPoolEstimationRequest `json:"amm_exit_pool_estimation,omitempty"`
AmmSlippageTrack *ammtypes.QuerySlippageTrackRequest `json:"amm_slippage_track,omitempty"`
AmmSlippageTrackAll *ammtypes.QuerySlippageTrackAllRequest `json:"amm_slippage_track_all,omitempty"`
AmmBalance *ammtypes.QueryBalanceRequest `json:"amm_balance,omitempty"`
Expand Down
57 changes: 57 additions & 0 deletions x/amm/client/cli/query_exit_pool_estimation.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package cli

import (
"errors"
"strconv"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/elys-network/elys/x/amm/types"
"github.com/spf13/cobra"
)

func CmdExitPoolEstimation() *cobra.Command {
cmd := &cobra.Command{
Use: "exit-pool-estimation [pool_id] [token-in] [token_out_denom]",
Short: "Query ExitPoolEstimation",
Example: "elysd q amm exit-pool-estimation 1 10000 token",
Args: cobra.ExactArgs(3),
RunE: func(cmd *cobra.Command, args []string) (err error) {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}

poolId, err := strconv.Atoi(args[0])
if err != nil {
return err
}

shareAmountIn, ok := sdk.NewIntFromString(args[1])
if !ok {
return errors.New("invalid share in amount")
}

tokenOutDenom := args[2]

params := &types.QueryExitPoolEstimationRequest{
PoolId: uint64(poolId),
ShareAmountIn: shareAmountIn,
TokenOutDenom: tokenOutDenom,
}

queryClient := types.NewQueryClient(clientCtx)
res, err := queryClient.ExitPoolEstimation(cmd.Context(), params)
if err != nil {
return err
}

return clientCtx.PrintProto(res)
},
}

flags.AddQueryFlagsToCmd(cmd)

return cmd
}
53 changes: 53 additions & 0 deletions x/amm/client/cli/query_join_pool_estimation.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package cli

import (
"strconv"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/elys-network/elys/x/amm/types"
"github.com/spf13/cobra"
)

func CmdJoinPoolEstimation() *cobra.Command {
cmd := &cobra.Command{
Use: "join-pool-estimation [pool_id] [tokens-in]",
Short: "Query JoinPoolEstimation",
Example: "elysd q amm join-pool-estimation 1 100token,100token2",
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) (err error) {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}

poolId, err := strconv.Atoi(args[0])
if err != nil {
return err
}

reqTokensIn, err := sdk.ParseCoinsNormalized(args[1])
if err != nil {
return err
}

params := &types.QueryJoinPoolEstimationRequest{
PoolId: uint64(poolId),
AmountsIn: reqTokensIn,
}

queryClient := types.NewQueryClient(clientCtx)
res, err := queryClient.JoinPoolEstimation(cmd.Context(), params)
if err != nil {
return err
}

return clientCtx.PrintProto(res)
},
}

flags.AddQueryFlagsToCmd(cmd)

return cmd
}
4 changes: 4 additions & 0 deletions x/amm/client/wasm/querier.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ func (oq *Querier) HandleQuery(ctx sdk.Context, query wasmbindingstypes.ElysQuer
return oq.querySwapEstimation(ctx, query.AmmSwapEstimation)
case query.AmmSwapEstimationByDenom != nil:
return oq.querySwapEstimationByDenom(ctx, query.AmmSwapEstimationByDenom)
case query.AmmJoinPoolEstimation != nil:
return oq.queryJoinPoolEstimation(ctx, query.AmmJoinPoolEstimation)
case query.AmmExitPoolEstimation != nil:
return oq.queryExitPoolEstimation(ctx, query.AmmExitPoolEstimation)
case query.AmmSlippageTrack != nil:
return oq.querySlippageTrack(ctx, query.AmmSlippageTrack)
case query.AmmSlippageTrackAll != nil:
Expand Down
22 changes: 22 additions & 0 deletions x/amm/client/wasm/query_exit_pool_estimation.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package wasm

import (
"encoding/json"

errorsmod "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
ammtypes "github.com/elys-network/elys/x/amm/types"
)

func (oq *Querier) queryExitPoolEstimation(ctx sdk.Context, query *ammtypes.QueryExitPoolEstimationRequest) ([]byte, error) {
res, err := oq.keeper.ExitPoolEstimation(sdk.WrapSDKContext(ctx), query)
if err != nil {
return nil, errorsmod.Wrap(err, "failed to get exit pool estimation")
}

responseBytes, err := json.Marshal(res)
if err != nil {
return nil, errorsmod.Wrap(err, "failed to serialize exit pool estimation response")
}
return responseBytes, nil
}
Loading

0 comments on commit 60a39d8

Please sign in to comment.