@pear-protocol/symmio-client 0.2.1 → 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.
package/dist/index.mjs CHANGED
@@ -24363,6 +24363,18 @@ var SymmioSDK = class {
24363
24363
  appName: cfg.muonAppName ?? MUON_APP_NAME
24364
24364
  });
24365
24365
  }
24366
+ get walletClient() {
24367
+ return this._walletClient ?? null;
24368
+ }
24369
+ get isWriteReady() {
24370
+ return !!this._walletClient;
24371
+ }
24372
+ requireWalletClient() {
24373
+ if (!this._walletClient) {
24374
+ throw new Error("WalletClient is required for write operations");
24375
+ }
24376
+ return this._walletClient;
24377
+ }
24366
24378
  // ─── Contract Addresses ────────────────────────────────────────
24367
24379
  get addresses() {
24368
24380
  return {
@@ -24375,14 +24387,19 @@ var SymmioSDK = class {
24375
24387
  }
24376
24388
  // ─── Account Module (MultiAccount) ─────────────────────────────
24377
24389
  get account() {
24378
- const wc = this._walletClient;
24379
24390
  const pc = this._publicClient;
24380
24391
  const ma = this._multiAccount;
24381
24392
  return {
24382
24393
  /** Creates a new account. */
24383
- addAccount: (name) => addAccount(wc, pc, ma, name),
24394
+ addAccount: (name) => addAccount(this.requireWalletClient(), pc, ma, name),
24384
24395
  /** Edits an account's name. */
24385
- editName: (accountAddress, name) => editAccountName(wc, pc, ma, accountAddress, name),
24396
+ editName: (accountAddress, name) => editAccountName(
24397
+ this.requireWalletClient(),
24398
+ pc,
24399
+ ma,
24400
+ accountAddress,
24401
+ name
24402
+ ),
24386
24403
  /** Gets all accounts for a user (paginated). */
24387
24404
  getAll: (user, start, size) => getAccounts(pc, ma, user, start, size),
24388
24405
  /** Gets the number of accounts for a user. */
@@ -24393,71 +24410,137 @@ var SymmioSDK = class {
24393
24410
  }
24394
24411
  // ─── Deposit Module (MultiAccount) ─────────────────────────────
24395
24412
  get deposit() {
24396
- const wc = this._walletClient;
24397
24413
  const pc = this._publicClient;
24398
24414
  const ma = this._multiAccount;
24399
24415
  return {
24400
24416
  /** Standard deposit to an account. */
24401
- standard: (params) => deposit(wc, pc, ma, params),
24417
+ standard: (params) => deposit(this.requireWalletClient(), pc, ma, params),
24402
24418
  /** Deposit and allocate in a single transaction. */
24403
- depositAndAllocate: (params) => depositAndAllocate(wc, pc, ma, params)
24419
+ depositAndAllocate: (params) => depositAndAllocate(
24420
+ this.requireWalletClient(),
24421
+ pc,
24422
+ ma,
24423
+ params
24424
+ )
24404
24425
  };
24405
24426
  }
24406
24427
  // ─── Withdraw Module (MultiAccount) ────────────────────────────
24407
24428
  get withdraw() {
24408
- const wc = this._walletClient;
24409
24429
  const pc = this._publicClient;
24410
24430
  const ma = this._multiAccount;
24411
24431
  return {
24412
24432
  /** Withdraws collateral from an account. */
24413
- withdraw: (params) => withdraw(wc, pc, ma, params)
24433
+ withdraw: (params) => withdraw(this.requireWalletClient(), pc, ma, params)
24414
24434
  };
24415
24435
  }
24416
24436
  // ─── Allocate / Deallocate Module (via _call proxy) ────────────
24417
24437
  get collateral() {
24418
- const wc = this._walletClient;
24419
24438
  const pc = this._publicClient;
24420
24439
  const ma = this._multiAccount;
24421
24440
  return {
24422
24441
  /** Allocate collateral to a trading account. */
24423
- allocate: (subAccount, params) => allocate(wc, pc, ma, subAccount, params),
24442
+ allocate: (subAccount, params) => allocate(
24443
+ this.requireWalletClient(),
24444
+ pc,
24445
+ ma,
24446
+ subAccount,
24447
+ params
24448
+ ),
24424
24449
  /** Deallocate collateral (requires Muon signature). */
24425
- deallocate: (subAccount, params) => deallocate(wc, pc, ma, subAccount, params),
24450
+ deallocate: (subAccount, params) => deallocate(
24451
+ this.requireWalletClient(),
24452
+ pc,
24453
+ ma,
24454
+ subAccount,
24455
+ params
24456
+ ),
24426
24457
  /** Transfer funds to recipient's allocated balance. */
24427
- internalTransfer: (subAccount, params) => internalTransfer(wc, pc, ma, subAccount, params)
24458
+ internalTransfer: (subAccount, params) => internalTransfer(
24459
+ this.requireWalletClient(),
24460
+ pc,
24461
+ ma,
24462
+ subAccount,
24463
+ params
24464
+ )
24428
24465
  };
24429
24466
  }
24430
24467
  // ─── Trade Module ──────────────────────────────────────────────
24431
24468
  get trade() {
24432
- const wc = this._walletClient;
24433
24469
  const pc = this._publicClient;
24434
24470
  const ma = this._multiAccount;
24435
24471
  return {
24436
24472
  /** Opens a position via sendQuoteWithAffiliate. */
24437
- sendQuote: (subAccount, params) => sendQuote(wc, pc, ma, subAccount, params),
24473
+ sendQuote: (subAccount, params) => sendQuote(
24474
+ this.requireWalletClient(),
24475
+ pc,
24476
+ ma,
24477
+ subAccount,
24478
+ params
24479
+ ),
24438
24480
  /** Close a position. */
24439
- closePosition: (subAccount, params) => closePosition(wc, pc, ma, subAccount, params),
24481
+ closePosition: (subAccount, params) => closePosition(
24482
+ this.requireWalletClient(),
24483
+ pc,
24484
+ ma,
24485
+ subAccount,
24486
+ params
24487
+ ),
24440
24488
  /** Cancel a pending quote. */
24441
- cancelQuote: (subAccount, quoteId) => cancelQuote(wc, pc, ma, subAccount, quoteId),
24489
+ cancelQuote: (subAccount, quoteId) => cancelQuote(
24490
+ this.requireWalletClient(),
24491
+ pc,
24492
+ ma,
24493
+ subAccount,
24494
+ quoteId
24495
+ ),
24442
24496
  /** Cancel a pending close request. */
24443
- cancelCloseRequest: (subAccount, quoteId) => cancelCloseRequest(wc, pc, ma, subAccount, quoteId),
24497
+ cancelCloseRequest: (subAccount, quoteId) => cancelCloseRequest(
24498
+ this.requireWalletClient(),
24499
+ pc,
24500
+ ma,
24501
+ subAccount,
24502
+ quoteId
24503
+ ),
24444
24504
  /** Force cancel a quote. */
24445
- forceCancelQuote: (subAccount, quoteId) => forceCancelQuote(wc, pc, ma, subAccount, quoteId),
24505
+ forceCancelQuote: (subAccount, quoteId) => forceCancelQuote(
24506
+ this.requireWalletClient(),
24507
+ pc,
24508
+ ma,
24509
+ subAccount,
24510
+ quoteId
24511
+ ),
24446
24512
  /** Force cancel a close request. */
24447
- forceCancelCloseRequest: (subAccount, quoteId) => forceCancelCloseRequest(wc, pc, ma, subAccount, quoteId)
24513
+ forceCancelCloseRequest: (subAccount, quoteId) => forceCancelCloseRequest(
24514
+ this.requireWalletClient(),
24515
+ pc,
24516
+ ma,
24517
+ subAccount,
24518
+ quoteId
24519
+ )
24448
24520
  };
24449
24521
  }
24450
24522
  // ─── Approval Module ───────────────────────────────────────────
24451
24523
  get approval() {
24452
- const wc = this._walletClient;
24453
24524
  const pc = this._publicClient;
24454
24525
  const collateral = this._collateral;
24455
24526
  const ma = this._multiAccount;
24456
24527
  return {
24457
24528
  /** Approve the MultiAccount contract to spend collateral. */
24458
- approveCollateral: (amount) => approve(wc, pc, collateral, ma, amount),
24529
+ approveCollateral: (amount) => approve(
24530
+ this.requireWalletClient(),
24531
+ pc,
24532
+ collateral,
24533
+ ma,
24534
+ amount
24535
+ ),
24459
24536
  /** Approve any spender for any token. */
24460
- approve: (token, spender, amount) => approve(wc, pc, token, spender, amount),
24537
+ approve: (token, spender, amount) => approve(
24538
+ this.requireWalletClient(),
24539
+ pc,
24540
+ token,
24541
+ spender,
24542
+ amount
24543
+ ),
24461
24544
  /** Get current allowance. */
24462
24545
  getAllowance: (token, owner, spender) => getAllowance(pc, token, owner, spender),
24463
24546
  /** Get token balance. */
@@ -24468,33 +24551,51 @@ var SymmioSDK = class {
24468
24551
  }
24469
24552
  // ─── Delegation Module ─────────────────────────────────────────
24470
24553
  get delegation() {
24471
- const wc = this._walletClient;
24472
24554
  const pc = this._publicClient;
24473
24555
  const ma = this._multiAccount;
24474
24556
  return {
24475
24557
  /** Delegate access to selectors. */
24476
- delegateAccess: (params) => delegateAccess(wc, pc, ma, params),
24558
+ delegateAccess: (params) => delegateAccess(
24559
+ this.requireWalletClient(),
24560
+ pc,
24561
+ ma,
24562
+ params
24563
+ ),
24477
24564
  /** Propose to revoke delegated access (starts cooldown). */
24478
- proposeRevoke: (params) => proposeRevoke(wc, pc, ma, params),
24565
+ proposeRevoke: (params) => proposeRevoke(
24566
+ this.requireWalletClient(),
24567
+ pc,
24568
+ ma,
24569
+ params
24570
+ ),
24479
24571
  /** Revoke delegated access (after cooldown). */
24480
- revokeAccess: (params) => revokeAccess(wc, pc, ma, params),
24572
+ revokeAccess: (params) => revokeAccess(
24573
+ this.requireWalletClient(),
24574
+ pc,
24575
+ ma,
24576
+ params
24577
+ ),
24481
24578
  /** Reads whether a selector is delegated to a target for a sub-account. */
24482
24579
  hasAccess: (params) => hasDelegatedAccess(pc, ma, params)
24483
24580
  };
24484
24581
  }
24485
24582
  // ─── Signature Module ──────────────────────────────────────────
24486
24583
  get signature() {
24487
- const wc = this._walletClient;
24488
24584
  const pc = this._publicClient;
24489
24585
  const ss = this._signatureStore;
24490
24586
  return {
24491
24587
  signTerms: () => {
24492
24588
  if (!ss) throw new Error("SignatureStore not configured for this chain");
24493
- return signTermsMessage(wc, pc, ss);
24589
+ return signTermsMessage(this.requireWalletClient(), pc, ss);
24494
24590
  },
24495
24591
  storeSignature: (sig) => {
24496
24592
  if (!ss) throw new Error("SignatureStore not configured for this chain");
24497
- return storeSignature(wc, pc, ss, sig);
24593
+ return storeSignature(
24594
+ this.requireWalletClient(),
24595
+ pc,
24596
+ ss,
24597
+ sig
24598
+ );
24498
24599
  },
24499
24600
  hasSigned: (user) => {
24500
24601
  if (!ss) throw new Error("SignatureStore not configured for this chain");
@@ -24508,12 +24609,11 @@ var SymmioSDK = class {
24508
24609
  }
24509
24610
  // ─── Admin Module ──────────────────────────────────────────────
24510
24611
  get admin() {
24511
- const wc = this._walletClient;
24512
24612
  const pc = this._publicClient;
24513
24613
  const sd = this._symmioDiamond;
24514
24614
  return {
24515
- grantRole: (role, grantee) => grantRole(wc, pc, sd, role, grantee),
24516
- revokeRole: (role, revokee) => revokeRole(wc, pc, sd, role, revokee)
24615
+ grantRole: (role, grantee) => grantRole(this.requireWalletClient(), pc, sd, role, grantee),
24616
+ revokeRole: (role, revokee) => revokeRole(this.requireWalletClient(), pc, sd, role, revokee)
24517
24617
  };
24518
24618
  }
24519
24619
  // ─── Instant Trading Module ──────────────────────────────────