@owney/sdk 0.7.22-beta.4 → 0.7.22-beta.5

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.cjs CHANGED
@@ -501,7 +501,7 @@ function createSurfBroker(options) {
501
501
  )
502
502
  };
503
503
  }
504
- var SURF_SESSION_HEADER, SURF_BROKER_TIMEOUT_MS, VAULT_MEMO_TTL_MS, AGENT_ID, DISCOVERY_WALLET, SurfSessionExpiredError, asRecord, unavailable;
504
+ var SURF_SESSION_HEADER, SURF_BROKER_TIMEOUT_MS, VAULT_MEMO_TTL_MS, AGENT_ID, DISCOVERY_WALLET, SurfSessionExpiredError, asRecord, unavailable, emptyVaultInfo;
505
505
  var init_surfliquid_broker = __esm({
506
506
  "src/agents/surfliquid/surfliquid.broker.ts"() {
507
507
  "use strict";
@@ -520,6 +520,7 @@ var init_surfliquid_broker = __esm({
520
520
  };
521
521
  asRecord = (value) => value && typeof value === "object" ? value : {};
522
522
  unavailable = (message, details) => new OwneyError("SURF_UNAVAILABLE", message, details, AGENT_ID);
523
+ emptyVaultInfo = () => normalizeVault(void 0);
523
524
  }
524
525
  });
525
526
 
@@ -562,8 +563,18 @@ function mapMessage(message) {
562
563
  }
563
564
  return [base4];
564
565
  }
566
+ function dedupeMessages(messages) {
567
+ const seen = /* @__PURE__ */ new Set();
568
+ return messages.filter((message) => {
569
+ if (!message.txHash) return true;
570
+ const key2 = `${message.transactionType}:${message.txHash}`;
571
+ if (seen.has(key2)) return false;
572
+ seen.add(key2);
573
+ return true;
574
+ });
575
+ }
565
576
  function mapHistory(result, _chainId) {
566
- const data = result.messages.flatMap(mapMessage);
577
+ const data = dedupeMessages(result.messages).flatMap(mapMessage);
567
578
  const hasMore = result.page < result.pages;
568
579
  return {
569
580
  data,
@@ -1296,8 +1307,20 @@ var init_surfliquid_agent = __esm({
1296
1307
  this.brokerWallet = null;
1297
1308
  this.smartAccountAddress = null;
1298
1309
  }
1299
- async activateAgent(state, _chainId) {
1300
- await this.connect(state);
1310
+ // The SDK orchestrator already marks the agent active and sets the chain. SurfLiquid
1311
+ // establishes its session lazily — on the first read of a deployed account, or on
1312
+ // deposit — so merely connecting a wallet never prompts for a signature.
1313
+ async activateAgent(_state, _chainId) {
1314
+ }
1315
+ /** A counterfactual account owns no vault and can't be a SIWE signer yet — reads answer empty. */
1316
+ async isSmartAccountDeployed(state) {
1317
+ if (this.broker?.hasSession()) return true;
1318
+ const wallet = await this.sponsoredWallet(state);
1319
+ this.smartAccountAddress = wallet.smartAccountAddress;
1320
+ const { createSponsoredChain: createSponsoredChain2 } = await Promise.resolve().then(() => (init_surfliquid_smart_account(), surfliquid_smart_account_exports));
1321
+ return createSponsoredChain2(this.config.rpcUrl).isDeployed(
1322
+ wallet.smartAccountAddress
1323
+ );
1301
1324
  }
1302
1325
  // --- IAgent: funds (gasless only) ---
1303
1326
  async deposit(state, _chainId, amount, _asset, _depositCallback) {
@@ -1355,6 +1378,7 @@ var init_surfliquid_agent = __esm({
1355
1378
  }
1356
1379
  // --- IAgent: portfolio reads ---
1357
1380
  async vault(state) {
1381
+ if (!await this.isSmartAccountDeployed(state)) return emptyVaultInfo();
1358
1382
  const broker = await this.connect(state);
1359
1383
  return this.withSession(state, () => broker.getVault(this.surfWallet(state)));
1360
1384
  }
@@ -1372,6 +1396,7 @@ var init_surfliquid_agent = __esm({
1372
1396
  return mapAccountApy(await this.vault(state), days);
1373
1397
  }
1374
1398
  async getHistory(state, chainId, options) {
1399
+ if (!await this.isSmartAccountDeployed(state)) return { data: [], hasMore: false };
1375
1400
  const broker = await this.connect(state);
1376
1401
  const page = options?.cursor ? Number(options.cursor) : 1;
1377
1402
  const limit = options?.limit ?? HISTORY_DEFAULT_LIMIT;
package/dist/index.js CHANGED
@@ -3036,7 +3036,7 @@ var OwneySDK = class {
3036
3036
  }
3037
3037
  if (agentId === "surfliquid") {
3038
3038
  if (!key2) return null;
3039
- const { SurfLiquidAgent } = await import("./surfliquid.agent-ZTIK54MW.js");
3039
+ const { SurfLiquidAgent } = await import("./surfliquid.agent-YC4VDPPF.js");
3040
3040
  return new SurfLiquidAgent({
3041
3041
  apiKey: this.apiKey,
3042
3042
  routingApiBaseUrl: this.routingApiBaseUrl
@@ -96,6 +96,7 @@ function parseJson(text) {
96
96
  return void 0;
97
97
  }
98
98
  }
99
+ var emptyVaultInfo = () => normalizeVault(void 0);
99
100
  function normalizeVault(json) {
100
101
  const root = asRecord(json);
101
102
  const data = asRecord(root.data);
@@ -301,8 +302,18 @@ function mapMessage(message) {
301
302
  }
302
303
  return [base];
303
304
  }
305
+ function dedupeMessages(messages) {
306
+ const seen = /* @__PURE__ */ new Set();
307
+ return messages.filter((message) => {
308
+ if (!message.txHash) return true;
309
+ const key = `${message.transactionType}:${message.txHash}`;
310
+ if (seen.has(key)) return false;
311
+ seen.add(key);
312
+ return true;
313
+ });
314
+ }
304
315
  function mapHistory(result, _chainId) {
305
- const data = result.messages.flatMap(mapMessage);
316
+ const data = dedupeMessages(result.messages).flatMap(mapMessage);
306
317
  const hasMore = result.page < result.pages;
307
318
  return {
308
319
  data,
@@ -583,8 +594,20 @@ var SurfLiquidAgent = class {
583
594
  this.brokerWallet = null;
584
595
  this.smartAccountAddress = null;
585
596
  }
586
- async activateAgent(state, _chainId) {
587
- await this.connect(state);
597
+ // The SDK orchestrator already marks the agent active and sets the chain. SurfLiquid
598
+ // establishes its session lazily — on the first read of a deployed account, or on
599
+ // deposit — so merely connecting a wallet never prompts for a signature.
600
+ async activateAgent(_state, _chainId) {
601
+ }
602
+ /** A counterfactual account owns no vault and can't be a SIWE signer yet — reads answer empty. */
603
+ async isSmartAccountDeployed(state) {
604
+ if (this.broker?.hasSession()) return true;
605
+ const wallet = await this.sponsoredWallet(state);
606
+ this.smartAccountAddress = wallet.smartAccountAddress;
607
+ const { createSponsoredChain } = await import("./surfliquid.smart-account-YV3PLZ72.js");
608
+ return createSponsoredChain(this.config.rpcUrl).isDeployed(
609
+ wallet.smartAccountAddress
610
+ );
588
611
  }
589
612
  // --- IAgent: funds (gasless only) ---
590
613
  async deposit(state, _chainId, amount, _asset, _depositCallback) {
@@ -642,6 +665,7 @@ var SurfLiquidAgent = class {
642
665
  }
643
666
  // --- IAgent: portfolio reads ---
644
667
  async vault(state) {
668
+ if (!await this.isSmartAccountDeployed(state)) return emptyVaultInfo();
645
669
  const broker = await this.connect(state);
646
670
  return this.withSession(state, () => broker.getVault(this.surfWallet(state)));
647
671
  }
@@ -659,6 +683,7 @@ var SurfLiquidAgent = class {
659
683
  return mapAccountApy(await this.vault(state), days);
660
684
  }
661
685
  async getHistory(state, chainId, options) {
686
+ if (!await this.isSmartAccountDeployed(state)) return { data: [], hasMore: false };
662
687
  const broker = await this.connect(state);
663
688
  const page = options?.cursor ? Number(options.cursor) : 1;
664
689
  const limit = options?.limit ?? HISTORY_DEFAULT_LIMIT;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@owney/sdk",
3
- "version": "0.7.22-beta.4",
3
+ "version": "0.7.22-beta.5",
4
4
  "type": "module",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.js",