Skip to content

Commit

Permalink
Merge branch 'dynamic-unbonding-rr-refactor' of github.com:Stride-Lab…
Browse files Browse the repository at this point in the history
…s/stride into dynamic-unbonding-rr-refactor
  • Loading branch information
sampocs committed Jan 11, 2024
2 parents b08635f + e23c4b3 commit fcd7e15
Show file tree
Hide file tree
Showing 25 changed files with 140 additions and 144 deletions.
5 changes: 3 additions & 2 deletions app/upgrades/v17/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func MigrateUnbondingRecords(ctx sdk.Context, k stakeibckeeper.Keeper) error {
}
// similarly, if there aren't any tokens to unbond, we don't want to modify the record
// as we won't be able to estimate a redemption rate
if hostZoneUnbonding.NativeTokenAmount == sdkmath.ZeroInt() {
if hostZoneUnbonding.NativeTokenAmount.IsZero() {
continue
}

Expand All @@ -173,6 +173,7 @@ func MigrateUnbondingRecords(ctx sdk.Context, k stakeibckeeper.Keeper) error {
stTokenAmountDec := sdk.NewDecFromInt(hostZoneUnbonding.StTokenAmount)
// this estimated rate is the amount of stTokens that would be received for 1 native token
// e.g. if the rate is 0.5, then 1 native token would be worth 0.5 stTokens
// e.g. if the rate is 0.5, then 1 native token would be worth 0.5 stTokens
estimatedStTokenConversionRate := stTokenAmountDec.Quo(nativeTokenAmountDec)

// Loop through User Redemption Records and insert an estimated stTokenAmount
Expand All @@ -184,7 +185,7 @@ func MigrateUnbondingRecords(ctx sdk.Context, k stakeibckeeper.Keeper) error {
continue
}

userRedemptionRecord.StTokenAmount = estimatedStTokenConversionRate.Mul(sdkmath.LegacyDec(userRedemptionRecord.Amount)).RoundInt()
userRedemptionRecord.StTokenAmount = estimatedStTokenConversionRate.Mul(sdk.NewDecFromInt(userRedemptionRecord.NativeTokenAmount)).RoundInt()
k.RecordsKeeper.SetUserRedemptionRecord(ctx, userRedemptionRecord)
}
}
Expand Down
4 changes: 0 additions & 4 deletions app/upgrades/v17/upgrades_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -572,11 +572,7 @@ func (s *UpgradeTestSuite) TestUpdateRateLimitThresholds() {
ChannelId: "channel-1",
HostDenom: "uosmo",
RateLimitDenom: "stuosmo",
<<<<<<< HEAD
Duration: 15,
=======
Duration: 20,
>>>>>>> v17-upgrade-handler
Threshold: sdkmath.NewInt(15),
},
"juno": {
Expand Down
2 changes: 1 addition & 1 deletion app/upgrades/v5/upgrades_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ func (s *UpgradeTestSuite) SetupOldRecordStore(codec codec.Codec) func() {
userRedemptionRecord, found := s.App.RecordsKeeper.GetUserRedemptionRecord(s.Ctx, userRedemptionRecordId)
s.Require().True(found, "redemption record found")
s.Require().Equal(userRedemptionRecord.Id, userRedemptionRecordId, "redemption record id")
s.Require().Equal(userRedemptionRecord.Amount, sdkmath.NewInt(1000000), "redemption record amount")
s.Require().Equal(userRedemptionRecord.NativeTokenAmount, sdkmath.NewInt(1000000), "redemption record amount")

epochUnbondingRecord, found := s.App.RecordsKeeper.GetEpochUnbondingRecord(s.Ctx, epochNumber)
s.Require().True(found, "epoch unbonding record found")
Expand Down
2 changes: 1 addition & 1 deletion proto/stride/records/records.proto
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ option go_package = "github.com/Stride-Labs/stride/v16/x/records/types";
message UserRedemptionRecord {
string id = 1; // {chain_id}.{epoch}.{receiver}
string receiver = 3;
string amount = 4 [
string native_token_amount = 4 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
];
Expand Down
2 changes: 1 addition & 1 deletion readme-docs/md/records_README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Epoch Unbonding Records
- `GetAllPreviousEpochUnbondingRecords()`
- `GetHostZoneUnbondingByChainId()`
- `AddHostZoneToEpochUnbondingRecord()`
- `SetHostZoneUnbondings()`
- `SetHostZoneUnbondingStatus()`

User Redemption Records
- `SetUserRedemptionRecord()`
Expand Down
2 changes: 1 addition & 1 deletion x/records/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Epoch Unbonding Records
- `GetAllPreviousEpochUnbondingRecords()`
- `GetHostZoneUnbondingByChainId()`
- `AddHostZoneToEpochUnbondingRecord()`
- `SetHostZoneUnbondings()`
- `SetHostZoneUnbondingStatus()`

User Redemption Records

Expand Down
6 changes: 3 additions & 3 deletions x/records/client/cli/query_user_redemption_record_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ func networkWithUserRedemptionRecordObjects(t *testing.T, n int) (*network.Netwo

for i := 0; i < n; i++ {
userRedemptionRecord := types.UserRedemptionRecord{
Id: strconv.Itoa(i),
Amount: sdkmath.NewInt(int64(i)),
StTokenAmount: sdkmath.NewInt(int64(i)),
Id: strconv.Itoa(i),
NativeTokenAmount: sdkmath.NewInt(int64(i)),
StTokenAmount: sdkmath.NewInt(int64(i)),
}
nullify.Fill(&userRedemptionRecord)
state.UserRedemptionRecordList = append(state.UserRedemptionRecordList, userRedemptionRecord)
Expand Down
3 changes: 1 addition & 2 deletions x/records/keeper/epoch_unbonding_record.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,7 @@ func (k Keeper) SetHostZoneUnbondingRecord(ctx sdk.Context, epochNumber uint64,
}

// Updates the status for a given host zone across relevant epoch unbonding record IDs
// TODO [cleanup]: Rename to SetHostZoneUnbondingStatus
func (k Keeper) SetHostZoneUnbondings(ctx sdk.Context, chainId string, epochUnbondingRecordIds []uint64, status types.HostZoneUnbonding_Status) error {
func (k Keeper) SetHostZoneUnbondingStatus(ctx sdk.Context, chainId string, epochUnbondingRecordIds []uint64, status types.HostZoneUnbonding_Status) error {
for _, epochUnbondingRecordId := range epochUnbondingRecordIds {
k.Logger(ctx).Info(fmt.Sprintf("Updating host zone unbondings on EpochUnbondingRecord %d to status %s", epochUnbondingRecordId, status.String()))
// fetch the host zone unbonding
Expand Down
2 changes: 1 addition & 1 deletion x/records/keeper/epoch_unbonding_record_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ func TestSetHostZoneUnbondings(t *testing.T) {
}
}

err := keeper.SetHostZoneUnbondings(ctx, hostIdToUpdate, epochsToUpdate, newStatus)
err := keeper.SetHostZoneUnbondingStatus(ctx, hostIdToUpdate, epochsToUpdate, newStatus)
require.Nil(t, err)

actualEpochUnbondingRecord := keeper.GetAllEpochUnbondingRecord(ctx)
Expand Down
2 changes: 1 addition & 1 deletion x/records/keeper/user_redemption_record_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func createNUserRedemptionRecord(keeper *keeper.Keeper, ctx sdk.Context, n int)
items := make([]types.UserRedemptionRecord, n)
for i := range items {
items[i].Id = strconv.Itoa(i)
items[i].Amount = sdkmath.NewInt(int64(i))
items[i].NativeTokenAmount = sdkmath.NewInt(int64(i))
items[i].StTokenAmount = sdkmath.NewInt(int64(i))
keeper.SetUserRedemptionRecord(ctx, items[i])
}
Expand Down
12 changes: 6 additions & 6 deletions x/records/migrations/v2/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ func convertToNewUserRedemptionRecord(oldRedemptionRecord oldrecordstypes.UserRe
return recordstypes.UserRedemptionRecord{
Id: oldRedemptionRecord.Id,
// Sender: oldRedemptionRecord.Sender,
Receiver: oldRedemptionRecord.Receiver,
Amount: sdkmath.NewIntFromUint64(oldRedemptionRecord.Amount),
Denom: oldRedemptionRecord.Denom,
HostZoneId: oldRedemptionRecord.HostZoneId,
EpochNumber: oldRedemptionRecord.EpochNumber,
ClaimIsPending: oldRedemptionRecord.ClaimIsPending,
Receiver: oldRedemptionRecord.Receiver,
NativeTokenAmount: sdkmath.NewIntFromUint64(oldRedemptionRecord.Amount),
Denom: oldRedemptionRecord.Denom,
HostZoneId: oldRedemptionRecord.HostZoneId,
EpochNumber: oldRedemptionRecord.EpochNumber,
ClaimIsPending: oldRedemptionRecord.ClaimIsPending,
}
}
10 changes: 5 additions & 5 deletions x/records/migrations/v2/convert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,11 @@ func TestConvertUserRedemptionRecord(t *testing.T) {
Id: id,
Receiver: receiver,
// Sender: sender,
Amount: sdkmath.NewInt(1),
Denom: denom,
HostZoneId: hostZoneId,
EpochNumber: epochNumber,
ClaimIsPending: claimIsPending,
NativeTokenAmount: sdkmath.NewInt(1),
Denom: denom,
HostZoneId: hostZoneId,
EpochNumber: epochNumber,
ClaimIsPending: claimIsPending,
}

actualNewUserRedemptionRecord := convertToNewUserRedemptionRecord(oldUserRedemptionRecord)
Expand Down
Loading

0 comments on commit fcd7e15

Please sign in to comment.