Skip to content

Commit

Permalink
comment out unused function to placate golint-ci
Browse files Browse the repository at this point in the history
  • Loading branch information
Joe Bowman committed Jan 5, 2024
1 parent 0a2abde commit 6ddd3cd
Showing 1 changed file with 64 additions and 65 deletions.
129 changes: 64 additions & 65 deletions x/interchainstaking/keeper/redemptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,74 +14,73 @@ import (
"github.com/quicksilver-zone/quicksilver/utils"
epochstypes "github.com/quicksilver-zone/quicksilver/x/epochs/types"
"github.com/quicksilver-zone/quicksilver/x/interchainstaking/types"
lsmstakingtypes "github.com/quicksilver-zone/quicksilver/x/lsmtypes"
)

// processRedemptionForLsm will determine based on user intent, the tokens to return to the user, generate Redeem message and send them.
func (k *Keeper) processRedemptionForLsm(ctx sdk.Context, zone *types.Zone, sender sdk.AccAddress, destination string, nativeTokens math.Int, burnAmount sdk.Coin, hash string) error {
intent, found := k.GetDelegatorIntent(ctx, zone, sender.String(), false)
// msgs is slice of MsgTokenizeShares, so we can handle dust allocation later.
msgs := make([]*lsmstakingtypes.MsgTokenizeShares, 0)
var err error
intents := intent.Intents

if !found || len(intents) == 0 {
// if user has no intent set (this can happen if redeeming tokens that were obtained offchain), use global intent.
// Note: this can be improved; user will receive a bunch of tokens.
intents, err = k.GetAggregateIntentOrDefault(ctx, zone)
if err != nil {
return err
}
}
outstanding := nativeTokens
distribution := make(map[string]uint64, 0)

availablePerValidator, _, err := k.GetUnlockedTokensForZone(ctx, zone)
if err != nil {
return err
}
for _, intent := range intents.Sort() {
thisAmount := intent.Weight.MulInt(nativeTokens).TruncateInt()
if thisAmount.GT(availablePerValidator[intent.ValoperAddress]) {
return errors.New("unable to satisfy unbond request; delegations may be locked")
}
distribution[intent.ValoperAddress] = thisAmount.Uint64()
outstanding = outstanding.Sub(thisAmount)
}

distribution[intents[0].ValoperAddress] += outstanding.Uint64()

if distribution[intents[0].ValoperAddress] > availablePerValidator[intents[0].ValoperAddress].Uint64() {
return errors.New("unable to satisfy unbond request (2); delegations may be locked")
}

for _, valoper := range utils.Keys(distribution) {
msgs = append(msgs, &lsmstakingtypes.MsgTokenizeShares{
DelegatorAddress: zone.DelegationAddress.Address,
ValidatorAddress: valoper,
Amount: sdk.NewCoin(zone.BaseDenom, sdk.NewIntFromUint64(distribution[valoper])),
TokenizedShareOwner: destination,
})
}

sdkMsgs := make([]sdk.Msg, 0)
for _, msg := range msgs {
sdkMsgs = append(sdkMsgs, sdk.Msg(msg))
}
distributions := make([]*types.Distribution, 0)

for valoper, amount := range distribution {
newDistribution := types.Distribution{
Valoper: valoper,
Amount: amount,
}
distributions = append(distributions, &newDistribution)
}

k.AddWithdrawalRecord(ctx, zone.ChainId, sender.String(), distributions, destination, sdk.Coins{}, burnAmount, hash, types.WithdrawStatusTokenize, time.Unix(0, 0), k.EpochsKeeper.GetEpochInfo(ctx, epochstypes.EpochIdentifierEpoch).CurrentEpoch)

return k.SubmitTx(ctx, sdkMsgs, zone.DelegationAddress, hash, zone.MessagesPerTx)
}
// func (k *Keeper) processRedemptionForLsm(ctx sdk.Context, zone *types.Zone, sender sdk.AccAddress, destination string, nativeTokens math.Int, burnAmount sdk.Coin, hash string) error {
// intent, found := k.GetDelegatorIntent(ctx, zone, sender.String(), false)
// // msgs is slice of MsgTokenizeShares, so we can handle dust allocation later.
// msgs := make([]*lsmstakingtypes.MsgTokenizeShares, 0)
// var err error
// intents := intent.Intents

// if !found || len(intents) == 0 {
// // if user has no intent set (this can happen if redeeming tokens that were obtained offchain), use global intent.
// // Note: this can be improved; user will receive a bunch of tokens.
// intents, err = k.GetAggregateIntentOrDefault(ctx, zone)
// if err != nil {
// return err
// }
// }
// outstanding := nativeTokens
// distribution := make(map[string]uint64, 0)

// availablePerValidator, _, err := k.GetUnlockedTokensForZone(ctx, zone)
// if err != nil {
// return err
// }
// for _, intent := range intents.Sort() {
// thisAmount := intent.Weight.MulInt(nativeTokens).TruncateInt()
// if thisAmount.GT(availablePerValidator[intent.ValoperAddress]) {
// return errors.New("unable to satisfy unbond request; delegations may be locked")
// }
// distribution[intent.ValoperAddress] = thisAmount.Uint64()
// outstanding = outstanding.Sub(thisAmount)
// }

// distribution[intents[0].ValoperAddress] += outstanding.Uint64()

// if distribution[intents[0].ValoperAddress] > availablePerValidator[intents[0].ValoperAddress].Uint64() {
// return errors.New("unable to satisfy unbond request (2); delegations may be locked")
// }

// for _, valoper := range utils.Keys(distribution) {
// msgs = append(msgs, &lsmstakingtypes.MsgTokenizeShares{
// DelegatorAddress: zone.DelegationAddress.Address,
// ValidatorAddress: valoper,
// Amount: sdk.NewCoin(zone.BaseDenom, sdk.NewIntFromUint64(distribution[valoper])),
// TokenizedShareOwner: destination,
// })
// }

// sdkMsgs := make([]sdk.Msg, 0)
// for _, msg := range msgs {
// sdkMsgs = append(sdkMsgs, sdk.Msg(msg))
// }
// distributions := make([]*types.Distribution, 0)

// for valoper, amount := range distribution {
// newDistribution := types.Distribution{
// Valoper: valoper,
// Amount: amount,
// }
// distributions = append(distributions, &newDistribution)
// }

// k.AddWithdrawalRecord(ctx, zone.ChainId, sender.String(), distributions, destination, sdk.Coins{}, burnAmount, hash, types.WithdrawStatusTokenize, time.Unix(0, 0), k.EpochsKeeper.GetEpochInfo(ctx, epochstypes.EpochIdentifierEpoch).CurrentEpoch)

// return k.SubmitTx(ctx, sdkMsgs, zone.DelegationAddress, hash, zone.MessagesPerTx)
// }

// queueRedemption will determine based on zone intent, the tokens to unbond, and add a withdrawal record with status QUEUED.
func (k *Keeper) queueRedemption(
Expand Down

0 comments on commit 6ddd3cd

Please sign in to comment.