-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add new CLP tx to add liquidity to rewards bucket
- Loading branch information
Showing
30 changed files
with
1,643 additions
and
147 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
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,13 @@ | ||
package sample | ||
|
||
import ( | ||
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
) | ||
|
||
// AccAddress returns a sample account address | ||
func AccAddress() string { | ||
pk := ed25519.GenPrivKey().PubKey() | ||
addr := pk.Address() | ||
return sdk.AccAddress(addr).String() | ||
} |
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,47 @@ | ||
package cli | ||
|
||
import ( | ||
"strconv" | ||
|
||
"github.com/Sifchain/sifnode/x/clp/types" | ||
"github.com/cosmos/cosmos-sdk/client" | ||
"github.com/cosmos/cosmos-sdk/client/flags" | ||
"github.com/cosmos/cosmos-sdk/client/tx" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var _ = strconv.Itoa(0) | ||
|
||
func CmdAddLiquidityToRewardsBucket() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "add-liquidity-to-rewards-bucket [amount]", | ||
Example: "sifnodecli tx clp add-liquidity-to-rewards-bucket 100000000000000000000000000rowan,100000000000000000000000000ceth,100000000cusdc", | ||
Short: "To add liquidity to the rewards bucket", | ||
Args: cobra.ExactArgs(1), | ||
RunE: func(cmd *cobra.Command, args []string) (err error) { | ||
argAmount, err := sdk.ParseCoinsNormalized(args[0]) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
clientCtx, err := client.GetClientTxContext(cmd) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
msg := types.NewMsgAddLiquidityToRewardsBucketRequest( | ||
clientCtx.GetFromAddress().String(), | ||
argAmount, | ||
) | ||
if err := msg.ValidateBasic(); err != nil { | ||
return err | ||
} | ||
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) | ||
}, | ||
} | ||
|
||
flags.AddTxFlagsToCmd(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
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,29 @@ | ||
package keeper | ||
|
||
import ( | ||
"github.com/Sifchain/sifnode/x/clp/types" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
) | ||
|
||
func (k Keeper) AddLiquidityToRewardsBucket(ctx sdk.Context, signer string, amounts sdk.Coins) (sdk.Coins, error) { | ||
// check that the sender has all the coins in the wallet | ||
for _, coin := range amounts { | ||
if !k.bankKeeper.HasBalance(ctx, sdk.AccAddress(signer), coin) { | ||
return nil, types.ErrBalanceNotAvailable | ||
} | ||
} | ||
|
||
// send from user to module | ||
err := k.bankKeeper.SendCoinsFromAccountToModule(ctx, sdk.AccAddress(signer), types.ModuleName, amounts) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
// add multiple coins to rewards buckets | ||
addedCoins, err := k.AddMultipleCoinsToRewardsBuckets(ctx, amounts) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return addedCoins, nil | ||
} |
Oops, something went wrong.