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