Skip to content

Commit b41f72d

Browse files
author
Joe Bowman
committed
ensure we use the correct zone denom where evaluating pool claims
1 parent ff35015 commit b41f72d

File tree

4 files changed

+51
-31
lines changed

4 files changed

+51
-31
lines changed

third-party-chains/osmosis-types/validation.go

Lines changed: 8 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
sdk "github.com/cosmos/cosmos-sdk/types"
1111

1212
osmosislockuptypes "github.com/quicksilver-zone/quicksilver/third-party-chains/osmosis-types/lockup"
13-
"github.com/quicksilver-zone/quicksilver/utils"
1413
participationrewardstypes "github.com/quicksilver-zone/quicksilver/x/participationrewards/types"
1514

1615
cl "github.com/quicksilver-zone/quicksilver/third-party-chains/osmosis-types/concentrated-liquidity"
@@ -22,7 +21,7 @@ type ParticipationRewardsKeeper interface {
2221
GetProtocolData(ctx sdk.Context, pdType participationrewardstypes.ProtocolDataType, key string) (participationrewardstypes.ProtocolData, bool)
2322
}
2423

25-
func DetermineApplicableTokensInPool(ctx sdk.Context, prKeeper ParticipationRewardsKeeper, lock osmosislockuptypes.PeriodLock, chainID string) (math.Int, error) {
24+
func DetermineApplicableTokensInPool(ctx sdk.Context, prKeeper ParticipationRewardsKeeper, lock osmosislockuptypes.PeriodLock, chainID string, poolDenom string) (math.Int, error) {
2625
gammtoken, err := lock.SingleCoin()
2726
if err != nil {
2827
return sdk.ZeroInt(), err
@@ -40,18 +39,6 @@ func DetermineApplicableTokensInPool(ctx sdk.Context, prKeeper ParticipationRewa
4039
}
4140
pool, _ := ipool.(*participationrewardstypes.OsmosisPoolProtocolData)
4241

43-
poolDenom := ""
44-
for _, zk := range utils.Keys(pool.Denoms) {
45-
if pool.Denoms[zk].ChainID == chainID {
46-
poolDenom = zk
47-
break
48-
}
49-
}
50-
51-
if poolDenom == "" {
52-
return sdk.ZeroInt(), fmt.Errorf("invalid zone, pool zone must match %s", chainID)
53-
}
54-
5542
poolData, err := pool.GetPool()
5643
if err != nil {
5744
return sdk.ZeroInt(), err
@@ -91,8 +78,10 @@ func CalculateUnderlyingAssetsFromPosition(ctx sdk.Context, position clmodel.Pos
9178
return coin0, coin1, nil
9279
}
9380

94-
func DetermineApplicableTokensInClPool(ctx sdk.Context, prKeeper ParticipationRewardsKeeper, position clmodel.Position, chainID string) (math.Int, error) {
81+
func DetermineApplicableTokensInClPool(ctx sdk.Context, prKeeper ParticipationRewardsKeeper, position clmodel.Position, chainID string, poolDenom string) (math.Int, error) {
9582
poolID := position.PoolId
83+
84+
ctx.Logger().Info("DetermineApplicableTokensInClPool", "poolID", poolID, "position", position)
9685
pd, ok := prKeeper.GetProtocolData(ctx, participationrewardstypes.ProtocolDataTypeOsmosisCLPool, fmt.Sprintf("%d", poolID))
9786
if !ok {
9887
return sdk.ZeroInt(), fmt.Errorf("unable to obtain protocol data for poolID=%d", poolID)
@@ -104,18 +93,6 @@ func DetermineApplicableTokensInClPool(ctx sdk.Context, prKeeper ParticipationRe
10493
}
10594
pool, _ := ipool.(*participationrewardstypes.OsmosisClPoolProtocolData)
10695

107-
poolDenom := ""
108-
for _, zk := range utils.Keys(pool.Denoms) {
109-
if pool.Denoms[zk].ChainID == chainID {
110-
poolDenom = zk
111-
break
112-
}
113-
}
114-
115-
if poolDenom == "" {
116-
return sdk.ZeroInt(), fmt.Errorf("invalid zone, pool zone must match %s", chainID)
117-
}
118-
11996
poolData, err := pool.GetPool()
12097
if err != nil {
12198
return sdk.ZeroInt(), err
@@ -126,13 +103,16 @@ func DetermineApplicableTokensInClPool(ctx sdk.Context, prKeeper ParticipationRe
126103
if err != nil {
127104
return sdk.ZeroInt(), errors.New("unable to determine underlying assets for position")
128105
}
106+
107+
ctx.Logger().Info("DetermineApplicableTokensInClPool", "asset0", asset0, "asset1", asset1)
108+
129109
switch true {
130110
case asset0.Denom == poolDenom:
131111
asset = asset0
132112
case asset1.Denom == poolDenom:
133113
asset = asset1
134114
default:
135-
return sdk.ZeroInt(), fmt.Errorf("position does not match local denom for %s", chainID)
115+
return sdk.ZeroInt(), fmt.Errorf("position does not match local denom for %s (poolDenom: %s)", chainID, poolDenom)
136116
}
137117

138118
return asset.Amount, nil

x/airdrop/keeper/claim_handler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ func (k *Keeper) verifyOsmosisLP(ctx sdk.Context, proofs []*cmtypes.Proof, cr ty
307307
}
308308

309309
func (k *Keeper) verifyPoolAndGetAmount(ctx sdk.Context, lock osmosislockuptypes.PeriodLock, cr types.ClaimRecord) (sdkmath.Int, error) {
310-
return osmosistypes.DetermineApplicableTokensInPool(ctx, k.prKeeper, lock, cr.ChainId)
310+
return osmosistypes.DetermineApplicableTokensInPool(ctx, k.prKeeper, lock, cr.ChainId, "UNUSED")
311311
}
312312

313313
// -----------

x/participationrewards/keeper/submodule_osmosis.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,13 @@ func (*OsmosisModule) ValidateClaim(ctx sdk.Context, k *Keeper, msg *types.MsgSu
139139
}
140140
}
141141
}
142-
sdkAmount, err := osmosistypes.DetermineApplicableTokensInPool(ctx, k, lock, msg.Zone)
142+
143+
denom, found := k.ApplicableDenomForZone(ctx, msg.Zone)
144+
if !found {
145+
return math.ZeroInt(), errors.New("no applicable denom found for zone")
146+
}
147+
148+
sdkAmount, err := osmosistypes.DetermineApplicableTokensInPool(ctx, k, lock, msg.Zone, denom)
143149
if err != nil {
144150
return sdk.ZeroInt(), err
145151
}

x/participationrewards/keeper/submodule_osmosiscl.go

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,12 @@ func (*OsmosisClModule) ValidateClaim(ctx sdk.Context, k *Keeper, msg *types.Msg
110110
}
111111
}
112112

113-
sdkAmount, err := osmosistypes.DetermineApplicableTokensInClPool(ctx, k, position, msg.Zone)
113+
denom, found := k.ApplicableDenomForZone(ctx, msg.Zone)
114+
if !found {
115+
return math.ZeroInt(), errors.New("no applicable denom found for zone")
116+
}
117+
118+
sdkAmount, err := osmosistypes.DetermineApplicableTokensInClPool(ctx, k, position, msg.Zone, denom)
114119
if err != nil {
115120
return math.ZeroInt(), err
116121
}
@@ -126,3 +131,32 @@ func (*OsmosisClModule) ValidateClaim(ctx sdk.Context, k *Keeper, msg *types.Msg
126131
func (*OsmosisClModule) KeyPool(poolID uint64) []byte {
127132
return osmocl.KeyPool(poolID)
128133
}
134+
135+
func (k *Keeper) ApplicableDenomForZone(ctx sdk.Context, chainId string) (denom string, found bool) {
136+
zone, found := k.icsKeeper.GetZone(ctx, chainId)
137+
if !found {
138+
return "", false
139+
}
140+
141+
params, found := k.GetProtocolData(ctx, types.ProtocolDataTypeOsmosisParams, types.OsmosisParamsKey)
142+
if !found {
143+
return "", false
144+
}
145+
146+
paramsData := types.OsmosisParamsProtocolData{}
147+
if err := json.Unmarshal(params.Data, &paramsData); err != nil {
148+
return "", false
149+
}
150+
151+
k.IteratePrefixedProtocolDatas(ctx, types.GetPrefixProtocolDataKey(types.ProtocolDataTypeLiquidToken), func(idx int64, key []byte, data types.ProtocolData) bool {
152+
liquidToken, _ := types.UnmarshalProtocolData(types.ProtocolDataTypeLiquidToken, data.Data)
153+
liquidTokenData := liquidToken.(*types.LiquidAllowedDenomProtocolData)
154+
if liquidTokenData.ChainID == paramsData.ChainID && liquidTokenData.QAssetDenom == zone.LocalDenom {
155+
found = true
156+
denom = liquidTokenData.IbcDenom
157+
return true
158+
}
159+
return false
160+
})
161+
return denom, found
162+
}

0 commit comments

Comments
 (0)