@dydxprotocol/v4-client-js 1.16.1 → 1.16.3
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 +2 -2
- package/build/examples/constants.d.ts +0 -1
- package/build/examples/constants.js +2 -3
- 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/blocktime/params.d.ts +0 -21
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/blocktime/params.js +2 -37
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/blocktime/tx.d.ts +1 -34
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/blocktime/tx.js +2 -72
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/blocktime/tx.rpc.msg.d.ts +1 -4
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/blocktime/tx.rpc.msg.js +1 -7
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/bundle.d.ts +1711 -2021
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/bundle.js +266 -272
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/clob/order_removals.d.ts +0 -5
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/clob/order_removals.js +1 -11
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/clob/query.d.ts +0 -31
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/clob/query.js +5 -94
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/clob/query.lcd.d.ts +1 -2
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/clob/query.lcd.js +1 -7
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/clob/query.rpc.Query.d.ts +1 -5
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/clob/query.rpc.Query.js +1 -10
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/clob/streaming.d.ts +1 -6
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/clob/streaming.js +2 -19
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/indexer/events/events.d.ts +6 -79
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/indexer/events/events.js +2 -78
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/lcd.d.ts +0 -1
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/lcd.js +1 -4
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/listing/genesis.d.ts +0 -4
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/listing/genesis.js +2 -11
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/listing/query.lcd.d.ts +1 -2
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/listing/query.lcd.js +1 -7
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/listing/tx.d.ts +0 -39
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/listing/tx.js +2 -72
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/listing/tx.rpc.msg.d.ts +1 -7
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/listing/tx.rpc.msg.js +1 -7
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/perpetuals/query.d.ts +0 -25
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/perpetuals/query.js +2 -64
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/perpetuals/query.lcd.d.ts +1 -2
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/perpetuals/query.lcd.js +1 -7
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/perpetuals/query.rpc.Query.d.ts +1 -5
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/perpetuals/query.rpc.Query.js +1 -10
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/prices/market_param.d.ts +0 -8
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/prices/market_param.js +1 -1
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/prices/market_price.d.ts +0 -3
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/prices/market_price.js +1 -1
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/prices/query.d.ts +0 -34
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/prices/query.js +2 -64
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/prices/query.lcd.d.ts +1 -2
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/prices/query.lcd.js +1 -7
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/prices/query.rpc.Query.d.ts +1 -5
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/prices/query.rpc.Query.js +1 -10
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/revshare/query.d.ts +1 -25
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/revshare/query.js +2 -63
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/revshare/query.lcd.d.ts +1 -2
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/revshare/query.lcd.js +1 -7
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/revshare/query.rpc.Query.d.ts +1 -5
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/revshare/query.rpc.Query.js +1 -10
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/revshare/tx.rpc.msg.d.ts +1 -1
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/rpc.query.d.ts +0 -4
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/subaccounts/streaming.d.ts +1 -1
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/subaccounts/streaming.js +5 -5
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/vault/params.d.ts +0 -21
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/vault/params.js +3 -55
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/vault/query.d.ts +6 -1
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/vault/query.js +12 -4
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/vault/query.lcd.d.ts +2 -1
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/vault/query.lcd.js +13 -1
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/vault/tx.d.ts +24 -51
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/vault/tx.js +46 -98
- 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 +21 -21
- package/build/src/clients/composite-client.d.ts +3 -12
- package/build/src/clients/composite-client.js +8 -22
- package/build/src/clients/constants.d.ts +0 -10
- package/build/src/clients/constants.js +4 -17
- package/build/src/clients/lib/registry.js +22 -26
- package/build/src/clients/modules/account.js +3 -2
- package/build/src/clients/modules/composer.d.ts +0 -3
- package/build/src/clients/modules/composer.js +1 -23
- package/build/src/clients/modules/get.d.ts +0 -2
- package/build/src/clients/modules/get.js +1 -9
- package/build/src/clients/modules/local-wallet.d.ts +4 -4
- package/build/src/clients/modules/local-wallet.js +3 -3
- package/build/src/clients/modules/post.d.ts +2 -4
- package/build/src/clients/modules/post.js +6 -15
- package/build/src/clients/modules/signer.d.ts +3 -5
- package/build/src/clients/modules/signer.js +14 -53
- package/build/src/clients/types.d.ts +0 -1
- package/build/src/clients/types.js +1 -1
- package/build/tsconfig.tsbuildinfo +1 -1
- package/examples/constants.ts +0 -2
- package/package.json +2 -2
- package/src/clients/composite-client.ts +3 -40
- package/src/clients/constants.ts +1 -16
- package/src/clients/lib/registry.ts +0 -8
- package/src/clients/modules/account.ts +2 -1
- package/src/clients/modules/composer.ts +0 -39
- package/src/clients/modules/get.ts +0 -16
- package/src/clients/modules/local-wallet.ts +6 -6
- package/src/clients/modules/post.ts +1 -44
- package/src/clients/modules/signer.ts +13 -79
- package/src/clients/types.ts +0 -1
- package/build/examples/permissioned_keys_example.d.ts +0 -1
- package/build/examples/permissioned_keys_example.js +0 -85
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/affiliates/query.lcd.d.ts +0 -12
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/affiliates/query.lcd.js +0 -34
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/clob/finalize_block.d.ts +0 -23
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/clob/finalize_block.js +0 -64
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/prices/streaming.d.ts +0 -23
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/prices/streaming.js +0 -81
- package/examples/permissioned_keys_example.ts +0 -110
package/examples/constants.ts
CHANGED
|
@@ -15,8 +15,6 @@ export const DYDX_LOCAL_ADDRESS = 'dydx199tqg4wdlnu4qjlxchpd7seg454937hjrknju4';
|
|
|
15
15
|
export const DYDX_LOCAL_MNEMONIC =
|
|
16
16
|
'merge panther lobster crazy road hollow amused security before critic about cliff exhibit cause coyote talent happy where lion river tobacco option coconut small';
|
|
17
17
|
|
|
18
|
-
export const DYDX_TEST_MNEMONIC_2 = 'movie yard still copper exile wear brisk chest ride dizzy novel future menu finish radar lunar claim hub middle force turtle mouse frequent embark';
|
|
19
|
-
|
|
20
18
|
export const MARKET_BTC_USD: string = 'BTC-USD';
|
|
21
19
|
export const PERPETUAL_PAIR_BTC_USD: number = 0;
|
|
22
20
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dydxprotocol/v4-client-js",
|
|
3
|
-
"version": "1.16.
|
|
3
|
+
"version": "1.16.3",
|
|
4
4
|
"description": "General client library for the new dYdX system (v4 decentralized)",
|
|
5
5
|
"main": "build/src/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -38,8 +38,8 @@
|
|
|
38
38
|
"@cosmjs/stargate": "^0.32.1",
|
|
39
39
|
"@cosmjs/tendermint-rpc": "^0.32.1",
|
|
40
40
|
"@cosmjs/utils": "^0.32.1",
|
|
41
|
-
"@dydxprotocol/v4-proto": "8.0.0",
|
|
42
41
|
"@osmonauts/lcd": "^0.6.0",
|
|
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",
|
|
@@ -5,7 +5,6 @@ import {
|
|
|
5
5
|
BroadcastTxAsyncResponse,
|
|
6
6
|
BroadcastTxSyncResponse,
|
|
7
7
|
} from '@cosmjs/tendermint-rpc/build/tendermint37';
|
|
8
|
-
import { GetAuthenticatorsResponse } from '@dydxprotocol/v4-proto/src/codegen/dydxprotocol/accountplus/query';
|
|
9
8
|
import {
|
|
10
9
|
Order_ConditionType,
|
|
11
10
|
Order_TimeInForce,
|
|
@@ -18,7 +17,6 @@ import { bigIntToBytes } from '../lib/helpers';
|
|
|
18
17
|
import { isStatefulOrder, verifyOrderFlags } from '../lib/validation';
|
|
19
18
|
import { GovAddNewMarketParams, OrderFlags } from '../types';
|
|
20
19
|
import {
|
|
21
|
-
AuthenticatorType,
|
|
22
20
|
Network,
|
|
23
21
|
OrderExecution,
|
|
24
22
|
OrderSide,
|
|
@@ -68,11 +66,6 @@ export interface OrderBatchWithMarketId {
|
|
|
68
66
|
clientIds: number[];
|
|
69
67
|
}
|
|
70
68
|
|
|
71
|
-
export interface PermissionedKeysAccountAuth {
|
|
72
|
-
authenticators: Long[];
|
|
73
|
-
accountForOrder: SubaccountInfo;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
69
|
export class CompositeClient {
|
|
77
70
|
public readonly network: Network;
|
|
78
71
|
public gasDenom: SelectedGasDenom = SelectedGasDenom.USDC;
|
|
@@ -158,7 +151,6 @@ export class CompositeClient {
|
|
|
158
151
|
memo?: string,
|
|
159
152
|
broadcastMode?: BroadcastMode,
|
|
160
153
|
account?: () => Promise<Account>,
|
|
161
|
-
authenticators?: Long[],
|
|
162
154
|
): Promise<BroadcastTxAsyncResponse | BroadcastTxSyncResponse | IndexedTx> {
|
|
163
155
|
return this.validatorClient.post.send(
|
|
164
156
|
wallet,
|
|
@@ -168,8 +160,6 @@ export class CompositeClient {
|
|
|
168
160
|
memo,
|
|
169
161
|
broadcastMode,
|
|
170
162
|
account,
|
|
171
|
-
undefined,
|
|
172
|
-
authenticators,
|
|
173
163
|
);
|
|
174
164
|
}
|
|
175
165
|
|
|
@@ -307,15 +297,10 @@ export class CompositeClient {
|
|
|
307
297
|
timeInForce: Order_TimeInForce,
|
|
308
298
|
reduceOnly: boolean,
|
|
309
299
|
memo?: string,
|
|
310
|
-
permissionedKeysAccountAuth?: PermissionedKeysAccountAuth,
|
|
311
300
|
): Promise<BroadcastTxAsyncResponse | BroadcastTxSyncResponse | IndexedTx> {
|
|
312
|
-
// For permissioned orders, use the permissioning account details instead of the subaccount
|
|
313
|
-
// This allows placing orders on behalf of another account when using permissioned keys
|
|
314
|
-
const accountForOrder = permissionedKeysAccountAuth ? permissionedKeysAccountAuth.accountForOrder : subaccount;
|
|
315
301
|
const msgs: Promise<EncodeObject[]> = new Promise((resolve, reject) => {
|
|
316
|
-
|
|
317
302
|
const msg = this.placeShortTermOrderMessage(
|
|
318
|
-
|
|
303
|
+
subaccount,
|
|
319
304
|
marketId,
|
|
320
305
|
side,
|
|
321
306
|
price,
|
|
@@ -326,16 +311,14 @@ export class CompositeClient {
|
|
|
326
311
|
reduceOnly,
|
|
327
312
|
);
|
|
328
313
|
msg
|
|
329
|
-
.then((it) =>
|
|
330
|
-
resolve([it]);
|
|
331
|
-
})
|
|
314
|
+
.then((it) => resolve([it]))
|
|
332
315
|
.catch((err) => {
|
|
333
316
|
console.log(err);
|
|
334
317
|
reject(err);
|
|
335
318
|
});
|
|
336
319
|
});
|
|
337
320
|
const account: Promise<Account> = this.validatorClient.post.account(
|
|
338
|
-
|
|
321
|
+
subaccount.address,
|
|
339
322
|
undefined,
|
|
340
323
|
);
|
|
341
324
|
return this.send(
|
|
@@ -346,7 +329,6 @@ export class CompositeClient {
|
|
|
346
329
|
memo,
|
|
347
330
|
undefined,
|
|
348
331
|
() => account,
|
|
349
|
-
permissionedKeysAccountAuth?.authenticators,
|
|
350
332
|
);
|
|
351
333
|
}
|
|
352
334
|
|
|
@@ -1235,23 +1217,4 @@ export class CompositeClient {
|
|
|
1235
1217
|
): Promise<BroadcastTxAsyncResponse | BroadcastTxSyncResponse | IndexedTx> {
|
|
1236
1218
|
return this.validatorClient.post.createMarketPermissionless(ticker, subaccount, broadcastMode, gasAdjustment, memo);
|
|
1237
1219
|
}
|
|
1238
|
-
|
|
1239
|
-
async addAuthenticator(
|
|
1240
|
-
subaccount: SubaccountInfo,
|
|
1241
|
-
authenticatorType: AuthenticatorType,
|
|
1242
|
-
data: Uint8Array,
|
|
1243
|
-
): Promise<BroadcastTxAsyncResponse | BroadcastTxSyncResponse | IndexedTx> {
|
|
1244
|
-
return this.validatorClient.post.addAuthenticator(subaccount, authenticatorType, data)
|
|
1245
|
-
}
|
|
1246
|
-
|
|
1247
|
-
async removeAuthenticator(
|
|
1248
|
-
subaccount: SubaccountInfo,
|
|
1249
|
-
id: Long,
|
|
1250
|
-
): Promise<BroadcastTxAsyncResponse | BroadcastTxSyncResponse | IndexedTx> {
|
|
1251
|
-
return this.validatorClient.post.removeAuthenticator(subaccount, id)
|
|
1252
|
-
}
|
|
1253
|
-
|
|
1254
|
-
async getAuthenticators(address: string): Promise<GetAuthenticatorsResponse>{
|
|
1255
|
-
return this.validatorClient.get.getAuthenticators(address);
|
|
1256
|
-
}
|
|
1257
1220
|
}
|
package/src/clients/constants.ts
CHANGED
|
@@ -116,10 +116,6 @@ export const TYPE_URL_MSG_UNDELEGATE = '/cosmos.staking.v1beta1.MsgUndelegate';
|
|
|
116
116
|
export const TYPE_URL_MSG_WITHDRAW_DELEGATOR_REWARD =
|
|
117
117
|
'/cosmos.distribution.v1beta1.MsgWithdrawDelegatorReward';
|
|
118
118
|
|
|
119
|
-
// x/accountplus
|
|
120
|
-
export const TYPE_URL_MSG_ADD_AUTHENTICATOR = '/dydxprotocol.accountplus.MsgAddAuthenticator'
|
|
121
|
-
export const TYPE_URL_MSG_REMOVE_AUTHENTICATOR = '/dydxprotocol.accountplus.MsgRemoveAuthenticator'
|
|
122
|
-
|
|
123
119
|
// ------------ Chain Constants ------------
|
|
124
120
|
// The following are same across different networks / deployments.
|
|
125
121
|
export const GOV_MODULE_ADDRESS = 'dydx10d07y265gmmuvt4z0w9aw880jnsr700jnmapky';
|
|
@@ -200,17 +196,6 @@ export enum PnlTickInterval {
|
|
|
200
196
|
day = 'day',
|
|
201
197
|
}
|
|
202
198
|
|
|
203
|
-
// ----------- Authenticators -------------
|
|
204
|
-
|
|
205
|
-
export enum AuthenticatorType {
|
|
206
|
-
ALL_OF = 'AllOf',
|
|
207
|
-
ANY_OF = 'AnyOf',
|
|
208
|
-
SIGNATURE_VERIFICATION = 'SignatureVerification',
|
|
209
|
-
MESSAGE_FILTER = 'MessageFilter',
|
|
210
|
-
CLOB_PAIR_ID_FILTER = 'ClobPairIdFilter',
|
|
211
|
-
SUBACCOUNT_FILTER = 'SubaccountFilter',
|
|
212
|
-
}
|
|
213
|
-
|
|
214
199
|
export enum TradingRewardAggregationPeriod {
|
|
215
200
|
DAILY = 'DAILY',
|
|
216
201
|
WEEKLY = 'WEEKLY',
|
|
@@ -300,7 +285,7 @@ export class Network {
|
|
|
300
285
|
const indexerConfig = new IndexerConfig(IndexerApiHost.STAGING, IndexerWSHost.STAGING);
|
|
301
286
|
const validatorConfig = new ValidatorConfig(
|
|
302
287
|
ValidatorApiHost.STAGING,
|
|
303
|
-
|
|
288
|
+
TESTNET_CHAIN_ID,
|
|
304
289
|
{
|
|
305
290
|
CHAINTOKEN_DENOM: 'adv4tnt',
|
|
306
291
|
USDC_DENOM: 'ibc/8E27BA2D5493AF5636760E354E46004562C46AB7EC0CC4C1CA14E9E20E2545B5',
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { GeneratedType, Registry } from '@cosmjs/proto-signing';
|
|
2
2
|
import { defaultRegistryTypes } from '@cosmjs/stargate';
|
|
3
|
-
import { MsgAddAuthenticator, MsgRemoveAuthenticator } from '@dydxprotocol/v4-proto/src/codegen/dydxprotocol/accountplus/tx';
|
|
4
3
|
import { MsgRegisterAffiliate } from '@dydxprotocol/v4-proto/src/codegen/dydxprotocol/affiliates/tx';
|
|
5
4
|
import {
|
|
6
5
|
MsgPlaceOrder,
|
|
@@ -39,8 +38,6 @@ import {
|
|
|
39
38
|
TYPE_URL_MSG_WITHDRAW_FROM_MEGAVAULT,
|
|
40
39
|
TYPE_URL_MSG_REGISTER_AFFILIATE,
|
|
41
40
|
TYPE_URL_MSG_CREATE_MARKET_PERMISSIONLESS,
|
|
42
|
-
TYPE_URL_MSG_ADD_AUTHENTICATOR,
|
|
43
|
-
TYPE_URL_MSG_REMOVE_AUTHENTICATOR,
|
|
44
41
|
} from '../constants';
|
|
45
42
|
|
|
46
43
|
export const registry: ReadonlyArray<[string, GeneratedType]> = [];
|
|
@@ -77,11 +74,6 @@ export function generateRegistry(): Registry {
|
|
|
77
74
|
// affiliates
|
|
78
75
|
[TYPE_URL_MSG_REGISTER_AFFILIATE, MsgRegisterAffiliate as GeneratedType],
|
|
79
76
|
|
|
80
|
-
|
|
81
|
-
// authentication
|
|
82
|
-
[TYPE_URL_MSG_ADD_AUTHENTICATOR, MsgAddAuthenticator as GeneratedType],
|
|
83
|
-
[TYPE_URL_MSG_REMOVE_AUTHENTICATOR, MsgRemoveAuthenticator as GeneratedType],
|
|
84
|
-
|
|
85
77
|
// default types
|
|
86
78
|
...defaultRegistryTypes,
|
|
87
79
|
]);
|
|
@@ -265,6 +265,7 @@ export default class AccountClient extends RestClient {
|
|
|
265
265
|
});
|
|
266
266
|
}
|
|
267
267
|
|
|
268
|
+
// limit applies to the subaccount ticks, so expect number of results to be much lower than limit
|
|
268
269
|
async getParentSubaccountNumberHistoricalPNLs(
|
|
269
270
|
address: string,
|
|
270
271
|
parentSubaccountNumber: number,
|
|
@@ -275,7 +276,7 @@ export default class AccountClient extends RestClient {
|
|
|
275
276
|
limit?: number | null,
|
|
276
277
|
page?: number | null,
|
|
277
278
|
): Promise<Data> {
|
|
278
|
-
const uri = '/v4/historical-pnl/
|
|
279
|
+
const uri = '/v4/historical-pnl/parentSubaccountNumber';
|
|
279
280
|
return this.get(uri, {
|
|
280
281
|
address,
|
|
281
282
|
parentSubaccountNumber,
|
|
@@ -7,7 +7,6 @@ import {
|
|
|
7
7
|
MsgDelegate,
|
|
8
8
|
MsgUndelegate,
|
|
9
9
|
} from '@dydxprotocol/v4-proto/src/codegen/cosmos/staking/v1beta1/tx';
|
|
10
|
-
import { MsgAddAuthenticator, MsgRemoveAuthenticator } from '@dydxprotocol/v4-proto/src/codegen/dydxprotocol/accountplus/tx';
|
|
11
10
|
import { MsgRegisterAffiliate } from '@dydxprotocol/v4-proto/src/codegen/dydxprotocol/affiliates/tx';
|
|
12
11
|
import { ClobPair_Status } from '@dydxprotocol/v4-proto/src/codegen/dydxprotocol/clob/clob_pair';
|
|
13
12
|
import {
|
|
@@ -53,9 +52,6 @@ import {
|
|
|
53
52
|
TYPE_URL_MSG_DEPOSIT_TO_MEGAVAULT,
|
|
54
53
|
TYPE_URL_MSG_WITHDRAW_FROM_MEGAVAULT,
|
|
55
54
|
TYPE_URL_MSG_CREATE_MARKET_PERMISSIONLESS,
|
|
56
|
-
TYPE_URL_MSG_ADD_AUTHENTICATOR,
|
|
57
|
-
TYPE_URL_MSG_REMOVE_AUTHENTICATOR,
|
|
58
|
-
AuthenticatorType,
|
|
59
55
|
} from '../constants';
|
|
60
56
|
import { DenomConfig } from '../types';
|
|
61
57
|
import {
|
|
@@ -109,7 +105,6 @@ export class Composer {
|
|
|
109
105
|
orderFlags,
|
|
110
106
|
clobPairId,
|
|
111
107
|
};
|
|
112
|
-
|
|
113
108
|
const order: Order = {
|
|
114
109
|
orderId,
|
|
115
110
|
side,
|
|
@@ -580,40 +575,6 @@ export class Composer {
|
|
|
580
575
|
}
|
|
581
576
|
}
|
|
582
577
|
|
|
583
|
-
// ----------- x/accountplus --------
|
|
584
|
-
|
|
585
|
-
public composeMsgAddAuthenticator(
|
|
586
|
-
address: string,
|
|
587
|
-
authenticatorType: AuthenticatorType,
|
|
588
|
-
data: Uint8Array,
|
|
589
|
-
): EncodeObject {
|
|
590
|
-
const msg: MsgAddAuthenticator = {
|
|
591
|
-
sender: address,
|
|
592
|
-
authenticatorType,
|
|
593
|
-
data,
|
|
594
|
-
}
|
|
595
|
-
|
|
596
|
-
return {
|
|
597
|
-
typeUrl: TYPE_URL_MSG_ADD_AUTHENTICATOR,
|
|
598
|
-
value: msg,
|
|
599
|
-
}
|
|
600
|
-
}
|
|
601
|
-
|
|
602
|
-
public composeMsgRemoveAuthenticator(
|
|
603
|
-
address: string,
|
|
604
|
-
id: Long,
|
|
605
|
-
): EncodeObject {
|
|
606
|
-
const msg: MsgRemoveAuthenticator = {
|
|
607
|
-
sender: address,
|
|
608
|
-
id,
|
|
609
|
-
}
|
|
610
|
-
|
|
611
|
-
return {
|
|
612
|
-
typeUrl: TYPE_URL_MSG_REMOVE_AUTHENTICATOR,
|
|
613
|
-
value: msg,
|
|
614
|
-
}
|
|
615
|
-
}
|
|
616
|
-
|
|
617
578
|
// ------------ util ------------
|
|
618
579
|
public validateGoodTilBlockAndTime(
|
|
619
580
|
orderFlags: number,
|
|
@@ -7,7 +7,6 @@ import {
|
|
|
7
7
|
TxExtension,
|
|
8
8
|
QueryAbciResponse,
|
|
9
9
|
} from '@cosmjs/stargate';
|
|
10
|
-
import { GetAuthenticatorsRequest, GetAuthenticatorsResponse } from '@dydxprotocol/v4-proto/src/codegen/dydxprotocol/accountplus/query';
|
|
11
10
|
import * as AuthModule from 'cosmjs-types/cosmos/auth/v1beta1/query';
|
|
12
11
|
import * as BankModule from 'cosmjs-types/cosmos/bank/v1beta1/query';
|
|
13
12
|
import { Any } from 'cosmjs-types/google/protobuf/any';
|
|
@@ -611,21 +610,6 @@ export class Get {
|
|
|
611
610
|
return AffiliateModule.AffiliateWhitelistResponse.decode(data);
|
|
612
611
|
}
|
|
613
612
|
|
|
614
|
-
async getAuthenticators(address: string): Promise<GetAuthenticatorsResponse> {
|
|
615
|
-
const requestData = Uint8Array.from(
|
|
616
|
-
GetAuthenticatorsRequest.encode({
|
|
617
|
-
account: address,
|
|
618
|
-
}).finish(),
|
|
619
|
-
);
|
|
620
|
-
|
|
621
|
-
const data = await this.sendQuery(
|
|
622
|
-
'/dydxprotocol.accountplus.Query/GetAuthenticators',
|
|
623
|
-
requestData,
|
|
624
|
-
);
|
|
625
|
-
|
|
626
|
-
return GetAuthenticatorsResponse.decode(data);
|
|
627
|
-
}
|
|
628
|
-
|
|
629
613
|
private async sendQuery(requestUrl: string, requestData: Uint8Array): Promise<Uint8Array> {
|
|
630
614
|
// eslint-disable-next-line max-len
|
|
631
615
|
const resp: QueryAbciResponse = await this.stargateQueryClient.queryAbci(
|
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
AccountData,
|
|
4
4
|
DirectSecp256k1HdWallet,
|
|
5
5
|
EncodeObject,
|
|
6
|
-
|
|
6
|
+
OfflineSigner,
|
|
7
7
|
} from '@cosmjs/proto-signing';
|
|
8
8
|
import { SigningStargateClient } from '@cosmjs/stargate';
|
|
9
9
|
import Long from 'long';
|
|
@@ -22,9 +22,9 @@ export default class LocalWallet {
|
|
|
22
22
|
address?: string;
|
|
23
23
|
pubKey?: Secp256k1Pubkey;
|
|
24
24
|
signer?: TransactionSigner;
|
|
25
|
-
offlineSigner?:
|
|
25
|
+
offlineSigner?: OfflineSigner;
|
|
26
26
|
|
|
27
|
-
static async fromOfflineSigner(signer:
|
|
27
|
+
static async fromOfflineSigner(signer: OfflineSigner): Promise<LocalWallet> {
|
|
28
28
|
const wallet = new LocalWallet();
|
|
29
29
|
await wallet.setSigner(signer);
|
|
30
30
|
return wallet;
|
|
@@ -36,7 +36,7 @@ export default class LocalWallet {
|
|
|
36
36
|
return wallet;
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
async setSigner(signer:
|
|
39
|
+
async setSigner(signer: OfflineSigner): Promise<void> {
|
|
40
40
|
this.offlineSigner = signer;
|
|
41
41
|
const stargateClient = await SigningStargateClient.offline(signer, {
|
|
42
42
|
registry: generateRegistry(),
|
|
@@ -46,7 +46,7 @@ export default class LocalWallet {
|
|
|
46
46
|
this.accounts = [...accountData];
|
|
47
47
|
this.address = firstAccount.address;
|
|
48
48
|
this.pubKey = encodeSecp256k1Pubkey(firstAccount.pubkey);
|
|
49
|
-
this.signer = new TransactionSigner(this.address, stargateClient
|
|
49
|
+
this.signer = new TransactionSigner(this.address, stargateClient);
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
async setMnemonic(mnemonic: string, prefix?: string): Promise<void> {
|
|
@@ -60,6 +60,6 @@ export default class LocalWallet {
|
|
|
60
60
|
fee?: StdFee,
|
|
61
61
|
memo: string = '',
|
|
62
62
|
): Promise<Uint8Array> {
|
|
63
|
-
return this.signer!.signTransaction(messages, transactionOptions, fee, memo
|
|
63
|
+
return this.signer!.signTransaction(messages, transactionOptions, fee, memo);
|
|
64
64
|
}
|
|
65
65
|
}
|
|
@@ -11,7 +11,7 @@ import _ from 'lodash';
|
|
|
11
11
|
import Long from 'long';
|
|
12
12
|
import protobuf from 'protobufjs';
|
|
13
13
|
|
|
14
|
-
import {
|
|
14
|
+
import { GAS_MULTIPLIER, SelectedGasDenom } from '../constants';
|
|
15
15
|
import { UnexpectedClientError } from '../lib/errors';
|
|
16
16
|
import { generateRegistry } from '../lib/registry';
|
|
17
17
|
import { SubaccountInfo } from '../subaccount';
|
|
@@ -178,7 +178,6 @@ export class Post {
|
|
|
178
178
|
broadcastMode?: BroadcastMode,
|
|
179
179
|
account?: () => Promise<Account>,
|
|
180
180
|
gasAdjustment: number = GAS_MULTIPLIER,
|
|
181
|
-
authenticators?: Long[],
|
|
182
181
|
): Promise<BroadcastTxAsyncResponse | BroadcastTxSyncResponse | IndexedTx> {
|
|
183
182
|
const msgsPromise = messaging();
|
|
184
183
|
const accountPromise = account ? await account() : this.account(wallet.address!);
|
|
@@ -194,7 +193,6 @@ export class Post {
|
|
|
194
193
|
memo ?? this.defaultClientMemo,
|
|
195
194
|
broadcastMode ?? this.defaultBroadcastMode(msgs),
|
|
196
195
|
gasAdjustment,
|
|
197
|
-
authenticators,
|
|
198
196
|
);
|
|
199
197
|
}
|
|
200
198
|
|
|
@@ -240,7 +238,6 @@ export class Post {
|
|
|
240
238
|
gasPrice: GasPrice = this.getGasPrice(),
|
|
241
239
|
memo?: string,
|
|
242
240
|
gasAdjustment: number = GAS_MULTIPLIER,
|
|
243
|
-
authenticators?: Long[],
|
|
244
241
|
): Promise<Uint8Array> {
|
|
245
242
|
// protocol expects timestamp nonce in UTC milliseconds, which is the unit returned by Date.now()
|
|
246
243
|
const sequence = this.useTimestampNonce ? Date.now() : account.sequence;
|
|
@@ -263,7 +260,6 @@ export class Post {
|
|
|
263
260
|
sequence,
|
|
264
261
|
accountNumber: account.accountNumber,
|
|
265
262
|
chainId: this.chainId,
|
|
266
|
-
authenticators,
|
|
267
263
|
};
|
|
268
264
|
// Generate signed transaction.
|
|
269
265
|
return wallet.signTransaction(messages, txOptions, fee, memo);
|
|
@@ -301,7 +297,6 @@ export class Post {
|
|
|
301
297
|
memo?: string,
|
|
302
298
|
broadcastMode?: BroadcastMode,
|
|
303
299
|
gasAdjustment: number = GAS_MULTIPLIER,
|
|
304
|
-
authenticators?: Long[],
|
|
305
300
|
): Promise<BroadcastTxAsyncResponse | BroadcastTxSyncResponse | IndexedTx> {
|
|
306
301
|
const signedTransaction = await this.signTransaction(
|
|
307
302
|
wallet,
|
|
@@ -311,7 +306,6 @@ export class Post {
|
|
|
311
306
|
gasPrice,
|
|
312
307
|
memo,
|
|
313
308
|
gasAdjustment,
|
|
314
|
-
authenticators,
|
|
315
309
|
);
|
|
316
310
|
return this.sendSignedTransaction(signedTransaction, broadcastMode);
|
|
317
311
|
}
|
|
@@ -950,41 +944,4 @@ export class Post {
|
|
|
950
944
|
gasAdjustment,
|
|
951
945
|
);
|
|
952
946
|
}
|
|
953
|
-
|
|
954
|
-
async addAuthenticator(
|
|
955
|
-
subaccount: SubaccountInfo,
|
|
956
|
-
authenticatorType: AuthenticatorType,
|
|
957
|
-
data: Uint8Array,
|
|
958
|
-
): Promise<BroadcastTxAsyncResponse | BroadcastTxSyncResponse | IndexedTx> {
|
|
959
|
-
const msg = this.composer.composeMsgAddAuthenticator(subaccount.address, authenticatorType, data);
|
|
960
|
-
|
|
961
|
-
return this.send(
|
|
962
|
-
subaccount.wallet,
|
|
963
|
-
() => Promise.resolve([msg]),
|
|
964
|
-
false,
|
|
965
|
-
undefined,
|
|
966
|
-
undefined,
|
|
967
|
-
Method.BroadcastTxSync,
|
|
968
|
-
undefined,
|
|
969
|
-
undefined,
|
|
970
|
-
);
|
|
971
|
-
}
|
|
972
|
-
|
|
973
|
-
async removeAuthenticator(
|
|
974
|
-
subaccount: SubaccountInfo,
|
|
975
|
-
id: Long,
|
|
976
|
-
): Promise<BroadcastTxAsyncResponse | BroadcastTxSyncResponse | IndexedTx> {
|
|
977
|
-
const msg = this.composer.composeMsgRemoveAuthenticator(subaccount.address, id);
|
|
978
|
-
|
|
979
|
-
return this.send(
|
|
980
|
-
subaccount.wallet,
|
|
981
|
-
() => Promise.resolve([msg]),
|
|
982
|
-
false,
|
|
983
|
-
undefined,
|
|
984
|
-
undefined,
|
|
985
|
-
Method.BroadcastTxSync,
|
|
986
|
-
undefined,
|
|
987
|
-
undefined,
|
|
988
|
-
);
|
|
989
|
-
}
|
|
990
947
|
}
|
|
@@ -1,15 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { fromBase64 } from '@cosmjs/encoding';
|
|
3
|
-
import { Int53 } from '@cosmjs/math';
|
|
4
|
-
import { EncodeObject, encodePubkey, makeAuthInfoBytes, makeSignDoc, OfflineDirectSigner } from '@cosmjs/proto-signing';
|
|
1
|
+
import { EncodeObject } from '@cosmjs/proto-signing';
|
|
5
2
|
import { SigningStargateClient, StdFee } from '@cosmjs/stargate';
|
|
6
|
-
import {
|
|
7
|
-
import { TxBody, TxRaw } from 'cosmjs-types/cosmos/tx/v1beta1/tx';
|
|
8
|
-
import { Any } from 'cosmjs-types/google/protobuf/any';
|
|
3
|
+
import { TxRaw } from 'cosmjs-types/cosmos/tx/v1beta1/tx';
|
|
9
4
|
import Long from 'long';
|
|
10
5
|
import protobuf from 'protobufjs';
|
|
11
6
|
|
|
12
|
-
import {
|
|
7
|
+
import { UserError } from '../lib/errors';
|
|
13
8
|
import { TransactionOptions } from '../types';
|
|
14
9
|
|
|
15
10
|
// Required for encoding and decoding queries that are of type Long.
|
|
@@ -22,16 +17,10 @@ protobuf.configure();
|
|
|
22
17
|
export class TransactionSigner {
|
|
23
18
|
readonly address: string;
|
|
24
19
|
readonly stargateSigningClient: SigningStargateClient;
|
|
25
|
-
readonly offlineSigner: OfflineDirectSigner;
|
|
26
20
|
|
|
27
|
-
constructor(
|
|
28
|
-
address: string,
|
|
29
|
-
stargateSigningClient: SigningStargateClient,
|
|
30
|
-
offlineSigner: OfflineDirectSigner,
|
|
31
|
-
) {
|
|
21
|
+
constructor(address: string, stargateSigningClient: SigningStargateClient) {
|
|
32
22
|
this.address = address;
|
|
33
23
|
this.stargateSigningClient = stargateSigningClient;
|
|
34
|
-
this.offlineSigner = offlineSigner;
|
|
35
24
|
}
|
|
36
25
|
|
|
37
26
|
/**
|
|
@@ -46,73 +35,18 @@ export class TransactionSigner {
|
|
|
46
35
|
transactionOptions: TransactionOptions,
|
|
47
36
|
fee?: StdFee,
|
|
48
37
|
memo: string = '',
|
|
49
|
-
publicKey?: Secp256k1Pubkey,
|
|
50
38
|
): Promise<Uint8Array> {
|
|
51
|
-
|
|
52
|
-
|
|
39
|
+
// Verify there is either a fee or a path to getting the fee present.
|
|
40
|
+
if (fee === undefined) {
|
|
41
|
+
throw new UserError('fee cannot be undefined');
|
|
53
42
|
}
|
|
54
43
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
// Encode the TxExtension message
|
|
61
|
-
const txExtension = TxExtension.encode({
|
|
62
|
-
selectedAuthenticators: transactionOptions.authenticators ?? [],
|
|
63
|
-
}).finish();
|
|
64
|
-
|
|
65
|
-
// Create the non-critical extension message
|
|
66
|
-
const nonCriticalExtensionOptions: Any[] = [
|
|
67
|
-
Any.fromPartial({
|
|
68
|
-
typeUrl: '/dydxprotocol.accountplus.TxExtension',
|
|
69
|
-
value: txExtension,
|
|
70
|
-
}),
|
|
71
|
-
];
|
|
72
|
-
|
|
73
|
-
// Construct the TxBody
|
|
74
|
-
const txBody: TxBody = TxBody.fromPartial({
|
|
75
|
-
messages: encodedMessages,
|
|
76
|
-
memo,
|
|
77
|
-
extensionOptions: [],
|
|
78
|
-
nonCriticalExtensionOptions,
|
|
44
|
+
// Sign, encode and return the transaction.
|
|
45
|
+
const rawTx: TxRaw = await this.stargateSigningClient.sign(this.address, messages, fee, memo, {
|
|
46
|
+
accountNumber: transactionOptions.accountNumber,
|
|
47
|
+
sequence: transactionOptions.sequence,
|
|
48
|
+
chainId: transactionOptions.chainId,
|
|
79
49
|
});
|
|
80
|
-
|
|
81
|
-
// Encode the TxBody
|
|
82
|
-
const txBodyBytes = TxBody.encode(txBody).finish();
|
|
83
|
-
|
|
84
|
-
if (!publicKey) {
|
|
85
|
-
throw new Error('Public key cannot be undefined');
|
|
86
|
-
}
|
|
87
|
-
const pubkey = encodePubkey(publicKey); // Use the public key of the signer
|
|
88
|
-
|
|
89
|
-
const gasLimit = Int53.fromString(String(fee.gas)).toNumber();
|
|
90
|
-
const authInfoBytes = makeAuthInfoBytes(
|
|
91
|
-
[{ pubkey, sequence: transactionOptions.sequence }],
|
|
92
|
-
fee.amount,
|
|
93
|
-
gasLimit,
|
|
94
|
-
undefined,
|
|
95
|
-
undefined,
|
|
96
|
-
);
|
|
97
|
-
|
|
98
|
-
// Create the SignDoc
|
|
99
|
-
const signDoc = makeSignDoc(
|
|
100
|
-
txBodyBytes,
|
|
101
|
-
authInfoBytes,
|
|
102
|
-
transactionOptions.chainId,
|
|
103
|
-
transactionOptions.accountNumber,
|
|
104
|
-
);
|
|
105
|
-
|
|
106
|
-
// Use OfflineSigner to sign the transaction
|
|
107
|
-
const signerAddress = this.address;
|
|
108
|
-
const { signed, signature } = await this.offlineSigner.signDirect(signerAddress, signDoc);
|
|
109
|
-
|
|
110
|
-
const txRaw = TxRaw.fromPartial({
|
|
111
|
-
bodyBytes: signed.bodyBytes,
|
|
112
|
-
authInfoBytes: signed.authInfoBytes,
|
|
113
|
-
signatures: [fromBase64(signature.signature)],
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
return Uint8Array.from(TxRaw.encode(txRaw).finish());
|
|
50
|
+
return Uint8Array.from(TxRaw.encode(rawTx).finish());
|
|
117
51
|
}
|
|
118
52
|
}
|
package/src/clients/types.ts
CHANGED
|
@@ -29,7 +29,6 @@ export interface PartialTransactionOptions {
|
|
|
29
29
|
// Information for signing a transaction while offline.
|
|
30
30
|
export interface TransactionOptions extends PartialTransactionOptions {
|
|
31
31
|
sequence: number;
|
|
32
|
-
authenticators?: Long[];
|
|
33
32
|
}
|
|
34
33
|
|
|
35
34
|
// OrderFlags, just a number in proto, defined as enum for convenience
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|