Skip to content

Commit

Permalink
refactor: reimplement BridgeTokens gRPC query (#748)
Browse files Browse the repository at this point in the history
  • Loading branch information
zakir-code authored Oct 17, 2024
1 parent 5a008d6 commit bff5bda
Show file tree
Hide file tree
Showing 27 changed files with 7,293 additions and 7,499 deletions.
473 changes: 160 additions & 313 deletions api/fx/gravity/crosschain/v1/genesis.pulsar.go

Large diffs are not rendered by default.

3,089 changes: 3,059 additions & 30 deletions api/fx/gravity/crosschain/v1/legacy.pulsar.go

Large diffs are not rendered by default.

3,325 changes: 1,077 additions & 2,248 deletions api/fx/gravity/crosschain/v1/query.pulsar.go

Large diffs are not rendered by default.

4,180 changes: 1,165 additions & 3,015 deletions api/fx/gravity/crosschain/v1/types.pulsar.go

Large diffs are not rendered by default.

8 changes: 0 additions & 8 deletions app/genesis.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
},
"oracles": [],
"oracle_sets": [],
"bridge_tokens": [],
"unbatched_transfers": [],
"batches": [],
"oracle_set_confirms": [],
Expand Down Expand Up @@ -86,7 +85,6 @@
},
"oracles": [],
"oracle_sets": [],
"bridge_tokens": [],
"unbatched_transfers": [],
"batches": [],
"oracle_set_confirms": [],
Expand Down Expand Up @@ -173,7 +171,6 @@
},
"oracles": [],
"oracle_sets": [],
"bridge_tokens": [],
"unbatched_transfers": [],
"batches": [],
"oracle_set_confirms": [],
Expand Down Expand Up @@ -254,7 +251,6 @@
},
"oracles": [],
"oracle_sets": [],
"bridge_tokens": [],
"unbatched_transfers": [],
"batches": [],
"oracle_set_confirms": [],
Expand Down Expand Up @@ -431,7 +427,6 @@
},
"oracles": [],
"oracle_sets": [],
"bridge_tokens": [],
"unbatched_transfers": [],
"batches": [],
"oracle_set_confirms": [],
Expand Down Expand Up @@ -491,7 +486,6 @@
},
"oracles": [],
"oracle_sets": [],
"bridge_tokens": [],
"unbatched_transfers": [],
"batches": [],
"oracle_set_confirms": [],
Expand Down Expand Up @@ -537,7 +531,6 @@
},
"oracles": [],
"oracle_sets": [],
"bridge_tokens": [],
"unbatched_transfers": [],
"batches": [],
"oracle_set_confirms": [],
Expand Down Expand Up @@ -619,7 +612,6 @@
},
"oracles": [],
"oracle_sets": [],
"bridge_tokens": [],
"unbatched_transfers": [],
"batches": [],
"oracle_set_confirms": [],
Expand Down
2 changes: 1 addition & 1 deletion docs/statik/statik.go

Large diffs are not rendered by default.

3 changes: 0 additions & 3 deletions docs/swagger-ui/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7314,7 +7314,6 @@ paths:
channel_ibc:
type: string
title: 'Deprecated: after upgrade v3'
title: BridgeToken
default:
description: An unexpected error response.
schema:
Expand Down Expand Up @@ -41567,7 +41566,6 @@ definitions:
channel_ibc:
type: string
title: 'Deprecated: after upgrade v3'
title: BridgeToken
fx.gravity.crosschain.v1.BridgeValidator:
type: object
properties:
Expand Down Expand Up @@ -42093,7 +42091,6 @@ definitions:
channel_ibc:
type: string
title: 'Deprecated: after upgrade v3'
title: BridgeToken
fx.gravity.crosschain.v1.QueryCurrentOracleSetResponse:
type: object
properties:
Expand Down
19 changes: 9 additions & 10 deletions proto/fx/gravity/crosschain/v1/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,15 @@ message GenesisState {
[ (gogoproto.nullable) = false ];
repeated Oracle oracles = 4 [ (gogoproto.nullable) = false ];
repeated OracleSet oracle_sets = 5 [ (gogoproto.nullable) = false ];
repeated BridgeToken bridge_tokens = 6 [ (gogoproto.nullable) = false ];
repeated OutgoingTransferTx unbatched_transfers = 7
repeated OutgoingTransferTx unbatched_transfers = 6
[ (gogoproto.nullable) = false ];
repeated OutgoingTxBatch batches = 8 [ (gogoproto.nullable) = false ];
repeated MsgOracleSetConfirm oracle_set_confirms = 9
repeated OutgoingTxBatch batches = 7 [ (gogoproto.nullable) = false ];
repeated MsgOracleSetConfirm oracle_set_confirms = 8
[ (gogoproto.nullable) = false ];
repeated MsgConfirmBatch batch_confirms = 10 [ (gogoproto.nullable) = false ];
repeated Attestation attestations = 11 [ (gogoproto.nullable) = false ];
ProposalOracle proposal_oracle = 12 [ (gogoproto.nullable) = false ];
OracleSet last_observed_oracle_set = 13 [ (gogoproto.nullable) = false ];
uint64 last_slashed_batch_block = 14;
uint64 last_slashed_oracle_set_nonce = 15;
repeated MsgConfirmBatch batch_confirms = 9 [ (gogoproto.nullable) = false ];
repeated Attestation attestations = 10 [ (gogoproto.nullable) = false ];
ProposalOracle proposal_oracle = 11 [ (gogoproto.nullable) = false ];
OracleSet last_observed_oracle_set = 12 [ (gogoproto.nullable) = false ];
uint64 last_slashed_batch_block = 13;
uint64 last_slashed_oracle_set_nonce = 14;
}
47 changes: 46 additions & 1 deletion proto/fx/gravity/crosschain/v1/legacy.proto
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,49 @@ message MsgOracleSetConfirmResponse { option deprecated = true; }

message MsgConfirmBatchResponse { option deprecated = true; }

message MsgBridgeCallConfirmResponse { option deprecated = true; }
message MsgBridgeCallConfirmResponse { option deprecated = true; }

message BridgeToken {
option deprecated = true;
string token = 1;
string denom = 2;
// Deprecated: after upgrade v3
string channel_ibc = 3;
}

message BatchFees {
option deprecated = true;
string token_contract = 1;
string total_fees = 2 [
(cosmos_proto.scalar) = "cosmos.Int",
(gogoproto.customtype) = "cosmossdk.io/math.Int",
(gogoproto.nullable) = false
];
uint64 total_txs = 3;
string total_amount = 4 [
(cosmos_proto.scalar) = "cosmos.Int",
(gogoproto.customtype) = "cosmossdk.io/math.Int",
(gogoproto.nullable) = false
];
}

message MinBatchFee {
option deprecated = true;
string token_contract = 1;
string base_fee = 2 [
(cosmos_proto.scalar) = "cosmos.Int",
(gogoproto.customtype) = "cosmossdk.io/math.Int",
(gogoproto.nullable) = false
];
}

message QueryBatchFeeRequest {
option deprecated = true;
string chain_name = 1;
repeated MinBatchFee min_batch_fees = 2 [ (gogoproto.nullable) = false ];
}

message QueryBatchFeeResponse {
option deprecated = true;
repeated BatchFees batch_fees = 1;
}
7 changes: 1 addition & 6 deletions proto/fx/gravity/crosschain/v1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import "cosmos/base/v1beta1/coin.proto";
import "cosmos_proto/cosmos.proto";
import "fx/gravity/crosschain/v1/tx.proto";
import "fx/gravity/crosschain/v1/types.proto";
import "fx/gravity/crosschain/v1/legacy.proto";
import "gogoproto/gogo.proto";
import "google/api/annotations.proto";
import "google/protobuf/any.proto";
Expand Down Expand Up @@ -187,12 +188,6 @@ message QueryLastPendingOracleSetRequestByAddrResponse {
repeated OracleSet oracle_sets = 1;
}

message QueryBatchFeeRequest {
string chain_name = 1;
repeated MinBatchFee min_batch_fees = 2 [ (gogoproto.nullable) = false ];
}
message QueryBatchFeeResponse { repeated BatchFees batch_fees = 1; }

message QueryLastPendingBatchRequestByAddrRequest {
string chain_name = 1;
string bridger_address = 2;
Expand Down
32 changes: 0 additions & 32 deletions proto/fx/gravity/crosschain/v1/types.proto
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,6 @@ message LastObservedBlockHeight {
uint64 block_height = 2;
}

// BridgeToken
message BridgeToken {
string token = 1;
string denom = 2;
// Deprecated: after upgrade v3
string channel_ibc = 3;
}

// ClaimType is the cosmos type of an event from the counterpart chain that can
// be handled
enum ClaimType {
Expand Down Expand Up @@ -124,30 +116,6 @@ message ERC20Token {
];
}

message BatchFees {
string token_contract = 1;
string total_fees = 2 [
(cosmos_proto.scalar) = "cosmos.Int",
(gogoproto.customtype) = "cosmossdk.io/math.Int",
(gogoproto.nullable) = false
];
uint64 total_txs = 3;
string total_amount = 4 [
(cosmos_proto.scalar) = "cosmos.Int",
(gogoproto.customtype) = "cosmossdk.io/math.Int",
(gogoproto.nullable) = false
];
}

message MinBatchFee {
string token_contract = 1;
string base_fee = 2 [
(cosmos_proto.scalar) = "cosmos.Int",
(gogoproto.customtype) = "cosmossdk.io/math.Int",
(gogoproto.nullable) = false
];
}

// Params represent the Gravity genesis and store parameters
// gravity_id:
// a random 32 byte value to prevent signature reuse, for example if the
Expand Down
6 changes: 3 additions & 3 deletions x/crosschain/keeper/bridge_token.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func (k Keeper) AddBridgeTokenExecuted(ctx sdk.Context, claim *types.MsgBridgeTo
return types.ErrInvalid.Wrapf("%s denom decimals not match %d, expect %d",
fxtypes.DefaultDenom, claim.Decimals, fxtypes.DenomUnit)
}
bridgeToken, err := k.erc20Keeper.GetBridgeToken(ctx, claim.Symbol, k.moduleName)
bridgeToken, err := k.erc20Keeper.GetBridgeToken(ctx, k.moduleName, claim.Symbol)
if err != nil {
return err
}
Expand All @@ -49,13 +49,13 @@ func (k Keeper) BridgeCoinSupply(ctx context.Context, token, target string) (sdk
}
var targetDenom string
if fxTarget.IsIBC() {
ibcToken, err := k.erc20Keeper.GetIBCToken(ctx, baseDenom, fxTarget.IBCChannel)
ibcToken, err := k.erc20Keeper.GetIBCToken(ctx, fxTarget.IBCChannel, baseDenom)
if err != nil {
return sdk.Coin{}, err
}
targetDenom = ibcToken.IbcDenom
} else {
bridgeToken, err := k.erc20Keeper.GetBridgeToken(ctx, baseDenom, fxTarget.GetModuleName())
bridgeToken, err := k.erc20Keeper.GetBridgeToken(ctx, fxTarget.GetModuleName(), baseDenom)
if err != nil {
return sdk.Coin{}, err
}
Expand Down
19 changes: 14 additions & 5 deletions x/crosschain/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ func (k QueryServer) DenomToToken(c context.Context, req *types.QueryDenomToToke
return nil, status.Error(codes.InvalidArgument, "denom")
}

bridgeToken, err := k.erc20Keeper.GetBridgeToken(c, req.Denom, req.ChainName)
bridgeToken, err := k.erc20Keeper.GetBridgeToken(c, req.ChainName, req.Denom)
if err != nil {
return nil, status.Error(codes.NotFound, err.Error())
}
Expand All @@ -207,7 +207,7 @@ func (k QueryServer) TokenToDenom(c context.Context, req *types.QueryTokenToDeno
if err != nil {
return nil, status.Error(codes.NotFound, err.Error())
}
_, err = k.erc20Keeper.GetBridgeToken(c, baseDenom, req.ChainName)
_, err = k.erc20Keeper.GetBridgeToken(c, req.ChainName, baseDenom)
if err != nil {
return nil, status.Error(codes.NotFound, err.Error())
}
Expand Down Expand Up @@ -282,9 +282,18 @@ func (k QueryServer) ProjectedBatchTimeoutHeight(c context.Context, _ *types.Que
return &types.QueryProjectedBatchTimeoutHeightResponse{TimeoutHeight: timeout}, nil
}

func (k QueryServer) BridgeTokens(c context.Context, _ *types.QueryBridgeTokensRequest) (*types.QueryBridgeTokensResponse, error) {
bridgeTokens := make([]*types.BridgeToken, 0)
// todo: need implement
func (k QueryServer) BridgeTokens(c context.Context, req *types.QueryBridgeTokensRequest) (*types.QueryBridgeTokensResponse, error) {
tokens, err := k.erc20Keeper.GetBridgeTokens(c, req.ChainName)
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
}
bridgeTokens := make([]*types.BridgeToken, 0, len(tokens))
for _, token := range tokens {
bridgeTokens = append(bridgeTokens, &types.BridgeToken{
Token: token.Contract,
Denom: token.BridgeDenom(),
})
}
return &types.QueryBridgeTokensResponse{BridgeTokens: bridgeTokens}, nil
}

Expand Down
6 changes: 3 additions & 3 deletions x/crosschain/keeper/many_to_one.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func (k Keeper) BridgeTokenToBaseCoin(ctx context.Context, holder sdk.AccAddress
}

func (k Keeper) BaseCoinToBridgeToken(ctx context.Context, holder sdk.AccAddress, baseCoin sdk.Coin) (bridgeToken erc20types.BridgeToken, err error) {
bridgeToken, err = k.erc20Keeper.GetBridgeToken(ctx, baseCoin.Denom, k.moduleName)
bridgeToken, err = k.erc20Keeper.GetBridgeToken(ctx, k.moduleName, baseCoin.Denom)
if err != nil {
return bridgeToken, err
}
Expand Down Expand Up @@ -106,7 +106,7 @@ func (k Keeper) IBCCoinToBaseCoin(ctx context.Context, holder sdk.AccAddress, ib
}

func (k Keeper) BaseCoinToIBCCoin(ctx context.Context, holder sdk.AccAddress, baseCoin sdk.Coin, channel string) (sdk.Coin, error) {
ibcToken, err := k.erc20Keeper.GetIBCToken(ctx, baseCoin.Denom, channel)
ibcToken, err := k.erc20Keeper.GetIBCToken(ctx, channel, baseCoin.Denom)
if err != nil {
// NOTE: if not found in IBCToken
return baseCoin, nil
Expand Down Expand Up @@ -168,5 +168,5 @@ func (k Keeper) GetBridgeToken(ctx context.Context, tokenAddr string) (erc20type
if err != nil {
return erc20types.BridgeToken{}, err
}
return k.erc20Keeper.GetBridgeToken(ctx, baseDenom, k.moduleName)
return k.erc20Keeper.GetBridgeToken(ctx, k.moduleName, baseDenom)
}
31 changes: 23 additions & 8 deletions x/crosschain/mock/expected_keepers_mocks.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions x/crosschain/types/expected_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,10 @@ type Erc20Keeper interface {

GetERC20Token(ctx context.Context, baseDenom string) (erc20types.ERC20Token, error)

GetBridgeToken(ctx context.Context, baseDenom, chainName string) (erc20types.BridgeToken, error)
GetBridgeToken(ctx context.Context, chainName, baseDenom string) (erc20types.BridgeToken, error)
GetBridgeTokens(ctx context.Context, chainName string) ([]erc20types.BridgeToken, error)

GetIBCToken(ctx context.Context, baseDenom, channel string) (erc20types.IBCToken, error)
GetIBCToken(ctx context.Context, channel, baseDenom string) (erc20types.IBCToken, error)
}

// EVMKeeper defines the expected EVM keeper interface used on crosschain
Expand Down
Loading

0 comments on commit bff5bda

Please sign in to comment.