@pear-protocol/symmio-client 0.1.0 → 0.1.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/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);
@@ -24095,6 +24099,176 @@ async function revokeRole(walletClient, publicClient, symmioDiamond, role, revok
24095
24099
  });
24096
24100
  }
24097
24101
 
24102
+ // src/actions/instant.ts
24103
+ var instant_exports = {};
24104
+ __export(instant_exports, {
24105
+ cancelInstantClose: () => cancelInstantClose,
24106
+ createSiweMessage: () => createSiweMessage,
24107
+ getNonce: () => getNonce,
24108
+ getOpenInstantCloses: () => getOpenInstantCloses,
24109
+ instantClose: () => instantClose,
24110
+ instantOpen: () => instantOpen,
24111
+ login: () => login
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
+ }
24120
+ function createSiweMessage(params) {
24121
+ const version = params.version ?? "1";
24122
+ const issuedAt = (/* @__PURE__ */ new Date()).toISOString();
24123
+ const expirationTime = new Date(
24124
+ Date.now() + 30 * 24 * 60 * 60 * 1e3
24125
+ ).toISOString();
24126
+ const message = [
24127
+ `${params.domain} wants you to sign in with your Ethereum account:`,
24128
+ params.address,
24129
+ "",
24130
+ params.statement,
24131
+ "",
24132
+ `URI: ${params.uri}`,
24133
+ `Version: ${version}`,
24134
+ `Chain ID: ${params.chainId}`,
24135
+ `Nonce: ${params.nonce}`,
24136
+ `Issued At: ${issuedAt}`,
24137
+ `Expiration Time: ${expirationTime}`
24138
+ ].join("\n");
24139
+ return { message, issuedAt, expirationTime };
24140
+ }
24141
+ async function getNonce(chainId, subAccount) {
24142
+ const hedgerBaseUrl = getHedgerBaseUrl(chainId);
24143
+ const url = new URL(`nonce/${subAccount}`, hedgerBaseUrl).href;
24144
+ const response = await fetch(url);
24145
+ if (!response.ok) {
24146
+ throw new Error(`Failed to fetch nonce: ${response.statusText}`);
24147
+ }
24148
+ const data = await response.json();
24149
+ return data.nonce;
24150
+ }
24151
+ async function login(chainId, params) {
24152
+ const hedgerBaseUrl = getHedgerBaseUrl(chainId);
24153
+ const url = new URL("login", hedgerBaseUrl).href;
24154
+ const body = {
24155
+ account_address: params.accountAddress,
24156
+ expiration_time: params.expirationTime,
24157
+ issued_at: params.issuedAt,
24158
+ signature: params.signature,
24159
+ nonce: params.nonce
24160
+ };
24161
+ const response = await fetch(url, {
24162
+ method: "POST",
24163
+ headers: { "Content-Type": "application/json" },
24164
+ body: JSON.stringify(body)
24165
+ });
24166
+ if (!response.ok) {
24167
+ const errorData = await response.json().catch(() => null);
24168
+ throw new Error(
24169
+ errorData?.error_message ?? `Login failed: ${response.statusText}`
24170
+ );
24171
+ }
24172
+ const data = await response.json();
24173
+ if (!data.access_token) {
24174
+ throw new Error("No access token received");
24175
+ }
24176
+ return {
24177
+ accessToken: data.access_token,
24178
+ expirationTime: params.expirationTime,
24179
+ issuedAt: params.issuedAt
24180
+ };
24181
+ }
24182
+ async function instantOpen(chainId, params, accessToken) {
24183
+ const hedgerBaseUrl = getHedgerBaseUrl(chainId);
24184
+ const url = new URL("instant_open", hedgerBaseUrl).href;
24185
+ const body = {
24186
+ symbolId: params.symbolId,
24187
+ positionType: params.positionType,
24188
+ orderType: params.orderType,
24189
+ price: params.price,
24190
+ quantity: params.quantity,
24191
+ cva: params.cva,
24192
+ lf: params.lf,
24193
+ partyAmm: params.partyAmm,
24194
+ partyBmm: params.partyBmm,
24195
+ maxFundingRate: params.maxFundingRate,
24196
+ deadline: params.deadline
24197
+ };
24198
+ const response = await fetch(url, {
24199
+ method: "POST",
24200
+ headers: {
24201
+ "Content-Type": "application/json",
24202
+ Authorization: `Bearer ${accessToken}`
24203
+ },
24204
+ body: JSON.stringify(body)
24205
+ });
24206
+ if (!response.ok) {
24207
+ const errorData = await response.json().catch(() => null);
24208
+ throw new Error(
24209
+ errorData?.error_message ?? `Instant open failed: ${response.statusText}`
24210
+ );
24211
+ }
24212
+ return response.json();
24213
+ }
24214
+ async function instantClose(chainId, params, accessToken) {
24215
+ const hedgerBaseUrl = getHedgerBaseUrl(chainId);
24216
+ const url = new URL("instant_close", hedgerBaseUrl).href;
24217
+ const body = {
24218
+ quote_id: params.quoteId,
24219
+ quantity_to_close: params.quantityToClose,
24220
+ close_price: params.closePrice
24221
+ };
24222
+ const response = await fetch(url, {
24223
+ method: "POST",
24224
+ headers: {
24225
+ "Content-Type": "application/json",
24226
+ Authorization: `Bearer ${accessToken}`
24227
+ },
24228
+ body: JSON.stringify(body)
24229
+ });
24230
+ if (!response.ok) {
24231
+ const errorData = await response.json().catch(() => null);
24232
+ throw new Error(
24233
+ errorData?.error_message ?? `Instant close failed: ${response.statusText}`
24234
+ );
24235
+ }
24236
+ return response.json();
24237
+ }
24238
+ async function cancelInstantClose(chainId, quoteId, accessToken) {
24239
+ const hedgerBaseUrl = getHedgerBaseUrl(chainId);
24240
+ const url = new URL(`instant_close/${quoteId}`, hedgerBaseUrl).href;
24241
+ const response = await fetch(url, {
24242
+ method: "DELETE",
24243
+ headers: {
24244
+ "Content-Type": "application/json",
24245
+ Authorization: `Bearer ${accessToken}`
24246
+ }
24247
+ });
24248
+ if (!response.ok) {
24249
+ const errorData = await response.json().catch(() => null);
24250
+ throw new Error(
24251
+ errorData?.error_message ?? `Cancel instant close failed: ${response.statusText}`
24252
+ );
24253
+ }
24254
+ }
24255
+ async function getOpenInstantCloses(chainId, account, accessToken) {
24256
+ const hedgerBaseUrl = getHedgerBaseUrl(chainId);
24257
+ const url = new URL(`instant_close/${account}`, hedgerBaseUrl).href;
24258
+ const response = await fetch(url, {
24259
+ headers: {
24260
+ Authorization: `Bearer ${accessToken}`
24261
+ }
24262
+ });
24263
+ if (!response.ok) {
24264
+ const errorData = await response.json().catch(() => null);
24265
+ throw new Error(
24266
+ errorData?.error_message ?? `Failed to fetch instant closes: ${response.statusText}`
24267
+ );
24268
+ }
24269
+ return response.json();
24270
+ }
24271
+
24098
24272
  // src/client.ts
24099
24273
  var SymmioSDK = class {
24100
24274
  chainId;
@@ -24278,6 +24452,25 @@ var SymmioSDK = class {
24278
24452
  revokeRole: (role, revokee) => revokeRole(wc, pc, sd, role, revokee)
24279
24453
  };
24280
24454
  }
24455
+ // ─── Instant Trading Module ──────────────────────────────────
24456
+ get instant() {
24457
+ return {
24458
+ /** Creates a SIWE message for instant trading authentication. */
24459
+ createSiweMessage: (params) => createSiweMessage(params),
24460
+ /** Fetches a nonce from the hedger for SIWE authentication. */
24461
+ getNonce: (subAccount) => getNonce(this.chainId, subAccount),
24462
+ /** Exchanges a signed SIWE message for an access token. */
24463
+ login: (params) => login(this.chainId, params),
24464
+ /** Opens a position instantly via the hedger (off-chain). */
24465
+ open: (params, accessToken) => instantOpen(this.chainId, params, accessToken),
24466
+ /** Closes a position instantly via the hedger (off-chain). */
24467
+ close: (params, accessToken) => instantClose(this.chainId, params, accessToken),
24468
+ /** Cancels a pending instant close request. */
24469
+ cancelClose: (quoteId, accessToken) => cancelInstantClose(this.chainId, quoteId, accessToken),
24470
+ /** Fetches the list of open instant close requests for an account. */
24471
+ getOpenCloses: (account, accessToken) => getOpenInstantCloses(this.chainId, account, accessToken)
24472
+ };
24473
+ }
24281
24474
  // ─── Muon Signatures ──────────────────────────────────────────
24282
24475
  async getQuoteSig(partyA, symbolId) {
24283
24476
  return this.muon.getQuoteSig({
@@ -24354,6 +24547,15 @@ var ClearingHouseLiquidationStatus = /* @__PURE__ */ ((ClearingHouseLiquidationS
24354
24547
  return ClearingHouseLiquidationStatus2;
24355
24548
  })(ClearingHouseLiquidationStatus || {});
24356
24549
 
24550
+ // src/types/instant.ts
24551
+ var InstantCloseStatus = /* @__PURE__ */ ((InstantCloseStatus2) => {
24552
+ InstantCloseStatus2[InstantCloseStatus2["STARTED"] = 0] = "STARTED";
24553
+ InstantCloseStatus2[InstantCloseStatus2["PROCESSING"] = 1] = "PROCESSING";
24554
+ InstantCloseStatus2[InstantCloseStatus2["FAILED"] = 2] = "FAILED";
24555
+ InstantCloseStatus2[InstantCloseStatus2["FINISHED"] = 3] = "FINISHED";
24556
+ return InstantCloseStatus2;
24557
+ })(InstantCloseStatus || {});
24558
+
24357
24559
  // src/abis/ClearingHouse.ts
24358
24560
  var ClearingHouseABI = [
24359
24561
  // ─── Liquidation Lifecycle ────────────────────────────────────
@@ -24602,6 +24804,6 @@ function applySlippage(price, slippagePercent, isLong) {
24602
24804
  return price - price * bps / 10000n;
24603
24805
  }
24604
24806
 
24605
- export { ALL_TRADING_SELECTORS, AffiliateFeeLevel, ApprovalState, CHAIN_NAMES, CLEARING_HOUSE_ADDRESS, CLOSE_QUOTE_SELECTOR, COLLATERAL_ADDRESS, COLLATERAL_DECIMALS, ClearingHouseABI, ClearingHouseLiquidationStatus, DEFAULT_PARTY_B_ADDRESS, DEFAULT_PRECISION, ERC20ABI, FALLBACK_CHAIN_ID, LIMIT_ORDER_DEADLINE, LiquidationStatus, MARKET_ORDER_DEADLINE, MARKET_PRICE_COEFFICIENT, MAX_LEVERAGE, MULTI_ACCOUNT_ADDRESS, MUON_APP_NAME, MUON_BASE_URLS, MultiAccountABI, MuonClient, MuonVerifierABI, OrderType, PositionType, QuoteStatus, SEND_QUOTE_WITH_AFFILIATE_SELECTOR, SIGNATURE_STORE_ADDRESS, STANDARD_WITHDRAW_COOLDOWN, SYMMIO_DIAMOND_ADDRESS, SignatureStoreABI, SoftLiquidationLevel, SupportedChainId, SymmioDiamondABI, SymmioSDK, SymmioSDKError, V3_CHAIN_IDS, account_exports as accountActions, admin_exports as adminActions, allocate_exports as allocateActions, applySlippage, approval_exports as approvalActions, calculateGasMargin, cancel_exports as cancelActions, close_exports as closeActions, delegation_exports as delegationActions, deposit_exports as depositActions, encodeCall, formatPrice, fromWei, getAddress, signature_exports as signatureActions, toWei, trade_exports as tradeActions, validateAddress, validateAmount, validateChainId, validateDeadline, validateQuantity, withdraw_exports as withdrawActions, wrapInProxyCall };
24807
+ export { ALL_TRADING_SELECTORS, AffiliateFeeLevel, ApprovalState, CHAIN_NAMES, CLEARING_HOUSE_ADDRESS, CLOSE_QUOTE_SELECTOR, COLLATERAL_ADDRESS, COLLATERAL_DECIMALS, ClearingHouseABI, ClearingHouseLiquidationStatus, DEFAULT_PARTY_B_ADDRESS, DEFAULT_PRECISION, ERC20ABI, FALLBACK_CHAIN_ID, InstantCloseStatus, LIMIT_ORDER_DEADLINE, LiquidationStatus, MARKET_ORDER_DEADLINE, MARKET_PRICE_COEFFICIENT, MAX_LEVERAGE, MULTI_ACCOUNT_ADDRESS, MUON_APP_NAME, MUON_BASE_URLS, MultiAccountABI, MuonClient, MuonVerifierABI, OrderType, PositionType, QuoteStatus, SEND_QUOTE_WITH_AFFILIATE_SELECTOR, SIGNATURE_STORE_ADDRESS, STANDARD_WITHDRAW_COOLDOWN, SYMMIO_DIAMOND_ADDRESS, SignatureStoreABI, SoftLiquidationLevel, SupportedChainId, SymmioDiamondABI, SymmioSDK, SymmioSDKError, V3_CHAIN_IDS, account_exports as accountActions, admin_exports as adminActions, allocate_exports as allocateActions, applySlippage, approval_exports as approvalActions, calculateGasMargin, cancel_exports as cancelActions, close_exports as closeActions, delegation_exports as delegationActions, deposit_exports as depositActions, encodeCall, formatPrice, fromWei, getAddress, instant_exports as instantActions, signature_exports as signatureActions, toWei, trade_exports as tradeActions, validateAddress, validateAmount, validateChainId, validateDeadline, validateQuantity, withdraw_exports as withdrawActions, wrapInProxyCall };
24606
24808
  //# sourceMappingURL=index.mjs.map
24607
24809
  //# sourceMappingURL=index.mjs.map