-
Notifications
You must be signed in to change notification settings - Fork 63
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
Add claimsmanager udpate spec. #1788
Draft
arhamchordia
wants to merge
14
commits into
main
Choose a base branch
from
spec/claimsmanager
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
dc7bb98
Add claimsmanager udpate spec.
arhamchordia 1aa3010
Add claim message to CM module.
arhamchordia cd9ca45
Adding errors.
arhamchordia 10b9212
Fix keeper imports
arhamchordia f5b720c
Add claimsmanager udpate spec.
arhamchordia 34f75ed
Add claim message to CM module.
arhamchordia 5823b7d
Adding errors.
arhamchordia c6a7d1a
Fix keeper imports
arhamchordia 7d5f47f
Claimable event functionalities.
arhamchordia 46ffa8d
Merge branch 'spec/claimsmanager' of https://github.com/quicksilver-z…
arhamchordia dc2905a
removing submodule dependent on ICS to figure out later.
arhamchordia 7fa5bd5
Merge branch 'main' into spec/claimsmanager
arhamchordia d2aa3e8
removing typos.
arhamchordia aed2670
Merge branch 'spec/claimsmanager' of https://github.com/quicksilver-z…
arhamchordia File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,59 @@ | ||
syntax = "proto3"; | ||
package quicksilver.claimsmanager.v1; | ||
|
||
import "quicksilver/claimsmanager/v1/claimsmanager.proto"; | ||
import "cosmos_proto/cosmos.proto"; | ||
import "gogoproto/gogo.proto"; | ||
import "google/api/annotations.proto"; | ||
|
||
option go_package = "github.com/quicksilver-zone/quicksilver/x/claimsmanager/types"; | ||
|
||
// Msg defines the claimsmanager Msg service. | ||
service Msg {} | ||
service Msg { | ||
rpc SubmitClaim(MsgSubmitClaim) returns (MsgSubmitClaimResponse) { | ||
option (google.api.http) = { | ||
post: "/quicksilver/tx/v1/claimsmanager/claim" | ||
body: "*" | ||
}; | ||
} | ||
rpc SubmitClaimableEvent(MsgSubmitClaimableEventClaim) returns (MsgSubmitClaimableEventClaimResponse) { | ||
option (google.api.http) = { | ||
post: "/quicksilver/tx/v1/claimsmanager/claimableEvent" | ||
body: "*" | ||
}; | ||
} | ||
} | ||
|
||
// MsgSubmitClaim represents a message type for submitting a | ||
// claim regarding the given zone (chain). | ||
message MsgSubmitClaim { | ||
option (gogoproto.equal) = false; | ||
option (gogoproto.goproto_getters) = false; | ||
|
||
string user_address = 1 [ | ||
json_name = "user_address", | ||
(cosmos_proto.scalar) = "cosmos.AddressString" | ||
]; | ||
string zone = 2 [json_name = "zone"]; | ||
string src_zone = 3 [json_name = "src_zone"]; | ||
quicksilver.claimsmanager.v1.ClaimType claim_type = 4 [json_name = "claim_type"]; | ||
repeated quicksilver.claimsmanager.v1.Proof proofs = 5 [json_name = "proofs"]; | ||
} | ||
|
||
// MsgSubmitClaimResponse defines the MsgSubmitClaim response type. | ||
message MsgSubmitClaimResponse {} | ||
|
||
message MsgSubmitClaimableEventClaim { | ||
option (gogoproto.equal) = false; | ||
option (gogoproto.goproto_getters) = false; | ||
|
||
string user_address = 1 [ | ||
json_name = "user_address", | ||
(cosmos_proto.scalar) = "cosmos.AddressString" | ||
]; | ||
string event_module = 3 [json_name = "event_module"]; | ||
string event_name = 4 [json_name = "event_name"]; | ||
repeated quicksilver.claimsmanager.v1.Proof proofs = 5 [json_name = "proofs"]; | ||
} | ||
|
||
message MsgSubmitClaimableEventClaimResponse {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
package keeper | ||
|
||
import ( | ||
"encoding/json" | ||
"errors" | ||
"fmt" | ||
|
||
"github.com/cosmos/cosmos-sdk/client/grpc/tmservice" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/quicksilver-zone/quicksilver/x/claimsmanager/types" | ||
icqtypes "github.com/quicksilver-zone/quicksilver/x/interchainquery/types" | ||
) | ||
|
||
const ( | ||
ValidatorSelectionRewardsCallbackID = "validatorselectionrewards" | ||
OsmosisPoolUpdateCallbackID = "osmosispoolupdate" | ||
OsmosisClPoolUpdateCallbackID = "osmosisclpoolupdate" | ||
SetEpochBlockCallbackID = "epochblock" | ||
UmeeReservesUpdateCallbackID = "umeereservesupdatecallback" | ||
UmeeTotalBorrowsUpdateCallbackID = "umeetotalborrowsupdatecallback" | ||
UmeeInterestScalarUpdateCallbackID = "umeeinterestscalarupdatecallback" | ||
UmeeUTokenSupplyUpdateCallbackID = "umeeutokensupplyupdatecallback" | ||
UmeeLeverageModuleBalanceUpdateCallbackID = "umeeleveragemodulebalanceupdatecallback" | ||
) | ||
|
||
type Callback func(sdk.Context, *Keeper, []byte, icqtypes.Query) error | ||
|
||
type Callbacks struct { | ||
k *Keeper | ||
callbacks map[string]Callback | ||
} | ||
|
||
var _ icqtypes.QueryCallbacks = Callbacks{} | ||
|
||
func (k *Keeper) CallbackHandler() Callbacks { | ||
return Callbacks{k, make(map[string]Callback)} | ||
} | ||
|
||
// Call calls callback handler. | ||
func (c Callbacks) Call(ctx sdk.Context, id string, args []byte, query icqtypes.Query) error { | ||
if !c.Has(id) { | ||
return fmt.Errorf("callback %s not found", id) | ||
} | ||
return c.callbacks[id](ctx, c.k, args, query) | ||
} | ||
|
||
func (c Callbacks) Has(id string) bool { | ||
_, found := c.callbacks[id] | ||
return found | ||
} | ||
|
||
func (c Callbacks) AddCallback(id string, fn interface{}) icqtypes.QueryCallbacks { | ||
c.callbacks[id], _ = fn.(Callback) | ||
return c | ||
} | ||
|
||
func (c Callbacks) RegisterCallbacks() icqtypes.QueryCallbacks { | ||
a := c.AddCallback(SetEpochBlockCallbackID, Callback(SetEpochBlockCallback)) | ||
|
||
return a.(Callbacks) | ||
} | ||
|
||
// SetEpochBlockCallback records the block height of the registered zone at the epoch boundary. | ||
func SetEpochBlockCallback(ctx sdk.Context, k *Keeper, args []byte, query icqtypes.Query) error { | ||
k.Logger(ctx).Debug("epoch callback called") | ||
data, connectionData, err := GetAndUnmarshalProtocolData[*types.ConnectionProtocolData](ctx, k, query.ChainId, types.ProtocolDataTypeConnection) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// block response is never expected to be nil | ||
if len(args) == 0 { | ||
return errors.New("attempted to unmarshal zero length byte slice (1)") | ||
} | ||
|
||
blockResponse := tmservice.GetLatestBlockResponse{} | ||
err = k.cdc.Unmarshal(args, &blockResponse) | ||
if err != nil { | ||
return err | ||
} | ||
k.Logger(ctx).Debug("got block response", "block", blockResponse) | ||
|
||
if blockResponse.SdkBlock == nil { | ||
// v0.45 and below | ||
// nolint:staticcheck // SA1019 ignore this! | ||
connectionData.LastEpoch = blockResponse.Block.Header.Height | ||
} else { | ||
// v0.46 and above | ||
connectionData.LastEpoch = blockResponse.SdkBlock.Header.Height | ||
} | ||
|
||
// todo update claimable events with all the heights collected here | ||
k.IteratePrefixedClaimableEvent(ctx, func(index int64, key []byte, data types.ClaimableEvent) (stop bool) { | ||
if ctx.BlockHeader().Time.Before(data.MaxClaimTime) { | ||
// Update the heights for each claimable event | ||
data.Heights[query.ChainId] = connectionData.LastEpoch // Update the height for the current chain | ||
|
||
// Save the updated claimable event back to the store | ||
if err = k.SetClaimableEvent(ctx, &data); err != nil { | ||
k.Logger(ctx).Error("Failed to update claimable event", "event", data.EventName, "error", err) | ||
} | ||
return false // Continue iterating till all events have updated the chain height | ||
} | ||
return false | ||
}) | ||
|
||
heightInBytes := sdk.Uint64ToBigEndian(uint64(connectionData.LastEpoch)) //nolint:gosec | ||
// trigger a client update at the epoch boundary | ||
k.IcqKeeper.MakeRequest( | ||
ctx, | ||
query.ConnectionId, | ||
query.ChainId, | ||
"ibc.ClientUpdate", | ||
heightInBytes, | ||
sdk.NewInt(-1), | ||
types.ModuleName, | ||
"", | ||
0, | ||
) | ||
|
||
k.Logger(ctx).Debug("emitted client update", "height", connectionData.LastEpoch) | ||
|
||
data.Data, err = json.Marshal(connectionData) | ||
if err != nil { | ||
return err | ||
} | ||
k.SetProtocolData(ctx, connectionData.GenerateKey(), &data) | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
package keeper | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/cosmos/cosmos-sdk/store/prefix" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/quicksilver-zone/quicksilver/x/claimsmanager/types" | ||
epochstypes "github.com/quicksilver-zone/quicksilver/x/epochs/types" | ||
participationrewardstypes "github.com/quicksilver-zone/quicksilver/x/participationrewards/types" | ||
) | ||
|
||
func (k *Keeper) SetClaimableEvent(ctx sdk.Context, claimableEvent *types.ClaimableEvent) error { | ||
if claimableEvent.MaxClaimTime.Before(ctx.BlockHeader().Time) { | ||
return fmt.Errorf("max time cannot be less than current block time") | ||
} | ||
|
||
// todo : 1. call the store consensus state here after each call | ||
// this might include callbacks etc | ||
switch claimableEvent.EventName { | ||
case epochstypes.ModuleName: | ||
if err := k.StoreSelfConsensusState(ctx, "epoch"); err != nil { | ||
return err | ||
} | ||
case participationrewardstypes.ModuleName: | ||
// zones: can get it from protocol data | ||
default: | ||
} | ||
|
||
var listOfChains []string | ||
k.IteratePrefixedProtocolDatas(ctx, types.GetPrefixProtocolDataKey(types.ProtocolDataTypeConnection), func(index int64, _ []byte, data types.ProtocolData) (stop bool) { | ||
iConnectionData, err := types.UnmarshalProtocolData(types.ProtocolDataTypeConnection, data.Data) | ||
if err != nil { | ||
k.Logger(ctx).Error("Error unmarshalling protocol data") | ||
} | ||
connectionData, _ := iConnectionData.(*types.ConnectionProtocolData) | ||
listOfChains = append(listOfChains, connectionData.ChainID) | ||
return | ||
}) | ||
|
||
for _, chainID := range listOfChains { | ||
claimableEvent.Heights[chainID] = 0 | ||
} | ||
|
||
//2. store rest of the data as is for the claimable event | ||
store := prefix.NewStore(ctx.KVStore(k.storeKey), nil) | ||
bz := k.cdc.MustMarshal(claimableEvent) | ||
store.Set(types.GetKeyClaimableEvent(claimableEvent.EventModule, claimableEvent.EventName), bz) | ||
return nil | ||
} | ||
|
||
func (k *Keeper) GetClaimableEvent(ctx sdk.Context, eventModule, eventName string) (types.ClaimableEvent, bool) { | ||
data := types.ClaimableEvent{} | ||
store := prefix.NewStore(ctx.KVStore(k.storeKey), nil) | ||
key := types.GetGenericKeyClaimableEvent(eventModule, eventName) | ||
bz := store.Get(key) | ||
if len(bz) == 0 { | ||
return data, false | ||
} | ||
|
||
k.cdc.MustUnmarshal(bz, &data) | ||
return data, true | ||
} | ||
|
||
func (k *Keeper) IteratePrefixedClaimableEvent(ctx sdk.Context, fn func(index int64, key []byte, data types.ClaimableEvent) (stop bool)) { | ||
if fn == nil { | ||
return | ||
} | ||
|
||
store := ctx.KVStore(k.storeKey) | ||
iterator := sdk.KVStorePrefixIterator(store, types.KeyPrefixClaimableEvent) | ||
defer iterator.Close() | ||
|
||
i := int64(0) | ||
for ; iterator.Valid(); iterator.Next() { | ||
data := types.ClaimableEvent{} | ||
k.cdc.MustUnmarshal(iterator.Value(), &data) | ||
stop := fn(i, iterator.Key(), data) | ||
if stop { | ||
break | ||
} | ||
i++ | ||
|
||
} | ||
} | ||
|
||
func (k *Keeper) DeleteClaimableEvent(ctx sdk.Context, eventModule, eventName string) { | ||
store := prefix.NewStore(ctx.KVStore(k.storeKey), nil) | ||
key := types.GetGenericKeyClaimableEvent(eventModule, eventName) | ||
|
||
store.Delete(key) | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not needed. Will get rid of it later.