Skip to content

Commit

Permalink
[LeverageLp]: add position usd value (#764)
Browse files Browse the repository at this point in the history
* feat: add position usd value

* add test

---------

Co-authored-by: Cosmic Vagabond <121588426+cosmic-vagabond@users.noreply.github.com>
  • Loading branch information
cryptokage1996 and cosmic-vagabond authored Sep 3, 2024
1 parent 6333cac commit 07ad6ea
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 44 deletions.
4 changes: 4 additions & 0 deletions proto/elys/leveragelp/types.proto
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ message LegacyPosition {
message QueryPosition {
Position position = 1;
string updated_leverage = 2 [(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", (gogoproto.nullable) = false];
string position_usd_value = 3 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
];
}

message PositionAndInterest {
Expand Down
5 changes: 3 additions & 2 deletions x/leveragelp/keeper/query_get_position_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,17 +101,18 @@ func (suite KeeperTestSuite) TestQueryGetPosition() {
suite.Require().Equal(position, res.Position.Position)
suite.Require().Equal(updated_leverage, res.Position.UpdatedLeverage)


expected := types.PositionAndInterest{
Position: &types.QueryPosition{
Position: position,
UpdatedLeverage: updated_leverage,
PositionUsdValue: sdk.NewInt(5000),
},
InterestRateHour: sdk.MustNewDecFromStr("0.000017123287671233"),
InterestRateHourUsd: sdk.ZeroDec(),
}
pos_for_address_res, _ := k.QueryPositionsForAddress(suite.ctx, &types.PositionsForAddressRequest{Address: addr.String(), Pagination: nil} )

suite.Require().Equal(expected.Position, pos_for_address_res.Positions[0].Position)
suite.Require().Equal(expected.InterestRateHour, pos_for_address_res.Positions[0].InterestRateHour)
suite.Require().True(expected.InterestRateHour.Equal(pos_for_address_res.Positions[0].InterestRateHour))
suite.Require().True(expected.InterestRateHourUsd.Equal(pos_for_address_res.Positions[0].InterestRateHourUsd))
}
1 change: 1 addition & 0 deletions x/leveragelp/keeper/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ func (k Keeper) GetLeverageLpUpdatedLeverage(ctx sdk.Context, positions []*types
updatedLeveragePositions = append(updatedLeveragePositions, &types.QueryPosition{
Position: position,
UpdatedLeverage: updated_leverage,
PositionUsdValue: exitAmountAfterFee,
})
}
return updatedLeveragePositions, nil
Expand Down
132 changes: 90 additions & 42 deletions x/leveragelp/types/types.pb.go

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

0 comments on commit 07ad6ea

Please sign in to comment.