Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TRA-125] Update withdrawal gating to be per collateral pool. #1208

Merged
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,17 @@ export class LCDQueryClient {
if so which block they are re-enabled on. */


async getWithdrawalAndTransfersBlockedInfo(_params: QueryGetWithdrawalAndTransfersBlockedInfoRequest = {}): Promise<QueryGetWithdrawalAndTransfersBlockedInfoResponseSDKType> {
async getWithdrawalAndTransfersBlockedInfo(params: QueryGetWithdrawalAndTransfersBlockedInfoRequest): Promise<QueryGetWithdrawalAndTransfersBlockedInfoResponseSDKType> {
const options: any = {
params: {}
};

if (typeof params?.perpetualId !== "undefined") {
options.params.perpetual_id = params.perpetualId;
}

const endpoint = `dydxprotocol/subaccounts/withdrawals_and_transfers_blocked_info`;
return await this.req.get<QueryGetWithdrawalAndTransfersBlockedInfoResponseSDKType>(endpoint);
return await this.req.get<QueryGetWithdrawalAndTransfersBlockedInfoResponseSDKType>(endpoint, options);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export interface Query {
* if so which block they are re-enabled on.
*/

getWithdrawalAndTransfersBlockedInfo(request?: QueryGetWithdrawalAndTransfersBlockedInfoRequest): Promise<QueryGetWithdrawalAndTransfersBlockedInfoResponse>;
getWithdrawalAndTransfersBlockedInfo(request: QueryGetWithdrawalAndTransfersBlockedInfoRequest): Promise<QueryGetWithdrawalAndTransfersBlockedInfoResponse>;
}
export class QueryClientImpl implements Query {
private readonly rpc: Rpc;
Expand All @@ -41,7 +41,7 @@ export class QueryClientImpl implements Query {
return promise.then(data => QuerySubaccountAllResponse.decode(new _m0.Reader(data)));
}

getWithdrawalAndTransfersBlockedInfo(request: QueryGetWithdrawalAndTransfersBlockedInfoRequest = {}): Promise<QueryGetWithdrawalAndTransfersBlockedInfoResponse> {
getWithdrawalAndTransfersBlockedInfo(request: QueryGetWithdrawalAndTransfersBlockedInfoRequest): Promise<QueryGetWithdrawalAndTransfersBlockedInfoResponse> {
const data = QueryGetWithdrawalAndTransfersBlockedInfoRequest.encode(request).finish();
const promise = this.rpc.request("dydxprotocol.subaccounts.Query", "GetWithdrawalAndTransfersBlockedInfo", data);
return promise.then(data => QueryGetWithdrawalAndTransfersBlockedInfoResponse.decode(new _m0.Reader(data)));
Expand All @@ -60,7 +60,7 @@ export const createRpcQueryExtension = (base: QueryClient) => {
return queryService.subaccountAll(request);
},

getWithdrawalAndTransfersBlockedInfo(request?: QueryGetWithdrawalAndTransfersBlockedInfoRequest): Promise<QueryGetWithdrawalAndTransfersBlockedInfoResponse> {
getWithdrawalAndTransfersBlockedInfo(request: QueryGetWithdrawalAndTransfersBlockedInfoRequest): Promise<QueryGetWithdrawalAndTransfersBlockedInfoResponse> {
return queryService.getWithdrawalAndTransfersBlockedInfo(request);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,22 @@ export interface QuerySubaccountAllResponseSDKType {
}
/**
* QueryGetWithdrawalAndTransfersBlockedInfoRequest is a request type for
* fetching information about whether withdrawals and transfers are blocked.
* fetching information about whether withdrawals and transfers are blocked for
* a collateral pool associated with the passed in perpetual id.
*/

export interface QueryGetWithdrawalAndTransfersBlockedInfoRequest {}
export interface QueryGetWithdrawalAndTransfersBlockedInfoRequest {
perpetualId: number;
}
/**
* QueryGetWithdrawalAndTransfersBlockedInfoRequest is a request type for
* fetching information about whether withdrawals and transfers are blocked.
* fetching information about whether withdrawals and transfers are blocked for
* a collateral pool associated with the passed in perpetual id.
*/

export interface QueryGetWithdrawalAndTransfersBlockedInfoRequestSDKType {}
export interface QueryGetWithdrawalAndTransfersBlockedInfoRequestSDKType {
perpetual_id: number;
}
/**
* QueryGetWithdrawalAndTransfersBlockedInfoRequest is a response type for
* fetching information about whether withdrawals and transfers are blocked.
Expand Down Expand Up @@ -280,11 +286,17 @@ export const QuerySubaccountAllResponse = {
};

function createBaseQueryGetWithdrawalAndTransfersBlockedInfoRequest(): QueryGetWithdrawalAndTransfersBlockedInfoRequest {
return {};
return {
perpetualId: 0
};
}

export const QueryGetWithdrawalAndTransfersBlockedInfoRequest = {
encode(_: QueryGetWithdrawalAndTransfersBlockedInfoRequest, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {
encode(message: QueryGetWithdrawalAndTransfersBlockedInfoRequest, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {
if (message.perpetualId !== 0) {
writer.uint32(8).uint32(message.perpetualId);
}

return writer;
},

Expand All @@ -297,6 +309,10 @@ export const QueryGetWithdrawalAndTransfersBlockedInfoRequest = {
const tag = reader.uint32();

switch (tag >>> 3) {
case 1:
message.perpetualId = reader.uint32();
break;

default:
reader.skipType(tag & 7);
break;
Expand All @@ -306,8 +322,9 @@ export const QueryGetWithdrawalAndTransfersBlockedInfoRequest = {
return message;
},

fromPartial(_: DeepPartial<QueryGetWithdrawalAndTransfersBlockedInfoRequest>): QueryGetWithdrawalAndTransfersBlockedInfoRequest {
fromPartial(object: DeepPartial<QueryGetWithdrawalAndTransfersBlockedInfoRequest>): QueryGetWithdrawalAndTransfersBlockedInfoRequest {
const message = createBaseQueryGetWithdrawalAndTransfersBlockedInfoRequest();
message.perpetualId = object.perpetualId ?? 0;
return message;
}

Expand Down
7 changes: 5 additions & 2 deletions proto/dydxprotocol/subaccounts/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,11 @@ message QuerySubaccountAllResponse {
}

// QueryGetWithdrawalAndTransfersBlockedInfoRequest is a request type for
// fetching information about whether withdrawals and transfers are blocked.
message QueryGetWithdrawalAndTransfersBlockedInfoRequest {}
// fetching information about whether withdrawals and transfers are blocked for
// a collateral pool associated with the passed in perpetual id.
message QueryGetWithdrawalAndTransfersBlockedInfoRequest {
uint32 perpetual_id = 1;
}

// QueryGetWithdrawalAndTransfersBlockedInfoRequest is a response type for
// fetching information about whether withdrawals and transfers are blocked.
Expand Down
6 changes: 6 additions & 0 deletions protocol/testutil/constants/addresses.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package constants

import (
sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
satypes "github.com/dydxprotocol/v4-chain/protocol/x/subaccounts/types"
)

var (
Expand All @@ -17,4 +19,8 @@ var (
BobConsAddress = sdk.ConsAddress(BobPrivateKey.PubKey().Address())
CarlConsAddress = sdk.ConsAddress(CarlPrivateKey.PubKey().Address())
DaveConsAddress = sdk.ConsAddress(DavePrivateKey.PubKey().Address())

// Collateral pool addresses for isolated perpetuals.
IsoCollateralPoolAddress = authtypes.NewModuleAddress(satypes.ModuleName + ":3")
Iso2CollateralPoolAddress = authtypes.NewModuleAddress(satypes.ModuleName + ":4")
)
36 changes: 36 additions & 0 deletions protocol/testutil/constants/clob_pair.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,40 @@ var (
QuantumConversionExponent: -8,
Status: clobtypes.ClobPair_STATUS_PAUSED,
}
ClobPair_3_Iso = clobtypes.ClobPair{
Id: 3,
Metadata: &clobtypes.ClobPair_PerpetualClobMetadata{
PerpetualClobMetadata: &clobtypes.PerpetualClobMetadata{
PerpetualId: 3,
},
},
StepBaseQuantums: 5,
SubticksPerTick: 5,
QuantumConversionExponent: -8,
Status: clobtypes.ClobPair_STATUS_ACTIVE,
}
ClobPair_3_Iso_Final_Settlement = clobtypes.ClobPair{
Id: 3,
Metadata: &clobtypes.ClobPair_PerpetualClobMetadata{
PerpetualClobMetadata: &clobtypes.PerpetualClobMetadata{
PerpetualId: 3,
},
},
StepBaseQuantums: 5,
SubticksPerTick: 5,
QuantumConversionExponent: -8,
Status: clobtypes.ClobPair_STATUS_FINAL_SETTLEMENT,
}
ClobPair_4_Iso2 = clobtypes.ClobPair{
Id: 4,
Metadata: &clobtypes.ClobPair_PerpetualClobMetadata{
PerpetualClobMetadata: &clobtypes.PerpetualClobMetadata{
PerpetualId: 4,
},
},
StepBaseQuantums: 5,
SubticksPerTick: 5,
QuantumConversionExponent: -8,
Status: clobtypes.ClobPair_STATUS_ACTIVE,
}
)
32 changes: 32 additions & 0 deletions protocol/testutil/constants/subaccounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,22 @@ var (
},
},
}
Carl_Num0_1ISO_Short_49USD = satypes.Subaccount{
Id: &Carl_Num0,
AssetPositions: []*satypes.AssetPosition{
{
AssetId: 0,
Quantums: dtypes.NewInt(49_000_000), // $49
},
},
PerpetualPositions: []*satypes.PerpetualPosition{
{
PerpetualId: 3,
Quantums: dtypes.NewInt(-1_000_000_000), // -1 ISO
FundingIndex: dtypes.NewInt(0),
},
},
}
Carl_Num0_599USD = satypes.Subaccount{
Id: &Carl_Num0,
AssetPositions: []*satypes.AssetPosition{
Expand Down Expand Up @@ -518,6 +534,22 @@ var (
},
},
}
Dave_Num0_1ISO2_Short_499USD = satypes.Subaccount{
Id: &Dave_Num0,
AssetPositions: []*satypes.AssetPosition{
{
AssetId: 0,
Quantums: dtypes.NewInt(499_000_000), // $499
},
},
PerpetualPositions: []*satypes.PerpetualPosition{
{
PerpetualId: 4,
Quantums: dtypes.NewInt(-10_000_000), // -1 ISO2
FundingIndex: dtypes.NewInt(0),
},
},
}
Dave_Num0_599USD = satypes.Subaccount{
Id: &Dave_Num0,
AssetPositions: []*satypes.AssetPosition{
Expand Down
6 changes: 5 additions & 1 deletion protocol/x/clob/e2e/withdrawal_gating_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,11 @@ func TestWithdrawalGating_NegativeTncSubaccount_BlocksThenUnblocks(t *testing.T)
tApp.App.SubaccountsKeeper.GetSubaccount(ctx, *expectedSubaccount.Id),
)
}
negativeTncSubaccountSeenAtBlock, exists := tApp.App.SubaccountsKeeper.GetNegativeTncSubaccountSeenAtBlock(ctx)
negativeTncSubaccountSeenAtBlock, exists, err := tApp.App.SubaccountsKeeper.GetNegativeTncSubaccountSeenAtBlock(
ctx,
constants.BtcUsd_NoMarginRequirement.Params.Id,
)
require.NoError(t, err)
require.Equal(t, tc.expectedWithdrawalsGated, exists)
require.Equal(t, tc.expectedNegativeTncSubaccountSeenAtBlock, negativeTncSubaccountSeenAtBlock)

Expand Down
8 changes: 7 additions & 1 deletion protocol/x/clob/keeper/process_operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -694,7 +694,13 @@ func (k Keeper) PersistMatchDeleveragingToState(
metrics.GetLabelForBoolValue(metrics.IsLong, position.GetIsLong()),
metrics.GetLabelForBoolValue(metrics.DeliverTx, true),
)
k.subaccountsKeeper.SetNegativeTncSubaccountSeenAtBlock(ctx, lib.MustConvertIntegerToUint32(ctx.BlockHeight()))
if err = k.subaccountsKeeper.SetNegativeTncSubaccountSeenAtBlock(
ctx,
perpetualId,
lib.MustConvertIntegerToUint32(ctx.BlockHeight()),
); err != nil {
return err
}
return nil
}

Expand Down
Loading
Loading