-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add LP_MINING_PROGRAM earn type (#402)
* 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
1 parent
d5a011a
commit 60a39d8
Showing
23 changed files
with
1,902 additions
and
189 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,4 +29,5 @@ enum EarnType { | |
ELYS_PROGRAM = 2; | ||
EDEN_PROGRAM = 3; | ||
EDENB_PROGRAM = 4; | ||
LP_MINING_PROGRAM = 5; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
Oops, something went wrong.