Skip to content

Commit

Permalink
Merge branch 'main' into v25
Browse files Browse the repository at this point in the history
  • Loading branch information
sampocs committed Sep 5, 2024
2 parents 4b0ade8 + 4cfda61 commit e9031c3
Show file tree
Hide file tree
Showing 39 changed files with 761 additions and 1,915 deletions.
145 changes: 97 additions & 48 deletions CHANGELOG.md

Large diffs are not rendered by default.

38 changes: 37 additions & 1 deletion app/upgrades/v24/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,18 @@ import (
stakeibckeeper "github.com/Stride-Labs/stride/v24/x/stakeibc/keeper"
)

const UpgradeName = "v24"
var (
UpgradeName = "v24"

// Redemption rate bounds updated to give ~3 months of slack on outer bounds
RedemptionRateOuterMinAdjustment = sdk.MustNewDecFromStr("0.05")
RedemptionRateOuterMaxAdjustment = sdk.MustNewDecFromStr("0.10")

// Osmosis will have a slighly larger buffer with the redemption rate
// since their yield is less predictable
OsmosisChainId = "osmosis-1"
OsmosisRedemptionRateBuffer = sdk.MustNewDecFromStr("0.02")
)

// CreateUpgradeHandler creates an SDK upgrade handler for v24
func CreateUpgradeHandler(
Expand All @@ -29,6 +40,7 @@ func CreateUpgradeHandler(
MigrateHostZones(ctx, stakeibcKeeper)
MigrateDepositRecords(ctx, recordsKeeper)
MigrateEpochUnbondingRecords(ctx, recordsKeeper)
UpdateRedemptionRateBounds(ctx, stakeibcKeeper)

ctx.Logger().Info("Running module migrations...")
return mm.RunMigrations(ctx, configurator, vm)
Expand Down Expand Up @@ -115,3 +127,27 @@ func MigrateEpochUnbondingRecords(ctx sdk.Context, k recordskeeper.Keeper) {
k.SetEpochUnbondingRecord(ctx, epochUnbondingRecord)
}
}

// Updates the outer redemption rate bounds
func UpdateRedemptionRateBounds(ctx sdk.Context, k stakeibckeeper.Keeper) {
ctx.Logger().Info("Updating redemption rate bounds...")

for _, hostZone := range k.GetAllHostZone(ctx) {
// Give osmosis a bit more slack since OSMO stakers collect real yield
outerAdjustment := RedemptionRateOuterMaxAdjustment
if hostZone.ChainId == OsmosisChainId {
outerAdjustment = outerAdjustment.Add(OsmosisRedemptionRateBuffer)
}

outerMinDelta := hostZone.RedemptionRate.Mul(RedemptionRateOuterMinAdjustment)
outerMaxDelta := hostZone.RedemptionRate.Mul(outerAdjustment)

outerMin := hostZone.RedemptionRate.Sub(outerMinDelta)
outerMax := hostZone.RedemptionRate.Add(outerMaxDelta)

hostZone.MinRedemptionRate = outerMin
hostZone.MaxRedemptionRate = outerMax

k.SetHostZone(ctx, hostZone)
}
}
61 changes: 59 additions & 2 deletions app/upgrades/v24/upgrades_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,23 @@ package v24_test
import (
"testing"

"github.com/stretchr/testify/suite"

sdkmath "cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/stretchr/testify/suite"

"github.com/Stride-Labs/stride/v24/app/apptesting"
v24 "github.com/Stride-Labs/stride/v24/app/upgrades/v24"
recordstypes "github.com/Stride-Labs/stride/v24/x/records/types"
stakeibctypes "github.com/Stride-Labs/stride/v24/x/stakeibc/types"
)

type UpdateRedemptionRateBounds struct {
ChainId string
CurrentRedemptionRate sdk.Dec
ExpectedMinOuterRedemptionRate sdk.Dec
ExpectedMaxOuterRedemptionRate sdk.Dec
}

type UpgradeTestSuite struct {
apptesting.AppTestHelper
}
Expand Down Expand Up @@ -59,6 +66,8 @@ func (s *UpgradeTestSuite) TestUpgrade() {
},
})

checkRedemptionRatesAfterUpgrade := s.SetupTestUpdateRedemptionRateBounds()

// Run the upgrade
s.ConfirmUpgradeSucceededs(v24.UpgradeName, upgradeHeight)

Expand All @@ -79,6 +88,8 @@ func (s *UpgradeTestSuite) TestUpgrade() {
s.Require().Equal(stTokens.Int64(), hostZoneUnbonding.StTokensToBurn.Int64(), "sttokens to burn")
s.Require().Equal(nativeTokens.Int64(), hostZoneUnbonding.NativeTokensToUnbond.Int64(), "native to unbond")
s.Require().Zero(hostZoneUnbonding.ClaimableNativeTokens.Int64(), "claimable tokens")

checkRedemptionRatesAfterUpgrade()
}

func (s *UpgradeTestSuite) TestMigrateHostZones() {
Expand Down Expand Up @@ -256,3 +267,49 @@ func (s *UpgradeTestSuite) TestMigrateEpochUnbondingRecords() {
"%s undelegation txs in progress", tc.chainId)
}
}

func (s *UpgradeTestSuite) SetupTestUpdateRedemptionRateBounds() func() {
// Define test cases consisting of an initial redemption rate and expected bounds
testCases := []UpdateRedemptionRateBounds{
{
ChainId: "chain-0",
CurrentRedemptionRate: sdk.MustNewDecFromStr("1.0"),
ExpectedMinOuterRedemptionRate: sdk.MustNewDecFromStr("0.95"), // 1 - 5% = 0.95
ExpectedMaxOuterRedemptionRate: sdk.MustNewDecFromStr("1.10"), // 1 + 10% = 1.1
},
{
ChainId: "chain-1",
CurrentRedemptionRate: sdk.MustNewDecFromStr("1.1"),
ExpectedMinOuterRedemptionRate: sdk.MustNewDecFromStr("1.045"), // 1.1 - 5% = 1.045
ExpectedMaxOuterRedemptionRate: sdk.MustNewDecFromStr("1.210"), // 1.1 + 10% = 1.21
},
{
// Max outer for osmo uses 12% instead of 10%
ChainId: v24.OsmosisChainId,
CurrentRedemptionRate: sdk.MustNewDecFromStr("1.25"),
ExpectedMinOuterRedemptionRate: sdk.MustNewDecFromStr("1.1875"), // 1.25 - 5% = 1.1875
ExpectedMaxOuterRedemptionRate: sdk.MustNewDecFromStr("1.4000"), // 1.25 + 12% = 1.400
},
}

// Create a host zone for each test case
for _, tc := range testCases {
hostZone := stakeibctypes.HostZone{
ChainId: tc.ChainId,
RedemptionRate: tc.CurrentRedemptionRate,
}
s.App.StakeibcKeeper.SetHostZone(s.Ctx, hostZone)
}

// Return callback to check store after upgrade
return func() {
// Confirm they were all updated
for _, tc := range testCases {
hostZone, found := s.App.StakeibcKeeper.GetHostZone(s.Ctx, tc.ChainId)
s.Require().True(found)

s.Require().Equal(tc.ExpectedMinOuterRedemptionRate, hostZone.MinRedemptionRate, "%s - min outer", tc.ChainId)
s.Require().Equal(tc.ExpectedMaxOuterRedemptionRate, hostZone.MaxRedemptionRate, "%s - max outer", tc.ChainId)
}
}
}
5 changes: 4 additions & 1 deletion cmd/strided/config_defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (

tmcli "github.com/cometbft/cometbft/libs/cli"
"github.com/cosmos/cosmos-sdk/server"

"github.com/Stride-Labs/stride/v24/utils"
)

/*
Expand Down Expand Up @@ -216,7 +218,8 @@ func OverwriteWithCustomConfig(configFilePath string, sectionKeyValues []Section
currentSection = line[1 : len(line)-1]
} else if configMap[currentSection] != nil {
// If the line is in a section that needs to be overwritten, check each key
for key, value := range configMap[currentSection] {
for _, key := range utils.StringMapKeys(configMap[currentSection]) {
value := configMap[currentSection][key]
// Split the line into key and value parts
parts := strings.SplitN(line, "=", 2)
if len(parts) != 2 {
Expand Down
2 changes: 1 addition & 1 deletion deps/gaia
Submodule gaia updated 582 files
2 changes: 1 addition & 1 deletion dockernet/config/ica_host.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"/ibc.applications.transfer.v1.MsgTransfer",
"/cosmwasm.wasm.v1.MsgExecuteContract",
"/cosmwasm.wasm.v1.MsgInstantiateContract",
"/osmosis.gamm.v1beta1.MsgSwapExactAmountIn"
"/osmosis.poolmanager.v1beta1.MsgSwapExactAmountIn"
]
}
}
Expand Down
2 changes: 1 addition & 1 deletion dockernet/config/relayer_config_stride.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ chains:
account-prefix: cosmos
keyring-backend: test
gas-adjustment: 1.3
gas-prices: 0.02uatom
gas-prices: 1ufee
coin-type: 118
debug: false
timeout: 20s
Expand Down
19 changes: 13 additions & 6 deletions dockernet/dockerfiles/Dockerfile.gaia
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
FROM golang:1.20-alpine3.16 AS builder
FROM golang:1.22-alpine AS builder

WORKDIR /opt

RUN apk add --update curl make git libc-dev bash gcc linux-headers eudev-dev python3
RUN apk add --update curl make git libc-dev bash gcc linux-headers eudev-dev ca-certificates build-base git

ENV COMMIT_HASH=v12.0.0-rc0
ENV COMMIT_HASH=v18.1.0

RUN git clone https://github.com/cosmos/gaia \
&& cd gaia \
&& git checkout $COMMIT_HASH \
&& CGO_ENABLED=0 make install
&& git checkout $COMMIT_HASH

FROM alpine:3.16
WORKDIR /opt/gaia

RUN WASMVM_VERSION=$(cat go.mod | grep github.com/CosmWasm/wasmvm | awk '{print $2}') \
&& wget https://github.com/CosmWasm/wasmvm/releases/download/$WASMVM_VERSION/libwasmvm_muslc.$(uname -m).a \
-O /lib/libwasmvm_muslc.a

RUN CGO_ENABLED=1 BUILD_TAGS="muslc linkstatic" LINK_STATICALLY=true LEDGER_ENABLED=false make install

FROM alpine:3.17
COPY --from=builder /go/bin/gaiad /usr/local/bin/
RUN apk add bash vim \
&& addgroup -g 1000 gaia \
Expand Down
2 changes: 1 addition & 1 deletion dockernet/scripts/1.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
source ${SCRIPT_DIR}/../config.sh

## IBC ATOM from GAIA to STRIDE
$GAIA_MAIN_CMD tx ibc-transfer transfer transfer channel-0 $(STRIDE_ADDRESS) 1000000uatom --from ${GAIA_VAL_PREFIX}1 -y
$GAIA_MAIN_CMD tx ibc-transfer transfer transfer channel-0 $(STRIDE_ADDRESS) 1000000uatom --from ${GAIA_VAL_PREFIX}1 -y --fees 1000000ufee
sleep 10
$STRIDE_MAIN_CMD q bank balances $(STRIDE_ADDRESS)
23 changes: 14 additions & 9 deletions dockernet/src/init_chain.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ STAKE_TOKENS=${STAKE_TOKENS}${MICRO_DENOM_UNITS}
ADMIN_TOKENS=${ADMIN_TOKENS}${MICRO_DENOM_UNITS}
USER_TOKENS=${USER_TOKENS}${MICRO_DENOM_UNITS}

FEES=1000000000ufee
GENESIS_CMD=$($BINARY 2>&1 | grep -q "genesis-related subcommands" && echo "genesis" || echo "")

set_stride_epochs() {
genesis_config=$1

Expand Down Expand Up @@ -127,11 +130,13 @@ set_host_genesis() {
sed -i -E 's|"downtime_jail_duration": "600s"|"downtime_jail_duration": "10s"|g' $genesis_config
sed -i -E 's|"slash_fraction_downtime": "0.010000000000000000"|"slash_fraction_downtime": "0.050000000000000000"|g' $genesis_config

# LSM params
# LSM and feemarket params
if [[ "$CHAIN" == "GAIA" ]]; then
jq '.app_state.staking.params.validator_bond_factor = $newVal' --arg newVal "$LSM_VALIDATOR_BOND_FACTOR" $genesis_config > json.tmp && mv json.tmp $genesis_config
jq '.app_state.staking.params.validator_liquid_staking_cap = $newVal' --arg newVal "$LSM_VALIDATOR_LIQUID_STAKING_CAP" $genesis_config > json.tmp && mv json.tmp $genesis_config
jq '.app_state.staking.params.global_liquid_staking_cap = $newVal' --arg newVal "$LSM_GLOBAL_LIQUID_STAKING_CAP" $genesis_config > json.tmp && mv json.tmp $genesis_config

jq '.app_state.feemarket.params.fee_denom = $newVal' --arg newVal "ufee" $genesis_config > json.tmp && mv json.tmp $genesis_config
fi
}

Expand All @@ -141,7 +146,7 @@ set_consumer_genesis() {
# add consumer genesis
home_directories=""
for (( i=1; i <= $NUM_NODES; i++ )); do
home_directories+="${STATE}/stride${i},"
home_directories+="${STATE}/${NODE_PREFIX}${i},"
done

$MAIN_CMD add-consumer-section --validator-home-directories $home_directories
Expand All @@ -161,7 +166,7 @@ add_genesis_account() {

create_account "$account_name" "$mnemonic"
address=$($MAIN_CMD keys show $account_name --keyring-backend test -a | tr -cd '[:alnum:]._-')
$MAIN_CMD add-genesis-account ${address} ${amount}${DENOM}
$MAIN_CMD $GENESIS_CMD add-genesis-account ${address} ${amount}${DENOM},${FEES}
}

MAIN_ID=1 # Node responsible for genesis and persistent_peers
Expand Down Expand Up @@ -225,7 +230,7 @@ for (( i=1; i <= $NUM_NODES; i++ )); do
if [[ "$CHAIN" == "NOBLE" ]]; then
genesis_coins=${genesis_coins},${VAL_TOKENS}${USDC_DENOM}
fi
$cmd add-genesis-account ${val_addr} ${genesis_coins}
$cmd $GENESIS_CMD add-genesis-account ${val_addr} ${genesis_coins},${FEES}

# Copy over the provider stride validator keys to the provider (in the event
# that we are testing ICS)
Expand All @@ -238,7 +243,7 @@ for (( i=1; i <= $NUM_NODES; i++ )); do

# Only generate the validator txs for host chains
if [[ "$CHAIN" != "STRIDE" && "$CHAIN" != "HOST" ]]; then
$cmd gentx $val_acct ${STAKE_TOKENS}${DENOM} --chain-id $CHAIN_ID --keyring-backend test &> /dev/null
$cmd $GENESIS_CMD gentx $val_acct ${STAKE_TOKENS}${DENOM} --chain-id $CHAIN_ID --keyring-backend test &> /dev/null
fi

# Get the endpoint and node ID
Expand All @@ -257,7 +262,7 @@ for (( i=1; i <= $NUM_NODES; i++ )); do
MAIN_GENESIS=$genesis_json
else
# also add this account and it's genesis tx to the main node
$MAIN_CMD add-genesis-account ${val_addr} ${VAL_TOKENS}${DENOM}
$MAIN_CMD $GENESIS_CMD add-genesis-account ${val_addr} ${VAL_TOKENS}${DENOM},${FEES}
if [ -d "${STATE}/${node_name}/config/gentx" ]; then
cp ${STATE}/${node_name}/config/gentx/*.json ${STATE}/${MAIN_NODE_NAME}/config/gentx/
fi
Expand Down Expand Up @@ -319,7 +324,7 @@ else
if [ "$CHAIN" == "NOBLE" ]; then
echo "$NOBLE_AUTHORITHY_MNEMONIC" | $MAIN_CMD keys add authority --recover --keyring-backend test >> $KEYS_LOGS 2>&1
AUTHORITHY_ADDRESS=$($MAIN_CMD keys show authority --keyring-backend test -a | tr -cd '[:alnum:]._-')
$MAIN_CMD add-genesis-account ${AUTHORITHY_ADDRESS} ${VAL_TOKENS}${DENOM},${VAL_TOKENS}${USDC_DENOM}
$MAIN_CMD $GENESIS_CMD add-genesis-account ${AUTHORITHY_ADDRESS} ${VAL_TOKENS}${DENOM},${VAL_TOKENS}${USDC_DENOM}

sed -i -E 's|"authority": ""|"authority":"'${AUTHORITHY_ADDRESS}'"|g' $genesis_json
sed -i -E 's|"mintingDenom": null|"mintingDenom":{"denom":"'${DENOM}'"}|g' $genesis_json
Expand All @@ -335,12 +340,12 @@ fi
# the account should live on both stride and the host chain
echo "$USER_MNEMONIC" | $MAIN_CMD keys add $USER_ACCT --recover --keyring-backend=test >> $KEYS_LOGS 2>&1
USER_ADDRESS=$($MAIN_CMD keys show $USER_ACCT --keyring-backend test -a)
$MAIN_CMD add-genesis-account ${USER_ADDRESS} ${USER_TOKENS}${DENOM}
$MAIN_CMD $GENESIS_CMD add-genesis-account ${USER_ADDRESS} ${USER_TOKENS}${DENOM},${FEES}

# Only collect the validator genesis txs for host chains
if [[ "$CHAIN" != "STRIDE" && "$CHAIN" != "HOST" ]]; then
# now we process gentx txs on the main node
$MAIN_CMD collect-gentxs &> /dev/null
$MAIN_CMD $GENESIS_CMD collect-gentxs &> /dev/null
fi

# wipe out the persistent peers for the main node (these are incorrectly autogenerated for each validator during collect-gentxs)
Expand Down
2 changes: 1 addition & 1 deletion dockernet/src/register_host.sh
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ for (( i=1; i <= $NUM_VALS; i++ )); do
if [[ "$i" == "1" ]]; then
echo "$CHAIN - Submitting validator bonds..."
fi
$GAIA_MAIN_CMD tx staking validator-bond $delegate_val --from ${VAL_PREFIX}${i} -y | TRIM_TX
$GAIA_MAIN_CMD tx staking validator-bond $delegate_val --from ${VAL_PREFIX}${i} -y --fees 1000000ufee | TRIM_TX
fi
done

Expand Down
Loading

0 comments on commit e9031c3

Please sign in to comment.