Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dogfood, oracle: remove default params #293

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 27 additions & 2 deletions local_node.sh
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ if [[ $overwrite == "y" || $overwrite == "Y" ]]; then
# x/dogfood
# for easy testing, use an epoch of 1 minute and 5 epochs until unbonded.
# i did not use 1 epoch to allow for testing that it does not happen at each epoch.
jq '.app_state["dogfood"]["params"]["asset_ids"][0]="0xdac17f958d2ee523a2206206994597c13d831ec7_0x65"' "$GENESIS" >"$TMP_GENESIS" && mv "$TMP_GENESIS" "$GENESIS"
jq '.app_state["dogfood"]["params"]["epoch_identifier"]="minute"' "$GENESIS" >"$TMP_GENESIS" && mv "$TMP_GENESIS" "$GENESIS"
jq '.app_state["dogfood"]["params"]["epochs_until_unbonded"]="5"' "$GENESIS" >"$TMP_GENESIS" && mv "$TMP_GENESIS" "$GENESIS"
jq '.app_state["dogfood"]["val_set"][0]["public_key"]="'"$CONSENSUS_KEY"'"' "$GENESIS" >"$TMP_GENESIS" && mv "$TMP_GENESIS" "$GENESIS"
Expand All @@ -178,9 +179,33 @@ if [[ $overwrite == "y" || $overwrite == "Y" ]]; then
jq '.app_state["exomint"]["params"]["epoch_identifier"]="minute"' "$GENESIS" >"$TMP_GENESIS" && mv "$TMP_GENESIS" "$GENESIS"

# x/oracle
# set the asset_id to default asset
jq '.app_state["oracle"]["params"]["tokens"][1]["asset_id"]="0xdac17f958d2ee523a2206206994597c13d831ec7_0x65"' "$GENESIS" >"$TMP_GENESIS" && mv "$TMP_GENESIS" "$GENESIS"
# chain
jq '.app_state["oracle"]["params"]["chains"][1]["name"]="Ethereum"' "$GENESIS" >"$TMP_GENESIS" && mv "$TMP_GENESIS" "$GENESIS"
jq '.app_state["oracle"]["params"]["chains"][1]["desc"]="-"' "$GENESIS" >"$TMP_GENESIS" && mv "$TMP_GENESIS" "$GENESIS"
# token
jq '.app_state["oracle"]["params"]["tokens"][1]["name"]="ETH"' "$GENESIS" >"$TMP_GENESIS" && mv "$TMP_GENESIS" "$GENESIS"
jq '.app_state["oracle"]["params"]["tokens"][1]["chain_id"]="1"' "$GENESIS" >"$TMP_GENESIS" && mv "$TMP_GENESIS" "$GENESIS"
jq '.app_state["oracle"]["params"]["tokens"][1]["contract_address"]="0x"' "$GENESIS" >"$TMP_GENESIS" && mv "$TMP_GENESIS" "$GENESIS"
jq '.app_state["oracle"]["params"]["tokens"][1]["decimal"]="8"' "$GENESIS" >"$TMP_GENESIS" && mv "$TMP_GENESIS" "$GENESIS"
jq '.app_state["oracle"]["params"]["tokens"][1]["active"]=true' "$GENESIS" >"$TMP_GENESIS" && mv "$TMP_GENESIS" "$GENESIS"
jq '.app_state["oracle"]["params"]["tokens"][1]["asset_id"]="0xdac17f958d2ee523a2206206994597c13d831ec7_0x65"' "$GENESIS" >"$TMP_GENESIS" && mv "$TMP_GENESIS" "$GENESIS"
# sources
jq '.app_state["oracle"]["params"]["sources"][1]["name"]="Chainlink"' "$GENESIS" >"$TMP_GENESIS" && mv "$TMP_GENESIS" "$GENESIS"
jq '.app_state["oracle"]["params"]["sources"][1]["entry"]["offchain"]["0"]=""' "$GENESIS" >"$TMP_GENESIS" && mv "$TMP_GENESIS" "$GENESIS"
jq '.app_state["oracle"]["params"]["sources"][1]["entry"]["onchain"]={}' "$GENESIS" >"$TMP_GENESIS" && mv "$TMP_GENESIS" "$GENESIS"
jq '.app_state["oracle"]["params"]["sources"][1]["valid"]=true' "$GENESIS" >"$TMP_GENESIS" && mv "$TMP_GENESIS" "$GENESIS"
jq '.app_state["oracle"]["params"]["sources"][1]["deterministic"]=true' "$GENESIS" >"$TMP_GENESIS" && mv "$TMP_GENESIS" "$GENESIS"
# rules
jq '.app_state["oracle"]["params"]["rules"][1]["source_ids"][0]="0"' "$GENESIS" >"$TMP_GENESIS" && mv "$TMP_GENESIS" "$GENESIS"
jq '.app_state["oracle"]["params"]["rules"][1]["nom"]=null' "$GENESIS" >"$TMP_GENESIS" && mv "$TMP_GENESIS" "$GENESIS"
# token feeder
jq '.app_state["oracle"]["params"]["token_feeders"][1]["token_id"]="1"' "$GENESIS" >"$TMP_GENESIS" && mv "$TMP_GENESIS" "$GENESIS"
jq '.app_state["oracle"]["params"]["token_feeders"][1]["rule_id"]="1"' "$GENESIS" >"$TMP_GENESIS" && mv "$TMP_GENESIS" "$GENESIS"
jq '.app_state["oracle"]["params"]["token_feeders"][1]["start_round_id"]="1"' "$GENESIS" >"$TMP_GENESIS" && mv "$TMP_GENESIS" "$GENESIS"
jq '.app_state["oracle"]["params"]["token_feeders"][1]["start_base_block"]="20"' "$GENESIS" >"$TMP_GENESIS" && mv "$TMP_GENESIS" "$GENESIS"
jq '.app_state["oracle"]["params"]["token_feeders"][1]["interval"]="10"' "$GENESIS" >"$TMP_GENESIS" && mv "$TMP_GENESIS" "$GENESIS"
jq '.app_state["oracle"]["params"]["token_feeders"][1]["end_block"]="0"' "$GENESIS" >"$TMP_GENESIS" && mv "$TMP_GENESIS" "$GENESIS"


# custom epoch definitions can be added here, if required.
# see https://github.com/ExocoreNetwork/exocore/blob/82b2509ad33ab7679592dcb1aa56a7a811128410/local_node.sh#L123 as an example
Expand Down
29 changes: 28 additions & 1 deletion testutil/keeper/oracle.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,34 @@ func OracleKeeper(t testing.TB) (*keeper.Keeper, sdk.Context) {

// Initialize params
p4Test := types.DefaultParams()
p4Test.TokenFeeders[1].StartBaseBlock = 1
p4Test.Chains = append(p4Test.Chains, &types.Chain{Name: "Ethereum", Desc: "-"})
p4Test.Tokens = append(p4Test.Tokens, &types.Token{
Name: "ETH",
ChainID: 1,
ContractAddress: "0x",
Decimal: 18,
Active: true,
AssetID: "0x0b34c4d876cd569129cf56bafabb3f9e97a4ff42_0x9ce1",
})
p4Test.Sources = append(p4Test.Sources, &types.Source{
Name: "Chainlink",
Entry: &types.Endpoint{
Offchain: map[uint64]string{0: ""},
},
Valid: true,
Deterministic: true,
})
p4Test.Rules = append(p4Test.Rules, &types.RuleSource{
// all sources math
SourceIDs: []uint64{0},
})
p4Test.TokenFeeders = append(p4Test.TokenFeeders, &types.TokenFeeder{
TokenID: 1,
RuleID: 1,
StartRoundID: 1,
StartBaseBlock: 1,
Interval: 10,
})
k.SetParams(ctx, p4Test)

return &k, ctx
Expand Down
34 changes: 30 additions & 4 deletions testutil/network/genesis_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,36 @@ var (
)

func init() {
// bond assetsIDs of ETH, NSTETH to ETH price
DefaultGenStateOracle.Params.Tokens[1].AssetID = fmt.Sprintf("%s,%s", ETHAssetID, NativeAssetID)
// set ETH tokenfeeder's 'StartBaseBlock' to 10
DefaultGenStateOracle.Params.TokenFeeders[1].StartBaseBlock = 10
DefaultGenStateOracle.Params.Chains = append(DefaultGenStateOracle.Params.Chains, &oracletypes.Chain{Name: "Ethereum", Desc: "-"})
DefaultGenStateOracle.Params.Tokens = append(DefaultGenStateOracle.Params.Tokens, &oracletypes.Token{
Name: "ETH",
ChainID: 1,
ContractAddress: "0x",
Decimal: 18,
Active: true,
// bond assetsIDs of ETH, NSTETH to ETH price
AssetID: fmt.Sprintf("%s,%s", ETHAssetID, NativeAssetID),
})
DefaultGenStateOracle.Params.Sources = append(DefaultGenStateOracle.Params.Sources, &oracletypes.Source{
Name: "Chainlink",
Entry: &oracletypes.Endpoint{
Offchain: map[uint64]string{0: ""},
},
Valid: true,
Deterministic: true,
})
DefaultGenStateOracle.Params.Rules = append(DefaultGenStateOracle.Params.Rules, &oracletypes.RuleSource{
// all sources math
SourceIDs: []uint64{0},
})
DefaultGenStateOracle.Params.TokenFeeders = append(DefaultGenStateOracle.Params.TokenFeeders, &oracletypes.TokenFeeder{
TokenID: 1,
RuleID: 1,
StartRoundID: 1,
// set ETH tokenfeeder's 'StartBaseBlock' to 10
StartBaseBlock: 10,
Interval: 10,
})
// set NSTETH token and tokenFeeder
DefaultGenStateOracle.Params.Tokens = append(DefaultGenStateOracle.Params.Tokens, &oracletypes.Token{
Name: "NSTETH",
Expand Down
31 changes: 29 additions & 2 deletions testutil/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,34 @@ func (suite *BaseTestSuite) SetupWithGenesisValSet(genAccs []authtypes.GenesisAc

// x/oracle initialization
oracleDefaultParams := oracletypes.DefaultParams()
oracleDefaultParams.Tokens[1].AssetID = "0xdac17f958d2ee523a2206206994597c13d831ec7_0x65"
oracleDefaultParams.TokenFeeders[1].StartBaseBlock = 1
oracleDefaultParams.Chains = append(oracleDefaultParams.Chains, &oracletypes.Chain{Name: "Ethereum", Desc: "-"})
oracleDefaultParams.Tokens = append(oracleDefaultParams.Tokens, &oracletypes.Token{
Name: "ETH",
ChainID: 1,
ContractAddress: "0x",
Decimal: 18,
Active: true,
AssetID: "0xdac17f958d2ee523a2206206994597c13d831ec7_0x65",
})
oracleDefaultParams.Sources = append(oracleDefaultParams.Sources, &oracletypes.Source{
Name: "Chainlink",
Entry: &oracletypes.Endpoint{
Offchain: map[uint64]string{0: ""},
},
Valid: true,
Deterministic: true,
})
oracleDefaultParams.Rules = append(oracleDefaultParams.Rules, &oracletypes.RuleSource{
// all sources math
SourceIDs: []uint64{0},
})
oracleDefaultParams.TokenFeeders = append(oracleDefaultParams.TokenFeeders, &oracletypes.TokenFeeder{
TokenID: 1,
RuleID: 1,
StartRoundID: 1,
StartBaseBlock: 1,
Interval: 10,
})
oracleDefaultParams.Tokens = append(oracleDefaultParams.Tokens, &oracletypes.Token{
Name: "USDT",
ChainID: 1,
Expand Down Expand Up @@ -380,6 +406,7 @@ func (suite *BaseTestSuite) SetupWithGenesisValSet(genAccs []authtypes.GenesisAc
[]dogfoodtypes.EpochToUndelegationRecordKeys{},
math.NewInt(power+power2), // must match total vote power
)
dogfoodGenesis.Params.AssetIDs = []string{assetID}
dogfoodGenesis.Params.MinSelfDelegation = math.NewInt(100)
genesisState[dogfoodtypes.ModuleName] = app.AppCodec().MustMarshalJSON(dogfoodGenesis)
distributionGenesis := distributiontypes.NewGenesisState(
Expand Down
1 change: 1 addition & 0 deletions x/dogfood/types/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ func (suite *GenesisTestSuite) TestValidateGenesis() {
),
)
params := types.DefaultParams()
params.AssetIDs = []string{"0x0b34c4d876cd569129cf56bafabb3f9e97a4ff42_0x9ce1"}
testCases := []struct {
name string
genState *types.GenesisState
Expand Down
16 changes: 8 additions & 8 deletions x/dogfood/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package types

import (
"fmt"
"strings"

sdkmath "cosmossdk.io/math"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
Expand All @@ -28,14 +27,15 @@ const (
// It is defined as a copy here so that we can use a value other than that in x/staking, if
// necessary.
DefaultHistoricalEntries = stakingtypes.DefaultHistoricalEntries
// DefaultAssetIDs is the default asset IDs accepted by the dogfood module. If multiple
// asset IDs are to be supported by default, separate them with a pipe character.
DefaultAssetIDs = "0xdac17f958d2ee523a2206206994597c13d831ec7_0x65"
)

// DefaultMinSelfDelegation is the default minimum self-delegation amount for a validator.
// It is denominated in USD. We do not support cents, since it is an integer.
var DefaultMinSelfDelegation = sdkmath.ZeroInt() // not a constant, hence var
var (
// DefaultAssetIDs is the default asset IDs accepted by the dogfood module.
DefaultAssetIDs = []string{}
// DefaultMinSelfDelegation is the default minimum self-delegation amount for a validator.
// It is denominated in USD. We do not support cents, since it is an integer.
DefaultMinSelfDelegation = sdkmath.ZeroInt()
)

// NewParams creates a new Params instance.
func NewParams(
Expand Down Expand Up @@ -63,7 +63,7 @@ func DefaultParams() Params {
DefaultEpochIdentifier,
DefaultMaxValidators,
DefaultHistoricalEntries,
strings.Split(DefaultAssetIDs, "|"),
DefaultAssetIDs,
DefaultMinSelfDelegation,
)
}
Expand Down
28 changes: 0 additions & 28 deletions x/oracle/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,52 +52,24 @@ func DefaultParams() Params {
return Params{
Chains: []*Chain{
{Name: "-", Desc: "-"},
{Name: "Ethereum", Desc: "-"},
},
Tokens: []*Token{
{},
{
Name: "ETH",
ChainID: 1,
ContractAddress: "0x",
Decimal: 18,
Active: true,
AssetID: "0x0b34c4d876cd569129cf56bafabb3f9e97a4ff42_0x9ce1",
},
},
// source defines where to fetch the prices
Sources: []*Source{
{
Name: "0 position is reserved",
},
{
Name: "Chainlink",
Entry: &Endpoint{
Offchain: map[uint64]string{0: ""},
},
Valid: true,
Deterministic: true,
},
},
// rules defines price from which sources are accepted, could be used to proof malicious
Rules: []*RuleSource{
// 0 is reserved
{},
{
// all sources math
SourceIDs: []uint64{0},
},
},
// TokenFeeder describes when a token start to be updated with its price, and the frequency, endTime.
TokenFeeders: []*TokenFeeder{
{},
{
TokenID: 1,
RuleID: 1,
StartRoundID: 1,
StartBaseBlock: 1000000,
Interval: 10,
},
},
MaxNonce: 3,
ThresholdA: 2,
Expand Down
Loading