@dydxprotocol/v4-client-js 1.5.0 → 1.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +3 -3
- package/__native__/__ios__/v4-native-client.js +10407 -7511
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/cosmos/bundle.d.ts +158 -158
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/cosmos/bundle.js +126 -126
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/accountplus/genesis.d.ts +44 -1
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/accountplus/genesis.js +75 -4
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/accountplus/models.d.ts +40 -0
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/accountplus/models.js +81 -0
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/accountplus/params.d.ts +20 -0
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/accountplus/params.js +64 -0
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/accountplus/query.d.ts +85 -0
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/accountplus/query.js +243 -0
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/accountplus/query.lcd.d.ts +11 -0
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/accountplus/query.lcd.js +28 -0
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/accountplus/query.rpc.Query.d.ts +24 -0
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/accountplus/query.rpc.Query.js +70 -0
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/accountplus/tx.d.ts +128 -0
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/accountplus/tx.js +313 -0
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/accountplus/tx.rpc.msg.d.ts +21 -0
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/accountplus/tx.rpc.msg.js +53 -0
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/affiliates/affiliates.d.ts +76 -0
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/affiliates/affiliates.js +197 -0
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/affiliates/genesis.d.ts +17 -0
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/affiliates/genesis.js +64 -0
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/affiliates/query.d.ts +161 -0
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/affiliates/query.js +327 -0
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/affiliates/query.rpc.Query.d.ts +28 -0
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/affiliates/query.rpc.Query.js +79 -0
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/affiliates/tx.d.ts +87 -0
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/affiliates/tx.js +239 -0
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/affiliates/tx.rpc.msg.d.ts +18 -0
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/affiliates/tx.rpc.msg.js +53 -0
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/bundle.d.ts +2929 -1778
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/bundle.js +321 -284
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/clob/order.d.ts +39 -0
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/clob/order.js +71 -2
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/clob/query.d.ts +87 -11
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/clob/query.js +157 -28
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/clob/streaming.d.ts +19 -0
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/clob/streaming.js +73 -0
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/indexer/events/events.d.ts +41 -0
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/indexer/events/events.js +107 -3
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/indexer/protocol/v1/vault.d.ts +17 -0
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/indexer/protocol/v1/vault.js +62 -0
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/lcd.d.ts +2 -0
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/lcd.js +7 -1
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/listing/params.d.ts +25 -0
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/listing/params.js +80 -0
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/listing/query.d.ts +25 -0
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/listing/query.js +64 -2
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/listing/query.lcd.d.ts +9 -0
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/listing/query.lcd.js +16 -0
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/listing/query.rpc.Query.d.ts +5 -1
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/listing/query.rpc.Query.js +10 -1
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/listing/tx.d.ts +81 -0
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/listing/tx.js +144 -2
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/listing/tx.rpc.msg.d.ts +7 -1
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/listing/tx.rpc.msg.js +13 -1
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/revshare/revshare.d.ts +37 -0
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/revshare/revshare.js +82 -2
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/revshare/tx.d.ts +28 -1
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/revshare/tx.js +72 -2
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/revshare/tx.rpc.msg.d.ts +4 -1
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/revshare/tx.rpc.msg.js +7 -1
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/rpc.query.d.ts +17 -1
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/rpc.query.js +3 -1
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/rpc.tx.d.ts +2 -0
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/rpc.tx.js +3 -1
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/stats/stats.d.ts +20 -0
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/stats/stats.js +46 -2
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/subaccounts/streaming.d.ts +86 -0
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/subaccounts/streaming.js +178 -0
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/vault/genesis.d.ts +69 -8
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/vault/genesis.js +153 -15
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/vault/params.d.ts +31 -0
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/vault/params.js +82 -2
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/vault/query.d.ts +214 -26
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/vault/query.js +385 -37
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/vault/query.lcd.d.ts +6 -2
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/vault/query.lcd.js +37 -5
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/vault/query.rpc.Query.d.ts +21 -5
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/vault/query.rpc.Query.js +46 -8
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/vault/share.d.ts +44 -4
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/vault/share.js +90 -2
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/vault/tx.d.ts +230 -45
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/vault/tx.js +476 -37
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/vault/tx.rpc.msg.d.ts +25 -7
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/vault/tx.rpc.msg.js +41 -11
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/vault/vault.d.ts +20 -0
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/vault/vault.js +63 -2
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/gogoproto/bundle.js +2 -2
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/google/bundle.d.ts +174 -174
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/google/bundle.js +12 -12
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/tendermint/bundle.d.ts +365 -365
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/tendermint/bundle.js +22 -22
- package/build/src/clients/composite-client.d.ts +11 -7
- package/build/src/clients/composite-client.js +23 -9
- package/build/src/clients/constants.d.ts +3 -0
- package/build/src/clients/constants.js +7 -2
- package/build/src/clients/helpers/chain-helpers.d.ts +1 -0
- package/build/src/clients/helpers/chain-helpers.js +11 -3
- package/build/src/clients/lib/registry.js +5 -1
- package/build/src/clients/modules/composer.d.ts +2 -0
- package/build/src/clients/modules/composer.js +31 -1
- package/build/src/clients/modules/get.d.ts +3 -1
- package/build/src/clients/modules/get.js +22 -4
- package/build/src/clients/modules/post.d.ts +4 -0
- package/build/src/clients/modules/post.js +16 -1
- package/build/src/clients/modules/proto-includes.d.ts +1 -0
- package/build/src/clients/modules/proto-includes.js +3 -2
- package/build/src/lib/helpers.d.ts +1 -0
- package/build/src/lib/helpers.js +11 -2
- package/build/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/src/clients/composite-client.ts +81 -29
- package/src/clients/constants.ts +7 -2
- package/src/clients/helpers/chain-helpers.ts +12 -2
- package/src/clients/lib/registry.ts +9 -0
- package/src/clients/modules/composer.ts +51 -0
- package/src/clients/modules/get.ts +45 -4
- package/src/clients/modules/post.ts +55 -0
- package/src/clients/modules/proto-includes.ts +1 -0
- package/src/lib/helpers.ts +10 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dydxprotocol/v4-client-js",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.1",
|
|
4
4
|
"description": "General client library for the new dYdX system (v4 decentralized)",
|
|
5
5
|
"main": "build/src/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"@cosmjs/tendermint-rpc": "^0.32.1",
|
|
40
40
|
"@cosmjs/utils": "^0.32.1",
|
|
41
41
|
"@osmonauts/lcd": "^0.6.0",
|
|
42
|
-
"@dydxprotocol/v4-proto": "
|
|
42
|
+
"@dydxprotocol/v4-proto": "7.0.0-dev.0",
|
|
43
43
|
"@scure/bip32": "^1.1.5",
|
|
44
44
|
"@scure/bip39": "^1.1.1",
|
|
45
45
|
"axios": "1.1.3",
|
|
@@ -13,6 +13,7 @@ import { parseUnits } from 'ethers';
|
|
|
13
13
|
import Long from 'long';
|
|
14
14
|
import protobuf from 'protobufjs';
|
|
15
15
|
|
|
16
|
+
import { bigIntToBytes } from '../lib/helpers';
|
|
16
17
|
import { isStatefulOrder, verifyOrderFlags } from '../lib/validation';
|
|
17
18
|
import { GovAddNewMarketParams, OrderFlags } from '../types';
|
|
18
19
|
import {
|
|
@@ -34,6 +35,7 @@ import {
|
|
|
34
35
|
calculateClientMetadata,
|
|
35
36
|
calculateConditionType,
|
|
36
37
|
calculateConditionalOrderTriggerSubticks,
|
|
38
|
+
calculateVaultQuantums,
|
|
37
39
|
} from './helpers/chain-helpers';
|
|
38
40
|
import { IndexerClient } from './indexer-client';
|
|
39
41
|
import { UserError } from './lib/errors';
|
|
@@ -708,35 +710,36 @@ export class CompositeClient {
|
|
|
708
710
|
}
|
|
709
711
|
|
|
710
712
|
/**
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
async batchCancelShortTermOrdersWithMarketId(
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
): Promise<BroadcastTxAsyncResponse | BroadcastTxSyncResponse | IndexedTx> {
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
713
|
+
* @description Batch cancel short term orders using marketId to clobPairId translation.
|
|
714
|
+
*
|
|
715
|
+
* @param subaccount The subaccount to cancel the order from
|
|
716
|
+
* @param shortTermOrders The list of short term order batches to cancel with marketId
|
|
717
|
+
* @param goodTilBlock The goodTilBlock of the order to cancel
|
|
718
|
+
* @returns The transaction hash.
|
|
719
|
+
*/
|
|
720
|
+
async batchCancelShortTermOrdersWithMarketId(
|
|
721
|
+
subaccount: SubaccountInfo,
|
|
722
|
+
shortTermOrders: OrderBatchWithMarketId[],
|
|
723
|
+
goodTilBlock: number,
|
|
724
|
+
broadcastMode?: BroadcastMode,
|
|
725
|
+
): Promise<BroadcastTxAsyncResponse | BroadcastTxSyncResponse | IndexedTx> {
|
|
726
|
+
const orderBatches = await Promise.all(
|
|
727
|
+
shortTermOrders.map(async ({ marketId, clobPairId, clientIds }) => ({
|
|
728
|
+
clobPairId: (
|
|
729
|
+
clobPairId ??
|
|
730
|
+
(await this.indexerClient.markets.getPerpetualMarkets(marketId)).markets[marketId]
|
|
731
|
+
).clobPairId,
|
|
732
|
+
clientIds,
|
|
733
|
+
})),
|
|
734
|
+
);
|
|
735
|
+
|
|
736
|
+
return this.validatorClient.post.batchCancelShortTermOrders(
|
|
737
|
+
subaccount,
|
|
738
|
+
orderBatches,
|
|
739
|
+
goodTilBlock,
|
|
740
|
+
broadcastMode,
|
|
741
|
+
);
|
|
742
|
+
}
|
|
740
743
|
|
|
741
744
|
/**
|
|
742
745
|
* @description Batch cancel short term orders using clobPairId.
|
|
@@ -1056,6 +1059,55 @@ async batchCancelShortTermOrdersWithMarketId(
|
|
|
1056
1059
|
return Buffer.from(signature).toString('base64');
|
|
1057
1060
|
}
|
|
1058
1061
|
|
|
1062
|
+
// vaults
|
|
1063
|
+
|
|
1064
|
+
async depositToMegavault(
|
|
1065
|
+
subaccount: SubaccountInfo,
|
|
1066
|
+
amountUsdc: number,
|
|
1067
|
+
broadcastMode?: BroadcastMode,
|
|
1068
|
+
): Promise<BroadcastTxAsyncResponse | BroadcastTxSyncResponse | IndexedTx> {
|
|
1069
|
+
return this.validatorClient.post.depositToMegavault(
|
|
1070
|
+
subaccount,
|
|
1071
|
+
bigIntToBytes(calculateVaultQuantums(amountUsdc)),
|
|
1072
|
+
broadcastMode,
|
|
1073
|
+
);
|
|
1074
|
+
}
|
|
1075
|
+
|
|
1076
|
+
depositToMegavaultMessage(subaccount: SubaccountInfo, amountUsdc: number): EncodeObject {
|
|
1077
|
+
return this.validatorClient.post.depositToMegavaultMsg(
|
|
1078
|
+
subaccount.address,
|
|
1079
|
+
subaccount.subaccountNumber,
|
|
1080
|
+
bigIntToBytes(calculateVaultQuantums(amountUsdc)),
|
|
1081
|
+
);
|
|
1082
|
+
}
|
|
1083
|
+
|
|
1084
|
+
async withdrawFromMegavault(
|
|
1085
|
+
subaccount: SubaccountInfo,
|
|
1086
|
+
shares: number,
|
|
1087
|
+
minAmount: number,
|
|
1088
|
+
broadcastMode?: BroadcastMode,
|
|
1089
|
+
): Promise<BroadcastTxAsyncResponse | BroadcastTxSyncResponse | IndexedTx> {
|
|
1090
|
+
return this.validatorClient.post.withdrawFromMegavault(
|
|
1091
|
+
subaccount,
|
|
1092
|
+
bigIntToBytes(BigInt(Math.floor(shares))),
|
|
1093
|
+
bigIntToBytes(calculateVaultQuantums(minAmount)),
|
|
1094
|
+
broadcastMode,
|
|
1095
|
+
);
|
|
1096
|
+
}
|
|
1097
|
+
|
|
1098
|
+
withdrawFromMegavaultMessage(
|
|
1099
|
+
subaccount: SubaccountInfo,
|
|
1100
|
+
shares: number,
|
|
1101
|
+
minAmount: number,
|
|
1102
|
+
): EncodeObject {
|
|
1103
|
+
return this.validatorClient.post.withdrawFromMegavaultMsg(
|
|
1104
|
+
subaccount.address,
|
|
1105
|
+
subaccount.subaccountNumber,
|
|
1106
|
+
bigIntToBytes(BigInt(Math.floor(shares))),
|
|
1107
|
+
bigIntToBytes(calculateVaultQuantums(minAmount)),
|
|
1108
|
+
);
|
|
1109
|
+
}
|
|
1110
|
+
|
|
1059
1111
|
/**
|
|
1060
1112
|
* @description Submit a governance proposal to add a new market.
|
|
1061
1113
|
*
|
package/src/clients/constants.ts
CHANGED
|
@@ -94,6 +94,10 @@ export const TYPE_URL_MSG_WITHDRAW_FROM_SUBACCOUNT =
|
|
|
94
94
|
'/dydxprotocol.sending.MsgWithdrawFromSubaccount';
|
|
95
95
|
export const TYPE_URL_MSG_DEPOSIT_TO_SUBACCOUNT = '/dydxprotocol.sending.MsgDepositToSubaccount';
|
|
96
96
|
|
|
97
|
+
// x/vault
|
|
98
|
+
export const TYPE_URL_MSG_DEPOSIT_TO_MEGAVAULT = '/dydxprotocol.vault.MsgDepositToMegavault';
|
|
99
|
+
export const TYPE_URL_MSG_WITHDRAW_FROM_MEGAVAULT = '/dydxprotocol.vault.MsgWithdrawFromMegavault';
|
|
100
|
+
|
|
97
101
|
// x/staking
|
|
98
102
|
export const TYPE_URL_MSG_DELEGATE = '/cosmos.staking.v1beta1.MsgDelegate';
|
|
99
103
|
export const TYPE_URL_MSG_UNDELEGATE = '/cosmos.staking.v1beta1.MsgUndelegate';
|
|
@@ -106,6 +110,7 @@ export const TYPE_URL_MSG_WITHDRAW_DELEGATOR_REWARD =
|
|
|
106
110
|
// The following are same across different networks / deployments.
|
|
107
111
|
export const GOV_MODULE_ADDRESS = 'dydx10d07y265gmmuvt4z0w9aw880jnsr700jnmapky';
|
|
108
112
|
export const DELAYMSG_MODULE_ADDRESS = 'dydx1mkkvp26dngu6n8rmalaxyp3gwkjuzztq5zx6tr';
|
|
113
|
+
export const MEGAVAULT_MODULE_ADDRESS = 'dydx18tkxrnrkqc2t0lr3zxr5g6a4hdvqksylxqje4r';
|
|
109
114
|
|
|
110
115
|
// ------------ Market Statistic Day Types ------------
|
|
111
116
|
export enum MarketStatisticDay {
|
|
@@ -177,8 +182,8 @@ export enum TimePeriod {
|
|
|
177
182
|
}
|
|
178
183
|
|
|
179
184
|
export enum PnlTickInterval {
|
|
180
|
-
HOUR =
|
|
181
|
-
day =
|
|
185
|
+
HOUR = 'hour',
|
|
186
|
+
day = 'day',
|
|
182
187
|
}
|
|
183
188
|
|
|
184
189
|
// ------------ API Defaults ------------
|
|
@@ -6,7 +6,11 @@ import { Order_ConditionType, Order_Side, Order_TimeInForce } from '../modules/p
|
|
|
6
6
|
import { OrderFlags } from '../types';
|
|
7
7
|
|
|
8
8
|
export function round(input: number, base: number): number {
|
|
9
|
-
return BigNumber(input)
|
|
9
|
+
return BigNumber(input)
|
|
10
|
+
.div(BigNumber(base))
|
|
11
|
+
.integerValue(BigNumber.ROUND_FLOOR)
|
|
12
|
+
.times(BigNumber(base))
|
|
13
|
+
.toNumber();
|
|
10
14
|
}
|
|
11
15
|
|
|
12
16
|
export function calculateQuantums(
|
|
@@ -14,13 +18,19 @@ export function calculateQuantums(
|
|
|
14
18
|
atomicResolution: number,
|
|
15
19
|
stepBaseQuantums: number,
|
|
16
20
|
): Long {
|
|
17
|
-
const rawQuantums = BigNumber(size).times(
|
|
21
|
+
const rawQuantums = BigNumber(size).times(
|
|
22
|
+
BigNumber(10).pow(BigNumber(atomicResolution).negated()),
|
|
23
|
+
);
|
|
18
24
|
const quantums = round(rawQuantums.toNumber(), stepBaseQuantums);
|
|
19
25
|
// stepBaseQuantums functions as minimum order size
|
|
20
26
|
const result = Math.max(quantums, stepBaseQuantums);
|
|
21
27
|
return Long.fromNumber(result);
|
|
22
28
|
}
|
|
23
29
|
|
|
30
|
+
export function calculateVaultQuantums(size: number): bigint {
|
|
31
|
+
return BigInt(BigNumber(size).times(1_000_000).toFixed(0, BigNumber.ROUND_FLOOR));
|
|
32
|
+
}
|
|
33
|
+
|
|
24
34
|
export function calculateSubticks(
|
|
25
35
|
price: number,
|
|
26
36
|
atomicResolution: number,
|
|
@@ -15,6 +15,10 @@ import {
|
|
|
15
15
|
MsgDepositToSubaccount,
|
|
16
16
|
} from '@dydxprotocol/v4-proto/src/codegen/dydxprotocol/sending/transfer';
|
|
17
17
|
import { MsgCreateTransfer } from '@dydxprotocol/v4-proto/src/codegen/dydxprotocol/sending/tx';
|
|
18
|
+
import {
|
|
19
|
+
MsgDepositToMegavault,
|
|
20
|
+
MsgWithdrawFromMegavault,
|
|
21
|
+
} from '@dydxprotocol/v4-proto/src/codegen/dydxprotocol/vault/tx';
|
|
18
22
|
|
|
19
23
|
import {
|
|
20
24
|
TYPE_URL_MSG_PLACE_ORDER,
|
|
@@ -28,6 +32,8 @@ import {
|
|
|
28
32
|
TYPE_URL_MSG_WITHDRAW_FROM_SUBACCOUNT,
|
|
29
33
|
TYPE_URL_MSG_DEPOSIT_TO_SUBACCOUNT,
|
|
30
34
|
TYPE_URL_BATCH_CANCEL,
|
|
35
|
+
TYPE_URL_MSG_DEPOSIT_TO_MEGAVAULT,
|
|
36
|
+
TYPE_URL_MSG_WITHDRAW_FROM_MEGAVAULT,
|
|
31
37
|
} from '../constants';
|
|
32
38
|
|
|
33
39
|
export const registry: ReadonlyArray<[string, GeneratedType]> = [];
|
|
@@ -49,6 +55,9 @@ export function generateRegistry(): Registry {
|
|
|
49
55
|
// prices
|
|
50
56
|
[TYPE_URL_MSG_CREATE_ORACLE_MARKET, MsgCreateOracleMarket as GeneratedType],
|
|
51
57
|
|
|
58
|
+
// vaults
|
|
59
|
+
[TYPE_URL_MSG_DEPOSIT_TO_MEGAVAULT, MsgDepositToMegavault as GeneratedType],
|
|
60
|
+
[TYPE_URL_MSG_WITHDRAW_FROM_MEGAVAULT, MsgWithdrawFromMegavault as GeneratedType],
|
|
52
61
|
// sending
|
|
53
62
|
[TYPE_URL_MSG_CREATE_TRANSFER, MsgCreateTransfer as GeneratedType],
|
|
54
63
|
[TYPE_URL_MSG_WITHDRAW_FROM_SUBACCOUNT, MsgWithdrawFromSubaccount as GeneratedType],
|
|
@@ -18,6 +18,10 @@ import { MsgDelayMessage } from '@dydxprotocol/v4-proto/src/codegen/dydxprotocol
|
|
|
18
18
|
import { PerpetualMarketType } from '@dydxprotocol/v4-proto/src/codegen/dydxprotocol/perpetuals/perpetual';
|
|
19
19
|
import { MsgCreatePerpetual } from '@dydxprotocol/v4-proto/src/codegen/dydxprotocol/perpetuals/tx';
|
|
20
20
|
import { MsgCreateOracleMarket } from '@dydxprotocol/v4-proto/src/codegen/dydxprotocol/prices/tx';
|
|
21
|
+
import {
|
|
22
|
+
MsgDepositToMegavault,
|
|
23
|
+
MsgWithdrawFromMegavault,
|
|
24
|
+
} from '@dydxprotocol/v4-proto/src/codegen/dydxprotocol/vault/tx';
|
|
21
25
|
import { MsgSend } from 'cosmjs-types/cosmos/bank/v1beta1/tx';
|
|
22
26
|
import { Coin } from 'cosmjs-types/cosmos/base/v1beta1/coin';
|
|
23
27
|
import { Any } from 'cosmjs-types/google/protobuf/any';
|
|
@@ -43,6 +47,8 @@ import {
|
|
|
43
47
|
TYPE_URL_MSG_UNDELEGATE,
|
|
44
48
|
TYPE_URL_MSG_WITHDRAW_DELEGATOR_REWARD,
|
|
45
49
|
TYPE_URL_BATCH_CANCEL,
|
|
50
|
+
TYPE_URL_MSG_DEPOSIT_TO_MEGAVAULT,
|
|
51
|
+
TYPE_URL_MSG_WITHDRAW_FROM_MEGAVAULT,
|
|
46
52
|
} from '../constants';
|
|
47
53
|
import { DenomConfig } from '../types';
|
|
48
54
|
import {
|
|
@@ -445,6 +451,51 @@ export class Composer {
|
|
|
445
451
|
};
|
|
446
452
|
}
|
|
447
453
|
|
|
454
|
+
// ------------ x/vault ------------
|
|
455
|
+
public composeMsgDepositToMegavault(
|
|
456
|
+
address: string,
|
|
457
|
+
subaccountNumber: number,
|
|
458
|
+
quoteQuantums: Uint8Array,
|
|
459
|
+
): EncodeObject {
|
|
460
|
+
const subaccountId: SubaccountId = {
|
|
461
|
+
owner: address,
|
|
462
|
+
number: subaccountNumber,
|
|
463
|
+
};
|
|
464
|
+
|
|
465
|
+
const msg: MsgDepositToMegavault = {
|
|
466
|
+
quoteQuantums,
|
|
467
|
+
subaccountId,
|
|
468
|
+
};
|
|
469
|
+
|
|
470
|
+
return {
|
|
471
|
+
typeUrl: TYPE_URL_MSG_DEPOSIT_TO_MEGAVAULT,
|
|
472
|
+
value: msg,
|
|
473
|
+
};
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
public composeMsgWithdrawFromMegavault(
|
|
477
|
+
address: string,
|
|
478
|
+
subaccountNumber: number,
|
|
479
|
+
shares: Uint8Array,
|
|
480
|
+
minQuoteQuantums: Uint8Array,
|
|
481
|
+
): EncodeObject {
|
|
482
|
+
const subaccountId: SubaccountId = {
|
|
483
|
+
owner: address,
|
|
484
|
+
number: subaccountNumber,
|
|
485
|
+
};
|
|
486
|
+
|
|
487
|
+
const msg: MsgWithdrawFromMegavault = {
|
|
488
|
+
minQuoteQuantums,
|
|
489
|
+
shares: { numShares: shares },
|
|
490
|
+
subaccountId,
|
|
491
|
+
};
|
|
492
|
+
|
|
493
|
+
return {
|
|
494
|
+
typeUrl: TYPE_URL_MSG_WITHDRAW_FROM_MEGAVAULT,
|
|
495
|
+
value: msg,
|
|
496
|
+
};
|
|
497
|
+
}
|
|
498
|
+
|
|
448
499
|
// ------------ x/staking ------------
|
|
449
500
|
public composeMsgDelegate(delegator: string, validator: string, amount: Coin): EncodeObject {
|
|
450
501
|
const msg: MsgDelegate = {
|
|
@@ -13,6 +13,7 @@ import { Any } from 'cosmjs-types/google/protobuf/any';
|
|
|
13
13
|
import Long from 'long';
|
|
14
14
|
import protobuf from 'protobufjs';
|
|
15
15
|
|
|
16
|
+
import { bigIntToBytes } from '../../lib/helpers';
|
|
16
17
|
import { PAGE_REQUEST } from '../constants';
|
|
17
18
|
import { UnexpectedClientError } from '../lib/errors';
|
|
18
19
|
import {
|
|
@@ -29,6 +30,7 @@ import {
|
|
|
29
30
|
StakingModule,
|
|
30
31
|
StatsModule,
|
|
31
32
|
SubaccountsModule,
|
|
33
|
+
VaultModule,
|
|
32
34
|
} from './proto-includes';
|
|
33
35
|
import { TendermintClient } from './tendermintClient';
|
|
34
36
|
|
|
@@ -415,8 +417,7 @@ export class Get {
|
|
|
415
417
|
const requestData = Uint8Array.from(
|
|
416
418
|
DistributionModule.QueryDelegationTotalRewardsRequest.encode({
|
|
417
419
|
delegatorAddress,
|
|
418
|
-
})
|
|
419
|
-
.finish(),
|
|
420
|
+
}).finish(),
|
|
420
421
|
);
|
|
421
422
|
|
|
422
423
|
const data: Uint8Array = await this.sendQuery(
|
|
@@ -491,9 +492,13 @@ export class Get {
|
|
|
491
492
|
return GovV1Module.QueryProposalsResponse.decode(data);
|
|
492
493
|
}
|
|
493
494
|
|
|
494
|
-
async getWithdrawalAndTransferGatingStatus(
|
|
495
|
+
async getWithdrawalAndTransferGatingStatus(
|
|
496
|
+
perpetualId: number,
|
|
497
|
+
): Promise<SubaccountsModule.QueryGetWithdrawalAndTransfersBlockedInfoResponse> {
|
|
495
498
|
const requestData = Uint8Array.from(
|
|
496
|
-
SubaccountsModule.QueryGetWithdrawalAndTransfersBlockedInfoRequest.encode({
|
|
499
|
+
SubaccountsModule.QueryGetWithdrawalAndTransfersBlockedInfoRequest.encode({
|
|
500
|
+
perpetualId,
|
|
501
|
+
}).finish(),
|
|
497
502
|
);
|
|
498
503
|
|
|
499
504
|
const data = await this.sendQuery(
|
|
@@ -518,6 +523,42 @@ export class Get {
|
|
|
518
523
|
return RateLimitModule.QueryCapacityByDenomResponse.decode(data);
|
|
519
524
|
}
|
|
520
525
|
|
|
526
|
+
async getMegavaultOwnerShares(
|
|
527
|
+
address: string,
|
|
528
|
+
): Promise<VaultModule.QueryMegavaultOwnerSharesResponse> {
|
|
529
|
+
const requestData: Uint8Array = Uint8Array.from(
|
|
530
|
+
VaultModule.QueryMegavaultOwnerSharesRequest.encode({
|
|
531
|
+
address,
|
|
532
|
+
}).finish(),
|
|
533
|
+
);
|
|
534
|
+
|
|
535
|
+
const data: Uint8Array = await this.sendQuery(
|
|
536
|
+
'/dydxprotocol.vault.Query/MegavaultOwnerShares',
|
|
537
|
+
requestData,
|
|
538
|
+
);
|
|
539
|
+
|
|
540
|
+
return VaultModule.QueryMegavaultOwnerSharesResponse.decode(data);
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
async getMegavaultWithdrawalInfo(
|
|
544
|
+
sharesToWithdraw: bigint,
|
|
545
|
+
): Promise<VaultModule.QueryMegavaultWithdrawalInfoResponse> {
|
|
546
|
+
const requestData: Uint8Array = Uint8Array.from(
|
|
547
|
+
VaultModule.QueryMegavaultWithdrawalInfoRequest.encode({
|
|
548
|
+
sharesToWithdraw: {
|
|
549
|
+
numShares: bigIntToBytes(sharesToWithdraw),
|
|
550
|
+
},
|
|
551
|
+
}).finish(),
|
|
552
|
+
);
|
|
553
|
+
|
|
554
|
+
const data: Uint8Array = await this.sendQuery(
|
|
555
|
+
'/dydxprotocol.vault.Query/MegavaultWithdrawalInfo',
|
|
556
|
+
requestData,
|
|
557
|
+
);
|
|
558
|
+
|
|
559
|
+
return VaultModule.QueryMegavaultWithdrawalInfoResponse.decode(data);
|
|
560
|
+
}
|
|
561
|
+
|
|
521
562
|
private async sendQuery(requestUrl: string, requestData: Uint8Array): Promise<Uint8Array> {
|
|
522
563
|
// eslint-disable-next-line max-len
|
|
523
564
|
const resp: QueryAbciResponse = await this.stargateQueryClient.queryAbci(
|
|
@@ -812,4 +812,59 @@ export class Post {
|
|
|
812
812
|
withdrawDelegatorRewardMsg(delegator: string, validator: string): EncodeObject {
|
|
813
813
|
return this.composer.composeMsgWithdrawDelegatorReward(delegator, validator);
|
|
814
814
|
}
|
|
815
|
+
|
|
816
|
+
// vaults
|
|
817
|
+
async depositToMegavault(
|
|
818
|
+
subaccount: SubaccountInfo,
|
|
819
|
+
quoteQuantums: Uint8Array,
|
|
820
|
+
broadcastMode?: BroadcastMode,
|
|
821
|
+
): Promise<BroadcastTxAsyncResponse | BroadcastTxSyncResponse | IndexedTx> {
|
|
822
|
+
const msg = await this.depositToMegavaultMsg(
|
|
823
|
+
subaccount.address,
|
|
824
|
+
subaccount.subaccountNumber,
|
|
825
|
+
quoteQuantums,
|
|
826
|
+
);
|
|
827
|
+
return this.send(
|
|
828
|
+
subaccount.wallet,
|
|
829
|
+
() => Promise.resolve([msg]),
|
|
830
|
+
false,
|
|
831
|
+
undefined,
|
|
832
|
+
undefined,
|
|
833
|
+
broadcastMode,
|
|
834
|
+
);
|
|
835
|
+
}
|
|
836
|
+
|
|
837
|
+
depositToMegavaultMsg(
|
|
838
|
+
...args: Parameters<Composer['composeMsgDepositToMegavault']>
|
|
839
|
+
): EncodeObject {
|
|
840
|
+
return this.composer.composeMsgDepositToMegavault(...args);
|
|
841
|
+
}
|
|
842
|
+
|
|
843
|
+
async withdrawFromMegavault(
|
|
844
|
+
subaccount: SubaccountInfo,
|
|
845
|
+
shares: Uint8Array,
|
|
846
|
+
minQuoteQuantums: Uint8Array,
|
|
847
|
+
broadcastMode?: BroadcastMode,
|
|
848
|
+
): Promise<BroadcastTxAsyncResponse | BroadcastTxSyncResponse | IndexedTx> {
|
|
849
|
+
const msg = await this.withdrawFromMegavaultMsg(
|
|
850
|
+
subaccount.address,
|
|
851
|
+
subaccount.subaccountNumber,
|
|
852
|
+
shares,
|
|
853
|
+
minQuoteQuantums,
|
|
854
|
+
);
|
|
855
|
+
return this.send(
|
|
856
|
+
subaccount.wallet,
|
|
857
|
+
() => Promise.resolve([msg]),
|
|
858
|
+
false,
|
|
859
|
+
undefined,
|
|
860
|
+
undefined,
|
|
861
|
+
broadcastMode,
|
|
862
|
+
);
|
|
863
|
+
}
|
|
864
|
+
|
|
865
|
+
withdrawFromMegavaultMsg(
|
|
866
|
+
...args: Parameters<Composer['composeMsgWithdrawFromMegavault']>
|
|
867
|
+
): EncodeObject {
|
|
868
|
+
return this.composer.composeMsgWithdrawFromMegavault(...args);
|
|
869
|
+
}
|
|
815
870
|
}
|
|
@@ -11,6 +11,7 @@ export * as RewardsModule from '@dydxprotocol/v4-proto/src/codegen/dydxprotocol/
|
|
|
11
11
|
export * as StakingModule from '@dydxprotocol/v4-proto/src/codegen/cosmos/staking/v1beta1/query';
|
|
12
12
|
export * as BridgeModule from '@dydxprotocol/v4-proto/src/codegen/dydxprotocol/bridge/query';
|
|
13
13
|
export * as DistributionModule from '@dydxprotocol/v4-proto/src/codegen/cosmos/distribution/v1beta1/query';
|
|
14
|
+
export * as VaultModule from '@dydxprotocol/v4-proto/src/codegen/dydxprotocol/vault/query';
|
|
14
15
|
|
|
15
16
|
export * from '@dydxprotocol/v4-proto/src/codegen/cosmos/base/abci/v1beta1/abci';
|
|
16
17
|
export * from '@dydxprotocol/v4-proto/src/codegen/cosmos/gov/v1/gov';
|
package/src/lib/helpers.ts
CHANGED
|
@@ -49,6 +49,16 @@ function toBigInt(u: Uint8Array): BigInt {
|
|
|
49
49
|
return negated ? -abs : abs;
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
+
export function bigIntToBytes(value: bigint): Uint8Array {
|
|
53
|
+
const absoluteValue = value < 0 ? value * BigInt(-1) : value;
|
|
54
|
+
const nonPaddedHexValue = absoluteValue.toString(16);
|
|
55
|
+
const paddedHexValue =
|
|
56
|
+
nonPaddedHexValue.length % 2 === 0 ? nonPaddedHexValue : `0${nonPaddedHexValue}`;
|
|
57
|
+
const numberBytes = Buffer.from(paddedHexValue, 'hex');
|
|
58
|
+
const signedBytes = Uint8Array.of(value < 0 ? 3 : 2, ...numberBytes);
|
|
59
|
+
return signedBytes;
|
|
60
|
+
}
|
|
61
|
+
|
|
52
62
|
export enum ByteArrayEncoding {
|
|
53
63
|
HEX = 'hex',
|
|
54
64
|
BIGINT = 'bigint',
|