@pear-protocol/symmio-client 0.1.1 → 0.1.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/dist/index.mjs CHANGED
@@ -80,6 +80,10 @@ var MUON_BASE_URLS = [
80
80
  ];
81
81
  var MUON_APP_NAME = "symmio";
82
82
  var MUON_REQUEST_TIMEOUT = 15e3;
83
+ var HEDGER_BASE_URLS = {
84
+ [42161 /* ARBITRUM */]: "https://www.perps-streaming.com/v1/42161a/0x6273242a7E88b3De90822b31648C212215caaFE4",
85
+ [8453 /* BASE */]: "https://www.perps-streaming.com/v1/8453a/0x6273242a7E88b3De90822b31648C212215caaFE4"
86
+ };
83
87
  var SymmioSDKError = class extends Error {
84
88
  constructor(message, code) {
85
89
  super(message);
@@ -24106,6 +24110,13 @@ __export(instant_exports, {
24106
24110
  instantOpen: () => instantOpen,
24107
24111
  login: () => login
24108
24112
  });
24113
+ function getHedgerBaseUrl(chainId) {
24114
+ const baseUrl = HEDGER_BASE_URLS[chainId];
24115
+ if (!baseUrl) {
24116
+ throw new Error(`No hedger base URL configured for chain ${chainId}.`);
24117
+ }
24118
+ return baseUrl;
24119
+ }
24109
24120
  function createSiweMessage(params) {
24110
24121
  const version = params.version ?? "1";
24111
24122
  const issuedAt = (/* @__PURE__ */ new Date()).toISOString();
@@ -24127,7 +24138,8 @@ function createSiweMessage(params) {
24127
24138
  ].join("\n");
24128
24139
  return { message, issuedAt, expirationTime };
24129
24140
  }
24130
- async function getNonce(hedgerBaseUrl, subAccount) {
24141
+ async function getNonce(chainId, subAccount) {
24142
+ const hedgerBaseUrl = getHedgerBaseUrl(chainId);
24131
24143
  const url = new URL(`nonce/${subAccount}`, hedgerBaseUrl).href;
24132
24144
  const response = await fetch(url);
24133
24145
  if (!response.ok) {
@@ -24136,7 +24148,8 @@ async function getNonce(hedgerBaseUrl, subAccount) {
24136
24148
  const data = await response.json();
24137
24149
  return data.nonce;
24138
24150
  }
24139
- async function login(hedgerBaseUrl, params) {
24151
+ async function login(chainId, params) {
24152
+ const hedgerBaseUrl = getHedgerBaseUrl(chainId);
24140
24153
  const url = new URL("login", hedgerBaseUrl).href;
24141
24154
  const body = {
24142
24155
  account_address: params.accountAddress,
@@ -24166,7 +24179,8 @@ async function login(hedgerBaseUrl, params) {
24166
24179
  issuedAt: params.issuedAt
24167
24180
  };
24168
24181
  }
24169
- async function instantOpen(hedgerBaseUrl, params, accessToken) {
24182
+ async function instantOpen(chainId, params, accessToken) {
24183
+ const hedgerBaseUrl = getHedgerBaseUrl(chainId);
24170
24184
  const url = new URL("instant_open", hedgerBaseUrl).href;
24171
24185
  const body = {
24172
24186
  symbolId: params.symbolId,
@@ -24197,7 +24211,8 @@ async function instantOpen(hedgerBaseUrl, params, accessToken) {
24197
24211
  }
24198
24212
  return response.json();
24199
24213
  }
24200
- async function instantClose(hedgerBaseUrl, params, accessToken) {
24214
+ async function instantClose(chainId, params, accessToken) {
24215
+ const hedgerBaseUrl = getHedgerBaseUrl(chainId);
24201
24216
  const url = new URL("instant_close", hedgerBaseUrl).href;
24202
24217
  const body = {
24203
24218
  quote_id: params.quoteId,
@@ -24220,7 +24235,8 @@ async function instantClose(hedgerBaseUrl, params, accessToken) {
24220
24235
  }
24221
24236
  return response.json();
24222
24237
  }
24223
- async function cancelInstantClose(hedgerBaseUrl, quoteId, accessToken) {
24238
+ async function cancelInstantClose(chainId, quoteId, accessToken) {
24239
+ const hedgerBaseUrl = getHedgerBaseUrl(chainId);
24224
24240
  const url = new URL(`instant_close/${quoteId}`, hedgerBaseUrl).href;
24225
24241
  const response = await fetch(url, {
24226
24242
  method: "DELETE",
@@ -24236,7 +24252,8 @@ async function cancelInstantClose(hedgerBaseUrl, quoteId, accessToken) {
24236
24252
  );
24237
24253
  }
24238
24254
  }
24239
- async function getOpenInstantCloses(hedgerBaseUrl, account, accessToken) {
24255
+ async function getOpenInstantCloses(chainId, account, accessToken) {
24256
+ const hedgerBaseUrl = getHedgerBaseUrl(chainId);
24240
24257
  const url = new URL(`instant_close/${account}`, hedgerBaseUrl).href;
24241
24258
  const response = await fetch(url, {
24242
24259
  headers: {
@@ -24263,7 +24280,6 @@ var SymmioSDK = class {
24263
24280
  _collateral;
24264
24281
  _clearingHouse;
24265
24282
  _signatureStore;
24266
- _hedgerBaseUrl;
24267
24283
  constructor(options) {
24268
24284
  this.chainId = options.chainId;
24269
24285
  this._publicClient = options.publicClient;
@@ -24280,7 +24296,6 @@ var SymmioSDK = class {
24280
24296
  this._signatureStore = cfg.signatureStoreAddress ?? getAddress(SIGNATURE_STORE_ADDRESS, this.chainId, "SignatureStore");
24281
24297
  } catch {
24282
24298
  }
24283
- this._hedgerBaseUrl = cfg.hedgerBaseUrl;
24284
24299
  this.muon = new MuonClient({
24285
24300
  baseUrls: cfg.muonBaseUrls ?? MUON_BASE_URLS,
24286
24301
  appName: cfg.muonAppName ?? MUON_APP_NAME
@@ -24438,46 +24453,22 @@ var SymmioSDK = class {
24438
24453
  };
24439
24454
  }
24440
24455
  // ─── Instant Trading Module ──────────────────────────────────
24441
- _requireHedgerUrl() {
24442
- if (!this._hedgerBaseUrl) {
24443
- throw new Error(
24444
- "hedgerBaseUrl is required for instant trading. Pass it in the SDK config."
24445
- );
24446
- }
24447
- return this._hedgerBaseUrl;
24448
- }
24449
24456
  get instant() {
24450
24457
  return {
24451
24458
  /** Creates a SIWE message for instant trading authentication. */
24452
24459
  createSiweMessage: (params) => createSiweMessage(params),
24453
24460
  /** Fetches a nonce from the hedger for SIWE authentication. */
24454
- getNonce: (subAccount) => getNonce(this._requireHedgerUrl(), subAccount),
24461
+ getNonce: (subAccount) => getNonce(this.chainId, subAccount),
24455
24462
  /** Exchanges a signed SIWE message for an access token. */
24456
- login: (params) => login(this._requireHedgerUrl(), params),
24463
+ login: (params) => login(this.chainId, params),
24457
24464
  /** Opens a position instantly via the hedger (off-chain). */
24458
- open: (params, accessToken) => instantOpen(
24459
- this._requireHedgerUrl(),
24460
- params,
24461
- accessToken
24462
- ),
24465
+ open: (params, accessToken) => instantOpen(this.chainId, params, accessToken),
24463
24466
  /** Closes a position instantly via the hedger (off-chain). */
24464
- close: (params, accessToken) => instantClose(
24465
- this._requireHedgerUrl(),
24466
- params,
24467
- accessToken
24468
- ),
24467
+ close: (params, accessToken) => instantClose(this.chainId, params, accessToken),
24469
24468
  /** Cancels a pending instant close request. */
24470
- cancelClose: (quoteId, accessToken) => cancelInstantClose(
24471
- this._requireHedgerUrl(),
24472
- quoteId,
24473
- accessToken
24474
- ),
24469
+ cancelClose: (quoteId, accessToken) => cancelInstantClose(this.chainId, quoteId, accessToken),
24475
24470
  /** Fetches the list of open instant close requests for an account. */
24476
- getOpenCloses: (account, accessToken) => getOpenInstantCloses(
24477
- this._requireHedgerUrl(),
24478
- account,
24479
- accessToken
24480
- )
24471
+ getOpenCloses: (account, accessToken) => getOpenInstantCloses(this.chainId, account, accessToken)
24481
24472
  };
24482
24473
  }
24483
24474
  // ─── Muon Signatures ──────────────────────────────────────────