@pear-protocol/symmio-client 0.2.2 → 0.2.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.
@@ -24045,6 +24045,18 @@ var SymmioSDK = class {
24045
24045
  appName: cfg.muonAppName ?? MUON_APP_NAME
24046
24046
  });
24047
24047
  }
24048
+ get walletClient() {
24049
+ return this._walletClient ?? null;
24050
+ }
24051
+ get isWriteReady() {
24052
+ return !!this._walletClient;
24053
+ }
24054
+ requireWalletClient() {
24055
+ if (!this._walletClient) {
24056
+ throw new Error("WalletClient is required for write operations");
24057
+ }
24058
+ return this._walletClient;
24059
+ }
24048
24060
  // ─── Contract Addresses ────────────────────────────────────────
24049
24061
  get addresses() {
24050
24062
  return {
@@ -24057,14 +24069,19 @@ var SymmioSDK = class {
24057
24069
  }
24058
24070
  // ─── Account Module (MultiAccount) ─────────────────────────────
24059
24071
  get account() {
24060
- const wc = this._walletClient;
24061
24072
  const pc = this._publicClient;
24062
24073
  const ma = this._multiAccount;
24063
24074
  return {
24064
24075
  /** Creates a new account. */
24065
- addAccount: (name) => addAccount(wc, pc, ma, name),
24076
+ addAccount: (name) => addAccount(this.requireWalletClient(), pc, ma, name),
24066
24077
  /** Edits an account's name. */
24067
- editName: (accountAddress, name) => editAccountName(wc, pc, ma, accountAddress, name),
24078
+ editName: (accountAddress, name) => editAccountName(
24079
+ this.requireWalletClient(),
24080
+ pc,
24081
+ ma,
24082
+ accountAddress,
24083
+ name
24084
+ ),
24068
24085
  /** Gets all accounts for a user (paginated). */
24069
24086
  getAll: (user, start, size) => getAccounts(pc, ma, user, start, size),
24070
24087
  /** Gets the number of accounts for a user. */
@@ -24075,71 +24092,137 @@ var SymmioSDK = class {
24075
24092
  }
24076
24093
  // ─── Deposit Module (MultiAccount) ─────────────────────────────
24077
24094
  get deposit() {
24078
- const wc = this._walletClient;
24079
24095
  const pc = this._publicClient;
24080
24096
  const ma = this._multiAccount;
24081
24097
  return {
24082
24098
  /** Standard deposit to an account. */
24083
- standard: (params) => deposit(wc, pc, ma, params),
24099
+ standard: (params) => deposit(this.requireWalletClient(), pc, ma, params),
24084
24100
  /** Deposit and allocate in a single transaction. */
24085
- depositAndAllocate: (params) => depositAndAllocate(wc, pc, ma, params)
24101
+ depositAndAllocate: (params) => depositAndAllocate(
24102
+ this.requireWalletClient(),
24103
+ pc,
24104
+ ma,
24105
+ params
24106
+ )
24086
24107
  };
24087
24108
  }
24088
24109
  // ─── Withdraw Module (MultiAccount) ────────────────────────────
24089
24110
  get withdraw() {
24090
- const wc = this._walletClient;
24091
24111
  const pc = this._publicClient;
24092
24112
  const ma = this._multiAccount;
24093
24113
  return {
24094
24114
  /** Withdraws collateral from an account. */
24095
- withdraw: (params) => withdraw(wc, pc, ma, params)
24115
+ withdraw: (params) => withdraw(this.requireWalletClient(), pc, ma, params)
24096
24116
  };
24097
24117
  }
24098
24118
  // ─── Allocate / Deallocate Module (via _call proxy) ────────────
24099
24119
  get collateral() {
24100
- const wc = this._walletClient;
24101
24120
  const pc = this._publicClient;
24102
24121
  const ma = this._multiAccount;
24103
24122
  return {
24104
24123
  /** Allocate collateral to a trading account. */
24105
- allocate: (subAccount, params) => allocate(wc, pc, ma, subAccount, params),
24124
+ allocate: (subAccount, params) => allocate(
24125
+ this.requireWalletClient(),
24126
+ pc,
24127
+ ma,
24128
+ subAccount,
24129
+ params
24130
+ ),
24106
24131
  /** Deallocate collateral (requires Muon signature). */
24107
- deallocate: (subAccount, params) => deallocate(wc, pc, ma, subAccount, params),
24132
+ deallocate: (subAccount, params) => deallocate(
24133
+ this.requireWalletClient(),
24134
+ pc,
24135
+ ma,
24136
+ subAccount,
24137
+ params
24138
+ ),
24108
24139
  /** Transfer funds to recipient's allocated balance. */
24109
- internalTransfer: (subAccount, params) => internalTransfer(wc, pc, ma, subAccount, params)
24140
+ internalTransfer: (subAccount, params) => internalTransfer(
24141
+ this.requireWalletClient(),
24142
+ pc,
24143
+ ma,
24144
+ subAccount,
24145
+ params
24146
+ )
24110
24147
  };
24111
24148
  }
24112
24149
  // ─── Trade Module ──────────────────────────────────────────────
24113
24150
  get trade() {
24114
- const wc = this._walletClient;
24115
24151
  const pc = this._publicClient;
24116
24152
  const ma = this._multiAccount;
24117
24153
  return {
24118
24154
  /** Opens a position via sendQuoteWithAffiliate. */
24119
- sendQuote: (subAccount, params) => sendQuote(wc, pc, ma, subAccount, params),
24155
+ sendQuote: (subAccount, params) => sendQuote(
24156
+ this.requireWalletClient(),
24157
+ pc,
24158
+ ma,
24159
+ subAccount,
24160
+ params
24161
+ ),
24120
24162
  /** Close a position. */
24121
- closePosition: (subAccount, params) => closePosition(wc, pc, ma, subAccount, params),
24163
+ closePosition: (subAccount, params) => closePosition(
24164
+ this.requireWalletClient(),
24165
+ pc,
24166
+ ma,
24167
+ subAccount,
24168
+ params
24169
+ ),
24122
24170
  /** Cancel a pending quote. */
24123
- cancelQuote: (subAccount, quoteId) => cancelQuote(wc, pc, ma, subAccount, quoteId),
24171
+ cancelQuote: (subAccount, quoteId) => cancelQuote(
24172
+ this.requireWalletClient(),
24173
+ pc,
24174
+ ma,
24175
+ subAccount,
24176
+ quoteId
24177
+ ),
24124
24178
  /** Cancel a pending close request. */
24125
- cancelCloseRequest: (subAccount, quoteId) => cancelCloseRequest(wc, pc, ma, subAccount, quoteId),
24179
+ cancelCloseRequest: (subAccount, quoteId) => cancelCloseRequest(
24180
+ this.requireWalletClient(),
24181
+ pc,
24182
+ ma,
24183
+ subAccount,
24184
+ quoteId
24185
+ ),
24126
24186
  /** Force cancel a quote. */
24127
- forceCancelQuote: (subAccount, quoteId) => forceCancelQuote(wc, pc, ma, subAccount, quoteId),
24187
+ forceCancelQuote: (subAccount, quoteId) => forceCancelQuote(
24188
+ this.requireWalletClient(),
24189
+ pc,
24190
+ ma,
24191
+ subAccount,
24192
+ quoteId
24193
+ ),
24128
24194
  /** Force cancel a close request. */
24129
- forceCancelCloseRequest: (subAccount, quoteId) => forceCancelCloseRequest(wc, pc, ma, subAccount, quoteId)
24195
+ forceCancelCloseRequest: (subAccount, quoteId) => forceCancelCloseRequest(
24196
+ this.requireWalletClient(),
24197
+ pc,
24198
+ ma,
24199
+ subAccount,
24200
+ quoteId
24201
+ )
24130
24202
  };
24131
24203
  }
24132
24204
  // ─── Approval Module ───────────────────────────────────────────
24133
24205
  get approval() {
24134
- const wc = this._walletClient;
24135
24206
  const pc = this._publicClient;
24136
24207
  const collateral = this._collateral;
24137
24208
  const ma = this._multiAccount;
24138
24209
  return {
24139
24210
  /** Approve the MultiAccount contract to spend collateral. */
24140
- approveCollateral: (amount) => approve(wc, pc, collateral, ma, amount),
24211
+ approveCollateral: (amount) => approve(
24212
+ this.requireWalletClient(),
24213
+ pc,
24214
+ collateral,
24215
+ ma,
24216
+ amount
24217
+ ),
24141
24218
  /** Approve any spender for any token. */
24142
- approve: (token, spender, amount) => approve(wc, pc, token, spender, amount),
24219
+ approve: (token, spender, amount) => approve(
24220
+ this.requireWalletClient(),
24221
+ pc,
24222
+ token,
24223
+ spender,
24224
+ amount
24225
+ ),
24143
24226
  /** Get current allowance. */
24144
24227
  getAllowance: (token, owner, spender) => getAllowance(pc, token, owner, spender),
24145
24228
  /** Get token balance. */
@@ -24150,33 +24233,51 @@ var SymmioSDK = class {
24150
24233
  }
24151
24234
  // ─── Delegation Module ─────────────────────────────────────────
24152
24235
  get delegation() {
24153
- const wc = this._walletClient;
24154
24236
  const pc = this._publicClient;
24155
24237
  const ma = this._multiAccount;
24156
24238
  return {
24157
24239
  /** Delegate access to selectors. */
24158
- delegateAccess: (params) => delegateAccess(wc, pc, ma, params),
24240
+ delegateAccess: (params) => delegateAccess(
24241
+ this.requireWalletClient(),
24242
+ pc,
24243
+ ma,
24244
+ params
24245
+ ),
24159
24246
  /** Propose to revoke delegated access (starts cooldown). */
24160
- proposeRevoke: (params) => proposeRevoke(wc, pc, ma, params),
24247
+ proposeRevoke: (params) => proposeRevoke(
24248
+ this.requireWalletClient(),
24249
+ pc,
24250
+ ma,
24251
+ params
24252
+ ),
24161
24253
  /** Revoke delegated access (after cooldown). */
24162
- revokeAccess: (params) => revokeAccess(wc, pc, ma, params),
24254
+ revokeAccess: (params) => revokeAccess(
24255
+ this.requireWalletClient(),
24256
+ pc,
24257
+ ma,
24258
+ params
24259
+ ),
24163
24260
  /** Reads whether a selector is delegated to a target for a sub-account. */
24164
24261
  hasAccess: (params) => hasDelegatedAccess(pc, ma, params)
24165
24262
  };
24166
24263
  }
24167
24264
  // ─── Signature Module ──────────────────────────────────────────
24168
24265
  get signature() {
24169
- const wc = this._walletClient;
24170
24266
  const pc = this._publicClient;
24171
24267
  const ss = this._signatureStore;
24172
24268
  return {
24173
24269
  signTerms: () => {
24174
24270
  if (!ss) throw new Error("SignatureStore not configured for this chain");
24175
- return signTermsMessage(wc, pc, ss);
24271
+ return signTermsMessage(this.requireWalletClient(), pc, ss);
24176
24272
  },
24177
24273
  storeSignature: (sig) => {
24178
24274
  if (!ss) throw new Error("SignatureStore not configured for this chain");
24179
- return storeSignature(wc, pc, ss, sig);
24275
+ return storeSignature(
24276
+ this.requireWalletClient(),
24277
+ pc,
24278
+ ss,
24279
+ sig
24280
+ );
24180
24281
  },
24181
24282
  hasSigned: (user) => {
24182
24283
  if (!ss) throw new Error("SignatureStore not configured for this chain");
@@ -24190,12 +24291,11 @@ var SymmioSDK = class {
24190
24291
  }
24191
24292
  // ─── Admin Module ──────────────────────────────────────────────
24192
24293
  get admin() {
24193
- const wc = this._walletClient;
24194
24294
  const pc = this._publicClient;
24195
24295
  const sd = this._symmioDiamond;
24196
24296
  return {
24197
- grantRole: (role, grantee) => grantRole(wc, pc, sd, role, grantee),
24198
- revokeRole: (role, revokee) => revokeRole(wc, pc, sd, role, revokee)
24297
+ grantRole: (role, grantee) => grantRole(this.requireWalletClient(), pc, sd, role, grantee),
24298
+ revokeRole: (role, revokee) => revokeRole(this.requireWalletClient(), pc, sd, role, revokee)
24199
24299
  };
24200
24300
  }
24201
24301
  // ─── Instant Trading Module ──────────────────────────────────
@@ -24370,7 +24470,7 @@ function SymmProvider({
24370
24470
  } = symmioConfig ?? {};
24371
24471
  const muonBaseUrlsKey = muonBaseUrls?.join(",");
24372
24472
  const symmioClient = useMemo(() => {
24373
- if (!publicClient || !walletClient || !address) return null;
24473
+ if (!publicClient) return null;
24374
24474
  return new SymmioSDK({
24375
24475
  chainId,
24376
24476
  publicClient,
@@ -24380,7 +24480,6 @@ function SymmProvider({
24380
24480
  }, [
24381
24481
  publicClient,
24382
24482
  walletClient,
24383
- address,
24384
24483
  chainId,
24385
24484
  multiAccountAddress,
24386
24485
  symmioDiamondAddress,
@@ -24399,6 +24498,7 @@ function SymmProvider({
24399
24498
  hasPublicClient: !!publicClient,
24400
24499
  hasWalletClient: !!walletClient,
24401
24500
  hasAddress: !!address,
24501
+ isWriteReady: !!symmioClient?.isWriteReady,
24402
24502
  symmioClientBuilt: !!symmioClient
24403
24503
  });
24404
24504
  }, [
@@ -24482,9 +24582,17 @@ function SymmProvider({
24482
24582
  accessToken,
24483
24583
  authToken: accessToken,
24484
24584
  isReady: !!symmioClient && !!symmCoreClient,
24585
+ isWriteReady: !!symmioClient?.isWriteReady,
24485
24586
  refreshAuth
24486
24587
  }),
24487
- [symmioClient, symmCoreClient, chainId, address, accessToken, refreshAuth]
24588
+ [
24589
+ symmioClient,
24590
+ symmCoreClient,
24591
+ chainId,
24592
+ address,
24593
+ accessToken,
24594
+ refreshAuth
24595
+ ]
24488
24596
  );
24489
24597
  return /* @__PURE__ */ jsx(SymmContext.Provider, { value, children });
24490
24598
  }