@dydxprotocol/v4-client-js 0.30.0 → 0.30.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.
@@ -8,7 +8,7 @@ import { Order_Side, Order_TimeInForce } from '@dydxprotocol/dydxjs/src/codegen/
8
8
  import * as AuthModule from 'cosmjs-types/cosmos/auth/v1beta1/query';
9
9
  import Long from 'long';
10
10
 
11
- import { BECH32_PREFIX, USDC_DENOM } from '../lib/constants';
11
+ import { BECH32_PREFIX, GAS_PRICE_DYDX_DENOM, USDC_DENOM } from '../lib/constants';
12
12
  import { UserError } from '../lib/errors';
13
13
  import { encodeJson } from '../lib/helpers';
14
14
  import { deriveHDKeyFromEthereumSignature } from '../lib/onboarding';
@@ -360,6 +360,7 @@ export async function withdraw(
360
360
  const tx = await client.withdrawFromSubaccount(
361
361
  subaccount,
362
362
  amount,
363
+ json.recipient,
363
364
  );
364
365
  return encodeJson(tx);
365
366
  } catch (error) {
@@ -444,6 +445,53 @@ export async function withdrawToIBC(
444
445
  }
445
446
  }
446
447
 
448
+ export async function transferNativeToken(
449
+ payload: string,
450
+ ): Promise<string> {
451
+ try {
452
+ const client = globalThis.client;
453
+ if (client === undefined) {
454
+ throw new UserError('client is not connected. Call connectClient() first');
455
+ }
456
+ const wallet = globalThis.wallet;
457
+ if (wallet === undefined) {
458
+ throw new UserError('wallet is not set. Call connectWallet() first');
459
+ }
460
+
461
+ const json = JSON.parse(payload);
462
+ const subaccountNumber = json.subaccountNumber;
463
+ if (subaccountNumber === undefined) {
464
+ throw new UserError('subaccountNumber is not set');
465
+ }
466
+ const amount = json.amount;
467
+ if (amount === undefined) {
468
+ throw new UserError('amount is not set');
469
+ }
470
+
471
+ const subaccount = new Subaccount(wallet, subaccountNumber);
472
+ const msg: EncodeObject = client.sendTokenMessage(
473
+ subaccount,
474
+ amount,
475
+ json.recipient,
476
+ );
477
+ const msgs = [msg];
478
+ const encodeObjects: Promise<EncodeObject[]> = new Promise((resolve) => resolve(msgs));
479
+
480
+ const tx = await client.send(
481
+ wallet,
482
+ () => {
483
+ return encodeObjects;
484
+ },
485
+ false,
486
+ GAS_PRICE_DYDX_DENOM,
487
+ undefined,
488
+ );
489
+ return encodeJson(tx);
490
+ } catch (error) {
491
+ return wrappedError(error);
492
+ }
493
+ }
494
+
447
495
  export async function getAccountBalance(): Promise<String> {
448
496
  try {
449
497
  const client = globalThis.client;
@@ -567,6 +615,7 @@ export async function simulateWithdraw(
567
615
  const msg: EncodeObject = client.withdrawFromSubaccountMessage(
568
616
  subaccount,
569
617
  amount,
618
+ json.recipient,
570
619
  );
571
620
  const msgs: EncodeObject[] = [msg];
572
621
  const encodeObjects: Promise<EncodeObject[]> = new Promise((resolve) => resolve(msgs));
@@ -579,6 +628,53 @@ export async function simulateWithdraw(
579
628
  }
580
629
  }
581
630
 
631
+ export async function simulateTransferNativeToken(
632
+ payload: string,
633
+ ): Promise<string> {
634
+ try {
635
+ const client = globalThis.client;
636
+ if (client === undefined) {
637
+ throw new UserError('client is not connected. Call connectClient() first');
638
+ }
639
+ const wallet = globalThis.wallet;
640
+ if (wallet === undefined) {
641
+ throw new UserError('wallet is not set. Call connectWallet() first');
642
+ }
643
+ const json = JSON.parse(payload);
644
+ const subaccountNumber = json.subaccountNumber;
645
+ if (subaccountNumber === undefined) {
646
+ throw new UserError('subaccountNumber is not set');
647
+ }
648
+ const recipient = json.recipient;
649
+ if (recipient === undefined) {
650
+ throw new UserError('recipient is not set');
651
+ }
652
+ const amount = json.amount;
653
+ if (amount === undefined) {
654
+ throw new UserError('amount is not set');
655
+ }
656
+
657
+ const subaccount = new Subaccount(wallet, subaccountNumber);
658
+ const msg: EncodeObject = client.sendTokenMessage(
659
+ subaccount,
660
+ amount,
661
+ json.recipient,
662
+ );
663
+ const msgs: EncodeObject[] = [msg];
664
+ const encodeObjects: Promise<EncodeObject[]> = new Promise((resolve) => resolve(msgs));
665
+ const stdFee = await client.simulate(
666
+ globalThis.wallet,
667
+ () => {
668
+ return encodeObjects;
669
+ },
670
+ GAS_PRICE_DYDX_DENOM,
671
+ );
672
+ return encodeJson(stdFee);
673
+ } catch (error) {
674
+ return wrappedError(error);
675
+ }
676
+ }
677
+
582
678
  export async function signRawPlaceOrder(
583
679
  subaccountNumber: number,
584
680
  clientId: number,