@dydxprotocol/v4-client-js 1.0.0 → 1.0.2
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/__native__/__ios__/v4-native-client.js +63 -22
- package/__tests__/modules/client/Transfers.test.ts +3 -3
- package/__tests__/modules/client/ValidatorPostEndpoints.test.ts +2 -2
- package/build/__tests__/modules/client/Transfers.test.js +2 -2
- package/build/__tests__/modules/client/ValidatorPostEndpoints.test.js +2 -2
- package/build/examples/composite_example.js +2 -2
- package/build/examples/long_term_order_cancel_example.js +2 -2
- package/build/examples/short_term_order_cancel_example.js +2 -2
- package/build/examples/short_term_order_composite_example.js +2 -2
- package/build/examples/test.js +2 -2
- package/build/examples/transfer_example_deposit.js +2 -2
- package/build/examples/transfer_example_send.js +2 -2
- package/build/examples/transfer_example_subaccount_transfer.js +2 -2
- package/build/examples/transfer_example_withdraw.js +2 -2
- package/build/examples/transfer_example_withdraw_other.js +2 -2
- package/build/examples/validator_post_example.js +2 -2
- package/build/src/clients/composite-client.d.ts +13 -13
- package/build/src/clients/composite-client.js +1 -1
- package/build/src/clients/modules/post.d.ts +9 -9
- package/build/src/clients/modules/post.js +1 -1
- package/build/src/clients/native.d.ts +1 -0
- package/build/src/clients/native.js +26 -11
- package/build/src/clients/subaccount.d.ts +1 -1
- package/build/src/clients/subaccount.js +4 -4
- package/build/src/index.d.ts +1 -1
- package/build/src/index.js +2 -2
- package/build/src/lib/helpers.d.ts +5 -1
- package/build/src/lib/helpers.js +30 -5
- package/examples/composite_example.ts +2 -2
- package/examples/long_term_order_cancel_example.ts +2 -2
- package/examples/short_term_order_cancel_example.ts +2 -2
- package/examples/short_term_order_composite_example.ts +2 -2
- package/examples/test.ts +2 -2
- package/examples/transfer_example_deposit.ts +2 -2
- package/examples/transfer_example_send.ts +2 -2
- package/examples/transfer_example_subaccount_transfer.ts +2 -2
- package/examples/transfer_example_withdraw.ts +2 -2
- package/examples/transfer_example_withdraw_other.ts +2 -2
- package/examples/validator_post_example.ts +2 -2
- package/package.json +1 -1
- package/src/clients/composite-client.ts +15 -15
- package/src/clients/modules/post.ts +9 -9
- package/src/clients/native.ts +25 -11
- package/src/clients/subaccount.ts +1 -1
- package/src/index.ts +1 -1
- package/src/lib/helpers.ts +30 -3
|
@@ -3,7 +3,7 @@ import Long from 'long';
|
|
|
3
3
|
import { BECH32_PREFIX } from '../src';
|
|
4
4
|
import { Network } from '../src/clients/constants';
|
|
5
5
|
import LocalWallet from '../src/clients/modules/local-wallet';
|
|
6
|
-
import {
|
|
6
|
+
import { SubaccountInfo } from '../src/clients/subaccount';
|
|
7
7
|
import { ValidatorClient } from '../src/clients/validator-client';
|
|
8
8
|
import { DYDX_TEST_MNEMONIC } from './constants';
|
|
9
9
|
|
|
@@ -15,7 +15,7 @@ async function test(): Promise<void> {
|
|
|
15
15
|
console.log('**Client**');
|
|
16
16
|
console.log(client);
|
|
17
17
|
|
|
18
|
-
const subaccount = new
|
|
18
|
+
const subaccount = new SubaccountInfo(wallet, 0);
|
|
19
19
|
|
|
20
20
|
const tx = await client.post.transfer(
|
|
21
21
|
subaccount,
|
|
@@ -3,7 +3,7 @@ import Long from 'long';
|
|
|
3
3
|
import { BECH32_PREFIX } from '../src';
|
|
4
4
|
import { Network } from '../src/clients/constants';
|
|
5
5
|
import LocalWallet from '../src/clients/modules/local-wallet';
|
|
6
|
-
import {
|
|
6
|
+
import { SubaccountInfo } from '../src/clients/subaccount';
|
|
7
7
|
import { ValidatorClient } from '../src/clients/validator-client';
|
|
8
8
|
import { DYDX_TEST_MNEMONIC } from './constants';
|
|
9
9
|
|
|
@@ -17,7 +17,7 @@ async function test(): Promise<void> {
|
|
|
17
17
|
console.log('**Client**');
|
|
18
18
|
console.log(client);
|
|
19
19
|
|
|
20
|
-
const subaccount = new
|
|
20
|
+
const subaccount = new SubaccountInfo(wallet, 0);
|
|
21
21
|
|
|
22
22
|
const tx = await client.post.withdraw(
|
|
23
23
|
subaccount,
|
|
@@ -6,7 +6,7 @@ import { TEST_RECIPIENT_ADDRESS } from '../__tests__/helpers/constants';
|
|
|
6
6
|
import { BECH32_PREFIX } from '../src';
|
|
7
7
|
import { Network } from '../src/clients/constants';
|
|
8
8
|
import LocalWallet from '../src/clients/modules/local-wallet';
|
|
9
|
-
import {
|
|
9
|
+
import { SubaccountInfo } from '../src/clients/subaccount';
|
|
10
10
|
import { ValidatorClient } from '../src/clients/validator-client';
|
|
11
11
|
import { DYDX_TEST_MNEMONIC } from './constants';
|
|
12
12
|
|
|
@@ -18,7 +18,7 @@ async function test(): Promise<void> {
|
|
|
18
18
|
console.log('**Client**');
|
|
19
19
|
console.log(client);
|
|
20
20
|
|
|
21
|
-
const subaccount = new
|
|
21
|
+
const subaccount = new SubaccountInfo(wallet, 0);
|
|
22
22
|
|
|
23
23
|
const amount = new Long(100_000_000);
|
|
24
24
|
|
|
@@ -4,7 +4,7 @@ import protobuf from 'protobufjs';
|
|
|
4
4
|
import { BECH32_PREFIX } from '../src';
|
|
5
5
|
import { Network } from '../src/clients/constants';
|
|
6
6
|
import LocalWallet from '../src/clients/modules/local-wallet';
|
|
7
|
-
import {
|
|
7
|
+
import { SubaccountInfo } from '../src/clients/subaccount';
|
|
8
8
|
import { IPlaceOrder } from '../src/clients/types';
|
|
9
9
|
import { ValidatorClient } from '../src/clients/validator-client';
|
|
10
10
|
import { randomInt } from '../src/lib/utils';
|
|
@@ -40,7 +40,7 @@ async function test(): Promise<void> {
|
|
|
40
40
|
const value1 = Long.fromNumber(400000000000);
|
|
41
41
|
console.log(value1.toString());
|
|
42
42
|
|
|
43
|
-
const subaccount = new
|
|
43
|
+
const subaccount = new SubaccountInfo(wallet, 0);
|
|
44
44
|
for (const orderParams of ordersParams) {
|
|
45
45
|
const height = await client.get.latestBlockHeight();
|
|
46
46
|
const placeOrder = dummyOrder(height);
|
package/package.json
CHANGED
|
@@ -32,7 +32,7 @@ import {
|
|
|
32
32
|
import { IndexerClient } from './indexer-client';
|
|
33
33
|
import { UserError } from './lib/errors';
|
|
34
34
|
import LocalWallet from './modules/local-wallet';
|
|
35
|
-
import {
|
|
35
|
+
import { SubaccountInfo } from './subaccount';
|
|
36
36
|
import { ValidatorClient } from './validator-client';
|
|
37
37
|
|
|
38
38
|
// Required for encoding and decoding queries that are of type Long.
|
|
@@ -268,7 +268,7 @@ export class CompositeClient {
|
|
|
268
268
|
* @returns The transaction hash.
|
|
269
269
|
*/
|
|
270
270
|
async placeShortTermOrder(
|
|
271
|
-
subaccount:
|
|
271
|
+
subaccount: SubaccountInfo,
|
|
272
272
|
marketId: string,
|
|
273
273
|
side: OrderSide,
|
|
274
274
|
price: number,
|
|
@@ -340,7 +340,7 @@ export class CompositeClient {
|
|
|
340
340
|
* @returns The transaction hash.
|
|
341
341
|
*/
|
|
342
342
|
async placeOrder(
|
|
343
|
-
subaccount:
|
|
343
|
+
subaccount: SubaccountInfo,
|
|
344
344
|
marketId: string,
|
|
345
345
|
type: OrderType,
|
|
346
346
|
side: OrderSide,
|
|
@@ -420,7 +420,7 @@ export class CompositeClient {
|
|
|
420
420
|
* @returns The message to be passed into the protocol
|
|
421
421
|
*/
|
|
422
422
|
private async placeOrderMessage(
|
|
423
|
-
subaccount:
|
|
423
|
+
subaccount: SubaccountInfo,
|
|
424
424
|
marketId: string,
|
|
425
425
|
type: OrderType,
|
|
426
426
|
side: OrderSide,
|
|
@@ -541,7 +541,7 @@ export class CompositeClient {
|
|
|
541
541
|
* @returns The message to be passed into the protocol
|
|
542
542
|
*/
|
|
543
543
|
private async placeShortTermOrderMessage(
|
|
544
|
-
subaccount:
|
|
544
|
+
subaccount: SubaccountInfo,
|
|
545
545
|
marketId: string,
|
|
546
546
|
side: OrderSide,
|
|
547
547
|
price: number,
|
|
@@ -607,7 +607,7 @@ export class CompositeClient {
|
|
|
607
607
|
* @returns The transaction hash.
|
|
608
608
|
*/
|
|
609
609
|
async cancelRawOrder(
|
|
610
|
-
subaccount:
|
|
610
|
+
subaccount: SubaccountInfo,
|
|
611
611
|
clientId: number,
|
|
612
612
|
orderFlags: OrderFlags,
|
|
613
613
|
clobPairId: number,
|
|
@@ -639,7 +639,7 @@ export class CompositeClient {
|
|
|
639
639
|
* @returns The transaction hash.
|
|
640
640
|
*/
|
|
641
641
|
async cancelOrder(
|
|
642
|
-
subaccount:
|
|
642
|
+
subaccount: SubaccountInfo,
|
|
643
643
|
clientId: number,
|
|
644
644
|
orderFlags: OrderFlags,
|
|
645
645
|
marketId: string,
|
|
@@ -699,7 +699,7 @@ export class CompositeClient {
|
|
|
699
699
|
* @returns The transaction hash.
|
|
700
700
|
*/
|
|
701
701
|
async transferToSubaccount(
|
|
702
|
-
subaccount:
|
|
702
|
+
subaccount: SubaccountInfo,
|
|
703
703
|
recipientAddress: string,
|
|
704
704
|
recipientSubaccountNumber: number,
|
|
705
705
|
amount: string,
|
|
@@ -733,7 +733,7 @@ export class CompositeClient {
|
|
|
733
733
|
* @returns The message
|
|
734
734
|
*/
|
|
735
735
|
transferToSubaccountMessage(
|
|
736
|
-
subaccount:
|
|
736
|
+
subaccount: SubaccountInfo,
|
|
737
737
|
recipientAddress: string,
|
|
738
738
|
recipientSubaccountNumber: number,
|
|
739
739
|
amount: string,
|
|
@@ -771,7 +771,7 @@ export class CompositeClient {
|
|
|
771
771
|
* @returns The transaction hash.
|
|
772
772
|
*/
|
|
773
773
|
async depositToSubaccount(
|
|
774
|
-
subaccount:
|
|
774
|
+
subaccount: SubaccountInfo,
|
|
775
775
|
amount: string,
|
|
776
776
|
): Promise<BroadcastTxAsyncResponse | BroadcastTxSyncResponse | IndexedTx> {
|
|
777
777
|
const msgs: Promise<EncodeObject[]> = new Promise((resolve) => {
|
|
@@ -797,7 +797,7 @@ export class CompositeClient {
|
|
|
797
797
|
* @returns The message
|
|
798
798
|
*/
|
|
799
799
|
depositToSubaccountMessage(
|
|
800
|
-
subaccount:
|
|
800
|
+
subaccount: SubaccountInfo,
|
|
801
801
|
amount: string,
|
|
802
802
|
): EncodeObject {
|
|
803
803
|
const validatorClient = this._validatorClient;
|
|
@@ -832,7 +832,7 @@ export class CompositeClient {
|
|
|
832
832
|
* @returns The transaction hash
|
|
833
833
|
*/
|
|
834
834
|
async withdrawFromSubaccount(
|
|
835
|
-
subaccount:
|
|
835
|
+
subaccount: SubaccountInfo,
|
|
836
836
|
amount: string,
|
|
837
837
|
recipient?: string,
|
|
838
838
|
): Promise<BroadcastTxAsyncResponse | BroadcastTxSyncResponse | IndexedTx> {
|
|
@@ -863,7 +863,7 @@ export class CompositeClient {
|
|
|
863
863
|
* @returns The message
|
|
864
864
|
*/
|
|
865
865
|
withdrawFromSubaccountMessage(
|
|
866
|
-
subaccount:
|
|
866
|
+
subaccount: SubaccountInfo,
|
|
867
867
|
amount: string,
|
|
868
868
|
recipient?: string,
|
|
869
869
|
): EncodeObject {
|
|
@@ -929,7 +929,7 @@ export class CompositeClient {
|
|
|
929
929
|
}
|
|
930
930
|
|
|
931
931
|
async signPlaceOrder(
|
|
932
|
-
subaccount:
|
|
932
|
+
subaccount: SubaccountInfo,
|
|
933
933
|
marketId: string,
|
|
934
934
|
type: OrderType,
|
|
935
935
|
side: OrderSide,
|
|
@@ -973,7 +973,7 @@ export class CompositeClient {
|
|
|
973
973
|
}
|
|
974
974
|
|
|
975
975
|
async signCancelOrder(
|
|
976
|
-
subaccount:
|
|
976
|
+
subaccount: SubaccountInfo,
|
|
977
977
|
clientId: number,
|
|
978
978
|
orderFlags: OrderFlags,
|
|
979
979
|
clobPairId: number,
|
|
@@ -25,7 +25,7 @@ import protobuf from 'protobufjs';
|
|
|
25
25
|
import { GAS_MULTIPLIER } from '../constants';
|
|
26
26
|
import { UnexpectedClientError } from '../lib/errors';
|
|
27
27
|
import { generateRegistry } from '../lib/registry';
|
|
28
|
-
import {
|
|
28
|
+
import { SubaccountInfo } from '../subaccount';
|
|
29
29
|
import {
|
|
30
30
|
OrderFlags,
|
|
31
31
|
BroadcastMode,
|
|
@@ -343,7 +343,7 @@ export class Post {
|
|
|
343
343
|
// ------ State-Changing Requests ------ //
|
|
344
344
|
|
|
345
345
|
async placeOrder(
|
|
346
|
-
subaccount:
|
|
346
|
+
subaccount: SubaccountInfo,
|
|
347
347
|
clientId: number,
|
|
348
348
|
clobPairId: number,
|
|
349
349
|
side: Order_Side,
|
|
@@ -392,7 +392,7 @@ export class Post {
|
|
|
392
392
|
}
|
|
393
393
|
|
|
394
394
|
async placeOrderObject(
|
|
395
|
-
subaccount:
|
|
395
|
+
subaccount: SubaccountInfo,
|
|
396
396
|
placeOrder: IPlaceOrder,
|
|
397
397
|
broadcastMode?: BroadcastMode,
|
|
398
398
|
): Promise<BroadcastTxAsyncResponse | BroadcastTxSyncResponse | IndexedTx> {
|
|
@@ -416,7 +416,7 @@ export class Post {
|
|
|
416
416
|
}
|
|
417
417
|
|
|
418
418
|
async cancelOrder(
|
|
419
|
-
subaccount:
|
|
419
|
+
subaccount: SubaccountInfo,
|
|
420
420
|
clientId: number,
|
|
421
421
|
orderFlags: OrderFlags,
|
|
422
422
|
clobPairId: number,
|
|
@@ -446,7 +446,7 @@ export class Post {
|
|
|
446
446
|
}
|
|
447
447
|
|
|
448
448
|
async cancelOrderObject(
|
|
449
|
-
subaccount:
|
|
449
|
+
subaccount: SubaccountInfo,
|
|
450
450
|
cancelOrder: ICancelOrder,
|
|
451
451
|
broadcastMode?: BroadcastMode,
|
|
452
452
|
): Promise<BroadcastTxAsyncResponse | BroadcastTxSyncResponse | IndexedTx> {
|
|
@@ -462,7 +462,7 @@ export class Post {
|
|
|
462
462
|
}
|
|
463
463
|
|
|
464
464
|
async transfer(
|
|
465
|
-
subaccount:
|
|
465
|
+
subaccount: SubaccountInfo,
|
|
466
466
|
recipientAddress: string,
|
|
467
467
|
recipientSubaccountNumber: number,
|
|
468
468
|
assetId: number,
|
|
@@ -491,7 +491,7 @@ export class Post {
|
|
|
491
491
|
}
|
|
492
492
|
|
|
493
493
|
async deposit(
|
|
494
|
-
subaccount:
|
|
494
|
+
subaccount: SubaccountInfo,
|
|
495
495
|
assetId: number,
|
|
496
496
|
quantums: Long,
|
|
497
497
|
broadcastMode?: BroadcastMode,
|
|
@@ -516,7 +516,7 @@ export class Post {
|
|
|
516
516
|
}
|
|
517
517
|
|
|
518
518
|
async withdraw(
|
|
519
|
-
subaccount:
|
|
519
|
+
subaccount: SubaccountInfo,
|
|
520
520
|
assetId: number,
|
|
521
521
|
quantums: Long,
|
|
522
522
|
recipient?: string,
|
|
@@ -543,7 +543,7 @@ export class Post {
|
|
|
543
543
|
}
|
|
544
544
|
|
|
545
545
|
async sendToken(
|
|
546
|
-
subaccount:
|
|
546
|
+
subaccount: SubaccountInfo,
|
|
547
547
|
recipient: string,
|
|
548
548
|
coinDenom: string,
|
|
549
549
|
quantums: string,
|
package/src/clients/native.ts
CHANGED
|
@@ -10,7 +10,7 @@ import Long from 'long';
|
|
|
10
10
|
|
|
11
11
|
import { BECH32_PREFIX } from '../lib/constants';
|
|
12
12
|
import { UserError } from '../lib/errors';
|
|
13
|
-
import { encodeJson } from '../lib/helpers';
|
|
13
|
+
import { ByteArrayEncoding, encodeJson } from '../lib/helpers';
|
|
14
14
|
import { deriveHDKeyFromEthereumSignature } from '../lib/onboarding';
|
|
15
15
|
import { NetworkOptimizer } from '../network_optimizer';
|
|
16
16
|
import { CompositeClient, MarketInfo } from './composite-client';
|
|
@@ -19,7 +19,7 @@ import {
|
|
|
19
19
|
} from './constants';
|
|
20
20
|
import { FaucetClient } from './faucet-client';
|
|
21
21
|
import LocalWallet from './modules/local-wallet';
|
|
22
|
-
import {
|
|
22
|
+
import { SubaccountInfo } from './subaccount';
|
|
23
23
|
import { OrderFlags } from './types';
|
|
24
24
|
|
|
25
25
|
declare global {
|
|
@@ -172,6 +172,20 @@ export async function getUserFeeTier(address: string): Promise<string> {
|
|
|
172
172
|
}
|
|
173
173
|
}
|
|
174
174
|
|
|
175
|
+
export async function getEquityTiers(): Promise<string> {
|
|
176
|
+
try {
|
|
177
|
+
const client = globalThis.client;
|
|
178
|
+
if (client === undefined) {
|
|
179
|
+
throw new UserError('client is not connected. Call connectClient() first');
|
|
180
|
+
}
|
|
181
|
+
const equityTiers = await globalThis.client?.validatorClient.get
|
|
182
|
+
.getEquityTierLimitConfiguration();
|
|
183
|
+
return encodeJson(equityTiers, ByteArrayEncoding.BIGINT);
|
|
184
|
+
} catch (e) {
|
|
185
|
+
return wrappedError(e);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
175
189
|
export async function getPerpetualMarkets(): Promise<string> {
|
|
176
190
|
try {
|
|
177
191
|
const client = globalThis.client;
|
|
@@ -238,7 +252,7 @@ export async function placeOrder(
|
|
|
238
252
|
const marketInfo = json.marketInfo as MarketInfo;
|
|
239
253
|
const currentHeight = json.currentHeight as number;
|
|
240
254
|
|
|
241
|
-
const subaccount = new
|
|
255
|
+
const subaccount = new SubaccountInfo(wallet, subaccountNumber);
|
|
242
256
|
const tx = await client.placeOrder(
|
|
243
257
|
subaccount,
|
|
244
258
|
marketId,
|
|
@@ -300,7 +314,7 @@ export async function cancelOrder(
|
|
|
300
314
|
const goodTilBlock = json.goodTilBlock;
|
|
301
315
|
const goodTilBlockTime = json.goodTilBlockTime;
|
|
302
316
|
|
|
303
|
-
const subaccount = new
|
|
317
|
+
const subaccount = new SubaccountInfo(wallet, subaccountNumber);
|
|
304
318
|
const tx = await client.cancelRawOrder(
|
|
305
319
|
subaccount,
|
|
306
320
|
clientId,
|
|
@@ -338,7 +352,7 @@ export async function deposit(
|
|
|
338
352
|
throw new UserError('amount is not set');
|
|
339
353
|
}
|
|
340
354
|
|
|
341
|
-
const subaccount = new
|
|
355
|
+
const subaccount = new SubaccountInfo(wallet, subaccountNumber);
|
|
342
356
|
const tx = await client.depositToSubaccount(
|
|
343
357
|
subaccount,
|
|
344
358
|
amount,
|
|
@@ -372,7 +386,7 @@ export async function withdraw(
|
|
|
372
386
|
throw new UserError('amount is not set');
|
|
373
387
|
}
|
|
374
388
|
|
|
375
|
-
const subaccount = new
|
|
389
|
+
const subaccount = new SubaccountInfo(wallet, subaccountNumber);
|
|
376
390
|
const tx = await client.withdrawFromSubaccount(
|
|
377
391
|
subaccount,
|
|
378
392
|
amount,
|
|
@@ -440,7 +454,7 @@ export async function withdrawToIBC(
|
|
|
440
454
|
value: json.msg,
|
|
441
455
|
};
|
|
442
456
|
|
|
443
|
-
const subaccount = new
|
|
457
|
+
const subaccount = new SubaccountInfo(wallet, subaccountNumber);
|
|
444
458
|
const subaccountMsg = client.withdrawFromSubaccountMessage(subaccount, amount);
|
|
445
459
|
|
|
446
460
|
const msgs = [subaccountMsg, ibcMsg];
|
|
@@ -583,7 +597,7 @@ export async function simulateDeposit(
|
|
|
583
597
|
throw new UserError('amount is not set');
|
|
584
598
|
}
|
|
585
599
|
|
|
586
|
-
const subaccount = new
|
|
600
|
+
const subaccount = new SubaccountInfo(wallet, subaccountNumber);
|
|
587
601
|
const msg: EncodeObject = client.depositToSubaccountMessage(
|
|
588
602
|
subaccount,
|
|
589
603
|
amount,
|
|
@@ -625,7 +639,7 @@ export async function simulateWithdraw(
|
|
|
625
639
|
throw new UserError('amount is not set');
|
|
626
640
|
}
|
|
627
641
|
|
|
628
|
-
const subaccount = new
|
|
642
|
+
const subaccount = new SubaccountInfo(wallet, subaccountNumber);
|
|
629
643
|
const msg: EncodeObject = client.withdrawFromSubaccountMessage(
|
|
630
644
|
subaccount,
|
|
631
645
|
amount,
|
|
@@ -766,7 +780,7 @@ export async function signPlaceOrder(
|
|
|
766
780
|
throw new UserError('wallet is not set. Call connectWallet() first');
|
|
767
781
|
}
|
|
768
782
|
|
|
769
|
-
const subaccount = new
|
|
783
|
+
const subaccount = new SubaccountInfo(wallet, subaccountNumber);
|
|
770
784
|
const signed = await client.signPlaceOrder(
|
|
771
785
|
subaccount,
|
|
772
786
|
marketId,
|
|
@@ -805,7 +819,7 @@ export async function signCancelOrder(
|
|
|
805
819
|
throw new UserError('wallet is not set. Call connectWallet() first');
|
|
806
820
|
}
|
|
807
821
|
|
|
808
|
-
const subaccount = new
|
|
822
|
+
const subaccount = new SubaccountInfo(wallet, subaccountNumber);
|
|
809
823
|
const signed = await client.signCancelOrder(
|
|
810
824
|
subaccount,
|
|
811
825
|
clientId,
|
package/src/index.ts
CHANGED
|
@@ -7,7 +7,7 @@ export * as validation from './lib/validation';
|
|
|
7
7
|
export * as onboarding from './lib/onboarding';
|
|
8
8
|
|
|
9
9
|
export { default as LocalWallet } from './clients/modules/local-wallet';
|
|
10
|
-
export {
|
|
10
|
+
export { SubaccountInfo as SubaccountClient } from './clients/subaccount';
|
|
11
11
|
export { CompositeClient } from './clients/composite-client';
|
|
12
12
|
export { IndexerClient } from './clients/indexer-client';
|
|
13
13
|
export { ValidatorClient } from './clients/validator-client';
|
package/src/lib/helpers.ts
CHANGED
|
@@ -38,7 +38,26 @@ export function stripHexPrefix(input: string): string {
|
|
|
38
38
|
return input;
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
|
|
41
|
+
function toBigInt(u: Uint8Array): BigInt {
|
|
42
|
+
if (u.length <= 1) {
|
|
43
|
+
return BigInt(0);
|
|
44
|
+
}
|
|
45
|
+
// eslint-disable-next-line no-bitwise
|
|
46
|
+
const negated: boolean = (u[0] & 1) === 1;
|
|
47
|
+
const hex: string = Buffer.from(u.slice(1)).toString('hex');
|
|
48
|
+
const abs: bigint = BigInt(`0x${hex}`);
|
|
49
|
+
return negated ? -abs : abs;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export enum ByteArrayEncoding {
|
|
53
|
+
HEX = 'hex',
|
|
54
|
+
BIGINT = 'bigint',
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function encodeJson(
|
|
58
|
+
object?: Object,
|
|
59
|
+
byteArrayEncoding: ByteArrayEncoding = ByteArrayEncoding.HEX,
|
|
60
|
+
): string {
|
|
42
61
|
// eslint-disable-next-line prefer-arrow-callback
|
|
43
62
|
return JSON.stringify(object, function replacer(_key, value) {
|
|
44
63
|
// Even though we set the an UInt8Array as the value,
|
|
@@ -50,9 +69,17 @@ export function encodeJson(object?: Object): string {
|
|
|
50
69
|
return value.toString();
|
|
51
70
|
}
|
|
52
71
|
if (value?.buffer instanceof Uint8Array) {
|
|
53
|
-
|
|
72
|
+
if (byteArrayEncoding === ByteArrayEncoding.HEX) {
|
|
73
|
+
return toHex(value.buffer);
|
|
74
|
+
} else {
|
|
75
|
+
return toBigInt(value.buffer).toString();
|
|
76
|
+
}
|
|
54
77
|
} else if (value instanceof Uint8Array) {
|
|
55
|
-
|
|
78
|
+
if (byteArrayEncoding === ByteArrayEncoding.HEX) {
|
|
79
|
+
return toHex(value);
|
|
80
|
+
} else {
|
|
81
|
+
return toBigInt(value).toString();
|
|
82
|
+
}
|
|
56
83
|
}
|
|
57
84
|
return value;
|
|
58
85
|
});
|