Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions v4-client-js/src/clients/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ export const TYPE_URL_MSG_CANCEL_ORDER = '/dydxprotocol.clob.MsgCancelOrder';
export const TYPE_URL_BATCH_CANCEL = '/dydxprotocol.clob.MsgBatchCancel';
export const TYPE_URL_MSG_CREATE_CLOB_PAIR = '/dydxprotocol.clob.MsgCreateClobPair';
export const TYPE_URL_MSG_UPDATE_CLOB_PAIR = '/dydxprotocol.clob.MsgUpdateClobPair';
export const TYPE_URL_MSG_UPDATE_LEVERAGE = '/dydxprotocol.clob.MsgUpdateLeverage';

// x/delaymsg
export const TYPE_URL_MSG_DELAY_MESSAGE = '/dydxprotocol.delaymsg.MsgDelayMessage';
Expand Down
9 changes: 7 additions & 2 deletions v4-client-js/src/clients/lib/registry.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import { GeneratedType, Registry } from '@cosmjs/proto-signing';
import { defaultRegistryTypes } from '@cosmjs/stargate';
import { MsgAddAuthenticator, MsgRemoveAuthenticator } from '@dydxprotocol/v4-proto/src/codegen/dydxprotocol/accountplus/tx';
import {
MsgAddAuthenticator,
MsgRemoveAuthenticator,
} from '@dydxprotocol/v4-proto/src/codegen/dydxprotocol/accountplus/tx';
import { MsgRegisterAffiliate } from '@dydxprotocol/v4-proto/src/codegen/dydxprotocol/affiliates/tx';
import {
MsgPlaceOrder,
MsgCancelOrder,
MsgCreateClobPair,
MsgUpdateClobPair,
MsgBatchCancel,
MsgUpdateLeverage,
} from '@dydxprotocol/v4-proto/src/codegen/dydxprotocol/clob/tx';
import { MsgDelayMessage } from '@dydxprotocol/v4-proto/src/codegen/dydxprotocol/delaymsg/tx';
import { MsgCreateMarketPermissionless } from '@dydxprotocol/v4-proto/src/codegen/dydxprotocol/listing/tx';
Expand Down Expand Up @@ -41,6 +45,7 @@ import {
TYPE_URL_MSG_CREATE_MARKET_PERMISSIONLESS,
TYPE_URL_MSG_ADD_AUTHENTICATOR,
TYPE_URL_MSG_REMOVE_AUTHENTICATOR,
TYPE_URL_MSG_UPDATE_LEVERAGE,
} from '../constants';

export const registry: ReadonlyArray<[string, GeneratedType]> = [];
Expand All @@ -52,6 +57,7 @@ export function generateRegistry(): Registry {
[TYPE_URL_BATCH_CANCEL, MsgBatchCancel as GeneratedType],
[TYPE_URL_MSG_CREATE_CLOB_PAIR, MsgCreateClobPair as GeneratedType],
[TYPE_URL_MSG_UPDATE_CLOB_PAIR, MsgUpdateClobPair as GeneratedType],
[TYPE_URL_MSG_UPDATE_LEVERAGE, MsgUpdateLeverage as GeneratedType],

// delaymsg
[TYPE_URL_MSG_DELAY_MESSAGE, MsgDelayMessage as GeneratedType],
Expand All @@ -77,7 +83,6 @@ export function generateRegistry(): Registry {
// affiliates
[TYPE_URL_MSG_REGISTER_AFFILIATE, MsgRegisterAffiliate as GeneratedType],


// authentication
[TYPE_URL_MSG_ADD_AUTHENTICATOR, MsgAddAuthenticator as GeneratedType],
[TYPE_URL_MSG_REMOVE_AUTHENTICATOR, MsgRemoveAuthenticator as GeneratedType],
Expand Down
48 changes: 36 additions & 12 deletions v4-client-js/src/clients/modules/composer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,18 @@ import {
MsgDelegate,
MsgUndelegate,
} from '@dydxprotocol/v4-proto/src/codegen/cosmos/staking/v1beta1/tx';
import { MsgAddAuthenticator, MsgRemoveAuthenticator } from '@dydxprotocol/v4-proto/src/codegen/dydxprotocol/accountplus/tx';
import {
MsgAddAuthenticator,
MsgRemoveAuthenticator,
} from '@dydxprotocol/v4-proto/src/codegen/dydxprotocol/accountplus/tx';
import { MsgRegisterAffiliate } from '@dydxprotocol/v4-proto/src/codegen/dydxprotocol/affiliates/tx';
import { ClobPair_Status } from '@dydxprotocol/v4-proto/src/codegen/dydxprotocol/clob/clob_pair';
import {
LeverageEntry,
MsgBatchCancel,
MsgCreateClobPair,
MsgUpdateClobPair,
MsgUpdateLeverage,
OrderBatch,
} from '@dydxprotocol/v4-proto/src/codegen/dydxprotocol/clob/tx';
import { MsgDelayMessage } from '@dydxprotocol/v4-proto/src/codegen/dydxprotocol/delaymsg/tx';
Expand Down Expand Up @@ -56,6 +61,7 @@ import {
TYPE_URL_MSG_ADD_AUTHENTICATOR,
TYPE_URL_MSG_REMOVE_AUTHENTICATOR,
AuthenticatorType,
TYPE_URL_MSG_UPDATE_LEVERAGE,
} from '../constants';
import { DenomConfig, ITwapParameters, IBuilderCodeParameters } from '../types';
import {
Expand Down Expand Up @@ -97,7 +103,7 @@ export class Composer {
conditionalOrderTriggerSubticks: Long = Long.fromInt(0),
twapParameters?: ITwapParameters,
builderCodeParameters?: IBuilderCodeParameters,
orderRouterAddress: string = "",
orderRouterAddress: string = '',
): EncodeObject {
this.validateGoodTilBlockAndTime(orderFlags, goodTilBlock, goodTilBlockTime);

Expand Down Expand Up @@ -252,6 +258,27 @@ export class Composer {
};
}

public composeMsgUpdateLeverage(
address: string,
subaccountNumber: number,
entries: LeverageEntry[],
): EncodeObject {
const subaccountId: SubaccountId = {
owner: address,
number: subaccountNumber,
};

const msg: MsgUpdateLeverage = {
subaccountId,
clobPairLeverage: entries,
};

return {
typeUrl: TYPE_URL_MSG_UPDATE_LEVERAGE,
value: msg,
};
}

// ------------ x/sending ------------
public composeMsgTransfer(
address: string,
Expand Down Expand Up @@ -577,13 +604,13 @@ export class Composer {

const msg: MsgCreateMarketPermissionless = {
ticker,
subaccountId
subaccountId,
};

return {
typeUrl: TYPE_URL_MSG_CREATE_MARKET_PERMISSIONLESS,
value: msg,
}
};
}

// ----------- x/accountplus --------
Expand All @@ -597,27 +624,24 @@ export class Composer {
sender: address,
authenticatorType,
data,
}
};

return {
typeUrl: TYPE_URL_MSG_ADD_AUTHENTICATOR,
value: msg,
}
};
}

public composeMsgRemoveAuthenticator(
address: string,
id: Long,
): EncodeObject {
public composeMsgRemoveAuthenticator(address: string, id: Long): EncodeObject {
const msg: MsgRemoveAuthenticator = {
sender: address,
id,
}
};

return {
typeUrl: TYPE_URL_MSG_REMOVE_AUTHENTICATOR,
value: msg,
}
};
}

// ------------ util ------------
Expand Down
16 changes: 16 additions & 0 deletions v4-client-js/src/clients/modules/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,22 @@ export class Get {
return ClobModule.QueryEquityTierLimitConfigurationResponse.decode(data);
}

/**
* @description Get user leverage settings for a given subaccount
* @returns User set leverage for all clob pairs
*/
async getPerpetualMarketsLeverage(
address: string,
subaccountNumber: number,
): Promise<ClobModule.QueryLeverageResponse> {
const requestData: Uint8Array = Uint8Array.from(
ClobModule.QueryLeverageRequest.encode({ owner: address, number: subaccountNumber }).finish(),
);

const data: Uint8Array = await this.sendQuery('/dydxprotocol.clob.Query/Leverage', requestData);
return ClobModule.QueryLeverageResponse.decode(data);
}

/**
*
* @description Get all delegations from a delegator.
Expand Down
33 changes: 33 additions & 0 deletions v4-client-js/src/clients/modules/post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import {
MsgCancelOrder,
Order_ConditionType,
OrderBatch,
LeverageEntry,
} from './proto-includes';

// Required for encoding and decoding queries that are of type Long.
Expand Down Expand Up @@ -628,6 +629,38 @@ export class Post {
});
}

async updatePerpetualMarketsLeverage(
subaccount: SubaccountInfo,
address: string,
entries: LeverageEntry[],
broadcastMode?: BroadcastMode,
): Promise<BroadcastTxAsyncResponse | BroadcastTxSyncResponse | IndexedTx> {
const msg = await this.updatePerpetualMarketsLeverageMsg(subaccount, address, entries);
return this.send(
subaccount,
() => Promise.resolve([msg]),
false,
undefined,
undefined,
broadcastMode,
);
}

async updatePerpetualMarketsLeverageMsg(
subaccount: SubaccountInfo,
address: string,
entries: LeverageEntry[],
): Promise<EncodeObject> {
return new Promise((resolve) => {
const msg = this.composer.composeMsgUpdateLeverage(
address,
subaccount.subaccountNumber,
entries,
);
resolve(msg);
});
}

async transfer(
subaccount: SubaccountInfo,
recipientAddress: string,
Expand Down
Loading