@pear-protocol/core-sdk 2.0.0 → 2.2.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.
@@ -61,7 +61,26 @@ class Core {
61
61
  method: "POST",
62
62
  headers
63
63
  });
64
- }, "restore")
64
+ }, "restore"),
65
+ createVault: /* @__PURE__ */ __name(async (body, headers) => {
66
+ return await this.client.fetch(`/trade-accounts/vault`, {
67
+ method: "POST",
68
+ headers,
69
+ body
70
+ });
71
+ }, "createVault"),
72
+ getVaultStatus: /* @__PURE__ */ __name(async (vaultAddress, headers) => {
73
+ return await this.client.fetch(`/trade-accounts/vault/${vaultAddress}`, {
74
+ method: "GET",
75
+ headers
76
+ });
77
+ }, "getVaultStatus"),
78
+ refreshVault: /* @__PURE__ */ __name(async (vaultAddress, headers) => {
79
+ return await this.client.fetch(`/trade-accounts/vault/${vaultAddress}/refresh`, {
80
+ method: "POST",
81
+ headers
82
+ });
83
+ }, "refreshVault")
65
84
  };
66
85
  fee = {
67
86
  // Resolves the trading fee and connector fee recipient for the caller's selected trade account.
@@ -631,7 +650,15 @@ class Core {
631
650
  headers,
632
651
  body
633
652
  });
634
- }, "setLeverage")
653
+ }, "setLeverage"),
654
+ /** Add or remove margin from an isolated position without changing its size. */
655
+ adjustIsolatedMargin: /* @__PURE__ */ __name(async (body, headers) => {
656
+ return await this.client.fetch(`/margin`, {
657
+ method: "POST",
658
+ headers,
659
+ body
660
+ });
661
+ }, "adjustIsolatedMargin")
635
662
  };
636
663
  triggers = {
637
664
  list: /* @__PURE__ */ __name(async (query, headers) => {
@@ -692,52 +719,80 @@ class Core {
692
719
  };
693
720
  misc = {
694
721
  lighter: {
722
+ ...this.buildLighterMiscRoutes("/misc/lighter"),
723
+ /** Mints the Fun.xyz universal deposit addresses that credit a wallet's Lighter account. */
724
+ createUda: /* @__PURE__ */ __name(async (body, headers) => {
725
+ return await this.client.fetch(`/misc/lighter/uda`, {
726
+ method: "POST",
727
+ headers,
728
+ body
729
+ });
730
+ }, "createUda"),
731
+ /** Reads the deposits the Fun.xyz bridge has seen for one wallet. */
732
+ listUdaDeposits: /* @__PURE__ */ __name(async (walletAddress, headers) => {
733
+ return await this.client.fetch(`/misc/lighter/uda/${encodeURIComponent(walletAddress)}`, {
734
+ method: "GET",
735
+ headers
736
+ });
737
+ }, "listUdaDeposits")
738
+ },
739
+ // Lighter's Robinhood Chain deployment: the same signer surface bound to the RHC host and
740
+ // chain id. The Fun.xyz UDA routes stay zkLighter-only, so this client carries no deposit
741
+ // surface at all.
742
+ lighterRhc: this.buildLighterMiscRoutes("/misc/lighter-rhc")
743
+ };
744
+ /**
745
+ * The signer routes every Lighter deployment exposes, bound to one deployment's base path.
746
+ * zkLighter and Robinhood Chain share this whole surface; only the deployment behind it differs.
747
+ */
748
+ buildLighterMiscRoutes(basePath) {
749
+ return {
695
750
  createApiKey: /* @__PURE__ */ __name(async (body, headers) => {
696
- return await this.client.fetch(`/misc/lighter/create-api-key`, {
751
+ return await this.client.fetch(`${basePath}/create-api-key`, {
697
752
  method: "POST",
698
753
  headers,
699
754
  body
700
755
  });
701
756
  }, "createApiKey"),
702
757
  changePubKey: /* @__PURE__ */ __name(async (body, headers) => {
703
- return await this.client.fetch(`/misc/lighter/change-pub-key`, {
758
+ return await this.client.fetch(`${basePath}/change-pub-key`, {
704
759
  method: "POST",
705
760
  headers,
706
761
  body
707
762
  });
708
763
  }, "changePubKey"),
709
764
  prepareApproveIntegrator: /* @__PURE__ */ __name(async (body, headers) => {
710
- return await this.client.fetch(`/misc/lighter/prepare-approve-integrator`, {
765
+ return await this.client.fetch(`${basePath}/prepare-approve-integrator`, {
711
766
  method: "POST",
712
767
  headers,
713
768
  body
714
769
  });
715
770
  }, "prepareApproveIntegrator"),
716
771
  submitApproveIntegrator: /* @__PURE__ */ __name(async (body, headers) => {
717
- return await this.client.fetch(`/misc/lighter/submit-approve-integrator`, {
772
+ return await this.client.fetch(`${basePath}/submit-approve-integrator`, {
718
773
  method: "POST",
719
774
  headers,
720
775
  body
721
776
  });
722
777
  }, "submitApproveIntegrator"),
723
778
  createAuthToken: /* @__PURE__ */ __name(async (body, headers) => {
724
- return await this.client.fetch(`/misc/lighter/create-auth-token`, {
779
+ return await this.client.fetch(`${basePath}/create-auth-token`, {
725
780
  method: "POST",
726
781
  headers,
727
782
  body
728
783
  });
729
784
  }, "createAuthToken"),
730
- /** Prepares a fast USDC withdrawal for L1 wallet authorization. */
785
+ /** Prepares a fast collateral withdrawal for L1 wallet authorization. */
731
786
  prepareFastWithdraw: /* @__PURE__ */ __name(async (body, headers) => {
732
- return await this.client.fetch(`/misc/lighter/prepare-fast-withdraw`, {
787
+ return await this.client.fetch(`${basePath}/prepare-fast-withdraw`, {
733
788
  method: "POST",
734
789
  headers,
735
790
  body
736
791
  });
737
792
  }, "prepareFastWithdraw"),
738
- /** Submits a wallet-authorized fast USDC withdrawal. */
793
+ /** Submits a wallet-authorized fast collateral withdrawal. */
739
794
  submitFastWithdraw: /* @__PURE__ */ __name(async (body, headers) => {
740
- return await this.client.fetch(`/misc/lighter/submit-fast-withdraw`, {
795
+ return await this.client.fetch(`${basePath}/submit-fast-withdraw`, {
741
796
  method: "POST",
742
797
  headers,
743
798
  body
@@ -745,29 +800,14 @@ class Core {
745
800
  }, "submitFastWithdraw"),
746
801
  /** Moves a Lighter account onto the standard, plus, or premium tier. */
747
802
  changeAccountTier: /* @__PURE__ */ __name(async (body, headers) => {
748
- return await this.client.fetch(`/misc/lighter/change-account-tier`, {
749
- method: "POST",
750
- headers,
751
- body
752
- });
753
- }, "changeAccountTier"),
754
- /** Mints the Fun.xyz universal deposit addresses that credit a wallet's Lighter account. */
755
- createUda: /* @__PURE__ */ __name(async (body, headers) => {
756
- return await this.client.fetch(`/misc/lighter/uda`, {
803
+ return await this.client.fetch(`${basePath}/change-account-tier`, {
757
804
  method: "POST",
758
805
  headers,
759
806
  body
760
807
  });
761
- }, "createUda"),
762
- /** Reads the deposits the Fun.xyz bridge has seen for one wallet. */
763
- listUdaDeposits: /* @__PURE__ */ __name(async (walletAddress, headers) => {
764
- return await this.client.fetch(`/misc/lighter/uda/${encodeURIComponent(walletAddress)}`, {
765
- method: "GET",
766
- headers
767
- });
768
- }, "listUdaDeposits")
769
- }
770
- };
808
+ }, "changeAccountTier")
809
+ };
810
+ }
771
811
  statistics = {
772
812
  volume: /* @__PURE__ */ __name(async (query, headers) => {
773
813
  return await this.client.fetch(`/statistics/volume`, {
package/dist/index.d.ts CHANGED
@@ -8,6 +8,8 @@ export * from '@pear-protocol/utils';
8
8
  export { FetchError } from './utils.js';
9
9
  import './http.js';
10
10
 
11
+ /** Header that makes a request act as a Pear vault (see `SDKConfig.getVaultAddress`). */
12
+ declare const VAULT_ADDRESS_HEADER = "pear-vault-address";
11
13
  declare class PearSDK {
12
14
  auth: Auth;
13
15
  core: Core;
@@ -15,4 +17,4 @@ declare class PearSDK {
15
17
  constructor(config: SDKConfig);
16
18
  }
17
19
 
18
- export { External, PearSDK as default };
20
+ export { External, VAULT_ADDRESS_HEADER, PearSDK as default };
package/dist/index.js CHANGED
@@ -10,6 +10,7 @@ export { FetchError } from './utils';
10
10
 
11
11
  var __defProp = Object.defineProperty;
12
12
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
13
+ const VAULT_ADDRESS_HEADER = "pear-vault-address";
13
14
  class PearSDK {
14
15
  static {
15
16
  __name(this, "PearSDK");
@@ -161,10 +162,16 @@ class PearSDK {
161
162
  client.useResponse(apiKeyAuthMiddleware);
162
163
  }
163
164
  }
164
- if (config.getTradeAccountId) {
165
+ if (config.getTradeAccountId || config.getVaultAddress) {
165
166
  const getTradeAccountId = config.getTradeAccountId;
167
+ const getVaultAddress = config.getVaultAddress;
166
168
  client.useRequest(async (request, next) => {
167
- const tradeAccountId = getTradeAccountId();
169
+ const vaultAddress = getVaultAddress?.();
170
+ if (vaultAddress) {
171
+ request.headers.set(VAULT_ADDRESS_HEADER, vaultAddress);
172
+ return next();
173
+ }
174
+ const tradeAccountId = getTradeAccountId?.();
168
175
  if (tradeAccountId) {
169
176
  request.headers.set("x-trade-account-id", tradeAccountId);
170
177
  }
@@ -192,4 +199,4 @@ function readBearerCredential(request) {
192
199
  }
193
200
  __name(readBearerCredential, "readBearerCredential");
194
201
 
195
- export { PearSDK as default };
202
+ export { VAULT_ADDRESS_HEADER, PearSDK as default };
package/dist/types.d.ts CHANGED
@@ -62,6 +62,17 @@ type SDKConfig = {
62
62
  * Example: () => localStorage.getState().activeTradeAccountId
63
63
  */
64
64
  getTradeAccountId?: () => string | null;
65
+ /**
66
+ * Pear vault address getter (used in both modes). When it returns an address the
67
+ * request carries the `pear-vault-address` header and acts as that vault: the
68
+ * backend authorizes the caller as the vault's owner/trader and resolves the
69
+ * vault's own trade account, so the trade-account header is not sent. For a
70
+ * one-off call without this hook, pass `{ [VAULT_ADDRESS_HEADER]: address }` as
71
+ * the call's headers.
72
+ *
73
+ * Example: () => useSessionStore.getState().activeVault?.address ?? null
74
+ */
75
+ getVaultAddress?: () => string | null;
65
76
  /**
66
77
  * Default attribution client code (client_ids.code). When set, it is
67
78
  * auto-added to the body of trade / trigger / schedule / rebalance requests
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pear-protocol/core-sdk",
3
- "version": "2.0.0",
3
+ "version": "2.2.0",
4
4
  "description": "Pear Protocol Core SDK",
5
5
  "private": false,
6
6
  "type": "module",
@@ -26,8 +26,8 @@
26
26
  "typecheck": "tsc --noEmit"
27
27
  },
28
28
  "dependencies": {
29
- "@pear-protocol/types": "^2.0.0",
30
- "@pear-protocol/utils": "^1.0.0",
29
+ "@pear-protocol/types": "^2.2.0",
30
+ "@pear-protocol/utils": "^1.1.0",
31
31
  "qs": "^6.14.0"
32
32
  },
33
33
  "devDependencies": {