@dydxprotocol/v4-client-js 1.16.3 → 1.18.0
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/build/examples/constants.d.ts +1 -0
- package/build/examples/constants.js +3 -2
- package/build/examples/permissioned_keys_example.d.ts +1 -0
- package/build/examples/permissioned_keys_example.js +85 -0
- package/build/examples/websocket_orderbook_example.d.ts +1 -0
- package/build/examples/websocket_orderbook_example.js +198 -0
- 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/affiliates/query.lcd.d.ts +12 -0
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/affiliates/query.lcd.js +34 -0
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/blocktime/params.d.ts +21 -0
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/blocktime/params.js +37 -2
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/blocktime/tx.d.ts +34 -1
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/blocktime/tx.js +72 -2
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/blocktime/tx.rpc.msg.d.ts +4 -1
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/blocktime/tx.rpc.msg.js +7 -1
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/bundle.d.ts +2021 -1711
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/bundle.js +272 -266
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/clob/finalize_block.d.ts +23 -0
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/clob/finalize_block.js +64 -0
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/clob/order_removals.d.ts +5 -0
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/clob/order_removals.js +11 -1
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/clob/query.d.ts +31 -0
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/clob/query.js +94 -5
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/clob/query.lcd.d.ts +2 -1
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/clob/query.lcd.js +7 -1
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/clob/query.rpc.Query.d.ts +5 -1
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/clob/query.rpc.Query.js +10 -1
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/clob/streaming.d.ts +6 -1
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/clob/streaming.js +19 -2
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/indexer/events/events.d.ts +79 -6
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/indexer/events/events.js +78 -2
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/lcd.d.ts +1 -0
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/lcd.js +4 -1
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/listing/genesis.d.ts +4 -0
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/listing/genesis.js +11 -2
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/listing/query.lcd.d.ts +2 -1
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/listing/query.lcd.js +7 -1
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/listing/tx.d.ts +39 -0
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/listing/tx.js +72 -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 +7 -1
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/perpetuals/query.d.ts +25 -0
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/perpetuals/query.js +64 -2
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/perpetuals/query.lcd.d.ts +2 -1
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/perpetuals/query.lcd.js +7 -1
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/perpetuals/query.rpc.Query.d.ts +5 -1
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/perpetuals/query.rpc.Query.js +10 -1
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/prices/market_param.d.ts +8 -0
- 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 +3 -0
- 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 +34 -0
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/prices/query.js +64 -2
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/prices/query.lcd.d.ts +2 -1
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/prices/query.lcd.js +7 -1
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/prices/query.rpc.Query.d.ts +5 -1
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/prices/query.rpc.Query.js +10 -1
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/prices/streaming.d.ts +23 -0
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/prices/streaming.js +81 -0
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/revshare/query.d.ts +25 -1
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/revshare/query.js +63 -2
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/revshare/query.lcd.d.ts +2 -1
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/revshare/query.lcd.js +7 -1
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/revshare/query.rpc.Query.d.ts +5 -1
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/revshare/query.rpc.Query.js +10 -1
- 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 +4 -0
- 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 +21 -0
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/vault/params.js +55 -3
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/vault/query.d.ts +1 -6
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/vault/query.js +4 -12
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/vault/query.lcd.d.ts +1 -2
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/vault/query.lcd.js +1 -13
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/vault/tx.d.ts +51 -24
- package/build/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/vault/tx.js +98 -46
- 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 +12 -3
- package/build/src/clients/composite-client.js +22 -8
- package/build/src/clients/constants.d.ts +10 -0
- package/build/src/clients/constants.js +17 -4
- package/build/src/clients/lib/registry.js +26 -22
- package/build/src/clients/modules/composer.d.ts +3 -0
- package/build/src/clients/modules/composer.js +23 -1
- package/build/src/clients/modules/get.d.ts +2 -0
- package/build/src/clients/modules/get.js +9 -1
- 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 +4 -2
- package/build/src/clients/modules/post.js +15 -6
- package/build/src/clients/modules/signer.d.ts +5 -3
- package/build/src/clients/modules/signer.js +53 -14
- package/build/src/clients/modules/utility.d.ts +7 -1
- package/build/src/clients/modules/utility.js +10 -1
- package/build/src/clients/types.d.ts +22 -0
- package/build/src/clients/types.js +19 -2
- package/build/tsconfig.tsbuildinfo +1 -1
- package/examples/constants.ts +2 -0
- package/examples/permissioned_keys_example.ts +110 -0
- package/examples/websocket_orderbook_example.ts +252 -0
- package/package.json +2 -2
- package/src/clients/composite-client.ts +40 -3
- package/src/clients/constants.ts +16 -1
- package/src/clients/lib/registry.ts +8 -0
- package/src/clients/modules/composer.ts +39 -0
- package/src/clients/modules/get.ts +16 -0
- package/src/clients/modules/local-wallet.ts +6 -6
- package/src/clients/modules/post.ts +44 -1
- package/src/clients/modules/signer.ts +79 -13
- package/src/clients/modules/utility.ts +16 -1
- package/src/clients/types.ts +25 -0
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
AccountData,
|
|
4
4
|
DirectSecp256k1HdWallet,
|
|
5
5
|
EncodeObject,
|
|
6
|
-
|
|
6
|
+
OfflineDirectSigner,
|
|
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?: OfflineDirectSigner;
|
|
26
26
|
|
|
27
|
-
static async fromOfflineSigner(signer:
|
|
27
|
+
static async fromOfflineSigner(signer: OfflineDirectSigner): 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: OfflineDirectSigner): 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, signer);
|
|
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, this.pubKey);
|
|
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 { GAS_MULTIPLIER, SelectedGasDenom } from '../constants';
|
|
14
|
+
import { AuthenticatorType, 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,6 +178,7 @@ export class Post {
|
|
|
178
178
|
broadcastMode?: BroadcastMode,
|
|
179
179
|
account?: () => Promise<Account>,
|
|
180
180
|
gasAdjustment: number = GAS_MULTIPLIER,
|
|
181
|
+
authenticators?: Long[],
|
|
181
182
|
): Promise<BroadcastTxAsyncResponse | BroadcastTxSyncResponse | IndexedTx> {
|
|
182
183
|
const msgsPromise = messaging();
|
|
183
184
|
const accountPromise = account ? await account() : this.account(wallet.address!);
|
|
@@ -193,6 +194,7 @@ export class Post {
|
|
|
193
194
|
memo ?? this.defaultClientMemo,
|
|
194
195
|
broadcastMode ?? this.defaultBroadcastMode(msgs),
|
|
195
196
|
gasAdjustment,
|
|
197
|
+
authenticators,
|
|
196
198
|
);
|
|
197
199
|
}
|
|
198
200
|
|
|
@@ -238,6 +240,7 @@ export class Post {
|
|
|
238
240
|
gasPrice: GasPrice = this.getGasPrice(),
|
|
239
241
|
memo?: string,
|
|
240
242
|
gasAdjustment: number = GAS_MULTIPLIER,
|
|
243
|
+
authenticators?: Long[],
|
|
241
244
|
): Promise<Uint8Array> {
|
|
242
245
|
// protocol expects timestamp nonce in UTC milliseconds, which is the unit returned by Date.now()
|
|
243
246
|
const sequence = this.useTimestampNonce ? Date.now() : account.sequence;
|
|
@@ -260,6 +263,7 @@ export class Post {
|
|
|
260
263
|
sequence,
|
|
261
264
|
accountNumber: account.accountNumber,
|
|
262
265
|
chainId: this.chainId,
|
|
266
|
+
authenticators,
|
|
263
267
|
};
|
|
264
268
|
// Generate signed transaction.
|
|
265
269
|
return wallet.signTransaction(messages, txOptions, fee, memo);
|
|
@@ -297,6 +301,7 @@ export class Post {
|
|
|
297
301
|
memo?: string,
|
|
298
302
|
broadcastMode?: BroadcastMode,
|
|
299
303
|
gasAdjustment: number = GAS_MULTIPLIER,
|
|
304
|
+
authenticators?: Long[],
|
|
300
305
|
): Promise<BroadcastTxAsyncResponse | BroadcastTxSyncResponse | IndexedTx> {
|
|
301
306
|
const signedTransaction = await this.signTransaction(
|
|
302
307
|
wallet,
|
|
@@ -306,6 +311,7 @@ export class Post {
|
|
|
306
311
|
gasPrice,
|
|
307
312
|
memo,
|
|
308
313
|
gasAdjustment,
|
|
314
|
+
authenticators,
|
|
309
315
|
);
|
|
310
316
|
return this.sendSignedTransaction(signedTransaction, broadcastMode);
|
|
311
317
|
}
|
|
@@ -944,4 +950,41 @@ export class Post {
|
|
|
944
950
|
gasAdjustment,
|
|
945
951
|
);
|
|
946
952
|
}
|
|
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
|
+
}
|
|
947
990
|
}
|
|
@@ -1,10 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Secp256k1Pubkey } from '@cosmjs/amino';
|
|
2
|
+
import { fromBase64 } from '@cosmjs/encoding';
|
|
3
|
+
import { Int53 } from '@cosmjs/math';
|
|
4
|
+
import { EncodeObject, encodePubkey, makeAuthInfoBytes, makeSignDoc, OfflineDirectSigner } from '@cosmjs/proto-signing';
|
|
2
5
|
import { SigningStargateClient, StdFee } from '@cosmjs/stargate';
|
|
3
|
-
import {
|
|
6
|
+
import { TxExtension } from '@dydxprotocol/v4-proto/src/codegen/dydxprotocol/accountplus/tx';
|
|
7
|
+
import { TxBody, TxRaw } from 'cosmjs-types/cosmos/tx/v1beta1/tx';
|
|
8
|
+
import { Any } from 'cosmjs-types/google/protobuf/any';
|
|
4
9
|
import Long from 'long';
|
|
5
10
|
import protobuf from 'protobufjs';
|
|
6
11
|
|
|
7
|
-
import {
|
|
12
|
+
import { generateRegistry } from '../lib/registry';
|
|
8
13
|
import { TransactionOptions } from '../types';
|
|
9
14
|
|
|
10
15
|
// Required for encoding and decoding queries that are of type Long.
|
|
@@ -17,10 +22,16 @@ protobuf.configure();
|
|
|
17
22
|
export class TransactionSigner {
|
|
18
23
|
readonly address: string;
|
|
19
24
|
readonly stargateSigningClient: SigningStargateClient;
|
|
25
|
+
readonly offlineSigner: OfflineDirectSigner;
|
|
20
26
|
|
|
21
|
-
constructor(
|
|
27
|
+
constructor(
|
|
28
|
+
address: string,
|
|
29
|
+
stargateSigningClient: SigningStargateClient,
|
|
30
|
+
offlineSigner: OfflineDirectSigner,
|
|
31
|
+
) {
|
|
22
32
|
this.address = address;
|
|
23
33
|
this.stargateSigningClient = stargateSigningClient;
|
|
34
|
+
this.offlineSigner = offlineSigner;
|
|
24
35
|
}
|
|
25
36
|
|
|
26
37
|
/**
|
|
@@ -35,18 +46,73 @@ export class TransactionSigner {
|
|
|
35
46
|
transactionOptions: TransactionOptions,
|
|
36
47
|
fee?: StdFee,
|
|
37
48
|
memo: string = '',
|
|
49
|
+
publicKey?: Secp256k1Pubkey,
|
|
38
50
|
): Promise<Uint8Array> {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
throw new UserError('fee cannot be undefined');
|
|
51
|
+
if (!fee) {
|
|
52
|
+
throw new Error('Fee cannot be undefined');
|
|
42
53
|
}
|
|
43
54
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
55
|
+
const registry = generateRegistry();
|
|
56
|
+
|
|
57
|
+
// Encode the messages
|
|
58
|
+
const encodedMessages = messages.map((msg) => registry.encodeAsAny(msg));
|
|
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,
|
|
49
79
|
});
|
|
50
|
-
|
|
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());
|
|
51
117
|
}
|
|
52
118
|
}
|
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type {
|
|
2
|
+
ComplianceResponse,
|
|
3
|
+
ComplianceV2Response,
|
|
4
|
+
HeightResponse,
|
|
5
|
+
TimeResponse,
|
|
6
|
+
} from '../types';
|
|
2
7
|
import RestClient from './rest';
|
|
3
8
|
|
|
4
9
|
export default class UtilityClient extends RestClient {
|
|
@@ -29,4 +34,14 @@ export default class UtilityClient extends RestClient {
|
|
|
29
34
|
const uri = '/v4/screen';
|
|
30
35
|
return this.get(uri, { address });
|
|
31
36
|
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* @description Screen an address to see if it is restricted
|
|
40
|
+
* @param {string} address evm or dydx address
|
|
41
|
+
* @returns {ComplianceResponse} whether the specified address is restricted
|
|
42
|
+
*/
|
|
43
|
+
async complianceScreen(address: string): Promise<ComplianceV2Response> {
|
|
44
|
+
const uri = `/v4/compliance/screen/${address}`;
|
|
45
|
+
return this.get(uri);
|
|
46
|
+
}
|
|
32
47
|
}
|
package/src/clients/types.ts
CHANGED
|
@@ -29,6 +29,7 @@ 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[];
|
|
32
33
|
}
|
|
33
34
|
|
|
34
35
|
// OrderFlags, just a number in proto, defined as enum for convenience
|
|
@@ -104,6 +105,30 @@ export interface HeightResponse {
|
|
|
104
105
|
|
|
105
106
|
export interface ComplianceResponse {
|
|
106
107
|
restricted: boolean;
|
|
108
|
+
reason?: string;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export enum ComplianceReason {
|
|
112
|
+
MANUAL = 'MANUAL',
|
|
113
|
+
US_GEO = 'US_GEO',
|
|
114
|
+
CA_GEO = 'CA_GEO',
|
|
115
|
+
GB_GEO = 'GB_GEO',
|
|
116
|
+
SANCTIONED_GEO = 'SANCTIONED_GEO',
|
|
117
|
+
COMPLIANCE_PROVIDER = 'COMPLIANCE_PROVIDER',
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export enum ComplianceStatus {
|
|
121
|
+
COMPLIANT = 'COMPLIANT',
|
|
122
|
+
FIRST_STRIKE_CLOSE_ONLY = 'FIRST_STRIKE_CLOSE_ONLY',
|
|
123
|
+
FIRST_STRIKE = 'FIRST_STRIKE',
|
|
124
|
+
CLOSE_ONLY = 'CLOSE_ONLY',
|
|
125
|
+
BLOCKED = 'BLOCKED',
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export interface ComplianceV2Response {
|
|
129
|
+
status: ComplianceStatus;
|
|
130
|
+
reason?: ComplianceReason;
|
|
131
|
+
updatedAt?: string;
|
|
107
132
|
}
|
|
108
133
|
|
|
109
134
|
// ------------ Squid ------------ //
|