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

send staketia redemption rate to oracle #1115

Merged
merged 4 commits into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 2 additions & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -633,8 +633,9 @@ func NewStrideApp(
keys[staketiatypes.StoreKey],
app.AccountKeeper,
app.BankKeeper,
app.TransferKeeper,
app.ICAOracleKeeper,
app.RatelimitKeeper,
app.TransferKeeper,
)
stakeTiaModule := staketia.NewAppModule(appCodec, app.StaketiaKeeper)

Expand Down
5 changes: 5 additions & 0 deletions x/staketia/keeper/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ func (k Keeper) BeforeEpochStart(ctx sdk.Context, epochInfo epochstypes.EpochInf
return
}

// Post the redemption rate to the oracle (if it doesn't exceed the bounds)
if err := k.PostRedemptionRateToOracles(ctx); err != nil {
k.Logger(ctx).Error(fmt.Sprintf("Unable to post redemption rate to oracle: %s", err.Error()))
}

// Prepare delegations by transferring the deposited tokens to the host zone
if err := k.SafelyPrepareDelegation(ctx, epochNumber, epochInfo.Duration); err != nil {
k.Logger(ctx).Error(fmt.Sprintf("Unable to prepare delegation for epoch %d: %s", epochNumber, err.Error()))
Expand Down
9 changes: 6 additions & 3 deletions x/staketia/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,28 @@ type Keeper struct {
storeKey storetypes.StoreKey
accountKeeper types.AccountKeeper
bankKeeper types.BankKeeper
transferKeeper types.TransferKeeper
icaOracleKeeper types.ICAOracleKeeper
ratelimitKeeper types.RatelimitKeeper
transferKeeper types.TransferKeeper
}

func NewKeeper(
cdc codec.BinaryCodec,
storeKey storetypes.StoreKey,
accountKeeper types.AccountKeeper,
bankKeeper types.BankKeeper,
transferKeeper types.TransferKeeper,
icaOracleKeeper types.ICAOracleKeeper,
ratelimitKeeper types.RatelimitKeeper,
transferKeeper types.TransferKeeper,
) *Keeper {
return &Keeper{
cdc: cdc,
storeKey: storeKey,
accountKeeper: accountKeeper,
bankKeeper: bankKeeper,
transferKeeper: transferKeeper,
icaOracleKeeper: icaOracleKeeper,
ratelimitKeeper: ratelimitKeeper,
transferKeeper: transferKeeper,
}
}

Expand Down
32 changes: 32 additions & 0 deletions x/staketia/keeper/redemption_rate.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package keeper

import (
"encoding/json"
"errors"
"fmt"

errorsmod "cosmossdk.io/errors"
sdkmath "cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/Stride-Labs/stride/v18/utils"
icaoracletypes "github.com/Stride-Labs/stride/v18/x/icaoracle/types"
"github.com/Stride-Labs/stride/v18/x/staketia/types"
)

Expand Down Expand Up @@ -105,3 +108,32 @@ func (k Keeper) CheckRedemptionRateExceedsBounds(ctx sdk.Context) error {

return nil
}

// Pushes a redemption rate update to the ICA oracle
func (k Keeper) PostRedemptionRateToOracles(ctx sdk.Context) error {
if err := k.CheckRedemptionRateExceedsBounds(ctx); err != nil {
return errorsmod.Wrapf(err, "preventing oracle update since redemption rate exceeded bounds")
}

hostZone, err := k.GetHostZone(ctx)
if err != nil {
return err
}
redemptionRate := hostZone.RedemptionRate

stDenom := utils.StAssetDenomFromHostZoneDenom(hostZone.NativeTokenDenom)
attributes, err := json.Marshal(icaoracletypes.RedemptionRateAttributes{
SttokenDenom: stDenom,
})
if err != nil {
return err
}

// Metric Key is of format: {stToken}_redemption_rate
metricKey := fmt.Sprintf("%s_%s", stDenom, icaoracletypes.MetricType_RedemptionRate)
metricValue := redemptionRate.String()
metricType := icaoracletypes.MetricType_RedemptionRate
k.icaOracleKeeper.QueueMetricUpdate(ctx, metricKey, metricValue, metricType, string(attributes))

return nil
}
5 changes: 5 additions & 0 deletions x/staketia/types/expected_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,8 @@ type RatelimitKeeper interface {
AddDenomToBlacklist(ctx sdk.Context, denom string)
RemoveDenomFromBlacklist(ctx sdk.Context, denom string)
}

// Required ICAOracleKeeper functions
type ICAOracleKeeper interface {
QueueMetricUpdate(ctx sdk.Context, key, value, metricType, attributes string)
}
Loading