Skip to content

Commit

Permalink
Merge branch 'main' into feature-1118-handle-non-staking-tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
Joe Bowman authored Feb 13, 2024
2 parents c94d2a7 + 9850a44 commit 9572b8f
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
go-version: '1.21.x'
cache: false
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
uses: golangci/golangci-lint-action@v4
with:
# Require: The version of golangci-lint to use.
# When `install-mode` is `binary` (default) the value can be v1.2 or v1.2.3 or `latest` to use the latest version.
Expand Down
9 changes: 6 additions & 3 deletions x/interchainstaking/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,15 +181,18 @@ func (k *Keeper) Delegations(c context.Context, req *types.QueryDelegationsReque
}

delegations := make([]types.Delegation, 0)
var sum int64
sum := sdk.ZeroInt()

k.IterateAllDelegations(ctx, zone.ChainId, func(delegation types.Delegation) (stop bool) {
delegations = append(delegations, delegation)
sum += delegation.Amount.Amount.Int64()
sum = sum.Add(delegation.Amount.Amount)
return false
})

return &types.QueryDelegationsResponse{Delegations: delegations, Tvl: sum}, nil
if sum.IsInt64() {
return &types.QueryDelegationsResponse{Delegations: delegations, Tvl: sum.Int64()}, nil
}
return &types.QueryDelegationsResponse{Delegations: delegations}, status.Error(codes.OutOfRange, "tvl out of bound Int64")
}

func (k *Keeper) Receipts(c context.Context, req *types.QueryReceiptsRequest) (*types.QueryReceiptsResponse, error) {
Expand Down
5 changes: 5 additions & 0 deletions x/interchainstaking/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,11 @@ func (k *Keeper) Rebalance(ctx sdk.Context, zone *types.Zone, epochNumber int64)
for _, rebalance := range rebalances {
if rebalance.Amount.GTE(sdk.NewInt(1_000_000)) {
// don't redelegate dust; TODO: config per zone
if !rebalance.Amount.IsInt64() {
k.Logger(ctx).Error("Rebalance amount out of bound Int64", "amount", rebalance.Amount.String())
// Ignore this
continue
}
msgs = append(msgs, &stakingtypes.MsgBeginRedelegate{DelegatorAddress: zone.DelegationAddress.Address, ValidatorSrcAddress: rebalance.Source, ValidatorDstAddress: rebalance.Target, Amount: sdk.NewCoin(zone.BaseDenom, rebalance.Amount)})
k.SetRedelegationRecord(ctx, types.RedelegationRecord{
ChainId: zone.ChainId,
Expand Down
2 changes: 1 addition & 1 deletion x/interchainstaking/keeper/redemptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ WITHDRAWAL:
}

if !sumIn.Equal(sumOut) {
return nil, nil, nil, fmt.Errorf("sumIn <-> sumOut mismatch; sumIn = %d, sumOut = %d", sumIn.Amount.Int64(), sumOut.Amount.Int64())
return nil, nil, nil, fmt.Errorf("sumIn <-> sumOut mismatch; sumIn = %s, sumOut = %s", sumIn.Amount.String(), sumOut.Amount.String())
}

return coinsOutPerValidator, txHashesPerValidator, distributionsPerWithdrawal, nil
Expand Down
2 changes: 1 addition & 1 deletion x/interchainstaking/keeper/withdrawal_record.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ func (k *Keeper) UpdateWithdrawalRecordsForSlash(ctx sdk.Context, zone *types.Zo
thisSubAmount := distAmount.TruncateInt().Sub(newAmount)
recordSubAmount = recordSubAmount.Add(thisSubAmount)
d.Amount = newAmount.Uint64()
k.Logger(ctx).Info("Updated withdrawal record due to slashing", "valoper", valoper, "old_amount", d.Amount, "new_amount", newAmount.Int64(), "sub_amount", thisSubAmount.Int64())
k.Logger(ctx).Info("Updated withdrawal record due to slashing", "valoper", valoper, "old_amount", d.Amount, "new_amount", newAmount.String(), "sub_amount", thisSubAmount.String())
}
record.Distribution = distr
subAmount := sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, recordSubAmount))
Expand Down
6 changes: 3 additions & 3 deletions x/interchainstaking/types/redemptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func DetermineAllocationsForUndelegation(currentAllocations map[string]math.Int,
}

if !amount[0].Amount.IsPositive() {
return outWeights, fmt.Errorf("amount was invalid, expected positive value, got %d", amount[0].Amount.Int64())
return outWeights, fmt.Errorf("amount was invalid, expected positive value, got %s", amount[0].Amount.String())
}
input := amount[0].Amount
underAllocated, overAllocated := CalculateAllocationDeltas(currentAllocations, lockedAllocations, currentSum /* .Sub(input) */, targetAllocations, make(map[string]math.Int))
Expand Down Expand Up @@ -159,7 +159,7 @@ func DetermineAllocationsForUndelegation(currentAllocations map[string]math.Int,
}

if !outSum.LTE(amount[0].Amount) {
return map[string]math.Int{}, fmt.Errorf("outSum (%d) is unexpectedly greater than the input amount (%d), aborting", outSum.Int64(), amount[0].Amount.Int64())
return map[string]math.Int{}, fmt.Errorf("outSum (%s) is unexpectedly greater than the input amount (%s), aborting", outSum.String(), amount[0].Amount.String())
}
if input.IsNegative() {
return map[string]math.Int{}, fmt.Errorf("input is unexpectedly negative (2), aborting")
Expand Down Expand Up @@ -317,7 +317,7 @@ func DetermineAllocationsForUndelegationPredef(currentAllocations map[string]mat
}

if !outSum.LTE(amount[0].Amount) {
return map[string]math.Int{}, fmt.Errorf("outSum (%d) is unexpectedly greater than the input amount (%d), aborting", outSum.Int64(), amount[0].Amount.Int64())
return map[string]math.Int{}, fmt.Errorf("outSum (%s) is unexpectedly greater than the input amount (%s), aborting", outSum.String(), amount[0].Amount.String())
}
if input.IsNegative() {
return map[string]math.Int{}, fmt.Errorf("input is unexpectedly negative (2), aborting")
Expand Down

0 comments on commit 9572b8f

Please sign in to comment.