Skip to content

Commit

Permalink
fix: rename collateralDenom
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiasmatt committed Nov 2, 2023
1 parent b34931b commit f212a13
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 25 deletions.
6 changes: 3 additions & 3 deletions x/perp/v2/integration/action/dnr.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,12 @@ func MarketOrderFeeIs(
}

func (o *marketOrderFeeIs) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error, bool) {
collateralDenom, err := app.PerpKeeperV2.Collateral.Get(ctx)
collateral, err := app.PerpKeeperV2.Collateral.Get(ctx)
if err != nil {
return ctx, err, true
}

balanceBefore := app.BankKeeper.GetBalance(ctx, o.trader, collateralDenom.GetTFDenom()).Amount
balanceBefore := app.BankKeeper.GetBalance(ctx, o.trader, collateral.GetTFDenom()).Amount
resp, err := app.PerpKeeperV2.MarketOrder(
ctx, o.pair, o.dir, o.trader,
o.margin, o.leverage, o.baseAssetLimit,
Expand All @@ -148,7 +148,7 @@ func (o *marketOrderFeeIs) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context,
balanceBefore = balanceBefore.Sub(resp.MarginToVault.TruncateInt())

expectedFee := math.LegacyNewDecFromInt(o.margin).Mul(o.fee.Add(sdk.MustNewDecFromStr("0.001"))) // we add the ecosystem fund fee
balanceAfter := app.BankKeeper.GetBalance(ctx, o.trader, collateralDenom.GetTFDenom()).Amount
balanceAfter := app.BankKeeper.GetBalance(ctx, o.trader, collateral.GetTFDenom()).Amount
paidFees := balanceBefore.Sub(balanceAfter)
if !paidFees.Equal(expectedFee.TruncateInt()) {
return ctx, fmt.Errorf("unexpected fee, wanted %s, got %s", expectedFee, paidFees), true
Expand Down
16 changes: 8 additions & 8 deletions x/perp/v2/integration/action/margin.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ type addMarginAction struct {
}

func (a addMarginAction) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error, bool) {
collateralDenom, err := app.PerpKeeperV2.Collateral.Get(ctx)
collateral, err := app.PerpKeeperV2.Collateral.Get(ctx)
if err != nil {
return ctx, err, true
}

_, err = app.PerpKeeperV2.AddMargin(
ctx, a.Pair, a.Account, sdk.NewCoin(collateralDenom.GetTFDenom(), a.Margin),
ctx, a.Pair, a.Account, sdk.NewCoin(collateral.GetTFDenom(), a.Margin),
)
if err != nil {
return ctx, err, true
Expand Down Expand Up @@ -70,13 +70,13 @@ type addMarginFailAction struct {
}

func (a addMarginFailAction) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error, bool) {
collateralDenom, err := app.PerpKeeperV2.Collateral.Get(ctx)
collateral, err := app.PerpKeeperV2.Collateral.Get(ctx)
if err != nil {
return ctx, err, true
}

_, err = app.PerpKeeperV2.AddMargin(
ctx, a.Pair, a.Account, sdk.NewCoin(collateralDenom.GetTFDenom(), a.Margin),
ctx, a.Pair, a.Account, sdk.NewCoin(collateral.GetTFDenom(), a.Margin),
)
if !errors.Is(err, a.ExpectedErr) {
return ctx, fmt.Errorf("expected error %v, got %v", a.ExpectedErr, err), false
Expand Down Expand Up @@ -104,13 +104,13 @@ type removeMarginAction struct {
}

func (a removeMarginAction) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error, bool) {
collateralDenom, err := app.PerpKeeperV2.Collateral.Get(ctx)
collateral, err := app.PerpKeeperV2.Collateral.Get(ctx)
if err != nil {
return ctx, err, true
}

_, err = app.PerpKeeperV2.RemoveMargin(
ctx, a.Pair, a.Account, sdk.NewCoin(collateralDenom.GetTFDenom(), a.Margin),
ctx, a.Pair, a.Account, sdk.NewCoin(collateral.GetTFDenom(), a.Margin),
)
if err != nil {
return ctx, err, false
Expand Down Expand Up @@ -141,13 +141,13 @@ type removeMarginActionFail struct {
}

func (a removeMarginActionFail) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error, bool) {
collateralDenom, err := app.PerpKeeperV2.Collateral.Get(ctx)
collateral, err := app.PerpKeeperV2.Collateral.Get(ctx)
if err != nil {
return ctx, err, true
}

_, err = app.PerpKeeperV2.RemoveMargin(
ctx, a.Pair, a.Account, sdk.NewCoin(collateralDenom.GetTFDenom(), a.Margin),
ctx, a.Pair, a.Account, sdk.NewCoin(collateral.GetTFDenom(), a.Margin),
)
if !errors.Is(err, a.ExpectedErr) {
return ctx, fmt.Errorf("expected error %v, got %v", a.ExpectedErr, err), false
Expand Down
4 changes: 2 additions & 2 deletions x/perp/v2/integration/action/market.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ func CreateCustomMarket(pair asset.Pair, marketModifiers ...MarketModifier) acti

type MarketModifier func(market *types.Market, amm *types.AMM)

func WithPrepaidBadDebt(amount sdkmath.Int, collateralDenom string) MarketModifier {
func WithPrepaidBadDebt(amount sdkmath.Int, collateral string) MarketModifier {
return func(market *types.Market, amm *types.AMM) {
market.PrepaidBadDebt = sdk.NewCoin(collateralDenom, amount)
market.PrepaidBadDebt = sdk.NewCoin(collateral, amount)
}
}

Expand Down
4 changes: 2 additions & 2 deletions x/perp/v2/integration/assertion/market.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ func Market_LatestCPFShouldBeEqualTo(expectedCPF sdk.Dec) MarketChecker {
}
}

func Market_PrepaidBadDebtShouldBeEqualTo(expectedAmount sdkmath.Int, collateralDenom string) MarketChecker {
func Market_PrepaidBadDebtShouldBeEqualTo(expectedAmount sdkmath.Int, collateral string) MarketChecker {
return func(market types.Market) error {
expectedBadDebt := sdk.NewCoin(collateralDenom, expectedAmount)
expectedBadDebt := sdk.NewCoin(collateral, expectedAmount)
if !market.PrepaidBadDebt.Equal(expectedBadDebt) {
return fmt.Errorf("expected prepaid bad debt to be %s, got %s", expectedBadDebt, market.PrepaidBadDebt)
}
Expand Down
8 changes: 4 additions & 4 deletions x/perp/v2/keeper/clearing_house.go
Original file line number Diff line number Diff line change
Expand Up @@ -540,14 +540,14 @@ func (k Keeper) afterPositionUpdate(
// transfer trader <=> vault
marginToVault := positionResp.MarginToVault.RoundInt()

collateralDenom, err := k.Collateral.Get(ctx)
collateral, err := k.Collateral.Get(ctx)
if errors.Is(err, collections.ErrNotFound) {
return types.ErrCollateralTokenFactoryDenomNotSet
}

switch {
case marginToVault.IsPositive():
coinToSend := sdk.NewCoin(collateralDenom.GetTFDenom(), marginToVault)
coinToSend := sdk.NewCoin(collateral.GetTFDenom(), marginToVault)
if err = k.BankKeeper.SendCoinsFromAccountToModule(
ctx, traderAddr, types.VaultModuleAccount, sdk.NewCoins(coinToSend)); err != nil {
return err
Expand Down Expand Up @@ -583,9 +583,9 @@ func (k Keeper) afterPositionUpdate(
&types.PositionChangedEvent{
FinalPosition: positionResp.Position,
PositionNotional: positionNotional,
TransactionFee: sdk.NewCoin(collateralDenom.GetTFDenom(), transferredFee),
TransactionFee: sdk.NewCoin(collateral.GetTFDenom(), transferredFee),
RealizedPnl: positionResp.RealizedPnl,
BadDebt: sdk.NewCoin(collateralDenom.GetTFDenom(), positionResp.BadDebt.RoundInt()),
BadDebt: sdk.NewCoin(collateral.GetTFDenom(), positionResp.BadDebt.RoundInt()),
FundingPayment: positionResp.FundingPayment,
BlockHeight: ctx.BlockHeight(),
MarginToUser: marginToVault.Neg().Sub(transferredFee),
Expand Down
8 changes: 4 additions & 4 deletions x/perp/v2/keeper/withdraw.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ func (k Keeper) WithdrawFromVault(
return nil
}

collateralDenom, err := k.Collateral.Get(ctx)
collateral, err := k.Collateral.Get(ctx)
if err != nil {
return err
}

vaultQuoteBalance := k.BankKeeper.GetBalance(
ctx,
k.AccountKeeper.GetModuleAddress(types.VaultModuleAccount),
collateralDenom.GetTFDenom(),
collateral.GetTFDenom(),
)
if vaultQuoteBalance.Amount.LT(amountToWithdraw) {
// if withdraw amount is larger than entire balance of vault
Expand All @@ -65,7 +65,7 @@ func (k Keeper) WithdrawFromVault(
types.PerpEFModuleAccount,
types.VaultModuleAccount,
sdk.NewCoins(
sdk.NewCoin(collateralDenom.GetTFDenom(), shortage),
sdk.NewCoin(collateral.GetTFDenom(), shortage),
),
); err != nil {
return err
Expand All @@ -78,7 +78,7 @@ func (k Keeper) WithdrawFromVault(
/* from */ types.VaultModuleAccount,
/* to */ receiver,
sdk.NewCoins(
sdk.NewCoin(collateralDenom.GetTFDenom(), amountToWithdraw),
sdk.NewCoin(collateral.GetTFDenom(), amountToWithdraw),
),
)
}
Expand Down
4 changes: 2 additions & 2 deletions x/perp/v2/types/collateral.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ var ErrInvalidCollateral = sdkerrors.Register("collateral", 1, "invalid token fa
// Default collateral used for testing only.
var DefaultTestingCollateralNotForProd = NewCollateral("cosmos15u3dt79t6sxxa3x3kpkhzsy56edaa5a66wvt3kxmukqjz2sx0hesh45zsv", "unusd")

func NewCollateral(contractAddress string, collateralDenom string) Collateral {
func NewCollateral(contractAddress string, collateral string) Collateral {
return Collateral{
ContractAddress: contractAddress,
Denom: collateralDenom,
Denom: collateral,
}
}

Expand Down

0 comments on commit f212a13

Please sign in to comment.