-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[TRA-181] Add query function for collateral pool address. (#1256)
- Loading branch information
1 parent
2f6fffc
commit ddd1715
Showing
9 changed files
with
883 additions
and
68 deletions.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
46 changes: 46 additions & 0 deletions
46
protocol/x/subaccounts/keeper/grpc_query_collateral_pool.go
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,46 @@ | ||
package keeper | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"fmt" | ||
|
||
"github.com/dydxprotocol/v4-chain/protocol/lib" | ||
perptypes "github.com/dydxprotocol/v4-chain/protocol/x/perpetuals/types" | ||
"github.com/dydxprotocol/v4-chain/protocol/x/subaccounts/types" | ||
"google.golang.org/grpc/codes" | ||
"google.golang.org/grpc/status" | ||
) | ||
|
||
func (k Keeper) CollateralPoolAddress( | ||
c context.Context, | ||
req *types.QueryCollateralPoolAddressRequest, | ||
) (*types.QueryCollateralPoolAddressResponse, error) { | ||
if req == nil { | ||
return nil, status.Error(codes.InvalidArgument, "invalid request") | ||
} | ||
ctx := lib.UnwrapSDKContext(c, types.ModuleName) | ||
|
||
collateralPool, err := k.GetCollateralPoolFromPerpetualId( | ||
ctx, | ||
req.PerpetualId, | ||
) | ||
if err != nil { | ||
if errors.Is(err, perptypes.ErrPerpetualDoesNotExist) { | ||
return nil, | ||
status.Error( | ||
codes.NotFound, | ||
fmt.Sprintf( | ||
"Perpetual id %+v not found.", | ||
req.PerpetualId, | ||
), | ||
) | ||
} | ||
|
||
return nil, status.Error(codes.Internal, "internal error") | ||
} | ||
|
||
return &types.QueryCollateralPoolAddressResponse{ | ||
CollateralPoolAddress: collateralPool.String(), | ||
}, nil | ||
} |
Oops, something went wrong.