diff --git a/indexer/packages/v4-protos/src/codegen/dydxprotocol/subaccounts/query.lcd.ts b/indexer/packages/v4-protos/src/codegen/dydxprotocol/subaccounts/query.lcd.ts index a839f3ee2f..93d034a144 100644 --- a/indexer/packages/v4-protos/src/codegen/dydxprotocol/subaccounts/query.lcd.ts +++ b/indexer/packages/v4-protos/src/codegen/dydxprotocol/subaccounts/query.lcd.ts @@ -1,6 +1,6 @@ import { setPaginationParams } from "../../helpers"; import { LCDClient } from "@osmonauts/lcd"; -import { QueryGetSubaccountRequest, QuerySubaccountResponseSDKType, QueryAllSubaccountRequest, QuerySubaccountAllResponseSDKType } from "./query"; +import { QueryGetSubaccountRequest, QuerySubaccountResponseSDKType, QueryAllSubaccountRequest, QuerySubaccountAllResponseSDKType, QueryGetWithdrawalAndTransfersBlockedInfoRequest, QueryGetWithdrawalAndTransfersBlockedInfoResponseSDKType } from "./query"; export class LCDQueryClient { req: LCDClient; @@ -12,6 +12,7 @@ export class LCDQueryClient { this.req = requestClient; this.subaccount = this.subaccount.bind(this); this.subaccountAll = this.subaccountAll.bind(this); + this.getWithdrawalAndTransfersBlockedInfo = this.getWithdrawalAndTransfersBlockedInfo.bind(this); } /* Queries a Subaccount by id */ @@ -37,5 +38,13 @@ export class LCDQueryClient { const endpoint = `dydxprotocol/subaccounts/subaccount`; return await this.req.get(endpoint, options); } + /* Queries information about whether withdrawal and transfers are blocked, and + if so which block they are re-enabled on. */ + + + async getWithdrawalAndTransfersBlockedInfo(_params: QueryGetWithdrawalAndTransfersBlockedInfoRequest = {}): Promise { + const endpoint = `dydxprotocol/subaccounts/withdrawals_and_transfers_blocked_info`; + return await this.req.get(endpoint); + } } \ No newline at end of file diff --git a/indexer/packages/v4-protos/src/codegen/dydxprotocol/subaccounts/query.rpc.Query.ts b/indexer/packages/v4-protos/src/codegen/dydxprotocol/subaccounts/query.rpc.Query.ts index 274c97443a..41f65d7652 100644 --- a/indexer/packages/v4-protos/src/codegen/dydxprotocol/subaccounts/query.rpc.Query.ts +++ b/indexer/packages/v4-protos/src/codegen/dydxprotocol/subaccounts/query.rpc.Query.ts @@ -1,7 +1,7 @@ import { Rpc } from "../../helpers"; import * as _m0 from "protobufjs/minimal"; import { QueryClient, createProtobufRpcClient } from "@cosmjs/stargate"; -import { QueryGetSubaccountRequest, QuerySubaccountResponse, QueryAllSubaccountRequest, QuerySubaccountAllResponse } from "./query"; +import { QueryGetSubaccountRequest, QuerySubaccountResponse, QueryAllSubaccountRequest, QuerySubaccountAllResponse, QueryGetWithdrawalAndTransfersBlockedInfoRequest, QueryGetWithdrawalAndTransfersBlockedInfoResponse } from "./query"; /** Query defines the gRPC querier service. */ export interface Query { @@ -10,6 +10,12 @@ export interface Query { /** Queries a list of Subaccount items. */ subaccountAll(request?: QueryAllSubaccountRequest): Promise; + /** + * Queries information about whether withdrawal and transfers are blocked, and + * if so which block they are re-enabled on. + */ + + getWithdrawalAndTransfersBlockedInfo(request?: QueryGetWithdrawalAndTransfersBlockedInfoRequest): Promise; } export class QueryClientImpl implements Query { private readonly rpc: Rpc; @@ -18,6 +24,7 @@ export class QueryClientImpl implements Query { this.rpc = rpc; this.subaccount = this.subaccount.bind(this); this.subaccountAll = this.subaccountAll.bind(this); + this.getWithdrawalAndTransfersBlockedInfo = this.getWithdrawalAndTransfersBlockedInfo.bind(this); } subaccount(request: QueryGetSubaccountRequest): Promise { @@ -34,6 +41,12 @@ export class QueryClientImpl implements Query { return promise.then(data => QuerySubaccountAllResponse.decode(new _m0.Reader(data))); } + getWithdrawalAndTransfersBlockedInfo(request: QueryGetWithdrawalAndTransfersBlockedInfoRequest = {}): Promise { + 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))); + } + } export const createRpcQueryExtension = (base: QueryClient) => { const rpc = createProtobufRpcClient(base); @@ -45,6 +58,10 @@ export const createRpcQueryExtension = (base: QueryClient) => { subaccountAll(request?: QueryAllSubaccountRequest): Promise { return queryService.subaccountAll(request); + }, + + getWithdrawalAndTransfersBlockedInfo(request?: QueryGetWithdrawalAndTransfersBlockedInfoRequest): Promise { + return queryService.getWithdrawalAndTransfersBlockedInfo(request); } }; diff --git a/indexer/packages/v4-protos/src/codegen/dydxprotocol/subaccounts/query.ts b/indexer/packages/v4-protos/src/codegen/dydxprotocol/subaccounts/query.ts index 34f103f823..0b1d182ed9 100644 --- a/indexer/packages/v4-protos/src/codegen/dydxprotocol/subaccounts/query.ts +++ b/indexer/packages/v4-protos/src/codegen/dydxprotocol/subaccounts/query.ts @@ -46,6 +46,38 @@ export interface QuerySubaccountAllResponseSDKType { subaccount: SubaccountSDKType[]; pagination?: PageResponseSDKType; } +/** + * QueryGetWithdrawalAndTransfersBlockedInfoRequest is a request type for + * fetching information about whether withdrawals and transfers are blocked. + */ + +export interface QueryGetWithdrawalAndTransfersBlockedInfoRequest {} +/** + * QueryGetWithdrawalAndTransfersBlockedInfoRequest is a request type for + * fetching information about whether withdrawals and transfers are blocked. + */ + +export interface QueryGetWithdrawalAndTransfersBlockedInfoRequestSDKType {} +/** + * QueryGetWithdrawalAndTransfersBlockedInfoRequest is a response type for + * fetching information about whether withdrawals and transfers are blocked. + */ + +export interface QueryGetWithdrawalAndTransfersBlockedInfoResponse { + negativeTncSubaccountSeenAtBlock: number; + chainOutageSeenAtBlock: number; + withdrawalsAndTransfersUnblockedAtBlock: number; +} +/** + * QueryGetWithdrawalAndTransfersBlockedInfoRequest is a response type for + * fetching information about whether withdrawals and transfers are blocked. + */ + +export interface QueryGetWithdrawalAndTransfersBlockedInfoResponseSDKType { + negative_tnc_subaccount_seen_at_block: number; + chain_outage_seen_at_block: number; + withdrawals_and_transfers_unblocked_at_block: number; +} function createBaseQueryGetSubaccountRequest(): QueryGetSubaccountRequest { return { @@ -245,4 +277,103 @@ export const QuerySubaccountAllResponse = { return message; } +}; + +function createBaseQueryGetWithdrawalAndTransfersBlockedInfoRequest(): QueryGetWithdrawalAndTransfersBlockedInfoRequest { + return {}; +} + +export const QueryGetWithdrawalAndTransfersBlockedInfoRequest = { + encode(_: QueryGetWithdrawalAndTransfersBlockedInfoRequest, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): QueryGetWithdrawalAndTransfersBlockedInfoRequest { + const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); + let end = length === undefined ? reader.len : reader.pos + length; + const message = createBaseQueryGetWithdrawalAndTransfersBlockedInfoRequest(); + + while (reader.pos < end) { + const tag = reader.uint32(); + + switch (tag >>> 3) { + default: + reader.skipType(tag & 7); + break; + } + } + + return message; + }, + + fromPartial(_: DeepPartial): QueryGetWithdrawalAndTransfersBlockedInfoRequest { + const message = createBaseQueryGetWithdrawalAndTransfersBlockedInfoRequest(); + return message; + } + +}; + +function createBaseQueryGetWithdrawalAndTransfersBlockedInfoResponse(): QueryGetWithdrawalAndTransfersBlockedInfoResponse { + return { + negativeTncSubaccountSeenAtBlock: 0, + chainOutageSeenAtBlock: 0, + withdrawalsAndTransfersUnblockedAtBlock: 0 + }; +} + +export const QueryGetWithdrawalAndTransfersBlockedInfoResponse = { + encode(message: QueryGetWithdrawalAndTransfersBlockedInfoResponse, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + if (message.negativeTncSubaccountSeenAtBlock !== 0) { + writer.uint32(8).uint32(message.negativeTncSubaccountSeenAtBlock); + } + + if (message.chainOutageSeenAtBlock !== 0) { + writer.uint32(16).uint32(message.chainOutageSeenAtBlock); + } + + if (message.withdrawalsAndTransfersUnblockedAtBlock !== 0) { + writer.uint32(24).uint32(message.withdrawalsAndTransfersUnblockedAtBlock); + } + + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): QueryGetWithdrawalAndTransfersBlockedInfoResponse { + const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); + let end = length === undefined ? reader.len : reader.pos + length; + const message = createBaseQueryGetWithdrawalAndTransfersBlockedInfoResponse(); + + while (reader.pos < end) { + const tag = reader.uint32(); + + switch (tag >>> 3) { + case 1: + message.negativeTncSubaccountSeenAtBlock = reader.uint32(); + break; + + case 2: + message.chainOutageSeenAtBlock = reader.uint32(); + break; + + case 3: + message.withdrawalsAndTransfersUnblockedAtBlock = reader.uint32(); + break; + + default: + reader.skipType(tag & 7); + break; + } + } + + return message; + }, + + fromPartial(object: DeepPartial): QueryGetWithdrawalAndTransfersBlockedInfoResponse { + const message = createBaseQueryGetWithdrawalAndTransfersBlockedInfoResponse(); + message.negativeTncSubaccountSeenAtBlock = object.negativeTncSubaccountSeenAtBlock ?? 0; + message.chainOutageSeenAtBlock = object.chainOutageSeenAtBlock ?? 0; + message.withdrawalsAndTransfersUnblockedAtBlock = object.withdrawalsAndTransfersUnblockedAtBlock ?? 0; + return message; + } + }; \ No newline at end of file diff --git a/proto/dydxprotocol/subaccounts/query.proto b/proto/dydxprotocol/subaccounts/query.proto index 8e70497a5d..740d50977a 100644 --- a/proto/dydxprotocol/subaccounts/query.proto +++ b/proto/dydxprotocol/subaccounts/query.proto @@ -22,6 +22,15 @@ service Query { returns (QuerySubaccountAllResponse) { option (google.api.http).get = "/dydxprotocol/subaccounts/subaccount"; } + + // Queries information about whether withdrawal and transfers are blocked, and + // if so which block they are re-enabled on. + rpc GetWithdrawalAndTransfersBlockedInfo( + QueryGetWithdrawalAndTransfersBlockedInfoRequest) + returns (QueryGetWithdrawalAndTransfersBlockedInfoResponse) { + option (google.api.http).get = + "/dydxprotocol/subaccounts/withdrawals_and_transfers_blocked_info"; + } } // QueryGetSubaccountRequest is request type for the Query RPC method. @@ -45,3 +54,15 @@ message QuerySubaccountAllResponse { repeated Subaccount subaccount = 1 [ (gogoproto.nullable) = false ]; cosmos.base.query.v1beta1.PageResponse pagination = 2; } + +// QueryGetWithdrawalAndTransfersBlockedInfoRequest is a request type for +// fetching information about whether withdrawals and transfers are blocked. +message QueryGetWithdrawalAndTransfersBlockedInfoRequest {} + +// QueryGetWithdrawalAndTransfersBlockedInfoRequest is a response type for +// fetching information about whether withdrawals and transfers are blocked. +message QueryGetWithdrawalAndTransfersBlockedInfoResponse { + uint32 negative_tnc_subaccount_seen_at_block = 1; + uint32 chain_outage_seen_at_block = 2; + uint32 withdrawals_and_transfers_unblocked_at_block = 3; +} diff --git a/protocol/mocks/MemClob.go b/protocol/mocks/MemClob.go index c1d596b5c9..48da388ea0 100644 --- a/protocol/mocks/MemClob.go +++ b/protocol/mocks/MemClob.go @@ -25,6 +25,10 @@ func (_m *MemClob) CancelOrder(ctx types.Context, msgCancelOrder *clobtypes.MsgC ret := _m.Called(ctx, msgCancelOrder) var r0 *clobtypes.OffchainUpdates + var r1 error + if rf, ok := ret.Get(0).(func(types.Context, *clobtypes.MsgCancelOrder) (*clobtypes.OffchainUpdates, error)); ok { + return rf(ctx, msgCancelOrder) + } if rf, ok := ret.Get(0).(func(types.Context, *clobtypes.MsgCancelOrder) *clobtypes.OffchainUpdates); ok { r0 = rf(ctx, msgCancelOrder) } else { @@ -33,7 +37,6 @@ func (_m *MemClob) CancelOrder(ctx types.Context, msgCancelOrder *clobtypes.MsgC } } - var r1 error if rf, ok := ret.Get(1).(func(types.Context, *clobtypes.MsgCancelOrder) error); ok { r1 = rf(ctx, msgCancelOrder) } else { @@ -67,6 +70,10 @@ func (_m *MemClob) DeleverageSubaccount(ctx types.Context, subaccountId subaccou ret := _m.Called(ctx, subaccountId, perpetualId, deltaQuantums, isFinalSettlement) var r0 *big.Int + var r1 error + if rf, ok := ret.Get(0).(func(types.Context, subaccountstypes.SubaccountId, uint32, *big.Int, bool) (*big.Int, error)); ok { + return rf(ctx, subaccountId, perpetualId, deltaQuantums, isFinalSettlement) + } if rf, ok := ret.Get(0).(func(types.Context, subaccountstypes.SubaccountId, uint32, *big.Int, bool) *big.Int); ok { r0 = rf(ctx, subaccountId, perpetualId, deltaQuantums, isFinalSettlement) } else { @@ -75,7 +82,6 @@ func (_m *MemClob) DeleverageSubaccount(ctx types.Context, subaccountId subaccou } } - var r1 error if rf, ok := ret.Get(1).(func(types.Context, subaccountstypes.SubaccountId, uint32, *big.Int, bool) error); ok { r1 = rf(ctx, subaccountId, perpetualId, deltaQuantums, isFinalSettlement) } else { @@ -90,13 +96,16 @@ func (_m *MemClob) GetCancelOrder(ctx types.Context, orderId clobtypes.OrderId) ret := _m.Called(ctx, orderId) var r0 uint32 + var r1 bool + if rf, ok := ret.Get(0).(func(types.Context, clobtypes.OrderId) (uint32, bool)); ok { + return rf(ctx, orderId) + } if rf, ok := ret.Get(0).(func(types.Context, clobtypes.OrderId) uint32); ok { r0 = rf(ctx, orderId) } else { r0 = ret.Get(0).(uint32) } - var r1 bool if rf, ok := ret.Get(1).(func(types.Context, clobtypes.OrderId) bool); ok { r1 = rf(ctx, orderId) } else { @@ -111,27 +120,30 @@ func (_m *MemClob) GetMidPrice(ctx types.Context, clobPairId clobtypes.ClobPairI ret := _m.Called(ctx, clobPairId) var r0 clobtypes.Subticks + var r1 clobtypes.Order + var r2 clobtypes.Order + var r3 bool + if rf, ok := ret.Get(0).(func(types.Context, clobtypes.ClobPairId) (clobtypes.Subticks, clobtypes.Order, clobtypes.Order, bool)); ok { + return rf(ctx, clobPairId) + } if rf, ok := ret.Get(0).(func(types.Context, clobtypes.ClobPairId) clobtypes.Subticks); ok { r0 = rf(ctx, clobPairId) } else { r0 = ret.Get(0).(clobtypes.Subticks) } - var r1 clobtypes.Order if rf, ok := ret.Get(1).(func(types.Context, clobtypes.ClobPairId) clobtypes.Order); ok { r1 = rf(ctx, clobPairId) } else { r1 = ret.Get(1).(clobtypes.Order) } - var r2 clobtypes.Order if rf, ok := ret.Get(2).(func(types.Context, clobtypes.ClobPairId) clobtypes.Order); ok { r2 = rf(ctx, clobPairId) } else { r2 = ret.Get(2).(clobtypes.Order) } - var r3 bool if rf, ok := ret.Get(3).(func(types.Context, clobtypes.ClobPairId) bool); ok { r3 = rf(ctx, clobPairId) } else { @@ -162,6 +174,10 @@ func (_m *MemClob) GetOperationsToReplay(ctx types.Context) ([]clobtypes.Interna ret := _m.Called(ctx) var r0 []clobtypes.InternalOperation + var r1 map[clobtypes.OrderHash][]byte + if rf, ok := ret.Get(0).(func(types.Context) ([]clobtypes.InternalOperation, map[clobtypes.OrderHash][]byte)); ok { + return rf(ctx) + } if rf, ok := ret.Get(0).(func(types.Context) []clobtypes.InternalOperation); ok { r0 = rf(ctx) } else { @@ -170,7 +186,6 @@ func (_m *MemClob) GetOperationsToReplay(ctx types.Context) ([]clobtypes.Interna } } - var r1 map[clobtypes.OrderHash][]byte if rf, ok := ret.Get(1).(func(types.Context) map[clobtypes.OrderHash][]byte); ok { r1 = rf(ctx) } else { @@ -187,13 +202,16 @@ func (_m *MemClob) GetOrder(ctx types.Context, orderId clobtypes.OrderId) (clobt ret := _m.Called(ctx, orderId) var r0 clobtypes.Order + var r1 bool + if rf, ok := ret.Get(0).(func(types.Context, clobtypes.OrderId) (clobtypes.Order, bool)); ok { + return rf(ctx, orderId) + } if rf, ok := ret.Get(0).(func(types.Context, clobtypes.OrderId) clobtypes.Order); ok { r0 = rf(ctx, orderId) } else { r0 = ret.Get(0).(clobtypes.Order) } - var r1 bool if rf, ok := ret.Get(1).(func(types.Context, clobtypes.OrderId) bool); ok { r1 = rf(ctx, orderId) } else { @@ -222,13 +240,16 @@ func (_m *MemClob) GetOrderRemainingAmount(ctx types.Context, order clobtypes.Or ret := _m.Called(ctx, order) var r0 subaccountstypes.BaseQuantums + var r1 bool + if rf, ok := ret.Get(0).(func(types.Context, clobtypes.Order) (subaccountstypes.BaseQuantums, bool)); ok { + return rf(ctx, order) + } if rf, ok := ret.Get(0).(func(types.Context, clobtypes.Order) subaccountstypes.BaseQuantums); ok { r0 = rf(ctx, order) } else { r0 = ret.Get(0).(subaccountstypes.BaseQuantums) } - var r1 bool if rf, ok := ret.Get(1).(func(types.Context, clobtypes.Order) bool); ok { r1 = rf(ctx, order) } else { @@ -243,13 +264,16 @@ func (_m *MemClob) GetPricePremium(ctx types.Context, clobPair clobtypes.ClobPai ret := _m.Called(ctx, clobPair, params) var r0 int32 + var r1 error + if rf, ok := ret.Get(0).(func(types.Context, clobtypes.ClobPair, perpetualstypes.GetPricePremiumParams) (int32, error)); ok { + return rf(ctx, clobPair, params) + } if rf, ok := ret.Get(0).(func(types.Context, clobtypes.ClobPair, perpetualstypes.GetPricePremiumParams) int32); ok { r0 = rf(ctx, clobPair, params) } else { r0 = ret.Get(0).(int32) } - var r1 error if rf, ok := ret.Get(1).(func(types.Context, clobtypes.ClobPair, perpetualstypes.GetPricePremiumParams) error); ok { r1 = rf(ctx, clobPair, params) } else { @@ -264,6 +288,10 @@ func (_m *MemClob) GetSubaccountOrders(ctx types.Context, clobPairId clobtypes.C ret := _m.Called(ctx, clobPairId, subaccountId, side) var r0 []clobtypes.Order + var r1 error + if rf, ok := ret.Get(0).(func(types.Context, clobtypes.ClobPairId, subaccountstypes.SubaccountId, clobtypes.Order_Side) ([]clobtypes.Order, error)); ok { + return rf(ctx, clobPairId, subaccountId, side) + } if rf, ok := ret.Get(0).(func(types.Context, clobtypes.ClobPairId, subaccountstypes.SubaccountId, clobtypes.Order_Side) []clobtypes.Order); ok { r0 = rf(ctx, clobPairId, subaccountId, side) } else { @@ -272,7 +300,6 @@ func (_m *MemClob) GetSubaccountOrders(ctx types.Context, clobPairId clobtypes.C } } - var r1 error if rf, ok := ret.Get(1).(func(types.Context, clobtypes.ClobPairId, subaccountstypes.SubaccountId, clobtypes.Order_Side) error); ok { r1 = rf(ctx, clobPairId, subaccountId, side) } else { @@ -292,20 +319,24 @@ func (_m *MemClob) PlaceOrder(ctx types.Context, order clobtypes.Order) (subacco ret := _m.Called(ctx, order) var r0 subaccountstypes.BaseQuantums + var r1 clobtypes.OrderStatus + var r2 *clobtypes.OffchainUpdates + var r3 error + if rf, ok := ret.Get(0).(func(types.Context, clobtypes.Order) (subaccountstypes.BaseQuantums, clobtypes.OrderStatus, *clobtypes.OffchainUpdates, error)); ok { + return rf(ctx, order) + } if rf, ok := ret.Get(0).(func(types.Context, clobtypes.Order) subaccountstypes.BaseQuantums); ok { r0 = rf(ctx, order) } else { r0 = ret.Get(0).(subaccountstypes.BaseQuantums) } - var r1 clobtypes.OrderStatus if rf, ok := ret.Get(1).(func(types.Context, clobtypes.Order) clobtypes.OrderStatus); ok { r1 = rf(ctx, order) } else { r1 = ret.Get(1).(clobtypes.OrderStatus) } - var r2 *clobtypes.OffchainUpdates if rf, ok := ret.Get(2).(func(types.Context, clobtypes.Order) *clobtypes.OffchainUpdates); ok { r2 = rf(ctx, order) } else { @@ -314,7 +345,6 @@ func (_m *MemClob) PlaceOrder(ctx types.Context, order clobtypes.Order) (subacco } } - var r3 error if rf, ok := ret.Get(3).(func(types.Context, clobtypes.Order) error); ok { r3 = rf(ctx, order) } else { @@ -329,20 +359,24 @@ func (_m *MemClob) PlacePerpetualLiquidation(ctx types.Context, liquidationOrder ret := _m.Called(ctx, liquidationOrder) var r0 subaccountstypes.BaseQuantums + var r1 clobtypes.OrderStatus + var r2 *clobtypes.OffchainUpdates + var r3 error + if rf, ok := ret.Get(0).(func(types.Context, clobtypes.LiquidationOrder) (subaccountstypes.BaseQuantums, clobtypes.OrderStatus, *clobtypes.OffchainUpdates, error)); ok { + return rf(ctx, liquidationOrder) + } if rf, ok := ret.Get(0).(func(types.Context, clobtypes.LiquidationOrder) subaccountstypes.BaseQuantums); ok { r0 = rf(ctx, liquidationOrder) } else { r0 = ret.Get(0).(subaccountstypes.BaseQuantums) } - var r1 clobtypes.OrderStatus if rf, ok := ret.Get(1).(func(types.Context, clobtypes.LiquidationOrder) clobtypes.OrderStatus); ok { r1 = rf(ctx, liquidationOrder) } else { r1 = ret.Get(1).(clobtypes.OrderStatus) } - var r2 *clobtypes.OffchainUpdates if rf, ok := ret.Get(2).(func(types.Context, clobtypes.LiquidationOrder) *clobtypes.OffchainUpdates); ok { r2 = rf(ctx, liquidationOrder) } else { @@ -351,7 +385,6 @@ func (_m *MemClob) PlacePerpetualLiquidation(ctx types.Context, liquidationOrder } } - var r3 error if rf, ok := ret.Get(3).(func(types.Context, clobtypes.LiquidationOrder) error); ok { r3 = rf(ctx, liquidationOrder) } else { diff --git a/protocol/mocks/MemClobKeeper.go b/protocol/mocks/MemClobKeeper.go index 537e3375c1..43666914f1 100644 --- a/protocol/mocks/MemClobKeeper.go +++ b/protocol/mocks/MemClobKeeper.go @@ -29,13 +29,16 @@ func (_m *MemClobKeeper) AddOrderToOrderbookCollatCheck(ctx types.Context, clobP ret := _m.Called(ctx, clobPairId, subaccountOpenOrders) var r0 bool + var r1 map[subaccountstypes.SubaccountId]subaccountstypes.UpdateResult + if rf, ok := ret.Get(0).(func(types.Context, clobtypes.ClobPairId, map[subaccountstypes.SubaccountId][]clobtypes.PendingOpenOrder) (bool, map[subaccountstypes.SubaccountId]subaccountstypes.UpdateResult)); ok { + return rf(ctx, clobPairId, subaccountOpenOrders) + } if rf, ok := ret.Get(0).(func(types.Context, clobtypes.ClobPairId, map[subaccountstypes.SubaccountId][]clobtypes.PendingOpenOrder) bool); ok { r0 = rf(ctx, clobPairId, subaccountOpenOrders) } else { r0 = ret.Get(0).(bool) } - var r1 map[subaccountstypes.SubaccountId]subaccountstypes.UpdateResult if rf, ok := ret.Get(1).(func(types.Context, clobtypes.ClobPairId, map[subaccountstypes.SubaccountId][]clobtypes.PendingOpenOrder) map[subaccountstypes.SubaccountId]subaccountstypes.UpdateResult); ok { r1 = rf(ctx, clobPairId, subaccountOpenOrders) } else { @@ -52,20 +55,24 @@ func (_m *MemClobKeeper) AddPreexistingStatefulOrder(ctx types.Context, order *c ret := _m.Called(ctx, order, memclob) var r0 subaccountstypes.BaseQuantums + var r1 clobtypes.OrderStatus + var r2 *clobtypes.OffchainUpdates + var r3 error + if rf, ok := ret.Get(0).(func(types.Context, *clobtypes.Order, clobtypes.MemClob) (subaccountstypes.BaseQuantums, clobtypes.OrderStatus, *clobtypes.OffchainUpdates, error)); ok { + return rf(ctx, order, memclob) + } if rf, ok := ret.Get(0).(func(types.Context, *clobtypes.Order, clobtypes.MemClob) subaccountstypes.BaseQuantums); ok { r0 = rf(ctx, order, memclob) } else { r0 = ret.Get(0).(subaccountstypes.BaseQuantums) } - var r1 clobtypes.OrderStatus if rf, ok := ret.Get(1).(func(types.Context, *clobtypes.Order, clobtypes.MemClob) clobtypes.OrderStatus); ok { r1 = rf(ctx, order, memclob) } else { r1 = ret.Get(1).(clobtypes.OrderStatus) } - var r2 *clobtypes.OffchainUpdates if rf, ok := ret.Get(2).(func(types.Context, *clobtypes.Order, clobtypes.MemClob) *clobtypes.OffchainUpdates); ok { r2 = rf(ctx, order, memclob) } else { @@ -74,7 +81,6 @@ func (_m *MemClobKeeper) AddPreexistingStatefulOrder(ctx types.Context, order *c } } - var r3 error if rf, ok := ret.Get(3).(func(types.Context, *clobtypes.Order, clobtypes.MemClob) error); ok { r3 = rf(ctx, order, memclob) } else { @@ -89,20 +95,23 @@ func (_m *MemClobKeeper) CanDeleverageSubaccount(ctx types.Context, subaccountId ret := _m.Called(ctx, subaccountId, perpetualId) var r0 bool + var r1 bool + var r2 error + if rf, ok := ret.Get(0).(func(types.Context, subaccountstypes.SubaccountId, uint32) (bool, bool, error)); ok { + return rf(ctx, subaccountId, perpetualId) + } if rf, ok := ret.Get(0).(func(types.Context, subaccountstypes.SubaccountId, uint32) bool); ok { r0 = rf(ctx, subaccountId, perpetualId) } else { r0 = ret.Get(0).(bool) } - var r1 bool if rf, ok := ret.Get(1).(func(types.Context, subaccountstypes.SubaccountId, uint32) bool); ok { r1 = rf(ctx, subaccountId, perpetualId) } else { r1 = ret.Get(1).(bool) } - var r2 error if rf, ok := ret.Get(2).(func(types.Context, subaccountstypes.SubaccountId, uint32) error); ok { r2 = rf(ctx, subaccountId, perpetualId) } else { @@ -147,13 +156,16 @@ func (_m *MemClobKeeper) GetLongTermOrderPlacement(ctx types.Context, orderId cl ret := _m.Called(ctx, orderId) var r0 clobtypes.LongTermOrderPlacement + var r1 bool + if rf, ok := ret.Get(0).(func(types.Context, clobtypes.OrderId) (clobtypes.LongTermOrderPlacement, bool)); ok { + return rf(ctx, orderId) + } if rf, ok := ret.Get(0).(func(types.Context, clobtypes.OrderId) clobtypes.LongTermOrderPlacement); ok { r0 = rf(ctx, orderId) } else { r0 = ret.Get(0).(clobtypes.LongTermOrderPlacement) } - var r1 bool if rf, ok := ret.Get(1).(func(types.Context, clobtypes.OrderId) bool); ok { r1 = rf(ctx, orderId) } else { @@ -168,20 +180,23 @@ func (_m *MemClobKeeper) GetOrderFillAmount(ctx types.Context, orderId clobtypes ret := _m.Called(ctx, orderId) var r0 bool + var r1 subaccountstypes.BaseQuantums + var r2 uint32 + if rf, ok := ret.Get(0).(func(types.Context, clobtypes.OrderId) (bool, subaccountstypes.BaseQuantums, uint32)); ok { + return rf(ctx, orderId) + } if rf, ok := ret.Get(0).(func(types.Context, clobtypes.OrderId) bool); ok { r0 = rf(ctx, orderId) } else { r0 = ret.Get(0).(bool) } - var r1 subaccountstypes.BaseQuantums if rf, ok := ret.Get(1).(func(types.Context, clobtypes.OrderId) subaccountstypes.BaseQuantums); ok { r1 = rf(ctx, orderId) } else { r1 = ret.Get(1).(subaccountstypes.BaseQuantums) } - var r2 uint32 if rf, ok := ret.Get(2).(func(types.Context, clobtypes.OrderId) uint32); ok { r2 = rf(ctx, orderId) } else { @@ -212,13 +227,16 @@ func (_m *MemClobKeeper) IsLiquidatable(ctx types.Context, subaccountId subaccou ret := _m.Called(ctx, subaccountId) var r0 bool + var r1 error + if rf, ok := ret.Get(0).(func(types.Context, subaccountstypes.SubaccountId) (bool, error)); ok { + return rf(ctx, subaccountId) + } if rf, ok := ret.Get(0).(func(types.Context, subaccountstypes.SubaccountId) bool); ok { r0 = rf(ctx, subaccountId) } else { r0 = ret.Get(0).(bool) } - var r1 error if rf, ok := ret.Get(1).(func(types.Context, subaccountstypes.SubaccountId) error); ok { r1 = rf(ctx, subaccountId) } else { @@ -254,6 +272,10 @@ func (_m *MemClobKeeper) OffsetSubaccountPerpetualPosition(ctx types.Context, li ret := _m.Called(ctx, liquidatedSubaccountId, perpetualId, deltaQuantumsTotal, isFinalSettlement) var r0 []clobtypes.MatchPerpetualDeleveraging_Fill + var r1 *big.Int + if rf, ok := ret.Get(0).(func(types.Context, subaccountstypes.SubaccountId, uint32, *big.Int, bool) ([]clobtypes.MatchPerpetualDeleveraging_Fill, *big.Int)); ok { + return rf(ctx, liquidatedSubaccountId, perpetualId, deltaQuantumsTotal, isFinalSettlement) + } if rf, ok := ret.Get(0).(func(types.Context, subaccountstypes.SubaccountId, uint32, *big.Int, bool) []clobtypes.MatchPerpetualDeleveraging_Fill); ok { r0 = rf(ctx, liquidatedSubaccountId, perpetualId, deltaQuantumsTotal, isFinalSettlement) } else { @@ -262,7 +284,6 @@ func (_m *MemClobKeeper) OffsetSubaccountPerpetualPosition(ctx types.Context, li } } - var r1 *big.Int if rf, ok := ret.Get(1).(func(types.Context, subaccountstypes.SubaccountId, uint32, *big.Int, bool) *big.Int); ok { r1 = rf(ctx, liquidatedSubaccountId, perpetualId, deltaQuantumsTotal, isFinalSettlement) } else { @@ -279,27 +300,31 @@ func (_m *MemClobKeeper) ProcessSingleMatch(ctx types.Context, matchWithOrders * ret := _m.Called(ctx, matchWithOrders) var r0 bool + var r1 subaccountstypes.UpdateResult + var r2 subaccountstypes.UpdateResult + var r3 *clobtypes.OffchainUpdates + var r4 error + if rf, ok := ret.Get(0).(func(types.Context, *clobtypes.MatchWithOrders) (bool, subaccountstypes.UpdateResult, subaccountstypes.UpdateResult, *clobtypes.OffchainUpdates, error)); ok { + return rf(ctx, matchWithOrders) + } if rf, ok := ret.Get(0).(func(types.Context, *clobtypes.MatchWithOrders) bool); ok { r0 = rf(ctx, matchWithOrders) } else { r0 = ret.Get(0).(bool) } - var r1 subaccountstypes.UpdateResult if rf, ok := ret.Get(1).(func(types.Context, *clobtypes.MatchWithOrders) subaccountstypes.UpdateResult); ok { r1 = rf(ctx, matchWithOrders) } else { r1 = ret.Get(1).(subaccountstypes.UpdateResult) } - var r2 subaccountstypes.UpdateResult if rf, ok := ret.Get(2).(func(types.Context, *clobtypes.MatchWithOrders) subaccountstypes.UpdateResult); ok { r2 = rf(ctx, matchWithOrders) } else { r2 = ret.Get(2).(subaccountstypes.UpdateResult) } - var r3 *clobtypes.OffchainUpdates if rf, ok := ret.Get(3).(func(types.Context, *clobtypes.MatchWithOrders) *clobtypes.OffchainUpdates); ok { r3 = rf(ctx, matchWithOrders) } else { @@ -308,7 +333,6 @@ func (_m *MemClobKeeper) ProcessSingleMatch(ctx types.Context, matchWithOrders * } } - var r4 error if rf, ok := ret.Get(4).(func(types.Context, *clobtypes.MatchWithOrders) error); ok { r4 = rf(ctx, matchWithOrders) } else { @@ -323,20 +347,24 @@ func (_m *MemClobKeeper) ReplayPlaceOrder(ctx types.Context, msg *clobtypes.MsgP ret := _m.Called(ctx, msg) var r0 subaccountstypes.BaseQuantums + var r1 clobtypes.OrderStatus + var r2 *clobtypes.OffchainUpdates + var r3 error + if rf, ok := ret.Get(0).(func(types.Context, *clobtypes.MsgPlaceOrder) (subaccountstypes.BaseQuantums, clobtypes.OrderStatus, *clobtypes.OffchainUpdates, error)); ok { + return rf(ctx, msg) + } if rf, ok := ret.Get(0).(func(types.Context, *clobtypes.MsgPlaceOrder) subaccountstypes.BaseQuantums); ok { r0 = rf(ctx, msg) } else { r0 = ret.Get(0).(subaccountstypes.BaseQuantums) } - var r1 clobtypes.OrderStatus if rf, ok := ret.Get(1).(func(types.Context, *clobtypes.MsgPlaceOrder) clobtypes.OrderStatus); ok { r1 = rf(ctx, msg) } else { r1 = ret.Get(1).(clobtypes.OrderStatus) } - var r2 *clobtypes.OffchainUpdates if rf, ok := ret.Get(2).(func(types.Context, *clobtypes.MsgPlaceOrder) *clobtypes.OffchainUpdates); ok { r2 = rf(ctx, msg) } else { @@ -345,7 +373,6 @@ func (_m *MemClobKeeper) ReplayPlaceOrder(ctx types.Context, msg *clobtypes.MsgP } } - var r3 error if rf, ok := ret.Get(3).(func(types.Context, *clobtypes.MsgPlaceOrder) error); ok { r3 = rf(ctx, msg) } else { diff --git a/protocol/mocks/QueryClient.go b/protocol/mocks/QueryClient.go index faacbd534d..43e03db14e 100644 --- a/protocol/mocks/QueryClient.go +++ b/protocol/mocks/QueryClient.go @@ -393,6 +393,39 @@ func (_m *QueryClient) EquityTierLimitConfiguration(ctx context.Context, in *clo return r0, r1 } +// GetWithdrawalAndTransfersBlockedInfo provides a mock function with given fields: ctx, in, opts +func (_m *QueryClient) GetWithdrawalAndTransfersBlockedInfo(ctx context.Context, in *subaccountstypes.QueryGetWithdrawalAndTransfersBlockedInfoRequest, opts ...grpc.CallOption) (*subaccountstypes.QueryGetWithdrawalAndTransfersBlockedInfoResponse, error) { + _va := make([]interface{}, len(opts)) + for _i := range opts { + _va[_i] = opts[_i] + } + var _ca []interface{} + _ca = append(_ca, ctx, in) + _ca = append(_ca, _va...) + ret := _m.Called(_ca...) + + var r0 *subaccountstypes.QueryGetWithdrawalAndTransfersBlockedInfoResponse + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, *subaccountstypes.QueryGetWithdrawalAndTransfersBlockedInfoRequest, ...grpc.CallOption) (*subaccountstypes.QueryGetWithdrawalAndTransfersBlockedInfoResponse, error)); ok { + return rf(ctx, in, opts...) + } + if rf, ok := ret.Get(0).(func(context.Context, *subaccountstypes.QueryGetWithdrawalAndTransfersBlockedInfoRequest, ...grpc.CallOption) *subaccountstypes.QueryGetWithdrawalAndTransfersBlockedInfoResponse); ok { + r0 = rf(ctx, in, opts...) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*subaccountstypes.QueryGetWithdrawalAndTransfersBlockedInfoResponse) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, *subaccountstypes.QueryGetWithdrawalAndTransfersBlockedInfoRequest, ...grpc.CallOption) error); ok { + r1 = rf(ctx, in, opts...) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + // LiquidateSubaccounts provides a mock function with given fields: ctx, in, opts func (_m *QueryClient) LiquidateSubaccounts(ctx context.Context, in *liquidationapi.LiquidateSubaccountsRequest, opts ...grpc.CallOption) (*liquidationapi.LiquidateSubaccountsResponse, error) { _va := make([]interface{}, len(opts)) diff --git a/protocol/x/subaccounts/keeper/grpc_query_withdrawal_and_transfers_blocked_info.go b/protocol/x/subaccounts/keeper/grpc_query_withdrawal_and_transfers_blocked_info.go new file mode 100644 index 0000000000..eb0931e75b --- /dev/null +++ b/protocol/x/subaccounts/keeper/grpc_query_withdrawal_and_transfers_blocked_info.go @@ -0,0 +1,44 @@ +package keeper + +import ( + "context" + + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" + + sdktypes "github.com/cosmos/cosmos-sdk/types" + "github.com/dydxprotocol/v4-chain/protocol/x/subaccounts/types" +) + +func (k Keeper) GetWithdrawalAndTransfersBlockedInfo( + c context.Context, + req *types.QueryGetWithdrawalAndTransfersBlockedInfoRequest, +) (*types.QueryGetWithdrawalAndTransfersBlockedInfoResponse, error) { + if req == nil { + return nil, status.Error(codes.InvalidArgument, "invalid request") + } + ctx := sdktypes.UnwrapSDKContext(c) + + downtimeInfo := k.blocktimeKeeper.GetDowntimeInfoFor( + ctx, + types.WITHDRAWAL_AND_TRANSFERS_BLOCKED_AFTER_CHAIN_OUTAGE_DURATION, + ) + chainOutageSeenAtBlock, chainOutageExists := downtimeInfo.BlockInfo.Height, + downtimeInfo.BlockInfo.Height > 0 && downtimeInfo.Duration > 0 + negativeTncSubaccountSeenAtBlock, negativeTncSubaccountSeenAtBlockExists := k.GetNegativeTncSubaccountSeenAtBlock(ctx) + + // Withdrawals and transfers are blocked at non-zero block iff a chain outage or negative TNC subaccount exists. + withdrawalsAndTransfersBlockedUntilBlock := uint32(0) + if chainOutageExists || negativeTncSubaccountSeenAtBlockExists { + withdrawalsAndTransfersBlockedUntilBlock = max( + chainOutageSeenAtBlock, + negativeTncSubaccountSeenAtBlock, + ) + types.WITHDRAWAL_AND_TRANSFERS_BLOCKED_AFTER_NEGATIVE_TNC_SUBACCOUNT_SEEN_BLOCKS + } + + return &types.QueryGetWithdrawalAndTransfersBlockedInfoResponse{ + NegativeTncSubaccountSeenAtBlock: negativeTncSubaccountSeenAtBlock, + ChainOutageSeenAtBlock: chainOutageSeenAtBlock, + WithdrawalsAndTransfersUnblockedAtBlock: withdrawalsAndTransfersBlockedUntilBlock, + }, nil +} diff --git a/protocol/x/subaccounts/keeper/grpc_query_withdrawal_and_transfers_blocked_info_test.go b/protocol/x/subaccounts/keeper/grpc_query_withdrawal_and_transfers_blocked_info_test.go new file mode 100644 index 0000000000..735eefcaa0 --- /dev/null +++ b/protocol/x/subaccounts/keeper/grpc_query_withdrawal_and_transfers_blocked_info_test.go @@ -0,0 +1,214 @@ +package keeper_test + +import ( + "testing" + "time" + + "github.com/stretchr/testify/require" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" + + sdktypes "github.com/cosmos/cosmos-sdk/types" + keepertest "github.com/dydxprotocol/v4-chain/protocol/testutil/keeper" + btkeeper "github.com/dydxprotocol/v4-chain/protocol/x/blocktime/keeper" + blocktimetypes "github.com/dydxprotocol/v4-chain/protocol/x/blocktime/types" + sakeeper "github.com/dydxprotocol/v4-chain/protocol/x/subaccounts/keeper" + "github.com/dydxprotocol/v4-chain/protocol/x/subaccounts/types" +) + +func TestQueryWithdrawalAndTransfersBlockedInfo(t *testing.T) { + for testName, tc := range map[string]struct { + // Setup. + setup func(ctx sdktypes.Context, sk sakeeper.Keeper, bk btkeeper.Keeper) + + // Parameters. + request *types.QueryGetWithdrawalAndTransfersBlockedInfoRequest + + // Expectations. + response *types.QueryGetWithdrawalAndTransfersBlockedInfoResponse + err error + }{ + "Nil request returns an error": { + setup: func(ctx sdktypes.Context, sk sakeeper.Keeper, bk btkeeper.Keeper) {}, + + err: status.Error(codes.InvalidArgument, "invalid request"), + }, + `No negative TNC subaccount or chain outage in state returns withdrawals and transfers unblocked + at block 0`: { + setup: func(ctx sdktypes.Context, sk sakeeper.Keeper, bk btkeeper.Keeper) {}, + + request: &types.QueryGetWithdrawalAndTransfersBlockedInfoRequest{}, + + response: &types.QueryGetWithdrawalAndTransfersBlockedInfoResponse{ + NegativeTncSubaccountSeenAtBlock: 0, + ChainOutageSeenAtBlock: 0, + WithdrawalsAndTransfersUnblockedAtBlock: 0, + }, + }, + `Negative TNC subaccount seen in state returns withdrawals and transfers unblocked + after the delay`: { + setup: func(ctx sdktypes.Context, sk sakeeper.Keeper, bk btkeeper.Keeper) { + sk.SetNegativeTncSubaccountSeenAtBlock(ctx, 7) + }, + + request: &types.QueryGetWithdrawalAndTransfersBlockedInfoRequest{}, + + response: &types.QueryGetWithdrawalAndTransfersBlockedInfoResponse{ + NegativeTncSubaccountSeenAtBlock: 7, + ChainOutageSeenAtBlock: 0, + WithdrawalsAndTransfersUnblockedAtBlock: 7 + + types.WITHDRAWAL_AND_TRANSFERS_BLOCKED_AFTER_NEGATIVE_TNC_SUBACCOUNT_SEEN_BLOCKS, + }, + }, + `Chain outage seen in state returns withdrawals and transfers unblocked after the delay`: { + setup: func(ctx sdktypes.Context, k sakeeper.Keeper, bk btkeeper.Keeper) { + bk.SetAllDowntimeInfo( + ctx, + &blocktimetypes.AllDowntimeInfo{ + Infos: []*blocktimetypes.AllDowntimeInfo_DowntimeInfo{ + { + Duration: 10 * time.Second, + BlockInfo: blocktimetypes.BlockInfo{ + Height: 30, + Timestamp: time.Unix(300, 0).UTC(), + }, + }, + { + Duration: 5 * time.Minute, + BlockInfo: blocktimetypes.BlockInfo{ + Height: 25, + Timestamp: time.Unix(300, 0).UTC(), + }, + }, + }, + }) + }, + + request: &types.QueryGetWithdrawalAndTransfersBlockedInfoRequest{}, + + response: &types.QueryGetWithdrawalAndTransfersBlockedInfoResponse{ + NegativeTncSubaccountSeenAtBlock: 0, + ChainOutageSeenAtBlock: 25, + WithdrawalsAndTransfersUnblockedAtBlock: 25 + + types.WITHDRAWAL_AND_TRANSFERS_BLOCKED_AFTER_NEGATIVE_TNC_SUBACCOUNT_SEEN_BLOCKS, + }, + }, + `Negative TNC subaccount and chain outage seen in state returns withdrawals and transfers + unblocked after the max block number + delay (negative TNC subaccount block greater)`: { + setup: func(ctx sdktypes.Context, sk sakeeper.Keeper, bk btkeeper.Keeper) { + sk.SetNegativeTncSubaccountSeenAtBlock(ctx, 27) + bk.SetAllDowntimeInfo( + ctx, + &blocktimetypes.AllDowntimeInfo{ + Infos: []*blocktimetypes.AllDowntimeInfo_DowntimeInfo{ + { + Duration: 10 * time.Second, + BlockInfo: blocktimetypes.BlockInfo{ + Height: 30, + Timestamp: time.Unix(300, 0).UTC(), + }, + }, + { + Duration: 5 * time.Minute, + BlockInfo: blocktimetypes.BlockInfo{ + Height: 25, + Timestamp: time.Unix(300, 0).UTC(), + }, + }, + }, + }) + }, + + request: &types.QueryGetWithdrawalAndTransfersBlockedInfoRequest{}, + + response: &types.QueryGetWithdrawalAndTransfersBlockedInfoResponse{ + NegativeTncSubaccountSeenAtBlock: 27, + ChainOutageSeenAtBlock: 25, + WithdrawalsAndTransfersUnblockedAtBlock: 27 + + types.WITHDRAWAL_AND_TRANSFERS_BLOCKED_AFTER_NEGATIVE_TNC_SUBACCOUNT_SEEN_BLOCKS, + }, + }, + `Negative TNC subaccount and chain outage seen in state returns withdrawals and transfers + unblocked after the max block number + delay (chain outage block greater)`: { + setup: func(ctx sdktypes.Context, sk sakeeper.Keeper, bk btkeeper.Keeper) { + sk.SetNegativeTncSubaccountSeenAtBlock(ctx, 37) + bk.SetAllDowntimeInfo( + ctx, + &blocktimetypes.AllDowntimeInfo{ + Infos: []*blocktimetypes.AllDowntimeInfo_DowntimeInfo{ + { + Duration: 10 * time.Second, + BlockInfo: blocktimetypes.BlockInfo{ + Height: 50, + Timestamp: time.Unix(300, 0).UTC(), + }, + }, + { + Duration: 5 * time.Minute, + BlockInfo: blocktimetypes.BlockInfo{ + Height: 47, + Timestamp: time.Unix(300, 0).UTC(), + }, + }, + }, + }) + }, + + request: &types.QueryGetWithdrawalAndTransfersBlockedInfoRequest{}, + + response: &types.QueryGetWithdrawalAndTransfersBlockedInfoResponse{ + NegativeTncSubaccountSeenAtBlock: 37, + ChainOutageSeenAtBlock: 47, + WithdrawalsAndTransfersUnblockedAtBlock: 47 + + types.WITHDRAWAL_AND_TRANSFERS_BLOCKED_AFTER_NEGATIVE_TNC_SUBACCOUNT_SEEN_BLOCKS, + }, + }, + `Negative TNC subaccount and chain outage seen in state returns withdrawals and transfers + unblocked after the max block number + delay (both blocks equal)`: { + setup: func(ctx sdktypes.Context, sk sakeeper.Keeper, bk btkeeper.Keeper) { + sk.SetNegativeTncSubaccountSeenAtBlock(ctx, 3) + bk.SetAllDowntimeInfo( + ctx, + &blocktimetypes.AllDowntimeInfo{ + Infos: []*blocktimetypes.AllDowntimeInfo_DowntimeInfo{ + { + Duration: 10 * time.Second, + BlockInfo: blocktimetypes.BlockInfo{ + Height: 50, + Timestamp: time.Unix(300, 0).UTC(), + }, + }, + { + Duration: 5 * time.Minute, + BlockInfo: blocktimetypes.BlockInfo{ + Height: 3, + Timestamp: time.Unix(300, 0).UTC(), + }, + }, + }, + }) + }, + + request: &types.QueryGetWithdrawalAndTransfersBlockedInfoRequest{}, + + response: &types.QueryGetWithdrawalAndTransfersBlockedInfoResponse{ + NegativeTncSubaccountSeenAtBlock: 3, + ChainOutageSeenAtBlock: 3, + WithdrawalsAndTransfersUnblockedAtBlock: 3 + + types.WITHDRAWAL_AND_TRANSFERS_BLOCKED_AFTER_NEGATIVE_TNC_SUBACCOUNT_SEEN_BLOCKS, + }, + }, + } { + t.Run(testName, func(t *testing.T) { + ctx, keeper, _, _, _, _, _, blocktimeKeeper, _ := keepertest.SubaccountsKeepers(t, true) + tc.setup(ctx, *keeper, *blocktimeKeeper) + response, err := keeper.GetWithdrawalAndTransfersBlockedInfo(ctx, tc.request) + if tc.err != nil { + require.ErrorIs(t, err, tc.err) + } else { + require.NoError(t, err) + require.Equal(t, tc.response, response) + } + }) + } +} diff --git a/protocol/x/subaccounts/keeper/subaccount.go b/protocol/x/subaccounts/keeper/subaccount.go index ff4626d135..08d51ac269 100644 --- a/protocol/x/subaccounts/keeper/subaccount.go +++ b/protocol/x/subaccounts/keeper/subaccount.go @@ -505,7 +505,10 @@ func (k Keeper) internalCanUpdateSubaccounts( } // Panic if the current block is less than the last block a chain outage was seen. - downtimeInfo := k.blocktimeKeeper.GetDowntimeInfoFor(ctx, 5*time.Minute) + downtimeInfo := k.blocktimeKeeper.GetDowntimeInfoFor( + ctx, + types.WITHDRAWAL_AND_TRANSFERS_BLOCKED_AFTER_CHAIN_OUTAGE_DURATION, + ) chainOutageExists := downtimeInfo.BlockInfo.Height > 0 && downtimeInfo.Duration > 0 if chainOutageExists && currentBlock < downtimeInfo.BlockInfo.Height { panic( diff --git a/protocol/x/subaccounts/types/query.pb.go b/protocol/x/subaccounts/types/query.pb.go index 969f808a30..1c0893dc8a 100644 --- a/protocol/x/subaccounts/types/query.pb.go +++ b/protocol/x/subaccounts/types/query.pb.go @@ -227,11 +227,121 @@ func (m *QuerySubaccountAllResponse) GetPagination() *query.PageResponse { return nil } +// QueryGetWithdrawalAndTransfersBlockedInfoRequest is a request type for +// fetching information about whether withdrawals and transfers are blocked. +type QueryGetWithdrawalAndTransfersBlockedInfoRequest struct { +} + +func (m *QueryGetWithdrawalAndTransfersBlockedInfoRequest) Reset() { + *m = QueryGetWithdrawalAndTransfersBlockedInfoRequest{} +} +func (m *QueryGetWithdrawalAndTransfersBlockedInfoRequest) String() string { + return proto.CompactTextString(m) +} +func (*QueryGetWithdrawalAndTransfersBlockedInfoRequest) ProtoMessage() {} +func (*QueryGetWithdrawalAndTransfersBlockedInfoRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_adc19ff1d5b72954, []int{4} +} +func (m *QueryGetWithdrawalAndTransfersBlockedInfoRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryGetWithdrawalAndTransfersBlockedInfoRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryGetWithdrawalAndTransfersBlockedInfoRequest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryGetWithdrawalAndTransfersBlockedInfoRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryGetWithdrawalAndTransfersBlockedInfoRequest.Merge(m, src) +} +func (m *QueryGetWithdrawalAndTransfersBlockedInfoRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryGetWithdrawalAndTransfersBlockedInfoRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryGetWithdrawalAndTransfersBlockedInfoRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryGetWithdrawalAndTransfersBlockedInfoRequest proto.InternalMessageInfo + +// QueryGetWithdrawalAndTransfersBlockedInfoRequest is a response type for +// fetching information about whether withdrawals and transfers are blocked. +type QueryGetWithdrawalAndTransfersBlockedInfoResponse struct { + NegativeTncSubaccountSeenAtBlock uint32 `protobuf:"varint,1,opt,name=negative_tnc_subaccount_seen_at_block,json=negativeTncSubaccountSeenAtBlock,proto3" json:"negative_tnc_subaccount_seen_at_block,omitempty"` + ChainOutageSeenAtBlock uint32 `protobuf:"varint,2,opt,name=chain_outage_seen_at_block,json=chainOutageSeenAtBlock,proto3" json:"chain_outage_seen_at_block,omitempty"` + WithdrawalsAndTransfersUnblockedAtBlock uint32 `protobuf:"varint,3,opt,name=withdrawals_and_transfers_unblocked_at_block,json=withdrawalsAndTransfersUnblockedAtBlock,proto3" json:"withdrawals_and_transfers_unblocked_at_block,omitempty"` +} + +func (m *QueryGetWithdrawalAndTransfersBlockedInfoResponse) Reset() { + *m = QueryGetWithdrawalAndTransfersBlockedInfoResponse{} +} +func (m *QueryGetWithdrawalAndTransfersBlockedInfoResponse) String() string { + return proto.CompactTextString(m) +} +func (*QueryGetWithdrawalAndTransfersBlockedInfoResponse) ProtoMessage() {} +func (*QueryGetWithdrawalAndTransfersBlockedInfoResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_adc19ff1d5b72954, []int{5} +} +func (m *QueryGetWithdrawalAndTransfersBlockedInfoResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryGetWithdrawalAndTransfersBlockedInfoResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryGetWithdrawalAndTransfersBlockedInfoResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryGetWithdrawalAndTransfersBlockedInfoResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryGetWithdrawalAndTransfersBlockedInfoResponse.Merge(m, src) +} +func (m *QueryGetWithdrawalAndTransfersBlockedInfoResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryGetWithdrawalAndTransfersBlockedInfoResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryGetWithdrawalAndTransfersBlockedInfoResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryGetWithdrawalAndTransfersBlockedInfoResponse proto.InternalMessageInfo + +func (m *QueryGetWithdrawalAndTransfersBlockedInfoResponse) GetNegativeTncSubaccountSeenAtBlock() uint32 { + if m != nil { + return m.NegativeTncSubaccountSeenAtBlock + } + return 0 +} + +func (m *QueryGetWithdrawalAndTransfersBlockedInfoResponse) GetChainOutageSeenAtBlock() uint32 { + if m != nil { + return m.ChainOutageSeenAtBlock + } + return 0 +} + +func (m *QueryGetWithdrawalAndTransfersBlockedInfoResponse) GetWithdrawalsAndTransfersUnblockedAtBlock() uint32 { + if m != nil { + return m.WithdrawalsAndTransfersUnblockedAtBlock + } + return 0 +} + func init() { proto.RegisterType((*QueryGetSubaccountRequest)(nil), "dydxprotocol.subaccounts.QueryGetSubaccountRequest") proto.RegisterType((*QuerySubaccountResponse)(nil), "dydxprotocol.subaccounts.QuerySubaccountResponse") proto.RegisterType((*QueryAllSubaccountRequest)(nil), "dydxprotocol.subaccounts.QueryAllSubaccountRequest") proto.RegisterType((*QuerySubaccountAllResponse)(nil), "dydxprotocol.subaccounts.QuerySubaccountAllResponse") + proto.RegisterType((*QueryGetWithdrawalAndTransfersBlockedInfoRequest)(nil), "dydxprotocol.subaccounts.QueryGetWithdrawalAndTransfersBlockedInfoRequest") + proto.RegisterType((*QueryGetWithdrawalAndTransfersBlockedInfoResponse)(nil), "dydxprotocol.subaccounts.QueryGetWithdrawalAndTransfersBlockedInfoResponse") } func init() { @@ -239,38 +349,49 @@ func init() { } var fileDescriptor_adc19ff1d5b72954 = []byte{ - // 487 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x92, 0x41, 0x6b, 0x14, 0x31, - 0x14, 0xc7, 0x37, 0xab, 0x2d, 0x18, 0xe9, 0x25, 0x14, 0xdd, 0x0e, 0x32, 0x96, 0x61, 0xa9, 0x55, - 0x6c, 0xc2, 0xb6, 0x15, 0x4f, 0x3d, 0xec, 0x1e, 0x2c, 0x78, 0xd2, 0xe9, 0x41, 0xf0, 0x22, 0x99, - 0xd9, 0x90, 0x0e, 0xcc, 0x26, 0xd3, 0x49, 0xa6, 0x76, 0x29, 0xbd, 0xf8, 0x09, 0x04, 0xbf, 0x84, - 0x57, 0xd1, 0x0f, 0xd1, 0x63, 0xd1, 0x8b, 0x27, 0x91, 0x5d, 0x0f, 0x7e, 0x0c, 0xd9, 0x24, 0xee, - 0xcc, 0xba, 0x0e, 0xbb, 0xf4, 0x96, 0xe4, 0xbd, 0xff, 0x7b, 0xbf, 0xff, 0xcb, 0x83, 0xed, 0xfe, - 0xb0, 0x7f, 0x96, 0xe5, 0x52, 0xcb, 0x58, 0xa6, 0x44, 0x15, 0x11, 0x8d, 0x63, 0x59, 0x08, 0xad, - 0xc8, 0x49, 0xc1, 0xf2, 0x21, 0x36, 0x21, 0xd4, 0xaa, 0x66, 0xe1, 0x4a, 0x96, 0xb7, 0x11, 0x4b, - 0x35, 0x90, 0xea, 0x8d, 0x09, 0x12, 0x7b, 0xb1, 0x22, 0x6f, 0x9d, 0x4b, 0x2e, 0xed, 0xfb, 0xe4, - 0xe4, 0x5e, 0xef, 0x71, 0x29, 0x79, 0xca, 0x08, 0xcd, 0x12, 0x42, 0x85, 0x90, 0x9a, 0xea, 0x44, - 0x8a, 0xbf, 0x9a, 0x47, 0xb6, 0x02, 0x89, 0xa8, 0x62, 0x96, 0x80, 0x9c, 0x76, 0x22, 0xa6, 0x69, - 0x87, 0x64, 0x94, 0x27, 0xc2, 0x24, 0xbb, 0xdc, 0x87, 0xb5, 0xe8, 0xe5, 0xd9, 0xa6, 0x06, 0x31, - 0xdc, 0x78, 0x39, 0x29, 0x76, 0xc8, 0xf4, 0xd1, 0x34, 0x16, 0xb2, 0x93, 0x82, 0x29, 0x8d, 0x30, - 0x5c, 0x91, 0x6f, 0x05, 0xcb, 0x5b, 0x60, 0x13, 0x6c, 0xdf, 0xea, 0xb5, 0xbe, 0x7e, 0xd9, 0x59, - 0x77, 0x46, 0xba, 0xfd, 0x7e, 0xce, 0x94, 0x3a, 0xd2, 0x79, 0x22, 0x78, 0x68, 0xd3, 0xd0, 0x1d, - 0xb8, 0x2a, 0x8a, 0x41, 0xc4, 0xf2, 0x56, 0x73, 0x13, 0x6c, 0xaf, 0x85, 0xee, 0x16, 0x30, 0x78, - 0xd7, 0x34, 0xa9, 0x76, 0x50, 0x99, 0x14, 0x8a, 0xa1, 0xe7, 0x10, 0x96, 0x4c, 0xa6, 0xcf, 0xed, - 0xdd, 0x36, 0xae, 0x1b, 0x2a, 0x2e, 0x2b, 0xf4, 0x6e, 0x5e, 0xfe, 0xb8, 0xdf, 0x08, 0x2b, 0xea, - 0xa9, 0x97, 0x6e, 0x9a, 0xce, 0x7b, 0x79, 0x06, 0x61, 0x39, 0x27, 0xd7, 0x68, 0x0b, 0x3b, 0x37, - 0x93, 0xa1, 0x62, 0xfb, 0xad, 0x6e, 0xa8, 0xf8, 0x05, 0xe5, 0xcc, 0x69, 0xc3, 0x8a, 0x32, 0xf8, - 0x04, 0xa0, 0xf7, 0x8f, 0x99, 0x6e, 0x9a, 0xd6, 0xfa, 0xb9, 0x71, 0x7d, 0x3f, 0xe8, 0x70, 0x06, - 0xb9, 0x69, 0x90, 0x1f, 0x2c, 0x44, 0xb6, 0x20, 0x55, 0xe6, 0xdd, 0xdf, 0x4d, 0xb8, 0x62, 0x98, - 0xd1, 0x67, 0x00, 0x61, 0xd9, 0x13, 0xed, 0xd5, 0x93, 0xd5, 0x6e, 0x85, 0xd7, 0x59, 0x20, 0x9a, - 0xff, 0xe5, 0xe0, 0xe0, 0xdd, 0xb7, 0x5f, 0x1f, 0x9a, 0x4f, 0xd1, 0x13, 0xb2, 0xc4, 0x66, 0x92, - 0x73, 0xb3, 0x4d, 0x17, 0xe4, 0xdc, 0xae, 0xcf, 0x05, 0xfa, 0x08, 0xe0, 0xda, 0xcc, 0xb8, 0x17, - 0x82, 0xff, 0x6f, 0x05, 0xbc, 0xfd, 0xa5, 0xc1, 0x2b, 0x3f, 0x1a, 0x3c, 0x36, 0xec, 0x5b, 0xa8, - 0xbd, 0x0c, 0x7b, 0xef, 0xd5, 0xe5, 0xc8, 0x07, 0x57, 0x23, 0x1f, 0xfc, 0x1c, 0xf9, 0xe0, 0xfd, - 0xd8, 0x6f, 0x5c, 0x8d, 0xfd, 0xc6, 0xf7, 0xb1, 0xdf, 0x78, 0x7d, 0xc0, 0x13, 0x7d, 0x5c, 0x44, - 0x38, 0x96, 0x83, 0xd9, 0x4a, 0xa7, 0xfb, 0x3b, 0xf1, 0x31, 0x4d, 0x04, 0x99, 0xbe, 0x9c, 0xcd, - 0x54, 0xd7, 0xc3, 0x8c, 0xa9, 0x68, 0xd5, 0x44, 0xf7, 0xfe, 0x04, 0x00, 0x00, 0xff, 0xff, 0x3a, - 0x73, 0x87, 0x23, 0x97, 0x04, 0x00, 0x00, + // 666 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x53, 0x4d, 0x6b, 0xd4, 0x40, + 0x18, 0xde, 0x6c, 0x3f, 0xc0, 0x91, 0x5e, 0x86, 0x52, 0xb7, 0x41, 0xd6, 0xb2, 0xac, 0x6d, 0x95, + 0x36, 0xe3, 0xb6, 0x15, 0x41, 0x28, 0xb8, 0x7b, 0xb0, 0x5a, 0x0f, 0xd5, 0xb4, 0x52, 0x10, 0x24, + 0x4c, 0x92, 0x69, 0x1a, 0x4c, 0x67, 0xb6, 0x99, 0x49, 0x3f, 0x28, 0xbd, 0x78, 0xf3, 0x26, 0xf8, + 0x03, 0xbc, 0x7a, 0x15, 0xfd, 0x11, 0x3d, 0x16, 0xbd, 0x78, 0x12, 0x69, 0xfd, 0x09, 0xfe, 0x00, + 0xd9, 0x99, 0xc9, 0x26, 0xdb, 0x1a, 0x76, 0x15, 0x6f, 0xc9, 0xcc, 0xfb, 0x3c, 0xef, 0xf3, 0xbc, + 0xf3, 0x3e, 0xa0, 0xee, 0x1f, 0xfa, 0x07, 0xed, 0x98, 0x09, 0xe6, 0xb1, 0x08, 0xf1, 0xc4, 0xc5, + 0x9e, 0xc7, 0x12, 0x2a, 0x38, 0xda, 0x4d, 0x48, 0x7c, 0x68, 0xc9, 0x2b, 0x58, 0xc9, 0x57, 0x59, + 0xb9, 0x2a, 0x73, 0xd2, 0x63, 0x7c, 0x87, 0x71, 0x47, 0x5e, 0x22, 0xf5, 0xa3, 0x40, 0xe6, 0x78, + 0xc0, 0x02, 0xa6, 0xce, 0x3b, 0x5f, 0xfa, 0xf4, 0x7a, 0xc0, 0x58, 0x10, 0x11, 0x84, 0xdb, 0x21, + 0xc2, 0x94, 0x32, 0x81, 0x45, 0xc8, 0x68, 0x8a, 0xb9, 0xad, 0x18, 0x90, 0x8b, 0x39, 0x51, 0x0a, + 0xd0, 0x5e, 0xc3, 0x25, 0x02, 0x37, 0x50, 0x1b, 0x07, 0x21, 0x95, 0xc5, 0xba, 0xf6, 0x56, 0xa1, + 0xf4, 0xec, 0x5b, 0x95, 0xd6, 0x3c, 0x30, 0xf9, 0xac, 0x43, 0xb6, 0x42, 0xc4, 0x7a, 0xf7, 0xce, + 0x26, 0xbb, 0x09, 0xe1, 0x02, 0x5a, 0x60, 0x84, 0xed, 0x53, 0x12, 0x57, 0x8c, 0x29, 0x63, 0xf6, + 0x4a, 0xab, 0xf2, 0xe5, 0xf3, 0xfc, 0xb8, 0x36, 0xd2, 0xf4, 0xfd, 0x98, 0x70, 0xbe, 0x2e, 0xe2, + 0x90, 0x06, 0xb6, 0x2a, 0x83, 0x13, 0x60, 0x94, 0x26, 0x3b, 0x2e, 0x89, 0x2b, 0xe5, 0x29, 0x63, + 0x76, 0xcc, 0xd6, 0x7f, 0x35, 0x02, 0xae, 0xc9, 0x26, 0xf9, 0x0e, 0xbc, 0xcd, 0x28, 0x27, 0x70, + 0x15, 0x80, 0x4c, 0x93, 0xec, 0x73, 0x75, 0xa1, 0x6e, 0x15, 0x0d, 0xd5, 0xca, 0x18, 0x5a, 0xc3, + 0x27, 0xdf, 0x6f, 0x94, 0xec, 0x1c, 0xba, 0xeb, 0xa5, 0x19, 0x45, 0x97, 0xbd, 0x3c, 0x04, 0x20, + 0x9b, 0x93, 0x6e, 0x34, 0x6d, 0x69, 0x37, 0x9d, 0xa1, 0x5a, 0xea, 0x59, 0xf5, 0x50, 0xad, 0xa7, + 0x38, 0x20, 0x1a, 0x6b, 0xe7, 0x90, 0xb5, 0x8f, 0x06, 0x30, 0x2f, 0x98, 0x69, 0x46, 0x51, 0xa1, + 0x9f, 0xa1, 0x7f, 0xf7, 0x03, 0x57, 0x7a, 0x24, 0x97, 0xa5, 0xe4, 0x99, 0xbe, 0x92, 0x95, 0x90, + 0x1e, 0xcd, 0x0b, 0xe0, 0x4e, 0xfa, 0xc8, 0x9b, 0xa1, 0xd8, 0xf6, 0x63, 0xbc, 0x8f, 0xa3, 0x26, + 0xf5, 0x37, 0x62, 0x4c, 0xf9, 0x16, 0x89, 0x79, 0x2b, 0x62, 0xde, 0x2b, 0xe2, 0x3f, 0xa6, 0x5b, + 0x4c, 0x7b, 0xae, 0xbd, 0x2f, 0x83, 0xc6, 0x5f, 0x80, 0xb4, 0xfd, 0x35, 0x70, 0x93, 0x92, 0x00, + 0x8b, 0x70, 0x8f, 0x38, 0x82, 0x7a, 0x4e, 0xe6, 0xc6, 0xe1, 0x84, 0x50, 0x07, 0x0b, 0xc7, 0xed, + 0xc0, 0xe4, 0x03, 0x8c, 0xd9, 0x53, 0x69, 0xf1, 0x06, 0xf5, 0xb2, 0x51, 0xac, 0x13, 0x42, 0x9b, + 0x42, 0xd2, 0xc3, 0xfb, 0xc0, 0xf4, 0xb6, 0x71, 0x48, 0x1d, 0x96, 0x08, 0x1c, 0x90, 0x0b, 0x2c, + 0x6a, 0xcd, 0x26, 0x64, 0xc5, 0x9a, 0x2c, 0xc8, 0x63, 0x5f, 0x82, 0xb9, 0xfd, 0xae, 0x72, 0xee, + 0x60, 0xea, 0x3b, 0x22, 0x15, 0xef, 0x24, 0xd4, 0x55, 0xfa, 0x33, 0xb6, 0x21, 0xc9, 0x36, 0x93, + 0xc3, 0xe4, 0xed, 0x3e, 0x4f, 0x01, 0x9a, 0x7e, 0xe1, 0xd7, 0x30, 0x18, 0x91, 0x13, 0x82, 0x9f, + 0x0c, 0x00, 0x32, 0xf9, 0x70, 0xb1, 0xf8, 0xbd, 0x0b, 0xb3, 0x66, 0x36, 0xfa, 0x80, 0x2e, 0x67, + 0xa7, 0xb6, 0xfc, 0xfa, 0xeb, 0xcf, 0x77, 0xe5, 0x7b, 0xf0, 0x2e, 0x1a, 0x20, 0xef, 0xe8, 0x48, + 0x66, 0xf4, 0x18, 0x1d, 0xa9, 0x50, 0x1e, 0xc3, 0x0f, 0x06, 0x18, 0xeb, 0x59, 0xe2, 0xbe, 0xc2, + 0xff, 0x14, 0x2c, 0x73, 0x69, 0x60, 0xe1, 0xb9, 0x9c, 0xd4, 0xe6, 0xa4, 0xf6, 0x69, 0x58, 0x1f, + 0x44, 0x3b, 0x7c, 0x53, 0x06, 0xf5, 0x41, 0xf6, 0x10, 0xae, 0xf6, 0x1f, 0xfd, 0xa0, 0x09, 0x30, + 0x9f, 0xfc, 0x17, 0x2e, 0xed, 0xf7, 0x91, 0xf4, 0xdb, 0x82, 0x0f, 0x8a, 0xfd, 0x16, 0xef, 0x6a, + 0xba, 0xa9, 0x21, 0xdd, 0x62, 0xad, 0xcd, 0x93, 0xb3, 0xaa, 0x71, 0x7a, 0x56, 0x35, 0x7e, 0x9c, + 0x55, 0x8d, 0xb7, 0xe7, 0xd5, 0xd2, 0xe9, 0x79, 0xb5, 0xf4, 0xed, 0xbc, 0x5a, 0x7a, 0xb1, 0x1c, + 0x84, 0x62, 0x3b, 0x71, 0x2d, 0x8f, 0xed, 0xf4, 0x76, 0xd9, 0x5b, 0x9a, 0x97, 0x11, 0x41, 0xdd, + 0x93, 0x83, 0x9e, 0xce, 0xe2, 0xb0, 0x4d, 0xb8, 0x3b, 0x2a, 0x6f, 0x17, 0x7f, 0x07, 0x00, 0x00, + 0xff, 0xff, 0x06, 0xb5, 0xab, 0xe1, 0xf9, 0x06, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -289,6 +410,9 @@ type QueryClient interface { Subaccount(ctx context.Context, in *QueryGetSubaccountRequest, opts ...grpc.CallOption) (*QuerySubaccountResponse, error) // Queries a list of Subaccount items. SubaccountAll(ctx context.Context, in *QueryAllSubaccountRequest, opts ...grpc.CallOption) (*QuerySubaccountAllResponse, error) + // Queries information about whether withdrawal and transfers are blocked, and + // if so which block they are re-enabled on. + GetWithdrawalAndTransfersBlockedInfo(ctx context.Context, in *QueryGetWithdrawalAndTransfersBlockedInfoRequest, opts ...grpc.CallOption) (*QueryGetWithdrawalAndTransfersBlockedInfoResponse, error) } type queryClient struct { @@ -317,12 +441,24 @@ func (c *queryClient) SubaccountAll(ctx context.Context, in *QueryAllSubaccountR return out, nil } +func (c *queryClient) GetWithdrawalAndTransfersBlockedInfo(ctx context.Context, in *QueryGetWithdrawalAndTransfersBlockedInfoRequest, opts ...grpc.CallOption) (*QueryGetWithdrawalAndTransfersBlockedInfoResponse, error) { + out := new(QueryGetWithdrawalAndTransfersBlockedInfoResponse) + err := c.cc.Invoke(ctx, "/dydxprotocol.subaccounts.Query/GetWithdrawalAndTransfersBlockedInfo", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + // QueryServer is the server API for Query service. type QueryServer interface { // Queries a Subaccount by id Subaccount(context.Context, *QueryGetSubaccountRequest) (*QuerySubaccountResponse, error) // Queries a list of Subaccount items. SubaccountAll(context.Context, *QueryAllSubaccountRequest) (*QuerySubaccountAllResponse, error) + // Queries information about whether withdrawal and transfers are blocked, and + // if so which block they are re-enabled on. + GetWithdrawalAndTransfersBlockedInfo(context.Context, *QueryGetWithdrawalAndTransfersBlockedInfoRequest) (*QueryGetWithdrawalAndTransfersBlockedInfoResponse, error) } // UnimplementedQueryServer can be embedded to have forward compatible implementations. @@ -335,6 +471,9 @@ func (*UnimplementedQueryServer) Subaccount(ctx context.Context, req *QueryGetSu func (*UnimplementedQueryServer) SubaccountAll(ctx context.Context, req *QueryAllSubaccountRequest) (*QuerySubaccountAllResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method SubaccountAll not implemented") } +func (*UnimplementedQueryServer) GetWithdrawalAndTransfersBlockedInfo(ctx context.Context, req *QueryGetWithdrawalAndTransfersBlockedInfoRequest) (*QueryGetWithdrawalAndTransfersBlockedInfoResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method GetWithdrawalAndTransfersBlockedInfo not implemented") +} func RegisterQueryServer(s grpc1.Server, srv QueryServer) { s.RegisterService(&_Query_serviceDesc, srv) @@ -376,6 +515,24 @@ func _Query_SubaccountAll_Handler(srv interface{}, ctx context.Context, dec func return interceptor(ctx, in, info, handler) } +func _Query_GetWithdrawalAndTransfersBlockedInfo_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryGetWithdrawalAndTransfersBlockedInfoRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).GetWithdrawalAndTransfersBlockedInfo(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/dydxprotocol.subaccounts.Query/GetWithdrawalAndTransfersBlockedInfo", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).GetWithdrawalAndTransfersBlockedInfo(ctx, req.(*QueryGetWithdrawalAndTransfersBlockedInfoRequest)) + } + return interceptor(ctx, in, info, handler) +} + var _Query_serviceDesc = grpc.ServiceDesc{ ServiceName: "dydxprotocol.subaccounts.Query", HandlerType: (*QueryServer)(nil), @@ -388,6 +545,10 @@ var _Query_serviceDesc = grpc.ServiceDesc{ MethodName: "SubaccountAll", Handler: _Query_SubaccountAll_Handler, }, + { + MethodName: "GetWithdrawalAndTransfersBlockedInfo", + Handler: _Query_GetWithdrawalAndTransfersBlockedInfo_Handler, + }, }, Streams: []grpc.StreamDesc{}, Metadata: "dydxprotocol/subaccounts/query.proto", @@ -545,6 +706,67 @@ func (m *QuerySubaccountAllResponse) MarshalToSizedBuffer(dAtA []byte) (int, err return len(dAtA) - i, nil } +func (m *QueryGetWithdrawalAndTransfersBlockedInfoRequest) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryGetWithdrawalAndTransfersBlockedInfoRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryGetWithdrawalAndTransfersBlockedInfoRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func (m *QueryGetWithdrawalAndTransfersBlockedInfoResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryGetWithdrawalAndTransfersBlockedInfoResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryGetWithdrawalAndTransfersBlockedInfoResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.WithdrawalsAndTransfersUnblockedAtBlock != 0 { + i = encodeVarintQuery(dAtA, i, uint64(m.WithdrawalsAndTransfersUnblockedAtBlock)) + i-- + dAtA[i] = 0x18 + } + if m.ChainOutageSeenAtBlock != 0 { + i = encodeVarintQuery(dAtA, i, uint64(m.ChainOutageSeenAtBlock)) + i-- + dAtA[i] = 0x10 + } + if m.NegativeTncSubaccountSeenAtBlock != 0 { + i = encodeVarintQuery(dAtA, i, uint64(m.NegativeTncSubaccountSeenAtBlock)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + func encodeVarintQuery(dAtA []byte, offset int, v uint64) int { offset -= sovQuery(v) base := offset @@ -615,6 +837,33 @@ func (m *QuerySubaccountAllResponse) Size() (n int) { return n } +func (m *QueryGetWithdrawalAndTransfersBlockedInfoRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func (m *QueryGetWithdrawalAndTransfersBlockedInfoResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.NegativeTncSubaccountSeenAtBlock != 0 { + n += 1 + sovQuery(uint64(m.NegativeTncSubaccountSeenAtBlock)) + } + if m.ChainOutageSeenAtBlock != 0 { + n += 1 + sovQuery(uint64(m.ChainOutageSeenAtBlock)) + } + if m.WithdrawalsAndTransfersUnblockedAtBlock != 0 { + n += 1 + sovQuery(uint64(m.WithdrawalsAndTransfersUnblockedAtBlock)) + } + return n +} + func sovQuery(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } @@ -1011,6 +1260,163 @@ func (m *QuerySubaccountAllResponse) Unmarshal(dAtA []byte) error { } return nil } +func (m *QueryGetWithdrawalAndTransfersBlockedInfoRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryGetWithdrawalAndTransfersBlockedInfoRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryGetWithdrawalAndTransfersBlockedInfoRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryGetWithdrawalAndTransfersBlockedInfoResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryGetWithdrawalAndTransfersBlockedInfoResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryGetWithdrawalAndTransfersBlockedInfoResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field NegativeTncSubaccountSeenAtBlock", wireType) + } + m.NegativeTncSubaccountSeenAtBlock = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.NegativeTncSubaccountSeenAtBlock |= uint32(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field ChainOutageSeenAtBlock", wireType) + } + m.ChainOutageSeenAtBlock = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.ChainOutageSeenAtBlock |= uint32(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 3: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field WithdrawalsAndTransfersUnblockedAtBlock", wireType) + } + m.WithdrawalsAndTransfersUnblockedAtBlock = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.WithdrawalsAndTransfersUnblockedAtBlock |= uint32(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func skipQuery(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 diff --git a/protocol/x/subaccounts/types/query.pb.gw.go b/protocol/x/subaccounts/types/query.pb.gw.go index 7ff298553d..00ebde2bbe 100644 --- a/protocol/x/subaccounts/types/query.pb.gw.go +++ b/protocol/x/subaccounts/types/query.pb.gw.go @@ -145,6 +145,24 @@ func local_request_Query_SubaccountAll_0(ctx context.Context, marshaler runtime. } +func request_Query_GetWithdrawalAndTransfersBlockedInfo_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryGetWithdrawalAndTransfersBlockedInfoRequest + var metadata runtime.ServerMetadata + + msg, err := client.GetWithdrawalAndTransfersBlockedInfo(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_GetWithdrawalAndTransfersBlockedInfo_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryGetWithdrawalAndTransfersBlockedInfoRequest + var metadata runtime.ServerMetadata + + msg, err := server.GetWithdrawalAndTransfersBlockedInfo(ctx, &protoReq) + return msg, metadata, err + +} + // RegisterQueryHandlerServer registers the http handlers for service Query to "mux". // UnaryRPC :call QueryServer directly. // StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. @@ -197,6 +215,29 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv }) + mux.Handle("GET", pattern_Query_GetWithdrawalAndTransfersBlockedInfo_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_GetWithdrawalAndTransfersBlockedInfo_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_GetWithdrawalAndTransfersBlockedInfo_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + return nil } @@ -278,6 +319,26 @@ func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, clie }) + mux.Handle("GET", pattern_Query_GetWithdrawalAndTransfersBlockedInfo_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_GetWithdrawalAndTransfersBlockedInfo_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_GetWithdrawalAndTransfersBlockedInfo_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + return nil } @@ -285,10 +346,14 @@ var ( pattern_Query_Subaccount_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 3, 1, 0, 4, 1, 5, 4}, []string{"dydxprotocol", "subaccounts", "subaccount", "owner", "number"}, "", runtime.AssumeColonVerbOpt(false))) pattern_Query_SubaccountAll_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"dydxprotocol", "subaccounts", "subaccount"}, "", runtime.AssumeColonVerbOpt(false))) + + pattern_Query_GetWithdrawalAndTransfersBlockedInfo_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"dydxprotocol", "subaccounts", "withdrawals_and_transfers_blocked_info"}, "", runtime.AssumeColonVerbOpt(false))) ) var ( forward_Query_Subaccount_0 = runtime.ForwardResponseMessage forward_Query_SubaccountAll_0 = runtime.ForwardResponseMessage + + forward_Query_GetWithdrawalAndTransfersBlockedInfo_0 = runtime.ForwardResponseMessage ) diff --git a/protocol/x/subaccounts/types/update.go b/protocol/x/subaccounts/types/update.go index 5e907cca16..d700bb1541 100644 --- a/protocol/x/subaccounts/types/update.go +++ b/protocol/x/subaccounts/types/update.go @@ -2,6 +2,7 @@ package types import ( "math/big" + "time" errorsmod "cosmossdk.io/errors" ) @@ -122,3 +123,5 @@ func (u UpdateType) String() string { // blocks withdrawals and transfers will be blocked if a negative TNC subaccount is seen in state, // starting from the last block a negative TNC subaccount was seen. const WITHDRAWAL_AND_TRANSFERS_BLOCKED_AFTER_NEGATIVE_TNC_SUBACCOUNT_SEEN_BLOCKS = 50 + +const WITHDRAWAL_AND_TRANSFERS_BLOCKED_AFTER_CHAIN_OUTAGE_DURATION = 5 * time.Minute