Skip to content

Commit

Permalink
Feature (#1087)
Browse files Browse the repository at this point in the history
Co-authored-by: sampocs <sam.pochyly@gmail.com>
Co-authored-by: ethan <ethan@stridelabs.co>
Co-authored-by: ethan-stride <126913021+ethan-stride@users.noreply.github.com>
Co-authored-by: riley-stride <104941670+riley-stride@users.noreply.github.com>
Co-authored-by: shellvish <104537253+shellvish@users.noreply.github.com>
Co-authored-by: Riley Edmunds <riley@stridelabs.co>
Co-authored-by: vish-stride <vishal@stridelabs.co>
  • Loading branch information
8 people authored Jan 26, 2024
1 parent 8d00ae6 commit a2289f8
Show file tree
Hide file tree
Showing 80 changed files with 24,018 additions and 86 deletions.
30 changes: 29 additions & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,9 @@ import (
stakeibcclient "github.com/Stride-Labs/stride/v17/x/stakeibc/client"
stakeibcmodulekeeper "github.com/Stride-Labs/stride/v17/x/stakeibc/keeper"
stakeibcmoduletypes "github.com/Stride-Labs/stride/v17/x/stakeibc/types"
staketia "github.com/Stride-Labs/stride/v17/x/staketia"
staketiakeeper "github.com/Stride-Labs/stride/v17/x/staketia/keeper"
staketiatypes "github.com/Stride-Labs/stride/v17/x/staketia/types"

ccvconsumer "github.com/cosmos/interchain-security/v3/x/ccv/consumer"
ccvconsumerkeeper "github.com/cosmos/interchain-security/v3/x/ccv/consumer/keeper"
Expand Down Expand Up @@ -230,6 +233,7 @@ var (
tendermint.AppModuleBasic{},
packetforward.AppModuleBasic{},
evmosvesting.AppModuleBasic{},
staketia.AppModuleBasic{},
)

// module account permissions
Expand All @@ -249,6 +253,7 @@ var (
interchainquerytypes.ModuleName: nil,
icatypes.ModuleName: nil,
stakeibcmoduletypes.RewardCollectorName: nil,
staketiatypes.ModuleName: {authtypes.Minter, authtypes.Burner},
}
)

Expand Down Expand Up @@ -327,6 +332,7 @@ type StrideApp struct {
RatelimitKeeper ratelimitmodulekeeper.Keeper
ClaimKeeper claimkeeper.Keeper
ICAOracleKeeper icaoraclekeeper.Keeper
StaketiaKeeper staketiakeeper.Keeper

mm *module.Manager
sm *module.SimulationManager
Expand Down Expand Up @@ -376,6 +382,7 @@ func NewStrideApp(
consensusparamtypes.StoreKey,
packetforwardtypes.StoreKey,
evmosvestingtypes.StoreKey,
staketiatypes.StoreKey,
)
tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey)
memKeys := sdk.NewMemoryStoreKeys(capabilitytypes.MemStoreKey)
Expand Down Expand Up @@ -642,6 +649,17 @@ func NewStrideApp(
)
autopilotModule := autopilot.NewAppModule(appCodec, app.AutopilotKeeper)

// Staketia Keeper must be initialized after TransferKeeper
app.StaketiaKeeper = *staketiakeeper.NewKeeper(
appCodec,
keys[staketiatypes.StoreKey],
app.AccountKeeper,
app.BankKeeper,
app.TransferKeeper,
app.RatelimitKeeper,
)
stakeTiaModule := staketia.NewAppModule(appCodec, app.StaketiaKeeper)

app.VestingKeeper = evmosvestingkeeper.NewKeeper(
keys[evmosvestingtypes.StoreKey], authtypes.NewModuleAddress(govtypes.ModuleName), appCodec,
app.AccountKeeper, app.BankKeeper, app.DistrKeeper, app.StakingKeeper,
Expand Down Expand Up @@ -676,6 +694,7 @@ func NewStrideApp(
app.MintKeeper.Hooks(),
app.ClaimKeeper.Hooks(),
app.RatelimitKeeper.Hooks(),
app.StaketiaKeeper.Hooks(),
),
)
epochsModule := epochsmodule.NewAppModule(appCodec, app.EpochsKeeper)
Expand Down Expand Up @@ -732,6 +751,7 @@ func NewStrideApp(
// - core ibc
// - autopilot
// - records
// - staketia
// - ratelimit
// - pfm
// - transfer
Expand All @@ -747,6 +767,7 @@ func NewStrideApp(
packetforwardkeeper.DefaultRefundTransferPacketTimeoutTimestamp, // refund timeout
)
transferStack = ratelimitmodule.NewIBCMiddleware(app.RatelimitKeeper, transferStack)
transferStack = staketia.NewIBCMiddleware(app.StaketiaKeeper, transferStack)
transferStack = recordsmodule.NewIBCModule(app.RecordsKeeper, transferStack)
transferStack = autopilot.NewIBCModule(app.AutopilotKeeper, transferStack)

Expand Down Expand Up @@ -811,6 +832,7 @@ func NewStrideApp(
consumerModule,
autopilotModule,
icaoracleModule,
stakeTiaModule,
)

// During begin block slashing happens after distr.BeginBlocker so that
Expand Down Expand Up @@ -851,6 +873,7 @@ func NewStrideApp(
icaoracletypes.ModuleName,
consensusparamtypes.ModuleName,
packetforwardtypes.ModuleName,
staketiatypes.ModuleName,
)

app.mm.SetOrderEndBlockers(
Expand Down Expand Up @@ -887,6 +910,7 @@ func NewStrideApp(
icaoracletypes.ModuleName,
consensusparamtypes.ModuleName,
packetforwardtypes.ModuleName,
staketiatypes.ModuleName,
)

// NOTE: The genutils module must occur after staking so that pools are
Expand Down Expand Up @@ -928,6 +952,7 @@ func NewStrideApp(
icaoracletypes.ModuleName,
consensusparamtypes.ModuleName,
packetforwardtypes.ModuleName,
staketiatypes.ModuleName,
)

app.mm.RegisterInvariants(app.CrisisKeeper)
Expand Down Expand Up @@ -1078,7 +1103,10 @@ func (app *StrideApp) BlacklistedModuleAccountAddrs() map[string]bool {
// DO NOT REMOVE: StringMapKeys fixes non-deterministic map iteration
for _, acc := range utils.StringMapKeys(maccPerms) {
// don't blacklist stakeibc module account, so that it can ibc transfer tokens
if acc == stakeibcmoduletypes.ModuleName || acc == stakeibcmoduletypes.RewardCollectorName || acc == ccvconsumertypes.ConsumerToSendToProviderName {
if acc == stakeibcmoduletypes.ModuleName ||
acc == stakeibcmoduletypes.RewardCollectorName ||
acc == ccvconsumertypes.ConsumerToSendToProviderName ||
acc == staketiatypes.ModuleName {
continue
}
modAccAddrs[authtypes.NewModuleAddress(acc).String()] = true
Expand Down
7 changes: 7 additions & 0 deletions app/apptesting/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,13 @@ func (s *AppTestHelper) Setup() {
s.TestAccs = CreateRandomAccounts(3)
s.IbcEnabled = false
s.IcaAddresses = make(map[string]string)

// Remove host zone and accumulating record for staketia, by default,
// since the tests will override it directly if needed
s.App.StaketiaKeeper.RemoveHostZone(s.Ctx)
for _, unbondingRecord := range s.App.StaketiaKeeper.GetAllActiveUnbondingRecords(s.Ctx) {
s.App.StaketiaKeeper.RemoveUnbondingRecord(s.Ctx, unbondingRecord.Id)
}
}

// Instantiates an TestHelper without the test suite
Expand Down
14 changes: 14 additions & 0 deletions dockernet/config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,20 @@ REV_MNEMONIC="tonight bonus finish chaos orchard plastic view nurse salad regret
USER_MNEMONIC="brief play describe burden half aim soccer carbon hope wait output play vacuum joke energy crucial output mimic cruise brother document rail anger leaf"
USER_ACCT=user

# stTIA MNEMONICS
## On Stride
DEPOSIT_MNEMONIC="alpha annual multiply search scene gospel wood empower video estate erosion sister legend title man bicycle find adjust conduct exercise jewel great state park"
REDEMPTION_MNEMONIC="frame noodle guilt clinic laugh pink own reflect clog lady slice execute renew excess ranch face praise knife spare accident catch figure pony feel"
CLAIM_MNEMONIC="boat caution burst hybrid melody input kitten account pull explain couch pact educate omit inmate area drastic town sugar rail spare nothing matrix gate"
SAFE_MNEMONIC="chat mechanic patient palm screen response beef cactus report rebuild equal cargo essay craft rigid injury rocket below monster boost clay charge toss debate"
OPERATOR_MNEMONIC="equal fetch soccer crouch dash similar dinosaur divide video polar fork banana engine tomorrow thought web ramp slight stumble throw kid ridge today afford"

## On Host Chain
DELEGATION_ADDRESS="cosmos1n4reqytr7arvpk5z2ute274h2yukcss8dtxjyd"
REWARD_ADDRESS="cosmos1atchlrd8m4868t5ep2fywxhl2u9c3qg0grnt0e"
DELEGATION_MNEMONIC="arrange indicate grass click bulk wage vivid strong evil uncover raven solar stone hole strategy about rate negative word inch enforce alley never wealth"
REWARD_MNEMONIC="drive someone knee omit disease clerk stand rebel asthma lift valid era armed ticket any undo increase magnet rabbit improve rude fortune afraid soon"

# STRIDE
STRIDE_CHAIN_ID=STRIDE
STRIDE_NODE_PREFIX=stride
Expand Down
38 changes: 38 additions & 0 deletions dockernet/scripts/staketia/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
## Staketia Integration Tests
* Use the default host chain settings, but shorten the day and stride epochs in `config.sh`
```
STRIDE_DAY_EPOCH_DURATION="40s"
STRIDE_EPOCH_EPOCH_DURATION="10s"
```
* Start dockernet
```bash
make start-docker
```
* As you go through the below flow, watch the `balances.log` and `state.log` files
* Run the setup script to transfer native tokens to Stride and set the withdrawal address
```bash
bash dockernet/scripts/staketia/setup.sh
```
* Run the liquid stake script. Watch the stToken appear in the validator account and a delegation record be created during the next epoch.
```bash
bash dockernet/scripts/staketia/liquid_stake.sh
```
* Delegate on the host zone and confirm on stride. Watch the delegated balance increase and the delegation record be removed.
```bash
bash dockernet/scripts/staketia/delegate.sh
```
* Redeem the stTokens. Watch the stTokens move into the redemption account and the accumulation unbonding record be incremented. A redemption record should also be created.
```bash
bash dockernet/scripts/staketia/redeem_stake.sh
```
* Wait for the next 4 day epoch and see the unbonding record change to status `UNBONDING_QUEUE`. This may take a few minutes.
* Unbond from the host zone and submit the confirm tx back to stride
```bash
bash dockernet/scripts/staketia/undelegate.sh
```
* Wait for the unbonding record's status to change to `UNBONDED`, after the tokens have finished unbonding. This will take a couple minutes.
* Sweep the tokens back to stride and confirm the tx. During the next epoch, the native tokens should be returned the redeemer and the redemption record should be removed.
```bash
bash dockernet/scripts/staketia/sweep.sh
```

25 changes: 25 additions & 0 deletions dockernet/scripts/staketia/delegate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash
set -eu
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
source ${SCRIPT_DIR}/../../config.sh

HOST_CHAIN="${HOST_CHAINS[0]}"
HOST_MAIN_CMD=$(GET_VAR_VALUE ${HOST_CHAIN}_MAIN_CMD)
HOST_DENOM=$(GET_VAR_VALUE ${HOST_CHAIN}_DENOM)

echo ">>> Querying action from records..."
$STRIDE_MAIN_CMD q staketia delegation-records
delegation_amount=$($STRIDE_MAIN_CMD q staketia delegation-records | grep -B 2 "DELEGATION_QUEUE" | grep "native_amount" | NUMBERS_ONLY)
record_id=$($STRIDE_MAIN_CMD q staketia delegation-records | grep -B 3 "DELEGATION_QUEUE" | grep "id" | NUMBERS_ONLY)
sleep 1

echo -e "\n>>> Delegating ${delegation_amount}${HOST_DENOM} for record $record_id..."
validator_address=$(GET_VAL_ADDR $HOST_CHAIN 1)
output=$($HOST_MAIN_CMD tx staking delegate $validator_address ${delegation_amount}${HOST_DENOM} \
--from delegation -y | TRIM_TX)
echo $output
sleep 1

echo -e "\n>>> Submitting confirm-delegation tx for record $record_id on Stride..."
tx_hash=$(echo $output | awk '{print $4}')
$STRIDE_MAIN_CMD tx staketia confirm-delegation $record_id $tx_hash --from operator -y | TRIM_TX
8 changes: 8 additions & 0 deletions dockernet/scripts/staketia/liquid_stake.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#/bin/bash
set -eu
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
source ${SCRIPT_DIR}/../../config.sh

echo ">>> Liquid staking..."
$STRIDE_MAIN_CMD tx staketia liquid-stake 1000000 --from ${STRIDE_VAL_PREFIX}1 -y | TRIM_TX
sleep 1
8 changes: 8 additions & 0 deletions dockernet/scripts/staketia/redeem_stake.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#/bin/bash
set -eu
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
source ${SCRIPT_DIR}/../../config.sh

echo ">>> Redeeming stake..."
$STRIDE_MAIN_CMD tx staketia redeem-stake 1000000 --from ${STRIDE_VAL_PREFIX}1 -y | TRIM_TX
sleep 1
37 changes: 37 additions & 0 deletions dockernet/scripts/staketia/reinvest.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/bash
set -eu
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
source ${SCRIPT_DIR}/../../config.sh

HOST_CHAIN="${HOST_CHAINS[0]}"
HOST_MAIN_CMD=$(GET_VAR_VALUE ${HOST_CHAIN}_MAIN_CMD)
HOST_DENOM=$(GET_VAR_VALUE ${HOST_CHAIN}_DENOM)

reward_address=$($HOST_MAIN_CMD keys show -a reward)
deposit_address=$($STRIDE_MAIN_CMD keys show -a deposit)
fee_address=$($STRIDE_MAIN_CMD q staketia host-zone | grep fee_address | awk '{print $2}')

echo ">>> Claiming outstanding rewards records..."
$HOST_MAIN_CMD tx distribution withdraw-all-rewards --from delegation -y | TRIM_TX
sleep 5

echo -e "\n>>> Querying rewards balance..."
output=$($HOST_MAIN_CMD q bank balances $reward_address --denom $HOST_DENOM)
echo $output
reward_amount=$(echo $output | NUMBERS_ONLY)
sleep 1

reinvest_amount=$(echo "scale=0; $reward_amount * 90 / 100" | bc -l)
fee_amount=$(echo "scale=0; $reward_amount * 10 / 100" | bc -l)

echo -e "\n>>> Sweeping ${reinvest_amount}${HOST_DENOM} for reinvestment..."
output=$($HOST_MAIN_CMD tx ibc-transfer transfer transfer channel-0 $deposit_address ${reinvest_amount}${HOST_DENOM} \
--from delegation -y | TRIM_TX)
echo $output
sleep 10

echo -e "\n>>> Sweeping ${fee_amount}${HOST_DENOM} for fee collection..."
output=$($HOST_MAIN_CMD tx ibc-transfer transfer transfer channel-0 $fee_address ${fee_amount}${HOST_DENOM} \
--from delegation -y | TRIM_TX)
echo $output
sleep 10
19 changes: 19 additions & 0 deletions dockernet/scripts/staketia/setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash
set -eu
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
source ${SCRIPT_DIR}/../../config.sh

HOST_CHAIN="${HOST_CHAINS[0]}"
HOST_MAIN_CMD=$(GET_VAR_VALUE ${HOST_CHAIN}_MAIN_CMD)
HOST_VAL_PREFIX=$(GET_VAR_VALUE ${HOST_CHAIN}_VAL_PREFIX)
HOST_DENOM=$(GET_VAR_VALUE ${HOST_CHAIN}_DENOM)

echo ">>> Transfering native tokens to stride..."
$HOST_MAIN_CMD tx ibc-transfer transfer transfer channel-0 $(STRIDE_ADDRESS) 10000000${HOST_DENOM} \
--from ${HOST_VAL_PREFIX}1 -y | TRIM_TX
sleep 10

echo ">>> Setting withdrawal address..."
reward_address=$($HOST_MAIN_CMD keys show -a reward)
$HOST_MAIN_CMD tx distribution set-withdraw-addr $reward_address --from delegation -y | TRIM_TX
sleep 10
25 changes: 25 additions & 0 deletions dockernet/scripts/staketia/sweep.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash
set -eu
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
source ${SCRIPT_DIR}/../../config.sh

HOST_CHAIN="${HOST_CHAINS[0]}"
HOST_MAIN_CMD=$(GET_VAR_VALUE ${HOST_CHAIN}_MAIN_CMD)
HOST_DENOM=$(GET_VAR_VALUE ${HOST_CHAIN}_DENOM)

echo ">>> Querying action from records..."
$STRIDE_MAIN_CMD q staketia unbonding-records
unbond_amount=$($STRIDE_MAIN_CMD q staketia unbonding-records | grep -B 2 "UNBONDED" | grep "native_amount" | NUMBERS_ONLY)
record_id=$($STRIDE_MAIN_CMD q staketia unbonding-records | grep -B 4 "UNBONDED" | grep "id" | NUMBERS_ONLY)
sleep 1

echo -e "\n>>> Sweeping ${unbond_amount}${HOST_DENOM} for record $record_id..."
claim_address=$($STRIDE_MAIN_CMD keys show -a claim)
output=$($HOST_MAIN_CMD tx ibc-transfer transfer transfer channel-0 $claim_address ${unbond_amount}${HOST_DENOM} \
--from delegation -y | TRIM_TX)
echo $output
sleep 10

echo -e "\n>>> Submitting confirm-sweep tx for record $record_id on Stride..."
tx_hash=$(echo $output | awk '{print $4}')
$STRIDE_MAIN_CMD tx staketia confirm-sweep $record_id $tx_hash --from operator -y | TRIM_TX
25 changes: 25 additions & 0 deletions dockernet/scripts/staketia/undelegate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash
set -eu
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
source ${SCRIPT_DIR}/../../config.sh

HOST_CHAIN="${HOST_CHAINS[0]}"
HOST_MAIN_CMD=$(GET_VAR_VALUE ${HOST_CHAIN}_MAIN_CMD)
HOST_DENOM=$(GET_VAR_VALUE ${HOST_CHAIN}_DENOM)

echo ">>> Querying action from records..."
$STRIDE_MAIN_CMD q staketia unbonding-records
unbond_amount=$($STRIDE_MAIN_CMD q staketia unbonding-records | grep -B 2 "UNBONDING_QUEUE" | grep "native_amount" | NUMBERS_ONLY)
record_id=$($STRIDE_MAIN_CMD q staketia unbonding-records | grep -B 4 "UNBONDING_QUEUE" | grep "id" | NUMBERS_ONLY)
sleep 1

echo -e "\n>>> Unbonding ${unbond_amount}${HOST_DENOM} for record $record_id..."
validator_address=$(GET_VAL_ADDR $HOST_CHAIN 1)
output=$($HOST_MAIN_CMD tx staking unbond $validator_address ${unbond_amount}${HOST_DENOM} \
--from delegation -y | TRIM_TX)
echo $output
sleep 1

echo -e "\n>>> Submitting confirm-undelegation tx for record $record_id on Stride..."
tx_hash=$(echo $output | awk '{print $4}')
$STRIDE_MAIN_CMD tx staketia confirm-undelegation $record_id $tx_hash --from operator -y | TRIM_TX
Loading

0 comments on commit a2289f8

Please sign in to comment.