Skip to content

Commit

Permalink
remove unused code
Browse files Browse the repository at this point in the history
Signed-off-by: Shrenuj Bansal <[email protected]>
  • Loading branch information
shrenujb committed Jun 25, 2024
1 parent 0292c2b commit 2fbcffa
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 73 deletions.
11 changes: 10 additions & 1 deletion protocol/testutil/keeper/subaccounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,16 @@ func SubaccountsKeepers(t testing.TB, msgSenderEnabled bool) (
// Mock time provider response for market creation.
mockTimeProvider.On("Now").Return(constants.TimeT)

return ctx, keeper, pricesKeeper, perpetualsKeeper, accountKeeper, bankKeeper, assetsKeeper, blocktimeKeeper, revShareKeeper, storeKey
return ctx,
keeper,
pricesKeeper,
perpetualsKeeper,
accountKeeper,
bankKeeper,
assetsKeeper,
blocktimeKeeper,
revShareKeeper,
storeKey
}

func createSubaccountsKeeper(
Expand Down
18 changes: 1 addition & 17 deletions protocol/x/clob/keeper/process_single_match.go
Original file line number Diff line number Diff line change
Expand Up @@ -434,24 +434,8 @@ func (k Keeper) persistMatchedOrders(
return takerUpdateResult, makerUpdateResult, err
}

// Transfer the fee amount from subacounts module to fee collector module account.
// Distribute the fee amount from subacounts module to fee collector and rev share accounts
bigTotalFeeQuoteQuantums := new(big.Int).Add(bigTakerFeeQuoteQuantums, bigMakerFeeQuoteQuantums)
//if err := k.subaccountsKeeper.TransferFeesToFeeCollectorModule(
// ctx,
// assettypes.AssetUsdc.Id,
// bigTotalFeeQuoteQuantums,
// perpetualId,
//); err != nil {
// return takerUpdateResult, makerUpdateResult, errorsmod.Wrapf(
// types.ErrSubaccountFeeTransferFailed,
// "persistMatchedOrders: subaccounts (%v, %v) updated, but fee transfer (bigFeeQuoteQuantums: %v)"+
// " to fee-collector failed. Err: %v",
// matchWithOrders.MakerOrder.GetSubaccountId(),
// matchWithOrders.TakerOrder.GetSubaccountId(),
// bigTotalFeeQuoteQuantums,
// err,
// )
//}
if err := k.subaccountsKeeper.DistributeFees(
ctx,
assettypes.AssetUsdc.Id,
Expand Down
53 changes: 0 additions & 53 deletions protocol/x/subaccounts/keeper/transfer.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,59 +316,6 @@ func (k Keeper) TransferFees(
return nil
}

// TransferFeesToFeeCollectorModule translates the assetId and quantums into a sdk.Coin,
// and moves the funds from subaccounts module to the `fee_collector` module account by calling
// bankKeeper.SendCoins(). Does not change any individual subaccount state.
func (k Keeper) TransferFeesToFeeCollectorModule(
ctx sdk.Context,
assetId uint32,
quantums *big.Int,
perpetualId uint32,
) error {
// TODO(DEC-715): Support non-USDC assets.
if assetId != assettypes.AssetUsdc.Id {
return types.ErrAssetTransferThroughBankNotImplemented
}

if quantums.Sign() == 0 {
return nil
}

_, coinToTransfer, err := k.assetsKeeper.ConvertAssetToCoin(
ctx,
assetId,
new(big.Int).Abs(quantums),
)
if err != nil {
return err
}

collateralPoolAddr, err := k.GetCollateralPoolFromPerpetualId(ctx, perpetualId)
if err != nil {
return err
}

// Send coins from `subaccounts` to the `auth` module fee collector account.
fromModuleAddr := collateralPoolAddr
toModuleAddr := authtypes.NewModuleAddress(authtypes.FeeCollectorName)

if quantums.Sign() < 0 {
// In the case of a liquidation, net fees can be negative if the maker gets a rebate.
fromModuleAddr, toModuleAddr = toModuleAddr, fromModuleAddr
}

if err := k.bankKeeper.SendCoins(
ctx,
fromModuleAddr,
toModuleAddr,
[]sdk.Coin{coinToTransfer},
); err != nil {
return err
}

return nil
}

// TransferInsuranceFundPayments transfers funds in and out of the insurance fund to the subaccounts
// module by calling `bankKeeper.SendCoins`.
// This function transfers funds
Expand Down
4 changes: 2 additions & 2 deletions protocol/x/subaccounts/keeper/transfer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1168,7 +1168,7 @@ func TestTransferFundsFromSubaccountToSubaccount_Failure(t *testing.T) {
}
}

func TestTransferFeesToFeeCollectorModule(t *testing.T) {
func TestDistributeFees(t *testing.T) {
tests := map[string]struct {
skipSetUpUsdc bool

Expand Down Expand Up @@ -1452,7 +1452,7 @@ func TestTransferFeesToFeeCollectorModule(t *testing.T) {
}

// Check the subaccount module balance.
subaccountsModuleAccBalance = bankKeeper.GetBalance(ctx, tc.collateralPoolAddr, tc.asset.Denom)
subaccountsModuleAccBalance := bankKeeper.GetBalance(ctx, tc.collateralPoolAddr, tc.asset.Denom)
require.Equal(t,
sdk.NewCoin(tc.asset.Denom, sdkmath.NewIntFromBigInt(tc.expectedSubaccountsModuleAccBalance)),
subaccountsModuleAccBalance,
Expand Down

0 comments on commit 2fbcffa

Please sign in to comment.