forked from osmosis-labs/osmosis
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Claim module - April 5 rebase (osmosis-labs#72)
* claim module + genesis generator command prototype * Update x/claim/spec/README.md Co-authored-by: Dev Ojha <[email protected]> * Update x/claim/spec/README.md Co-authored-by: Dev Ojha <[email protected]> * Update x/claim/spec/README.md Co-authored-by: Dev Ojha <[email protected]> * Update x/claim/keeper/claim.go Co-authored-by: Dev Ojha <[email protected]> * Update x/claim/keeper/claim.go Co-authored-by: Dev Ojha <[email protected]> * Update x/claim/keeper/claim.go Co-authored-by: Dev Ojha <[email protected]> * add description about claimables * add prototype hooks * add hooks * modify numbers to enum * implement withdraw by activity * add spec for hooks, user actions, withdrawn hooks * add comment about user withdrawables * more description * add queries for activity based withdraw * add cli test for new query cmds * compile errors fix for tests * fix claim tests * withdraw inside hook * remove withdrawn actions flag and msgs * remove lockup hook, add test TestDelegationAutoWithdrawAndDelegateMore * Update cmd/osmosisd/cmd/genesis.go Co-authored-by: Dev Ojha <[email protected]> * Update x/claim/spec/README.md Co-authored-by: Dev Ojha <[email protected]> * fix comments * in progress * fix naming of file * works * export module account balance * Update x/gamm/keeper/multihop_test.go * address comments * create EndAirdrop function * fixed file name Co-authored-by: Dev Ojha <[email protected]> Co-authored-by: Sunny Aggarwal <[email protected]> Co-authored-by: Sunny Aggarwal <[email protected]>
- Loading branch information
1 parent
4b03170
commit 9e4f397
Showing
44 changed files
with
4,797 additions
and
37 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package params | ||
|
||
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
) | ||
|
||
// configurations | ||
var ( | ||
AccountAddressPrefix = "osm1" | ||
AccountPubKeyPrefix = "osm1pub" | ||
|
||
ValidatorAddressPrefix = "osm1valoper" | ||
ValidatorPubKeyPrefix = "osm1valoperpub" | ||
|
||
ConsNodeAddressPrefix = "osm1valcons" | ||
ConsNodePubKeyPrefix = "osm1valconspub" | ||
) | ||
|
||
// SetBech32Prefixes set bech32 prefixes | ||
func SetBech32Prefixes() { | ||
config := sdk.GetConfig() | ||
config.SetBech32PrefixForAccount(AccountAddressPrefix, AccountPubKeyPrefix) | ||
config.SetBech32PrefixForValidator(ValidatorAddressPrefix, ValidatorPubKeyPrefix) | ||
config.SetBech32PrefixForConsensusNode(ConsNodeAddressPrefix, ConsNodePubKeyPrefix) | ||
} |
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,151 @@ | ||
package cmd | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"io/ioutil" | ||
"os" | ||
|
||
appparams "github.com/c-osmosis/osmosis/app/params" | ||
claimtypes "github.com/c-osmosis/osmosis/x/claim/types" | ||
"github.com/cosmos/cosmos-sdk/client" | ||
"github.com/cosmos/cosmos-sdk/client/flags" | ||
"github.com/cosmos/cosmos-sdk/codec" | ||
"github.com/cosmos/cosmos-sdk/server" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" | ||
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" | ||
"github.com/cosmos/cosmos-sdk/x/genutil" | ||
genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func GenerateGenesisCmd() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "export-genesis [input-snapshot-file]", | ||
Short: "Export a genesis from fairdrop snapshot", | ||
Long: `Export a genesis from fairdrop snapshot | ||
Example: | ||
osmosisd export-genesis ../snapshot.json | ||
- Check input genesis: | ||
file is at ~/.gaiad/config/genesis.json | ||
`, | ||
Args: cobra.ExactArgs(1), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
clientCtx := client.GetClientContextFromCmd(cmd) | ||
depCdc := clientCtx.JSONMarshaler | ||
cdc := depCdc.(codec.Marshaler) | ||
aminoCodec := clientCtx.LegacyAmino.Amino | ||
|
||
serverCtx := server.GetServerContextFromCmd(cmd) | ||
config := serverCtx.Config | ||
|
||
config.SetRoot(clientCtx.HomeDir) | ||
|
||
snapshotInput := args[0] | ||
|
||
genFile := config.GenesisFile() | ||
appState, genDoc, err := genutiltypes.GenesisStateFromGenFile(genFile) | ||
if err != nil { | ||
return fmt.Errorf("failed to unmarshal genesis state: %w", err) | ||
} | ||
|
||
authGenState := authtypes.GetGenesisStateFromAppState(cdc, appState) | ||
|
||
accs, err := authtypes.UnpackAccounts(authGenState.Accounts) | ||
if err != nil { | ||
return fmt.Errorf("failed to get accounts from any: %w", err) | ||
} | ||
|
||
// Read snapshot file | ||
snapshotJson, err := os.Open(snapshotInput) | ||
if err != nil { | ||
return err | ||
} | ||
defer snapshotJson.Close() | ||
|
||
byteValue, _ := ioutil.ReadAll(snapshotJson) | ||
|
||
// Produce the map of address to total atom balance, both staked and unstaked | ||
snapshot := make(map[string]SnapshotFields) | ||
err = aminoCodec.UnmarshalJSON(byteValue, &snapshot) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
balances := []banktypes.Balance{} | ||
feeBalances := []banktypes.Balance{} | ||
|
||
totalNormalizedOsmoBalance := sdk.NewInt(0) | ||
for _, acc := range snapshot { | ||
// calculate total osmo balance | ||
totalNormalizedOsmoBalance = totalNormalizedOsmoBalance.Add(acc.OsmoNormalizedBalance) | ||
|
||
// set atom bech32 prefixes | ||
setCosmosBech32Prefixes() | ||
|
||
// read address from snapshot | ||
address, err := sdk.AccAddressFromBech32(acc.AtomAddress) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// set osmo bech32 prefixes | ||
appparams.SetBech32Prefixes() | ||
|
||
// airdrop balances | ||
coins := sdk.NewCoins(sdk.NewCoin(claimtypes.OsmoBondDenom, acc.OsmoNormalizedBalance)) | ||
balances = append(balances, banktypes.Balance{Address: address.String(), Coins: coins}) | ||
|
||
// transaction fee balances | ||
feeCoins := claimtypes.DefaultClaimModuleAcctBalance | ||
feeBalances = append(feeBalances, banktypes.Balance{Address: address.String(), Coins: feeCoins}) | ||
} | ||
|
||
// auth module genesis | ||
genAccs, err := authtypes.PackAccounts(accs) | ||
if err != nil { | ||
return fmt.Errorf("failed to convert accounts into any's: %w", err) | ||
} | ||
authGenState.Accounts = genAccs | ||
authGenStateBz, err := cdc.MarshalJSON(&authGenState) | ||
if err != nil { | ||
return fmt.Errorf("failed to marshal auth genesis state: %w", err) | ||
} | ||
appState[authtypes.ModuleName] = authGenStateBz | ||
|
||
// bank module genesis | ||
bankGenState := banktypes.GetGenesisStateFromAppState(depCdc, appState) | ||
bankGenState.Balances = banktypes.SanitizeGenesisBalances(feeBalances) | ||
bankGenStateBz, err := cdc.MarshalJSON(bankGenState) | ||
if err != nil { | ||
return fmt.Errorf("failed to marshal bank genesis state: %w", err) | ||
} | ||
appState[banktypes.ModuleName] = bankGenStateBz | ||
|
||
// claim module genesis | ||
claimGenState := claimtypes.DefaultGenesis() | ||
claimGenState.ModuleAccountBalance = sdk.NewCoin(sdk.DefaultBondDenom, totalNormalizedOsmoBalance) | ||
claimGenState.InitialClaimables = balances | ||
claimGenStateBz, err := cdc.MarshalJSON(claimGenState) | ||
if err != nil { | ||
return fmt.Errorf("failed to marshal claim genesis state: %w", err) | ||
} | ||
appState[claimtypes.ModuleName] = claimGenStateBz | ||
|
||
appStateJSON, err := json.Marshal(appState) | ||
if err != nil { | ||
return fmt.Errorf("failed to marshal application genesis state: %w", err) | ||
} | ||
genDoc.AppState = appStateJSON | ||
|
||
err = genutil.ExportGenesisFile(genDoc, genFile) | ||
return err | ||
}, | ||
} | ||
|
||
cmd.Flags().String(flagOsmoSupply, "", "OSMO total genesis supply") | ||
flags.AddQueryFlagsToCmd(cmd) | ||
|
||
return cmd | ||
} |
Oops, something went wrong.