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

support mapped accounts in claims #1642

Merged
merged 1 commit into from
Jun 3, 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
12 changes: 11 additions & 1 deletion x/participationrewards/keeper/submodule_liquid.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

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

"cosmossdk.io/math"
Expand Down Expand Up @@ -46,7 +47,16 @@
// or if the denom found is not valid.
denom, err := utils.DenomFromRequestKey(proof.Key, addr)
if err != nil {
return sdk.ZeroInt(), err
// check for mapped address for this user from SrcZone.
mappedAddr, found := k.icsKeeper.GetLocalAddressMap(ctx, addr, msg.SrcZone)
if found {
denom, err = utils.DenomFromRequestKey(proof.Key, mappedAddr)
if err != nil {
return sdk.ZeroInt(), errors.New("not a valid proof for submitting user or mapped account")

Check warning on line 55 in x/participationrewards/keeper/submodule_liquid.go

View check run for this annotation

Codecov / codecov/patch

x/participationrewards/keeper/submodule_liquid.go#L51-L55

Added lines #L51 - L55 were not covered by tests
}
} else {
return sdk.ZeroInt(), errors.New("not a valid proof for submitting user")

Check warning on line 58 in x/participationrewards/keeper/submodule_liquid.go

View check run for this annotation

Codecov / codecov/patch

x/participationrewards/keeper/submodule_liquid.go#L57-L58

Added lines #L57 - L58 were not covered by tests
}
}

data, found := k.GetProtocolData(ctx, types.ProtocolDataTypeLiquidToken, fmt.Sprintf("%s_%s", msg.SrcZone, denom))
Expand Down
31 changes: 26 additions & 5 deletions x/participationrewards/keeper/submodule_osmosis.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package keeper

import (
"bytes"
"encoding/json"
"errors"
"fmt"
Expand All @@ -13,10 +14,11 @@
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/bech32"
"github.com/cosmos/cosmos-sdk/x/bank/keeper"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"

osmosistypes "github.com/quicksilver-zone/quicksilver/third-party-chains/osmosis-types"
osmolockup "github.com/quicksilver-zone/quicksilver/third-party-chains/osmosis-types/lockup"
"github.com/quicksilver-zone/quicksilver/utils"
"github.com/quicksilver-zone/quicksilver/utils/addressutils"
"github.com/quicksilver-zone/quicksilver/x/participationrewards/types"
)

Expand Down Expand Up @@ -76,12 +78,28 @@
func (*OsmosisModule) ValidateClaim(ctx sdk.Context, k *Keeper, msg *types.MsgSubmitClaim) (math.Int, error) {
amount := sdk.ZeroInt()
var lock osmolockup.PeriodLock

addr, err := addressutils.AccAddressFromBech32(msg.UserAddress, "")
if err != nil {
return sdk.ZeroInt(), err

Check warning on line 84 in x/participationrewards/keeper/submodule_osmosis.go

View check run for this annotation

Codecov / codecov/patch

x/participationrewards/keeper/submodule_osmosis.go#L84

Added line #L84 was not covered by tests
}

for _, proof := range msg.Proofs {
if proof.ProofType == types.ProofTypeBank {
addr, poolDenom, err := banktypes.AddressAndDenomFromBalancesStore(proof.Key[1:])
poolDenom, err := utils.DenomFromRequestKey(proof.Key, addr)
if err != nil {
return sdk.ZeroInt(), err
// check for mapped address for this user from SrcZone.
mappedAddr, found := k.icsKeeper.GetLocalAddressMap(ctx, addr, msg.SrcZone)
if found {
poolDenom, err = utils.DenomFromRequestKey(proof.Key, mappedAddr)
if err != nil {
return sdk.ZeroInt(), errors.New("not a valid proof for submitting user or mapped account")

Check warning on line 96 in x/participationrewards/keeper/submodule_osmosis.go

View check run for this annotation

Codecov / codecov/patch

x/participationrewards/keeper/submodule_osmosis.go#L92-L96

Added lines #L92 - L96 were not covered by tests
}
} else {
return sdk.ZeroInt(), errors.New("not a valid proof for submitting user")

Check warning on line 99 in x/participationrewards/keeper/submodule_osmosis.go

View check run for this annotation

Codecov / codecov/patch

x/participationrewards/keeper/submodule_osmosis.go#L98-L99

Added lines #L98 - L99 were not covered by tests
}
}

coin, err := keeper.UnmarshalBalanceCompat(k.cdc, proof.Data, poolDenom)
if err != nil {
return sdk.ZeroInt(), err
Expand All @@ -103,8 +121,11 @@
return sdk.ZeroInt(), err
}

if sdk.AccAddress(lockupOwner).String() != msg.UserAddress {
return sdk.ZeroInt(), errors.New("not a valid proof for submitting user")
if !bytes.Equal(lockupOwner, addr) {
mappedAddr, found := k.icsKeeper.GetLocalAddressMap(ctx, addr, msg.SrcZone)
if !found || !bytes.Equal(lockupOwner, mappedAddr) {
return sdk.ZeroInt(), errors.New("not a valid proof for submitting user or mapped account")

Check warning on line 127 in x/participationrewards/keeper/submodule_osmosis.go

View check run for this annotation

Codecov / codecov/patch

x/participationrewards/keeper/submodule_osmosis.go#L125-L127

Added lines #L125 - L127 were not covered by tests
}
}
}
sdkAmount, err := osmosistypes.DetermineApplicableTokensInPool(ctx, k, lock, msg.Zone)
Expand Down
15 changes: 13 additions & 2 deletions x/participationrewards/keeper/submodule_osmosiscl.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package keeper

import (
"bytes"
"encoding/json"
"errors"
"fmt"
Expand All @@ -13,6 +14,7 @@
osmosistypes "github.com/quicksilver-zone/quicksilver/third-party-chains/osmosis-types"
osmocl "github.com/quicksilver-zone/quicksilver/third-party-chains/osmosis-types/concentrated-liquidity"
osmoclmodel "github.com/quicksilver-zone/quicksilver/third-party-chains/osmosis-types/concentrated-liquidity/model"
"github.com/quicksilver-zone/quicksilver/utils/addressutils"
"github.com/quicksilver-zone/quicksilver/x/participationrewards/types"
)

Expand Down Expand Up @@ -72,6 +74,12 @@
func (*OsmosisClModule) ValidateClaim(ctx sdk.Context, k *Keeper, msg *types.MsgSubmitClaim) (math.Int, error) {
claimAmount := math.ZeroInt()
var position osmoclmodel.Position

addr, err := addressutils.AccAddressFromBech32(msg.UserAddress, "")
if err != nil {
return math.ZeroInt(), err

Check warning on line 80 in x/participationrewards/keeper/submodule_osmosiscl.go

View check run for this annotation

Codecov / codecov/patch

x/participationrewards/keeper/submodule_osmosiscl.go#L78-L80

Added lines #L78 - L80 were not covered by tests
}

for _, proof := range msg.Proofs {
position = osmoclmodel.Position{}
err := k.cdc.Unmarshal(proof.Data, &position)
Expand All @@ -84,8 +92,11 @@
return math.ZeroInt(), err
}

if sdk.AccAddress(lockupOwner).String() != msg.UserAddress {
return math.ZeroInt(), errors.New("not a valid proof for submitting user")
if !bytes.Equal(lockupOwner, addr) {
mappedAddr, found := k.icsKeeper.GetLocalAddressMap(ctx, addr, msg.SrcZone)
if !found || !bytes.Equal(lockupOwner, mappedAddr) {
return math.ZeroInt(), errors.New("not a valid proof for submitting user or mapped account")

Check warning on line 98 in x/participationrewards/keeper/submodule_osmosiscl.go

View check run for this annotation

Codecov / codecov/patch

x/participationrewards/keeper/submodule_osmosiscl.go#L95-L98

Added lines #L95 - L98 were not covered by tests
}
}

sdkAmount, err := osmosistypes.DetermineApplicableTokensInClPool(ctx, k, position, msg.Zone)
Expand Down
18 changes: 15 additions & 3 deletions x/participationrewards/keeper/submodule_umee.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,20 @@

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

"cosmossdk.io/math"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/bech32"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"

umee "github.com/quicksilver-zone/quicksilver/third-party-chains/umee-types"
leveragetypes "github.com/quicksilver-zone/quicksilver/third-party-chains/umee-types/leverage/types"
"github.com/quicksilver-zone/quicksilver/utils"
"github.com/quicksilver-zone/quicksilver/utils/addressutils"
cmtypes "github.com/quicksilver-zone/quicksilver/x/claimsmanager/types"
icstypes "github.com/quicksilver-zone/quicksilver/x/interchainstaking/types"
"github.com/quicksilver-zone/quicksilver/x/participationrewards/types"
Expand Down Expand Up @@ -185,7 +186,10 @@
return sdk.ZeroInt(), fmt.Errorf("unable to find registered zone for chain id: %s", msg.Zone)
}

_, addr, err := bech32.DecodeAndConvert(msg.UserAddress)
addr, err := addressutils.AccAddressFromBech32(msg.UserAddress, "")
if err != nil {
return sdk.ZeroInt(), err

Check warning on line 191 in x/participationrewards/keeper/submodule_umee.go

View check run for this annotation

Codecov / codecov/patch

x/participationrewards/keeper/submodule_umee.go#L191

Added line #L191 was not covered by tests
}

amount := sdk.ZeroInt()
for _, proof := range msg.Proofs {
Expand All @@ -196,7 +200,15 @@

udenom, err := getDenomFromProof(proof, addr)
if err != nil {
return sdk.ZeroInt(), err
mappedAddr, found := k.icsKeeper.GetLocalAddressMap(ctx, addr, msg.SrcZone)
if found {
udenom, err = getDenomFromProof(proof, mappedAddr)
if err != nil {
return sdk.ZeroInt(), errors.New("not a valid proof for submitting user or mapped account")

Check warning on line 207 in x/participationrewards/keeper/submodule_umee.go

View check run for this annotation

Codecov / codecov/patch

x/participationrewards/keeper/submodule_umee.go#L205-L207

Added lines #L205 - L207 were not covered by tests
}
} else {
return sdk.ZeroInt(), errors.New("not a valid proof for submitting user")
}
}

denom := leveragetypes.ToTokenDenom(udenom)
Expand Down
1 change: 1 addition & 0 deletions x/participationrewards/types/expected_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,5 @@ type InterchainStakingKeeper interface {
IterateDelegatorIntents(ctx sdk.Context, zone *interchainstakingtypes.Zone, snapshot bool, fn func(index int64, intent interchainstakingtypes.DelegatorIntent) (stop bool))
GetValidators(ctx sdk.Context, chainID string) []interchainstakingtypes.Validator
SetValidator(ctx sdk.Context, chainID string, val interchainstakingtypes.Validator) error
GetLocalAddressMap(ctx sdk.Context, remoteAddress sdk.AccAddress, chainID string) (sdk.AccAddress, bool)
}
Loading