Skip to content

Commit

Permalink
feat: Add a claim-rewards command (#566)
Browse files Browse the repository at this point in the history
Co-authored-by: Itay Levy <[email protected]>
  • Loading branch information
ItayLevyOfficial and Itay Levy authored Oct 25, 2023
1 parent 1e6decd commit dffb1ec
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 16 deletions.
15 changes: 15 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,28 @@ jobs:
make build
make go-install
make cel-key
- name: Get the latest version of the cosmos sdk
run: |
if [ -d "./cosmos-sdk" ]; then
cd cosmos-sdk
git fetch --all
else
git clone https://github.com/cosmos/cosmos-sdk.git
cd cosmos-sdk
fi
git checkout tags/v0.47.5
- name: Build cosmos-sdk
run: |
cd ./cosmos-sdk
make build
- name: Create roller_bins archive folder structure
run: |
rm -rf roller_bins
mkdir roller_bins
mkdir roller_bins/lib
sudo cp ./celestia-node/cel-key ./roller_bins/lib/cel-key
sudo cp ./celestia-node/build/celestia ./roller_bins/lib/celestia
sudo cp ./cosmos-sdk/build/simd ./roller_bins/lib/simd
sudo cp -r /usr/local/bin/roller_bins/* ./roller_bins/lib/
sudo cp /usr/local/bin/roller ./roller_bins/roller
sudo cp /usr/local/bin/rollapp_evm ./roller_bins/rollapp_evm
Expand Down
23 changes: 13 additions & 10 deletions cmd/consts/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package consts
import (
"fmt"
"github.com/dymensionxyz/roller/config"
"math/big"
)

const binsDir = "/usr/local/bin"
Expand All @@ -17,13 +16,15 @@ var Executables = struct {
Dymension string
CelKey string
Roller string
Simd string
}{
Roller: fmt.Sprintf("%s/roller", binsDir),
RollappEVM: fmt.Sprintf("%s/rollapp_evm", binsDir),
Dymension: fmt.Sprintf("%s/dymd", binsDir),
Celestia: fmt.Sprintf("%s/celestia", internalBinsDir),
CelKey: fmt.Sprintf("%s/cel-key", internalBinsDir),
Relayer: fmt.Sprintf("%s/rly", internalBinsDir),
Simd: fmt.Sprintf("%s/simd", internalBinsDir),
}

var KeysIds = struct {
Expand Down Expand Up @@ -74,9 +75,6 @@ const (
DefaultRollappRPC = "http://localhost:26657"
)

// TODO: Check DA LC write price on arabica and update this value.
var OneDAWritePrice = big.NewInt(1)

var SpinnerMsgs = struct {
UniqueIdVerification string
BalancesVerification string
Expand All @@ -85,6 +83,13 @@ var SpinnerMsgs = struct {
BalancesVerification: " Verifying balances...\n",
}

var FroopylandHubData = config.HubData{
API_URL: "https://froopyland.api.silknodes.io:443",
ID: FroopylandHubID,
RPC_URL: "https://froopyland.rpc.silknodes.io:443",
GAS_PRICE: "0.25",
}

// TODO(#112): The avaialble hub networks should be read from YAML file
var Hubs = map[string]config.HubData{
StagingHubName: {
Expand All @@ -93,24 +98,22 @@ var Hubs = map[string]config.HubData{
RPC_URL: "https://dymension-devnet.rpc.silknodes.io:443",
GAS_PRICE: "0.25",
},
FroopylandHubName: {
API_URL: "https://froopyland.api.silknodes.io:443",
ID: FroopylandHubID,
RPC_URL: "https://froopyland.rpc.silknodes.io:443",
GAS_PRICE: "0.25",
},
FroopylandHubName: FroopylandHubData,
LocalHubName: {
API_URL: "http://localhost:1318",
ID: LocalHubID,
RPC_URL: "http://localhost:36657",
GAS_PRICE: "0",
},
// TODO: Add mainnet hub data
MainnetHubName: FroopylandHubData,
}

const (
StagingHubName = "devnet"
FroopylandHubName = "froopyland"
LocalHubName = "local"
MainnetHubName = "mainnet"
LocalHubID = "dymension_100-1"
StagingHubID = "devnet_304-1"
FroopylandHubID = "froopyland_100-1"
Expand Down
75 changes: 75 additions & 0 deletions cmd/tx/claim/claim.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package claim

import (
"fmt"
"github.com/dymensionxyz/roller/cmd/consts"
"github.com/dymensionxyz/roller/cmd/utils"
"github.com/spf13/cobra"
"math/big"
"os"
"os/exec"
)

func Cmd() *cobra.Command {
cmd := &cobra.Command{
Use: "claim-rewards <private-key> <destination-address>",
Short: "Send the DYM rewards associated with the given private key to the destination address",
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
shouldProceed, err := utils.PromptBool(fmt.Sprintf(
"This command will transfer all Rollapp rewards on the mainnet to %s. Please note that once"+
" initiated, this action cannot be undone. Do you wish to proceed", args[1]))
if err != nil {
return err
}
if !shouldProceed {
return nil
}
tempDir, err := os.MkdirTemp(os.TempDir(), "hub_sequencer")
if err != nil {
return err
}
importKeyCmd := exec.Command(consts.Executables.Simd, "keys", "import-hex",
consts.KeysIds.HubSequencer, args[0], "--home", tempDir)
_, err = utils.ExecBashCommandWithStdout(importKeyCmd)
if err != nil {
return err
}
sequencerAddr, err := utils.GetAddressBinary(utils.KeyConfig{
ID: consts.KeysIds.HubSequencer,
Dir: tempDir,
}, consts.Executables.Dymension)
if err != nil {
return err
}
mainnetHub := consts.Hubs[consts.MainnetHubName]
sequencerBalance, err := utils.QueryBalance(utils.ChainQueryConfig{
Binary: consts.Executables.Dymension,
Denom: consts.Denoms.Hub,
RPC: mainnetHub.RPC_URL,
}, sequencerAddr)
if err != nil {
return err
}
// Calculated by sending a tx on Froopyland and see how much fees were paid
txGasPrice := big.NewInt(50000)
totalBalanceMinusFees := new(big.Int).Sub(sequencerBalance.Amount, txGasPrice)
if totalBalanceMinusFees.Cmp(big.NewInt(0)) != 1 {
return fmt.Errorf("no rewards to claim for the address associated with the given private key: %s"+
"please try to import the private key to keplr and claim the rewards from there",
sequencerAddr)
}
rewardsAmountStr := totalBalanceMinusFees.String() + consts.Denoms.Hub
sendAllFundsCmd := exec.Command(consts.Executables.Dymension, "tx", "bank", "send", consts.KeysIds.HubSequencer,
args[1], rewardsAmountStr, "--node", mainnetHub.RPC_URL, "--chain-id", mainnetHub.ID,
"--fees", txGasPrice.String()+consts.Denoms.Hub, "-b", "block", "--yes", "--home", tempDir)
_, err = utils.ExecBashCommandWithStdout(sendAllFundsCmd)
if err != nil {
return err
}
fmt.Printf("💈 Successfully claimed %s to %s!\n", rewardsAmountStr, args[1])
return nil
},
}
return cmd
}
2 changes: 2 additions & 0 deletions cmd/tx/tx.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package tx

import (
"github.com/dymensionxyz/roller/cmd/tx/claim"
"github.com/dymensionxyz/roller/cmd/tx/fund_faucet"
"github.com/dymensionxyz/roller/cmd/tx/register"
"github.com/spf13/cobra"
Expand All @@ -13,5 +14,6 @@ func Cmd() *cobra.Command {
}
cmd.AddCommand(register.Cmd())
cmd.AddCommand(fund_faucet.Cmd())
cmd.AddCommand(claim.Cmd())
return cmd
}
2 changes: 0 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,11 @@ require (
)

require (
github.com/avast/retry-go v3.0.0+incompatible
github.com/briandowns/spinner v1.23.0
github.com/centrifuge/go-substrate-rpc-client/v4 v4.0.0-00010101000000-000000000000
github.com/cosmos/go-bip39 v1.0.0
github.com/fatih/color v1.15.0
github.com/gizak/termui/v3 v3.1.0
github.com/google/go-cmp v0.5.9
github.com/manifoldco/promptui v0.9.0
github.com/olekukonko/tablewriter v0.0.5
github.com/pelletier/go-toml v1.9.5
Expand Down
4 changes: 0 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883/go.mod h1:rCTlJbsFo
github.com/apache/arrow/go/arrow v0.0.0-20191024131854-af6fa24be0db/go.mod h1:VTxUBvSJ3s3eHAg65PNgrsn5BtqCRPdmyXh6rAfdxN0=
github.com/availproject/go-substrate-rpc-client/v4 v4.0.12-avail-1.4.0-rc1-5e286e3 h1:9bPK0/Vd+uOQul3vEBSemRXO+rwqi+UXDAvFzNUlG8A=
github.com/availproject/go-substrate-rpc-client/v4 v4.0.12-avail-1.4.0-rc1-5e286e3/go.mod h1:5g1oM4Zu3BOaLpsKQ+O8PAv2kNuq+kPcA1VzFbsSqxE=
github.com/avast/retry-go v3.0.0+incompatible h1:4SOWQ7Qs+oroOTQOYnAHqelpCO0biHSxpiH9JdtuBj0=
github.com/avast/retry-go v3.0.0+incompatible/go.mod h1:XtSnn+n/sHqQIpZ10K1qAevBhOOCWBLXXy3hyiqqBrY=
github.com/aws/aws-sdk-go-v2 v1.2.0/go.mod h1:zEQs02YRBw1DjK0PoJv3ygDYOFTre1ejlJWl8FwAuQo=
github.com/aws/aws-sdk-go-v2/config v1.1.1/go.mod h1:0XsVy9lBI/BCXm+2Tuvt39YmdHwS5unDQmxZOYe8F5Y=
github.com/aws/aws-sdk-go-v2/credentials v1.1.1/go.mod h1:mM2iIjwl7LULWtS6JCACyInboHirisUUdkBPoTHMOUo=
Expand Down Expand Up @@ -179,8 +177,6 @@ github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMyw
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.4.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/gofuzz v1.1.1-0.20200604201612-c04b05f3adfa h1:Q75Upo5UN4JbPFURXZ8nLKYUvF85dyFRop/vQ0Rv+64=
github.com/google/gofuzz v1.1.1-0.20200604201612-c04b05f3adfa/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs=
Expand Down

0 comments on commit dffb1ec

Please sign in to comment.